@kerebron/extension-menu 0.0.6 → 0.0.7

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 (60) hide show
  1. package/esm/editor/src/CoreEditor.d.ts +28 -0
  2. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  3. package/esm/editor/src/CoreEditor.js +170 -0
  4. package/esm/editor/src/Extension.d.ts +26 -0
  5. package/esm/editor/src/Extension.d.ts.map +1 -0
  6. package/esm/editor/src/Extension.js +33 -0
  7. package/esm/editor/src/ExtensionManager.d.ts +32 -0
  8. package/esm/editor/src/ExtensionManager.d.ts.map +1 -0
  9. package/esm/editor/src/ExtensionManager.js +253 -0
  10. package/esm/editor/src/Mark.d.ts +18 -0
  11. package/esm/editor/src/Mark.d.ts.map +1 -0
  12. package/esm/editor/src/Mark.js +34 -0
  13. package/esm/editor/src/Node.d.ts +27 -0
  14. package/esm/editor/src/Node.d.ts.map +1 -0
  15. package/esm/editor/src/Node.js +43 -0
  16. package/esm/editor/src/commands/CommandManager.d.ts +20 -0
  17. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -0
  18. package/esm/editor/src/commands/CommandManager.js +60 -0
  19. package/esm/editor/src/commands/createChainableState.d.ts +3 -0
  20. package/esm/editor/src/commands/createChainableState.d.ts.map +1 -0
  21. package/esm/editor/src/commands/createChainableState.js +29 -0
  22. package/esm/editor/src/commands/mod.d.ts +49 -0
  23. package/esm/editor/src/commands/mod.d.ts.map +1 -0
  24. package/esm/editor/src/commands/mod.js +928 -0
  25. package/esm/editor/src/mod.d.ts +5 -0
  26. package/esm/editor/src/mod.d.ts.map +1 -0
  27. package/esm/editor/src/mod.js +4 -0
  28. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  29. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  30. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  31. package/esm/editor/src/types.d.ts +29 -0
  32. package/esm/editor/src/types.d.ts.map +1 -0
  33. package/esm/editor/src/types.js +1 -0
  34. package/esm/editor/src/utilities/createNodeFromContent.d.ts +12 -0
  35. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  36. package/esm/editor/src/utilities/createNodeFromContent.js +118 -0
  37. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +4 -0
  38. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  39. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  40. package/esm/{ExtensionMenu.d.ts → extension-menu/src/ExtensionMenu.d.ts} +1 -1
  41. package/esm/extension-menu/src/ExtensionMenu.d.ts.map +1 -0
  42. package/esm/{ExtensionMenu.js → extension-menu/src/ExtensionMenu.js} +2 -2
  43. package/esm/extension-menu/src/MenuPlugin.d.ts.map +1 -0
  44. package/esm/{MenuPlugin.js → extension-menu/src/MenuPlugin.js} +1 -1
  45. package/esm/extension-menu/src/icons.d.ts.map +1 -0
  46. package/esm/extension-menu/src/menu.d.ts.map +1 -0
  47. package/esm/{menu.js → extension-menu/src/menu.js} +2 -2
  48. package/esm/extension-menu/src/prompt.d.ts.map +1 -0
  49. package/package.json +6 -3
  50. package/esm/ExtensionMenu.d.ts.map +0 -1
  51. package/esm/MenuPlugin.d.ts.map +0 -1
  52. package/esm/icons.d.ts.map +0 -1
  53. package/esm/menu.d.ts.map +0 -1
  54. package/esm/prompt.d.ts.map +0 -1
  55. /package/esm/{MenuPlugin.d.ts → extension-menu/src/MenuPlugin.d.ts} +0 -0
  56. /package/esm/{icons.d.ts → extension-menu/src/icons.d.ts} +0 -0
  57. /package/esm/{icons.js → extension-menu/src/icons.js} +0 -0
  58. /package/esm/{menu.d.ts → extension-menu/src/menu.d.ts} +0 -0
  59. /package/esm/{prompt.d.ts → extension-menu/src/prompt.d.ts} +0 -0
  60. /package/esm/{prompt.js → extension-menu/src/prompt.js} +0 -0
@@ -0,0 +1,28 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { Fragment, Node as ProseMirrorNode, type Schema } from 'prosemirror-model';
3
+ import type { EditorOptions, JSONContent } from './types.js';
4
+ import { EditorState } from 'prosemirror-state';
5
+ import { ChainedCommands } from './commands/CommandManager.js';
6
+ export declare function getHTMLFromFragment(fragment: Fragment, schema: Schema): string;
7
+ export declare class CoreEditor extends EventTarget {
8
+ readonly options: Partial<EditorOptions>;
9
+ private extensionManager;
10
+ private commandManager;
11
+ view: EditorView;
12
+ state: EditorState;
13
+ constructor(options?: Partial<EditorOptions>);
14
+ get schema(): Schema<any, any>;
15
+ chain(): ChainedCommands;
16
+ can(): ChainedCommands;
17
+ private createView;
18
+ private dispatchTransaction;
19
+ private setupPlugins;
20
+ getJSON(): JSONContent;
21
+ /**
22
+ * Get the document as HTML.
23
+ */
24
+ getHTML(): string;
25
+ setDocument(content?: any, mediaType?: string): void;
26
+ getDocument(mediaType?: string): void | ProseMirrorNode;
27
+ }
28
+ //# sourceMappingURL=CoreEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreEditor.d.ts","sourceRoot":"","sources":["../../../src/editor/src/CoreEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEL,QAAQ,EACR,IAAI,IAAI,eAAe,EAEvB,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAW,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAkB,MAAM,8BAA8B,CAAC;AAE/E,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAWR;AAeD,qBAAa,UAAW,SAAQ,WAAW;IACzC,SAAgB,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAG7C;IACF,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,cAAc,CAAiB;IAChC,IAAI,EAAG,UAAU,CAAC;IAClB,KAAK,EAAG,WAAW,CAAA;gBAEd,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM;IA0BhD,IAAW,MAAM,qBAEhB;IAEM,KAAK,IAAI,eAAe;IAIxB,GAAG,IAAI,eAAe;IAI7B,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,YAAY;IAcb,OAAO,IAAI,WAAW;IAI7B;;OAEG;IACI,OAAO,IAAI,MAAM;IAIjB,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM;IA4C7C,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM;CAUtC"}
@@ -0,0 +1,170 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { DOMSerializer, } from 'prosemirror-model';
3
+ import { ExtensionManager } from './ExtensionManager.js';
4
+ import { EditorState } from 'prosemirror-state';
5
+ import { createNodeFromContent } from './utilities/createNodeFromContent.js';
6
+ import { CommandManager } from './commands/CommandManager.js';
7
+ export function getHTMLFromFragment(fragment, schema) {
8
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
9
+ const temporaryDocument = document.implementation.createHTMLDocument();
10
+ const container = temporaryDocument.createElement('div');
11
+ container.appendChild(documentFragment);
12
+ return container.innerHTML;
13
+ }
14
+ function createDocument(content, schema, parseOptions = {}, options = {}) {
15
+ return createNodeFromContent(content, schema, {
16
+ slice: false,
17
+ parseOptions,
18
+ errorOnInvalidContent: options.errorOnInvalidContent,
19
+ });
20
+ }
21
+ export class CoreEditor extends EventTarget {
22
+ constructor(options = {}) {
23
+ super();
24
+ Object.defineProperty(this, "options", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: {
29
+ element: null, // document.createElement('div'),
30
+ extensions: [],
31
+ }
32
+ });
33
+ Object.defineProperty(this, "extensionManager", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "commandManager", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "view", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "state", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ this.options = {
58
+ ...this.options,
59
+ ...options,
60
+ };
61
+ this.extensionManager = new ExtensionManager(this.options.extensions, this);
62
+ // const content = this.options.content ? this.options.content : {
63
+ // type: this.extensionManager.schema.topNodeType.name,
64
+ // content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC,
65
+ // };
66
+ const content = this.options.content
67
+ ? this.options.content
68
+ : this.extensionManager.schema.topNodeType.spec.EMPTY_DOC;
69
+ this.createView(structuredClone(content));
70
+ // this.createView('');
71
+ this.commandManager = new CommandManager(this, this.extensionManager.commandConstructors);
72
+ this.setupPlugins();
73
+ }
74
+ get schema() {
75
+ return this.extensionManager.schema;
76
+ }
77
+ chain() {
78
+ return this.commandManager.chain();
79
+ }
80
+ can() {
81
+ return this.commandManager.can();
82
+ }
83
+ createView(content) {
84
+ let doc = createDocument(content, this.schema, this.options.parseOptions, { errorOnInvalidContent: false });
85
+ this.state = EditorState.create({ doc });
86
+ if (this.options.element) {
87
+ this.view = new EditorView(this.options.element, {
88
+ state: this.state,
89
+ dispatchTransaction: (tx) => this.dispatchTransaction(tx),
90
+ });
91
+ }
92
+ }
93
+ dispatchTransaction(transaction) {
94
+ this.state = this.state.apply(transaction);
95
+ if (this.view) {
96
+ this.view.updateState(this.state);
97
+ const event = new CustomEvent('transaction', {
98
+ detail: {
99
+ editor: this,
100
+ transaction,
101
+ },
102
+ });
103
+ this.dispatchEvent(event);
104
+ }
105
+ }
106
+ setupPlugins() {
107
+ this.state = this.state.reconfigure({
108
+ plugins: this.extensionManager.plugins,
109
+ });
110
+ if (this.view) {
111
+ this.view.updateState(this.state);
112
+ this.view.setProps({
113
+ nodeViews: this.extensionManager.nodeViews,
114
+ });
115
+ }
116
+ }
117
+ getJSON() {
118
+ return this.state.doc.toJSON();
119
+ }
120
+ /**
121
+ * Get the document as HTML.
122
+ */
123
+ getHTML() {
124
+ return getHTMLFromFragment(this.state.doc.content, this.schema);
125
+ }
126
+ setDocument(content, mediaType) {
127
+ if (!content) { // clear
128
+ content = {
129
+ type: this.extensionManager.schema.topNodeType.name,
130
+ content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC.content,
131
+ // content: this.extensionManager.schema.topNodeType.createAndFill(),
132
+ };
133
+ mediaType = undefined;
134
+ }
135
+ let doc;
136
+ if (mediaType) {
137
+ const converter = this.extensionManager.converters[mediaType];
138
+ if (converter) {
139
+ doc = converter.toDoc(content);
140
+ }
141
+ }
142
+ else {
143
+ doc = createDocument(content, this.schema, this.options.parseOptions, { errorOnInvalidContent: false });
144
+ }
145
+ this.state = EditorState.create({
146
+ doc,
147
+ plugins: this.state.plugins,
148
+ storedMarks: this.state.storedMarks,
149
+ });
150
+ if (this.view) {
151
+ this.view.updateState(this.state);
152
+ }
153
+ const event = new CustomEvent('doc:loaded', {
154
+ detail: {
155
+ editor: this,
156
+ doc,
157
+ },
158
+ });
159
+ this.dispatchEvent(event);
160
+ }
161
+ getDocument(mediaType) {
162
+ if (mediaType) {
163
+ const converter = this.extensionManager.converters[mediaType];
164
+ if (converter) {
165
+ return converter.fromDoc(this.state.doc);
166
+ }
167
+ }
168
+ return this.state.doc;
169
+ }
170
+ }
@@ -0,0 +1,26 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import { type CoreEditor } from './CoreEditor.js';
3
+ import { InputRule } from './plugins/input-rules/InputRulesPlugin.js';
4
+ import { Commands, CommandShortcuts } from './commands/mod.js';
5
+ import { Schema, type SchemaSpec } from 'prosemirror-model';
6
+ export interface ExtensionConfig {
7
+ [key: string]: any;
8
+ requires: Array<Extension | string>;
9
+ }
10
+ export interface Converter {
11
+ fromDoc(document: unknown): void;
12
+ toDoc(content: unknown): any;
13
+ }
14
+ export declare abstract class Extension {
15
+ protected config: Partial<ExtensionConfig>;
16
+ readonly type = "extension";
17
+ abstract name: string;
18
+ protected constructor(config?: Partial<ExtensionConfig>);
19
+ getInputRules(): InputRule[];
20
+ getProseMirrorPlugins(editor: CoreEditor, schema: Schema): Plugin[];
21
+ getCommands(editor: CoreEditor): Partial<Commands>;
22
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
23
+ getConverters(): 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,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,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,OAAO,GAAG,IAAI,CAAC;IACjC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG,CAAC;CAC9B;AAED,8BAAsB,SAAS;IAIP,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC;IAHhE,QAAQ,CAAC,IAAI,eAAe;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,SAAS,aAAuB,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM;IAGrE,aAAa,IAAI,SAAS,EAAE;IAI5B,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAInE,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIlD,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIjD,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAI1C,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
+ getCommands(editor) {
23
+ return {};
24
+ }
25
+ getKeyboardShortcuts() {
26
+ return {};
27
+ }
28
+ getConverters() {
29
+ return {};
30
+ }
31
+ setupSpec(spec) {
32
+ }
33
+ }
@@ -0,0 +1,32 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ import { Plugin } from 'prosemirror-state';
3
+ import { NodeViewConstructor } from 'prosemirror-view';
4
+ import { Extension } from './Extension.js';
5
+ import { AnyExtension } from './types.js';
6
+ import { CoreEditor } from './CoreEditor.js';
7
+ import { Mark } from './Mark.js';
8
+ import { Node } from './Node.js';
9
+ import { type Command } from 'prosemirror-state';
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 commandConstructors: {
23
+ [key: string]: () => Command;
24
+ };
25
+ private converters;
26
+ private debug;
27
+ constructor(extensions: Set<AnyExtension>, editor: CoreEditor);
28
+ private getPlugins;
29
+ private setupExtensions;
30
+ getSchemaByResolvedExtensions(editor: CoreEditor): Schema;
31
+ }
32
+ //# 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;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAa,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,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,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD,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;IAYgB,OAAO,CAAC,MAAM;IAXzD,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,mBAAmB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,OAAO,CAAA;KAAE,CAAM;IACpE,OAAO,CAAC,UAAU,CAAiC;IAEnD,OAAO,CAAC,KAAK,CAAQ;gBAET,UAAU,EAAE,GAAG,CAAC,YAAY,CAAC,EAAU,MAAM,EAAE,UAAU;IAcrE,OAAO,CAAC,UAAU;IAkIlB,OAAO,CAAC,eAAe;IA6DvB,6BAA6B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;CA6C1D"}
@@ -0,0 +1,253 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ import { keymap } from 'prosemirror-keymap';
3
+ import { InputRulesPlugin, } from './plugins/input-rules/InputRulesPlugin.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, "commandConstructors", {
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(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
+ getPlugins() {
82
+ const plugins = [];
83
+ const inputRules = [];
84
+ const commands = new Map();
85
+ const keyBindings = new Map();
86
+ const mergeCommands = (toInsert, extName) => {
87
+ for (const key in toInsert) {
88
+ const commandConstructor = toInsert[key];
89
+ if (this.debug) {
90
+ const wrappedConstructor = () => {
91
+ const realCommand = commandConstructor();
92
+ const command = (state, dispatch, view) => {
93
+ if (dispatch) {
94
+ console.debug(`Command: ${extName}.${key}`);
95
+ }
96
+ return realCommand(state, dispatch, view);
97
+ };
98
+ return command;
99
+ };
100
+ commands.set(key, wrappedConstructor);
101
+ this.commandConstructors[key] = wrappedConstructor;
102
+ }
103
+ else {
104
+ commands.set(key, commandConstructor);
105
+ this.commandConstructors[key] = commandConstructor;
106
+ }
107
+ }
108
+ };
109
+ function mergeShortcuts(toInsert, extName) {
110
+ for (const key in toInsert) {
111
+ const commandConstructor = commands.get(toInsert[key]);
112
+ if (!commandConstructor) {
113
+ console.warn(`No command constructor: ${toInsert[key]}`);
114
+ continue;
115
+ }
116
+ const command = commandConstructor();
117
+ const keyBinding = keyBindings.get(key);
118
+ if (keyBinding) {
119
+ keyBindings.set(key, chainCommands(keyBinding, command));
120
+ }
121
+ else {
122
+ keyBindings.set(key, command);
123
+ }
124
+ }
125
+ }
126
+ let converters = {};
127
+ for (const extension of this.extensions) {
128
+ if (extension.type === 'node') {
129
+ const nodeType = this.schema.nodes[extension.name];
130
+ inputRules.push(...extension.getInputRules(nodeType));
131
+ plugins.push(...extension.getProseMirrorPlugins(this.editor, this.schema));
132
+ mergeCommands(extension.getCommands(this.editor, nodeType), extension.name);
133
+ mergeShortcuts(extension.getKeyboardShortcuts(this.editor), extension.name);
134
+ converters = {
135
+ ...converters,
136
+ ...extension.getConverters(this.schema),
137
+ };
138
+ const nodeView = extension.getNodeView();
139
+ if (nodeView) {
140
+ this.nodeViews[extension.name] = nodeView;
141
+ }
142
+ }
143
+ if (extension.type === 'mark') {
144
+ const markType = this.schema.marks[extension.name];
145
+ inputRules.push(...extension.getInputRules(markType));
146
+ mergeCommands(extension.getCommands(this.editor, markType), extension.name);
147
+ mergeShortcuts(extension.getKeyboardShortcuts(this.editor), extension.name);
148
+ }
149
+ if (extension.type === 'extension') {
150
+ plugins.push(...extension.getProseMirrorPlugins(this.editor, this.schema));
151
+ mergeCommands(extension.getCommands(this.editor), extension.name);
152
+ mergeShortcuts(extension.getKeyboardShortcuts(this.editor), extension.name);
153
+ converters = {
154
+ ...converters,
155
+ ...extension.getConverters(this.schema),
156
+ };
157
+ }
158
+ }
159
+ if (this.debug) {
160
+ for (const key in keyBindings) {
161
+ const wrapperCommand = (state, dispatch, view) => {
162
+ console.debug(`Key: ${key}`);
163
+ return true;
164
+ };
165
+ keyBindings.set(key, chainCommands(wrapperCommand, keyBindings.get(key)));
166
+ }
167
+ }
168
+ this.converters = converters;
169
+ plugins.push(new InputRulesPlugin(inputRules));
170
+ plugins.push(keymap(Object.fromEntries(keyBindings)));
171
+ return plugins;
172
+ }
173
+ setupExtensions(extensions) {
174
+ const allExtensions = new Map();
175
+ const createMap = (extensions) => {
176
+ for (const extension of extensions) {
177
+ allExtensions.set(extension.name, extension);
178
+ if (extension.requires) {
179
+ const childExtensions = Array.from(extension.requires).filter((e) => typeof e !== 'string');
180
+ createMap(new Set(childExtensions));
181
+ }
182
+ }
183
+ };
184
+ createMap(extensions);
185
+ const initialized = new Set();
186
+ const initializeExtension = (extension) => {
187
+ console.info(`Initialize ${extension.type} ${extension.name}`);
188
+ this.extensions.add(extension);
189
+ };
190
+ function recursiveInitializeExtension(extension) {
191
+ if (initialized.has(extension.name)) {
192
+ return;
193
+ }
194
+ const requires = (extension.requires || []).map((e) => typeof e === 'string' ? e : e.name);
195
+ for (const require of requires) {
196
+ if (!initialized.has(require)) {
197
+ const requiredExtension = allExtensions.get(require);
198
+ if (!requiredExtension) {
199
+ throw new Error('Required extension not found: ' + require);
200
+ }
201
+ recursiveInitializeExtension(requiredExtension);
202
+ }
203
+ }
204
+ initializeExtension(extension);
205
+ initialized.add(extension.name);
206
+ allExtensions.delete(extension.name);
207
+ }
208
+ for (const extension of allExtensions.values()) {
209
+ recursiveInitializeExtension(extension);
210
+ }
211
+ if (allExtensions.size > 0) {
212
+ throw new Error('Not all extensions initialized: ' +
213
+ Array.from(allExtensions.keys()).join(', '));
214
+ }
215
+ }
216
+ getSchemaByResolvedExtensions(editor) {
217
+ const { nodeExtensions, markExtensions, baseExtensions } = splitExtensions(this.extensions);
218
+ const nodes = {};
219
+ for (const extension of nodeExtensions) {
220
+ nodes[extension.name] = extension.getNodeSpec();
221
+ addAttributesToSchema(nodes[extension.name], extension);
222
+ if ('automerge' in extension) {
223
+ nodes[extension.name].automerge = extension.automerge;
224
+ }
225
+ }
226
+ const marks = {};
227
+ for (const extension of markExtensions) {
228
+ marks[extension.name] = extension.getMarkSpec();
229
+ addAttributesToSchema(marks[extension.name], extension);
230
+ if ('automerge' in extension) {
231
+ marks[extension.name].automerge = extension.automerge;
232
+ }
233
+ }
234
+ const spec = {
235
+ topNode: this.editor.options.topNode || 'doc',
236
+ nodes,
237
+ marks,
238
+ };
239
+ for (const extension of baseExtensions) {
240
+ if ('setupSpec' in baseExtensions) {
241
+ baseExtensions.setupSpec(spec);
242
+ }
243
+ }
244
+ const event = new CustomEvent('schema:spec', {
245
+ detail: {
246
+ editor,
247
+ spec,
248
+ },
249
+ });
250
+ editor.dispatchEvent(event);
251
+ return new Schema(spec);
252
+ }
253
+ }
@@ -0,0 +1,18 @@
1
+ import { MarkSpec, MarkType } from 'prosemirror-model';
2
+ import { InputRule } from './plugins/input-rules/InputRulesPlugin.js';
3
+ import { CoreEditor } from './CoreEditor.js';
4
+ import { Commands, CommandShortcuts } from './commands/mod.js';
5
+ export interface MarkConfig {
6
+ [key: string]: any;
7
+ }
8
+ export declare abstract class Mark {
9
+ protected config: Partial<MarkConfig>;
10
+ readonly type = "mark";
11
+ name: string;
12
+ constructor(config?: Partial<MarkConfig>);
13
+ getMarkSpec(): MarkSpec;
14
+ getInputRules(type: MarkType): InputRule[];
15
+ getCommands(editor: CoreEditor, type: MarkType): Partial<Commands>;
16
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
17
+ }
18
+ //# 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,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE/D,MAAM,WAAW,UAAU;IAEzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,8BAAsB,IAAI;IAIL,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC;IAHxD,QAAQ,CAAC,IAAI,UAAU;IACvB,IAAI,EAAE,MAAM,CAAU;gBAEO,MAAM,GAAE,OAAO,CAAC,UAAU,CAAM;IAE7D,WAAW,IAAI,QAAQ;IAIvB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,EAAE;IAI1C,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIlE,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAGlD"}
@@ -0,0 +1,34 @@
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
+ }
22
+ getMarkSpec() {
23
+ throw new Error('MarkSpec not defined: ' + this.name);
24
+ }
25
+ getInputRules(type) {
26
+ return [];
27
+ }
28
+ getCommands(editor, type) {
29
+ return {};
30
+ }
31
+ getKeyboardShortcuts() {
32
+ return {};
33
+ }
34
+ }
@@ -0,0 +1,27 @@
1
+ import { NodeSpec, NodeType } from 'prosemirror-model';
2
+ import { NodeViewConstructor } from 'prosemirror-view';
3
+ import { Plugin } from 'prosemirror-state';
4
+ import { InputRule } from './plugins/input-rules/InputRulesPlugin.js';
5
+ import { CoreEditor } from './CoreEditor.js';
6
+ import { Command, CommandShortcuts } from './commands/mod.js';
7
+ import { Converter } from './Extension.js';
8
+ export interface NodeConfig {
9
+ [key: string]: any;
10
+ }
11
+ export interface CommandConstructors {
12
+ [key: string]: () => Command;
13
+ }
14
+ export declare abstract class Node {
15
+ protected config: Partial<NodeConfig>;
16
+ readonly type = "node";
17
+ name: string;
18
+ constructor(config?: Partial<NodeConfig>);
19
+ getNodeSpec(): NodeSpec;
20
+ getInputRules(type: NodeType): InputRule[];
21
+ getProseMirrorPlugins(editor: CoreEditor): Plugin[];
22
+ getCommands(editor: CoreEditor, type: NodeType): Partial<CommandConstructors>;
23
+ getKeyboardShortcuts(): Partial<CommandShortcuts>;
24
+ getNodeView(): NodeViewConstructor | undefined;
25
+ getConverters(): Record<string, Converter>;
26
+ }
27
+ //# 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,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAY,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,WAAW,UAAU;IAEzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC;CAC9B;AAED,8BAAsB,IAAI;IAIL,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC;IAHxD,QAAQ,CAAC,IAAI,UAAU;IACvB,IAAI,EAAE,MAAM,CAAU;gBAEO,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,GAAG,MAAM,EAAE;IAInD,WAAW,CACT,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,mBAAmB,CAAC;IAI/B,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIjD,WAAW,IAAI,mBAAmB,GAAG,SAAS;IAI9C,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CAG3C"}