* Insert a node before target node. * @param {string | import('./jsmind.node.js').Node} node_before * @param {string} node_id * @param {string} topic * @param {Record =} data * @param {('left'|'center'|'right'|'-1'|'0'|'1'|number)=} direction - Direction for node
(node_before, node_id, topic, data, direction)
| 617 | * @returns {import('./jsmind.node.js').Node|null} |
| 618 | */ |
| 619 | insert_node_before(node_before, node_id, topic, data, direction) { |
| 620 | if (this.get_editable()) { |
| 621 | var the_node_before = this.get_node(node_before); |
| 622 | var dir = Direction.of(direction); |
| 623 | if (dir === undefined) { |
| 624 | dir = this.layout.calculate_next_child_direction(the_node_before.parent); |
| 625 | } |
| 626 | var node = this.mind.insert_node_before(the_node_before, node_id, topic, data, dir); |
| 627 | if (!!node) { |
| 628 | this.view.add_node(node); |
| 629 | this.layout.layout(); |
| 630 | this.view.show(false); |
| 631 | this.invoke_event_handle(EventType.edit, { |
| 632 | evt: 'insert_node_before', |
| 633 | data: [the_node_before.id, node_id, topic, data, dir], |
| 634 | node: node_id, |
| 635 | }); |
| 636 | } |
| 637 | return node; |
| 638 | } else { |
| 639 | logger.error('fail, this mind map is not editable'); |
| 640 | return null; |
| 641 | } |
| 642 | } |
| 643 | /** |
| 644 | * Insert a node after target node. |
| 645 | * @param {string | import('./jsmind.node.js').Node} node_after |
no test coverage detected