Skip to content

Commit 6aa975a

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
trying to pull
2 parents 1f9807b + 699832f commit 6aa975a

File tree

9 files changed

+152
-124
lines changed

9 files changed

+152
-124
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { Component, Fragment } from 'react';
2+
import { Rect } from 'react-konva';
3+
// import PropTypes from 'prop-types';
4+
5+
class GrandchildRectangle extends Component {
6+
render() {
7+
return <Rect />;
8+
}
9+
}
10+
11+
export default GrandchildRectangle;

src/components/KonvaStage.jsx

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { Component, createRef } from "react";
1+
import React, { Component, createRef, Fragment } from "react";
22
// import PropTypes from 'prop-types';
3-
import { Stage, Layer, Image, Group } from "react-konva";
3+
import { Stage, Layer, Group, Label, Text } from "react-konva";
44
import TransformerComponent from "./TransformerComponent.jsx";
55
import Rectangle from "./Rectangle.jsx";
66

@@ -63,38 +63,26 @@ class KonvaStage extends Component {
6363
height={window.innerHeight}
6464
>
6565
<Layer>
66-
<Group
67-
scaleX={scaleX}
68-
scaleY={scaleY}
69-
ref={node => {
70-
this.group = node;
71-
}}
72-
draggable={draggable}
73-
>
74-
{components
75-
.find(comp => comp.title === focusComponent.title)
76-
.childrenArray.map((child, i) => (
77-
<Rectangle
78-
draggable={child.draggable}
79-
selectedShapeName={selectedShapeName}
80-
key={`${i}${child.componentName}`}
81-
childId={child.childId}
82-
componentId={focusComponent.id}
83-
x={child.position.x}
84-
y={child.position.y}
85-
width={child.position.width}
86-
height={child.position.height}
87-
title={child.childId + child.componentName}
88-
color={child.color}
89-
handleTransform={handleTransform}
90-
/>
91-
))}
92-
<TransformerComponent
93-
focusComponent={focusComponent}
94-
focusChild={focusChild}
95-
selectedShapeName={selectedShapeName}
96-
/>
97-
</Group>
66+
{components
67+
.find(comp => comp.title === focusComponent.title)
68+
.childrenArray.map((child, i) => (
69+
<Rectangle
70+
key={`${i}${child.componentName}`}
71+
draggable={false}
72+
selectedShapeName={selectedShapeName}
73+
childId={child.childId}
74+
focusChild={focusChild}
75+
focusComponent={focusComponent}
76+
componentId={focusComponent.id}
77+
x={child.position.x}
78+
y={child.position.y}
79+
width={child.position.width}
80+
height={child.position.height}
81+
title={child.componentName + child.childId}
82+
color={child.color}
83+
handleTransform={handleTransform}
84+
/>
85+
))}
9886
</Layer>
9987
</Stage>
10088
);

src/components/LeftColExpansionPanel.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const LeftColExpansionPanel = (props) => {
3333
return focusComponent.title === title ? 'focused' : '';
3434
}
3535

36-
function isAncestor() {
36+
function isAncestorOfFocused() {
3737
// add logic for determining if given component is an ancestor of focusedComponent
3838
return false;
3939
}
@@ -47,7 +47,6 @@ const LeftColExpansionPanel = (props) => {
4747
component="a"
4848
style={{ color: 'red' }}
4949
onClick={() => {
50-
console.log({ title });
5150
changeFocusComponent({ title });
5251
}}
5352
>
@@ -63,17 +62,14 @@ const LeftColExpansionPanel = (props) => {
6362
style={{ color }}
6463
/>
6564
<ListItemSecondaryAction>
66-
{isFocused() || isAncestor() ? (
65+
{isFocused() || isAncestorOfFocused() ? (
6766
<div />
6867
) : (
6968
<IconButton aria-label="Add">
7069
<AddIcon
7170
style={{ color, float: 'right' }}
7271
onClick={() => {
73-
console.log(title);
7472
addChild({ title });
75-
// get childId somewhere, or call changeFocusChild within addChild (better idea)
76-
// changeFocusChild({ title });
7773
}}
7874
/>
7975
</IconButton>

src/components/Rectangle.jsx

Lines changed: 70 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,95 @@
11
import React, { Component } from 'react';
2-
import { Rect } from 'react-konva';
2+
import {
3+
Rect, Group, Label, Text,
4+
} from 'react-konva';
5+
import TransformerComponent from './TransformerComponent.jsx';
36
// import PropTypes from 'prop-types';
47

58
class Rectangle extends Component {
6-
extractPositionInfo(componentId, childId, target) {
7-
console.log('extracting position info, Rectanlge.jsx');
9+
handleResize(componentId, childId, target) {
810
const transformation = {
9-
x: target.x(),
10-
y: target.y(),
1111
width: target.width() * target.scaleX(),
1212
height: target.height() * target.scaleY(),
1313
};
14+
this.props.handleTransform(componentId, childId, transformation);
15+
}
1416

17+
handleDrag(componentId, childId, target) {
18+
const transformation = {
19+
x: target.x(),
20+
y: target.y(),
21+
};
1522
this.props.handleTransform(componentId, childId, transformation);
1623
}
1724

1825
render() {
1926
const {
20-
color, x, y, childId, componentId, draggable, width, height, title,
27+
color,
28+
x,
29+
y,
30+
childId,
31+
componentId,
32+
draggable,
33+
width,
34+
height,
35+
title,
36+
focusChild,
37+
focusComponent,
2138
} = this.props;
22-
console.log('childId in rectangle:', childId);
39+
40+
// the Group is responsible for dragging of all children
41+
// the Rect emits changes to child width and height with help from Transformer
2342
return (
24-
<Rect
25-
name={`${childId}`}
43+
<Group
44+
draggable={true}
2645
x={x}
2746
y={y}
28-
childId={childId}
29-
componentId={componentId}
30-
title={title}
3147
scaleX={1}
3248
scaleY={1}
3349
width={width}
3450
height={height}
35-
stroke={color}
36-
strokeWidth={6}
37-
strokeScaleEnabled={false}
38-
onTransformEnd={event => this.extractPositionInfo(componentId, childId, event.target)}
39-
onDragEnd={event => this.extractPositionInfo(componentId, childId, event.target)}
40-
draggable={draggable}
41-
color={color}
42-
// use dragBoundFunc to bind children within parents
43-
// (but if only children are rendered/movable, and parent is size of canvas, won't need this anyways )
44-
// dragBoundFunc={function dragBoundFunc(pos) {
45-
// console.log('binding');
46-
// const newY = pos.y < 200 ? 200 : pos.y;
47-
// const newX = pos.x < 200 ? 200 : pos.x;
48-
// return {
49-
// x: newX,
50-
// y: newY,
51-
// };
52-
// }}
53-
/>
51+
onDragEnd={event => this.handleDrag(componentId, childId, event.target)}
52+
>
53+
<Rect
54+
name={`${childId}`}
55+
// x={0}
56+
// y={0}
57+
childId={childId}
58+
componentId={componentId}
59+
title={title}
60+
scaleX={1}
61+
scaleY={1}
62+
width={width}
63+
height={height}
64+
stroke={color}
65+
color={color}
66+
// fill={color}
67+
// opacity={0.8}
68+
onTransformEnd={event => this.handleResize(componentId, childId, event.target)}
69+
strokeWidth={4}
70+
strokeScaleEnabled={false}
71+
draggable={false}
72+
/>
73+
<Label>
74+
<Text text={title} fill={'white'} />
75+
</Label>
76+
<Rect
77+
// replace with grandchildren rectangles
78+
scaleX={0.2}
79+
scaleY={0.2}
80+
width={width}
81+
height={height}
82+
stroke={color}
83+
color={color}
84+
strokeWidth={4}
85+
draggable={false}
86+
/>
87+
{focusChild.childId === childId ? (
88+
<TransformerComponent focusComponent={focusComponent} focusChild={focusChild} />
89+
) : (
90+
<Label />
91+
)}
92+
</Group>
5493
);
5594
}
5695
}

src/components/TransformerComponent.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ export default class TransformerComponent extends Component {
1111
this.checkNode();
1212
}
1313

14+
// this function makes sure the transformer follows along with the focusChild
1415
checkNode() {
1516
const stage = this.transformer.getStage();
1617
const { focusChild } = this.props;
1718
const selectedNode = stage.findOne(`.${focusChild.childId}`);
18-
// console.log('selected node from within TransformerComponent: ', selectedNode);
19-
// console.log('stage: ', stage);
20-
// console.log('focusChild: ', focusChild, focusChild.childId, typeof focusChild.childId);
19+
2120
if (selectedNode === this.transformer.node()) {
2221
return;
2322
}

src/containers/MainContainer.jsx

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ class MainContainer extends Component {
5858

5959
componentDidMount() {}
6060

61-
increaseHeight = () => {
62-
this.setState({
63-
scaleX: this.state.scaleX * 1.5,
64-
scaleY: this.state.scaleY * 1.5,
65-
});
66-
};
61+
// increaseHeight = () => {
62+
// this.setState({
63+
// scaleX: this.state.scaleX * 1.5,
64+
// scaleY: this.state.scaleY * 1.5,
65+
// });
66+
// };
6767

68-
decreaseHeight = () => {
69-
this.setState({
70-
scaleX: this.state.scaleX * 0.75,
71-
scaleY: this.state.scaleY * 0.75,
72-
});
73-
};
68+
// decreaseHeight = () => {
69+
// this.setState({
70+
// scaleX: this.state.scaleX * 0.75,
71+
// scaleY: this.state.scaleY * 0.75,
72+
// });
73+
// };
7474

7575
toggleDrag = () => {
7676
this.props.toggleComponentDragging(this.state.draggable);
@@ -111,22 +111,18 @@ class MainContainer extends Component {
111111
<MuiThemeProvider theme={theme}>
112112
<div className="main-container" style={{ cursor }}>
113113
<div className="main" ref={main}>
114-
{components.length > 0 ? (
115-
<KonvaStage
116-
scaleX={scaleX}
117-
scaleY={scaleY}
118-
image={image}
119-
draggable={draggable}
120-
components={components}
121-
handleTransform={handleTransformation}
122-
openExpansionPanel={openPanel}
123-
focusComponent={focusComponent}
124-
focusChild={focusChild}
125-
changeFocusChild={changeFocusChild}
126-
/>
127-
) : (
128-
<p>Add some components</p>
129-
)}
114+
<KonvaStage
115+
scaleX={scaleX}
116+
scaleY={scaleY}
117+
image={image}
118+
draggable={draggable}
119+
components={components}
120+
handleTransform={handleTransformation}
121+
openExpansionPanel={openPanel}
122+
focusComponent={focusComponent}
123+
focusChild={focusChild}
124+
changeFocusChild={changeFocusChild}
125+
/>
130126
</div>
131127
</div>
132128
</MuiThemeProvider>

src/containers/RightContainer.jsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux';
33
// import PropTypes from 'prop-types';
4-
import {
5-
handleClose,
6-
deleteCompProp,
7-
addCompProp,
8-
} from '../actions/components';
4+
import { handleClose, deleteCompProp, addCompProp } from '../actions/components';
95
// import Snackbars from '../components/Snackbars.jsx';
106
// import RightTabs from '../components/RightTabs.jsx';
117

@@ -27,11 +23,11 @@ class RightContainer extends Component {
2723
state = {
2824
successOpen: false,
2925
errorOpen: false,
30-
}
26+
};
3127

3228
viewAppDir = () => {
3329
IPC.send('view_app_dir', this.props.appDir);
34-
}
30+
};
3531

3632
render() {
3733
const {
@@ -47,7 +43,7 @@ class RightContainer extends Component {
4743
} = this.props;
4844

4945
return (
50-
<div className='column-right' style={{ width: `${this.props.width}%` }} >
46+
<div className="column-right" style={{ width: `${this.props.width}%` }}>
5147
{/* <RightTabs
5248
components={components}
5349
focusComponent={focusComponent}
@@ -80,5 +76,7 @@ class RightContainer extends Component {
8076
// rightColumnOpen: PropTypes.bool.isRequired,
8177
// };
8278

83-
84-
export default connect(mapStateToProps, mapDispatchToProps)(RightContainer);
79+
export default connect(
80+
mapStateToProps,
81+
mapDispatchToProps,
82+
)(RightContainer);

src/store.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ let composer;
1010

1111
if (process.env.NODE_ENV === 'development') {
1212
composer = compose(
13-
applyMiddleware(logger, thunk),
13+
applyMiddleware(thunk), // re-add logger if you want redux log messages
1414
composeWithDevTools(),
1515
);
1616
} else {
1717
composer = compose(applyMiddleware(thunk));
1818
}
1919

20-
const store = createStore(
21-
reducers,
22-
composer,
23-
);
20+
const store = createStore(reducers, composer);
2421

2522
store.subscribe(throttle(() => saveState(store.getState()), 1000));
2623

0 commit comments

Comments
 (0)