1- import {
2- IPublicModelPluginContext ,
3- IPublicTypeNodeSchema ,
4- IPublicTypePropType ,
5- } from '@alilc/lowcode-types' ;
1+ import { IPublicModelPluginContext , IPublicTypeNodeSchema , IPublicTypePlugin , IPublicTypePropType } from '@alilc/lowcode-types' ;
62import { isNodeSchema } from '@alilc/lowcode-utils' ;
73
84const sampleNodeSchema : IPublicTypePropType = {
@@ -226,45 +222,7 @@ export const nodeSchemaPropType: IPublicTypePropType = {
226222 ] ,
227223} ;
228224
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 ) => {
268226 const { command, project } = ctx ;
269227 return {
270228 init ( ) {
@@ -521,6 +479,14 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
521479 ] ,
522480 } ) ;
523481 } ,
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+ } ,
524490 } ;
525491} ;
526492
@@ -529,18 +495,3 @@ nodeCommand.meta = {
529495 commandScope : 'node' ,
530496} ;
531497
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- } ;
0 commit comments