@@ -29,30 +29,53 @@ interface PropsInt {
29
29
30
30
31
31
class Rectangle extends Component < PropsInt > {
32
-
32
+ //This assigns the color to the Rect based on componentId's color in the state
33
33
getComponentColor ( componentId : number ) {
34
34
const color = this . props . components . find (
35
35
( comp : ComponentInt ) => comp . id === componentId
36
36
) . color ;
37
37
return color ;
38
38
}
39
39
40
+ //this grabs the component ID of the child component when in the parent component's display mode
41
+ //mysteriously name pseudochild although it is the true child of the component currently rendered on the stage...
42
+ //maybe some poeple don't consider children to be real children, kind of how my grandmother treated me better than
43
+ //she treated my mother
40
44
getPseudoChild ( ) {
41
45
return this . props . components . find (
42
46
( comp : ComponentInt ) => comp . id === this . props . childComponentId
43
47
) ;
44
48
}
45
49
50
+ //resize function
46
51
handleResize ( componentId : number , childId : number , target : Konva . Group , blockSnapSize : number ) {
52
+ //find the id of the component where the componentID in the state equals the currently focused component
53
+ //and then find the numberID for that component
54
+ //So, this would be assigning "Container 1", with component ID being whatever the ID for "Container" is
55
+ //and 1 being the child ID
47
56
let focChild : ChildInt | ComponentInt = this . props . components
48
57
. find ( ( comp : ComponentInt ) => comp . id === this . props . componentId )
49
58
. childrenArray . find ( ( child : ChildInt ) => child . childId === childId ) ;
50
59
60
+ //If this is the parent component, it would not have a childID (hence -1), so it just would assign the forChild
61
+ //variable to the parent.
51
62
if ( childId === - 1 ) {
52
63
focChild = this . props . components . find (
53
64
( comp : ComponentInt ) => comp . id === this . props . componentId
54
65
) ;
55
66
}
67
+
68
+ //The math here is easier than it looks
69
+ //Basically, the height and width is first rounded up to a whole number (behind the whole snapping phenomenon)
70
+ //after scaling it by multiplying it by scaleX/Y (height and width are the original height and width, the scale is the CHANGE in w/h),
71
+ //dividing it by the 'snapsize' or grid unit area (which is 10x10 for this entire application) and re-multiplied by
72
+ //that same snapsize. I'm not entirely sure why this had to be divided before the rounding, and re-multiplied,
73
+ //since having positions that aren't a whole number doesn't seem to be that big of a deal.
74
+
75
+ //So there's a bit of redundancy in the x and y info. target.x() or y() only log the CHANGE of position of the Rect component.
76
+ //Since when you change the width or height of the component you do not change the actual position, the
77
+ //value for x an y dispatched to the action creator will always be the same as the current x,y position, unless you can somehow
78
+ //resize AND reposition at the same time.
56
79
const transformation = {
57
80
width :
58
81
Math . round ( ( target . width ( ) * target . scaleX ( ) ) / blockSnapSize ) *
@@ -66,6 +89,8 @@ class Rectangle extends Component<PropsInt> {
66
89
this . props . handleTransform ( componentId , childId , transformation ) ;
67
90
}
68
91
92
+ //mostly the same logic as above, just grabbing the change in position for the focused child and sending it
93
+ //to the action creator.
69
94
handleDrag ( componentId : number , childId : number , target : Konva . Group , blockSnapSize : number ) {
70
95
const transformation = {
71
96
x : Math . round ( target . x ( ) / blockSnapSize ) * blockSnapSize ,
@@ -108,15 +133,15 @@ class Rectangle extends Component<PropsInt> {
108
133
onDragEnd = { event =>
109
134
this . handleDrag ( componentId , childId , event . target , blockSnapSize )
110
135
}
111
- ref = { node => {
136
+ ref = { node => { //this refference actually isn't doing anything since it isn't within the transformer component
112
137
this . group = node ;
113
138
} }
114
139
tabIndex = '0' // required for keypress event to be heard by this.group
115
140
>
116
- < Rect
141
+ < Rect //basically the entire canvas
117
142
// a Konva Rect is generated for each child of the focusComponent (including the pseudochild, representing the focusComponent itself)
118
143
ref = { node => {
119
- this . rect = node ;
144
+ this . rect = node ; //same as above, the reference isn't assigned or pointing to anything
120
145
} }
121
146
tabIndex = '0' // required for keypress event to be heard by this.group
122
147
name = { `${ childId } ` }
@@ -133,45 +158,45 @@ class Rectangle extends Component<PropsInt> {
133
158
stroke = {
134
159
childType === 'COMP'
135
160
? this . getComponentColor ( childComponentId )
136
- : '#000000'
161
+ : '#000000' //sets the parent component color to black, this logic actually doesn't need to exist at the level of this component
137
162
}
138
163
onTransformEnd = { event =>
139
164
this . handleResize ( componentId , childId , event . target , blockSnapSize )
140
165
}
141
- strokeWidth = { childType === 'COMP' ? 4 : 2 }
166
+ strokeWidth = { childType === 'COMP' ? 4 : 2 }
142
167
strokeScaleEnabled = { false }
143
168
draggable = { false }
144
169
fill = { null }
145
170
shadowBlur = { childId === - 1 ? 6 : null }
146
171
fillPatternImage = { childId === - 1 ? this . props . image : null } //spooky addition, image if uploaded will only be background of App component
147
- fillPatternScaleX = { this . props . image ? width / this . props . image . width : 1 }
148
- fillPatternScaleY = { this . props . image ? height / this . props . image . height : 1 }
172
+ fillPatternScaleX = { this . props . image ? width / this . props . image . width : 1 } //here we are making sure the width of the image will stretch of shrink
173
+ fillPatternScaleY = { this . props . image ? height / this . props . image . height : 1 } //based on the width or height of the App component
149
174
_useStrictMode
150
175
/>
151
176
< Label >
152
- < Text
177
+ < Text //this is just the text that goes above each Rect,
153
178
fontStyle = { 'bold' }
154
179
fontVariant = { 'small-caps' }
155
180
// pseudochild's label should look different than normal children:
156
- text = { childId === - 1 ? title . slice ( 0 , title . length - 2 ) : title }
181
+ text = { childId === - 1 ? title . slice ( 0 , title . length - 2 ) : title } //slices the number off of the title of the top component
157
182
fill = {
158
183
childId === - 1
159
184
? this . getComponentColor ( childComponentId )
160
- : '#000000'
185
+ : '#000000' //opposite logic of the stroke
161
186
}
162
187
fontSize = { childId === - 1 ? 15 : 10 }
163
188
x = { 4 }
164
189
y = { childId === - 1 ? - 20 : - 12 }
165
190
/>
166
191
</ Label >
167
192
{ // for all children other than the pseudoChild, find their component's children array and recursively render the children found there
168
- childId !== - 1 &&
169
- childType === 'COMP' &&
170
- components
193
+ childId !== - 1 && //inline conditional to check if a child exists
194
+ childType === 'COMP' && //inline conditional to see if the child is a component, not an HTML element
195
+ components //map all 'grandchildren' in the child on display to this new component
171
196
. find ( ( comp : ComponentInt ) => comp . title === childComponentName )
172
197
. childrenArray . filter ( ( child : ChildInt ) => child . childId !== - 1 )
173
198
. map ( ( grandchild : ChildInt , i : number ) => (
174
- < GrandchildRectangle
199
+ < GrandchildRectangle
175
200
key = { i }
176
201
components = { components }
177
202
componentId = { componentId }
@@ -181,15 +206,15 @@ class Rectangle extends Component<PropsInt> {
181
206
childComponentId = { grandchild . childComponentId }
182
207
focusChild = { focusChild }
183
208
childId = { childId } // scary addition, grandchildren rects default to childId of "direct" children
184
- width = {
209
+ width = { //this is the logic used to display the grandchildren with proper scaling based on the parent (technically child) h/w
185
210
grandchild . position . width *
186
211
( width / this . getPseudoChild ( ) . position . width )
187
212
}
188
213
height = {
189
214
grandchild . position . height *
190
215
( height / this . getPseudoChild ( ) . position . height )
191
216
}
192
- x = {
217
+ x = { //similar logic to above
193
218
( grandchild . position . x - this . getPseudoChild ( ) . position . x ) *
194
219
( width / this . getPseudoChild ( ) . position . width )
195
220
}
@@ -199,7 +224,7 @@ class Rectangle extends Component<PropsInt> {
199
224
}
200
225
/>
201
226
) ) }
202
- { focusChild && focusChild . childId === childId && draggable && (
227
+ { focusChild && focusChild . childId === childId && draggable && ( //this conditional logic binds the transformer to the focused child, and Draggable is checked to make sure grandchildren can't be selected
203
228
< TransformerComponent //This is the component that binds the Rect nodes to the Transformer node so they can be resized.
204
229
focusChild = { focusChild }
205
230
rectClass = { 'childRect' }
0 commit comments