|
1 | 1 | import getSelectable from './getSelectable.util';
|
2 | 2 | import getColor from './colors.util';
|
3 |
| -import { getSize } from './htmlElements.util.ts'; |
| 3 | +import { getSize } from './htmlElements.util'; |
4 | 4 | import cloneDeep from './cloneDeep';
|
5 |
| -import { ComponentInt, ApplicationStateInt, ChildrenInt, ChildInt, ComponentsInt, PropInt } from './interfaces'; |
| 5 | +import { |
| 6 | + ComponentInt, |
| 7 | + ApplicationStateInt, |
| 8 | + ChildrenInt, |
| 9 | + ChildInt, |
| 10 | + ComponentsInt, |
| 11 | + PropInt, |
| 12 | + PositionInt, |
| 13 | +} from './interfaces'; |
6 | 14 |
|
7 | 15 | const initialComponentState: ComponentInt = {
|
8 | 16 | id: 0,
|
@@ -107,7 +115,12 @@ export const addChild = (
|
107 | 115 | parentComponent = state.components.find(comp => comp.title === title);
|
108 | 116 | }
|
109 | 117 |
|
110 |
| - let htmlElemPosition; |
| 118 | + interface htmlElemPositionInt { |
| 119 | + width: number; |
| 120 | + height: number; |
| 121 | + } |
| 122 | + |
| 123 | + let htmlElemPosition: htmlElemPositionInt = { width: null, height: null }; |
111 | 124 | if (childType === 'HTML') {
|
112 | 125 | htmlElemPosition = getSize(htmlElement);
|
113 | 126 | // if above function doesnt reutn anything, it means html element is not in our database
|
@@ -314,6 +327,7 @@ export const handleTransform = (
|
314 | 327 | return {
|
315 | 328 | ...state,
|
316 | 329 | components,
|
| 330 | + focusChild: newFocusChild, |
317 | 331 | };
|
318 | 332 | };
|
319 | 333 |
|
@@ -533,19 +547,27 @@ export const updateHtmlAttr = (state: ApplicationStateInt, { attr, value }: { at
|
533 | 547 | };
|
534 | 548 | };
|
535 | 549 |
|
536 |
| -export const updateChildrenSort = ( |
537 |
| - state: ApplicationStateInt, |
538 |
| - { newChildrenArray }: { newChildrenArray: ChildrenInt }, |
539 |
| -) => { |
540 |
| - console.log('hello from updateChildrenSort. newChildrenArray: ', newChildrenArray); |
541 |
| - // the new Array has the same data exactly. the array index is the new sort... |
542 |
| - // const modifiedChldrenArray = cloneDeep(state.focusComponent.childrenArray) |
543 |
| - // modifiedChldrenArray.forEach( (child: ChildInt, idx:number, arr:any ) => { |
544 |
| - // console.log(`chidl id:${child.childId} currSort:${child.childSort}`) |
545 |
| - // const newSort = newChildrenArray.findIndex( (newChild:ChildInt) => newChild.childId === child.childId) + 1 ; |
546 |
| - // console.log(`new sort: ${newSort}`) |
547 |
| - // }) |
548 |
| - // console.log('modifiedCHildArrrrrr',modifiedChldrenArray) |
| 550 | +export const updateChildrenSort = (state: ApplicationStateInt, { newSortValues }: { newSortValues: any }) => { |
| 551 | + console.log('hello from updateChildrenSort. newSortValues: ', newSortValues); |
| 552 | + |
| 553 | + // const modifiedChildrenArray:ChildrenInt = JSON.parse(JSON.stringify(state.focusComponent.childrenArray)) ; |
| 554 | + const modifiedChildrenArray: ChildrenInt = cloneDeep(state.focusComponent.childrenArray); |
| 555 | + |
| 556 | + for (let i = 0; i < modifiedChildrenArray.length; i += 1) { |
| 557 | + const currChild = modifiedChildrenArray[i]; |
| 558 | + const currChildId = currChild.childId; |
| 559 | + const newValueObj = newSortValues.find((n: any) => n.childId === currChildId); |
| 560 | + const newSortValue = newValueObj.childSort; |
| 561 | + console.log(` currChildId ${currChildId} currSortValue: ${currChild.childSort} newSortValue:${newSortValue}`); |
| 562 | + currChild.childSort = newSortValue; |
| 563 | + } |
| 564 | + |
| 565 | + const modifiedComponent = state.components.find(comp => comp.id === state.focusComponent.id); |
| 566 | + modifiedComponent.childrenArray = modifiedChildrenArray; |
| 567 | + |
| 568 | + const modifiedComponentsArray = state.components.filter(comp => comp.id !== state.focusComponent.id); |
| 569 | + modifiedComponentsArray.push(modifiedComponent); |
| 570 | + |
549 | 571 | return {
|
550 | 572 | ...state,
|
551 | 573 | components: modifiedComponentsArray,
|
|
0 commit comments