diff --git a/packages/design/src/modules/panel-layer/index.tsx b/packages/design/src/modules/panel-layer/index.tsx
index e805bf6..11c785d 100644
--- a/packages/design/src/modules/panel-layer/index.tsx
+++ b/packages/design/src/modules/panel-layer/index.tsx
@@ -7,27 +7,35 @@ import { prefixName } from './config';
import { LayerTree } from './layer-tree';
import FileOutlined from '@ant-design/icons/FileOutlined';
import AppstoreOutlined from '@ant-design/icons/AppstoreOutlined';
-import ProjectOutlined from '@ant-design/icons/ProjectOutlined';
+import CalculatorOutlined from '@ant-design/icons/CalculatorOutlined';
const items: TabsProps['items'] = [
{
- key: '1',
+ key: 'page',
label: ,
children: (
-
+
)
},
{
- key: '2',
+ key: 'module',
label: ,
- children: `Content of Tab Pane 2`
+ children: (
+
+
+
+ )
},
{
- key: '3',
- label: ,
- children: `Content of Tab Pane 3`
+ key: 'component',
+ label: ,
+ children: (
+
+
+
+ )
}
];
@@ -38,11 +46,13 @@ export interface PanelLayerProps {
export const PanelLayer = (props: PanelLayerProps) => {
const { className, style } = props;
+
+ const defaultTabKey = items[2].key;
return (
{/*
header
*/}
-
+
{/*
footer
*/}
diff --git a/packages/design/src/modules/panel-layer/layer-tree.tsx b/packages/design/src/modules/panel-layer/layer-tree.tsx
index 9e10758..ca8baec 100644
--- a/packages/design/src/modules/panel-layer/layer-tree.tsx
+++ b/packages/design/src/modules/panel-layer/layer-tree.tsx
@@ -1,78 +1,38 @@
-import React from 'react';
-import type { CSSProperties } from 'react';
+import React, { useEffect, useContext } from 'react';
import classnames from 'classnames';
import Tree from 'antd/es/tree';
import DownOutlined from '@ant-design/icons/DownOutlined';
import { prefixName } from './config';
+import { Context } from '../../context';
+import { parseComponentViewTree } from '../../util/component';
+
+import type { CSSProperties } from 'react';
import type { DataNode, TreeProps } from 'antd/es/tree';
+import type { DesignItemType } from '../../types';
const { DirectoryTree } = Tree;
-
-const treeData: DataNode[] = [0, 1].map((i) => {
- return {
- title: 'design-layer-data parent 1',
- key: `${i}-0`,
- children: [
- {
- title: 'design-layer-data parent 1-0',
- key: `${i}-0-0`,
- children: [
- {
- title: 'design-layer-data leaf',
- key: `${i}-0-0-0`
- },
- {
- title: 'design-layer-data leaf',
- key: `${i}-0-0-1`
- },
- {
- title: 'design-layer-data leaf',
- key: `${i}-0-0-2`
- }
- ]
- },
- {
- title: 'design-layer-data parent 1-1',
- key: `${i}-0-1`,
- children: [
- {
- title: 'design-layer-data leaf',
- key: `${i}-0-1-0`
- }
- ]
- },
- {
- title: 'design-layer-data parent 1-2',
- key: `${i}-0-2`,
- children: [
- {
- title: 'design-layer-data leaf',
- key: `${i}-0-2-0`
- },
- {
- title: 'design-layer-data leaf',
- key: `${i}-0-2-1`
- }
- ]
- }
- ]
- };
-});
-
const baseName = 'layer-tree';
export interface LayerTreeProps {
className?: string;
style?: CSSProperties;
+ type: DesignItemType;
}
export const LayerTree = (props: LayerTreeProps) => {
- const { className, style } = props;
+ const { className, style, type } = props;
+ const { state } = useContext(Context);
const onSelect: TreeProps['onSelect'] = (selectedKeys, info) => {
console.log('selected', selectedKeys, info);
};
+ let treeData: DataNode[] = [];
+
+ if (type === 'component') {
+ treeData = parseComponentViewTree(state?.designData || null);
+ }
+
return (
} icon={null} defaultExpandedKeys={['0-0-0']} onSelect={onSelect} treeData={treeData} />
diff --git a/packages/design/src/types/data.ts b/packages/design/src/types/data.ts
index 634e6d4..f613900 100644
--- a/packages/design/src/types/data.ts
+++ b/packages/design/src/types/data.ts
@@ -1,9 +1,11 @@
import type { Element, ElementType, ElementSize, ElementBaseDesc } from '@idraw/types';
+export type DesignItemType = 'component' | 'module' | 'page';
+
export type DesignComponent = Omit & {
uuid: string;
type: 'component';
- name?: string;
+ name: string;
desc?: ElementBaseDesc & {
children: Array | DesignComponent>;
};
@@ -12,7 +14,7 @@ export type DesignComponent = Omit & {
export type DesignModule = Omit & {
uuid: string;
type: 'module';
- name?: string;
+ name: string;
desc?: ElementBaseDesc & {
children: Array;
};
@@ -21,7 +23,7 @@ export type DesignModule = Omit & {
export type DesignPage = Omit & {
uuid: string;
type: 'page';
- name?: string;
+ name: string;
desc: ElementBaseDesc & {
children: Array;
};
diff --git a/packages/design/src/types/index.ts b/packages/design/src/types/index.ts
index 3707679..d90f396 100644
--- a/packages/design/src/types/index.ts
+++ b/packages/design/src/types/index.ts
@@ -1 +1,2 @@
export * from './data';
+export * from './view';
diff --git a/packages/design/src/types/view.ts b/packages/design/src/types/view.ts
new file mode 100644
index 0000000..0a4b83b
--- /dev/null
+++ b/packages/design/src/types/view.ts
@@ -0,0 +1,5 @@
+export interface ViewTreeNode {
+ title: string;
+ key: string;
+ children?: ViewTreeNode[];
+}
diff --git a/packages/design/src/util/component.ts b/packages/design/src/util/component.ts
new file mode 100644
index 0000000..4085a4a
--- /dev/null
+++ b/packages/design/src/util/component.ts
@@ -0,0 +1,24 @@
+import { Data } from '@idraw/types';
+import { ViewTreeNode, DesignData, DesignComponent } from '../types';
+
+export function parseComponentViewTree(designData: DesignData | null): ViewTreeNode[] {
+ const list: ViewTreeNode[] = [];
+ designData?.components?.forEach((comp: DesignComponent) => {
+ const children: ViewTreeNode[] = [];
+ if (Array.isArray(comp?.desc?.children)) {
+ comp?.desc?.children?.forEach((child) => {
+ children.push({
+ key: child.uuid,
+ title: child.name || 'Unamed',
+ children: []
+ });
+ });
+ }
+ list.push({
+ key: comp.uuid,
+ title: comp.name || 'Unamed',
+ children
+ });
+ });
+ return list;
+}