()
| 226 | const { command, project } = ctx; |
| 227 | return { |
| 228 | init() { |
| 229 | command.registerCommand({ |
| 230 | name: 'add', |
| 231 | description: 'Add a node to the canvas.', |
| 232 | handler: (param: { |
| 233 | parentNodeId: string; |
| 234 | nodeSchema: IPublicTypeNodeSchema; |
| 235 | index: number; |
| 236 | }) => { |
| 237 | const { |
| 238 | parentNodeId, |
| 239 | nodeSchema, |
| 240 | index, |
| 241 | } = param; |
| 242 | const { project } = ctx; |
| 243 | const parentNode = project.currentDocument?.getNodeById(parentNodeId); |
| 244 | if (!parentNode) { |
| 245 | throw new Error(`Can not find node '${parentNodeId}'.`); |
| 246 | } |
| 247 | |
| 248 | if (!parentNode.isContainerNode) { |
| 249 | throw new Error(`Node '${parentNodeId}' is not a container node.`); |
| 250 | } |
| 251 | |
| 252 | if (!isNodeSchema(nodeSchema)) { |
| 253 | throw new Error('Invalid node.'); |
| 254 | } |
| 255 | |
| 256 | if (index < 0 || index > (parentNode.children?.size || 0)) { |
| 257 | throw new Error(`Invalid index '${index}'.`); |
| 258 | } |
| 259 | |
| 260 | project.currentDocument?.insertNode(parentNode, nodeSchema, index); |
| 261 | }, |
| 262 | parameters: [ |
| 263 | { |
| 264 | name: 'parentNodeId', |
| 265 | propType: 'string', |
| 266 | description: 'The id of the parent node.', |
| 267 | }, |
| 268 | { |
| 269 | name: 'nodeSchema', |
| 270 | propType: nodeSchemaPropType, |
| 271 | description: 'The node to be added.', |
| 272 | }, |
| 273 | { |
| 274 | name: 'index', |
| 275 | propType: 'number', |
| 276 | description: 'The index of the node to be added.', |
| 277 | }, |
| 278 | ], |
| 279 | }); |
| 280 | |
| 281 | command.registerCommand({ |
| 282 | name: 'move', |
| 283 | description: 'Move a node to another node.', |
| 284 | handler(param: { |
| 285 | nodeId: string; |
nothing calls this directly
no test coverage detected
searching dependent graphs…