Get the "dirty" paths generated from an operation.
export const getDirtyPaths: WithEditorFirstArg<Editor["getDirtyPaths"]> = ...Create a new Slate Editor
object.
The Editor
interface stores all the state of a Slate editor. It is extended
by plugins that wish to add their own helpers and implement new behaviors.
Add a custom property to the leaf text nodes in the current selection.
If the selection is currently collapsed, the marks will be added to the
editor.marks
property instead, and applied when text is inserted next.
Delete the content in the current selection.
const deleteFragment: (editor: Editor, options?: EditorFragmentDeletionOptions) => void = ...Insert a block break at the current selection.
If the selection is currently expanded, it will be deleted first.
Atomically inserts nodes
at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
Insert a soft break at the current selection.
If the selection is currently expanded, it will be deleted first.
Normalize any dirty objects in the editor.
const normalize: (editor: Editor, options?: EditorNormalizeOptions) => void = ...Remove a custom property from all of the leaf text nodes in the current selection.
If the selection is currently collapsed, the removal will be stored on
editor.marks
and applied to the text inserted next.
Manually set if the editor should currently be normalizing.
Note: Using this incorrectly can leave the editor in an invalid state.
Call a function, deferring normalization until after it completes.
const withoutNormalizing: (editor: Editor, fn: () => void) => void = ...Get the point after a location.
const after: (editor: Editor, at: Location, options?: EditorAfterOptions) => Point | undefined = ...Get the point before a location.
const before: (editor: Editor, at: Location, options?: EditorBeforeOptions) => Point | undefined = ...Get the start and end points of a location.
const edges: (editor: Editor, at: Location) => [Point, Point] = ...Match a read-only element in the current branch of the editor.
const elementReadOnly: (editor: Editor, options?: EditorElementReadOnlyOptions) => NodeEntry<Element> | undefined = ...Get the marks that would be added to text at the current selection.
const marks: (editor: Editor) => Omit<Text, "text"> | null = ...Check if a node has block children.
const hasBlocks: (editor: Editor, element: Element) => boolean = ...Check if a node has inline and text children.
const hasInlines: (editor: Editor, element: Element) => boolean = ...Check if a node has text children.
const hasTexts: (editor: Editor, element: Element) => boolean = ...Check if a value is a block Element
object.
Check if a point is an edge of a location.
const isEdge: (editor: Editor, point: Point, at: Location) => boolean = ...Check if an element is empty, accounting for void nodes.
const isEmpty: (editor: Editor, element: Element) => boolean = ...Check if a point is the end point of a location.
const isEnd: (editor: Editor, point: Point, at: Location) => boolean = ...Check if a value is an inline Element
object.
Check if the editor is currently normalizing after each operation.
const isNormalizing: (editor: Editor) => boolean = ...Check if a point is the start point of a location.
const isStart: (editor: Editor, point: Point, at: Location) => boolean = ...Check if a value is a void Element
object.
Get the leaf text node at a location.
const leaf: (editor: Editor, at: Location, options?: EditorLeafOptions) => NodeEntry<Text> = ...Get the node at a location.
const node: (editor: Editor, at: Location, options?: EditorNodeOptions) => NodeEntry = ...Get the parent node of a location.
const parent: (editor: Editor, at: Location, options?: EditorParentOptions) => NodeEntry<Ancestor> = ...Get the path of a location.
const path: (editor: Editor, at: Location, options?: EditorPathOptions) => Path = ...Create a mutable ref for a Path
object, which will stay in sync as new
operations are applied to the editor.
Get the set of currently tracked path refs of the editor.
const pathRefs: (editor: Editor) => Set<PathRef> = ...Get the start or end point of a location.
const point: (editor: Editor, at: Location, options?: EditorPointOptions) => Point = ...Create a mutable ref for a Point
object, which will stay in sync as new
operations are applied to the editor.
Get the set of currently tracked point refs of the editor.
const pointRefs: (editor: Editor) => Set<PointRef> = ...Return all the positions in at
range where a Point
can be placed.
By default, moves forward by individual offsets at a time, but
the unit
option can be used to to move by character, word, line, or block.
The reverse
option can be used to change iteration direction.
Note: By default void nodes are treated as a single point and iteration
will not happen inside their content unless you pass in true for the
voids
option, then iteration will occur.
Create a mutable ref for a Range
object, which will stay in sync as new
operations are applied to the editor.
Get the set of currently tracked range refs of the editor.
const rangeRefs: (editor: Editor) => Set<RangeRef> = ...Get the text string content of a location.
Note: by default the text of void nodes is considered to be an empty string, regardless of content, unless you pass in true for the voids option
Convert a range into a non-hanging one.
const unhangRange: (editor: Editor, range: Range, options?: EditorUnhangRangeOptions) => Range = ...Match a void node in the current branch of the editor.
const void: (editor: Editor, options?: EditorVoidOptions) => NodeEntry<Element> | undefined = ...Call a function, Determine whether or not remove the previous node when merge.
const shouldMergeNodesRemovePrevNode: (editor: Editor, prevNodeEntry: NodeEntry, curNodeEntry: NodeEntry) => boolean = ...Get the ancestor above a location in the document.
above: <T extends Ancestor>(editor: Editor, options?: EditorAboveOptions<T>) => NodeEntry<T> | undefined;Add a custom property to the leaf text nodes in the current selection.
If the selection is currently collapsed, the marks will be added to the
editor.marks
property instead, and applied when text is inserted next.
Get the point after a location.
after: (editor: Editor, at: Location, options?: EditorAfterOptions) => Point | undefined;Get the point before a location.
before: (editor: Editor, at: Location, options?: EditorBeforeOptions) => Point | undefined;Delete content in the editor backward from the current selection.
deleteBackward: (editor: Editor, options?: EditorDirectedDeletionOptions) => void;Delete content in the editor forward from the current selection.
deleteForward: (editor: Editor, options?: EditorDirectedDeletionOptions) => void;Delete the content in the current selection.
deleteFragment: (editor: Editor, options?: EditorFragmentDeletionOptions) => void;Match a read-only element in the current branch of the editor.
elementReadOnly: (editor: Editor, options?: EditorElementReadOnlyOptions) => NodeEntry<Element> | undefined;Check if a node has inline and text children.
hasInlines: (editor: Editor, element: Element) => boolean;Insert a block break at the current selection.
If the selection is currently expanded, it will be deleted first.
Inserts a fragment at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
insertFragment: (editor: Editor, fragment: Node[], options?: TextInsertFragmentOptions) => void;Atomically inserts nodes
at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
Insert a soft break at the current selection.
If the selection is currently expanded, it will be deleted first.
Insert a string of text at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
insertText: (editor: Editor, text: string, options?: TextInsertTextOptions) => void;Check if a point is an edge of a location.
isEdge: (editor: Editor, point: Point, at: Location) => boolean;Check if a value is a read-only Element
object.
Check if an element is empty, accounting for void nodes.
isEmpty: (editor: Editor, element: Element) => boolean;Check if a point is the end point of a location.
isEnd: (editor: Editor, point: Point, at: Location) => boolean;Check if the editor is currently normalizing after each operation.
isNormalizing: (editor: Editor) => boolean;Check if a value is a selectable Element
object.
Check if a point is the start point of a location.
isStart: (editor: Editor, point: Point, at: Location) => boolean;Get the leaf text node at a location.
leaf: (editor: Editor, at: Location, options?: EditorLeafOptions) => NodeEntry<Text>;Iterate through all of the levels at a location.
levels: <T extends Node>(editor: Editor, options?: EditorLevelsOptions<T>) => Generator<NodeEntry<T>, void, undefined>;Get the marks that would be added to text at the current selection.
marks: (editor: Editor) => Omit<Text, "text"> | null;Get the matching node in the branch of the document after a location.
next: <T extends Descendant>(editor: Editor, options?: EditorNextOptions<T>) => NodeEntry<T> | undefined;Get the node at a location.
node: (editor: Editor, at: Location, options?: EditorNodeOptions) => NodeEntry;Iterate through all of the nodes in the Editor.
nodes: <T extends Node>(editor: Editor, options?: EditorNodesOptions<T>) => Generator<NodeEntry<T>, void, undefined>;Normalize any dirty objects in the editor.
normalize: (editor: Editor, options?: EditorNormalizeOptions) => void;Get the parent node of a location.
parent: (editor: Editor, at: Location, options?: EditorParentOptions) => NodeEntry<Ancestor>;Get the path of a location.
path: (editor: Editor, at: Location, options?: EditorPathOptions) => Path;Create a mutable ref for a Path
object, which will stay in sync as new
operations are applied to the editor.
Get the set of currently tracked path refs of the editor.
pathRefs: (editor: Editor) => Set<PathRef>;Get the start or end point of a location.
point: (editor: Editor, at: Location, options?: EditorPointOptions) => Point;Create a mutable ref for a Point
object, which will stay in sync as new
operations are applied to the editor.
Get the set of currently tracked point refs of the editor.
pointRefs: (editor: Editor) => Set<PointRef>;Return all the positions in at
range where a Point
can be placed.
By default, moves forward by individual offsets at a time, but
the unit
option can be used to to move by character, word, line, or block.
The reverse
option can be used to change iteration direction.
Note: By default void nodes are treated as a single point and iteration
will not happen inside their content unless you pass in true for the
voids
option, then iteration will occur.
Get the matching node in the branch of the document before a location.
previous: <T extends Node>(editor: Editor, options?: EditorPreviousOptions<T>) => NodeEntry<T> | undefined;Create a mutable ref for a Range
object, which will stay in sync as new
operations are applied to the editor.
Get the set of currently tracked range refs of the editor.
rangeRefs: (editor: Editor) => Set<RangeRef>;Remove a custom property from all of the leaf text nodes in the current selection.
If the selection is currently collapsed, the removal will be stored on
editor.marks
and applied to the text inserted next.
Manually set if the editor should currently be normalizing.
Note: Using this incorrectly can leave the editor in an invalid state.
Get the text string content of a location.
Note: by default the text of void nodes is considered to be an empty string, regardless of content, unless you pass in true for the voids option
Convert a range into a non-hanging one.
unhangRange: (editor: Editor, range: Range, options?: EditorUnhangRangeOptions) => Range;Match a void node in the current branch of the editor.
void: (editor: Editor, options?: EditorVoidOptions) => NodeEntry<Element> | undefined;Call a function, deferring normalization until after it completes.
withoutNormalizing: (editor: Editor, fn: () => void) => void;Call a function, Determine whether or not remove the previous node when merge.
shouldMergeNodesRemovePrevNode: (editor: Editor, prevNodeEntry: NodeEntry, curNodeEntry: NodeEntry) => boolean;A helper type for narrowing matched nodes with a predicate.
export type NodeMatch<T extends Node> = ((node: Node, path: Path) => node is T) | ((node: Node, path: Path) => boolean)Element
objects are a type of node in a Slate document that contain other
element nodes or text nodes. They can be either "blocks" or "inlines"
depending on the Slate editor's configuration.
Check if a value implements the 'Ancestor' interface.
isAncestor: (value: any) => value is Ancestor;Check if a set of props is a partial of Element.
isElementProps: (props: any) => props is Partial<Element>;Check if a value implements the Element
interface and has elementKey with selected value.
Default it check to type
key value
Check if an element matches set of properties.
Note: this checks custom properties, and it does not ensure that any children are equivalent.
ElementEntry
objects refer to an Element
and the Path
where it can be
found inside a root node.
The Location
interface is a union of the ways to refer to a specific
location in a Slate document: paths, points or ranges.
Methods will often accept a Location
instead of requiring only a Path
,
Point
or Range
. This eliminates the need for developers to manage
converting between the different interfaces in their own code base.
The Span
interface is a low-level way to refer to locations in nodes
without using Point
which requires leaf text nodes to be present.
The Node
union type represents all of the different types of nodes that
occur in a Slate document tree.
Get the node at a specific path, asserting that it's an ancestor node.
ancestor: (root: Node, path: Path) => Ancestor;Return a generator of all the ancestor nodes above a specific path.
By default the order is top-down, from highest to lowest ancestor in
the tree, but you can pass the reverse: true
option to go bottom-up.
Iterate over the children of a node at a specific path.
children: (root: Node, path: Path, options?: NodeChildrenOptions) => Generator<NodeEntry<Descendant>, void, undefined>;Get an entry for the common ancesetor node of two paths.
common: (root: Node, path: Path, another: Path) => NodeEntry;Get the node at a specific path, asserting that it's a descendant node.
descendant: (root: Node, path: Path) => Descendant;Return a generator of all the descendant node entries inside a root node.
descendants: (root: Node, options?: NodeDescendantsOptions) => Generator<NodeEntry<Descendant>, void, undefined>;Return a generator of all the element nodes inside a root node. Each iteration
will return an ElementEntry
tuple consisting of [Element, Path]
. If the
root node is an element it will be included in the iteration as well.
Get the sliced fragment represented by a range inside a root node.
fragment: (root: Node, range: Range) => Descendant[];Get the descendant node referred to by a specific path. If the path is an empty array, it refers to the root node itself.
get: (root: Node, path: Path) => Node;Similar to get, but returns undefined if the node does not exist.
getIf: (root: Node, path: Path) => Node | undefined;Get the node at a specific path, ensuring it's a leaf text node.
leaf: (root: Node, path: Path) => Text;Return a generator of the in a branch of the tree, from a specific path.
By default the order is top-down, from highest to lowest node in the tree,
but you can pass the reverse: true
option to go bottom-up.
Return a generator of all the node entries of a root node. Each entry is
returned as a [Node, Path]
tuple, with the path referring to the node's
position inside the root node.
Get the concatenated text string of a node's content.
Note that this will not include spaces or line breaks between block nodes. It is not a user-facing string, but a string for performing offset-related computations for a node.
Return a generator of all leaf text nodes in a root node.
texts: (root: Node, options?: NodeTextsOptions) => Generator<NodeEntry<Text>, void, undefined>;The Descendant
union type represents nodes that are descendants in the
tree. It is returned as a convenience in certain cases to narrow a value
further than the more generic Node
union.
The Ancestor
union type represents nodes that are ancestors in the tree.
It is returned as a convenience in certain cases to narrow a value further
than the more generic Node
union.
Convenience type for returning the props of a node.
export type NodeProps = Omit<Editor, "children"> | Omit<Element, "children"> | Omit<Text, "text">Operation
objects define the low-level instructions that Slate editors use
to apply changes to their internal state. Representing all changes as
operations is what allows Slate editors to easily implement history,
collaboration, and other features.
Check if a value is a list of Operation
objects.
Check if a value is a SelectionOperation
object.
Invert an operation, returning a new operation that will exactly undo the original when applied.
inverse: (op: Operation) => Operation;PathRef
objects keep a specific path in a document synced over time as new
operations are applied to the editor. You can access their current
property
at any time for the up-to-date path value.
Transform the path ref's current value by an operation.
transform: (ref: PathRef, op: Operation) => void;Path
arrays are a list of indexes that describe a node's exact position in
a Slate node tree. Although they are usually relative to the root Editor
object, they can be relative to any Node
object.
Get a list of ancestor paths for a given path.
The paths are sorted from shallowest to deepest ancestor. However, if the
reverse: true
option is passed, they are reversed.
Compare a path to another, returning an integer indicating whether the path was before, at, or after the other.
Note: Two paths of unequal length can still receive a 0
result if one is
directly above or below the other. If you want exact matching, use
[[Path.equals]] instead.
Check if a path ends after one of the indexes in another.
endsAfter: (path: Path, another: Path) => boolean;Check if a path ends at one of the indexes in another.
endsAt: (path: Path, another: Path) => boolean;Check if a path ends before one of the indexes in another.
endsBefore: (path: Path, another: Path) => boolean;Check if a path is equal to or an ancestor of another.
isCommon: (path: Path, another: Path) => boolean;Get a list of paths at every level down to a path. Note: this is the same
as Path.ancestors
, but including the path itself.
The paths are sorted from shallowest to deepest. However, if the reverse: true
option is passed, they are reversed.
Returns whether this operation can affect paths or not. Used as an optimization when updating dirty paths during normalization
NOTE: This must be kept in sync with the implementation of 'transform' below
Transform a path by an operation.
transform: (path: Path, operation: Operation, options?: PathTransformOptions) => Path | null;PointRef
objects keep a specific point in a document synced over time as new
operations are applied to the editor. You can access their current
property
at any time for the up-to-date point value.
Transform the point ref's current value by an operation.
transform: (ref: PointRef, op: Operation) => void;Point
objects refer to a specific location in a text node in a Slate
document. Its path refers to the location of the node in the tree, and its
offset refers to the distance into the node's string of text. Points can
only refer to Text
nodes.
Compare a point to another, returning an integer indicating whether the point was before, at, or after the other.
compare: (point: Point, another: Point) => -1 | 0 | 1;Transform a point by an operation.
transform: (point: Point, op: Operation, options?: PointTransformOptions) => Point | null;PointEntry
objects are returned when iterating over Point
objects that
belong to a range.
RangeRef
objects keep a specific range in a document synced over time as new
operations are applied to the editor. You can access their current
property
at any time for the up-to-date range value.
Transform the range ref's current value by an operation.
transform: (ref: RangeRef, op: Operation) => void;Range
objects are a set of points that refer to a specific span of a Slate
document. They can define a span inside a single node or a can span across
multiple nodes.
Get the start and end points of a range, in the order in which they appear in the document.
edges: (range: Range, options?: RangeEdgesOptions) => [Point, Point];Check if a range includes a path, a point or part of another range.
includes: (range: Range, target: Path | Point | Range) => boolean;Get the intersection of a range with another.
intersection: (range: Range, another: Range) => Range | null;Check if a range is backward, meaning that its anchor point appears in the document after its focus point.
isBackward: (range: Range) => boolean;Check if a range is collapsed, meaning that both its anchor and focus points refer to the exact same position in the document.
isCollapsed: (range: Range) => boolean;Check if a range is expanded.
This is the opposite of [[Range.isCollapsed]] and is provided for legibility.
Check if a range is forward.
This is the opposite of [[Range.isBackward]] and is provided for legibility.
Iterate through all of the point entries in a range.
points: (range: Range) => Generator<PointEntry, void, undefined>;Transform a range by an operation.
transform: (range: Range, op: Operation, options?: RangeTransformOptions) => Range | null;This interface implements a stringify() function, which is used by Slate internally when generating exceptions containing end user data. Developers using Slate may call Scrubber.setScrubber() to alter the behavior of this stringify() function.
For example, to prevent the cleartext logging of 'text' fields within Nodes:
import { Scrubber } from 'slate'; Scrubber.setScrubber((key, val) => { if (key === 'text') return '...scrubbed...' return val });
Text
objects represent the nodes that contain the actual text content of a
Slate document along with any formatting properties. They are always leaf
nodes in the document tree as they cannot contain any children.
Customize how another decoration is merged into a text node. If not specified, Object.assign
would be used.
It is useful for overlapping decorations with the same key but different values.
Check if two text nodes are equal.
When loose is set, the text is not compared. This is used to check whether sibling text nodes can be merged.
Check if an text matches set of properties.
Note: this is for matching custom properties, and it does not ensure that
the text
property are two nodes equal.
Get the leaves for a text node given decorations.
decorations: (node: Text, decorations: DecoratedRange[]) => Text[];Insert nodes in the editor at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
insertNodes: <T extends Node>(editor: Editor, nodes: Node | Node[], options?: NodeInsertNodesOptions<T>) => void;Lift nodes at a specific location upwards in the document tree, splitting their parent in two if necessary.
liftNodes: <T extends Node>(editor: Editor, options?: {Merge a node at a location with the previous node of the same depth, removing any empty containing nodes after the merge if necessary.
mergeNodes: <T extends Node>(editor: Editor, options?: {Move the nodes at a location to a new location.
moveNodes: <T extends Node>(editor: Editor, options: {Remove the nodes at a specific location in the document.
removeNodes: <T extends Node>(editor: Editor, options?: {Set new properties on the nodes at a location.
setNodes: <T extends Node>(editor: Editor, props: Partial<T>, options?: {Split the nodes at a specific location.
splitNodes: <T extends Node>(editor: Editor, options?: {Unset properties on the nodes at a location.
unsetNodes: <T extends Node>(editor: Editor, props: string | string[], options?: {Unwrap the nodes at a location from a parent node, splitting the parent if necessary to ensure that only the content in the range is unwrapped.
unwrapNodes: <T extends Node>(editor: Editor, options?: {Wrap the nodes at a location in a new container node, splitting the edges of the range first to ensure that only the content in the range is wrapped.
wrapNodes: <T extends Node>(editor: Editor, element: Element, options?: {Move the selection's point forward or backward.
move: (editor: Editor, options?: SelectionMoveOptions) => void;Set new properties on one of the selection's points.
setPoint: (editor: Editor, props: Partial<Point>, options?: SelectionSetPointOptions) => void;Insert a fragment in the editor at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
insertFragment: (editor: Editor, fragment: Node[], options?: TextInsertFragmentOptions) => void;Insert a string of text in the editor at the specified location or (if not defined) the current selection or (if not defined) the end of the document.
insertText: (editor: Editor, text: string, options?: TextInsertTextOptions) => void;Extendable Custom Types Interface
type ExtendableTypes = "Editor" | "Element" | "Text" | "Selection" | "Range" | "Point" | "Operation" | "InsertNodeOperation" | "InsertTextOperation" | "MergeNodeOperation" | "MoveNodeOperation" | "RemoveNodeOperation" | "RemoveTextOperation" | "SetNodeOperation" | "SetSelectionOperation" | "SplitNodeOperation"