@@ -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,16 +64,25 @@ 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
66
77
this . props . handleTransform ( componentId , childId , transformation ) ;
67
78
}
68
79
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
+ ) {
70
86
const transformation = {
71
87
x : Math . round ( target . x ( ) / blockSnapSize ) * blockSnapSize ,
72
88
y : Math . round ( target . y ( ) / blockSnapSize ) * blockSnapSize
@@ -114,18 +130,20 @@ class Rectangle extends Component<PropsInt, StateInt> {
114
130
scaleY = { scaleY }
115
131
width = { width }
116
132
height = { height }
117
- onDragEnd = { event => this . handleDrag ( componentId , childId , event . target , blockSnapSize ) }
133
+ onDragEnd = { event =>
134
+ this . handleDrag ( componentId , childId , event . target , blockSnapSize )
135
+ }
118
136
ref = { node => {
119
137
this . group = node ;
120
138
} }
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
122
140
>
123
141
< Rect
124
142
// a Konva Rect is generated for each child of the focusComponent (including the pseudochild, representing the focusComponent itself)
125
143
ref = { node => {
126
144
this . rect = node ;
127
145
} }
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
129
147
name = { `${ childId } ` }
130
148
className = { 'childRect' }
131
149
x = { 0 }
@@ -137,7 +155,11 @@ class Rectangle extends Component<PropsInt, StateInt> {
137
155
scaleY = { 1 }
138
156
width = { width }
139
157
height = { height }
140
- stroke = { childType === 'COMP' ? this . getComponentColor ( childComponentId ) : '#000000' }
158
+ stroke = {
159
+ childType === 'COMP'
160
+ ? this . getComponentColor ( childComponentId )
161
+ : '#000000'
162
+ }
141
163
onTransformEnd = { event =>
142
164
this . handleResize ( componentId , childId , event . target , blockSnapSize )
143
165
}
@@ -146,17 +168,28 @@ class Rectangle extends Component<PropsInt, StateInt> {
146
168
draggable = { false }
147
169
fill = { childId === - 1 ? 'white' : null }
148
170
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
152
181
/>
153
182
< Label >
154
183
< Text
155
184
fontStyle = { 'bold' }
156
185
fontVariant = { 'small-caps' }
157
186
// pseudochild's label should look different than normal children:
158
187
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
+ }
160
193
fontSize = { childId === - 1 ? 15 : 10 }
161
194
x = { 4 }
162
195
y = { childId === - 1 ? - 20 : - 12 }
@@ -175,14 +208,20 @@ class Rectangle extends Component<PropsInt, StateInt> {
175
208
componentId = { componentId }
176
209
directParentName = { childComponentName }
177
210
childType = { grandchild . childType }
178
- imageSource = { grandchild . htmlElement === 'Image' && grandchild . HTMLInfo . Src }
211
+ imageSource = {
212
+ grandchild . htmlElement === 'Image' && grandchild . HTMLInfo . Src
213
+ }
179
214
childComponentName = { grandchild . componentName }
180
215
childComponentId = { grandchild . childComponentId }
181
216
focusChild = { focusChild }
182
217
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
+ }
184
222
height = {
185
- grandchild . position . height * ( height / this . getPseudoChild ( ) . position . height )
223
+ grandchild . position . height *
224
+ ( height / this . getPseudoChild ( ) . position . height )
186
225
}
187
226
x = {
188
227
( grandchild . position . x - this . getPseudoChild ( ) . position . x ) *
@@ -194,16 +233,14 @@ class Rectangle extends Component<PropsInt, StateInt> {
194
233
}
195
234
/>
196
235
) ) }
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
+ ) }
207
244
</ Group >
208
245
) ;
209
246
}
0 commit comments