editate 0.6.21 → 0.6.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/doc/node.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const getNodeSize: (node: Node) => number;
4
4
  export declare const getChildAt: <T extends BlockNode>({ children }: T, offset: number, isBackwardAffinity?: boolean) => [node: T["children"][number], offset: number, index: number] | null;
5
5
  export declare const getLeafBlockAt: <T extends DocNode | BlockNode>(node: T, offset: number) => [node: InferLeafBlockNode<T>, offset: number, path: Path];
6
6
  export declare const getLeafAt: <T extends DocNode | BlockNode>(node: T, offset: number, isBackwardAffinity?: boolean) => [node: InferInlineNode<T>, offset: number, path: Path] | null;
7
+ export declare const getNodeOffset: (root: DocNode | BlockNode, target: Node) => number | null;
7
8
  export declare const offsetToPosition: (node: DocNode | BlockNode, offset: number) => DomPosition;
8
9
  export declare function iterLeafBlocks<T extends Node>(node: T, range: Range): Generator<[node: InferLeafBlockNode<T>, offset: number], void, void>;
9
10
  export declare function iterLeaves<T extends Node>(node: T, range: Range): Generator<[node: InferInlineNode<T>, offset: number], void, void>;
@@ -31,5 +31,9 @@ type PatchNodeOperation = Readonly<{
31
31
  value: unknown;
32
32
  }>;
33
33
  export type Operation = DeleteOperation | InsertTextOperation | InsertNodeOperation | FormatOperation | PatchNodeOperation;
34
- export declare const rebase: (position: number, ops: readonly Operation[]) => number;
34
+ /**
35
+ * Remap a position through the given operation.
36
+ * @param stickBefore `true` to keep the position in place when content is inserted at it, instead of moving it after the inserted content.
37
+ */
38
+ export declare const mapPosition: (position: number, op: Operation, stickBefore?: boolean) => number;
35
39
  export {};
package/lib/editor.d.ts CHANGED
@@ -58,7 +58,11 @@ export type CopyHook = (dataTransfer: DataTransfer) => void;
58
58
  */
59
59
  export type PasteHook = (dataTransfer: DataTransfer) => string | Fragment | null;
60
60
  type EditorHookMap = {
61
- apply: (op: Operation, next: (op?: Operation) => void) => void;
61
+ /**
62
+ * Call `next(op)` to continue applying the operation, or `next()` with a nullish value to cancel it.
63
+ * If the hook returns without calling `next`, the operation is passed through as is.
64
+ */
65
+ apply: (op: Operation, next: (op?: Operation | null) => void) => void;
62
66
  mount: (element: HTMLElement, parser: Parser) => void | (() => void);
63
67
  keyboard: KeyboardHook;
64
68
  copy: CopyHook;