Skip to content

Commit 837d84d

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
childcompid merged with canvas resizing fix
2 parents c8d80bb + 264f825 commit 837d84d

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/components/KonvaStage.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class KonvaStage extends Component {
7070
key={`${i}${child.componentName}`}
7171
draggable={false}
7272
selectedShapeName={selectedShapeName}
73+
components={components}
7374
childId={child.childId}
7475
focusChild={focusChild}
7576
focusComponent={focusComponent}

src/components/Rectangle.jsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,35 @@ import TransformerComponent from './TransformerComponent.jsx';
66
// import PropTypes from 'prop-types';
77

88
class Rectangle extends Component {
9-
handleResize(componentId, childId, target) {
9+
handleResize(componentId, childId, target, components) {
10+
const focChild = components
11+
.find(comp => comp.id === componentId)
12+
.childrenArray.find(child => child.childId === childId);
13+
1014
const transformation = {
1115
width: target.width() * target.scaleX(),
1216
height: target.height() * target.scaleY(),
17+
x: target.x() + focChild.position.x,
18+
y: target.y() + focChild.position.y,
1319
};
20+
1421
this.props.handleTransform(componentId, childId, transformation);
1522
}
1623

1724
handleDrag(componentId, childId, target) {
25+
console.log(target);
26+
1827
const transformation = {
1928
x: target.x(),
2029
y: target.y(),
2130
};
2231
this.props.handleTransform(componentId, childId, transformation);
2332
}
2433

34+
findDescendants(component) {
35+
36+
}
37+
2538
render() {
2639
const {
2740
color,
@@ -35,6 +48,7 @@ class Rectangle extends Component {
3548
title,
3649
focusChild,
3750
focusComponent,
51+
components,
3852
} = this.props;
3953

4054
// the Group is responsible for dragging of all children
@@ -52,8 +66,9 @@ class Rectangle extends Component {
5266
>
5367
<Rect
5468
name={`${childId}`}
55-
// x={0}
56-
// y={0}
69+
x={0}
70+
y={0}
71+
// absolutePosition={{ x, y }}
5772
childId={childId}
5873
componentId={componentId}
5974
title={title}
@@ -65,14 +80,16 @@ class Rectangle extends Component {
6580
color={color}
6681
// fill={color}
6782
// opacity={0.8}
68-
onTransformEnd={event => this.handleResize(componentId, childId, event.target)}
83+
onTransformEnd={event => this.handleResize(componentId, childId, event.target, components)
84+
}
6985
strokeWidth={4}
7086
strokeScaleEnabled={false}
7187
draggable={false}
7288
/>
7389
<Label>
7490
<Text text={title} fill={'white'} />
7591
</Label>
92+
{}
7693
<Rect
7794
// replace with grandchildren rectangles
7895
scaleX={0.2}

src/utils/componentReducer.util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ export const handleTransform = (
116116
state,
117117
{ componentId, childId, x, y, width, height }
118118
) => {
119-
console.log("componentId and childId: ", componentId, childId);
120-
console.log("state.focuscomponent: ", state.focusComponent);
121-
119+
// console.log('componentId and childId: ', componentId, childId);
120+
// console.log('state.focuscomponent: ', state.focusComponent);
121+
console.log("incoming x and y: ", x, y);
122122
const child = state.components
123123
.find(comp => comp.id === componentId)
124124
.childrenArray.find(child => child.childId === childId);

0 commit comments

Comments
 (0)