unwrapNodesto every parent of block Elements:
atoption is very versatile, and can be used to implement more complex transforms very easily. Since it is a
Locationit can always be either a
Range. And each of those types of locations will result in slightly different transformations.
Rangelocation, the range will first be deleted, collapsing to a single point where your text is then inserted.
Pathlocation, it will expand to a range that covers the entire node at that path. Then, using the range-based behavior it will delete all of the content of the node, and replace it with your text.
atoption. It can be hard to wrap your head around at first, but it makes the API very powerful and capable of expressing many subtly different transforms.
matchfunction option, which restricts the transform to only apply to nodes for which the function returns
true. When combined with
matchcan also be very powerful.
atoption is expanded to be a range representing all of the content inside the node at
. Which might look something like:
matchoption is defaulted to a function that only matches the specific path, in this case
matchis defaulted to only match the exact
path, that node is moved.
matchoptions to match all of the children:
atpath (which is expanded to a range), but instead of letting it match just that path by default, we're supplying our own
matchfunction which happens to match only the children of the node.
matchcan make representing complex logic a lot simpler.
matchcan solve your use case, and offload the complexity of managing loops to Slate instead. The
matchfunction can examine the children of a node, in
node.children, or use
Node.parentto examine its parent.