editate 0.6.9 → 0.6.11
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 +7 -6
- package/lib/doc/types-infer.d.ts +18 -0
- package/lib/doc/types.d.ts +0 -9
- package/lib/editor.d.ts +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -0
- 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 +2 -2
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 { ExtractAttrValue, 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,17 +27,17 @@ 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
|
*/
|
|
37
|
-
export declare function SetBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends
|
|
38
|
+
export declare function SetBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends string>(editor: Editor<T>, key: K, value: ExtractAttrValue<N, K>, offset?: number): void;
|
|
38
39
|
/**
|
|
39
40
|
* Toggle attr of block node at the caret or specified position.
|
|
40
41
|
*/
|
|
41
|
-
export declare function ToggleBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends
|
|
42
|
+
export declare function ToggleBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends string>(editor: Editor<T>, key: K, onValue: ExtractAttrValue<N, K>, offValue: ExtractAttrValue<N, K>, offset?: number): void;
|
|
42
43
|
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
type FlattenAllNodes<T extends Node> = T extends any ? T | (T extends {
|
|
12
|
+
children: readonly (infer N extends Node)[];
|
|
13
|
+
} ? FlattenAllNodes<N> : never) : never;
|
|
14
|
+
type LookupValue<N extends Node, K extends PropertyKey> = FlattenAllNodes<N> extends infer AllNodes extends Node ? AllNodes extends any ? K extends keyof AllNodes ? AllNodes[K] : never : never : never;
|
|
15
|
+
export type ExtractAttrValue<N extends Node, K extends PropertyKey> = [
|
|
16
|
+
LookupValue<N, K>
|
|
17
|
+
] extends [never] ? never : LookupValue<N, K>;
|
|
18
|
+
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
|
@@ -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
|