@lexical/table 0.44.1-nightly.20260519.0 → 0.45.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LexicalTable.dev.js → dist/LexicalTable.dev.js} +268 -33
- package/{LexicalTable.dev.mjs → dist/LexicalTable.dev.mjs} +264 -33
- package/{LexicalTable.mjs → dist/LexicalTable.mjs} +4 -0
- package/{LexicalTable.node.mjs → dist/LexicalTable.node.mjs} +4 -0
- package/dist/LexicalTable.prod.js +9 -0
- package/dist/LexicalTable.prod.mjs +9 -0
- package/dist/TableImportExtension.d.ts +41 -0
- package/{index.d.ts → dist/index.d.ts} +1 -0
- package/package.json +34 -18
- package/src/LexicalTableCellNode.ts +479 -0
- package/src/LexicalTableCommands.ts +27 -0
- package/src/LexicalTableExtension.ts +104 -0
- package/src/LexicalTableNode.ts +678 -0
- package/src/LexicalTableObserver.ts +575 -0
- package/src/LexicalTablePluginHelpers.ts +694 -0
- package/src/LexicalTableRowNode.ts +154 -0
- package/src/LexicalTableSelection.ts +460 -0
- package/src/LexicalTableSelectionHelpers.ts +2409 -0
- package/src/LexicalTableUtils.ts +1386 -0
- package/src/TableImportExtension.ts +324 -0
- package/src/constants.ts +13 -0
- package/src/index.ts +97 -0
- package/LexicalTable.prod.js +0 -9
- package/LexicalTable.prod.mjs +0 -9
- /package/{LexicalTable.js → dist/LexicalTable.js} +0 -0
- /package/{LexicalTable.js.flow → dist/LexicalTable.js.flow} +0 -0
- /package/{LexicalTableCellNode.d.ts → dist/LexicalTableCellNode.d.ts} +0 -0
- /package/{LexicalTableCommands.d.ts → dist/LexicalTableCommands.d.ts} +0 -0
- /package/{LexicalTableExtension.d.ts → dist/LexicalTableExtension.d.ts} +0 -0
- /package/{LexicalTableNode.d.ts → dist/LexicalTableNode.d.ts} +0 -0
- /package/{LexicalTableObserver.d.ts → dist/LexicalTableObserver.d.ts} +0 -0
- /package/{LexicalTablePluginHelpers.d.ts → dist/LexicalTablePluginHelpers.d.ts} +0 -0
- /package/{LexicalTableRowNode.d.ts → dist/LexicalTableRowNode.d.ts} +0 -0
- /package/{LexicalTableSelection.d.ts → dist/LexicalTableSelection.d.ts} +0 -0
- /package/{LexicalTableSelectionHelpers.d.ts → dist/LexicalTableSelectionHelpers.d.ts} +0 -0
- /package/{LexicalTableUtils.d.ts → dist/LexicalTableUtils.d.ts} +0 -0
- /package/{constants.d.ts → dist/constants.d.ts} +0 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {ChildSchema, ImportContextPairOrUpdater} from '@lexical/html';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
$propagateTextAlignToBlockChildren,
|
|
13
|
+
contextValue,
|
|
14
|
+
defineImportRule,
|
|
15
|
+
DOMImportExtension,
|
|
16
|
+
ImportTextFormat,
|
|
17
|
+
ImportTextStyle,
|
|
18
|
+
sel,
|
|
19
|
+
} from '@lexical/html';
|
|
20
|
+
import {$descendantsMatching} from '@lexical/utils';
|
|
21
|
+
import {
|
|
22
|
+
$createParagraphNode,
|
|
23
|
+
$isInlineElementOrDecoratorNode,
|
|
24
|
+
$isLineBreakNode,
|
|
25
|
+
$isTextNode,
|
|
26
|
+
configExtension,
|
|
27
|
+
defineExtension,
|
|
28
|
+
IS_BOLD,
|
|
29
|
+
IS_ITALIC,
|
|
30
|
+
IS_STRIKETHROUGH,
|
|
31
|
+
IS_UNDERLINE,
|
|
32
|
+
isHTMLTableRowElement,
|
|
33
|
+
type LexicalNode,
|
|
34
|
+
type ParagraphNode,
|
|
35
|
+
} from 'lexical';
|
|
36
|
+
|
|
37
|
+
import {PIXEL_VALUE_REG_EXP} from './constants';
|
|
38
|
+
import {
|
|
39
|
+
$createTableCellNode,
|
|
40
|
+
$isTableCellNode,
|
|
41
|
+
TableCellHeaderStates,
|
|
42
|
+
} from './LexicalTableCellNode';
|
|
43
|
+
import {TableExtension} from './LexicalTableExtension';
|
|
44
|
+
import {$createTableNode} from './LexicalTableNode';
|
|
45
|
+
import {$createTableRowNode, $isTableRowNode} from './LexicalTableRowNode';
|
|
46
|
+
|
|
47
|
+
function isValidVerticalAlign(
|
|
48
|
+
verticalAlign?: null | string,
|
|
49
|
+
): verticalAlign is 'middle' | 'bottom' {
|
|
50
|
+
return verticalAlign === 'middle' || verticalAlign === 'bottom';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Bitmask of TextNode format bits implied by a `<th>` / `<td>`'s
|
|
55
|
+
* inline styles (`font-weight: bold`, `font-style: italic`, and
|
|
56
|
+
* `underline` / `line-through` in `text-decoration`).
|
|
57
|
+
*/
|
|
58
|
+
function cellTextFormatMask(style: CSSStyleDeclaration): number {
|
|
59
|
+
let mask = 0;
|
|
60
|
+
const fontWeight = style.fontWeight;
|
|
61
|
+
if (fontWeight === '700' || fontWeight === 'bold') {
|
|
62
|
+
mask |= IS_BOLD;
|
|
63
|
+
}
|
|
64
|
+
if (style.fontStyle === 'italic') {
|
|
65
|
+
mask |= IS_ITALIC;
|
|
66
|
+
}
|
|
67
|
+
const decoration = (style.textDecoration || '').split(' ');
|
|
68
|
+
if (decoration.includes('underline')) {
|
|
69
|
+
mask |= IS_UNDERLINE;
|
|
70
|
+
}
|
|
71
|
+
if (decoration.includes('line-through')) {
|
|
72
|
+
mask |= IS_STRIKETHROUGH;
|
|
73
|
+
}
|
|
74
|
+
return mask;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Coalesce inline + line-break runs inside a `<td>`/`<th>` into their own
|
|
79
|
+
* `ParagraphNode`s, leaving any pre-existing `ParagraphNode` children
|
|
80
|
+
* (real `<p>` elements, or the `ParagraphNode` stand-ins that
|
|
81
|
+
* {@link TransparentBlockRule} lowers `<div>`/`<section>`/… to) in
|
|
82
|
+
* place as their own paragraph siblings. Mirrors the legacy `<td>`
|
|
83
|
+
* importer where a bare `<td>789<div>000</div></td>` ended up as two
|
|
84
|
+
* paragraphs (`<p>789</p><p>000</p>`), and also drops a sole leading
|
|
85
|
+
* `<br>` that the legacy `removeSingleLineBreakNode` cleanup would have
|
|
86
|
+
* removed.
|
|
87
|
+
*/
|
|
88
|
+
function $packageCellChildren(children: LexicalNode[]): LexicalNode[] {
|
|
89
|
+
const result: LexicalNode[] = [];
|
|
90
|
+
let paragraph: ParagraphNode | null = null;
|
|
91
|
+
|
|
92
|
+
const flushSingleLineBreak = () => {
|
|
93
|
+
if (paragraph !== null) {
|
|
94
|
+
const first = paragraph.getFirstChild();
|
|
95
|
+
if ($isLineBreakNode(first) && paragraph.getChildrenSize() === 1) {
|
|
96
|
+
first.remove();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
for (const child of children) {
|
|
102
|
+
if (
|
|
103
|
+
$isInlineElementOrDecoratorNode(child) ||
|
|
104
|
+
$isTextNode(child) ||
|
|
105
|
+
$isLineBreakNode(child)
|
|
106
|
+
) {
|
|
107
|
+
if (paragraph !== null) {
|
|
108
|
+
paragraph.append(child);
|
|
109
|
+
} else {
|
|
110
|
+
paragraph = $createParagraphNode().append(child);
|
|
111
|
+
result.push(paragraph);
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
// Block children (paragraphs, nested tables, decorator blocks, …)
|
|
115
|
+
// start their own sibling — any inline run that was being
|
|
116
|
+
// accumulated into `paragraph` is closed off here.
|
|
117
|
+
flushSingleLineBreak();
|
|
118
|
+
paragraph = null;
|
|
119
|
+
result.push(child);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
flushSingleLineBreak();
|
|
123
|
+
if (result.length === 0) {
|
|
124
|
+
result.push($createParagraphNode());
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const TableRule = defineImportRule({
|
|
130
|
+
$import: (ctx, el) => {
|
|
131
|
+
const node = $createTableNode();
|
|
132
|
+
if (el.hasAttribute('data-lexical-row-striping')) {
|
|
133
|
+
node.setRowStriping(true);
|
|
134
|
+
}
|
|
135
|
+
if (el.hasAttribute('data-lexical-frozen-column')) {
|
|
136
|
+
node.setFrozenColumns(1);
|
|
137
|
+
}
|
|
138
|
+
if (el.hasAttribute('data-lexical-frozen-row')) {
|
|
139
|
+
node.setFrozenRows(1);
|
|
140
|
+
}
|
|
141
|
+
const colGroup = el.querySelector(':scope > colgroup');
|
|
142
|
+
if (colGroup) {
|
|
143
|
+
let columns: number[] | undefined = [];
|
|
144
|
+
for (const col of colGroup.querySelectorAll<HTMLTableColElement>(
|
|
145
|
+
':scope > col',
|
|
146
|
+
)) {
|
|
147
|
+
let width = col.style.width || '';
|
|
148
|
+
if (!PIXEL_VALUE_REG_EXP.test(width)) {
|
|
149
|
+
width = col.getAttribute('width') || '';
|
|
150
|
+
if (!/^\d+$/.test(width)) {
|
|
151
|
+
columns = undefined;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
columns.push(parseFloat(width));
|
|
156
|
+
}
|
|
157
|
+
if (columns) {
|
|
158
|
+
node.setColWidths(columns);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return [
|
|
162
|
+
node.splice(
|
|
163
|
+
0,
|
|
164
|
+
0,
|
|
165
|
+
$descendantsMatching(ctx.$importChildren(el), $isTableRowNode),
|
|
166
|
+
),
|
|
167
|
+
];
|
|
168
|
+
},
|
|
169
|
+
match: sel.tag('table'),
|
|
170
|
+
name: '@lexical/table/table',
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const TableRowRule = defineImportRule({
|
|
174
|
+
$import: (ctx, el) => {
|
|
175
|
+
const height = PIXEL_VALUE_REG_EXP.test(el.style.height)
|
|
176
|
+
? parseFloat(el.style.height)
|
|
177
|
+
: undefined;
|
|
178
|
+
return [
|
|
179
|
+
$createTableRowNode(height).splice(
|
|
180
|
+
0,
|
|
181
|
+
0,
|
|
182
|
+
$descendantsMatching(ctx.$importChildren(el), $isTableCellNode),
|
|
183
|
+
),
|
|
184
|
+
];
|
|
185
|
+
},
|
|
186
|
+
match: sel.tag('tr'),
|
|
187
|
+
name: '@lexical/table/tr',
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const TableCellRule = defineImportRule({
|
|
191
|
+
$import: (ctx, el) => {
|
|
192
|
+
const isHeader = el.nodeName === 'TH';
|
|
193
|
+
const width = PIXEL_VALUE_REG_EXP.test(el.style.width)
|
|
194
|
+
? parseFloat(el.style.width)
|
|
195
|
+
: undefined;
|
|
196
|
+
let headerState = TableCellHeaderStates.NO_STATUS;
|
|
197
|
+
if (isHeader) {
|
|
198
|
+
const scope = el.getAttribute('scope');
|
|
199
|
+
if (scope === 'col') {
|
|
200
|
+
headerState = TableCellHeaderStates.COLUMN;
|
|
201
|
+
} else if (scope === 'row') {
|
|
202
|
+
headerState = TableCellHeaderStates.ROW;
|
|
203
|
+
} else {
|
|
204
|
+
const parentRow = el.parentElement;
|
|
205
|
+
const isInHeaderRow =
|
|
206
|
+
isHTMLTableRowElement(parentRow) &&
|
|
207
|
+
((parentRow.parentElement &&
|
|
208
|
+
parentRow.parentElement.nodeName === 'THEAD') ||
|
|
209
|
+
parentRow.rowIndex === 0);
|
|
210
|
+
const isFirstColumn = el.cellIndex === 0;
|
|
211
|
+
if (isInHeaderRow) {
|
|
212
|
+
headerState |= TableCellHeaderStates.ROW;
|
|
213
|
+
}
|
|
214
|
+
if (isFirstColumn) {
|
|
215
|
+
headerState |= TableCellHeaderStates.COLUMN;
|
|
216
|
+
}
|
|
217
|
+
if (headerState === TableCellHeaderStates.NO_STATUS) {
|
|
218
|
+
headerState = TableCellHeaderStates.ROW;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const cell = $createTableCellNode(headerState, el.colSpan, width);
|
|
223
|
+
cell.__rowSpan = el.rowSpan;
|
|
224
|
+
const backgroundColor = el.style.backgroundColor;
|
|
225
|
+
if (backgroundColor !== '') {
|
|
226
|
+
cell.__backgroundColor = backgroundColor;
|
|
227
|
+
}
|
|
228
|
+
const verticalAlign = el.style.verticalAlign;
|
|
229
|
+
if (isValidVerticalAlign(verticalAlign)) {
|
|
230
|
+
cell.__verticalAlign = verticalAlign;
|
|
231
|
+
}
|
|
232
|
+
// Propagate the cell's bold/italic/underline/strikethrough as
|
|
233
|
+
// format bits, and the cell's `color` as a parsed-style record.
|
|
234
|
+
// The core `#text` rule reads both at construction time and
|
|
235
|
+
// applies them to each TextNode — no post-walk needed.
|
|
236
|
+
const inheritedFormat = ctx.get(ImportTextFormat);
|
|
237
|
+
const cellFormat = inheritedFormat | cellTextFormatMask(el.style);
|
|
238
|
+
const inheritedStyle = ctx.get(ImportTextStyle);
|
|
239
|
+
const color = el.style.color;
|
|
240
|
+
const cellStyle: Readonly<Record<string, string>> = color
|
|
241
|
+
? {...inheritedStyle, color}
|
|
242
|
+
: inheritedStyle;
|
|
243
|
+
const branchContext: ImportContextPairOrUpdater[] = [];
|
|
244
|
+
if (cellFormat !== inheritedFormat) {
|
|
245
|
+
branchContext.push(contextValue(ImportTextFormat, cellFormat));
|
|
246
|
+
}
|
|
247
|
+
if (cellStyle !== inheritedStyle) {
|
|
248
|
+
branchContext.push(contextValue(ImportTextStyle, cellStyle));
|
|
249
|
+
}
|
|
250
|
+
// {@link $packageCellChildren} keeps each `ParagraphNode` child
|
|
251
|
+
// (from a real `<p>`, or from {@link TransparentBlockRule}'s
|
|
252
|
+
// lowering of `<div>`/`<section>`/…) as its own sibling paragraph
|
|
253
|
+
// — matching legacy `<td>`'s `<td>789<div>000</div></td>` →
|
|
254
|
+
// `<p>789</p><p>000</p>` shape.
|
|
255
|
+
const packaged = $packageCellChildren(
|
|
256
|
+
ctx.$importChildren(el, {context: branchContext}),
|
|
257
|
+
);
|
|
258
|
+
// Only `<td>` propagates `text-align` onto its block children —
|
|
259
|
+
// mirroring legacy `wrapContinuousInlines`, which runs only for
|
|
260
|
+
// `isBlockDomNode` elements. `<th>` is intentionally absent from
|
|
261
|
+
// the block-tag set (see `BLOCK_TAG_RE` in `LexicalUtils.ts`), so a
|
|
262
|
+
// `<th style="text-align: start">` wrapping a bare `<p>` leaves the
|
|
263
|
+
// paragraph format empty.
|
|
264
|
+
const children = isHeader
|
|
265
|
+
? packaged
|
|
266
|
+
: $propagateTextAlignToBlockChildren(packaged, el);
|
|
267
|
+
return [cell.splice(0, 0, children)];
|
|
268
|
+
},
|
|
269
|
+
match: sel.tag('td', 'th'),
|
|
270
|
+
name: '@lexical/table/cell',
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* A {@link ChildSchema} that enforces TableNode invariants: only
|
|
275
|
+
* `TableRowNode` children are accepted; orphan `TableCellNode` runs are
|
|
276
|
+
* wrapped in a synthesized row.
|
|
277
|
+
*
|
|
278
|
+
* @experimental
|
|
279
|
+
*/
|
|
280
|
+
export const TableSchema: ChildSchema = {
|
|
281
|
+
$accepts: $isTableRowNode,
|
|
282
|
+
$packageRun: run =>
|
|
283
|
+
run.every($isTableCellNode)
|
|
284
|
+
? [$createTableRowNode().splice(0, 0, run)]
|
|
285
|
+
: [],
|
|
286
|
+
name: 'TableSchema',
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A {@link ChildSchema} that enforces TableRowNode invariants: only
|
|
291
|
+
* `TableCellNode` children are accepted; non-cell children are dropped
|
|
292
|
+
* (the legacy converter does the same via `$descendantsMatching`).
|
|
293
|
+
*
|
|
294
|
+
* @experimental
|
|
295
|
+
*/
|
|
296
|
+
export const TableRowSchema: ChildSchema = {
|
|
297
|
+
$accepts: $isTableCellNode,
|
|
298
|
+
name: 'TableRowSchema',
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Import rules for {@link TableNode}, {@link TableRowNode}, and
|
|
303
|
+
* {@link TableCellNode}.
|
|
304
|
+
*
|
|
305
|
+
* @experimental
|
|
306
|
+
*/
|
|
307
|
+
export const TableImportRules = [TableRule, TableRowRule, TableCellRule];
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Bundles {@link TableImportRules} together with the runtime
|
|
311
|
+
* {@link TableExtension}. The application is expected to already have
|
|
312
|
+
* `CoreImportExtension` (or some equivalent) in its dependency graph —
|
|
313
|
+
* the core/text/paragraph/inline-format rules are a shared baseline,
|
|
314
|
+
* not something this leaf importer should re-declare.
|
|
315
|
+
*
|
|
316
|
+
* @experimental
|
|
317
|
+
*/
|
|
318
|
+
export const TableImportExtension = defineExtension({
|
|
319
|
+
dependencies: [
|
|
320
|
+
TableExtension,
|
|
321
|
+
configExtension(DOMImportExtension, {rules: TableImportRules}),
|
|
322
|
+
],
|
|
323
|
+
name: '@lexical/table/Import',
|
|
324
|
+
});
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const PIXEL_VALUE_REG_EXP = /^(\d+(?:\.\d+)?)px$/;
|
|
10
|
+
|
|
11
|
+
// .PlaygroundEditorTheme__tableCell width value from
|
|
12
|
+
// packages/lexical-playground/src/themes/PlaygroundEditorTheme.css
|
|
13
|
+
export const COLUMN_WIDTH = 75;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type {SerializedTableCellNode} from './LexicalTableCellNode';
|
|
10
|
+
export {
|
|
11
|
+
$createTableCellNode,
|
|
12
|
+
$isTableCellNode,
|
|
13
|
+
TableCellHeaderStates,
|
|
14
|
+
TableCellNode,
|
|
15
|
+
} from './LexicalTableCellNode';
|
|
16
|
+
export type {
|
|
17
|
+
InsertTableCommandPayload,
|
|
18
|
+
InsertTableCommandPayloadHeaders,
|
|
19
|
+
} from './LexicalTableCommands';
|
|
20
|
+
export {INSERT_TABLE_COMMAND} from './LexicalTableCommands';
|
|
21
|
+
export {type TableConfig, TableExtension} from './LexicalTableExtension';
|
|
22
|
+
export type {SerializedTableNode} from './LexicalTableNode';
|
|
23
|
+
export {
|
|
24
|
+
$createTableNode,
|
|
25
|
+
$getElementForTableNode,
|
|
26
|
+
$isScrollableTablesActive,
|
|
27
|
+
$isTableNode,
|
|
28
|
+
setScrollableTablesActive,
|
|
29
|
+
TableNode,
|
|
30
|
+
} from './LexicalTableNode';
|
|
31
|
+
export type {TableDOMCell} from './LexicalTableObserver';
|
|
32
|
+
export {$getTableAndElementByKey, TableObserver} from './LexicalTableObserver';
|
|
33
|
+
export {
|
|
34
|
+
registerTableCellUnmergeTransform,
|
|
35
|
+
registerTablePlugin,
|
|
36
|
+
registerTableSelectionObserver,
|
|
37
|
+
} from './LexicalTablePluginHelpers';
|
|
38
|
+
export type {SerializedTableRowNode} from './LexicalTableRowNode';
|
|
39
|
+
export {
|
|
40
|
+
$createTableRowNode,
|
|
41
|
+
$isTableRowNode,
|
|
42
|
+
TableRowNode,
|
|
43
|
+
} from './LexicalTableRowNode';
|
|
44
|
+
export type {
|
|
45
|
+
TableMapType,
|
|
46
|
+
TableMapValueType,
|
|
47
|
+
TableSelection,
|
|
48
|
+
TableSelectionShape,
|
|
49
|
+
} from './LexicalTableSelection';
|
|
50
|
+
export {
|
|
51
|
+
$createTableSelection,
|
|
52
|
+
$createTableSelectionFrom,
|
|
53
|
+
$isTableSelection,
|
|
54
|
+
} from './LexicalTableSelection';
|
|
55
|
+
export type {HTMLTableElementWithWithTableSelectionState} from './LexicalTableSelectionHelpers';
|
|
56
|
+
export {
|
|
57
|
+
$findCellNode,
|
|
58
|
+
$findTableNode,
|
|
59
|
+
applyTableHandlers,
|
|
60
|
+
getDOMCellFromTarget,
|
|
61
|
+
getTableElement,
|
|
62
|
+
getTableObserverFromTableElement,
|
|
63
|
+
} from './LexicalTableSelectionHelpers';
|
|
64
|
+
export {
|
|
65
|
+
$computeTableMap,
|
|
66
|
+
$computeTableMapSkipCellCheck,
|
|
67
|
+
$createTableNodeWithDimensions,
|
|
68
|
+
$deleteTableColumn,
|
|
69
|
+
$deleteTableColumn__EXPERIMENTAL,
|
|
70
|
+
$deleteTableColumnAtSelection,
|
|
71
|
+
$deleteTableRow__EXPERIMENTAL,
|
|
72
|
+
$deleteTableRowAtSelection,
|
|
73
|
+
$getNodeTriplet,
|
|
74
|
+
$getTableCellNodeFromLexicalNode,
|
|
75
|
+
$getTableCellNodeRect,
|
|
76
|
+
$getTableColumnIndexFromTableCellNode,
|
|
77
|
+
$getTableNodeFromLexicalNodeOrThrow,
|
|
78
|
+
$getTableRowIndexFromTableCellNode,
|
|
79
|
+
$getTableRowNodeFromTableCellNodeOrThrow,
|
|
80
|
+
$insertTableColumn,
|
|
81
|
+
$insertTableColumn__EXPERIMENTAL,
|
|
82
|
+
$insertTableColumnAtSelection,
|
|
83
|
+
$insertTableRow,
|
|
84
|
+
$insertTableRow__EXPERIMENTAL,
|
|
85
|
+
$insertTableRowAtSelection,
|
|
86
|
+
$isSimpleTable,
|
|
87
|
+
$mergeCells,
|
|
88
|
+
$moveTableColumn,
|
|
89
|
+
$removeTableRowAtIndex,
|
|
90
|
+
$unmergeCell,
|
|
91
|
+
} from './LexicalTableUtils';
|
|
92
|
+
export {
|
|
93
|
+
TableImportExtension,
|
|
94
|
+
TableImportRules,
|
|
95
|
+
TableRowSchema,
|
|
96
|
+
TableSchema,
|
|
97
|
+
} from './TableImportExtension';
|
package/LexicalTable.prod.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension"),o=require("@lexical/clipboard");const r=/^(\d+(?:\.\d+)?)px$/,l={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class s extends t.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new s(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){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}static importDOM(){return{td:e=>({conversion:a,priority:0}),th:e=>({conversion:a,priority:0})}}static importJSON(e){return c().updateFromJSON(e)}updateFromJSON(e){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)}constructor(e=l.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());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),i(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;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")}return n}exportJSON(){return{...super.exportJSON(),...i(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=l.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==l.NO_STATUS}updateDOM(e){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}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function i(e){return"middle"===e||"bottom"===e}function a(e){const n=e,o=e.nodeName.toLowerCase();let s;r.test(n.style.width)&&(s=parseFloat(n.style.width));let a=l.NO_STATUS;if("th"===o){const e=n.getAttribute("scope");if("col"===e)a=l.COLUMN;else if("row"===e)a=l.ROW;else{const e=n.parentElement,o=t.isHTMLElement(e)&&"tr"===e.nodeName.toLowerCase()&&t.isHTMLElement(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),r=0===n.cellIndex;o&&(a|=l.ROW),r&&(a|=l.COLUMN),a===l.NO_STATUS&&(a=l.ROW)}}const u=c(a,n.colSpan,s);u.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(u.__backgroundColor=d);const h=n.style.verticalAlign;i(h)&&(u.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,C=f.includes("line-through"),p="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:e=>{const n=[];let o=null;const r=()=>{if(o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)if(t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)){if(t.$isTextNode(l)&&(m&&l.toggleFormat("bold"),C&&l.toggleFormat("strikethrough"),p&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(t.$createParagraphNode()),n},node:u}}function c(e=l.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new s(e,n,o))}function u(e){return e instanceof s}const d=t.createCommand("INSERT_TABLE_COMMAND");function h(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);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.`)}class g extends t.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new g(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:f,priority:0})}}static importJSON(e){return m().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function f(t){const n=t;let o;return r.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,u),node:m(o)}}function m(e){return t.$applyNodeReplacement(new g(e))}function C(e){return e instanceof g}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function N(e,n,o=!0){const r=Ue();for(let s=0;s<e;s++){const e=m();for(let r=0;r<n;r++){let n=l.NO_STATUS;"object"==typeof o?(0===s&&o.rows&&(n|=l.ROW),0===r&&o.columns&&(n|=l.COLUMN)):o&&(0===s&&(n|=l.ROW),0===r&&(n|=l.COLUMN));const i=c(n),a=t.$createParagraphNode();a.append(t.$createTextNode()),i.append(a),e.append(i)}r.append(e)}return r}function b(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,e=>Xe(e));if(Xe(n))return n;throw new Error("Expected table cell to be inside of table.")}function y(e,t){const n=w(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}p&&"InputEvent"in window&&!_&&new window.InputEvent("input");const $=(e,t)=>e===l.BOTH||e===t?t:l.NO_STATUS;function T(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||q(n)||h(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=B(o),[s,,i]=B(r),[,a,c]=L(i,s,l),{startRow:u}=c,{startRow:d}=a;return e?M(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):M(d<u?s:l,!1)}const R=T;function M(e,n=!0){const[,,o]=B(e),[r,s]=L(o,e,e),i=r[0].length,{startRow:a}=s;let u=null;if(n){const n=a+e.__rowSpan-1,s=r[n],d=m();for(let e=0;e<i;e++){const{cell:o,startRow:r}=s[e];if(r+o.__rowSpan-1<=n){const n=s[e].cell.__headerState,o=$(n,l.COLUMN);d.append(c(o).append(t.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const g=o.getChildAtIndex(n);C(g)||h(256),g.insertAfter(d),u=d}else{const e=a,n=r[e],s=m();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===e){const e=n[o].cell.__headerState,r=$(e,l.COLUMN);s.append(c(r).append(t.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(e);C(d)||h(257),d.insertBefore(s),u=s}return u}function E(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||q(n)||h(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=B(o),[s,,i]=B(r),[,a,c]=L(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return e?x(u+l.__colSpan>d+s.__colSpan?l:s,!0):x(d<u?s:l,!1)}const O=E;function x(e,n=!0,o=!0){const[,,r]=B(e),[s,i]=L(r,e,e),a=s.length,{startColumn:u}=i,d=n?u+e.__colSpan-1:u-1,g=r.getFirstChild();C(g)||h(120);let f=null;function m(e=l.NO_STATUS){const n=c(e).append(t.$createParagraphNode());return null===f&&(f=n),n}let p=g;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||h(121),p=e}const t=s[e],n=t[d<0?0:d].cell.__headerState,o=$(n,l.ROW);if(d<0){D(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&K(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function A(){const e=t.$getSelection();t.$isRangeSelection(e)||q(e)||h(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=B(n),[s]=B(o),[i,a,c]=L(l,r,s),{startRow:u}=a,{startRow:d}=c,g=d+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,m=i[g+1],p=l.getChildAtIndex(g+1);for(let e=g;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>g){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,g),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>g&&e===g){null===p&&h(122);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?D(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||h(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];K(e)}else{const e=i[u-1],{cell:t}=e[0];K(t)}}const v=A;function F(){const e=t.$getSelection();t.$isRangeSelection(e)||q(e)||h(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=B(n),[s]=B(o),[i,a,c]=L(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),C=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const p=i.length;for(let e=0;e<p;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(C,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>g?_[u+r.__colSpan]:_[g+s.__colSpan];if(void 0!==S){const{cell:e}=S;K(e)}else{const e=g<u?_[g-1]:_[u-1],{cell:t}=e;K(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}}const P=F;function K(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function D(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function I(e){if(0===e.length)return null;const n=w(e[0]),[o]=W(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const t of o)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!a.has(t)&&e.some(e=>e.is(n.cell))){a.add(t);const e=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,e),l=Math.max(l,e+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);k(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(t.$createParagraphNode()),h}function k(e){if(1!==e.getChildrenSize())return!1;const n=e.getFirstChildOrThrow();return!(!t.$isParagraphNode(n)||!n.isEmpty())}function H(e){const[n,o,r]=B(e),s=n.__colSpan,i=n.__rowSpan;if(1===s&&1===i)return;const[a,u]=L(r,n,n),{startColumn:d,startRow:g}=u,f=n.__headerState&l.COLUMN,m=Array.from({length:s},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&l.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+g][e].cell.__headerState;return n});if(s>1){for(let e=1;e<s;e++)n.insertAfter(c(m[e]|_[0]).append(t.$createParagraphNode()));n.setColSpan(1)}if(i>1){let e;for(let n=1;n<i;n++){const r=g+n,l=a[r];e=(e||o).getNextSibling(),C(e)||h(125);let i=null;for(let e=0;e<d;e++){const t=l[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=s-1;o>=0;o--)D(e,c(m[o]|_[n]).append(t.$createParagraphNode()));else for(let e=s-1;e>=0;e--)i.insertAfter(c(m[e]|_[n]).append(t.$createParagraphNode()))}n.setRowSpan(1)}}function L(e,t,n){const[o,r,l]=W(e,t,n);return null===r&&h(207),null===l&&h(208),[o,r,l]}function W(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||h(209);const a=s(e);for(let c=o.getFirstChild(),d=0;null!=c;c=c.getNextSibling()){for(u(c)||h(147);void 0!==a[d];)d++;const o={cell:c,startColumn:d,startRow:e},{__rowSpan:g,__colSpan:f}=c;for(let t=0;t<g&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[d+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function B(t){let n;if(t instanceof s)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,u);u(o)||h(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),u);u(o)||h(148),n=o}const o=n.getParent();C(o)||h(149);const r=o.getParent();return Xe(r)||h(210),[n,o,r]}function z(e,t,n){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);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Y(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!u(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function U(e){const[t,,n]=B(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function X(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,u);u(r)||h(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||h(239,n);const s=l.getParent();return Xe(s)||h(240,n),[o,r,l,s]});return l.is(c)||h(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class G{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=t.$getNodeByKey(this.tableKey),n=t.$getNodeByKey(this.anchor.key),o=t.$getNodeByKey(this.focus.key);return null!==e&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return q(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){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}clone(){return new G(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(u).forEach(e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=t.TEXT_TYPE_TO_FORMAT[e];return 0!==(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||h(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=X(this),n=U(e);null===n&&h(153);const o=U(t);null===o&&h(155);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);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=X(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&h(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&h(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=L(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:g}=z(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||h(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||V(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>u(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function q(e){return e instanceof G}function J(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new G("root",e,n)}function j(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=q(r)?r.clone():J();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function V(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function Q(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Xe(o)||h(231,e);const r=oe(o,n.getElementByKey(e));return null===r&&h(232,e),{tableElement:r,tableNode:o}}class Z{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class ee{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},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()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Q(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=Ce(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Ce(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const n=this.editor;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();const{tableNode:o,tableElement:r}=this.$lookup();pe(n,Ce(o,r),null),e&&null!==t.$getSelection()&&(t.$setSelection(null),n.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&h(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),pe(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,s=e.y;if(this.focusCell=e,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=De(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=i;if(null===e&&n&&(e=r.getCellNodeFromCords(l,s,this.table)),null!==e){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=j(r,n,e),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),pe(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&h(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&h(235),e}$setAnchorCellForSelection(e){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;const{tableNode:t}=this.$lookup(),n=De(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=j(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();q(n)||h(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(u);s.length>0||h(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach(t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)}),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Xe(n))throw new Error("Expected TableNode.");const o=t.$getSelection();q(o)||h(253);const r=o.getNodes().filter(u),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(t.$isRootNode(o)&&o.isEmpty()&&e.dispatchCommand(t.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(e=>{if(t.$isElementNode(e)){const n=t.$createParagraphNode(),o=t.$createTextNode();n.append(o),e.append(n),e.getChildren().forEach(e=>{e!==n&&e.remove()})}}),pe(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const te="__lexicalTableSelection";function ne(e){return t.isHTMLElement(e)&&"TABLE"===e.nodeName}function oe(e,t){if(!t)return t;const n=ne(t)?t:t.querySelector("table");return ne(n)||h(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function re(e){return e._window}function le(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;u(n)&&(o=n)}return null}const se=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],ie=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],ae=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function ce(e,n){return e.registerRootListener(o=>{if(null===o)return;const r=e._window;if(null===r)return;const l=r=>{const l=r.target;if(0!==r.button||!t.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=fe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&te in n&&n[te])return{cellElement:t,tableElement:n,tableObserver:n[te]};n=n.parentNode}return null}(l);e.update(()=>{if(q(t.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(e,n,o,r,l,s){const i=e._window;if(!i)return;const a=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});const o=()=>{l.isSelecting=!1,i.removeEventListener("pointerup",o),i.removeEventListener("pointermove",a)},a=n=>{if(!(e=>!(1&~e.buttons))(n)&&l.isSelecting)return l.isSelecting=!1,i.removeEventListener("pointerup",o),void i.removeEventListener("pointermove",a);if(!t.isDOMNode(n.target))return;let c=null;const u=!(S||r.contains(n.target));if(u)c=me(r,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(c=me(r,e),c)break;if(c){const n=c;null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&c.elem===l.focusCell.elem||(s.setNextFocus({focusCell:c,override:u,tableKey:l.tableNodeKey}),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}};i.addEventListener("pointerup",o,l.listenerOptions),i.addEventListener("pointermove",a,l.listenerOptions)};l.pointerType=n.pointerType;const c=t.$getNodeByKeyOrThrow(l.tableNodeKey),u=t.$getPreviousSelection();if(S&&n.shiftKey&&$e(u,c)&&(t.$isRangeSelection(u)||q(u))){const e=u.anchor.getNode(),t=le(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Ke(l,t)),l.$setFocusCellForSelection(o),ve(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(e,r,i,l,o,n)})};return r.addEventListener("pointerdown",l),()=>{r.removeEventListener("pointerdown",l)}})}function ue(n,r,l,s,i){const a=l.getRootElement(),c=re(l);null!==a&&null!==c||h(246);const d=new ee(l,n.getKey()),g=oe(n,r);!function(e,t){null!==ge(e)&&h(205);e[te]=t}(g,d),d.listenersToRemove.add(()=>function(e,t){ge(e)===t&&delete e[te]}(g,d));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==fe(e.target)&&e.preventDefault()}};g.addEventListener("mousedown",f,d.listenerOptions),d.listenersToRemove.add(()=>{g.removeEventListener("mousedown",f)});for(const[e,o]of se)d.listenersToRemove.add(l.registerCommand(e,e=>Ae(l,e,o,n,d,i),t.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,e=>{const o=t.$getSelection();if(q(o)){const t=le(n,o.focus.getNode());if(null!==t)return ve(e),t.selectEnd(),!0}return!1},t.COMMAND_PRIORITY_HIGH));const m=o=>()=>{const r=t.$getSelection();if(!$e(r,n))return!1;if(q(r))return d.$clearText(),!0;if(t.$isRangeSelection(r)){if(!u(le(n,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=n.isParentOf(l),a=n.isParentOf(s);if(i&&!a||a&&!i)return d.$clearText(),!0;const c=e.$findMatchingParent(r.anchor.getNode(),e=>t.$isElementNode(e)),h=c&&e.$findMatchingParent(c,e=>t.$isElementNode(e)&&u(e.getParent()));if(!t.$isElementNode(h)||!t.$isElementNode(c))return!1;if(o===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of ie)d.listenersToRemove.add(l.registerCommand(e,m(e),t.COMMAND_PRIORITY_HIGH));const p=e=>{const o=t.$getSelection();if(!q(o)&&!t.$isRangeSelection(o))return!1;const r=n.isParentOf(o.anchor.getNode());if(r!==n.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=o[t];return n[o[e].isBefore(o[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!$e(o,n)&&(!!q(o)&&(e&&(e.preventDefault(),e.stopPropagation()),d.$clearText(),!0))};for(const e of ae)d.listenersToRemove.add(l.registerCommand(e,p,t.COMMAND_PRIORITY_HIGH));return d.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,n=>{const r=t.$getSelection();if(r){if(!q(r)&&!t.$isRangeSelection(r))return!1;o.copyToClipboard(l,e.objectKlassEquals(n,ClipboardEvent)?n:null,o.$getClipboardDataFromSelection(r));const s=p(n);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,o=>{const r=t.$getSelection();if(!$e(r,n))return!1;if(q(r))return d.$formatCells(o),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),e=>u(e));if(!u(t))return!1}return!1},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,e=>{const o=t.$getSelection();if(!q(o)||!$e(o,n))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!u(r)||!u(l))return!1;if(function(e,t){if(q(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=L(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,n))return n.setFormat(e),!0;const[s,i,a]=L(n,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=c;n++)for(let o=g;o<=d;o++){const r=s[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,o=>{const r=t.$getSelection();if(!$e(r,n))return!1;if(q(r))return d.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),e=>u(e));if(!u(s))return!1;if("string"==typeof o){const e=Pe(l,r,n);if(e)return Fe(e,n,[t.$createTextNode(o)]),!0}}return!1},t.COMMAND_PRIORITY_HIGH)),s&&d.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,o=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!$e(r,n))return!1;const l=Ee(r.anchor.getNode());return!(null===l||!n.is(Oe(l)))&&(ve(o),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&h(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Xe);null===a&&h(248);"next"===o?a.selectNext():a.selectPrevious()}(l,o.shiftKey?"previous":"next"),!0)},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,e=>n.isSelected(),t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!$e(e,n))return!1;const o=Pe(l,e,n);return!!o&&(Fe(o,n),!0)},t.COMMAND_PRIORITY_HIGH)),d}function de(n,o){const r=t.$getSelection(),l=t.$getPreviousSelection(),s=n.getAndClearNextFocus();if(null!==s){const{tableKey:e,focusCell:t}=s,o=n.observers.get(e);o||h(335,e);const[l]=o;if(q(r)&&r.tableKey===l.tableNodeKey)return(t.x!==l.focusX||t.y!==l.focusY)&&(l.$setFocusCellForSelection(t),!0);if(null!==l.anchorCell&&null!==l.anchorCellNodeKey&&t.elem!==l.anchorCell.elem&&null!==l.tableSelection)return l.$setFocusCellForSelection(t,!0),!0}const i=n.getAndClearShouldCheckSelectionForTable();if(i&&t.$isRangeSelection(l)&&t.$isRangeSelection(r)&&r.isCollapsed()){const n=t.$getNodeByKeyOrThrow(i),o=r.anchor.getNode(),l=n.getFirstChild(),s=Ee(o);if(null!==s&&C(l)){const t=l.getFirstChild();if(u(t)&&n.is(e.$findMatchingParent(s,e=>e.is(n)||e.is(t))))return t.selectStart(),!0}}q(r)&&function(e,n){const o=re(e),r=t.$getPreviousSelection();if(!n.is(r))return;const l=t.$getNodeByKeyOrThrow(n.tableKey),s=t.getDOMSelection(o);if(s&&s.anchorNode&&s.focusNode){const o=t.$getNearestNodeFromDOMNode(s.focusNode),r=o&&!l.isParentOf(o),i=t.$getNearestNodeFromDOMNode(s.anchorNode),a=i&&l.isParentOf(i);if(r&&a&&s.rangeCount>0){const o=t.$createRangeSelectionFromDom(s,e);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),t.$setSelection(o))}}}(o,r),t.$isRangeSelection(r)&&function(e,n){const o=t.$getPreviousSelection(),{anchor:r,focus:l}=e,s=r.getNode(),i=l.getNode(),a=Ee(s),c=Ee(i),u=a?Oe(a):null,d=c?Oe(c):null,g=e.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),C=u&&(!d||d.isParentOf(u));if(m){const n=e.clone(),[o]=L(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(g?r.getKey():l.getKey(),g?0:l.getChildrenSize(),"element"),t.$setSelection(n)}else if(C){const n=e.clone(),[o]=L(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(g?l.getKey():r.getKey(),g?l.getChildrenSize():0,"element"),t.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||h(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Ke(l,a)),l.$setFocusCellForSelection(Ke(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&t.$isRangeSelection(o)&&o.isCollapsed()){const e=Ee(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Ke(l,e)),l.$setFocusCellForSelection(Ke(l,c),!0),l.pointerType=null)}}}(r,n);const a=Array.from(n.observers.entries()).map(([e,[n]])=>({tableNode:t.$getNodeByKeyOrThrow(e),tableObserver:n}));for(const{tableNode:e,tableObserver:t}of a)he(o,e,t);return!1}function he(e,n,o){const r=t.$getSelection(),l=t.$getPreviousSelection();r&&!r.is(l)&&(q(r)||q(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(q(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!q(r)&&q(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),_e(t.table,t=>{const n=t.elem;t.highlighted=!1,Me(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),_e(t.table,t=>{t.highlighted=!0,Re(e,t)})}(e,o)}function ge(e){return e[te]||null}function fe(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function me(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function Ce(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=oe(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function pe(e,t,n){const o=new Set(n?n.getNodes():[]);_e(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Re(e,t)):(t.highlighted=!1,Me(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function _e(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=t.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:e})}}}const Se=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Te(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Te(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Te(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Te(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function be([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function we(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&h(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&h(250,n,String(s)),i}function ye(e,t,n,o,r){const l=z(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=Ne(e,t);return null===n&&h(249,t.cell.getKey()),n}(l,n),[g,f]=be(d);let m=l[g],C=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?C+="maxRow"===f?1:i:"up"===r&&(C-="minRow"===f?1:c);const p=t[C];if(void 0===p)return!1;const _=p[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=z(e,t,n),r=Ne(o,t);if(r)return[we(e,o,r),we(e,o,be(r))];const l=Ne(o,n);if(l)return[we(e,o,be(l)),we(e,o,l)];const s=["minColumn","minRow"];return[we(e,o,s),we(e,o,be(s))]}(t,n,_),b=Ke(e,S.cell),w=Ke(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function $e(e,n){if(t.$isRangeSelection(e)||q(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function Te(e,t){t?e.selectStart():e.selectEnd()}function Re(n,o){const r=o.elem,l=n._config.theme;u(t.$getNearestNodeFromDOMNode(r))||h(131),e.addClassNamesToElement(r,l.tableCellSelected)}function Me(n,o){const r=o.elem;u(t.$getNearestNodeFromDOMNode(r))||h(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function Ee(t){const n=e.$findMatchingParent(t,u);return u(n)?n:null}function Oe(t){const n=e.$findMatchingParent(t,Xe);return Xe(n)?n:null}function xe(n,o,r,l,s,i,a){const c=t.$caretFromPoint(r.focus,s?"previous":"next");if(t.$isExtendableTextPointCaret(c))return!1;let d=c;for(const e of t.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;d=e}const h=d.getParentAtCaret();if(!u(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(u(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!C(o))break}return null}(t.$getSiblingCaret(g,d.direction)),m=e.$findMatchingParent(g,Xe);if(!m||!m.is(i))return!1;const p=n.getElementByKey(g.getKey()),_=fe(p);if(!p||!_)return!1;const S=ze(n,m);if(a.table=S,f)if("extend"===l){const e=fe(n.getElementByKey(f.origin.getKey()));if(!e)return!1;a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(e,!0)}else{const e=t.$normalizeCaret(f);t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}else if("extend"===l)a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(_,!0);else{const e=function(e){const n=t.$getAdjacentChildCaret(e);return t.$isChildCaret(n)?t.$normalizeCaret(n):e}(t.$getSiblingCaret(m,c.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return ve(o),!0}function Ae(n,o,r,l,s,i){if(("up"===r||"down"===r)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(n))return!1;const a=t.$getSelection();if(!$e(a,l)){if(t.$isRangeSelection(a)){if("backward"===r){if(a.focus.offset>0)return!1;const e=function(e){for(let n=e,o=e;null!==o;n=o,o=o.getParent())if(t.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(a.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Xe(n)&&(ve(o),o.shiftKey?a.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=a.focus.getNode();if(!a.isCollapsed()&&("up"===r&&!a.isBackward()||"down"===r&&a.isBackward())){let s=e.$findMatchingParent(n,e=>Xe(e));if(u(s)&&(s=e.$findMatchingParent(s,Xe)),s!==l)return!1;if(!s)return!1;const i="down"===r?s.getNextSibling():s.getPreviousSibling();if(!i)return!1;let c=0;"up"===r&&t.$isElementNode(i)&&(c=i.getChildrenSize());let d=i;if("up"===r&&t.$isElementNode(i)){const e=i.getLastChild();d=e||i,c=t.$isTextNode(d)?d.getTextContentSize():0}const h=a.clone();return h.focus.set(d.getKey(),c,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),ve(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?a.getNodes()[a.getNodes().length-1]:a.getNodes()[0];if(e){if(null!==le(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=B(e),[o]=B(t),r=l.getCordsFromCellNode(n,s.table),i=l.getCordsFromCellNode(o,s.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,s.table),c=l.getDOMCellFromCordsOrThrow(i.x,i.y,s.table);return s.$setAnchorCellForSelection(a),s.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,e=>t.$isElementNode(e)&&!e.isInline());if(u(l)&&(l=e.$findMatchingParent(l,Xe)),!l)return!1;const i="down"===r?l.getNextSibling():l.getPreviousSibling();if(Xe(i)&&s.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[l]=B(e),[s]=B(n),c=a.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),ve(o),t.$setSelection(c),!0}}}}return"down"===r&&Le(n)&&i.setShouldCheckSelectionForTable(l.getKey()),!1}if(t.$isRangeSelection(a)){if("backward"===r||"forward"===r){return xe(n,o,a,o.shiftKey?"extend":"move","backward"===r,l,s)}if(a.isCollapsed()){const{anchor:c,focus:d}=a,h=e.$findMatchingParent(c.getNode(),u),g=e.$findMatchingParent(d.getNode(),u);if(!u(h)||!h.is(g))return!1;const f=Oe(h);if(f!==l&&null!=f){const e=oe(f,n.getElementByKey(f.getKey()));if(null!=e)return s.table=Ce(f,e),Ae(n,o,r,f,s,i)}const m=n.getElementByKey(h.__key),C=n.getElementByKey(c.key);if(null==C||null==m)return!1;let p;if("element"===c.type)p=C.getBoundingClientRect();else{const e=t.getDOMSelection(re(n));if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const _="up"===r?h.getFirstChild():h.getLastChild();if(null==_)return!1;const S=n.getElementByKey(_.__key);if(null==S)return!1;const N=S.getBoundingClientRect();if("up"===r?N.top>p.top-p.height:p.bottom+p.height>N.bottom){ve(o);const e=l.getCordsFromCellNode(h,s.table);if(!o.shiftKey)return Se(s,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,s.table);s.$setAnchorCellForSelection(t),s.$setFocusCellForSelection(t,!0)}return!0}}}else if(q(a)){const{anchor:t,focus:i,tableKey:c}=a;if(c!==l.getKey())return!1;const d=e.$findMatchingParent(t.getNode(),u),g=e.$findMatchingParent(i.getNode(),u),[f]=a.getNodes();Xe(f)||h(251);const m=oe(f,n.getElementByKey(f.getKey()));if(!u(d)||!u(g)||!Xe(f)||null==m)return!1;s.$updateTableTableSelection(a);const C=Ce(f,m),p=l.getCordsFromCellNode(d,C),_=l.getDOMCellFromCordsOrThrow(p.x,p.y,C);if(s.$setAnchorCellForSelection(_),ve(o),o.shiftKey){const[e,t,n]=L(l,d,g);return ye(s,e,t,n,r)}return g.selectEnd(),!0}return!1}function ve(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Fe(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Pe(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(re(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),c=oe(r,n.getElementByKey(r.getKey()));if(!i||!a||!c||!a.contains(i)||c.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),e=>u(e));if(!d)return;const h=e.$findMatchingParent(d,e=>Xe(e));if(!Xe(h)||!h.is(r))return;const[g,f]=L(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:p,startColumn:_}=f,S=p===m.startRow&&_===m.startColumn,N=p===C.startRow&&_===C.startColumn;return S?"first":N?"last":void 0}function Ke(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function De(e,n,o){return le(e,t.$getNearestNodeFromDOMNode(n,o))}function Ie(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function ke(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const He=new WeakSet;function Le(e=t.$getEditor()){return He.has(e)}function We(e,t){t?He.add(e):He.delete(e)}class Be extends t.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Be(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Ye,priority:1})}}static importJSON(e){return Ue().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=ne(e)?e:e.querySelector("table");return ne(t)||h(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&t.setDOMStyleFromCSS(r.style,this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),this.updateTableElement(null,r,n),Le(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.overflowX="auto",t.appendChild(r),this.updateTableWrapper(null,t,r,n),t}return r}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(n,o,r){this.__style!==(n?n.__style:"")&&t.setDOMStyleFromCSS(o.style,this.__style,n?n.__style:""),this.__rowStriping!==(!!n&&n.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(o,r,this.__rowStriping);const l=n?n.getColumnCount():0,s=n?n.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Ie(o,this.getColumnCount(),this.getColWidths()),ke(o,r,this.getFormatType())}updateDOM(t,n,o){const r=oe(this,n);return n===r===Le()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Ie(oe(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!ne(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!ne(o))return null;ke(o,t._config,this.getFormatType());const[r]=W(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:!ne(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=De(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return u(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{u(e)&&(t+=e.getColSpan())}),t}}function ze(e,t){const n=e.getElementByKey(t.getKey());return null===n&&h(230),Ce(t,n)}function Ye(t){const n=Ue();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);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!r.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function Ue(){return t.$applyNodeReplacement(new Be)}function Xe(e){return e instanceof Be}function Ge(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function qe(t){Xe(t.getParent())?e.$unwrapAndFilterDescendants(t,u):t.remove()}function Je(n){e.$unwrapAndFilterDescendants(n,C);const[o]=W(n,null,null),r=o.reduce((e,t)=>Math.max(e,t.length),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||h(254,n.constructor.name,n.getType());const s=o[e].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let e=s;e<r;++e){const e=c();e.append(t.$createParagraphNode()),n.append(e)}}const s=n.getColWidths(),i=n.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}n.setColWidths(e)}}function je(n){if(n.detail<3||!t.isDOMNode(n.target))return!1;const o=t.$getNearestNodeFromDOMNode(n.target);if(null===o)return!1;const r=e.$findMatchingParent(o,e=>t.$isElementNode(e)&&!e.isInline());if(null===r)return!1;return!!u(r.getParent())&&(r.select(0),!0)}function Ve(){const e=t.$getSelection();if(!t.$isRangeSelection(e))return!1;const n=Oe(e.anchor.getNode());if(null===n)return!1;const o=t.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=W(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=j(n,l.cell,i.cell);return t.$setSelection(a),!0}function Qe(t){return t.registerNodeTransform(s,t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=B(t),[o]=L(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||h(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||h(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],a=l.cell;if(l.startRow===t&&l.startColumn===r)n=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){u(a)||h(176);const t=c(a.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Ze(n,o=!0){const r=new Z,l=(e,t,l)=>{const s=oe(e,l),i=ue(e,s,n,o,r);r.observers.set(t,[i,s])};return e.mergeRegister(ce(n,r),n.registerCommand(t.SELECTION_CHANGE_COMMAND,()=>de(r,n),t.COMMAND_PRIORITY_HIGH),n.registerMutationListener(Be,e=>{n.getEditorState().read(()=>{for(const[t,n]of e){const e=r.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:o}=Q(t);void 0===e?l(n,t,o):o!==e[1]&&(e[0].removeListeners(),r.observers.delete(t),l(n,t,o))}else"destroyed"===n&&void 0!==e&&(e[0].removeListeners(),r.observers.delete(t))}},{editor:n})},{skipInitialization:!1}),()=>{for(const[,[e]]of r.observers)e.removeListeners()})}function et(o,r){o.hasNodes([Be])||h(255);const{hasNestedTables:l=n.signal(!1)}=r??{};return e.mergeRegister(o.registerCommand(d,n=>function({rows:n,columns:o,includeHeaders:r},l){const s=t.$getSelection()||t.$getPreviousSelection();if(!s||!t.$isRangeSelection(s))return!1;if(!l&&Oe(s.anchor.getNode()))return!1;const i=N(Number(n),Number(o),r);e.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return t.$isTextNode(a)&&a.select(),!0}(n,l.peek()),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n,r)=>o===r&&function(n,o){const{nodes:r,selection:l}=n;if(!r.some(t=>Xe(t)||e.$dfs(t).some(e=>Xe(e.node))))return!1;const s=q(l),i=t.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>u(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>u(e))||s))return!1;if(1===r.length&&Xe(r[0]))return function(n,o){const r=o.getStartEndPoints(),l=q(o);if(null===r)return!1;const[s,i]=r,[a,c,d]=B(s),h=e.$findMatchingParent(i.getNode(),e=>u(e));if(!(u(a)&&u(h)&&C(c)&&Xe(d)))return!1;const[g,f,m]=L(d,a,h),[p]=W(n,null,null),_=g.length,S=_>0?g[0].length:0;let N=f.startRow,b=f.startColumn,w=p.length,y=w>0?p[0].length:0;if(l){const e=z(g,f,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;N=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let $=!1;const T=Math.min(_,N+w)-1,R=Math.min(S,b+y)-1,E=new Set;for(let e=N;e<=T;e++)for(let t=b;t<=R;t++){const n=g[e][t];E.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(H(n.cell),E.add(n.cell.getKey()),$=!0))}let[O]=W(d.getWritable(),null,null);const A=w-_+N;for(let e=0;e<A;e++){M(O[_-1][0].cell)}const v=y-S+b;for(let e=0;e<v;e++){x(O[0][S-1].cell,!0,!1)}[O]=W(d.getWritable(),null,null);for(let e=N;e<N+w;e++)for(let n=b;n<b+y;n++){const o=e-N,r=n-b,l=p[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const t=[],o=Math.min(e+s.__rowSpan,N+w)-1,r=Math.min(n+s.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=n;e<=r;e++){const n=O[l][e];t.push(n.cell)}I(t),$=!0}const{cell:i}=O[e][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),i.append(e)}else i.append(e)}),c.forEach(e=>e.remove())}if(l&&$){const[e]=W(d.getWritable(),null,null);e[f.startRow][f.startColumn].cell.selectEnd()}return!0}(r[0],l);if(i&&o.peek()&&!function(e){if(q(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(t.$isRangeSelection(e)&&u(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(l))return!1;return!0}(n,l),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECT_ALL_COMMAND,Ve,t.COMMAND_PRIORITY_LOW),o.registerCommand(t.CLICK_COMMAND,je,t.COMMAND_PRIORITY_EDITOR),o.registerNodeTransform(Be,Je),o.registerNodeTransform(g,qe),o.registerNodeTransform(s,Ge))}const tt=t.defineExtension({build:(e,t,o)=>n.namedSignals(t),config:t.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[Be,g,s],register(t,o,r){const l=r.getOutput();return e.mergeRegister(n.effect(()=>{const e=l.hasHorizontalScroll.value;Le(t)!==e&&(We(t,e),t.registerNodeTransform(Be,()=>{})())}),et(t,l),n.effect(()=>Ze(t,l.hasTabHandler.value)),n.effect(()=>l.hasCellMerge.value?void 0:Qe(t)),n.effect(()=>l.hasCellBackgroundColor.value?void 0:t.registerNodeTransform(s,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});exports.$computeTableMap=L,exports.$computeTableMapSkipCellCheck=W,exports.$createTableCellNode=c,exports.$createTableNode=Ue,exports.$createTableNodeWithDimensions=N,exports.$createTableRowNode=m,exports.$createTableSelection=J,exports.$createTableSelectionFrom=j,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=F,exports.$deleteTableColumn__EXPERIMENTAL=P,exports.$deleteTableRowAtSelection=A,exports.$deleteTableRow__EXPERIMENTAL=v,exports.$findCellNode=Ee,exports.$findTableNode=Oe,exports.$getElementForTableNode=ze,exports.$getNodeTriplet=B,exports.$getTableAndElementByKey=Q,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>u(e));return u(n)?n:null},exports.$getTableCellNodeRect=U,exports.$getTableColumnIndexFromTableCellNode=function(e){return b(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=b(e);return w(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=b,exports.$insertTableColumn=function(e,n,o=!0,r,s){const i=e.getChildren(),a=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<r;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const r=e[n];u(r)||h(12);const{left:i,right:d}=y(r,s);let g=l.NO_STATUS;(i&&i.hasHeaderState(l.ROW)||d&&d.hasHeaderState(l.ROW))&&(g|=l.ROW);const f=c(g);f.append(t.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),e},exports.$insertTableColumnAtSelection=E,exports.$insertTableColumn__EXPERIMENTAL=O,exports.$insertTableRow=function(e,n,o=!0,r,s){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let e=0;e<r;e++){const e=a.getChildren(),n=e.length,r=m();for(let o=0;o<n;o++){const n=e[o];u(n)||h(12);const{above:i,below:a}=y(n,s);let d=l.NO_STATUS;const g=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(l.COLUMN)||a&&a.hasHeaderState(l.COLUMN))&&(d|=l.COLUMN);const f=c(d,1,g);f.append(t.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return e},exports.$insertTableRowAtSelection=T,exports.$insertTableRow__EXPERIMENTAL=R,exports.$isScrollableTablesActive=Le,exports.$isSimpleTable=Y,exports.$isTableCellNode=u,exports.$isTableNode=Xe,exports.$isTableRowNode=C,exports.$isTableSelection=q,exports.$mergeCells=I,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Y(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const n=t.$getSelection();t.$isRangeSelection(n)||q(n)||h(188);const o=n.anchor.getNode(),r=e.$findMatchingParent(o,u);return u(r)||h(148),H(r)},exports.INSERT_TABLE_COMMAND=d,exports.TableCellHeaderStates=l,exports.TableCellNode=s,exports.TableExtension=tt,exports.TableNode=Be,exports.TableObserver=ee,exports.TableRowNode=g,exports.applyTableHandlers=ue,exports.getDOMCellFromTarget=fe,exports.getTableElement=oe,exports.getTableObserverFromTableElement=ge,exports.registerTableCellUnmergeTransform=Qe,exports.registerTablePlugin=et,exports.registerTableSelectionObserver=Ze,exports.setScrollableTablesActive=We;
|