GeezerVison is showing github.com — refactor(plugin-command): add plugin-command package · WatsonWangSZ/lowcode-engine@2439321
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test packages.yml +17-1Lines changed: 17 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -121,4 +121,20 @@ jobs: | 121 | 121 | run: npm i && npm run setup:skip-build | 122 | 122 |
| 123 | 123 | - name: test | 124 | | - run: cd packages/editor-core && npm test | | 124 | + run: cd packages/editor-core && npm test | | 125 | + | | 126 | + test-plugin-command | | 127 | + runs-on: ubuntu-latest | | 128 | + steps: | | 129 | + - name: checkout | | 130 | + uses: actions/checkout@v2 | | 131 | + | | 132 | + - uses: actions/setup-node@v2 | | 133 | + with: | | 134 | + node-version: '14' | | 135 | + | | 136 | + - name: install | | 137 | + run: npm i && npm run setup:skip-build | | 138 | + | | 139 | + - name: test | | 140 | + run: cd packages/plugin-command && npm test |
Collapse file Copy file name to clipboardExpand all lines: packages/engine/src/engine-core.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -66,7 +66,7 @@ import { defaultPanelRegistry } from './inner-plugins/default-panel-registry'; | 66 | 66 | import { shellModelFactory } from './modules/shell-model-factory'; | 67 | 67 | import { builtinHotkey } from './inner-plugins/builtin-hotkey'; | 68 | 68 | import { defaultContextMenu } from './inner-plugins/default-context-menu'; | 69 | | -import { defaultCommand } from './inner-plugins/default-command'; | | 69 | +import { defaultCommand } from '@alilc/lowcode-plugin-command'; | 70 | 70 | import { OutlinePlugin } from '@alilc/lowcode-plugin-outline-pane'; | 71 | 71 |
| 72 | 72 | export * from './modules/skeleton-types'; | |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# `@alilc/plugin-command` | | 2 | + | | 3 | +> TODO: description | | 4 | +
| | 5 | +## Usage | | 6 | + | | 7 | +``` | | 8 | +const pluginCommand = require('@alilc/plugin-command'); | | 9 | +
| | 10 | +// TODO: DEMONSTRATE API | | 11 | +``` |
Collapse file Copy file name to clipboardExpand all lines: packages/plugin-command/__tests__/node-command.test.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { checkPropTypes } from '@alilc/lowcode-utils/src/check-prop-types'; | 2 | | -import { nodeSchemaPropType } from '../../src/inner-plugins/default-command'; | | 2 | +import { nodeSchemaPropType } from '../src/node-command'; | 3 | 3 |
| 4 | 4 | describe('nodeSchemaPropType', () => { | 5 | 5 | const componentName = 'NodeComponent'; | @@ -10,8 +10,8 @@ describe('nodeSchemaPropType', () => { | 10 | 10 | const invalidId = 123; // Not a string | 11 | 11 | expect(checkPropTypes(validId, 'id', getPropType('id'), componentName)).toBe(true); | 12 | 12 | expect(checkPropTypes(invalidId, 'id', getPropType('id'), componentName)).toBe(false); | 13 | | - // isRequired | 14 | | - expect(checkPropTypes(undefined, 'id', getPropType('id'), componentName)).toBe(false); | | 13 | + // is not required | | 14 | + expect(checkPropTypes(undefined, 'id', getPropType('id'), componentName)).toBe(true); | 15 | 15 | }); | 16 | 16 |
| 17 | 17 | it('should validate the componentName as a string', () => { | @@ -71,7 +71,7 @@ describe('nodeSchemaPropType', () => { | 71 | 71 | const invalidLoop = { type: 'JSExpression', value: 123 }; // Not a string | 72 | 72 | expect(checkPropTypes(validLoop, 'loop', getPropType('loop'), componentName)).toBe(true); | 73 | 73 | expect(checkPropTypes(invalidLoop, 'loop', getPropType('loop'), componentName)).toBe(false); | 74 | | - }) | | 74 | + }); | 75 | 75 |
| 76 | 76 | it('should validate the loopArgs as an array', () => { | 77 | 77 | const validLoopArgs = ['item']; | |
Collapse file Copy file name to clipboard +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "plugins": [ | | 3 | + "@alilc/build-plugin-lce", | | 4 | + "build-plugin-fusion", | | 5 | + ["build-plugin-moment-locales", { | | 6 | + "locales": ["zh-cn"] | | 7 | + }] | | 8 | + ] | | 9 | +} |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "plugins": [ | | 3 | + [ | | 4 | + "@alilc/build-plugin-lce", | | 5 | + { | | 6 | + "filename": "editor-preset-vision", | | 7 | + "library": "LowcodeEditor", | | 8 | + "libraryTarget": "umd", | | 9 | + "externals": { | | 10 | + "react": "var window.React", | | 11 | + "react-dom": "var window.ReactDOM", | | 12 | + "prop-types": "var window.PropTypes", | | 13 | + "rax": "var window.Rax" | | 14 | + } | | 15 | + } | | 16 | + ], | | 17 | + "@alilc/lowcode-test-mate/plugin/index.ts" | | 18 | + ] | | 19 | +} |
Collapse file Copy file name to clipboard +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "name": "@alilc/lowcode-plugin-command", | | 3 | + "version": "1.3.1", | | 4 | + "description": "> TODO: description", | | 5 | + | | 6 | + "homepage": "https://github.com/alibaba/lowcode-engine#readme", | | 7 | + "license": "ISC", | | 8 | + "main": "lib/plugin-command.js", | | 9 | + "directories": { | | 10 | + "lib": "lib", | | 11 | + "test": "__tests__" | | 12 | + }, | | 13 | + "files": [ | | 14 | + "lib" | | 15 | + ], | | 16 | + "publishConfig": { | | 17 | + "access": "public" | | 18 | + }, | | 19 | + "repository": { | | 20 | + "type": "git", | | 21 | + "url": "git+https://github.com/alibaba/lowcode-engine.git" | | 22 | + }, | | 23 | + "scripts": { | | 24 | + "test": "build-scripts test --config build.test.json --jest-passWithNoTests", | | 25 | + "build": "build-scripts build" | | 26 | + }, | | 27 | + "bugs": { | | 28 | + "url": "https://github.com/alibaba/lowcode-engine/issues" | | 29 | + }, | | 30 | + "dependencies": { | | 31 | + "@alilc/lowcode-types": "^1.3.1", | | 32 | + "@alilc/lowcode-utils": "^1.3.1" | | 33 | + } | | 34 | +} |
Collapse file Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { IPublicModelPluginContext, IPublicTypePlugin } from '@alilc/lowcode-types'; | | 2 | + | | 3 | +export const historyCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => { | | 4 | + const { command, project } = ctx; | | 5 | + return { | | 6 | + init() { | | 7 | + command.registerCommand({ | | 8 | + name: 'undo', | | 9 | + description: 'Undo the last operation.', | | 10 | + handler: () => { | | 11 | + const state = project.currentDocument?.history.getState() || 0; | | 12 | + const enable = !!(state & 1); | | 13 | + if (!enable) { | | 14 | + throw new Error('Can not undo.'); | | 15 | + } | | 16 | + project.currentDocument?.history.back(); | | 17 | + }, | | 18 | + }); | | 19 | + | | 20 | + command.registerCommand({ | | 21 | + name: 'redo', | | 22 | + description: 'Redo the last operation.', | | 23 | + handler: () => { | | 24 | + const state = project.currentDocument?.history.getState() || 0; | | 25 | + const enable = !!(state & 2); | | 26 | + if (!enable) { | | 27 | + throw new Error('Can not redo.'); | | 28 | + } | | 29 | + project.currentDocument?.history.forward(); | | 30 | + }, | | 31 | + }); | | 32 | + }, | | 33 | + destroy() { | | 34 | + command.unregisterCommand('history:undo'); | | 35 | + command.unregisterCommand('history:redo'); | | 36 | + }, | | 37 | + }; | | 38 | +}; | | 39 | + | | 40 | +historyCommand.pluginName = '___history_command___'; | | 41 | +historyCommand.meta = { | | 42 | + commandScope: 'history', | | 43 | +}; |
Collapse file Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { IPublicModelPluginContext, IPublicTypePlugin } from '@alilc/lowcode-types'; | | 2 | +import { nodeCommand } from './node-command'; | | 3 | +import { historyCommand } from './history-command'; | | 4 | + | | 5 | +export const defaultCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => { | | 6 | + const { plugins } = ctx; | | 7 | + | | 8 | + return { | | 9 | + async init() { | | 10 | + await plugins.register(nodeCommand, {}, { autoInit: true }); | | 11 | + await plugins.register(historyCommand, {}, { autoInit: true }); | | 12 | + }, | | 13 | + destroy() { | | 14 | + plugins.delete(nodeCommand.pluginName); | | 15 | + plugins.delete(historyCommand.pluginName); | | 16 | + }, | | 17 | + }; | | 18 | +}; | | 19 | + | | 20 | +defaultCommand.pluginName = '___default_command___'; | | 21 | +defaultCommand.meta = { | | 22 | + commandScope: 'common', | | 23 | +}; |
Collapse file Copy file name to clipboardExpand all lines: packages/plugin-command/src/node-command.ts +10-59Lines changed: 10 additions & 59 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { | 2 | | - IPublicModelPluginContext, | 3 | | - IPublicTypeNodeSchema, | 4 | | - IPublicTypePropType, | 5 | | -} from '@alilc/lowcode-types'; | | 1 | +import { IPublicModelPluginContext, IPublicTypeNodeSchema, IPublicTypePlugin, IPublicTypePropType } from '@alilc/lowcode-types'; | 6 | 2 | import { isNodeSchema } from '@alilc/lowcode-utils'; | 7 | 3 |
| 8 | 4 | const sampleNodeSchema: IPublicTypePropType = { | @@ -226,45 +222,7 @@ export const nodeSchemaPropType: IPublicTypePropType = { | 226 | 222 | ], | 227 | 223 | }; | 228 | 224 |
| 229 | | -export const historyCommand = (ctx: IPublicModelPluginContext) => { | 230 | | - const { command, project } = ctx; | 231 | | - return { | 232 | | - init() { | 233 | | - command.registerCommand({ | 234 | | - name: 'undo', | 235 | | - description: 'Undo the last operation.', | 236 | | - handler: () => { | 237 | | - const state = project.currentDocument?.history.getState() || 0; | 238 | | - const enable = !!(state & 1); | 239 | | - if (!enable) { | 240 | | - throw new Error('Can not undo.'); | 241 | | - } | 242 | | - project.currentDocument?.history.back(); | 243 | | - }, | 244 | | - }); | 245 | | - | 246 | | - command.registerCommand({ | 247 | | - name: 'redo', | 248 | | - description: 'Redo the last operation.', | 249 | | - handler: () => { | 250 | | - const state = project.currentDocument?.history.getState() || 0; | 251 | | - const enable = !!(state & 2); | 252 | | - if (!enable) { | 253 | | - throw new Error('Can not redo.'); | 254 | | - } | 255 | | - project.currentDocument?.history.forward(); | 256 | | - }, | 257 | | - }); | 258 | | - }, | 259 | | - }; | 260 | | -}; | 261 | | - | 262 | | -historyCommand.pluginName = '___history_command___'; | 263 | | -historyCommand.meta = { | 264 | | - commandScope: 'history', | 265 | | -}; | 266 | | - | 267 | | -export const nodeCommand = (ctx: IPublicModelPluginContext) => { | | 225 | +export const nodeCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => { | 268 | 226 | const { command, project } = ctx; | 269 | 227 | return { | 270 | 228 | init() { | @@ -521,6 +479,14 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 521 | 479 | ], | 522 | 480 | }); | 523 | 481 | }, | | 482 | + destroy() { | | 483 | + command.unregisterCommand('node:add'); | | 484 | + command.unregisterCommand('node:move'); | | 485 | + command.unregisterCommand('node:remove'); | | 486 | + command.unregisterCommand('node:update'); | | 487 | + command.unregisterCommand('node:updateProps'); | | 488 | + command.unregisterCommand('node:removeProps'); | | 489 | + }, | 524 | 490 | }; | 525 | 491 | }; | 526 | 492 |
| @@ -529,18 +495,3 @@ nodeCommand.meta = { | 529 | 495 | commandScope: 'node', | 530 | 496 | }; | 531 | 497 |
| 532 | | -export const defaultCommand = (ctx: IPublicModelPluginContext) => { | 533 | | - const { plugins } = ctx; | 534 | | - plugins.register(nodeCommand); | 535 | | - plugins.register(historyCommand); | 536 | | - | 537 | | - return { | 538 | | - init() { | 539 | | - }, | 540 | | - }; | 541 | | -}; | 542 | | - | 543 | | -defaultCommand.pluginName = '___default_command___'; | 544 | | -defaultCommand.meta = { | 545 | | - commandScope: 'common', | 546 | | -}; |
|