@kerebron/extension-menu 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/menu.css +539 -0
- package/package.json +4 -1
- package/esm/editor/src/CoreEditor.d.ts +0 -25
- package/esm/editor/src/CoreEditor.d.ts.map +0 -1
- package/esm/editor/src/CoreEditor.js +0 -194
- package/esm/editor/src/Extension.d.ts +0 -26
- package/esm/editor/src/Extension.d.ts.map +0 -1
- package/esm/editor/src/Extension.js +0 -33
- package/esm/editor/src/ExtensionManager.d.ts +0 -32
- package/esm/editor/src/ExtensionManager.d.ts.map +0 -1
- package/esm/editor/src/ExtensionManager.js +0 -253
- package/esm/editor/src/Mark.d.ts +0 -18
- package/esm/editor/src/Mark.d.ts.map +0 -1
- package/esm/editor/src/Mark.js +0 -34
- package/esm/editor/src/Node.d.ts +0 -27
- package/esm/editor/src/Node.d.ts.map +0 -1
- package/esm/editor/src/Node.js +0 -43
- package/esm/editor/src/commands/CommandManager.d.ts +0 -20
- package/esm/editor/src/commands/CommandManager.d.ts.map +0 -1
- package/esm/editor/src/commands/CommandManager.js +0 -60
- package/esm/editor/src/commands/createChainableState.d.ts +0 -3
- package/esm/editor/src/commands/createChainableState.d.ts.map +0 -1
- package/esm/editor/src/commands/createChainableState.js +0 -29
- package/esm/editor/src/commands/mod.d.ts +0 -49
- package/esm/editor/src/commands/mod.d.ts.map +0 -1
- package/esm/editor/src/commands/mod.js +0 -928
- package/esm/editor/src/mod.d.ts +0 -6
- package/esm/editor/src/mod.d.ts.map +0 -1
- package/esm/editor/src/mod.js +0 -5
- package/esm/editor/src/nodeToTreeString.d.ts +0 -4
- package/esm/editor/src/nodeToTreeString.d.ts.map +0 -1
- package/esm/editor/src/nodeToTreeString.js +0 -56
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +0 -23
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +0 -1
- package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +0 -163
- package/esm/editor/src/types.d.ts +0 -29
- package/esm/editor/src/types.d.ts.map +0 -1
- package/esm/editor/src/types.js +0 -1
- package/esm/editor/src/utilities/createNodeFromContent.d.ts +0 -8
- package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +0 -1
- package/esm/editor/src/utilities/createNodeFromContent.js +0 -33
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts +0 -4
- package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +0 -1
- package/esm/editor/src/utilities/getHtmlAttributes.js +0 -47
- package/esm/extension-menu/src/ExtensionMenu.d.ts +0 -17
- package/esm/extension-menu/src/ExtensionMenu.d.ts.map +0 -1
- package/esm/extension-menu/src/ExtensionMenu.js +0 -318
- package/esm/extension-menu/src/MenuPlugin.d.ts +0 -9
- package/esm/extension-menu/src/MenuPlugin.d.ts.map +0 -1
- package/esm/extension-menu/src/MenuPlugin.js +0 -246
- package/esm/extension-menu/src/icons.d.ts +0 -15
- package/esm/extension-menu/src/icons.d.ts.map +0 -1
- package/esm/extension-menu/src/icons.js +0 -118
- package/esm/extension-menu/src/menu.d.ts +0 -86
- package/esm/extension-menu/src/menu.d.ts.map +0 -1
- package/esm/extension-menu/src/menu.js +0 -353
- package/esm/extension-menu/src/prompt.d.ts +0 -36
- package/esm/extension-menu/src/prompt.d.ts.map +0 -1
- package/esm/extension-menu/src/prompt.js +0 -158
- package/esm/package.json +0 -3
|
@@ -1,194 +0,0 @@
|
|
|
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
|
-
dispatchTransaction: (tx) => this.dispatchTransaction(tx),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
dispatchTransaction(transaction) {
|
|
107
|
-
this.state = this.state.apply(transaction);
|
|
108
|
-
if (this.view) {
|
|
109
|
-
this.view.updateState(this.state);
|
|
110
|
-
const event = new CustomEvent('transaction', {
|
|
111
|
-
detail: {
|
|
112
|
-
editor: this,
|
|
113
|
-
transaction,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
this.dispatchEvent(event);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
setupPlugins() {
|
|
120
|
-
this.state = this.state.reconfigure({
|
|
121
|
-
plugins: this.extensionManager.plugins,
|
|
122
|
-
});
|
|
123
|
-
if (this.view) {
|
|
124
|
-
this.view.updateState(this.state);
|
|
125
|
-
this.view.setProps({
|
|
126
|
-
nodeViews: this.extensionManager.nodeViews,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
setDocument(content, mediaType) {
|
|
131
|
-
if (!content) {
|
|
132
|
-
content = {
|
|
133
|
-
type: this.extensionManager.schema.topNodeType.name,
|
|
134
|
-
content: this.extensionManager.schema.topNodeType.spec.EMPTY_DOC.content,
|
|
135
|
-
};
|
|
136
|
-
mediaType = undefined;
|
|
137
|
-
}
|
|
138
|
-
let doc;
|
|
139
|
-
if (mediaType) {
|
|
140
|
-
const converter = this.extensionManager.converters[mediaType];
|
|
141
|
-
if (converter) {
|
|
142
|
-
doc = converter.toDoc(content);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
doc = createNodeFromContent(content, this.schema);
|
|
147
|
-
}
|
|
148
|
-
ensureDocSchema(doc, this.schema);
|
|
149
|
-
this.state = EditorState.create({
|
|
150
|
-
doc,
|
|
151
|
-
plugins: this.state.plugins,
|
|
152
|
-
storedMarks: this.state.storedMarks,
|
|
153
|
-
});
|
|
154
|
-
if (this.view) {
|
|
155
|
-
this.view.updateState(this.state);
|
|
156
|
-
}
|
|
157
|
-
const event = new CustomEvent('doc:loaded', {
|
|
158
|
-
detail: {
|
|
159
|
-
editor: this,
|
|
160
|
-
doc,
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
this.dispatchEvent(event);
|
|
164
|
-
}
|
|
165
|
-
getDocument(mediaType) {
|
|
166
|
-
if (mediaType) {
|
|
167
|
-
const converter = this.extensionManager.converters[mediaType];
|
|
168
|
-
if (converter) {
|
|
169
|
-
const json = this.state.doc.toJSON();
|
|
170
|
-
const clonedDoc = ProseMirrorNode.fromJSON(this.state.schema, json);
|
|
171
|
-
return converter.fromDoc(clonedDoc);
|
|
172
|
-
}
|
|
173
|
-
if (mediaType === 'text/json') {
|
|
174
|
-
return this.getJSON();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return this.state.doc;
|
|
178
|
-
}
|
|
179
|
-
getJSON() {
|
|
180
|
-
return this.state.doc.toJSON();
|
|
181
|
-
}
|
|
182
|
-
clone(options = {}) {
|
|
183
|
-
return new CoreEditor({
|
|
184
|
-
...options,
|
|
185
|
-
extensions: [...this.options.extensions],
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
debug(doc) {
|
|
189
|
-
if (!doc) {
|
|
190
|
-
doc = this.state.doc;
|
|
191
|
-
}
|
|
192
|
-
console.debug(nodeToTreeString(doc));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,253 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/editor/src/Mark.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/esm/editor/src/Mark.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
package/esm/editor/src/Node.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/esm/editor/src/Node.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|
|
22
|
-
getNodeSpec() {
|
|
23
|
-
throw new Error('NodeSpec not defined: ' + this.name);
|
|
24
|
-
}
|
|
25
|
-
getInputRules(type) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
getProseMirrorPlugins(editor) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
getCommands(editor, type) {
|
|
32
|
-
return {};
|
|
33
|
-
}
|
|
34
|
-
getKeyboardShortcuts() {
|
|
35
|
-
return {};
|
|
36
|
-
}
|
|
37
|
-
getNodeView() {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
getConverters() {
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
43
|
-
}
|