Socket
Socket
Sign inDemoInstall

@udecode/slate

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udecode/slate - npm Package Compare versions

Comparing version 23.7.4 to 24.3.0

dist/index.d.mts

1082

dist/index.d.ts

@@ -0,10 +1,1076 @@

import { UnknownObject, Simplify, UnionToIntersection, Modify } from '@udecode/utils';
import * as slate from 'slate';
import { Path, Location, Range, Selection, Span, Editor, Point, EditorLevelsOptions, NodeAncestorsOptions, NodeChildrenOptions, NodeDescendantsOptions, NodeElementsOptions, NodeLevelsOptions, NodeTextsOptions, NodeNodesOptions, EditorNextOptions, EditorUnhangRangeOptions, EditorNodesOptions, EditorNodeOptions, EditorParentOptions, EditorPathOptions, EditorPointOptions, EditorAfterOptions, EditorBeforeOptions, EditorPositionsOptions, EditorPreviousOptions, EditorVoidOptions, EditorNormalizeOptions, Transforms } from 'slate';
import { EditorPathRefOptions, EditorPointRefOptions, EditorRangeRefOptions, EditorDirectedDeletionOptions, EditorFragmentDeletionOptions, EditorAboveOptions, EditorStringOptions, EditorLeafOptions } from 'slate/dist/interfaces/editor';
import { HistoryEditor } from 'slate-history';
import { SelectionCollapseOptions, SelectionMoveOptions, SelectionSetPointOptions } from 'slate/dist/interfaces/transforms/selection';
import { TextDeleteOptions, TextInsertFragmentOptions, TextInsertTextOptions } from 'slate/dist/interfaces/transforms/text';
import { RenderLeafProps } from 'slate-react';
/**
* @file Automatically generated by barrelsby.
* `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.
*/
export * from './createTEditor';
export * from './interfaces/index';
export * from './queries/index';
export * from './transforms/index';
export * from './types/index';
export * from './utils/index';
//# sourceMappingURL=index.d.ts.map
type TText = UnknownObject & {
text: string;
};
/**
* Text node of an editor.
*/
type EText<V extends Value> = TextOf<TEditor<V>>;
/**
* A utility type to get all the text node types from a root node type.
*/
type TextOf<N extends TNode> = TEditor extends N ? TText : TElement extends N ? TText : N extends TEditor ? TextOf<N['children'][number]> : N extends TElement ? Extract<N['children'][number], TText> | TextOf<N['children'][number]> : N extends TText ? N : never;
/**
* A utility type to get all the mark types from a root node type.
*/
type MarksOf<N extends TNode> = Simplify<UnionToIntersection<TNodeProps<TextOf<N>>>>;
type EMarks<V extends Value> = MarksOf<TEditor<V>>;
type MarkKeysOf<N extends TNode> = {} extends MarksOf<N> ? unknown : keyof MarksOf<N>;
type TNode = TEditor | TElement | TText;
/**
* Node of an editor.
*/
type ENode<V extends Value> = NodeOf<TEditor<V>>;
/**
* A utility type to get all the node types from a root node type.
*/
type NodeOf<N extends TNode> = N | ElementOf<N> | TextOf<N>;
/**
* Convenience type for returning the props of a node.
*/
type TNodeProps<N extends TNode> = N extends TEditor ? Omit<N, 'children'> : N extends TElement ? Omit<N, 'children'> : Omit<N, 'text'>;
/**
* A helper type for narrowing matched nodes with a predicate.
*/
type TNodeMatch<N extends TNode = TNode> = ((node: N, path: Path) => node is N) | ((node: N, 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.
*/
type TElement = UnknownObject & {
children: TDescendant[];
type: string;
};
/**
* Element of an editor.
*/
type EElement<V extends Value> = ElementOf<TEditor<V>>;
/**
* Element or text of an editor. Differs from EDescendant<V>.
*/
type EElementOrText<V extends Value> = EElement<V> | EText<V>;
/**
* `ElementEntry` objects refer to an `Element` and the `Path` where it can be
* found inside a root node.
*/
/**
* A utility type to get all the element nodes type from a root node.
*/
type ElementOf<N extends TNode> = TEditor extends N ? TElement : TElement extends N ? TElement : N extends TEditor ? Extract<N['children'][number], TElement> | ElementOf<N['children'][number]> : N extends TElement ? N | Extract<N['children'][number], TElement> | ElementOf<N['children'][number]> : never;
/**
* 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.
*/
type TDescendant = TElement | TText;
/**
* Descendant of an editor.
*/
type EDescendant<V extends Value> = DescendantOf<TEditor<V>>;
/**
* A utility type to get all the descendant node types from a root node type.
*/
type DescendantOf<N extends TNode> = N extends TEditor ? ElementOf<N> | TextOf<N> : N extends TElement ? ElementOf<N['children'][number]> | TextOf<N> : never;
/**
* A utility type to get the child node types from a root node type.
*/
type ChildOf<N extends TNode, I extends number = number> = N extends TEditor ? N['children'][I] : N extends TElement ? N['children'][I] : never;
declare const isDescendant: (value: any) => value is TDescendant;
type TLocation = Location;
type TPath = Path;
type TRange = Range;
type TSelection = Selection;
type TSpan = Span;
type TInsertNodeOperation<N extends TDescendant = TDescendant> = {
type: 'insert_node';
path: TPath;
node: N;
[key: string]: unknown;
};
type TInsertTextOperation = {
type: 'insert_text';
path: TPath;
offset: number;
text: string;
[key: string]: unknown;
};
type TMergeNodeOperation = {
type: 'merge_node';
path: TPath;
position: number;
properties: object;
[key: string]: unknown;
};
type TMoveNodeOperation = {
type: 'move_node';
path: TPath;
newPath: TPath;
[key: string]: unknown;
};
type TRemoveNodeOperation<N extends TDescendant = TDescendant> = {
type: 'remove_node';
path: TPath;
node: N;
[key: string]: unknown;
};
type TRemoveTextOperation = {
type: 'remove_text';
path: TPath;
offset: number;
text: string;
[key: string]: unknown;
};
type TSetNodeOperation = {
type: 'set_node';
path: TPath;
properties: object;
newProperties: object;
[key: string]: unknown;
};
type TSetSelectionOperation = {
type: 'set_selection';
properties: null;
newProperties: TRange;
[key: string]: unknown;
} | {
type: 'set_selection';
properties: Partial<TRange>;
newProperties: Partial<TRange>;
[key: string]: unknown;
} | {
type: 'set_selection';
properties: TRange;
newProperties: null;
[key: string]: unknown;
};
type TSplitNodeOperation = {
type: 'split_node';
path: TPath;
position: number;
properties: object;
[key: string]: unknown;
};
type TNodeOperation<N extends TDescendant = TDescendant> = TInsertNodeOperation<N> | TMergeNodeOperation | TMoveNodeOperation | TRemoveNodeOperation<N> | TSetNodeOperation | TSplitNodeOperation;
type TSelectionOperation = TSetSelectionOperation;
type TTextOperation = TInsertTextOperation | TRemoveTextOperation;
/**
* `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.
*/
type TOperation<N extends TDescendant = TDescendant> = TNodeOperation<N> | TSelectionOperation | TTextOperation;
/**
* 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.
*/
type TAncestor = TEditor | TElement;
/**
* Ancestor of an editor.
*/
type EAncestor<V extends Value> = AncestorOf<TEditor<V>>;
/**
* A utility type to get all the ancestor node types from a root node type.
*/
type AncestorOf<N extends TNode> = TEditor extends N ? TEditor | TElement : TElement extends N ? TElement : N extends TEditor ? N | N['children'][number] | ElementOf<N['children'][number]> : N extends TElement ? N | ElementOf<N> : never;
/**
* `TNodeEntry` objects are returned when iterating over the nodes in a Slate
* document tree. They consist of the node and its `Path` relative to the root
* node in the document.
*/
type TNodeEntry<N extends TNode = TNode> = [N, Path];
/**
* Node entry from an editor.
*/
type ENodeEntry<V extends Value> = TNodeEntry<ENode<V>>;
/**
* Element entry from a node.
*/
type TElementEntry<N extends TNode = TNode> = TNodeEntry<ElementOf<N>>;
/**
* Element entry from an editor.
*/
/**
* Element entry of a value.
*/
type EElementEntry<V extends Value> = TNodeEntry<EElement<V>>;
/**
* Text node entry from a node.
*/
type TTextEntry<N extends TNode = TNode> = TNodeEntry<TextOf<N>>;
/**
* Text node entry from an editor.
*/
/**
* Text node entry of a value.
*/
type ETextEntry<V extends Value> = TNodeEntry<EText<V>>;
/**
* Ancestor entry from a node.
*/
type TAncestorEntry<N extends TNode = TNode> = TNodeEntry<AncestorOf<N>>;
/**
* Ancestor entry from an editor.
*/
type EAncestorEntry<V extends Value> = TAncestorEntry<TEditor<V>>;
/**
* Descendant entry from a node.
*/
type TDescendantEntry<N extends TNode = TNode> = TNodeEntry<DescendantOf<N>>;
/**
* Descendant entry from an editor.
*/
/**
* Descendant entry of a value.
*/
type EDescendantEntry<V extends Value> = TNodeEntry<EDescendant<V>>;
/**
* Child node entry from a node.
*/
type TNodeChildEntry<N extends TNode = TNode> = TNodeEntry<ChildOf<N>>;
type Value = TElement[];
/**
* A helper type for getting the value of an editor.
*/
type ValueOf<E extends TEditor> = E['children'];
type TEditor<V extends Value = Value> = Modify<Editor, {
id: any;
children: V;
operations: TOperation[];
marks: Record<string, any> | null;
isInline: <N extends TElement>(element: N) => boolean;
isVoid: <N extends TElement>(element: N) => boolean;
markableVoid: <N extends TElement>(element: N) => boolean;
normalizeNode: <N extends TNode>(entry: TNodeEntry<N>) => void;
apply: <N extends TDescendant>(operation: TOperation<N>) => void;
getFragment: <N extends TDescendant>() => N[];
insertFragment: <N extends TDescendant>(fragment: N[]) => void;
insertNode: <N extends TDescendant>(node: N) => void;
getDirtyPaths: <N extends TDescendant>(operation: TOperation<N>) => Path[];
}> & UnknownObject;
/**
* Get editor with typed methods and operations.
* Note that it can't be used as a parameter of type TEditor.
*/
declare const getTEditor: <V extends Value, E extends TEditor<V> = TEditor<V>>(editor: E) => Modify<E, {
operations: TOperation<EElementOrText<V>>[];
isInline: (element: EElement<V>) => boolean;
isVoid: (element: EElement<V>) => boolean;
normalizeNode: (entry: TNodeEntry<ENode<V>>) => void;
apply: (operation: TOperation<EElementOrText<V>>) => void;
getFragment: () => EElementOrText<V>[];
insertFragment: (fragment: EElementOrText<V>[]) => void;
insertNode: (node: EElementOrText<V> | EElementOrText<V>[]) => void;
}>;
declare const createTEditor: <V extends Value>() => TEditor<V>;
/**
* 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.
*/
declare const addMark: <V extends Value>(editor: TEditor<V>, key: string, value: any) => void;
/**
* Create a mutable ref for a `Path` object, which will stay in sync as new
* operations are applied to the editor.
*/
declare const createPathRef: <V extends Value>(editor: TEditor<V>, at: Path, options?: EditorPathRefOptions) => slate.PathRef;
/**
* Create a mutable ref for a `Point` object, which will stay in sync as new
* operations are applied to the editor.
*/
declare const createPointRef: <V extends Value>(editor: TEditor<V>, point: Point, options?: EditorPointRefOptions) => slate.PointRef;
/**
* Create a mutable ref for a `Range` object, which will stay in sync as new
* operations are applied to the editor.
*/
declare const createRangeRef: <V extends Value>(editor: TEditor<V>, range: Range, options?: EditorRangeRefOptions) => slate.RangeRef;
/**
* Delete content in the editor backward from the current selection.
*/
declare const deleteBackward: <V extends Value>(editor: TEditor<V>, options?: EditorDirectedDeletionOptions) => void;
/**
* Delete content in the editor forward from the current selection.
*/
declare const deleteForward: <V extends Value>(editor: TEditor<V>, options?: EditorDirectedDeletionOptions) => void;
/**
* Delete the content in the current selection.
*/
declare const deleteFragment: <V extends Value>(editor: TEditor<V>, options?: EditorFragmentDeletionOptions) => void;
declare const deleteMerge: <V extends Value>(editor: TEditor<V>, options?: {
at?: Location;
distance?: number;
unit?: 'character' | 'word' | 'line' | 'block';
reverse?: boolean;
hanging?: boolean;
voids?: boolean;
test?: any;
}) => void;
type PredicateObj = Record<string, any | any[]>;
type PredicateFn<T extends TNode> = (obj: T, path: TPath) => boolean;
type Predicate<T extends TNode> = PredicateObj | PredicateFn<T>;
/**
* Match the object with a predicate object or function.
* If predicate is:
* - object: every predicate key/value should be in obj.
* - function: it should return true.
*/
declare const match: <T extends TNode>(obj: T, path: slate.Path, predicate?: Predicate<T> | undefined) => boolean;
/**
* Extended query options for slate queries:
* - `match` can be an object predicate where one of the values should include the node value.
* Example: { type: ['1', '2'] } will match the nodes having one of these 2 types.
*/
declare const getQueryOptions: <V extends Value>(editor: TEditor<V>, options?: any) => any;
type ENodeMatch<N extends TNode> = Predicate<N>;
interface ENodeMatchOptions<V extends Value = Value> {
match?: ENodeMatch<ENode<V>>;
block?: boolean;
}
type GetAboveNodeOptions<V extends Value = Value> = Modify<NonNullable<EditorAboveOptions<TAncestor>>, ENodeMatchOptions<V>>;
/**
* Get the ancestor above a location in the document.
*/
declare const getAboveNode: <N extends EAncestor<V>, V extends Value = Value>(editor: TEditor<V>, options?: GetAboveNodeOptions<V> | undefined) => TNodeEntry<N> | undefined;
/**
* Get the start and end points of a location.
*/
declare const getEdgePoints: <V extends Value>(editor: TEditor<V>, at: Location) => [slate.BasePoint, slate.BasePoint];
/**
* 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
*/
declare const getEditorString: <V extends Value>(editor: TEditor<V>, at: Location | null | undefined, options?: EditorStringOptions) => string;
/**
* Get the end point of a location.
*/
declare const getEndPoint: <V extends Value>(editor: TEditor<V>, at: Location) => slate.BasePoint;
/**
* Get the first node at a location.
*/
declare const getFirstNode: <V extends Value>(editor: TEditor<V>, at: Location) => ENodeEntry<V>;
/**
* Get the fragment at a location.
*/
declare const getFragment: <V extends Value>(editor: TEditor<V>, at: Location) => EElementOrText<V>[];
/**
* Get the last node at a location.
*/
declare const getLastNode: <V extends Value>(editor: TEditor<V>, at: Location) => ENodeEntry<V>;
/**
* Get the leaf text node at a location.
*/
declare const getLeafNode: <V extends Value>(editor: TEditor<V>, at: Location, options?: EditorLeafOptions) => ETextEntry<V>;
type GetLevelsOptions<V extends Value = Value> = Modify<NonNullable<EditorLevelsOptions<TNode>>, {
match?: TNodeMatch<ENode<V>>;
}>;
/**
* Iterate through all of the levels at a location.
*/
declare const getLevels: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, options?: GetLevelsOptions<V> | undefined) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Get the marks that would be added to text at the current selection.
*/
declare const getMarks: <V extends Value>(editor: TEditor<V>) => EMarks<V> | null;
/**
* Get an entry for the common ancesetor node of two paths.
*/
declare const getCommonNode: <N extends NodeOf<R>, R extends TNode = TNode>(root: R, path: Path, another: Path) => TNodeEntry<N>;
/**
* Get the descendant node referred to by a specific path.
* If the path is an empty array, it refers to the root node itself.
* If the node is not found, return null.
* Based on Slate get and has, performance optimization without overhead of
* stringify on throwing
*/
declare const getNode: <N extends NodeOf<R>, R extends TNode = TNode>(root: R, path: Path) => N | null;
/**
* Get the node at a specific path, asserting that it's an ancestor node.
*/
declare const getNodeAncestor: <N extends AncestorOf<R>, R extends TNode = TNode>(root: R, path: Path) => N;
/**
* Return a generator of all the ancestor nodes above a specific path.
*
* By default the order is bottom-up, from lowest to highest ancestor in
* the tree, but you can pass the `reverse: true` option to go top-down.
*/
declare const getNodeAncestors: <N extends AncestorOf<R>, R extends TNode = TNode>(root: R, path: Path, options?: NodeAncestorsOptions) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Get the child of a node at a specific index.
*/
declare const getNodeChild: <N extends ChildOf<R, I>, R extends TNode = TNode, I extends number = number>(root: R, index: I) => N;
/**
* Iterate over the children of a node at a specific path.
*/
declare const getNodeChildren: <N extends ChildOf<R>, R extends TNode = TNode>(root: R, path: Path, options?: NodeChildrenOptions) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Get the node at a specific path, asserting that it's a descendant node.
*/
declare const getNodeDescendant: <N extends DescendantOf<R>, R extends TNode = TNode>(root: R, path: Path) => N;
/**
* Return a generator of all the descendant node entries inside a root node.
*/
declare const getNodeDescendants: <N extends DescendantOf<R>, R extends TNode = TNode>(root: R, options?: Modify<NodeDescendantsOptions, {
pass?: ((node: TDescendantEntry<N>) => boolean) | undefined;
}> | undefined) => Generator<TNodeEntry<N>, 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.
*/
declare const getNodeElements: <N extends ElementOf<R>, R extends TNode = TNode>(root: R, options?: Modify<NodeElementsOptions, {
pass?: ((node: TElementEntry<N>) => boolean) | undefined;
}> | undefined) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Get the first node entry in a root node from a path.
*/
declare const getNodeFirstNode: <N extends NodeOf<R>, R extends TNode = TNode>(root: R, path: Path) => TNodeEntry<N>;
/**
* Get the sliced fragment represented by a range inside a root node.
*/
declare const getNodeFragment: <N extends ElementOf<R> | TextOf<R>, R extends TNode = TNode>(root: R, range: Range) => N[];
/**
* Get the last node entry in a root node from a path.
*/
declare const getNodeLastNode: <N extends NodeOf<R>, R extends TNode = TNode>(root: R, path: Path) => TNodeEntry<N>;
/**
* Get the node at a specific path, ensuring it's a leaf text node.
*/
declare const getNodeLeaf: <N extends TextOf<R>, R extends TNode = TNode>(root: R, path: Path) => N;
/**
* Return a generator of the in a branch of the tree, from a specific path.
*
* By default the order is top-down, from lowest to highest node in the tree,
* but you can pass the `reverse: true` option to go bottom-up.
*/
declare const getNodeLevels: <N extends NodeOf<R>, R extends TNode = TNode>(root: R, path: Path, options?: NodeLevelsOptions) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Get the parent of a node at a specific path.
*/
declare const getNodeParent: <N extends AncestorOf<R>, R extends TNode = TNode>(root: R, path: Path) => N;
/**
* Extract the custom properties from a node.
*/
declare const getNodeProps: <N extends TNode>(node: N) => TNodeProps<N>;
/**
* 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.
*/
declare const getNodeString: (node: TNode) => string;
/**
* Return a generator of all leaf text nodes in a root node.
*/
declare const getNodeTexts: <N extends TextOf<R>, R extends TNode = TNode>(root: R, options?: Modify<NodeTextsOptions, {
pass?: ((entry: TNodeEntry<NodeOf<N>>) => boolean) | undefined;
}> | undefined) => Generator<TNodeEntry<N>, void, undefined>;
/**
* 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.
*/
declare const getNodes: <N extends NodeOf<R>, R extends TNode = TNode>(root: R, options?: Modify<NodeNodesOptions, {
pass?: ((entry: TNodeEntry<NodeOf<N>>) => boolean) | undefined;
}> | undefined) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Check if a descendant node exists at a specific path.
*/
declare const hasNode: (root: TNode, path: Path) => boolean;
declare const hasSingleChild: <N extends TNode>(node: N) => boolean;
/**
* Check if a value implements the 'Ancestor' interface.
*/
declare const isAncestor: (value: any) => value is TAncestor;
/**
* Check if a value implements the `Node` interface.
*/
declare const isNode: (value: any) => value is TNode;
/**
* Check if a value is a list of `Node` objects.
*/
declare const isNodeList: (value: any) => value is TNode[];
/**
* Check if a node matches a set of props.
*/
declare const nodeMatches: (node: TNode, props: object) => boolean;
type GetNextNodeOptions<V extends Value = Value> = Modify<NonNullable<EditorNextOptions<TDescendant>>, {
match?: TNodeMatch<ENode<V>>;
}>;
/**
* Get the matching node in the branch of the document after a location.
*/
declare const getNextNode: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, options?: GetNextNodeOptions<V> | undefined) => TNodeEntry<N> | undefined;
type UnhangRangeOptions = EditorUnhangRangeOptions & {
unhang?: boolean;
};
/**
* Convert a range into a non-hanging one if:
* - `unhang` is true,
* - `at` (default: selection) is a range.
*/
declare const unhangRange: <V extends Value, R extends Path | slate.BasePoint | slate.BaseRange | Span | null | undefined>(editor: TEditor<V>, range: R, options?: UnhangRangeOptions) => R;
type GetNodeEntriesOptions<V extends Value = Value> = Modify<NonNullable<EditorNodesOptions<TNode>>, ENodeMatchOptions<V>> & UnhangRangeOptions;
/**
* Iterate through all of the nodes in the Editor.
*/
declare const getNodeEntries: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, options?: GetNodeEntriesOptions<V> | undefined) => Generator<TNodeEntry<N>, void, undefined>;
/**
* Get the node at a location.
*/
declare const getNodeEntry: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, at: Location, options?: EditorNodeOptions) => TNodeEntry<N> | undefined;
/**
* Get the parent node of a location.
* Returns undefined if there is no parent.
*/
declare const getParentNode: <N extends EAncestor<V>, V extends Value = Value>(editor: TEditor<V>, at: Location, options?: EditorParentOptions) => TNodeEntry<N> | undefined;
/**
* Get the path of a location.
*/
declare const getPath: <V extends Value>(editor: TEditor<V>, at: Location, options?: EditorPathOptions) => slate.Path;
/**
* Get the set of currently tracked path refs of the editor.
*/
declare const getPathRefs: <V extends Value>(editor: TEditor<V>) => Set<slate.PathRef>;
/**
* Get the start or end point of a location.
*/
declare const getPoint: <V extends Value>(editor: TEditor<V>, at: Location, options?: EditorPointOptions) => slate.BasePoint;
/**
* Get the point after a location.
*/
declare const getPointAfter: <V extends Value>(editor: TEditor<V>, at: Location, options?: EditorAfterOptions) => slate.BasePoint | undefined;
/**
* Get the point before a location.
*/
declare const getPointBefore: <V extends Value>(editor: TEditor<V>, at: Location, options?: EditorBeforeOptions) => slate.BasePoint | undefined;
/**
* Get the set of currently tracked point refs of the editor.
*/
declare const getPointRefs: <V extends Value>(editor: TEditor<V>) => Set<slate.PointRef>;
/**
* Iterate through all of the positions in the document where a `Point` can be
* placed.
*
* By default it will move forward by individual offsets at a time, but you
* can pass the `unit: 'character'` option to moved forward one character, word,
* or line at at time.
*
* 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.
*/
declare const getPositions: <V extends Value>(editor: TEditor<V>, options?: EditorPositionsOptions) => Generator<slate.BasePoint, void, undefined>;
type GetPreviousNodeOptions<V extends Value = Value> = Modify<NonNullable<EditorPreviousOptions<TNode>>, {
match?: TNodeMatch<ENode<V>>;
}>;
/**
* Get the matching node in the branch of the document before a location.
*/
declare const getPreviousNode: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, options?: GetPreviousNodeOptions<V> | undefined) => TNodeEntry<N> | undefined;
/**
* Get a range of a location.
*/
declare const getRange: <V extends Value>(editor: TEditor<V>, at: Location, to?: Location) => slate.BaseRange;
/**
* Get the set of currently tracked range refs of the editor.
*/
declare const getRangeRefs: <V extends Value>(editor: TEditor<V>) => Set<slate.RangeRef>;
/**
* Get the start point of a location.
*/
declare const getStartPoint: <V extends Value>(editor: TEditor<V>, at: Location) => slate.BasePoint;
/**
* Match a void node in the current branch of the editor.
*/
declare const getVoidNode: <N extends EElement<V>, V extends Value = Value>(editor: TEditor<V>, options?: EditorVoidOptions) => TNodeEntry<N> | undefined;
/**
* Check if a node has block children.
*/
declare const hasBlocks: <V extends Value>(editor: TEditor<V>, element: TElement) => boolean;
/**
* Check if a node has inline and text children.
*/
declare const hasInlines: <V extends Value>(editor: TEditor<V>, element: TElement) => boolean;
/**
* Check if a node has text children.
*/
declare const hasTexts: <V extends Value>(editor: TEditor<V>, element: TElement) => boolean;
/**
* Insert a block break at the current selection.
*
* If the selection is currently expanded, it will be deleted first.
*/
declare const insertBreak: <V extends Value>(editor: TEditor<V>) => void;
/**
* Insert a node at the current selection.
*
* If the selection is currently expanded, it will be deleted first.
*/
declare const insertNode: <V extends Value>(editor: TEditor<V>, node: EElementOrText<V> | EElementOrText<V>[]) => void;
/**
* Check if a value is a block `Element` object.
*/
declare const isBlock: <V extends Value>(editor: TEditor<V>, value: any) => boolean;
/**
* Check if a point is an edge of a location.
*/
declare const isEdgePoint: <V extends Value>(editor: TEditor<V>, point: Point, at: Location) => boolean;
/**
* Check if a value is an `Editor` object.
*/
declare const isEditor: (value: any) => value is TEditor;
/**
* Check if the editor is currently normalizing after each operation.
*/
declare const isEditorNormalizing: <V extends Value>(editor: TEditor<V>) => boolean;
/**
* Check if an element is empty, accounting for void nodes.
*/
declare const isElementEmpty: <V extends Value>(editor: TEditor<V>, element: EElement<V>) => boolean;
/**
* Check if a point is the end point of a location.
* If point is null, return false.
*/
declare const isEndPoint: <V extends Value>(editor: TEditor<V>, point: Point | null | undefined, at: Location) => boolean;
/**
* Check if a value is an inline `Element` object.
*/
declare const isInline: <V extends Value>(editor: TEditor<V>, value: any) => boolean;
/**
* Check if a value is a markable void `Element` object.
*/
declare const isMarkableVoid: <V extends Value>(editor: TEditor<V>, value: any) => boolean;
/**
* Check if a point is the start point of a location.
* If point is null, return false.
*/
declare const isStartPoint: <V extends Value>(editor: TEditor<V>, point: Point | null | undefined, at: Location) => boolean;
/**
* Check if a value is a void `Element` object.
*/
declare const isVoid: <V extends Value>(editor: TEditor<V>, value: any) => boolean;
/**
* Normalize any dirty objects in the editor.
*/
declare const normalizeEditor: <V extends Value>(editor: TEditor<V>, 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.
*/
declare const removeEditorMark: <V extends Value>(editor: TEditor<V>, key: string) => void;
/**
* Call a function, deferring normalization until after it completes
* @return true if normalized.
*/
declare const withoutNormalizing: <V extends Value>(editor: TEditor<V>, fn: () => boolean | void) => boolean;
/**
* Check if an element matches set of properties.
*
* Note: this checks custom properties, and it does not ensure that any
* children are equivalent.
*/
declare const elementMatches: (element: TElement, props: object) => boolean;
/**
* Check if a value implements the 'Element' interface.
*/
declare const isElement: (value: any) => value is TElement;
/**
* Check if a value is an array of `Element` objects.
*/
declare const isElementList: (value: any) => value is TElement[];
type THistoryEditor<V extends Value = Value> = TEditor<V> & Pick<HistoryEditor, 'history' | 'undo' | 'redo'>;
/**
* {@link HistoryEditor.isHistoryEditor}
*/
declare const isHistoryEditor: (value: any) => value is THistoryEditor;
/**
* {@link HistoryEditor.isMerging}
*/
declare const isHistoryMerging: <V extends Value>(editor: THistoryEditor<V>) => boolean | undefined;
/**
* {@link HistoryEditor.isSaving}
*/
declare const isHistorySaving: <V extends Value>(editor: THistoryEditor<V>) => boolean | undefined;
/**
* {@link HistoryEditor.withoutMerging}
*/
declare const withoutMergingHistory: <V extends Value>(editor: THistoryEditor<V>, fn: () => void) => void;
/**
* {@link HistoryEditor.withoutSaving}
*/
declare const withoutSavingHistory: <V extends Value>(editor: THistoryEditor<V>, fn: () => void) => void;
/**
* See {@link Range.isCollapsed}.
* Return false if `range` is not defined.
*/
declare const isCollapsed: (range?: Range | null) => boolean;
/**
* See {@link Range.isExpanded}.
* Return false if `range` is not defined.
*/
declare const isExpanded: (range?: Range | null) => boolean;
/**
* Check if a value implements the `Text` interface.
*/
declare const isText: (value: any) => value is TText;
/**
* Check if a value is a list of `Text` objects.
*/
declare const isTextList: (value: any) => value is TText[];
/**
* Check if two text nodes are equal.
*/
declare const textEquals: (text: TText, another: TText) => boolean;
/**
* 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.
*/
declare const textMatches: <T extends TText>(text: T, props: object) => boolean;
/**
* Collapse the selection.
*/
declare const collapseSelection: <V extends Value>(editor: TEditor<V>, options?: SelectionCollapseOptions) => void;
/**
* Delete content in the editor.
*/
declare const deleteText: <V extends Value>(editor: TEditor<V>, options?: TextDeleteOptions) => void;
/**
* Unset the selection.
*/
declare const deselect: <V extends Value>(editor: TEditor<V>) => void;
/**
* Insert a fragment at a specific location in the editor.
*/
declare const insertFragment: <N extends EElementOrText<V>, V extends Value = Value>(editor: TEditor<V>, fragment: N[], options?: TextInsertFragmentOptions) => void;
interface NodeMatchOption<V extends Value> {
match?: TNodeMatch<ENode<V>>;
}
type InsertNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.insertNodes>[2]>, NodeMatchOption<V>> & {
nextBlock?: boolean;
};
/**
* Insert nodes at a specific location in the Editor.
*/
declare const insertNodes: <N extends EElementOrText<V>, V extends Value = Value>(editor: TEditor<V>, nodes: N | N[], options?: InsertNodesOptions<V> | undefined) => void;
/**
* Insert a string of text in the Editor.
*/
declare const insertText: <V extends Value>(editor: TEditor<V>, text: string, options?: TextInsertTextOptions) => void;
type LiftNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.liftNodes>[1]>, NodeMatchOption<V>>;
/**
* Lift nodes at a specific location upwards in the document tree, splitting
* their parent in two if necessary.
*/
declare const liftNodes: <V extends Value>(editor: TEditor<V>, options?: LiftNodesOptions<V> | undefined) => void;
type MergeNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.mergeNodes>[1]>, NodeMatchOption<V>> & {
/**
* Default: if the node isn't already the next sibling of the previous node, move
* it so that it is before merging.
*/
mergeNode?: (editor: TEditor<V>, options: {
at: Path;
to: Path;
}) => void;
/**
* Default: if there was going to be an empty ancestor of the node that was merged,
* we remove it from the tree.
*/
removeEmptyAncestor?: (editor: TEditor<V>, options: {
at: Path;
}) => void;
};
/**
* Merge a node at a location with the previous node of the same depth,
* removing any empty containing nodes after the merge if necessary.
*/
declare const mergeNodes: <V extends Value>(editor: TEditor<V>, options?: MergeNodesOptions<V>) => void;
type MoveNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.moveNodes>[1]>, NodeMatchOption<V>>;
/**
* Move the nodes at a location to a new location.
*/
declare const moveNodes: <V extends Value>(editor: TEditor<V>, options?: MoveNodesOptions<V> | undefined) => void;
/**
* Move the selection's point forward or backward.
*/
declare const moveSelection: <V extends Value>(editor: TEditor<V>, options?: SelectionMoveOptions) => void;
type RemoveNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.removeNodes>[1]>, NodeMatchOption<V>>;
/**
* Remove the nodes at a specific location in the document.
*/
declare const removeNodes: <V extends Value>(editor: TEditor<V>, options?: RemoveNodesOptions<V> | undefined) => void;
/**
* Set the selection to a new value.
*/
declare const select: <V extends Value>(editor: TEditor<V>, target: Location) => void;
type SetNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.setNodes>[2]>, NodeMatchOption<V>>;
/**
* Set new properties on the nodes at a location.
*/
declare const setNodes: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, props: Partial<TNodeProps<N>>, options?: SetNodesOptions<V> | undefined) => void;
/**
* Set new properties on one of the selection's points.
*/
declare const setPoint: <V extends Value>(editor: TEditor<V>, props: Partial<Point>, options?: SelectionSetPointOptions) => void;
/**
* Set new properties on the selection.
*/
declare const setSelection: <V extends Value>(editor: TEditor<V>, props: Partial<Range>) => void;
type SplitNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.splitNodes>[1]>, NodeMatchOption<V>>;
/**
* Split the nodes at a specific location.
*/
declare const splitNodes: <V extends Value>(editor: TEditor<V>, options?: SplitNodesOptions<V> | undefined) => void;
type UnsetNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.unsetNodes>[2]>, NodeMatchOption<V>>;
/**
* Unset properties on the nodes at a location.
*/
declare const unsetNodes: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, props: keyof TNodeProps<N> | (keyof TNodeProps<N>)[], options?: UnsetNodesOptions<V> | undefined) => void;
type UnwrapNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.unwrapNodes>[1]>, ENodeMatchOptions<V>>;
/**
* 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.
*/
declare const unwrapNodes: <V extends Value>(editor: TEditor<V>, options?: UnwrapNodesOptions<V> | undefined) => void;
type WrapNodesOptions<V extends Value = Value> = Modify<NonNullable<Parameters<typeof Transforms.wrapNodes>[2]>, NodeMatchOption<V>>;
/**
* 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.
*/
declare const wrapNodes: <N extends EElement<V>, V extends Value = Value>(editor: TEditor<V>, element: N, options?: WrapNodesOptions<V> | undefined) => void;
type FindNodeOptions<V extends Value = Value> = GetNodeEntriesOptions<V>;
/**
* Find node matching the condition.
*/
declare const findNode: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, options?: FindNodeOptions<V>) => TNodeEntry<N> | undefined;
/**
* Iterate through all of the nodes in the editor and break early for the first truthy match. Otherwise
* returns false.
*/
declare const someNode: <N extends ENode<V>, V extends Value = Value>(editor: TEditor<V>, options: FindNodeOptions<V>) => boolean;
/**
* Add marks to each node of a range.
*/
declare const addRangeMarks: <V extends Value>(editor: TEditor<V>, props: any, { at, }?: {
at?: Location | null | undefined;
}) => void;
declare const setElements: <V extends Value>(editor: TEditor<V>, props: Partial<TNodeProps<TElement>>, options?: SetNodesOptions) => void;
/**
* Unhang the range of length 1 so both edges are in the same text node.
*/
declare const unhangCharacterRange: <V extends Value>(editor: TEditor<V>, at: Range) => {
anchor: slate.BasePoint;
focus: slate.BasePoint;
};
/**
* Filter nodes.
*/
interface QueryNodeOptions {
/**
* Query the node entry.
*/
filter?: <N extends TNode>(entry: TNodeEntry<N>) => boolean;
/**
* List of types that are valid. If empty or undefined - allow all.
*/
allow?: string[] | string | null;
/**
* List of types that are invalid.
*/
exclude?: string[] | string | null;
/**
* Valid path levels.
*/
level?: number[] | number | null;
/**
* Paths above that value are invalid.
*/
maxLevel?: number | null;
}
/**
* Query the editor state.
*/
interface QueryEditorOptions<V extends Value = Value, E extends TEditor<V> = TEditor<V>> extends Pick<QueryNodeOptions, 'allow' | 'exclude'> {
/**
* Query the editor.
*/
filter?: (editor: E) => boolean;
/**
* Location from where to lookup the node types (bottom-up)
*/
at?: Location;
/**
* When the selection is at the start of the block above.
*/
selectionAtBlockStart?: boolean;
/**
* When the selection is at the end of the block above.
*/
selectionAtBlockEnd?: boolean;
}
type TRenderLeafProps<V extends Value = Value, N extends TText = EText<V>> = Modify<RenderLeafProps, {
leaf: N;
text: N;
}>;
type RenderLeafFn<V extends Value = Value> = (props: TRenderLeafProps<V>) => React.ReactElement;
/**
* Query the node entry.
*/
declare const queryNode: <N extends TNode>(entry?: TNodeEntry<N> | undefined, { filter, allow, exclude, level, maxLevel }?: QueryNodeOptions) => boolean;
export { AncestorOf, ChildOf, DescendantOf, EAncestor, EAncestorEntry, EDescendant, EDescendantEntry, EElement, EElementEntry, EElementOrText, EMarks, ENode, ENodeEntry, ENodeMatch, ENodeMatchOptions, EText, ETextEntry, ElementOf, FindNodeOptions, GetAboveNodeOptions, GetLevelsOptions, GetNextNodeOptions, GetNodeEntriesOptions, GetPreviousNodeOptions, InsertNodesOptions, LiftNodesOptions, MarkKeysOf, MarksOf, MergeNodesOptions, MoveNodesOptions, NodeMatchOption, NodeOf, Predicate, PredicateFn, PredicateObj, QueryEditorOptions, QueryNodeOptions, RemoveNodesOptions, RenderLeafFn, SetNodesOptions, SplitNodesOptions, TAncestor, TAncestorEntry, TDescendant, TDescendantEntry, TEditor, TElement, TElementEntry, THistoryEditor, TInsertNodeOperation, TInsertTextOperation, TLocation, TMergeNodeOperation, TMoveNodeOperation, TNode, TNodeChildEntry, TNodeEntry, TNodeMatch, TNodeOperation, TNodeProps, TOperation, TPath, TRange, TRemoveNodeOperation, TRemoveTextOperation, TRenderLeafProps, TSelection, TSelectionOperation, TSetNodeOperation, TSetSelectionOperation, TSpan, TSplitNodeOperation, TText, TTextEntry, TTextOperation, TextOf, UnhangRangeOptions, UnsetNodesOptions, UnwrapNodesOptions, Value, ValueOf, WrapNodesOptions, addMark, addRangeMarks, collapseSelection, createPathRef, createPointRef, createRangeRef, createTEditor, deleteBackward, deleteForward, deleteFragment, deleteMerge, deleteText, deselect, elementMatches, findNode, getAboveNode, getCommonNode, getEdgePoints, getEditorString, getEndPoint, getFirstNode, getFragment, getLastNode, getLeafNode, getLevels, getMarks, getNextNode, getNode, getNodeAncestor, getNodeAncestors, getNodeChild, getNodeChildren, getNodeDescendant, getNodeDescendants, getNodeElements, getNodeEntries, getNodeEntry, getNodeFirstNode, getNodeFragment, getNodeLastNode, getNodeLeaf, getNodeLevels, getNodeParent, getNodeProps, getNodeString, getNodeTexts, getNodes, getParentNode, getPath, getPathRefs, getPoint, getPointAfter, getPointBefore, getPointRefs, getPositions, getPreviousNode, getQueryOptions, getRange, getRangeRefs, getStartPoint, getTEditor, getVoidNode, hasBlocks, hasInlines, hasNode, hasSingleChild, hasTexts, insertBreak, insertFragment, insertNode, insertNodes, insertText, isAncestor, isBlock, isCollapsed, isDescendant, isEdgePoint, isEditor, isEditorNormalizing, isElement, isElementEmpty, isElementList, isEndPoint, isExpanded, isHistoryEditor, isHistoryMerging, isHistorySaving, isInline, isMarkableVoid, isNode, isNodeList, isStartPoint, isText, isTextList, isVoid, liftNodes, match, mergeNodes, moveNodes, moveSelection, nodeMatches, normalizeEditor, queryNode, removeEditorMark, removeNodes, select, setElements, setNodes, setPoint, setSelection, someNode, splitNodes, textEquals, textMatches, unhangCharacterRange, unhangRange, unsetNodes, unwrapNodes, withoutMergingHistory, withoutNormalizing, withoutSavingHistory, wrapNodes };

1850

dist/index.js

@@ -1,163 +0,259 @@

'use strict';
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var slate = require('slate');
var slateHistory = require('slate-history');
// src/index.ts
var src_exports = {};
__export(src_exports, {
addMark: () => addMark,
addRangeMarks: () => addRangeMarks,
collapseSelection: () => collapseSelection,
createPathRef: () => createPathRef,
createPointRef: () => createPointRef,
createRangeRef: () => createRangeRef,
createTEditor: () => createTEditor,
deleteBackward: () => deleteBackward,
deleteForward: () => deleteForward,
deleteFragment: () => deleteFragment,
deleteMerge: () => deleteMerge,
deleteText: () => deleteText,
deselect: () => deselect,
elementMatches: () => elementMatches,
findNode: () => findNode,
getAboveNode: () => getAboveNode,
getCommonNode: () => getCommonNode,
getEdgePoints: () => getEdgePoints,
getEditorString: () => getEditorString,
getEndPoint: () => getEndPoint,
getFirstNode: () => getFirstNode,
getFragment: () => getFragment,
getLastNode: () => getLastNode,
getLeafNode: () => getLeafNode,
getLevels: () => getLevels,
getMarks: () => getMarks,
getNextNode: () => getNextNode,
getNode: () => getNode,
getNodeAncestor: () => getNodeAncestor,
getNodeAncestors: () => getNodeAncestors,
getNodeChild: () => getNodeChild,
getNodeChildren: () => getNodeChildren,
getNodeDescendant: () => getNodeDescendant,
getNodeDescendants: () => getNodeDescendants,
getNodeElements: () => getNodeElements,
getNodeEntries: () => getNodeEntries,
getNodeEntry: () => getNodeEntry,
getNodeFirstNode: () => getNodeFirstNode,
getNodeFragment: () => getNodeFragment,
getNodeLastNode: () => getNodeLastNode,
getNodeLeaf: () => getNodeLeaf,
getNodeLevels: () => getNodeLevels,
getNodeParent: () => getNodeParent,
getNodeProps: () => getNodeProps,
getNodeString: () => getNodeString,
getNodeTexts: () => getNodeTexts,
getNodes: () => getNodes,
getParentNode: () => getParentNode,
getPath: () => getPath,
getPathRefs: () => getPathRefs,
getPoint: () => getPoint,
getPointAfter: () => getPointAfter,
getPointBefore: () => getPointBefore,
getPointRefs: () => getPointRefs,
getPositions: () => getPositions,
getPreviousNode: () => getPreviousNode,
getQueryOptions: () => getQueryOptions,
getRange: () => getRange,
getRangeRefs: () => getRangeRefs,
getStartPoint: () => getStartPoint,
getTEditor: () => getTEditor,
getVoidNode: () => getVoidNode,
hasBlocks: () => hasBlocks,
hasInlines: () => hasInlines,
hasNode: () => hasNode,
hasSingleChild: () => hasSingleChild,
hasTexts: () => hasTexts,
insertBreak: () => insertBreak,
insertFragment: () => insertFragment,
insertNode: () => insertNode,
insertNodes: () => insertNodes,
insertText: () => insertText,
isAncestor: () => isAncestor,
isBlock: () => isBlock,
isCollapsed: () => isCollapsed,
isDescendant: () => isDescendant,
isEdgePoint: () => isEdgePoint,
isEditor: () => isEditor,
isEditorNormalizing: () => isEditorNormalizing,
isElement: () => isElement,
isElementEmpty: () => isElementEmpty,
isElementList: () => isElementList,
isEndPoint: () => isEndPoint,
isExpanded: () => isExpanded,
isHistoryEditor: () => isHistoryEditor,
isHistoryMerging: () => isHistoryMerging,
isHistorySaving: () => isHistorySaving,
isInline: () => isInline,
isMarkableVoid: () => isMarkableVoid,
isNode: () => isNode,
isNodeList: () => isNodeList,
isStartPoint: () => isStartPoint,
isText: () => isText,
isTextList: () => isTextList,
isVoid: () => isVoid,
liftNodes: () => liftNodes,
match: () => match,
mergeNodes: () => mergeNodes,
moveNodes: () => moveNodes,
moveSelection: () => moveSelection,
nodeMatches: () => nodeMatches,
normalizeEditor: () => normalizeEditor,
queryNode: () => queryNode,
removeEditorMark: () => removeEditorMark,
removeNodes: () => removeNodes,
select: () => select,
setElements: () => setElements,
setNodes: () => setNodes,
setPoint: () => setPoint,
setSelection: () => setSelection,
someNode: () => someNode,
splitNodes: () => splitNodes,
textEquals: () => textEquals,
textMatches: () => textMatches,
unhangCharacterRange: () => unhangCharacterRange,
unhangRange: () => unhangRange,
unsetNodes: () => unsetNodes,
unwrapNodes: () => unwrapNodes,
withoutMergingHistory: () => withoutMergingHistory,
withoutNormalizing: () => withoutNormalizing,
withoutSavingHistory: () => withoutSavingHistory,
wrapNodes: () => wrapNodes
});
module.exports = __toCommonJS(src_exports);
const createTEditor = () => slate.createEditor();
// src/createTEditor.ts
var import_slate = require("slate");
var createTEditor = () => (0, import_slate.createEditor)();
/**
* A helper type for getting the value of an editor.
*/
// src/interfaces/editor/TEditor.ts
var getTEditor = (editor) => editor;
/**
* Get editor with typed methods and operations.
* Note that it can't be used as a parameter of type TEditor.
*/
const getTEditor = editor => editor;
// src/interfaces/editor/addMark.ts
var import_slate2 = require("slate");
var addMark = (editor, key, value) => import_slate2.Editor.addMark(editor, key, value);
/**
* 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.
*/
const addMark = (editor, key, value) => slate.Editor.addMark(editor, key, value);
// src/interfaces/editor/createPathRef.ts
var import_slate3 = require("slate");
var createPathRef = (editor, at, options) => import_slate3.Editor.pathRef(editor, at, options);
/**
* Create a mutable ref for a `Path` object, which will stay in sync as new
* operations are applied to the editor.
*/
const createPathRef = (editor, at, options) => slate.Editor.pathRef(editor, at, options);
// src/interfaces/editor/createPointRef.ts
var import_slate4 = require("slate");
var createPointRef = (editor, point, options) => import_slate4.Editor.pointRef(editor, point, options);
/**
* Create a mutable ref for a `Point` object, which will stay in sync as new
* operations are applied to the editor.
*/
const createPointRef = (editor, point, options) => slate.Editor.pointRef(editor, point, options);
// src/interfaces/editor/createRangeRef.ts
var import_slate5 = require("slate");
var createRangeRef = (editor, range, options) => import_slate5.Editor.rangeRef(editor, range, options);
/**
* Create a mutable ref for a `Range` object, which will stay in sync as new
* operations are applied to the editor.
*/
const createRangeRef = (editor, range, options) => slate.Editor.rangeRef(editor, range, options);
// src/interfaces/editor/deleteBackward.ts
var import_slate6 = require("slate");
var deleteBackward = (editor, options) => import_slate6.Editor.deleteBackward(editor, options);
/**
* Delete content in the editor backward from the current selection.
*/
const deleteBackward = (editor, options) => slate.Editor.deleteBackward(editor, options);
// src/interfaces/editor/deleteForward.ts
var import_slate7 = require("slate");
var deleteForward = (editor, options) => import_slate7.Editor.deleteForward(editor, options);
/**
* Delete content in the editor forward from the current selection.
*/
const deleteForward = (editor, options) => slate.Editor.deleteForward(editor, options);
// src/interfaces/editor/deleteFragment.ts
var import_slate8 = require("slate");
var deleteFragment = (editor, options) => import_slate8.Editor.deleteFragment(editor, options);
/**
* Delete the content in the current selection.
*/
const deleteFragment = (editor, options) => slate.Editor.deleteFragment(editor, options);
// src/interfaces/editor/deleteMerge.ts
var import_slate33 = require("slate");
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
// src/interfaces/transforms/mergeNodes.ts
var import_slate25 = require("slate");
var isArray_1 = isArray;
// src/interfaces/editor/getAboveNode.ts
var import_slate13 = require("slate");
/**
* Casts `value` as an array if it's not one.
*
* @static
* @memberOf _
* @since 4.4.0
* @category Lang
* @param {*} value The value to inspect.
* @returns {Array} Returns the cast array.
* @example
*
* _.castArray(1);
* // => [1]
*
* _.castArray({ 'a': 1 });
* // => [{ 'a': 1 }]
*
* _.castArray('abc');
* // => ['abc']
*
* _.castArray(null);
* // => [null]
*
* _.castArray(undefined);
* // => [undefined]
*
* _.castArray();
* // => []
*
* var array = [1, 2, 3];
* console.log(_.castArray(array) === array);
* // => true
*/
function castArray() {
if (!arguments.length) {
return [];
}
var value = arguments[0];
return isArray_1(value) ? value : [value];
}
// src/utils/match.ts
var import_lodash = require("lodash");
var castArray_1 = castArray;
// src/interfaces/editor/isBlock.ts
var import_slate12 = require("slate");
/**
* Check if an element matches set of properties.
*
* Note: this checks custom properties, and it does not ensure that any
* children are equivalent.
*/
const elementMatches = (element, props) => slate.Element.matches(element, props);
// src/interfaces/element/elementMatches.ts
var import_slate9 = require("slate");
var elementMatches = (element, props) => import_slate9.Element.matches(element, props);
/**
* Check if a value implements the 'Element' interface.
*/
const isElement = value => slate.Element.isElement(value);
// src/interfaces/element/isElement.ts
var import_slate10 = require("slate");
var isElement = (value) => import_slate10.Element.isElement(value);
/**
* Check if a value is an array of `Element` objects.
*/
const isElementList = value => slate.Element.isElementList(value);
// src/interfaces/element/isElementList.ts
var import_slate11 = require("slate");
var isElementList = (value) => import_slate11.Element.isElementList(value);
/**
* Check if a value is a block `Element` object.
*/
const isBlock = (editor, value) => isElement(value) && slate.Editor.isBlock(editor, value);
// src/interfaces/editor/isBlock.ts
var isBlock = (editor, value) => isElement(value) && import_slate12.Editor.isBlock(editor, value);
/**
* Match the object with a predicate object or function.
* If predicate is:
* - object: every predicate key/value should be in obj.
* - function: it should return true.
*/
const match = (obj, path, predicate) => {
if (!predicate) return true;
if (typeof predicate === 'object') {
// src/utils/match.ts
var match = (obj, path, predicate) => {
if (!predicate)
return true;
if (typeof predicate === "object") {
return Object.entries(predicate).every(([key, value]) => {
const values = castArray_1(value);
const values = (0, import_lodash.castArray)(value);
return values.includes(obj[key]);

@@ -168,38 +264,21 @@ });

};
/**
* Extended query options for slate queries:
* - `match` can be an object predicate where one of the values should include the node value.
* Example: { type: ['1', '2'] } will match the nodes having one of these 2 types.
*/
const getQueryOptions = (editor, options = {}) => {
const {
match: _match,
block
} = options;
return {
...options,
match: _match || block ? (n, path) => match(n, path, _match) && (!block || isBlock(editor, n)) : undefined
};
var getQueryOptions = (editor, options = {}) => {
const { match: _match, block } = options;
return __spreadProps(__spreadValues({}, options), {
match: _match || block ? (n, path) => match(n, path, _match) && (!block || isBlock(editor, n)) : void 0
});
};
/**
* Get the ancestor above a location in the document.
*/
const getAboveNode = (editor, options) => slate.Editor.above(editor, getQueryOptions(editor, options));
// src/interfaces/editor/getAboveNode.ts
var getAboveNode = (editor, options) => import_slate13.Editor.above(editor, getQueryOptions(editor, options));
/**
* Convert a range into a non-hanging one if:
* - `unhang` is true,
* - `at` (default: selection) is a range.
*/
const unhangRange = (editor, range, options = {}) => {
const {
voids,
unhang = true
} = options;
if (slate.Range.isRange(range) && unhang) {
return slate.Editor.unhangRange(editor, range, {
voids
});
// src/interfaces/editor/getNodeEntries.ts
var import_slate15 = require("slate");
// src/interfaces/editor/unhangRange.ts
var import_slate14 = require("slate");
var unhangRange = (editor, range, options = {}) => {
const { voids, unhang = true } = options;
if (import_slate14.Range.isRange(range) && unhang) {
return import_slate14.Editor.unhangRange(editor, range, { voids });
}

@@ -209,37 +288,30 @@ return range;

/**
* Iterate through all of the nodes in the Editor.
*/
const getNodeEntries = (editor, options) => {
unhangRange(editor, options === null || options === void 0 ? void 0 : options.at, options);
return slate.Editor.nodes(editor, getQueryOptions(editor, options));
// src/interfaces/editor/getNodeEntries.ts
var getNodeEntries = (editor, options) => {
unhangRange(editor, options == null ? void 0 : options.at, options);
return import_slate15.Editor.nodes(editor, getQueryOptions(editor, options));
};
/**
* Get the parent node of a location.
* Returns undefined if there is no parent.
*/
const getParentNode = (editor, at, options) => {
// src/interfaces/editor/getParentNode.ts
var import_slate16 = require("slate");
var getParentNode = (editor, at, options) => {
try {
return slate.Editor.parent(editor, at, options);
} catch (error) {}
return import_slate16.Editor.parent(editor, at, options);
} catch (error) {
}
};
/**
* Get the matching node in the branch of the document before a location.
*/
const getPreviousNode = (editor, options) => slate.Editor.previous(editor, options);
// src/interfaces/editor/getPreviousNode.ts
var import_slate17 = require("slate");
var getPreviousNode = (editor, options) => import_slate17.Editor.previous(editor, options);
/**
* Check if an element is empty, accounting for void nodes.
*/
const isElementEmpty = (editor, element) => slate.Editor.isEmpty(editor, element);
// src/interfaces/editor/isElementEmpty.ts
var import_slate18 = require("slate");
var isElementEmpty = (editor, element) => import_slate18.Editor.isEmpty(editor, element);
/**
* Call a function, deferring normalization until after it completes
* @return true if normalized.
*/
const withoutNormalizing = (editor, fn) => {
// src/interfaces/editor/withoutNormalizing.ts
var import_slate19 = require("slate");
var withoutNormalizing = (editor, fn) => {
let normalized = false;
slate.Editor.withoutNormalizing(editor, () => {
import_slate19.Editor.withoutNormalizing(editor, () => {
normalized = !!fn();

@@ -250,8 +322,8 @@ });

/**
* Check if a value implements the `Text` interface.
*/
const isText = value => slate.Text.isText(value);
// src/interfaces/text/isText.ts
var import_slate20 = require("slate");
var isText = (value) => import_slate20.Text.isText(value);
const hasSingleChild = node => {
// src/interfaces/node/hasSingleChild.ts
var hasSingleChild = (node) => {
if (isText(node)) {

@@ -263,36 +335,26 @@ return true;

/**
* Delete content in the editor.
*/
const deleteText = (editor, options) => {
slate.Transforms.delete(editor, options);
// src/interfaces/transforms/deleteText.ts
var import_slate21 = require("slate");
var deleteText = (editor, options) => {
import_slate21.Transforms.delete(editor, options);
};
/**
* Move the nodes at a location to a new location.
*/
const moveNodes = (editor, options) => slate.Transforms.moveNodes(editor, options);
// src/interfaces/transforms/moveNodes.ts
var import_slate22 = require("slate");
var moveNodes = (editor, options) => import_slate22.Transforms.moveNodes(editor, options);
/**
* Remove the nodes at a specific location in the document.
*/
const removeNodes = (editor, options) => slate.Transforms.removeNodes(editor, options);
// src/interfaces/transforms/removeNodes.ts
var import_slate23 = require("slate");
var removeNodes = (editor, options) => import_slate23.Transforms.removeNodes(editor, options);
/**
* Set the selection to a new value.
*/
const select = (editor, target) => {
slate.Transforms.select(editor, target);
// src/interfaces/transforms/select.ts
var import_slate24 = require("slate");
var select = (editor, target) => {
import_slate24.Transforms.select(editor, target);
};
/**
* Merge a node at a location with the previous node of the same depth,
* removing any empty containing nodes after the merge if necessary.
*/
const mergeNodes = (editor, options = {}) => {
// src/interfaces/transforms/mergeNodes.ts
var mergeNodes = (editor, options = {}) => {
withoutNormalizing(editor, () => {
let {
match,
at = editor.selection
} = options;
let { match: match2, at = editor.selection } = options;
const {

@@ -303,3 +365,3 @@ mergeNode,

voids = false,
mode = 'lowest'
mode = "lowest"
} = options;

@@ -309,22 +371,20 @@ if (!at) {

}
if (match == null) {
if (slate.Path.isPath(at)) {
if (match2 == null) {
if (import_slate25.Path.isPath(at)) {
const [parent] = getParentNode(editor, at);
match = n => parent.children.includes(n);
match2 = (n) => parent.children.includes(n);
} else {
match = n => isBlock(editor, n);
match2 = (n) => isBlock(editor, n);
}
}
if (!hanging && slate.Range.isRange(at)) {
at = slate.Editor.unhangRange(editor, at);
if (!hanging && import_slate25.Range.isRange(at)) {
at = import_slate25.Editor.unhangRange(editor, at);
}
if (slate.Range.isRange(at)) {
if (slate.Range.isCollapsed(at)) {
if (import_slate25.Range.isRange(at)) {
if (import_slate25.Range.isCollapsed(at)) {
at = at.anchor;
} else {
const [, end] = slate.Range.edges(at);
const [, end] = import_slate25.Range.edges(at);
const pointRef = createPointRef(editor, end);
deleteText(editor, {
at
});
deleteText(editor, { at });
at = pointRef.unref();

@@ -336,15 +396,5 @@ if (options.at == null) {

}
const _nodes = getNodeEntries(editor, {
at,
match,
voids,
mode
});
const _nodes = getNodeEntries(editor, { at, match: match2, voids, mode });
const [current] = Array.from(_nodes);
const prev = getPreviousNode(editor, {
at,
match,
voids,
mode
});
const prev = getPreviousNode(editor, { at, match: match2, voids, mode });
if (!current || !prev) {

@@ -358,16 +408,13 @@ return;

}
const newPath = slate.Path.next(prevPath);
const commonPath = slate.Path.common(path, prevPath);
const isPreviousSibling = slate.Path.isSibling(path, prevPath);
const _levels = slate.Editor.levels(editor, {
at: path
});
const levels = new Set(Array.from(_levels, ([n]) => n).slice(commonPath.length).slice(0, -1));
// Determine if the merge will leave an ancestor of the path empty as a
// result, in which case we'll want to remove it after merging.
const newPath = import_slate25.Path.next(prevPath);
const commonPath = import_slate25.Path.common(path, prevPath);
const isPreviousSibling = import_slate25.Path.isSibling(path, prevPath);
const _levels = import_slate25.Editor.levels(editor, { at: path });
const levels = new Set(
Array.from(_levels, ([n]) => n).slice(commonPath.length).slice(0, -1)
);
const emptyAncestor = getAboveNode(editor, {
at: path,
mode: 'highest',
match: n => levels.has(n) && isElement(n) && hasSingleChild(n)
mode: "highest",
match: (n) => levels.has(n) && isElement(n) && hasSingleChild(n)
});

@@ -377,72 +424,36 @@ const emptyRef = emptyAncestor && createPathRef(editor, emptyAncestor[1]);

let position;
// Ensure that the nodes are equivalent, and figure out what the position
// and extra properties of the merge will be.
if (isText(node) && isText(prevNode)) {
const {
text,
...rest
} = node;
const _a = node, { text } = _a, rest = __objRest(_a, ["text"]);
position = prevNode.text.length;
properties = rest;
} else if (isElement(node) && isElement(prevNode)) {
const {
children,
...rest
} = node;
const _b = node, { children } = _b, rest = __objRest(_b, ["children"]);
position = prevNode.children.length;
properties = rest;
} else {
throw new Error(`Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify(node)} ${JSON.stringify(prevNode)}`);
throw new Error(
`Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify(
node
)} ${JSON.stringify(prevNode)}`
);
}
// If the node isn't already the next sibling of the previous node, move
// it so that it is before merging.
if (!isPreviousSibling &&
// DIFF
if (!isPreviousSibling && // DIFF
!mergeNode) {
moveNodes(editor, {
at: path,
to: newPath,
voids
});
moveNodes(editor, { at: path, to: newPath, voids });
}
// If there was going to be an empty ancestor of the node that was merged,
// we remove it from the tree.
if (emptyRef) {
// DIFF: start
if (removeEmptyAncestor) {
const emptyPath = emptyRef.current;
emptyPath && removeEmptyAncestor(editor, {
at: emptyPath
});
emptyPath && removeEmptyAncestor(editor, { at: emptyPath });
} else {
removeNodes(editor, {
at: emptyRef.current,
voids
});
removeNodes(editor, { at: emptyRef.current, voids });
}
// DIFF: end
}
// If the target node that we're merging with is empty, remove it instead
// of merging the two. This is a common rich text editor behavior to
// prevent losing formatting when deleting entire nodes when you have a
// hanging selection.
// DIFF: start
if (mergeNode) {
mergeNode(editor, {
at: path,
to: newPath
});
// DIFF: end
} else if (isElement(prevNode) && isElementEmpty(editor, prevNode) || isText(prevNode) && prevNode.text === '') {
removeNodes(editor, {
at: prevPath,
voids
});
mergeNode(editor, { at: path, to: newPath });
} else if (isElement(prevNode) && isElementEmpty(editor, prevNode) || isText(prevNode) && prevNode.text === "") {
removeNodes(editor, { at: prevPath, voids });
} else {
editor.apply({
type: 'merge_node',
type: "merge_node",
path: newPath,

@@ -459,62 +470,50 @@ position,

/**
* Get the end point of a location.
*/
const getEndPoint = (editor, at) => slate.Editor.end(editor, at);
// src/interfaces/editor/getEndPoint.ts
var import_slate26 = require("slate");
var getEndPoint = (editor, at) => import_slate26.Editor.end(editor, at);
/**
* Get the leaf text node at a location.
*/
const getLeafNode = (editor, at, options) => slate.Editor.leaf(editor, at, options);
// src/interfaces/editor/getLeafNode.ts
var import_slate27 = require("slate");
var getLeafNode = (editor, at, options) => import_slate27.Editor.leaf(editor, at, options);
/**
* Get the point after a location.
*/
const getPointAfter = (editor, at, options) => slate.Editor.after(editor, at, options);
// src/interfaces/editor/getPointAfter.ts
var import_slate28 = require("slate");
var getPointAfter = (editor, at, options) => import_slate28.Editor.after(editor, at, options);
/**
* Get the point before a location.
*/
const getPointBefore = (editor, at, options) => slate.Editor.before(editor, at, options);
// src/interfaces/editor/getPointBefore.ts
var import_slate29 = require("slate");
var getPointBefore = (editor, at, options) => import_slate29.Editor.before(editor, at, options);
/**
* Get the start point of a location.
*/
const getStartPoint = (editor, at) => slate.Editor.start(editor, at);
// src/interfaces/editor/getStartPoint.ts
var import_slate30 = require("slate");
var getStartPoint = (editor, at) => import_slate30.Editor.start(editor, at);
/**
* Match a void node in the current branch of the editor.
*/
const getVoidNode = (editor, options) => slate.Editor.void(editor, options);
// src/interfaces/editor/getVoidNode.ts
var import_slate31 = require("slate");
var getVoidNode = (editor, options) => import_slate31.Editor.void(editor, options);
/**
* Check if a value is a void `Element` object.
*/
const isVoid = (editor, value) => {
return isElement(value) && slate.Editor.isVoid(editor, value);
// src/interfaces/editor/isVoid.ts
var import_slate32 = require("slate");
var isVoid = (editor, value) => {
return isElement(value) && import_slate32.Editor.isVoid(editor, value);
};
const deleteMerge = (editor, options = {}) => {
// src/interfaces/editor/deleteMerge.ts
var deleteMerge = (editor, options = {}) => {
withoutNormalizing(editor, () => {
const {
reverse = false,
unit = 'character',
unit = "character",
distance = 1,
voids = false
} = options;
let {
at = editor.selection,
hanging = false
} = options;
let { at = editor.selection, hanging = false } = options;
if (!at) {
return;
}
if (slate.Range.isRange(at) && slate.Range.isCollapsed(at)) {
if (import_slate33.Range.isRange(at) && import_slate33.Range.isCollapsed(at)) {
at = at.anchor;
}
if (slate.Point.isPoint(at)) {
const furthestVoid = getVoidNode(editor, {
at,
mode: 'highest'
});
if (import_slate33.Point.isPoint(at)) {
const furthestVoid = getVoidNode(editor, { at, mode: "highest" });
if (!voids && furthestVoid) {

@@ -524,32 +523,21 @@ const [, voidPath] = furthestVoid;

} else {
const opts = {
unit,
distance
};
const opts = { unit, distance };
const target = reverse ? getPointBefore(editor, at, opts) || getStartPoint(editor, []) : getPointAfter(editor, at, opts) || getEndPoint(editor, []);
at = {
anchor: at,
focus: target
};
at = { anchor: at, focus: target };
hanging = true;
}
}
if (slate.Path.isPath(at)) {
removeNodes(editor, {
at,
voids
});
if (import_slate33.Path.isPath(at)) {
removeNodes(editor, { at, voids });
return;
}
if (slate.Range.isCollapsed(at)) {
if (import_slate33.Range.isCollapsed(at)) {
return;
}
if (!hanging) {
at = slate.Editor.unhangRange(editor, at, {
voids
});
at = import_slate33.Editor.unhangRange(editor, at, { voids });
}
let [start, end] = slate.Range.edges(at);
let [start, end] = import_slate33.Range.edges(at);
const startBlock = getAboveNode(editor, {
match: n => isBlock(editor, n),
match: (n) => isBlock(editor, n),
at: start,

@@ -559,21 +547,13 @@ voids

const endBlock = getAboveNode(editor, {
match: n => isBlock(editor, n),
match: (n) => isBlock(editor, n),
at: end,
voids
});
const isAcrossBlocks = startBlock && endBlock && !slate.Path.equals(startBlock[1], endBlock[1]);
const isSingleText = slate.Path.equals(start.path, end.path);
const startVoid = voids ? null : getVoidNode(editor, {
at: start,
mode: 'highest'
});
const endVoid = voids ? null : getVoidNode(editor, {
at: end,
mode: 'highest'
});
// If the start or end points are inside an inline void, nudge them out.
const isAcrossBlocks = startBlock && endBlock && !import_slate33.Path.equals(startBlock[1], endBlock[1]);
const isSingleText = import_slate33.Path.equals(start.path, end.path);
const startVoid = voids ? null : getVoidNode(editor, { at: start, mode: "highest" });
const endVoid = voids ? null : getVoidNode(editor, { at: end, mode: "highest" });
if (startVoid) {
const before = getPointBefore(editor, start);
if (before && startBlock && slate.Path.isAncestor(startBlock[1], before.path)) {
if (before && startBlock && import_slate33.Path.isAncestor(startBlock[1], before.path)) {
start = before;

@@ -584,21 +564,15 @@ }

const after = getPointAfter(editor, end);
if (after && endBlock && slate.Path.isAncestor(endBlock[1], after.path)) {
if (after && endBlock && import_slate33.Path.isAncestor(endBlock[1], after.path)) {
end = after;
}
}
// Get the highest nodes that are completely inside the range, as well as
// the start and end nodes.
const matches = [];
let lastPath;
const _nodes = getNodeEntries(editor, {
at,
voids
});
const _nodes = getNodeEntries(editor, { at, voids });
for (const entry of _nodes) {
const [node, path] = entry;
if (lastPath && slate.Path.compare(path, lastPath) === 0) {
if (lastPath && import_slate33.Path.compare(path, lastPath) === 0) {
continue;
}
if (!voids && isVoid(editor, node) || !slate.Path.isCommon(path, start.path) && !slate.Path.isCommon(path, end.path)) {
if (!voids && isVoid(editor, node) || !import_slate33.Path.isCommon(path, start.path) && !import_slate33.Path.isCommon(path, end.path)) {
matches.push(entry);

@@ -608,46 +582,29 @@ lastPath = path;

}
const pathRefs = Array.from(matches, ([, p]) => createPathRef(editor, p));
const pathRefs = Array.from(
matches,
([, p]) => createPathRef(editor, p)
);
const startRef = createPointRef(editor, start);
const endRef = createPointRef(editor, end);
if (!isSingleText && !startVoid) {
const point = startRef.current;
const [node] = getLeafNode(editor, point);
const {
path
} = point;
const {
offset
} = start;
const point2 = startRef.current;
const [node] = getLeafNode(editor, point2);
const { path } = point2;
const { offset } = start;
const text = node.text.slice(offset);
editor.apply({
type: 'remove_text',
path,
offset,
text
});
editor.apply({ type: "remove_text", path, offset, text });
}
for (const pathRef of pathRefs) {
const path = pathRef.unref();
removeNodes(editor, {
at: path,
voids
});
removeNodes(editor, { at: path, voids });
}
if (!endVoid) {
const point = endRef.current;
const [node] = getLeafNode(editor, point);
const {
path
} = point;
const point2 = endRef.current;
const [node] = getLeafNode(editor, point2);
const { path } = point2;
const offset = isSingleText ? start.offset : 0;
const text = node.text.slice(offset, end.offset);
editor.apply({
type: 'remove_text',
path,
offset,
text
});
editor.apply({ type: "remove_text", path, offset, text });
}
if (!isSingleText && isAcrossBlocks && endRef.current && startRef.current) {
// DIFF: allow custom mergeNodes
mergeNodes(editor, {

@@ -666,263 +623,177 @@ at: endRef.current,

/**
* Get the start and end points of a location.
*/
const getEdgePoints = (editor, at) => slate.Editor.edges(editor, at);
// src/interfaces/editor/getEdgePoints.ts
var import_slate34 = require("slate");
var getEdgePoints = (editor, at) => import_slate34.Editor.edges(editor, at);
/**
* 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
*/
const getEditorString = (editor, at, options) => {
if (!at) return '';
// src/interfaces/editor/getEditorString.ts
var import_slate35 = require("slate");
var getEditorString = (editor, at, options) => {
if (!at)
return "";
try {
return slate.Editor.string(editor, at, options);
return import_slate35.Editor.string(editor, at, options);
} catch (error) {
return '';
return "";
}
};
/**
* Get the first node at a location.
*/
const getFirstNode = (editor, at) => slate.Editor.first(editor, at);
// src/interfaces/editor/getFirstNode.ts
var import_slate36 = require("slate");
var getFirstNode = (editor, at) => import_slate36.Editor.first(editor, at);
/**
* Get the fragment at a location.
*/
const getFragment = (editor, at) => slate.Editor.fragment(editor, at);
// src/interfaces/editor/getFragment.ts
var import_slate37 = require("slate");
var getFragment = (editor, at) => import_slate37.Editor.fragment(editor, at);
/**
* Get the last node at a location.
*/
const getLastNode = (editor, at) => slate.Editor.last(editor, at);
// src/interfaces/editor/getLastNode.ts
var import_slate38 = require("slate");
var getLastNode = (editor, at) => import_slate38.Editor.last(editor, at);
/**
* Iterate through all of the levels at a location.
*/
const getLevels = (editor, options) => slate.Editor.levels(editor, options);
// src/interfaces/editor/getLevels.ts
var import_slate39 = require("slate");
var getLevels = (editor, options) => import_slate39.Editor.levels(editor, options);
/**
* Get the marks that would be added to text at the current selection.
*/
const getMarks = editor => slate.Editor.marks(editor);
// src/interfaces/editor/getMarks.ts
var import_slate40 = require("slate");
var getMarks = (editor) => import_slate40.Editor.marks(editor);
/**
* Get the matching node in the branch of the document after a location.
*/
const getNextNode = (editor, options) => slate.Editor.next(editor, options);
// src/interfaces/editor/getNextNode.ts
var import_slate41 = require("slate");
var getNextNode = (editor, options) => import_slate41.Editor.next(editor, options);
/**
* Get the node at a location.
*/
const getNodeEntry = (editor, at, options) => {
// src/interfaces/editor/getNodeEntry.ts
var import_slate42 = require("slate");
var getNodeEntry = (editor, at, options) => {
try {
return slate.Editor.node(editor, at, options);
} catch (error) {}
return import_slate42.Editor.node(editor, at, options);
} catch (error) {
}
};
/**
* Get the path of a location.
*/
const getPath = (editor, at, options) => slate.Editor.path(editor, at, options);
// src/interfaces/editor/getPath.ts
var import_slate43 = require("slate");
var getPath = (editor, at, options) => import_slate43.Editor.path(editor, at, options);
/**
* Get the set of currently tracked path refs of the editor.
*/
const getPathRefs = editor => slate.Editor.pathRefs(editor);
// src/interfaces/editor/getPathRefs.ts
var import_slate44 = require("slate");
var getPathRefs = (editor) => import_slate44.Editor.pathRefs(editor);
/**
* Get the start or end point of a location.
*/
const getPoint = (editor, at, options) => slate.Editor.point(editor, at, options);
// src/interfaces/editor/getPoint.ts
var import_slate45 = require("slate");
var getPoint = (editor, at, options) => import_slate45.Editor.point(editor, at, options);
/**
* Get the set of currently tracked point refs of the editor.
*/
const getPointRefs = editor => slate.Editor.pointRefs(editor);
// src/interfaces/editor/getPointRefs.ts
var import_slate46 = require("slate");
var getPointRefs = (editor) => import_slate46.Editor.pointRefs(editor);
/**
* Iterate through all of the positions in the document where a `Point` can be
* placed.
*
* By default it will move forward by individual offsets at a time, but you
* can pass the `unit: 'character'` option to moved forward one character, word,
* or line at at time.
*
* 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.
*/
const getPositions = (editor, options) => slate.Editor.positions(editor, options);
// src/interfaces/editor/getPositions.ts
var import_slate47 = require("slate");
var getPositions = (editor, options) => import_slate47.Editor.positions(editor, options);
/**
* Get a range of a location.
*/
const getRange = (editor, at, to) => slate.Editor.range(editor, at, to);
// src/interfaces/editor/getRange.ts
var import_slate48 = require("slate");
var getRange = (editor, at, to) => import_slate48.Editor.range(editor, at, to);
/**
* Get the set of currently tracked range refs of the editor.
*/
const getRangeRefs = editor => slate.Editor.rangeRefs(editor);
// src/interfaces/editor/getRangeRefs.ts
var import_slate49 = require("slate");
var getRangeRefs = (editor) => import_slate49.Editor.rangeRefs(editor);
/**
* Check if a node has block children.
*/
const hasBlocks = (editor, element) => slate.Editor.hasBlocks(editor, element);
// src/interfaces/editor/hasBlocks.ts
var import_slate50 = require("slate");
var hasBlocks = (editor, element) => import_slate50.Editor.hasBlocks(editor, element);
/**
* Check if a node has inline and text children.
*/
const hasInlines = (editor, element) => slate.Editor.hasInlines(editor, element);
// src/interfaces/editor/hasInlines.ts
var import_slate51 = require("slate");
var hasInlines = (editor, element) => import_slate51.Editor.hasInlines(editor, element);
/**
* Check if a node has text children.
*/
const hasTexts = (editor, element) => slate.Editor.hasTexts(editor, element);
// src/interfaces/editor/hasTexts.ts
var import_slate52 = require("slate");
var hasTexts = (editor, element) => import_slate52.Editor.hasTexts(editor, element);
/**
* Insert a block break at the current selection.
*
* If the selection is currently expanded, it will be deleted first.
*/
const insertBreak = editor => slate.Editor.insertBreak(editor);
// src/interfaces/editor/insertBreak.ts
var import_slate53 = require("slate");
var insertBreak = (editor) => import_slate53.Editor.insertBreak(editor);
/**
* Insert a node at the current selection.
*
* If the selection is currently expanded, it will be deleted first.
*/
const insertNode = (editor, node) => slate.Editor.insertNode(editor, node);
// src/interfaces/editor/insertNode.ts
var import_slate54 = require("slate");
var insertNode = (editor, node) => import_slate54.Editor.insertNode(editor, node);
/**
* Check if a point is an edge of a location.
*/
const isEdgePoint = (editor, point, at) => slate.Editor.isEdge(editor, point, at);
// src/interfaces/editor/isEdgePoint.ts
var import_slate55 = require("slate");
var isEdgePoint = (editor, point, at) => import_slate55.Editor.isEdge(editor, point, at);
/**
* Check if a value is an `Editor` object.
*/
const isEditor = value => slate.Editor.isEditor(value);
// src/interfaces/editor/isEditor.ts
var import_slate56 = require("slate");
var isEditor = (value) => import_slate56.Editor.isEditor(value);
/**
* Check if the editor is currently normalizing after each operation.
*/
const isEditorNormalizing = editor => slate.Editor.isNormalizing(editor);
// src/interfaces/editor/isEditorNormalizing.ts
var import_slate57 = require("slate");
var isEditorNormalizing = (editor) => import_slate57.Editor.isNormalizing(editor);
/**
* Check if a point is the end point of a location.
* If point is null, return false.
*/
const isEndPoint = (editor, point, at) => !!point && slate.Editor.isEnd(editor, point, at);
// src/interfaces/editor/isEndPoint.ts
var import_slate58 = require("slate");
var isEndPoint = (editor, point, at) => !!point && import_slate58.Editor.isEnd(editor, point, at);
/**
* Check if a value is an inline `Element` object.
*/
const isInline = (editor, value) => isElement(value) && slate.Editor.isInline(editor, value);
// src/interfaces/editor/isInline.ts
var import_slate59 = require("slate");
var isInline = (editor, value) => isElement(value) && import_slate59.Editor.isInline(editor, value);
/**
* Check if a point is the start point of a location.
* If point is null, return false.
*/
const isStartPoint = (editor, point, at) => !!point && slate.Editor.isStart(editor, point, at);
/**
* Check if a value is a markable void `Element` object.
*/
const isMarkableVoid = (editor, value) => {
// src/interfaces/editor/isMarkableVoid.ts
var isMarkableVoid = (editor, value) => {
return isElement(value) && editor.markableVoid(value);
};
/**
* Normalize any dirty objects in the editor.
*/
const normalizeEditor = (editor, options) => slate.Editor.normalize(editor, options);
// src/interfaces/editor/isStartPoint.ts
var import_slate60 = require("slate");
var isStartPoint = (editor, point, at) => !!point && import_slate60.Editor.isStart(editor, point, at);
/**
* 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.
*/
const removeEditorMark = (editor, key) => slate.Editor.removeMark(editor, key);
// src/interfaces/editor/normalizeEditor.ts
var import_slate61 = require("slate");
var normalizeEditor = (editor, options) => import_slate61.Editor.normalize(editor, options);
/**
* {@link HistoryEditor.isHistoryEditor}
*/
const isHistoryEditor = value => slateHistory.HistoryEditor.isHistoryEditor(value);
// src/interfaces/editor/removeEditorMark.ts
var import_slate62 = require("slate");
var removeEditorMark = (editor, key) => import_slate62.Editor.removeMark(editor, key);
/**
* {@link HistoryEditor.isMerging}
*/
const isHistoryMerging = editor => slateHistory.HistoryEditor.isMerging(editor);
// src/interfaces/history-editor/isHistoryEditor.ts
var import_slate_history = require("slate-history");
var isHistoryEditor = (value) => import_slate_history.HistoryEditor.isHistoryEditor(value);
/**
* {@link HistoryEditor.isSaving}
*/
const isHistorySaving = editor => slateHistory.HistoryEditor.isSaving(editor);
// src/interfaces/history-editor/isHistoryMerging.ts
var import_slate_history2 = require("slate-history");
var isHistoryMerging = (editor) => import_slate_history2.HistoryEditor.isMerging(editor);
/**
* {@link HistoryEditor.withoutMerging}
*/
const withoutMergingHistory = (editor, fn) => slateHistory.HistoryEditor.withoutMerging(editor, fn);
// src/interfaces/history-editor/isHistorySaving.ts
var import_slate_history3 = require("slate-history");
var isHistorySaving = (editor) => import_slate_history3.HistoryEditor.isSaving(editor);
/**
* {@link HistoryEditor.withoutSaving}
*/
const withoutSavingHistory = (editor, fn) => slateHistory.HistoryEditor.withoutSaving(editor, fn);
// src/interfaces/history-editor/withoutMergingHistory.ts
var import_slate_history4 = require("slate-history");
var withoutMergingHistory = (editor, fn) => import_slate_history4.HistoryEditor.withoutMerging(editor, fn);
/**
* 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.
*/
// src/interfaces/history-editor/withoutSavingHistory.ts
var import_slate_history5 = require("slate-history");
var withoutSavingHistory = (editor, fn) => import_slate_history5.HistoryEditor.withoutSaving(editor, fn);
/**
* Descendant of an editor.
*/
// src/interfaces/node/TDescendant.ts
var isDescendant = (node) => isElement(node) || isText(node);
/**
* A utility type to get all the descendant node types from a root node type.
*/
// src/interfaces/node/getCommonNode.ts
var import_slate63 = require("slate");
var getCommonNode = (root, path, another) => import_slate63.Node.common(root, path, another);
/**
* A utility type to get the child node types from a root node type.
*/
// src/interfaces/text/isTextList.ts
var import_slate64 = require("slate");
var isTextList = (value) => import_slate64.Text.isTextList(value);
const isDescendant = node => isElement(node) || isText(node);
// src/interfaces/text/textEquals.ts
var import_slate65 = require("slate");
var textEquals = (text, another) => import_slate65.Text.equals(text, another);
/**
* Get an entry for the common ancesetor node of two paths.
*/
const getCommonNode = (root, path, another) => slate.Node.common(root, path, another);
// src/interfaces/text/textMatches.ts
var import_slate66 = require("slate");
var textMatches = (text, props) => import_slate66.Text.matches(text, props);
/**
* Check if a value is a list of `Text` objects.
*/
const isTextList = value => slate.Text.isTextList(value);
/**
* Check if two text nodes are equal.
*/
const textEquals = (text, another) => slate.Text.equals(text, another);
/**
* 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.
*/
const textMatches = (text, props) => slate.Text.matches(text, props);
/**
* Get the descendant node referred to by a specific path.
* If the path is an empty array, it refers to the root node itself.
* If the node is not found, return null.
* Based on Slate get and has, performance optimization without overhead of
* stringify on throwing
*/
const getNode = (root, path) => {
// src/interfaces/node/getNode.ts
var getNode = (root, path) => {
try {

@@ -942,165 +813,121 @@ for (let i = 0; i < path.length; i++) {

/**
* Get the node at a specific path, asserting that it's an ancestor node.
*/
const getNodeAncestor = (root, path) => slate.Node.ancestor(root, path);
// src/interfaces/node/getNodeAncestor.ts
var import_slate67 = require("slate");
var getNodeAncestor = (root, path) => import_slate67.Node.ancestor(root, path);
/**
* Return a generator of all the ancestor nodes above a specific path.
*
* By default the order is bottom-up, from lowest to highest ancestor in
* the tree, but you can pass the `reverse: true` option to go top-down.
*/
const getNodeAncestors = (root, path, options) => slate.Node.ancestors(root, path, options);
// src/interfaces/node/getNodeAncestors.ts
var import_slate68 = require("slate");
var getNodeAncestors = (root, path, options) => import_slate68.Node.ancestors(root, path, options);
/**
* Get the child of a node at a specific index.
*/
const getNodeChild = (root, index) => slate.Node.child(root, index);
// src/interfaces/node/getNodeChild.ts
var import_slate69 = require("slate");
var getNodeChild = (root, index) => import_slate69.Node.child(root, index);
/**
* Iterate over the children of a node at a specific path.
*/
const getNodeChildren = (root, path, options) => slate.Node.children(root, path, options);
// src/interfaces/node/getNodeChildren.ts
var import_slate70 = require("slate");
var getNodeChildren = (root, path, options) => import_slate70.Node.children(root, path, options);
/**
* Get the node at a specific path, asserting that it's a descendant node.
*/
const getNodeDescendant = (root, path) => slate.Node.descendant(root, path);
// src/interfaces/node/getNodeDescendant.ts
var import_slate71 = require("slate");
var getNodeDescendant = (root, path) => import_slate71.Node.descendant(root, path);
/**
* Return a generator of all the descendant node entries inside a root node.
*/
const getNodeDescendants = (root, options) => slate.Node.descendants(root, options);
// src/interfaces/node/getNodeDescendants.ts
var import_slate72 = require("slate");
var getNodeDescendants = (root, options) => import_slate72.Node.descendants(root, options);
/**
* 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.
*/
const getNodeElements = (root, options) => slate.Node.elements(root, options);
// src/interfaces/node/getNodeElements.ts
var import_slate73 = require("slate");
var getNodeElements = (root, options) => import_slate73.Node.elements(root, options);
/**
* Get the first node entry in a root node from a path.
*/
const getNodeFirstNode = (root, path) => slate.Node.first(root, path);
// src/interfaces/node/getNodeFirstNode.ts
var import_slate74 = require("slate");
var getNodeFirstNode = (root, path) => import_slate74.Node.first(root, path);
/**
* Get the sliced fragment represented by a range inside a root node.
*/
const getNodeFragment = (root, range) => slate.Node.fragment(root, range);
// src/interfaces/node/getNodeFragment.ts
var import_slate75 = require("slate");
var getNodeFragment = (root, range) => import_slate75.Node.fragment(root, range);
/**
* Get the last node entry in a root node from a path.
*/
const getNodeLastNode = (root, path) => slate.Node.last(root, path);
// src/interfaces/node/getNodeLastNode.ts
var import_slate76 = require("slate");
var getNodeLastNode = (root, path) => import_slate76.Node.last(root, path);
/**
* Get the node at a specific path, ensuring it's a leaf text node.
*/
const getNodeLeaf = (root, path) => slate.Node.leaf(root, path);
// src/interfaces/node/getNodeLeaf.ts
var import_slate77 = require("slate");
var getNodeLeaf = (root, path) => import_slate77.Node.leaf(root, path);
/**
* Return a generator of the in a branch of the tree, from a specific path.
*
* By default the order is top-down, from lowest to highest node in the tree,
* but you can pass the `reverse: true` option to go bottom-up.
*/
const getNodeLevels = (root, path, options) => slate.Node.levels(root, path, options);
// src/interfaces/node/getNodeLevels.ts
var import_slate78 = require("slate");
var getNodeLevels = (root, path, options) => import_slate78.Node.levels(root, path, options);
/**
* Get the parent of a node at a specific path.
*/
const getNodeParent = (root, path) => slate.Node.parent(root, path);
// src/interfaces/node/getNodeParent.ts
var import_slate79 = require("slate");
var getNodeParent = (root, path) => import_slate79.Node.parent(root, path);
/**
* Extract the custom properties from a node.
*/
const getNodeProps = node => slate.Node.extractProps(node);
// src/interfaces/node/getNodeProps.ts
var import_slate80 = require("slate");
var getNodeProps = (node) => import_slate80.Node.extractProps(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.
*/
const getNodeString = node => slate.Node.string(node);
// src/interfaces/node/getNodeString.ts
var import_slate81 = require("slate");
var getNodeString = (node) => import_slate81.Node.string(node);
/**
* Return a generator of all leaf text nodes in a root node.
*/
const getNodeTexts = (root, options) => slate.Node.texts(root, options);
// src/interfaces/node/getNodeTexts.ts
var import_slate82 = require("slate");
var getNodeTexts = (root, options) => import_slate82.Node.texts(root, options);
/**
* 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.
*/
const getNodes = (root, options) => slate.Node.nodes(root, options);
// src/interfaces/node/getNodes.ts
var import_slate83 = require("slate");
var getNodes = (root, options) => import_slate83.Node.nodes(root, options);
/**
* Check if a descendant node exists at a specific path.
*/
const hasNode = (root, path) => slate.Node.has(root, path);
// src/interfaces/node/hasNode.ts
var import_slate84 = require("slate");
var hasNode = (root, path) => import_slate84.Node.has(root, path);
/**
* Check if a value implements the 'Ancestor' interface.
*/
const isAncestor = value => slate.Element.isAncestor(value);
// src/interfaces/node/isAncestor.ts
var import_slate85 = require("slate");
var isAncestor = (value) => import_slate85.Element.isAncestor(value);
/**
* Check if a value implements the `Node` interface.
*/
const isNode = value => slate.Node.isNode(value);
// src/interfaces/node/isNode.ts
var import_slate86 = require("slate");
var isNode = (value) => import_slate86.Node.isNode(value);
/**
* Check if a value is a list of `Node` objects.
*/
const isNodeList = value => slate.Node.isNodeList(value);
// src/interfaces/node/isNodeList.ts
var import_slate87 = require("slate");
var isNodeList = (value) => import_slate87.Node.isNodeList(value);
/**
* Check if a node matches a set of props.
*/
const nodeMatches = (node, props) => slate.Node.matches(node, props);
// src/interfaces/node/nodeMatches.ts
var import_slate88 = require("slate");
var nodeMatches = (node, props) => import_slate88.Node.matches(node, props);
/**
* See {@link Range.isCollapsed}.
* Return false if `range` is not defined.
*/
const isCollapsed = range => !!range && slate.Range.isCollapsed(range);
// src/interfaces/range/isCollapsed.ts
var import_slate89 = require("slate");
var isCollapsed = (range) => !!range && import_slate89.Range.isCollapsed(range);
/**
* See {@link Range.isExpanded}.
* Return false if `range` is not defined.
*/
const isExpanded = range => !!range && slate.Range.isExpanded(range);
// src/interfaces/range/isExpanded.ts
var import_slate90 = require("slate");
var isExpanded = (range) => !!range && import_slate90.Range.isExpanded(range);
/**
* Collapse the selection.
*/
const collapseSelection = (editor, options) => {
slate.Transforms.collapse(editor, options);
// src/interfaces/transforms/collapseSelection.ts
var import_slate91 = require("slate");
var collapseSelection = (editor, options) => {
import_slate91.Transforms.collapse(editor, options);
};
/**
* Unset the selection.
*/
const deselect = editor => {
slate.Transforms.deselect(editor);
// src/interfaces/transforms/deselect.ts
var import_slate92 = require("slate");
var deselect = (editor) => {
import_slate92.Transforms.deselect(editor);
};
/**
* Insert a fragment at a specific location in the editor.
*/
const insertFragment = (editor, fragment, options) => {
slate.Transforms.insertFragment(editor, fragment, options);
// src/interfaces/transforms/insertFragment.ts
var import_slate93 = require("slate");
var insertFragment = (editor, fragment, options) => {
import_slate93.Transforms.insertFragment(editor, fragment, options);
};
/**
* Insert nodes at a specific location in the Editor.
*/
const insertNodes = (editor, nodes, options) => {
if (options !== null && options !== void 0 && options.nextBlock) {
const at = (options === null || options === void 0 ? void 0 : options.at) || editor.selection;
// src/interfaces/transforms/insertNodes.ts
var import_slate94 = require("slate");
var insertNodes = (editor, nodes, options) => {
if (options == null ? void 0 : options.nextBlock) {
const at = (options == null ? void 0 : options.at) || editor.selection;
if (at) {

@@ -1113,3 +940,3 @@ const endPoint = getEndPoint(editor, at);

if (blockEntry) {
const nextPath = slate.Path.next(blockEntry[1]);
const nextPath = import_slate94.Path.next(blockEntry[1]);
options.at = nextPath;

@@ -1119,87 +946,68 @@ }

}
slate.Transforms.insertNodes(editor, nodes, options);
import_slate94.Transforms.insertNodes(editor, nodes, options);
};
/**
* Insert a string of text in the Editor.
*/
const insertText = (editor, text, options) => {
slate.Transforms.insertText(editor, text, options);
// src/interfaces/transforms/insertText.ts
var import_slate95 = require("slate");
var insertText = (editor, text, options) => {
import_slate95.Transforms.insertText(editor, text, options);
};
/**
* Lift nodes at a specific location upwards in the document tree, splitting
* their parent in two if necessary.
*/
const liftNodes = (editor, options) => slate.Transforms.liftNodes(editor, options);
// src/interfaces/transforms/liftNodes.ts
var import_slate96 = require("slate");
var liftNodes = (editor, options) => import_slate96.Transforms.liftNodes(editor, options);
/**
* Move the selection's point forward or backward.
*/
const moveSelection = (editor, options) => {
slate.Transforms.move(editor, options);
// src/interfaces/transforms/moveSelection.ts
var import_slate97 = require("slate");
var moveSelection = (editor, options) => {
import_slate97.Transforms.move(editor, options);
};
/**
* Set new properties on the nodes at a location.
*/
const setNodes = (editor, props, options) => slate.Transforms.setNodes(editor, props, options);
// src/interfaces/transforms/setNodes.ts
var import_slate98 = require("slate");
var setNodes = (editor, props, options) => import_slate98.Transforms.setNodes(editor, props, options);
/**
* Set new properties on one of the selection's points.
*/
const setPoint = (editor, props, options) => {
slate.Transforms.setPoint(editor, props, options);
// src/interfaces/transforms/setPoint.ts
var import_slate99 = require("slate");
var setPoint = (editor, props, options) => {
import_slate99.Transforms.setPoint(editor, props, options);
};
/**
* Set new properties on the selection.
*/
const setSelection = (editor, props) => {
slate.Transforms.setSelection(editor, props);
// src/interfaces/transforms/setSelection.ts
var import_slate100 = require("slate");
var setSelection = (editor, props) => {
import_slate100.Transforms.setSelection(editor, props);
};
/**
* Split the nodes at a specific location.
*/
const splitNodes = (editor, options) => slate.Transforms.splitNodes(editor, options);
// src/interfaces/transforms/splitNodes.ts
var import_slate101 = require("slate");
var splitNodes = (editor, options) => import_slate101.Transforms.splitNodes(editor, options);
/**
* Unset properties on the nodes at a location.
*/
const unsetNodes = (editor, props, options) => {
return slate.Transforms.unsetNodes(editor, props, options);
// src/interfaces/transforms/unsetNodes.ts
var import_slate102 = require("slate");
var unsetNodes = (editor, props, options) => {
return import_slate102.Transforms.unsetNodes(editor, props, 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.
*/
const unwrapNodes = (editor, options) => {
slate.Transforms.unwrapNodes(editor, getQueryOptions(editor, options));
// src/interfaces/transforms/unwrapNodes.ts
var import_slate103 = require("slate");
var unwrapNodes = (editor, options) => {
import_slate103.Transforms.unwrapNodes(editor, getQueryOptions(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.
*/
const wrapNodes = (editor, element, options) => {
unhangRange(editor, options === null || options === void 0 ? void 0 : options.at, options);
slate.Transforms.wrapNodes(editor, element, options);
// src/interfaces/transforms/wrapNodes.ts
var import_slate104 = require("slate");
var wrapNodes = (editor, element, options) => {
unhangRange(editor, options == null ? void 0 : options.at, options);
import_slate104.Transforms.wrapNodes(editor, element, options);
};
/**
* Query the node entry.
*/
const queryNode = (entry, {
filter,
allow,
exclude,
level,
maxLevel
} = {}) => {
if (!entry) return false;
// src/utils/queryNode.ts
var import_castArray = __toESM(require("lodash/castArray"));
var queryNode = (entry, { filter, allow, exclude, level, maxLevel } = {}) => {
if (!entry)
return false;
const [node, path] = entry;
if (level) {
const levels = castArray_1(level);
const levels = (0, import_castArray.default)(level);
if (!levels.includes(path.length)) {

@@ -1216,3 +1024,3 @@ return false;

if (allow) {
const allows = castArray_1(allow);
const allows = (0, import_castArray.default)(allow);
if (allows.length > 0 && !allows.includes(node.type)) {

@@ -1223,3 +1031,3 @@ return false;

if (exclude) {
const excludes = castArray_1(exclude);
const excludes = (0, import_castArray.default)(exclude);
if (excludes.length > 0 && excludes.includes(node.type)) {

@@ -1232,14 +1040,8 @@ return false;

/**
* Find node matching the condition.
*/
const findNode = (editor, options = {}) => {
// Slate throws when things aren't found so we wrap in a try catch and return undefined on throw.
// src/queries/findNode.ts
var findNode = (editor, options = {}) => {
try {
const nodeEntries = getNodeEntries(editor, {
at: editor.selection || [],
...getQueryOptions(editor, options)
});
// eslint-disable-next-line no-unreachable-loop
const nodeEntries = getNodeEntries(editor, __spreadValues({
at: editor.selection || []
}, getQueryOptions(editor, options)));
for (const [node, path] of nodeEntries) {

@@ -1249,43 +1051,41 @@ return [node, path];

} catch (error) {
return undefined;
return void 0;
}
};
/**
* Iterate through all of the nodes in the editor and break early for the first truthy match. Otherwise
* returns false.
*/
const someNode = (editor, options) => {
// src/queries/someNode.ts
var someNode = (editor, options) => {
return !!findNode(editor, options);
};
/**
* Add marks to each node of a range.
*/
const addRangeMarks = (editor, props, {
// src/transforms/addRangeMarks.ts
var import_slate105 = require("slate");
var addRangeMarks = (editor, props, {
at = editor.selection
} = {}) => {
if (at) {
if (slate.Path.isPath(at)) {
if (import_slate105.Path.isPath(at)) {
at = getRange(editor, at);
}
const match = (node, path) => {
if (!slate.Text.isText(node)) {
return false; // marks can only be applied to text
const match2 = (node, path) => {
if (!import_slate105.Text.isText(node)) {
return false;
}
const parentEntry = slate.Editor.parent(editor, path);
if (!parentEntry) return false;
const parentEntry = import_slate105.Editor.parent(editor, path);
if (!parentEntry)
return false;
const [parentNode] = parentEntry;
return !editor.isVoid(parentNode) || editor.markableVoid(parentNode);
};
const isExpandedRange = slate.Range.isExpanded(at);
const isExpandedRange = import_slate105.Range.isExpanded(at);
let markAcceptingVoidSelected = false;
if (!isExpandedRange) {
const selectedEntry = slate.Editor.node(editor, at);
if (!selectedEntry) return;
const selectedEntry = import_slate105.Editor.node(editor, at);
if (!selectedEntry)
return;
const [selectedNode, selectedPath] = selectedEntry;
if (selectedNode && match(selectedNode, selectedPath)) {
const parentEntry = slate.Editor.parent(editor, selectedPath);
if (!parentEntry) return;
if (selectedNode && match2(selectedNode, selectedPath)) {
const parentEntry = import_slate105.Editor.parent(editor, selectedPath);
if (!parentEntry)
return;
const [parentNode] = parentEntry;

@@ -1296,4 +1096,4 @@ markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode);

if (isExpandedRange || markAcceptingVoidSelected) {
slate.Transforms.setNodes(editor, props, {
match,
import_slate105.Transforms.setNodes(editor, props, {
match: match2,
split: true,

@@ -1304,24 +1104,13 @@ voids: true,

}
// else {
// const marks = {
// ...(Editor.marks(editor as any) || {}),
// [key]: value,
// };
//
// editor.marks = marks;
// if (!FLUSHING.get(editor as any)) {
// editor.onChange();
// }
// }
}
};
const setElements = (editor, props, options) => setNodes(editor, props, options);
// src/transforms/setElements.ts
var setElements = (editor, props, options) => setNodes(editor, props, options);
/**
* Unhang the range of length 1 so both edges are in the same text node.
*/
const unhangCharacterRange = (editor, at) => {
let [start, end] = slate.Range.edges(at);
if (!slate.Path.equals(start.path, end.path)) {
// src/transforms/unhangCharacterRange.ts
var import_slate106 = require("slate");
var unhangCharacterRange = (editor, at) => {
let [start, end] = import_slate106.Range.edges(at);
if (!import_slate106.Path.equals(start.path, end.path)) {
if (end.offset === 0) {

@@ -1339,130 +1128,129 @@ const pointAfter = getPointAfter(editor, start);

}
return {
anchor: start,
focus: end
};
return { anchor: start, focus: end };
};
exports.addMark = addMark;
exports.addRangeMarks = addRangeMarks;
exports.collapseSelection = collapseSelection;
exports.createPathRef = createPathRef;
exports.createPointRef = createPointRef;
exports.createRangeRef = createRangeRef;
exports.createTEditor = createTEditor;
exports.deleteBackward = deleteBackward;
exports.deleteForward = deleteForward;
exports.deleteFragment = deleteFragment;
exports.deleteMerge = deleteMerge;
exports.deleteText = deleteText;
exports.deselect = deselect;
exports.elementMatches = elementMatches;
exports.findNode = findNode;
exports.getAboveNode = getAboveNode;
exports.getCommonNode = getCommonNode;
exports.getEdgePoints = getEdgePoints;
exports.getEditorString = getEditorString;
exports.getEndPoint = getEndPoint;
exports.getFirstNode = getFirstNode;
exports.getFragment = getFragment;
exports.getLastNode = getLastNode;
exports.getLeafNode = getLeafNode;
exports.getLevels = getLevels;
exports.getMarks = getMarks;
exports.getNextNode = getNextNode;
exports.getNode = getNode;
exports.getNodeAncestor = getNodeAncestor;
exports.getNodeAncestors = getNodeAncestors;
exports.getNodeChild = getNodeChild;
exports.getNodeChildren = getNodeChildren;
exports.getNodeDescendant = getNodeDescendant;
exports.getNodeDescendants = getNodeDescendants;
exports.getNodeElements = getNodeElements;
exports.getNodeEntries = getNodeEntries;
exports.getNodeEntry = getNodeEntry;
exports.getNodeFirstNode = getNodeFirstNode;
exports.getNodeFragment = getNodeFragment;
exports.getNodeLastNode = getNodeLastNode;
exports.getNodeLeaf = getNodeLeaf;
exports.getNodeLevels = getNodeLevels;
exports.getNodeParent = getNodeParent;
exports.getNodeProps = getNodeProps;
exports.getNodeString = getNodeString;
exports.getNodeTexts = getNodeTexts;
exports.getNodes = getNodes;
exports.getParentNode = getParentNode;
exports.getPath = getPath;
exports.getPathRefs = getPathRefs;
exports.getPoint = getPoint;
exports.getPointAfter = getPointAfter;
exports.getPointBefore = getPointBefore;
exports.getPointRefs = getPointRefs;
exports.getPositions = getPositions;
exports.getPreviousNode = getPreviousNode;
exports.getQueryOptions = getQueryOptions;
exports.getRange = getRange;
exports.getRangeRefs = getRangeRefs;
exports.getStartPoint = getStartPoint;
exports.getTEditor = getTEditor;
exports.getVoidNode = getVoidNode;
exports.hasBlocks = hasBlocks;
exports.hasInlines = hasInlines;
exports.hasNode = hasNode;
exports.hasSingleChild = hasSingleChild;
exports.hasTexts = hasTexts;
exports.insertBreak = insertBreak;
exports.insertFragment = insertFragment;
exports.insertNode = insertNode;
exports.insertNodes = insertNodes;
exports.insertText = insertText;
exports.isAncestor = isAncestor;
exports.isBlock = isBlock;
exports.isCollapsed = isCollapsed;
exports.isDescendant = isDescendant;
exports.isEdgePoint = isEdgePoint;
exports.isEditor = isEditor;
exports.isEditorNormalizing = isEditorNormalizing;
exports.isElement = isElement;
exports.isElementEmpty = isElementEmpty;
exports.isElementList = isElementList;
exports.isEndPoint = isEndPoint;
exports.isExpanded = isExpanded;
exports.isHistoryEditor = isHistoryEditor;
exports.isHistoryMerging = isHistoryMerging;
exports.isHistorySaving = isHistorySaving;
exports.isInline = isInline;
exports.isMarkableVoid = isMarkableVoid;
exports.isNode = isNode;
exports.isNodeList = isNodeList;
exports.isStartPoint = isStartPoint;
exports.isText = isText;
exports.isTextList = isTextList;
exports.isVoid = isVoid;
exports.liftNodes = liftNodes;
exports.match = match;
exports.mergeNodes = mergeNodes;
exports.moveNodes = moveNodes;
exports.moveSelection = moveSelection;
exports.nodeMatches = nodeMatches;
exports.normalizeEditor = normalizeEditor;
exports.queryNode = queryNode;
exports.removeEditorMark = removeEditorMark;
exports.removeNodes = removeNodes;
exports.select = select;
exports.setElements = setElements;
exports.setNodes = setNodes;
exports.setPoint = setPoint;
exports.setSelection = setSelection;
exports.someNode = someNode;
exports.splitNodes = splitNodes;
exports.textEquals = textEquals;
exports.textMatches = textMatches;
exports.unhangCharacterRange = unhangCharacterRange;
exports.unhangRange = unhangRange;
exports.unsetNodes = unsetNodes;
exports.unwrapNodes = unwrapNodes;
exports.withoutMergingHistory = withoutMergingHistory;
exports.withoutNormalizing = withoutNormalizing;
exports.withoutSavingHistory = withoutSavingHistory;
exports.wrapNodes = wrapNodes;
//# sourceMappingURL=index.js.map
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addMark,
addRangeMarks,
collapseSelection,
createPathRef,
createPointRef,
createRangeRef,
createTEditor,
deleteBackward,
deleteForward,
deleteFragment,
deleteMerge,
deleteText,
deselect,
elementMatches,
findNode,
getAboveNode,
getCommonNode,
getEdgePoints,
getEditorString,
getEndPoint,
getFirstNode,
getFragment,
getLastNode,
getLeafNode,
getLevels,
getMarks,
getNextNode,
getNode,
getNodeAncestor,
getNodeAncestors,
getNodeChild,
getNodeChildren,
getNodeDescendant,
getNodeDescendants,
getNodeElements,
getNodeEntries,
getNodeEntry,
getNodeFirstNode,
getNodeFragment,
getNodeLastNode,
getNodeLeaf,
getNodeLevels,
getNodeParent,
getNodeProps,
getNodeString,
getNodeTexts,
getNodes,
getParentNode,
getPath,
getPathRefs,
getPoint,
getPointAfter,
getPointBefore,
getPointRefs,
getPositions,
getPreviousNode,
getQueryOptions,
getRange,
getRangeRefs,
getStartPoint,
getTEditor,
getVoidNode,
hasBlocks,
hasInlines,
hasNode,
hasSingleChild,
hasTexts,
insertBreak,
insertFragment,
insertNode,
insertNodes,
insertText,
isAncestor,
isBlock,
isCollapsed,
isDescendant,
isEdgePoint,
isEditor,
isEditorNormalizing,
isElement,
isElementEmpty,
isElementList,
isEndPoint,
isExpanded,
isHistoryEditor,
isHistoryMerging,
isHistorySaving,
isInline,
isMarkableVoid,
isNode,
isNodeList,
isStartPoint,
isText,
isTextList,
isVoid,
liftNodes,
match,
mergeNodes,
moveNodes,
moveSelection,
nodeMatches,
normalizeEditor,
queryNode,
removeEditorMark,
removeNodes,
select,
setElements,
setNodes,
setPoint,
setSelection,
someNode,
splitNodes,
textEquals,
textMatches,
unhangCharacterRange,
unhangRange,
unsetNodes,
unwrapNodes,
withoutMergingHistory,
withoutNormalizing,
withoutSavingHistory,
wrapNodes
});
//# sourceMappingURL=index.js.map
{
"name": "@udecode/slate",
"version": "23.7.4",
"version": "24.3.0",
"description": "Slate extension",

@@ -15,8 +15,17 @@ "license": "MIT",

},
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.es.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist/**/*"
],
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"module": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"scripts": {

@@ -34,3 +43,3 @@ "build": "yarn p:build",

"dependencies": {
"@udecode/utils": "19.7.1"
"@udecode/utils": "24.3.0"
},

@@ -37,0 +46,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc