mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-11 18:42:56 +00:00
feat(command): update default commands
This commit is contained in:
parent
ed7befbff0
commit
80bb7102b6
@ -10,10 +10,7 @@ const sampleNodeSchema: IPublicTypePropType = {
|
|||||||
value: [
|
value: [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
propType: {
|
propType: 'string',
|
||||||
type: 'string',
|
|
||||||
isRequired: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'componentName',
|
name: 'componentName',
|
||||||
@ -277,10 +274,12 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
handler: (param: {
|
handler: (param: {
|
||||||
parentNodeId: string;
|
parentNodeId: string;
|
||||||
nodeSchema: IPublicTypeNodeSchema;
|
nodeSchema: IPublicTypeNodeSchema;
|
||||||
|
index: number;
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
parentNodeId,
|
parentNodeId,
|
||||||
nodeSchema,
|
nodeSchema,
|
||||||
|
index,
|
||||||
} = param;
|
} = param;
|
||||||
const { project } = ctx;
|
const { project } = ctx;
|
||||||
const parentNode = project.currentDocument?.getNodeById(parentNodeId);
|
const parentNode = project.currentDocument?.getNodeById(parentNodeId);
|
||||||
@ -296,7 +295,11 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
throw new Error('Invalid node.');
|
throw new Error('Invalid node.');
|
||||||
}
|
}
|
||||||
|
|
||||||
project.currentDocument?.insertNode(parentNode, nodeSchema);
|
if (index < 0 || index > (parentNode.children?.size || 0)) {
|
||||||
|
throw new Error(`Invalid index '${index}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
project.currentDocument?.insertNode(parentNode, nodeSchema, index);
|
||||||
},
|
},
|
||||||
parameters: [
|
parameters: [
|
||||||
{
|
{
|
||||||
@ -309,6 +312,11 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
propType: nodeSchemaPropType,
|
propType: nodeSchemaPropType,
|
||||||
description: 'The node to be added.',
|
description: 'The node to be added.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'index',
|
||||||
|
propType: 'number',
|
||||||
|
description: 'The index of the node to be added.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -326,6 +334,14 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
index = 0,
|
index = 0,
|
||||||
} = param;
|
} = param;
|
||||||
|
|
||||||
|
if (!nodeId) {
|
||||||
|
throw new Error('Invalid node id.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetNodeId) {
|
||||||
|
throw new Error('Invalid target node id.');
|
||||||
|
}
|
||||||
|
|
||||||
const node = project.currentDocument?.getNodeById(nodeId);
|
const node = project.currentDocument?.getNodeById(nodeId);
|
||||||
const targetNode = project.currentDocument?.getNodeById(targetNodeId);
|
const targetNode = project.currentDocument?.getNodeById(targetNodeId);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
@ -350,12 +366,18 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
parameters: [
|
parameters: [
|
||||||
{
|
{
|
||||||
name: 'nodeId',
|
name: 'nodeId',
|
||||||
propType: 'string',
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
description: 'The id of the node to be moved.',
|
description: 'The id of the node to be moved.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'targetNodeId',
|
name: 'targetNodeId',
|
||||||
propType: 'string',
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
description: 'The id of the target node.',
|
description: 'The id of the target node.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -393,8 +415,8 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
command.registerCommand({
|
command.registerCommand({
|
||||||
name: 'replace',
|
name: 'update',
|
||||||
description: 'Replace a node with another node.',
|
description: 'Update a node.',
|
||||||
handler(param: {
|
handler(param: {
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
nodeSchema: IPublicTypeNodeSchema;
|
nodeSchema: IPublicTypeNodeSchema;
|
||||||
@ -419,12 +441,12 @@ export const nodeCommand = (ctx: IPublicModelPluginContext) => {
|
|||||||
{
|
{
|
||||||
name: 'nodeId',
|
name: 'nodeId',
|
||||||
propType: 'string',
|
propType: 'string',
|
||||||
description: 'The id of the node to be replaced.',
|
description: 'The id of the node to be updated.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'nodeSchema',
|
name: 'nodeSchema',
|
||||||
propType: nodeSchemaPropType,
|
propType: nodeSchemaPropType,
|
||||||
description: 'The node to replace.',
|
description: 'The node to be updated.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -15,12 +15,12 @@ export interface IPublicApiCommand {
|
|||||||
/**
|
/**
|
||||||
* 通过名称和给定参数执行一个命令,会校验参数是否符合命令定义
|
* 通过名称和给定参数执行一个命令,会校验参数是否符合命令定义
|
||||||
*/
|
*/
|
||||||
executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void;
|
executeCommand(name: string, args?: IPublicTypeCommandHandlerArgs): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量执行命令,执行完所有命令后再进行一次重绘,历史记录中只会记录一次
|
* 批量执行命令,执行完所有命令后再进行一次重绘,历史记录中只会记录一次
|
||||||
*/
|
*/
|
||||||
batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[]): void;
|
batchExecuteCommand(commands: { name: string; args?: IPublicTypeCommandHandlerArgs }[]): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列出所有已注册的命令
|
* 列出所有已注册的命令
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user