@@ -36,7 +36,9 @@ class Rectangle extends Component<PropsInt, StateInt> {
36
36
} ;
37
37
38
38
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 ;
40
42
return color ;
41
43
}
42
44
@@ -46,7 +48,12 @@ class Rectangle extends Component<PropsInt, StateInt> {
46
48
) ;
47
49
}
48
50
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
+ ) {
50
57
let focChild : ChildInt = this . props . components
51
58
. find ( ( comp : ComponentInt ) => comp . id === this . props . componentId )
52
59
. childrenArray . find ( ( child : ChildInt ) => child . childId === childId ) ;
@@ -57,15 +64,24 @@ class Rectangle extends Component<PropsInt, StateInt> {
57
64
) ;
58
65
}
59
66
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 ,
62
73
x : target . x ( ) + focChild . position . x ,
63
74
y : target . y ( ) + focChild . position . y
64
75
} ;
65
76
this . props . handleTransform ( componentId , childId , transformation ) ;
66
77
}
67
78
68
- handleDrag ( componentId : number , childId : number , target : any , blockSnapSize : any ) {
79
+ handleDrag (
80
+ componentId : number ,
81
+ childId : number ,
82
+ target : any ,
83
+ blockSnapSize : any
84
+ ) {
69
85
const transformation = {
70
86
x : Math . round ( target . x ( ) / blockSnapSize ) * blockSnapSize ,
71
87
y : Math . round ( target . y ( ) / blockSnapSize ) * blockSnapSize
@@ -113,18 +129,20 @@ class Rectangle extends Component<PropsInt, StateInt> {
113
129
scaleY = { scaleY }
114
130
width = { width }
115
131
height = { height }
116
- onDragEnd = { event => this . handleDrag ( componentId , childId , event . target , blockSnapSize ) }
132
+ onDragEnd = { event =>
133
+ this . handleDrag ( componentId , childId , event . target , blockSnapSize )
134
+ }
117
135
ref = { node => {
118
136
this . group = node ;
119
137
} }
120
- tabIndex = "0" // required for keypress event to be heard by this.group
138
+ tabIndex = '0' // required for keypress event to be heard by this.group
121
139
>
122
140
< Rect
123
141
// a Konva Rect is generated for each child of the focusComponent (including the pseudochild, representing the focusComponent itself)
124
142
ref = { node => {
125
143
this . rect = node ;
126
144
} }
127
- tabIndex = "0" // required for keypress event to be heard by this.group
145
+ tabIndex = '0' // required for keypress event to be heard by this.group
128
146
name = { `${ childId } ` }
129
147
className = { 'childRect' }
130
148
x = { 0 }
@@ -136,7 +154,11 @@ class Rectangle extends Component<PropsInt, StateInt> {
136
154
scaleY = { 1 }
137
155
width = { width }
138
156
height = { height }
139
- stroke = { childType === 'COMP' ? this . getComponentColor ( childComponentId ) : '#000000' }
157
+ stroke = {
158
+ childType === 'COMP'
159
+ ? this . getComponentColor ( childComponentId )
160
+ : '#000000'
161
+ }
140
162
onTransformEnd = { event =>
141
163
this . handleResize ( componentId , childId , event . target , blockSnapSize )
142
164
}
@@ -145,9 +167,11 @@ class Rectangle extends Component<PropsInt, StateInt> {
145
167
draggable = { false }
146
168
fill = { null }
147
169
shadowBlur = { childId === - 1 ? 6 : null }
170
+
148
171
fillPatternImage = { this . state . image ? this . state . image : null }
149
172
fillPatternScaleX = { this . state . image ? width / this . state . image . width : 1 }
150
173
fillPatternScaleY = { this . state . image ? height / this . state . image . height : 1 }
174
+
151
175
_useStrictMode
152
176
/>
153
177
< Label >
@@ -156,7 +180,11 @@ class Rectangle extends Component<PropsInt, StateInt> {
156
180
fontVariant = { 'small-caps' }
157
181
// pseudochild's label should look different than normal children:
158
182
text = { childId === - 1 ? title . slice ( 0 , title . length - 2 ) : title }
159
- fill = { childId === - 1 ? this . getComponentColor ( childComponentId ) : '#000000' }
183
+ fill = {
184
+ childId === - 1
185
+ ? this . getComponentColor ( childComponentId )
186
+ : '#000000'
187
+ }
160
188
fontSize = { childId === - 1 ? 15 : 10 }
161
189
x = { 4 }
162
190
y = { childId === - 1 ? - 20 : - 12 }
@@ -175,14 +203,20 @@ class Rectangle extends Component<PropsInt, StateInt> {
175
203
componentId = { componentId }
176
204
directParentName = { childComponentName }
177
205
childType = { grandchild . childType }
178
- imageSource = { grandchild . htmlElement === 'Image' && grandchild . HTMLInfo . Src }
206
+ imageSource = {
207
+ grandchild . htmlElement === 'Image' && grandchild . HTMLInfo . Src
208
+ }
179
209
childComponentName = { grandchild . componentName }
180
210
childComponentId = { grandchild . childComponentId }
181
211
focusChild = { focusChild }
182
212
childId = { childId } // scary addition, grandchildren rects default to childId of "direct" children
183
- width = { grandchild . position . width * ( width / this . getPseudoChild ( ) . position . width ) }
213
+ width = {
214
+ grandchild . position . width *
215
+ ( width / this . getPseudoChild ( ) . position . width )
216
+ }
184
217
height = {
185
- grandchild . position . height * ( height / this . getPseudoChild ( ) . position . height )
218
+ grandchild . position . height *
219
+ ( height / this . getPseudoChild ( ) . position . height )
186
220
}
187
221
x = {
188
222
( grandchild . position . x - this . getPseudoChild ( ) . position . x ) *
@@ -194,16 +228,14 @@ class Rectangle extends Component<PropsInt, StateInt> {
194
228
}
195
229
/>
196
230
) ) }
197
- { focusChild &&
198
- focusChild . childId === childId &&
199
- draggable && (
200
- < TransformerComponent
201
- focusChild = { focusChild }
202
- rectClass = { 'childRect' }
203
- anchorSize = { 8 }
204
- color = { 'grey' }
205
- />
206
- ) }
231
+ { focusChild && focusChild . childId === childId && draggable && (
232
+ < TransformerComponent
233
+ focusChild = { focusChild }
234
+ rectClass = { 'childRect' }
235
+ anchorSize = { 8 }
236
+ color = { 'grey' }
237
+ />
238
+ ) }
207
239
</ Group >
208
240
) ;
209
241
}
0 commit comments