Skip to content

Commit

Permalink
refactor: move common to shell
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLian authored and liujuping committed Nov 30, 2022
1 parent f49c629 commit b664663
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 119 deletions.
34 changes: 15 additions & 19 deletions packages/engine/src/engine-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
LowCodePluginManager,
ILowCodePluginContext,
PluginPreference,
TransformStage,
} from '@alilc/lowcode-designer';
import {
Skeleton as InnerSkeleton,
Expand All @@ -16,15 +15,21 @@ import {

import Outline, { OutlineBackupPane, getTreeMaster } from '@alilc/lowcode-plugin-outline-pane';
import DesignerPlugin from '@alilc/lowcode-plugin-designer';
import { Hotkey, Project, Skeleton, Setters, Material, Event, DocumentModel } from '@alilc/lowcode-shell';
import {
Hotkey,
Project,
Skeleton,
Setters,
Material,
Event,
DocumentModel,
Common,
} from '@alilc/lowcode-shell';
import { getLogger, isPlainObject } from '@alilc/lowcode-utils';
import './modules/live-editing';
import utils from './modules/utils';
import * as editorCabin from './modules/editor-cabin';
import getSkeletonCabin from './modules/skeleton-cabin';
import getDesignerCabin from './modules/designer-cabin';
import classes from './modules/classes';
import symbols from './modules/symbols';

export * from './modules/editor-types';
export * from './modules/skeleton-types';
export * from './modules/designer-types';
Expand All @@ -46,8 +51,6 @@ const plugins = new LowCodePluginManager(editor).toProxy();
editor.set('plugins' as any, plugins);

const { project: innerProject } = designer;
const skeletonCabin = getSkeletonCabin(innerSkeleton);
const { Workbench } = skeletonCabin;

const hotkey = new Hotkey();
const project = new Project(innerProject);
Expand All @@ -57,17 +60,7 @@ const material = new Material(editor);
const config = engineConfig;
const event = new Event(editor, { prefix: 'common' });
const logger = getLogger({ level: 'warn', bizName: 'common' });
const designerCabin = getDesignerCabin(editor);
const objects = {
TransformStage,
};
const common = {
utils,
objects,
editorCabin,
designerCabin,
skeletonCabin,
};
const common = new Common(editor, innerSkeleton);

export {
skeleton,
Expand Down Expand Up @@ -189,6 +182,7 @@ let engineContainer: HTMLElement;
// @ts-ignore webpack Define variable
export const version = VERSION_PLACEHOLDER;
engineConfig.set('ENGINE_VERSION', version);

export async function init(
container?: HTMLElement,
options?: EngineOptions,
Expand All @@ -213,6 +207,8 @@ export async function init(
engineConfig.setEngineOptions(engineOptions as any);

await plugins.init(pluginPreference as any);

const { Workbench } = common.skeletonCabin;
render(
createElement(Workbench, {
skeleton: innerSkeleton,
Expand Down
50 changes: 0 additions & 50 deletions packages/engine/src/modules/designer-cabin.ts

This file was deleted.

15 changes: 0 additions & 15 deletions packages/engine/src/modules/editor-cabin.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/engine/src/modules/skeleton-cabin.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions packages/engine/src/modules/utils.ts

This file was deleted.

183 changes: 183 additions & 0 deletions packages/shell/src/common.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import { editorSymbol, skeletonSymbol, designerCabinSymbol } from './symbols';
import {
isFormEvent as innerIsFormEvent,
compatibleLegaoSchema as innerCompatibleLegaoSchema,
getNodeSchemaById as innerGetNodeSchemaById,
transactionManager,
} from '@alilc/lowcode-utils';
import {
isNodeSchema as innerIsNodeSchema,
NodeSchema,
TransitionType,
} from '@alilc/lowcode-types';
import {
SettingField,
isSettingField,
Designer,
TransformStage,
LiveEditing,
isDragNodeDataObject,
isDragNodeObject,
isDragAnyObject,
DragObjectType,
isNode,
isShaken,
contains,
LocationDetailType,
isLocationChildrenDetail,
ScrollTarget,
getConvertedExtraKey as innerGetConvertedExtraKey,
getOriginalExtraKey as innerGetOriginalExtraKey,
} from '@alilc/lowcode-designer';
import {
Skeleton as InnerSkeleton,
createSettingFieldView,
PopupContext,
PopupPipe,
Workbench as InnerWorkbench,
} from '@alilc/lowcode-editor-skeleton';
import Dragon from './dragon';
import {
Editor,
Title as InnerTitle,
Tip as InnerTip,
shallowIntl,
createIntl as innerCreateIntl,
intl,
createSetterContent,
obx,
observable,
makeObservable,
untracked,
computed,
observer,
globalLocale,
} from '@alilc/lowcode-editor-core';
import { ReactNode } from 'react';


const getDesignerCabin = (editor: Editor) => {
const designer = editor.get('designer') as Designer;

return {
SettingField,
isSettingField,
dragon: Dragon.create(designer.dragon),
TransformStage,
LiveEditing,
DragObjectType,
isDragNodeDataObject,
isNode,
[designerCabinSymbol]: {
isDragNodeObject,
isDragAnyObject,
isShaken,
contains,
LocationDetailType,
isLocationChildrenDetail,
ScrollTarget,
isSettingField,
TransformStage,
SettingField,
LiveEditing,
DragObjectType,
isDragNodeDataObject,
isNode,
},
};
};

const getSkeletonCabin = (skeleton: InnerSkeleton) => {
return {
createSettingFieldView,
PopupContext,
PopupPipe,
Workbench: (props: any) => <InnerWorkbench {...props} skeleton={skeleton} />, // hijack skeleton
};
};

class Utils {
isNodeSchema(data: any): data is NodeSchema {
return innerIsNodeSchema(data);
}

isFormEvent(e: KeyboardEvent | MouseEvent): boolean {
return innerIsFormEvent(e);
}

compatibleLegaoSchema(props: any): any {
return innerCompatibleLegaoSchema(props);
}

getNodeSchemaById(schema: NodeSchema, nodeId: string): NodeSchema | undefined {
return innerGetNodeSchemaById(schema, nodeId);
}

getConvertedExtraKey(key: string): string {
return innerGetConvertedExtraKey(key);
}

getOriginalExtraKey(key: string): string {
return innerGetOriginalExtraKey(key);
}

executeTransaction(fn: () => void, type: TransitionType = TransitionType.REPAINT): void {
transactionManager.executeTransaction(fn, type);
}

createIntl(instance: string | object): {
intlNode(id: string, params?: object): ReactNode;
intl(id: string, params?: object): string;
getLocale(): string;
setLocale(locale: string): void;
} {
return innerCreateIntl(instance);
}
}

export default class Common {
private readonly [editorSymbol]: Editor;
private readonly [skeletonSymbol]: InnerSkeleton;
private readonly __designerCabin: any;
private readonly __skeletonCabin: any;
private readonly __editorCabin: any;
private readonly __utils: Utils;

constructor(editor: Editor, skeleton: InnerSkeleton) {
this[editorSymbol] = editor;
this[skeletonSymbol] = skeleton;
this.__designerCabin = getDesignerCabin(this[editorSymbol]);
this.__skeletonCabin = getSkeletonCabin(this[skeletonSymbol]);
this.__utils = new Utils();
}

get utils(): any {
return this.__utils;
}

get editorCabin(): any {
return {
Title: InnerTitle,
Tip: InnerTip,
shallowIntl,
createIntl: innerCreateIntl,
intl,
createSetterContent,
obx,
observable,
makeObservable,
untracked,
computed,
observer,
globalLocale,
};
}

get designerCabin(): any {
return this.__designerCabin;
}

get skeletonCabin(): any {
return this.__skeletonCabin;
}
}
Loading

0 comments on commit b664663

Please sign in to comment.