@kerebron/extension-dev-toolkit 0.3.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.
Files changed (61) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +67 -0
  3. package/esm/editor/src/CoreEditor.d.ts +31 -0
  4. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  5. package/esm/editor/src/CoreEditor.js +200 -0
  6. package/esm/editor/src/DummyEditorView.d.ts +60 -0
  7. package/esm/editor/src/DummyEditorView.d.ts.map +1 -0
  8. package/esm/editor/src/DummyEditorView.js +277 -0
  9. package/esm/editor/src/Extension.d.ts +26 -0
  10. package/esm/editor/src/Extension.d.ts.map +1 -0
  11. package/esm/editor/src/Extension.js +33 -0
  12. package/esm/editor/src/ExtensionManager.d.ts +33 -0
  13. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  14. package/esm/editor/src/ExtensionManager.js +272 -0
  15. package/esm/editor/src/Mark.d.ts +20 -0
  16. package/esm/editor/src/Mark.d.ts.map +1 -0
  17. package/esm/editor/src/Mark.js +40 -0
  18. package/esm/editor/src/Node.d.ts +29 -0
  19. package/esm/editor/src/Node.d.ts.map +1 -0
  20. package/esm/editor/src/Node.js +49 -0
  21. package/esm/editor/src/commands/CommandManager.d.ts +16 -0
  22. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  23. package/esm/editor/src/commands/CommandManager.js +61 -0
  24. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  25. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  26. package/esm/editor/src/commands/createChainableState.js +29 -0
  27. package/esm/editor/src/commands/mod.d.ts +55 -0
  28. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  29. package/esm/editor/src/commands/mod.js +883 -0
  30. package/esm/editor/src/mod.d.ts +7 -0
  31. package/esm/editor/src/mod.d.ts.map +1 -0
  32. package/esm/editor/src/mod.js +6 -0
  33. package/esm/editor/src/nodeToTreeString.d.ts +10 -0
  34. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
  35. package/esm/editor/src/nodeToTreeString.js +74 -0
  36. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  37. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  38. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  39. package/esm/editor/src/plugins/keymap/keymap.d.ts +11 -0
  40. package/esm/editor/src/plugins/keymap/keymap.d.ts.map +1 -0
  41. package/esm/editor/src/plugins/keymap/keymap.js +125 -0
  42. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts +4 -0
  43. package/esm/editor/src/plugins/keymap/w3c-keyname.d.ts.map +1 -0
  44. package/esm/editor/src/plugins/keymap/w3c-keyname.js +124 -0
  45. package/esm/editor/src/types.d.ts +34 -0
  46. package/esm/editor/src/types.d.ts.map +1 -0
  47. package/esm/editor/src/types.js +1 -0
  48. package/esm/editor/src/utilities/SmartOutput.d.ts +39 -0
  49. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -0
  50. package/esm/editor/src/utilities/SmartOutput.js +213 -0
  51. package/esm/editor/src/utilities/createNodeFromContent.d.ts +9 -0
  52. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  53. package/esm/editor/src/utilities/createNodeFromContent.js +32 -0
  54. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +9 -0
  55. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  56. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  57. package/esm/extension-dev-toolkit/src/mod.d.ts +13 -0
  58. package/esm/extension-dev-toolkit/src/mod.d.ts.map +1 -0
  59. package/esm/extension-dev-toolkit/src/mod.js +50 -0
  60. package/esm/package.json +3 -0
  61. package/package.json +23 -0
@@ -0,0 +1,26 @@
1
+ import type { Plugin } from 'prosemirror-state';
2
+ import type { Node, Schema, SchemaSpec } from 'prosemirror-model';
3
+ import { type CoreEditor } from './CoreEditor.js';
4
+ import type { InputRule } from './plugins/input-rules/InputRulesPlugin.js';
5
+ import { CommandFactories, CommandShortcuts } from './commands/mod.js';
6
+ export interface ExtensionConfig {
7
+ [key: string]: any;
8
+ requires: Array<Extension | string>;
9
+ }
10
+ export interface Converter {
11
+ fromDoc(document: Node): Promise<Uint8Array>;
12
+ toDoc(content: Uint8Array): Promise<Node>;
13
+ }
14
+ export declare abstract class Extension {
15
+ protected config: Partial<ExtensionConfig>;
16
+ readonly type = "extension";
17
+ abstract name: string;
18
+ constructor(config?: Partial<ExtensionConfig>);
19
+ getInputRules(): InputRule[];
20
+ getProseMirrorPlugins(editor: CoreEditor, schema: Schema): Plugin[];
21
+ getCommandFactories(editor: CoreEditor): Partial<CommandFactories>;
22
+ getKeyboardShortcuts(editor: CoreEditor): Partial<CommandShortcuts>;
23
+ getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
24
+ setupSpec(spec: SchemaSpec): void;
25
+ }
26
+ //# sourceMappingURL=Extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Extension.d.ts","sourceRoot":"","sources":["../../../src/editor/src/Extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,MAAM,WAAW,eAAe;IAE9B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB,QAAQ,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7C,KAAK,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,8BAAsB,SAAS;IAIV,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC;IAH7D,QAAQ,CAAC,IAAI,eAAe;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEO,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM;IAGlE,aAAa,IAAI,SAAS,EAAE;IAI5B,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAInE,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIlE,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAInE,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAI5E,SAAS,CAAC,IAAI,EAAE,UAAU;CAE3B"}
@@ -0,0 +1,33 @@
1
+ export class Extension {
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: 'extension'
14
+ });
15
+ }
16
+ getInputRules() {
17
+ return [];
18
+ }
19
+ getProseMirrorPlugins(editor, schema) {
20
+ return [];
21
+ }
22
+ getCommandFactories(editor) {
23
+ return {};
24
+ }
25
+ getKeyboardShortcuts(editor) {
26
+ return {};
27
+ }
28
+ getConverters(editor, schema) {
29
+ return {};
30
+ }
31
+ setupSpec(spec) {
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ import { Plugin } from 'prosemirror-state';
3
+ import { NodeViewConstructor } from 'prosemirror-view';
4
+ import { Converter, Extension } from './Extension.js';
5
+ import { AnyExtension, AnyExtensionOrReq } from './types.js';
6
+ import { CoreEditor } from './CoreEditor.js';
7
+ import { Mark } from './Mark.js';
8
+ import { Node } from './Node.js';
9
+ import { CommandFactory } from './commands/mod.js';
10
+ export declare function findDuplicates(items: any[]): any[];
11
+ export declare function splitExtensions(extensions: Iterable<AnyExtension>): {
12
+ baseExtensions: Extension[];
13
+ nodeExtensions: Node[];
14
+ markExtensions: Mark[];
15
+ };
16
+ export declare class ExtensionManager {
17
+ private editor;
18
+ readonly schema: Schema;
19
+ private extensions;
20
+ readonly plugins: Plugin[];
21
+ readonly nodeViews: Record<string, NodeViewConstructor>;
22
+ readonly commandFactories: {
23
+ [key: string]: CommandFactory;
24
+ };
25
+ converters: Record<string, Converter>;
26
+ private debug;
27
+ constructor(extensions: AnyExtensionOrReq[], editor: CoreEditor);
28
+ getExtension<T extends Extension>(name: string): T | undefined;
29
+ private getPlugins;
30
+ private setupExtensions;
31
+ getSchemaByResolvedExtensions(editor: CoreEditor): Schema;
32
+ }
33
+ //# sourceMappingURL=ExtensionManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionManager.d.ts","sourceRoot":"","sources":["../../../src/editor/src/ExtensionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,OAAO,EAGL,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAK3B,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAIlD;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC;;;;EAgBjE;AAED,qBAAa,gBAAgB;IAYkB,OAAO,CAAC,MAAM;IAX3D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,UAAU,CAAgC;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAM;IAE7D,QAAQ,CAAC,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;KAAE,CAAM;IAC3D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAM;IAElD,OAAO,CAAC,KAAK,CAAQ;gBAET,UAAU,EAAE,iBAAiB,EAAE,EAAU,MAAM,EAAE,UAAU;IAcvE,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAY9D,OAAO,CAAC,UAAU;IAoJlB,OAAO,CAAC,eAAe;IAoEvB,6BAA6B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;CAuC1D"}
@@ -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,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,WAAW,UAAU;IAEzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC;CAC9B;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,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAInE,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;IAInE,WAAW,IAAI,mBAAmB,GAAG,SAAS;IAI9C,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CAG7E"}
@@ -0,0 +1,49 @@
1
+ export class Node {
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: '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,3 @@
1
+ import { EditorState, Transaction } from 'prosemirror-state';
2
+ export declare function createChainableState(transaction: Transaction, state: EditorState): EditorState;
3
+ //# sourceMappingURL=createChainableState.d.ts.map
@@ -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
+ }