node.d.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Editor, Path, Range, Text } from '..';
  2. import { Element, ElementEntry } from './element';
  3. /**
  4. * The `Node` union type represents all of the different types of nodes that
  5. * occur in a Slate document tree.
  6. */
  7. export declare type BaseNode = Editor | Element | Text;
  8. export declare type Node = Editor | Element | Text;
  9. export interface NodeInterface {
  10. ancestor: (root: Node, path: Path) => Ancestor;
  11. ancestors: (root: Node, path: Path, options?: {
  12. reverse?: boolean;
  13. }) => Generator<NodeEntry<Ancestor>, void, undefined>;
  14. child: (root: Node, index: number) => Descendant;
  15. children: (root: Node, path: Path, options?: {
  16. reverse?: boolean;
  17. }) => Generator<NodeEntry<Descendant>, void, undefined>;
  18. common: (root: Node, path: Path, another: Path) => NodeEntry;
  19. descendant: (root: Node, path: Path) => Descendant;
  20. descendants: (root: Node, options?: {
  21. from?: Path;
  22. to?: Path;
  23. reverse?: boolean;
  24. pass?: (node: NodeEntry) => boolean;
  25. }) => Generator<NodeEntry<Descendant>, void, undefined>;
  26. elements: (root: Node, options?: {
  27. from?: Path;
  28. to?: Path;
  29. reverse?: boolean;
  30. pass?: (node: NodeEntry) => boolean;
  31. }) => Generator<ElementEntry, void, undefined>;
  32. extractProps: (node: Node) => NodeProps;
  33. first: (root: Node, path: Path) => NodeEntry;
  34. fragment: (root: Node, range: Range) => Descendant[];
  35. get: (root: Node, path: Path) => Node;
  36. has: (root: Node, path: Path) => boolean;
  37. isNode: (value: any) => value is Node;
  38. isNodeList: (value: any) => value is Node[];
  39. last: (root: Node, path: Path) => NodeEntry;
  40. leaf: (root: Node, path: Path) => Text;
  41. levels: (root: Node, path: Path, options?: {
  42. reverse?: boolean;
  43. }) => Generator<NodeEntry, void, undefined>;
  44. matches: (node: Node, props: Partial<Node>) => boolean;
  45. nodes: (root: Node, options?: {
  46. from?: Path;
  47. to?: Path;
  48. reverse?: boolean;
  49. pass?: (entry: NodeEntry) => boolean;
  50. }) => Generator<NodeEntry, void, undefined>;
  51. parent: (root: Node, path: Path) => Ancestor;
  52. string: (node: Node) => string;
  53. texts: (root: Node, options?: {
  54. from?: Path;
  55. to?: Path;
  56. reverse?: boolean;
  57. pass?: (node: NodeEntry) => boolean;
  58. }) => Generator<NodeEntry<Text>, void, undefined>;
  59. }
  60. export declare const Node: NodeInterface;
  61. /**
  62. * The `Descendant` union type represents nodes that are descendants in the
  63. * tree. It is returned as a convenience in certain cases to narrow a value
  64. * further than the more generic `Node` union.
  65. */
  66. export declare type Descendant = Element | Text;
  67. /**
  68. * The `Ancestor` union type represents nodes that are ancestors in the tree.
  69. * It is returned as a convenience in certain cases to narrow a value further
  70. * than the more generic `Node` union.
  71. */
  72. export declare type Ancestor = Editor | Element;
  73. /**
  74. * `NodeEntry` objects are returned when iterating over the nodes in a Slate
  75. * document tree. They consist of the node and its `Path` relative to the root
  76. * node in the document.
  77. */
  78. export declare type NodeEntry<T extends Node = Node> = [T, Path];
  79. /**
  80. * Convenience type for returning the props of a node.
  81. */
  82. export declare type NodeProps = Omit<Editor, 'children'> | Omit<Element, 'children'> | Omit<Text, 'text'>;
  83. //# sourceMappingURL=node.d.ts.map