@etrepum/lexical-builder 0.0.36-nightly.20250714.0 → 0.0.37-nightly.20250715.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/dist/{AutoFocusPlan.d.ts → AutoFocusExtension.d.ts} +3 -3
- package/dist/AutoFocusExtension.d.ts.map +1 -0
- package/dist/{DragonPlan.d.ts → DragonExtension.d.ts} +2 -2
- package/dist/DragonExtension.d.ts.map +1 -0
- package/dist/ExtensionRep.d.ts +76 -0
- package/dist/ExtensionRep.d.ts.map +1 -0
- package/dist/{HistoryPlan.d.ts → HistoryExtension.d.ts} +3 -3
- package/dist/HistoryExtension.d.ts.map +1 -0
- package/dist/InitialStateExtension.d.ts +7 -0
- package/dist/InitialStateExtension.d.ts.map +1 -0
- package/dist/LexicalBuilder.d.ts +23 -23
- package/dist/LexicalBuilder.d.ts.map +1 -1
- package/dist/PlainTextExtension.d.ts +5 -0
- package/dist/PlainTextExtension.d.ts.map +1 -0
- package/dist/RichTextExtension.d.ts +13 -0
- package/dist/RichTextExtension.d.ts.map +1 -0
- package/dist/getExtensionDependencyFromEditor.d.ts +17 -0
- package/dist/getExtensionDependencyFromEditor.d.ts.map +1 -0
- package/dist/getPeerDependencyFromEditor.d.ts +20 -20
- package/dist/getPeerDependencyFromEditor.d.ts.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +240 -234
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/AutoFocusPlan.d.ts.map +0 -1
- package/dist/DragonPlan.d.ts.map +0 -1
- package/dist/HistoryPlan.d.ts.map +0 -1
- package/dist/InitialStatePlan.d.ts +0 -7
- package/dist/InitialStatePlan.d.ts.map +0 -1
- package/dist/PlainTextPlan.d.ts +0 -5
- package/dist/PlainTextPlan.d.ts.map +0 -1
- package/dist/PlanRep.d.ts +0 -76
- package/dist/PlanRep.d.ts.map +0 -1
- package/dist/RichTextPlan.d.ts +0 -13
- package/dist/RichTextPlan.d.ts.map +0 -1
- package/dist/getPlanDependencyFromEditor.d.ts +0 -17
- package/dist/getPlanDependencyFromEditor.d.ts.map +0 -1
package/dist/index.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4
|
-
import { shallowMergeConfig,
|
5
|
-
import {
|
4
|
+
import { shallowMergeConfig, defineExtension, safeCast, provideOutput, configExtension } from "@etrepum/lexical-builder-core";
|
5
|
+
import { configExtension as configExtension2, declarePeerDependency, defineExtension as defineExtension2, provideOutput as provideOutput2, safeCast as safeCast2, shallowMergeConfig as shallowMergeConfig2 } from "@etrepum/lexical-builder-core";
|
6
6
|
import { RootNode, TextNode, LineBreakNode, TabNode, ParagraphNode, $getRoot, $createParagraphNode, createEditor } from "lexical";
|
7
7
|
import { mergeRegister } from "@lexical/utils";
|
8
8
|
import { registerDragonSupport } from "@lexical/dragon";
|
9
9
|
import { createEmptyHistoryState, registerHistory } from "@lexical/history";
|
10
10
|
import { registerPlainText } from "@lexical/plain-text";
|
11
11
|
import { HeadingNode, QuoteNode, registerRichText } from "@lexical/rich-text";
|
12
|
-
const PACKAGE_VERSION = "0.0.
|
12
|
+
const PACKAGE_VERSION = "0.0.37-nightly.20250715.0";
|
13
13
|
function invariant(cond, message, ...args) {
|
14
14
|
if (cond) {
|
15
15
|
return;
|
@@ -29,7 +29,7 @@ function deepThemeMergeInPlace(a, b) {
|
|
29
29
|
}
|
30
30
|
return b;
|
31
31
|
}
|
32
|
-
const
|
32
|
+
const ExtensionRepStateIds = {
|
33
33
|
unmarked: 0,
|
34
34
|
temporary: 1,
|
35
35
|
permanent: 2,
|
@@ -38,90 +38,94 @@ const PlanRepStateIds = {
|
|
38
38
|
registered: 5,
|
39
39
|
afterInitialization: 6
|
40
40
|
};
|
41
|
-
function
|
42
|
-
return state.id ===
|
41
|
+
function isExactlyUnmarkedExtensionRepState(state) {
|
42
|
+
return state.id === ExtensionRepStateIds.unmarked;
|
43
43
|
}
|
44
|
-
function
|
45
|
-
return state.id ===
|
44
|
+
function isExactlyTemporaryExtensionRepState(state) {
|
45
|
+
return state.id === ExtensionRepStateIds.temporary;
|
46
46
|
}
|
47
|
-
function
|
48
|
-
return state.id ===
|
47
|
+
function isExactlyPermanentExtensionRepState(state) {
|
48
|
+
return state.id === ExtensionRepStateIds.permanent;
|
49
49
|
}
|
50
|
-
function
|
51
|
-
return state.id >=
|
50
|
+
function isInitializedExtensionRepState(state) {
|
51
|
+
return state.id >= ExtensionRepStateIds.initialized;
|
52
52
|
}
|
53
|
-
function
|
54
|
-
return state.id >=
|
53
|
+
function isConfiguredExtensionRepState(state) {
|
54
|
+
return state.id >= ExtensionRepStateIds.configured;
|
55
55
|
}
|
56
|
-
function
|
57
|
-
return state.id >=
|
56
|
+
function isRegisteredExtensionRepState(state) {
|
57
|
+
return state.id >= ExtensionRepStateIds.registered;
|
58
58
|
}
|
59
59
|
function isAfterInitializationState(state) {
|
60
|
-
return state.id >=
|
60
|
+
return state.id >= ExtensionRepStateIds.afterInitialization;
|
61
61
|
}
|
62
62
|
function applyTemporaryMark(state) {
|
63
63
|
invariant(
|
64
|
-
|
65
|
-
"LexicalBuilder: Can not apply a temporary mark
|
64
|
+
isExactlyUnmarkedExtensionRepState(state),
|
65
|
+
"LexicalBuilder: Can not apply a temporary mark from state id %s (expected %s unmarked)",
|
66
|
+
String(state.id),
|
67
|
+
String(ExtensionRepStateIds.unmarked)
|
66
68
|
);
|
67
|
-
return Object.assign(state, { id:
|
69
|
+
return Object.assign(state, { id: ExtensionRepStateIds.temporary });
|
68
70
|
}
|
69
71
|
function applyPermanentMark(state) {
|
70
72
|
invariant(
|
71
|
-
|
72
|
-
"LexicalBuilder: Can not apply a permanent mark
|
73
|
+
isExactlyTemporaryExtensionRepState(state),
|
74
|
+
"LexicalBuilder: Can not apply a permanent mark from state id %s (expected %s temporary)",
|
75
|
+
String(state.id),
|
76
|
+
String(ExtensionRepStateIds.temporary)
|
73
77
|
);
|
74
|
-
return Object.assign(state, { id:
|
78
|
+
return Object.assign(state, { id: ExtensionRepStateIds.permanent });
|
75
79
|
}
|
76
80
|
function applyConfiguredState(state, config, registerState) {
|
77
81
|
return Object.assign(state, {
|
78
|
-
id:
|
82
|
+
id: ExtensionRepStateIds.configured,
|
79
83
|
config,
|
80
84
|
registerState
|
81
85
|
});
|
82
86
|
}
|
83
87
|
function applyInitializedState(state, initResult, registerState) {
|
84
88
|
return Object.assign(state, {
|
85
|
-
id:
|
89
|
+
id: ExtensionRepStateIds.initialized,
|
86
90
|
initResult,
|
87
91
|
registerState
|
88
92
|
});
|
89
93
|
}
|
90
94
|
function applyRegisteredState(state, cleanup) {
|
91
95
|
return Object.assign(state, {
|
92
|
-
id:
|
96
|
+
id: ExtensionRepStateIds.registered,
|
93
97
|
output: cleanup ? cleanup.output : void 0
|
94
98
|
});
|
95
99
|
}
|
96
100
|
function applyAfterInitializationState(state) {
|
97
|
-
return Object.assign(state, { id:
|
101
|
+
return Object.assign(state, { id: ExtensionRepStateIds.afterInitialization });
|
98
102
|
}
|
99
103
|
const emptySet = /* @__PURE__ */ new Set();
|
100
|
-
class
|
101
|
-
constructor(builder,
|
104
|
+
class ExtensionRep {
|
105
|
+
constructor(builder, extension) {
|
102
106
|
__publicField(this, "builder");
|
103
107
|
__publicField(this, "configs");
|
104
108
|
__publicField(this, "_dependency");
|
105
109
|
__publicField(this, "_output");
|
106
110
|
__publicField(this, "_peerNameSet");
|
107
|
-
__publicField(this, "
|
111
|
+
__publicField(this, "extension");
|
108
112
|
__publicField(this, "state");
|
109
113
|
this.builder = builder;
|
110
|
-
this.
|
114
|
+
this.extension = extension;
|
111
115
|
this.configs = /* @__PURE__ */ new Set();
|
112
|
-
this.state = { id:
|
116
|
+
this.state = { id: ExtensionRepStateIds.unmarked };
|
113
117
|
}
|
114
118
|
afterInitialization(editor) {
|
115
119
|
const state = this.state;
|
116
120
|
invariant(
|
117
|
-
state.id ===
|
118
|
-
"
|
121
|
+
state.id === ExtensionRepStateIds.registered,
|
122
|
+
"ExtensionRep: afterInitialization called in state id %s (expected %s registered)",
|
119
123
|
String(state.id),
|
120
|
-
String(
|
124
|
+
String(ExtensionRepStateIds.registered)
|
121
125
|
);
|
122
126
|
let rval;
|
123
|
-
if (this.
|
124
|
-
rval = this.
|
127
|
+
if (this.extension.afterInitialization) {
|
128
|
+
rval = this.extension.afterInitialization(
|
125
129
|
editor,
|
126
130
|
state.config,
|
127
131
|
state.registerState
|
@@ -133,14 +137,14 @@ class PlanRep {
|
|
133
137
|
register(editor) {
|
134
138
|
const state = this.state;
|
135
139
|
invariant(
|
136
|
-
state.id ===
|
137
|
-
"
|
140
|
+
state.id === ExtensionRepStateIds.initialized,
|
141
|
+
"ExtensionRep: register called in state id %s (expected %s initialized)",
|
138
142
|
String(state.id),
|
139
|
-
String(
|
143
|
+
String(ExtensionRepStateIds.initialized)
|
140
144
|
);
|
141
145
|
let cleanup;
|
142
|
-
if (this.
|
143
|
-
cleanup = this.
|
146
|
+
if (this.extension.register) {
|
147
|
+
cleanup = this.extension.register(
|
144
148
|
editor,
|
145
149
|
state.config,
|
146
150
|
state.registerState
|
@@ -152,8 +156,8 @@ class PlanRep {
|
|
152
156
|
init(editorConfig, signal) {
|
153
157
|
const initialState = this.state;
|
154
158
|
invariant(
|
155
|
-
|
156
|
-
"
|
159
|
+
isExactlyPermanentExtensionRepState(initialState),
|
160
|
+
"ExtensionRep: Can not configure from state id %s",
|
157
161
|
String(initialState.id)
|
158
162
|
);
|
159
163
|
const initState = {
|
@@ -176,8 +180,8 @@ class PlanRep {
|
|
176
180
|
);
|
177
181
|
this.state = state;
|
178
182
|
let initResult;
|
179
|
-
if (this.
|
180
|
-
initResult = this.
|
183
|
+
if (this.extension.init) {
|
184
|
+
initResult = this.extension.init(
|
181
185
|
editorConfig,
|
182
186
|
state.config,
|
183
187
|
initState
|
@@ -187,85 +191,87 @@ class PlanRep {
|
|
187
191
|
}
|
188
192
|
getInitResult() {
|
189
193
|
invariant(
|
190
|
-
this.
|
191
|
-
"
|
192
|
-
this.
|
194
|
+
this.extension.init !== void 0,
|
195
|
+
"ExtensionRep: getInitResult() called for Extension %s that does not define init",
|
196
|
+
this.extension.name
|
193
197
|
);
|
194
198
|
const state = this.state;
|
195
199
|
invariant(
|
196
|
-
|
197
|
-
"
|
200
|
+
isInitializedExtensionRepState(state),
|
201
|
+
"ExtensionRep: getInitResult() called for ExtensionRep in state id %s < %s (initialized)",
|
198
202
|
String(state.id),
|
199
|
-
String(
|
203
|
+
String(ExtensionRepStateIds.initialized)
|
200
204
|
);
|
201
205
|
return state.initResult;
|
202
206
|
}
|
203
207
|
getInitPeer(name) {
|
204
|
-
const rep = this.builder.
|
205
|
-
return rep ? rep.
|
208
|
+
const rep = this.builder.extensionNameMap.get(name);
|
209
|
+
return rep ? rep.getExtensionInitDependency() : void 0;
|
206
210
|
}
|
207
|
-
|
211
|
+
getExtensionInitDependency() {
|
208
212
|
const state = this.state;
|
209
213
|
invariant(
|
210
|
-
|
211
|
-
"
|
214
|
+
isConfiguredExtensionRepState(state),
|
215
|
+
"ExtensionRep: getExtensionInitDependency called in state id %s (expected >= %s configured)",
|
212
216
|
String(state.id),
|
213
|
-
String(
|
217
|
+
String(ExtensionRepStateIds.configured)
|
214
218
|
);
|
215
219
|
return { config: state.config };
|
216
220
|
}
|
217
221
|
getPeer(name) {
|
218
|
-
const rep = this.builder.
|
219
|
-
return rep ? rep.
|
222
|
+
const rep = this.builder.extensionNameMap.get(name);
|
223
|
+
return rep ? rep.getExtensionDependency() : void 0;
|
220
224
|
}
|
221
225
|
getInitDependency(dep) {
|
222
|
-
const rep = this.builder.
|
226
|
+
const rep = this.builder.getExtensionRep(dep);
|
223
227
|
invariant(
|
224
228
|
rep !== void 0,
|
225
|
-
"
|
226
|
-
this.
|
229
|
+
"LexicalExtensionBuilder: Extension %s missing dependency extension %s to be in registry",
|
230
|
+
this.extension.name,
|
227
231
|
dep.name
|
228
232
|
);
|
229
|
-
return rep.
|
233
|
+
return rep.getExtensionInitDependency();
|
230
234
|
}
|
231
235
|
getDependency(dep) {
|
232
|
-
const rep = this.builder.
|
236
|
+
const rep = this.builder.getExtensionRep(dep);
|
233
237
|
invariant(
|
234
238
|
rep !== void 0,
|
235
|
-
"
|
236
|
-
this.
|
239
|
+
"LexicalExtensionBuilder: Extension %s missing dependency extension %s to be in registry",
|
240
|
+
this.extension.name,
|
237
241
|
dep.name
|
238
242
|
);
|
239
|
-
return rep.
|
243
|
+
return rep.getExtensionDependency();
|
240
244
|
}
|
241
245
|
getState() {
|
242
246
|
const state = this.state;
|
243
247
|
invariant(
|
244
248
|
isAfterInitializationState(state),
|
245
|
-
"
|
249
|
+
"ExtensionRep getState called in state id %s (expected %s afterInitialization)",
|
246
250
|
String(state.id),
|
247
|
-
String(
|
251
|
+
String(ExtensionRepStateIds.afterInitialization)
|
248
252
|
);
|
249
253
|
return state;
|
250
254
|
}
|
251
255
|
getDirectDependentNames() {
|
252
|
-
return this.builder.incomingEdges.get(this.
|
256
|
+
return this.builder.incomingEdges.get(this.extension.name) || emptySet;
|
253
257
|
}
|
254
258
|
getPeerNameSet() {
|
255
259
|
let s = this._peerNameSet;
|
256
260
|
if (!s) {
|
257
|
-
s = new Set(
|
261
|
+
s = new Set(
|
262
|
+
(this.extension.peerDependencies || []).map(([name]) => name)
|
263
|
+
);
|
258
264
|
this._peerNameSet = s;
|
259
265
|
}
|
260
266
|
return s;
|
261
267
|
}
|
262
|
-
|
268
|
+
getExtensionDependency() {
|
263
269
|
if (!this._dependency) {
|
264
270
|
const state = this.state;
|
265
271
|
invariant(
|
266
|
-
|
267
|
-
"
|
268
|
-
this.
|
272
|
+
isRegisteredExtensionRepState(state),
|
273
|
+
"Extension %s used as a dependency before registration",
|
274
|
+
this.extension.name
|
269
275
|
);
|
270
276
|
this._dependency = {
|
271
277
|
config: state.config,
|
@@ -275,8 +281,8 @@ class PlanRep {
|
|
275
281
|
return this._dependency;
|
276
282
|
}
|
277
283
|
mergeConfigs() {
|
278
|
-
let config = this.
|
279
|
-
const mergeConfig = this.
|
284
|
+
let config = this.extension.config || {};
|
285
|
+
const mergeConfig = this.extension.mergeConfig ? this.extension.mergeConfig.bind(this.extension) : shallowMergeConfig;
|
280
286
|
for (const cfg of this.configs) {
|
281
287
|
config = mergeConfig(config, cfg);
|
282
288
|
}
|
@@ -290,10 +296,10 @@ function $defaultInitializer() {
|
|
290
296
|
root.append($createParagraphNode());
|
291
297
|
}
|
292
298
|
}
|
293
|
-
const
|
299
|
+
const InitialStateExtension = defineExtension({
|
294
300
|
name: "@etrepum/lexical-builder/InitialState",
|
295
301
|
// These are automatically added by createEditor, we add them here so they are
|
296
|
-
// visible during
|
302
|
+
// visible during extensionRep.init so extensions can see all known types before the
|
297
303
|
// editor is created.
|
298
304
|
// (excluding ArtificialNode__DO_NOT_USE because it isn't really public API
|
299
305
|
// and shouldn't change anything)
|
@@ -331,8 +337,8 @@ const InitialStatePlan = definePlan({
|
|
331
337
|
}
|
332
338
|
});
|
333
339
|
const builderSymbol = Symbol.for("@etrepum/lexical-builder");
|
334
|
-
function
|
335
|
-
return LexicalBuilder.
|
340
|
+
function buildEditorFromExtensions(...extensions) {
|
341
|
+
return LexicalBuilder.fromExtensions(extensions).buildEditor();
|
336
342
|
}
|
337
343
|
function noop() {
|
338
344
|
}
|
@@ -342,32 +348,32 @@ function defaultOnError(err) {
|
|
342
348
|
function maybeWithBuilder(editor) {
|
343
349
|
return editor;
|
344
350
|
}
|
345
|
-
function
|
351
|
+
function normalizeExtensionArgument(arg) {
|
346
352
|
return Array.isArray(arg) ? arg : [arg];
|
347
353
|
}
|
348
354
|
class LexicalBuilder {
|
349
355
|
constructor(roots) {
|
350
356
|
__publicField(this, "roots");
|
351
|
-
__publicField(this, "
|
357
|
+
__publicField(this, "extensionNameMap");
|
352
358
|
__publicField(this, "outgoingConfigEdges");
|
353
359
|
__publicField(this, "incomingEdges");
|
354
360
|
__publicField(this, "conflicts");
|
355
|
-
__publicField(this, "
|
361
|
+
__publicField(this, "_sortedExtensionReps");
|
356
362
|
__publicField(this, "PACKAGE_VERSION");
|
357
363
|
this.outgoingConfigEdges = /* @__PURE__ */ new Map();
|
358
364
|
this.incomingEdges = /* @__PURE__ */ new Map();
|
359
|
-
this.
|
365
|
+
this.extensionNameMap = /* @__PURE__ */ new Map();
|
360
366
|
this.conflicts = /* @__PURE__ */ new Map();
|
361
367
|
this.PACKAGE_VERSION = PACKAGE_VERSION;
|
362
368
|
this.roots = roots;
|
363
|
-
for (const
|
364
|
-
this.
|
369
|
+
for (const extension of roots) {
|
370
|
+
this.addExtension(extension);
|
365
371
|
}
|
366
372
|
}
|
367
|
-
static
|
368
|
-
const roots = [
|
369
|
-
for (const
|
370
|
-
roots.push(
|
373
|
+
static fromExtensions(extensions) {
|
374
|
+
const roots = [normalizeExtensionArgument(InitialStateExtension)];
|
375
|
+
for (const extension of extensions) {
|
376
|
+
roots.push(normalizeExtensionArgument(extension));
|
371
377
|
}
|
372
378
|
return new LexicalBuilder(roots);
|
373
379
|
}
|
@@ -427,126 +433,126 @@ class LexicalBuilder {
|
|
427
433
|
);
|
428
434
|
return editor;
|
429
435
|
}
|
430
|
-
|
431
|
-
const rep = this.
|
436
|
+
getExtensionRep(extension) {
|
437
|
+
const rep = this.extensionNameMap.get(extension.name);
|
432
438
|
if (rep) {
|
433
439
|
invariant(
|
434
|
-
rep.
|
435
|
-
"LexicalBuilder: A registered
|
436
|
-
|
440
|
+
rep.extension === extension,
|
441
|
+
"LexicalBuilder: A registered extension with name %s exists but does not match the given extension",
|
442
|
+
extension.name
|
437
443
|
);
|
438
444
|
return rep;
|
439
445
|
}
|
440
446
|
}
|
441
|
-
addEdge(
|
442
|
-
const outgoing = this.outgoingConfigEdges.get(
|
447
|
+
addEdge(fromExtensionName, toExtensionName, configs) {
|
448
|
+
const outgoing = this.outgoingConfigEdges.get(fromExtensionName);
|
443
449
|
if (outgoing) {
|
444
|
-
outgoing.set(
|
450
|
+
outgoing.set(toExtensionName, configs);
|
445
451
|
} else {
|
446
452
|
this.outgoingConfigEdges.set(
|
447
|
-
|
448
|
-
/* @__PURE__ */ new Map([[
|
453
|
+
fromExtensionName,
|
454
|
+
/* @__PURE__ */ new Map([[toExtensionName, configs]])
|
449
455
|
);
|
450
456
|
}
|
451
|
-
const incoming = this.incomingEdges.get(
|
457
|
+
const incoming = this.incomingEdges.get(toExtensionName);
|
452
458
|
if (incoming) {
|
453
|
-
incoming.add(
|
459
|
+
incoming.add(fromExtensionName);
|
454
460
|
} else {
|
455
|
-
this.incomingEdges.set(
|
461
|
+
this.incomingEdges.set(toExtensionName, /* @__PURE__ */ new Set([fromExtensionName]));
|
456
462
|
}
|
457
463
|
}
|
458
|
-
|
464
|
+
addExtension(arg) {
|
459
465
|
invariant(
|
460
|
-
this.
|
461
|
-
"LexicalBuilder:
|
466
|
+
this._sortedExtensionReps === void 0,
|
467
|
+
"LexicalBuilder: addExtension called after finalization"
|
462
468
|
);
|
463
|
-
const normalized =
|
464
|
-
const [
|
469
|
+
const normalized = normalizeExtensionArgument(arg);
|
470
|
+
const [extension] = normalized;
|
465
471
|
invariant(
|
466
|
-
typeof
|
467
|
-
"LexicalBuilder:
|
468
|
-
typeof
|
472
|
+
typeof extension.name === "string",
|
473
|
+
"LexicalBuilder: extension name must be string, not %s",
|
474
|
+
typeof extension.name
|
469
475
|
);
|
470
|
-
let
|
476
|
+
let extensionRep = this.extensionNameMap.get(extension.name);
|
471
477
|
invariant(
|
472
|
-
|
473
|
-
"LexicalBuilder: Multiple
|
474
|
-
|
478
|
+
extensionRep === void 0 || extensionRep.extension === extension,
|
479
|
+
"LexicalBuilder: Multiple extensions registered with name %s, names must be unique",
|
480
|
+
extension.name
|
475
481
|
);
|
476
|
-
if (!
|
477
|
-
|
478
|
-
this.
|
479
|
-
const hasConflict = this.conflicts.get(
|
482
|
+
if (!extensionRep) {
|
483
|
+
extensionRep = new ExtensionRep(this, extension);
|
484
|
+
this.extensionNameMap.set(extension.name, extensionRep);
|
485
|
+
const hasConflict = this.conflicts.get(extension.name);
|
480
486
|
if (typeof hasConflict === "string") {
|
481
487
|
invariant(
|
482
488
|
false,
|
483
|
-
"LexicalBuilder:
|
484
|
-
|
489
|
+
"LexicalBuilder: extension %s conflicts with %s",
|
490
|
+
extension.name,
|
485
491
|
hasConflict
|
486
492
|
);
|
487
493
|
}
|
488
|
-
for (const name of
|
494
|
+
for (const name of extension.conflictsWith || []) {
|
489
495
|
invariant(
|
490
|
-
!this.
|
491
|
-
"LexicalBuilder:
|
492
|
-
|
496
|
+
!this.extensionNameMap.has(name),
|
497
|
+
"LexicalBuilder: extension %s conflicts with %s",
|
498
|
+
extension.name,
|
493
499
|
name
|
494
500
|
);
|
495
|
-
this.conflicts.set(name,
|
501
|
+
this.conflicts.set(name, extension.name);
|
496
502
|
}
|
497
|
-
for (const dep of
|
498
|
-
const normDep =
|
499
|
-
this.addEdge(
|
500
|
-
this.
|
503
|
+
for (const dep of extension.dependencies || []) {
|
504
|
+
const normDep = normalizeExtensionArgument(dep);
|
505
|
+
this.addEdge(extension.name, normDep[0].name, normDep.slice(1));
|
506
|
+
this.addExtension(normDep);
|
501
507
|
}
|
502
|
-
for (const [depName, config] of
|
503
|
-
this.addEdge(
|
508
|
+
for (const [depName, config] of extension.peerDependencies || []) {
|
509
|
+
this.addEdge(extension.name, depName, config ? [config] : []);
|
504
510
|
}
|
505
511
|
}
|
506
512
|
}
|
507
|
-
|
508
|
-
if (this.
|
509
|
-
return this.
|
513
|
+
sortedExtensionReps() {
|
514
|
+
if (this._sortedExtensionReps) {
|
515
|
+
return this._sortedExtensionReps;
|
510
516
|
}
|
511
|
-
const
|
512
|
-
const visit = (rep,
|
517
|
+
const sortedExtensionReps = [];
|
518
|
+
const visit = (rep, fromExtensionName) => {
|
513
519
|
let mark = rep.state;
|
514
|
-
if (
|
520
|
+
if (isExactlyPermanentExtensionRepState(mark)) {
|
515
521
|
return;
|
516
522
|
}
|
517
|
-
const
|
523
|
+
const extensionName = rep.extension.name;
|
518
524
|
invariant(
|
519
|
-
|
520
|
-
"LexicalBuilder: Circular dependency detected for
|
521
|
-
|
522
|
-
|
525
|
+
isExactlyUnmarkedExtensionRepState(mark),
|
526
|
+
"LexicalBuilder: Circular dependency detected for Extension %s from %s",
|
527
|
+
extensionName,
|
528
|
+
fromExtensionName || "[unknown]"
|
523
529
|
);
|
524
530
|
mark = applyTemporaryMark(mark);
|
525
531
|
rep.state = mark;
|
526
|
-
const outgoingConfigEdges = this.outgoingConfigEdges.get(
|
532
|
+
const outgoingConfigEdges = this.outgoingConfigEdges.get(extensionName);
|
527
533
|
if (outgoingConfigEdges) {
|
528
|
-
for (const
|
529
|
-
const toRep = this.
|
534
|
+
for (const toExtensionName of outgoingConfigEdges.keys()) {
|
535
|
+
const toRep = this.extensionNameMap.get(toExtensionName);
|
530
536
|
if (toRep) {
|
531
|
-
visit(toRep,
|
537
|
+
visit(toRep, extensionName);
|
532
538
|
}
|
533
539
|
}
|
534
540
|
}
|
535
541
|
mark = applyPermanentMark(mark);
|
536
542
|
rep.state = mark;
|
537
|
-
|
543
|
+
sortedExtensionReps.push(rep);
|
538
544
|
};
|
539
|
-
for (const rep of this.
|
540
|
-
if (
|
545
|
+
for (const rep of this.extensionNameMap.values()) {
|
546
|
+
if (isExactlyUnmarkedExtensionRepState(rep.state)) {
|
541
547
|
visit(rep);
|
542
548
|
}
|
543
549
|
}
|
544
|
-
for (const rep of
|
545
|
-
for (const [
|
546
|
-
rep.
|
550
|
+
for (const rep of sortedExtensionReps) {
|
551
|
+
for (const [toExtensionName, configs] of this.outgoingConfigEdges.get(
|
552
|
+
rep.extension.name
|
547
553
|
) || []) {
|
548
554
|
if (configs.length > 0) {
|
549
|
-
const toRep = this.
|
555
|
+
const toRep = this.extensionNameMap.get(toExtensionName);
|
550
556
|
if (toRep) {
|
551
557
|
for (const config of configs) {
|
552
558
|
toRep.configs.add(config);
|
@@ -555,33 +561,33 @@ class LexicalBuilder {
|
|
555
561
|
}
|
556
562
|
}
|
557
563
|
}
|
558
|
-
for (const [
|
564
|
+
for (const [extension, ...configs] of this.roots) {
|
559
565
|
if (configs.length > 0) {
|
560
|
-
const toRep = this.
|
566
|
+
const toRep = this.extensionNameMap.get(extension.name);
|
561
567
|
invariant(
|
562
568
|
toRep !== void 0,
|
563
|
-
"LexicalBuilder: Expecting existing
|
564
|
-
|
569
|
+
"LexicalBuilder: Expecting existing ExtensionRep for %s",
|
570
|
+
extension.name
|
565
571
|
);
|
566
572
|
for (const config of configs) {
|
567
573
|
toRep.configs.add(config);
|
568
574
|
}
|
569
575
|
}
|
570
576
|
}
|
571
|
-
this.
|
572
|
-
return this.
|
577
|
+
this._sortedExtensionReps = sortedExtensionReps;
|
578
|
+
return this._sortedExtensionReps;
|
573
579
|
}
|
574
580
|
registerEditor(editor, controller) {
|
575
581
|
const cleanups = [];
|
576
|
-
const
|
577
|
-
for (const
|
578
|
-
const cleanup =
|
582
|
+
const extensionReps = this.sortedExtensionReps();
|
583
|
+
for (const extensionRep of extensionReps) {
|
584
|
+
const cleanup = extensionRep.register(editor);
|
579
585
|
if (cleanup) {
|
580
586
|
cleanups.push(cleanup);
|
581
587
|
}
|
582
588
|
}
|
583
|
-
for (const
|
584
|
-
const cleanup =
|
589
|
+
for (const extensionRep of extensionReps) {
|
590
|
+
const cleanup = extensionRep.afterInitialization(editor);
|
585
591
|
if (cleanup) {
|
586
592
|
cleanups.push(cleanup);
|
587
593
|
}
|
@@ -607,57 +613,57 @@ class LexicalBuilder {
|
|
607
613
|
const htmlExport = /* @__PURE__ */ new Map();
|
608
614
|
const htmlImport = {};
|
609
615
|
const theme = {};
|
610
|
-
const
|
611
|
-
for (const
|
612
|
-
const {
|
613
|
-
if (
|
614
|
-
config.onError =
|
616
|
+
const extensionReps = this.sortedExtensionReps();
|
617
|
+
for (const extensionRep of extensionReps) {
|
618
|
+
const { extension } = extensionRep;
|
619
|
+
if (extension.onError !== void 0) {
|
620
|
+
config.onError = extension.onError;
|
615
621
|
}
|
616
|
-
if (
|
617
|
-
config.disableEvents =
|
622
|
+
if (extension.disableEvents !== void 0) {
|
623
|
+
config.disableEvents = extension.disableEvents;
|
618
624
|
}
|
619
|
-
if (
|
620
|
-
config.parentEditor =
|
625
|
+
if (extension.parentEditor !== void 0) {
|
626
|
+
config.parentEditor = extension.parentEditor;
|
621
627
|
}
|
622
|
-
if (
|
623
|
-
config.editable =
|
628
|
+
if (extension.editable !== void 0) {
|
629
|
+
config.editable = extension.editable;
|
624
630
|
}
|
625
|
-
if (
|
626
|
-
config.namespace =
|
631
|
+
if (extension.namespace !== void 0) {
|
632
|
+
config.namespace = extension.namespace;
|
627
633
|
}
|
628
|
-
if (
|
629
|
-
config.$initialEditorState =
|
634
|
+
if (extension.$initialEditorState !== void 0) {
|
635
|
+
config.$initialEditorState = extension.$initialEditorState;
|
630
636
|
}
|
631
|
-
if (
|
632
|
-
for (const node of
|
637
|
+
if (extension.nodes) {
|
638
|
+
for (const node of extension.nodes) {
|
633
639
|
if (typeof node !== "function") {
|
634
|
-
const
|
635
|
-
if (
|
640
|
+
const conflictExtension = replacedNodes.get(node.replace);
|
641
|
+
if (conflictExtension) {
|
636
642
|
invariant(
|
637
643
|
false,
|
638
|
-
"LexicalBuilder:
|
639
|
-
|
644
|
+
"LexicalBuilder: Extension %s can not register replacement for node %s because %s already did",
|
645
|
+
extension.name,
|
640
646
|
node.replace.name,
|
641
|
-
|
647
|
+
conflictExtension.extension.name
|
642
648
|
);
|
643
649
|
}
|
644
|
-
replacedNodes.set(node.replace,
|
650
|
+
replacedNodes.set(node.replace, extensionRep);
|
645
651
|
}
|
646
652
|
nodes.add(node);
|
647
653
|
}
|
648
654
|
}
|
649
|
-
if (
|
650
|
-
if (
|
651
|
-
for (const [k, v] of
|
655
|
+
if (extension.html) {
|
656
|
+
if (extension.html.export) {
|
657
|
+
for (const [k, v] of extension.html.export.entries()) {
|
652
658
|
htmlExport.set(k, v);
|
653
659
|
}
|
654
660
|
}
|
655
|
-
if (
|
656
|
-
Object.assign(htmlImport,
|
661
|
+
if (extension.html.import) {
|
662
|
+
Object.assign(htmlImport, extension.html.import);
|
657
663
|
}
|
658
664
|
}
|
659
|
-
if (
|
660
|
-
deepThemeMergeInPlace(theme,
|
665
|
+
if (extension.theme) {
|
666
|
+
deepThemeMergeInPlace(theme, extension.theme);
|
661
667
|
}
|
662
668
|
}
|
663
669
|
if (Object.keys(theme).length > 0) {
|
@@ -677,8 +683,8 @@ class LexicalBuilder {
|
|
677
683
|
config.html.export = htmlExport;
|
678
684
|
}
|
679
685
|
}
|
680
|
-
for (const
|
681
|
-
|
686
|
+
for (const extensionRep of extensionReps) {
|
687
|
+
extensionRep.init(config, signal);
|
682
688
|
}
|
683
689
|
if (!config.onError) {
|
684
690
|
config.onError = defaultOnError;
|
@@ -686,27 +692,27 @@ class LexicalBuilder {
|
|
686
692
|
return config;
|
687
693
|
}
|
688
694
|
}
|
689
|
-
function
|
695
|
+
function getExtensionDependencyFromEditor(editor, extension) {
|
690
696
|
const builder = LexicalBuilder.fromEditor(editor);
|
691
|
-
const rep = builder.
|
697
|
+
const rep = builder.getExtensionRep(extension);
|
692
698
|
invariant(
|
693
699
|
rep !== void 0,
|
694
|
-
"
|
695
|
-
|
700
|
+
"getExtensionDependencyFromEditor: Extension %s was not built when creating this editor",
|
701
|
+
extension.name
|
696
702
|
);
|
697
|
-
return rep.
|
703
|
+
return rep.getExtensionDependency();
|
698
704
|
}
|
699
|
-
function getPeerDependencyFromEditor(editor,
|
705
|
+
function getPeerDependencyFromEditor(editor, extensionName) {
|
700
706
|
const builder = LexicalBuilder.fromEditor(editor);
|
701
|
-
const peer = builder.
|
702
|
-
return peer ? peer.
|
707
|
+
const peer = builder.extensionNameMap.get(extensionName);
|
708
|
+
return peer ? peer.getExtensionDependency() : void 0;
|
703
709
|
}
|
704
|
-
function getPeerDependencyFromEditorOrThrow(editor,
|
705
|
-
const dep = getPeerDependencyFromEditor(editor,
|
710
|
+
function getPeerDependencyFromEditorOrThrow(editor, extensionName) {
|
711
|
+
const dep = getPeerDependencyFromEditor(editor, extensionName);
|
706
712
|
invariant(
|
707
713
|
dep !== void 0,
|
708
|
-
"getPeerDependencyFromEditorOrThrow: Editor was not
|
709
|
-
|
714
|
+
"getPeerDependencyFromEditorOrThrow: Editor was not built with Extension %s",
|
715
|
+
extensionName
|
710
716
|
);
|
711
717
|
return dep;
|
712
718
|
}
|
@@ -720,7 +726,7 @@ function getKnownTypesAndNodes(config) {
|
|
720
726
|
}
|
721
727
|
return { types, nodes };
|
722
728
|
}
|
723
|
-
const
|
729
|
+
const AutoFocusExtension = defineExtension({
|
724
730
|
config: safeCast({}),
|
725
731
|
name: "@etrepum/lexical-builder/AutoFocus",
|
726
732
|
register(editor, { defaultSelection }) {
|
@@ -797,7 +803,7 @@ function disabledToggle(opts) {
|
|
797
803
|
registerStoreToggle(disabled, (v) => !v, opts.register)
|
798
804
|
];
|
799
805
|
}
|
800
|
-
const
|
806
|
+
const DragonExtension = defineExtension({
|
801
807
|
name: "@lexical/dragon",
|
802
808
|
config: safeCast({ disabled: typeof window === "undefined" }),
|
803
809
|
register: (editor, config) => provideOutput(
|
@@ -807,7 +813,7 @@ const DragonPlan = definePlan({
|
|
807
813
|
})
|
808
814
|
)
|
809
815
|
});
|
810
|
-
const
|
816
|
+
const HistoryExtension = defineExtension({
|
811
817
|
config: safeCast({
|
812
818
|
createInitialHistoryState: createEmptyHistoryState,
|
813
819
|
delay: 300,
|
@@ -827,13 +833,13 @@ const HistoryPlan = definePlan({
|
|
827
833
|
}
|
828
834
|
});
|
829
835
|
function getHistoryPeer(editor) {
|
830
|
-
return editor ? getPeerDependencyFromEditor(editor,
|
836
|
+
return editor ? getPeerDependencyFromEditor(editor, HistoryExtension.name) : null;
|
831
837
|
}
|
832
|
-
const
|
838
|
+
const SharedHistoryExtension = defineExtension({
|
833
839
|
name: "@etrepum/lexical-builder/SharedHistory",
|
834
|
-
dependencies: [
|
840
|
+
dependencies: [configExtension(HistoryExtension, { disabled: true })],
|
835
841
|
init(editorConfig, _config, state) {
|
836
|
-
const { config } = state.getDependency(
|
842
|
+
const { config } = state.getDependency(HistoryExtension);
|
837
843
|
const parentPeer = getHistoryPeer(editorConfig.parentEditor);
|
838
844
|
if (parentPeer) {
|
839
845
|
config.delay = parentPeer.config.delay;
|
@@ -847,43 +853,43 @@ const SharedHistoryPlan = definePlan({
|
|
847
853
|
return () => {
|
848
854
|
};
|
849
855
|
}
|
850
|
-
const disabled = state.getDependency(
|
856
|
+
const disabled = state.getDependency(HistoryExtension).output.disabled;
|
851
857
|
return parentPeer.output.disabled.subscribe(disabled.set.bind(disabled));
|
852
858
|
}
|
853
859
|
});
|
854
|
-
const
|
860
|
+
const PlainTextExtension = defineExtension({
|
855
861
|
conflictsWith: ["@lexical/rich-text"],
|
856
862
|
name: "@lexical/plain-text",
|
857
|
-
dependencies: [
|
863
|
+
dependencies: [DragonExtension],
|
858
864
|
register: registerPlainText
|
859
865
|
});
|
860
|
-
const
|
866
|
+
const RichTextExtension = defineExtension({
|
861
867
|
conflictsWith: ["@lexical/plain-text"],
|
862
868
|
name: "@lexical/rich-text",
|
863
869
|
nodes: [HeadingNode, QuoteNode],
|
864
|
-
dependencies: [
|
870
|
+
dependencies: [DragonExtension],
|
865
871
|
register: registerRichText
|
866
872
|
});
|
867
873
|
export {
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
874
|
+
AutoFocusExtension,
|
875
|
+
DragonExtension,
|
876
|
+
HistoryExtension,
|
877
|
+
InitialStateExtension,
|
872
878
|
LexicalBuilder,
|
873
879
|
PACKAGE_VERSION,
|
874
|
-
|
875
|
-
|
876
|
-
|
880
|
+
PlainTextExtension,
|
881
|
+
RichTextExtension,
|
882
|
+
SharedHistoryExtension,
|
877
883
|
Store,
|
878
|
-
|
879
|
-
|
884
|
+
buildEditorFromExtensions,
|
885
|
+
configExtension2 as configExtension,
|
880
886
|
declarePeerDependency,
|
881
|
-
|
887
|
+
defineExtension2 as defineExtension,
|
882
888
|
disabledToggle,
|
889
|
+
getExtensionDependencyFromEditor,
|
883
890
|
getKnownTypesAndNodes,
|
884
891
|
getPeerDependencyFromEditor,
|
885
892
|
getPeerDependencyFromEditorOrThrow,
|
886
|
-
getPlanDependencyFromEditor,
|
887
893
|
provideOutput2 as provideOutput,
|
888
894
|
registerStoreToggle,
|
889
895
|
safeCast2 as safeCast,
|