refactor: mv shell/workspace to engine

This commit is contained in:
1ncounter 2024-03-29 17:29:25 +08:00
parent 1874a4b3e1
commit 01985a0f56
83 changed files with 78 additions and 197 deletions

View File

@ -17,6 +17,7 @@ export {
action,
runInAction,
untracked,
flow
} from 'mobx';
export type { IReactionDisposer, IReactionPublic, IReactionOptions } from 'mobx';

View File

@ -20,7 +20,7 @@ import { createIcon } from '@alilc/lowcode-utils';
interface ISettingsPrimaryPaneProps {
engineEditor: Editor;
config: any;
config?: any;
}
@observer

View File

@ -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",
@ -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"

View File

@ -38,7 +38,7 @@ import {
Workspace as InnerWorkspace,
Workbench as WorkSpaceWorkbench,
IWorkspace,
} from '@alilc/lowcode-workspace';
} from './workspace';
import {
Hotkey,
@ -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';
@ -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';
@ -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);

View File

@ -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)) {
@ -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;
@ -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;
}

View File

@ -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 ?? []);
});
},
};

View File

@ -7,6 +7,7 @@ const { intl, getLocale } = createIntl?.({
'zh-CN': zhCN,
}) || {
intl: (id) => {
// @ts-ignore
return zhCN[id];
},
};

1
packages/engine/src/module.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module 'ric-shim';

View File

@ -11,6 +11,6 @@ export {
Prop,
SimulatorHost,
SkeletonItem,
} from '@alilc/lowcode-shell';
} from '../shell';
export { Node as InnerNode } from '@alilc/lowcode-designer';

View File

@ -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;

View File

@ -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);
@ -16,4 +17,5 @@ class ShellModelFactory implements IShellModelFactory {
return SettingField.create(prop);
}
}
export const shellModelFactory = new ShellModelFactory();

View File

@ -15,7 +15,7 @@ import {
editorCabinSymbol,
skeletonCabinSymbol,
simulatorRenderSymbol,
} from '@alilc/lowcode-shell';
} from '../shell';
export default {
projectSymbol,

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;

View File

@ -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';

View File

@ -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)!);
});

View File

@ -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';

View File

@ -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';

View File

@ -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!,

View File

@ -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;
}
@ -138,7 +139,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
}
set dropLocation(loc: IPublicModelDropLocation | null) {
this[documentSymbol].dropLocation = loc;
this[documentSymbol].dropLocation = loc as any;
}
/**
@ -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));
}

View File

@ -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);
}
/**
@ -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]);
}
/**

View File

@ -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;

View File

@ -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 {

View File

@ -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';

View File

@ -33,7 +33,7 @@ import {
Canvas,
CommonUI,
Command,
} from '@alilc/lowcode-shell';
} from '../../shell';
import {
IPluginPreferenceMananger,
IPublicApiCanvas,

View File

@ -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';
@ -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));

View File

@ -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);

View File

@ -4,7 +4,6 @@
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true,
"paths": {}
"stripInternal": true
}
}

View File

@ -10,13 +10,20 @@ export default defineConfig({
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeDesigner',
formats: ['es', 'cjs'],
name: 'AliLowCodeEngine',
formats: ['es', 'cjs', 'iife'],
// the proper extensions will be added
fileName: 'designer',
fileName: 'engine',
},
rollupOptions: {
external: externals,
output: {
// for UMD
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
},
},
},
plugins: [react()],

View File

@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
include: ['tests/*.spec.ts'],
environment: 'jsdom'
}
})

View File

@ -8,6 +8,8 @@ const logger = getLogger({ level: 'warn', bizName: 'plugin:plugin-designer' });
export interface PluginProps {
engineEditor: Editor;
// ??
engineConfig?: any;
}
interface DesignerPluginState {

View File

@ -1,50 +0,0 @@
{
"name": "@alilc/lowcode-shell",
"version": "2.0.0-beta.0",
"description": "Shell Layer for AliLowCodeEngine",
"type": "module",
"main": "lib/index.js",
"module": "es/index.js",
"files": [
"lib",
"es"
],
"scripts": {
"build:target": "vite build",
"build:dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest"
},
"license": "MIT",
"dependencies": {
"@alifd/next": "^1.27.8",
"@alilc/lowcode-designer": "workspace:*",
"@alilc/lowcode-editor-core": "workspace:*",
"@alilc/lowcode-editor-skeleton": "workspace:*",
"@alilc/lowcode-types": "workspace:*",
"@alilc/lowcode-utils": "workspace:*",
"@alilc/lowcode-workspace": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@testing-library/react": "^14.2.2",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0"
},
"peerDependencies": {
"@alifd/next": "^1.27.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"repository": {
"type": "http",
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/shell"
},
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
}

View File

@ -1,10 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "temp",
"stripInternal": true,
"paths": {}
}
}

View File

@ -1,7 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"]
}

View File

@ -1,23 +0,0 @@
import { defineConfig } from 'vite';
import { resolve } from 'node:path';
import react from '@vitejs/plugin-react';
import { devDependencies, peerDependencies } from './package.json';
const externals = [...Object.keys(peerDependencies), ...Object.keys(devDependencies)];
export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(import.meta.dirname, 'src/index.ts'),
name: 'LowCodeDesigner',
formats: ['es', 'cjs'],
// the proper extensions will be added
fileName: 'designer',
},
rollupOptions: {
external: externals,
},
},
plugins: [react()],
});

View File

@ -1,56 +0,0 @@
{
"name": "@alilc/lowcode-workspace",
"version": "2.0.0-beta.0",
"description": "Shell Layer for AliLowCodeEngine",
"license": "MIT",
"type": "module",
"main": "lib/index.js",
"module": "es/index.js",
"exports": {
".": {}
},
"files": [
"dist",
"src",
"package.json"
],
"scripts": {
"build": "pnpm run \"/^build:.*/\"",
"build:target": "vite build",
"build:dts": "tsc -p tsconfig.declaration.json && node ../../scripts/rollup-dts.mjs",
"test": "vitest",
"test:cov": ""
},
"dependencies": {
"@alilc/lowcode-designer": "workspace:*",
"@alilc/lowcode-editor-core": "workspace:*",
"@alilc/lowcode-editor-skeleton": "workspace:*",
"@alilc/lowcode-types": "workspace:*",
"@alilc/lowcode-utils": "workspace:*",
"classnames": "^2.5.1",
"mobx": "^6.12.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@alib/build-scripts": "^0.1.29",
"@testing-library/react": "^11.2.2",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"repository": {
"type": "http",
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/workspace"
},
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
}

View File

@ -1,7 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"]
}