@chamn/engine 0.0.1 → 0.0.2

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.
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { Workbench } from './component/Workbench';
3
+ import { CPlugin, PluginManager } from './core/pluginManager';
4
+ import { Emitter } from 'mitt';
5
+ import { AssetPackage, CMaterialType, CNode, CPage, CPageDataType, CRootNode } from '@chamn/model';
6
+ export type EnginContext = {
7
+ pluginManager: PluginManager;
8
+ engine: Engine;
9
+ };
10
+ export type EngineProps = {
11
+ plugins: CPlugin[];
12
+ schema: CPageDataType;
13
+ material?: CMaterialType[];
14
+ assets?: AssetPackage[];
15
+ assetPackagesList?: AssetPackage[];
16
+ beforePluginRun?: (options: {
17
+ pluginManager: PluginManager;
18
+ }) => void;
19
+ onReady?: (ctx: EnginContext) => void;
20
+ };
21
+ declare class Engine extends React.Component<EngineProps> {
22
+ currentSelectNode: CNode | CRootNode | null;
23
+ pluginManager: PluginManager;
24
+ workbenchRef: React.RefObject<Workbench>;
25
+ pageSchema: CPageDataType | undefined;
26
+ pageModel: CPage;
27
+ material: CMaterialType[] | undefined;
28
+ emitter: Emitter<any>;
29
+ constructor(props: EngineProps);
30
+ updateCurrentSelectNode(node: CNode | CRootNode): void;
31
+ componentDidMount(): Promise<void>;
32
+ getActiveNode(): CNode | CRootNode | null;
33
+ updatePage: (page: CPageDataType) => void;
34
+ updateDesignerAssets: (assets: AssetPackage[]) => void;
35
+ updateMaterial: (material: CMaterialType[]) => void;
36
+ refresh: () => void;
37
+ getWorkbench: () => Workbench | null;
38
+ render(): JSX.Element;
39
+ }
40
+ export default Engine;
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { ResizeCallback } from 're-resizable';
3
+ import { Emitter } from 'mitt';
4
+ export interface PluginContext {
5
+ openPanel: () => void;
6
+ closePanel: () => void;
7
+ getPlugin: (pluginName: string) => any;
8
+ emitter: Emitter<any>;
9
+ }
10
+ type PanelItem = {
11
+ name: string;
12
+ title: string | React.ReactNode;
13
+ icon: React.ReactNode;
14
+ render: React.ReactNode;
15
+ };
16
+ type WorkbenchStateType = {
17
+ leftBoxVisible: boolean;
18
+ leftBoxSize: {
19
+ width: number;
20
+ height: number | string;
21
+ };
22
+ leftBoxFixed: boolean;
23
+ rightBoxSize: {
24
+ width: number;
25
+ height: number | string;
26
+ };
27
+ rightBoxVisible: boolean;
28
+ currentActiveLeftPanel: string;
29
+ leftPanels: PanelItem[];
30
+ bodyView: React.ReactNode | null;
31
+ rightView: React.ReactNode | null;
32
+ topToolBarView: React.ReactNode | null;
33
+ };
34
+ export type WorkbenchPropsType = {
35
+ emitter: Emitter<any>;
36
+ };
37
+ export declare class Workbench extends React.Component<WorkbenchPropsType, WorkbenchStateType> {
38
+ emitter: Emitter<any>;
39
+ leftPanelContentRef: React.RefObject<HTMLDivElement>;
40
+ constructor(props: WorkbenchPropsType);
41
+ addLeftPanel: (panel: PanelItem) => void;
42
+ openLeftPanel: (currentActiveLeftPanel?: string) => Promise<void>;
43
+ closeLeftPanel: () => Promise<void>;
44
+ toggleLeftPanel: () => void;
45
+ onPluginIconClick: (panel: PanelItem) => void;
46
+ openRightPanel: () => void;
47
+ closeRightPanel: () => void;
48
+ replaceBodyView: (newView: React.ReactNode) => void;
49
+ replaceRightView: (newView: React.ReactNode) => void;
50
+ replaceTopBarView: (newView: React.ReactNode) => void;
51
+ toggleRightPanel: () => void;
52
+ onLeftBoxResizeStop: ResizeCallback;
53
+ onGlobalClick: (e: MouseEvent) => void;
54
+ componentDidMount(): void;
55
+ render(): JSX.Element;
56
+ }
57
+ export {};
@@ -0,0 +1,56 @@
1
+ import Engine from '../Engine';
2
+ import { AssetPackage, CPage } from '@chamn/model';
3
+ import { Emitter } from 'mitt';
4
+ import { Workbench } from '../component/Workbench';
5
+ import { CustomI18n } from '../i18n';
6
+ export type PluginObj = {
7
+ name: string;
8
+ init: (ctx: CPluginCtx) => Promise<void>;
9
+ destroy: (ctx: CPluginCtx) => Promise<void>;
10
+ exports: (ctx: CPluginCtx) => any;
11
+ meta: {
12
+ engine: {
13
+ version: string;
14
+ };
15
+ };
16
+ };
17
+ export type CPlugin = PluginObj | ((ctx: CPluginCtx) => PluginObj);
18
+ type PluginManagerOptions = {
19
+ getWorkbench: () => Workbench;
20
+ emitter: Emitter<any>;
21
+ pageModel: CPage;
22
+ i18n: CustomI18n;
23
+ assets: AssetPackage[];
24
+ engine: Engine;
25
+ };
26
+ export type CPluginCtx<C = any> = {
27
+ globalEmitter: Emitter<any>;
28
+ config: C;
29
+ pluginManager: PluginManager;
30
+ pluginReadyOk: () => void;
31
+ } & PluginManagerOptions;
32
+ export type PluginInstance = {
33
+ ctx: CPluginCtx;
34
+ exports: any;
35
+ source: PluginObj;
36
+ ready: boolean;
37
+ };
38
+ export type CustomPluginHook = (pluginInstance: PluginInstance) => PluginInstance;
39
+ export declare class PluginManager {
40
+ plugins: Map<string, PluginInstance>;
41
+ emitter: Emitter<any>;
42
+ getWorkbench: () => Workbench;
43
+ pageModel: CPage;
44
+ i18n: CustomI18n;
45
+ assets: AssetPackage[];
46
+ engine: Engine;
47
+ customPluginHooks: Record<string, CustomPluginHook[]>;
48
+ constructor({ getWorkbench, emitter, pageModel, i18n, assets, engine }: PluginManagerOptions);
49
+ customPlugin: (pluginName: string, customPluginHook: CustomPluginHook) => void;
50
+ createPluginCtx: () => CPluginCtx<any>;
51
+ add(plugin: CPlugin): Promise<void>;
52
+ get(pluginName: string): Promise<PluginInstance | undefined>;
53
+ remove(name: string): Promise<void>;
54
+ onPluginReadyOk(pluginName: string, cb?: (pluginHandle: PluginInstance) => void): Promise<PluginInstance> | undefined;
55
+ }
56
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare const en_US: {
2
+ translation: {
3
+ 'Welcome to React': string;
4
+ };
5
+ };
@@ -0,0 +1,6 @@
1
+ import i18n from 'i18next';
2
+ export type CustomI18n = typeof i18n & {
3
+ update: () => void;
4
+ };
5
+ declare const customI18n: CustomI18n;
6
+ export default customI18n;
@@ -0,0 +1,5 @@
1
+ export declare const zh_CN: {
2
+ translation: {
3
+ 'Welcome to React': string;
4
+ };
5
+ };
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ ._workbenchContainer_1b5xq_2{width:100%;height:100%;display:flex;flex-direction:column}._workbenchContainer_1b5xq_2 ._topToolBarBox_1b5xq_8{height:64px;width:100%;border-bottom:1px solid rgb(233,233,233);display:flex}._workbenchContainer_1b5xq_2 ._topToolBarBox_1b5xq_8 ._logo_1b5xq_14{height:100%;font-size:20px;display:flex;align-items:center;margin-left:20px;font-weight:bolder}._workbenchContainer_1b5xq_2 ._topToolBarBox_1b5xq_8 ._topToolBarView_1b5xq_22{flex:1}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25{display:flex;width:100%;flex:1;overflow:hidden}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31{position:relative;display:flex;background-color:#fff;z-index:100}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginIconBar_1b5xq_37{width:50px;height:100%;border-right:1px solid rgb(233,233,233)}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginIconBar_1b5xq_37 ._pluginIconItem_1b5xq_42{position:relative;cursor:pointer;width:50px;height:50px;display:flex;align-items:center;justify-content:center;transition:all .1s}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginIconBar_1b5xq_37 ._pluginIconItem_1b5xq_42._active_1b5xq_52 :before,._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginIconBar_1b5xq_37 ._pluginIconItem_1b5xq_42:hover :before{transition:all .1s;display:block;content:"";width:2px;height:100%;position:absolute;left:0;top:0}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginIconBar_1b5xq_37 ._pluginIconItem_1b5xq_42._active_1b5xq_52 :before{border-left:4px solid #1677ff!important}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginIconBar_1b5xq_37 ._pluginIconItem_1b5xq_42:hover :before{border-left:4px solid rgba(22,119,255,.3)}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68{display:flex;flex-direction:column;background-color:#fff;z-index:100;border-right:1px solid rgb(233,233,233)}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68 ._pluginHeader_1b5xq_75{display:flex;color:#686868;height:30px;margin:10px;overflow:hidden;align-items:center}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68 ._pluginHeader_1b5xq_75 ._pluginNameText_1b5xq_83{font-size:16px;font-weight:700;margin-right:auto;flex-wrap:nowrap;word-break:keep-all}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68 ._pluginHeader_1b5xq_75 ._closeBtn_1b5xq_90,._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68 ._pluginHeader_1b5xq_75 ._fixedBtn_1b5xq_91{color:#686868}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68 ._pluginHeader_1b5xq_75 ._fixedBtn_1b5xq_91>*{transition:all .1s}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBoxResizeBox_1b5xq_68 ._pluginHeader_1b5xq_75 ._fixedBtn_1b5xq_91>._active_1b5xq_52{transform:rotate(-45deg)}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._leftBox_1b5xq_31 ._pluginPanelBox_1b5xq_68{width:100%;flex:1;background-color:#f8f8ff;overflow:hidden}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._rightResizeBox_1b5xq_106{position:relative}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._rightResizeBox_1b5xq_106 ._arrowCursor_1b5xq_109{cursor:pointer;position:absolute;left:-18px;top:50%;transform:translateY(-50%);z-index:2;background-color:#fff;padding:10px 3px;border-radius:4px 0 0 4px;font-size:12px}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._rightResizeBox_1b5xq_106 ._arrowCursor_1b5xq_109>._active_1b5xq_52{transform:rotate(-180deg)}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._rightResizeBox_1b5xq_106 ._rightBox_1b5xq_124{position:relative;width:100%;height:100%;border-left:1px rgb(233,233,233) solid}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._centerBox_1b5xq_130{display:flex;flex-direction:column;flex:1;overflow:hidden}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._centerBox_1b5xq_130 ._subTopToolbarBox_1b5xq_136{width:100%;height:50px;background-color:#fff}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._centerBox_1b5xq_130 ._canvasBox_1b5xq_141{width:100%;flex:1;overflow:hidden;padding:20px 30px;background-color:#edeff3}._workbenchContainer_1b5xq_2 ._bodyContent_1b5xq_25 ._centerBox_1b5xq_130 ._canvasBox_1b5xq_141 ._scrollBox_1b5xq_148{width:100%;height:100%;box-shadow:0 1px 4px #1f325821}._engineContainer_f3ly9_2{color:#686868;font-size:14px;width:100%;height:100%;overflow:hidden}._engineContainer_f3ly9_2 *{box-sizing:border-box}
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param time 毫秒
4
+ * @returns
5
+ */
6
+ export declare const waitReactUpdate: (time?: number) => Promise<unknown>;
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chamn/engine",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@ant-design/icons": "^4.8.0",
21
- "@chamn/layout": "0.0.1",
22
- "@chamn/model": "0.0.1",
23
- "@chamn/render": "0.0.1",
21
+ "@chamn/layout": "0.0.2",
22
+ "@chamn/model": "0.0.2",
23
+ "@chamn/render": "0.0.2",
24
24
  "@dnd-kit/core": "^6.0.7",
25
25
  "@dnd-kit/modifiers": "^6.0.1",
26
26
  "@dnd-kit/sortable": "^7.0.2",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@babel/core": "^7.21.0",
43
- "@chamn/build-script": "0.0.1",
44
- "@chamn/demo-page": "0.0.1",
43
+ "@chamn/build-script": "0.0.2",
44
+ "@chamn/demo-page": "0.0.2",
45
45
  "@storybook/addon-actions": "^6.5.16",
46
46
  "@storybook/addon-essentials": "^6.5.16",
47
47
  "@storybook/addon-interactions": "^6.5.16",
@@ -63,5 +63,5 @@
63
63
  "vite-plugin-monaco-editor": "^1.1.0"
64
64
  },
65
65
  "config": {},
66
- "gitHead": "c8d421b3e2addf2ba311aebf9af65e5b161e94d2"
66
+ "gitHead": "c31f7abd436ccdf79c549d0475ca6c012e778ddb"
67
67
  }