Skip to content

Commit 5b06f95

Browse files
authored
Merge pull request #7 from jzuniga206/feature
Fixed resizing bug for component rectangle
2 parents 1244e09 + 1abcb0e commit 5b06f95

File tree

2 files changed

+65
-28
lines changed

2 files changed

+65
-28
lines changed

src/components/CodePreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import { format } from 'prettier';
3-
import componentRender from '../utils/componentRender.util.ts';
4-
import { ComponentInt, ComponentsInt } from '../utils/Interfaces.ts';
3+
import componentRender from '../utils/componentRender.util';
4+
import { ComponentInt, ComponentsInt } from '../utils/Interfaces';
55
/** ** SortCHildren will be fixed , dont XXX the file *** */
66
// import SortChildren from './SortChildren.jsx';
77
import SyntaxHighlighter from 'react-syntax-highlighter';

src/components/Rectangle.tsx

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class Rectangle extends Component<PropsInt, StateInt> {
3636
};
3737

3838
getComponentColor(componentId: number) {
39-
const color = this.props.components.find((comp: ComponentInt) => comp.id === componentId).color;
39+
const color = this.props.components.find(
40+
(comp: ComponentInt) => comp.id === componentId
41+
).color;
4042
return color;
4143
}
4244

@@ -46,7 +48,12 @@ class Rectangle extends Component<PropsInt, StateInt> {
4648
);
4749
}
4850

49-
handleResize(componentId: number, childId: number, target: any, blockSnapSize: number) {
51+
handleResize(
52+
componentId: number,
53+
childId: number,
54+
target: any,
55+
blockSnapSize: number
56+
) {
5057
let focChild: ChildInt = this.props.components
5158
.find((comp: ComponentInt) => comp.id === this.props.componentId)
5259
.childrenArray.find((child: ChildInt) => child.childId === childId);
@@ -57,16 +64,25 @@ class Rectangle extends Component<PropsInt, StateInt> {
5764
);
5865
}
5966
const transformation = {
60-
width: Math.round((target.width() * target.scaleX()) / blockSnapSize) * blockSnapSize,
61-
height: Math.round((target.height() * target.scaleY()) / blockSnapSize) * blockSnapSize,
67+
width:
68+
Math.round((target.width() * target.scaleX()) / blockSnapSize) *
69+
blockSnapSize,
70+
height:
71+
Math.round((target.height() * target.scaleY()) / blockSnapSize) *
72+
blockSnapSize,
6273
x: target.x() + focChild.position.x,
6374
y: target.y() + focChild.position.y
6475
};
6576

6677
this.props.handleTransform(componentId, childId, transformation);
6778
}
6879

69-
handleDrag(componentId: number, childId: number, target: any, blockSnapSize: any) {
80+
handleDrag(
81+
componentId: number,
82+
childId: number,
83+
target: any,
84+
blockSnapSize: any
85+
) {
7086
const transformation = {
7187
x: Math.round(target.x() / blockSnapSize) * blockSnapSize,
7288
y: Math.round(target.y() / blockSnapSize) * blockSnapSize
@@ -114,18 +130,20 @@ class Rectangle extends Component<PropsInt, StateInt> {
114130
scaleY={scaleY}
115131
width={width}
116132
height={height}
117-
onDragEnd={event => this.handleDrag(componentId, childId, event.target, blockSnapSize)}
133+
onDragEnd={event =>
134+
this.handleDrag(componentId, childId, event.target, blockSnapSize)
135+
}
118136
ref={node => {
119137
this.group = node;
120138
}}
121-
tabIndex="0" // required for keypress event to be heard by this.group
139+
tabIndex='0' // required for keypress event to be heard by this.group
122140
>
123141
<Rect
124142
// a Konva Rect is generated for each child of the focusComponent (including the pseudochild, representing the focusComponent itself)
125143
ref={node => {
126144
this.rect = node;
127145
}}
128-
tabIndex="0" // required for keypress event to be heard by this.group
146+
tabIndex='0' // required for keypress event to be heard by this.group
129147
name={`${childId}`}
130148
className={'childRect'}
131149
x={0}
@@ -137,7 +155,11 @@ class Rectangle extends Component<PropsInt, StateInt> {
137155
scaleY={1}
138156
width={width}
139157
height={height}
140-
stroke={childType === 'COMP' ? this.getComponentColor(childComponentId) : '#000000'}
158+
stroke={
159+
childType === 'COMP'
160+
? this.getComponentColor(childComponentId)
161+
: '#000000'
162+
}
141163
onTransformEnd={event =>
142164
this.handleResize(componentId, childId, event.target, blockSnapSize)
143165
}
@@ -146,17 +168,28 @@ class Rectangle extends Component<PropsInt, StateInt> {
146168
draggable={false}
147169
fill={childId === -1 ? 'white' : null}
148170
shadowBlur={childId === -1 ? 6 : null}
149-
fillPatternImage={this.state.image ? this.state.image : this.setImage(imageSource)}
150-
fillPatternScaleX={this.state.image ? width / this.state.image.width : 1}
151-
fillPatternScaleY={this.state.image ? height / this.state.image.height : 1}
171+
fillPatternImage={
172+
this.state.image ? this.state.image : this.setImage(imageSource)
173+
}
174+
fillPatternScaleX={
175+
this.state.image ? width / this.state.image.width : 1
176+
}
177+
fillPatternScaleY={
178+
this.state.image ? height / this.state.image.height : 1
179+
}
180+
_useStrictMode
152181
/>
153182
<Label>
154183
<Text
155184
fontStyle={'bold'}
156185
fontVariant={'small-caps'}
157186
// pseudochild's label should look different than normal children:
158187
text={childId === -1 ? title.slice(0, title.length - 2) : title}
159-
fill={childId === -1 ? this.getComponentColor(childComponentId) : '#000000'}
188+
fill={
189+
childId === -1
190+
? this.getComponentColor(childComponentId)
191+
: '#000000'
192+
}
160193
fontSize={childId === -1 ? 15 : 10}
161194
x={4}
162195
y={childId === -1 ? -20 : -12}
@@ -175,14 +208,20 @@ class Rectangle extends Component<PropsInt, StateInt> {
175208
componentId={componentId}
176209
directParentName={childComponentName}
177210
childType={grandchild.childType}
178-
imageSource={grandchild.htmlElement === 'Image' && grandchild.HTMLInfo.Src}
211+
imageSource={
212+
grandchild.htmlElement === 'Image' && grandchild.HTMLInfo.Src
213+
}
179214
childComponentName={grandchild.componentName}
180215
childComponentId={grandchild.childComponentId}
181216
focusChild={focusChild}
182217
childId={childId} // scary addition, grandchildren rects default to childId of "direct" children
183-
width={grandchild.position.width * (width / this.getPseudoChild().position.width)}
218+
width={
219+
grandchild.position.width *
220+
(width / this.getPseudoChild().position.width)
221+
}
184222
height={
185-
grandchild.position.height * (height / this.getPseudoChild().position.height)
223+
grandchild.position.height *
224+
(height / this.getPseudoChild().position.height)
186225
}
187226
x={
188227
(grandchild.position.x - this.getPseudoChild().position.x) *
@@ -194,16 +233,14 @@ class Rectangle extends Component<PropsInt, StateInt> {
194233
}
195234
/>
196235
))}
197-
{focusChild &&
198-
focusChild.childId === childId &&
199-
draggable && (
200-
<TransformerComponent
201-
focusChild={focusChild}
202-
rectClass={'childRect'}
203-
anchorSize={8}
204-
color={'grey'}
205-
/>
206-
)}
236+
{focusChild && focusChild.childId === childId && draggable && (
237+
<TransformerComponent
238+
focusChild={focusChild}
239+
rectClass={'childRect'}
240+
anchorSize={8}
241+
color={'grey'}
242+
/>
243+
)}
207244
</Group>
208245
);
209246
}

0 commit comments

Comments
 (0)