@kerebron/extension-menu 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/esm/editor/src/CoreEditor.d.ts +31 -0
- package/esm/editor/src/CoreEditor.d.ts.map +1 -0
- package/esm/editor/src/CoreEditor.js +198 -0
- package/esm/editor/src/DummyEditorView.d.ts +60 -0
- package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
- package/esm/editor/src/DummyEditorView.js +277 -0
- package/esm/editor/src/Extension.d.ts +26 -0
- package/esm/editor/src/Extension.d.ts.map +1 -0
- package/esm/editor/src/Extension.js +33 -0
- package/esm/editor/src/ExtensionManager.d.ts +33 -0
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
- package/esm/editor/src/ExtensionManager.js +272 -0
- package/esm/editor/src/Mark.d.ts +20 -0
- package/esm/editor/src/Mark.d.ts.map +1 -0
- package/esm/editor/src/Mark.js +40 -0
- package/esm/editor/src/Node.d.ts +29 -0
- package/esm/editor/src/Node.d.ts.map +1 -0
- package/esm/editor/src/Node.js +49 -0
- package/esm/editor/src/commands/CommandManager.d.ts +16 -0
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
- package/esm/editor/src/commands/CommandManager.js +61 -0
- package/esm/editor/src/commands/createChainableState.d.ts +3 -0
- package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
- package/esm/editor/src/commands/createChainableState.js +29 -0
- package/esm/editor/src/commands/mod.d.ts +55 -0
- package/esm/editor/src/commands/mod.d.ts.map +1 -0
- package/esm/editor/src/commands/mod.js +883 -0
- package/esm/editor/src/mod.d.ts +7 -0
- package/esm/editor/src/mod.d.ts.map +1 -0
- package/esm/editor/src/mod.js +6 -0
- package/esm/editor/src/nodeToTreeString.d.ts +4 -0
- package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
- package/esm/editor/src/nodeToTreeString.js +58 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
- package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/keymap.js +125 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
- package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
- package/esm/editor/src/types.d.ts +34 -0
- package/esm/editor/src/types.d.ts.map +1 -0
- package/esm/editor/src/types.js +1 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
- package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
- package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
- package/esm/extension-menu/src/ExtensionMenu.d.ts +17 -0
- package/esm/extension-menu/src/ExtensionMenu.d.ts.map +1 -0
- package/esm/extension-menu/src/ExtensionMenu.js +318 -0
- package/esm/extension-menu/src/MenuPlugin.d.ts +9 -0
- package/esm/extension-menu/src/MenuPlugin.d.ts.map +1 -0
- package/esm/extension-menu/src/MenuPlugin.js +245 -0
- package/esm/extension-menu/src/icons.d.ts +15 -0
- package/esm/extension-menu/src/icons.d.ts.map +1 -0
- package/esm/extension-menu/src/icons.js +118 -0
- package/esm/extension-menu/src/menu.d.ts +88 -0
- package/esm/extension-menu/src/menu.d.ts.map +1 -0
- package/esm/extension-menu/src/menu.js +392 -0
- package/esm/extension-menu/src/prompt.d.ts +36 -0
- package/esm/extension-menu/src/prompt.d.ts.map +1 -0
- package/esm/extension-menu/src/prompt.js +158 -0
- package/esm/package.json +3 -0
- package/package.json +2 -6
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { Schema } from 'prosemirror-model';
|
|
2
|
+
import { InputRulesPlugin, } from './plugins/input-rules/InputRulesPlugin.js';
|
|
3
|
+
import { KeymapPlugin } from './plugins/keymap/keymap.js';
|
|
4
|
+
import { chainCommands, } from './commands/mod.js';
|
|
5
|
+
import { addAttributesToSchema } from './utilities/getHtmlAttributes.js';
|
|
6
|
+
export function findDuplicates(items) {
|
|
7
|
+
const filtered = items.filter((el, index) => items.indexOf(el) !== index);
|
|
8
|
+
return Array.from(new Set(filtered));
|
|
9
|
+
}
|
|
10
|
+
export function splitExtensions(extensions) {
|
|
11
|
+
const baseExtensions = Array.from(extensions).filter((extension) => extension.type === 'extension');
|
|
12
|
+
const nodeExtensions = Array.from(extensions).filter((extension) => extension.type === 'node');
|
|
13
|
+
const markExtensions = Array.from(extensions).filter((extension) => extension.type === 'mark');
|
|
14
|
+
return {
|
|
15
|
+
baseExtensions,
|
|
16
|
+
nodeExtensions,
|
|
17
|
+
markExtensions,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export class ExtensionManager {
|
|
21
|
+
constructor(extensions, editor) {
|
|
22
|
+
Object.defineProperty(this, "editor", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: editor
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "schema", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "extensions", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: new Set()
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "plugins", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "nodeViews", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: {}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "commandFactories", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: {}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(this, "converters", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: {}
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(this, "debug", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: true
|
|
69
|
+
});
|
|
70
|
+
this.setupExtensions(new Set(extensions));
|
|
71
|
+
this.schema = this.getSchemaByResolvedExtensions(editor);
|
|
72
|
+
const event = new CustomEvent('schema:ready', {
|
|
73
|
+
detail: {
|
|
74
|
+
editor,
|
|
75
|
+
schema: this.schema,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
editor.dispatchEvent(event);
|
|
79
|
+
this.plugins = this.getPlugins();
|
|
80
|
+
}
|
|
81
|
+
getExtension(name) {
|
|
82
|
+
const { nodeExtensions, markExtensions, baseExtensions } = splitExtensions(this.extensions);
|
|
83
|
+
for (const extension of baseExtensions) {
|
|
84
|
+
if (extension.name === name) {
|
|
85
|
+
return extension;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
getPlugins() {
|
|
90
|
+
const plugins = [];
|
|
91
|
+
const inputRules = [];
|
|
92
|
+
const commands = new Map();
|
|
93
|
+
const keyBindings = new Map();
|
|
94
|
+
const mergeCommands = (toInsert, extName) => {
|
|
95
|
+
for (const key in toInsert) {
|
|
96
|
+
const commandFactory = toInsert[key];
|
|
97
|
+
if (!commandFactory) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (this.debug) {
|
|
101
|
+
const wrappedFactory = (...args) => {
|
|
102
|
+
const realCommand = commandFactory(...args);
|
|
103
|
+
const command = (state, dispatch, view) => {
|
|
104
|
+
if (dispatch) {
|
|
105
|
+
console.debug(`Command: ${extName}.${key}`);
|
|
106
|
+
}
|
|
107
|
+
return realCommand(state, dispatch, view);
|
|
108
|
+
};
|
|
109
|
+
return command;
|
|
110
|
+
};
|
|
111
|
+
commands.set(key, wrappedFactory);
|
|
112
|
+
this.commandFactories[key] = wrappedFactory;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
commands.set(key, commandFactory);
|
|
116
|
+
this.commandFactories[key] = commandFactory;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function mergeShortcuts(toInsert, extName) {
|
|
121
|
+
for (const key in toInsert) {
|
|
122
|
+
if (!toInsert[key]) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const commandFactory = commands.get(toInsert[key]);
|
|
126
|
+
if (!commandFactory) {
|
|
127
|
+
console.warn(`No command constructor: ${toInsert[key]}`);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const command = commandFactory();
|
|
131
|
+
const keyBinding = keyBindings.get(key);
|
|
132
|
+
if (keyBinding) {
|
|
133
|
+
keyBindings.set(key, chainCommands(keyBinding, command));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
keyBindings.set(key, command);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
let converters = {};
|
|
141
|
+
for (const extension of this.extensions) {
|
|
142
|
+
if (extension.type === 'node') {
|
|
143
|
+
const nodeType = this.schema.nodes[extension.name];
|
|
144
|
+
inputRules.push(...extension.getInputRules(nodeType));
|
|
145
|
+
plugins.push(...extension.getProseMirrorPlugins(this.editor, this.schema));
|
|
146
|
+
mergeCommands(extension.getCommandFactories(this.editor, nodeType), extension.name);
|
|
147
|
+
mergeShortcuts(extension.getKeyboardShortcuts(this.editor), extension.name);
|
|
148
|
+
converters = {
|
|
149
|
+
...converters,
|
|
150
|
+
...extension.getConverters(this.editor, this.schema),
|
|
151
|
+
};
|
|
152
|
+
const nodeView = extension.getNodeView();
|
|
153
|
+
if (nodeView) {
|
|
154
|
+
this.nodeViews[extension.name] = nodeView;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (extension.type === 'mark') {
|
|
158
|
+
const markType = this.schema.marks[extension.name];
|
|
159
|
+
inputRules.push(...extension.getInputRules(markType));
|
|
160
|
+
mergeCommands(extension.getCommandFactories(this.editor, markType), extension.name);
|
|
161
|
+
mergeShortcuts(extension.getKeyboardShortcuts(this.editor), extension.name);
|
|
162
|
+
}
|
|
163
|
+
if (extension.type === 'extension') {
|
|
164
|
+
plugins.push(...extension.getProseMirrorPlugins(this.editor, this.schema));
|
|
165
|
+
mergeCommands(extension.getCommandFactories(this.editor), extension.name);
|
|
166
|
+
mergeShortcuts(extension.getKeyboardShortcuts(this.editor), extension.name);
|
|
167
|
+
converters = {
|
|
168
|
+
...converters,
|
|
169
|
+
...extension.getConverters(this.editor, this.schema),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (this.debug) {
|
|
174
|
+
for (const key in keyBindings) {
|
|
175
|
+
const keyBinding = keyBindings.get(key);
|
|
176
|
+
if (!keyBinding) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const wrapperCommand = (state, dispatch, view) => {
|
|
180
|
+
console.debug(`Key: ${key}`);
|
|
181
|
+
return true;
|
|
182
|
+
};
|
|
183
|
+
keyBindings.set(key, chainCommands(wrapperCommand, keyBinding));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
this.converters = converters;
|
|
187
|
+
plugins.push(new InputRulesPlugin(inputRules));
|
|
188
|
+
plugins.push(new KeymapPlugin(Object.fromEntries(keyBindings)));
|
|
189
|
+
return plugins;
|
|
190
|
+
}
|
|
191
|
+
setupExtensions(extensions) {
|
|
192
|
+
const allExtensions = new Map();
|
|
193
|
+
const createMap = (extensions) => {
|
|
194
|
+
for (const extension of extensions) {
|
|
195
|
+
if ('name' in extension) {
|
|
196
|
+
allExtensions.set(extension.name, extension);
|
|
197
|
+
}
|
|
198
|
+
if ('requires' in extension) {
|
|
199
|
+
const childExtensions = Array.from(extension.requires).filter((e) => typeof e !== 'string');
|
|
200
|
+
createMap(new Set(childExtensions));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
createMap(extensions);
|
|
205
|
+
const initialized = new Set();
|
|
206
|
+
const initializeExtension = (extension) => {
|
|
207
|
+
console.info(`Initialize ${extension.type} ${extension.name}`);
|
|
208
|
+
this.extensions.add(extension);
|
|
209
|
+
};
|
|
210
|
+
function recursiveInitializeExtension(extension) {
|
|
211
|
+
if ('name' in extension && initialized.has(extension.name)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if ('requires' in extension) {
|
|
215
|
+
const requires = extension.requires || [];
|
|
216
|
+
const requireNames = requires.map((e) => typeof e === 'string' ? e : ('name' in e ? e.name : ''));
|
|
217
|
+
for (const require of requireNames) {
|
|
218
|
+
if (!initialized.has(require)) {
|
|
219
|
+
const requiredExtension = allExtensions.get(require);
|
|
220
|
+
if (!requiredExtension) {
|
|
221
|
+
throw new Error('Required extension not found: ' + require);
|
|
222
|
+
}
|
|
223
|
+
recursiveInitializeExtension(requiredExtension);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if ('name' in extension) {
|
|
228
|
+
initializeExtension(extension);
|
|
229
|
+
initialized.add(extension.name);
|
|
230
|
+
allExtensions.delete(extension.name);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
for (const extension of allExtensions.values()) {
|
|
234
|
+
recursiveInitializeExtension(extension);
|
|
235
|
+
}
|
|
236
|
+
if (allExtensions.size > 0) {
|
|
237
|
+
throw new Error('Not all extensions initialized: ' +
|
|
238
|
+
Array.from(allExtensions.keys()).join(', '));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
getSchemaByResolvedExtensions(editor) {
|
|
242
|
+
const { nodeExtensions, markExtensions, baseExtensions } = splitExtensions(this.extensions);
|
|
243
|
+
const nodes = {};
|
|
244
|
+
for (const extension of nodeExtensions) {
|
|
245
|
+
nodes[extension.name] = extension.getNodeSpec();
|
|
246
|
+
addAttributesToSchema(nodes[extension.name], extension);
|
|
247
|
+
}
|
|
248
|
+
const marks = {};
|
|
249
|
+
for (const extension of markExtensions) {
|
|
250
|
+
marks[extension.name] = extension.getMarkSpec();
|
|
251
|
+
addAttributesToSchema(marks[extension.name], extension);
|
|
252
|
+
}
|
|
253
|
+
const spec = {
|
|
254
|
+
topNode: this.editor.options.topNode || 'doc',
|
|
255
|
+
nodes,
|
|
256
|
+
marks,
|
|
257
|
+
};
|
|
258
|
+
for (const extension of baseExtensions) {
|
|
259
|
+
if ('setupSpec' in baseExtensions) {
|
|
260
|
+
extension.setupSpec(spec);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const event = new CustomEvent('schema:spec', {
|
|
264
|
+
detail: {
|
|
265
|
+
editor,
|
|
266
|
+
spec,
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
editor.dispatchEvent(event);
|
|
270
|
+
return new Schema(spec);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MarkSpec, MarkType } from 'prosemirror-model';
|
|
2
|
+
import type { InputRule } from './plugins/input-rules/InputRulesPlugin.js';
|
|
3
|
+
import type { CoreEditor } from './CoreEditor.js';
|
|
4
|
+
import type { CommandFactories, CommandShortcuts } from './commands/mod.js';
|
|
5
|
+
import { Attribute } from './types.js';
|
|
6
|
+
export interface MarkConfig {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class Mark {
|
|
10
|
+
protected config: Partial<MarkConfig>;
|
|
11
|
+
readonly type = "mark";
|
|
12
|
+
name: string;
|
|
13
|
+
readonly attributes: Record<string, Attribute<any>>;
|
|
14
|
+
constructor(config?: Partial<MarkConfig>);
|
|
15
|
+
getMarkSpec(): MarkSpec;
|
|
16
|
+
getInputRules(type: MarkType): InputRule[];
|
|
17
|
+
getCommandFactories(editor: CoreEditor, type: MarkType): Partial<CommandFactories>;
|
|
18
|
+
getKeyboardShortcuts(editor: CoreEditor): Partial<CommandShortcuts>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=Mark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mark.d.ts","sourceRoot":"","sources":["../../../src/editor/src/Mark.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,WAAW,UAAU;IAEzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,8BAAsB,IAAI;IAML,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC;IALxD,QAAQ,CAAC,IAAI,UAAU;IACvB,IAAI,EAAE,MAAM,CAAU;IAEtB,SAAgB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAM;gBAEnC,MAAM,GAAE,OAAO,CAAC,UAAU,CAAM;IAE7D,WAAW,IAAI,QAAQ;IAIvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAI1C,mBAAmB,CACjB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,CAAC;IAI5B,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAGpE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class Mark {
|
|
2
|
+
constructor(config = {}) {
|
|
3
|
+
Object.defineProperty(this, "config", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: config
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "type", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: 'mark'
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "name", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: 'node'
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "attributes", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: {}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getMarkSpec() {
|
|
29
|
+
throw new Error('MarkSpec not defined: ' + this.name);
|
|
30
|
+
}
|
|
31
|
+
getInputRules(type) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
getCommandFactories(editor, type) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
getKeyboardShortcuts(editor) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NodeSpec, NodeType, Schema } from 'prosemirror-model';
|
|
2
|
+
import type { NodeViewConstructor } from 'prosemirror-view';
|
|
3
|
+
import type { Plugin } from 'prosemirror-state';
|
|
4
|
+
import type { InputRule } from './plugins/input-rules/InputRulesPlugin.js';
|
|
5
|
+
import type { CoreEditor } from './CoreEditor.js';
|
|
6
|
+
import type { Command, CommandShortcuts } from './commands/mod.js';
|
|
7
|
+
import type { Converter } from './Extension.js';
|
|
8
|
+
import { Attribute } from './types.js';
|
|
9
|
+
export interface NodeConfig {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface CommandFactories {
|
|
13
|
+
[key: string]: () => Command;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class Node {
|
|
16
|
+
protected config: Partial<NodeConfig>;
|
|
17
|
+
readonly type = "node";
|
|
18
|
+
name: string;
|
|
19
|
+
readonly attributes: Record<string, Attribute<any>>;
|
|
20
|
+
constructor(config?: Partial<NodeConfig>);
|
|
21
|
+
getNodeSpec(): NodeSpec;
|
|
22
|
+
getInputRules(type: NodeType): InputRule[];
|
|
23
|
+
getProseMirrorPlugins(editor: CoreEditor, schema: Schema): Plugin[];
|
|
24
|
+
getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
|
|
25
|
+
getKeyboardShortcuts(editor: CoreEditor): Partial<CommandShortcuts>;
|
|
26
|
+
getNodeView(): NodeViewConstructor | undefined;
|
|
27
|
+
getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=Node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Node.d.ts","sourceRoot":"","sources":["../../../src/editor/src/Node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM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|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: config
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "type", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: 'node'
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "name", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: 'node'
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "attributes", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: {}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getNodeSpec() {
|
|
29
|
+
throw new Error('NodeSpec not defined: ' + this.name);
|
|
30
|
+
}
|
|
31
|
+
getInputRules(type) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
getProseMirrorPlugins(editor, schema) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
getCommandFactories(editor, type) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
getKeyboardShortcuts(editor) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
getNodeView() {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
getConverters(editor, schema) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EditorState, Transaction } from 'prosemirror-state';
|
|
2
|
+
import { CoreEditor } from '../CoreEditor.js';
|
|
3
|
+
import { ChainedCommands, CommandFactory } from './mod.js';
|
|
4
|
+
export declare class CommandManager {
|
|
5
|
+
private editor;
|
|
6
|
+
private commandFactories;
|
|
7
|
+
constructor(editor: CoreEditor, commandFactories?: {
|
|
8
|
+
[key: string]: CommandFactory;
|
|
9
|
+
});
|
|
10
|
+
get state(): EditorState;
|
|
11
|
+
get chain(): () => ChainedCommands;
|
|
12
|
+
get can(): () => ChainedCommands;
|
|
13
|
+
createChain(startTr?: Transaction, shouldDispatch?: boolean): ChainedCommands;
|
|
14
|
+
createCan(startTr?: Transaction): ChainedCommands;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=CommandManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandManager.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/commands/CommandManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE3D,qBAAa,cAAc;IAEvB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,gBAAgB;gBADhB,MAAM,EAAE,UAAU,EAClB,gBAAgB,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;KAAO;IAIlE,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,IAAI,KAAK,IAAI,MAAM,eAAe,CAEjC;IAED,IAAI,GAAG,IAAI,MAAM,eAAe,CAE/B;IAEM,WAAW,CAChB,OAAO,CAAC,EAAE,WAAW,EACrB,cAAc,UAAO,GACpB,eAAe;IA4CX,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,eAAe;CAGzD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createChainableState } from './createChainableState.js';
|
|
2
|
+
export class CommandManager {
|
|
3
|
+
constructor(editor, commandFactories = {}) {
|
|
4
|
+
Object.defineProperty(this, "editor", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: editor
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(this, "commandFactories", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: commandFactories
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
get state() {
|
|
18
|
+
return this.editor.state;
|
|
19
|
+
}
|
|
20
|
+
get chain() {
|
|
21
|
+
return () => this.createChain();
|
|
22
|
+
}
|
|
23
|
+
get can() {
|
|
24
|
+
return () => this.createCan();
|
|
25
|
+
}
|
|
26
|
+
createChain(startTr, shouldDispatch = true) {
|
|
27
|
+
const { commandFactories, editor, state } = this;
|
|
28
|
+
const { view } = editor;
|
|
29
|
+
const callbacks = [];
|
|
30
|
+
const hasStartTransaction = !!startTr;
|
|
31
|
+
const tr = startTr || state.tr;
|
|
32
|
+
const chainedState = createChainableState(tr, state);
|
|
33
|
+
const fakeDispatch = () => undefined;
|
|
34
|
+
const chain = {
|
|
35
|
+
...Object.fromEntries(Object.entries(commandFactories).map(([name, commandFactory]) => {
|
|
36
|
+
const chainedCommand = (...args) => {
|
|
37
|
+
const command = commandFactory(...args);
|
|
38
|
+
const callback = command(chainedState, shouldDispatch ? fakeDispatch : undefined);
|
|
39
|
+
callbacks.push(callback);
|
|
40
|
+
return chain;
|
|
41
|
+
};
|
|
42
|
+
return [name, chainedCommand];
|
|
43
|
+
})),
|
|
44
|
+
run: () => {
|
|
45
|
+
if (!hasStartTransaction &&
|
|
46
|
+
shouldDispatch &&
|
|
47
|
+
!tr.getMeta('preventDispatch')) {
|
|
48
|
+
view.dispatch(tr);
|
|
49
|
+
}
|
|
50
|
+
return callbacks.every((callback) => callback === true);
|
|
51
|
+
},
|
|
52
|
+
chain: () => {
|
|
53
|
+
return this.createChain(tr, shouldDispatch);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
return chain;
|
|
57
|
+
}
|
|
58
|
+
createCan(startTr) {
|
|
59
|
+
return this.createChain(startTr, false);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createChainableState.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/commands/createChainableState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE7D,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,WAAW,GACjB,WAAW,CA8Bb"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function createChainableState(transaction, state) {
|
|
2
|
+
let { selection } = transaction;
|
|
3
|
+
let { doc } = transaction;
|
|
4
|
+
let { storedMarks } = transaction;
|
|
5
|
+
return {
|
|
6
|
+
...state,
|
|
7
|
+
apply: state.apply.bind(state),
|
|
8
|
+
applyTransaction: state.applyTransaction.bind(state),
|
|
9
|
+
plugins: state.plugins,
|
|
10
|
+
schema: state.schema,
|
|
11
|
+
reconfigure: state.reconfigure.bind(state),
|
|
12
|
+
toJSON: state.toJSON.bind(state),
|
|
13
|
+
get storedMarks() {
|
|
14
|
+
return storedMarks;
|
|
15
|
+
},
|
|
16
|
+
get selection() {
|
|
17
|
+
return selection;
|
|
18
|
+
},
|
|
19
|
+
get doc() {
|
|
20
|
+
return doc;
|
|
21
|
+
},
|
|
22
|
+
get tr() {
|
|
23
|
+
selection = transaction.selection;
|
|
24
|
+
doc = transaction.doc;
|
|
25
|
+
storedMarks = transaction.storedMarks;
|
|
26
|
+
return transaction;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Attrs, MarkType, Node, NodeRange, NodeType, ResolvedPos } from 'prosemirror-model';
|
|
2
|
+
import { Command, Transaction } from 'prosemirror-state';
|
|
3
|
+
export { type Command } from 'prosemirror-state';
|
|
4
|
+
export declare function wrapInList(listType: NodeType, attrs?: Attrs | null): Command;
|
|
5
|
+
export declare function wrapRangeInList(tr: Transaction | null, range: NodeRange, listType: NodeType, attrs?: Attrs | null): boolean;
|
|
6
|
+
export declare const deleteSelection: Command;
|
|
7
|
+
export declare const joinBackward: Command;
|
|
8
|
+
export declare const joinTextblockBackward: Command;
|
|
9
|
+
export declare const joinTextblockForward: Command;
|
|
10
|
+
export declare const selectNodeBackward: Command;
|
|
11
|
+
export declare const joinForward: Command;
|
|
12
|
+
export declare const selectNodeForward: Command;
|
|
13
|
+
export declare const joinUp: Command;
|
|
14
|
+
export declare const joinDown: Command;
|
|
15
|
+
export declare const lift: Command;
|
|
16
|
+
export declare const newlineInCode: Command;
|
|
17
|
+
export declare const exitCode: Command;
|
|
18
|
+
export declare const createParagraphNear: Command;
|
|
19
|
+
export declare const liftEmptyBlock: Command;
|
|
20
|
+
export declare function splitBlockAs(splitNode?: (node: Node, atEnd: boolean, $from: ResolvedPos) => {
|
|
21
|
+
type: NodeType;
|
|
22
|
+
attrs?: Attrs;
|
|
23
|
+
} | null): Command;
|
|
24
|
+
export declare const splitBlock: Command;
|
|
25
|
+
export declare const splitBlockKeepMarks: Command;
|
|
26
|
+
export declare const selectParentNode: Command;
|
|
27
|
+
export declare const selectAll: Command;
|
|
28
|
+
export declare const selectTextblockStart: Command;
|
|
29
|
+
export declare const selectTextblockEnd: Command;
|
|
30
|
+
export declare function wrapIn(nodeType: NodeType, attrs?: Attrs | null): Command;
|
|
31
|
+
export declare function setBlockType(nodeType: NodeType, attrs?: Attrs | null): Command;
|
|
32
|
+
export declare function toggleMark(markType: MarkType, attrs?: Attrs | null, options?: {
|
|
33
|
+
removeWhenPresent?: boolean;
|
|
34
|
+
enterInlineAtoms?: boolean;
|
|
35
|
+
includeWhitespace?: boolean;
|
|
36
|
+
}): Command;
|
|
37
|
+
export declare function autoJoin(command: Command, isJoinable: ((before: Node, after: Node) => boolean) | readonly string[]): Command;
|
|
38
|
+
export declare function chainCommands(...commands: readonly Command[]): Command;
|
|
39
|
+
export declare function alternativeCommands(...commands: readonly Command[]): Command;
|
|
40
|
+
export type CommandFactory = (...args: any[]) => Command;
|
|
41
|
+
export interface Commands {
|
|
42
|
+
[name: string]: Command;
|
|
43
|
+
}
|
|
44
|
+
export interface CommandFactories {
|
|
45
|
+
[name: string]: CommandFactory;
|
|
46
|
+
}
|
|
47
|
+
export type CommandShortcuts = {
|
|
48
|
+
[name: string]: string;
|
|
49
|
+
};
|
|
50
|
+
export type ChainedCommands = {
|
|
51
|
+
[Item in keyof Commands]: (...args: unknown[]) => ChainedCommands;
|
|
52
|
+
} & {
|
|
53
|
+
run: () => boolean;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/commands/mod.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,EAGL,QAAQ,EACR,IAAI,EACJ,SAAS,EAET,QAAQ,EACR,WAAW,EAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,OAAO,EAMP,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAMjD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,KAAK,GAAE,KAAK,GAAG,IAAW,GACzB,OAAO,CAUT;AAOD,wBAAgB,eAAe,CAC7B,EAAE,EAAE,WAAW,GAAG,IAAI,EACtB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,QAAQ,EAClB,KAAK,GAAE,KAAK,GAAG,IAAW,WA0B3B;AAmDD,eAAO,MAAM,eAAe,EAAE,OAI7B,CAAC;AAuBF,eAAO,MAAM,YAAY,EAAE,OAiE1B,CAAC;AAKF,eAAO,MAAM,qBAAqB,EAAE,OAKnC,CAAC;AAKF,eAAO,MAAM,oBAAoB,EAAE,OAKlC,CAAC;AAsDF,eAAO,MAAM,kBAAkB,EAAE,OAoBhC,CAAC;AAgCF,eAAO,MAAM,WAAW,EAAE,OAqDzB,CAAC;AAQF,eAAO,MAA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