Skip to content

Commit

Permalink
[feature/#2-programatic-canvas] Merge branch 'master' into feature/#2-…
Browse files Browse the repository at this point in the history
…programatic-canvas
  • Loading branch information
prevwong committed Jul 1, 2019
2 parents ae6751f + 505a896 commit 0c23a3e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/core/nodes/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const shortid = require("shortid");

export interface Canvas extends ConnectedInternalNode, React.Props<any> {
id?: NodeId,
style?: any,
className?: any,
is?: React.ElementType
children?: React.ReactNode
}

export const Canvas = connectInternalNode(({ craft: { node, manager }, children, is="div", id, ...props}: Canvas) => {
Expand All @@ -19,15 +20,19 @@ export const Canvas = connectInternalNode(({ craft: { node, manager }, children,
let canvasId = `canvas-${shortid.generate()}`;

if (node.data.type === Canvas) {
canvasId = internal.current.id = node.id;
const childNodes = mapChildrenToNodes(children, canvasId);
manager.add(node.id, childNodes);
if ( !(node as CanvasNode).data.nodes ) { // don't recreate nodes from children after initial hydration
canvasId = internal.current.id = node.id;
const childNodes = mapChildrenToNodes(children, canvasId);
manager.add(node.id, childNodes);
}
} else {
if (!id) throw new Error("Root Canvas cannot ommit `id` prop");
if (!node.data._childCanvas || (node.data._childCanvas && !node.data._childCanvas[id])) {
const rootNode = createNode(Canvas, { is, children } as any, canvasId, null);
internal.current.id = canvasId;
manager.pushChildCanvas(node.id, id, rootNode);
} else {
internal.current.id = node.data._childCanvas[id];
}
}
}, []);
Expand Down

0 comments on commit 0c23a3e

Please sign in to comment.