(param: {
nodeId: string;
targetNodeId: string;
index: number;
})
| 282 | name: 'move', |
| 283 | description: 'Move a node to another node.', |
| 284 | handler(param: { |
| 285 | nodeId: string; |
| 286 | targetNodeId: string; |
| 287 | index: number; |
| 288 | }) { |
| 289 | const { |
| 290 | nodeId, |
| 291 | targetNodeId, |
| 292 | index = 0, |
| 293 | } = param; |
| 294 | |
| 295 | if (!nodeId) { |
| 296 | throw new Error('Invalid node id.'); |
| 297 | } |
| 298 | |
| 299 | if (!targetNodeId) { |
| 300 | throw new Error('Invalid target node id.'); |
| 301 | } |
| 302 | |
| 303 | const node = project.currentDocument?.getNodeById(nodeId); |
| 304 | const targetNode = project.currentDocument?.getNodeById(targetNodeId); |
| 305 | if (!node) { |
| 306 | throw new Error(`Can not find node '${nodeId}'.`); |
| 307 | } |
| 308 | |
| 309 | if (!targetNode) { |
| 310 | throw new Error(`Can not find node '${targetNodeId}'.`); |
| 311 | } |
| 312 | |
| 313 | if (!targetNode.isContainerNode) { |
| 314 | throw new Error(`Node '${targetNodeId}' is not a container node.`); |
| 315 | } |
| 316 | |
| 317 | if (index < 0 || index > (targetNode.children?.size || 0)) { |
| 318 | throw new Error(`Invalid index '${index}'.`); |
| 319 | } |
| 320 | |
| 321 | project.currentDocument?.removeNode(node); |
| 322 | project.currentDocument?.insertNode(targetNode, node, index); |
| 323 | }, |
| 324 | parameters: [ |
| 325 | { |
| 326 | name: 'nodeId', |
no test coverage detected
searching dependent graphs…