@kerebron/extension-tables 0.2.0 → 0.2.1

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 (110) hide show
  1. package/esm/editor/src/CoreEditor.d.ts +25 -0
  2. package/esm/editor/src/CoreEditor.d.ts.map +1 -0
  3. package/esm/editor/src/CoreEditor.js +197 -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 +6 -0
  26. package/esm/editor/src/mod.d.ts.map +1 -0
  27. package/esm/editor/src/mod.js +5 -0
  28. package/esm/editor/src/nodeToTreeString.d.ts +4 -0
  29. package/esm/editor/src/nodeToTreeString.d.ts.map +1 -0
  30. package/esm/editor/src/nodeToTreeString.js +56 -0
  31. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +23 -0
  32. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +1 -0
  33. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +163 -0
  34. package/esm/editor/src/plugins/input-rules/mod.d.ts +3 -0
  35. package/esm/editor/src/plugins/input-rules/mod.d.ts.map +1 -0
  36. package/esm/editor/src/plugins/input-rules/mod.js +2 -0
  37. package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts +5 -0
  38. package/esm/editor/src/plugins/input-rules/rulebuilders.d.ts.map +1 -0
  39. package/esm/editor/src/plugins/input-rules/rulebuilders.js +50 -0
  40. package/esm/editor/src/types.d.ts +29 -0
  41. package/esm/editor/src/types.d.ts.map +1 -0
  42. package/esm/editor/src/types.js +1 -0
  43. package/esm/editor/src/utilities/createNodeFromContent.d.ts +8 -0
  44. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +1 -0
  45. package/esm/editor/src/utilities/createNodeFromContent.js +33 -0
  46. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +4 -0
  47. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +1 -0
  48. package/esm/editor/src/utilities/getHtmlAttributes.js +47 -0
  49. package/esm/editor/src/utilities/mod.d.ts +3 -0
  50. package/esm/editor/src/utilities/mod.d.ts.map +1 -0
  51. package/esm/editor/src/utilities/mod.js +2 -0
  52. package/esm/extension-tables/src/ExtensionTables.d.ts +10 -0
  53. package/esm/extension-tables/src/ExtensionTables.d.ts.map +1 -0
  54. package/esm/extension-tables/src/ExtensionTables.js +27 -0
  55. package/esm/extension-tables/src/NodeTable.d.ts +24 -0
  56. package/esm/extension-tables/src/NodeTable.d.ts.map +1 -0
  57. package/esm/extension-tables/src/NodeTable.js +115 -0
  58. package/esm/extension-tables/src/NodeTableCell.d.ts +16 -0
  59. package/esm/extension-tables/src/NodeTableCell.d.ts.map +1 -0
  60. package/esm/extension-tables/src/NodeTableCell.js +77 -0
  61. package/esm/extension-tables/src/NodeTableHeader.d.ts +16 -0
  62. package/esm/extension-tables/src/NodeTableHeader.d.ts.map +1 -0
  63. package/esm/extension-tables/src/NodeTableHeader.js +75 -0
  64. package/esm/extension-tables/src/NodeTableRow.d.ts +16 -0
  65. package/esm/extension-tables/src/NodeTableRow.d.ts.map +1 -0
  66. package/esm/extension-tables/src/NodeTableRow.js +47 -0
  67. package/esm/extension-tables/src/utilities/CellSelection.d.ts +53 -0
  68. package/esm/extension-tables/src/utilities/CellSelection.d.ts.map +1 -0
  69. package/esm/extension-tables/src/utilities/CellSelection.js +382 -0
  70. package/esm/extension-tables/src/utilities/TableMap.d.ts +92 -0
  71. package/esm/extension-tables/src/utilities/TableMap.d.ts.map +1 -0
  72. package/esm/extension-tables/src/utilities/TableMap.js +335 -0
  73. package/esm/extension-tables/src/utilities/TableView.d.ts +21 -0
  74. package/esm/extension-tables/src/utilities/TableView.d.ts.map +1 -0
  75. package/esm/extension-tables/src/utilities/TableView.js +108 -0
  76. package/esm/extension-tables/src/utilities/columnResizing.d.ts +50 -0
  77. package/esm/extension-tables/src/utilities/columnResizing.d.ts.map +1 -0
  78. package/esm/extension-tables/src/utilities/columnResizing.js +306 -0
  79. package/esm/extension-tables/src/utilities/commands.d.ts +166 -0
  80. package/esm/extension-tables/src/utilities/commands.d.ts.map +1 -0
  81. package/esm/extension-tables/src/utilities/commands.js +702 -0
  82. package/esm/extension-tables/src/utilities/copypaste.d.ts +35 -0
  83. package/esm/extension-tables/src/utilities/copypaste.d.ts.map +1 -0
  84. package/esm/extension-tables/src/utilities/copypaste.js +283 -0
  85. package/esm/extension-tables/src/utilities/createCell.d.ts +3 -0
  86. package/esm/extension-tables/src/utilities/createCell.d.ts.map +1 -0
  87. package/esm/extension-tables/src/utilities/createCell.js +6 -0
  88. package/esm/extension-tables/src/utilities/createTable.d.ts +3 -0
  89. package/esm/extension-tables/src/utilities/createTable.d.ts.map +1 -0
  90. package/esm/extension-tables/src/utilities/createTable.js +30 -0
  91. package/esm/extension-tables/src/utilities/fixTables.d.ts +20 -0
  92. package/esm/extension-tables/src/utilities/fixTables.d.ts.map +1 -0
  93. package/esm/extension-tables/src/utilities/fixTables.js +146 -0
  94. package/esm/extension-tables/src/utilities/getTableNodeTypes.d.ts +5 -0
  95. package/esm/extension-tables/src/utilities/getTableNodeTypes.d.ts.map +1 -0
  96. package/esm/extension-tables/src/utilities/getTableNodeTypes.js +14 -0
  97. package/esm/extension-tables/src/utilities/input.d.ts +21 -0
  98. package/esm/extension-tables/src/utilities/input.d.ts.map +1 -0
  99. package/esm/extension-tables/src/utilities/input.js +241 -0
  100. package/esm/extension-tables/src/utilities/tableEditing.d.ts +23 -0
  101. package/esm/extension-tables/src/utilities/tableEditing.d.ts.map +1 -0
  102. package/esm/extension-tables/src/utilities/tableEditing.js +63 -0
  103. package/esm/extension-tables/src/utilities/tableNodeTypes.d.ts +14 -0
  104. package/esm/extension-tables/src/utilities/tableNodeTypes.d.ts.map +1 -0
  105. package/esm/extension-tables/src/utilities/tableNodeTypes.js +16 -0
  106. package/esm/extension-tables/src/utilities/util.d.ts +73 -0
  107. package/esm/extension-tables/src/utilities/util.d.ts.map +1 -0
  108. package/esm/extension-tables/src/utilities/util.js +155 -0
  109. package/esm/package.json +3 -0
  110. package/package.json +1 -4
@@ -0,0 +1,25 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { Node as ProseMirrorNode, type Schema } from 'prosemirror-model';
3
+ import type { EditorOptions, JSONContent } from './types.js';
4
+ import { EditorState, Transaction } from 'prosemirror-state';
5
+ import { ChainedCommands } from './commands/CommandManager.js';
6
+ export declare class CoreEditor extends EventTarget {
7
+ readonly options: Partial<EditorOptions>;
8
+ private extensionManager;
9
+ private commandManager;
10
+ view: EditorView;
11
+ state: EditorState;
12
+ constructor(options?: Partial<EditorOptions>);
13
+ get schema(): Schema<any, any>;
14
+ chain(): ChainedCommands;
15
+ can(): ChainedCommands;
16
+ private createView;
17
+ dispatchTransaction(transaction: Transaction): void;
18
+ private setupPlugins;
19
+ setDocument(content?: any, mediaType?: string): void;
20
+ getDocument(mediaType?: string): void | ProseMirrorNode | JSONContent;
21
+ getJSON(): JSONContent;
22
+ clone(options?: Partial<EditorOptions>): CoreEditor;
23
+ debug(doc?: ProseMirrorNode): void;
24
+ }
25
+ //# 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,EAAE,IAAI,IAAI,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAkB,MAAM,8BAA8B,CAAC;AAgC/E,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,CAAC;gBAEf,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM;IAyBhD,IAAW,MAAM,qBAEhB;IAEM,KAAK,IAAI,eAAe;IAIxB,GAAG,IAAI,eAAe;IAI7B,OAAO,CAAC,UAAU;IAgBX,mBAAmB,CAAC,WAAW,EAAE,WAAW;IAcnD,OAAO,CAAC,YAAY;IAcb,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM;IAwC7C,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM;IAkB9B,OAAO,IAAI,WAAW;IAItB,KAAK,CAAC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,UAAU;IAOvD,KAAK,CAAC,GAAG,CAAC,EAAE,eAAe;CAMnC"}
@@ -0,0 +1,197 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { Node as ProseMirrorNode } 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
+ import { nodeToTreeString } from './nodeToTreeString.js';
8
+ function ensureDocSchema(doc, schema) {
9
+ if (doc.type.schema != schema) {
10
+ const findNode = (nodeName) => {
11
+ if (!schema.nodes[nodeName]) {
12
+ throw new Error(`Not able to rewrite schema for node '${nodeName}'`);
13
+ }
14
+ return schema.nodes[nodeName];
15
+ };
16
+ const findMark = (markName) => {
17
+ if (!schema.marks[markName]) {
18
+ throw new Error(`Not able to rewrite schema for mark '${markName}'`);
19
+ }
20
+ return schema.marks[markName];
21
+ };
22
+ // TODO fix readonly warnings
23
+ doc.type = findNode(doc.type.name);
24
+ doc.marks.forEach((mark) => {
25
+ mark.type = findMark(mark.type.name);
26
+ });
27
+ doc.descendants((node) => {
28
+ node.type = findNode(node.type.name);
29
+ node.marks.forEach((mark) => {
30
+ mark.type = findMark(mark.type.name);
31
+ });
32
+ });
33
+ }
34
+ }
35
+ export class CoreEditor extends EventTarget {
36
+ constructor(options = {}) {
37
+ super();
38
+ Object.defineProperty(this, "options", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: {
43
+ element: null, // document.createElement('div'),
44
+ extensions: [],
45
+ }
46
+ });
47
+ Object.defineProperty(this, "extensionManager", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ Object.defineProperty(this, "commandManager", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ Object.defineProperty(this, "view", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ Object.defineProperty(this, "state", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
71
+ this.options = {
72
+ ...this.options,
73
+ ...options,
74
+ };
75
+ this.extensionManager = new ExtensionManager(this.options.extensions, this);
76
+ // const content = this.options.content ? this.options.content : {
77
+ // type: this.extensionManager.schema.topNodeType.name,
78
+ // content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC,
79
+ // };
80
+ const content = this.options.content
81
+ ? this.options.content
82
+ : this.extensionManager.schema.topNodeType.spec.EMPTY_DOC;
83
+ this.createView(content);
84
+ this.commandManager = new CommandManager(this, this.extensionManager.commandConstructors);
85
+ this.setupPlugins();
86
+ }
87
+ get schema() {
88
+ return this.extensionManager.schema;
89
+ }
90
+ chain() {
91
+ return this.commandManager.chain();
92
+ }
93
+ can() {
94
+ return this.commandManager.can();
95
+ }
96
+ createView(content) {
97
+ const doc = createNodeFromContent(content, this.schema);
98
+ this.state = EditorState.create({ doc });
99
+ if (this.options.element) {
100
+ this.view = new EditorView(this.options.element, {
101
+ state: this.state,
102
+ attributes: {
103
+ class: 'kb-editor',
104
+ },
105
+ dispatchTransaction: (tx) => this.dispatchTransaction(tx),
106
+ });
107
+ }
108
+ }
109
+ dispatchTransaction(transaction) {
110
+ this.state = this.state.apply(transaction);
111
+ if (this.view) {
112
+ this.view.updateState(this.state);
113
+ const event = new CustomEvent('transaction', {
114
+ detail: {
115
+ editor: this,
116
+ transaction,
117
+ },
118
+ });
119
+ this.dispatchEvent(event);
120
+ }
121
+ }
122
+ setupPlugins() {
123
+ this.state = this.state.reconfigure({
124
+ plugins: this.extensionManager.plugins,
125
+ });
126
+ if (this.view) {
127
+ this.view.updateState(this.state);
128
+ this.view.setProps({
129
+ nodeViews: this.extensionManager.nodeViews,
130
+ });
131
+ }
132
+ }
133
+ setDocument(content, mediaType) {
134
+ if (!content) {
135
+ content = {
136
+ type: this.extensionManager.schema.topNodeType.name,
137
+ content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC.content,
138
+ };
139
+ mediaType = undefined;
140
+ }
141
+ let doc;
142
+ if (mediaType) {
143
+ const converter = this.extensionManager.converters[mediaType];
144
+ if (converter) {
145
+ doc = converter.toDoc(content);
146
+ }
147
+ }
148
+ else {
149
+ doc = createNodeFromContent(content, this.schema);
150
+ }
151
+ ensureDocSchema(doc, this.schema);
152
+ this.state = EditorState.create({
153
+ doc,
154
+ plugins: this.state.plugins,
155
+ storedMarks: this.state.storedMarks,
156
+ });
157
+ if (this.view) {
158
+ this.view.updateState(this.state);
159
+ }
160
+ const event = new CustomEvent('doc:loaded', {
161
+ detail: {
162
+ editor: this,
163
+ doc,
164
+ },
165
+ });
166
+ this.dispatchEvent(event);
167
+ }
168
+ getDocument(mediaType) {
169
+ if (mediaType) {
170
+ const converter = this.extensionManager.converters[mediaType];
171
+ if (converter) {
172
+ const json = this.state.doc.toJSON();
173
+ const clonedDoc = ProseMirrorNode.fromJSON(this.state.schema, json);
174
+ return converter.fromDoc(clonedDoc);
175
+ }
176
+ if (mediaType === 'text/json') {
177
+ return this.getJSON();
178
+ }
179
+ }
180
+ return this.state.doc;
181
+ }
182
+ getJSON() {
183
+ return this.state.doc.toJSON();
184
+ }
185
+ clone(options = {}) {
186
+ return new CoreEditor({
187
+ ...options,
188
+ extensions: [...this.options.extensions],
189
+ });
190
+ }
191
+ debug(doc) {
192
+ if (!doc) {
193
+ doc = this.state.doc;
194
+ }
195
+ console.debug(nodeToTreeString(doc));
196
+ }
197
+ }
@@ -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(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,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,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
+ getCommands(editor) {
23
+ return {};
24
+ }
25
+ getKeyboardShortcuts() {
26
+ return {};
27
+ }
28
+ getConverters(editor, schema) {
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.editor, 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.editor, 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"}