@lexical/table 0.13.1 → 0.14.1
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.esm.js +2433 -0
- package/LexicalTable.dev.js +56 -12
- package/LexicalTable.esm.js +45 -0
- package/LexicalTable.js +1 -1
- package/LexicalTable.js.flow +1 -1
- package/LexicalTable.prod.esm.js +7 -0
- package/LexicalTable.prod.js +71 -70
- package/LexicalTableNode.d.ts +0 -1
- package/LexicalTableRowNode.d.ts +3 -3
- package/README.md +2 -0
- package/package.json +6 -4
package/LexicalTable.dev.js
CHANGED
@@ -222,6 +222,12 @@ function convertTableCellNodeElement(domNode) {
|
|
222
222
|
tableCellNode.__backgroundColor = backgroundColor;
|
223
223
|
}
|
224
224
|
return {
|
225
|
+
after: childLexicalNodes => {
|
226
|
+
if (childLexicalNodes.length === 0) {
|
227
|
+
childLexicalNodes.push(lexical.$createParagraphNode());
|
228
|
+
}
|
229
|
+
return childLexicalNodes;
|
230
|
+
},
|
225
231
|
forChild: (lexicalNode, parentLexicalNode) => {
|
226
232
|
if ($isTableCellNode(parentLexicalNode) && !lexical.$isElementNode(lexicalNode)) {
|
227
233
|
const paragraphNode = lexical.$createParagraphNode();
|
@@ -287,6 +293,9 @@ class TableRowNode extends lexical.ElementNode {
|
|
287
293
|
exportJSON() {
|
288
294
|
return {
|
289
295
|
...super.exportJSON(),
|
296
|
+
...(this.getHeight() && {
|
297
|
+
height: this.getHeight()
|
298
|
+
}),
|
290
299
|
type: 'tablerow',
|
291
300
|
version: 1
|
292
301
|
};
|
@@ -361,11 +370,19 @@ function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders =
|
|
361
370
|
for (let iColumn = 0; iColumn < columnCount; iColumn++) {
|
362
371
|
let headerState = TableCellHeaderStates.NO_STATUS;
|
363
372
|
if (typeof includeHeaders === 'object') {
|
364
|
-
if (iRow === 0 && includeHeaders.rows)
|
365
|
-
|
373
|
+
if (iRow === 0 && includeHeaders.rows) {
|
374
|
+
headerState |= TableCellHeaderStates.ROW;
|
375
|
+
}
|
376
|
+
if (iColumn === 0 && includeHeaders.columns) {
|
377
|
+
headerState |= TableCellHeaderStates.COLUMN;
|
378
|
+
}
|
366
379
|
} else if (includeHeaders) {
|
367
|
-
if (iRow === 0)
|
368
|
-
|
380
|
+
if (iRow === 0) {
|
381
|
+
headerState |= TableCellHeaderStates.ROW;
|
382
|
+
}
|
383
|
+
if (iColumn === 0) {
|
384
|
+
headerState |= TableCellHeaderStates.COLUMN;
|
385
|
+
}
|
369
386
|
}
|
370
387
|
const tableCellNode = $createTableCellNode(headerState);
|
371
388
|
const paragraphNode = lexical.$createParagraphNode();
|
@@ -1692,6 +1709,36 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1692
1709
|
}
|
1693
1710
|
return false;
|
1694
1711
|
}, lexical.COMMAND_PRIORITY_CRITICAL));
|
1712
|
+
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, formatType => {
|
1713
|
+
const selection = lexical.$getSelection();
|
1714
|
+
if (!$isTableSelection(selection) || !$isSelectionInTable(selection, tableNode)) {
|
1715
|
+
return false;
|
1716
|
+
}
|
1717
|
+
const anchorNode = selection.anchor.getNode();
|
1718
|
+
const focusNode = selection.focus.getNode();
|
1719
|
+
if (!$isTableCellNode(anchorNode) || !$isTableCellNode(focusNode)) {
|
1720
|
+
return false;
|
1721
|
+
}
|
1722
|
+
const [tableMap, anchorCell, focusCell] = $computeTableMap(tableNode, anchorNode, focusNode);
|
1723
|
+
const maxRow = Math.max(anchorCell.startRow, focusCell.startRow);
|
1724
|
+
const maxColumn = Math.max(anchorCell.startColumn, focusCell.startColumn);
|
1725
|
+
const minRow = Math.min(anchorCell.startRow, focusCell.startRow);
|
1726
|
+
const minColumn = Math.min(anchorCell.startColumn, focusCell.startColumn);
|
1727
|
+
for (let i = minRow; i <= maxRow; i++) {
|
1728
|
+
for (let j = minColumn; j <= maxColumn; j++) {
|
1729
|
+
const cell = tableMap[i][j].cell;
|
1730
|
+
cell.setFormat(formatType);
|
1731
|
+
const cellChildren = cell.getChildren();
|
1732
|
+
for (let k = 0; k < cellChildren.length; k++) {
|
1733
|
+
const child = cellChildren[k];
|
1734
|
+
if (lexical.$isElementNode(child) && !child.isInline()) {
|
1735
|
+
child.setFormat(formatType);
|
1736
|
+
}
|
1737
|
+
}
|
1738
|
+
}
|
1739
|
+
}
|
1740
|
+
return true;
|
1741
|
+
}, lexical.COMMAND_PRIORITY_CRITICAL));
|
1695
1742
|
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, payload => {
|
1696
1743
|
const selection = lexical.$getSelection();
|
1697
1744
|
if (!$isSelectionInTable(selection, tableNode)) {
|
@@ -1828,8 +1875,8 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1828
1875
|
// as in that case we'll leave selection resolving to that table
|
1829
1876
|
const anchorCellNode = $findCellNode(anchorNode);
|
1830
1877
|
const focusCellNode = $findCellNode(focusNode);
|
1831
|
-
const isAnchorInside = anchorCellNode && tableNode.is($findTableNode(anchorCellNode));
|
1832
|
-
const isFocusInside = focusCellNode && tableNode.is($findTableNode(focusCellNode));
|
1878
|
+
const isAnchorInside = !!(anchorCellNode && tableNode.is($findTableNode(anchorCellNode)));
|
1879
|
+
const isFocusInside = !!(focusCellNode && tableNode.is($findTableNode(focusCellNode)));
|
1833
1880
|
const isPartialyWithinTable = isAnchorInside !== isFocusInside;
|
1834
1881
|
const isWithinTable = isAnchorInside && isFocusInside;
|
1835
1882
|
const isBackward = selection.isBackward();
|
@@ -2285,11 +2332,6 @@ class TableNode extends lexical.ElementNode {
|
|
2285
2332
|
}
|
2286
2333
|
};
|
2287
2334
|
}
|
2288
|
-
|
2289
|
-
// TODO 0.10 deprecate
|
2290
|
-
canExtractContents() {
|
2291
|
-
return false;
|
2292
|
-
}
|
2293
2335
|
canBeEmpty() {
|
2294
2336
|
return false;
|
2295
2337
|
}
|
@@ -2307,7 +2349,9 @@ class TableNode extends lexical.ElementNode {
|
|
2307
2349
|
continue;
|
2308
2350
|
}
|
2309
2351
|
const x = row.findIndex(cell => {
|
2310
|
-
if (!cell)
|
2352
|
+
if (!cell) {
|
2353
|
+
return;
|
2354
|
+
}
|
2311
2355
|
const {
|
2312
2356
|
elem
|
2313
2357
|
} = cell;
|
@@ -0,0 +1,45 @@
|
|
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
|
+
import * as modDev from './LexicalTable.dev.esm.js';
|
8
|
+
import * as modProd from './LexicalTable.prod.esm.js';
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
10
|
+
export const $computeTableMap = mod.$computeTableMap;
|
11
|
+
export const $createTableCellNode = mod.$createTableCellNode;
|
12
|
+
export const $createTableNode = mod.$createTableNode;
|
13
|
+
export const $createTableNodeWithDimensions = mod.$createTableNodeWithDimensions;
|
14
|
+
export const $createTableRowNode = mod.$createTableRowNode;
|
15
|
+
export const $createTableSelection = mod.$createTableSelection;
|
16
|
+
export const $deleteTableColumn = mod.$deleteTableColumn;
|
17
|
+
export const $deleteTableColumn__EXPERIMENTAL = mod.$deleteTableColumn__EXPERIMENTAL;
|
18
|
+
export const $deleteTableRow__EXPERIMENTAL = mod.$deleteTableRow__EXPERIMENTAL;
|
19
|
+
export const $getElementForTableNode = mod.$getElementForTableNode;
|
20
|
+
export const $getNodeTriplet = mod.$getNodeTriplet;
|
21
|
+
export const $getTableCellNodeFromLexicalNode = mod.$getTableCellNodeFromLexicalNode;
|
22
|
+
export const $getTableCellNodeRect = mod.$getTableCellNodeRect;
|
23
|
+
export const $getTableColumnIndexFromTableCellNode = mod.$getTableColumnIndexFromTableCellNode;
|
24
|
+
export const $getTableNodeFromLexicalNodeOrThrow = mod.$getTableNodeFromLexicalNodeOrThrow;
|
25
|
+
export const $getTableRowIndexFromTableCellNode = mod.$getTableRowIndexFromTableCellNode;
|
26
|
+
export const $getTableRowNodeFromTableCellNodeOrThrow = mod.$getTableRowNodeFromTableCellNodeOrThrow;
|
27
|
+
export const $insertTableColumn = mod.$insertTableColumn;
|
28
|
+
export const $insertTableColumn__EXPERIMENTAL = mod.$insertTableColumn__EXPERIMENTAL;
|
29
|
+
export const $insertTableRow = mod.$insertTableRow;
|
30
|
+
export const $insertTableRow__EXPERIMENTAL = mod.$insertTableRow__EXPERIMENTAL;
|
31
|
+
export const $isTableCellNode = mod.$isTableCellNode;
|
32
|
+
export const $isTableNode = mod.$isTableNode;
|
33
|
+
export const $isTableRowNode = mod.$isTableRowNode;
|
34
|
+
export const $isTableSelection = mod.$isTableSelection;
|
35
|
+
export const $removeTableRowAtIndex = mod.$removeTableRowAtIndex;
|
36
|
+
export const $unmergeCell = mod.$unmergeCell;
|
37
|
+
export const INSERT_TABLE_COMMAND = mod.INSERT_TABLE_COMMAND;
|
38
|
+
export const TableCellHeaderStates = mod.TableCellHeaderStates;
|
39
|
+
export const TableCellNode = mod.TableCellNode;
|
40
|
+
export const TableNode = mod.TableNode;
|
41
|
+
export const TableObserver = mod.TableObserver;
|
42
|
+
export const TableRowNode = mod.TableRowNode;
|
43
|
+
export const applyTableHandlers = mod.applyTableHandlers;
|
44
|
+
export const getDOMCellFromTarget = mod.getDOMCellFromTarget;
|
45
|
+
export const getTableObserverFromTableElement = mod.getTableObserverFromTableElement;
|
package/LexicalTable.js
CHANGED
@@ -5,5 +5,5 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
'use strict'
|
8
|
-
const LexicalTable = process.env.NODE_ENV === 'development' ? require('./LexicalTable.dev.js') : require('./LexicalTable.prod.js')
|
8
|
+
const LexicalTable = process.env.NODE_ENV === 'development' ? require('./LexicalTable.dev.js') : require('./LexicalTable.prod.js');
|
9
9
|
module.exports = LexicalTable;
|
package/LexicalTable.js.flow
CHANGED
@@ -245,7 +245,7 @@ declare export function $deleteTableColumn__EXPERIMENTAL(): void;
|
|
245
245
|
|
246
246
|
declare export function $unmergeCell(): void;
|
247
247
|
|
248
|
-
declare export function $
|
248
|
+
declare export function $computeTableMap(
|
249
249
|
table: TableNode,
|
250
250
|
cellA: TableCellNode,
|
251
251
|
cellB: TableCellNode,
|
@@ -0,0 +1,7 @@
|
|
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
|
+
import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,isHTMLElement as o}from"@lexical/utils";import{ElementNode as r,$applyNodeReplacement as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as a,createCommand as c,$createTextNode as h,$getSelection as d,$isRangeSelection as u,$normalizeSelection__EXPERIMENTAL as g,$getNodeByKey as f,isCurrentlyReadOnlyMode as m,$createPoint as p,$setSelection as _,SELECTION_CHANGE_COMMAND as C,$getNearestNodeFromDOMNode as S,$createRangeSelection as w,$getRoot as b,KEY_ARROW_DOWN_COMMAND as y,COMMAND_PRIORITY_HIGH as N,KEY_ARROW_UP_COMMAND as T,KEY_ARROW_LEFT_COMMAND as x,KEY_ARROW_RIGHT_COMMAND as E,KEY_ESCAPE_COMMAND as O,DELETE_WORD_COMMAND as v,DELETE_LINE_COMMAND as M,DELETE_CHARACTER_COMMAND as R,COMMAND_PRIORITY_CRITICAL as K,KEY_BACKSPACE_COMMAND as F,KEY_DELETE_COMMAND as k,FORMAT_TEXT_COMMAND as H,FORMAT_ELEMENT_COMMAND as A,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as D,FOCUS_COMMAND as P,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as L,$isTextNode as I,$getPreviousSelection as W}from"lexical";const U=/^(\d+(?:\.\d+)?)px$/,X={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Y extends r{static getType(){return"tablecell"}static clone(e){const t=new Y(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:z,priority:0}),th:e=>({conversion:z,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=J(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=X.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}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),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t,n=700,o=this.getParentOrThrow().getChildrenSize();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()||Math.max(90,n/o)}px`,e.style.verticalAlign="top",e.style.textAlign="start";const r=this.getBackgroundColor();null!==r?e.style.backgroundColor=r:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){return this.getWritable().__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){return this.getWritable().__width=e,this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e}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!==X.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}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function z(e){const t=e,n=e.nodeName.toLowerCase();let o;U.test(t.style.width)&&(o=parseFloat(t.style.width));const r=J("th"===n?X.ROW:X.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;return""!==l&&(r.__backgroundColor=l),{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if($(t)&&!i(e)){const t=s();return a(e)&&"\n"===e.getTextContent()?null:(t.append(e),t)}return e},node:r}}function J(e,t=1,n){return l(new Y(e,t,n))}function $(e){return e instanceof Y}const j=c("INSERT_TABLE_COMMAND");class q extends r{static getType(){return"tablerow"}static clone(e){return new q(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:G,priority:0})}}static importJSON(e){return Q(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function G(e){const t=e;let n;return U.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:Q(n)}}function Q(e){return l(new q(e))}function V(e){return e instanceof q}var Z=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};const ee="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function te(e,t,n=!0){const o=Ge();for(let r=0;r<e;r++){const e=Q();for(let o=0;o<t;o++){let t=X.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=X.ROW),0===o&&n.columns&&(t|=X.COLUMN)):n&&(0===r&&(t|=X.ROW),0===o&&(t|=X.COLUMN));const l=J(t),i=s();i.append(h()),l.append(i),e.append(l)}o.append(e)}return o}function ne(e){const n=t(e,(e=>$(e)));return $(n)?n:null}function oe(e){const n=t(e,(e=>V(e)));if(V(n))return n;throw new Error("Expected table cell to be inside of table row.")}function re(e){const n=t(e,(e=>Qe(e)));if(Qe(n))return n;throw new Error("Expected table cell to be inside of table.")}function le(e){const t=oe(e);return re(t).getChildren().findIndex((e=>e.is(t)))}function se(e){return oe(e).getChildren().findIndex((t=>t.is(e)))}function ie(e,t){const n=re(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)}}function ae(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}function ce(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const i=l[t];if(!V(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=Q();for(let n=0;n<t;n++){const t=e[n];$(t)||Z(12);const{above:l,below:i}=ie(t,r);let a=X.NO_STATUS;const c=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(X.COLUMN)||i&&i.hasHeaderState(X.COLUMN))&&(a|=X.COLUMN);const h=J(a,1,c);h.append(s()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const he=(e,t)=>e===X.BOTH||e===t?t:X.NO_STATUS;function de(e=!0){const t=d();u(t)||Te(t)||Z(118);const n=t.focus.getNode(),[o,,r]=be(n),[l,i]=we(r,o,o),a=l[0].length,{startRow:c}=i;if(e){const e=c+o.__rowSpan-1,t=l[e],n=Q();for(let o=0;o<a;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=he(e,X.COLUMN);n.append(J(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);V(i)||Z(145),i.insertAfter(n)}else{const e=l[c],t=Q();for(let n=0;n<a;n++){const{cell:o,startRow:r}=e[n];if(r===c){const o=e[n].cell.__headerState,r=he(o,X.COLUMN);t.append(J(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(c);V(n)||Z(145),n.insertBefore(t)}}function ue(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(V(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];$(o)||Z(12);const{left:l,right:a}=ie(o,r);let c=X.NO_STATUS;(l&&l.hasHeaderState(X.ROW)||a&&a.hasHeaderState(X.ROW))&&(c|=X.ROW);const h=J(c);h.append(s()),i.push({newTableCell:h,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function ge(e=!0){const t=d();u(t)||Te(t)||Z(118);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=be(n),[l,,i]=be(o),[a,c,h]=we(i,l,r),g=a.length,f=e?Math.max(c.startColumn,h.startColumn):Math.min(c.startColumn,h.startColumn),m=e?f+l.__colSpan-1:f-1,p=i.getFirstChild();V(p)||Z(120);let _=null;function C(e=X.NO_STATUS){const t=J(e).append(s());return null===_&&(_=t),t}let S=p;e:for(let e=0;e<g;e++){if(0!==e){const e=S.getNextSibling();V(e)||Z(121),S=e}const t=a[e],n=t[m<0?0:m].cell.__headerState,o=he(n,X.ROW);if(m<0){Ce(S,C(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){S.append(C(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(C(o))}else r.setColSpan(r.__colSpan+1)}null!==_&&_e(_)}function fe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(V(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}function me(){const e=d();u(e)||Te(e)||Z(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=be(t),[l]=be(n),[s,i,a]=we(r,o,l),{startRow:c}=i,{startRow:h}=a,g=h+l.__rowSpan-1;if(s.length===g-c+1)return void r.remove();const f=s[0].length,m=s[g+1],p=r.getChildAtIndex(g+1);for(let e=g;e>=c;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===c&&o<c&&n.setRowSpan(n.__rowSpan-(o-c)),o>=c&&o+n.__rowSpan-1>g))if(n.setRowSpan(n.__rowSpan-(g-o+1)),null===p&&Z(122),0===t)Ce(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);V(t)||Z(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];_e(e)}else{const e=s[c-1],{cell:t}=e[0];_e(t)}}function pe(){const e=d();u(e)||Te(e)||Z(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=be(t),[l]=be(n),[s,i,a]=we(r,o,l),{startColumn:c}=i,{startRow:h,startColumn:g}=a,f=Math.min(c,g),m=Math.max(c+o.__colSpan-1,g+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const _=s.length;for(let e=0;e<_;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,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 C=s[h],S=C[g+l.__colSpan];if(void 0!==S){const{cell:e}=S;_e(e)}else{const e=C[g-1],{cell:t}=e;_e(t)}}function _e(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ce(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Se(){const e=d();u(e)||Te(e)||Z(118);const t=e.anchor.getNode(),[n,o,r]=be(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(J(X.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=we(r,n,n),{startColumn:i,startRow:a}=t;let c;for(let t=1;t<s;t++){const n=a+t,r=e[n];c=(c||o).getNextSibling(),V(c)||Z(125);let s=null;for(let e=0;e<i;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let e=0;e<l;e++)Ce(c,J(X.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(J(X.NO_STATUS))}n.setRowSpan(1)}}function we(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const a={cell:i,startColumn:s,startRow:e},c=i.__rowSpan,h=i.__colSpan;for(let t=0;t<c;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<h;n++)o[e+t][s+n]=a}t.is(i)&&(r=a),n.is(i)&&(l=a)}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const a=e.getChildren();for(let e=0;e<a.length;e++){const t=a[e];V(t)||Z(146);const n=t.getChildren();let o=0;for(const t of n){for($(t)||Z(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return null===r&&Z(110),null===l&&Z(111),[o,r,l]}function be(e){let n;if(e instanceof Y)n=e;else if("__type"in e){const o=t(e,$);$(o)||Z(148),n=o}else{const o=t(e.getNode(),$);$(o)||Z(148),n=o}const o=n.getParent();V(o)||Z(149);const r=o.getParent();return Qe(r)||Z(150),[n,o,r]}function ye(e){const[t,,n]=be(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}class Ne{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]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!Te(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Ne(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();i(t)||Z(151);g(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=f(this.anchor.key);$(e)||Z(152);const t=ye(e);null===t&&Z(153);const n=f(this.focus.key);$(n)||Z(154);const o=ye(n);null===o&&Z(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex,o.columnIndex),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex,o.rowIndex);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,$),l=t(o,$);$(r)||Z(152),$(l)||Z(154);const s=r.getParent();V(s)||Z(156);const i=s.getParent();Qe(i)||Z(157);const a=l.getParents()[1];if(a!==i){if(i.isParentOf(l)){const e=a.getParent();null==e&&Z(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&Z(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[c,h,d]=we(i,r,l);let u=Math.min(h.startColumn,d.startColumn),g=Math.min(h.startRow,d.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,d.startColumn+d.cell.__colSpan-1),p=Math.max(h.startRow+h.cell.__rowSpan-1,d.startRow+d.cell.__rowSpan-1),_=u,C=g,S=u,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;u=Math.min(u,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),p=Math.max(p,o+t.__rowSpan-1)}for(;u<_||g<C||f>S||p>w;){if(u<_){const e=w-C,t=_-1;for(let n=0;n<=e;n++)b(c[C+n][t]);_=t}if(g<C){const e=S-_,t=C-1;for(let n=0;n<=e;n++)b(c[t][_+n]);C=t}if(f>S){const e=w-C,t=S+1;for(let n=0;n<=e;n++)b(c[C+n][t]);S=t}if(p>w){const e=S-_,t=w+1;for(let n=0;n<=e;n++)b(c[t][_+n]);w=t}}const y=[i];let N=null;for(let e=g;e<=p;e++)for(let t=u;t<=f;t++){const{cell:n}=c[e][t],o=n.getParent();V(o)||Z(160),o!==N&&y.push(o),y.push(n,...Ee(n)),N=o}return m()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function Te(e){return e instanceof Ne}function xe(){const e=p("root",0,"element"),t=p("root",0,"element");return new Ne("root",e,t)}function Ee(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&Z(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class Oe{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.trackTable()}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach((e=>e()))}trackTable(){const e=new MutationObserver((e=>{this.editor.update((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TR"===o){t=!0;break}}if(!t)return;const n=this.editor.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");this.table=Fe(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Fe(t),e.observe(t,{childList:!0,subtree:!0})}))}clearHighlight(){const e=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(),e.update((()=>{if(!Qe(f(this.tableNodeKey)))throw new Error("Expected TableNode.");const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");const n=Fe(t);ke(e,n,null),_(null),e.dispatchCommand(C,void 0)}))}enableHighlightStyle(){const e=this.editor;e.update((()=>{const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}))}disableHighlightStyle(){const t=this.editor;t.update((()=>{const n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}))}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),ke(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{if(!Qe(f(this.tableNodeKey)))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");const o=e.x,r=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=(l=n._window,ee?(l||window).getSelection():null);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}var l;if(this.isHighlightingCells||this.anchorX===o&&this.anchorY===r&&!t){if(o===this.focusX&&r===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=o,this.focusY=r,this.isHighlightingCells){const t=S(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&$(t)){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||xe(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),_(this.tableSelection),n.dispatchCommand(C,void 0),ke(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=S(e.elem);if($(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():xe(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=d();Te(t)||Z(11);const n=w(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{$(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),_(t),this.editor.dispatchCommand(C,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=f(this.tableNodeKey);if(!Qe(t))throw new Error("Expected TableNode.");const n=d();Te(n)||Z(11);const o=n.getNodes().filter($);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=h();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),ke(e,this.table,null),_(null),e.dispatchCommand(C,void 0);else{t.selectPrevious(),t.remove();b().selectStart()}}))}}const ve="__lexicalTableSelection";function Me(e,n,o,r){const l=o.getRootElement();if(null===l)throw new Error("No root element.");const a=new Oe(o,e.getKey()),c=o._window||window;!function(e,t){e[ve]=t}(n,a),n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!c)return;const t=Ke(e.target);null!==t&&(Je(e),a.setAnchorCellForSelection(t));const n=()=>{c.removeEventListener("mouseup",n),c.removeEventListener("mousemove",o)},o=e=>{const t=Ke(e.target);null===t||a.anchorX===t.x&&a.anchorY===t.y||(e.preventDefault(),a.setFocusCellForSelection(t))};c.addEventListener("mouseup",n),c.addEventListener("mousemove",o)}),0)}));const h=e=>{0===e.button&&o.update((()=>{const t=d(),n=e.target;Te(t)&&t.tableKey===a.tableNodeKey&&l.contains(n)&&a.clearHighlight()}))};c.addEventListener("mousedown",h),a.listenersToRemove.add((()=>c.removeEventListener("mousedown",h))),a.listenersToRemove.add(o.registerCommand(y,(t=>ze(o,t,"down",e,a)),N)),a.listenersToRemove.add(o.registerCommand(T,(t=>ze(o,t,"up",e,a)),N)),a.listenersToRemove.add(o.registerCommand(x,(t=>ze(o,t,"backward",e,a)),N)),a.listenersToRemove.add(o.registerCommand(E,(t=>ze(o,t,"forward",e,a)),N)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=d();if(Te(n)){const o=t(n.focus.getNode(),$);if($(o))return Je(e),o.selectEnd(),!0}return!1}),N));[v,M,R].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=d();if(!Pe(o,e))return!1;if(Te(o))return a.clearText(),!0;if(u(o)){const r=t(o.anchor.getNode(),(e=>$(e)));if(!$(r))return!1;const l=o.anchor.getNode(),c=o.focus.getNode(),h=e.isParentOf(l),d=e.isParentOf(c);if(h&&!d||d&&!h)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>i(e))),g=u&&t(u,(e=>i(e)&&$(e.getParent())));if(!i(g)||!i(u))return!1;if(n===M&&null===g.getPreviousSibling())return!0;if((n===R||n===v)&&o.isCollapsed()&&0===o.anchor.offset&&u!==g){const e=u.getChildren(),t=s();return e.forEach((e=>t.append(e))),u.replace(t),u.getWritable().__parent=r.getKey(),!0}}return!1})(n),K))}));const g=n=>{const o=d();if(!Pe(o,e))return!1;if(Te(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(u(o)){const e=t(o.anchor.getNode(),(e=>$(e)));if(!$(e))return!1}return!1};function f(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(F,g,K)),a.listenersToRemove.add(o.registerCommand(k,g,K)),a.listenersToRemove.add(o.registerCommand(H,(n=>{const o=d();if(!Pe(o,e))return!1;if(Te(o))return a.formatCells(n),!0;if(u(o)){const e=t(o.anchor.getNode(),(e=>$(e)));if(!$(e))return!1}return!1}),K)),a.listenersToRemove.add(o.registerCommand(A,(t=>{const n=d();if(!Te(n)||!Pe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!$(o)||!$(r))return!1;const[l,s,a]=we(e,o,r),c=Math.max(s.startRow,a.startRow),h=Math.max(s.startColumn,a.startColumn),u=Math.min(s.startRow,a.startRow),g=Math.min(s.startColumn,a.startColumn);for(let e=u;e<=c;e++)for(let n=g;n<=h;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),K)),a.listenersToRemove.add(o.registerCommand(B,(n=>{const o=d();if(!Pe(o,e))return!1;if(Te(o))return a.clearHighlight(),!1;if(u(o)){const e=t(o.anchor.getNode(),(e=>$(e)));if(!$(e))return!1}return!1}),K)),r&&a.listenersToRemove.add(o.registerCommand(D,(t=>{const n=d();if(!u(n)||!n.isCollapsed()||!Pe(n,e))return!1;const o=Xe(n.anchor.getNode());if(null===o)return!1;Je(t);const r=e.getCordsFromCellNode(o,a.table);return Be(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),K)),a.listenersToRemove.add(o.registerCommand(P,(t=>e.isSelected()),N)),a.listenersToRemove.add(o.registerCommand(L,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=Te(o),i=u(o)&&null!==t(o.anchor.getNode(),(e=>$(e)))&&null!==t(o.focus.getNode(),(e=>$(e)))||l;if(1!==n.length||!Qe(n[0])||!i||null===r)return!1;const[a]=r,c=n[0],h=c.getChildren(),d=c.getFirstChildOrThrow().getChildrenSize(),g=c.getChildrenSize(),f=t(a.getNode(),(e=>$(e))),m=f&&t(f,(e=>V(e))),p=m&&t(m,(e=>Qe(e)));if(!$(f)||!V(m)||!Qe(p))return!1;const C=m.getIndexWithinParent(),S=Math.min(p.getChildrenSize()-1,C+g-1),w=f.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(C,S),T=Math.max(w,b),x=Math.max(C,S),E=p.getChildren();let O,v,M=0;for(let e=N;e<=x;e++){const t=E[e];if(!V(t))return!1;const n=h[M];if(!V(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let t=y;t<=T;t++){const n=o[t];if(!$(n))return!1;const i=r[l];if(!$(i))return!1;e===N&&t===y?O=n.getKey():e===x&&t===T&&(v=n.getKey());const a=n.getChildren();i.getChildren().forEach((e=>{if(I(e)){s().append(e),n.append(e)}else n.append(e)})),a.forEach((e=>e.remove())),l++}M++}if(O&&v){const e=xe();e.set(n[0].getKey(),O,v),_(e)}return!0}),K)),a.listenersToRemove.add(o.registerCommand(C,(()=>{const t=d(),n=W();if(u(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Xe(l),c=Xe(s),h=!(!i||!e.is(Ye(i))),d=!(!c||!e.is(Ye(c))),u=h!==d,g=h&&d,m=t.isBackward();if(u){const n=t.clone();n.focus.set(e.getKey(),m?0:e.getChildrenSize(),"element"),_(n),Ae(o,a)}else g&&(i.is(c)||(a.setAnchorCellForSelection(f(i)),a.setFocusCellForSelection(f(c),!0)))}return t&&!t.is(n)&&(Te(t)||Te(n))&&a.tableSelection&&!a.tableSelection.is(n)?(Te(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!Te(t)&&Te(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),He(t.table,(t=>{const n=t.elem;t.highlighted=!1,Ue(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&Ae(o,a),!1)}),K)),a}function Re(e){return e[ve]}function Ke(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 Fe(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.firstChild,r=0,l=0;for(t.length=0;null!=o;){const e=o.nodeName;if("TD"===e||"TH"===e){const e={elem:o,hasBackgroundColor:""!==o.style.backgroundColor,highlighted:!1,x:r,y:l};o._cell=e;let n=t[l];void 0===n&&(n=t[l]=[]),n[r]=e}else{const e=o.firstChild;if(null!=e){o=e;continue}}const n=o.nextSibling;if(null!=n){r++,o=n;continue}const s=o.parentNode;if(null!=s){const e=s.nextSibling;if(null==e)break;l++,r=0,o=e}}return n.columns=r+1,n.rows=l+1,n}function ke(e,t,n){const o=new Set(n?n.getNodes():[]);He(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,We(e,t)):(t.highlighted=!1,Ue(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function He(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=S(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ae(e,t){t.disableHighlightStyle(),He(t.table,(t=>{t.highlighted=!0,We(e,t)}))}const Be=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Le(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Le(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?Le(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Le(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},De=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function Pe(e,t){if(u(e)||Te(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Le(e,t){t?e.selectStart():e.selectEnd()}const Ie="172,206,247";function We(e,t){const n=t.elem,o=S(n);$(o)||Z(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Ie})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Ie},0.85), rgba(${Ie},0.85))`),n.style.setProperty("caret-color","transparent")}function Ue(e,t){const n=t.elem,o=S(n);$(o)||Z(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function Xe(e){const n=t(e,$);return $(n)?n:null}function Ye(e){const n=t(e,Qe);return Qe(n)?n:null}function ze(e,n,o,r,l){const s=d();if(!Pe(s,r))return!1;if(u(s)&&s.isCollapsed()){if("backward"===o||"forward"===o)return!1;const{anchor:i,focus:a}=s,c=t(i.getNode(),$),h=t(a.getNode(),$);if(!$(c)||!c.is(h))return!1;const d=Ye(c);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=Fe(t),ze(e,n,o,d,l)}const u=e.getElementByKey(c.__key),g=e.getElementByKey(i.key);if(null==g||null==u)return!1;let f;if("element"===i.type)f=g.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;f=e.getRangeAt(0).getBoundingClientRect()}const m="up"===o?c.getFirstChild():c.getLastChild();if(null==m)return!1;const p=e.getElementByKey(m.__key);if(null==p)return!1;const _=p.getBoundingClientRect();if("up"===o?_.top>f.top-f.height:f.bottom+f.height>_.bottom){Je(n);const e=r.getCordsFromCellNode(c,l.table);if(!n.shiftKey)return Be(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.setAnchorCellForSelection(t),l.setFocusCellForSelection(t,!0)}return!0}}else if(Te(s)){const{anchor:i,focus:a}=s,c=t(i.getNode(),$),h=t(a.getNode(),$),[d]=s.getNodes(),u=e.getElementByKey(d.getKey());if(!$(c)||!$(h)||!Qe(d)||null==u)return!1;l.updateTableTableSelection(s);const g=Fe(u),f=r.getCordsFromCellNode(c,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Je(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return De(l,d,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function Je(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}class $e extends r{static getType(){return"table"}static clone(e){return new $e(e.__key)}static importDOM(){return{table:e=>({conversion:qe,priority:1})}}static importJSON(e){return Ge()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(o,t.theme.table),o}updateDOM(){return!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!V(l))throw new Error("Expected to find row node.");const s=l.getChildrenSize();for(let e=0;e<s;e++){const e=document.createElement("col");n.append(e)}return t.replaceChildren(n,r),t}}}}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)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return S(n)===e}));if(-1!==r)return{x:r,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];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,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=S(o.elem);return $(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}canSelectBefore(){return!0}canIndent(){return!1}}function je(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Fe(n)}function qe(e){return{node:Ge()}}function Ge(){return l(new $e)}function Qe(e){return e instanceof $e}export{we as $computeTableMap,J as $createTableCellNode,Ge as $createTableNode,te as $createTableNodeWithDimensions,Q as $createTableRowNode,xe as $createTableSelection,fe as $deleteTableColumn,pe as $deleteTableColumn__EXPERIMENTAL,me as $deleteTableRow__EXPERIMENTAL,je as $getElementForTableNode,be as $getNodeTriplet,ne as $getTableCellNodeFromLexicalNode,ye as $getTableCellNodeRect,se as $getTableColumnIndexFromTableCellNode,re as $getTableNodeFromLexicalNodeOrThrow,le as $getTableRowIndexFromTableCellNode,oe as $getTableRowNodeFromTableCellNodeOrThrow,ue as $insertTableColumn,ge as $insertTableColumn__EXPERIMENTAL,ce as $insertTableRow,de as $insertTableRow__EXPERIMENTAL,$ as $isTableCellNode,Qe as $isTableNode,V as $isTableRowNode,Te as $isTableSelection,ae as $removeTableRowAtIndex,Se as $unmergeCell,j as INSERT_TABLE_COMMAND,X as TableCellHeaderStates,Y as TableCellNode,$e as TableNode,Oe as TableObserver,q as TableRowNode,Me as applyTableHandlers,Ke as getDOMCellFromTarget,Re as getTableObserverFromTableElement};
|
package/LexicalTable.prod.js
CHANGED
@@ -4,82 +4,83 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
|
-
'use strict';var h=require("@lexical/utils"),v=require("lexical");let
|
7
|
+
'use strict';var h=require("@lexical/utils"),v=require("lexical");let aa=/^(\d+(?:\.\d+)?)px$/,w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
8
8
|
class y extends v.ElementNode{static getType(){return"tablecell"}static clone(a){let b=new y(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:da,priority:0}),th:()=>({conversion:da,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=z(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=w.NO_STATUS,b=1,c,d){super(d);
|
9
9
|
this.__colSpan=b;this.__rowSpan=1;this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);h.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
|
10
10
|
if(a){var b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";b=this.getBackgroundColor();null!==b?a.style.backgroundColor=b:this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),
|
11
11
|
colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(a){this.getWritable().__colSpan=a;return this}getRowSpan(){return this.__rowSpan}setRowSpan(a){this.getWritable().__rowSpan=a;return this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=
|
12
12
|
a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==w.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==
|
13
13
|
this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
|
14
|
-
function da(a){var b=a.nodeName.toLowerCase();let c=void 0;
|
15
|
-
function A(a){return a instanceof y}let ea=v.createCommand("INSERT_TABLE_COMMAND");
|
16
|
-
class B extends v.ElementNode{static getType(){return"tablerow"}static clone(a){return new B(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return
|
17
|
-
a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function fa(a){let b=void 0;
|
18
|
-
function
|
19
|
-
function ia(a){a=h.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>
|
20
|
-
let la=(a,b)=>a===w.BOTH||a===b?b:w.NO_STATUS;function
|
21
|
-
function
|
22
|
-
function
|
23
|
-
function
|
24
|
-
class
|
25
|
-
this._cachedNodes=null}clone(){return new
|
26
|
-
c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(
|
27
|
-
A);A(d)||
|
28
|
-
f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=
|
29
|
-
this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function
|
30
|
-
class
|
31
|
-
{this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=
|
32
|
-
!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=v.$getNodeByKey(this.tableNodeKey);if(!
|
14
|
+
function da(a){var b=a.nodeName.toLowerCase();let c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("th"===b?w.ROW:w.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{after:d=>{0===d.length&&d.push(v.$createParagraphNode());return d},forChild:(d,e)=>{if(A(e)&&!v.$isElementNode(d)){e=v.$createParagraphNode();if(v.$isLineBreakNode(d)&&"\n"===d.getTextContent())return null;e.append(d);return e}return d},node:b}}
|
15
|
+
function z(a,b=1,c){return v.$applyNodeReplacement(new y(a,b,c))}function A(a){return a instanceof y}let ea=v.createCommand("INSERT_TABLE_COMMAND");
|
16
|
+
class B extends v.ElementNode{static getType(){return"tablerow"}static clone(a){return new B(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);h.addClassNamesToElement(b,
|
17
|
+
a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function fa(a){let b=void 0;aa.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:E(b)}}function E(a){return v.$applyNodeReplacement(new B(a))}function F(a){return a instanceof B}
|
18
|
+
function I(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
19
|
+
function ia(a){a=h.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:e}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,e-1,b),below:c.getCellNodeFromCords(d,e+1,b),left:c.getCellNodeFromCords(d-1,e,b),right:c.getCellNodeFromCords(d+1,e,b)}}
|
20
|
+
let la=(a,b)=>a===w.BOTH||a===b?b:w.NO_STATUS;function L(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}
|
21
|
+
function M(a,b,c){let d=[],e=null,l=null;a=a.getChildren();for(let g=0;g<a.length;g++){var f=a[g];F(f)||I(146);var m=f.getChildren();f=0;for(let k of m){for(A(k)||I(147);void 0!==d[g]&&void 0!==d[g][f];)f++;m=g;var q=f,u=k;let n={cell:u,startColumn:q,startRow:m},p=u.__rowSpan,r=u.__colSpan;for(let t=0;t<p;t++){void 0===d[m+t]&&(d[m+t]=[]);for(let x=0;x<r;x++)d[m+t][q+x]=n}b.is(u)&&(e=n);c.is(u)&&(l=n);f+=k.__colSpan}}null===e&&I(110);null===l&&I(111);return[d,e,l]}
|
22
|
+
function O(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,A),A(a)||I(148)):(a=h.$findMatchingParent(a.getNode(),A),A(a)||I(148)));let b=a.getParent();F(b)||I(149);let c=b.getParent();K(c)||I(150);return[a,b,c]}
|
23
|
+
function na(a){let [b,,c]=O(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let l=Array(d);for(var f=0;f<d;f++)l[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let q=0;q<f.length;q++){for(;l[e][m];)m++;let u=f[q],g=u.__rowSpan||1,k=u.__colSpan||1;for(let n=0;n<g;n++)for(let p=0;p<k;p++)l[e+n][m+p]=u;if(b===u)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:g};m+=k}}return null}
|
24
|
+
class oa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return P(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
|
25
|
+
this._cachedNodes=null}clone(){return new oa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();v.$isElementNode(b)||I(151);v.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=v.$getNodeByKey(this.anchor.key);A(a)||I(152);a=na(a);null===a&&I(153);var b=v.$getNodeByKey(this.focus.key);A(b)||I(154);let c=na(b);null===c&&I(155);b=Math.min(a.columnIndex,
|
26
|
+
c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(t){let {cell:x,startColumn:D,startRow:C}=t;q=Math.min(q,D);u=Math.min(u,C);g=Math.max(g,D+x.__colSpan-1);k=Math.max(k,C+x.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=h.$findMatchingParent(c,A);c=h.$findMatchingParent(b,
|
27
|
+
A);A(d)||I(152);A(c)||I(154);b=d.getParent();F(b)||I(156);b=b.getParent();K(b)||I(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&I(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&I(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [l,f,m]=M(b,d,c),q=Math.min(f.startColumn,m.startColumn),u=Math.min(f.startRow,m.startRow),g=Math.max(f.startColumn+f.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),k=Math.max(f.startRow+
|
28
|
+
f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=u;e=q;for(var n=u;q<c||u<d||g>e||k>n;){if(q<c){var p=n-d;--c;for(var r=0;r<=p;r++)a(l[d+r][c])}if(u<d)for(p=e-c,--d,r=0;r<=p;r++)a(l[d][c+r]);if(g>e)for(p=n-d,e+=1,r=0;r<=p;r++)a(l[d+r][e]);if(k>n)for(p=e-c,n+=1,r=0;r<=p;r++)a(l[n][c+r])}b=[b];c=null;for(d=u;d<=k;d++)for(e=q;e<=g;e++)({cell:n}=l[d][e]),p=n.getParent(),F(p)||I(160),p!==c&&b.push(p),b.push(n,...pa(n)),c=p;v.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
|
29
|
+
this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function P(a){return a instanceof oa}function Q(){let a=v.$createPoint("root",0,"element"),b=v.$createPoint("root",0,"element");return new oa("root",a,b)}function pa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&I(112);v.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
|
30
|
+
class qa{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTable()}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTable(){let a=new MutationObserver(b=>
|
31
|
+
{this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=R(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.table=R(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
|
32
|
+
!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=v.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=R(b);S(a,b,null);v.$setSelection(null);a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,
|
33
33
|
void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.addClassNamesToElement(b,a._config.theme.tableSelection);
|
34
|
-
this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();
|
35
|
-
d=a.x;let e=a.y;this.focusCell=a;if(null!==this.anchorCell){let
|
36
|
-
A(d)&&(d=d.getKey(),this.tableSelection=this.tableSelection.clone()||
|
37
|
-
this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():
|
38
|
-
a.update(()=>{let b=v.$getNodeByKey(this.tableNodeKey);if(!
|
39
|
-
void 0))})}}function
|
40
|
-
function
|
41
|
-
function
|
42
|
-
function
|
43
|
-
let
|
44
|
-
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},
|
45
|
-
d+1,a.table)),!0):!1;default:return!1}};function
|
46
|
-
function
|
47
|
-
function
|
48
|
-
function
|
49
|
-
q.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;m=m.getRangeAt(0).getBoundingClientRect()}q="up"===c?f.getFirstChild():f.getLastChild();if(null==q)return!1;a=a.getElementByKey(q.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){
|
50
|
-
!0);else return
|
51
|
-
function
|
52
|
-
class
|
53
|
-
e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let
|
54
|
-
|
55
|
-
|
56
|
-
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=
|
34
|
+
this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();S(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=v.$getNodeByKey(this.tableNodeKey);if(!K(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
|
35
|
+
d=a.x;let e=a.y;this.focusCell=a;if(null!==this.anchorCell){let l=ha?(c._window||window).getSelection():null;l&&l.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==d||this.anchorY!==e||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(d===this.focusX&&e===this.focusY)return;this.focusX=d;this.focusY=e;this.isHighlightingCells&&(d=v.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&
|
36
|
+
A(d)&&(d=d.getKey(),this.tableSelection=this.tableSelection.clone()||Q(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),v.$setSelection(this.tableSelection),c.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0),S(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=v.$getNearestNodeFromDOMNode(a.elem);A(b)&&(b=b.getKey(),
|
37
|
+
this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Q(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=v.$getSelection();P(b)||I(11);let c=v.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(l=>{A(l)&&0!==l.getTextContentSize()&&(d.set(l.getKey(),0,"element"),e.set(l.getKey(),l.getChildrenSize(),"element"),c.formatText(a))});v.$setSelection(b);this.editor.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;
|
38
|
+
a.update(()=>{let b=v.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");var c=v.$getSelection();P(c)||I(11);c=c.getNodes().filter(A);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),v.$getRoot().selectStart()):(c.forEach(d=>{if(v.$isElementNode(d)){let e=v.$createParagraphNode(),l=v.$createTextNode();e.append(l);d.append(e);d.getChildren().forEach(f=>{f!==e&&f.remove()})}}),S(a,this.table,null),v.$setSelection(null),a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,
|
39
|
+
void 0))})}}function ra(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
40
|
+
function R(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.firstChild;let e=a=0;for(b.length=0;null!=d;){var l=d.nodeName;if("TD"===l||"TH"===l){l=d;l={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=l;let f=b[e];void 0===f&&(f=b[e]=[]);f[a]=l}else if(l=d.firstChild,null!=l){d=l;continue}l=d.nextSibling;if(null!=l)a++,d=l;else if(l=d.parentNode,null!=l){d=l.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
|
41
|
+
function S(a,b,c){let d=new Set(c?c.getNodes():[]);sa(b,(e,l)=>{let f=e.elem;d.has(l)?(e.highlighted=!0,ta(a,e)):(e.highlighted=!1,ua(a,e),f.getAttribute("style")||f.removeAttribute("style"))})}function sa(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let l=d[e];if(!l)continue;let f=v.$getNearestNodeFromDOMNode(l.elem);null!==f&&b(l,f,{x:e,y:c})}}}function va(a,b){b.disableHighlightStyle();sa(b.table,c=>{c.highlighted=!0;ta(a,c)})}
|
42
|
+
function xa(a,b){b.enableHighlightStyle();sa(b.table,c=>{let d=c.elem;c.highlighted=!1;ua(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
|
43
|
+
let ya=(a,b,c,d,e)=>{const l="forward"===e;switch(e){case "backward":case "forward":return c!==(l?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(l?1:-1),d,a.table),l?a.selectStart():a.selectEnd()):d!==(l?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(l?0:a.table.columns-1,d+(l?1:-1),a.table),l?a.selectStart():a.selectEnd()):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==d?b.getCellNodeFromCordsOrThrow(c,d-1,a.table).selectEnd():b.selectPrevious(),!0;case "down":return d!==
|
44
|
+
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},za=(a,b,c,d,e)=>{const l="forward"===e;switch(e){case "backward":case "forward":return c!==(l?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(l?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
|
45
|
+
d+1,a.table)),!0):!1;default:return!1}};function W(a,b){if(v.$isRangeSelection(a)||P(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
|
46
|
+
function ta(a,b){a=b.elem;b=v.$getNearestNodeFromDOMNode(a);A(b)||I(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
|
47
|
+
function ua(a,b){a=b.elem;b=v.$getNearestNodeFromDOMNode(a);A(b)||I(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Aa(a){a=h.$findMatchingParent(a,A);return A(a)?a:null}function Ba(a){a=h.$findMatchingParent(a,K);return K(a)?a:null}
|
48
|
+
function X(a,b,c,d,e){let l=v.$getSelection();if(!W(l,d))return!1;if(v.$isRangeSelection(l)&&l.isCollapsed()){if("backward"===c||"forward"===c)return!1;let {anchor:u,focus:g}=l;var f=h.$findMatchingParent(u.getNode(),A),m=h.$findMatchingParent(g.getNode(),A);if(!A(f)||!f.is(m))return!1;m=Ba(f);if(m!==d&&null!=m){var q=a.getElementByKey(m.getKey());if(null!=q)return e.table=R(q),X(a,b,c,m,e)}m=a.getElementByKey(f.__key);q=a.getElementByKey(u.key);if(null==q||null==m)return!1;if("element"===u.type)m=
|
49
|
+
q.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;m=m.getRangeAt(0).getBoundingClientRect()}q="up"===c?f.getFirstChild():f.getLastChild();if(null==q)return!1;a=a.getElementByKey(q.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){Y(b);a=d.getCordsFromCellNode(f,e.table);if(b.shiftKey)c=d.getDOMCellFromCordsOrThrow(a.x,a.y,e.table),e.setAnchorCellForSelection(c),e.setFocusCellForSelection(c,
|
50
|
+
!0);else return ya(e,d,a.x,a.y,c);return!0}}else if(P(l)){let {anchor:u,focus:g}=l;q=h.$findMatchingParent(u.getNode(),A);m=h.$findMatchingParent(g.getNode(),A);[f]=l.getNodes();a=a.getElementByKey(f.getKey());if(!A(q)||!A(m)||!K(f)||null==a)return!1;e.updateTableTableSelection(l);a=R(a);q=d.getCordsFromCellNode(q,a);q=d.getDOMCellFromCordsOrThrow(q.x,q.y,a);e.setAnchorCellForSelection(q);Y(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,a),za(e,f,b.x,b.y,c);m.selectEnd();return!0}return!1}
|
51
|
+
function Y(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
|
52
|
+
class Z extends v.ElementNode{static getType(){return"table"}static clone(a){return new Z(a.__key)}static importDOM(){return{table:()=>({conversion:Ca,priority:1})}}static importJSON(){return Da()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");h.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),d=document.createElement("colgroup"),
|
53
|
+
e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let f=document.createElement("col");d.append(f)}c.replaceChildren(d,e);return c}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var e=d[b];if(null!=e&&(e=e.findIndex(l=>{if(l)return{elem:l}=l,v.$getNearestNodeFromDOMNode(l)===a}),
|
54
|
+
-1!==e))return{x:e,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getDOMCellFromCordsOrThrow(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=v.$getNearestNodeFromDOMNode(a.elem);return A(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);
|
55
|
+
if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function Ca(){return{node:Da()}}function Da(){return v.$applyNodeReplacement(new Z)}function K(a){return a instanceof Z}exports.$computeTableMap=M;exports.$createTableCellNode=z;exports.$createTableNode=Da;
|
56
|
+
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Da();for(let l=0;l<a;l++){let f=E();for(let m=0;m<b;m++){var e=w.NO_STATUS;"object"===typeof c?(0===l&&c.rows&&(e|=w.ROW),0===m&&c.columns&&(e|=w.COLUMN)):c&&(0===l&&(e|=w.ROW),0===m&&(e|=w.COLUMN));e=z(e);let q=v.$createParagraphNode();q.append(v.$createTextNode());e.append(q);f.append(e)}d.append(f)}return d};exports.$createTableRowNode=E;exports.$createTableSelection=Q;
|
57
57
|
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(F(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
|
58
|
-
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||
|
59
|
-
Math.min(g,
|
60
|
-
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||
|
61
|
-
1>a))if(n.setRowSpan(n.__rowSpan-(a-p+1)),null===
|
62
|
-
exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>A(b));return A(a)?a:null};exports.$getTableCellNodeRect=
|
63
|
-
exports.$insertTableColumn=function(a,b,c=!0,d,e){let
|
64
|
-
g.insertAfter(
|
65
|
-
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(
|
66
|
-
F(g)||
|
67
|
-
exports.$insertTableRow=function(a,b,c=!0,d,e){var
|
58
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||P(a)||I(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=O(b);[b]=O(a);let [e,l,f]=M(d,c,b);var {startColumn:m}=l;let {startRow:q,startColumn:u}=f;a=Math.min(m,u);m=Math.max(m+c.__colSpan-1,u+b.__colSpan-1);let g=m-a+1;if(e[0].length===m-a+1)d.selectPrevious(),d.remove();else{var k=e.length;for(let n=0;n<k;n++)for(let p=a;p<=m;p++){let {cell:r,startColumn:t}=e[n][p];t<a?p===a&&r.setColSpan(r.__colSpan-
|
59
|
+
Math.min(g,r.__colSpan-(a-t))):t+r.__colSpan-1>m?p===m&&r.setColSpan(r.__colSpan-(m-t+1)):r.remove()}a=e[q];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,L(b)):({cell:b}=a[u-1],L(b))}};
|
60
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||P(a)||I(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=O(b);[a]=O(a);let [e,l,f]=M(d,c,a);({startRow:b}=l);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var q=e[a+1],u=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var g=m-1;0<=g;g--){let {cell:n,startRow:p,startColumn:r}=e[k][g];if(r===g&&(k===b&&p<b&&n.setRowSpan(n.__rowSpan-(p-b)),p>=b&&p+n.__rowSpan-
|
61
|
+
1>a))if(n.setRowSpan(n.__rowSpan-(a-p+1)),null===u&&I(122),0===g)ma(u,n);else{let {cell:t}=q[g-1];t.insertAfter(n)}}g=d.getChildAtIndex(k);F(g)||I(123,String(k));g.remove()}void 0!==q?({cell:b}=q[0],L(b)):({cell:b}=e[b-1][0],L(b))}};exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return R(a)};exports.$getNodeTriplet=O;
|
62
|
+
exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>A(b));return A(a)?a:null};exports.$getTableCellNodeRect=na;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
|
63
|
+
exports.$insertTableColumn=function(a,b,c=!0,d,e){let l=a.getChildren(),f=[];for(let u=0;u<l.length;u++){let g=l[u];if(F(g))for(let k=0;k<d;k++){var m=g.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];A(m)||I(12);let {left:n,right:p}=ka(m,e);var q=w.NO_STATUS;if(n&&n.hasHeaderState(w.ROW)||p&&p.hasHeaderState(w.ROW))q|=w.ROW;q=z(q);q.append(v.$createParagraphNode());f.push({newTableCell:q,targetCell:m})}}f.forEach(({newTableCell:u,targetCell:g})=>{c?
|
64
|
+
g.insertAfter(u):g.insertBefore(u)});return a};
|
65
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=w.NO_STATUS){k=z(k).append(v.$createParagraphNode());null===u&&(u=k);return k}var c=v.$getSelection();v.$isRangeSelection(c)||P(c)||I(118);var d=c.anchor.getNode();c=c.focus.getNode();[d]=O(d);let [e,,l]=O(c),[f,m,q]=M(l,e,d);d=f.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);a=a?c+e.__colSpan-1:c-1;c=l.getFirstChild();F(c)||I(120);let u=null;var g=c;a:for(c=0;c<d;c++){0!==c&&(g=g.getNextSibling(),
|
66
|
+
F(g)||I(121));let k=f[c],n=la(k[0>a?0:a].cell.__headerState,w.ROW);if(0>a){ma(g,b(n));continue}let {cell:p,startColumn:r,startRow:t}=k[a];if(r+p.__colSpan-1<=a){let x=p,D=t,C=a;for(;D!==c&&1<x.__rowSpan;)if(C-=p.__colSpan,0<=C){let {cell:H,startRow:J}=k[C];x=H;D=J}else{g.append(b(n));continue a}x.insertAfter(b(n))}else p.setColSpan(p.__colSpan+1)}null!==u&&L(u)};
|
67
|
+
exports.$insertTableRow=function(a,b,c=!0,d,e){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<d;l++){let m=b.getChildren(),q=m.length,u=E();for(let g=0;g<q;g++){var f=m[g];A(f)||I(12);let {above:k,below:n}=ka(f,e);f=w.NO_STATUS;let p=k&&k.getWidth()||n&&n.getWidth()||void 0;if(k&&k.hasHeaderState(w.COLUMN)||n&&n.hasHeaderState(w.COLUMN))f|=w.COLUMN;f=z(f,1,p);f.append(v.$createParagraphNode());u.append(f)}c?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
|
68
68
|
return a};
|
69
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=v.$getSelection();v.$isRangeSelection(b)||
|
70
|
-
a=
|
71
|
-
exports.$unmergeCell=function(){var a=v.$getSelection();v.$isRangeSelection(a)||
|
72
|
-
a;m++)ma(n,z(w.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ea;exports.TableCellHeaderStates=w;exports.TableCellNode=y;exports.TableNode=
|
73
|
-
exports.applyTableHandlers=function(a,b,c,d){function e(g){g=a.getCordsFromCellNode(g,f.table);return a.getDOMCellFromCordsOrThrow(g.x,g.y,f.table)}let
|
74
|
-
p)},p=
|
75
|
-
g=>
|
76
|
-
A),A(
|
77
|
-
if(!v.$isElementNode(n)||!v.$isElementNode(p))return!1;if(g===v.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0;if((g===v.DELETE_CHARACTER_COMMAND||g===v.DELETE_WORD_COMMAND)&&
|
78
|
-
|
79
|
-
g=>{let
|
80
|
-
|
81
|
-
var
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
69
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=v.$getSelection();v.$isRangeSelection(b)||P(b)||I(118);b=b.focus.getNode();let [c,,d]=O(b),[e,l]=M(d,c,c);b=e[0].length;var {startRow:f}=l;if(a){a=f+c.__rowSpan-1;var m=e[a];f=E();for(var q=0;q<b;q++){let {cell:g,startRow:k}=m[q];if(k+g.__rowSpan-1<=a){var u=la(m[q].cell.__headerState,w.COLUMN);f.append(z(u).append(v.$createParagraphNode()))}else g.setRowSpan(g.__rowSpan+1)}b=d.getChildAtIndex(a);F(b)||I(145);b.insertAfter(f)}else{m=e[f];
|
70
|
+
a=E();for(q=0;q<b;q++){let {cell:g,startRow:k}=m[q];k===f?(u=la(m[q].cell.__headerState,w.COLUMN),a.append(z(u).append(v.$createParagraphNode()))):g.setRowSpan(g.__rowSpan+1)}b=d.getChildAtIndex(f);F(b)||I(145);b.insertBefore(a)}};exports.$isTableCellNode=A;exports.$isTableNode=K;exports.$isTableRowNode=F;exports.$isTableSelection=P;exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
|
71
|
+
exports.$unmergeCell=function(){var a=v.$getSelection();v.$isRangeSelection(a)||P(a)||I(118);a=a.anchor.getNode();let [b,c,d]=O(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var l=1;l<a;l++)b.insertAfter(z(w.NO_STATUS));b.setColSpan(1)}if(1<e){let [q,u]=M(d,b,b),{startColumn:g,startRow:k}=u,n;for(l=1;l<e;l++){var f=k+l;let p=q[f];n=(n||c).getNextSibling();F(n)||I(125);var m=null;for(let r=0;r<g;r++){let t=p[r],x=t.cell;t.startRow===f&&(m=x);1<x.__colSpan&&(r+=x.__colSpan-1)}if(null===m)for(m=0;m<
|
72
|
+
a;m++)ma(n,z(w.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ea;exports.TableCellHeaderStates=w;exports.TableCellNode=y;exports.TableNode=Z;exports.TableObserver=qa;exports.TableRowNode=B;
|
73
|
+
exports.applyTableHandlers=function(a,b,c,d){function e(g){g=a.getCordsFromCellNode(g,f.table);return a.getDOMCellFromCordsOrThrow(g.x,g.y,f.table)}let l=c.getRootElement();if(null===l)throw Error("No root element.");let f=new qa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button&&m){var k=ra(g.target);null!==k&&(Y(g),f.setAnchorCellForSelection(k));var n=()=>{m.removeEventListener("mouseup",n);m.removeEventListener("mousemove",
|
74
|
+
p)},p=r=>{const t=ra(r.target);null===t||f.anchorX===t.x&&f.anchorY===t.y||(r.preventDefault(),f.setFocusCellForSelection(t))};m.addEventListener("mouseup",n);m.addEventListener("mousemove",p)}},0)});let q=g=>{0===g.button&&c.update(()=>{const k=v.$getSelection(),n=g.target;P(k)&&k.tableKey===f.tableNodeKey&&l.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",q);f.listenersToRemove.add(()=>m.removeEventListener("mousedown",q));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_DOWN_COMMAND,
|
75
|
+
g=>X(c,g,"down",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_UP_COMMAND,g=>X(c,g,"up",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_LEFT_COMMAND,g=>X(c,g,"backward",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_RIGHT_COMMAND,g=>X(c,g,"forward",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ESCAPE_COMMAND,g=>{var k=v.$getSelection();return P(k)&&(k=h.$findMatchingParent(k.focus.getNode(),
|
76
|
+
A),A(k))?(Y(g),k.selectEnd(),!0):!1},v.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var k=v.$getSelection();if(!W(k,a))return!1;if(P(k))return f.clearText(),!0;if(v.$isRangeSelection(k)){const r=h.$findMatchingParent(k.anchor.getNode(),t=>A(t));if(!A(r))return!1;var n=k.anchor.getNode(),p=k.focus.getNode();n=a.isParentOf(n);p=a.isParentOf(p);if(n&&!p||p&&!n)return f.clearText(),!0;n=(p=h.$findMatchingParent(k.anchor.getNode(),t=>v.$isElementNode(t)))&&h.$findMatchingParent(p,t=>v.$isElementNode(t)&&A(t.getParent()));
|
77
|
+
if(!v.$isElementNode(n)||!v.$isElementNode(p))return!1;if(g===v.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0;if((g===v.DELETE_CHARACTER_COMMAND||g===v.DELETE_WORD_COMMAND)&&k.isCollapsed()&&0===k.anchor.offset&&p!==n){k=p.getChildren();const t=v.$createParagraphNode();k.forEach(x=>t.append(x));p.replace(t);p.getWritable().__parent=r.getKey();return!0}}return!1};[v.DELETE_WORD_COMMAND,v.DELETE_LINE_COMMAND,v.DELETE_CHARACTER_COMMAND].forEach(g=>{f.listenersToRemove.add(c.registerCommand(g,
|
78
|
+
u(g),v.COMMAND_PRIORITY_CRITICAL))});b=g=>{const k=v.$getSelection();if(!W(k,a))return!1;if(P(k))return g.preventDefault(),g.stopPropagation(),f.clearText(),!0;v.$isRangeSelection(k)&&(g=h.$findMatchingParent(k.anchor.getNode(),n=>A(n)),A(g));return!1};f.listenersToRemove.add(c.registerCommand(v.KEY_BACKSPACE_COMMAND,b,v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.KEY_DELETE_COMMAND,b,v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.FORMAT_TEXT_COMMAND,
|
79
|
+
g=>{let k=v.$getSelection();if(!W(k,a))return!1;if(P(k))return f.formatCells(g),!0;v.$isRangeSelection(k)&&(g=h.$findMatchingParent(k.anchor.getNode(),n=>A(n)),A(g));return!1},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.FORMAT_ELEMENT_COMMAND,g=>{var k=v.$getSelection();if(!P(k)||!W(k,a))return!1;var n=k.anchor.getNode();k=k.focus.getNode();if(!A(n)||!A(k))return!1;let [p,r,t]=M(a,n,k);n=Math.max(r.startRow,t.startRow);k=Math.max(r.startColumn,t.startColumn);var x=Math.min(r.startRow,
|
80
|
+
t.startRow);let D=Math.min(r.startColumn,t.startColumn);for(;x<=n;x++)for(let H=D;H<=k;H++){var C=p[x][H].cell;C.setFormat(g);C=C.getChildren();for(let J=0;J<C.length;J++){let N=C[J];v.$isElementNode(N)&&!N.isInline()&&N.setFormat(g)}}return!0},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=v.$getSelection();if(!W(g,a))return!1;P(g)?f.clearHighlight():v.$isRangeSelection(g)&&(g=h.$findMatchingParent(g.anchor.getNode(),k=>A(k)),
|
81
|
+
A(g));return!1},v.COMMAND_PRIORITY_CRITICAL));d&&f.listenersToRemove.add(c.registerCommand(v.KEY_TAB_COMMAND,g=>{var k=v.$getSelection();if(!v.$isRangeSelection(k)||!k.isCollapsed()||!W(k,a))return!1;k=Aa(k.anchor.getNode());if(null===k)return!1;Y(g);k=a.getCordsFromCellNode(k,f.table);ya(f,a,k.x,k.y,g.shiftKey?"backward":"forward");return!0},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.FOCUS_COMMAND,()=>a.isSelected(),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,
|
82
|
+
g=>{let {nodes:k,selection:n}=g;g=n.getStartEndPoints();var p=P(n);p=v.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),G=>A(G))&&null!==h.$findMatchingParent(n.focus.getNode(),G=>A(G))||p;if(1!==k.length||!K(k[0])||!p||null===g)return!1;var [r]=g,t=k[0];g=t.getChildren();p=t.getFirstChildOrThrow().getChildrenSize();t=t.getChildrenSize();var x=h.$findMatchingParent(r.getNode(),G=>A(G)),D=(r=x&&h.$findMatchingParent(x,G=>F(G)))&&h.$findMatchingParent(r,G=>K(G));if(!A(x)||!F(r)||
|
83
|
+
!K(D))return!1;var C=r.getIndexWithinParent(),H=Math.min(D.getChildrenSize()-1,C+t-1);t=x.getIndexWithinParent();x=Math.min(r.getChildrenSize()-1,t+p-1);p=Math.min(t,x);r=Math.min(C,H);t=Math.max(t,x);C=Math.max(C,H);D=D.getChildren();H=0;let J,N;for(x=r;x<=C;x++){var ba=D[x];if(!F(ba))return!1;var ca=g[H];if(!F(ca))return!1;ba=ba.getChildren();ca=ca.getChildren();let G=0;for(let T=p;T<=t;T++){let U=ba[T];if(!A(U))return!1;let wa=ca[G];if(!A(wa))return!1;x===r&&T===p?J=U.getKey():x===C&&T===t&&(N=
|
84
|
+
U.getKey());let Ea=U.getChildren();wa.getChildren().forEach(V=>{v.$isTextNode(V)&&v.$createParagraphNode().append(V);U.append(V)});Ea.forEach(V=>V.remove());G++}H++}J&&N&&(g=Q(),g.set(k[0].getKey(),J,N),v.$setSelection(g));return!0},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.SELECTION_CHANGE_COMMAND,()=>{let g=v.$getSelection(),k=v.$getPreviousSelection();if(v.$isRangeSelection(g)){let {anchor:x,focus:D}=g;var n=x.getNode(),p=D.getNode();n=Aa(n);p=Aa(p);var r=!(!n||
|
85
|
+
!a.is(Ba(n))),t=!(!p||!a.is(Ba(p)));let C=r!==t;t=r&&t;r=g.isBackward();C?(n=g.clone(),n.focus.set(a.getKey(),r?0:a.getChildrenSize(),"element"),v.$setSelection(n),va(c,f)):t&&!n.is(p)&&(f.setAnchorCellForSelection(e(n)),f.setFocusCellForSelection(e(p),!0))}if(g&&!g.is(k)&&(P(g)||P(k))&&f.tableSelection&&!f.tableSelection.is(k))return P(g)&&g.tableKey===f.tableNodeKey?f.updateTableTableSelection(g):!P(g)&&P(k)&&k.tableKey===f.tableNodeKey&&f.updateTableTableSelection(null),!1;f.hasHijackedSelectionStyles&&
|
86
|
+
!a.isSelected()?xa(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&va(c,f);return!1},v.COMMAND_PRIORITY_CRITICAL));return f};exports.getDOMCellFromTarget=ra;exports.getTableObserverFromTableElement=function(a){return a.__lexicalTableSelection}
|
package/LexicalTableNode.d.ts
CHANGED
@@ -21,7 +21,6 @@ export declare class TableNode extends ElementNode {
|
|
21
21
|
createDOM(config: EditorConfig, editor?: LexicalEditor): HTMLElement;
|
22
22
|
updateDOM(): boolean;
|
23
23
|
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
24
|
-
canExtractContents(): false;
|
25
24
|
canBeEmpty(): false;
|
26
25
|
isShadowRoot(): boolean;
|
27
26
|
getCordsFromCellNode(tableCellNode: TableCellNode, table: TableDOMTable): {
|