* Insert the given node(s) at the specified index in the children list. * * @example * ```tsx * const node = ( * * * * * ); * * node.insert( , 1); * ``` * * Result: * ```mermaid * graph TD; *
(node: ComponentChildren, index = 0)
| 720 | * @param index - An index at which to insert the node(s). |
| 721 | */ |
| 722 | public insert(node: ComponentChildren, index = 0): this { |
| 723 | const array: ComponentChild[] = Array.isArray(node) ? node : [node]; |
| 724 | if (array.length === 0) { |
| 725 | return this; |
| 726 | } |
| 727 | |
| 728 | const children = this.children(); |
| 729 | const newChildren = children.slice(0, index); |
| 730 | |
| 731 | for (const node of array) { |
| 732 | if (node instanceof Node) { |
| 733 | newChildren.push(node); |
| 734 | node.remove(); |
| 735 | node.parent(this); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | newChildren.push(...children.slice(index)); |
| 740 | this.setParsedChildren(newChildren); |
| 741 | |
| 742 | return this; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Remove this node from the tree. |
no test coverage detected