superdoc-macros 0.2.0 → 0.3.0
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/README.md +69 -66
- package/dist/host/superdoc-host.d.ts +2 -21
- package/dist/host/superdoc-host.js +56 -28
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/manager.d.ts +24 -21
- package/dist/manager.js +36 -28
- package/dist/messages.d.ts +50 -0
- package/dist/messages.js +78 -0
- package/dist/recorder/recorder.d.ts +7 -19
- package/dist/recorder/recorder.js +21 -6
- package/dist/scripting/eval-runner.d.ts +1 -12
- package/dist/scripting/eval-runner.js +20 -6
- package/dist/scripting/iframe-runner.d.ts +5 -4
- package/dist/scripting/iframe-runner.js +27 -8
- package/dist/scripting/macro-api.d.ts +12 -23
- package/dist/scripting/macro-api.js +24 -9
- package/dist/scripting/runner.d.ts +3 -3
- package/dist/shortcuts.d.ts +8 -6
- package/dist/shortcuts.js +5 -4
- package/dist/snippets/autotext.d.ts +16 -13
- package/dist/snippets/autotext.js +8 -6
- package/dist/snippets/snippets.d.ts +14 -10
- package/dist/snippets/snippets.js +8 -6
- package/dist/storage.d.ts +7 -6
- package/dist/storage.js +4 -4
- package/dist/types.d.ts +33 -32
- package/dist/types.js +6 -5
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared contracts.
|
|
3
3
|
*
|
|
4
|
-
* `MacroHost`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* `MacroHost` is the single connection point to the editor: all three
|
|
5
|
+
* capabilities (scripts, recorder, snippets) work against it rather than
|
|
6
|
+
* against SuperDoc directly. That is what makes the toolkit testable with an
|
|
7
|
+
* in-memory double, and what lets another host (a different engine version,
|
|
8
|
+
* a different editor) plug in with one implementation of this interface.
|
|
8
9
|
*/
|
|
9
|
-
/**
|
|
10
|
+
/** Result of an operation. Same shape as otzaria-word-editor's `CommandOutcome`. */
|
|
10
11
|
export type MacroOutcome = {
|
|
11
12
|
ok: true;
|
|
12
13
|
} | {
|
|
@@ -14,20 +15,20 @@ export type MacroOutcome = {
|
|
|
14
15
|
message: string;
|
|
15
16
|
reason?: string;
|
|
16
17
|
};
|
|
17
|
-
/**
|
|
18
|
+
/** Snapshot of the document selection at the moment of the call. */
|
|
18
19
|
export interface SelectionSnapshot {
|
|
19
|
-
/**
|
|
20
|
+
/** The selected text. `''` when there is no selection or it was not requested. */
|
|
20
21
|
text: string;
|
|
21
|
-
/**
|
|
22
|
+
/** Whether a range is selected, as opposed to a caret only. */
|
|
22
23
|
hasRange: boolean;
|
|
23
|
-
/**
|
|
24
|
+
/** Id of the block the selection starts in, or `null`. */
|
|
24
25
|
blockId: string | null;
|
|
25
|
-
/**
|
|
26
|
+
/** The target that write operations (`insert`) consume. Opaque — handed back to the engine as-is. */
|
|
26
27
|
selectionTarget: unknown | null;
|
|
27
|
-
/**
|
|
28
|
+
/** Whether the selection is empty (caret only). */
|
|
28
29
|
empty: boolean;
|
|
29
30
|
}
|
|
30
|
-
/**
|
|
31
|
+
/** A typing event the host reports to the recorder and to auto-text. */
|
|
31
32
|
export type TextInputEvent = {
|
|
32
33
|
kind: 'insert-text';
|
|
33
34
|
text: string;
|
|
@@ -39,40 +40,40 @@ export type TextInputEvent = {
|
|
|
39
40
|
kind: 'delete-forward';
|
|
40
41
|
};
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
43
|
+
* What the toolkit needs from the editor. The SuperDoc v2 implementation is
|
|
44
|
+
* `createSuperdocHost`; tests use an in-memory double.
|
|
44
45
|
*/
|
|
45
46
|
export interface MacroHost {
|
|
46
47
|
commands: {
|
|
47
|
-
/**
|
|
48
|
+
/** Whether the engine recognizes the command. */
|
|
48
49
|
has(id: string): boolean;
|
|
49
|
-
/**
|
|
50
|
+
/** Runs a command from the engine's catalog and returns a normalized outcome. */
|
|
50
51
|
execute(id: string, payload?: unknown): Promise<MacroOutcome>;
|
|
51
|
-
/**
|
|
52
|
+
/** The known command ids, when the host can enumerate them. */
|
|
52
53
|
ids(): readonly string[];
|
|
53
54
|
};
|
|
54
|
-
/**
|
|
55
|
+
/** Inserts text at the caret (or at the end of the document when there is no caret). */
|
|
55
56
|
insertText(text: string): Promise<MacroOutcome>;
|
|
56
|
-
/**
|
|
57
|
+
/** Deletes characters backwards from the caret. */
|
|
57
58
|
deleteBackward(count: number): Promise<MacroOutcome>;
|
|
58
|
-
/**
|
|
59
|
+
/** Snapshot of the current selection. Never throws. */
|
|
59
60
|
getSelection(options?: {
|
|
60
61
|
includeText?: boolean;
|
|
61
62
|
}): Promise<SelectionSnapshot>;
|
|
62
|
-
/**
|
|
63
|
+
/** Replaces every occurrence of `query` with `replacement`. Returns how many were replaced. */
|
|
63
64
|
replaceAll(query: string, replacement: string): Promise<{
|
|
64
65
|
ok: boolean;
|
|
65
66
|
replaced: number;
|
|
66
67
|
message?: string;
|
|
67
68
|
}>;
|
|
68
|
-
/**
|
|
69
|
+
/** The full text of the document body. `''` when unavailable. */
|
|
69
70
|
getDocumentText(): Promise<string>;
|
|
70
|
-
/**
|
|
71
|
+
/** Observes every command the engine runs (from any source). Returns a dispose function. */
|
|
71
72
|
onCommand(listener: (id: string, payload: unknown) => void): () => void;
|
|
72
|
-
/**
|
|
73
|
+
/** Observes typing in the document. Returns a dispose function. */
|
|
73
74
|
onTextInput(listener: (event: TextInputEvent) => void): () => void;
|
|
74
75
|
}
|
|
75
|
-
/**
|
|
76
|
+
/** One step of a recorded macro. Fully JSON-serializable. */
|
|
76
77
|
export type MacroStep = {
|
|
77
78
|
type: 'command';
|
|
78
79
|
id: string;
|
|
@@ -89,7 +90,7 @@ export type MacroStep = {
|
|
|
89
90
|
type: 'delete-forward';
|
|
90
91
|
count: number;
|
|
91
92
|
};
|
|
92
|
-
/**
|
|
93
|
+
/** A recorded macro, as persisted and imported/exported. */
|
|
93
94
|
export interface RecordedMacro {
|
|
94
95
|
version: 1;
|
|
95
96
|
id: string;
|
|
@@ -99,21 +100,21 @@ export interface RecordedMacro {
|
|
|
99
100
|
shortcut?: string;
|
|
100
101
|
steps: MacroStep[];
|
|
101
102
|
}
|
|
102
|
-
/**
|
|
103
|
+
/** A written macro — a JavaScript script that runs against the toolkit's API. */
|
|
103
104
|
export interface SavedScript {
|
|
104
105
|
id: string;
|
|
105
106
|
name: string;
|
|
106
107
|
source: string;
|
|
107
108
|
shortcut?: string;
|
|
108
109
|
}
|
|
109
|
-
/**
|
|
110
|
+
/** A text snippet (AutoText building block). */
|
|
110
111
|
export interface Snippet {
|
|
111
112
|
id: string;
|
|
112
113
|
name: string;
|
|
113
|
-
/**
|
|
114
|
+
/** Snippet content. Supports `{{...}}` variables — see `renderSnippet`. */
|
|
114
115
|
text: string;
|
|
115
|
-
/**
|
|
116
|
+
/** Auto-text trigger word: typing the word followed by a space replaces it with the content. */
|
|
116
117
|
trigger?: string;
|
|
117
|
-
/**
|
|
118
|
+
/** Keyboard shortcut, e.g. `Ctrl+Alt+1`. */
|
|
118
119
|
shortcut?: string;
|
|
119
120
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared contracts.
|
|
3
3
|
*
|
|
4
|
-
* `MacroHost`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* `MacroHost` is the single connection point to the editor: all three
|
|
5
|
+
* capabilities (scripts, recorder, snippets) work against it rather than
|
|
6
|
+
* against SuperDoc directly. That is what makes the toolkit testable with an
|
|
7
|
+
* in-memory double, and what lets another host (a different engine version,
|
|
8
|
+
* a different editor) plug in with one implementation of this interface.
|
|
8
9
|
*/
|
|
9
10
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superdoc-macros",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Macro toolkit for SuperDoc-based editors: sandboxed scripted macros, a Word-style macro recorder, and snippets with auto-text expansion.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|