* Add a new node to the mind map. * @param {string | import('./jsmind.node.js').Node} parent_node * @param {string} node_id * @param {string} topic * @param {Record =} data * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction - Direction for node p
(parent_node, node_id, topic, data, direction)
| 459 | * @returns {import('./jsmind.node.js').Node|null} |
| 460 | */ |
| 461 | add_node(parent_node, node_id, topic, data, direction) { |
| 462 | if (!this.get_editable()) { |
| 463 | logger.error('fail, this mind map is not editable'); |
| 464 | return null; |
| 465 | } |
| 466 | |
| 467 | var the_parent_node = this.get_node(parent_node); |
| 468 | if (!the_parent_node) { |
| 469 | logger.error('parent node not found'); |
| 470 | return null; |
| 471 | } |
| 472 | |
| 473 | var node = this._add_node_data(the_parent_node, node_id, topic, data, direction); |
| 474 | if (!!node) { |
| 475 | this._refresh_node_ui(the_parent_node); |
| 476 | this.invoke_event_handle(EventType.edit, { |
| 477 | evt: 'add_node', |
| 478 | data: [the_parent_node.id, node_id, topic, data, Direction.of(direction)], |
| 479 | node: node_id, |
| 480 | }); |
| 481 | } |
| 482 | return node; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Add multiple nodes to the mind map with optimized performance. |