@lexion-rte/core 0.1.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/LICENSE +674 -0
- package/dist/editor.d.ts +33 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +187 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +4 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +33 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
- package/src/editor.d.ts +33 -0
- package/src/editor.d.ts.map +1 -0
- package/src/editor.js +187 -0
- package/src/editor.js.map +1 -0
- package/src/editor.ts +243 -0
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +3 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +17 -0
- package/src/schema.d.ts +4 -0
- package/src/schema.d.ts.map +1 -0
- package/src/schema.js +33 -0
- package/src/schema.js.map +1 -0
- package/src/schema.ts +37 -0
- package/src/types.d.ts +54 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +2 -0
- package/src/types.js.map +1 -0
- package/src/types.ts +66 -0
- package/tsconfig.json +8 -0
package/src/editor.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { Node as ProseMirrorNode, type Schema } from "prosemirror-model";
|
|
2
|
+
import { EditorState, type Plugin, type Transaction } from "prosemirror-state";
|
|
3
|
+
|
|
4
|
+
import { coreSchema } from "./schema.js";
|
|
5
|
+
import type {
|
|
6
|
+
CommandHandler,
|
|
7
|
+
CommandMap,
|
|
8
|
+
EditorCommandContext,
|
|
9
|
+
JSONDocument,
|
|
10
|
+
LexionEditor as LexionEditorContract,
|
|
11
|
+
LexionEditorOptions,
|
|
12
|
+
LexionExtension,
|
|
13
|
+
PluginFactoryContext,
|
|
14
|
+
PluginLifecycleContext
|
|
15
|
+
} from "./types.js";
|
|
16
|
+
|
|
17
|
+
export class LexionEditor implements LexionEditorContract {
|
|
18
|
+
private readonly _schema: Schema;
|
|
19
|
+
private _state: EditorState;
|
|
20
|
+
private readonly commandMap: Map<string, CommandHandler>;
|
|
21
|
+
private readonly extensionsByKey: Map<string, LexionExtension>;
|
|
22
|
+
private readonly extensionCommandsByKey: Map<string, readonly string[]>;
|
|
23
|
+
private destroyed: boolean;
|
|
24
|
+
|
|
25
|
+
public constructor(options: LexionEditorOptions = {}) {
|
|
26
|
+
const optionsExtensions = options.extensions ?? options.plugins ?? [];
|
|
27
|
+
this._schema = this.resolveSchema(options.schema, optionsExtensions);
|
|
28
|
+
this.commandMap = new Map();
|
|
29
|
+
this.extensionsByKey = new Map();
|
|
30
|
+
this.extensionCommandsByKey = new Map();
|
|
31
|
+
this.destroyed = false;
|
|
32
|
+
|
|
33
|
+
this.registerCommands(options.commands ?? {});
|
|
34
|
+
|
|
35
|
+
for (const extension of optionsExtensions) {
|
|
36
|
+
this.addExtension(extension);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const initialDoc = options.doc ? this.parseDocument(options.doc) : undefined;
|
|
40
|
+
this._state = this.createState(initialDoc);
|
|
41
|
+
this.runExtensionOnCreate();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public get schema(): Schema {
|
|
45
|
+
return this._schema;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public get state(): EditorState {
|
|
49
|
+
return this._state;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public get doc(): ProseMirrorNode {
|
|
53
|
+
return this._state.doc;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public getJSON(): JSONDocument {
|
|
57
|
+
return this._state.doc.toJSON() as JSONDocument;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public setJSON(document: JSONDocument): void {
|
|
61
|
+
this.assertNotDestroyed();
|
|
62
|
+
const nextDocument = this.parseDocument(document);
|
|
63
|
+
this._state = this.createState(nextDocument);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public dispatchTransaction(transaction: Transaction): void {
|
|
67
|
+
this.assertNotDestroyed();
|
|
68
|
+
this._state = this._state.apply(transaction);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public execute(command: string, ...args: readonly unknown[]): boolean {
|
|
72
|
+
this.assertNotDestroyed();
|
|
73
|
+
const handler = this.commandMap.get(command);
|
|
74
|
+
if (!handler) {
|
|
75
|
+
throw new Error(`Unknown command: ${command}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const context: EditorCommandContext = {
|
|
79
|
+
editor: this,
|
|
80
|
+
schema: this._schema,
|
|
81
|
+
state: this._state,
|
|
82
|
+
dispatch: (transaction: Transaction): void => {
|
|
83
|
+
this.dispatchTransaction(transaction);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return handler(context, ...args);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public registerCommand(name: string, command: CommandHandler): void {
|
|
91
|
+
this.assertNotDestroyed();
|
|
92
|
+
if (this.commandMap.has(name)) {
|
|
93
|
+
throw new Error(`Command already registered: ${name}`);
|
|
94
|
+
}
|
|
95
|
+
this.commandMap.set(name, command);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public unregisterCommand(name: string): void {
|
|
99
|
+
this.assertNotDestroyed();
|
|
100
|
+
this.commandMap.delete(name);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public use(extension: LexionExtension): void {
|
|
104
|
+
this.assertNotDestroyed();
|
|
105
|
+
this.addExtension(extension);
|
|
106
|
+
this._state = this.createState(this._state.doc);
|
|
107
|
+
this.runExtensionOnCreate([extension]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public removePlugin(key: string): void {
|
|
111
|
+
this.assertNotDestroyed();
|
|
112
|
+
const extension = this.extensionsByKey.get(key);
|
|
113
|
+
if (!extension) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const lifecycleContext = this.createPluginLifecycleContext();
|
|
118
|
+
extension.onDestroy?.(lifecycleContext);
|
|
119
|
+
|
|
120
|
+
for (const commandName of this.extensionCommandsByKey.get(key) ?? []) {
|
|
121
|
+
this.commandMap.delete(commandName);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.extensionCommandsByKey.delete(key);
|
|
125
|
+
this.extensionsByKey.delete(key);
|
|
126
|
+
this._state = this.createState(this._state.doc);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public destroy(): void {
|
|
130
|
+
if (this.destroyed) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const lifecycleContext = this.createPluginLifecycleContext();
|
|
135
|
+
for (const extension of [...this.extensionsByKey.values()].reverse()) {
|
|
136
|
+
extension.onDestroy?.(lifecycleContext);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.commandMap.clear();
|
|
140
|
+
this.extensionCommandsByKey.clear();
|
|
141
|
+
this.extensionsByKey.clear();
|
|
142
|
+
this.destroyed = true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private assertNotDestroyed(): void {
|
|
146
|
+
if (this.destroyed) {
|
|
147
|
+
throw new Error("LexionEditor instance has been destroyed");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private resolveSchema(
|
|
152
|
+
explicitSchema: Schema | undefined,
|
|
153
|
+
extensions: readonly LexionExtension[]
|
|
154
|
+
): Schema {
|
|
155
|
+
if (explicitSchema) {
|
|
156
|
+
return explicitSchema;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const schemaCandidates: Schema[] = [];
|
|
160
|
+
for (const extension of extensions) {
|
|
161
|
+
if (!extension.schema) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const schema =
|
|
165
|
+
typeof extension.schema === "function" ? extension.schema() : extension.schema;
|
|
166
|
+
schemaCandidates.push(schema);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (schemaCandidates.length > 1) {
|
|
170
|
+
throw new Error("Only one schema provider extension is supported per editor instance");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return schemaCandidates[0] ?? coreSchema;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private parseDocument(document: JSONDocument): ProseMirrorNode {
|
|
177
|
+
return ProseMirrorNode.fromJSON(this._schema, document as unknown as Record<string, unknown>);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private createState(document?: ProseMirrorNode): EditorState {
|
|
181
|
+
const pluginContext: PluginFactoryContext = { schema: this._schema };
|
|
182
|
+
const plugins: Plugin[] = [];
|
|
183
|
+
|
|
184
|
+
for (const extension of this.extensionsByKey.values()) {
|
|
185
|
+
for (const prosemirrorPlugin of extension.prosemirrorPlugins?.(pluginContext) ?? []) {
|
|
186
|
+
plugins.push(prosemirrorPlugin);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const config = document
|
|
191
|
+
? {
|
|
192
|
+
schema: this._schema,
|
|
193
|
+
doc: document,
|
|
194
|
+
plugins
|
|
195
|
+
}
|
|
196
|
+
: {
|
|
197
|
+
schema: this._schema,
|
|
198
|
+
plugins
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
return EditorState.create(config);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private addExtension(extension: LexionExtension): void {
|
|
205
|
+
if (this.extensionsByKey.has(extension.key)) {
|
|
206
|
+
throw new Error(`Extension already registered: ${extension.key}`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.extensionsByKey.set(extension.key, extension);
|
|
210
|
+
const commandNames: string[] = [];
|
|
211
|
+
const extensionCommands = extension.commands?.({ schema: this._schema }) ?? {};
|
|
212
|
+
|
|
213
|
+
for (const [name, handler] of Object.entries(extensionCommands)) {
|
|
214
|
+
if (this.commandMap.has(name)) {
|
|
215
|
+
throw new Error(`Command already registered: ${name}`);
|
|
216
|
+
}
|
|
217
|
+
this.commandMap.set(name, handler);
|
|
218
|
+
commandNames.push(name);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.extensionCommandsByKey.set(extension.key, commandNames);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private createPluginLifecycleContext(): PluginLifecycleContext {
|
|
225
|
+
return {
|
|
226
|
+
editor: this,
|
|
227
|
+
schema: this._schema
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private runExtensionOnCreate(extensions?: readonly LexionExtension[]): void {
|
|
232
|
+
const lifecycleContext = this.createPluginLifecycleContext();
|
|
233
|
+
for (const extension of extensions ?? this.extensionsByKey.values()) {
|
|
234
|
+
extension.onCreate?.(lifecycleContext);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private registerCommands(commands: CommandMap): void {
|
|
239
|
+
for (const [name, command] of Object.entries(commands)) {
|
|
240
|
+
this.registerCommand(name, command);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { LexionEditor } from "./editor.js";
|
|
2
|
+
export { createCoreSchema, coreSchema } from "./schema.js";
|
|
3
|
+
export type { CommandHandler, CommandMap, EditorCommandContext, JSONDocument, JSONArray, JSONObject, JSONPrimitive, JSONValue, LexionEditorOptions, LexionExtension, LexionPlugin, PluginFactoryContext, PluginLifecycleContext } from "./types.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EACV,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,UAAU,EACV,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,YAAY,CAAC"}
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { LexionEditor } from "./editor.js";
|
|
2
|
+
export { createCoreSchema, coreSchema } from "./schema.js";
|
|
3
|
+
export type {
|
|
4
|
+
CommandHandler,
|
|
5
|
+
CommandMap,
|
|
6
|
+
EditorCommandContext,
|
|
7
|
+
JSONDocument,
|
|
8
|
+
JSONArray,
|
|
9
|
+
JSONObject,
|
|
10
|
+
JSONPrimitive,
|
|
11
|
+
JSONValue,
|
|
12
|
+
LexionEditorOptions,
|
|
13
|
+
LexionExtension,
|
|
14
|
+
LexionPlugin,
|
|
15
|
+
PluginFactoryContext,
|
|
16
|
+
PluginLifecycleContext
|
|
17
|
+
} from "./types.js";
|
package/src/schema.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgC,MAAM,mBAAmB,CAAC;AA8BzE,eAAO,MAAM,gBAAgB,QAAO,MAIhC,CAAC;AAEL,eAAO,MAAM,UAAU,kBAAqB,CAAC"}
|
package/src/schema.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Schema } from "prosemirror-model";
|
|
2
|
+
const coreNodeSpecs = {
|
|
3
|
+
doc: {
|
|
4
|
+
content: "block+"
|
|
5
|
+
},
|
|
6
|
+
paragraph: {
|
|
7
|
+
group: "block",
|
|
8
|
+
content: "inline*",
|
|
9
|
+
parseDOM: [{ tag: "p" }],
|
|
10
|
+
toDOM() {
|
|
11
|
+
return ["p", 0];
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
text: {
|
|
15
|
+
group: "inline"
|
|
16
|
+
},
|
|
17
|
+
hard_break: {
|
|
18
|
+
inline: true,
|
|
19
|
+
group: "inline",
|
|
20
|
+
selectable: false,
|
|
21
|
+
parseDOM: [{ tag: "br" }],
|
|
22
|
+
toDOM() {
|
|
23
|
+
return ["br"];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const coreMarkSpecs = {};
|
|
28
|
+
export const createCoreSchema = () => new Schema({
|
|
29
|
+
nodes: coreNodeSpecs,
|
|
30
|
+
marks: coreMarkSpecs
|
|
31
|
+
});
|
|
32
|
+
export const coreSchema = createCoreSchema();
|
|
33
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgC,MAAM,mBAAmB,CAAC;AAEzE,MAAM,aAAa,GAA6B;IAC9C,GAAG,EAAE;QACH,OAAO,EAAE,QAAQ;KAClB;IACD,SAAS,EAAE;QACT,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,SAAS;QAClB,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACxB,KAAK;YACH,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAClB,CAAC;KACF;IACD,IAAI,EAAE;QACJ,KAAK,EAAE,QAAQ;KAChB;IACD,UAAU,EAAE;QACV,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QACzB,KAAK;YACH,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;KACF;CACF,CAAC;AAEF,MAAM,aAAa,GAA6B,EAAE,CAAC;AAEnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAW,EAAE,CAC3C,IAAI,MAAM,CAAC;IACT,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,aAAa;CACrB,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC"}
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Schema, type MarkSpec, type NodeSpec } from "prosemirror-model";
|
|
2
|
+
|
|
3
|
+
const coreNodeSpecs: Record<string, NodeSpec> = {
|
|
4
|
+
doc: {
|
|
5
|
+
content: "block+"
|
|
6
|
+
},
|
|
7
|
+
paragraph: {
|
|
8
|
+
group: "block",
|
|
9
|
+
content: "inline*",
|
|
10
|
+
parseDOM: [{ tag: "p" }],
|
|
11
|
+
toDOM() {
|
|
12
|
+
return ["p", 0];
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
text: {
|
|
16
|
+
group: "inline"
|
|
17
|
+
},
|
|
18
|
+
hard_break: {
|
|
19
|
+
inline: true,
|
|
20
|
+
group: "inline",
|
|
21
|
+
selectable: false,
|
|
22
|
+
parseDOM: [{ tag: "br" }],
|
|
23
|
+
toDOM() {
|
|
24
|
+
return ["br"];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const coreMarkSpecs: Record<string, MarkSpec> = {};
|
|
30
|
+
|
|
31
|
+
export const createCoreSchema = (): Schema =>
|
|
32
|
+
new Schema({
|
|
33
|
+
nodes: coreNodeSpecs,
|
|
34
|
+
marks: coreMarkSpecs
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const coreSchema = createCoreSchema();
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Node as ProseMirrorNode, Schema } from "prosemirror-model";
|
|
2
|
+
import type { Plugin, EditorState, Transaction } from "prosemirror-state";
|
|
3
|
+
export type JSONPrimitive = string | number | boolean | null;
|
|
4
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
5
|
+
export interface JSONObject {
|
|
6
|
+
readonly [key: string]: JSONValue;
|
|
7
|
+
}
|
|
8
|
+
export type JSONArray = readonly JSONValue[];
|
|
9
|
+
export type JSONDocument = JSONObject;
|
|
10
|
+
export interface LexionEditorOptions {
|
|
11
|
+
readonly schema?: Schema;
|
|
12
|
+
readonly doc?: JSONDocument;
|
|
13
|
+
readonly extensions?: readonly LexionExtension[];
|
|
14
|
+
readonly plugins?: readonly LexionPlugin[];
|
|
15
|
+
readonly commands?: CommandMap;
|
|
16
|
+
}
|
|
17
|
+
export interface PluginFactoryContext {
|
|
18
|
+
readonly schema: Schema;
|
|
19
|
+
}
|
|
20
|
+
export interface PluginLifecycleContext extends PluginFactoryContext {
|
|
21
|
+
readonly editor: LexionEditor;
|
|
22
|
+
}
|
|
23
|
+
export interface EditorCommandContext {
|
|
24
|
+
readonly editor: LexionEditor;
|
|
25
|
+
readonly schema: Schema;
|
|
26
|
+
readonly state: EditorState;
|
|
27
|
+
readonly dispatch: (transaction: Transaction) => void;
|
|
28
|
+
}
|
|
29
|
+
export type CommandHandler = (context: EditorCommandContext, ...args: readonly unknown[]) => boolean;
|
|
30
|
+
export type CommandMap = Readonly<Record<string, CommandHandler>>;
|
|
31
|
+
export interface LexionExtension {
|
|
32
|
+
readonly key: string;
|
|
33
|
+
readonly schema?: Schema | (() => Schema);
|
|
34
|
+
readonly prosemirrorPlugins?: (context: PluginFactoryContext) => readonly Plugin[];
|
|
35
|
+
readonly commands?: (context: PluginFactoryContext) => CommandMap;
|
|
36
|
+
readonly onCreate?: (context: PluginLifecycleContext) => void;
|
|
37
|
+
readonly onDestroy?: (context: PluginLifecycleContext) => void;
|
|
38
|
+
}
|
|
39
|
+
export type LexionPlugin = LexionExtension;
|
|
40
|
+
export interface LexionEditor {
|
|
41
|
+
readonly schema: Schema;
|
|
42
|
+
readonly state: EditorState;
|
|
43
|
+
readonly doc: ProseMirrorNode;
|
|
44
|
+
getJSON: () => JSONDocument;
|
|
45
|
+
setJSON: (document: JSONDocument) => void;
|
|
46
|
+
dispatchTransaction: (transaction: Transaction) => void;
|
|
47
|
+
execute: (command: string, ...args: readonly unknown[]) => boolean;
|
|
48
|
+
registerCommand: (name: string, command: CommandHandler) => void;
|
|
49
|
+
unregisterCommand: (name: string) => void;
|
|
50
|
+
use: (extension: LexionExtension) => void;
|
|
51
|
+
removePlugin: (key: string) => void;
|
|
52
|
+
destroy: () => void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"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"}
|
package/src/types.js
ADDED
package/src/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Node as ProseMirrorNode, Schema } from "prosemirror-model";
|
|
2
|
+
import type { Plugin, EditorState, Transaction } from "prosemirror-state";
|
|
3
|
+
|
|
4
|
+
export type JSONPrimitive = string | number | boolean | null;
|
|
5
|
+
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
|
|
6
|
+
export interface JSONObject {
|
|
7
|
+
readonly [key: string]: JSONValue;
|
|
8
|
+
}
|
|
9
|
+
export type JSONArray = readonly JSONValue[];
|
|
10
|
+
export type JSONDocument = JSONObject;
|
|
11
|
+
|
|
12
|
+
export interface LexionEditorOptions {
|
|
13
|
+
readonly schema?: Schema;
|
|
14
|
+
readonly doc?: JSONDocument;
|
|
15
|
+
readonly extensions?: readonly LexionExtension[];
|
|
16
|
+
readonly plugins?: readonly LexionPlugin[];
|
|
17
|
+
readonly commands?: CommandMap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PluginFactoryContext {
|
|
21
|
+
readonly schema: Schema;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PluginLifecycleContext extends PluginFactoryContext {
|
|
25
|
+
readonly editor: LexionEditor;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface EditorCommandContext {
|
|
29
|
+
readonly editor: LexionEditor;
|
|
30
|
+
readonly schema: Schema;
|
|
31
|
+
readonly state: EditorState;
|
|
32
|
+
readonly dispatch: (transaction: Transaction) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type CommandHandler = (
|
|
36
|
+
context: EditorCommandContext,
|
|
37
|
+
...args: readonly unknown[]
|
|
38
|
+
) => boolean;
|
|
39
|
+
|
|
40
|
+
export type CommandMap = Readonly<Record<string, CommandHandler>>;
|
|
41
|
+
|
|
42
|
+
export interface LexionExtension {
|
|
43
|
+
readonly key: string;
|
|
44
|
+
readonly schema?: Schema | (() => Schema);
|
|
45
|
+
readonly prosemirrorPlugins?: (context: PluginFactoryContext) => readonly Plugin[];
|
|
46
|
+
readonly commands?: (context: PluginFactoryContext) => CommandMap;
|
|
47
|
+
readonly onCreate?: (context: PluginLifecycleContext) => void;
|
|
48
|
+
readonly onDestroy?: (context: PluginLifecycleContext) => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type LexionPlugin = LexionExtension;
|
|
52
|
+
|
|
53
|
+
export interface LexionEditor {
|
|
54
|
+
readonly schema: Schema;
|
|
55
|
+
readonly state: EditorState;
|
|
56
|
+
readonly doc: ProseMirrorNode;
|
|
57
|
+
getJSON: () => JSONDocument;
|
|
58
|
+
setJSON: (document: JSONDocument) => void;
|
|
59
|
+
dispatchTransaction: (transaction: Transaction) => void;
|
|
60
|
+
execute: (command: string, ...args: readonly unknown[]) => boolean;
|
|
61
|
+
registerCommand: (name: string, command: CommandHandler) => void;
|
|
62
|
+
unregisterCommand: (name: string) => void;
|
|
63
|
+
use: (extension: LexionExtension) => void;
|
|
64
|
+
removePlugin: (key: string) => void;
|
|
65
|
+
destroy: () => void;
|
|
66
|
+
}
|