Transforms API
16 min
transforms are helper functions operating on the document they can be used in defining your own commands node options docid\ ivorsdntr 7lbfullsy static methods docid\ ivorsdntr 7lbfullsy node transforms docid\ ivorsdntr 7lbfullsy selection transforms docid\ ivorsdntr 7lbfullsy text transforms docid\ ivorsdntr 7lbfullsy editor transforms docid\ ivorsdntr 7lbfullsy node options all transforms support a parameter options this includes options specific to the transform, and general nodeoptions to specify which nodes in the document that the transform is applied to interface nodeoptions { at? location match? (node node, path location) => boolean mode? 'highest' | 'lowest' voids? boolean } the at option selects a location docid 3wfrrppqglllxjdm12dqu in the editor it defaults to the user's current selection learn more about the at option docid 794j2fusyhey wmrfa2h the match option filters the set of nodes with a custom function learn more about the match option docid 794j2fusyhey wmrfa2h the mode option also filters the set of nodes when voids is false, void elements docid\ ivorsdntr 7lbfullsy are filtered out static methods node transforms transforms that operate on nodes transforms insertfragment(editor editor, fragment node\[], options?) insert of fragment of nodes at the specified location in the document if no location is specified, insert at the current selection options {at? location, hanging? boolean, voids? boolean} transforms insertnodes(editor editor, nodes node | node\[], options?) atomically inserts nodes at the specified location in the document if no location is specified, inserts at the current selection if there is no selection, inserts at the end of the document options supported nodeoptions & {hanging? boolean, select? boolean} for example, to insert at the very end, without replacing the current selection and regardless of block nesting, use transforms insertnodes( editor, { type targettype, children \[{ text '' }] }, { at \[editor children length] } ) transforms removenodes(editor editor, options?) remove nodes at the specified location in the document if no location is specified, remove the nodes in the selection options supported nodeoptions & {hanging? boolean} transforms mergenodes(editor editor, options?) merge a node at the specified location with the previous node at the same depth if no location is specified, use the selection resulting empty container nodes are removed options supported nodeoptions & {hanging? boolean} transforms splitnodes(editor editor, options?) split nodes at the specified location if no location is specified, split the selection options supported nodeoptions & {height? number, always? boolean} transforms wrapnodes(editor editor, element element, options?) wrap nodes at the specified location in the element container if no location is specified, wrap the selection options supported nodeoptions & {split? boolean} options mode 'all' is also supported options split indicates that it's okay to split a node in order to wrap the location for example, if ipsum was selected in a text node with lorem ipsum dolar , split true would wrap the word ipsum only, resulting in splitting the text node if split false , the entire text node lorem ipsum dolar would be wrapped transforms unwrapnodes(editor editor, options?) unwrap nodes at the specified location if necessary, the parent node is split if no location is specified, use the selection options supported nodeoptions & {split? boolean} for options mode , 'all' is also supported transforms setnodes(editor editor, props partial\<node>, options?) set properties of nodes at the specified location if no location is specified, use the selection options supported nodeoptions & {hanging? boolean, split? boolean} for options mode , 'all' is also supported transforms unsetnodes(editor editor, props string | string\[], options?) unset properties of nodes at the specified location if no location is specified, use the selection options supported nodeoptions & {split? boolean} for options mode , 'all' is also supported transforms liftnodes(editor editor, options?) lift nodes at the specified location upwards in the document tree if necessary, the parent node is split if no location is specified, use the selection options supported nodeoptions for options mode , 'all' is also supported transforms movenodes(editor editor, options) move the nodes from an origin to a destination a destination must be specified in the options if no origin is specified, move the selection options supported nodeoptions & {to path} for options mode , 'all' is also supported selection transforms transforms that operate on the document's selection transforms collapse(editor editor, options?) collapse the selection to a single point options {edge? 'anchor' | 'focus' | 'start' | 'end'} transforms select(editor editor, target location) set the selection to a new value specified by target when a selection already exists, this method is just a proxy for setselection and will update the existing value for example, to set the selection to the entire contents of the editor transforms select(editor, { anchor editor start(editor, \[]), focus editor end(editor, \[]), }) transforms deselect(editor editor) unset the selection transforms move(editor editor, options?) move the selection's point forward or backward options {distance? number, unit? 'offset' | 'character' | 'word' | 'line', reverse? boolean, edge? 'anchor' | 'focus' | 'start' | 'end'} transforms setpoint(editor editor, props partial\<point>, options?) set new properties on one of the selection's points options {edge? 'anchor' | 'focus' | 'start' | 'end'} transforms setselection(editor editor, props partial\<range>) set new properties on an active selection since the value is a partial\<range> , this method can only handle updates to an existing selection if there is no active selection the operation will be void use select if you'd like to create a selection when there is none text transforms transforms that operate on text transforms delete(editor editor, options?) delete text in the document options {at? location, distance? number, unit? 'character' | 'word' | 'line' | 'block', reverse? boolean, hanging? boolean, voids? boolean} transforms inserttext(editor editor, text string, options?) insert a string of text at the specified location in the document if no location is specified, insert at the current selection options {at? location, voids? boolean} editor transforms transforms transform(editor editor, transform transform) transform the editor by an operation