GeezerVison is showing github.com — feat(command): update default commands · czfadmin/lowcode-engine@80bb710
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: packages/engine/src/inner-plugins/default-command.ts +33-11Lines changed: 33 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,10 +10,7 @@ const sampleNodeSchema: IPublicTypePropType = { | 10 | 10 | value: [ | 11 | 11 | { | 12 | 12 | name: 'id', | 13 | | - propType: { | 14 | | - type: 'string', | 15 | | - isRequired: true, | 16 | | - }, | | 13 | + propType: 'string', | 17 | 14 | }, | 18 | 15 | { | 19 | 16 | name: 'componentName', | @@ -277,10 +274,12 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 277 | 274 | handler: (param: { | 278 | 275 | parentNodeId: string; | 279 | 276 | nodeSchema: IPublicTypeNodeSchema; | | 277 | + index: number; | 280 | 278 | }) => { | 281 | 279 | const { | 282 | 280 | parentNodeId, | 283 | 281 | nodeSchema, | | 282 | + index, | 284 | 283 | } = param; | 285 | 284 | const { project } = ctx; | 286 | 285 | const parentNode = project.currentDocument?.getNodeById(parentNodeId); | @@ -296,7 +295,11 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 296 | 295 | throw new Error('Invalid node.'); | 297 | 296 | } | 298 | 297 |
| 299 | | - project.currentDocument?.insertNode(parentNode, nodeSchema); | | 298 | + if (index < 0 || index > (parentNode.children?.size || 0)) { | | 299 | + throw new Error(`Invalid index '${index}'.`); | | 300 | + } | | 301 | + | | 302 | + project.currentDocument?.insertNode(parentNode, nodeSchema, index); | 300 | 303 | }, | 301 | 304 | parameters: [ | 302 | 305 | { | @@ -309,6 +312,11 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 309 | 312 | propType: nodeSchemaPropType, | 310 | 313 | description: 'The node to be added.', | 311 | 314 | }, | | 315 | + { | | 316 | + name: 'index', | | 317 | + propType: 'number', | | 318 | + description: 'The index of the node to be added.', | | 319 | + }, | 312 | 320 | ], | 313 | 321 | }); | 314 | 322 |
| @@ -326,6 +334,14 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 326 | 334 | index = 0, | 327 | 335 | } = param; | 328 | 336 |
| | 337 | + if (!nodeId) { | | 338 | + throw new Error('Invalid node id.'); | | 339 | + } | | 340 | + | | 341 | + if (!targetNodeId) { | | 342 | + throw new Error('Invalid target node id.'); | | 343 | + } | | 344 | + | 329 | 345 | const node = project.currentDocument?.getNodeById(nodeId); | 330 | 346 | const targetNode = project.currentDocument?.getNodeById(targetNodeId); | 331 | 347 | if (!node) { | @@ -350,12 +366,18 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 350 | 366 | parameters: [ | 351 | 367 | { | 352 | 368 | name: 'nodeId', | 353 | | - propType: 'string', | | 369 | + propType: { | | 370 | + type: 'string', | | 371 | + isRequired: true, | | 372 | + }, | 354 | 373 | description: 'The id of the node to be moved.', | 355 | 374 | }, | 356 | 375 | { | 357 | 376 | name: 'targetNodeId', | 358 | | - propType: 'string', | | 377 | + propType: { | | 378 | + type: 'string', | | 379 | + isRequired: true, | | 380 | + }, | 359 | 381 | description: 'The id of the target node.', | 360 | 382 | }, | 361 | 383 | { | @@ -393,8 +415,8 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 393 | 415 | }); | 394 | 416 |
| 395 | 417 | command.registerCommand({ | 396 | | - name: 'replace', | 397 | | - description: 'Replace a node with another node.', | | 418 | + name: 'update', | | 419 | + description: 'Update a node.', | 398 | 420 | handler(param: { | 399 | 421 | nodeId: string; | 400 | 422 | nodeSchema: IPublicTypeNodeSchema; | @@ -419,12 +441,12 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => { | 419 | 441 | { | 420 | 442 | name: 'nodeId', | 421 | 443 | propType: 'string', | 422 | | - description: 'The id of the node to be replaced.', | | 444 | + description: 'The id of the node to be updated.', | 423 | 445 | }, | 424 | 446 | { | 425 | 447 | name: 'nodeSchema', | 426 | 448 | propType: nodeSchemaPropType, | 427 | | - description: 'The node to replace.', | | 449 | + description: 'The node to be updated.', | 428 | 450 | }, | 429 | 451 | ], | 430 | 452 | }); | |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/api/command.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,12 +15,12 @@ export interface IPublicApiCommand { | 15 | 15 | /** | 16 | 16 | * 通过名称和给定参数执行一个命令,会校验参数是否符合命令定义 | 17 | 17 | */ | 18 | | - executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void; | | 18 | + executeCommand(name: string, args?: IPublicTypeCommandHandlerArgs): void; | 19 | 19 |
| 20 | 20 | /** | 21 | 21 | * 批量执行命令,执行完所有命令后再进行一次重绘,历史记录中只会记录一次 | 22 | 22 | */ | 23 | | - batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[]): void; | | 23 | + batchExecuteCommand(commands: { name: string; args?: IPublicTypeCommandHandlerArgs }[]): void; | 24 | 24 |
| 25 | 25 | /** | 26 | 26 | * 列出所有已注册的命令 | |
|