Skip to content

Commit

Permalink
refactor: mv shell/workspace to engine
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Mar 29, 2024
1 parent 1874a4b commit 01985a0
Show file tree
Hide file tree
Showing 83 changed files with 78 additions and 197 deletions.
1 change: 1 addition & 0 deletions packages/editor-core/src/utils/obx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export {
action,
runInAction,
untracked,
flow
} from 'mobx';
export type { IReactionDisposer, IReactionPublic, IReactionOptions } from 'mobx';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createIcon } from '@alilc/lowcode-utils';

interface ISettingsPrimaryPaneProps {
engineEditor: Editor;
config: any;
config?: any;
}

@observer
Expand Down
24 changes: 17 additions & 7 deletions packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
"name": "@alilc/lowcode-engine",
"version": "2.0.0-beta.0",
"description": "An enterprise-class low-code technology stack with scale-out design / 一套面向扩展设计的企业级低代码技术体系",
"main": "dist/engine-core.js",
"module": "dist/engine-core.js",
"type": "module",
"main": "dist/engine.js",
"module": "dist/engine.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/engine.js",
"require": "./dist/engine.cjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist",
"es",
"lib"
"src",
"package.json"
],
"scripts": {
"version:update": "node ./scripts/version.js",
"build:target": "vite build",
"build:dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest"
},
"license": "MIT",
Expand All @@ -23,9 +33,9 @@
"@alilc/lowcode-plugin-command": "workspace:*",
"@alilc/lowcode-plugin-designer": "workspace:*",
"@alilc/lowcode-plugin-outline-pane": "workspace:*",
"@alilc/lowcode-shell": "workspace:*",
"@alilc/lowcode-utils": "workspace:*",
"@alilc/lowcode-workspace": "workspace:*",
"@alilc/lowcode-types": "workspace:*",
"classnames": "^2.5.1",
"prop-types": "^15.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
8 changes: 5 additions & 3 deletions packages/engine/src/engine-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
Workspace as InnerWorkspace,
Workbench as WorkSpaceWorkbench,
IWorkspace,
} from '@alilc/lowcode-workspace';
} from './workspace';

import {
Hotkey,
Expand All @@ -55,7 +55,7 @@ import {
Config,
CommonUI,
Command,
} from '@alilc/lowcode-shell';
} from './shell';
import { isPlainObject } from '@alilc/lowcode-utils';
import './modules/live-editing';
import * as classes from './modules/classes';
Expand All @@ -68,6 +68,7 @@ import { builtinHotkey } from './inner-plugins/builtin-hotkey';
import { defaultContextMenu } from './inner-plugins/default-context-menu';
import { CommandPlugin } from '@alilc/lowcode-plugin-command';
import { OutlinePlugin } from '@alilc/lowcode-plugin-outline-pane';
import { version } from '../package.json'

export * from './modules/skeleton-types';
export * from './modules/designer-types';
Expand Down Expand Up @@ -210,7 +211,8 @@ engineConfig.set('isOpenSource', isOpenSource);
// container which will host LowCodeEngine DOM
let engineContainer: HTMLElement;
// @ts-ignore webpack Define variable
export const version = VERSION_PLACEHOLDER;

export { version }
engineConfig.set('ENGINE_VERSION', version);

const pluginPromise = registryInnerPlugin(designer, editor, plugins);
Expand Down
8 changes: 4 additions & 4 deletions packages/engine/src/inner-plugins/builtin-hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function getSuitableInsertion(
} else {
// FIXME!!, parent maybe null
target = refNode.parent!;
index = refNode.index + 1;
index = refNode.index! + 1;
}

if (target && insertNode && !target.componentMeta?.checkNestingDown(target, insertNode)) {
Expand Down Expand Up @@ -116,14 +116,14 @@ function getNextForSelect(next: IPublicModelNode | null, head?: any, parent?: IP
}
}

ret = getNextForSelect(next.nextSibling);
ret = getNextForSelect(next.nextSibling!);
if (ret) {
return ret;
}
}

if (parent) {
return getNextForSelect(parent.nextSibling, false, parent?.parent);
return getNextForSelect(parent.nextSibling!, false, parent?.parent);
}

return null;
Expand All @@ -147,7 +147,7 @@ function getPrevForSelect(prev: IPublicModelNode | null, head?: any, parent?: IP
return prev;
}

ret = getPrevForSelect(prev.prevSibling);
ret = getPrevForSelect(prev.prevSibling!);
if (ret) {
return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/engine/src/inner-plugins/component-meta-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const componentMetaParser = (designer: any) => {
const { material } = ctx;
material.onChangeAssets(() => {
const assets = material.getAssets();
const { components = [] } = assets;
designer.buildComponentMetasMap(components);
designer.buildComponentMetasMap(assets?.components ?? []);
});
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { intl, getLocale } = createIntl?.({
'zh-CN': zhCN,
}) || {
intl: (id) => {
// @ts-ignore
return zhCN[id];
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'ric-shim';
2 changes: 1 addition & 1 deletion packages/engine/src/modules/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export {
Prop,
SimulatorHost,
SkeletonItem,
} from '@alilc/lowcode-shell';
} from '../shell';
export { Node as InnerNode } from '@alilc/lowcode-designer';

1 change: 0 additions & 1 deletion packages/engine/src/modules/designer-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as designerCabin from '@alilc/lowcode-designer';
// 这样做的目的是为了去除 Node / DocumentModel 等的值属性,仅保留类型属性
export type Node = designerCabin.Node;
export type DocumentModel = designerCabin.DocumentModel;
export type RootNode = designerCabin.RootNode;
export type EditingTarget = designerCabin.EditingTarget;
export type SaveHandler = designerCabin.SaveHandler;
export type ComponentMeta = designerCabin.ComponentMeta;
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/src/modules/shell-model-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { IPublicModelSettingField } from '../../../types/src/shell/model/setting
import {
Node,
SettingField,
} from '@alilc/lowcode-shell';
} from '../shell';

class ShellModelFactory implements IShellModelFactory {
createNode(node: INode | null | undefined): IPublicModelNode | null {
return Node.create(node);
Expand All @@ -16,4 +17,5 @@ class ShellModelFactory implements IShellModelFactory {
return SettingField.create(prop);
}
}

export const shellModelFactory = new ShellModelFactory();
2 changes: 1 addition & 1 deletion packages/engine/src/modules/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
editorCabinSymbol,
skeletonCabinSymbol,
simulatorRenderSymbol,
} from '@alilc/lowcode-shell';
} from '../shell';

export default {
projectSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Canvas implements IPublicApiCanvas {
}

get activeTracker(): IPublicModelActiveTracker | null {
const activeTracker = new ShellActiveTracker(this[designerSymbol].activeTracker);
const activeTracker = new ShellActiveTracker(this[designerSymbol].activeTracker as any);
return activeTracker;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Command implements IPublicApiCommand {
}

batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[]): void {
this[commandSymbol].batchExecuteCommand(commands, this[pluginContextSymbol]);
this[commandSymbol].batchExecuteCommand(commands, this[pluginContextSymbol]!);
}

executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class CommonUI implements IPublicApiCommonUI {
Search = Search;
Select = Select;
SplitButton = SplitButton;
Step = Step;
Step = Step as any;
Switch = Switch;
Tab = Tab;
Table = Table;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
IPublicTypeContextMenuAction,
IPublicTypeContextMenuItem,
} from '@alilc/lowcode-types';
import { Workspace as InnerWorkspace } from '@alilc/lowcode-workspace';
import { Workspace as InnerWorkspace } from '../../workspace';
import { editorSymbol, designerSymbol } from '../symbols';
import { ComponentMeta as ShellComponentMeta } from '../model';
import { ComponentType } from 'react';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class Project implements IPublicApiProject {
* 当前 project 的模拟器 ready 事件
*/
onSimulatorHostReady(fn: (host: IPublicApiSimulatorHost) => void): IPublicTypeDisposable {
// @ts-ignore
const offFn = this[projectSymbol].onSimulatorReady((simulator: BuiltinSimulatorHost) => {
fn(SimulatorHost.create(simulator)!);
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPublicApiWorkspace, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
import { IWorkspace } from '@alilc/lowcode-workspace';
import { IWorkspace } from '../../workspace';
import { resourceSymbol, workspaceSymbol } from '../symbols';
import { Resource as ShellResource, Window as ShellWindow } from '../model';
import { Plugins } from './plugins';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
CommonUI,
Command,
} from './api';
import { getEvent, type Event } from '@alilc/lowcode-editor-skeleton';
import { getEvent, Event } from '@alilc/lowcode-editor-skeleton';

export * from './symbols';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ActiveTracker implements IPublicModelActiveTracker {
return null;
}

const { node: innerNode, detail, instance } = _target;
const { node: innerNode, detail, instance } = _target as any;
const publicNode = ShellNode.create(innerNode);
return {
node: publicNode!,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
const shellDoc = new DocumentModel(document);
// @ts-ignore 直接返回已挂载的 shell doc 实例
document[shellDocSymbol] = shellDoc;
// @ts-ignore
return shellDoc;
}

Expand Down Expand Up @@ -138,7 +139,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
}

set dropLocation(loc: IPublicModelDropLocation | null) {
this[documentSymbol].dropLocation = loc;
this[documentSymbol].dropLocation = loc as any;
}

/**
Expand Down Expand Up @@ -196,7 +197,9 @@ export class DocumentModel implements IPublicModelDocumentModel {
* @param data
* @returns
*/
// @ts-ignore
createNode<IPublicModelNode>(data: IPublicTypeNodeSchema): IPublicModelNode | null {
// @ts-ignore
return ShellNode.create(this[documentSymbol].createNode(data));
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Dragon implements IPublicModelDragon {
* @param boost 拖拽转换函数
*/
from(shell: Element, boost: (e: MouseEvent) => IPublicTypeDragNodeDataObject | null): any {
return this[dragonSymbol].from(shell, boost);
return this[dragonSymbol].from(shell, boost as any);
}

/**
Expand All @@ -111,7 +111,7 @@ export class Dragon implements IPublicModelDragon {
return this[dragonSymbol].boost({
...dragObject,
nodes: dragObject.nodes.map((node: any) => node[nodeSymbol]),
}, boostEvent, fromRglNode?.[nodeSymbol]);
} as any, boostEvent, fromRglNode?.[nodeSymbol]);
}

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { editorViewSymbol, pluginContextSymbol } from '../symbols';
import { IPublicModelPluginContext } from '@alilc/lowcode-types';
import { IViewContext } from '@alilc/lowcode-workspace';
import { IViewContext } from '../../workspace';

export class EditorView {
[editorViewSymbol]: IViewContext;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPublicModelResource } from '@alilc/lowcode-types';
import { IResource } from '@alilc/lowcode-workspace';
import { IResource } from '../../workspace';
import { resourceSymbol } from '../symbols';

export class Resource implements IPublicModelResource {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { windowSymbol } from '../symbols';
import { IPublicModelResource, IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types';
import { IEditorWindow } from '@alilc/lowcode-workspace';
import { IEditorWindow } from '../../workspace';
import { Resource as ShellResource } from './resource';
import { EditorView } from './editor-view';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
Canvas,
CommonUI,
Command,
} from '@alilc/lowcode-shell';
} from '../../shell';
import {
IPluginPreferenceMananger,
IPublicApiCanvas,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { computed, makeObservable, obx } from '@alilc/lowcode-editor-core';
import { computed, makeObservable, obx, flow } from '@alilc/lowcode-editor-core';
import {
IPublicEditorViewConfig,
IPublicEnumPluginRegisterLevel,
IPublicTypeEditorView,
} from '@alilc/lowcode-types';
import { flow } from 'mobx';
import { IWorkspace } from '../workspace';
import { BasicContext, IBasicContext } from './base-context';
import { IEditorWindow } from '../window';
Expand All @@ -29,7 +28,7 @@ export class Context extends BasicContext implements IViewContext {

@obx isInit: boolean = false;

init = flow(function* (this: Context) {
init: any = flow(function* (this: Context) {
if (this.viewType === 'webview') {
const url = yield this.instance?.url?.();
yield this.plugins.register(getWebviewPlugin(url, this.viewName));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class EditorWindow implements Omit<IPublicModelWindow<IResource>, 'change
constructor(readonly resource: IResource, readonly workspace: IWorkspace, private config: IWindowCOnfig) {
makeObservable(this);
this.title = config.title;
this.icon = resource.icon;
this.icon = resource.icon as any;
this.sleep = config.sleep;
if (config.sleep) {
this.updateState(WINDOW_STATE.sleep);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true,
"paths": {}
"stripInternal": true
}
}
Loading

0 comments on commit 01985a0

Please sign in to comment.