editate 0.6.0 → 0.6.2
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/editor.d.ts +19 -4
- package/lib/index.cjs +214 -190
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +241 -209
- package/lib/index.js.map +1 -1
- package/lib/plugins/history.d.ts +17 -1
- package/lib/plugins/index.d.ts +1 -0
- package/package.json +1 -1
package/lib/commands.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Editor } from "./editor.js";
|
|
2
|
-
import type { DocNode, InferBlockNode, InferInlineNode,
|
|
2
|
+
import type { DocNode, InferBlockNode, InferInlineNode, Range, TextNode } from "./doc/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Delete content in the selection or specified range.
|
|
5
5
|
*/
|
|
@@ -34,9 +34,9 @@ export declare function ToggleFormat<T extends DocNode>(editor: Editor<T>, key:
|
|
|
34
34
|
/**
|
|
35
35
|
* Set attr to a block node at the caret or specified position.
|
|
36
36
|
*/
|
|
37
|
-
export declare function SetBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends Extract<keyof N, string>>(editor: Editor<T>, key: K, value: N[K],
|
|
37
|
+
export declare function SetBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends Extract<keyof N, string>>(editor: Editor<T>, key: K, value: N[K], offset?: number): void;
|
|
38
38
|
/**
|
|
39
39
|
* Toggle attr of block node at the caret or specified position.
|
|
40
40
|
*/
|
|
41
|
-
export declare function ToggleBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends Extract<keyof N, string>>(editor: Editor<T>, key: K, onValue: N[K], offValue: N[K],
|
|
41
|
+
export declare function ToggleBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends Extract<keyof N, string>>(editor: Editor<T>, key: K, onValue: N[K], offValue: N[K], offset?: number): void;
|
|
42
42
|
export {};
|
package/lib/editor.d.ts
CHANGED
|
@@ -27,10 +27,17 @@ export interface EditorOptions<T extends DocNode, S extends StandardSchemaV1<T,
|
|
|
27
27
|
/**
|
|
28
28
|
* Callback invoked when errors happen.
|
|
29
29
|
*
|
|
30
|
-
* @default console.
|
|
30
|
+
* @default console.warn
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
onWarn?: (message: string) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Callback invoked when errors happen.
|
|
35
|
+
*
|
|
36
|
+
* @default `throw new Error(message)`
|
|
37
|
+
*/
|
|
38
|
+
onError?: (message: string) => never;
|
|
33
39
|
}
|
|
40
|
+
export type EditorContext<_> = {};
|
|
34
41
|
type EditorEventMap = {
|
|
35
42
|
change: () => void;
|
|
36
43
|
selectionchange: () => void;
|
|
@@ -45,7 +52,7 @@ export type KeyboardHook = (keyboard: KeyboardEvent) => boolean | void;
|
|
|
45
52
|
/**
|
|
46
53
|
* Functions to handle copy events
|
|
47
54
|
*/
|
|
48
|
-
export type CopyHook = (dataTransfer: DataTransfer
|
|
55
|
+
export type CopyHook = (dataTransfer: DataTransfer) => void;
|
|
49
56
|
/**
|
|
50
57
|
* Functions to handle paste / drop events
|
|
51
58
|
*/
|
|
@@ -90,6 +97,14 @@ export interface Editor<T extends DocNode = DocNode> {
|
|
|
90
97
|
* @returns cleanup function
|
|
91
98
|
*/
|
|
92
99
|
hook<K extends keyof EditorHookMap>(key: K, callback: EditorHookMap[K]): () => void;
|
|
100
|
+
/**
|
|
101
|
+
* Get a value from the context.
|
|
102
|
+
*/
|
|
103
|
+
get<V>(key: EditorContext<V>): V;
|
|
104
|
+
/**
|
|
105
|
+
* Set a value for the context.
|
|
106
|
+
*/
|
|
107
|
+
set<V>(key: EditorContext<V>, value: V): this;
|
|
93
108
|
/**
|
|
94
109
|
* A function to make DOM editable.
|
|
95
110
|
* @returns A function to stop subscribing DOM changes and restores previous DOM state.
|
|
@@ -99,5 +114,5 @@ export interface Editor<T extends DocNode = DocNode> {
|
|
|
99
114
|
/**
|
|
100
115
|
* A function to initialize {@link Editor}.
|
|
101
116
|
*/
|
|
102
|
-
export declare const createEditor: <T extends DocNode, S extends StandardSchemaV1<T, T> | void = void>({ doc, readonly, schema, isBlock, onError, }: EditorOptions<T, S>) => Editor<T>;
|
|
117
|
+
export declare const createEditor: <T extends DocNode, S extends StandardSchemaV1<T, T> | void = void>({ doc, readonly, schema, isBlock, onWarn, onError, }: EditorOptions<T, S>) => Editor<T>;
|
|
103
118
|
export {};
|