1
1
//import setSelectableParents from "./setSelectableParents.util";
2
2
import getSelectable from "./getSelectable.util" ;
3
3
import getColor from "./colors.util" ;
4
+ import { HTMLelements , getSize } from "../utils/htmlElements.util" ;
4
5
5
6
const initialComponentState = {
6
7
id : null ,
7
8
stateful : false ,
8
9
title : "" ,
9
10
parentIds : [ ] ,
10
11
color : getColor ( ) ,
11
- draggable : true ,
12
+ // draggable: true,
12
13
childrenIds : [ ] ,
13
14
selectableParents : [ ] ,
14
15
expanded : true ,
@@ -51,7 +52,7 @@ export const addComponent = (state, { title }) => {
51
52
width : 600 ,
52
53
height : 400
53
54
} ,
54
- draggable : true ,
55
+ // draggable: true,
55
56
color : componentColor ,
56
57
childType : "COMP"
57
58
} ;
@@ -95,8 +96,7 @@ export const addComponent = (state, { title }) => {
95
96
// get the focus component (aka the component were adding the child to)
96
97
97
98
export const addChild = ( state , { title, childType = "" , HTMLInfo = { } } ) => {
98
- console . log ( HTMLInfo ) ;
99
-
99
+
100
100
let strippedTitle = title ;
101
101
102
102
if ( ! childType ) {
@@ -126,34 +126,30 @@ export const addChild = (state, { title, childType = "", HTMLInfo = {} }) => {
126
126
console . log ( "inside if statement" ) ;
127
127
}
128
128
129
- // } else if (childType !== "COMP") {
130
-
131
- // console.log("inside else statement");
132
- // parentComponent = {
133
- // id: "888",
134
- // position: {
135
- // x: 25,
136
- // y: 25,
137
- // width: 600,
138
- // height: 400
139
- // },
140
- // color: "#000000"
141
- // };
142
- // }
129
+ let htmlElemPosition ;
130
+ if ( childType == 'HTML' ) {
131
+ htmlElemPosition = getSize ( htmlElement )
132
+ // if above function doesnt reutn anything, it means html element is not in our database
133
+ if ( ! htmlElemPosition . width ) {
134
+ console . log ( `Did not add html child: ${ htmlElement } the GetSize function indicated that it isnt in our DB` )
135
+ return ;
136
+ }
137
+ console . log ( `htmlElemPosition: ${ JSON . stringify ( htmlElemPosition ) } ` )
138
+ }
143
139
144
140
const newPosition =
145
141
childType === "COMP"
146
142
? {
147
- x : parentComponent . position . x + view . nextChildId * 5 , // new children are offset by 5px, x and y
148
- y : parentComponent . position . y + view . nextChildId * 5 ,
149
- width : parentComponent . position . width * 0.9 , // new children have an initial position of their parentComponent (maybe don't need 90%)
143
+ x : view . position . x + view . nextChildId * 5 , // new children are offset by 5px, x and y
144
+ y : view . position . y + view . nextChildId * 5 ,
145
+ width : parentComponent . position . width * 0.9 , // new children have an initial position of their CLASS (maybe don't need 90%)
150
146
height : parentComponent . position . height * 0.9
151
147
}
152
148
: {
153
- x : 25 + view . nextChildId * 5 ,
154
- y : 25 + view . nextChildId * 5 ,
155
- width : 600 * 0.9 ,
156
- height : 400 * 0.9
149
+ x : view . position . x + view . nextChildId * 5 ,
150
+ y : view . position . y + view . nextChildId * 5 ,
151
+ width : htmlElemPosition . width ,
152
+ height : htmlElemPosition . height
157
153
} ;
158
154
159
155
const newChild = {
@@ -162,7 +158,7 @@ export const addChild = (state, { title, childType = "", HTMLInfo = {} }) => {
162
158
childComponentId : childType == "COMP" ? parentComponent . id : null , // only relevant fot children of type COMPONENT
163
159
componentName : strippedTitle ,
164
160
position : newPosition ,
165
- draggable : true ,
161
+ // draggable: true,
166
162
color : null , // parentComponent.color, // only relevant fot children of type COMPONENT
167
163
htmlElement : htmlElement , // only relevant fot children of type HTML
168
164
HTMLInfo : HTMLInfo
0 commit comments