@mx-space/cli 0.14.1 → 0.15.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.
Files changed (56) hide show
  1. package/README.md +35 -11
  2. package/dist/{Lexical.dev-DTxuYHmG.mjs → Lexical.dev-Cck4n26y.mjs} +998 -584
  3. package/dist/{Lexical.node-BlCLnfA6.mjs → Lexical.node-D6wf2D5M.mjs} +15 -5
  4. package/dist/Lexical.prod-DCwS1oTq.mjs +7170 -0
  5. package/dist/{LexicalClipboard.dev-CdFkLR_D.mjs → LexicalClipboard.dev-CMkPHV7O.mjs} +6 -6
  6. package/dist/{LexicalClipboard.node-ktUajxsv.mjs → LexicalClipboard.node-m4nZ7IYw.mjs} +2 -2
  7. package/dist/{LexicalClipboard.prod-DliyLofW.mjs → LexicalClipboard.prod-B_rN1vE1.mjs} +10 -8
  8. package/dist/{LexicalCodeCore.dev-CL9tHWJX.mjs → LexicalCodeCore.dev-DyJw3i8V.mjs} +62 -72
  9. package/dist/{LexicalCodeCore.prod-BoMSJc29.mjs → LexicalCodeCore.prod-DPXLHQLF.mjs} +212 -213
  10. package/dist/{LexicalDragon.dev-CqW7Aq5H.mjs → LexicalDragon.dev-ZkNfMwrE.mjs} +3 -3
  11. package/dist/{LexicalDragon.node-DLXctJyy.mjs → LexicalDragon.node-Ds9oLUFh.mjs} +2 -2
  12. package/dist/{LexicalDragon.prod-DHI3T6n5.mjs → LexicalDragon.prod-B58ic2av.mjs} +5 -4
  13. package/dist/{LexicalExtension.dev-BP-18zns.mjs → LexicalExtension.dev-DvwHs1Xv.mjs} +79 -67
  14. package/dist/{LexicalExtension.node-BWH6xbzG.mjs → LexicalExtension.node-5OymZQfy.mjs} +4 -2
  15. package/dist/{LexicalExtension.prod-Cs6OgrDn.mjs → LexicalExtension.prod-Ce0T5smQ.mjs} +372 -358
  16. package/dist/{LexicalHeadless.dev-DJp__UcP.mjs → LexicalHeadless.dev-DA0WldSR.mjs} +2 -2
  17. package/dist/{LexicalHeadless.prod-o0v9cIu5.mjs → LexicalHeadless.prod-1kQgKB6c.mjs} +2 -2
  18. package/dist/{LexicalHtml.dev-DoymwFpG.mjs → LexicalHtml.dev-BDB7CUrx.mjs} +14 -12
  19. package/dist/{LexicalHtml.node-CVkbWtUA.mjs → LexicalHtml.node-DpVNt7It.mjs} +4 -4
  20. package/dist/{LexicalHtml.prod-C2b3z99k.mjs → LexicalHtml.prod-HkxM5scw.mjs} +331 -300
  21. package/dist/{LexicalLink.dev-7cgLOLIe.mjs → LexicalLink.dev-C5zNJlrm.mjs} +65 -59
  22. package/dist/{LexicalLink.prod-DWFgoXHR.mjs → LexicalLink.prod-Bkt9hQAt.mjs} +196 -201
  23. package/dist/{LexicalList.dev-Ci2iOxFx.mjs → LexicalList.dev-B7VgME-m.mjs} +55 -82
  24. package/dist/LexicalList.prod-B8c7TDjH.mjs +951 -0
  25. package/dist/{LexicalMarkdown.dev-C0ZYCyuR.mjs → LexicalMarkdown.dev-B5z9kLbV.mjs} +62 -42
  26. package/dist/{LexicalMarkdown.prod-0M-Nc-rh.mjs → LexicalMarkdown.prod-wKzw7FFH.mjs} +255 -202
  27. package/dist/{LexicalRichText.dev-Cnr1kDym.mjs → LexicalRichText.dev-CUd6Li5F.mjs} +399 -120
  28. package/dist/{LexicalRichText.node-BUJZAiap.mjs → LexicalRichText.node-BKfaQ-CH.mjs} +12 -8
  29. package/dist/LexicalRichText.prod-SBewjJHx.mjs +708 -0
  30. package/dist/{LexicalSelection.dev-C4L7l8OB.mjs → LexicalSelection.dev-D27JOCqj.mjs} +48 -17
  31. package/dist/{LexicalSelection.node-CLKroUMQ.mjs → LexicalSelection.node-DBEwPjBu.mjs} +5 -4
  32. package/dist/{LexicalSelection.prod-DzFqpTlw.mjs → LexicalSelection.prod-OaYhXHOL.mjs} +101 -92
  33. package/dist/{LexicalTable.dev-Cc9-zqKa.mjs → LexicalTable.dev-6IFFOAE0.mjs} +590 -259
  34. package/dist/LexicalTable.prod-2CaLZ7fH.mjs +2524 -0
  35. package/dist/{LexicalUtils.dev-BRgK0L6G.mjs → LexicalUtils.dev-DJA7J_7v.mjs} +15 -19
  36. package/dist/{LexicalUtils.node-BVAwOkL4.mjs → LexicalUtils.node-Df9oPTlA.mjs} +6 -6
  37. package/dist/{LexicalUtils.prod-C1gtvVDP.mjs → LexicalUtils.prod-Bb7V4Ewg.mjs} +155 -159
  38. package/dist/bin/mxs.mjs +1 -1
  39. package/dist/esm-CDcJmHkG.mjs +2 -0
  40. package/dist/{esm-BNu4sUWV.mjs → esm-DLzrv7gD.mjs} +1837 -6015
  41. package/dist/index.d.mts +57 -62
  42. package/dist/index.mjs +1 -1
  43. package/dist/{mxs-CMX2yklg.mjs → mxs-BIRW5Axj.mjs} +13579 -8682
  44. package/dist/rolldown-runtime-JspESFgx.mjs +35 -0
  45. package/dist/vendor/litexml/cli.mjs +7043 -6207
  46. package/dist/vendor/litexml/litexml-html-preview-client.css +80 -47
  47. package/dist/vendor/litexml/litexml-html-preview-client.js +14422 -10838
  48. package/dist/vendor/litexml/style.css +6 -2
  49. package/package.json +23 -23
  50. package/skills/commands-ai.md +45 -12
  51. package/skills/overview.md +1 -1
  52. package/dist/Lexical.prod-CeB9UQuo.mjs +0 -6816
  53. package/dist/LexicalList.prod-D0xX5d3G.mjs +0 -944
  54. package/dist/LexicalRichText.prod-BfbMQ9uM.mjs +0 -538
  55. package/dist/LexicalTable.prod-BgO4nCxy.mjs +0 -2336
  56. package/dist/esm-jbwcVZth.mjs +0 -2
@@ -1,2336 +0,0 @@
1
- import { f as namedSignals, l as effect, p as signal } from "./LexicalExtension.node-BWH6xbzG.mjs";
2
- import { $t as CONTROLLED_TEXT_INSERTION_COMMAND, A as $getChildCaret, An as IS_FIREFOX, B as $getNodeByKeyOrThrow, Bn as KEY_ARROW_LEFT_COMMAND, Br as isDOMDocumentNode, C as $getAdjacentChildCaret, Ct as $normalizeCaret, Dn as IS_BOLD, Dr as getDOMSelectionRange, Er as getDOMSelectionPoints, Fn as IS_STRIKETHROUGH, G as $getSiblingCaret, H as $getPreviousSelection, Hn as KEY_ARROW_UP_COMMAND, Hr as isDOMShadowRoot, Ht as CLICK_COMMAND, I as $getEditor, Jn as KEY_TAB_COMMAND, Jr as isHTMLTableRowElement, Jt as COMMAND_PRIORITY_HIGH, Kn as KEY_ESCAPE_COMMAND, Mt as $setSelection, Nn as IS_ITALIC, R as $getNearestNodeFromDOMNode, Rn as IS_UNDERLINE, Tr as getDOMSelection, U as $getRoot, Un as KEY_BACKSPACE_COMMAND, Vn as KEY_ARROW_RIGHT_COMMAND, Vr as isDOMNode, W as $getSelection, Wn as KEY_DELETE_COMMAND, Yt as COMMAND_PRIORITY_LOW, _t as $isSiblingCaret, ai as safeCast, an as DELETE_LINE_COMMAND, ar as SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, at as $isElementNode, b as $findMatchingParent, bn as INSERT_PARAGRAPH_COMMAND, br as defineExtension, bt as $isTextNode, dn as ElementNode, fn as FOCUS_COMMAND, ft as $isParagraphNode, g as $createRangeSelectionFromDom, gr as createCommand, h as $createRangeSelection, hr as configExtension, ht as $isRootOrShadowRoot, i as $caretFromPoint, ii as removeClassNamesFromElement, in as DELETE_CHARACTER_COMMAND, ir as SELECTION_CHANGE_COMMAND, jt as $setPointFromCaret, m as $createPoint, mn as FORMAT_TEXT_COMMAND, mt as $isRootNode, n as $applyNodeReplacement, ni as mergeRegister, nt as $isChildCaret, oi as setDOMStyleFromCSS, on as DELETE_WORD_COMMAND, or as SELECT_ALL_COMMAND, ot as $isExtendableTextPointCaret, p as $createParagraphNode, pn as FORMAT_ELEMENT_COMMAND, pr as addClassNamesToElement, pt as $isRangeSelection, qr as isHTMLElement, qt as COMMAND_PRIORITY_EDITOR, si as setDOMUnmanaged, st as $isInlineElementOrDecoratorNode, tn as CUT_COMMAND, ur as TEXT_TYPE_TO_FORMAT, ut as $isLineBreakNode, v as $createTextNode, wr as getComposedEventTarget, wt as $normalizeSelection__EXPERIMENTAL, x as $fullReconcile, y as $extendCaretToRange, z as $getNodeByKey, zn as KEY_ARROW_DOWN_COMMAND, zr as isCurrentlyReadOnlyMode } from "./Lexical.node-BlCLnfA6.mjs";
3
- import { c as DOMImportExtension, f as ImportTextFormat, h as defineImportRule, m as contextValue, o as $propagateTextAlignToBlockChildren, p as ImportTextStyle, s as CoreImportExtension, v as sel } from "./LexicalHtml.node-CVkbWtUA.mjs";
4
- import { d as $unwrapAndFilterDescendants, h as objectKlassEquals, n as $dfsWithSlots, o as $insertFirst, s as $insertNodeToNearestRoot, t as $descendantsMatching } from "./LexicalUtils.node-BVAwOkL4.mjs";
5
- import { o as copyToClipboard, t as $getClipboardDataFromSelection } from "./LexicalClipboard.node-ktUajxsv.mjs";
6
- //#region ../../node_modules/.pnpm/@lexical+table@0.46.0_typescript@6.0.3/node_modules/@lexical/table/dist/LexicalTable.prod.mjs
7
- /**
8
- * Copyright (c) Meta Platforms, Inc. and affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- */
14
- const Ve = /^(\d+(?:\.\d+)?)px$/, Ge = {
15
- BOTH: 3,
16
- COLUMN: 2,
17
- NO_STATUS: 0,
18
- ROW: 1
19
- };
20
- var Qe = class Qe extends ElementNode {
21
- __colSpan;
22
- __rowSpan;
23
- __headerState;
24
- __width;
25
- __backgroundColor;
26
- __verticalAlign;
27
- static getType() {
28
- return "tablecell";
29
- }
30
- static clone(e) {
31
- return new Qe(e.__headerState, e.__colSpan, e.__width, e.__key);
32
- }
33
- afterCloneFrom(e) {
34
- super.afterCloneFrom(e), this.__rowSpan = e.__rowSpan, this.__backgroundColor = e.__backgroundColor, this.__verticalAlign = e.__verticalAlign, this.__colSpan = e.__colSpan, this.__headerState = e.__headerState, this.__width = e.__width;
35
- }
36
- static importDOM() {
37
- return {
38
- td: (e) => ({
39
- conversion: et,
40
- priority: 0
41
- }),
42
- th: (e) => ({
43
- conversion: et,
44
- priority: 0
45
- })
46
- };
47
- }
48
- static importJSON(e) {
49
- return tt().updateFromJSON(e);
50
- }
51
- updateFromJSON(e) {
52
- return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan || 1).setRowSpan(e.rowSpan || 1).setWidth(e.width || void 0).setBackgroundColor(e.backgroundColor || null).setVerticalAlign(e.verticalAlign || void 0);
53
- }
54
- constructor(e = Ge.NO_STATUS, t = 1, n, o) {
55
- super(o), this.__colSpan = t, this.__rowSpan = 1, this.__headerState = e, this.__width = n, this.__backgroundColor = null, this.__verticalAlign = void 0;
56
- }
57
- createDOM(e) {
58
- const n = document.createElement(this.getTag());
59
- return this.__width && (n.style.width = `${this.__width}px`), this.__colSpan > 1 && (n.colSpan = this.__colSpan), this.__rowSpan > 1 && (n.rowSpan = this.__rowSpan), null !== this.__backgroundColor && (n.style.backgroundColor = this.__backgroundColor), Ze(this.__verticalAlign) && (n.style.verticalAlign = this.__verticalAlign), addClassNamesToElement(n, e.theme.tableCell, this.hasHeader() && e.theme.tableCellHeader), n;
60
- }
61
- exportDOM(e) {
62
- const t = super.exportDOM(e);
63
- if (isHTMLElement(t.element)) {
64
- const e = t.element;
65
- e.setAttribute("data-temporary-table-cell-lexical-key", this.getKey()), e.style.border = "1px solid black", this.__colSpan > 1 && (e.colSpan = this.__colSpan), this.__rowSpan > 1 && (e.rowSpan = this.__rowSpan), e.style.width = `${this.getWidth() || 75}px`, e.style.verticalAlign = this.getVerticalAlign() || "top", e.style.textAlign = "start", null === this.__backgroundColor && this.hasHeader() && (e.style.backgroundColor = "#f2f3f5");
66
- }
67
- return t;
68
- }
69
- exportJSON() {
70
- return {
71
- ...super.exportJSON(),
72
- ...Ze(this.__verticalAlign) && { verticalAlign: this.__verticalAlign },
73
- backgroundColor: this.getBackgroundColor(),
74
- colSpan: this.__colSpan,
75
- headerState: this.__headerState,
76
- rowSpan: this.__rowSpan,
77
- width: this.getWidth()
78
- };
79
- }
80
- getColSpan() {
81
- return this.getLatest().__colSpan;
82
- }
83
- setColSpan(e) {
84
- const t = this.getWritable();
85
- return t.__colSpan = e, t;
86
- }
87
- getRowSpan() {
88
- return this.getLatest().__rowSpan;
89
- }
90
- setRowSpan(e) {
91
- const t = this.getWritable();
92
- return t.__rowSpan = e, t;
93
- }
94
- getTag() {
95
- return this.hasHeader() ? "th" : "td";
96
- }
97
- setHeaderStyles(e, t = Ge.BOTH) {
98
- const n = this.getWritable();
99
- return n.__headerState = e & t | n.__headerState & ~t, n;
100
- }
101
- getHeaderStyles() {
102
- return this.getLatest().__headerState;
103
- }
104
- setWidth(e) {
105
- const t = this.getWritable();
106
- return t.__width = e, t;
107
- }
108
- getWidth() {
109
- return this.getLatest().__width;
110
- }
111
- getBackgroundColor() {
112
- return this.getLatest().__backgroundColor;
113
- }
114
- setBackgroundColor(e) {
115
- const t = this.getWritable();
116
- return t.__backgroundColor = e, t;
117
- }
118
- getVerticalAlign() {
119
- return this.getLatest().__verticalAlign;
120
- }
121
- setVerticalAlign(e) {
122
- const t = this.getWritable();
123
- return t.__verticalAlign = e || void 0, t;
124
- }
125
- toggleHeaderStyle(e) {
126
- const t = this.getWritable();
127
- return (t.__headerState & e) === e ? t.__headerState -= e : t.__headerState += e, t;
128
- }
129
- hasHeaderState(e) {
130
- return (this.getHeaderStyles() & e) === e;
131
- }
132
- hasHeader() {
133
- return this.getLatest().__headerState !== Ge.NO_STATUS;
134
- }
135
- updateDOM(e) {
136
- return e.__headerState !== this.__headerState || e.__width !== this.__width || e.__colSpan !== this.__colSpan || e.__rowSpan !== this.__rowSpan || e.__backgroundColor !== this.__backgroundColor || e.__verticalAlign !== this.__verticalAlign;
137
- }
138
- isShadowRoot() {
139
- return !0;
140
- }
141
- collapseAtStart() {
142
- return !0;
143
- }
144
- canBeEmpty() {
145
- return !1;
146
- }
147
- canIndent() {
148
- return !1;
149
- }
150
- };
151
- function Ze(e) {
152
- return "middle" === e || "bottom" === e;
153
- }
154
- function et(e) {
155
- const t = e, i = e.nodeName.toLowerCase();
156
- let c;
157
- Ve.test(t.style.width) && (c = parseFloat(t.style.width));
158
- let a = Ge.NO_STATUS;
159
- if ("th" === i) {
160
- const e = t.getAttribute("scope");
161
- if ("col" === e) a = Ge.COLUMN;
162
- else if ("row" === e) a = Ge.ROW;
163
- else {
164
- const e = t.parentElement, o = isHTMLElement(e) && "tr" === e.nodeName.toLowerCase() && isHTMLElement(e.parentElement) && ("thead" === e.parentElement.nodeName.toLowerCase() || 0 === e.rowIndex), r = 0 === t.cellIndex;
165
- o && (a |= Ge.ROW), r && (a |= Ge.COLUMN), a === Ge.NO_STATUS && (a = Ge.ROW);
166
- }
167
- }
168
- const u = tt(a, t.colSpan, c);
169
- u.__rowSpan = t.rowSpan;
170
- const h = t.style.backgroundColor;
171
- "" !== h && (u.__backgroundColor = h);
172
- const d = t.style.verticalAlign;
173
- Ze(d) && (u.__verticalAlign = d);
174
- const f = t.style, g = (f && f.textDecoration || "").split(" "), m = "700" === f.fontWeight || "bold" === f.fontWeight, p = g.includes("line-through"), C = "italic" === f.fontStyle, _ = g.includes("underline"), S = f.color;
175
- return {
176
- after: (e) => {
177
- const t = [];
178
- let n = null;
179
- const i = () => {
180
- if (n) {
181
- const e = n.getFirstChild();
182
- $isLineBreakNode(e) && 1 === n.getChildrenSize() && e.remove();
183
- }
184
- };
185
- for (const c of e) if ($isInlineElementOrDecoratorNode(c) || $isTextNode(c) || $isLineBreakNode(c)) {
186
- if ($isTextNode(c) && (m && c.toggleFormat("bold"), p && c.toggleFormat("strikethrough"), C && c.toggleFormat("italic"), _ && c.toggleFormat("underline"), S)) {
187
- const e = c.getStyle();
188
- e.includes("color:") || c.setStyle(e + `color: ${S};`);
189
- }
190
- n ? n.append(c) : (n = $createParagraphNode().append(c), t.push(n));
191
- } else t.push(c), i(), n = null;
192
- return i(), 0 === t.length && t.push($createParagraphNode()), t;
193
- },
194
- node: u
195
- };
196
- }
197
- function tt(e = Ge.NO_STATUS, t = 1, n) {
198
- return $applyNodeReplacement(new Qe(e, t, n));
199
- }
200
- function nt(e) {
201
- return e instanceof Qe;
202
- }
203
- const ot = /* @__PURE__ */ createCommand("INSERT_TABLE_COMMAND");
204
- function rt(e, ...t) {
205
- const n = new URL("https://lexical.dev/docs/error"), o = new URLSearchParams();
206
- o.append("code", e);
207
- for (const e of t) o.append("v", e);
208
- throw n.search = o.toString(), Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
209
- }
210
- var lt = class lt extends ElementNode {
211
- __height;
212
- static getType() {
213
- return "tablerow";
214
- }
215
- static clone(e) {
216
- return new lt(e.__height, e.__key);
217
- }
218
- afterCloneFrom(e) {
219
- super.afterCloneFrom(e), this.__height = e.__height;
220
- }
221
- static importDOM() {
222
- return { tr: (e) => ({
223
- conversion: st,
224
- priority: 0
225
- }) };
226
- }
227
- static importJSON(e) {
228
- return it().updateFromJSON(e);
229
- }
230
- updateFromJSON(e) {
231
- return super.updateFromJSON(e).setHeight(e.height);
232
- }
233
- constructor(e, t) {
234
- super(t), this.__height = e;
235
- }
236
- exportJSON() {
237
- const e = this.getHeight();
238
- return {
239
- ...super.exportJSON(),
240
- ...void 0 === e ? void 0 : { height: e }
241
- };
242
- }
243
- createDOM(e) {
244
- const n = document.createElement("tr");
245
- return this.__height && (n.style.height = `${this.__height}px`), addClassNamesToElement(n, e.theme.tableRow), n;
246
- }
247
- extractWithChild(e, t, n) {
248
- return "html" === n;
249
- }
250
- isShadowRoot() {
251
- return !0;
252
- }
253
- setHeight(e) {
254
- const t = this.getWritable();
255
- return t.__height = e, t;
256
- }
257
- getHeight() {
258
- return this.getLatest().__height;
259
- }
260
- updateDOM(e) {
261
- return e.__height !== this.__height;
262
- }
263
- canBeEmpty() {
264
- return !1;
265
- }
266
- canIndent() {
267
- return !1;
268
- }
269
- };
270
- function st(e) {
271
- const t = e;
272
- let n;
273
- return Ve.test(t.style.height) && (n = parseFloat(t.style.height)), {
274
- after: (e) => $descendantsMatching(e, nt),
275
- node: it(n)
276
- };
277
- }
278
- function it(e) {
279
- return $applyNodeReplacement(new lt(e));
280
- }
281
- function ct(e) {
282
- return e instanceof lt;
283
- }
284
- function at(e, t, n = !0) {
285
- const o = Jn();
286
- for (let r = 0; r < e; r++) {
287
- const e = it();
288
- for (let o = 0; o < t; o++) {
289
- let t = Ge.NO_STATUS;
290
- "object" == typeof n ? (0 === r && n.rows && (t |= Ge.ROW), 0 === o && n.columns && (t |= Ge.COLUMN)) : n && (0 === r && (t |= Ge.ROW), 0 === o && (t |= Ge.COLUMN));
291
- const l = tt(t), i = $createParagraphNode();
292
- i.append($createTextNode()), l.append(i), e.append(l);
293
- }
294
- o.append(e);
295
- }
296
- return o;
297
- }
298
- function ut(e) {
299
- const t = $findMatchingParent(e, (e) => nt(e));
300
- return nt(t) ? t : null;
301
- }
302
- function ht(e) {
303
- const t = $findMatchingParent(e, (e) => ct(e));
304
- if (ct(t)) return t;
305
- throw new Error("Expected table cell to be inside of table row.");
306
- }
307
- function dt(e) {
308
- const t = $findMatchingParent(e, (e) => Xn(e));
309
- if (Xn(t)) return t;
310
- throw new Error("Expected table cell to be inside of table.");
311
- }
312
- function ft(e) {
313
- const t = ht(e);
314
- return dt(t).getChildren().findIndex((e) => e.is(t));
315
- }
316
- function gt(e) {
317
- return ht(e).getChildren().findIndex((t) => t.is(e));
318
- }
319
- function mt(e, t) {
320
- const n = dt(e), { x: o, y: r } = n.getCordsFromCellNode(e, t);
321
- return {
322
- above: n.getCellNodeFromCords(o, r - 1, t),
323
- below: n.getCellNodeFromCords(o, r + 1, t),
324
- left: n.getCellNodeFromCords(o - 1, r, t),
325
- right: n.getCellNodeFromCords(o + 1, r, t)
326
- };
327
- }
328
- function pt(e, t) {
329
- const n = e.getChildren();
330
- if (t >= n.length || t < 0) throw new Error("Expected table cell to be inside of table row.");
331
- return n[t].remove(), e;
332
- }
333
- function Ct(e, t, n = !0, o, r) {
334
- const l = e.getChildren();
335
- if (t >= l.length || t < 0) throw new Error("Table row target index out of range");
336
- const i = l[t];
337
- if (!ct(i)) throw new Error("Row before insertion index does not exist.");
338
- for (let e = 0; e < o; e++) {
339
- const e = i.getChildren(), t = e.length, o = it();
340
- for (let n = 0; n < t; n++) {
341
- const t = e[n];
342
- nt(t) || rt(12);
343
- const { above: l, below: i } = mt(t, r);
344
- let c = Ge.NO_STATUS;
345
- const a = l && l.getWidth() || i && i.getWidth() || void 0;
346
- (l && l.hasHeaderState(Ge.COLUMN) || i && i.hasHeaderState(Ge.COLUMN)) && (c |= Ge.COLUMN);
347
- const u = tt(c, 1, a);
348
- u.append($createParagraphNode()), o.append(u);
349
- }
350
- n ? i.insertAfter(o) : i.insertBefore(o);
351
- }
352
- return e;
353
- }
354
- const _t = (e, t) => e === Ge.BOTH || e === t ? t : Ge.NO_STATUS;
355
- function St(e = !0) {
356
- const t = $getSelection();
357
- $isRangeSelection(t) || Xt(t) || rt(188);
358
- const n = t.anchor.getNode(), o = t.focus.getNode(), [r] = Lt(n), [l, , s] = Lt(o), [, i, c] = zt(s, l, r), { startRow: a } = c, { startRow: d } = i;
359
- return e ? wt(a + r.__rowSpan > d + l.__rowSpan ? r : l, !0) : wt(d < a ? l : r, !1);
360
- }
361
- const bt = St;
362
- function wt(e, t = !0) {
363
- const [, , n] = Lt(e), [o, r] = zt(n, e, e), l = o[0].length, { startRow: i } = r;
364
- let c = null;
365
- if (t) {
366
- const t = i + e.__rowSpan - 1, r = o[t], a = it();
367
- for (let e = 0; e < l; e++) {
368
- const { cell: n, startRow: o } = r[e];
369
- if (o + n.__rowSpan - 1 <= t) {
370
- const t = r[e].cell.__headerState, n = _t(t, Ge.COLUMN);
371
- a.append(tt(n).append($createParagraphNode()));
372
- } else n.setRowSpan(n.__rowSpan + 1);
373
- }
374
- const u = n.getChildAtIndex(t);
375
- ct(u) || rt(256), u.insertAfter(a), c = a;
376
- } else {
377
- const e = i, t = o[e], r = it();
378
- for (let n = 0; n < l; n++) {
379
- const { cell: o, startRow: l } = t[n];
380
- if (l === e) {
381
- const e = t[n].cell.__headerState, o = _t(e, Ge.COLUMN);
382
- r.append(tt(o).append($createParagraphNode()));
383
- } else o.setRowSpan(o.__rowSpan + 1);
384
- }
385
- const a = n.getChildAtIndex(e);
386
- ct(a) || rt(257), a.insertBefore(r), c = r;
387
- }
388
- return c;
389
- }
390
- function yt(e, t, n = !0, o, r) {
391
- const l = e.getChildren(), i = [];
392
- for (let e = 0; e < l.length; e++) {
393
- const n = l[e];
394
- if (ct(n)) for (let e = 0; e < o; e++) {
395
- const e = n.getChildren();
396
- if (t >= e.length || t < 0) throw new Error("Table column target index out of range");
397
- const o = e[t];
398
- nt(o) || rt(12);
399
- const { left: l, right: c } = mt(o, r);
400
- let a = Ge.NO_STATUS;
401
- (l && l.hasHeaderState(Ge.ROW) || c && c.hasHeaderState(Ge.ROW)) && (a |= Ge.ROW);
402
- const u = tt(a);
403
- u.append($createParagraphNode()), i.push({
404
- newTableCell: u,
405
- targetCell: o
406
- });
407
- }
408
- }
409
- return i.forEach(({ newTableCell: e, targetCell: t }) => {
410
- n ? t.insertAfter(e) : t.insertBefore(e);
411
- }), e;
412
- }
413
- function Nt(e = !0) {
414
- const t = $getSelection();
415
- $isRangeSelection(t) || Xt(t) || rt(188);
416
- const n = t.anchor.getNode(), o = t.focus.getNode(), [r] = Lt(n), [l, , s] = Lt(o), [, i, c] = zt(s, l, r), { startColumn: a } = c, { startColumn: d } = i;
417
- return e ? xt(a + r.__colSpan > d + l.__colSpan ? r : l, !0) : xt(d < a ? l : r, !1);
418
- }
419
- const vt = Nt;
420
- function xt(e, t = !0, n = !0) {
421
- const [, , o] = Lt(e), [r, l] = zt(o, e, e), i = r.length, { startColumn: c } = l, a = t ? c + e.__colSpan - 1 : c - 1, u = o.getFirstChild();
422
- ct(u) || rt(120);
423
- let h = null;
424
- function d(e = Ge.NO_STATUS) {
425
- const t = tt(e).append($createParagraphNode());
426
- return null === h && (h = t), t;
427
- }
428
- let f = u;
429
- e: for (let e = 0; e < i; e++) {
430
- if (0 !== e) {
431
- const e = f.getNextSibling();
432
- ct(e) || rt(121), f = e;
433
- }
434
- const t = r[e], n = t[a < 0 ? 0 : a].cell.__headerState, o = _t(n, Ge.ROW);
435
- if (a < 0) {
436
- kt(f, d(o));
437
- continue;
438
- }
439
- const { cell: l, startColumn: s, startRow: i } = t[a];
440
- if (s + l.__colSpan - 1 <= a) {
441
- let n = l, r = i, s = a;
442
- for (; r !== e && n.__rowSpan > 1;) {
443
- if (s -= l.__colSpan, !(s >= 0)) {
444
- f.append(d(o));
445
- continue e;
446
- }
447
- {
448
- const { cell: e, startRow: o } = t[s];
449
- n = e, r = o;
450
- }
451
- }
452
- n.insertAfter(d(o));
453
- } else l.setColSpan(l.__colSpan + 1);
454
- }
455
- null !== h && n && Kt(h);
456
- const g = o.getColWidths();
457
- if (g) {
458
- const e = [...g], t = a < 0 ? 0 : a, n = e[t];
459
- e.splice(t, 0, n), o.setColWidths(e);
460
- }
461
- return h;
462
- }
463
- function Tt(e, t) {
464
- const n = e.getChildren();
465
- for (let e = 0; e < n.length; e++) {
466
- const o = n[e];
467
- if (ct(o)) {
468
- const e = o.getChildren();
469
- if (t >= e.length || t < 0) throw new Error("Table column target index out of range");
470
- e[t].remove();
471
- }
472
- }
473
- return e;
474
- }
475
- function Rt() {
476
- const e = $getSelection();
477
- $isRangeSelection(e) || Xt(e) || rt(188);
478
- const [t, n] = e.isBackward() ? [e.focus.getNode(), e.anchor.getNode()] : [e.anchor.getNode(), e.focus.getNode()], [o, , r] = Lt(t), [l] = Lt(n), [s, i, c] = zt(r, o, l), { startRow: a } = i, { startRow: d } = c, f = d + l.__rowSpan - 1;
479
- if (s.length === f - a + 1) return void r.remove();
480
- const g = s[0].length, m = s[f + 1], p = r.getChildAtIndex(f + 1);
481
- for (let e = f; e >= a; e--) {
482
- for (let t = g - 1; t >= 0; t--) {
483
- const { cell: n, startRow: o, startColumn: r } = s[e][t];
484
- if (r === t) {
485
- if (o < a || o + n.__rowSpan - 1 > f) {
486
- const e = Math.max(o, a), t = Math.min(n.__rowSpan + o - 1, f), r = e <= t ? t - e + 1 : 0;
487
- n.setRowSpan(n.__rowSpan - r);
488
- }
489
- if (o >= a && o + n.__rowSpan - 1 > f && e === f) {
490
- ct(p) || rt(387);
491
- let o = null;
492
- for (let n = 0; n < t; n++) {
493
- const t = m[n], r = t.cell;
494
- t.startRow === e + 1 && (o = r), r.__colSpan > 1 && (n += r.__colSpan - 1);
495
- }
496
- null === o ? kt(p, n) : o.insertAfter(n);
497
- }
498
- }
499
- }
500
- const t = r.getChildAtIndex(e);
501
- ct(t) || rt(206, String(e)), t.remove();
502
- }
503
- if (void 0 !== m) {
504
- const { cell: e } = m[0];
505
- Kt(e);
506
- } else {
507
- const { cell: t } = s[a - 1][0];
508
- Kt(t);
509
- }
510
- }
511
- const Ft = Rt;
512
- function Ot() {
513
- const e = $getSelection();
514
- $isRangeSelection(e) || Xt(e) || rt(188);
515
- const t = e.anchor.getNode(), n = e.focus.getNode(), [o, , r] = Lt(t), [l] = Lt(n), [s, i, c] = zt(r, o, l), { startColumn: a } = i, { startRow: d, startColumn: f } = c, g = Math.min(a, f), m = Math.max(a + o.__colSpan - 1, f + l.__colSpan - 1), p = m - g + 1;
516
- if (s[0].length === m - g + 1) return r.selectPrevious(), void r.remove();
517
- const C = s.length;
518
- for (let e = 0; e < C; e++) for (let t = g; t <= m; t++) {
519
- const { cell: n, startColumn: o } = s[e][t];
520
- if (o < g) {
521
- if (t === g) {
522
- const e = g - o;
523
- n.setColSpan(n.__colSpan - Math.min(p, n.__colSpan - e));
524
- }
525
- } else if (o + n.__colSpan - 1 > m) {
526
- if (t === m) {
527
- const e = m - o + 1;
528
- n.setColSpan(n.__colSpan - e);
529
- }
530
- } else n.remove();
531
- }
532
- const _ = s[d], S = a > f ? _[a + o.__colSpan] : _[f + l.__colSpan];
533
- if (void 0 !== S) {
534
- const { cell: e } = S;
535
- Kt(e);
536
- } else {
537
- const { cell: t } = f < a ? _[f - 1] : _[a - 1];
538
- Kt(t);
539
- }
540
- const b = r.getColWidths();
541
- if (b) {
542
- const e = [...b];
543
- e.splice(g, p), r.setColWidths(e);
544
- }
545
- }
546
- const At = Ot;
547
- function Kt(e) {
548
- const t = e.getFirstDescendant();
549
- null == t ? e.selectStart() : t.getParentOrThrow().selectStart();
550
- }
551
- function kt(e, t) {
552
- const n = e.getFirstChild();
553
- null !== n ? n.insertBefore(t) : e.append(t);
554
- }
555
- function Et(e) {
556
- if (0 === e.length) return null;
557
- const [n] = Ht(dt(e[0]), null, null);
558
- let o = Infinity, r = -Infinity, l = Infinity, i = -Infinity;
559
- const c = /* @__PURE__ */ new Set();
560
- for (const t of n) for (const n of t) {
561
- if (!n || !n.cell) continue;
562
- const t = n.cell.getKey();
563
- if (!c.has(t) && e.some((e) => e.is(n.cell))) {
564
- c.add(t);
565
- const e = n.startRow, s = n.startColumn, a = n.cell.__rowSpan || 1, u = n.cell.__colSpan || 1;
566
- o = Math.min(o, e), r = Math.max(r, e + a - 1), l = Math.min(l, s), i = Math.max(i, s + u - 1);
567
- }
568
- }
569
- if (o === Infinity || l === Infinity) return null;
570
- const a = r - o + 1, u = i - l + 1, h = n[o][l];
571
- if (!h.cell) return null;
572
- const d = h.cell;
573
- d.setColSpan(u), d.setRowSpan(a);
574
- const f = /* @__PURE__ */ new Set([d.getKey()]);
575
- for (let e = o; e <= r; e++) for (let t = l; t <= i; t++) {
576
- const o = n[e][t];
577
- if (!o.cell) continue;
578
- const r = o.cell, l = r.getKey();
579
- if (!f.has(l)) {
580
- f.add(l);
581
- Mt(r) || d.append(...r.getChildren()), r.remove();
582
- }
583
- }
584
- return 0 === d.getChildrenSize() && d.append($createParagraphNode()), d;
585
- }
586
- function Mt(e) {
587
- if (1 !== e.getChildrenSize()) return !1;
588
- const t = e.getFirstChildOrThrow();
589
- return !(!$isParagraphNode(t) || !t.isEmpty());
590
- }
591
- function $t() {
592
- const e = $getSelection();
593
- $isRangeSelection(e) || Xt(e) || rt(188);
594
- const n = $findMatchingParent(e.anchor.getNode(), nt);
595
- return nt(n) || rt(148), Wt(n);
596
- }
597
- function Wt(e) {
598
- const [t, n, o] = Lt(e), r = t.__colSpan, l = t.__rowSpan;
599
- if (1 === r && 1 === l) return;
600
- const [i, c] = zt(o, t, t), { startColumn: a, startRow: u } = c, h = t.__headerState & Ge.COLUMN, d = Array.from({ length: r }, (e, t) => {
601
- let n = h;
602
- for (let e = 0; 0 !== n && e < i.length; e++) n &= i[e][t + a].cell.__headerState;
603
- return n;
604
- }), f = t.__headerState & Ge.ROW, g = Array.from({ length: l }, (e, t) => {
605
- let n = f;
606
- for (let e = 0; 0 !== n && e < i[0].length; e++) n &= i[t + u][e].cell.__headerState;
607
- return n;
608
- });
609
- if (r > 1) {
610
- for (let e = 1; e < r; e++) t.insertAfter(tt(d[e] | g[0]).append($createParagraphNode()));
611
- t.setColSpan(1);
612
- }
613
- if (l > 1) {
614
- let e;
615
- for (let t = 1; t < l; t++) {
616
- const o = u + t, l = i[o];
617
- e = (e || n).getNextSibling(), ct(e) || rt(125);
618
- let c = null;
619
- for (let e = 0; e < a; e++) {
620
- const t = l[e], n = t.cell;
621
- t.startRow === o && (c = n), n.__colSpan > 1 && (e += n.__colSpan - 1);
622
- }
623
- if (null === c) for (let n = r - 1; n >= 0; n--) kt(e, tt(d[n] | g[t]).append($createParagraphNode()));
624
- else for (let e = r - 1; e >= 0; e--) c.insertAfter(tt(d[e] | g[t]).append($createParagraphNode()));
625
- }
626
- t.setRowSpan(1);
627
- }
628
- }
629
- function zt(e, t, n) {
630
- const [o, r, l] = Ht(e, t, n);
631
- return null === r && rt(207), null === l && rt(208), [
632
- o,
633
- r,
634
- l
635
- ];
636
- }
637
- function Ht(e, t, n) {
638
- const o = [];
639
- let r = null, l = null;
640
- function s(e) {
641
- let t = o[e];
642
- return void 0 === t && (o[e] = t = []), t;
643
- }
644
- const i = e.getChildren();
645
- for (let e = 0; e < i.length; e++) {
646
- const o = i[e];
647
- ct(o) || rt(209);
648
- const c = s(e);
649
- for (let a = o.getFirstChild(), u = 0; null != a; a = a.getNextSibling()) {
650
- for (nt(a) || rt(147); void 0 !== c[u];) u++;
651
- const o = {
652
- cell: a,
653
- startColumn: u,
654
- startRow: e
655
- }, { __rowSpan: h, __colSpan: d } = a;
656
- for (let t = 0; t < h && !(e + t >= i.length); t++) {
657
- const n = s(e + t);
658
- for (let e = 0; e < d; e++) n[u + e] = o;
659
- }
660
- null !== t && null === r && t.is(a) && (r = o), null !== n && null === l && n.is(a) && (l = o);
661
- }
662
- }
663
- return [
664
- o,
665
- r,
666
- l
667
- ];
668
- }
669
- function Lt(e) {
670
- let t;
671
- if (e instanceof Qe) t = e;
672
- else if ("__type" in e) {
673
- const n = $findMatchingParent(e, nt);
674
- nt(n) || rt(148), t = n;
675
- } else {
676
- const n = $findMatchingParent(e.getNode(), nt);
677
- nt(n) || rt(148), t = n;
678
- }
679
- const n = t.getParent();
680
- ct(n) || rt(149);
681
- const o = n.getParent();
682
- return Xn(o) || rt(210), [
683
- t,
684
- n,
685
- o
686
- ];
687
- }
688
- function Bt(e, t, n) {
689
- let o, r = Math.min(t.startColumn, n.startColumn), l = Math.min(t.startRow, n.startRow), s = Math.max(t.startColumn + t.cell.__colSpan - 1, n.startColumn + n.cell.__colSpan - 1), i = Math.max(t.startRow + t.cell.__rowSpan - 1, n.startRow + n.cell.__rowSpan - 1);
690
- do {
691
- o = !1;
692
- for (let t = 0; t < e.length; t++) for (let n = 0; n < e[0].length; n++) {
693
- const c = e[t][n];
694
- if (!c) continue;
695
- const a = c.startColumn + c.cell.__colSpan - 1, u = c.startRow + c.cell.__rowSpan - 1, h = c.startColumn <= s && a >= r, d = c.startRow <= i && u >= l;
696
- if (h && d) {
697
- const e = Math.min(r, c.startColumn), t = Math.max(s, a), n = Math.min(l, c.startRow), h = Math.max(i, u);
698
- e === r && t === s && n === l && h === i || (r = e, s = t, l = n, i = h, o = !0);
699
- }
700
- }
701
- } while (o);
702
- return {
703
- maxColumn: s,
704
- maxRow: i,
705
- minColumn: r,
706
- minRow: l
707
- };
708
- }
709
- function Pt(e) {
710
- const t = e.getChildren();
711
- let n = null;
712
- for (const e of t) {
713
- if (!ct(e)) return !1;
714
- if (null === n && (n = e.getChildrenSize()), e.getChildrenSize() !== n) return !1;
715
- const t = e.getChildren();
716
- for (const e of t) if (!nt(e) || 1 !== e.getRowSpan() || 1 !== e.getColSpan()) return !1;
717
- }
718
- return (n || 0) > 0;
719
- }
720
- function Dt(e, t, n) {
721
- if (t === n) return;
722
- const o = e.getColumnCount();
723
- if (t < 0 || t >= o || n < 0 || n >= o) return;
724
- if (!Pt(e)) return;
725
- e.getChildren().filter(ct).forEach((e) => {
726
- const o = e.getChildren(), [r] = o.splice(t, 1);
727
- o.splice(n, 0, r), e.splice(0, o.length, o);
728
- });
729
- const r = e.getColWidths();
730
- if (r && r.length === o) {
731
- const o = [...r], [l] = o.splice(t, 1);
732
- o.splice(n, 0, l), e.setColWidths(o);
733
- }
734
- }
735
- function It(e) {
736
- const [t, , n] = Lt(e), o = n.getChildren().filter(ct), r = o.length, l = o[0].getChildren().length, s = new Array(r);
737
- for (let e = 0; e < r; e++) s[e] = new Array(l);
738
- for (let e = 0; e < r; e++) {
739
- const n = o[e].getChildren().filter(nt);
740
- let r = 0;
741
- for (let o = 0; o < n.length; o++) {
742
- for (; s[e][r];) r++;
743
- const l = n[o], i = l.__rowSpan || 1, c = l.__colSpan || 1;
744
- for (let t = 0; t < i; t++) for (let n = 0; n < c; n++) s[e + t][r + n] = l;
745
- if (t === l) return {
746
- colSpan: c,
747
- columnIndex: r,
748
- rowIndex: e,
749
- rowSpan: i
750
- };
751
- r += c;
752
- }
753
- }
754
- return null;
755
- }
756
- function Ut(e) {
757
- const [[t, n, o, r], [l, s, i, c]] = ["anchor", "focus"].map((t) => {
758
- const n = e[t].getNode(), o = $findMatchingParent(n, nt);
759
- nt(o) || rt(238, t, n.getKey(), n.getType());
760
- const r = o.getParent();
761
- ct(r) || rt(239, t);
762
- const l = r.getParent();
763
- return Xn(l) || rt(240, t), [
764
- n,
765
- o,
766
- r,
767
- l
768
- ];
769
- });
770
- return r.is(c) || rt(241), {
771
- anchorCell: n,
772
- anchorNode: t,
773
- anchorRow: o,
774
- anchorTable: r,
775
- focusCell: s,
776
- focusNode: l,
777
- focusRow: i,
778
- focusTable: c
779
- };
780
- }
781
- var Jt = class Jt {
782
- tableKey;
783
- anchor;
784
- focus;
785
- _cachedNodes;
786
- dirty;
787
- constructor(e, t, n) {
788
- this.anchor = t, this.focus = n, t._selection = this, n._selection = this, this._cachedNodes = null, this.dirty = !1, this.tableKey = e;
789
- }
790
- getStartEndPoints() {
791
- return [this.anchor, this.focus];
792
- }
793
- isValid() {
794
- if ("root" === this.tableKey || "root" === this.anchor.key || "element" !== this.anchor.type || "root" === this.focus.key || "element" !== this.focus.type) return !1;
795
- const e = $getNodeByKey(this.tableKey), t = $getNodeByKey(this.anchor.key), n = $getNodeByKey(this.focus.key);
796
- return null !== e && null !== t && null !== n;
797
- }
798
- isBackward() {
799
- return this.focus.isBefore(this.anchor);
800
- }
801
- getCachedNodes() {
802
- return this._cachedNodes;
803
- }
804
- setCachedNodes(e) {
805
- this._cachedNodes = e;
806
- }
807
- is(e) {
808
- return Xt(e) && this.tableKey === e.tableKey && this.anchor.is(e.anchor) && this.focus.is(e.focus);
809
- }
810
- set(e, t, n) {
811
- this.dirty = this.dirty || e !== this.tableKey || t !== this.anchor.key || n !== this.focus.key, this.tableKey = e, this.anchor.key = t, this.focus.key = n, this._cachedNodes = null;
812
- }
813
- clone() {
814
- return new Jt(this.tableKey, $createPoint(this.anchor.key, this.anchor.offset, this.anchor.type), $createPoint(this.focus.key, this.focus.offset, this.focus.type));
815
- }
816
- isCollapsed() {
817
- return !1;
818
- }
819
- extract() {
820
- return this.getNodes();
821
- }
822
- insertRawText(e) {}
823
- insertText() {}
824
- hasFormat(e) {
825
- let t = 0;
826
- this.getNodes().filter(nt).forEach((e) => {
827
- const n = e.getFirstChild();
828
- $isParagraphNode(n) && (t |= n.getTextFormat());
829
- });
830
- const n = TEXT_TYPE_TO_FORMAT[e];
831
- return 0 !== (t & n);
832
- }
833
- insertNodes(e) {
834
- const t = this.focus.getNode();
835
- $isElementNode(t) || rt(151);
836
- $normalizeSelection__EXPERIMENTAL(t.select(0, t.getChildrenSize())).insertNodes(e);
837
- }
838
- getShape() {
839
- const { anchorCell: e, focusCell: t } = Ut(this), n = It(e);
840
- null === n && rt(153);
841
- const o = It(t);
842
- null === o && rt(155);
843
- const r = Math.min(n.columnIndex, o.columnIndex), l = Math.max(n.columnIndex + n.colSpan - 1, o.columnIndex + o.colSpan - 1), s = Math.min(n.rowIndex, o.rowIndex), i = Math.max(n.rowIndex + n.rowSpan - 1, o.rowIndex + o.rowSpan - 1);
844
- return {
845
- fromX: Math.min(r, l),
846
- fromY: Math.min(s, i),
847
- toX: Math.max(r, l),
848
- toY: Math.max(s, i)
849
- };
850
- }
851
- getNodes() {
852
- if (!this.isValid()) return [];
853
- const e = this._cachedNodes;
854
- if (null !== e) return e;
855
- const { anchorTable: t, anchorCell: n, focusCell: o } = Ut(this), r = o.getParents()[1];
856
- if (r !== t) {
857
- if (t.isParentOf(o)) {
858
- const e = r.getParent();
859
- e ?? rt(159), this.set(this.tableKey, o.getKey(), e.getKey());
860
- } else {
861
- const e = t.getParent();
862
- e ?? rt(158), this.set(this.tableKey, e.getKey(), o.getKey());
863
- }
864
- return this.getNodes();
865
- }
866
- const [l, s, i] = zt(t, n, o), { minColumn: c, maxColumn: a, minRow: u, maxRow: h } = Bt(l, s, i), d = /* @__PURE__ */ new Map([[t.getKey(), t]]);
867
- let f = null;
868
- for (let e = u; e <= h; e++) for (let t = c; t <= a; t++) {
869
- const { cell: n } = l[e][t], o = n.getParent();
870
- ct(o) || rt(160), o !== f && (d.set(o.getKey(), o), f = o), d.has(n.getKey()) || jt(n, (e) => {
871
- d.set(e.getKey(), e);
872
- });
873
- }
874
- const g = Array.from(d.values());
875
- return isCurrentlyReadOnlyMode() || (this._cachedNodes = g), g;
876
- }
877
- getTextContent() {
878
- const e = this.getNodes().filter((e) => nt(e));
879
- let t = "";
880
- for (let n = 0; n < e.length; n++) {
881
- const o = e[n], r = o.__parent, l = (e[n + 1] || {}).__parent;
882
- t += o.getTextContent() + (l !== r ? "\n" : " ");
883
- }
884
- return t;
885
- }
886
- };
887
- function Xt(e) {
888
- return e instanceof Jt;
889
- }
890
- function Yt() {
891
- return new Jt("root", $createPoint("root", 0, "element"), $createPoint("root", 0, "element"));
892
- }
893
- function qt(e, t, n) {
894
- e.getKey(), t.getKey(), n.getKey();
895
- const o = $getSelection(), r = Xt(o) ? o.clone() : Yt();
896
- return r.set(e.getKey(), t.getKey(), n.getKey()), r;
897
- }
898
- function jt(e, t) {
899
- const n = [[e]];
900
- for (let e = n.at(-1); void 0 !== e && n.length > 0; e = n.at(-1)) {
901
- const o = e.pop();
902
- void 0 === o ? n.pop() : !1 !== t(o) && $isElementNode(o) && n.push(o.getChildren());
903
- }
904
- }
905
- function Vt(e, t = $getEditor()) {
906
- const n = $getNodeByKey(e);
907
- Xn(n) || rt(231, e);
908
- const o = nn(n, t.getElementByKey(e));
909
- return null === o && rt(232, e), {
910
- tableElement: o,
911
- tableNode: n
912
- };
913
- }
914
- var Gt = class {
915
- observers;
916
- nextFocus;
917
- shouldCheckSelectionForTable;
918
- constructor() {
919
- this.observers = /* @__PURE__ */ new Map(), this.nextFocus = null, this.shouldCheckSelectionForTable = null;
920
- }
921
- setNextFocus(e) {
922
- this.nextFocus = e;
923
- }
924
- getAndClearNextFocus() {
925
- const { nextFocus: e } = this;
926
- return null !== e && (this.nextFocus = null), e;
927
- }
928
- setShouldCheckSelectionForTable(e) {
929
- this.shouldCheckSelectionForTable = e;
930
- }
931
- getAndClearShouldCheckSelectionForTable() {
932
- const { shouldCheckSelectionForTable: e } = this;
933
- return e ? (this.shouldCheckSelectionForTable = null, e) : null;
934
- }
935
- removeObserver(e) {
936
- const t = this.observers.get(e);
937
- return void 0 !== t && (t[0].removeListeners(), this.observers.delete(e), !0);
938
- }
939
- removeAllObservers() {
940
- for (const e of Array.from(this.observers.keys())) this.removeObserver(e);
941
- }
942
- $getTableNodesAndObservers() {
943
- const e = [];
944
- for (const [t, [n]] of Array.from(this.observers.entries())) {
945
- const o = $getNodeByKey(t);
946
- Xn(o) ? e.push([o, n]) : this.removeObserver(t);
947
- }
948
- return e;
949
- }
950
- };
951
- var Qt = class {
952
- focusX;
953
- focusY;
954
- listenersToRemove;
955
- table;
956
- isHighlightingCells;
957
- anchorX;
958
- anchorY;
959
- tableNodeKey;
960
- anchorCell;
961
- focusCell;
962
- anchorCellNodeKey;
963
- focusCellNodeKey;
964
- editor;
965
- tableSelection;
966
- hasHijackedSelectionStyles;
967
- isSelecting;
968
- pointerType;
969
- abortController;
970
- listenerOptions;
971
- constructor(e, t) {
972
- this.isHighlightingCells = !1, this.anchorX = -1, this.anchorY = -1, this.focusX = -1, this.focusY = -1, this.listenersToRemove = /* @__PURE__ */ new Set(), this.tableNodeKey = t, this.editor = e, this.table = {
973
- columns: 0,
974
- domRows: [],
975
- rows: 0
976
- }, this.tableSelection = null, this.anchorCellNodeKey = null, this.focusCellNodeKey = null, this.anchorCell = null, this.focusCell = null, this.hasHijackedSelectionStyles = !1, this.isSelecting = !1, this.pointerType = null, this.abortController = new AbortController(), this.listenerOptions = { signal: this.abortController.signal }, this.trackTable();
977
- }
978
- getTable() {
979
- return this.table;
980
- }
981
- removeListeners() {
982
- this.abortController.abort("removeListeners"), Array.from(this.listenersToRemove).forEach((e) => e()), this.listenersToRemove.clear();
983
- }
984
- $lookup() {
985
- return Vt(this.tableNodeKey, this.editor);
986
- }
987
- trackTable() {
988
- const e = new MutationObserver((e) => {
989
- this.editor.read("latest", () => {
990
- let t = !1;
991
- for (let n = 0; n < e.length; n++) {
992
- const o = e[n].target.nodeName;
993
- if ("TABLE" === o || "TBODY" === o || "THEAD" === o || "TR" === o) {
994
- t = !0;
995
- break;
996
- }
997
- }
998
- if (!t) return;
999
- const { tableNode: n, tableElement: o } = this.$lookup();
1000
- this.table = pn(n, o);
1001
- });
1002
- });
1003
- this.editor.read("latest", () => {
1004
- const { tableNode: t, tableElement: n } = this.$lookup();
1005
- this.table = pn(t, n), e.observe(n, {
1006
- attributes: !0,
1007
- childList: !0,
1008
- subtree: !0
1009
- });
1010
- });
1011
- }
1012
- $clearHighlight(e = !0) {
1013
- const t = this.editor;
1014
- this.isHighlightingCells = !1, this.anchorX = -1, this.anchorY = -1, this.focusX = -1, this.focusY = -1, this.tableSelection = null, this.anchorCellNodeKey = null, this.focusCellNodeKey = null, this.anchorCell = null, this.focusCell = null, this.hasHijackedSelectionStyles = !1, this.$enableHighlightStyle();
1015
- const { tableNode: n, tableElement: o } = this.$lookup();
1016
- Cn(t, pn(n, o), null), e && null !== $getSelection() && ($setSelection(null), t.dispatchCommand(SELECTION_CHANGE_COMMAND, void 0));
1017
- }
1018
- $enableHighlightStyle() {
1019
- const e = this.editor, { tableElement: t } = this.$lookup();
1020
- removeClassNamesFromElement(t, e._config.theme.tableSelection), t.classList.remove("disable-selection"), this.hasHijackedSelectionStyles = !1;
1021
- }
1022
- $disableHighlightStyle() {
1023
- const { tableElement: e } = this.$lookup();
1024
- addClassNamesToElement(e, this.editor._config.theme.tableSelection), this.hasHijackedSelectionStyles = !0;
1025
- }
1026
- $updateTableTableSelection(e) {
1027
- if (null !== e) {
1028
- e.tableKey !== this.tableNodeKey && rt(233, e.tableKey, this.tableNodeKey);
1029
- const t = this.editor;
1030
- this.tableSelection = e, this.isHighlightingCells = !0, this.$disableHighlightStyle(), this.updateDOMSelection(), Cn(t, this.table, this.tableSelection);
1031
- } else this.$clearHighlight();
1032
- }
1033
- updateDOMSelection() {
1034
- if (null !== this.anchorCell && null !== this.focusCell) {
1035
- const e = getDOMSelection(this.editor._window);
1036
- e && e.rangeCount > 0 && e.removeAllRanges();
1037
- }
1038
- }
1039
- $setFocusCellForSelection(e, t = !1) {
1040
- const n = this.editor, { tableNode: o } = this.$lookup(), r = e.x, l = e.y;
1041
- if (this.focusCell = e, !this.isHighlightingCells) (t || this.anchorX !== r || this.anchorY !== l || null != this.tableSelection && null != this.anchorCellNodeKey) && (this.isHighlightingCells = !0, this.$disableHighlightStyle());
1042
- if (-1 !== this.focusX && -1 !== this.focusY && r === this.focusX && l === this.focusY) return !1;
1043
- if (this.focusX = r, this.focusY = l, this.isHighlightingCells) {
1044
- const s = Wn(o, e.elem);
1045
- if (null != this.tableSelection && null != this.anchorCellNodeKey) {
1046
- let e = s;
1047
- if (null === e && t && (e = o.getCellNodeFromCords(r, l, this.table)), null !== e) {
1048
- const t = this.$getAnchorTableCellOrThrow();
1049
- return this.focusCellNodeKey = e.getKey(), this.tableSelection = qt(o, t, e), $setSelection(this.tableSelection), n.dispatchCommand(SELECTION_CHANGE_COMMAND, void 0), Cn(n, this.table, this.tableSelection), !0;
1050
- }
1051
- }
1052
- }
1053
- return !1;
1054
- }
1055
- $getAnchorTableCell() {
1056
- const e = this.anchorCellNodeKey ? $getNodeByKey(this.anchorCellNodeKey) : null;
1057
- return nt(e) ? e : null;
1058
- }
1059
- $getAnchorTableCellOrThrow() {
1060
- const e = this.$getAnchorTableCell();
1061
- return null === e && rt(234), e;
1062
- }
1063
- $getFocusTableCell() {
1064
- const e = this.focusCellNodeKey ? $getNodeByKey(this.focusCellNodeKey) : null;
1065
- return nt(e) ? e : null;
1066
- }
1067
- $getFocusTableCellOrThrow() {
1068
- const e = this.$getFocusTableCell();
1069
- return null === e && rt(235), e;
1070
- }
1071
- $setAnchorCellForSelection(e) {
1072
- this.isHighlightingCells = !1, this.anchorCell = e, this.anchorX = e.x, this.anchorY = e.y, this.focusX = -1, this.focusY = -1, this.focusCell = null, this.focusCellNodeKey = null;
1073
- const { tableNode: t } = this.$lookup(), n = Wn(t, e.elem);
1074
- if (null !== n) {
1075
- const e = n.getKey();
1076
- null != this.tableSelection ? (this.tableSelection = this.tableSelection.clone(), this.tableSelection.set(t.getKey(), e, e)) : this.tableSelection = qt(t, n, n), this.anchorCellNodeKey = e;
1077
- }
1078
- }
1079
- $formatCells(e) {
1080
- const t = $getSelection();
1081
- Xt(t) || rt(236);
1082
- const n = $createRangeSelection(), o = n.anchor, r = n.focus, l = t.getNodes().filter(nt);
1083
- l.length > 0 || rt(237);
1084
- const s = l[0].getFirstChild(), i = $isParagraphNode(s) ? s.getFormatFlags(e, null) : null;
1085
- l.forEach((t) => {
1086
- o.set(t.getKey(), 0, "element"), r.set(t.getKey(), t.getChildrenSize(), "element"), n.formatText(e, i);
1087
- }), $setSelection(t), this.editor.dispatchCommand(SELECTION_CHANGE_COMMAND, void 0);
1088
- }
1089
- $clearText() {
1090
- const { editor: e } = this, t = $getNodeByKey(this.tableNodeKey);
1091
- if (!Xn(t)) throw new Error("Expected TableNode.");
1092
- const n = $getSelection();
1093
- Xt(n) || rt(253);
1094
- const o = n.getNodes().filter(nt), r = t.getFirstChild(), l = t.getLastChild();
1095
- if (o.length > 0 && null !== r && null !== l && ct(r) && ct(l) && o[0] === r.getFirstChild() && o[o.length - 1] === l.getLastChild()) {
1096
- t.selectPrevious();
1097
- const n = t.getParent();
1098
- t.remove(), $isRootNode(n) && n.isEmpty() && e.dispatchCommand(INSERT_PARAGRAPH_COMMAND, void 0);
1099
- return;
1100
- }
1101
- o.forEach((e) => {
1102
- if ($isElementNode(e)) {
1103
- const t = $createParagraphNode(), n = $createTextNode();
1104
- t.append(n), e.append(t), e.getChildren().forEach((e) => {
1105
- e !== t && e.remove();
1106
- });
1107
- }
1108
- }), Cn(e, this.table, null), $setSelection(null), e.dispatchCommand(SELECTION_CHANGE_COMMAND, void 0);
1109
- }
1110
- };
1111
- const Zt = "__lexicalTableSelection";
1112
- function en(e) {
1113
- const t = $getNodeByKeyOrThrow(e);
1114
- return Xn(t) || rt(386, e), t;
1115
- }
1116
- function tn(e) {
1117
- return isHTMLElement(e) && "TABLE" === e.nodeName;
1118
- }
1119
- function nn(e, t) {
1120
- if (!t) return t;
1121
- const n = tn(t) ? t : t.querySelector("table");
1122
- return tn(n) || rt(341, e.constructor.name, e.getType(), e.getKey(), t.nodeName), n;
1123
- }
1124
- function on(e) {
1125
- return e._window;
1126
- }
1127
- function rn(e, t) {
1128
- for (let n = t, o = null; null !== n; n = n.getParent()) {
1129
- if (e.is(n)) return o;
1130
- nt(n) && (o = n);
1131
- }
1132
- return null;
1133
- }
1134
- const ln = [
1135
- [KEY_ARROW_DOWN_COMMAND, "down"],
1136
- [KEY_ARROW_UP_COMMAND, "up"],
1137
- [KEY_ARROW_LEFT_COMMAND, "backward"],
1138
- [KEY_ARROW_RIGHT_COMMAND, "forward"]
1139
- ], sn = [
1140
- DELETE_WORD_COMMAND,
1141
- DELETE_LINE_COMMAND,
1142
- DELETE_CHARACTER_COMMAND
1143
- ], cn = [KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND];
1144
- function an(e, t) {
1145
- return e.registerRootListener((n) => {
1146
- if (null === n) return;
1147
- const o = e._window;
1148
- if (null === o) return;
1149
- const r = (o) => {
1150
- const r = getComposedEventTarget(o);
1151
- if (0 !== o.button || !isDOMNode(r) || !n.contains(r)) return;
1152
- const l = function(e) {
1153
- const t = gn(e);
1154
- if (null === t) return null;
1155
- let n = t.elem;
1156
- for (; null != n;) {
1157
- if ("TABLE" === n.nodeName && Zt in n && n[Zt]) return {
1158
- cellElement: t,
1159
- tableElement: n,
1160
- tableObserver: n[Zt]
1161
- };
1162
- n = n.parentNode;
1163
- }
1164
- return null;
1165
- }(r);
1166
- e.update(() => {
1167
- if (Xt($getSelection())) {
1168
- for (const [e] of t.observers.values()) e.$clearHighlight(!1);
1169
- $setSelection(null), e.dispatchCommand(SELECTION_CHANGE_COMMAND, void 0);
1170
- }
1171
- if (!l) return;
1172
- const { tableObserver: n, tableElement: r, cellElement: s } = l;
1173
- (function(e, t, n, o, r, l) {
1174
- const s = e._window;
1175
- if (!s) return;
1176
- const i = (t) => {
1177
- if (r.isSelecting) return;
1178
- r.isSelecting = !0, null !== t && null === r.anchorCell && e.update(() => {
1179
- r.$setAnchorCellForSelection(t);
1180
- });
1181
- const n = () => {
1182
- r.isSelecting = !1, s.removeEventListener("pointerup", n), s.removeEventListener("pointermove", i);
1183
- }, i = (t) => {
1184
- if (!((e) => !(1 & ~e.buttons))(t) && r.isSelecting) return r.isSelecting = !1, s.removeEventListener("pointerup", n), void s.removeEventListener("pointermove", i);
1185
- const c = getComposedEventTarget(t);
1186
- if (!isDOMNode(c)) return;
1187
- let a = null;
1188
- const u = !(IS_FIREFOX || o.contains(c));
1189
- if (u) a = mn(o, c);
1190
- else {
1191
- const e = o.getRootNode();
1192
- if (!isDOMDocumentNode(e) && !isDOMShadowRoot(e)) return;
1193
- for (const n of e.elementsFromPoint(t.clientX, t.clientY)) if (a = mn(o, n), a) break;
1194
- }
1195
- if (a) {
1196
- const t = a;
1197
- null === r.anchorCell && e.update(() => {
1198
- r.$setAnchorCellForSelection(t);
1199
- }), null !== r.focusCell && a.elem === r.focusCell.elem || (l.setNextFocus({
1200
- focusCell: a,
1201
- override: u,
1202
- tableKey: r.tableNodeKey
1203
- }), e.dispatchCommand(SELECTION_CHANGE_COMMAND, void 0));
1204
- }
1205
- };
1206
- s.addEventListener("pointerup", n, r.listenerOptions), s.addEventListener("pointermove", i, r.listenerOptions);
1207
- };
1208
- r.pointerType = t.pointerType;
1209
- const c = en(r.tableNodeKey), a = $getPreviousSelection();
1210
- if (IS_FIREFOX && t.shiftKey && vn(a, c) && ($isRangeSelection(a) || Xt(a))) {
1211
- const e = a.anchor.getNode(), o = rn(c, a.anchor.getNode());
1212
- if (o) r.$setAnchorCellForSelection($n(r, o)), r.$setFocusCellForSelection(n), kn(t);
1213
- else (c.isBefore(e) ? c.selectStart() : c.selectEnd()).anchor.set(a.anchor.key, a.anchor.offset, a.anchor.type);
1214
- } else "touch" !== t.pointerType && r.$setAnchorCellForSelection(n);
1215
- i(n);
1216
- })(e, o, s, r, n, t);
1217
- });
1218
- };
1219
- return o.addEventListener("pointerdown", r), () => {
1220
- o.removeEventListener("pointerdown", r);
1221
- };
1222
- });
1223
- }
1224
- function un(e, t, n, o, r) {
1225
- const l = n.getRootElement(), s = on(n);
1226
- null !== l && null !== s || rt(246);
1227
- const i = new Qt(n, e.getKey()), c = nn(e, t);
1228
- (function(e, t) {
1229
- null !== fn(e) && rt(205);
1230
- e[Zt] = t;
1231
- })(c, i), i.listenersToRemove.add(() => function(e, t) {
1232
- fn(e) === t && delete e[Zt];
1233
- }(c, i));
1234
- const f = (e) => {
1235
- const t = getComposedEventTarget(e);
1236
- if (e.detail >= 3 && isDOMNode(t)) null !== gn(t) && e.preventDefault();
1237
- };
1238
- c.addEventListener("mousedown", f, i.listenerOptions), i.listenersToRemove.add(() => {
1239
- c.removeEventListener("mousedown", f);
1240
- });
1241
- for (const [t, o] of ln) i.listenersToRemove.add(n.registerCommand(t, (t) => Kn(n, t, o, e, i, r), COMMAND_PRIORITY_HIGH));
1242
- i.listenersToRemove.add(n.registerCommand(KEY_ESCAPE_COMMAND, (t) => {
1243
- const n = $getSelection();
1244
- if (Xt(n)) {
1245
- const o = rn(e, n.focus.getNode());
1246
- if (null !== o) return kn(t), o.selectEnd(), !0;
1247
- }
1248
- return !1;
1249
- }, COMMAND_PRIORITY_HIGH));
1250
- const g = (t) => () => {
1251
- const n = $getSelection();
1252
- if (!vn(n, e)) return !1;
1253
- if (Xt(n)) return i.$clearText(), !0;
1254
- if ($isRangeSelection(n)) {
1255
- if (!nt(rn(e, n.anchor.getNode()))) return !1;
1256
- const o = n.anchor.getNode(), r = n.focus.getNode(), l = e.isParentOf(o), s = e.isParentOf(r);
1257
- if (l && !s || s && !l) return i.$clearText(), !0;
1258
- const c = $findMatchingParent(n.anchor.getNode(), (e) => $isElementNode(e)), a = c && $findMatchingParent(c, (e) => $isElementNode(e) && nt(e.getParent()));
1259
- if (!$isElementNode(a) || !$isElementNode(c)) return !1;
1260
- if (t === DELETE_LINE_COMMAND && null === a.getPreviousSibling()) return !0;
1261
- }
1262
- return !1;
1263
- };
1264
- for (const e of sn) i.listenersToRemove.add(n.registerCommand(e, g(e), COMMAND_PRIORITY_HIGH));
1265
- const m = (t) => {
1266
- const n = $getSelection();
1267
- if (!Xt(n) && !$isRangeSelection(n)) return !1;
1268
- const o = e.isParentOf(n.anchor.getNode());
1269
- if (o !== e.isParentOf(n.focus.getNode())) {
1270
- const t = o ? "anchor" : "focus", r = o ? "focus" : "anchor", { key: l, offset: s, type: i } = n[r];
1271
- return e[n[t].isBefore(n[r]) ? "selectPrevious" : "selectNext"]()[r].set(l, s, i), !1;
1272
- }
1273
- return !!vn(n, e) && !!Xt(n) && (t && (t.preventDefault(), t.stopPropagation()), i.$clearText(), !0);
1274
- };
1275
- for (const e of cn) i.listenersToRemove.add(n.registerCommand(e, m, COMMAND_PRIORITY_HIGH));
1276
- return i.listenersToRemove.add(n.registerCommand(CUT_COMMAND, (e) => {
1277
- const t = $getSelection();
1278
- if (t) {
1279
- if (!Xt(t) && !$isRangeSelection(t)) return !1;
1280
- copyToClipboard(n, objectKlassEquals(e, ClipboardEvent) ? e : null, $getClipboardDataFromSelection(t));
1281
- const o = m(e);
1282
- return $isRangeSelection(t) ? (t.removeText(), !0) : o;
1283
- }
1284
- return !1;
1285
- }, COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(n.registerCommand(FORMAT_TEXT_COMMAND, (t) => {
1286
- const n = $getSelection();
1287
- if (!vn(n, e)) return !1;
1288
- if (Xt(n)) return i.$formatCells(t), !0;
1289
- if ($isRangeSelection(n)) {
1290
- if (!nt($findMatchingParent(n.anchor.getNode(), (e) => nt(e)))) return !1;
1291
- }
1292
- return !1;
1293
- }, COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(n.registerCommand(FORMAT_ELEMENT_COMMAND, (t) => {
1294
- const n = $getSelection();
1295
- if (!Xt(n) || !vn(n, e)) return !1;
1296
- const o = n.anchor.getNode(), r = n.focus.getNode();
1297
- if (!nt(o) || !nt(r)) return !1;
1298
- if (function(e, t) {
1299
- if (Xt(e)) {
1300
- const n = e.anchor.getNode(), o = e.focus.getNode();
1301
- if (t && n && o) {
1302
- const [e] = zt(t, n, o);
1303
- return n.getKey() === e[0][0].cell.getKey() && o.getKey() === e[e.length - 1].at(-1).cell.getKey();
1304
- }
1305
- }
1306
- return !1;
1307
- }(n, e)) return e.setFormat(t), !0;
1308
- const [l, s, i] = zt(e, o, r), c = Math.max(s.startRow + s.cell.__rowSpan - 1, i.startRow + i.cell.__rowSpan - 1), a = Math.max(s.startColumn + s.cell.__colSpan - 1, i.startColumn + i.cell.__colSpan - 1), h = Math.min(s.startRow, i.startRow), d = Math.min(s.startColumn, i.startColumn), f = /* @__PURE__ */ new Set();
1309
- for (let e = h; e <= c; e++) for (let n = d; n <= a; n++) {
1310
- const o = l[e][n].cell;
1311
- if (f.has(o)) continue;
1312
- f.add(o), o.setFormat(t);
1313
- const r = o.getChildren();
1314
- for (let e = 0; e < r.length; e++) {
1315
- const n = r[e];
1316
- $isElementNode(n) && !n.isInline() && n.setFormat(t);
1317
- }
1318
- }
1319
- return !0;
1320
- }, COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(n.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND, (t) => {
1321
- const o = $getSelection();
1322
- if (!vn(o, e)) return !1;
1323
- if (Xt(o)) return i.$clearHighlight(), !1;
1324
- if ($isRangeSelection(o)) {
1325
- if (!nt($findMatchingParent(o.anchor.getNode(), (e) => nt(e)))) return !1;
1326
- if ("string" == typeof t) {
1327
- const r = Mn(n, o, e);
1328
- if (r) return En(r, e, [$createTextNode(t)]), !0;
1329
- }
1330
- }
1331
- return !1;
1332
- }, COMMAND_PRIORITY_HIGH)), o && i.listenersToRemove.add(n.registerCommand(KEY_TAB_COMMAND, (t) => {
1333
- const n = $getSelection();
1334
- if (!$isRangeSelection(n) || !n.isCollapsed() || !vn(n, e)) return !1;
1335
- const o = Fn(n.anchor.getNode());
1336
- return !(null === o || !e.is(On(o))) && (kn(t), function(e, t) {
1337
- const n = "next" === t ? "getNextSibling" : "getPreviousSibling", o = "next" === t ? "getFirstChild" : "getLastChild", r = e[n]();
1338
- if ($isElementNode(r)) return r.selectEnd();
1339
- const l = $findMatchingParent(e, ct);
1340
- null === l && rt(247);
1341
- for (let e = l[n](); ct(e); e = e[n]()) {
1342
- const t = e[o]();
1343
- if ($isElementNode(t)) return t.selectEnd();
1344
- }
1345
- const s = $findMatchingParent(l, Xn);
1346
- null === s && rt(248);
1347
- "next" === t ? s.selectNext() : s.selectPrevious();
1348
- }(o, t.shiftKey ? "previous" : "next"), !0);
1349
- }, COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(n.registerCommand(FOCUS_COMMAND, (t) => e.isSelected(), COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(n.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
1350
- const t = $getSelection();
1351
- if (!$isRangeSelection(t) || !t.isCollapsed() || !vn(t, e)) return !1;
1352
- const o = Mn(n, t, e);
1353
- return !!o && (En(o, e), !0);
1354
- }, COMMAND_PRIORITY_HIGH)), i;
1355
- }
1356
- function hn(e, t) {
1357
- const n = $getSelection(), o = $getPreviousSelection(), r = e.getAndClearNextFocus();
1358
- if (null !== r) {
1359
- const { tableKey: t, focusCell: o } = r, l = e.observers.get(t);
1360
- l || rt(335, t);
1361
- const [s] = l;
1362
- if (Xt(n) && n.tableKey === s.tableNodeKey) return (o.x !== s.focusX || o.y !== s.focusY) && (s.$setFocusCellForSelection(o), !0);
1363
- if (null !== s.anchorCell && null !== s.anchorCellNodeKey && o.elem !== s.anchorCell.elem && null !== s.tableSelection) return s.$setFocusCellForSelection(o, !0), !0;
1364
- }
1365
- const l = e.getAndClearShouldCheckSelectionForTable();
1366
- if (l && $isRangeSelection(o) && $isRangeSelection(n) && n.isCollapsed()) {
1367
- const e = $getNodeByKey(l);
1368
- if (Xn(e)) {
1369
- const t = n.anchor.getNode(), o = e.getFirstChild(), r = Fn(t);
1370
- if (null !== r && ct(o)) {
1371
- const t = o.getFirstChild();
1372
- if (nt(t) && e.is($findMatchingParent(r, (n) => n.is(e) || n.is(t)))) return t.selectStart(), !0;
1373
- }
1374
- }
1375
- }
1376
- Xt(n) && function(e, t) {
1377
- const n = on(e), o = $getPreviousSelection();
1378
- if (!t.is(o)) return;
1379
- const r = en(t.tableKey), l = getDOMSelection(n), s = l && getDOMSelectionPoints(l, e.getRootElement());
1380
- if (l && s && s.anchorNode && s.focusNode) {
1381
- const n = $getNearestNodeFromDOMNode(s.focusNode), o = n && !r.isParentOf(n), i = $getNearestNodeFromDOMNode(s.anchorNode), c = i && r.isParentOf(i);
1382
- if (o && c && l.rangeCount > 0) {
1383
- const n = $createRangeSelectionFromDom(l, e);
1384
- n && (n.anchor.set(r.getKey(), t.isBackward() ? r.getChildrenSize() : 0, "element"), l.removeAllRanges(), $setSelection(n));
1385
- }
1386
- }
1387
- }(t, n), $isRangeSelection(n) && function(e, t) {
1388
- const n = $getPreviousSelection(), { anchor: o, focus: r } = e, l = o.getNode(), s = r.getNode(), i = Fn(l), c = Fn(s), a = i ? On(i) : null, u = c ? On(c) : null, d = e.isBackward(), f = i && c && a && u && a.is(u), g = u && (!a || a.isParentOf(u)), m = a && (!u || u.isParentOf(a));
1389
- if (g) {
1390
- const t = e.clone(), [n] = zt(u, c, c), o = n[0][0].cell, r = n[n.length - 1].at(-1).cell;
1391
- t.focus.set(d ? o.getKey() : r.getKey(), d ? 0 : r.getChildrenSize(), "element"), $setSelection(t);
1392
- } else if (m) {
1393
- const t = e.clone(), [n] = zt(a, i, i), o = n[0][0].cell, r = n[n.length - 1].at(-1).cell;
1394
- t.anchor.set(d ? r.getKey() : o.getKey(), d ? r.getChildrenSize() : 0, "element"), $setSelection(t);
1395
- } else if (f) {
1396
- const o = t.observers.get(a.getKey());
1397
- o || rt(335, a.getKey());
1398
- const [r] = o;
1399
- if (i.is(c) || (r.$setAnchorCellForSelection($n(r, i)), r.$setFocusCellForSelection($n(r, c), !0)), "touch" === r.pointerType && r.isSelecting && e.isCollapsed() && $isRangeSelection(n) && n.isCollapsed()) {
1400
- const e = Fn(n.anchor.getNode());
1401
- e && !e.is(c) && (r.$setAnchorCellForSelection($n(r, e)), r.$setFocusCellForSelection($n(r, c), !0), r.pointerType = null);
1402
- }
1403
- }
1404
- }(n, e);
1405
- for (const [n, o] of e.$getTableNodesAndObservers()) dn(t, n, o);
1406
- return !1;
1407
- }
1408
- function dn(e, t, n) {
1409
- const o = $getSelection(), r = $getPreviousSelection();
1410
- o && !o.is(r) && (Xt(o) || Xt(r)) && n.tableSelection && !n.tableSelection.is(r) && (Xt(o) && o.tableKey === n.tableNodeKey ? n.$updateTableTableSelection(o) : !Xt(o) && Xt(r) && r.tableKey === n.tableNodeKey && n.$updateTableTableSelection(null)), n.hasHijackedSelectionStyles && !t.isSelected() ? function(e, t) {
1411
- t.$enableHighlightStyle(), _n(t.table, (t) => {
1412
- const n = t.elem;
1413
- t.highlighted = !1, Rn(e, t), n.getAttribute("style") || n.removeAttribute("style");
1414
- });
1415
- }(e, n) : !n.hasHijackedSelectionStyles && t.isSelected() && function(e, t) {
1416
- t.$disableHighlightStyle(), _n(t.table, (t) => {
1417
- t.highlighted = !0, Tn(e, t);
1418
- });
1419
- }(e, n);
1420
- }
1421
- function fn(e) {
1422
- return e[Zt] || null;
1423
- }
1424
- function gn(e) {
1425
- let t = e;
1426
- for (; null != t;) {
1427
- const e = t.nodeName;
1428
- if ("TD" === e || "TH" === e) {
1429
- const e = t._cell;
1430
- return void 0 === e ? null : e;
1431
- }
1432
- t = t.parentNode;
1433
- }
1434
- return null;
1435
- }
1436
- function mn(e, t) {
1437
- if (!e.contains(t)) return null;
1438
- let n = null;
1439
- for (let o = t; null != o; o = o.parentNode) {
1440
- if (o === e) return n;
1441
- const t = o.nodeName;
1442
- "TD" !== t && "TH" !== t || (n = o._cell || null);
1443
- }
1444
- return null;
1445
- }
1446
- function pn(e, t) {
1447
- const n = [], o = {
1448
- columns: 0,
1449
- domRows: n,
1450
- rows: 0
1451
- };
1452
- let r = nn(e, t).querySelector("tr"), l = 0, s = 0;
1453
- for (n.length = 0; null != r;) {
1454
- const e = r.nodeName;
1455
- if ("TD" === e || "TH" === e) {
1456
- const e = {
1457
- elem: r,
1458
- hasBackgroundColor: "" !== r.style.backgroundColor,
1459
- highlighted: !1,
1460
- x: l,
1461
- y: s
1462
- };
1463
- r._cell = e;
1464
- let t = n[s];
1465
- void 0 === t && (t = n[s] = []), t[l] = e;
1466
- } else {
1467
- const e = r.firstChild;
1468
- if (null != e) {
1469
- r = e;
1470
- continue;
1471
- }
1472
- }
1473
- const t = r.nextSibling;
1474
- if (null != t) {
1475
- l++, r = t;
1476
- continue;
1477
- }
1478
- const o = r.parentNode;
1479
- if (null != o) {
1480
- const e = o.nextSibling;
1481
- if (null == e) break;
1482
- s++, l = 0, r = e;
1483
- }
1484
- }
1485
- return o.columns = l + 1, o.rows = s + 1, o;
1486
- }
1487
- function Cn(e, t, n) {
1488
- const o = new Set(n ? n.getNodes() : []);
1489
- _n(t, (t, n) => {
1490
- const r = t.elem;
1491
- o.has(n) ? (t.highlighted = !0, Tn(e, t)) : (t.highlighted = !1, Rn(e, t), r.getAttribute("style") || r.removeAttribute("style"));
1492
- });
1493
- }
1494
- function _n(e, t) {
1495
- const { domRows: n } = e;
1496
- for (let e = 0; e < n.length; e++) {
1497
- const o = n[e];
1498
- if (o) for (let n = 0; n < o.length; n++) {
1499
- const r = o[n];
1500
- if (!r) continue;
1501
- const l = $getNearestNodeFromDOMNode(r.elem);
1502
- null !== l && t(r, l, {
1503
- x: n,
1504
- y: e
1505
- });
1506
- }
1507
- }
1508
- }
1509
- const Sn = (e, t, n, o, r) => {
1510
- const l = "forward" === r;
1511
- switch (r) {
1512
- case "backward":
1513
- case "forward": return n !== (l ? e.table.columns - 1 : 0) ? xn(t.getCellNodeFromCordsOrThrow(n + (l ? 1 : -1), o, e.table), l) : o !== (l ? e.table.rows - 1 : 0) ? xn(t.getCellNodeFromCordsOrThrow(l ? 0 : e.table.columns - 1, o + (l ? 1 : -1), e.table), l) : l ? t.selectNext() : t.selectPrevious(), !0;
1514
- case "up": return 0 !== o ? xn(t.getCellNodeFromCordsOrThrow(n, o - 1, e.table), !1) : t.selectPrevious(), !0;
1515
- case "down": return o !== e.table.rows - 1 ? xn(t.getCellNodeFromCordsOrThrow(n, o + 1, e.table), !0) : t.selectNext(), !0;
1516
- default: return !1;
1517
- }
1518
- };
1519
- function bn(e, t) {
1520
- let n, o;
1521
- if (t.startColumn === e.minColumn) n = "minColumn";
1522
- else {
1523
- if (t.startColumn + t.cell.__colSpan - 1 !== e.maxColumn) return null;
1524
- n = "maxColumn";
1525
- }
1526
- if (t.startRow === e.minRow) o = "minRow";
1527
- else {
1528
- if (t.startRow + t.cell.__rowSpan - 1 !== e.maxRow) return null;
1529
- o = "maxRow";
1530
- }
1531
- return [n, o];
1532
- }
1533
- function wn([e, t]) {
1534
- return ["minColumn" === e ? "maxColumn" : "minColumn", "minRow" === t ? "maxRow" : "minRow"];
1535
- }
1536
- function yn(e, t, [n, o]) {
1537
- const r = t[o], l = e[r];
1538
- void 0 === l && rt(250, o, String(r));
1539
- const s = t[n], i = l[s];
1540
- return void 0 === i && rt(250, n, String(s)), i;
1541
- }
1542
- function Nn(e, t, n, o, r) {
1543
- const l = Bt(t, n, o), { topSpan: i, leftSpan: c, bottomSpan: a, rightSpan: u } = function(e, t) {
1544
- const { minColumn: n, maxColumn: o, minRow: r, maxRow: l } = t;
1545
- let s = 1, i = 1, c = 1, a = 1;
1546
- const u = e[r], h = e[l];
1547
- for (let e = n; e <= o; e++) s = Math.max(s, u[e].cell.__rowSpan), a = Math.max(a, h[e].cell.__rowSpan);
1548
- for (let t = r; t <= l; t++) i = Math.max(i, e[t][n].cell.__colSpan), c = Math.max(c, e[t][o].cell.__colSpan);
1549
- return {
1550
- bottomSpan: a,
1551
- leftSpan: i,
1552
- rightSpan: c,
1553
- topSpan: s
1554
- };
1555
- }(t, l), [d, f] = wn(function(e, t) {
1556
- const n = bn(e, t);
1557
- return null === n && rt(249, t.cell.getKey()), n;
1558
- }(l, n));
1559
- let g = l[d], m = l[f];
1560
- "forward" === r ? g += "maxColumn" === d ? 1 : c : "backward" === r ? g -= "minColumn" === d ? 1 : u : "down" === r ? m += "maxRow" === f ? 1 : i : "up" === r && (m -= "minRow" === f ? 1 : a);
1561
- const p = t[m];
1562
- if (void 0 === p) return !1;
1563
- const C = p[g];
1564
- if (void 0 === C) return !1;
1565
- const [_, S] = function(e, t, n) {
1566
- const o = Bt(e, t, n), r = bn(o, t);
1567
- if (r) return [yn(e, o, r), yn(e, o, wn(r))];
1568
- const l = bn(o, n);
1569
- if (l) return [yn(e, o, wn(l)), yn(e, o, l)];
1570
- const s = ["minColumn", "minRow"];
1571
- return [yn(e, o, s), yn(e, o, wn(s))];
1572
- }(t, n, C), b = $n(e, _.cell), w = $n(e, S.cell);
1573
- return e.$setAnchorCellForSelection(b), e.$setFocusCellForSelection(w, !0), !0;
1574
- }
1575
- function vn(e, t) {
1576
- if ($isRangeSelection(e) || Xt(e)) {
1577
- const n = t.isParentOf(e.anchor.getNode()), o = t.isParentOf(e.focus.getNode());
1578
- return n && o;
1579
- }
1580
- return !1;
1581
- }
1582
- function xn(e, t) {
1583
- t ? e.selectStart() : e.selectEnd();
1584
- }
1585
- function Tn(e, n) {
1586
- const o = n.elem, r = e._config.theme;
1587
- nt($getNearestNodeFromDOMNode(o)) || rt(131), addClassNamesToElement(o, r.tableCellSelected);
1588
- }
1589
- function Rn(e, t) {
1590
- const n = t.elem;
1591
- nt($getNearestNodeFromDOMNode(n)) || rt(131);
1592
- const o = e._config.theme;
1593
- removeClassNamesFromElement(n, o.tableCellSelected);
1594
- }
1595
- function Fn(e) {
1596
- const t = $findMatchingParent(e, nt);
1597
- return nt(t) ? t : null;
1598
- }
1599
- function On(e) {
1600
- const t = $findMatchingParent(e, Xn);
1601
- return Xn(t) ? t : null;
1602
- }
1603
- function An(e, t, n, o, r, l, s) {
1604
- const i = $caretFromPoint(n.focus, r ? "previous" : "next");
1605
- if ($isExtendableTextPointCaret(i)) return !1;
1606
- let c = i;
1607
- for (const e of $extendCaretToRange(i).iterNodeCarets("shadowRoot")) {
1608
- if (!$isSiblingCaret(e) || !$isElementNode(e.origin)) return !1;
1609
- c = e;
1610
- }
1611
- const a = c.getParentAtCaret();
1612
- if (!nt(a)) return !1;
1613
- const u = a, h = function(e) {
1614
- for (const t of $extendCaretToRange(e).iterNodeCarets("root")) {
1615
- const { origin: n } = t;
1616
- if (nt(n)) {
1617
- if ($isChildCaret(t)) return $getChildCaret(n, e.direction);
1618
- } else if (!ct(n)) break;
1619
- }
1620
- return null;
1621
- }($getSiblingCaret(u, c.direction)), f = $findMatchingParent(u, Xn);
1622
- if (!f || !f.is(l)) return !1;
1623
- const g = e.getElementByKey(u.getKey()), m = gn(g);
1624
- if (!g || !m) return !1;
1625
- if (s.table = In(e, f), h) if ("extend" === o) {
1626
- const t = gn(e.getElementByKey(h.origin.getKey()));
1627
- if (!t) return !1;
1628
- s.$setAnchorCellForSelection(m), s.$setFocusCellForSelection(t, !0);
1629
- } else {
1630
- const e = $normalizeCaret(h);
1631
- $setPointFromCaret(n.anchor, e), $setPointFromCaret(n.focus, e);
1632
- }
1633
- else if ("extend" === o) s.$setAnchorCellForSelection(m), s.$setFocusCellForSelection(m, !0);
1634
- else {
1635
- const e = function(e) {
1636
- const t = $getAdjacentChildCaret(e);
1637
- return $isChildCaret(t) ? $normalizeCaret(t) : e;
1638
- }($getSiblingCaret(f, i.direction));
1639
- $setPointFromCaret(n.anchor, e), $setPointFromCaret(n.focus, e);
1640
- }
1641
- return kn(t), !0;
1642
- }
1643
- function Kn(e, t, n, o, l, s) {
1644
- if (("up" === n || "down" === n) && function(e) {
1645
- const t = e.getRootElement();
1646
- if (!t) return !1;
1647
- return t.hasAttribute("aria-controls") && "typeahead-menu" === t.getAttribute("aria-controls");
1648
- }(e)) return !1;
1649
- const i = $getSelection();
1650
- if (!vn(i, o)) {
1651
- if ($isRangeSelection(i)) {
1652
- if ("backward" === n) {
1653
- if (i.focus.offset > 0) return !1;
1654
- const e = function(e) {
1655
- for (let t = e, n = e; null !== n; t = n, n = n.getParent()) if ($isElementNode(n)) {
1656
- if (n !== t && n.getFirstChild() !== t) return null;
1657
- if (!n.isInline()) return n;
1658
- }
1659
- return null;
1660
- }(i.focus.getNode());
1661
- if (!e) return !1;
1662
- const n = e.getPreviousSibling();
1663
- return !!Xn(n) && (kn(t), t.shiftKey ? i.focus.set(n.getParentOrThrow().getKey(), n.getIndexWithinParent(), "element") : n.selectEnd(), !0);
1664
- }
1665
- if (t.shiftKey && ("up" === n || "down" === n)) {
1666
- const e = i.focus.getNode();
1667
- if (!i.isCollapsed() && ("up" === n && !i.isBackward() || "down" === n && i.isBackward())) {
1668
- let l = $findMatchingParent(e, (e) => Xn(e));
1669
- if (nt(l) && (l = $findMatchingParent(l, Xn)), l !== o) return !1;
1670
- if (!l) return !1;
1671
- const s = "down" === n ? l.getNextSibling() : l.getPreviousSibling();
1672
- if (!s) return !1;
1673
- let c = 0;
1674
- "up" === n && $isElementNode(s) && (c = s.getChildrenSize());
1675
- let a = s;
1676
- if ("up" === n && $isElementNode(s)) a = s.getLastChild() || s, c = $isTextNode(a) ? a.getTextContentSize() : 0;
1677
- const u = i.clone();
1678
- return u.focus.set(a.getKey(), c, $isTextNode(a) ? "text" : "element"), $setSelection(u), kn(t), !0;
1679
- }
1680
- if ($isRootOrShadowRoot(e)) {
1681
- const e = "up" === n ? i.getNodes()[i.getNodes().length - 1] : i.getNodes()[0];
1682
- if (e) {
1683
- if (null !== rn(o, e)) {
1684
- const e = o.getFirstDescendant(), t = o.getLastDescendant();
1685
- if (!e || !t) return !1;
1686
- const [n] = Lt(e), [r] = Lt(t), s = o.getCordsFromCellNode(n, l.table), i = o.getCordsFromCellNode(r, l.table), c = o.getDOMCellFromCordsOrThrow(s.x, s.y, l.table), a = o.getDOMCellFromCordsOrThrow(i.x, i.y, l.table);
1687
- return l.$setAnchorCellForSelection(c), l.$setFocusCellForSelection(a, !0), !0;
1688
- }
1689
- }
1690
- return !1;
1691
- }
1692
- {
1693
- let o = $findMatchingParent(e, (e) => $isElementNode(e) && !e.isInline());
1694
- if (nt(o) && (o = $findMatchingParent(o, Xn)), !o) return !1;
1695
- const r = "down" === n ? o.getNextSibling() : o.getPreviousSibling();
1696
- if (Xn(r) && l.tableNodeKey === r.getKey()) {
1697
- const e = r.getFirstDescendant(), o = r.getLastDescendant();
1698
- if (!e || !o) return !1;
1699
- const [l] = Lt(e), [s] = Lt(o), c = i.clone();
1700
- return c.focus.set(("up" === n ? l : s).getKey(), "up" === n ? 0 : s.getChildrenSize(), "element"), kn(t), $setSelection(c), !0;
1701
- }
1702
- }
1703
- }
1704
- }
1705
- return "down" === n && Bn(e) && s.setShouldCheckSelectionForTable(o.getKey()), !1;
1706
- }
1707
- if ($isRangeSelection(i)) {
1708
- if ("backward" === n || "forward" === n) return An(e, t, i, t.shiftKey ? "extend" : "move", "backward" === n, o, l);
1709
- if (i.isCollapsed()) {
1710
- const { anchor: r, focus: c } = i, a = $findMatchingParent(r.getNode(), nt), u = $findMatchingParent(c.getNode(), nt);
1711
- if (!nt(a) || !a.is(u)) return !1;
1712
- const h = On(a);
1713
- if (h !== o && null != h) {
1714
- const o = nn(h, e.getElementByKey(h.getKey()));
1715
- if (null != o) return l.table = pn(h, o), Kn(e, t, n, h, l, s);
1716
- }
1717
- const f = e.getElementByKey(a.__key), g = e.getElementByKey(r.key);
1718
- if (null == g || null == f) return !1;
1719
- let m;
1720
- if ("element" === r.type) m = g.getBoundingClientRect();
1721
- else {
1722
- const t = getDOMSelection(on(e));
1723
- if (null === t || 0 === t.rangeCount) return !1;
1724
- const n = getDOMSelectionRange(t, e.getRootElement());
1725
- if (null === n) return !1;
1726
- m = n.getBoundingClientRect();
1727
- }
1728
- const p = "up" === n ? a.getFirstChild() : a.getLastChild();
1729
- if (null == p) return !1;
1730
- const C = e.getElementByKey(p.__key);
1731
- if (null == C) return !1;
1732
- const _ = C.getBoundingClientRect();
1733
- if ("up" === n ? _.top > m.top - m.height : m.bottom + m.height > _.bottom) {
1734
- kn(t);
1735
- const e = o.getCordsFromCellNode(a, l.table);
1736
- if (!t.shiftKey) return Sn(l, o, e.x, e.y, n);
1737
- {
1738
- const t = o.getDOMCellFromCordsOrThrow(e.x, e.y, l.table);
1739
- l.$setAnchorCellForSelection(t), l.$setFocusCellForSelection(t, !0);
1740
- }
1741
- return !0;
1742
- }
1743
- }
1744
- } else if (Xt(i)) {
1745
- const { anchor: r, focus: s, tableKey: c } = i;
1746
- if (c !== o.getKey()) return !1;
1747
- const a = $findMatchingParent(r.getNode(), nt), u = $findMatchingParent(s.getNode(), nt), [h] = i.getNodes();
1748
- Xn(h) || rt(251);
1749
- const f = nn(h, e.getElementByKey(h.getKey()));
1750
- if (!nt(a) || !nt(u) || !Xn(h) || null == f) return !1;
1751
- l.$updateTableTableSelection(i);
1752
- const g = pn(h, f), m = o.getCordsFromCellNode(a, g), p = o.getDOMCellFromCordsOrThrow(m.x, m.y, g);
1753
- if (l.$setAnchorCellForSelection(p), kn(t), t.shiftKey) {
1754
- const [e, t, r] = zt(o, a, u);
1755
- return Nn(l, e, t, r, n);
1756
- }
1757
- return u.selectEnd(), !0;
1758
- }
1759
- return !1;
1760
- }
1761
- function kn(e) {
1762
- e.preventDefault(), e.stopImmediatePropagation(), e.stopPropagation();
1763
- }
1764
- function En(e, t, n) {
1765
- const o = $createParagraphNode();
1766
- "first" === e ? t.insertBefore(o) : t.insertAfter(o), o.append(...n || []), o.selectEnd();
1767
- }
1768
- function Mn(e, t, n) {
1769
- const o = n.getParent();
1770
- if (!o) return;
1771
- const r = getDOMSelection(on(e));
1772
- if (!r) return;
1773
- const l = getDOMSelectionPoints(r, e.getRootElement()).anchorNode, s = e.getElementByKey(o.getKey()), i = nn(n, e.getElementByKey(n.getKey()));
1774
- if (!l || !s || !i || !s.contains(l) || i.contains(l)) return;
1775
- const c = $findMatchingParent(t.anchor.getNode(), (e) => nt(e));
1776
- if (!c) return;
1777
- const a = $findMatchingParent(c, (e) => Xn(e));
1778
- if (!Xn(a) || !a.is(n)) return;
1779
- const [u, h] = zt(n, c, c), f = u[0][0], g = u[u.length - 1][u[0].length - 1], { startRow: m, startColumn: p } = h, C = m === f.startRow && p === f.startColumn, _ = m === g.startRow && p === g.startColumn;
1780
- return C ? "first" : _ ? "last" : void 0;
1781
- }
1782
- function $n(e, t) {
1783
- const { tableNode: n } = e.$lookup(), o = n.getCordsFromCellNode(t, e.table);
1784
- return n.getDOMCellFromCordsOrThrow(o.x, o.y, e.table);
1785
- }
1786
- function Wn(e, t, n) {
1787
- return rn(e, $getNearestNodeFromDOMNode(t, n));
1788
- }
1789
- function zn(e, t, n) {
1790
- const o = e.querySelector("colgroup");
1791
- if (!o) return;
1792
- const r = [];
1793
- for (let e = 0; e < t; e++) {
1794
- const t = document.createElement("col"), o = n && n[e];
1795
- o && (t.style.width = `${o}px`), r.push(t);
1796
- }
1797
- o.replaceChildren(...r);
1798
- }
1799
- function Hn(e, n, o) {
1800
- if (!n.theme.tableAlignment) return;
1801
- const r = [], l = [];
1802
- for (const e of ["center", "right"]) {
1803
- const t = n.theme.tableAlignment[e];
1804
- t && (e === o ? l : r).push(t);
1805
- }
1806
- removeClassNamesFromElement(e, ...r), addClassNamesToElement(e, ...l);
1807
- }
1808
- const Ln = /* @__PURE__ */ new WeakSet();
1809
- function Bn(e = $getEditor()) {
1810
- return Ln.has(e);
1811
- }
1812
- function Pn(e, t) {
1813
- t ? Ln.add(e) : Ln.delete(e);
1814
- }
1815
- var Dn = class Dn extends ElementNode {
1816
- __rowStriping;
1817
- __frozenColumnCount;
1818
- __frozenRowCount;
1819
- __colWidths;
1820
- static getType() {
1821
- return "table";
1822
- }
1823
- getColWidths() {
1824
- return this.getLatest().__colWidths;
1825
- }
1826
- setColWidths(e) {
1827
- const t = this.getWritable();
1828
- return t.__colWidths = e, t;
1829
- }
1830
- static clone(e) {
1831
- return new Dn(e.__key);
1832
- }
1833
- afterCloneFrom(e) {
1834
- super.afterCloneFrom(e), this.__colWidths = e.__colWidths, this.__rowStriping = e.__rowStriping, this.__frozenColumnCount = e.__frozenColumnCount, this.__frozenRowCount = e.__frozenRowCount;
1835
- }
1836
- static importDOM() {
1837
- return { table: (e) => ({
1838
- conversion: Un,
1839
- priority: 1
1840
- }) };
1841
- }
1842
- static importJSON(e) {
1843
- return Jn().updateFromJSON(e);
1844
- }
1845
- updateFromJSON(e) {
1846
- return super.updateFromJSON(e).setRowStriping(e.rowStriping || !1).setFrozenColumns(e.frozenColumnCount || 0).setFrozenRows(e.frozenRowCount || 0).setColWidths(e.colWidths);
1847
- }
1848
- constructor(e) {
1849
- super(e), this.__rowStriping = !1, this.__frozenColumnCount = 0, this.__frozenRowCount = 0, this.__colWidths = void 0;
1850
- }
1851
- exportJSON() {
1852
- return {
1853
- ...super.exportJSON(),
1854
- colWidths: this.getColWidths(),
1855
- frozenColumnCount: this.__frozenColumnCount ? this.__frozenColumnCount : void 0,
1856
- frozenRowCount: this.__frozenRowCount ? this.__frozenRowCount : void 0,
1857
- rowStriping: this.__rowStriping ? this.__rowStriping : void 0
1858
- };
1859
- }
1860
- extractWithChild(e, t, n) {
1861
- return "html" === n;
1862
- }
1863
- getDOMSlot(e) {
1864
- const t = tn(e) ? e : e.querySelector("table");
1865
- return tn(t) || rt(229), super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"));
1866
- }
1867
- createDOM(e, n) {
1868
- const o = document.createElement("table");
1869
- this.__style && setDOMStyleFromCSS(o.style, this.__style);
1870
- const r = document.createElement("colgroup");
1871
- if (o.appendChild(r), setDOMUnmanaged(r), addClassNamesToElement(o, e.theme.table), this.updateTableElement(null, o, e), Bn(n)) {
1872
- const n = document.createElement("div"), r = e.theme.tableScrollableWrapper;
1873
- return r ? addClassNamesToElement(n, r) : n.style.overflowX = "auto", n.appendChild(o), this.updateTableWrapper(null, n, o, e), n;
1874
- }
1875
- return o;
1876
- }
1877
- updateTableWrapper(e, n, o, r) {
1878
- this.__frozenColumnCount !== (e ? e.__frozenColumnCount : 0) && function(e, n, o, r) {
1879
- r > 0 ? (addClassNamesToElement(e, o.theme.tableFrozenColumn), n.setAttribute("data-lexical-frozen-column", "true")) : (removeClassNamesFromElement(e, o.theme.tableFrozenColumn), n.removeAttribute("data-lexical-frozen-column"));
1880
- }(n, o, r, this.__frozenColumnCount), this.__frozenRowCount !== (e ? e.__frozenRowCount : 0) && function(e, n, o, r) {
1881
- r > 0 ? (addClassNamesToElement(e, o.theme.tableFrozenRow), n.setAttribute("data-lexical-frozen-row", "true")) : (removeClassNamesFromElement(e, o.theme.tableFrozenRow), n.removeAttribute("data-lexical-frozen-row"));
1882
- }(n, o, r, this.__frozenRowCount);
1883
- }
1884
- updateTableElement(e, n, o) {
1885
- this.__style !== (e ? e.__style : "") && setDOMStyleFromCSS(n.style, this.__style, e ? e.__style : ""), this.__rowStriping !== (!!e && e.__rowStriping) && function(e, n, o) {
1886
- o ? (addClassNamesToElement(e, n.theme.tableRowStriping), e.setAttribute("data-lexical-row-striping", "true")) : (removeClassNamesFromElement(e, n.theme.tableRowStriping), e.removeAttribute("data-lexical-row-striping"));
1887
- }(n, o, this.__rowStriping);
1888
- const r = e ? e.getColumnCount() : 0, l = e ? e.__colWidths : void 0;
1889
- this.getColumnCount() === r && this.getColWidths() === l || zn(n, this.getColumnCount(), this.getColWidths()), Hn(n, o, this.getFormatType());
1890
- }
1891
- updateDOM(e, t, o) {
1892
- const r = nn(this, t);
1893
- return t === r === Bn() || (isHTMLElement(l = t) && "DIV" === l.nodeName && this.updateTableWrapper(e, t, r, o), this.updateTableElement(e, r, o), !1);
1894
- var l;
1895
- }
1896
- scaleDOMColWidths(e, t) {
1897
- const n = this.getColWidths();
1898
- if (!n) return;
1899
- zn(nn(this, e), this.getColumnCount(), n.map((e) => e * t));
1900
- }
1901
- exportDOM(e) {
1902
- const t = super.exportDOM(e), { element: o } = t;
1903
- return {
1904
- after: (o) => {
1905
- if (t.after && (o = t.after(o)), !tn(o) && isHTMLElement(o) && (o = o.querySelector("table")), !tn(o)) return null;
1906
- Hn(o, e._config, this.getFormatType());
1907
- const [r] = Ht(this, null, null), l = /* @__PURE__ */ new Map();
1908
- for (const e of r) for (const t of e) {
1909
- const e = t.cell.getKey();
1910
- l.has(e) || l.set(e, {
1911
- colSpan: t.cell.getColSpan(),
1912
- startColumn: t.startColumn
1913
- });
1914
- }
1915
- const s = /* @__PURE__ */ new Set();
1916
- for (const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")) {
1917
- const t = e.getAttribute("data-temporary-table-cell-lexical-key");
1918
- if (t) {
1919
- const n = l.get(t);
1920
- if (e.removeAttribute("data-temporary-table-cell-lexical-key"), n) {
1921
- l.delete(t);
1922
- for (let e = 0; e < n.colSpan; e++) s.add(e + n.startColumn);
1923
- }
1924
- }
1925
- }
1926
- const i = o.querySelector(":scope > colgroup");
1927
- if (i) {
1928
- const e = Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e, t) => s.has(t));
1929
- i.replaceChildren(...e);
1930
- }
1931
- const c = o.querySelectorAll(":scope > tr");
1932
- if (c.length > 0) {
1933
- const e = document.createElement("tbody");
1934
- for (const t of c) e.appendChild(t);
1935
- o.append(e);
1936
- }
1937
- return o;
1938
- },
1939
- element: !tn(o) && isHTMLElement(o) ? o.querySelector("table") : o
1940
- };
1941
- }
1942
- canBeEmpty() {
1943
- return !1;
1944
- }
1945
- isShadowRoot() {
1946
- return !0;
1947
- }
1948
- getCordsFromCellNode(e, t) {
1949
- const { rows: n, domRows: o } = t;
1950
- for (let t = 0; t < n; t++) {
1951
- const n = o[t];
1952
- if (null != n) for (let o = 0; o < n.length; o++) {
1953
- const r = n[o];
1954
- if (null == r) continue;
1955
- const { elem: l } = r, s = Wn(this, l);
1956
- if (null !== s && e.is(s)) return {
1957
- x: o,
1958
- y: t
1959
- };
1960
- }
1961
- }
1962
- throw new Error("Cell not found in table.");
1963
- }
1964
- getDOMCellFromCords(e, t, n) {
1965
- const { domRows: o } = n, r = o[t];
1966
- if (null == r) return null;
1967
- const l = r[e < r.length ? e : r.length - 1];
1968
- return null == l ? null : l;
1969
- }
1970
- getDOMCellFromCordsOrThrow(e, t, n) {
1971
- const o = this.getDOMCellFromCords(e, t, n);
1972
- if (!o) throw new Error("Cell not found at cords.");
1973
- return o;
1974
- }
1975
- getCellNodeFromCords(e, t, n) {
1976
- const o = this.getDOMCellFromCords(e, t, n);
1977
- if (null == o) return null;
1978
- const r = $getNearestNodeFromDOMNode(o.elem);
1979
- return nt(r) ? r : null;
1980
- }
1981
- getCellNodeFromCordsOrThrow(e, t, n) {
1982
- const o = this.getCellNodeFromCords(e, t, n);
1983
- if (!o) throw new Error("Node at cords not TableCellNode.");
1984
- return o;
1985
- }
1986
- getRowStriping() {
1987
- return Boolean(this.getLatest().__rowStriping);
1988
- }
1989
- setRowStriping(e) {
1990
- const t = this.getWritable();
1991
- return t.__rowStriping = e, t;
1992
- }
1993
- setFrozenColumns(e) {
1994
- const t = this.getWritable();
1995
- return t.__frozenColumnCount = e, t;
1996
- }
1997
- getFrozenColumns() {
1998
- return this.getLatest().__frozenColumnCount;
1999
- }
2000
- setFrozenRows(e) {
2001
- const t = this.getWritable();
2002
- return t.__frozenRowCount = e, t;
2003
- }
2004
- getFrozenRows() {
2005
- return this.getLatest().__frozenRowCount;
2006
- }
2007
- canSelectBefore() {
2008
- return !0;
2009
- }
2010
- canIndent() {
2011
- return !1;
2012
- }
2013
- getColumnCount() {
2014
- const e = this.getFirstChild();
2015
- if (!ct(e)) return 0;
2016
- let t = 0;
2017
- return e.getChildren().forEach((e) => {
2018
- nt(e) && (t += e.getColSpan());
2019
- }), t;
2020
- }
2021
- };
2022
- function In(e, t) {
2023
- const n = e.getElementByKey(t.getKey());
2024
- return null === n && rt(230), pn(t, n);
2025
- }
2026
- function Un(e) {
2027
- const t = Jn();
2028
- e.hasAttribute("data-lexical-row-striping") && t.setRowStriping(!0), e.hasAttribute("data-lexical-frozen-column") && t.setFrozenColumns(1), e.hasAttribute("data-lexical-frozen-row") && t.setFrozenRows(1);
2029
- const n = e.querySelector(":scope > colgroup");
2030
- if (n) {
2031
- let e = [];
2032
- for (const t of n.querySelectorAll(":scope > col")) {
2033
- let n = t.style.width || "";
2034
- if (!Ve.test(n) && (n = t.getAttribute("width") || "", !/^\d+$/.test(n))) {
2035
- e = void 0;
2036
- break;
2037
- }
2038
- e.push(parseFloat(n));
2039
- }
2040
- e && t.setColWidths(e);
2041
- }
2042
- return {
2043
- after: (e) => $descendantsMatching(e, ct),
2044
- node: t
2045
- };
2046
- }
2047
- function Jn() {
2048
- return $applyNodeReplacement(new Dn());
2049
- }
2050
- function Xn(e) {
2051
- return e instanceof Dn;
2052
- }
2053
- function Yn(e) {
2054
- ct(e.getParent()) ? e.isEmpty() && e.append($createParagraphNode()) : e.remove();
2055
- }
2056
- function qn(e) {
2057
- Xn(e.getParent()) ? $unwrapAndFilterDescendants(e, nt) : e.remove();
2058
- }
2059
- function jn(e) {
2060
- $unwrapAndFilterDescendants(e, ct);
2061
- const [t] = Ht(e, null, null), n = t.reduce((e, t) => Math.max(e, t.length), 0), o = e.getChildren();
2062
- for (let e = 0; e < t.length; ++e) {
2063
- const r = o[e];
2064
- if (!r) continue;
2065
- ct(r) || rt(254, r.constructor.name, r.getType());
2066
- const l = t[e].reduce((e, t) => t ? 1 + e : e, 0);
2067
- if (l !== n) for (let e = l; e < n; ++e) {
2068
- const e = tt();
2069
- e.append($createParagraphNode()), r.append(e);
2070
- }
2071
- }
2072
- const r = e.getColWidths(), l = e.getColumnCount();
2073
- if (r && r.length !== l) {
2074
- let t;
2075
- if (l < r.length) t = r.slice(0, l);
2076
- else if (r.length > 0) {
2077
- const e = r[r.length - 1];
2078
- t = [...r, ...Array(l - r.length).fill(e)];
2079
- }
2080
- e.setColWidths(t);
2081
- }
2082
- }
2083
- function Vn(e) {
2084
- if (e.detail < 3 || !isDOMNode(e.target)) return !1;
2085
- const t = $getNearestNodeFromDOMNode(e.target);
2086
- if (null === t) return !1;
2087
- const n = $findMatchingParent(t, (e) => $isElementNode(e) && !e.isInline());
2088
- if (null === n) return !1;
2089
- return !!nt(n.getParent()) && (n.select(0), !0);
2090
- }
2091
- function Gn() {
2092
- const e = $getSelection();
2093
- if (!$isRangeSelection(e)) return !1;
2094
- const t = On(e.anchor.getNode());
2095
- if (null === t) return !1;
2096
- const n = $getRoot();
2097
- if (!n.is(t.getParent()) || 1 !== n.getChildrenSize()) return !1;
2098
- const [o] = Ht(t, null, null);
2099
- if (0 === o.length || 0 === o[0].length) return !1;
2100
- const r = o[0][0];
2101
- if (!r || !r.cell) return !1;
2102
- const l = o[o.length - 1], s = l[l.length - 1];
2103
- if (!s || !s.cell) return !1;
2104
- return $setSelection(qt(t, r.cell, s.cell)), !0;
2105
- }
2106
- function Qn(e) {
2107
- return e.registerNodeTransform(Qe, (e) => {
2108
- if (e.getColSpan() > 1 || e.getRowSpan() > 1) {
2109
- const [, , t] = Lt(e), [n] = zt(t, e, e), o = n.length, r = n[0].length;
2110
- let l = t.getFirstChild();
2111
- ct(l) || rt(175);
2112
- const s = [];
2113
- for (let e = 0; e < o; e++) {
2114
- 0 !== e && (l = l.getNextSibling(), ct(l) || rt(175));
2115
- let t = null;
2116
- for (let o = 0; o < r; o++) {
2117
- const r = n[e][o], i = r.cell;
2118
- if (r.startRow === e && r.startColumn === o) t = i, s.push(i);
2119
- else if (i.getColSpan() > 1 || i.getRowSpan() > 1) {
2120
- nt(i) || rt(176);
2121
- const e = tt(i.__headerState);
2122
- null !== t ? t.insertAfter(e) : $insertFirst(l, e);
2123
- }
2124
- }
2125
- }
2126
- for (const e of s) e.setColSpan(1), e.setRowSpan(1);
2127
- }
2128
- });
2129
- }
2130
- function Zn(e, t = !0) {
2131
- const n = new Gt(), o = (o, r, l) => {
2132
- const s = nn(o, l), i = un(o, s, e, t, n);
2133
- n.observers.set(r, [i, s]);
2134
- };
2135
- return mergeRegister(an(e, n), e.registerCommand(SELECTION_CHANGE_COMMAND, () => hn(n, e), COMMAND_PRIORITY_HIGH), e.registerMutationListener(Dn, (t) => {
2136
- e.read("latest", () => {
2137
- for (const [e, r] of t) {
2138
- const t = n.observers.get(e);
2139
- if ("created" === r || "updated" === r) {
2140
- const { tableNode: r, tableElement: l } = Vt(e);
2141
- void 0 === t ? o(r, e, l) : l !== t[1] && (n.removeObserver(e), o(r, e, l));
2142
- } else "destroyed" === r && n.removeObserver(e);
2143
- }
2144
- });
2145
- }, { skipInitialization: !1 }), () => {
2146
- n.removeAllObservers();
2147
- });
2148
- }
2149
- function eo(e, t) {
2150
- e.hasNodes([Dn]) || rt(255);
2151
- const { hasNestedTables: n = signal(!1) } = t ?? {};
2152
- return mergeRegister(e.registerCommand(ot, (e) => function({ rows: e, columns: t, includeHeaders: n }, o) {
2153
- const l = $getSelection() || $getPreviousSelection();
2154
- if (!l || !$isRangeSelection(l)) return !1;
2155
- if (!o && On(l.anchor.getNode())) return !1;
2156
- const s = at(Number(e), Number(t), n);
2157
- $insertNodeToNearestRoot(s);
2158
- const i = s.getFirstDescendant();
2159
- return $isTextNode(i) && i.select(), !0;
2160
- }(e, n.peek()), COMMAND_PRIORITY_EDITOR), e.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, (t, o) => e === o && function(e, t) {
2161
- const { nodes: n, selection: o } = e;
2162
- if (!n.some((e) => Xn(e) || $dfsWithSlots(e).some((e) => Xn(e.node)))) return !1;
2163
- const l = Xt(o), i = $isRangeSelection(o);
2164
- if (!(i && null !== $findMatchingParent(o.anchor.getNode(), (e) => nt(e)) && null !== $findMatchingParent(o.focus.getNode(), (e) => nt(e)) || l)) return !1;
2165
- if (1 === n.length && Xn(n[0])) return function(e, t) {
2166
- const n = t.getStartEndPoints(), o = Xt(t);
2167
- if (null === n) return !1;
2168
- const [l, i] = n, [c, a, u] = Lt(l), h = $findMatchingParent(i.getNode(), (e) => nt(e));
2169
- if (!(nt(c) && nt(h) && ct(a) && Xn(u))) return !1;
2170
- const [f, g, m] = zt(u, c, h), [p] = Ht(e, null, null), C = f.length, _ = C > 0 ? f[0].length : 0;
2171
- let S = g.startRow, b = g.startColumn, w = p.length, y = w > 0 ? p[0].length : 0;
2172
- if (o) {
2173
- const e = Bt(f, g, m), t = e.maxRow - e.minRow + 1, n = e.maxColumn - e.minColumn + 1;
2174
- S = e.minRow, b = e.minColumn, w = Math.min(w, t), y = Math.min(y, n);
2175
- }
2176
- let N = !1;
2177
- const v = Math.min(C, S + w) - 1, x = Math.min(_, b + y) - 1, T = /* @__PURE__ */ new Set();
2178
- for (let e = S; e <= v; e++) for (let t = b; t <= x; t++) {
2179
- const n = f[e][t];
2180
- T.has(n.cell.getKey()) || 1 === n.cell.__rowSpan && 1 === n.cell.__colSpan || (Wt(n.cell), T.add(n.cell.getKey()), N = !0);
2181
- }
2182
- let [R] = Ht(u.getWritable(), null, null);
2183
- const F = w - C + S;
2184
- for (let e = 0; e < F; e++) wt(R[C - 1][0].cell);
2185
- const O = y - _ + b;
2186
- for (let e = 0; e < O; e++) xt(R[0][_ - 1].cell, !0, !1);
2187
- [R] = Ht(u.getWritable(), null, null);
2188
- for (let e = S; e < S + w; e++) for (let t = b; t < b + y; t++) {
2189
- const n = e - S, o = t - b, l = p[n][o];
2190
- if (l.startRow !== n || l.startColumn !== o) continue;
2191
- const i = l.cell;
2192
- if (1 !== i.__rowSpan || 1 !== i.__colSpan) {
2193
- const n = [], o = Math.min(e + i.__rowSpan, S + w) - 1, r = Math.min(t + i.__colSpan, b + y) - 1;
2194
- for (let l = e; l <= o; l++) for (let e = t; e <= r; e++) {
2195
- const t = R[l][e];
2196
- n.push(t.cell);
2197
- }
2198
- Et(n), N = !0;
2199
- }
2200
- const { cell: c } = R[e][t], a = i.getBackgroundColor();
2201
- null != a && c.setBackgroundColor(a);
2202
- const u = c.getChildren();
2203
- i.getChildren().forEach((e) => {
2204
- if ($isTextNode(e)) $createParagraphNode().append(e), c.append(e);
2205
- else c.append(e);
2206
- }), u.forEach((e) => e.remove());
2207
- }
2208
- if (o && N) {
2209
- const [e] = Ht(u.getWritable(), null, null);
2210
- e[g.startRow][g.startColumn].cell.selectEnd();
2211
- }
2212
- return !0;
2213
- }(n[0], o);
2214
- if (i && t.peek() && !function(e) {
2215
- if (Xt(e) && !e.focus.getNode().is(e.anchor.getNode())) return !0;
2216
- if ($isRangeSelection(e) && nt(e.anchor.getNode()) && !e.anchor.getNode().is(e.focus.getNode())) return !0;
2217
- return !1;
2218
- }(o)) return !1;
2219
- return !0;
2220
- }(t, n), COMMAND_PRIORITY_EDITOR), e.registerCommand(SELECT_ALL_COMMAND, Gn, COMMAND_PRIORITY_LOW), e.registerCommand(CLICK_COMMAND, Vn, COMMAND_PRIORITY_EDITOR), e.registerNodeTransform(Dn, jn), e.registerNodeTransform(lt, qn), e.registerNodeTransform(Qe, Yn));
2221
- }
2222
- const to = {
2223
- $accepts: ct,
2224
- $packageRun: (e) => e.every(nt) ? [it().splice(0, 0, e)] : [],
2225
- name: "TableSchema"
2226
- }, no = {
2227
- $accepts: nt,
2228
- name: "TableRowSchema"
2229
- }, oo = [
2230
- /* @__PURE__ */ defineImportRule({
2231
- $import: (e, t) => {
2232
- const n = Jn();
2233
- t.hasAttribute("data-lexical-row-striping") && n.setRowStriping(!0), t.hasAttribute("data-lexical-frozen-column") && n.setFrozenColumns(1), t.hasAttribute("data-lexical-frozen-row") && n.setFrozenRows(1);
2234
- const o = t.querySelector(":scope > colgroup");
2235
- if (o) {
2236
- let e = [];
2237
- for (const t of o.querySelectorAll(":scope > col")) {
2238
- let n = t.style.width || "";
2239
- if (!Ve.test(n) && (n = t.getAttribute("width") || "", !/^\d+$/.test(n))) {
2240
- e = void 0;
2241
- break;
2242
- }
2243
- e.push(parseFloat(n));
2244
- }
2245
- e && n.setColWidths(e);
2246
- }
2247
- return [n.splice(0, 0, $descendantsMatching(e.$importChildren(t), ct))];
2248
- },
2249
- match: sel.tag("table"),
2250
- name: "@lexical/table/table"
2251
- }),
2252
- /* @__PURE__ */ defineImportRule({
2253
- $import: (e, t) => [it(Ve.test(t.style.height) ? parseFloat(t.style.height) : void 0).splice(0, 0, $descendantsMatching(e.$importChildren(t), nt))],
2254
- match: sel.tag("tr"),
2255
- name: "@lexical/table/tr"
2256
- }),
2257
- /* @__PURE__ */ defineImportRule({
2258
- $import: (e, t) => {
2259
- const n = "TH" === t.nodeName, i = Ve.test(t.style.width) ? parseFloat(t.style.width) : void 0;
2260
- let c = Ge.NO_STATUS;
2261
- if (n) {
2262
- const e = t.getAttribute("scope");
2263
- if ("col" === e) c = Ge.COLUMN;
2264
- else if ("row" === e) c = Ge.ROW;
2265
- else {
2266
- const e = t.parentElement, n = isHTMLTableRowElement(e) && (e.parentElement && "THEAD" === e.parentElement.nodeName || 0 === e.rowIndex), o = 0 === t.cellIndex;
2267
- n && (c |= Ge.ROW), o && (c |= Ge.COLUMN), c === Ge.NO_STATUS && (c = Ge.ROW);
2268
- }
2269
- }
2270
- const a = tt(c, t.colSpan, i);
2271
- a.__rowSpan = t.rowSpan;
2272
- const u = t.style.backgroundColor;
2273
- "" !== u && (a.__backgroundColor = u);
2274
- const h = t.style.verticalAlign;
2275
- (function(e) {
2276
- return "middle" === e || "bottom" === e;
2277
- })(h) && (a.__verticalAlign = h);
2278
- const d = e.get(ImportTextFormat), f = d | function(e) {
2279
- let t = 0;
2280
- const n = e.fontWeight;
2281
- "700" !== n && "bold" !== n || (t |= IS_BOLD), "italic" === e.fontStyle && (t |= IS_ITALIC);
2282
- const o = (e.textDecoration || "").split(" ");
2283
- return o.includes("underline") && (t |= IS_UNDERLINE), o.includes("line-through") && (t |= IS_STRIKETHROUGH), t;
2284
- }(t.style), g = e.get(ImportTextStyle), m = t.style.color, p = m ? {
2285
- ...g,
2286
- color: m
2287
- } : g, C = [];
2288
- f !== d && C.push(contextValue(ImportTextFormat, f)), p !== g && C.push(contextValue(ImportTextStyle, p));
2289
- const _ = function(e) {
2290
- const t = [];
2291
- let n = null;
2292
- const i = () => {
2293
- if (null !== n) {
2294
- const e = n.getFirstChild();
2295
- $isLineBreakNode(e) && 1 === n.getChildrenSize() && e.remove();
2296
- }
2297
- };
2298
- for (const c of e) $isInlineElementOrDecoratorNode(c) || $isTextNode(c) || $isLineBreakNode(c) ? null !== n ? n.append(c) : (n = $createParagraphNode().append(c), t.push(n)) : (i(), n = null, t.push(c));
2299
- return i(), 0 === t.length && t.push($createParagraphNode()), t;
2300
- }(e.$importChildren(t, { context: C })), S = n ? _ : $propagateTextAlignToBlockChildren(_, t);
2301
- return [a.splice(0, 0, S)];
2302
- },
2303
- match: sel.tag("td", "th"),
2304
- name: "@lexical/table/cell"
2305
- })
2306
- ], ro = /* @__PURE__ */ defineExtension({
2307
- build: (e, t, n) => namedSignals(t),
2308
- config: /* @__PURE__ */ safeCast({
2309
- hasCellBackgroundColor: !0,
2310
- hasCellMerge: !0,
2311
- hasHorizontalScroll: !0,
2312
- hasNestedTables: !1,
2313
- hasTabHandler: !0
2314
- }),
2315
- dependencies: [CoreImportExtension, /* @__PURE__ */ configExtension(DOMImportExtension, { rules: oo })],
2316
- name: "@lexical/table/Table",
2317
- nodes: () => [
2318
- Dn,
2319
- lt,
2320
- Qe
2321
- ],
2322
- register(e, t, n) {
2323
- const o = n.getOutput();
2324
- return mergeRegister(effect(() => {
2325
- const t = o.hasHorizontalScroll.value;
2326
- Bn(e) !== t && (Pn(e, t), e.update($fullReconcile));
2327
- }), eo(e, o), effect(() => Zn(e, o.hasTabHandler.value)), effect(() => o.hasCellMerge.value ? void 0 : Qn(e)), effect(() => o.hasCellBackgroundColor.value ? void 0 : e.registerNodeTransform(Qe, (e) => {
2328
- null !== e.getBackgroundColor() && e.setBackgroundColor(null);
2329
- })));
2330
- }
2331
- }), lo = /* @__PURE__ */ defineExtension({
2332
- dependencies: [ro],
2333
- name: "@lexical/table/Import"
2334
- });
2335
- //#endregion
2336
- export { zt as $computeTableMap, Ht as $computeTableMapSkipCellCheck, tt as $createTableCellNode, Jn as $createTableNode, at as $createTableNodeWithDimensions, it as $createTableRowNode, Yt as $createTableSelection, qt as $createTableSelectionFrom, Tt as $deleteTableColumn, Ot as $deleteTableColumnAtSelection, At as $deleteTableColumn__EXPERIMENTAL, Rt as $deleteTableRowAtSelection, Ft as $deleteTableRow__EXPERIMENTAL, Fn as $findCellNode, On as $findTableNode, In as $getElementForTableNode, Lt as $getNodeTriplet, Vt as $getTableAndElementByKey, ut as $getTableCellNodeFromLexicalNode, It as $getTableCellNodeRect, gt as $getTableColumnIndexFromTableCellNode, dt as $getTableNodeFromLexicalNodeOrThrow, ft as $getTableRowIndexFromTableCellNode, ht as $getTableRowNodeFromTableCellNodeOrThrow, yt as $insertTableColumn, Nt as $insertTableColumnAtSelection, vt as $insertTableColumn__EXPERIMENTAL, Ct as $insertTableRow, St as $insertTableRowAtSelection, bt as $insertTableRow__EXPERIMENTAL, Bn as $isScrollableTablesActive, Pt as $isSimpleTable, nt as $isTableCellNode, Xn as $isTableNode, ct as $isTableRowNode, Xt as $isTableSelection, Et as $mergeCells, Dt as $moveTableColumn, pt as $removeTableRowAtIndex, $t as $unmergeCell, ot as INSERT_TABLE_COMMAND, Ge as TableCellHeaderStates, Qe as TableCellNode, ro as TableExtension, lo as TableImportExtension, oo as TableImportRules, Dn as TableNode, Qt as TableObserver, lt as TableRowNode, no as TableRowSchema, to as TableSchema, un as applyTableHandlers, gn as getDOMCellFromTarget, nn as getTableElement, fn as getTableObserverFromTableElement, Qn as registerTableCellUnmergeTransform, eo as registerTablePlugin, Zn as registerTableSelectionObserver, Pn as setScrollableTablesActive };