3

I know I can create custom nodes that are an extension of inbuilt node classes. And it works great, But I would also like to extend the functionality of inbuilt classes themselves.

For example, I have this helper function:

import { LexicalNode } from 'lexical'

function insertMultipleAfter(targetNode: LexicalNode, nodesToInsert: LexicalNode[]) {
  ;[...nodesToInsert].reverse().forEach(node => targetNode.insertAfter(node))
}

and I would like to make it part of LexicalNode itself, so I can call node.insertMultipleAfter(arrayOfNodes) on any node of any type - or perhaps even add a new overload to insertAfter to make it also handle an array.

Is there a "correct" way to do this? Or is it not advisable, and should I stick to my helper functions?

Michal Kurz
  • 1,592
  • 13
  • 41

0 Answers0