From ea156060c4f2009e9f85a7cade7cc00207d357da Mon Sep 17 00:00:00 2001 From: Siklos Date: Mon, 1 Aug 2022 00:30:43 +0200 Subject: [PATCH] Add Container to SVGSidebar + disable Symbol for userdata --- src/Components/SVG/Elements/Container.tsx | 2 +- src/Components/SVGSidebar/SVGSidebar.tsx | 33 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Components/SVG/Elements/Container.tsx b/src/Components/SVG/Elements/Container.tsx index c3374ca..86f69cd 100644 --- a/src/Components/SVG/Elements/Container.tsx +++ b/src/Components/SVG/Elements/Container.tsx @@ -9,7 +9,7 @@ interface IContainerProps { width: number, height: number, style?: React.CSSProperties, - userData?: Record + userData?: Record } export class Container extends React.Component { diff --git a/src/Components/SVGSidebar/SVGSidebar.tsx b/src/Components/SVGSidebar/SVGSidebar.tsx index c6e6f8d..e4107b7 100644 --- a/src/Components/SVGSidebar/SVGSidebar.tsx +++ b/src/Components/SVGSidebar/SVGSidebar.tsx @@ -8,18 +8,42 @@ interface ISVGSidebarProps { } export class SVGSidebar extends React.Component { - public iterateChilds(handleContainer: () => void): React.ReactNode { - if (!this.props.MainContainer) { - return undefined; + public iterateChilds(handleContainer: (container: Container) => void): React.ReactNode { + const root = this.props.MainContainer; + if (!root) { + return null; } - if (this.props.MainContainer) { + const queue = [root]; + const visited = new Set([root]); + while (queue.length > 0) { + const container = queue.pop() as Container; + handleContainer(container); + + container.props.children.forEach((child) => { + if (visited.has(child)) { + return; + } + visited.add(child); + queue.push(child); + }); } } public render() { const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64'; + + const containerRows: React.ReactNode[] = []; + this.iterateChilds((container: Container) => { + const key = container.props.id.toString(); + containerRows.push( + + ); + }); + return (
@@ -28,6 +52,7 @@ export class SVGSidebar extends React.Component {
Liste des éléments
+ { containerRows }
); }