Skip to content

started recursive solution to descendant rendering #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/components/KonvaStage.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { Component, createRef, Fragment } from "react";
import React, { Component, createRef, Fragment } from 'react';
// import PropTypes from 'prop-types';
import { Stage, Layer, Group, Label, Text } from "react-konva";
import TransformerComponent from "./TransformerComponent.jsx";
import Rectangle from "./Rectangle.jsx";
import {
Stage, Layer, Group, Label, Text,
} from 'react-konva';
import TransformerComponent from './TransformerComponent.jsx';
import Rectangle from './Rectangle.jsx';

class KonvaStage extends Component {
state = {
x: undefined,
y: undefined
y: undefined,
};

constructor(props) {
Expand All @@ -16,22 +18,21 @@ class KonvaStage extends Component {
this.group = createRef();
}

handleStageMouseDown = e => {
handleStageMouseDown = (e) => {
// // clicked on stage - clear selection
if (e.target === e.target.getStage()) {
// add functionality for allowing no focusChild
return;
}
// // clicked on transformer - do nothing
const clickedOnTransformer =
e.target.getParent().className === "Transformer";
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
if (clickedOnTransformer) {
return;
}

// find clicked rect by its name
const rectChildId = e.target.attrs.childId;
console.log("e.target : ", rectChildId);
console.log('e.target : ', rectChildId);
this.props.changeFocusChild({ childId: rectChildId });
};

Expand All @@ -49,13 +50,13 @@ class KonvaStage extends Component {
scaleY,
focusComponent,
focusChild,
changeFocusChild
changeFocusChild,
} = this.props;
const { selectedShapeName } = this.state;

return (
<Stage
ref={node => {
ref={(node) => {
this.stage = node;
}}
onMouseDown={this.handleStageMouseDown}
Expand Down
13 changes: 10 additions & 3 deletions src/components/Rectangle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ class Rectangle extends Component {
this.props.handleTransform(componentId, childId, transformation);
}

findDescendants(component) {

findDescendants(component, components, descendants = []) {
// fix this stuff Adam
if (!component) return;
component.childrenArray.forEach((child) => {
descendants.push(child);
const childComponent = components.find(comp => comp.title === child.componentName);
this.findDescendants(childComponent, components, descendants);
});
return descendants;
}

render() {
Expand Down Expand Up @@ -89,7 +96,7 @@ class Rectangle extends Component {
<Label>
<Text text={title} fill={'white'} />
</Label>
{}
{this.findDescendants().map}
<Rect
// replace with grandchildren rectangles
scaleX={0.2}
Expand Down