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