editate 0.6.10 → 0.6.12
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 +3 -3
- package/lib/doc/node.d.ts +6 -1
- package/lib/doc/operation.d.ts +4 -4
- package/lib/doc/types-infer.d.ts +14 -8
- package/lib/index.cjs +398 -397
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +436 -436
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/commands.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor } from './editor.js';
|
|
2
2
|
import { DocNode, Range } from './doc/types.js';
|
|
3
|
-
import { InferBlockNode, InferTextNode, InferVoidNode } from './doc/types-infer.js';
|
|
3
|
+
import { ExtractAttrValue, InferBlockNode, InferTextNode, InferVoidNode } from './doc/types-infer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Delete content in the selection or specified range.
|
|
6
6
|
*/
|
|
@@ -35,9 +35,9 @@ export declare function ToggleFormat<T extends DocNode>(editor: Editor<T>, key:
|
|
|
35
35
|
/**
|
|
36
36
|
* Set attr to a block node at the caret or specified position.
|
|
37
37
|
*/
|
|
38
|
-
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;
|
|
39
39
|
/**
|
|
40
40
|
* Toggle attr of block node at the caret or specified position.
|
|
41
41
|
*/
|
|
42
|
-
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;
|
|
43
43
|
export {};
|
package/lib/doc/node.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import { BlockNode, DocNode, Node, DomPosition } from './types.js';
|
|
1
|
+
import { BlockNode, DocNode, InlineNode, Node, Path, DomPosition } from './types.js';
|
|
2
2
|
export declare const getNodeSize: (node: Node) => number;
|
|
3
|
+
export declare const getChildAt: <T extends BlockNode>({ children }: T, offset: number) => [node: T["children"][number], offset: number, index: number] | null;
|
|
4
|
+
export declare const getBlockAt: (node: DocNode | BlockNode, offset: number) => [node: BlockNode, offset: number, path: Path];
|
|
5
|
+
export declare const getLeafAt: (node: DocNode | BlockNode, offset: number) => [node: InlineNode, offset: number] | null;
|
|
3
6
|
export declare const offsetToPosition: (node: DocNode | BlockNode, offset: number) => DomPosition;
|
|
7
|
+
export declare function iterNode<T extends Node>(node: T, start: number, end: number): Generator<[node: Node, offset: number], void, void>;
|
|
8
|
+
export declare function iterLeaf<T extends Node>(node: T, start: number, end: number): Generator<[node: InlineNode, offset: number], void, void>;
|
package/lib/doc/operation.d.ts
CHANGED
|
@@ -23,13 +23,13 @@ type FormatOperation = Readonly<{
|
|
|
23
23
|
key: string;
|
|
24
24
|
value: unknown;
|
|
25
25
|
}>;
|
|
26
|
-
declare const
|
|
27
|
-
type
|
|
28
|
-
type: typeof
|
|
26
|
+
declare const OP_PATCH_NODE = "patch_node";
|
|
27
|
+
type PatchNodeOperation = Readonly<{
|
|
28
|
+
type: typeof OP_PATCH_NODE;
|
|
29
29
|
path: Path;
|
|
30
30
|
key: string;
|
|
31
31
|
value: unknown;
|
|
32
32
|
}>;
|
|
33
|
-
export type Operation = DeleteOperation | InsertTextOperation | InsertNodeOperation | FormatOperation |
|
|
33
|
+
export type Operation = DeleteOperation | InsertTextOperation | InsertNodeOperation | FormatOperation | PatchNodeOperation;
|
|
34
34
|
export declare const rebase: (position: number, ops: readonly Operation[]) => number;
|
|
35
35
|
export {};
|
package/lib/doc/types-infer.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type
|
|
3
|
-
export type InferBlockNode<T extends Node> = Flatten<T extends {
|
|
1
|
+
import { Node, TextNode } from './types.js';
|
|
2
|
+
export type InferBlockNode<T extends Node> = T extends {
|
|
4
3
|
children: readonly (infer N extends Node)[];
|
|
5
|
-
} ? T | InferBlockNode<N> : never
|
|
6
|
-
export type InferInlineNode<T extends Node> =
|
|
4
|
+
} ? T | InferBlockNode<N> : never;
|
|
5
|
+
export type InferInlineNode<T extends Node> = T extends {
|
|
7
6
|
children: readonly (infer N extends Node)[];
|
|
8
|
-
} ? InferInlineNode<N> : T
|
|
9
|
-
export type InferVoidNode<T extends
|
|
10
|
-
export type InferTextNode<T extends
|
|
7
|
+
} ? InferInlineNode<N> : T;
|
|
8
|
+
export type InferVoidNode<T extends Node> = Exclude<InferInlineNode<T>, TextNode>;
|
|
9
|
+
export type InferTextNode<T extends Node> = Extract<InferInlineNode<T>, TextNode>;
|
|
10
|
+
type FlattenAllNodes<T extends Node> = T extends any ? T | (T extends {
|
|
11
|
+
children: readonly (infer N extends Node)[];
|
|
12
|
+
} ? FlattenAllNodes<N> : never) : never;
|
|
13
|
+
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;
|
|
14
|
+
export type ExtractAttrValue<N extends Node, K extends PropertyKey> = [
|
|
15
|
+
LookupValue<N, K>
|
|
16
|
+
] extends [never] ? never : LookupValue<N, K>;
|
|
11
17
|
export {};
|