@chamn/engine 0.0.7 → 0.0.9
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/CHANGELOG.md +18 -0
- package/README.md +2 -2
- package/build.config.js +16 -2
- package/dist/index.cjs.js +90 -362
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +17844 -46121
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +10 -9
- package/public/component/Workbench/style.module.scss.d.ts +0 -1
- package/src/_dev_/index.css +10 -0
- package/src/_dev_/page/Editor/index.tsx +9 -86
- package/src/_dev_/page/Editor/indexCustom.tsx +274 -0
- package/src/_dev_/page/Preview/index.tsx +38 -6
- package/src/_dev_/router.tsx +0 -1
- package/src/component/Workbench/index.tsx +0 -2
- package/src/component/Workbench/style.module.scss +0 -8
- package/src/component/Workbench/style.module.scss.d.ts +0 -1
- package/src/index.tsx +12 -4
- package/src/plugins/Designer/util.ts +1 -1
- package/src/plugins/Designer/view.tsx +5 -3
- package/src/utils/defaultEngineConfig.tsx +55 -0
- package/dist/Engine.module.scss.d.ts +0 -5
- package/dist/component/CSSEditor/index.d.ts +0 -16
- package/dist/component/CSSEditor/style.module.scss.d.ts +0 -6
- package/dist/component/CSSPropertiesEditor/cssProperties.d.ts +0 -898
- package/dist/component/CSSPropertiesEditor/index.d.ts +0 -43
- package/dist/component/CSSPropertiesEditor/style.module.scss.d.ts +0 -15
- package/dist/component/CSSPropertiesEditor/util.d.ts +0 -1
- package/dist/component/CSSPropertiesVariableBindEditor/cssProperties.d.ts +0 -898
- package/dist/component/CSSPropertiesVariableBindEditor/index.d.ts +0 -37
- package/dist/component/CSSPropertiesVariableBindEditor/style.module.scss.d.ts +0 -15
- package/dist/component/CSSPropertiesVariableBindEditor/util.d.ts +0 -1
- package/dist/component/ClassNameEditor/index.d.ts +0 -16
- package/dist/component/CustomSchemaForm/components/Form/Field/index.d.ts +0 -11
- package/dist/component/CustomSchemaForm/components/Form/Field/style.module.scss.d.ts +0 -8
- package/dist/component/CustomSchemaForm/components/Form/context.d.ts +0 -10
- package/dist/component/CustomSchemaForm/components/Form/index.d.ts +0 -17
- package/dist/component/CustomSchemaForm/components/SetterSwitcher/index.d.ts +0 -12
- package/dist/component/CustomSchemaForm/components/SetterSwitcher/style.module.scss.d.ts +0 -7
- package/dist/component/CustomSchemaForm/components/Setters/ArraySetter/ArrayItem.d.ts +0 -11
- package/dist/component/CustomSchemaForm/components/Setters/ArraySetter/SortItemOrderModal.d.ts +0 -10
- package/dist/component/CustomSchemaForm/components/Setters/ArraySetter/index.d.ts +0 -14
- package/dist/component/CustomSchemaForm/components/Setters/ArraySetter/style.module.scss.d.ts +0 -7
- package/dist/component/CustomSchemaForm/components/Setters/BooleanSetter/index.d.ts +0 -5
- package/dist/component/CustomSchemaForm/components/Setters/CSSValueSetter/index.d.ts +0 -6
- package/dist/component/CustomSchemaForm/components/Setters/CSSValueSetter/style.module.scss.d.ts +0 -6
- package/dist/component/CustomSchemaForm/components/Setters/ExpressionSetter/index.d.ts +0 -8
- package/dist/component/CustomSchemaForm/components/Setters/FunctionSetter/defaultDts.d.ts +0 -1
- package/dist/component/CustomSchemaForm/components/Setters/FunctionSetter/index.d.ts +0 -2
- package/dist/component/CustomSchemaForm/components/Setters/JSONSetter/index.d.ts +0 -2
- package/dist/component/CustomSchemaForm/components/Setters/NumberSetter/index.d.ts +0 -3
- package/dist/component/CustomSchemaForm/components/Setters/SelectSetter/index.d.ts +0 -3
- package/dist/component/CustomSchemaForm/components/Setters/ShapeSetter/index.d.ts +0 -8
- package/dist/component/CustomSchemaForm/components/Setters/StringSetter/index.d.ts +0 -3
- package/dist/component/CustomSchemaForm/components/Setters/TextAreaSetter/index.d.ts +0 -3
- package/dist/component/CustomSchemaForm/components/Setters/index.d.ts +0 -3
- package/dist/component/CustomSchemaForm/components/Setters/type.d.ts +0 -19
- package/dist/component/CustomSchemaForm/context.d.ts +0 -15
- package/dist/component/CustomSchemaForm/index.d.ts +0 -17
- package/dist/component/CustomSchemaForm/style.module.scss.d.ts +0 -11
- package/dist/component/CustomSchemaForm/utils.d.ts +0 -2
- package/dist/component/MonacoEditor/index.d.ts +0 -15
- package/dist/component/Workbench/index.d.ts +0 -57
- package/dist/component/Workbench/style.module.scss.d.ts +0 -26
- package/dist/core/pluginManager.d.ts +0 -56
- package/dist/i18n/en_US/index.d.ts +0 -5
- package/dist/i18n/index.d.ts +0 -6
- package/dist/i18n/zh_CN/index.d.ts +0 -5
- package/dist/index.d.ts +0 -42
- package/dist/material/innerMaterial.d.ts +0 -2
- package/dist/monacoeditorwork/css.worker.bundle.js +0 -45072
- package/dist/monacoeditorwork/editor.worker.bundle.js +0 -8294
- package/dist/monacoeditorwork/html.worker.bundle.js +0 -24321
- package/dist/monacoeditorwork/json.worker.bundle.js +0 -15550
- package/dist/monacoeditorwork/ts.worker.bundle.js +0 -169967
- package/dist/plugins/AdvancePanel/index.d.ts +0 -10
- package/dist/plugins/AdvancePanel/style.module.scss.d.ts +0 -7
- package/dist/plugins/ComponentLibrary/components/DragItem/index.d.ts +0 -12
- package/dist/plugins/ComponentLibrary/components/DragItem/style.module.scss.d.ts +0 -9
- package/dist/plugins/ComponentLibrary/components/ListView/index.d.ts +0 -9
- package/dist/plugins/ComponentLibrary/components/ListView/style.module.scss.d.ts +0 -12
- package/dist/plugins/ComponentLibrary/index.d.ts +0 -3
- package/dist/plugins/ComponentLibrary/localize/en_US/index.d.ts +0 -1
- package/dist/plugins/ComponentLibrary/localize/index.d.ts +0 -2
- package/dist/plugins/ComponentLibrary/localize/zh_CN/index.d.ts +0 -1
- package/dist/plugins/ComponentLibrary/style.module.scss.d.ts +0 -11
- package/dist/plugins/ComponentLibrary/util.d.ts +0 -1
- package/dist/plugins/ComponentStatePanel/index.d.ts +0 -10
- package/dist/plugins/Designer/components/DefaultSelectToolBar/index.d.ts +0 -10
- package/dist/plugins/Designer/components/DefaultSelectToolBar/style.module.scss.d.ts +0 -11
- package/dist/plugins/Designer/components/GhostView/index.d.ts +0 -5
- package/dist/plugins/Designer/config.d.ts +0 -1
- package/dist/plugins/Designer/index.d.ts +0 -15
- package/dist/plugins/Designer/localize/en_US/index.d.ts +0 -1
- package/dist/plugins/Designer/localize/index.d.ts +0 -2
- package/dist/plugins/Designer/localize/zh_CN/index.d.ts +0 -1
- package/dist/plugins/Designer/style.module.scss.d.ts +0 -5
- package/dist/plugins/Designer/util.d.ts +0 -2
- package/dist/plugins/Designer/view.d.ts +0 -30
- package/dist/plugins/DisplaySourceSchema/index.d.ts +0 -9
- package/dist/plugins/GlobalStatePanel/index.d.ts +0 -3
- package/dist/plugins/GlobalStatePanel/localize/en_US/index.d.ts +0 -1
- package/dist/plugins/GlobalStatePanel/localize/index.d.ts +0 -2
- package/dist/plugins/GlobalStatePanel/localize/zh_CN/index.d.ts +0 -1
- package/dist/plugins/GlobalStatePanel/style.module.scss.d.ts +0 -5
- package/dist/plugins/History/index.d.ts +0 -2
- package/dist/plugins/OutlineTree/components/TreeView/context.d.ts +0 -30
- package/dist/plugins/OutlineTree/components/TreeView/dataStruct.d.ts +0 -21
- package/dist/plugins/OutlineTree/components/TreeView/index.d.ts +0 -34
- package/dist/plugins/OutlineTree/components/TreeView/style.module.scss.d.ts +0 -16
- package/dist/plugins/OutlineTree/components/TreeView/treeNode.d.ts +0 -9
- package/dist/plugins/OutlineTree/index.d.ts +0 -3
- package/dist/plugins/OutlineTree/localize/en_US/index.d.ts +0 -1
- package/dist/plugins/OutlineTree/localize/index.d.ts +0 -2
- package/dist/plugins/OutlineTree/localize/zh_CN/index.d.ts +0 -1
- package/dist/plugins/OutlineTree/util.d.ts +0 -15
- package/dist/plugins/PropertyPanel/index.d.ts +0 -9
- package/dist/plugins/PropertyPanel/style.module.scss.d.ts +0 -10
- package/dist/plugins/RightPanel/index.d.ts +0 -2
- package/dist/plugins/RightPanel/style.module.scss.d.ts +0 -10
- package/dist/plugins/RightPanel/view.d.ts +0 -34
- package/dist/plugins/VisualPanelPlus/index.d.ts +0 -9
- package/dist/plugins/VisualPanelPlus/style.module.scss.d.ts +0 -10
- package/dist/plugins/index.d.ts +0 -9
- package/dist/utils/css.d.ts +0 -19
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/logger.d.ts +0 -1
package/src/index.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import i18n from './i18n/index';
|
|
|
5
5
|
import { CPlugin, PluginManager } from './core/pluginManager';
|
|
6
6
|
import mitt, { Emitter } from 'mitt';
|
|
7
7
|
import { AssetPackage, CMaterialType, CNode, CPage, CPageDataType, CRootNode, EmptyPage } from '@chamn/model';
|
|
8
|
+
import { defaultRender, beforeInitRender } from './utils/defaultEngineConfig';
|
|
8
9
|
|
|
9
10
|
export type EnginContext = {
|
|
10
11
|
pluginManager: PluginManager;
|
|
@@ -15,10 +16,11 @@ export type EngineProps = {
|
|
|
15
16
|
plugins: CPlugin[];
|
|
16
17
|
schema: CPageDataType;
|
|
17
18
|
material?: CMaterialType[];
|
|
18
|
-
assets?: AssetPackage[];
|
|
19
19
|
assetPackagesList?: AssetPackage[];
|
|
20
20
|
beforePluginRun?: (options: { pluginManager: PluginManager }) => void;
|
|
21
21
|
onReady?: (ctx: EnginContext) => void;
|
|
22
|
+
/** 渲染器 umd 格式 js 地址, 默认 ./render.umd.js */
|
|
23
|
+
renderJSUrl?: string;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export class Engine extends React.Component<EngineProps> {
|
|
@@ -60,15 +62,21 @@ export class Engine extends React.Component<EngineProps> {
|
|
|
60
62
|
async componentDidMount() {
|
|
61
63
|
(window as any).__C_ENGINE__ = this;
|
|
62
64
|
const plugins = this.props.plugins;
|
|
63
|
-
|
|
65
|
+
const pluginManager = new PluginManager({
|
|
64
66
|
engine: this,
|
|
65
67
|
getWorkbench: () => this.workbenchRef.current!,
|
|
66
68
|
emitter: this.emitter,
|
|
67
69
|
pageModel: this.pageModel,
|
|
68
70
|
i18n,
|
|
69
|
-
assets: this.props.
|
|
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;
|
|
70
79
|
});
|
|
71
|
-
|
|
72
80
|
this.props.beforePluginRun?.({
|
|
73
81
|
pluginManager: this.pluginManager,
|
|
74
82
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CNode, CPage, CProp, CRootNode, CSlot, isNodeModel } from '@chamn/model';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const getClosestNodeList = (node: CNode | CRootNode, level = 5) => {
|
|
4
4
|
const res = [];
|
|
5
5
|
let count = 0;
|
|
6
6
|
let currentNode: CNode | CRootNode | CSlot | CProp | CPage | null = node;
|
|
@@ -5,7 +5,7 @@ import { CPluginCtx } from '../../core/pluginManager';
|
|
|
5
5
|
import localize from './localize';
|
|
6
6
|
import { PLUGIN_NAME } from './config';
|
|
7
7
|
import { DefaultSelectToolBar } from './components/DefaultSelectToolBar';
|
|
8
|
-
import {
|
|
8
|
+
import { getClosestNodeList } from './util';
|
|
9
9
|
import { GhostView } from './components/GhostView';
|
|
10
10
|
|
|
11
11
|
import styles from './style.module.scss';
|
|
@@ -128,7 +128,7 @@ export class Designer extends React.Component<DesignerPropsType, DesignerStateTy
|
|
|
128
128
|
const { pluginCtx } = this.props;
|
|
129
129
|
pluginCtx.engine.updateCurrentSelectNode(node);
|
|
130
130
|
const pageModel = this.props.pluginCtx.pageModel;
|
|
131
|
-
const list =
|
|
131
|
+
const list = getClosestNodeList(node, 5);
|
|
132
132
|
const { layoutRef } = this;
|
|
133
133
|
this.setState({
|
|
134
134
|
selectToolBar: (
|
|
@@ -200,13 +200,15 @@ export class Designer extends React.Component<DesignerPropsType, DesignerStateTy
|
|
|
200
200
|
render() {
|
|
201
201
|
const { layoutRef, props, onSelectNode, onDragStart, onHoverNode } = this;
|
|
202
202
|
const { pageModel, hoverToolBar, selectToolBar, ghostView, assets } = this.state;
|
|
203
|
+
const { pluginCtx } = props;
|
|
204
|
+
const renderJSUrl = pluginCtx.engine.props.renderJSUrl || './render.umd.js';
|
|
203
205
|
return (
|
|
204
206
|
<Layout
|
|
205
207
|
beforeInitRender={props.pluginCtx.config.beforeInitRender}
|
|
206
208
|
customRender={props.pluginCtx.config.customRender}
|
|
207
209
|
ref={layoutRef}
|
|
208
210
|
pageModel={pageModel}
|
|
209
|
-
|
|
211
|
+
renderJSUrl={renderJSUrl}
|
|
210
212
|
{...props}
|
|
211
213
|
hoverToolBar={hoverToolBar}
|
|
212
214
|
selectToolBar={selectToolBar}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { LayoutPropsType, collectVariable, flatObject } from '@chamn/layout';
|
|
2
|
+
|
|
3
|
+
/** 默认使用 react 18 模式渲染 */
|
|
4
|
+
export const beforeInitRender: LayoutPropsType['beforeInitRender'] = async ({ iframe }) => {
|
|
5
|
+
const subWin = iframe.getWindow();
|
|
6
|
+
if (!subWin) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
(subWin as any).React = window.React;
|
|
10
|
+
(subWin as any).ReactDOM = window.ReactDOM;
|
|
11
|
+
(subWin as any).ReactDOMClient = (window as any).ReactDOMClient;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** 默认使用 react 18 模式渲染 */
|
|
15
|
+
export const defaultRender: LayoutPropsType['customRender'] = async ({
|
|
16
|
+
iframe: iframeContainer,
|
|
17
|
+
assets,
|
|
18
|
+
page,
|
|
19
|
+
pageModel,
|
|
20
|
+
ready,
|
|
21
|
+
renderJSUrl,
|
|
22
|
+
}) => {
|
|
23
|
+
await iframeContainer.injectJS(renderJSUrl || '');
|
|
24
|
+
const iframeWindow = iframeContainer.getWindow()!;
|
|
25
|
+
const iframeDoc = iframeContainer.getDocument()!;
|
|
26
|
+
const IframeReact = iframeWindow.React!;
|
|
27
|
+
const IframeReactDOM = iframeWindow.ReactDOMClient!;
|
|
28
|
+
const CRender = iframeWindow.CRender!;
|
|
29
|
+
|
|
30
|
+
// 注入组件物料资源
|
|
31
|
+
const assetLoader = new CRender.AssetLoader(assets, {
|
|
32
|
+
window: iframeContainer.getWindow()!,
|
|
33
|
+
});
|
|
34
|
+
assetLoader
|
|
35
|
+
.onSuccess(() => {
|
|
36
|
+
// 从子窗口获取物料对象
|
|
37
|
+
const componentCollection = collectVariable(assets, iframeWindow);
|
|
38
|
+
const components = flatObject(componentCollection);
|
|
39
|
+
|
|
40
|
+
const App = IframeReact?.createElement(CRender.DesignRender, {
|
|
41
|
+
adapter: CRender?.ReactAdapter,
|
|
42
|
+
page: page,
|
|
43
|
+
pageModel: pageModel,
|
|
44
|
+
components,
|
|
45
|
+
onMount: (designRenderInstance) => {
|
|
46
|
+
ready(designRenderInstance);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
IframeReactDOM.createRoot(iframeDoc.getElementById('app')!).render(App);
|
|
50
|
+
})
|
|
51
|
+
.onError(() => {
|
|
52
|
+
console.log('资源加载出粗');
|
|
53
|
+
})
|
|
54
|
+
.load();
|
|
55
|
+
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react';
|
|
2
|
-
declare const DOM_CSS_STATUS: ("normal" | "hover" | "focus" | "focus-within" | "focus-visible" | "checked" | "disable" | "active")[];
|
|
3
|
-
type DomCSSStatusType = typeof DOM_CSS_STATUS[number];
|
|
4
|
-
export type CSSVal = Partial<Record<DomCSSStatusType, Record<
|
|
5
|
-
/** media query key */
|
|
6
|
-
string, Record<string, string>>>>;
|
|
7
|
-
export type CSSEditorRef = {
|
|
8
|
-
setValue: (val: CSSVal) => void;
|
|
9
|
-
};
|
|
10
|
-
export type CSSEditorProps = {
|
|
11
|
-
onValueChange?: (val: CSSVal) => void;
|
|
12
|
-
initialValue?: CSSVal;
|
|
13
|
-
handler?: MutableRefObject<CSSEditorRef | null>;
|
|
14
|
-
};
|
|
15
|
-
export declare const CSSEditor: (props: CSSEditorProps) => JSX.Element;
|
|
16
|
-
export {};
|