From 43921cea2d21321fa9366e34e27ea15649a7f944 Mon Sep 17 00:00:00 2001 From: liujuping Date: Tue, 30 Jan 2024 18:31:52 +0800 Subject: [PATCH 1/5] fix(workspace): fix workspace.plugins.xxx api is invalid --- packages/shell/src/api/workspace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shell/src/api/workspace.ts b/packages/shell/src/api/workspace.ts index fd3e82fa9..f5bc79009 100644 --- a/packages/shell/src/api/workspace.ts +++ b/packages/shell/src/api/workspace.ts @@ -90,7 +90,7 @@ export class Workspace implements IPublicApiWorkspace { } get plugins() { - return new Plugins(this[workspaceSymbol].plugins, true); + return new Plugins(this[workspaceSymbol].plugins, true).toProxy(); } get skeleton() { From de95b87b1e2ef1a7bd90b52e7f3cf8ca22a5f999 Mon Sep 17 00:00:00 2001 From: liujuping Date: Wed, 31 Jan 2024 18:53:23 +0800 Subject: [PATCH 2/5] feat: update ts defined --- packages/types/src/shell/api/workspace.ts | 5 ++++- packages/types/src/shell/type/command.ts | 18 +++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/types/src/shell/api/workspace.ts b/packages/types/src/shell/api/workspace.ts index 9e1080b31..b6e7d84cb 100644 --- a/packages/types/src/shell/api/workspace.ts +++ b/packages/types/src/shell/api/workspace.ts @@ -1,8 +1,9 @@ import { IPublicModelWindow } from '../model'; -import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types'; +import { IPublicApiPlugins, IPublicApiSkeleton, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types'; export interface IPublicApiWorkspace< Plugins = IPublicApiPlugins, + Skeleton = IPublicApiSkeleton, ModelWindow = IPublicModelWindow, Resource = IPublicModelResource, > { @@ -15,6 +16,8 @@ export interface IPublicApiWorkspace< plugins: Plugins; + skeleton: Skeleton; + /** 当前设计器的编辑窗口 */ windows: ModelWindow[]; diff --git a/packages/types/src/shell/type/command.ts b/packages/types/src/shell/type/command.ts index dd0420def..0f301bd65 100644 --- a/packages/types/src/shell/type/command.ts +++ b/packages/types/src/shell/type/command.ts @@ -1,22 +1,10 @@ +import { IPublicTypePropType } from './prop-types'; + // 定义命令处理函数的参数类型 export interface IPublicTypeCommandHandlerArgs { [key: string]: any; } -// 定义复杂参数类型的接口 -export interface IPublicTypeCommandPropType { - - /** - * 参数基础类型 - */ - type: string; - - /** - * 参数是否必需(可选) - */ - isRequired?: boolean; -} - // 定义命令参数的接口 export interface IPublicTypeCommandParameter { @@ -28,7 +16,7 @@ export interface IPublicTypeCommandParameter { /** * 参数类型或详细类型描述 */ - propType: string | IPublicTypeCommandPropType; + propType: string | IPublicTypePropType; /** * 参数描述 From 24393211b404575bd81c62007e324ed1dfdca112 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 1 Feb 2024 12:23:31 +0800 Subject: [PATCH 3/5] refactor(plugin-command): add plugin-command package --- .github/workflows/test packages.yml | 18 ++++- packages/engine/src/engine-core.ts | 2 +- packages/plugin-command/README.md | 11 +++ .../__tests__/node-command.test.ts} | 8 +-- packages/plugin-command/build.json | 9 +++ packages/plugin-command/build.test.json | 19 +++++ packages/plugin-command/package.json | 34 +++++++++ .../plugin-command/src/history-command.ts | 43 ++++++++++++ packages/plugin-command/src/index.ts | 23 +++++++ .../src/node-command.ts} | 69 +++---------------- 10 files changed, 171 insertions(+), 65 deletions(-) create mode 100644 packages/plugin-command/README.md rename packages/{engine/tests/inner-plugins/default-command.test.ts => plugin-command/__tests__/node-command.test.ts} (97%) create mode 100644 packages/plugin-command/build.json create mode 100644 packages/plugin-command/build.test.json create mode 100644 packages/plugin-command/package.json create mode 100644 packages/plugin-command/src/history-command.ts create mode 100644 packages/plugin-command/src/index.ts rename packages/{engine/src/inner-plugins/default-command.ts => plugin-command/src/node-command.ts} (88%) diff --git a/.github/workflows/test packages.yml b/.github/workflows/test packages.yml index abb297370..573a1ade0 100644 --- a/.github/workflows/test packages.yml +++ b/.github/workflows/test packages.yml @@ -121,4 +121,20 @@ jobs: run: npm i && npm run setup:skip-build - name: test - run: cd packages/editor-core && npm test \ No newline at end of file + run: cd packages/editor-core && npm test + + test-plugin-command + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: install + run: npm i && npm run setup:skip-build + + - name: test + run: cd packages/plugin-command && npm test \ No newline at end of file diff --git a/packages/engine/src/engine-core.ts b/packages/engine/src/engine-core.ts index 778438a3d..5a2cbbc65 100644 --- a/packages/engine/src/engine-core.ts +++ b/packages/engine/src/engine-core.ts @@ -66,7 +66,7 @@ import { defaultPanelRegistry } from './inner-plugins/default-panel-registry'; import { shellModelFactory } from './modules/shell-model-factory'; import { builtinHotkey } from './inner-plugins/builtin-hotkey'; import { defaultContextMenu } from './inner-plugins/default-context-menu'; -import { defaultCommand } from './inner-plugins/default-command'; +import { defaultCommand } from '@alilc/lowcode-plugin-command'; import { OutlinePlugin } from '@alilc/lowcode-plugin-outline-pane'; export * from './modules/skeleton-types'; diff --git a/packages/plugin-command/README.md b/packages/plugin-command/README.md new file mode 100644 index 000000000..8476b47e5 --- /dev/null +++ b/packages/plugin-command/README.md @@ -0,0 +1,11 @@ +# `@alilc/plugin-command` + +> TODO: description + +## Usage + +``` +const pluginCommand = require('@alilc/plugin-command'); + +// TODO: DEMONSTRATE API +``` diff --git a/packages/engine/tests/inner-plugins/default-command.test.ts b/packages/plugin-command/__tests__/node-command.test.ts similarity index 97% rename from packages/engine/tests/inner-plugins/default-command.test.ts rename to packages/plugin-command/__tests__/node-command.test.ts index 0e28c642b..2e9d21b35 100644 --- a/packages/engine/tests/inner-plugins/default-command.test.ts +++ b/packages/plugin-command/__tests__/node-command.test.ts @@ -1,5 +1,5 @@ import { checkPropTypes } from '@alilc/lowcode-utils/src/check-prop-types'; -import { nodeSchemaPropType } from '../../src/inner-plugins/default-command'; +import { nodeSchemaPropType } from '../src/node-command'; describe('nodeSchemaPropType', () => { const componentName = 'NodeComponent'; @@ -10,8 +10,8 @@ describe('nodeSchemaPropType', () => { const invalidId = 123; // Not a string expect(checkPropTypes(validId, 'id', getPropType('id'), componentName)).toBe(true); expect(checkPropTypes(invalidId, 'id', getPropType('id'), componentName)).toBe(false); - // isRequired - expect(checkPropTypes(undefined, 'id', getPropType('id'), componentName)).toBe(false); + // is not required + expect(checkPropTypes(undefined, 'id', getPropType('id'), componentName)).toBe(true); }); it('should validate the componentName as a string', () => { @@ -71,7 +71,7 @@ describe('nodeSchemaPropType', () => { const invalidLoop = { type: 'JSExpression', value: 123 }; // Not a string expect(checkPropTypes(validLoop, 'loop', getPropType('loop'), componentName)).toBe(true); expect(checkPropTypes(invalidLoop, 'loop', getPropType('loop'), componentName)).toBe(false); - }) + }); it('should validate the loopArgs as an array', () => { const validLoopArgs = ['item']; diff --git a/packages/plugin-command/build.json b/packages/plugin-command/build.json new file mode 100644 index 000000000..d0aec1038 --- /dev/null +++ b/packages/plugin-command/build.json @@ -0,0 +1,9 @@ +{ + "plugins": [ + "@alilc/build-plugin-lce", + "build-plugin-fusion", + ["build-plugin-moment-locales", { + "locales": ["zh-cn"] + }] + ] +} diff --git a/packages/plugin-command/build.test.json b/packages/plugin-command/build.test.json new file mode 100644 index 000000000..9596d43e7 --- /dev/null +++ b/packages/plugin-command/build.test.json @@ -0,0 +1,19 @@ +{ + "plugins": [ + [ + "@alilc/build-plugin-lce", + { + "filename": "editor-preset-vision", + "library": "LowcodeEditor", + "libraryTarget": "umd", + "externals": { + "react": "var window.React", + "react-dom": "var window.ReactDOM", + "prop-types": "var window.PropTypes", + "rax": "var window.Rax" + } + } + ], + "@alilc/lowcode-test-mate/plugin/index.ts" + ] +} diff --git a/packages/plugin-command/package.json b/packages/plugin-command/package.json new file mode 100644 index 000000000..3c84e265e --- /dev/null +++ b/packages/plugin-command/package.json @@ -0,0 +1,34 @@ +{ + "name": "@alilc/lowcode-plugin-command", + "version": "1.3.1", + "description": "> TODO: description", + "author": "liujuping ", + "homepage": "https://github.com/alibaba/lowcode-engine#readme", + "license": "ISC", + "main": "lib/plugin-command.js", + "directories": { + "lib": "lib", + "test": "__tests__" + }, + "files": [ + "lib" + ], + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/alibaba/lowcode-engine.git" + }, + "scripts": { + "test": "build-scripts test --config build.test.json --jest-passWithNoTests", + "build": "build-scripts build" + }, + "bugs": { + "url": "https://github.com/alibaba/lowcode-engine/issues" + }, + "dependencies": { + "@alilc/lowcode-types": "^1.3.1", + "@alilc/lowcode-utils": "^1.3.1" + } +} diff --git a/packages/plugin-command/src/history-command.ts b/packages/plugin-command/src/history-command.ts new file mode 100644 index 000000000..ea7e491bc --- /dev/null +++ b/packages/plugin-command/src/history-command.ts @@ -0,0 +1,43 @@ +import { IPublicModelPluginContext, IPublicTypePlugin } from '@alilc/lowcode-types'; + +export const historyCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => { + const { command, project } = ctx; + return { + init() { + command.registerCommand({ + name: 'undo', + description: 'Undo the last operation.', + handler: () => { + const state = project.currentDocument?.history.getState() || 0; + const enable = !!(state & 1); + if (!enable) { + throw new Error('Can not undo.'); + } + project.currentDocument?.history.back(); + }, + }); + + command.registerCommand({ + name: 'redo', + description: 'Redo the last operation.', + handler: () => { + const state = project.currentDocument?.history.getState() || 0; + const enable = !!(state & 2); + if (!enable) { + throw new Error('Can not redo.'); + } + project.currentDocument?.history.forward(); + }, + }); + }, + destroy() { + command.unregisterCommand('history:undo'); + command.unregisterCommand('history:redo'); + }, + }; +}; + +historyCommand.pluginName = '___history_command___'; +historyCommand.meta = { + commandScope: 'history', +}; diff --git a/packages/plugin-command/src/index.ts b/packages/plugin-command/src/index.ts new file mode 100644 index 000000000..8e5d64ebc --- /dev/null +++ b/packages/plugin-command/src/index.ts @@ -0,0 +1,23 @@ +import { IPublicModelPluginContext, IPublicTypePlugin } from '@alilc/lowcode-types'; +import { nodeCommand } from './node-command'; +import { historyCommand } from './history-command'; + +export const defaultCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => { + const { plugins } = ctx; + + return { + async init() { + await plugins.register(nodeCommand, {}, { autoInit: true }); + await plugins.register(historyCommand, {}, { autoInit: true }); + }, + destroy() { + plugins.delete(nodeCommand.pluginName); + plugins.delete(historyCommand.pluginName); + }, + }; +}; + +defaultCommand.pluginName = '___default_command___'; +defaultCommand.meta = { + commandScope: 'common', +}; diff --git a/packages/engine/src/inner-plugins/default-command.ts b/packages/plugin-command/src/node-command.ts similarity index 88% rename from packages/engine/src/inner-plugins/default-command.ts rename to packages/plugin-command/src/node-command.ts index 68d65c500..eeda1d168 100644 --- a/packages/engine/src/inner-plugins/default-command.ts +++ b/packages/plugin-command/src/node-command.ts @@ -1,8 +1,4 @@ -import { - IPublicModelPluginContext, - IPublicTypeNodeSchema, - IPublicTypePropType, -} from '@alilc/lowcode-types'; +import { IPublicModelPluginContext, IPublicTypeNodeSchema, IPublicTypePlugin, IPublicTypePropType } from '@alilc/lowcode-types'; import { isNodeSchema } from '@alilc/lowcode-utils'; const sampleNodeSchema: IPublicTypePropType = { @@ -226,45 +222,7 @@ export const nodeSchemaPropType: IPublicTypePropType = { ], }; -export const historyCommand = (ctx: IPublicModelPluginContext) => { - const { command, project } = ctx; - return { - init() { - command.registerCommand({ - name: 'undo', - description: 'Undo the last operation.', - handler: () => { - const state = project.currentDocument?.history.getState() || 0; - const enable = !!(state & 1); - if (!enable) { - throw new Error('Can not undo.'); - } - project.currentDocument?.history.back(); - }, - }); - - command.registerCommand({ - name: 'redo', - description: 'Redo the last operation.', - handler: () => { - const state = project.currentDocument?.history.getState() || 0; - const enable = !!(state & 2); - if (!enable) { - throw new Error('Can not redo.'); - } - project.currentDocument?.history.forward(); - }, - }); - }, - }; -}; - -historyCommand.pluginName = '___history_command___'; -historyCommand.meta = { - commandScope: 'history', -}; - -export const nodeCommand = (ctx: IPublicModelPluginContext) => { +export const nodeCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => { const { command, project } = ctx; return { init() { @@ -521,6 +479,14 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { ], }); }, + destroy() { + command.unregisterCommand('node:add'); + command.unregisterCommand('node:move'); + command.unregisterCommand('node:remove'); + command.unregisterCommand('node:update'); + command.unregisterCommand('node:updateProps'); + command.unregisterCommand('node:removeProps'); + }, }; }; @@ -529,18 +495,3 @@ nodeCommand.meta = { commandScope: 'node', }; -export const defaultCommand = (ctx: IPublicModelPluginContext) => { - const { plugins } = ctx; - plugins.register(nodeCommand); - plugins.register(historyCommand); - - return { - init() { - }, - }; -}; - -defaultCommand.pluginName = '___default_command___'; -defaultCommand.meta = { - commandScope: 'common', -}; From 5b46d96df77d738249b0170bad222eedc29a1802 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 1 Feb 2024 14:41:55 +0800 Subject: [PATCH 4/5] refactor(plugin-command): add plugin-command package --- scripts/build.sh | 1 + scripts/sync.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index 828bb16d9..751e9094f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -10,6 +10,7 @@ lerna run build \ --scope @alilc/lowcode-editor-skeleton \ --scope @alilc/lowcode-designer \ --scope @alilc/lowcode-plugin-designer \ + --scope @alilc/lowcode-plugin-command \ --scope @alilc/lowcode-plugin-outline-pane \ --scope @alilc/lowcode-react-renderer \ --scope @alilc/lowcode-react-simulator-renderer \ diff --git a/scripts/sync.sh b/scripts/sync.sh index e9840eeca..3edac0384 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -13,4 +13,5 @@ tnpm sync @alilc/lowcode-renderer-core tnpm sync @alilc/lowcode-react-renderer tnpm sync @alilc/lowcode-react-simulator-renderer tnpm sync @alilc/lowcode-engine -tnpm sync @alilc/lowcode-workspace \ No newline at end of file +tnpm sync @alilc/lowcode-workspace +tnpm sync @alilc/lowcode-plugin-command \ No newline at end of file From 5657d9c084899e91077008c491284248776ad7d8 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 1 Feb 2024 14:49:25 +0800 Subject: [PATCH 5/5] feat: update test package.yaml --- .github/workflows/test packages.yml | 2 +- packages/workspace/src/context/base-context.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test packages.yml b/.github/workflows/test packages.yml index 573a1ade0..45fa66546 100644 --- a/.github/workflows/test packages.yml +++ b/.github/workflows/test packages.yml @@ -123,7 +123,7 @@ jobs: - name: test run: cd packages/editor-core && npm test - test-plugin-command + test-plugin-command: runs-on: ubuntu-latest steps: - name: checkout diff --git a/packages/workspace/src/context/base-context.ts b/packages/workspace/src/context/base-context.ts index db33597ae..445677a61 100644 --- a/packages/workspace/src/context/base-context.ts +++ b/packages/workspace/src/context/base-context.ts @@ -96,7 +96,7 @@ export class BasicContext implements IBasicContext { designer: IDesigner; registerInnerPlugins: () => Promise; innerSetters: InnerSetters; - innerSkeleton: InnerSkeleton; + innerSkeleton: ISkeleton; innerHotkey: IHotKey; innerPlugins: ILowCodePluginManager; canvas: IPublicApiCanvas;