editate 0.6.8 → 0.6.10
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/commands.d.ts +5 -4
- package/lib/doc/node.d.ts +3 -0
- package/lib/doc/{edit.d.ts → operation.d.ts} +1 -3
- package/lib/doc/types-infer.d.ts +11 -0
- package/lib/doc/types.d.ts +0 -9
- package/lib/editor.d.ts +3 -3
- package/lib/index.cjs +628 -605
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +463 -440
- package/lib/index.js.map +1 -1
- package/lib/plugins/transfer/htmlTransfer.d.ts +2 -1
- package/lib/plugins/transfer/plainTransfer.d.ts +2 -1
- package/package.json +3 -3
package/lib/commands.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Editor } from './editor.js';
|
|
2
|
-
import { DocNode,
|
|
2
|
+
import { DocNode, Range } from './doc/types.js';
|
|
3
|
+
import { InferBlockNode, InferTextNode, InferVoidNode } from './doc/types-infer.js';
|
|
3
4
|
/**
|
|
4
5
|
* Delete content in the selection or specified range.
|
|
5
6
|
*/
|
|
@@ -11,7 +12,7 @@ export declare function InsertText(editor: Editor, text: string, position?: numb
|
|
|
11
12
|
/**
|
|
12
13
|
* Insert node at the caret or specified position.
|
|
13
14
|
*/
|
|
14
|
-
export declare function InsertNode<T extends DocNode>(editor: Editor<T>, node:
|
|
15
|
+
export declare function InsertNode<T extends DocNode>(editor: Editor<T>, node: InferVoidNode<T>, position?: number): void;
|
|
15
16
|
/**
|
|
16
17
|
* Replace text in the selection or specified range.
|
|
17
18
|
*/
|
|
@@ -26,11 +27,11 @@ type ToggleableKey<T> = {
|
|
|
26
27
|
/**
|
|
27
28
|
* Format content in the selection or specified range.
|
|
28
29
|
*/
|
|
29
|
-
export declare function Format<T extends DocNode, N extends Omit<
|
|
30
|
+
export declare function Format<T extends DocNode, N extends Omit<InferTextNode<T>, "text">, K extends Extract<keyof N, string>>(editor: Editor<T>, key: K, value: N[K], range?: Range): void;
|
|
30
31
|
/**
|
|
31
32
|
* Toggle formatting in the selection or specified range.
|
|
32
33
|
*/
|
|
33
|
-
export declare function ToggleFormat<T extends DocNode>(editor: Editor<T>, key: Extract<ToggleableKey<Omit<
|
|
34
|
+
export declare function ToggleFormat<T extends DocNode>(editor: Editor<T>, key: Extract<ToggleableKey<Omit<InferTextNode<T>, "text">>, string>, range?: Range): void;
|
|
34
35
|
/**
|
|
35
36
|
* Set attr to a block node at the caret or specified position.
|
|
36
37
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment, Path, Range } from './types.js';
|
|
2
2
|
declare const OP_DELETE = "delete";
|
|
3
3
|
type DeleteOperation = Readonly<{
|
|
4
4
|
type: typeof OP_DELETE;
|
|
@@ -31,7 +31,5 @@ type SetNodeAttrOperation = Readonly<{
|
|
|
31
31
|
value: unknown;
|
|
32
32
|
}>;
|
|
33
33
|
export type Operation = DeleteOperation | InsertTextOperation | InsertNodeOperation | FormatOperation | SetNodeAttrOperation;
|
|
34
|
-
export declare const getNodeSize: (node: Node) => number;
|
|
35
|
-
export declare const offsetToPosition: (node: DocNode | BlockNode, offset: number) => DomPosition;
|
|
36
34
|
export declare const rebase: (position: number, ops: readonly Operation[]) => number;
|
|
37
35
|
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DocNode, Node, TextNode } from './types.js';
|
|
2
|
+
type Flatten<T> = T extends any ? T : never;
|
|
3
|
+
export type InferBlockNode<T extends Node> = Flatten<T extends {
|
|
4
|
+
children: readonly (infer N extends Node)[];
|
|
5
|
+
} ? T | InferBlockNode<N> : never>;
|
|
6
|
+
export type InferInlineNode<T extends Node> = Flatten<T extends {
|
|
7
|
+
children: readonly (infer N extends Node)[];
|
|
8
|
+
} ? InferInlineNode<N> : T>;
|
|
9
|
+
export type InferVoidNode<T extends DocNode> = Exclude<InferInlineNode<T>, TextNode>;
|
|
10
|
+
export type InferTextNode<T extends DocNode> = Extract<InferInlineNode<T>, TextNode>;
|
|
11
|
+
export {};
|
package/lib/doc/types.d.ts
CHANGED
|
@@ -12,14 +12,6 @@ export interface DocNode {
|
|
|
12
12
|
readonly children: readonly BlockNode[];
|
|
13
13
|
}
|
|
14
14
|
export type Fragment = DocNode["children"];
|
|
15
|
-
type InferChild<T> = T extends {
|
|
16
|
-
children: readonly (infer N)[];
|
|
17
|
-
} ? InferChild<N> : T;
|
|
18
|
-
type InferBlock<T> = T extends {
|
|
19
|
-
children: readonly (infer N)[];
|
|
20
|
-
} ? T & InferBlock<N> : T;
|
|
21
|
-
export type InferInlineNode<T extends DocNode> = InferChild<T>;
|
|
22
|
-
export type InferBlockNode<T extends DocNode> = InferBlock<T>;
|
|
23
15
|
export type Path = readonly number[];
|
|
24
16
|
export type DomPosition = readonly [path: Path, offset: number];
|
|
25
17
|
export type Range = readonly [start: number, end: number];
|
|
@@ -28,4 +20,3 @@ export type SelectionSnapshot = readonly [
|
|
|
28
20
|
anchor: DomPosition,
|
|
29
21
|
focus: DomPosition
|
|
30
22
|
];
|
|
31
|
-
export {};
|
package/lib/editor.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import { DocNode, Fragment, Selection } from './doc/types.js';
|
|
3
|
-
import { Operation } from './doc/
|
|
3
|
+
import { Operation } from './doc/operation.js';
|
|
4
4
|
import { Parser } from './dom/parser.js';
|
|
5
5
|
type EditorCommandOrPlugin<A extends unknown[], T extends DocNode = DocNode> = (editor: Editor<T>, ...args: A) => void | undefined;
|
|
6
6
|
type EditorQuery<A extends unknown[], V, T extends DocNode = DocNode> = (editor: Editor<T>, ...args: A) => V;
|
|
@@ -85,8 +85,8 @@ export interface Editor<T extends DocNode = DocNode> {
|
|
|
85
85
|
* @param fn {@link EditorCommandOrPlugin} or {@link EditorQuery}
|
|
86
86
|
* @param args arguments of the function
|
|
87
87
|
*/
|
|
88
|
-
exec<A extends unknown[]>(fn: EditorCommandOrPlugin<A, T>, ...args: A): this;
|
|
89
|
-
exec<A extends unknown[], V>(fn: EditorQuery<A, V, T>, ...args: A): V;
|
|
88
|
+
exec<const A extends unknown[]>(fn: EditorCommandOrPlugin<A, T>, ...args: A): this;
|
|
89
|
+
exec<const A extends unknown[], V>(fn: EditorQuery<A, V, T>, ...args: A): V;
|
|
90
90
|
/**
|
|
91
91
|
* A function to subscribe editor events.
|
|
92
92
|
* @returns cleanup function
|