@mx-space/cli 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 +33 -0
- package/README.md +375 -0
- package/ROADMAP.md +42 -0
- package/bin/mxs.cjs +40 -0
- package/dist/Lexical.dev-DpU35QTu.mjs +10992 -0
- package/dist/Lexical.dev-DpU35QTu.mjs.map +1 -0
- package/dist/Lexical.node-gYNDt_p9.mjs +247 -0
- package/dist/Lexical.node-gYNDt_p9.mjs.map +1 -0
- package/dist/Lexical.prod-t4c3bHV3.mjs +5579 -0
- package/dist/Lexical.prod-t4c3bHV3.mjs.map +1 -0
- package/dist/LexicalClipboard.dev-CdeeWCIq.mjs +496 -0
- package/dist/LexicalClipboard.dev-CdeeWCIq.mjs.map +1 -0
- package/dist/LexicalClipboard.node-0e9GBL1g.mjs +26 -0
- package/dist/LexicalClipboard.node-0e9GBL1g.mjs.map +1 -0
- package/dist/LexicalClipboard.prod-CsCWYmV7.mjs +293 -0
- package/dist/LexicalClipboard.prod-CsCWYmV7.mjs.map +1 -0
- package/dist/LexicalCodeCore.dev-haI2cqH8.mjs +539 -0
- package/dist/LexicalCodeCore.dev-haI2cqH8.mjs.map +1 -0
- package/dist/LexicalCodeCore.prod-D_k7zuE5.mjs +383 -0
- package/dist/LexicalCodeCore.prod-D_k7zuE5.mjs.map +1 -0
- package/dist/LexicalDragon.dev-CAggdFh_.mjs +90 -0
- package/dist/LexicalDragon.dev-CAggdFh_.mjs.map +1 -0
- package/dist/LexicalDragon.node-QMR_wqJg.mjs +15 -0
- package/dist/LexicalDragon.node-QMR_wqJg.mjs.map +1 -0
- package/dist/LexicalDragon.prod-OssQhwS-.mjs +61 -0
- package/dist/LexicalDragon.prod-OssQhwS-.mjs.map +1 -0
- package/dist/LexicalExtension.dev-CtDZiMCU.mjs +1665 -0
- package/dist/LexicalExtension.dev-CtDZiMCU.mjs.map +1 -0
- package/dist/LexicalExtension.node-BM0gh8zu.mjs +51 -0
- package/dist/LexicalExtension.node-BM0gh8zu.mjs.map +1 -0
- package/dist/LexicalExtension.prod-Ug6emhEO.mjs +971 -0
- package/dist/LexicalExtension.prod-Ug6emhEO.mjs.map +1 -0
- package/dist/LexicalHeadless.dev-D4yQpl_s.mjs +45 -0
- package/dist/LexicalHeadless.dev-D4yQpl_s.mjs.map +1 -0
- package/dist/LexicalHeadless.prod-jeN65B3k.mjs +31 -0
- package/dist/LexicalHeadless.prod-jeN65B3k.mjs.map +1 -0
- package/dist/LexicalHtml.dev-BdU1_ITQ.mjs +686 -0
- package/dist/LexicalHtml.dev-BdU1_ITQ.mjs.map +1 -0
- package/dist/LexicalHtml.node-DLtAh00E.mjs +26 -0
- package/dist/LexicalHtml.node-DLtAh00E.mjs.map +1 -0
- package/dist/LexicalHtml.prod-DdLE1HHT.mjs +432 -0
- package/dist/LexicalHtml.prod-DdLE1HHT.mjs.map +1 -0
- package/dist/LexicalLink.dev-DK87Biuy.mjs +1084 -0
- package/dist/LexicalLink.dev-DK87Biuy.mjs.map +1 -0
- package/dist/LexicalLink.prod-fssuv6Sf.mjs +717 -0
- package/dist/LexicalLink.prod-fssuv6Sf.mjs.map +1 -0
- package/dist/LexicalList.dev-BJ4dr_rk.mjs +1352 -0
- package/dist/LexicalList.dev-BJ4dr_rk.mjs.map +1 -0
- package/dist/LexicalList.prod-jWBbaWfi.mjs +841 -0
- package/dist/LexicalList.prod-jWBbaWfi.mjs.map +1 -0
- package/dist/LexicalMarkdown.dev-C8e-eh6y.mjs +1207 -0
- package/dist/LexicalMarkdown.dev-C8e-eh6y.mjs.map +1 -0
- package/dist/LexicalMarkdown.prod-k73tZVb2.mjs +756 -0
- package/dist/LexicalMarkdown.prod-k73tZVb2.mjs.map +1 -0
- package/dist/LexicalRichText.dev-CrSqq3K-.mjs +645 -0
- package/dist/LexicalRichText.dev-CrSqq3K-.mjs.map +1 -0
- package/dist/LexicalRichText.node-B7k7wlQz.mjs +106 -0
- package/dist/LexicalRichText.node-B7k7wlQz.mjs.map +1 -0
- package/dist/LexicalRichText.prod-CqvyxQ9m.mjs +429 -0
- package/dist/LexicalRichText.prod-CqvyxQ9m.mjs.map +1 -0
- package/dist/LexicalSelection.dev-sNOHKHe_.mjs +725 -0
- package/dist/LexicalSelection.dev-sNOHKHe_.mjs.map +1 -0
- package/dist/LexicalSelection.node-Di7GwBCZ.mjs +38 -0
- package/dist/LexicalSelection.node-Di7GwBCZ.mjs.map +1 -0
- package/dist/LexicalSelection.prod-SWllPJop.mjs +388 -0
- package/dist/LexicalSelection.prod-SWllPJop.mjs.map +1 -0
- package/dist/LexicalTable.dev-CQkLHXJx.mjs +3262 -0
- package/dist/LexicalTable.dev-CQkLHXJx.mjs.map +1 -0
- package/dist/LexicalTable.prod-BtqCwKSi.mjs +2218 -0
- package/dist/LexicalTable.prod-BtqCwKSi.mjs.map +1 -0
- package/dist/LexicalUtils.dev-DiUpsXE8.mjs +850 -0
- package/dist/LexicalUtils.dev-DiUpsXE8.mjs.map +1 -0
- package/dist/LexicalUtils.node-CmK462d1.mjs +66 -0
- package/dist/LexicalUtils.node-CmK462d1.mjs.map +1 -0
- package/dist/LexicalUtils.prod-bWwV4GAF.mjs +377 -0
- package/dist/LexicalUtils.prod-bWwV4GAF.mjs.map +1 -0
- package/dist/auth-DIFZzoMm.mjs +211 -0
- package/dist/auth-DIFZzoMm.mjs.map +1 -0
- package/dist/bin/mxs.d.mts +927 -0
- package/dist/bin/mxs.mjs +3249 -0
- package/dist/bin/mxs.mjs.map +1 -0
- package/dist/chunk-hT5z_Zn9.mjs +35 -0
- package/dist/config-store-DIu7x0ao.mjs +121 -0
- package/dist/config-store-DIu7x0ao.mjs.map +1 -0
- package/dist/create-B2AOQL1e.mjs +24 -0
- package/dist/create-B2AOQL1e.mjs.map +1 -0
- package/dist/create-CwjGcv2n.mjs +23 -0
- package/dist/create-CwjGcv2n.mjs.map +1 -0
- package/dist/create-DT1l2hue.mjs +23 -0
- package/dist/create-DT1l2hue.mjs.map +1 -0
- package/dist/create-DjlRHPXy.mjs +23 -0
- package/dist/create-DjlRHPXy.mjs.map +1 -0
- package/dist/create-Dz6rJJSS.mjs +19 -0
- package/dist/create-Dz6rJJSS.mjs.map +1 -0
- package/dist/delete-B4dGrrus.mjs +22 -0
- package/dist/delete-B4dGrrus.mjs.map +1 -0
- package/dist/delete-BH6ZngTz.mjs +22 -0
- package/dist/delete-BH6ZngTz.mjs.map +1 -0
- package/dist/delete-BrY5zJ6S.mjs +22 -0
- package/dist/delete-BrY5zJ6S.mjs.map +1 -0
- package/dist/delete-CaG2d_xt.mjs +31 -0
- package/dist/delete-CaG2d_xt.mjs.map +1 -0
- package/dist/delete-YzRliRn8.mjs +31 -0
- package/dist/delete-YzRliRn8.mjs.map +1 -0
- package/dist/document-output-BVB8emLt.mjs +145 -0
- package/dist/document-output-BVB8emLt.mjs.map +1 -0
- package/dist/edit-Bb0Ze4w6.mjs +79 -0
- package/dist/edit-Bb0Ze4w6.mjs.map +1 -0
- package/dist/edit-BeFmC3XD.mjs +80 -0
- package/dist/edit-BeFmC3XD.mjs.map +1 -0
- package/dist/edit-DLDw_ZWX.mjs +86 -0
- package/dist/edit-DLDw_ZWX.mjs.map +1 -0
- package/dist/edit-z55ofr1S.mjs +40 -0
- package/dist/edit-z55ofr1S.mjs.map +1 -0
- package/dist/editor-xrF-j3UE.mjs +42 -0
- package/dist/editor-xrF-j3UE.mjs.map +1 -0
- package/dist/envelope-overlays-DPAlMNW1.mjs +26 -0
- package/dist/envelope-overlays-DPAlMNW1.mjs.map +1 -0
- package/dist/get-2qjq0wgG.mjs +28 -0
- package/dist/get-2qjq0wgG.mjs.map +1 -0
- package/dist/get-BGAk1Zmv.mjs +14 -0
- package/dist/get-BGAk1Zmv.mjs.map +1 -0
- package/dist/get-CRR13lgj.mjs +10 -0
- package/dist/get-CRR13lgj.mjs.map +1 -0
- package/dist/get-ClkpDBTL.mjs +13 -0
- package/dist/get-ClkpDBTL.mjs.map +1 -0
- package/dist/get-DJfUJ3sP.mjs +10 -0
- package/dist/get-DJfUJ3sP.mjs.map +1 -0
- package/dist/get-DiqaQvoS.mjs +14 -0
- package/dist/get-DiqaQvoS.mjs.map +1 -0
- package/dist/index.d.mts +338 -0
- package/dist/index.mjs +10 -0
- package/dist/list-BYzhflDg.mjs +14 -0
- package/dist/list-BYzhflDg.mjs.map +1 -0
- package/dist/list-DY-tPNG-.mjs +10 -0
- package/dist/list-DY-tPNG-.mjs.map +1 -0
- package/dist/list-DlQSkbqx.mjs +10 -0
- package/dist/list-DlQSkbqx.mjs.map +1 -0
- package/dist/list-DsrA5wIz.mjs +15 -0
- package/dist/list-DsrA5wIz.mjs.map +1 -0
- package/dist/list-Fp4nKfQb.mjs +10 -0
- package/dist/list-Fp4nKfQb.mjs.map +1 -0
- package/dist/list-s_tloiEX.mjs +10 -0
- package/dist/list-s_tloiEX.mjs.map +1 -0
- package/dist/litexml-codec-CDoRloiR.mjs +13451 -0
- package/dist/litexml-codec-CDoRloiR.mjs.map +1 -0
- package/dist/login-CLOJ-fTJ.mjs +579 -0
- package/dist/login-CLOJ-fTJ.mjs.map +1 -0
- package/dist/logout-v8ihxsim.mjs +11 -0
- package/dist/logout-v8ihxsim.mjs.map +1 -0
- package/dist/onboarding-640IldLz.mjs +888 -0
- package/dist/onboarding-640IldLz.mjs.map +1 -0
- package/dist/output-BM7aBFwt.mjs +120 -0
- package/dist/output-BM7aBFwt.mjs.map +1 -0
- package/dist/output-CTnO1lYt.d.mts +16 -0
- package/dist/payload-CN11pUto.mjs +547 -0
- package/dist/payload-CN11pUto.mjs.map +1 -0
- package/dist/publish-DkTYB-eK.mjs +23 -0
- package/dist/publish-DkTYB-eK.mjs.map +1 -0
- package/dist/publish-pRBfTJfe.mjs +23 -0
- package/dist/publish-pRBfTJfe.mjs.map +1 -0
- package/dist/resolve-BogJOR7R.mjs +119 -0
- package/dist/resolve-BogJOR7R.mjs.map +1 -0
- package/dist/resolve-Bp1AfBmM.mjs +26 -0
- package/dist/resolve-Bp1AfBmM.mjs.map +1 -0
- package/dist/resolve-Bw5Po9yK.mjs +16 -0
- package/dist/resolve-Bw5Po9yK.mjs.map +1 -0
- package/dist/resolve-CyjMlaoJ.mjs +23 -0
- package/dist/resolve-CyjMlaoJ.mjs.map +1 -0
- package/dist/resolve-helpers-CahPoJ0Y.mjs +30 -0
- package/dist/resolve-helpers-CahPoJ0Y.mjs.map +1 -0
- package/dist/set-BEGQz2si.mjs +43 -0
- package/dist/set-BEGQz2si.mjs.map +1 -0
- package/dist/shared-D0HVBDHI.mjs +39 -0
- package/dist/shared-D0HVBDHI.mjs.map +1 -0
- package/dist/status-LXrN9fI-.mjs +22 -0
- package/dist/status-LXrN9fI-.mjs.map +1 -0
- package/dist/update-B9ynFCdZ.mjs +30 -0
- package/dist/update-B9ynFCdZ.mjs.map +1 -0
- package/dist/update-BMZQPOvR.mjs +28 -0
- package/dist/update-BMZQPOvR.mjs.map +1 -0
- package/dist/update-BXz0l7Lz.mjs +36 -0
- package/dist/update-BXz0l7Lz.mjs.map +1 -0
- package/dist/update-Dx6AF8tf.mjs +30 -0
- package/dist/update-Dx6AF8tf.mjs.map +1 -0
- package/dist/update-q66TLS38.mjs +37 -0
- package/dist/update-q66TLS38.mjs.map +1 -0
- package/dist/whoami-CTkctOEd.mjs +22 -0
- package/dist/whoami-CTkctOEd.mjs.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,1665 @@
|
|
|
1
|
+
import { $n as safeCast, An as createState, At as COMMAND_PRIORITY_LOW, Cn as TabNode, Dn as configExtension, Dt as COMMAND_PRIORITY_CRITICAL, G as $isBlockElementNode, Gt as FORMAT_TEXT_COMMAND, Hn as isDOMNode, I as $getNodeFromDOMNode, In as getStaticNodeConfig, J as $isEditorState, Mn as defineExtension, On as createCommand, Ot as COMMAND_PRIORITY_EDITOR, P as $getNodeByKey, Qn as removeClassNamesFromElement, Qt as INSERT_TAB_COMMAND, R as $getRoot, Sn as TEXT_TYPE_TO_FORMAT, Tn as addClassNamesToElement, Tt as CLICK_COMMAND, V as $getState, Vt as DecoratorNode, Xn as mergeRegister, Yt as INDENT_CONTENT_COMMAND, bt as $setState, d as $createNodeSelection, dn as OUTDENT_CONTENT_COMMAND, f as $createParagraphNode, ft as $normalizeSelection__EXPERIMENTAL, gn as RootNode, ir as toggleTextFormatType, j as $getEditor, jn as declarePeerDependency, kn as createEditor, l as $create, ln as KEY_TAB_COMMAND, m as $createRangeSelection, mn as ParagraphNode, qt as HISTORY_MERGE_TAG, rr as shallowMergeConfig, rt as $isRangeSelection, tt as $isNodeSelection, un as LineBreakNode, vt as $setSelection, wn as TextNode, wt as CLEAR_EDITOR_COMMAND, z as $getSelection } from "./Lexical.node-gYNDt_p9.mjs";
|
|
2
|
+
import { c as $insertNodeToNearestRoot, i as $getNearestBlockElementAncestorOrThrow, o as $handleIndentAndOutdent, v as selectionAlwaysOnDisplay } from "./LexicalUtils.node-CmK462d1.mjs";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@lexical+extension@0.44.0/node_modules/@lexical/extension/LexicalExtension.dev.mjs
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
const i = Symbol.for("preact-signals");
|
|
12
|
+
function t() {
|
|
13
|
+
if (e > 1) {
|
|
14
|
+
e--;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let i, t = false;
|
|
18
|
+
(function() {
|
|
19
|
+
let i = r;
|
|
20
|
+
r = void 0;
|
|
21
|
+
while (void 0 !== i) {
|
|
22
|
+
if (i.S.v === i.v) i.S.i = i.i;
|
|
23
|
+
i = i.o;
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
while (void 0 !== s) {
|
|
27
|
+
let n = s;
|
|
28
|
+
s = void 0;
|
|
29
|
+
u++;
|
|
30
|
+
while (void 0 !== n) {
|
|
31
|
+
const o = n.u;
|
|
32
|
+
n.u = void 0;
|
|
33
|
+
n.f &= -3;
|
|
34
|
+
if (!(8 & n.f) && w(n)) try {
|
|
35
|
+
n.c();
|
|
36
|
+
} catch (n) {
|
|
37
|
+
if (!t) {
|
|
38
|
+
i = n;
|
|
39
|
+
t = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
n = o;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
u = 0;
|
|
46
|
+
e--;
|
|
47
|
+
if (t) throw i;
|
|
48
|
+
}
|
|
49
|
+
function n(i) {
|
|
50
|
+
if (e > 0) return i();
|
|
51
|
+
d = ++c;
|
|
52
|
+
e++;
|
|
53
|
+
try {
|
|
54
|
+
return i();
|
|
55
|
+
} finally {
|
|
56
|
+
t();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let o, s;
|
|
60
|
+
function h(i) {
|
|
61
|
+
const t = o;
|
|
62
|
+
o = void 0;
|
|
63
|
+
try {
|
|
64
|
+
return i();
|
|
65
|
+
} finally {
|
|
66
|
+
o = t;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let r, e = 0, u = 0, c = 0, d = 0, v = 0;
|
|
70
|
+
function l(i) {
|
|
71
|
+
if (void 0 === o) return;
|
|
72
|
+
let t = i.n;
|
|
73
|
+
if (void 0 === t || t.t !== o) {
|
|
74
|
+
t = {
|
|
75
|
+
i: 0,
|
|
76
|
+
S: i,
|
|
77
|
+
p: o.s,
|
|
78
|
+
n: void 0,
|
|
79
|
+
t: o,
|
|
80
|
+
e: void 0,
|
|
81
|
+
x: void 0,
|
|
82
|
+
r: t
|
|
83
|
+
};
|
|
84
|
+
if (void 0 !== o.s) o.s.n = t;
|
|
85
|
+
o.s = t;
|
|
86
|
+
i.n = t;
|
|
87
|
+
if (32 & o.f) i.S(t);
|
|
88
|
+
return t;
|
|
89
|
+
} else if (-1 === t.i) {
|
|
90
|
+
t.i = 0;
|
|
91
|
+
if (void 0 !== t.n) {
|
|
92
|
+
t.n.p = t.p;
|
|
93
|
+
if (void 0 !== t.p) t.p.n = t.n;
|
|
94
|
+
t.p = o.s;
|
|
95
|
+
t.n = void 0;
|
|
96
|
+
o.s.n = t;
|
|
97
|
+
o.s = t;
|
|
98
|
+
}
|
|
99
|
+
return t;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function y(i, t) {
|
|
103
|
+
this.v = i;
|
|
104
|
+
this.i = 0;
|
|
105
|
+
this.n = void 0;
|
|
106
|
+
this.t = void 0;
|
|
107
|
+
this.l = 0;
|
|
108
|
+
this.W = null == t ? void 0 : t.watched;
|
|
109
|
+
this.Z = null == t ? void 0 : t.unwatched;
|
|
110
|
+
this.name = null == t ? void 0 : t.name;
|
|
111
|
+
}
|
|
112
|
+
y.prototype.brand = i;
|
|
113
|
+
y.prototype.h = function() {
|
|
114
|
+
return true;
|
|
115
|
+
};
|
|
116
|
+
y.prototype.S = function(i) {
|
|
117
|
+
const t = this.t;
|
|
118
|
+
if (t !== i && void 0 === i.e) {
|
|
119
|
+
i.x = t;
|
|
120
|
+
this.t = i;
|
|
121
|
+
if (void 0 !== t) t.e = i;
|
|
122
|
+
else h(() => {
|
|
123
|
+
var i;
|
|
124
|
+
null == (i = this.W) || i.call(this);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
y.prototype.U = function(i) {
|
|
129
|
+
if (void 0 !== this.t) {
|
|
130
|
+
const t = i.e, n = i.x;
|
|
131
|
+
if (void 0 !== t) {
|
|
132
|
+
t.x = n;
|
|
133
|
+
i.e = void 0;
|
|
134
|
+
}
|
|
135
|
+
if (void 0 !== n) {
|
|
136
|
+
n.e = t;
|
|
137
|
+
i.x = void 0;
|
|
138
|
+
}
|
|
139
|
+
if (i === this.t) {
|
|
140
|
+
this.t = n;
|
|
141
|
+
if (void 0 === n) h(() => {
|
|
142
|
+
var i;
|
|
143
|
+
null == (i = this.Z) || i.call(this);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
y.prototype.subscribe = function(i) {
|
|
149
|
+
return j(() => {
|
|
150
|
+
const t = this.value, n = o;
|
|
151
|
+
o = void 0;
|
|
152
|
+
try {
|
|
153
|
+
i(t);
|
|
154
|
+
} finally {
|
|
155
|
+
o = n;
|
|
156
|
+
}
|
|
157
|
+
}, { name: "sub" });
|
|
158
|
+
};
|
|
159
|
+
y.prototype.valueOf = function() {
|
|
160
|
+
return this.value;
|
|
161
|
+
};
|
|
162
|
+
y.prototype.toString = function() {
|
|
163
|
+
return this.value + "";
|
|
164
|
+
};
|
|
165
|
+
y.prototype.toJSON = function() {
|
|
166
|
+
return this.value;
|
|
167
|
+
};
|
|
168
|
+
y.prototype.peek = function() {
|
|
169
|
+
const i = o;
|
|
170
|
+
o = void 0;
|
|
171
|
+
try {
|
|
172
|
+
return this.value;
|
|
173
|
+
} finally {
|
|
174
|
+
o = i;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
Object.defineProperty(y.prototype, "value", {
|
|
178
|
+
get() {
|
|
179
|
+
const i = l(this);
|
|
180
|
+
if (void 0 !== i) i.i = this.i;
|
|
181
|
+
return this.v;
|
|
182
|
+
},
|
|
183
|
+
set(i) {
|
|
184
|
+
if (i !== this.v) {
|
|
185
|
+
if (u > 100) throw new Error("Cycle detected");
|
|
186
|
+
(function(i) {
|
|
187
|
+
if (0 !== e && 0 === u) {
|
|
188
|
+
if (i.l !== d) {
|
|
189
|
+
i.l = d;
|
|
190
|
+
r = {
|
|
191
|
+
S: i,
|
|
192
|
+
v: i.v,
|
|
193
|
+
i: i.i,
|
|
194
|
+
o: r
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
})(this);
|
|
199
|
+
this.v = i;
|
|
200
|
+
this.i++;
|
|
201
|
+
v++;
|
|
202
|
+
e++;
|
|
203
|
+
try {
|
|
204
|
+
for (let i = this.t; void 0 !== i; i = i.x) i.t.N();
|
|
205
|
+
} finally {
|
|
206
|
+
t();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
function a(i, t) {
|
|
212
|
+
return new y(i, t);
|
|
213
|
+
}
|
|
214
|
+
function w(i) {
|
|
215
|
+
for (let t = i.s; void 0 !== t; t = t.n) if (t.S.i !== t.i || !t.S.h() || t.S.i !== t.i) return true;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
function _(i) {
|
|
219
|
+
for (let t = i.s; void 0 !== t; t = t.n) {
|
|
220
|
+
const n = t.S.n;
|
|
221
|
+
if (void 0 !== n) t.r = n;
|
|
222
|
+
t.S.n = t;
|
|
223
|
+
t.i = -1;
|
|
224
|
+
if (void 0 === t.n) {
|
|
225
|
+
i.s = t;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function b(i) {
|
|
231
|
+
let t, n = i.s;
|
|
232
|
+
while (void 0 !== n) {
|
|
233
|
+
const i = n.p;
|
|
234
|
+
if (-1 === n.i) {
|
|
235
|
+
n.S.U(n);
|
|
236
|
+
if (void 0 !== i) i.n = n.n;
|
|
237
|
+
if (void 0 !== n.n) n.n.p = i;
|
|
238
|
+
} else t = n;
|
|
239
|
+
n.S.n = n.r;
|
|
240
|
+
if (void 0 !== n.r) n.r = void 0;
|
|
241
|
+
n = i;
|
|
242
|
+
}
|
|
243
|
+
i.s = t;
|
|
244
|
+
}
|
|
245
|
+
function p(i, t) {
|
|
246
|
+
y.call(this, void 0);
|
|
247
|
+
this.x = i;
|
|
248
|
+
this.s = void 0;
|
|
249
|
+
this.g = v - 1;
|
|
250
|
+
this.f = 4;
|
|
251
|
+
this.W = null == t ? void 0 : t.watched;
|
|
252
|
+
this.Z = null == t ? void 0 : t.unwatched;
|
|
253
|
+
this.name = null == t ? void 0 : t.name;
|
|
254
|
+
}
|
|
255
|
+
p.prototype = new y();
|
|
256
|
+
p.prototype.h = function() {
|
|
257
|
+
this.f &= -3;
|
|
258
|
+
if (1 & this.f) return false;
|
|
259
|
+
if (32 == (36 & this.f)) return true;
|
|
260
|
+
this.f &= -5;
|
|
261
|
+
if (this.g === v) return true;
|
|
262
|
+
this.g = v;
|
|
263
|
+
this.f |= 1;
|
|
264
|
+
if (this.i > 0 && !w(this)) {
|
|
265
|
+
this.f &= -2;
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
const i = o;
|
|
269
|
+
try {
|
|
270
|
+
_(this);
|
|
271
|
+
o = this;
|
|
272
|
+
const i = this.x();
|
|
273
|
+
if (16 & this.f || this.v !== i || 0 === this.i) {
|
|
274
|
+
this.v = i;
|
|
275
|
+
this.f &= -17;
|
|
276
|
+
this.i++;
|
|
277
|
+
}
|
|
278
|
+
} catch (i) {
|
|
279
|
+
this.v = i;
|
|
280
|
+
this.f |= 16;
|
|
281
|
+
this.i++;
|
|
282
|
+
}
|
|
283
|
+
o = i;
|
|
284
|
+
b(this);
|
|
285
|
+
this.f &= -2;
|
|
286
|
+
return true;
|
|
287
|
+
};
|
|
288
|
+
p.prototype.S = function(i) {
|
|
289
|
+
if (void 0 === this.t) {
|
|
290
|
+
this.f |= 36;
|
|
291
|
+
for (let i = this.s; void 0 !== i; i = i.n) i.S.S(i);
|
|
292
|
+
}
|
|
293
|
+
y.prototype.S.call(this, i);
|
|
294
|
+
};
|
|
295
|
+
p.prototype.U = function(i) {
|
|
296
|
+
if (void 0 !== this.t) {
|
|
297
|
+
y.prototype.U.call(this, i);
|
|
298
|
+
if (void 0 === this.t) {
|
|
299
|
+
this.f &= -33;
|
|
300
|
+
for (let i = this.s; void 0 !== i; i = i.n) i.S.U(i);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
p.prototype.N = function() {
|
|
305
|
+
if (!(2 & this.f)) {
|
|
306
|
+
this.f |= 6;
|
|
307
|
+
for (let i = this.t; void 0 !== i; i = i.x) i.t.N();
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
Object.defineProperty(p.prototype, "value", { get() {
|
|
311
|
+
if (1 & this.f) throw new Error("Cycle detected");
|
|
312
|
+
const i = l(this);
|
|
313
|
+
this.h();
|
|
314
|
+
if (void 0 !== i) i.i = this.i;
|
|
315
|
+
if (16 & this.f) throw this.v;
|
|
316
|
+
return this.v;
|
|
317
|
+
} });
|
|
318
|
+
function g(i, t) {
|
|
319
|
+
return new p(i, t);
|
|
320
|
+
}
|
|
321
|
+
function S(i) {
|
|
322
|
+
const n = i.m;
|
|
323
|
+
i.m = void 0;
|
|
324
|
+
if ("function" == typeof n) {
|
|
325
|
+
e++;
|
|
326
|
+
const s = o;
|
|
327
|
+
o = void 0;
|
|
328
|
+
try {
|
|
329
|
+
n();
|
|
330
|
+
} catch (t) {
|
|
331
|
+
i.f &= -2;
|
|
332
|
+
i.f |= 8;
|
|
333
|
+
m(i);
|
|
334
|
+
throw t;
|
|
335
|
+
} finally {
|
|
336
|
+
o = s;
|
|
337
|
+
t();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function m(i) {
|
|
342
|
+
for (let t = i.s; void 0 !== t; t = t.n) t.S.U(t);
|
|
343
|
+
i.x = void 0;
|
|
344
|
+
i.s = void 0;
|
|
345
|
+
S(i);
|
|
346
|
+
}
|
|
347
|
+
function x(i) {
|
|
348
|
+
if (o !== this) throw new Error("Out-of-order effect");
|
|
349
|
+
b(this);
|
|
350
|
+
o = i;
|
|
351
|
+
this.f &= -2;
|
|
352
|
+
if (8 & this.f) m(this);
|
|
353
|
+
t();
|
|
354
|
+
}
|
|
355
|
+
function E(i, t) {
|
|
356
|
+
this.x = i;
|
|
357
|
+
this.m = void 0;
|
|
358
|
+
this.s = void 0;
|
|
359
|
+
this.u = void 0;
|
|
360
|
+
this.f = 32;
|
|
361
|
+
this.name = null == t ? void 0 : t.name;
|
|
362
|
+
}
|
|
363
|
+
E.prototype.c = function() {
|
|
364
|
+
const i = this.S();
|
|
365
|
+
try {
|
|
366
|
+
if (8 & this.f) return;
|
|
367
|
+
if (void 0 === this.x) return;
|
|
368
|
+
const t = this.x();
|
|
369
|
+
if ("function" == typeof t) this.m = t;
|
|
370
|
+
} finally {
|
|
371
|
+
i();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
E.prototype.S = function() {
|
|
375
|
+
if (1 & this.f) throw new Error("Cycle detected");
|
|
376
|
+
this.f |= 1;
|
|
377
|
+
this.f &= -9;
|
|
378
|
+
S(this);
|
|
379
|
+
_(this);
|
|
380
|
+
e++;
|
|
381
|
+
const i = o;
|
|
382
|
+
o = this;
|
|
383
|
+
return x.bind(this, i);
|
|
384
|
+
};
|
|
385
|
+
E.prototype.N = function() {
|
|
386
|
+
if (!(2 & this.f)) {
|
|
387
|
+
this.f |= 2;
|
|
388
|
+
this.u = s;
|
|
389
|
+
s = this;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
E.prototype.d = function() {
|
|
393
|
+
this.f |= 8;
|
|
394
|
+
if (!(1 & this.f)) m(this);
|
|
395
|
+
};
|
|
396
|
+
E.prototype.dispose = function() {
|
|
397
|
+
this.d();
|
|
398
|
+
};
|
|
399
|
+
function j(i, t) {
|
|
400
|
+
const n = new E(i, t);
|
|
401
|
+
try {
|
|
402
|
+
n.c();
|
|
403
|
+
} catch (i) {
|
|
404
|
+
n.d();
|
|
405
|
+
throw i;
|
|
406
|
+
}
|
|
407
|
+
const o = n.d.bind(n);
|
|
408
|
+
o[Symbol.dispose] = o;
|
|
409
|
+
return o;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
413
|
+
*
|
|
414
|
+
* This source code is licensed under the MIT license found in the
|
|
415
|
+
* LICENSE file in the root directory of this source tree.
|
|
416
|
+
*
|
|
417
|
+
*/
|
|
418
|
+
/**
|
|
419
|
+
* Return an object with the same shape as `defaults` with a {@link Signal}
|
|
420
|
+
* for each value. If specified, the second `opts` argument is a partial
|
|
421
|
+
* of overrides to the defaults and will be used as the initial value.
|
|
422
|
+
*
|
|
423
|
+
* Typically used to make a reactive version of some subset of the
|
|
424
|
+
* configuration of an extension, so it can be reconfigured at runtime.
|
|
425
|
+
*
|
|
426
|
+
* @param defaults The object with default values
|
|
427
|
+
* @param opts Overrides to those default values
|
|
428
|
+
* @returns An object with signals initialized with the default values
|
|
429
|
+
*/
|
|
430
|
+
function namedSignals(defaults, opts = {}) {
|
|
431
|
+
const initial = {};
|
|
432
|
+
for (const k in defaults) {
|
|
433
|
+
const v = opts[k];
|
|
434
|
+
initial[k] = a(v === void 0 ? defaults[k] : v);
|
|
435
|
+
}
|
|
436
|
+
return initial;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
440
|
+
*
|
|
441
|
+
* This source code is licensed under the MIT license found in the
|
|
442
|
+
* LICENSE file in the root directory of this source tree.
|
|
443
|
+
*
|
|
444
|
+
*/
|
|
445
|
+
/**
|
|
446
|
+
* An Extension to focus the LexicalEditor when the root element is set
|
|
447
|
+
* (typically only when the editor is first created).
|
|
448
|
+
*/
|
|
449
|
+
const AutoFocusExtension = defineExtension({
|
|
450
|
+
build: (editor, config, state) => {
|
|
451
|
+
return namedSignals(config);
|
|
452
|
+
},
|
|
453
|
+
config: safeCast({
|
|
454
|
+
defaultSelection: "rootEnd",
|
|
455
|
+
disabled: false
|
|
456
|
+
}),
|
|
457
|
+
name: "@lexical/extension/AutoFocus",
|
|
458
|
+
register(editor, config, state) {
|
|
459
|
+
const stores = state.getOutput();
|
|
460
|
+
return j(() => stores.disabled.value ? void 0 : editor.registerRootListener((rootElement) => {
|
|
461
|
+
editor.focus(() => {
|
|
462
|
+
const activeElement = document.activeElement;
|
|
463
|
+
if (rootElement !== null && (activeElement === null || !rootElement.contains(activeElement))) rootElement.focus({ preventScroll: true });
|
|
464
|
+
}, { defaultSelection: stores.defaultSelection.peek() });
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
/**
|
|
469
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
470
|
+
*
|
|
471
|
+
* This source code is licensed under the MIT license found in the
|
|
472
|
+
* LICENSE file in the root directory of this source tree.
|
|
473
|
+
*
|
|
474
|
+
*/
|
|
475
|
+
function $defaultOnClear() {
|
|
476
|
+
const root = $getRoot();
|
|
477
|
+
const selection = $getSelection();
|
|
478
|
+
const paragraph = $createParagraphNode();
|
|
479
|
+
root.clear();
|
|
480
|
+
root.append(paragraph);
|
|
481
|
+
if (selection !== null) paragraph.select();
|
|
482
|
+
if ($isRangeSelection(selection)) selection.format = 0;
|
|
483
|
+
}
|
|
484
|
+
function registerClearEditor(editor, $onClear = $defaultOnClear) {
|
|
485
|
+
return editor.registerCommand(CLEAR_EDITOR_COMMAND, (payload) => {
|
|
486
|
+
editor.update($onClear);
|
|
487
|
+
return true;
|
|
488
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* An extension to provide an implementation of {@link CLEAR_EDITOR_COMMAND}
|
|
492
|
+
*/
|
|
493
|
+
const ClearEditorExtension = defineExtension({
|
|
494
|
+
build(editor, config, state) {
|
|
495
|
+
return namedSignals(config);
|
|
496
|
+
},
|
|
497
|
+
config: safeCast({ $onClear: $defaultOnClear }),
|
|
498
|
+
name: "@lexical/extension/ClearEditor",
|
|
499
|
+
register(editor, config, state) {
|
|
500
|
+
const { $onClear } = state.getOutput();
|
|
501
|
+
return j(() => registerClearEditor(editor, $onClear.value));
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
/**
|
|
505
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
506
|
+
*
|
|
507
|
+
* This source code is licensed under the MIT license found in the
|
|
508
|
+
* LICENSE file in the root directory of this source tree.
|
|
509
|
+
*
|
|
510
|
+
*/
|
|
511
|
+
/**
|
|
512
|
+
* Get the sets of nodes and types registered in the
|
|
513
|
+
* {@link InitialEditorConfig}. This is to be used when an extension
|
|
514
|
+
* needs to register optional behavior if some node or type is present.
|
|
515
|
+
*
|
|
516
|
+
* @param config The InitialEditorConfig (accessible from an extension's init)
|
|
517
|
+
* @returns The known types and nodes as Sets
|
|
518
|
+
*/
|
|
519
|
+
function getKnownTypesAndNodes(config) {
|
|
520
|
+
const types = /* @__PURE__ */ new Set();
|
|
521
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
522
|
+
for (const klassOrReplacement of getNodeConfig(config)) {
|
|
523
|
+
const klass = typeof klassOrReplacement === "function" ? klassOrReplacement : klassOrReplacement.replace;
|
|
524
|
+
getStaticNodeConfig(klass);
|
|
525
|
+
types.add(klass.getType());
|
|
526
|
+
nodes.add(klass);
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
nodes,
|
|
530
|
+
types
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function getNodeConfig(config) {
|
|
534
|
+
return (typeof config.nodes === "function" ? config.nodes() : config.nodes) || [];
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
538
|
+
*
|
|
539
|
+
* This source code is licensed under the MIT license found in the
|
|
540
|
+
* LICENSE file in the root directory of this source tree.
|
|
541
|
+
*
|
|
542
|
+
*/
|
|
543
|
+
const formatState = createState("format", { parse: (value) => typeof value === "number" ? value : 0 });
|
|
544
|
+
var DecoratorTextNode = class extends DecoratorNode {
|
|
545
|
+
$config() {
|
|
546
|
+
return this.config("decorator-text", {
|
|
547
|
+
extends: DecoratorNode,
|
|
548
|
+
stateConfigs: [{
|
|
549
|
+
flat: true,
|
|
550
|
+
stateConfig: formatState
|
|
551
|
+
}]
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
getFormat() {
|
|
555
|
+
return $getState(this, formatState);
|
|
556
|
+
}
|
|
557
|
+
getFormatFlags(type, alignWithFormat) {
|
|
558
|
+
return toggleTextFormatType(this.getFormat(), type, alignWithFormat);
|
|
559
|
+
}
|
|
560
|
+
hasFormat(type) {
|
|
561
|
+
const formatFlag = TEXT_TYPE_TO_FORMAT[type];
|
|
562
|
+
return (this.getFormat() & formatFlag) !== 0;
|
|
563
|
+
}
|
|
564
|
+
setFormat(type) {
|
|
565
|
+
return $setState(this, formatState, type);
|
|
566
|
+
}
|
|
567
|
+
toggleFormat(type) {
|
|
568
|
+
const newFormat = toggleTextFormatType(this.getFormat(), type, null);
|
|
569
|
+
return this.setFormat(newFormat);
|
|
570
|
+
}
|
|
571
|
+
isInline() {
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
createDOM() {
|
|
575
|
+
return document.createElement("span");
|
|
576
|
+
}
|
|
577
|
+
updateDOM() {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
function $isDecoratorTextNode(node) {
|
|
582
|
+
return node instanceof DecoratorTextNode;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Applies formatting to the node based on the properties in the passed style object.
|
|
586
|
+
* By default, properties are checked according to the values set
|
|
587
|
+
* when importing content from Google Docs.
|
|
588
|
+
* This algorithm is identical to the TextNode import.
|
|
589
|
+
|
|
590
|
+
* @param lexicalNode The node to which the format will apply
|
|
591
|
+
* @param style CSS style object
|
|
592
|
+
* @param shouldApply format to apply if it is not in style
|
|
593
|
+
* @returns lexicalNode
|
|
594
|
+
*/
|
|
595
|
+
function applyFormatFromStyle(lexicalNode, style, shouldApply) {
|
|
596
|
+
const fontWeight = style.fontWeight;
|
|
597
|
+
const textDecoration = style.textDecoration.split(" ");
|
|
598
|
+
const hasBoldFontWeight = fontWeight === "700" || fontWeight === "bold";
|
|
599
|
+
const hasLinethroughTextDecoration = textDecoration.includes("line-through");
|
|
600
|
+
const hasItalicFontStyle = style.fontStyle === "italic";
|
|
601
|
+
const hasUnderlineTextDecoration = textDecoration.includes("underline");
|
|
602
|
+
const verticalAlign = style.verticalAlign;
|
|
603
|
+
if (hasBoldFontWeight && !lexicalNode.hasFormat("bold")) lexicalNode.toggleFormat("bold");
|
|
604
|
+
if (hasLinethroughTextDecoration && !lexicalNode.hasFormat("strikethrough")) lexicalNode.toggleFormat("strikethrough");
|
|
605
|
+
if (hasItalicFontStyle && !lexicalNode.hasFormat("italic")) lexicalNode.toggleFormat("italic");
|
|
606
|
+
if (hasUnderlineTextDecoration && !lexicalNode.hasFormat("underline")) lexicalNode.toggleFormat("underline");
|
|
607
|
+
if (verticalAlign === "sub" && !lexicalNode.hasFormat("subscript")) lexicalNode.toggleFormat("subscript");
|
|
608
|
+
if (verticalAlign === "super" && !lexicalNode.hasFormat("superscript")) lexicalNode.toggleFormat("superscript");
|
|
609
|
+
if (shouldApply && !lexicalNode.hasFormat(shouldApply)) lexicalNode.toggleFormat(shouldApply);
|
|
610
|
+
return lexicalNode;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* The function wraps the passed DOM node in semantic tags depending on the node format.
|
|
614
|
+
*
|
|
615
|
+
* @param lexicalNode The node where the format is checked
|
|
616
|
+
* @param domNode DOM that will be wrapped in tags
|
|
617
|
+
* @param tagNameToFormat Tag name and format mapping
|
|
618
|
+
* @returns domNode
|
|
619
|
+
*/
|
|
620
|
+
function applyFormatToDom(lexicalNode, domNode, tagNameToFormat = DEFAULT_TAG_NAME_TO_FORMAT) {
|
|
621
|
+
for (const [tag, format] of Object.entries(tagNameToFormat)) if (lexicalNode.hasFormat(format)) domNode = wrapElementWith(domNode, tag);
|
|
622
|
+
return domNode;
|
|
623
|
+
}
|
|
624
|
+
function wrapElementWith(element, tag) {
|
|
625
|
+
const el = document.createElement(tag);
|
|
626
|
+
el.appendChild(element);
|
|
627
|
+
return el;
|
|
628
|
+
}
|
|
629
|
+
const DEFAULT_TAG_NAME_TO_FORMAT = {
|
|
630
|
+
b: "bold",
|
|
631
|
+
code: "code",
|
|
632
|
+
em: "italic",
|
|
633
|
+
i: "italic",
|
|
634
|
+
mark: "highlight",
|
|
635
|
+
s: "strikethrough",
|
|
636
|
+
strong: "bold",
|
|
637
|
+
sub: "subscript",
|
|
638
|
+
sup: "superscript",
|
|
639
|
+
u: "underline"
|
|
640
|
+
};
|
|
641
|
+
/**
|
|
642
|
+
* An extension for DecoratorTextNode that sets the format for the node and CSS classes for the DOM container.
|
|
643
|
+
* The base class is always set, and the focus class is set when the node is selected.
|
|
644
|
+
*/
|
|
645
|
+
const DecoratorTextExtension = defineExtension({
|
|
646
|
+
name: "@lexical/extension/DecoratorText",
|
|
647
|
+
nodes: () => [DecoratorTextNode],
|
|
648
|
+
register(editor, config, state) {
|
|
649
|
+
return editor.registerCommand(FORMAT_TEXT_COMMAND, (formatType) => {
|
|
650
|
+
const selection = $getSelection();
|
|
651
|
+
if ($isNodeSelection(selection) || $isRangeSelection(selection)) {
|
|
652
|
+
for (const node of selection.getNodes()) if ($isDecoratorTextNode(node)) node.toggleFormat(formatType);
|
|
653
|
+
}
|
|
654
|
+
return false;
|
|
655
|
+
}, COMMAND_PRIORITY_LOW);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
/**
|
|
659
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
660
|
+
*
|
|
661
|
+
* This source code is licensed under the MIT license found in the
|
|
662
|
+
* LICENSE file in the root directory of this source tree.
|
|
663
|
+
*
|
|
664
|
+
*/
|
|
665
|
+
/**
|
|
666
|
+
* Create a Signal that will subscribe to a value from an external store when watched, similar to
|
|
667
|
+
* React's [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore).
|
|
668
|
+
*
|
|
669
|
+
* @param getSnapshot Used to get the initial value of the signal when created and when first watched.
|
|
670
|
+
* @param register A callback that will subscribe to some external store and update the signal, must return a dispose function.
|
|
671
|
+
* @returns The signal
|
|
672
|
+
*/
|
|
673
|
+
function watchedSignal(getSnapshot, register) {
|
|
674
|
+
let dispose;
|
|
675
|
+
return a(getSnapshot(), {
|
|
676
|
+
unwatched() {
|
|
677
|
+
if (dispose) {
|
|
678
|
+
dispose();
|
|
679
|
+
dispose = void 0;
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
watched() {
|
|
683
|
+
this.value = getSnapshot();
|
|
684
|
+
dispose = register(this);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
690
|
+
*
|
|
691
|
+
* This source code is licensed under the MIT license found in the
|
|
692
|
+
* LICENSE file in the root directory of this source tree.
|
|
693
|
+
*
|
|
694
|
+
*/
|
|
695
|
+
/**
|
|
696
|
+
* An extension to provide the current EditorState as a signal
|
|
697
|
+
*/
|
|
698
|
+
const EditorStateExtension = defineExtension({
|
|
699
|
+
build(editor) {
|
|
700
|
+
return watchedSignal(() => editor.getEditorState(), (editorStateSignal) => editor.registerUpdateListener((payload) => {
|
|
701
|
+
editorStateSignal.value = payload.editorState;
|
|
702
|
+
}));
|
|
703
|
+
},
|
|
704
|
+
name: "@lexical/extension/EditorState"
|
|
705
|
+
});
|
|
706
|
+
/**
|
|
707
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
708
|
+
*
|
|
709
|
+
* This source code is licensed under the MIT license found in the
|
|
710
|
+
* LICENSE file in the root directory of this source tree.
|
|
711
|
+
*
|
|
712
|
+
*/
|
|
713
|
+
function formatDevErrorMessage(message) {
|
|
714
|
+
throw new Error(message);
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
718
|
+
*
|
|
719
|
+
* This source code is licensed under the MIT license found in the
|
|
720
|
+
* LICENSE file in the root directory of this source tree.
|
|
721
|
+
*
|
|
722
|
+
*/
|
|
723
|
+
/**
|
|
724
|
+
* Recursively merge the given theme configuration in-place.
|
|
725
|
+
*
|
|
726
|
+
* @returns If `a` and `b` are both objects (and `b` is not an Array) then
|
|
727
|
+
* all keys in `b` are merged into `a` then `a` is returned.
|
|
728
|
+
* Otherwise `b` is returned.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```ts
|
|
732
|
+
* const a = { a: "a", nested: { a: 1 } };
|
|
733
|
+
* const b = { b: "b", nested: { b: 2 } };
|
|
734
|
+
* const rval = deepThemeMergeInPlace(a, b);
|
|
735
|
+
* expect(a).toBe(rval);
|
|
736
|
+
* expect(a).toEqual({ a: "a", b: "b", nested: { a: 1, b: 2 } });
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
function deepThemeMergeInPlace(a, b) {
|
|
740
|
+
if (a && b && !Array.isArray(b) && typeof a === "object" && typeof b === "object") {
|
|
741
|
+
const aObj = a;
|
|
742
|
+
const bObj = b;
|
|
743
|
+
for (const k in bObj) aObj[k] = deepThemeMergeInPlace(aObj[k], bObj[k]);
|
|
744
|
+
return a;
|
|
745
|
+
}
|
|
746
|
+
return b;
|
|
747
|
+
}
|
|
748
|
+
const ExtensionRepStateIds = {
|
|
749
|
+
unmarked: 0,
|
|
750
|
+
temporary: 1,
|
|
751
|
+
permanent: 2,
|
|
752
|
+
configured: 3,
|
|
753
|
+
initialized: 4,
|
|
754
|
+
built: 5,
|
|
755
|
+
registered: 6,
|
|
756
|
+
afterRegistration: 7
|
|
757
|
+
};
|
|
758
|
+
function isExactlyUnmarkedExtensionRepState(state) {
|
|
759
|
+
return state.id === ExtensionRepStateIds.unmarked;
|
|
760
|
+
}
|
|
761
|
+
function isExactlyTemporaryExtensionRepState(state) {
|
|
762
|
+
return state.id === ExtensionRepStateIds.temporary;
|
|
763
|
+
}
|
|
764
|
+
function isExactlyPermanentExtensionRepState(state) {
|
|
765
|
+
return state.id === ExtensionRepStateIds.permanent;
|
|
766
|
+
}
|
|
767
|
+
function isConfiguredExtensionRepState(state) {
|
|
768
|
+
return state.id >= ExtensionRepStateIds.configured;
|
|
769
|
+
}
|
|
770
|
+
function isInitializedExtensionRepState(state) {
|
|
771
|
+
return state.id >= ExtensionRepStateIds.initialized;
|
|
772
|
+
}
|
|
773
|
+
function isBuiltExtensionRepState(state) {
|
|
774
|
+
return state.id >= ExtensionRepStateIds.built;
|
|
775
|
+
}
|
|
776
|
+
function isAfterRegistrationState(state) {
|
|
777
|
+
return state.id >= ExtensionRepStateIds.afterRegistration;
|
|
778
|
+
}
|
|
779
|
+
function applyTemporaryMark(state) {
|
|
780
|
+
if (!isExactlyUnmarkedExtensionRepState(state)) formatDevErrorMessage(`LexicalBuilder: Can not apply a temporary mark from state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.unmarked)} unmarked)`);
|
|
781
|
+
return Object.assign(state, { id: ExtensionRepStateIds.temporary });
|
|
782
|
+
}
|
|
783
|
+
function applyPermanentMark(state) {
|
|
784
|
+
if (!isExactlyTemporaryExtensionRepState(state)) formatDevErrorMessage(`LexicalBuilder: Can not apply a permanent mark from state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.temporary)} temporary)`);
|
|
785
|
+
return Object.assign(state, { id: ExtensionRepStateIds.permanent });
|
|
786
|
+
}
|
|
787
|
+
function applyConfiguredState(state, config, registerState) {
|
|
788
|
+
return Object.assign(state, {
|
|
789
|
+
config,
|
|
790
|
+
id: ExtensionRepStateIds.configured,
|
|
791
|
+
registerState
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
function applyInitializedState(state, initResult, registerState) {
|
|
795
|
+
return Object.assign(state, {
|
|
796
|
+
id: ExtensionRepStateIds.initialized,
|
|
797
|
+
initResult,
|
|
798
|
+
registerState
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
function applyBuiltState(state, output, registerState) {
|
|
802
|
+
return Object.assign(state, {
|
|
803
|
+
id: ExtensionRepStateIds.built,
|
|
804
|
+
output,
|
|
805
|
+
registerState
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
function applyRegisteredState(state) {
|
|
809
|
+
return Object.assign(state, { id: ExtensionRepStateIds.registered });
|
|
810
|
+
}
|
|
811
|
+
function applyAfterRegistrationState(state) {
|
|
812
|
+
return Object.assign(state, { id: ExtensionRepStateIds.afterRegistration });
|
|
813
|
+
}
|
|
814
|
+
function rollbackToBuiltState(state) {
|
|
815
|
+
return Object.assign(state, { id: ExtensionRepStateIds.built });
|
|
816
|
+
}
|
|
817
|
+
const emptySet = /* @__PURE__ */ new Set();
|
|
818
|
+
/**
|
|
819
|
+
* @internal
|
|
820
|
+
*/
|
|
821
|
+
var ExtensionRep = class {
|
|
822
|
+
builder;
|
|
823
|
+
configs;
|
|
824
|
+
_dependency;
|
|
825
|
+
_peerNameSet;
|
|
826
|
+
extension;
|
|
827
|
+
state;
|
|
828
|
+
_signal;
|
|
829
|
+
constructor(builder, extension) {
|
|
830
|
+
this.builder = builder;
|
|
831
|
+
this.extension = extension;
|
|
832
|
+
this.configs = /* @__PURE__ */ new Set();
|
|
833
|
+
this.state = { id: ExtensionRepStateIds.unmarked };
|
|
834
|
+
}
|
|
835
|
+
mergeConfigs() {
|
|
836
|
+
let config = this.extension.config || {};
|
|
837
|
+
const mergeConfig = this.extension.mergeConfig ? this.extension.mergeConfig.bind(this.extension) : shallowMergeConfig;
|
|
838
|
+
for (const cfg of this.configs) config = mergeConfig(config, cfg);
|
|
839
|
+
return config;
|
|
840
|
+
}
|
|
841
|
+
init(editorConfig) {
|
|
842
|
+
const initialState = this.state;
|
|
843
|
+
if (!isExactlyPermanentExtensionRepState(initialState)) formatDevErrorMessage(`ExtensionRep: Can not configure from state id ${String(initialState.id)}`);
|
|
844
|
+
const initState = {
|
|
845
|
+
getDependency: this.getInitDependency.bind(this),
|
|
846
|
+
getDirectDependentNames: this.getDirectDependentNames.bind(this),
|
|
847
|
+
getPeer: this.getInitPeer.bind(this),
|
|
848
|
+
getPeerNameSet: this.getPeerNameSet.bind(this)
|
|
849
|
+
};
|
|
850
|
+
const buildState = {
|
|
851
|
+
...initState,
|
|
852
|
+
getDependency: this.getDependency.bind(this),
|
|
853
|
+
getInitResult: this.getInitResult.bind(this),
|
|
854
|
+
getPeer: this.getPeer.bind(this)
|
|
855
|
+
};
|
|
856
|
+
const state = applyConfiguredState(initialState, this.mergeConfigs(), initState);
|
|
857
|
+
this.state = state;
|
|
858
|
+
let initResult;
|
|
859
|
+
if (this.extension.init) initResult = this.extension.init(editorConfig, state.config, initState);
|
|
860
|
+
this.state = applyInitializedState(state, initResult, buildState);
|
|
861
|
+
}
|
|
862
|
+
build(editor) {
|
|
863
|
+
const state = this.state;
|
|
864
|
+
if (!(state.id === ExtensionRepStateIds.initialized)) formatDevErrorMessage(`ExtensionRep: register called in state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.built)} initialized)`);
|
|
865
|
+
let output;
|
|
866
|
+
if (this.extension.build) output = this.extension.build(editor, state.config, state.registerState);
|
|
867
|
+
const registerState = {
|
|
868
|
+
...state.registerState,
|
|
869
|
+
getOutput: () => output,
|
|
870
|
+
getSignal: this.getSignal.bind(this)
|
|
871
|
+
};
|
|
872
|
+
this.state = applyBuiltState(state, output, registerState);
|
|
873
|
+
}
|
|
874
|
+
register(editor, signal) {
|
|
875
|
+
this._signal = signal;
|
|
876
|
+
const state = this.state;
|
|
877
|
+
if (!(state.id === ExtensionRepStateIds.built)) formatDevErrorMessage(`ExtensionRep: register called in state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.built)} built)`);
|
|
878
|
+
const cleanup = this.extension.register && this.extension.register(editor, state.config, state.registerState);
|
|
879
|
+
this.state = applyRegisteredState(state);
|
|
880
|
+
return () => {
|
|
881
|
+
const afterRegistrationState = this.state;
|
|
882
|
+
if (!(afterRegistrationState.id === ExtensionRepStateIds.afterRegistration)) formatDevErrorMessage(`ExtensionRep: rollbackToBuiltState called in state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.afterRegistration)} afterRegistration)`);
|
|
883
|
+
this.state = rollbackToBuiltState(afterRegistrationState);
|
|
884
|
+
if (cleanup) cleanup();
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
afterRegistration(editor) {
|
|
888
|
+
const state = this.state;
|
|
889
|
+
if (!(state.id === ExtensionRepStateIds.registered)) formatDevErrorMessage(`ExtensionRep: afterRegistration called in state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.registered)} registered)`);
|
|
890
|
+
let rval;
|
|
891
|
+
if (this.extension.afterRegistration) rval = this.extension.afterRegistration(editor, state.config, state.registerState);
|
|
892
|
+
this.state = applyAfterRegistrationState(state);
|
|
893
|
+
return rval;
|
|
894
|
+
}
|
|
895
|
+
getSignal() {
|
|
896
|
+
if (!(this._signal !== void 0)) formatDevErrorMessage(`ExtensionRep.getSignal() called before register`);
|
|
897
|
+
return this._signal;
|
|
898
|
+
}
|
|
899
|
+
getInitResult() {
|
|
900
|
+
if (!(this.extension.init !== void 0)) formatDevErrorMessage(`ExtensionRep: getInitResult() called for Extension ${this.extension.name} that does not define init`);
|
|
901
|
+
const state = this.state;
|
|
902
|
+
if (!isInitializedExtensionRepState(state)) formatDevErrorMessage(`ExtensionRep: getInitResult() called for ExtensionRep in state id ${String(state.id)} < ${String(ExtensionRepStateIds.initialized)} (initialized)`);
|
|
903
|
+
return state.initResult;
|
|
904
|
+
}
|
|
905
|
+
getInitPeer(name) {
|
|
906
|
+
const rep = this.builder.extensionNameMap.get(name);
|
|
907
|
+
return rep ? rep.getExtensionInitDependency() : void 0;
|
|
908
|
+
}
|
|
909
|
+
getExtensionInitDependency() {
|
|
910
|
+
const state = this.state;
|
|
911
|
+
if (!isConfiguredExtensionRepState(state)) formatDevErrorMessage(`ExtensionRep: getExtensionInitDependency called in state id ${String(state.id)} (expected >= ${String(ExtensionRepStateIds.configured)} configured)`);
|
|
912
|
+
return { config: state.config };
|
|
913
|
+
}
|
|
914
|
+
getPeer(name) {
|
|
915
|
+
const rep = this.builder.extensionNameMap.get(name);
|
|
916
|
+
return rep ? rep.getExtensionDependency() : void 0;
|
|
917
|
+
}
|
|
918
|
+
getInitDependency(dep) {
|
|
919
|
+
const rep = this.builder.getExtensionRep(dep);
|
|
920
|
+
if (!(rep !== void 0)) formatDevErrorMessage(`LexicalExtensionBuilder: Extension ${this.extension.name} missing dependency extension ${dep.name} to be in registry`);
|
|
921
|
+
return rep.getExtensionInitDependency();
|
|
922
|
+
}
|
|
923
|
+
getDependency(dep) {
|
|
924
|
+
const rep = this.builder.getExtensionRep(dep);
|
|
925
|
+
if (!(rep !== void 0)) formatDevErrorMessage(`LexicalExtensionBuilder: Extension ${this.extension.name} missing dependency extension ${dep.name} to be in registry`);
|
|
926
|
+
return rep.getExtensionDependency();
|
|
927
|
+
}
|
|
928
|
+
getState() {
|
|
929
|
+
const state = this.state;
|
|
930
|
+
if (!isAfterRegistrationState(state)) formatDevErrorMessage(`ExtensionRep getState called in state id ${String(state.id)} (expected ${String(ExtensionRepStateIds.afterRegistration)} afterRegistration)`);
|
|
931
|
+
return state;
|
|
932
|
+
}
|
|
933
|
+
getDirectDependentNames() {
|
|
934
|
+
return this.builder.incomingEdges.get(this.extension.name) || emptySet;
|
|
935
|
+
}
|
|
936
|
+
getPeerNameSet() {
|
|
937
|
+
let s = this._peerNameSet;
|
|
938
|
+
if (!s) {
|
|
939
|
+
s = new Set((this.extension.peerDependencies || []).map(([name]) => name));
|
|
940
|
+
this._peerNameSet = s;
|
|
941
|
+
}
|
|
942
|
+
return s;
|
|
943
|
+
}
|
|
944
|
+
getExtensionDependency() {
|
|
945
|
+
if (!this._dependency) {
|
|
946
|
+
const state = this.state;
|
|
947
|
+
if (!isBuiltExtensionRepState(state)) formatDevErrorMessage(`Extension ${this.extension.name} used as a dependency before build`);
|
|
948
|
+
this._dependency = {
|
|
949
|
+
config: state.config,
|
|
950
|
+
init: state.initResult,
|
|
951
|
+
output: state.output
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
return this._dependency;
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
/**
|
|
958
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
959
|
+
*
|
|
960
|
+
* This source code is licensed under the MIT license found in the
|
|
961
|
+
* LICENSE file in the root directory of this source tree.
|
|
962
|
+
*
|
|
963
|
+
*/
|
|
964
|
+
const HISTORY_MERGE_OPTIONS = { tag: HISTORY_MERGE_TAG };
|
|
965
|
+
function $defaultInitializer() {
|
|
966
|
+
const root = $getRoot();
|
|
967
|
+
if (root.isEmpty()) root.append($createParagraphNode());
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* An extension to set the initial state of the editor from
|
|
971
|
+
* a function or serialized JSON EditorState. This is
|
|
972
|
+
* implicitly included with all editors built with
|
|
973
|
+
* Lexical Extension. This happens in the `afterRegistration`
|
|
974
|
+
* phase so your initial state may depend on registered commands,
|
|
975
|
+
* but you should not call `editor.setRootElement` earlier than
|
|
976
|
+
* this phase to avoid rendering an empty editor first.
|
|
977
|
+
*/
|
|
978
|
+
const InitialStateExtension = defineExtension({
|
|
979
|
+
config: safeCast({
|
|
980
|
+
setOptions: HISTORY_MERGE_OPTIONS,
|
|
981
|
+
updateOptions: HISTORY_MERGE_OPTIONS
|
|
982
|
+
}),
|
|
983
|
+
init({ $initialEditorState = $defaultInitializer }) {
|
|
984
|
+
return {
|
|
985
|
+
$initialEditorState,
|
|
986
|
+
initialized: false
|
|
987
|
+
};
|
|
988
|
+
},
|
|
989
|
+
afterRegistration(editor, { updateOptions, setOptions }, state) {
|
|
990
|
+
const initResult = state.getInitResult();
|
|
991
|
+
if (!initResult.initialized) {
|
|
992
|
+
initResult.initialized = true;
|
|
993
|
+
const { $initialEditorState } = initResult;
|
|
994
|
+
if ($isEditorState($initialEditorState)) editor.setEditorState($initialEditorState, setOptions);
|
|
995
|
+
else if (typeof $initialEditorState === "function") editor.update(() => {
|
|
996
|
+
$initialEditorState(editor);
|
|
997
|
+
}, updateOptions);
|
|
998
|
+
else if ($initialEditorState && (typeof $initialEditorState === "string" || typeof $initialEditorState === "object")) {
|
|
999
|
+
const parsedEditorState = editor.parseEditorState($initialEditorState);
|
|
1000
|
+
editor.setEditorState(parsedEditorState, setOptions);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
return () => {};
|
|
1004
|
+
},
|
|
1005
|
+
name: "@lexical/extension/InitialState",
|
|
1006
|
+
nodes: [
|
|
1007
|
+
RootNode,
|
|
1008
|
+
TextNode,
|
|
1009
|
+
LineBreakNode,
|
|
1010
|
+
TabNode,
|
|
1011
|
+
ParagraphNode
|
|
1012
|
+
]
|
|
1013
|
+
});
|
|
1014
|
+
/** @internal Use a well-known symbol for dev tools purposes */
|
|
1015
|
+
const builderSymbol = Symbol.for("@lexical/extension/LexicalBuilder");
|
|
1016
|
+
/**
|
|
1017
|
+
* Build a LexicalEditor by combining together one or more extensions, optionally
|
|
1018
|
+
* overriding some of their configuration.
|
|
1019
|
+
*
|
|
1020
|
+
* @param extensions - Extension arguments (extensions or extensions with config overrides)
|
|
1021
|
+
* @returns An editor handle
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* A single root extension with multiple dependencies
|
|
1025
|
+
*
|
|
1026
|
+
* ```ts
|
|
1027
|
+
* const editor = buildEditorFromExtensions(
|
|
1028
|
+
* defineExtension({
|
|
1029
|
+
* name: "[root]",
|
|
1030
|
+
* dependencies: [
|
|
1031
|
+
* RichTextExtension,
|
|
1032
|
+
* configExtension(EmojiExtension, { emojiBaseUrl: "/assets/emoji" }),
|
|
1033
|
+
* ],
|
|
1034
|
+
* register: (editor: LexicalEditor) => {
|
|
1035
|
+
* console.log("Editor Created");
|
|
1036
|
+
* return () => console.log("Editor Disposed");
|
|
1037
|
+
* },
|
|
1038
|
+
* }),
|
|
1039
|
+
* );
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* @example
|
|
1043
|
+
* A very similar minimal configuration without the register hook
|
|
1044
|
+
*
|
|
1045
|
+
* ```ts
|
|
1046
|
+
* const editor = buildEditorFromExtensions(
|
|
1047
|
+
* RichTextExtension,
|
|
1048
|
+
* configExtension(EmojiExtension, { emojiBaseUrl: "/assets/emoji" }),
|
|
1049
|
+
* );
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
function buildEditorFromExtensions(...extensions) {
|
|
1053
|
+
return LexicalBuilder.fromExtensions(extensions).buildEditor();
|
|
1054
|
+
}
|
|
1055
|
+
/** @internal */
|
|
1056
|
+
function noop() {}
|
|
1057
|
+
/** Throw the given Error */
|
|
1058
|
+
function defaultOnError(err) {
|
|
1059
|
+
throw err;
|
|
1060
|
+
}
|
|
1061
|
+
/** @internal */
|
|
1062
|
+
function maybeWithBuilder(editor) {
|
|
1063
|
+
return editor;
|
|
1064
|
+
}
|
|
1065
|
+
function normalizeExtensionArgument(arg) {
|
|
1066
|
+
return Array.isArray(arg) ? arg : [arg];
|
|
1067
|
+
}
|
|
1068
|
+
const PACKAGE_VERSION = "0.44.0+dev.esm";
|
|
1069
|
+
/** @internal */
|
|
1070
|
+
var LexicalBuilder = class LexicalBuilder {
|
|
1071
|
+
roots;
|
|
1072
|
+
extensionNameMap;
|
|
1073
|
+
outgoingConfigEdges;
|
|
1074
|
+
incomingEdges;
|
|
1075
|
+
conflicts;
|
|
1076
|
+
_sortedExtensionReps;
|
|
1077
|
+
PACKAGE_VERSION;
|
|
1078
|
+
constructor(roots) {
|
|
1079
|
+
this.outgoingConfigEdges = /* @__PURE__ */ new Map();
|
|
1080
|
+
this.incomingEdges = /* @__PURE__ */ new Map();
|
|
1081
|
+
this.extensionNameMap = /* @__PURE__ */ new Map();
|
|
1082
|
+
this.conflicts = /* @__PURE__ */ new Map();
|
|
1083
|
+
this.PACKAGE_VERSION = PACKAGE_VERSION;
|
|
1084
|
+
this.roots = roots;
|
|
1085
|
+
for (const extension of roots) this.addExtension(extension);
|
|
1086
|
+
}
|
|
1087
|
+
static fromExtensions(extensions) {
|
|
1088
|
+
const roots = [normalizeExtensionArgument(InitialStateExtension)];
|
|
1089
|
+
for (const extension of extensions) roots.push(normalizeExtensionArgument(extension));
|
|
1090
|
+
return new LexicalBuilder(roots);
|
|
1091
|
+
}
|
|
1092
|
+
static maybeFromEditor(editor) {
|
|
1093
|
+
const builder = maybeWithBuilder(editor)[builderSymbol];
|
|
1094
|
+
if (builder) {
|
|
1095
|
+
if (!(builder.PACKAGE_VERSION === PACKAGE_VERSION)) formatDevErrorMessage(`LexicalBuilder.fromEditor: The given editor was created with LexicalBuilder ${builder.PACKAGE_VERSION} but this version is ${PACKAGE_VERSION}. A project should have exactly one copy of LexicalBuilder`);
|
|
1096
|
+
if (!(builder instanceof LexicalBuilder)) formatDevErrorMessage(`LexicalBuilder.fromEditor: There are multiple copies of the same version of LexicalBuilder in your project, and this editor was created with another one. Your project, or one of its dependencies, has its package.json and/or bundler configured incorrectly.`);
|
|
1097
|
+
}
|
|
1098
|
+
return builder;
|
|
1099
|
+
}
|
|
1100
|
+
/** Look up the editor that was created by this LexicalBuilder or throw */
|
|
1101
|
+
static fromEditor(editor) {
|
|
1102
|
+
const builder = LexicalBuilder.maybeFromEditor(editor);
|
|
1103
|
+
if (!(builder !== void 0)) formatDevErrorMessage(`LexicalBuilder.fromEditor: The given editor was not created with LexicalBuilder`);
|
|
1104
|
+
return builder;
|
|
1105
|
+
}
|
|
1106
|
+
constructEditor() {
|
|
1107
|
+
const { $initialEditorState: _$initialEditorState, onError, ...editorConfig } = this.buildCreateEditorArgs();
|
|
1108
|
+
const editor = Object.assign(createEditor({
|
|
1109
|
+
...editorConfig,
|
|
1110
|
+
...onError ? { onError: (err) => {
|
|
1111
|
+
onError(err, editor);
|
|
1112
|
+
} } : {}
|
|
1113
|
+
}), { [builderSymbol]: this });
|
|
1114
|
+
for (const extensionRep of this.sortedExtensionReps()) extensionRep.build(editor);
|
|
1115
|
+
return editor;
|
|
1116
|
+
}
|
|
1117
|
+
buildEditor() {
|
|
1118
|
+
let disposeOnce = noop;
|
|
1119
|
+
function dispose() {
|
|
1120
|
+
try {
|
|
1121
|
+
disposeOnce();
|
|
1122
|
+
} finally {
|
|
1123
|
+
disposeOnce = noop;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
const editor = Object.assign(this.constructEditor(), {
|
|
1127
|
+
dispose,
|
|
1128
|
+
[Symbol.dispose]: dispose
|
|
1129
|
+
});
|
|
1130
|
+
disposeOnce = mergeRegister(this.registerEditor(editor), () => editor.setRootElement(null));
|
|
1131
|
+
return editor;
|
|
1132
|
+
}
|
|
1133
|
+
hasExtensionByName(name) {
|
|
1134
|
+
return this.extensionNameMap.has(name);
|
|
1135
|
+
}
|
|
1136
|
+
getExtensionRep(extension) {
|
|
1137
|
+
const rep = this.extensionNameMap.get(extension.name);
|
|
1138
|
+
if (rep) {
|
|
1139
|
+
if (!(rep.extension === extension)) formatDevErrorMessage(`LexicalBuilder: A registered extension with name ${extension.name} exists but does not match the given extension`);
|
|
1140
|
+
return rep;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
addEdge(fromExtensionName, toExtensionName, configs) {
|
|
1144
|
+
const outgoing = this.outgoingConfigEdges.get(fromExtensionName);
|
|
1145
|
+
if (outgoing) outgoing.set(toExtensionName, configs);
|
|
1146
|
+
else this.outgoingConfigEdges.set(fromExtensionName, new Map([[toExtensionName, configs]]));
|
|
1147
|
+
const incoming = this.incomingEdges.get(toExtensionName);
|
|
1148
|
+
if (incoming) incoming.add(fromExtensionName);
|
|
1149
|
+
else this.incomingEdges.set(toExtensionName, new Set([fromExtensionName]));
|
|
1150
|
+
}
|
|
1151
|
+
addExtension(arg) {
|
|
1152
|
+
if (!(this._sortedExtensionReps === void 0)) formatDevErrorMessage(`LexicalBuilder: addExtension called after finalization`);
|
|
1153
|
+
const [extension] = normalizeExtensionArgument(arg);
|
|
1154
|
+
if (!(typeof extension.name === "string")) formatDevErrorMessage(`LexicalBuilder: extension name must be string, not ${typeof extension.name}`);
|
|
1155
|
+
let extensionRep = this.extensionNameMap.get(extension.name);
|
|
1156
|
+
if (!(extensionRep === void 0 || extensionRep.extension === extension)) formatDevErrorMessage(`LexicalBuilder: Multiple extensions registered with name ${extension.name}, names must be unique`);
|
|
1157
|
+
if (!extensionRep) {
|
|
1158
|
+
extensionRep = new ExtensionRep(this, extension);
|
|
1159
|
+
this.extensionNameMap.set(extension.name, extensionRep);
|
|
1160
|
+
const hasConflict = this.conflicts.get(extension.name);
|
|
1161
|
+
if (typeof hasConflict === "string") formatDevErrorMessage(`LexicalBuilder: extension ${extension.name} conflicts with ${hasConflict}`);
|
|
1162
|
+
for (const name of extension.conflictsWith || []) {
|
|
1163
|
+
if (!!this.extensionNameMap.has(name)) formatDevErrorMessage(`LexicalBuilder: extension ${extension.name} conflicts with ${name}`);
|
|
1164
|
+
this.conflicts.set(name, extension.name);
|
|
1165
|
+
}
|
|
1166
|
+
for (const dep of extension.dependencies || []) {
|
|
1167
|
+
const normDep = normalizeExtensionArgument(dep);
|
|
1168
|
+
this.addEdge(extension.name, normDep[0].name, normDep.slice(1));
|
|
1169
|
+
this.addExtension(normDep);
|
|
1170
|
+
}
|
|
1171
|
+
for (const [depName, config] of extension.peerDependencies || []) this.addEdge(extension.name, depName, config ? [config] : []);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
sortedExtensionReps() {
|
|
1175
|
+
if (this._sortedExtensionReps) return this._sortedExtensionReps;
|
|
1176
|
+
const sortedExtensionReps = [];
|
|
1177
|
+
const visit = (rep, fromExtensionName) => {
|
|
1178
|
+
let mark = rep.state;
|
|
1179
|
+
if (isExactlyPermanentExtensionRepState(mark)) return;
|
|
1180
|
+
const extensionName = rep.extension.name;
|
|
1181
|
+
if (!isExactlyUnmarkedExtensionRepState(mark)) formatDevErrorMessage(`LexicalBuilder: Circular dependency detected for Extension ${extensionName} from ${fromExtensionName || "[unknown]"}`);
|
|
1182
|
+
mark = applyTemporaryMark(mark);
|
|
1183
|
+
rep.state = mark;
|
|
1184
|
+
const outgoingConfigEdges = this.outgoingConfigEdges.get(extensionName);
|
|
1185
|
+
if (outgoingConfigEdges) for (const toExtensionName of outgoingConfigEdges.keys()) {
|
|
1186
|
+
const toRep = this.extensionNameMap.get(toExtensionName);
|
|
1187
|
+
if (toRep) visit(toRep, extensionName);
|
|
1188
|
+
}
|
|
1189
|
+
mark = applyPermanentMark(mark);
|
|
1190
|
+
rep.state = mark;
|
|
1191
|
+
sortedExtensionReps.push(rep);
|
|
1192
|
+
};
|
|
1193
|
+
for (const rep of this.extensionNameMap.values()) if (isExactlyUnmarkedExtensionRepState(rep.state)) visit(rep);
|
|
1194
|
+
for (const rep of sortedExtensionReps) for (const [toExtensionName, configs] of this.outgoingConfigEdges.get(rep.extension.name) || []) if (configs.length > 0) {
|
|
1195
|
+
const toRep = this.extensionNameMap.get(toExtensionName);
|
|
1196
|
+
if (toRep) for (const config of configs) toRep.configs.add(config);
|
|
1197
|
+
}
|
|
1198
|
+
for (const [extension, ...configs] of this.roots) if (configs.length > 0) {
|
|
1199
|
+
const toRep = this.extensionNameMap.get(extension.name);
|
|
1200
|
+
if (!(toRep !== void 0)) formatDevErrorMessage(`LexicalBuilder: Expecting existing ExtensionRep for ${extension.name}`);
|
|
1201
|
+
for (const config of configs) toRep.configs.add(config);
|
|
1202
|
+
}
|
|
1203
|
+
this._sortedExtensionReps = sortedExtensionReps;
|
|
1204
|
+
return this._sortedExtensionReps;
|
|
1205
|
+
}
|
|
1206
|
+
registerEditor(editor) {
|
|
1207
|
+
const extensionReps = this.sortedExtensionReps();
|
|
1208
|
+
const controller = new AbortController();
|
|
1209
|
+
const cleanups = [() => controller.abort()];
|
|
1210
|
+
const signal = controller.signal;
|
|
1211
|
+
for (const extensionRep of extensionReps) {
|
|
1212
|
+
const cleanup = extensionRep.register(editor, signal);
|
|
1213
|
+
if (cleanup) cleanups.push(cleanup);
|
|
1214
|
+
}
|
|
1215
|
+
for (const extensionRep of extensionReps) {
|
|
1216
|
+
const cleanup = extensionRep.afterRegistration(editor);
|
|
1217
|
+
if (cleanup) cleanups.push(cleanup);
|
|
1218
|
+
}
|
|
1219
|
+
return mergeRegister(...cleanups);
|
|
1220
|
+
}
|
|
1221
|
+
buildCreateEditorArgs() {
|
|
1222
|
+
const config = {};
|
|
1223
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
1224
|
+
const replacedNodes = /* @__PURE__ */ new Map();
|
|
1225
|
+
const htmlExport = /* @__PURE__ */ new Map();
|
|
1226
|
+
const htmlImport = {};
|
|
1227
|
+
const theme = {};
|
|
1228
|
+
const extensionReps = this.sortedExtensionReps();
|
|
1229
|
+
for (const extensionRep of extensionReps) {
|
|
1230
|
+
const { extension } = extensionRep;
|
|
1231
|
+
if (extension.onError !== void 0) config.onError = extension.onError;
|
|
1232
|
+
if (extension.disableEvents !== void 0) config.disableEvents = extension.disableEvents;
|
|
1233
|
+
if (extension.parentEditor !== void 0) config.parentEditor = extension.parentEditor;
|
|
1234
|
+
if (extension.editable !== void 0) config.editable = extension.editable;
|
|
1235
|
+
if (extension.namespace !== void 0) config.namespace = extension.namespace;
|
|
1236
|
+
if (extension.$initialEditorState !== void 0) config.$initialEditorState = extension.$initialEditorState;
|
|
1237
|
+
if (extension.nodes) for (const node of getNodeConfig(extension)) {
|
|
1238
|
+
if (typeof node !== "function") {
|
|
1239
|
+
const conflictExtension = replacedNodes.get(node.replace);
|
|
1240
|
+
if (conflictExtension) formatDevErrorMessage(`LexicalBuilder: Extension ${extension.name} can not register replacement for node ${node.replace.name} because ${conflictExtension.extension.name} already did`);
|
|
1241
|
+
replacedNodes.set(node.replace, extensionRep);
|
|
1242
|
+
}
|
|
1243
|
+
nodes.add(node);
|
|
1244
|
+
}
|
|
1245
|
+
if (extension.html) {
|
|
1246
|
+
if (extension.html.export) for (const [k, v] of extension.html.export.entries()) htmlExport.set(k, v);
|
|
1247
|
+
if (extension.html.import) Object.assign(htmlImport, extension.html.import);
|
|
1248
|
+
}
|
|
1249
|
+
if (extension.theme) deepThemeMergeInPlace(theme, extension.theme);
|
|
1250
|
+
}
|
|
1251
|
+
if (Object.keys(theme).length > 0) config.theme = theme;
|
|
1252
|
+
if (nodes.size) config.nodes = [...nodes];
|
|
1253
|
+
const hasImport = Object.keys(htmlImport).length > 0;
|
|
1254
|
+
const hasExport = htmlExport.size > 0;
|
|
1255
|
+
if (hasImport || hasExport) {
|
|
1256
|
+
config.html = {};
|
|
1257
|
+
if (hasImport) config.html.import = htmlImport;
|
|
1258
|
+
if (hasExport) config.html.export = htmlExport;
|
|
1259
|
+
}
|
|
1260
|
+
for (const extensionRep of extensionReps) extensionRep.init(config);
|
|
1261
|
+
if (!config.onError) config.onError = defaultOnError;
|
|
1262
|
+
return config;
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
/**
|
|
1266
|
+
* Get the finalized config and output of an Extension that was used to build the editor.
|
|
1267
|
+
*
|
|
1268
|
+
* This is useful in the implementation of a LexicalNode or in other
|
|
1269
|
+
* situations where you have an editor reference but it's not easy to
|
|
1270
|
+
* pass the config or {@link ExtensionRegisterState} around.
|
|
1271
|
+
*
|
|
1272
|
+
* It will throw if the Editor was not built using this Extension.
|
|
1273
|
+
*
|
|
1274
|
+
* @param editor - The editor that was built using extension
|
|
1275
|
+
* @param extension - The concrete reference to an Extension used to build this editor
|
|
1276
|
+
* @returns The config and output for that Extension
|
|
1277
|
+
*/
|
|
1278
|
+
function getExtensionDependencyFromEditor(editor, extension) {
|
|
1279
|
+
const rep = LexicalBuilder.fromEditor(editor).getExtensionRep(extension);
|
|
1280
|
+
if (!(rep !== void 0)) formatDevErrorMessage(`getExtensionDependencyFromEditor: Extension ${extension.name} was not built when creating this editor`);
|
|
1281
|
+
return rep.getExtensionDependency();
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Get the finalized config and output of an Extension that was used to build the
|
|
1285
|
+
* editor by name.
|
|
1286
|
+
*
|
|
1287
|
+
* This can be used from the implementation of a LexicalNode or in other
|
|
1288
|
+
* situation where you have an editor reference but it's not easy to pass the
|
|
1289
|
+
* config around. Use this version if you do not have a concrete reference to
|
|
1290
|
+
* the Extension for some reason (e.g. it is an optional peer dependency, or you
|
|
1291
|
+
* are avoiding a circular import).
|
|
1292
|
+
*
|
|
1293
|
+
* Both the explicit Extension type and the name are required.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```tsx
|
|
1297
|
+
* import type { HistoryExtension } from "@lexical/history";
|
|
1298
|
+
* getPeerDependencyFromEditor<typeof HistoryExtension>(editor, "@lexical/history/History");
|
|
1299
|
+
* ```
|
|
1300
|
+
|
|
1301
|
+
* @param editor - The editor that may have been built using extension
|
|
1302
|
+
* @param extensionName - The name of the Extension
|
|
1303
|
+
* @returns The config and output of the Extension or undefined
|
|
1304
|
+
*/
|
|
1305
|
+
function getPeerDependencyFromEditor(editor, extensionName) {
|
|
1306
|
+
const builder = LexicalBuilder.maybeFromEditor(editor);
|
|
1307
|
+
if (!builder) return void 0;
|
|
1308
|
+
const peer = builder.extensionNameMap.get(extensionName);
|
|
1309
|
+
return peer ? peer.getExtensionDependency() : void 0;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Get the finalized config and output of an Extension that was used to build the
|
|
1313
|
+
* editor by name.
|
|
1314
|
+
*
|
|
1315
|
+
* This can be used from the implementation of a LexicalNode or in other
|
|
1316
|
+
* situation where you have an editor reference but it's not easy to pass the
|
|
1317
|
+
* config around. Use this version if you do not have a concrete reference to
|
|
1318
|
+
* the Extension for some reason (e.g. it is an optional peer dependency, or you
|
|
1319
|
+
* are avoiding a circular import).
|
|
1320
|
+
*
|
|
1321
|
+
* Both the explicit Extension type and the name are required.
|
|
1322
|
+
*
|
|
1323
|
+
* @example
|
|
1324
|
+
* ```tsx
|
|
1325
|
+
* import type { EmojiExtension } from "./EmojiExtension";
|
|
1326
|
+
* export class EmojiNode extends TextNode {
|
|
1327
|
+
* // other implementation details not included
|
|
1328
|
+
* createDOM(
|
|
1329
|
+
* config: EditorConfig,
|
|
1330
|
+
* editor?: LexicalEditor | undefined
|
|
1331
|
+
* ): HTMLElement {
|
|
1332
|
+
* const dom = super.createDOM(config, editor);
|
|
1333
|
+
* addClassNamesToElement(
|
|
1334
|
+
* dom,
|
|
1335
|
+
* getPeerDependencyFromEditorOrThrow<typeof EmojiExtension>(
|
|
1336
|
+
* editor || $getEditor(),
|
|
1337
|
+
* "@lexical/playground/emoji",
|
|
1338
|
+
* ).config.emojiClass,
|
|
1339
|
+
* );
|
|
1340
|
+
* return dom;
|
|
1341
|
+
* }
|
|
1342
|
+
* }
|
|
1343
|
+
* ```
|
|
1344
|
+
|
|
1345
|
+
* @param editor - The editor that may have been built using extension
|
|
1346
|
+
* @param extensionName - The name of the Extension
|
|
1347
|
+
* @returns The config and output of the Extension
|
|
1348
|
+
*/
|
|
1349
|
+
function getPeerDependencyFromEditorOrThrow(editor, extensionName) {
|
|
1350
|
+
const dep = getPeerDependencyFromEditor(editor, extensionName);
|
|
1351
|
+
if (!(dep !== void 0)) formatDevErrorMessage(`getPeerDependencyFromEditorOrThrow: Editor was not built with Extension ${extensionName}`);
|
|
1352
|
+
return dep;
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1356
|
+
*
|
|
1357
|
+
* This source code is licensed under the MIT license found in the
|
|
1358
|
+
* LICENSE file in the root directory of this source tree.
|
|
1359
|
+
*
|
|
1360
|
+
*/
|
|
1361
|
+
const EMPTY_SET = /* @__PURE__ */ new Set();
|
|
1362
|
+
/**
|
|
1363
|
+
* An extension that provides a `watchNodeKey` output that
|
|
1364
|
+
* returns a signal for the selection state of a node.
|
|
1365
|
+
*
|
|
1366
|
+
* Typically used for tracking whether a DecoratorNode is
|
|
1367
|
+
* currently selected or not. A framework independent
|
|
1368
|
+
* alternative to {@link useLexicalNodeSelection}.
|
|
1369
|
+
*/
|
|
1370
|
+
const NodeSelectionExtension = defineExtension({
|
|
1371
|
+
build(editor, config, state) {
|
|
1372
|
+
const editorStateStore = state.getDependency(EditorStateExtension).output;
|
|
1373
|
+
const watchedNodeStore = a({ watchedNodeKeys: /* @__PURE__ */ new Map() });
|
|
1374
|
+
const selectedNodeKeys = watchedSignal(() => void 0, () => j(() => {
|
|
1375
|
+
const prevSelectedNodeKeys = selectedNodeKeys.peek();
|
|
1376
|
+
const { watchedNodeKeys } = watchedNodeStore.value;
|
|
1377
|
+
let nextSelectedNodeKeys;
|
|
1378
|
+
let didChange = false;
|
|
1379
|
+
editorStateStore.value.read(() => {
|
|
1380
|
+
if ($getSelection()) for (const [key, listeners] of watchedNodeKeys.entries()) {
|
|
1381
|
+
if (listeners.size === 0) {
|
|
1382
|
+
watchedNodeKeys.delete(key);
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
const node = $getNodeByKey(key);
|
|
1386
|
+
const isSelected = node && node.isSelected() || false;
|
|
1387
|
+
didChange = didChange || isSelected !== (prevSelectedNodeKeys ? prevSelectedNodeKeys.has(key) : false);
|
|
1388
|
+
if (isSelected) {
|
|
1389
|
+
nextSelectedNodeKeys = nextSelectedNodeKeys || /* @__PURE__ */ new Set();
|
|
1390
|
+
nextSelectedNodeKeys.add(key);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
if (!(!didChange && nextSelectedNodeKeys && prevSelectedNodeKeys && nextSelectedNodeKeys.size === prevSelectedNodeKeys.size)) selectedNodeKeys.value = nextSelectedNodeKeys;
|
|
1395
|
+
}));
|
|
1396
|
+
function watchNodeKey(key) {
|
|
1397
|
+
const watcher = g(() => (selectedNodeKeys.value || EMPTY_SET).has(key));
|
|
1398
|
+
const { watchedNodeKeys } = watchedNodeStore.peek();
|
|
1399
|
+
let listeners = watchedNodeKeys.get(key);
|
|
1400
|
+
const hadListener = listeners !== void 0;
|
|
1401
|
+
listeners = listeners || /* @__PURE__ */ new Set();
|
|
1402
|
+
listeners.add(watcher);
|
|
1403
|
+
if (!hadListener) {
|
|
1404
|
+
watchedNodeKeys.set(key, listeners);
|
|
1405
|
+
watchedNodeStore.value = { watchedNodeKeys };
|
|
1406
|
+
}
|
|
1407
|
+
return watcher;
|
|
1408
|
+
}
|
|
1409
|
+
return { watchNodeKey };
|
|
1410
|
+
},
|
|
1411
|
+
dependencies: [EditorStateExtension],
|
|
1412
|
+
name: "@lexical/extension/NodeSelection"
|
|
1413
|
+
});
|
|
1414
|
+
/**
|
|
1415
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1416
|
+
*
|
|
1417
|
+
* This source code is licensed under the MIT license found in the
|
|
1418
|
+
* LICENSE file in the root directory of this source tree.
|
|
1419
|
+
*
|
|
1420
|
+
*/
|
|
1421
|
+
const INSERT_HORIZONTAL_RULE_COMMAND = createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
|
|
1422
|
+
var HorizontalRuleNode = class HorizontalRuleNode extends DecoratorNode {
|
|
1423
|
+
static getType() {
|
|
1424
|
+
return "horizontalrule";
|
|
1425
|
+
}
|
|
1426
|
+
static clone(node) {
|
|
1427
|
+
return new HorizontalRuleNode(node.__key);
|
|
1428
|
+
}
|
|
1429
|
+
static importJSON(serializedNode) {
|
|
1430
|
+
return $createHorizontalRuleNode().updateFromJSON(serializedNode);
|
|
1431
|
+
}
|
|
1432
|
+
static importDOM() {
|
|
1433
|
+
return { hr: () => ({
|
|
1434
|
+
conversion: $convertHorizontalRuleElement,
|
|
1435
|
+
priority: 0
|
|
1436
|
+
}) };
|
|
1437
|
+
}
|
|
1438
|
+
exportDOM() {
|
|
1439
|
+
return { element: document.createElement("hr") };
|
|
1440
|
+
}
|
|
1441
|
+
createDOM(config) {
|
|
1442
|
+
const element = document.createElement("hr");
|
|
1443
|
+
addClassNamesToElement(element, config.theme.hr);
|
|
1444
|
+
return element;
|
|
1445
|
+
}
|
|
1446
|
+
getTextContent() {
|
|
1447
|
+
return "\n";
|
|
1448
|
+
}
|
|
1449
|
+
isInline() {
|
|
1450
|
+
return false;
|
|
1451
|
+
}
|
|
1452
|
+
updateDOM() {
|
|
1453
|
+
return false;
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
function $convertHorizontalRuleElement() {
|
|
1457
|
+
return { node: $createHorizontalRuleNode() };
|
|
1458
|
+
}
|
|
1459
|
+
function $createHorizontalRuleNode() {
|
|
1460
|
+
return $create(HorizontalRuleNode);
|
|
1461
|
+
}
|
|
1462
|
+
function $isHorizontalRuleNode(node) {
|
|
1463
|
+
return node instanceof HorizontalRuleNode;
|
|
1464
|
+
}
|
|
1465
|
+
function $toggleNodeSelection(node, shiftKey = false) {
|
|
1466
|
+
const selection = $getSelection();
|
|
1467
|
+
const wasSelected = node.isSelected();
|
|
1468
|
+
const key = node.getKey();
|
|
1469
|
+
let nodeSelection;
|
|
1470
|
+
if (shiftKey && $isNodeSelection(selection)) nodeSelection = selection;
|
|
1471
|
+
else {
|
|
1472
|
+
nodeSelection = $createNodeSelection();
|
|
1473
|
+
$setSelection(nodeSelection);
|
|
1474
|
+
}
|
|
1475
|
+
if (wasSelected) nodeSelection.delete(key);
|
|
1476
|
+
else nodeSelection.add(key);
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* An extension for HorizontalRuleNode that provides an implementation that
|
|
1480
|
+
* works without any React dependency.
|
|
1481
|
+
*/
|
|
1482
|
+
const HorizontalRuleExtension = defineExtension({
|
|
1483
|
+
dependencies: [EditorStateExtension, NodeSelectionExtension],
|
|
1484
|
+
name: "@lexical/extension/HorizontalRule",
|
|
1485
|
+
nodes: () => [HorizontalRuleNode],
|
|
1486
|
+
register(editor, config, state) {
|
|
1487
|
+
const { watchNodeKey } = state.getDependency(NodeSelectionExtension).output;
|
|
1488
|
+
const nodeSelectionStore = a({ nodeSelections: /* @__PURE__ */ new Map() });
|
|
1489
|
+
const isSelectedClassName = editor._config.theme.hrSelected ?? "selected";
|
|
1490
|
+
return mergeRegister(editor.registerCommand(INSERT_HORIZONTAL_RULE_COMMAND, (type) => {
|
|
1491
|
+
const selection = $getSelection();
|
|
1492
|
+
if (!$isRangeSelection(selection)) return false;
|
|
1493
|
+
if (selection.focus.getNode() !== null) $insertNodeToNearestRoot($createHorizontalRuleNode());
|
|
1494
|
+
return true;
|
|
1495
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CLICK_COMMAND, (event) => {
|
|
1496
|
+
if (isDOMNode(event.target)) {
|
|
1497
|
+
const node = $getNodeFromDOMNode(event.target);
|
|
1498
|
+
if ($isHorizontalRuleNode(node)) {
|
|
1499
|
+
$toggleNodeSelection(node, event.shiftKey);
|
|
1500
|
+
return true;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return false;
|
|
1504
|
+
}, COMMAND_PRIORITY_LOW), editor.registerMutationListener(HorizontalRuleNode, (nodes, payload) => {
|
|
1505
|
+
n(() => {
|
|
1506
|
+
let didChange = false;
|
|
1507
|
+
const { nodeSelections } = nodeSelectionStore.peek();
|
|
1508
|
+
for (const [k, v] of nodes.entries()) if (v === "destroyed") {
|
|
1509
|
+
nodeSelections.delete(k);
|
|
1510
|
+
didChange = true;
|
|
1511
|
+
} else {
|
|
1512
|
+
const prev = nodeSelections.get(k);
|
|
1513
|
+
const dom = editor.getElementByKey(k);
|
|
1514
|
+
if (prev) prev.domNode.value = dom;
|
|
1515
|
+
else {
|
|
1516
|
+
didChange = true;
|
|
1517
|
+
nodeSelections.set(k, {
|
|
1518
|
+
domNode: a(dom),
|
|
1519
|
+
selectedSignal: watchNodeKey(k)
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
if (didChange) nodeSelectionStore.value = { nodeSelections };
|
|
1524
|
+
});
|
|
1525
|
+
}), j(() => {
|
|
1526
|
+
const effects = [];
|
|
1527
|
+
for (const { domNode, selectedSignal } of nodeSelectionStore.value.nodeSelections.values()) effects.push(j(() => {
|
|
1528
|
+
const dom = domNode.value;
|
|
1529
|
+
if (dom) if (selectedSignal.value) addClassNamesToElement(dom, isSelectedClassName);
|
|
1530
|
+
else removeClassNamesFromElement(dom, isSelectedClassName);
|
|
1531
|
+
}));
|
|
1532
|
+
return mergeRegister(...effects);
|
|
1533
|
+
}));
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
/**
|
|
1537
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1538
|
+
*
|
|
1539
|
+
* This source code is licensed under the MIT license found in the
|
|
1540
|
+
* LICENSE file in the root directory of this source tree.
|
|
1541
|
+
*
|
|
1542
|
+
*/
|
|
1543
|
+
function $defaultGetParentEditor() {
|
|
1544
|
+
const editor = $getEditor();
|
|
1545
|
+
LexicalBuilder.fromEditor(editor);
|
|
1546
|
+
return editor;
|
|
1547
|
+
}
|
|
1548
|
+
const NestedEditorExtension = defineExtension({
|
|
1549
|
+
build: (editor, config) => namedSignals({ inheritEditableFromParent: config.inheritEditableFromParent }),
|
|
1550
|
+
config: safeCast({
|
|
1551
|
+
$getParentEditor: $defaultGetParentEditor,
|
|
1552
|
+
inheritEditableFromParent: false
|
|
1553
|
+
}),
|
|
1554
|
+
init: (editorConfig, config, state) => {
|
|
1555
|
+
const parentEditor = config.$getParentEditor();
|
|
1556
|
+
editorConfig.parentEditor = parentEditor;
|
|
1557
|
+
editorConfig.theme = editorConfig.theme || parentEditor._config.theme;
|
|
1558
|
+
},
|
|
1559
|
+
name: "@lexical/extension/NestedEditor",
|
|
1560
|
+
register: (editor, config, state) => j(() => {
|
|
1561
|
+
const parentEditor = editor._parentEditor;
|
|
1562
|
+
if (parentEditor) {
|
|
1563
|
+
if (state.getOutput().inheritEditableFromParent.value) {
|
|
1564
|
+
editor.setEditable(parentEditor.isEditable());
|
|
1565
|
+
return parentEditor.registerEditableListener(editor.setEditable.bind(editor));
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
})
|
|
1569
|
+
});
|
|
1570
|
+
/**
|
|
1571
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1572
|
+
*
|
|
1573
|
+
* This source code is licensed under the MIT license found in the
|
|
1574
|
+
* LICENSE file in the root directory of this source tree.
|
|
1575
|
+
*
|
|
1576
|
+
*/
|
|
1577
|
+
/**
|
|
1578
|
+
* An extension that highlights selected content in the Lexical editor
|
|
1579
|
+
* even when the editor is not currently focused.
|
|
1580
|
+
*/
|
|
1581
|
+
const SelectionAlwaysOnDisplayExtension = defineExtension({
|
|
1582
|
+
build: (editor, config, state) => namedSignals(config),
|
|
1583
|
+
config: safeCast({
|
|
1584
|
+
disabled: false,
|
|
1585
|
+
onReposition: void 0
|
|
1586
|
+
}),
|
|
1587
|
+
name: "@lexical/utils/SelectionAlwaysOnDisplay",
|
|
1588
|
+
register: (editor, config, state) => {
|
|
1589
|
+
const stores = state.getOutput();
|
|
1590
|
+
return j(() => {
|
|
1591
|
+
if (!stores.disabled.value) return selectionAlwaysOnDisplay(editor, stores.onReposition.value);
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
/**
|
|
1596
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1597
|
+
*
|
|
1598
|
+
* This source code is licensed under the MIT license found in the
|
|
1599
|
+
* LICENSE file in the root directory of this source tree.
|
|
1600
|
+
*
|
|
1601
|
+
*/
|
|
1602
|
+
function $indentOverTab(selection) {
|
|
1603
|
+
if (selection.getNodes().filter((node) => $isBlockElementNode(node) && node.canIndent()).length > 0) return true;
|
|
1604
|
+
const anchor = selection.anchor;
|
|
1605
|
+
const focus = selection.focus;
|
|
1606
|
+
const first = focus.isBefore(anchor) ? focus : anchor;
|
|
1607
|
+
const firstBlock = $getNearestBlockElementAncestorOrThrow(first.getNode());
|
|
1608
|
+
if (firstBlock.canIndent()) {
|
|
1609
|
+
const firstBlockKey = firstBlock.getKey();
|
|
1610
|
+
let selectionAtStart = $createRangeSelection();
|
|
1611
|
+
selectionAtStart.anchor.set(firstBlockKey, 0, "element");
|
|
1612
|
+
selectionAtStart.focus.set(firstBlockKey, 0, "element");
|
|
1613
|
+
selectionAtStart = $normalizeSelection__EXPERIMENTAL(selectionAtStart);
|
|
1614
|
+
if (selectionAtStart.anchor.is(first)) return true;
|
|
1615
|
+
}
|
|
1616
|
+
return false;
|
|
1617
|
+
}
|
|
1618
|
+
function $defaultCanIndent(node) {
|
|
1619
|
+
return node.canBeEmpty();
|
|
1620
|
+
}
|
|
1621
|
+
function registerTabIndentation(editor, maxIndent, $canIndent = $defaultCanIndent) {
|
|
1622
|
+
return mergeRegister(editor.registerCommand(KEY_TAB_COMMAND, (event) => {
|
|
1623
|
+
const selection = $getSelection();
|
|
1624
|
+
if (!$isRangeSelection(selection)) return false;
|
|
1625
|
+
event.preventDefault();
|
|
1626
|
+
const command = $indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
|
|
1627
|
+
return editor.dispatchCommand(command, void 0);
|
|
1628
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INDENT_CONTENT_COMMAND, () => {
|
|
1629
|
+
const currentMaxIndent = typeof maxIndent === "number" ? maxIndent : maxIndent ? maxIndent.peek() : null;
|
|
1630
|
+
if (!$isRangeSelection($getSelection())) return false;
|
|
1631
|
+
const $currentCanIndent = typeof $canIndent === "function" ? $canIndent : $canIndent.peek();
|
|
1632
|
+
return $handleIndentAndOutdent((block) => {
|
|
1633
|
+
if ($currentCanIndent(block)) {
|
|
1634
|
+
const newIndent = block.getIndent() + 1;
|
|
1635
|
+
if (!currentMaxIndent || newIndent < currentMaxIndent) block.setIndent(newIndent);
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
}, COMMAND_PRIORITY_CRITICAL));
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* This extension adds the ability to indent content using the tab key. Generally, we don't
|
|
1642
|
+
* recommend using this plugin as it could negatively affect accessibility for keyboard
|
|
1643
|
+
* users, causing focus to become trapped within the editor.
|
|
1644
|
+
*/
|
|
1645
|
+
const TabIndentationExtension = defineExtension({
|
|
1646
|
+
build(editor, config, state) {
|
|
1647
|
+
return namedSignals(config);
|
|
1648
|
+
},
|
|
1649
|
+
config: safeCast({
|
|
1650
|
+
$canIndent: $defaultCanIndent,
|
|
1651
|
+
disabled: false,
|
|
1652
|
+
maxIndent: null
|
|
1653
|
+
}),
|
|
1654
|
+
name: "@lexical/extension/TabIndentation",
|
|
1655
|
+
register(editor, config, state) {
|
|
1656
|
+
const { disabled, maxIndent, $canIndent } = state.getOutput();
|
|
1657
|
+
return j(() => {
|
|
1658
|
+
if (!disabled.value) return registerTabIndentation(editor, maxIndent, $canIndent);
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
//#endregion
|
|
1663
|
+
export { $createHorizontalRuleNode, $isDecoratorTextNode, $isHorizontalRuleNode, AutoFocusExtension, ClearEditorExtension, DecoratorTextExtension, DecoratorTextNode, EditorStateExtension, HorizontalRuleExtension, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND, InitialStateExtension, LexicalBuilder, NestedEditorExtension, NodeSelectionExtension, SelectionAlwaysOnDisplayExtension, TabIndentationExtension, applyFormatFromStyle, applyFormatToDom, n as batch, buildEditorFromExtensions, g as computed, configExtension, declarePeerDependency, defineExtension, j as effect, getExtensionDependencyFromEditor, getKnownTypesAndNodes, getPeerDependencyFromEditor, getPeerDependencyFromEditorOrThrow, namedSignals, registerClearEditor, registerTabIndentation, safeCast, shallowMergeConfig, a as signal, h as untracked, watchedSignal };
|
|
1664
|
+
|
|
1665
|
+
//# sourceMappingURL=LexicalExtension.dev-CtDZiMCU.mjs.map
|