Skip to content

Commit f4d0b9f

Browse files
better recursive rendering, size is relative to canvas size. Shoube redesigned from canvas/component perspective
1 parent 9b0dc2b commit f4d0b9f

File tree

4 files changed

+48
-52
lines changed

4 files changed

+48
-52
lines changed

src/actions/components.js

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,54 @@ import {
2525
DELETE_PROP,
2626
ADD_PROP,
2727
DELETE_ALL_DATA,
28-
CHANGE_IMAGE_PATH
29-
} from "../actionTypes/index";
28+
CHANGE_IMAGE_PATH,
29+
} from '../actionTypes/index';
3030

31-
import { loadState } from "../localStorage";
31+
import { loadState } from '../localStorage';
3232

3333
// import createFiles from '../utils/createFiles.util';
3434
// import createApplicationUtil from '../utils/createApplication.util';
3535

36-
export const loadInitData = () => dispatch => {
37-
loadState().then(data =>
38-
dispatch({
39-
type: LOAD_INIT_DATA,
40-
payload: {
41-
data: data ? data.workspace : {}
42-
}
43-
})
44-
);
36+
export const loadInitData = () => (dispatch) => {
37+
loadState().then(data => dispatch({
38+
type: LOAD_INIT_DATA,
39+
payload: {
40+
data: data ? data.workspace : {},
41+
},
42+
}));
4543
};
4644

4745
export const updateChildren = ({ parentIds, childIndex, childId }) => ({
4846
type: UPDATE_CHILDREN,
4947
payload: {
5048
parentIds,
5149
childIndex,
52-
childId
53-
}
50+
childId,
51+
},
5452
});
5553

5654
export const parentReassignment = ({ index, id, parentIds }) => ({
5755
type: REASSIGN_PARENT,
5856
payload: {
5957
index,
6058
id,
61-
parentIds
62-
}
59+
parentIds,
60+
},
6361
});
6462

65-
export const addComponent = ({ title }) => dispatch => {
63+
export const addComponent = ({ title }) => (dispatch) => {
6664
dispatch({ type: ADD_COMPONENT, payload: { title } });
6765
};
6866

69-
export const addChild = ({ title }) => dispatch => {
67+
export const addChild = ({ title }) => (dispatch) => {
7068
dispatch({ type: ADD_CHILD, payload: { title } });
7169
};
7270

73-
export const deleteChild = ({ title }) => dispatch => {
71+
export const deleteChild = ({ title }) => (dispatch) => {
7472
dispatch({ type: DELETE_CHILD, payload: { title } });
7573
};
7674

77-
export const deleteComponent = ({ index, id, parentIds = [] }) => dispatch => {
75+
export const deleteComponent = ({ index, id, parentIds = [] }) => (dispatch) => {
7876
if (parentIds.length) {
7977
// Delete Component from its parent if it has a parent.
8078
dispatch(updateChildren({ parentIds, childId: id, childIndex: index }));
@@ -91,38 +89,38 @@ export const updateComponent = ({
9189
index,
9290
newParentId = null,
9391
color = null,
94-
stateful = null
95-
}) => dispatch => {
92+
stateful = null,
93+
}) => (dispatch) => {
9694
dispatch({
9795
type: UPDATE_COMPONENT,
9896
payload: {
9997
id,
10098
index,
10199
newParentId,
102100
color,
103-
stateful
104-
}
101+
stateful,
102+
},
105103
});
106104

107105
if (newParentId) {
108106
dispatch(
109107
updateChildren({
110108
parentIds: [newParentId],
111109
childId: id,
112-
childIndex: index
113-
})
110+
childIndex: index,
111+
}),
114112
);
115113
}
116114

117115
dispatch({ type: SET_SELECTABLE_PARENTS });
118116
};
119117

120-
export const changeFocusComponent = ({ title }) => dispatch => {
118+
export const changeFocusComponent = ({ title }) => (dispatch) => {
121119
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
122120
};
123121

124122
// make sure childId is being sent in
125-
export const changeFocusChild = ({ title, childId }) => dispatch => {
123+
export const changeFocusChild = ({ title, childId }) => (dispatch) => {
126124
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
127125
};
128126

@@ -144,23 +142,21 @@ export const changeFocusChild = ({ title, childId }) => dispatch => {
144142

145143
export const handleClose = () => ({
146144
type: HANDLE_CLOSE,
147-
payload: false
145+
payload: false,
148146
});
149147

150-
export const handleTransform = (
151-
componentId,
152-
childId,
153-
{ x, y, width, height }
154-
) => ({
148+
export const handleTransform = (componentId, childId, {
149+
x, y, width, height,
150+
}) => ({
155151
type: HANDLE_TRANSFORM,
156152
payload: {
157153
componentId,
158154
childId,
159155
x,
160156
y,
161157
width,
162-
height
163-
}
158+
height,
159+
},
164160
});
165161

166162
// export const createApplication = ({
@@ -190,7 +186,7 @@ export const handleTransform = (
190186

191187
export const toggleDragging = status => ({
192188
type: TOGGLE_DRAGGING,
193-
payload: status
189+
payload: status,
194190
});
195191

196192
// export const moveToBottom = componentId => ({
@@ -205,7 +201,7 @@ export const toggleDragging = status => ({
205201

206202
export const openExpansionPanel = component => ({
207203
type: OPEN_EXPANSION_PANEL,
208-
payload: { component }
204+
payload: { component },
209205
});
210206

211207
// export const deleteAllData = () => ({

src/components/GrandchildRectangle.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class GrandchildRectangle extends Component {
6161
componentName={grandchild.componentName}
6262
focusChild={focusChild}
6363
// childId={grandchild.childId}
64-
x={grandchild.position.x}
65-
y={grandchild.position.y}
66-
scaleX={0.8}
67-
scaleY={0.8}
68-
width={grandchild.position.width}
69-
height={grandchild.position.height}
64+
x={grandchild.position.x * (width / (window.innerWidth / 2))}
65+
y={grandchild.position.y * (height / window.innerHeight)}
66+
scaleX={1}
67+
scaleY={1}
68+
width={grandchild.position.width * (width / (window.innerWidth / 2))}
69+
height={grandchild.position.height * (height / window.innerHeight)}
7070
color={color}
7171
/>
7272
))}

src/components/KonvaStage.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class KonvaStage extends Component {
2222
// // clicked on stage - clear selection
2323
if (e.target === e.target.getStage()) {
2424
// add functionality for allowing no focusChild
25-
console.log(e.target.getStage(), this.main, this.group);
25+
console.log(e.target.getStage());
2626
return;
2727
}
2828
// // clicked on transformer - do nothing
@@ -61,7 +61,7 @@ class KonvaStage extends Component {
6161
// this.stage = node;
6262
// }}
6363
onMouseDown={this.handleStageMouseDown}
64-
width={window.innerWidth}
64+
width={window.innerWidth / 2}
6565
height={window.innerHeight}
6666
>
6767
<Layer>

src/components/Rectangle.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ class Rectangle extends Component {
105105
componentName={grandchild.componentName}
106106
focusChild={focusChild}
107107
// childId={childId}
108-
x={grandchild.position.x * 0.8 + 10}
109-
y={grandchild.position.y * 0.8 + 10}
110-
scaleX={0.8}
111-
scaleY={0.8}
112-
width={grandchild.position.width}
113-
height={grandchild.position.height}
108+
x={grandchild.position.x * (width / (window.innerWidth / 2))}
109+
y={grandchild.position.y * (height / (window.innerHeight))}
110+
scaleX={1}
111+
scaleY={1}
112+
width={grandchild.position.width * (width / (window.innerWidth / 2))}
113+
height={grandchild.position.height * (height / (window.innerHeight))}
114114
// title={child.componentName + child.childId}
115115
color={color}
116116
draggable={false}

0 commit comments

Comments
 (0)