@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,25 +0,0 @@
|
|
|
1
|
-
import globalClassNames from '../../style.d';
|
|
2
|
-
declare const classNames: typeof globalClassNames & {
|
|
3
|
-
readonly workbenchContainer: 'workbenchContainer';
|
|
4
|
-
readonly topToolBarBox: 'topToolBarBox';
|
|
5
|
-
readonly topToolBarView: 'topToolBarView';
|
|
6
|
-
readonly bodyContent: 'bodyContent';
|
|
7
|
-
readonly leftBox: 'leftBox';
|
|
8
|
-
readonly pluginIconBar: 'pluginIconBar';
|
|
9
|
-
readonly pluginIconItem: 'pluginIconItem';
|
|
10
|
-
readonly active: 'active';
|
|
11
|
-
readonly pluginPanelBoxResizeBox: 'pluginPanelBoxResizeBox';
|
|
12
|
-
readonly pluginHeader: 'pluginHeader';
|
|
13
|
-
readonly pluginNameText: 'pluginNameText';
|
|
14
|
-
readonly closeBtn: 'closeBtn';
|
|
15
|
-
readonly fixedBtn: 'fixedBtn';
|
|
16
|
-
readonly pluginPanelBox: 'pluginPanelBox';
|
|
17
|
-
readonly rightResizeBox: 'rightResizeBox';
|
|
18
|
-
readonly arrowCursor: 'arrowCursor';
|
|
19
|
-
readonly rightBox: 'rightBox';
|
|
20
|
-
readonly centerBox: 'centerBox';
|
|
21
|
-
readonly subTopToolbarBox: 'subTopToolbarBox';
|
|
22
|
-
readonly canvasBox: 'canvasBox';
|
|
23
|
-
readonly scrollBox: 'scrollBox';
|
|
24
|
-
};
|
|
25
|
-
export = classNames;
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Engine } from '@/index';
|
|
2
|
-
import { AssetPackage, CPage } from '@chamn/model';
|
|
3
|
-
import { i18n } from 'i18next';
|
|
4
|
-
import mitt, { Emitter } from 'mitt';
|
|
5
|
-
import { Workbench } from '../component/Workbench';
|
|
6
|
-
import { CustomI18n } from '../i18n';
|
|
7
|
-
|
|
8
|
-
export type PluginObj = {
|
|
9
|
-
name: string;
|
|
10
|
-
init: (ctx: CPluginCtx) => Promise<void>;
|
|
11
|
-
destroy: (ctx: CPluginCtx) => Promise<void>;
|
|
12
|
-
exports: (ctx: CPluginCtx) => any;
|
|
13
|
-
meta: {
|
|
14
|
-
engine: {
|
|
15
|
-
version: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type CPlugin = PluginObj | ((ctx: CPluginCtx) => PluginObj);
|
|
21
|
-
|
|
22
|
-
type PluginManagerOptions = {
|
|
23
|
-
getWorkbench: () => Workbench;
|
|
24
|
-
emitter: Emitter<any>;
|
|
25
|
-
pageModel: CPage;
|
|
26
|
-
i18n: CustomI18n;
|
|
27
|
-
assets: AssetPackage[];
|
|
28
|
-
engine: Engine;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type CPluginCtx<C = any> = {
|
|
32
|
-
globalEmitter: Emitter<any>;
|
|
33
|
-
config: C;
|
|
34
|
-
pluginManager: PluginManager;
|
|
35
|
-
pluginReadyOk: () => void;
|
|
36
|
-
} & PluginManagerOptions;
|
|
37
|
-
|
|
38
|
-
export type PluginInstance = {
|
|
39
|
-
ctx: CPluginCtx;
|
|
40
|
-
exports: any;
|
|
41
|
-
source: PluginObj;
|
|
42
|
-
ready: boolean;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type CustomPluginHook = (pluginInstance: PluginInstance) => PluginInstance;
|
|
46
|
-
|
|
47
|
-
export class PluginManager {
|
|
48
|
-
plugins: Map<string, PluginInstance> = new Map();
|
|
49
|
-
emitter: Emitter<any> = mitt();
|
|
50
|
-
getWorkbench!: () => Workbench;
|
|
51
|
-
pageModel!: CPage;
|
|
52
|
-
i18n: CustomI18n;
|
|
53
|
-
assets: AssetPackage[];
|
|
54
|
-
engine: Engine;
|
|
55
|
-
customPluginHooks: Record<string, CustomPluginHook[]> = {};
|
|
56
|
-
|
|
57
|
-
constructor({ getWorkbench, emitter, pageModel, i18n, assets, engine }: PluginManagerOptions) {
|
|
58
|
-
this.getWorkbench = getWorkbench;
|
|
59
|
-
this.emitter = emitter;
|
|
60
|
-
this.pageModel = pageModel;
|
|
61
|
-
this.i18n = i18n;
|
|
62
|
-
this.assets = assets;
|
|
63
|
-
this.engine = engine;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
customPlugin = (pluginName: string, customPluginHook: CustomPluginHook) => {
|
|
67
|
-
const customPluginHooks = this.customPluginHooks;
|
|
68
|
-
const hookList = customPluginHooks[pluginName] || [];
|
|
69
|
-
hookList.push(customPluginHook);
|
|
70
|
-
customPluginHooks[pluginName] = hookList;
|
|
71
|
-
this.customPluginHooks = customPluginHooks;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
createPluginCtx = () => {
|
|
75
|
-
const ctx: CPluginCtx = {
|
|
76
|
-
globalEmitter: this.emitter,
|
|
77
|
-
emitter: mitt(),
|
|
78
|
-
config: {},
|
|
79
|
-
getWorkbench: this.getWorkbench,
|
|
80
|
-
pluginManager: this,
|
|
81
|
-
pageModel: this.pageModel,
|
|
82
|
-
i18n: this.i18n,
|
|
83
|
-
assets: this.assets,
|
|
84
|
-
engine: this.engine,
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
86
|
-
pluginReadyOk: () => {},
|
|
87
|
-
};
|
|
88
|
-
return ctx;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
async add(plugin: CPlugin) {
|
|
92
|
-
const ctx = this.createPluginCtx();
|
|
93
|
-
|
|
94
|
-
let innerPlugin: PluginObj;
|
|
95
|
-
if (typeof plugin === 'function') {
|
|
96
|
-
innerPlugin = plugin(ctx);
|
|
97
|
-
} else {
|
|
98
|
-
innerPlugin = plugin;
|
|
99
|
-
}
|
|
100
|
-
let pluginCtx: PluginInstance = {
|
|
101
|
-
source: innerPlugin,
|
|
102
|
-
ctx: ctx,
|
|
103
|
-
exports: innerPlugin.exports?.(ctx) || {},
|
|
104
|
-
ready: false,
|
|
105
|
-
};
|
|
106
|
-
const customHookList = this.customPluginHooks[innerPlugin.name] || [];
|
|
107
|
-
customHookList.forEach((cb) => {
|
|
108
|
-
pluginCtx = cb(pluginCtx);
|
|
109
|
-
});
|
|
110
|
-
ctx.pluginReadyOk = () => {
|
|
111
|
-
this.emitter.emit(`${innerPlugin.name}:ready`);
|
|
112
|
-
pluginCtx.ready = true;
|
|
113
|
-
};
|
|
114
|
-
this.plugins.set(innerPlugin.name, pluginCtx);
|
|
115
|
-
await innerPlugin.init(ctx);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async get(pluginName: string) {
|
|
119
|
-
const pluginInstance = this.plugins.get(pluginName);
|
|
120
|
-
if (pluginInstance?.ready) {
|
|
121
|
-
return pluginInstance;
|
|
122
|
-
} else {
|
|
123
|
-
await this.onPluginReadyOk(pluginName);
|
|
124
|
-
return pluginInstance;
|
|
125
|
-
}
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async remove(name: string) {
|
|
130
|
-
const p = this.plugins.get(name);
|
|
131
|
-
await p?.source.destroy(p.ctx);
|
|
132
|
-
this.plugins.delete(name);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
onPluginReadyOk(pluginName: string, cb?: (pluginHandle: PluginInstance) => void) {
|
|
136
|
-
const pluginObj = this.plugins.get(pluginName);
|
|
137
|
-
if (pluginObj?.ready) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return new Promise<PluginInstance>((resolve) => {
|
|
142
|
-
this.emitter.on(`${pluginName}:ready`, () => {
|
|
143
|
-
if (pluginObj) {
|
|
144
|
-
pluginObj.ready = true;
|
|
145
|
-
cb?.(pluginObj);
|
|
146
|
-
resolve(pluginObj);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
package/src/i18n/en_US/index.ts
DELETED
package/src/i18n/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import i18n from 'i18next';
|
|
2
|
-
import { initReactI18next } from 'react-i18next';
|
|
3
|
-
import { zh_CN } from './zh_CN';
|
|
4
|
-
import { en_US } from './en_US';
|
|
5
|
-
|
|
6
|
-
// the translations
|
|
7
|
-
// (tip move them in a JSON file and import them,
|
|
8
|
-
// or even better, manage them separated from your code: https://react.i18next.com/guides/multiple-translation-files)
|
|
9
|
-
const resources = {
|
|
10
|
-
zh_CN,
|
|
11
|
-
en_US,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
i18n
|
|
15
|
-
.use(initReactI18next) // passes i18n down to react-i18next
|
|
16
|
-
.init({
|
|
17
|
-
resources,
|
|
18
|
-
lng: 'zh_CN', // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
|
|
19
|
-
// you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage
|
|
20
|
-
// if you're using a language detector, do not define the lng option
|
|
21
|
-
react: {
|
|
22
|
-
bindI18n: 'added languageChanged',
|
|
23
|
-
bindI18nStore: 'added',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export type CustomI18n = typeof i18n & {
|
|
28
|
-
update: () => void;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const customI18n: CustomI18n = i18n as any;
|
|
32
|
-
|
|
33
|
-
customI18n.update = () => {
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
i18n.emit('added');
|
|
36
|
-
}, 0);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default customI18n;
|
package/src/i18n/zh_CN/index.ts
DELETED
package/src/index.tsx
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Workbench } from './component/Workbench';
|
|
3
|
-
import styles from './Engine.module.scss';
|
|
4
|
-
import i18n from './i18n/index';
|
|
5
|
-
import { CPlugin, PluginManager } from './core/pluginManager';
|
|
6
|
-
import mitt, { Emitter } from 'mitt';
|
|
7
|
-
import { AssetPackage, CMaterialType, CNode, CPage, CPageDataType, CRootNode, EmptyPage } from '@chamn/model';
|
|
8
|
-
import { defaultRender, beforeInitRender } from './utils/defaultEngineConfig';
|
|
9
|
-
|
|
10
|
-
export type EnginContext = {
|
|
11
|
-
pluginManager: PluginManager;
|
|
12
|
-
engine: Engine;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type EngineProps = {
|
|
16
|
-
plugins: CPlugin[];
|
|
17
|
-
schema: CPageDataType;
|
|
18
|
-
material?: CMaterialType[];
|
|
19
|
-
assetPackagesList?: AssetPackage[];
|
|
20
|
-
beforePluginRun?: (options: { pluginManager: PluginManager }) => void;
|
|
21
|
-
onReady?: (ctx: EnginContext) => void;
|
|
22
|
-
/** 渲染器 umd 格式 js 地址, 默认 ./render.umd.js */
|
|
23
|
-
renderJSUrl?: string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export class Engine extends React.Component<EngineProps> {
|
|
27
|
-
currentSelectNode: CNode | CRootNode | null;
|
|
28
|
-
|
|
29
|
-
pluginManager!: PluginManager;
|
|
30
|
-
workbenchRef = React.createRef<Workbench>();
|
|
31
|
-
pageSchema: CPageDataType | undefined;
|
|
32
|
-
pageModel: CPage;
|
|
33
|
-
material: CMaterialType[] | undefined;
|
|
34
|
-
emitter: Emitter<any>;
|
|
35
|
-
|
|
36
|
-
constructor(props: EngineProps) {
|
|
37
|
-
super(props);
|
|
38
|
-
this.pageSchema = props.schema;
|
|
39
|
-
this.material = props.material;
|
|
40
|
-
this.currentSelectNode = null;
|
|
41
|
-
(window as any).__CHAMELEON_ENG__ = this;
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
this.pageModel = new CPage(this.pageSchema, {
|
|
45
|
-
materials: this.material || [],
|
|
46
|
-
assetPackagesList: props.assetPackagesList || [],
|
|
47
|
-
});
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.error(e);
|
|
50
|
-
this.pageModel = new CPage(EmptyPage);
|
|
51
|
-
}
|
|
52
|
-
this.emitter = mitt();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
updateCurrentSelectNode(node: CNode | CRootNode) {
|
|
56
|
-
this.currentSelectNode = node;
|
|
57
|
-
this.emitter.emit('onSelectNodeChange', {
|
|
58
|
-
node,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async componentDidMount() {
|
|
63
|
-
(window as any).__C_ENGINE__ = this;
|
|
64
|
-
const plugins = this.props.plugins;
|
|
65
|
-
const pluginManager = new PluginManager({
|
|
66
|
-
engine: this,
|
|
67
|
-
getWorkbench: () => this.workbenchRef.current!,
|
|
68
|
-
emitter: this.emitter,
|
|
69
|
-
pageModel: this.pageModel,
|
|
70
|
-
i18n,
|
|
71
|
-
assets: this.props.assetPackagesList || [],
|
|
72
|
-
});
|
|
73
|
-
this.pluginManager = pluginManager;
|
|
74
|
-
// 使用默认的渲染策略
|
|
75
|
-
pluginManager.customPlugin('Designer', (pluginInstance) => {
|
|
76
|
-
pluginInstance.ctx.config.beforeInitRender = beforeInitRender;
|
|
77
|
-
pluginInstance.ctx.config.customRender = defaultRender;
|
|
78
|
-
return pluginInstance;
|
|
79
|
-
});
|
|
80
|
-
this.props.beforePluginRun?.({
|
|
81
|
-
pluginManager: this.pluginManager,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const pList = plugins.map((p) => {
|
|
85
|
-
return this.pluginManager.add(p);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await Promise.all(pList);
|
|
89
|
-
|
|
90
|
-
this.pageModel.emitter.on('onReloadPage', () => {
|
|
91
|
-
if (!this.currentSelectNode) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const newSelectNode = this.pageModel.getNode(this.currentSelectNode?.id);
|
|
95
|
-
if (newSelectNode) {
|
|
96
|
-
this.updateCurrentSelectNode(newSelectNode);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
this.props.onReady?.({
|
|
101
|
-
pluginManager: this.pluginManager,
|
|
102
|
-
engine: this,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
getActiveNode() {
|
|
107
|
-
if (!this.currentSelectNode?.id) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
const node = this.pageModel.getNode(this.currentSelectNode.id);
|
|
111
|
-
this.currentSelectNode = node;
|
|
112
|
-
return node;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
updatePage = (page: CPageDataType) => {
|
|
116
|
-
this.emitter.emit('updatePage');
|
|
117
|
-
console.log(page);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
updateDesignerAssets = (assets: AssetPackage[]) => {
|
|
121
|
-
console.log('updateDesignerAssets', assets);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
updateMaterial = (material: CMaterialType[]) => {
|
|
125
|
-
this.emitter.emit('updateMaterial');
|
|
126
|
-
console.log(material);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
refresh = () => {
|
|
130
|
-
this.emitter.emit('refresh');
|
|
131
|
-
console.log('refresh engine');
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
getWorkbench = () => {
|
|
135
|
-
return this.workbenchRef.current;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
render() {
|
|
139
|
-
return (
|
|
140
|
-
<div className={styles.engineContainer}>
|
|
141
|
-
<Workbench ref={this.workbenchRef} emitter={this.emitter} />
|
|
142
|
-
</div>
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export * as plugins from './plugins';
|
|
148
|
-
export * from '@chamn/layout';
|
|
149
|
-
|
|
150
|
-
export * from './material/innerMaterial';
|