Skip to content

Commit 011a600

Browse files
transformer anchors are always selectable
1 parent e6a79dd commit 011a600

File tree

7 files changed

+103
-51
lines changed

7 files changed

+103
-51
lines changed

src/components/GrandchildRectangle.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ class GrandchildRectangle extends Component {
6464
childComponentId={grandchild.childComponentId}
6565
focusChild={focusChild}
6666
childId={childId}
67-
x={grandchild.position.x * (width / (window.innerWidth / 2))}
67+
x={grandchild.position.x * (width / window.innerWidth)}
6868
y={grandchild.position.y * (height / window.innerHeight)}
69-
scaleX={1}
70-
scaleY={1}
71-
width={grandchild.position.width * (width / (window.innerWidth / 2))}
69+
width={grandchild.position.width * (width / window.innerWidth)}
7270
height={grandchild.position.height * (height / window.innerHeight)}
71+
// x={grandchild.position.x}
72+
// y={grandchild.position.y}
73+
// width={grandchild.position.width}
74+
// height={grandchild.position.height}
7375
/>
7476
))}
7577
</Group>

src/components/KonvaStage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class KonvaStage extends Component {
5151

5252
// find clicked rect by its name
5353
const rectChildId = e.target.attrs.childId;
54-
console.log('user clicked on child rectangle with Id: ', rectChildId);
54+
console.log('user clicked on child rectangle with childId: ', rectChildId);
5555
this.props.changeFocusChild({ childId: rectChildId });
5656
this.props.changeComponentFocusChild({
5757
componentId: this.props.focusComponent.id,

src/components/Rectangle.jsx

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,42 @@ class Rectangle extends Component {
1111
return color;
1212
}
1313

14+
getGrandchildRatio(grandchild) {
15+
// const childInstance = pseudoChildComp.childrenArray.find()
16+
const pseudoParent = this.props.components.find(
17+
comp => comp.title === this.props.childComponentName,
18+
);
19+
const childInstance = pseudoParent.childrenArray.find(
20+
child => child.childId === grandchild.childId,
21+
);
22+
// console.log(
23+
// this.props.childId,
24+
// this.props.componentId,
25+
// this.props.childComponentName,
26+
// this.props.childComponentId,
27+
// );
28+
console.log(grandchild, pseudoParent, childInstance);
29+
// console.log(childInstance.position.width / pseudoParent.position.width);
30+
// console.log(childInstance.position.height / pseudoParent.position.height);
31+
32+
console.log(childInstance.position.x, pseudoParent.position.x);
33+
console.log(childInstance.position.y, pseudoParent.position.y);
34+
const ratioObj = {
35+
// x:
36+
// grandchild.position.x
37+
// - (pseudoParent.position.x * childInstance.position.width) / pseudoParent.position.width,
38+
// y:
39+
// grandchild.position.y
40+
// - (pseudoParent.position.y * childInstance.position.height) / pseudoParent.position.height,
41+
x: childInstance.position.x - pseudoParent.position.x,
42+
y: childInstance.position.y - pseudoParent.position.y,
43+
width: childInstance.position.width / pseudoParent.position.width,
44+
height: childInstance.position.height / pseudoParent.position.height,
45+
};
46+
// console.log('ratioObj', ratioObj);
47+
return ratioObj;
48+
}
49+
1450
handleResize(componentId, childId, target) {
1551
const focChild = this.props.components
1652
.find(comp => comp.id === componentId)
@@ -123,13 +159,19 @@ class Rectangle extends Component {
123159
childComponentName={grandchild.componentName}
124160
childComponentId={grandchild.childComponentId}
125161
focusChild={focusChild}
126-
childId={childId} // scary addition, grandchildren rects should default to childId of "direct" children
127-
x={grandchild.position.x * (width / (window.innerWidth / 2))}
128-
y={grandchild.position.y * (height / window.innerHeight)}
129-
scaleX={1}
130-
scaleY={1}
131-
width={grandchild.position.width * (width / (window.innerWidth / 2))}
132-
height={grandchild.position.height * (height / window.innerHeight)}
162+
childId={childId} // scary addition, grandchildren rects default to childId of "direct" children
163+
// x={grandchild.position.x * (width / window.innerWidth)}
164+
// y={grandchild.position.y * (height / window.innerHeight)}
165+
// width={grandchild.position.width * (width / window.innerWidth)}
166+
// height={grandchild.position.height * (height / window.innerHeight)}
167+
x={this.getGrandchildRatio(grandchild).x}
168+
y={this.getGrandchildRatio(grandchild).y}
169+
width={width * this.getGrandchildRatio(grandchild).width}
170+
height={height * this.getGrandchildRatio(grandchild).height}
171+
// x={grandchild.position.x}
172+
// y={grandchild.position.y}
173+
// width={grandchild.position.width}
174+
// height={grandchild.position.height}
133175
// title={child.componentName + child.childId}
134176
/>
135177
))}

src/components/TransformerComponent.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class TransformerComponent extends Component {
2626
} else {
2727
this.transformer.detach();
2828
}
29+
this.transformer.moveToTop(); // makes sure the transformer is always selectable
2930
this.transformer.getLayer().batchDraw();
3031
}
3132

src/containers/AppContainer.jsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import React, { Component } from "react";
2-
import { connect } from "react-redux";
1+
import React, { Component } from 'react';
2+
import { connect } from 'react-redux';
33
// import PropTypes from 'prop-types';
4-
import { MuiThemeProvider } from "@material-ui/core/styles";
5-
import LinearProgress from "@material-ui/core/LinearProgress";
6-
import LeftContainer from "./LeftContainer.jsx";
7-
import MainContainer from "./MainContainer.jsx";
8-
import RightContainer from "./RightContainer.jsx";
9-
import convertIdsToObjs from "../utils/convertIdsToObjs.util";
10-
import theme from "../components/theme";
11-
import { loadInitData } from "../actions/components";
4+
import { MuiThemeProvider } from '@material-ui/core/styles';
5+
import LinearProgress from '@material-ui/core/LinearProgress';
6+
import LeftContainer from './LeftContainer.jsx';
7+
import MainContainer from './MainContainer.jsx';
8+
import RightContainer from './RightContainer.jsx';
9+
import convertIdsToObjs from '../utils/convertIdsToObjs.util';
10+
import theme from '../components/theme';
11+
import { loadInitData } from '../actions/components';
1212

1313
const mapStateToProps = store => ({
1414
components: store.workspace.components,
1515
totalComponents: store.workspace.totalComponents,
1616
focusComponent: store.workspace.focusComponent,
1717
loading: store.workspace.loading,
18-
selectableChildren: store.workspace.selectableChildren
18+
selectableChildren: store.workspace.selectableChildren,
1919
});
2020

2121
const mapDispatchToProps = { loadInitData };
2222

2323
class AppContainer extends Component {
2424
state = {
2525
width: 25,
26-
rightColumnOpen: true
26+
rightColumnOpen: true,
2727
};
2828

2929
collapseColumn = () => {
3030
if (this.state.width === 25) {
3131
this.setState({
3232
width: 0,
33-
rightColumnOpen: false
33+
rightColumnOpen: false,
3434
});
3535
} else {
3636
this.setState({
3737
width: 25,
38-
rightColumnOpen: true
38+
rightColumnOpen: true,
3939
});
4040
}
4141
};
@@ -46,11 +46,7 @@ class AppContainer extends Component {
4646

4747
render() {
4848
const {
49-
components,
50-
totalComponents,
51-
focusComponent,
52-
loading,
53-
selectableChildren
49+
components, totalComponents, focusComponent, loading, selectableChildren,
5450
} = this.props;
5551
const { width, rightColumnOpen } = this.state;
5652

@@ -82,9 +78,9 @@ class AppContainer extends Component {
8278
{loading ? (
8379
<div
8480
style={{
85-
alignSelf: "flex-end",
86-
position: "fixed",
87-
width: "100%"
81+
alignSelf: 'flex-end',
82+
position: 'fixed',
83+
width: '100%',
8884
}}
8985
>
9086
<LinearProgress color="secondary" />
@@ -98,7 +94,7 @@ class AppContainer extends Component {
9894

9995
export default connect(
10096
mapStateToProps,
101-
mapDispatchToProps
97+
mapDispatchToProps,
10298
)(AppContainer);
10399

104100
// AppContainer.propTypes = {

src/reducers/componentReducer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ const appComponent = {
7878
props: [],
7979
nextPropId: 1,
8080
position: {
81-
x: 110,
82-
y: 120,
83-
width: 50,
84-
height: 50,
81+
x: 25,
82+
y: 25,
83+
width: 600,
84+
height: 400,
8585
},
8686

8787
childrenArray: [],
@@ -102,10 +102,10 @@ const initialApplicationState = {
102102
childId: 0,
103103
componentName: null,
104104
position: {
105-
x: 110,
106-
y: 120,
107-
width: 50,
108-
height: 50,
105+
x: 25,
106+
y: 25,
107+
width: 600,
108+
height: 400,
109109
},
110110
draggable: true,
111111
},

src/utils/componentReducer.util.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ export const addChild = (state, { title }) => {
103103
childComponentId: parentComponent.id,
104104
componentName: strippedTitle,
105105
position: {
106-
x: 110 + view.nextChildId * 5,
107-
y: 120 + view.nextChildId * 5,
108-
width: 50,
109-
height: 50,
106+
x: parentComponent.position.x + view.nextChildId * 5, // new children are offset by 5px, x and y
107+
y: parentComponent.position.y + view.nextChildId * 5,
108+
width: parentComponent.position.width * 0.9, // new children have an initial position of their parentComponent (maybe don't need 90%)
109+
height: parentComponent.position.height * 0.9,
110110
},
111111
draggable: true,
112112
color: parentComponent.color,
@@ -214,10 +214,21 @@ export const handleTransform = (state, {
214214
transformedChild,
215215
];
216216

217-
const component = {
218-
...state.components.find(comp => comp.id === componentId),
219-
childrenArray: children,
220-
};
217+
let component;
218+
if (childId === '-1') {
219+
console.log('pseudo');
220+
component = {
221+
...state.components.find(comp => comp.id === componentId),
222+
childrenArray: children,
223+
position: { ...transformedChild.position },
224+
};
225+
} else {
226+
console.log('real');
227+
component = {
228+
...state.components.find(comp => comp.id === componentId),
229+
childrenArray: children,
230+
};
231+
}
221232

222233
const components = [
223234
...state.components.filter((comp) => {

0 commit comments

Comments
 (0)