@chamn/engine 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component/CustomSchemaForm/components/Form/context.d.ts +2 -0
- package/dist/component/CustomSchemaForm/components/Form/index.d.ts +1 -0
- package/dist/component/CustomSchemaForm/components/SetterSwitcher/index.d.ts +2 -0
- package/dist/component/CustomSchemaForm/index.d.ts +3 -0
- package/dist/component/Workbench/index.d.ts +4 -0
- package/dist/core/pluginManager.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/{index.es.js → index.mjs} +2995 -2944
- package/dist/index.mjs.map +1 -0
- package/dist/plugins/RightPanel/view.d.ts +4 -0
- package/package.json +12 -9
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -36
- package/.prettierrc.json +0 -7
- package/.storybook/main.js +0 -24
- package/.storybook/preview.js +0 -9
- package/CHANGELOG.md +0 -54
- package/__tests__/demo.test.ts +0 -3
- package/build.config.js +0 -88
- package/dist/index.cjs.js +0 -197
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es.js.map +0 -1
- package/index.html +0 -16
- package/jest.config.js +0 -196
- package/public/Engine.module.scss.d.ts +0 -5
- package/public/_dev_/render.d.ts +0 -2
- package/public/component/CSSEditor/style.module.scss.d.ts +0 -6
- package/public/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
- package/public/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
- package/public/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
- package/public/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
- package/public/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
- package/public/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
- package/public/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
- package/public/component/Workbench/style.module.scss.d.ts +0 -25
- package/public/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
- package/public/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
- package/public/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
- package/public/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
- package/public/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
- package/public/plugins/Designer/style.module.scss.d.ts +0 -5
- package/public/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
- package/public/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
- package/public/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
- package/public/plugins/RightPanel/style.module.scss.d.ts +0 -10
- package/public/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
- package/public/render.umd.js +0 -42
- package/public/render.umd.js.map +0 -1
- package/src/Engine.module.scss +0 -10
- package/src/Engine.module.scss.d.ts +0 -5
- package/src/_dev_/index.css +0 -22
- package/src/_dev_/index.tsx +0 -5
- package/src/_dev_/page/Editor/index.tsx +0 -198
- package/src/_dev_/page/Editor/indexCustom.tsx +0 -274
- package/src/_dev_/page/Preview/index.tsx +0 -56
- package/src/_dev_/render.ts +0 -3
- package/src/_dev_/router.tsx +0 -14
- package/src/assets/react.svg +0 -4
- package/src/assets/styles/mixin.scss +0 -15
- package/src/component/CSSEditor/index.tsx +0 -247
- package/src/component/CSSEditor/style.module.scss +0 -22
- package/src/component/CSSEditor/style.module.scss.d.ts +0 -6
- package/src/component/CSSPropertiesEditor/cssProperties.ts +0 -1062
- package/src/component/CSSPropertiesEditor/index.tsx +0 -389
- package/src/component/CSSPropertiesEditor/style.module.scss +0 -46
- package/src/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
- package/src/component/CSSPropertiesEditor/util.ts +0 -19
- package/src/component/CSSPropertiesVariableBindEditor/cssProperties.ts +0 -782
- package/src/component/CSSPropertiesVariableBindEditor/index.tsx +0 -366
- package/src/component/CSSPropertiesVariableBindEditor/style.module.scss +0 -48
- package/src/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
- package/src/component/CSSPropertiesVariableBindEditor/util.ts +0 -19
- package/src/component/ClassNameEditor/index.tsx +0 -91
- package/src/component/ClassNameEditor/style.module.scss +0 -0
- package/src/component/CustomSchemaForm/components/Form/Field/index.tsx +0 -81
- package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss +0 -32
- package/src/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
- package/src/component/CustomSchemaForm/components/Form/context.ts +0 -23
- package/src/component/CustomSchemaForm/components/Form/index.tsx +0 -71
- package/src/component/CustomSchemaForm/components/SetterSwitcher/index.tsx +0 -273
- package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss +0 -16
- package/src/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/ArrayItem.tsx +0 -55
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/SortItemOrderModal.tsx +0 -160
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/index.tsx +0 -129
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss +0 -22
- package/src/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
- package/src/component/CustomSchemaForm/components/Setters/BooleanSetter/index.tsx +0 -32
- package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/index.tsx +0 -78
- package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss +0 -7
- package/src/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
- package/src/component/CustomSchemaForm/components/Setters/ExpressionSetter/index.tsx +0 -47
- package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/defaultDts.ts +0 -28
- package/src/component/CustomSchemaForm/components/Setters/FunctionSetter/index.tsx +0 -93
- package/src/component/CustomSchemaForm/components/Setters/JSONSetter/index.tsx +0 -80
- package/src/component/CustomSchemaForm/components/Setters/NumberSetter/index.tsx +0 -34
- package/src/component/CustomSchemaForm/components/Setters/SelectSetter/index.tsx +0 -35
- package/src/component/CustomSchemaForm/components/Setters/ShapeSetter/index.tsx +0 -65
- package/src/component/CustomSchemaForm/components/Setters/StringSetter/index.tsx +0 -30
- package/src/component/CustomSchemaForm/components/Setters/TextAreaSetter/index.tsx +0 -31
- package/src/component/CustomSchemaForm/components/Setters/index.ts +0 -26
- package/src/component/CustomSchemaForm/components/Setters/type.ts +0 -18
- package/src/component/CustomSchemaForm/context.ts +0 -20
- package/src/component/CustomSchemaForm/index.tsx +0 -93
- package/src/component/CustomSchemaForm/style.module.scss +0 -15
- package/src/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
- package/src/component/CustomSchemaForm/utils.ts +0 -13
- package/src/component/MonacoEditor/index.tsx +0 -81
- package/src/component/Workbench/index.tsx +0 -329
- package/src/component/Workbench/style.module.scss +0 -159
- package/src/component/Workbench/style.module.scss.d.ts +0 -25
- package/src/core/pluginManager.ts +0 -151
- package/src/i18n/en_US/index.ts +0 -5
- package/src/i18n/index.ts +0 -39
- package/src/i18n/zh_CN/index.ts +0 -5
- package/src/index.tsx +0 -150
- package/src/material/innerMaterial.ts +0 -343
- package/src/plugins/AdvancePanel/index.tsx +0 -191
- package/src/plugins/AdvancePanel/style.module.scss +0 -8
- package/src/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
- package/src/plugins/ComponentLibrary/components/DragItem/index.tsx +0 -65
- package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss +0 -58
- package/src/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
- package/src/plugins/ComponentLibrary/components/ListView/index.tsx +0 -50
- package/src/plugins/ComponentLibrary/components/ListView/style.module.scss +0 -27
- package/src/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
- package/src/plugins/ComponentLibrary/index.tsx +0 -184
- package/src/plugins/ComponentLibrary/localize/en_US/index.ts +0 -3
- package/src/plugins/ComponentLibrary/localize/index.ts +0 -3
- package/src/plugins/ComponentLibrary/localize/zh_CN/index.ts +0 -3
- package/src/plugins/ComponentLibrary/style.module.scss +0 -31
- package/src/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
- package/src/plugins/ComponentLibrary/util.ts +0 -14
- package/src/plugins/ComponentStatePanel/index.tsx +0 -59
- package/src/plugins/Designer/components/DefaultSelectToolBar/index.tsx +0 -94
- package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss +0 -59
- package/src/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
- package/src/plugins/Designer/components/GhostView/index.tsx +0 -18
- package/src/plugins/Designer/config.ts +0 -1
- package/src/plugins/Designer/index.tsx +0 -61
- package/src/plugins/Designer/localize/en_US/index.ts +0 -3
- package/src/plugins/Designer/localize/index.ts +0 -3
- package/src/plugins/Designer/localize/zh_CN/index.ts +0 -3
- package/src/plugins/Designer/style.module.scss +0 -10
- package/src/plugins/Designer/style.module.scss.d.ts +0 -5
- package/src/plugins/Designer/util.ts +0 -18
- package/src/plugins/Designer/view.tsx +0 -225
- package/src/plugins/DisplaySourceSchema/index.tsx +0 -76
- package/src/plugins/GlobalStatePanel/index.tsx +0 -96
- package/src/plugins/GlobalStatePanel/localize/en_US/index.ts +0 -3
- package/src/plugins/GlobalStatePanel/localize/index.ts +0 -3
- package/src/plugins/GlobalStatePanel/localize/zh_CN/index.ts +0 -3
- package/src/plugins/GlobalStatePanel/style.module.scss +0 -8
- package/src/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
- package/src/plugins/History/index.tsx +0 -110
- package/src/plugins/OutlineTree/components/TreeView/context.ts +0 -43
- package/src/plugins/OutlineTree/components/TreeView/dataStruct.ts +0 -58
- package/src/plugins/OutlineTree/components/TreeView/index.tsx +0 -376
- package/src/plugins/OutlineTree/components/TreeView/style.module.scss +0 -93
- package/src/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
- package/src/plugins/OutlineTree/components/TreeView/treeNode.tsx +0 -271
- package/src/plugins/OutlineTree/index.tsx +0 -39
- package/src/plugins/OutlineTree/localize/en_US/index.ts +0 -3
- package/src/plugins/OutlineTree/localize/index.ts +0 -3
- package/src/plugins/OutlineTree/localize/zh_CN/index.ts +0 -3
- package/src/plugins/OutlineTree/util.tsx +0 -302
- package/src/plugins/PropertyPanel/index.tsx +0 -63
- package/src/plugins/PropertyPanel/style.module.scss +0 -12
- package/src/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
- package/src/plugins/PropertyPanel/utils.ts +0 -13
- package/src/plugins/RightPanel/index.tsx +0 -30
- package/src/plugins/RightPanel/style.module.scss +0 -16
- package/src/plugins/RightPanel/style.module.scss.d.ts +0 -10
- package/src/plugins/RightPanel/view.tsx +0 -177
- package/src/plugins/VisualPanel/index.tsx +0 -185
- package/src/plugins/VisualPanel/style.module.scss +0 -17
- package/src/plugins/VisualPanelPlus/index.tsx +0 -103
- package/src/plugins/VisualPanelPlus/style.module.scss +0 -20
- package/src/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
- package/src/plugins/index.tsx +0 -26
- package/src/stories/Button.jsx +0 -50
- package/src/stories/Button.stories.jsx +0 -40
- package/src/stories/Introduction.stories.mdx +0 -194
- package/src/stories/assets/code-brackets.svg +0 -1
- package/src/stories/assets/colors.svg +0 -1
- package/src/stories/assets/comments.svg +0 -1
- package/src/stories/assets/direction.svg +0 -1
- package/src/stories/assets/flow.svg +0 -1
- package/src/stories/assets/plugin.svg +0 -1
- package/src/stories/assets/repo.svg +0 -1
- package/src/stories/assets/stackalt.svg +0 -1
- package/src/stories/button.css +0 -30
- package/src/stories/plugins/CSSEditor.stories.tsx +0 -75
- package/src/stories/plugins/VisualPanelPlus.stories.tsx +0 -74
- package/src/style.d.ts +0 -2
- package/src/typing.d.ts +0 -9
- package/src/utils/css.ts +0 -88
- package/src/utils/defaultEngineConfig.tsx +0 -55
- package/src/utils/index.ts +0 -12
- package/src/utils/logger.ts +0 -4
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -32
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { LayoutDragAndDropExtraDataType, Sensor, SensorEventObjType } from '@chamn/layout';
|
|
2
|
-
import { DropPosType } from '@chamn/layout/dist/components/DropAnchor/util';
|
|
3
|
-
import { CNode, CRootNode } from '@chamn/model';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { WithTranslation } from 'react-i18next';
|
|
6
|
-
import { CPluginCtx } from '../../../../core/pluginManager';
|
|
7
|
-
import { LOGGER } from '../../../../utils/logger';
|
|
8
|
-
import { DesignerExports } from '../../../Designer';
|
|
9
|
-
import { calculateDropPosInfo, getTargetMNodeKeyVal, transformPageSchemaToTreeData, traverseTree } from '../../util';
|
|
10
|
-
import { ContextState, CTreeContext, DragState } from './context';
|
|
11
|
-
import { TreeNodeData } from './dataStruct';
|
|
12
|
-
import styles from './style.module.scss';
|
|
13
|
-
import { DRAG_ITEM_KEY, TreeNode } from './treeNode';
|
|
14
|
-
|
|
15
|
-
interface TreeViewProps extends WithTranslation {
|
|
16
|
-
pluginCtx: CPluginCtx;
|
|
17
|
-
multiSelect?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class TreeView extends React.Component<
|
|
21
|
-
TreeViewProps,
|
|
22
|
-
ContextState & {
|
|
23
|
-
dropPosInfo: { x: number; y: number } | null;
|
|
24
|
-
}
|
|
25
|
-
> {
|
|
26
|
-
domRef: React.RefObject<HTMLDivElement>;
|
|
27
|
-
disposeCbList: (() => void)[] = [];
|
|
28
|
-
sensor?: Sensor;
|
|
29
|
-
constructor(props: TreeViewProps) {
|
|
30
|
-
super(props);
|
|
31
|
-
this.domRef = React.createRef<HTMLDivElement>();
|
|
32
|
-
|
|
33
|
-
this.state = {
|
|
34
|
-
treeData: [],
|
|
35
|
-
currentSelectNodeKeys: [],
|
|
36
|
-
expandKeys: [],
|
|
37
|
-
multiSelect: props.multiSelect || false,
|
|
38
|
-
dropPosInfo: {
|
|
39
|
-
x: 0,
|
|
40
|
-
y: 0,
|
|
41
|
-
},
|
|
42
|
-
pageModel: props.pluginCtx.pageModel,
|
|
43
|
-
dragState: DragState.NORMAL,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getDesignerHandler = async () => {
|
|
48
|
-
const designerPluginInstance = await this.props.pluginCtx.pluginManager.get('Designer');
|
|
49
|
-
const designerHandler: DesignerExports = designerPluginInstance?.exports;
|
|
50
|
-
return designerHandler;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
updateTreeDataFromNode = () => {
|
|
54
|
-
const { pluginCtx } = this.props;
|
|
55
|
-
const { pageModel } = pluginCtx;
|
|
56
|
-
const plainTreeData = pageModel.export();
|
|
57
|
-
const tempTreeData = transformPageSchemaToTreeData(plainTreeData, pageModel);
|
|
58
|
-
this.setState({
|
|
59
|
-
treeData: tempTreeData,
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
getParentKeyPaths = (targetKey: string) => {
|
|
64
|
-
const { treeData } = this.state;
|
|
65
|
-
let target: TreeNodeData = null as any;
|
|
66
|
-
traverseTree(treeData, (node) => {
|
|
67
|
-
if (node.key === targetKey) {
|
|
68
|
-
target = node;
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
});
|
|
73
|
-
if (target) {
|
|
74
|
-
let tempNode = target?.parent as TreeNodeData | undefined | null;
|
|
75
|
-
const res = [];
|
|
76
|
-
while (tempNode) {
|
|
77
|
-
if (tempNode.key) {
|
|
78
|
-
res.push(tempNode.key);
|
|
79
|
-
}
|
|
80
|
-
tempNode = tempNode.parent;
|
|
81
|
-
}
|
|
82
|
-
return res;
|
|
83
|
-
} else {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
scrollNodeToView = (key: string) => {
|
|
89
|
-
const dom = document.querySelector(`[${DRAG_ITEM_KEY}="${key}"]`);
|
|
90
|
-
dom?.scrollIntoView?.({
|
|
91
|
-
behavior: 'smooth',
|
|
92
|
-
block: 'center',
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
async componentDidMount() {
|
|
97
|
-
this.updateTreeDataFromNode();
|
|
98
|
-
const { pluginCtx } = this.props;
|
|
99
|
-
const { pageModel } = pluginCtx;
|
|
100
|
-
|
|
101
|
-
pageModel.emitter.on('*', () => {
|
|
102
|
-
this.updateTreeDataFromNode();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
pluginCtx.globalEmitter.on('onSelectNodeChange', ({ node }) => {
|
|
106
|
-
this.toSelectTreeNode(node);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const workbench = pluginCtx.getWorkbench();
|
|
110
|
-
|
|
111
|
-
workbench.emitter.on('leftPanelVisible', ({ visible, panelName }) => {
|
|
112
|
-
if (visible && panelName === 'OutlineTree') {
|
|
113
|
-
console.log('visible, panelName', visible, panelName);
|
|
114
|
-
const currentSelectNode = pluginCtx.engine.getActiveNode();
|
|
115
|
-
if (currentSelectNode) {
|
|
116
|
-
this.toSelectTreeNode(currentSelectNode);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const currentSelectNode = pluginCtx.engine.getActiveNode();
|
|
122
|
-
if (currentSelectNode) {
|
|
123
|
-
this.toSelectTreeNode(currentSelectNode);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
await this.props.pluginCtx.pluginManager.onPluginReadyOk('Designer');
|
|
127
|
-
this.registerDragEvent();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
toSelectTreeNode = (node: CNode | CRootNode) => {
|
|
131
|
-
const parentPaths = this.getParentKeyPaths(node.id);
|
|
132
|
-
LOGGER.debug('onSelectNodeChange parent path', parentPaths, node);
|
|
133
|
-
const newExpandKeys = Array.from(new Set([...this.state.expandKeys, ...parentPaths]));
|
|
134
|
-
|
|
135
|
-
LOGGER.debug('onSelectNodeChange newExpandKeys', newExpandKeys, node);
|
|
136
|
-
|
|
137
|
-
this.setState({
|
|
138
|
-
currentSelectNodeKeys: [node.id],
|
|
139
|
-
expandKeys: newExpandKeys,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
this.scrollNodeToView(node.id);
|
|
144
|
-
}, 100);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
containNode = (parentNode: TreeNodeData, targetNode: TreeNodeData) => {
|
|
148
|
-
let res = null;
|
|
149
|
-
traverseTree(parentNode, (node) => {
|
|
150
|
-
if (node.key === targetNode.key) {
|
|
151
|
-
res = node;
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
return false;
|
|
155
|
-
});
|
|
156
|
-
return res;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
getTreeNodeByKey = (key: string): TreeNodeData | null => {
|
|
160
|
-
const { treeData } = this.state;
|
|
161
|
-
let target: TreeNodeData | null = null;
|
|
162
|
-
traverseTree(treeData, (node) => {
|
|
163
|
-
if (node.key === key) {
|
|
164
|
-
target = node;
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
return false;
|
|
168
|
-
});
|
|
169
|
-
return target;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
registerDragEvent = async () => {
|
|
173
|
-
if (!this.domRef.current) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
const sensor = new Sensor({
|
|
177
|
-
container: this.domRef.current,
|
|
178
|
-
name: 'OutlineTree',
|
|
179
|
-
eventPriority: 999,
|
|
180
|
-
});
|
|
181
|
-
const { pluginCtx } = this.props;
|
|
182
|
-
|
|
183
|
-
const pageModel = pluginCtx.pageModel;
|
|
184
|
-
const designerExports: DesignerExports = await this.getDesignerHandler();
|
|
185
|
-
const dnd = designerExports.getDnd();
|
|
186
|
-
sensor.setCanDrag((eventObj: SensorEventObjType) => {
|
|
187
|
-
const targetDom = eventObj.event.target as HTMLDivElement;
|
|
188
|
-
if (!targetDom) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const targetNodeId = getTargetMNodeKeyVal(targetDom, DRAG_ITEM_KEY);
|
|
192
|
-
|
|
193
|
-
if (!targetNodeId) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const targetNode = pageModel.getNode(targetNodeId);
|
|
198
|
-
const targetTreeNode = this.getTreeNodeByKey(targetNodeId);
|
|
199
|
-
if (targetTreeNode?.canDrag !== undefined && targetTreeNode?.canDrag === false) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (!targetNode) {
|
|
203
|
-
console.log('targetNode not found');
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
...eventObj,
|
|
209
|
-
extraData: {
|
|
210
|
-
startNode: targetNode,
|
|
211
|
-
} as LayoutDragAndDropExtraDataType,
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
sensor.setCanDrop((eventObj: SensorEventObjType) => {
|
|
216
|
-
const targetDom = eventObj.event.target as HTMLDivElement;
|
|
217
|
-
|
|
218
|
-
if (!targetDom) {
|
|
219
|
-
LOGGER.debug('drop dom not found');
|
|
220
|
-
return eventObj;
|
|
221
|
-
}
|
|
222
|
-
const targetNodeId = getTargetMNodeKeyVal(targetDom, DRAG_ITEM_KEY);
|
|
223
|
-
|
|
224
|
-
if (!targetNodeId) {
|
|
225
|
-
LOGGER.debug('targetNodeId dom not found', eventObj, targetDom, DRAG_ITEM_KEY);
|
|
226
|
-
return eventObj;
|
|
227
|
-
}
|
|
228
|
-
const targetTreeNode = this.getTreeNodeByKey(targetNodeId);
|
|
229
|
-
if (targetTreeNode?.canDrop !== undefined && targetTreeNode.canDrop === false) {
|
|
230
|
-
LOGGER.debug('node can not be drop by tree node config');
|
|
231
|
-
return eventObj;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const targetNode = pageModel.getNode(targetNodeId);
|
|
235
|
-
|
|
236
|
-
if (!targetNode) {
|
|
237
|
-
LOGGER.debug('targetNode not found');
|
|
238
|
-
return eventObj;
|
|
239
|
-
}
|
|
240
|
-
const startNode = eventObj.extraData?.startNode as CNode;
|
|
241
|
-
if (!startNode) {
|
|
242
|
-
LOGGER.debug('startNode not found');
|
|
243
|
-
return eventObj;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (startNode?.id === targetNode.id) {
|
|
247
|
-
LOGGER.debug('startNode and dropNode is the same');
|
|
248
|
-
return eventObj;
|
|
249
|
-
}
|
|
250
|
-
const hasContain = startNode.contains(targetNode.id);
|
|
251
|
-
|
|
252
|
-
if (hasContain) {
|
|
253
|
-
LOGGER.debug('startNode contain dropNode');
|
|
254
|
-
return eventObj;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const dropInfo = calculateDropPosInfo({
|
|
258
|
-
point: eventObj.pointer,
|
|
259
|
-
dom: targetDom,
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
if (Array.isArray(targetTreeNode?.canDrop) && !targetTreeNode?.canDrop.includes(dropInfo.pos)) {
|
|
263
|
-
return eventObj;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
LOGGER.info('can dropNode', targetNode);
|
|
267
|
-
|
|
268
|
-
const res = {
|
|
269
|
-
...eventObj,
|
|
270
|
-
extraData: {
|
|
271
|
-
...eventObj.extraData,
|
|
272
|
-
dropPosInfo: dropInfo,
|
|
273
|
-
dropNode: targetNode,
|
|
274
|
-
dropNodeUid: undefined,
|
|
275
|
-
} as LayoutDragAndDropExtraDataType,
|
|
276
|
-
};
|
|
277
|
-
return res;
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
dnd.registerSensor(sensor);
|
|
281
|
-
|
|
282
|
-
sensor.emitter.on('dragging', (e) => {
|
|
283
|
-
const dropNode = e.extraData.dropNode as CNode;
|
|
284
|
-
this.setState({
|
|
285
|
-
dragState: DragState.DRAGGING,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
if (!dropNode) {
|
|
289
|
-
this.setState({
|
|
290
|
-
dropPosInfo: null,
|
|
291
|
-
});
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const dropDom = document.querySelectorAll(`[${DRAG_ITEM_KEY}="${dropNode.id}"]`)?.[0];
|
|
295
|
-
if (!dropDom) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
const dropPosInfo = e.extraData?.dropPosInfo as DropPosType;
|
|
299
|
-
const rect = dropDom.getBoundingClientRect();
|
|
300
|
-
const newDropInfo = { x: 0, y: 0 };
|
|
301
|
-
|
|
302
|
-
newDropInfo.x = rect.x;
|
|
303
|
-
if (dropPosInfo.pos === 'before') {
|
|
304
|
-
newDropInfo.y = rect.y;
|
|
305
|
-
} else if (dropPosInfo.pos == 'after') {
|
|
306
|
-
newDropInfo.y = rect.y + rect.height;
|
|
307
|
-
} else {
|
|
308
|
-
newDropInfo.y = rect.y + rect.height;
|
|
309
|
-
newDropInfo.x = rect.x + 20;
|
|
310
|
-
}
|
|
311
|
-
this.setState({
|
|
312
|
-
dropPosInfo: newDropInfo,
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
sensor.emitter.on('dragEnd', () => {
|
|
317
|
-
this.setState({
|
|
318
|
-
dragState: DragState.NORMAL,
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
this.sensor = sensor;
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
render() {
|
|
325
|
-
const { treeData, dragState, dropPosInfo } = this.state;
|
|
326
|
-
const { pluginCtx } = this.props;
|
|
327
|
-
|
|
328
|
-
return (
|
|
329
|
-
<CTreeContext.Provider
|
|
330
|
-
value={{
|
|
331
|
-
sensor: this.sensor,
|
|
332
|
-
state: this.state,
|
|
333
|
-
getDesignerHandler: this.getDesignerHandler,
|
|
334
|
-
onSelectNode: async ({ keys: sk }) => {
|
|
335
|
-
const designer = await pluginCtx.pluginManager.get('Designer');
|
|
336
|
-
if (!designer) {
|
|
337
|
-
console.warn('Designer is empty');
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
const nodeId = sk?.[0] || '';
|
|
341
|
-
const nn = pluginCtx.pageModel.getNode(nodeId);
|
|
342
|
-
const designerExports: DesignerExports = designer.exports;
|
|
343
|
-
designerExports.selectNode(nodeId);
|
|
344
|
-
if (nn) {
|
|
345
|
-
pluginCtx.engine.updateCurrentSelectNode(nn);
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
updateState: (newVal) => {
|
|
349
|
-
this.setState(newVal as any);
|
|
350
|
-
},
|
|
351
|
-
onDeleteNode: (id) => {
|
|
352
|
-
pluginCtx.pageModel.deleteNodeById(id);
|
|
353
|
-
},
|
|
354
|
-
onCopyNode: (id) => {
|
|
355
|
-
pluginCtx.pageModel.copyNodeById(id);
|
|
356
|
-
},
|
|
357
|
-
}}
|
|
358
|
-
>
|
|
359
|
-
<div className={styles.contentBox} ref={this.domRef}>
|
|
360
|
-
{treeData.map((item, index) => {
|
|
361
|
-
return <TreeNode item={item} key={item.key + `${index}`}></TreeNode>;
|
|
362
|
-
})}
|
|
363
|
-
{dragState === DragState.DRAGGING && dropPosInfo && (
|
|
364
|
-
<div
|
|
365
|
-
className={styles.dropAnchorLine}
|
|
366
|
-
style={{
|
|
367
|
-
left: `${dropPosInfo.x}px`,
|
|
368
|
-
top: `${dropPosInfo.y}px`,
|
|
369
|
-
}}
|
|
370
|
-
></div>
|
|
371
|
-
)}
|
|
372
|
-
</div>
|
|
373
|
-
</CTreeContext.Provider>
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
.contentBox {
|
|
2
|
-
background-color: white;
|
|
3
|
-
height: 100%;
|
|
4
|
-
border-top: 1px solid $borderColor;
|
|
5
|
-
overflow: auto;
|
|
6
|
-
position: relative;
|
|
7
|
-
* {
|
|
8
|
-
transition: all 0.1s;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
.nodeBox {
|
|
12
|
-
cursor: pointer;
|
|
13
|
-
.toolbarBox {
|
|
14
|
-
display: none;
|
|
15
|
-
padding-right: 10px;
|
|
16
|
-
}
|
|
17
|
-
.iconItem {
|
|
18
|
-
margin-right: 8px;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.nodeContent:hover {
|
|
23
|
-
.toolbarBox {
|
|
24
|
-
display: flex;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.nodeContent {
|
|
29
|
-
font-size: 14px;
|
|
30
|
-
cursor: pointer;
|
|
31
|
-
display: flex;
|
|
32
|
-
align-items: center;
|
|
33
|
-
&.selected {
|
|
34
|
-
background-color: rgba(221, 221, 221, 0.232);
|
|
35
|
-
}
|
|
36
|
-
.nodeArrow {
|
|
37
|
-
font-size: 12px;
|
|
38
|
-
|
|
39
|
-
&.expanded {
|
|
40
|
-
transform-origin: center;
|
|
41
|
-
transform: rotate(90deg);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.nodeRenderView {
|
|
46
|
-
padding: 5px 0;
|
|
47
|
-
flex: 1;
|
|
48
|
-
flex-wrap: nowrap;
|
|
49
|
-
overflow: hidden;
|
|
50
|
-
text-overflow: ellipsis;
|
|
51
|
-
white-space: nowrap;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.nodeChildren {
|
|
56
|
-
position: relative;
|
|
57
|
-
|
|
58
|
-
&::before {
|
|
59
|
-
display: block;
|
|
60
|
-
position: absolute;
|
|
61
|
-
left: 13px;
|
|
62
|
-
top: 0;
|
|
63
|
-
content: '';
|
|
64
|
-
height: 100%;
|
|
65
|
-
width: 1px;
|
|
66
|
-
background-color: $borderColor;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
&.selected::before {
|
|
70
|
-
background-color: rgba(0, 0, 255, 0.359);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.dropAnchorLine {
|
|
75
|
-
width: 100px;
|
|
76
|
-
height: 2px;
|
|
77
|
-
background-color: #1890ff;
|
|
78
|
-
position: fixed;
|
|
79
|
-
z-index: 99;
|
|
80
|
-
pointer-events: none;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.arrowSpan {
|
|
84
|
-
position: relative;
|
|
85
|
-
&::after {
|
|
86
|
-
content: '';
|
|
87
|
-
position: absolute;
|
|
88
|
-
top: 0px;
|
|
89
|
-
right: 0;
|
|
90
|
-
bottom: -0;
|
|
91
|
-
left: -8px;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import globalClassNames from '../../../../style.d';
|
|
2
|
-
declare const classNames: typeof globalClassNames & {
|
|
3
|
-
readonly contentBox: 'contentBox';
|
|
4
|
-
readonly nodeBox: 'nodeBox';
|
|
5
|
-
readonly toolbarBox: 'toolbarBox';
|
|
6
|
-
readonly iconItem: 'iconItem';
|
|
7
|
-
readonly nodeContent: 'nodeContent';
|
|
8
|
-
readonly selected: 'selected';
|
|
9
|
-
readonly nodeArrow: 'nodeArrow';
|
|
10
|
-
readonly expanded: 'expanded';
|
|
11
|
-
readonly nodeRenderView: 'nodeRenderView';
|
|
12
|
-
readonly nodeChildren: 'nodeChildren';
|
|
13
|
-
readonly dropAnchorLine: 'dropAnchorLine';
|
|
14
|
-
readonly arrowSpan: 'arrowSpan';
|
|
15
|
-
};
|
|
16
|
-
export = classNames;
|