@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,18 +0,0 @@
|
|
|
1
|
-
import { CNode, CPage, CProp, CRootNode, CSlot, isNodeModel } from '@chamn/model';
|
|
2
|
-
|
|
3
|
-
export const getClosestNodeList = (node: CNode | CRootNode, level = 5) => {
|
|
4
|
-
const res = [];
|
|
5
|
-
let count = 0;
|
|
6
|
-
let currentNode: CNode | CRootNode | CSlot | CProp | CPage | null = node;
|
|
7
|
-
|
|
8
|
-
while (count < level && currentNode) {
|
|
9
|
-
if (isNodeModel(currentNode)) {
|
|
10
|
-
res.push(currentNode);
|
|
11
|
-
count++;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
currentNode = currentNode.parent || null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return res;
|
|
18
|
-
};
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Layout, LayoutDragAndDropExtraDataType } from '@chamn/layout';
|
|
3
|
-
import { CNode, CPage, CRootNode, InsertNodePosType } from '@chamn/model';
|
|
4
|
-
import { CPluginCtx } from '../../core/pluginManager';
|
|
5
|
-
import localize from './localize';
|
|
6
|
-
import { PLUGIN_NAME } from './config';
|
|
7
|
-
import { DefaultSelectToolBar } from './components/DefaultSelectToolBar';
|
|
8
|
-
import { getClosestNodeList } from './util';
|
|
9
|
-
import { GhostView } from './components/GhostView';
|
|
10
|
-
|
|
11
|
-
import styles from './style.module.scss';
|
|
12
|
-
import '@chamn/layout/dist/style.css';
|
|
13
|
-
import { AssetPackage } from '@chamn/model';
|
|
14
|
-
|
|
15
|
-
export type DesignerPropsType = {
|
|
16
|
-
pluginCtx: CPluginCtx;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type DesignerStateType = {
|
|
20
|
-
pageModel: CPage;
|
|
21
|
-
hoverToolBar: React.ReactNode;
|
|
22
|
-
selectToolBar: React.ReactNode;
|
|
23
|
-
ghostView: React.ReactNode;
|
|
24
|
-
assets: AssetPackage[];
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export class Designer extends React.Component<DesignerPropsType, DesignerStateType> {
|
|
28
|
-
layoutRef: React.RefObject<Layout>;
|
|
29
|
-
constructor(props: DesignerPropsType) {
|
|
30
|
-
super(props);
|
|
31
|
-
|
|
32
|
-
this.state = {
|
|
33
|
-
pageModel: props.pluginCtx.pageModel,
|
|
34
|
-
hoverToolBar: null,
|
|
35
|
-
selectToolBar: null,
|
|
36
|
-
ghostView: null,
|
|
37
|
-
assets: props.pluginCtx.assets || ([] as AssetPackage[]),
|
|
38
|
-
};
|
|
39
|
-
this.layoutRef = React.createRef<Layout>();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
componentDidMount(): void {
|
|
43
|
-
const { i18n } = this.props.pluginCtx;
|
|
44
|
-
Object.keys(localize).forEach((lng) => {
|
|
45
|
-
i18n.addResourceBundle(lng, `plugin:${PLUGIN_NAME}`, localize[lng], true, true);
|
|
46
|
-
});
|
|
47
|
-
this.init();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
updateAssets(assets: AssetPackage[]) {
|
|
51
|
-
this.setState({
|
|
52
|
-
assets: assets,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
reloadRender({ assets }: { assets?: AssetPackage[] }) {
|
|
57
|
-
this.layoutRef.current?.reload({ assets });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async init() {
|
|
61
|
-
const { layoutRef } = this;
|
|
62
|
-
const { pluginCtx } = this.props;
|
|
63
|
-
if (!layoutRef.current) {
|
|
64
|
-
console.warn('layout not ready ok');
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await layoutRef.current.ready();
|
|
69
|
-
const layoutInstance = layoutRef.current;
|
|
70
|
-
layoutInstance.dnd?.emitter.on('drop', (eventObj) => {
|
|
71
|
-
const pageModel = this.props.pluginCtx.pageModel;
|
|
72
|
-
const extraData = eventObj.extraData as LayoutDragAndDropExtraDataType;
|
|
73
|
-
const dropPosInfo = extraData.dropPosInfo;
|
|
74
|
-
const posFlag = {
|
|
75
|
-
before: 'BEFORE',
|
|
76
|
-
after: 'AFTER',
|
|
77
|
-
current: 'CHILD_START',
|
|
78
|
-
}[dropPosInfo?.pos || 'after'] as InsertNodePosType;
|
|
79
|
-
|
|
80
|
-
if (!extraData.dropNode) {
|
|
81
|
-
console.warn('cancel drop, because drop node is null');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (extraData.type === 'NEW_ADD') {
|
|
85
|
-
if (extraData.dropNode?.nodeType !== 'NODE') {
|
|
86
|
-
pageModel?.addNode(extraData.startNode as CNode, extraData.dropNode!, 'CHILD_START');
|
|
87
|
-
} else {
|
|
88
|
-
pageModel?.addNode(extraData.startNode as CNode, extraData.dropNode!, posFlag);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
if (extraData.dropNode?.id === extraData.startNode?.id) {
|
|
92
|
-
console.warn(' id is the same');
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const res = pageModel.moveNodeById(extraData.startNode?.id || '', extraData?.dropNode?.id || '', posFlag);
|
|
96
|
-
if (!res) {
|
|
97
|
-
console.warn('drop failed');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
layoutRef.current?.selectNode(extraData.startNode?.id || '');
|
|
101
|
-
this.props.pluginCtx.emitter.emit('onDrop', eventObj);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
pluginCtx.emitter.emit('ready', {
|
|
105
|
-
UIInstance: this,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
layoutInstance.dnd.emitter.on('click', ({ event }) => {
|
|
109
|
-
const workbench = pluginCtx.getWorkbench();
|
|
110
|
-
workbench.onGlobalClick(event);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
this.props.pluginCtx.pageModel.emitter.on('onPageChange', ({ node }) => {
|
|
114
|
-
layoutRef.current?.designRenderRef?.current?.rerender(node);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
this.props.pluginCtx.pageModel.emitter.on('onReloadPage', ({ node }) => {
|
|
118
|
-
layoutRef.current?.designRenderRef?.current?.rerender(node);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
pluginCtx.pluginReadyOk();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
onSelectNode = (node: CNode | CRootNode | null) => {
|
|
125
|
-
if (!node) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const { pluginCtx } = this.props;
|
|
129
|
-
pluginCtx.engine.updateCurrentSelectNode(node);
|
|
130
|
-
const pageModel = this.props.pluginCtx.pageModel;
|
|
131
|
-
const list = getClosestNodeList(node, 5);
|
|
132
|
-
const { layoutRef } = this;
|
|
133
|
-
this.setState({
|
|
134
|
-
selectToolBar: (
|
|
135
|
-
<DefaultSelectToolBar
|
|
136
|
-
nodeList={list}
|
|
137
|
-
toSelectNode={(id) => {
|
|
138
|
-
layoutRef.current?.selectNode(id);
|
|
139
|
-
this.onSelectNode(pageModel.getNode(id));
|
|
140
|
-
}}
|
|
141
|
-
toCopy={(id) => {
|
|
142
|
-
const newNode = this.props.pluginCtx.pageModel.copyNodeById(id);
|
|
143
|
-
if (newNode) {
|
|
144
|
-
layoutRef.current?.selectNode(newNode.id);
|
|
145
|
-
this.onSelectNode(newNode);
|
|
146
|
-
} else {
|
|
147
|
-
layoutRef.current?.selectNode('');
|
|
148
|
-
this.onSelectNode(null);
|
|
149
|
-
}
|
|
150
|
-
}}
|
|
151
|
-
toDelete={(id) => {
|
|
152
|
-
this.props.pluginCtx.pageModel.deleteNodeById(id);
|
|
153
|
-
layoutRef.current?.selectNode('');
|
|
154
|
-
this.onSelectNode(null);
|
|
155
|
-
}}
|
|
156
|
-
toHidden={(id) => {
|
|
157
|
-
const targetNodeModel = this.props.pluginCtx.pageModel.getNode(id) as CNode;
|
|
158
|
-
if (!targetNodeModel) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const devState = targetNodeModel.value.configure.devState ?? {};
|
|
162
|
-
devState.condition = false;
|
|
163
|
-
targetNodeModel.value.configure.devState = devState;
|
|
164
|
-
targetNodeModel.updateValue();
|
|
165
|
-
}}
|
|
166
|
-
/>
|
|
167
|
-
),
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
onDragStart = (startNode: CNode | CRootNode | null) => {
|
|
172
|
-
if (!startNode) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
this.setState({
|
|
176
|
-
ghostView: <GhostView node={startNode} />,
|
|
177
|
-
});
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
onHoverNode = (node: CNode | CRootNode | null, startNode: CNode | CRootNode) => {
|
|
181
|
-
this.props.pluginCtx.emitter.emit('onHover', node);
|
|
182
|
-
const material = node?.material;
|
|
183
|
-
if (!material) {
|
|
184
|
-
console.warn('material not found', node);
|
|
185
|
-
}
|
|
186
|
-
if (!startNode) {
|
|
187
|
-
this.setState({
|
|
188
|
-
hoverToolBar: <div className={styles.hoverTips}>{material?.value.title || material?.componentName}</div>,
|
|
189
|
-
ghostView: null,
|
|
190
|
-
});
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
this.setState({
|
|
195
|
-
hoverToolBar: <div className={styles.hoverTips}>{material?.value.title || material?.componentName}</div>,
|
|
196
|
-
ghostView: <GhostView node={startNode} />,
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
render() {
|
|
201
|
-
const { layoutRef, props, onSelectNode, onDragStart, onHoverNode } = this;
|
|
202
|
-
const { pageModel, hoverToolBar, selectToolBar, ghostView, assets } = this.state;
|
|
203
|
-
const { pluginCtx } = props;
|
|
204
|
-
const renderJSUrl = pluginCtx.engine.props.renderJSUrl || './render.umd.js';
|
|
205
|
-
return (
|
|
206
|
-
<Layout
|
|
207
|
-
beforeInitRender={props.pluginCtx.config.beforeInitRender}
|
|
208
|
-
customRender={props.pluginCtx.config.customRender}
|
|
209
|
-
ref={layoutRef}
|
|
210
|
-
pageModel={pageModel}
|
|
211
|
-
renderJSUrl={renderJSUrl}
|
|
212
|
-
{...props}
|
|
213
|
-
hoverToolBar={hoverToolBar}
|
|
214
|
-
selectToolBar={selectToolBar}
|
|
215
|
-
selectBoxStyle={{}}
|
|
216
|
-
hoverBoxStyle={{}}
|
|
217
|
-
onSelectNode={onSelectNode}
|
|
218
|
-
onDragStart={onDragStart}
|
|
219
|
-
onHoverNode={onHoverNode}
|
|
220
|
-
ghostView={ghostView}
|
|
221
|
-
assets={assets}
|
|
222
|
-
/>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import { Modal } from 'antd';
|
|
3
|
-
import { MonacoEditor, MonacoEditorInstance } from '../../component/MonacoEditor';
|
|
4
|
-
import { CPage } from '@chamn/model';
|
|
5
|
-
import { waitReactUpdate } from '../../utils';
|
|
6
|
-
import { EnginContext } from '../../index';
|
|
7
|
-
import { DesignerExports } from '../Designer';
|
|
8
|
-
|
|
9
|
-
export type DisplaySourceSchemaProps = {
|
|
10
|
-
pageModel: CPage;
|
|
11
|
-
engineCtx: EnginContext;
|
|
12
|
-
children: React.ReactNode;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const DisplaySourceSchema = (props: DisplaySourceSchemaProps) => {
|
|
16
|
-
const initialValue = props.pageModel.export();
|
|
17
|
-
const { engineCtx } = props;
|
|
18
|
-
const [open, setOpen] = useState(false);
|
|
19
|
-
const editorRef = useRef<MonacoEditorInstance | null>(null);
|
|
20
|
-
return (
|
|
21
|
-
<>
|
|
22
|
-
<div
|
|
23
|
-
onClick={() => {
|
|
24
|
-
setOpen(true);
|
|
25
|
-
}}
|
|
26
|
-
>
|
|
27
|
-
{props.children}
|
|
28
|
-
</div>
|
|
29
|
-
<Modal
|
|
30
|
-
open={open}
|
|
31
|
-
title="Source Schema"
|
|
32
|
-
width={'100%'}
|
|
33
|
-
onCancel={() => setOpen(false)}
|
|
34
|
-
onOk={async () => {
|
|
35
|
-
setOpen(false);
|
|
36
|
-
const newPage = editorRef.current?.getValue();
|
|
37
|
-
if (!newPage) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const newPageJSON = JSON.parse(newPage);
|
|
41
|
-
props.pageModel.updatePage(newPageJSON);
|
|
42
|
-
await waitReactUpdate();
|
|
43
|
-
const currentSelectNode = engineCtx.engine.getActiveNode();
|
|
44
|
-
const designerPluginInstance = await engineCtx.pluginManager.get('Designer');
|
|
45
|
-
const nodeId = currentSelectNode?.id || '';
|
|
46
|
-
designerPluginInstance?.ctx.emitter.on('ready', () => {
|
|
47
|
-
const designerExports: DesignerExports = designerPluginInstance.exports;
|
|
48
|
-
designerExports.selectNode(nodeId);
|
|
49
|
-
});
|
|
50
|
-
if (designerPluginInstance) {
|
|
51
|
-
const designerExports: DesignerExports = designerPluginInstance.exports;
|
|
52
|
-
designerExports.selectNode(nodeId);
|
|
53
|
-
}
|
|
54
|
-
}}
|
|
55
|
-
style={{
|
|
56
|
-
height: 'calc(100vh - 50px)',
|
|
57
|
-
top: '25px',
|
|
58
|
-
}}
|
|
59
|
-
destroyOnClose
|
|
60
|
-
>
|
|
61
|
-
<div style={{ width: '100%', height: 'calc(100vh - 200px)' }}>
|
|
62
|
-
<MonacoEditor
|
|
63
|
-
initialValue={JSON.stringify(initialValue, null, 2)}
|
|
64
|
-
language={'json'}
|
|
65
|
-
options={{
|
|
66
|
-
automaticLayout: true,
|
|
67
|
-
}}
|
|
68
|
-
onDidMount={(editor) => {
|
|
69
|
-
editorRef.current = editor;
|
|
70
|
-
}}
|
|
71
|
-
/>
|
|
72
|
-
</div>
|
|
73
|
-
</Modal>
|
|
74
|
-
</>
|
|
75
|
-
);
|
|
76
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { DatabaseOutlined } from '@ant-design/icons';
|
|
3
|
-
import { CPlugin, CPluginCtx } from '../../core/pluginManager';
|
|
4
|
-
import { withTranslation } from 'react-i18next';
|
|
5
|
-
import localize from './localize';
|
|
6
|
-
import { MonacoEditor, MonacoEditorInstance } from '../../component/MonacoEditor';
|
|
7
|
-
import styles from './style.module.scss';
|
|
8
|
-
|
|
9
|
-
export const PLUGIN_NAME = 'GlobalState';
|
|
10
|
-
const i18nNamespace = `plugin:${PLUGIN_NAME}`;
|
|
11
|
-
|
|
12
|
-
type GlobalStatePanelProps = {
|
|
13
|
-
pluginCtx: CPluginCtx;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const GlobalStatePanel = (props: GlobalStatePanelProps) => {
|
|
17
|
-
const { pluginCtx } = props;
|
|
18
|
-
const rootState = pluginCtx.pageModel.value.componentsTree.value.state || {};
|
|
19
|
-
// 表示是不是自己触发的值更新
|
|
20
|
-
let triggerChangeBySelf = false;
|
|
21
|
-
const editorRef = useRef<MonacoEditorInstance | null>(null);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
editorRef?.current?.setValue(JSON.stringify(rootState, null, 2));
|
|
24
|
-
// 正常情况下, 只有 reloadPage 才需要同步数据
|
|
25
|
-
pluginCtx.pageModel.emitter.on('onReloadPage', (e) => {
|
|
26
|
-
console.log(e);
|
|
27
|
-
if (triggerChangeBySelf) {
|
|
28
|
-
triggerChangeBySelf = false;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
editorRef.current?.setValue(JSON.stringify(pluginCtx.pageModel.value.componentsTree.value.state, null, 2));
|
|
32
|
-
});
|
|
33
|
-
}, []);
|
|
34
|
-
|
|
35
|
-
const onValueChange = (newValStr: string) => {
|
|
36
|
-
try {
|
|
37
|
-
const newVal = JSON.parse(newValStr);
|
|
38
|
-
pluginCtx.pageModel.value.componentsTree.value.state = newVal;
|
|
39
|
-
triggerChangeBySelf = true;
|
|
40
|
-
pluginCtx.pageModel.value.componentsTree.updateValue();
|
|
41
|
-
} catch (e) {
|
|
42
|
-
console.warn(e);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<div className={styles.box}>
|
|
48
|
-
<MonacoEditor
|
|
49
|
-
language={'json'}
|
|
50
|
-
options={{
|
|
51
|
-
automaticLayout: true,
|
|
52
|
-
tabSize: 2,
|
|
53
|
-
minimap: { enabled: false },
|
|
54
|
-
quickSuggestions: false,
|
|
55
|
-
suggestOnTriggerCharacters: false,
|
|
56
|
-
folding: false,
|
|
57
|
-
}}
|
|
58
|
-
onDidMount={(editor) => {
|
|
59
|
-
editorRef.current = editor;
|
|
60
|
-
}}
|
|
61
|
-
onChange={onValueChange}
|
|
62
|
-
/>
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const GlobalStatePanelPlugin: CPlugin = {
|
|
68
|
-
name: PLUGIN_NAME,
|
|
69
|
-
async init(ctx) {
|
|
70
|
-
const { i18n } = ctx;
|
|
71
|
-
Object.keys(localize).forEach((lng) => {
|
|
72
|
-
i18n.addResourceBundle(lng, i18nNamespace, localize[lng], true, true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const GlobalStatePanelWithLocalize = withTranslation(i18nNamespace)(GlobalStatePanel);
|
|
76
|
-
const Title = withTranslation(i18nNamespace)(({ t }) => <>{t('pluginName')}</>);
|
|
77
|
-
const workbench = ctx.getWorkbench();
|
|
78
|
-
workbench.addLeftPanel({
|
|
79
|
-
title: <Title />,
|
|
80
|
-
name: PLUGIN_NAME,
|
|
81
|
-
icon: <DatabaseOutlined />,
|
|
82
|
-
render: <GlobalStatePanelWithLocalize pluginCtx={ctx} />,
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
async destroy(ctx) {
|
|
86
|
-
console.log('destroy', ctx);
|
|
87
|
-
},
|
|
88
|
-
exports: (ctx) => {
|
|
89
|
-
return {};
|
|
90
|
-
},
|
|
91
|
-
meta: {
|
|
92
|
-
engine: {
|
|
93
|
-
version: '1.0.0',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { waitReactUpdate } from '@/utils';
|
|
2
|
-
import { CPageDataType } from '@chamn/model';
|
|
3
|
-
import { cloneDeep } from 'lodash-es';
|
|
4
|
-
import { CPlugin, CPluginCtx } from '../../core/pluginManager';
|
|
5
|
-
|
|
6
|
-
const PLUGIN_NAME = 'History';
|
|
7
|
-
|
|
8
|
-
export const HistoryPlugin: CPlugin = (ctx) => {
|
|
9
|
-
const CTX: CPluginCtx | null = ctx;
|
|
10
|
-
const dataStore = {
|
|
11
|
-
historyRecords: [] as CPageDataType[],
|
|
12
|
-
currentStepIndex: 0,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
let originalPageRecord: CPageDataType | null = null;
|
|
16
|
-
const pageSchema = ctx.pageModel.export();
|
|
17
|
-
originalPageRecord = pageSchema;
|
|
18
|
-
dataStore.historyRecords.push(pageSchema);
|
|
19
|
-
|
|
20
|
-
const loadPage = async (page: CPageDataType) => {
|
|
21
|
-
if (!CTX) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
CTX.pageModel.reloadPage(page);
|
|
25
|
-
await waitReactUpdate();
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const resObj = {
|
|
29
|
-
addStep: () => {
|
|
30
|
-
const { currentStepIndex, historyRecords } = dataStore;
|
|
31
|
-
const newPage = ctx.pageModel.export();
|
|
32
|
-
if (currentStepIndex !== historyRecords.length - 1) {
|
|
33
|
-
dataStore.historyRecords = historyRecords.slice(0, currentStepIndex + 1);
|
|
34
|
-
}
|
|
35
|
-
dataStore.historyRecords.push(newPage);
|
|
36
|
-
dataStore.currentStepIndex = historyRecords.length - 1;
|
|
37
|
-
},
|
|
38
|
-
reset: async () => {
|
|
39
|
-
const ctx = CTX;
|
|
40
|
-
if (!ctx) {
|
|
41
|
-
console.warn('plugin ctx is null, pls check it');
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (!originalPageRecord) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
dataStore.historyRecords = [];
|
|
48
|
-
loadPage(originalPageRecord);
|
|
49
|
-
},
|
|
50
|
-
preStep: () => {
|
|
51
|
-
const { currentStepIndex, historyRecords } = dataStore;
|
|
52
|
-
if (!resObj.canGoPreStep()) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const newIndex = currentStepIndex - 1;
|
|
56
|
-
dataStore.currentStepIndex = newIndex;
|
|
57
|
-
const page = cloneDeep(historyRecords[newIndex]);
|
|
58
|
-
loadPage(page);
|
|
59
|
-
},
|
|
60
|
-
nextStep: () => {
|
|
61
|
-
if (!resObj.canGoNextStep()) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const { currentStepIndex, historyRecords } = dataStore;
|
|
65
|
-
const newIndex = currentStepIndex + 1;
|
|
66
|
-
dataStore.currentStepIndex = newIndex;
|
|
67
|
-
const page = cloneDeep(historyRecords[newIndex]);
|
|
68
|
-
return loadPage(page);
|
|
69
|
-
},
|
|
70
|
-
canGoPreStep: () => {
|
|
71
|
-
const { currentStepIndex } = dataStore;
|
|
72
|
-
if (currentStepIndex <= 0) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
},
|
|
77
|
-
canGoNextStep: () => {
|
|
78
|
-
const { currentStepIndex, historyRecords } = dataStore;
|
|
79
|
-
if (currentStepIndex >= historyRecords.length - 1) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
return true;
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
name: PLUGIN_NAME,
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
89
|
-
async init(ctx) {
|
|
90
|
-
ctx.pageModel.emitter.on('onNodeChange', () => {
|
|
91
|
-
resObj.addStep();
|
|
92
|
-
});
|
|
93
|
-
ctx.pageModel.emitter.on('onPageChange', () => {
|
|
94
|
-
resObj.addStep();
|
|
95
|
-
});
|
|
96
|
-
ctx.pluginReadyOk();
|
|
97
|
-
},
|
|
98
|
-
async destroy(ctx) {
|
|
99
|
-
console.log('destroy', ctx);
|
|
100
|
-
},
|
|
101
|
-
exports: () => {
|
|
102
|
-
return resObj;
|
|
103
|
-
},
|
|
104
|
-
meta: {
|
|
105
|
-
engine: {
|
|
106
|
-
version: '1.0.0',
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
-
import { Sensor } from '@chamn/layout';
|
|
3
|
-
import { CPage } from '@chamn/model';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { DesignerExports } from '../../../Designer';
|
|
6
|
-
import { TreeNodeData } from './dataStruct';
|
|
7
|
-
export enum DragState {
|
|
8
|
-
DRAGGING = 'DRAGGING',
|
|
9
|
-
NORMAL = 'NORMAL',
|
|
10
|
-
}
|
|
11
|
-
export type ContextState = {
|
|
12
|
-
treeData: TreeNodeData[];
|
|
13
|
-
currentSelectNodeKeys: string[];
|
|
14
|
-
expandKeys: string[];
|
|
15
|
-
multiSelect: boolean;
|
|
16
|
-
dragState: DragState;
|
|
17
|
-
pageModel: CPage | null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type CTreeContextData = {
|
|
21
|
-
sensor?: Sensor;
|
|
22
|
-
state: ContextState;
|
|
23
|
-
updateState: (state: Partial<ContextState>) => void;
|
|
24
|
-
onSelectNode: (params: { keys: string[]; node: TreeNodeData }) => void;
|
|
25
|
-
onDeleteNode: (id: string) => void;
|
|
26
|
-
onCopyNode: (id: string) => void;
|
|
27
|
-
getDesignerHandler?: () => Promise<DesignerExports>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const CTreeContext = React.createContext<CTreeContextData>({
|
|
31
|
-
state: {
|
|
32
|
-
treeData: [],
|
|
33
|
-
currentSelectNodeKeys: [],
|
|
34
|
-
expandKeys: [],
|
|
35
|
-
multiSelect: false,
|
|
36
|
-
dragState: DragState.NORMAL,
|
|
37
|
-
pageModel: null,
|
|
38
|
-
},
|
|
39
|
-
updateState: () => {},
|
|
40
|
-
onSelectNode: () => {},
|
|
41
|
-
onDeleteNode: (id: string) => {},
|
|
42
|
-
onCopyNode: (id: string) => {},
|
|
43
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export type TreeNodeData = {
|
|
4
|
-
containerRender?: (params: {
|
|
5
|
-
item: TreeNodeData;
|
|
6
|
-
treeNodeView: JSX.Element;
|
|
7
|
-
}) => React.ReactElement;
|
|
8
|
-
titleViewRender?: (params: {
|
|
9
|
-
item: TreeNodeData;
|
|
10
|
-
titleView: React.ReactNode;
|
|
11
|
-
}) => React.ReactElement;
|
|
12
|
-
title: React.ReactNode;
|
|
13
|
-
icon?: React.ReactNode;
|
|
14
|
-
key?: string;
|
|
15
|
-
children?: TreeNodeData[];
|
|
16
|
-
parent?: TreeNodeData | null;
|
|
17
|
-
canBeSelected?: boolean;
|
|
18
|
-
canDrag?: boolean;
|
|
19
|
-
canDrop?: boolean | ('before' | 'after' | 'current')[];
|
|
20
|
-
rootNode?: boolean;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const x = 10;
|
|
24
|
-
const y = 3;
|
|
25
|
-
const z = 2;
|
|
26
|
-
|
|
27
|
-
const generateData = (
|
|
28
|
-
_level: number,
|
|
29
|
-
_tns: TreeNodeData[],
|
|
30
|
-
_preKey?: React.Key
|
|
31
|
-
) => {
|
|
32
|
-
const preKey = _preKey || '0';
|
|
33
|
-
const tns = _tns || [];
|
|
34
|
-
|
|
35
|
-
const children: React.Key[] = [];
|
|
36
|
-
for (let i = 0; i < x; i++) {
|
|
37
|
-
const key = `${preKey}-${i}`;
|
|
38
|
-
tns.push({ title: key, key });
|
|
39
|
-
if (i < y) {
|
|
40
|
-
children.push(key);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (_level < 0) {
|
|
44
|
-
return tns;
|
|
45
|
-
}
|
|
46
|
-
const level = _level - 1;
|
|
47
|
-
children.forEach((key, index) => {
|
|
48
|
-
tns[index].children = [];
|
|
49
|
-
return generateData(level, tns[index].children!, key);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const tempData: TreeNodeData[] = [];
|
|
53
|
-
generateData(z, tempData);
|
|
54
|
-
|
|
55
|
-
export const DemoTreeData: TreeNodeData = {
|
|
56
|
-
title: 'Page',
|
|
57
|
-
children: tempData,
|
|
58
|
-
};
|