import { Ancestor, Descendant, Element, ExtendedType, Location, Node, NodeEntry, Operation, Path, PathRef, Point, PointRef, Range, RangeRef, Span, Text, Transforms } from '..'; import { LeafEdge, MaximizeMode, RangeDirection, SelectionMode, TextDirection, TextUnit, TextUnitAdjustment } from '../types/types'; import { OmitFirstArg } from '../utils/types'; import { TextInsertFragmentOptions, TextInsertTextOptions } from './transforms/text'; import { NodeInsertNodesOptions } from './transforms/node'; /** * 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. */ export interface BaseEditor { children: Descendant[]; selection: Selection; operations: Operation[]; marks: EditorMarks | null; apply: (operation: Operation) => void; getDirtyPaths: (operation: Operation) => Path[]; getFragment: () => Descendant[]; isElementReadOnly: (element: Element) => boolean; isSelectable: (element: Element) => boolean; markableVoid: (element: Element) => boolean; normalizeNode: (entry: NodeEntry, options?: { operation?: Operation; }) => void; onChange: (options?: { operation?: Operation; }) => void; shouldNormalize: ({ iteration, dirtyPaths, operation, }: { iteration: number; initialDirtyPathsLength: number; dirtyPaths: Path[]; operation?: Operation; }) => boolean; addMark: OmitFirstArg; collapse: OmitFirstArg; delete: OmitFirstArg; deleteBackward: (unit: TextUnit) => void; deleteForward: (unit: TextUnit) => void; deleteFragment: OmitFirstArg; deselect: OmitFirstArg; insertBreak: OmitFirstArg; insertFragment: OmitFirstArg; insertNode: OmitFirstArg; insertNodes: OmitFirstArg; insertSoftBreak: OmitFirstArg; insertText: OmitFirstArg; liftNodes: OmitFirstArg; mergeNodes: OmitFirstArg; move: OmitFirstArg; moveNodes: OmitFirstArg; normalize: OmitFirstArg; removeMark: OmitFirstArg; removeNodes: OmitFirstArg; select: OmitFirstArg; setNodes: (props: Partial, options?: { at?: Location; match?: NodeMatch; mode?: MaximizeMode; hanging?: boolean; split?: boolean; voids?: boolean; compare?: PropsCompare; merge?: PropsMerge; }) => void; setNormalizing: OmitFirstArg; setPoint: OmitFirstArg; setSelection: OmitFirstArg; splitNodes: OmitFirstArg; unsetNodes: OmitFirstArg; unwrapNodes: OmitFirstArg; withoutNormalizing: OmitFirstArg; wrapNodes: OmitFirstArg; above: (options?: EditorAboveOptions) => NodeEntry | undefined; after: OmitFirstArg; before: OmitFirstArg; edges: OmitFirstArg; elementReadOnly: OmitFirstArg; end: OmitFirstArg; first: OmitFirstArg; fragment: OmitFirstArg; getMarks: OmitFirstArg; hasBlocks: OmitFirstArg; hasInlines: OmitFirstArg; hasPath: OmitFirstArg; hasTexts: OmitFirstArg; isBlock: OmitFirstArg; isEdge: OmitFirstArg; isEmpty: OmitFirstArg; isEnd: OmitFirstArg; isInline: OmitFirstArg; isNormalizing: OmitFirstArg; isStart: OmitFirstArg; isVoid: OmitFirstArg; last: OmitFirstArg; leaf: OmitFirstArg; levels: (options?: EditorLevelsOptions) => Generator, void, undefined>; next: (options?: EditorNextOptions) => NodeEntry | undefined; node: OmitFirstArg; nodes: (options?: EditorNodesOptions) => Generator, void, undefined>; parent: OmitFirstArg; path: OmitFirstArg; pathRef: OmitFirstArg; pathRefs: OmitFirstArg; point: OmitFirstArg; pointRef: OmitFirstArg; pointRefs: OmitFirstArg; positions: OmitFirstArg; previous: (options?: EditorPreviousOptions) => NodeEntry | undefined; range: OmitFirstArg; rangeRef: OmitFirstArg; rangeRefs: OmitFirstArg; start: OmitFirstArg; string: OmitFirstArg; unhangRange: OmitFirstArg; void: OmitFirstArg; shouldMergeNodesRemovePrevNode: OmitFirstArg; } export type Editor = ExtendedType<'Editor', BaseEditor>; export type BaseSelection = Range | null; export type Selection = ExtendedType<'Selection', BaseSelection>; export type EditorMarks = Omit; export interface EditorAboveOptions { at?: Location; match?: NodeMatch; mode?: MaximizeMode; voids?: boolean; } export interface EditorAfterOptions { distance?: number; unit?: TextUnitAdjustment; voids?: boolean; } export interface EditorBeforeOptions { distance?: number; unit?: TextUnitAdjustment; voids?: boolean; } export interface EditorDirectedDeletionOptions { unit?: TextUnit; } export interface EditorElementReadOnlyOptions { at?: Location; mode?: MaximizeMode; voids?: boolean; } export interface EditorFragmentDeletionOptions { direction?: TextDirection; } export interface EditorLeafOptions { depth?: number; edge?: LeafEdge; } export interface EditorLevelsOptions { at?: Location; match?: NodeMatch; reverse?: boolean; voids?: boolean; } export interface EditorNextOptions { at?: Location; match?: NodeMatch; mode?: SelectionMode; voids?: boolean; } export interface EditorNodeOptions { depth?: number; edge?: LeafEdge; } export interface EditorNodesOptions { at?: Location | Span; match?: NodeMatch; mode?: SelectionMode; universal?: boolean; reverse?: boolean; voids?: boolean; ignoreNonSelectable?: boolean; } export interface EditorNormalizeOptions { force?: boolean; operation?: Operation; } export interface EditorParentOptions { depth?: number; edge?: LeafEdge; } export interface EditorPathOptions { depth?: number; edge?: LeafEdge; } export interface EditorPathRefOptions { affinity?: TextDirection | null; } export interface EditorPointOptions { edge?: LeafEdge; } export interface EditorPointRefOptions { affinity?: TextDirection | null; } export interface EditorPositionsOptions { at?: Location; unit?: TextUnitAdjustment; reverse?: boolean; voids?: boolean; ignoreNonSelectable?: boolean; } export interface EditorPreviousOptions { at?: Location; match?: NodeMatch; mode?: SelectionMode; voids?: boolean; } export interface EditorRangeRefOptions { affinity?: RangeDirection | null; } export interface EditorStringOptions { voids?: boolean; } export interface EditorUnhangRangeOptions { voids?: boolean; } export interface EditorVoidOptions { at?: Location; mode?: MaximizeMode; voids?: boolean; } export interface EditorInterface { /** * Get the ancestor above a location in the document. */ above: (editor: Editor, options?: EditorAboveOptions) => NodeEntry | 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. */ addMark: (editor: Editor, key: string, value: any) => void; /** * 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; /** * Get the start and end points of a location. */ edges: (editor: Editor, at: Location) => [Point, Point]; /** * Match a read-only element in the current branch of the editor. */ elementReadOnly: (editor: Editor, options?: EditorElementReadOnlyOptions) => NodeEntry | undefined; /** * Get the end point of a location. */ end: (editor: Editor, at: Location) => Point; /** * Get the first node at a location. */ first: (editor: Editor, at: Location) => NodeEntry; /** * Get the fragment at a location. */ fragment: (editor: Editor, at: Location) => Descendant[]; /** * Check if a node has block children. */ hasBlocks: (editor: Editor, element: Element) => boolean; /** * Check if a node has inline and text children. */ hasInlines: (editor: Editor, element: Element) => boolean; hasPath: (editor: Editor, path: Path) => boolean; /** * Check if a node has text children. */ hasTexts: (editor: Editor, element: Element) => boolean; /** * Insert a block break at the current selection. * * If the selection is currently expanded, it will be deleted first. */ insertBreak: (editor: Editor) => void; /** * 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. */ insertNode: (editor: Editor, node: Node, options?: NodeInsertNodesOptions) => void; /** * Insert a soft break at the current selection. * * If the selection is currently expanded, it will be deleted first. */ insertSoftBreak: (editor: Editor) => void; /** * 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 value is a block `Element` object. */ isBlock: (editor: Editor, value: Element) => boolean; /** * Check if a point is an edge of a location. */ isEdge: (editor: Editor, point: Point, at: Location) => boolean; /** * Check if a value is an `Editor` object. */ isEditor: (value: any) => value is Editor; /** * Check if a value is a read-only `Element` object. */ isElementReadOnly: (editor: Editor, element: Element) => boolean; /** * 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 a value is an inline `Element` object. */ isInline: (editor: Editor, value: Element) => boolean; /** * Check if the editor is currently normalizing after each operation. */ isNormalizing: (editor: Editor) => boolean; /** * Check if a value is a selectable `Element` object. */ isSelectable: (editor: Editor, element: Element) => boolean; /** * Check if a point is the start point of a location. */ isStart: (editor: Editor, point: Point, at: Location) => boolean; /** * Check if a value is a void `Element` object. */ isVoid: (editor: Editor, value: Element) => boolean; /** * Get the last node at a location. */ last: (editor: Editor, at: Location) => NodeEntry; /** * Get the leaf text node at a location. */ leaf: (editor: Editor, at: Location, options?: EditorLeafOptions) => NodeEntry; /** * Iterate through all of the levels at a location. */ levels: (editor: Editor, options?: EditorLevelsOptions) => Generator, void, undefined>; /** * Get the marks that would be added to text at the current selection. */ marks: (editor: Editor) => Omit | null; /** * Get the matching node in the branch of the document after a location. */ next: (editor: Editor, options?: EditorNextOptions) => NodeEntry | 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: (editor: Editor, options?: EditorNodesOptions) => Generator, 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; /** * 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. */ pathRef: (editor: Editor, path: Path, options?: EditorPathRefOptions) => PathRef; /** * Get the set of currently tracked path refs of the editor. */ pathRefs: (editor: Editor) => Set; /** * 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. */ pointRef: (editor: Editor, point: Point, options?: EditorPointRefOptions) => PointRef; /** * Get the set of currently tracked point refs of the editor. */ pointRefs: (editor: Editor) => Set; /** * 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. */ positions: (editor: Editor, options?: EditorPositionsOptions) => Generator; /** * Get the matching node in the branch of the document before a location. */ previous: (editor: Editor, options?: EditorPreviousOptions) => NodeEntry | undefined; /** * Get a range of a location. */ range: (editor: Editor, at: Location, to?: Location) => Range; /** * Create a mutable ref for a `Range` object, which will stay in sync as new * operations are applied to the editor. */ rangeRef: (editor: Editor, range: Range, options?: EditorRangeRefOptions) => RangeRef; /** * Get the set of currently tracked range refs of the editor. */ rangeRefs: (editor: Editor) => Set; /** * 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. */ removeMark: (editor: Editor, key: string) => void; /** * Manually set if the editor should currently be normalizing. * * Note: Using this incorrectly can leave the editor in an invalid state. * */ setNormalizing: (editor: Editor, isNormalizing: boolean) => void; /** * Get the start point of a location. */ start: (editor: Editor, at: Location) => Point; /** * 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 */ string: (editor: Editor, at: Location, options?: EditorStringOptions) => string; /** * 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 | 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; } export declare const Editor: EditorInterface; /** * A helper type for narrowing matched nodes with a predicate. */ export type NodeMatch = ((node: Node, path: Path) => node is T) | ((node: Node, path: Path) => boolean); export type PropsCompare = (prop: Partial, node: Partial) => boolean; export type PropsMerge = (prop: Partial, node: Partial) => object; //# sourceMappingURL=editor.d.ts.map