Skip to content

Commit 31e25db

Browse files
Merge pull request #98 from ChristianEdwardPadilla/development
image src scaling correctly, html attr set snapback bug fix
2 parents 6ee24f3 + 5ffb035 commit 31e25db

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

src/components/KonvaStage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class KonvaStage extends Component {
1010
constructor(props) {
1111
super(props);
1212
this.state = {
13-
stageWidth: 1500,
13+
stageWidth: 1800,
1414
stageHeight: 1500,
1515
blockSnapSize: 10,
1616
grid: [],
@@ -47,13 +47,13 @@ class KonvaStage extends Component {
4747
// here we should add listener for "container" resize
4848
// take a look here https://developers.google.com/web/updates/2016/10/resizeobserver
4949
// for simplicity I will just listen window resize
50-
// window.addEventListener('resize', this.checkSize);
50+
window.addEventListener('resize', this.checkSize);
5151
this.container.addEventListener('keydown', this.handleKeyDown);
5252
this.createGrid();
5353
}
5454

5555
componentWillUnmount() {
56-
// window.removeEventListener('resize', this.checkSize);
56+
window.removeEventListener('resize', this.checkSize);
5757
this.container.removeEventListener('keydown', this.handleKeyDown);
5858
}
5959

src/utils/Interfaces.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ChildInt {
2222
position: PositionInt;
2323
color: string | null; // maybe optional instead, look up null vs undefined
2424
htmlElement: string | null; // maybe should be optional instead
25-
HTMLInfo: object; // replace with HTMLinfo specifics
25+
HTMLInfo: { [index: string]: { info: any } }; // replace with HTMLinfo specifics
2626
}
2727

2828
export interface ChildrenInt extends Array<ChildInt> {}
@@ -48,8 +48,8 @@ export interface ApplicationStateInt {
4848
successOpen: boolean;
4949
errorOpen: boolean;
5050
focusComponent: ComponentInt;
51-
selectableChildren: Array<number>;
52-
ancestors: Array<number>;
51+
selectableChildren: number[];
52+
ancestors: number[];
5353
initialApplicationFocusChild: ChildInt;
5454
focusChild: ChildInt;
5555
components: ComponentsInt;

src/utils/componentReducer.util.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import getSelectable from './getSelectable.util';
22
import getColor from './colors.util';
3-
import { getSize } from './htmlElements.util.ts';
3+
import { getSize } from './htmlElements.util';
44
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';
614

715
const initialComponentState: ComponentInt = {
816
id: 0,
@@ -107,7 +115,12 @@ export const addChild = (
107115
parentComponent = state.components.find(comp => comp.title === title);
108116
}
109117

110-
let htmlElemPosition;
118+
interface htmlElemPositionInt {
119+
width: number;
120+
height: number;
121+
}
122+
123+
let htmlElemPosition: htmlElemPositionInt = { width: null, height: null };
111124
if (childType === 'HTML') {
112125
htmlElemPosition = getSize(htmlElement);
113126
// if above function doesnt reutn anything, it means html element is not in our database
@@ -314,6 +327,7 @@ export const handleTransform = (
314327
return {
315328
...state,
316329
components,
330+
focusChild: newFocusChild,
317331
};
318332
};
319333

@@ -533,19 +547,27 @@ export const updateHtmlAttr = (state: ApplicationStateInt, { attr, value }: { at
533547
};
534548
};
535549

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+
549571
return {
550572
...state,
551573
components: modifiedComponentsArray,

src/utils/componentRender.util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ const componentRender = (component: ComponentInt, components: ComponentsInt) =>
145145
return (
146146
<div>
147147
${cloneDeep(childrenArray)
148-
.sort((a, b) => a.childSort - b.childSort)
149-
.map(child => `<${componentNameGenerator(child)} ${propDrillTextGenerator(child)}/>`)
148+
.sort((a: ChildInt, b: ChildInt) => a.childSort - b.childSort)
149+
.map((child: ChildInt) => `<${componentNameGenerator(child)} ${propDrillTextGenerator(child)}/>`)
150150
.join('\n')}
151151
</div>
152152
);

0 commit comments

Comments
 (0)