@@ -4,6 +4,7 @@ import Rectangle from './Rectangle.tsx';
4
4
import { cloneDeep } from '../utils/index.util' ;
5
5
import { ComponentInt , ComponentsInt , ChildInt } from '../utils/interfaces.ts' ;
6
6
7
+ //Props are intended to totally describe configuration of a single Rectangle
7
8
interface PropsInt {
8
9
components : ComponentsInt ;
9
10
focusComponent : ComponentInt ;
@@ -43,14 +44,20 @@ class KonvaStage extends Component<PropsInt, StateInt> {
43
44
}
44
45
45
46
getDirectChildrenCopy ( focusComponent : ComponentInt ) {
47
+ //Finds the component currently selected by the user
46
48
const component = this . props . components . find (
47
49
( comp : ComponentInt ) => comp . id === focusComponent . id ,
48
50
) ;
49
-
51
+ // Removes the pseudoChild from the array
50
52
const childrenArr = component . children . filter ( ( child : ChildInt ) => child . childId !== - 1 ) ;
51
-
53
+
54
+ //childrenArr is a different array than component children
55
+ //However, it may have nested references (to original component.children array)
56
+ //Therefore, a deep copy is necessary to ensure that state is not accidentally mutated
52
57
let childrenArrCopy = cloneDeep ( childrenArr ) ;
53
-
58
+
59
+ //pseudoChild is a convenience object; other than its childID, it is a copy of the parent
60
+ //Not intended to be rendered
54
61
const pseudoChild = {
55
62
childId : - 1 ,
56
63
childComponentId : component . id ,
@@ -99,7 +106,9 @@ class KonvaStage extends Component<PropsInt, StateInt> {
99
106
this . props . deleteChild ( { } ) ;
100
107
}
101
108
} ;
102
-
109
+ //Handles a user click event on the Konva Stage (see line 199)
110
+ //Changes the focusChild of the selected component
111
+ //The focusChild's props may be changed in the right tab
103
112
handleStageMouseDown = ( e : any ) => {
104
113
// clicked on stage - clear selection
105
114
if ( e . target === e . target . getStage ( ) ) {
@@ -111,7 +120,7 @@ class KonvaStage extends Component<PropsInt, StateInt> {
111
120
return ;
112
121
}
113
122
114
- // find clicked rect by its name
123
+ // find clicked rect by its childId
115
124
const rectChildId = e . target . attrs . childId ;
116
125
// console.log("user clicked on child rectangle with childId: ", rectChildId);
117
126
this . props . changeFocusChild ( { childId : rectChildId } ) ;
@@ -121,6 +130,9 @@ class KonvaStage extends Component<PropsInt, StateInt> {
121
130
} ) ;
122
131
} ;
123
132
133
+ //Generates an array of Konva Line components (vertical and horizontal) spaced by blockSnapSize pixels
134
+ //Rectangle components are aligned to this grid
135
+ //blockSnapSize is used elsewhere to snap same to nearest grid line
124
136
createGrid = ( ) => {
125
137
const output = [ ] ;
126
138
for ( let i = 0 ; i < this . state . stageWidth / this . state . blockSnapSize ; i ++ ) {
@@ -195,6 +207,9 @@ class KonvaStage extends Component<PropsInt, StateInt> {
195
207
} }
196
208
>
197
209
{ this . state . grid }
210
+ { // Given the current focusComponent (selected by clicking in LeftContainer),
211
+ // the below code maps over its children and renders a Rectangle component for each
212
+ }
198
213
{ this . getDirectChildrenCopy ( focusComponent )
199
214
. map ( ( child : ChildInt , i : number ) => (
200
215
< Rectangle
0 commit comments