@lexical/table 0.21.1-nightly.20241211.0 → 0.21.1-nightly.20241213.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 +17 -6
- package/LexicalTable.dev.mjs +17 -6
- package/LexicalTable.prod.js +58 -57
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +4 -4
package/LexicalTable.dev.js
CHANGED
@@ -771,6 +771,7 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
771
771
|
return;
|
772
772
|
}
|
773
773
|
const columnCount = gridMap[0].length;
|
774
|
+
const selectedRowCount = anchorCell.__rowSpan;
|
774
775
|
const nextRow = gridMap[focusEndRow + 1];
|
775
776
|
const nextRowNode = grid.getChildAtIndex(focusEndRow + 1);
|
776
777
|
for (let row = focusEndRow; row >= anchorStartRow; row--) {
|
@@ -786,7 +787,8 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
786
787
|
}
|
787
788
|
// Rows overflowing top have to be trimmed
|
788
789
|
if (row === anchorStartRow && cellStartRow < anchorStartRow) {
|
789
|
-
|
790
|
+
const overflowTop = anchorStartRow - cellStartRow;
|
791
|
+
cell.setRowSpan(cell.__rowSpan - Math.min(selectedRowCount, cell.__rowSpan - overflowTop));
|
790
792
|
}
|
791
793
|
// Rows overflowing bottom have to be trimmed and moved to the next row
|
792
794
|
if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
|
@@ -794,13 +796,22 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
794
796
|
if (!(nextRowNode !== null)) {
|
795
797
|
throw Error(`Expected nextRowNode not to be null`);
|
796
798
|
}
|
797
|
-
|
799
|
+
let insertAfterCell = null;
|
800
|
+
for (let columnIndex = 0; columnIndex < column; columnIndex++) {
|
801
|
+
const currentCellMap = nextRow[columnIndex];
|
802
|
+
const currentCell = currentCellMap.cell;
|
803
|
+
// Checking the cell having startRow as same as nextRow
|
804
|
+
if (currentCellMap.startRow === row + 1) {
|
805
|
+
insertAfterCell = currentCell;
|
806
|
+
}
|
807
|
+
if (currentCell.__colSpan > 1) {
|
808
|
+
columnIndex += currentCell.__colSpan - 1;
|
809
|
+
}
|
810
|
+
}
|
811
|
+
if (insertAfterCell === null) {
|
798
812
|
$insertFirst(nextRowNode, cell);
|
799
813
|
} else {
|
800
|
-
|
801
|
-
cell: previousCell
|
802
|
-
} = nextRow[column - 1];
|
803
|
-
previousCell.insertAfter(cell);
|
814
|
+
insertAfterCell.insertAfter(cell);
|
804
815
|
}
|
805
816
|
}
|
806
817
|
}
|
package/LexicalTable.dev.mjs
CHANGED
@@ -769,6 +769,7 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
769
769
|
return;
|
770
770
|
}
|
771
771
|
const columnCount = gridMap[0].length;
|
772
|
+
const selectedRowCount = anchorCell.__rowSpan;
|
772
773
|
const nextRow = gridMap[focusEndRow + 1];
|
773
774
|
const nextRowNode = grid.getChildAtIndex(focusEndRow + 1);
|
774
775
|
for (let row = focusEndRow; row >= anchorStartRow; row--) {
|
@@ -784,7 +785,8 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
784
785
|
}
|
785
786
|
// Rows overflowing top have to be trimmed
|
786
787
|
if (row === anchorStartRow && cellStartRow < anchorStartRow) {
|
787
|
-
|
788
|
+
const overflowTop = anchorStartRow - cellStartRow;
|
789
|
+
cell.setRowSpan(cell.__rowSpan - Math.min(selectedRowCount, cell.__rowSpan - overflowTop));
|
788
790
|
}
|
789
791
|
// Rows overflowing bottom have to be trimmed and moved to the next row
|
790
792
|
if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
|
@@ -792,13 +794,22 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
792
794
|
if (!(nextRowNode !== null)) {
|
793
795
|
throw Error(`Expected nextRowNode not to be null`);
|
794
796
|
}
|
795
|
-
|
797
|
+
let insertAfterCell = null;
|
798
|
+
for (let columnIndex = 0; columnIndex < column; columnIndex++) {
|
799
|
+
const currentCellMap = nextRow[columnIndex];
|
800
|
+
const currentCell = currentCellMap.cell;
|
801
|
+
// Checking the cell having startRow as same as nextRow
|
802
|
+
if (currentCellMap.startRow === row + 1) {
|
803
|
+
insertAfterCell = currentCell;
|
804
|
+
}
|
805
|
+
if (currentCell.__colSpan > 1) {
|
806
|
+
columnIndex += currentCell.__colSpan - 1;
|
807
|
+
}
|
808
|
+
}
|
809
|
+
if (insertAfterCell === null) {
|
796
810
|
$insertFirst(nextRowNode, cell);
|
797
811
|
} else {
|
798
|
-
|
799
|
-
cell: previousCell
|
800
|
-
} = nextRow[column - 1];
|
801
|
-
previousCell.insertAfter(cell);
|
812
|
+
insertAfterCell.insertAfter(cell);
|
802
813
|
}
|
803
814
|
}
|
804
815
|
}
|
package/LexicalTable.prod.js
CHANGED
@@ -7,118 +7,119 @@
|
|
7
7
|
*/
|
8
8
|
|
9
9
|
'use strict';var h=require("@lexical/utils"),v=require("lexical"),aa=require("@lexical/clipboard");let ba=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
10
|
-
class y extends v.ElementNode{static getType(){return"tablecell"}static clone(a){return new y(a.__headerState,a.__colSpan,a.__width,a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__rowSpan=a.__rowSpan;this.__backgroundColor=a.__backgroundColor}static importDOM(){return{td:()=>({conversion:da,priority:0}),th:()=>({conversion:da,priority:0})}}static importJSON(a){let b=a.rowSpan||1;return
|
10
|
+
class y extends v.ElementNode{static getType(){return"tablecell"}static clone(a){return new y(a.__headerState,a.__colSpan,a.__width,a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__rowSpan=a.__rowSpan;this.__backgroundColor=a.__backgroundColor}static importDOM(){return{td:()=>({conversion:da,priority:0}),th:()=>({conversion:da,priority:0})}}static importJSON(a){let b=a.rowSpan||1;return B(a.headerState,a.colSpan||1,a.width||void 0).setRowSpan(b).setBackgroundColor(a.backgroundColor||null)}constructor(a=
|
11
11
|
x.NO_STATUS,b=1,c,d){super(d);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){a=
|
12
12
|
super.exportDOM(a);if(a.element&&v.isHTMLElement(a.element)){let b=a.element;b.setAttribute("data-temporary-table-cell-lexical-key",this.getKey());b.style.border="1px solid black";1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);b.style.width=`${this.getWidth()||75}px`;b.style.verticalAlign="top";b.style.textAlign="start";null===this.__backgroundColor&&this.hasHeader()&&(b.style.backgroundColor="#f2f3f5")}return a}exportJSON(){return{...super.exportJSON(),
|
13
13
|
backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(a){let b=this.getWritable();b.__colSpan=a;return b}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(a){let b=this.getWritable();b.__rowSpan=a;return b}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a,b=x.BOTH){let c=this.getWritable();c.__headerState=a&b|c.__headerState&
|
14
14
|
~b;return c}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){let b=this.getWritable();b.__width=a;return b}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){let b=this.getWritable();b.__backgroundColor=a;return b}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!==
|
15
15
|
x.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==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}}
|
16
|
-
function da(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=
|
17
|
-
{if(
|
18
|
-
function F(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.");}
|
16
|
+
function da(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=(a&&a.textDecoration||"").split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),f="italic"===a.fontStyle,g=c.includes("underline");return{after:m=>{0===m.length&&m.push(v.$createParagraphNode());return m},forChild:(m,p)=>
|
17
|
+
{if(C(p)&&!v.$isElementNode(m)){p=v.$createParagraphNode();if(v.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;v.$isTextNode(m)&&(d&&m.toggleFormat("bold"),e&&m.toggleFormat("strikethrough"),f&&m.toggleFormat("italic"),g&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function B(a=x.NO_STATUS,b=1,c){return v.$applyNodeReplacement(new y(a,b,c))}function C(a){return a instanceof y}let ea=v.createCommand("INSERT_TABLE_COMMAND");var E;
|
18
|
+
function F(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.");}E=F&&F.__esModule&&Object.prototype.hasOwnProperty.call(F,"default")?F["default"]:F;
|
19
19
|
class I extends v.ElementNode{static getType(){return"tablerow"}static clone(a){return new I(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return J(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,
|
20
|
-
a.theme.tableRow);return b}extractWithChild(a,b,c){return"html"===c}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;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{after:c=>h.$descendantsMatching(c,
|
20
|
+
a.theme.tableRow);return b}extractWithChild(a,b,c){return"html"===c}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;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{after:c=>h.$descendantsMatching(c,C),node:J(b)}}function J(a){return v.$applyNodeReplacement(new I(a))}
|
21
21
|
function K(a){return a instanceof I}let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,ia=ha&&"documentMode"in document?document.documentMode:null,ja=ha&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);ha&&"InputEvent"in window&&!ia?"getTargetRanges"in new window.InputEvent("input"):!1;
|
22
|
-
function ka(a,b,c=!0){let d=la();for(let f=0;f<a;f++){let g=J();for(let m=0;m<b;m++){var e=x.NO_STATUS;"object"===typeof c?(0===f&&c.rows&&(e|=x.ROW),0===m&&c.columns&&(e|=x.COLUMN)):c&&(0===f&&(e|=x.ROW),0===m&&(e|=x.COLUMN));e=
|
22
|
+
function ka(a,b,c=!0){let d=la();for(let f=0;f<a;f++){let g=J();for(let m=0;m<b;m++){var e=x.NO_STATUS;"object"===typeof c?(0===f&&c.rows&&(e|=x.ROW),0===m&&c.columns&&(e|=x.COLUMN)):c&&(0===f&&(e|=x.ROW),0===m&&(e|=x.COLUMN));e=B(e);let p=v.$createParagraphNode();p.append(v.$createTextNode());e.append(p);g.append(e)}d.append(g)}return d}function ma(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table row.");}
|
23
23
|
function na(a){a=h.$findMatchingParent(a,b=>L(b));if(L(a))return a;throw Error("Expected table cell to be inside of table.");}function oa(a,b){let c=na(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)}}let pa=(a,b)=>a===x.BOTH||a===b?b:x.NO_STATUS;function M(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}
|
24
|
-
function qa(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function O(a,b,c){let [d,e,f]=ra(a,b,c);null===e&&
|
25
|
-
function ra(a,b,c){function d(p){let r=e[p];void 0===r&&(e[p]=r=[]);return r}let e=[],f=null,g=null;a=a.getChildren();for(let p=0;p<a.length;p++){var m=a[p];K(m)||
|
26
|
-
f,g]}function Q(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,
|
24
|
+
function qa(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function O(a,b,c){let [d,e,f]=ra(a,b,c);null===e&&E(207);null===f&&E(208);return[d,e,f]}
|
25
|
+
function ra(a,b,c){function d(p){let r=e[p];void 0===r&&(e[p]=r=[]);return r}let e=[],f=null,g=null;a=a.getChildren();for(let p=0;p<a.length;p++){var m=a[p];K(m)||E(209);for(let r=m.getFirstChild(),k=0;null!=r;r=r.getNextSibling()){C(r)||E(147);for(m=d(p);void 0!==m[k];)k++;m={cell:r,startColumn:k,startRow:p};let {__rowSpan:l,__colSpan:n}=r;for(let q=0;q<l&&!(p+q>=a.length);q++){let u=d(p+q);for(let t=0;t<n;t++)u[k+t]=m}null!==b&&null===f&&b.is(r)&&(f=m);null!==c&&null===g&&c.is(r)&&(g=m)}}return[e,
|
26
|
+
f,g]}function Q(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,C),C(a)||E(148)):(a=h.$findMatchingParent(a.getNode(),C),C(a)||E(148)));let b=a.getParent();K(b)||E(149);let c=b.getParent();L(c)||E(210);return[a,b,c]}
|
27
27
|
function sa(a,b,c){function d(n){let {cell:q,startColumn:u,startRow:t}=n;e=Math.min(e,u);f=Math.min(f,t);g=Math.max(g,u+q.__colSpan-1);m=Math.max(m,t+q.__rowSpan-1)}let e=Math.min(b.startColumn,c.startColumn),f=Math.min(b.startRow,c.startRow),g=Math.max(b.startColumn+b.cell.__colSpan-1,c.startColumn+c.cell.__colSpan-1),m=Math.max(b.startRow+b.cell.__rowSpan-1,c.startRow+c.cell.__rowSpan-1);b=e;c=f;for(var p=e,r=f;e<b||f<c||g>p||m>r;){if(e<b){var k=r-c;--b;for(var l=0;l<=k;l++)d(a[c+l][b])}if(f<c)for(k=
|
28
28
|
p-b,--c,l=0;l<=k;l++)d(a[c][b+l]);if(g>p)for(k=r-c,p+=1,l=0;l<=k;l++)d(a[c+l][p]);if(m>r)for(k=p-b,r+=1,l=0;l<=k;l++)d(a[r][b+l])}return{maxColumn:g,maxRow:m,minColumn:e,minRow:f}}
|
29
29
|
function ta(a){let [b,,c]=Q(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let f=Array(d);for(var g=0;g<d;g++)f[g]=Array(e);for(e=0;e<d;e++){g=a[e].getChildren();let m=0;for(let p=0;p<g.length;p++){for(;f[e][m];)m++;let r=g[p],k=r.__rowSpan||1,l=r.__colSpan||1;for(let n=0;n<k;n++)for(let q=0;q<l;q++)f[e+n][m+q]=r;if(b===r)return{colSpan:l,columnIndex:m,rowIndex:e,rowSpan:k};m+=l}}return null}
|
30
|
-
function ua(a){let [[b,c,d,e],[f,g,m,p]]=["anchor","focus"].map(r=>{const k=a[r].getNode(),l=h.$findMatchingParent(k,
|
30
|
+
function ua(a){let [[b,c,d,e],[f,g,m,p]]=["anchor","focus"].map(r=>{const k=a[r].getNode(),l=h.$findMatchingParent(k,C);C(l)||E(238,r,k.getKey(),k.getType());const n=l.getParent();K(n)||E(239,r);const q=n.getParent();L(q)||E(240,r);return[k,l,n,q]});e.is(p)||E(241);return{anchorCell:c,anchorNode:b,anchorRow:d,anchorTable:e,focusCell:g,focusNode:f,focusRow:m,focusTable:p}}
|
31
31
|
class va{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]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return R(a)&&this.tableKey===
|
32
32
|
a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus)}set(a,b,c){this.dirty=this.dirty||a!==this.tableKey||b!==this.anchor.key||c!==this.focus.key;this.tableKey=a;this.anchor.key=b;this.focus.key=c;this._cachedNodes=null}clone(){return new va(this.tableKey,v.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),v.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b=
|
33
|
-
0;this.getNodes().filter(
|
34
|
-
d.colSpan-1),g=Math.min(c.rowIndex,d.rowIndex);c=Math.max(c.rowIndex+c.rowSpan-1,d.rowIndex+d.rowSpan-1);return{fromX:Math.min(e,f),fromY:Math.min(g,c),toX:Math.max(e,f),toY:Math.max(g,c)}}getNodes(){if(!this.isValid())return[];var a=this._cachedNodes;if(null!==a)return a;let {anchorTable:b,anchorCell:c,focusCell:d}=ua(this);a=d.getParents()[1];if(a!==b)return b.isParentOf(d)?(a=a.getParent(),null==a&&
|
35
|
-
a.getKey(),d.getKey())),this.getNodes();let [e,f,g]=O(b,c,d),{minColumn:m,maxColumn:p,minRow:r,maxRow:k}=sa(e,f,g),l=new Map([[b.getKey(),b]]);a=null;for(let n=r;n<=k;n++)for(let q=m;q<=p;q++){let {cell:u}=e[n][q],t=u.getParent();K(t)||
|
33
|
+
0;this.getNodes().filter(C).forEach(c=>{c=c.getFirstChild();v.$isParagraphNode(c)&&(b|=c.getTextFormat())});return 0!==(b&v.TEXT_TYPE_TO_FORMAT[a])}insertNodes(a){let b=this.focus.getNode();v.$isElementNode(b)||E(151);v.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){let {anchorCell:a,focusCell:b}=ua(this);var c=ta(a);null===c&&E(153);let d=ta(b);null===d&&E(155);let e=Math.min(c.columnIndex,d.columnIndex),f=Math.max(c.columnIndex+c.colSpan-1,d.columnIndex+
|
34
|
+
d.colSpan-1),g=Math.min(c.rowIndex,d.rowIndex);c=Math.max(c.rowIndex+c.rowSpan-1,d.rowIndex+d.rowSpan-1);return{fromX:Math.min(e,f),fromY:Math.min(g,c),toX:Math.max(e,f),toY:Math.max(g,c)}}getNodes(){if(!this.isValid())return[];var a=this._cachedNodes;if(null!==a)return a;let {anchorTable:b,anchorCell:c,focusCell:d}=ua(this);a=d.getParents()[1];if(a!==b)return b.isParentOf(d)?(a=a.getParent(),null==a&&E(159),this.set(this.tableKey,d.getKey(),a.getKey())):(a=b.getParent(),null==a&&E(158),this.set(this.tableKey,
|
35
|
+
a.getKey(),d.getKey())),this.getNodes();let [e,f,g]=O(b,c,d),{minColumn:m,maxColumn:p,minRow:r,maxRow:k}=sa(e,f,g),l=new Map([[b.getKey(),b]]);a=null;for(let n=r;n<=k;n++)for(let q=m;q<=p;q++){let {cell:u}=e[n][q],t=u.getParent();K(t)||E(160);t!==a&&(l.set(t.getKey(),t),a=t);l.has(u.getKey())||wa(u,w=>{l.set(w.getKey(),w)})}a=Array.from(l.values());v.isCurrentlyReadOnlyMode()||(this._cachedNodes=a);return a}getTextContent(){let a=this.getNodes().filter(c=>C(c)),b="";for(let c=0;c<a.length;c++){let d=
|
36
36
|
a[c],e=d.__parent,f=(a[c+1]||{}).__parent;b+=d.getTextContent()+(f!==e?"\n":"\t")}return b}}function R(a){return a instanceof va}function xa(){let a=v.$createPoint("root",0,"element"),b=v.$createPoint("root",0,"element");return new va("root",a,b)}function wa(a,b){a=[[a]];for(var c=a.at(-1);void 0!==c&&0<a.length;c=a.at(-1))c=c.pop(),void 0===c?a.pop():!1!==b(c)&&v.$isElementNode(c)&&a.push(c.getChildren())}
|
37
|
-
function ya(a,b=v.$getEditor()){let c=v.$getNodeByKey(a);L(c)||
|
37
|
+
function ya(a,b=v.$getEditor()){let c=v.$getNodeByKey(a);L(c)||E(231,a);b=S(c,b.getElementByKey(a));null===b&&E(232,a);return{tableElement:b,tableNode:c}}
|
38
38
|
class za{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.shouldCheckSelection=this.isSelecting=this.hasHijackedSelectionStyles=!1;this.abortController=new AbortController;this.listenerOptions={signal:this.abortController.signal};this.nextFocus=
|
39
39
|
null;this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners");Array.from(this.listenersToRemove).forEach(a=>a());this.listenersToRemove.clear()}$lookup(){return ya(this.tableNodeKey,this.editor)}trackTable(){let a=new MutationObserver(b=>{this.editor.getEditorState().read(()=>{let c=!1;for(let f=0;f<b.length;f++){const g=b[f].target.nodeName;if("TABLE"===g||"TBODY"===g||"THEAD"===g||"TR"===g){c=!0;break}}if(c){var {tableNode:d,tableElement:e}=
|
40
40
|
this.$lookup();this.table=T(d,e)}},{editor:this.editor})});this.editor.getEditorState().read(()=>{let {tableNode:b,tableElement:c}=this.$lookup();this.table=T(b,c);a.observe(c,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(){let a=this.editor;this.isHighlightingCells=!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();
|
41
41
|
let {tableNode:b,tableElement:c}=this.$lookup(),d=T(b,c);Aa(a,d,null);null!==v.$getSelection()&&(v.$setSelection(null),a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){let a=this.editor,{tableElement:b}=this.$lookup();h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){let {tableElement:a}=this.$lookup();h.addClassNamesToElement(a,this.editor._config.theme.tableSelection);
|
42
|
-
this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(a){if(null!==a){a.tableKey!==this.tableNodeKey&&
|
42
|
+
this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(a){if(null!==a){a.tableKey!==this.tableNodeKey&&E(233,a.tableKey,this.tableNodeKey);let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.$disableHighlightStyle();this.updateDOMSelection();Aa(b,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return this.shouldCheckSelection?(this.shouldCheckSelection=!1,!0):!1}setNextFocus(a){this.nextFocus=
|
43
43
|
a}getAndClearNextFocus(){let {nextFocus:a}=this;null!==a&&(this.nextFocus=null);return a}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){let a=v.getDOMSelection(this.editor._window);a&&0<a.rangeCount&&a.removeAllRanges()}}$setFocusCellForSelection(a,b=!1){let c=this.editor,{tableNode:d}=this.$lookup();var e=a.x;let f=a.y;this.focusCell=a;if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.$disableHighlightStyle();else if(e===
|
44
44
|
this.focusX&&f===this.focusY)return!1;this.focusX=e;this.focusY=f;return this.isHighlightingCells&&(b=U(d,v.$getNearestNodeFromDOMNode(a.elem,void 0)),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==b)?(this.focusCellNodeKey=b.getKey(),a=this.$getAnchorTableCellOrThrow(),d.getKey(),a.getKey(),b.getKey(),e=v.$getSelection(),e=R(e)?e.clone():xa(),e.set(d.getKey(),a.getKey(),b.getKey()),this.tableSelection=e,v.$setSelection(this.tableSelection),c.dispatchCommand(v.SELECTION_CHANGE_COMMAND,
|
45
|
-
void 0),Aa(c,this.table,this.tableSelection),!0):!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){let a=this.$getAnchorTableCell();null===a&&
|
46
|
-
a.x;this.anchorY=a.y;let {tableNode:b}=this.$lookup();a=U(b,v.$getNearestNodeFromDOMNode(a.elem,void 0));null!==a&&(a=a.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():xa(),this.anchorCellNodeKey=a)}$formatCells(a){let b=v.$getSelection();R(b)||
|
47
|
-
e.set(p.getKey(),p.getChildrenSize(),"element");c.formatText(a,m)});v.$setSelection(b);this.editor.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){let {editor:a}=this,b=v.$getNodeByKey(this.tableNodeKey);if(!L(b))throw Error("Expected TableNode.");var c=v.$getSelection();R(c)||
|
48
|
-
v.$createTextNode();e.append(f);d.append(e);d.getChildren().forEach(g=>{g!==e&&g.remove()})}}),Aa(a,this.table,null),v.$setSelection(null),a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0))}}function S(a,b){if(!b)return b;a="TABLE"===b.nodeName?b:a.getDOMSlot(b).element;"TABLE"!==a.nodeName&&
|
45
|
+
void 0),Aa(c,this.table,this.tableSelection),!0):!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){let a=this.$getAnchorTableCell();null===a&&E(234);return a}$getFocusTableCell(){return this.focusCellNodeKey?v.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){let a=this.$getFocusTableCell();null===a&&E(235);return a}$setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=
|
46
|
+
a.x;this.anchorY=a.y;let {tableNode:b}=this.$lookup();a=U(b,v.$getNearestNodeFromDOMNode(a.elem,void 0));null!==a&&(a=a.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():xa(),this.anchorCellNodeKey=a)}$formatCells(a){let b=v.$getSelection();R(b)||E(236);let c=v.$createRangeSelection(),d=c.anchor,e=c.focus,f=b.getNodes().filter(C);0<f.length||E(237);let g=f[0].getFirstChild(),m=v.$isParagraphNode(g)?g.getFormatFlags(a,null):null;f.forEach(p=>{d.set(p.getKey(),0,"element");
|
47
|
+
e.set(p.getKey(),p.getChildrenSize(),"element");c.formatText(a,m)});v.$setSelection(b);this.editor.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){let {editor:a}=this,b=v.$getNodeByKey(this.tableNodeKey);if(!L(b))throw Error("Expected TableNode.");var c=v.$getSelection();R(c)||E(11);c=c.getNodes().filter(C);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(),f=
|
48
|
+
v.$createTextNode();e.append(f);d.append(e);d.getChildren().forEach(g=>{g!==e&&g.remove()})}}),Aa(a,this.table,null),v.$setSelection(null),a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0))}}function S(a,b){if(!b)return b;a="TABLE"===b.nodeName?b:a.getDOMSlot(b).element;"TABLE"!==a.nodeName&&E(245,b.nodeName);return a}function U(a,b){for(let c=b,d=null;null!==c;c=c.getParent()){if(a.is(c))return d;C(c)&&(d=c)}return null}
|
49
49
|
let Ba=[[v.KEY_ARROW_DOWN_COMMAND,"down"],[v.KEY_ARROW_UP_COMMAND,"up"],[v.KEY_ARROW_LEFT_COMMAND,"backward"],[v.KEY_ARROW_RIGHT_COMMAND,"forward"]],Ca=[v.DELETE_WORD_COMMAND,v.DELETE_LINE_COMMAND,v.DELETE_CHARACTER_COMMAND],Da=[v.KEY_BACKSPACE_COMMAND,v.KEY_DELETE_COMMAND];
|
50
|
-
function Ea(a,b,c,d){let e=c.getRootElement(),f=c._window;null!==e&&null!==f||
|
50
|
+
function Ea(a,b,c,d){let e=c.getRootElement(),f=c._window;null!==e&&null!==f||E(246);let g=new za(c,a.getKey()),m=S(a,b);Fa(m,g);g.listenersToRemove.add(()=>{Ga(m)===g&&delete m.__lexicalTableSelection});let p=()=>{if(!g.isSelecting){var k=()=>{g.isSelecting=!1;f.removeEventListener("mouseup",k);f.removeEventListener("mousemove",l)},l=n=>{if(1!==(n.buttons&1)&&g.isSelecting)g.isSelecting=!1,f.removeEventListener("mouseup",k),f.removeEventListener("mousemove",l);else{var q=!m.contains(n.target),u=
|
51
51
|
null;if(q)for(const t of document.elementsFromPoint(n.clientX,n.clientY)){if(u=m.contains(t)?Ha(t):null)break}else u=Ha(n.target);!u||null!==g.focusCell&&u.elem===g.focusCell.elem||(g.setNextFocus({focusCell:u,override:q}),c.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0))}};g.isSelecting=!0;f.addEventListener("mouseup",k,g.listenerOptions);f.addEventListener("mousemove",l,g.listenerOptions)}};m.addEventListener("mousedown",k=>{if(0===k.button&&f){var l=Ha(k.target);null!==l&&c.update(()=>{const n=
|
52
52
|
v.$getPreviousSelection();if(ja&&k.shiftKey&&V(n,a)&&(v.$isRangeSelection(n)||R(n))){const q=n.anchor.getNode(),u=U(a,n.anchor.getNode());u?(g.$setAnchorCellForSelection(W(g,u)),g.$setFocusCellForSelection(l),X(k)):(a.isBefore(q)?a.selectStart():a.selectEnd()).anchor.set(n.anchor.key,n.anchor.offset,n.anchor.type)}else g.$setAnchorCellForSelection(l)});p()}},g.listenerOptions);f.addEventListener("mousedown",k=>{0===k.button&&c.update(()=>{const l=v.$getSelection(),n=k.target;R(l)&&l.tableKey===g.tableNodeKey&&
|
53
53
|
e.contains(n)&&g.$clearHighlight()})},g.listenerOptions);for(let [k,l]of Ba)g.listenersToRemove.add(c.registerCommand(k,n=>Ia(c,n,l,a,g),v.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(v.KEY_ESCAPE_COMMAND,k=>{var l=v.$getSelection();return R(l)&&(l=U(a,l.focus.getNode()),null!==l)?(X(k),l.selectEnd(),!0):!1},v.COMMAND_PRIORITY_HIGH));b=k=>()=>{var l=v.$getSelection();if(!V(l,a))return!1;if(R(l))return g.$clearText(),!0;if(v.$isRangeSelection(l)){var n=U(a,l.anchor.getNode());
|
54
|
-
if(!
|
54
|
+
if(!C(n))return!1;var q=l.anchor.getNode();n=l.focus.getNode();q=a.isParentOf(q);n=a.isParentOf(n);if(q&&!n||n&&!q)return g.$clearText(),!0;n=(l=h.$findMatchingParent(l.anchor.getNode(),u=>v.$isElementNode(u)))&&h.$findMatchingParent(l,u=>v.$isElementNode(u)&&C(u.getParent()));if(!v.$isElementNode(n)||!v.$isElementNode(l))return!1;if(k===v.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0}return!1};for(let k of Ca)g.listenersToRemove.add(c.registerCommand(k,b(k),v.COMMAND_PRIORITY_CRITICAL));
|
55
55
|
let r=k=>{const l=v.$getSelection();if(!R(l)&&!v.$isRangeSelection(l))return!1;const n=a.isParentOf(l.anchor.getNode()),q=a.isParentOf(l.focus.getNode());if(n!==q){k=n?"focus":"anchor";const {key:u,offset:t,type:w}=l[k];a[l[n?"anchor":"focus"].isBefore(l[k])?"selectPrevious":"selectNext"]()[k].set(u,t,w);return!1}return R(l)?(k&&(k.preventDefault(),k.stopPropagation()),g.$clearText(),!0):!1};for(let k of Da)g.listenersToRemove.add(c.registerCommand(k,r,v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.CUT_COMMAND,
|
56
56
|
k=>{let l=v.$getSelection();if(l){if(!R(l)&&!v.$isRangeSelection(l))return!1;void aa.copyToClipboard(c,h.objectKlassEquals(k,ClipboardEvent)?k:null,aa.$getClipboardDataFromSelection(l));k=r(k);return v.$isRangeSelection(l)?(l.removeText(),!0):k}return!1},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.FORMAT_TEXT_COMMAND,k=>{let l=v.$getSelection();if(!V(l,a))return!1;if(R(l))return g.$formatCells(k),!0;v.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),
|
57
|
-
n=>
|
58
|
-
new Set;for(;w<=n;w++)for(let G=
|
57
|
+
n=>C(n)),C(k));return!1},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.FORMAT_ELEMENT_COMMAND,k=>{var l=v.$getSelection();if(!R(l)||!V(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!C(n)||!C(l))return!1;let [q,u,t]=O(a,n,l);n=Math.max(u.startRow+u.cell.__rowSpan-1,t.startRow+t.cell.__rowSpan-1);l=Math.max(u.startColumn+u.cell.__colSpan-1,t.startColumn+t.cell.__colSpan-1);var w=Math.min(u.startRow,t.startRow);let D=Math.min(u.startColumn,t.startColumn),z=
|
58
|
+
new Set;for(;w<=n;w++)for(let G=D;G<=l;G++){var A=q[w][G].cell;if(!z.has(A)){z.add(A);A.setFormat(k);A=A.getChildren();for(let H=0;H<A.length;H++){let N=A[H];v.$isElementNode(N)&&!N.isInline()&&N.setFormat(k)}}}return!0},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=v.$getSelection();if(!V(l,a))return!1;if(R(l))g.$clearHighlight();else if(v.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),q=>C(q));if(!C(n))return!1;
|
59
59
|
if("string"===typeof k&&(l=Ja(c,l,a)))return La(l,a,[v.$createTextNode(k)]),!0}return!1},v.COMMAND_PRIORITY_CRITICAL));d&&g.listenersToRemove.add(c.registerCommand(v.KEY_TAB_COMMAND,k=>{var l=v.$getSelection();if(!v.$isRangeSelection(l)||!l.isCollapsed()||!V(l,a))return!1;var n=Ma(l.anchor.getNode());if(null===n||!a.is(Na(n)))return!1;X(k);a:{k=k.shiftKey?"previous":"next";l="next"===k?"getNextSibling":"getPreviousSibling";let u="next"===k?"getFirstChild":"getLastChild";var q=n[l]();if(v.$isElementNode(q))q.selectEnd();
|
60
|
-
else{n=h.$findMatchingParent(n,K);null===n&&
|
61
|
-
var q=R(n);q=v.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),H=>
|
62
|
-
1,u+t-1);t=w.getIndexWithinParent();w=Math.min(
|
63
|
-
H++}
|
64
|
-
k.isCollapsed()){var q=k.anchor.getNode();n=a.getFirstChild();q=Ma(q);if(null!==q&&K(n)){let w=n.getFirstChild();if(
|
60
|
+
else{n=h.$findMatchingParent(n,K);null===n&&E(247);for(q=n[l]();K(q);q=q[l]()){let t=q[u]();if(v.$isElementNode(t)){t.selectEnd();break a}}l=h.$findMatchingParent(n,L);null===l&&E(248);"next"===k?l.selectNext():l.selectPrevious()}}return!0},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.FOCUS_COMMAND,()=>a.isSelected(),v.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(v.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();
|
61
|
+
var q=R(n);q=v.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),H=>C(H))&&null!==h.$findMatchingParent(n.focus.getNode(),H=>C(H))||q;if(1!==l.length||!L(l[0])||!q||null===k)return!1;var [u]=k,t=l[0];k=t.getChildren();q=t.getFirstChildOrThrow().getChildrenSize();t=t.getChildrenSize();var w=h.$findMatchingParent(u.getNode(),H=>C(H)),D=w&&h.$findMatchingParent(w,H=>K(H)),z=D&&h.$findMatchingParent(D,H=>L(H));if(!C(w)||!K(D)||!L(z))return!1;u=D.getIndexWithinParent();var A=Math.min(z.getChildrenSize()-
|
62
|
+
1,u+t-1);t=w.getIndexWithinParent();w=Math.min(D.getChildrenSize()-1,t+q-1);q=Math.min(t,w);D=Math.min(u,A);t=Math.max(t,w);u=Math.max(u,A);z=z.getChildren();for(A=0;D<=u;D++){w=z[D];if(!K(w))return!1;var G=k[A];if(!K(G))return!1;w=w.getChildren();G=G.getChildren();let H=0;for(let N=q;N<=t;N++){let P=w[N];if(!C(P))return!1;let Ka=G[H];if(!C(Ka))return!1;let Ya=P.getChildren();Ka.getChildren().forEach(ca=>{v.$isTextNode(ca)&&v.$createParagraphNode().append(ca);P.append(ca)});Ya.forEach(ca=>ca.remove());
|
63
|
+
H++}A++}return!0},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.SELECTION_CHANGE_COMMAND,()=>{let k=v.$getSelection(),l=v.$getPreviousSelection();var n=g.getAndClearNextFocus();if(null!==n){({focusCell:n}=n);if(R(k)&&k.tableKey===g.tableNodeKey){if(n.x===g.focusX&&n.y===g.focusY)return!1;g.$setFocusCellForSelection(n);return!0}if(n!==g.anchorCell&&V(k,a))return g.$setFocusCellForSelection(n),!0}if(g.getAndClearShouldCheckSelection()&&v.$isRangeSelection(l)&&v.$isRangeSelection(k)&&
|
64
|
+
k.isCollapsed()){var q=k.anchor.getNode();n=a.getFirstChild();q=Ma(q);if(null!==q&&K(n)){let w=n.getFirstChild();if(C(w)&&a.is(h.$findMatchingParent(q,D=>D.is(a)||D.is(w))))return w.selectStart(),!0}}if(v.$isRangeSelection(k)){let {anchor:w,focus:D}=k;q=w.getNode();n=D.getNode();var u=Ma(q),t=Ma(n);let z=!(!u||!a.is(Na(u))),A=!(!t||!a.is(Na(t)));q=z!==A;let G=z&&A;n=k.isBackward();q?(q=k.clone(),A?([t]=O(a,t,t),u=t[0][0].cell,t=t[t.length-1].at(-1).cell,q.focus.set(n?u.getKey():t.getKey(),n?u.getChildrenSize():
|
65
65
|
t.getChildrenSize(),"element")):z&&([t]=O(a,u,u),u=t[0][0].cell,t=t[t.length-1].at(-1).cell,q.anchor.set(n?t.getKey():u.getKey(),n?t.getChildrenSize():0,"element")),v.$setSelection(q),Oa(c,g)):G&&!u.is(t)&&(g.$setAnchorCellForSelection(W(g,u)),g.$setFocusCellForSelection(W(g,t),!0))}else k&&R(k)&&k.is(l)&&k.tableKey===a.getKey()&&(n=v.getDOMSelection(f))&&n.anchorNode&&n.focusNode&&(q=(q=v.$getNearestNodeFromDOMNode(n.focusNode))&&!a.isParentOf(q),u=(u=v.$getNearestNodeFromDOMNode(n.anchorNode))&&
|
66
66
|
a.isParentOf(u),q&&u&&0<n.rangeCount&&(q=v.$createRangeSelectionFromDom(n,c)))&&(q.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),n.removeAllRanges(),v.$setSelection(q));if(k&&!k.is(l)&&(R(k)||R(l))&&g.tableSelection&&!g.tableSelection.is(l))return R(k)&&k.tableKey===g.tableNodeKey?g.$updateTableTableSelection(k):!R(k)&&R(l)&&l.tableKey===g.tableNodeKey&&g.$updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?Pa(c,g):!g.hasHijackedSelectionStyles&&
|
67
|
-
a.isSelected()&&Oa(c,g);return!1},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.INSERT_PARAGRAPH_COMMAND,()=>{var k=v.$getSelection();return v.$isRangeSelection(k)&&k.isCollapsed()&&V(k,a)?(k=Ja(c,k,a))?(La(k,a),!0):!1:!1},v.COMMAND_PRIORITY_CRITICAL));return g}function Fa(a,b){null!==Ga(a)&&
|
67
|
+
a.isSelected()&&Oa(c,g);return!1},v.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(v.INSERT_PARAGRAPH_COMMAND,()=>{var k=v.$getSelection();return v.$isRangeSelection(k)&&k.isCollapsed()&&V(k,a)?(k=Ja(c,k,a))?(La(k,a),!0):!1:!1},v.COMMAND_PRIORITY_CRITICAL));return g}function Fa(a,b){null!==Ga(a)&&E(205);a.__lexicalTableSelection=b}function Ga(a){return a.__lexicalTableSelection||null}
|
68
68
|
function Ha(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}
|
69
69
|
function T(a,b){var c=S(a,b);a=[];b={columns:0,domRows:a,rows:0};var d=c.querySelector("tr");let e=c=0;for(a.length=0;null!=d;){var f=d.nodeName;if("TD"===f||"TH"===f){f=d;f={elem:f,hasBackgroundColor:""!==f.style.backgroundColor,highlighted:!1,x:c,y:e};d._cell=f;let g=a[e];void 0===g&&(g=a[e]=[]);g[c]=f}else if(f=d.firstChild,null!=f){d=f;continue}f=d.nextSibling;if(null!=f)c++,d=f;else if(f=d.parentNode,null!=f){d=f.nextSibling;if(null==d)break;e++;c=0}}b.columns=c+1;b.rows=e+1;return b}
|
70
70
|
function Aa(a,b,c){let d=new Set(c?c.getNodes():[]);Qa(b,(e,f)=>{let g=e.elem;d.has(f)?(e.highlighted=!0,Ra(a,e)):(e.highlighted=!1,Sa(a,e),g.getAttribute("style")||g.removeAttribute("style"))})}function Qa(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 f=d[e];if(!f)continue;let g=v.$getNearestNodeFromDOMNode(f.elem);null!==g&&b(f,g,{x:e,y:c})}}}function Oa(a,b){b.$disableHighlightStyle();Qa(b.table,c=>{c.highlighted=!0;Ra(a,c)})}
|
71
71
|
function Pa(a,b){b.$enableHighlightStyle();Qa(b.table,c=>{let d=c.elem;c.highlighted=!1;Sa(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
|
72
72
|
let Ta=(a,b,c,d,e)=>{const f="forward"===e;switch(e){case "backward":case "forward":return c!==(f?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(f?1:-1),d,a.table),f?a.selectStart():a.selectEnd()):d!==(f?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(f?0:a.table.columns-1,d+(f?1:-1),a.table),f?a.selectStart():a.selectEnd()):f?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!==
|
73
73
|
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}};function Ua(a,b){let c;if(b.startColumn===a.minColumn)c="minColumn";else if(b.startColumn+b.cell.__colSpan-1===a.maxColumn)c="maxColumn";else return null;if(b.startRow===a.minRow)a="minRow";else if(b.startRow+b.cell.__rowSpan-1===a.maxRow)a="maxRow";else return null;return[c,a]}function Va([a,b]){return["minColumn"===a?"maxColumn":"minColumn","minRow"===b?"maxRow":"minRow"]}
|
74
|
-
function Y(a,b,[c,d]){let e=b[d];a=a[e];void 0===a&&
|
75
|
-
function Wa(a,b,c,d,e){d=sa(b,c,d);let {minColumn:f,maxColumn:g,minRow:m,maxRow:p}=d;var r=1;let k=1,l=1,n=1;var q=b[m];let u=b[p];for(let P=f;P<=g;P++)r=Math.max(r,q[P].cell.__rowSpan),n=Math.max(n,u[P].cell.__rowSpan);for(q=m;q<=p;q++)k=Math.max(k,b[q][f].cell.__colSpan),l=Math.max(l,b[q][g].cell.__colSpan);let {topSpan:t,leftSpan:w,bottomSpan:
|
76
|
-
"maxColumn"===
|
77
|
-
function V(a,b){if(v.$isRangeSelection(a)||R(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}function Ra(a,b){b=b.elem;a=a._config.theme;let c=v.$getNearestNodeFromDOMNode(b);
|
74
|
+
function Y(a,b,[c,d]){let e=b[d];a=a[e];void 0===a&&E(250,d,String(e));b=b[c];d=a[b];void 0===d&&E(250,c,String(b));return d}
|
75
|
+
function Wa(a,b,c,d,e){d=sa(b,c,d);let {minColumn:f,maxColumn:g,minRow:m,maxRow:p}=d;var r=1;let k=1,l=1,n=1;var q=b[m];let u=b[p];for(let P=f;P<=g;P++)r=Math.max(r,q[P].cell.__rowSpan),n=Math.max(n,u[P].cell.__rowSpan);for(q=m;q<=p;q++)k=Math.max(k,b[q][f].cell.__colSpan),l=Math.max(l,b[q][g].cell.__colSpan);let {topSpan:t,leftSpan:w,bottomSpan:D,rightSpan:z}={bottomSpan:n,leftSpan:k,rightSpan:l,topSpan:r};r=Ua(d,c);null===r&&E(249,c.cell.getKey());let [A,G]=Va(r);r=d[A];d=d[G];"forward"===e?r+=
|
76
|
+
"maxColumn"===A?1:w:"backward"===e?r-="minColumn"===A?1:z:"down"===e?d+="maxRow"===G?1:t:"up"===e&&(d-="minRow"===G?1:D);e=b[d];if(void 0===e)return!1;d=e[r];if(void 0===d)return!1;e=sa(b,c,d);(c=Ua(e,c))?b=[Y(b,e,c),Y(b,e,Va(c))]:(c=Ua(e,d))?b=[Y(b,e,Va(c)),Y(b,e,c)]:(c=["minColumn","minRow"],b=[Y(b,e,c),Y(b,e,Va(c))]);let [H,N]=b;b=W(a,H.cell);c=W(a,N.cell);a.$setAnchorCellForSelection(b);a.$setFocusCellForSelection(c,!0);return!0}
|
77
|
+
function V(a,b){if(v.$isRangeSelection(a)||R(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}function Ra(a,b){b=b.elem;a=a._config.theme;let c=v.$getNearestNodeFromDOMNode(b);C(c)||E(131);h.addClassNamesToElement(b,a.tableCellSelected)}function Sa(a,b){b=b.elem;let c=v.$getNearestNodeFromDOMNode(b);C(c)||E(131);h.removeClassNamesFromElement(b,a._config.theme.tableCellSelected)}function Ma(a){a=h.$findMatchingParent(a,C);return C(a)?a:null}
|
78
78
|
function Na(a){a=h.$findMatchingParent(a,L);return L(a)?a:null}function Xa(a){for(let b=a,c=a;null!==c;b=c,c=c.getParent())if(v.$isElementNode(c))if(c!==b&&c.getFirstChild()!==b)break;else if(!c.isInline())return c;return null}
|
79
79
|
function Ia(a,b,c,d,e){if(("up"===c||"down"===c)&&Za(a))return!1;var f=v.$getSelection();if(!V(f,d)){if(v.$isRangeSelection(f)){if("backward"===c){if(0<f.focus.offset)return!1;c=Xa(f.focus.getNode());if(!c)return!1;c=c.getPreviousSibling();if(!L(c))return!1;X(b);b.shiftKey?f.focus.set(c.getParentOrThrow().getKey(),c.getIndexWithinParent(),"element"):c.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c)){var g=f.focus.getNode();if(!f.isCollapsed()&&("up"===c&&!f.isBackward()||"down"===c&&f.isBackward())){e=
|
80
|
-
h.$findMatchingParent(g,r=>L(r));
|
81
|
-
1]:f.getNodes()[0])&&null!==U(d,b)){c=d.getFirstDescendant();b=d.getLastDescendant();if(!c||!b)return!1;[c]=Q(c);[b]=Q(b);c=d.getCordsFromCellNode(c,e.table);b=d.getCordsFromCellNode(b,e.table);c=d.getDOMCellFromCordsOrThrow(c.x,c.y,e.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,e.table);e.$setAnchorCellForSelection(c);e.$setFocusCellForSelection(b,!0);return!0}return!1}d=h.$findMatchingParent(g,r=>v.$isElementNode(r)&&!r.isInline());
|
82
|
-
c?d.getNextSibling():d.getPreviousSibling();if(L(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();a=d.getLastDescendant();if(!e||!a)return!1;[d]=Q(e);[e]=Q(a);f=f.clone();f.focus.set(("up"===c?d:e).getKey(),"up"===c?0:e.getChildrenSize(),"element");X(b);v.$setSelection(f);return!0}}}"down"===c&&$a(a)&&e.setShouldCheckSelection();return!1}if(v.$isRangeSelection(f)&&f.isCollapsed()){let {anchor:r,focus:k}=f;g=h.$findMatchingParent(r.getNode(),
|
80
|
+
h.$findMatchingParent(g,r=>L(r));C(e)&&(e=h.$findMatchingParent(e,L));if(e!==d||!e)return!1;d="down"===c?e.getNextSibling():e.getPreviousSibling();if(!d)return!1;e=0;"up"===c&&v.$isElementNode(d)&&(e=d.getChildrenSize());a=d;"up"===c&&v.$isElementNode(d)&&(a=(c=d.getLastChild())?c:d,e=v.$isTextNode(a)?a.getTextContentSize():0);c=f.clone();c.focus.set(a.getKey(),e,v.$isTextNode(a)?"text":"element");v.$setSelection(c);X(b);return!0}if(v.$isRootOrShadowRoot(g)){if((b="up"===c?f.getNodes()[f.getNodes().length-
|
81
|
+
1]:f.getNodes()[0])&&null!==U(d,b)){c=d.getFirstDescendant();b=d.getLastDescendant();if(!c||!b)return!1;[c]=Q(c);[b]=Q(b);c=d.getCordsFromCellNode(c,e.table);b=d.getCordsFromCellNode(b,e.table);c=d.getDOMCellFromCordsOrThrow(c.x,c.y,e.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,e.table);e.$setAnchorCellForSelection(c);e.$setFocusCellForSelection(b,!0);return!0}return!1}d=h.$findMatchingParent(g,r=>v.$isElementNode(r)&&!r.isInline());C(d)&&(d=h.$findMatchingParent(d,L));if(!d)return!1;d="down"===
|
82
|
+
c?d.getNextSibling():d.getPreviousSibling();if(L(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();a=d.getLastDescendant();if(!e||!a)return!1;[d]=Q(e);[e]=Q(a);f=f.clone();f.focus.set(("up"===c?d:e).getKey(),"up"===c?0:e.getChildrenSize(),"element");X(b);v.$setSelection(f);return!0}}}"down"===c&&$a(a)&&e.setShouldCheckSelection();return!1}if(v.$isRangeSelection(f)&&f.isCollapsed()){let {anchor:r,focus:k}=f;g=h.$findMatchingParent(r.getNode(),C);var m=h.$findMatchingParent(k.getNode(),C);if(!C(g)||
|
83
83
|
!g.is(m))return!1;m=Na(g);if(m!==d&&null!=m){var p=S(m,a.getElementByKey(m.getKey()));if(null!=p)return e.table=T(m,p),Ia(a,b,c,m,e)}if("backward"===c||"forward"===c){e=r.type;a=r.offset;m=r.getNode();if(!m)return!1;f=f.getNodes();return 1===f.length&&v.$isDecoratorNode(f[0])?!1:ab(e,a,m,c)?bb(b,m,g,d,c):!1}f=a.getElementByKey(g.__key);m=a.getElementByKey(r.key);if(null==m||null==f)return!1;if("element"===r.type)f=m.getBoundingClientRect();else{f=v.getDOMSelection(a._window);if(null===f||0===f.rangeCount)return!1;
|
84
84
|
f=f.getRangeAt(0).getBoundingClientRect()}m="up"===c?g.getFirstChild():g.getLastChild();if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>f.top-f.height:f.bottom+f.height>a.bottom){X(b);f=d.getCordsFromCellNode(g,e.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(f.x,f.y,e.table),e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(b,!0);else return Ta(e,d,f.x,f.y,c);return!0}}else if(R(f)){let {anchor:r,focus:k}=f;g=h.$findMatchingParent(r.getNode(),
|
85
|
-
|
85
|
+
C);m=h.$findMatchingParent(k.getNode(),C);[p]=f.getNodes();L(p)||E(251);a=S(p,a.getElementByKey(p.getKey()));if(!C(g)||!C(m)||!L(p)||null==a)return!1;e.$updateTableTableSelection(f);f=T(p,a);a=d.getCordsFromCellNode(g,f);f=d.getDOMCellFromCordsOrThrow(a.x,a.y,f);e.$setAnchorCellForSelection(f);X(b);if(b.shiftKey){let [l,n,q]=O(d,g,m);return Wa(e,l,n,q,c)}m.selectEnd();return!0}return!1}function X(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
|
86
86
|
function Za(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function ab(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||cb(a,b,c,d)}
|
87
87
|
function cb(a,b,c,d){let e=h.$findMatchingParent(c,f=>v.$isElementNode(f)&&!f.isInline());if(!e)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===e.getPreviousSibling():null===e.getNextSibling())}
|
88
88
|
function bb(a,b,c,d,e){let [f,g]=O(d,c,c);c=f[0][0];let m=f[f.length-1][f[0].length-1],{startColumn:p,startRow:r}=g;if("backward"===e?p!==c.startColumn||r!==c.startRow:p!==m.startColumn||r!==m.startRow)return!1;b=db(b,e,d);if(!b||L(b))return!1;X(a);"backward"===e?b.selectEnd():b.selectStart();return!0}
|
89
89
|
function db(a,b,c){if(a=h.$findMatchingParent(a,d=>v.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&L(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function La(a,b,c){let d=v.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
|
90
|
-
function Ja(a,b,c){var d=c.getParent();if(d){var e=v.getDOMSelection(a._window);if(e&&(e=e.anchorNode,d=a.getElementByKey(d.getKey()),a=S(c,a.getElementByKey(c.getKey())),e&&d&&a&&d.contains(e)&&!a.contains(e)&&(b=h.$findMatchingParent(b.anchor.getNode(),r=>
|
90
|
+
function Ja(a,b,c){var d=c.getParent();if(d){var e=v.getDOMSelection(a._window);if(e&&(e=e.anchorNode,d=a.getElementByKey(d.getKey()),a=S(c,a.getElementByKey(c.getKey())),e&&d&&a&&d.contains(e)&&!a.contains(e)&&(b=h.$findMatchingParent(b.anchor.getNode(),r=>C(r))))&&(a=h.$findMatchingParent(b,r=>L(r)),L(a)&&a.is(c))){var [f,g]=O(c,b,b);c=f[0][0];b=f[f.length-1][f[0].length-1];var {startRow:m,startColumn:p}=g;if(m===c.startRow&&p===c.startColumn)return"first";if(m===b.startRow&&p===b.startColumn)return"last"}}}
|
91
91
|
function W(a,b){let {tableNode:c}=a.$lookup();b=c.getCordsFromCellNode(b,a.table);return c.getDOMCellFromCordsOrThrow(b.x,b.y,a.table)}function eb(a,b,c,d){if(a=a.querySelector("colgroup")){b=[];for(let e=0;e<c;e++){let f=document.createElement("col"),g=d&&d[e];g&&(f.style.width=`${g}px`);b.push(f)}a.replaceChildren(...b)}}
|
92
92
|
function fb(a,b,c){c?(h.addClassNamesToElement(a,b.theme.tableRowStriping),a.setAttribute("data-lexical-row-striping","true")):(h.removeClassNamesFromElement(a,b.theme.tableRowStriping),a.removeAttribute("data-lexical-row-striping"))}let gb=new WeakSet;function $a(a=v.$getEditor()){return gb.has(a)}
|
93
93
|
class Z extends v.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(a){let b=this.getWritable();b.__colWidths=a;return b}static clone(a){return new Z(a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__colWidths=a.__colWidths;this.__rowStriping=a.__rowStriping}static importDOM(){return{table:()=>({conversion:hb,priority:1})}}static importJSON(a){let b=la();b.__rowStriping=a.rowStriping||!1;b.__colWidths=a.colWidths;return b}constructor(a){super(a);
|
94
|
-
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}extractWithChild(a,b,c){return"html"===c}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&
|
94
|
+
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}extractWithChild(a,b,c){return"html"===c}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&E(229);return super.getDOMSlot(a).withAfter(a.querySelector("colgroup"))}createDOM(a,b){let c=document.createElement("table"),d=document.createElement("colgroup");c.appendChild(d);eb(c,a,this.getColumnCount(),
|
95
95
|
this.getColWidths());v.setDOMUnmanaged(d);h.addClassNamesToElement(c,a.theme.table);this.__rowStriping&&fb(c,a,!0);return $a(b)?(b=document.createElement("div"),(a=a.theme.tableScrollableWrapper)?h.addClassNamesToElement(b,a):b.style.cssText="overflow-x: auto;",b.appendChild(c),b):c}updateDOM(a,b,c){a.__rowStriping!==this.__rowStriping&&fb(b,c,this.__rowStriping);eb(b,c,this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){let b=super.exportDOM(a);({element:a}=b);return{after:c=>{b.after&&
|
96
96
|
(c=b.after(c));c&&h.isHTMLElement(c)&&"TABLE"!==c.nodeName&&(c=c.querySelector("table"));if(!c||!h.isHTMLElement(c))return null;var [d]=ra(this,null,null),e=new Map;for(var f of d)for(var g of f)d=g.cell.getKey(),e.has(d)||e.set(d,{colSpan:g.cell.getColSpan(),startColumn:g.startColumn});let m=new Set;for(var p of c.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]"))if(g=p.getAttribute("data-temporary-table-cell-lexical-key"))if(f=e.get(g),p.removeAttribute("data-temporary-table-cell-lexical-key"),
|
97
97
|
f)for(e.delete(g),g=0;g<f.colSpan;g++)m.add(g+f.startColumn);if(e=c.querySelector(":scope > colgroup"))p=Array.from(c.querySelectorAll(":scope > colgroup > col")).filter((r,k)=>m.has(k)),e.replaceChildren(...p);e=c.querySelectorAll(":scope > tr");if(0<e.length){p=document.createElement("tbody");for(let r of e)p.appendChild(r);c.append(p)}return c},element:a&&h.isHTMLElement(a)&&"TABLE"!==a.nodeName?a.querySelector("table"):a}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,
|
98
98
|
domRows:d}=b;for(b=0;b<c;b++){let f=d[b];if(null!=f)for(let g=0;g<f.length;g++){var e=f[g];if(null!=e&&({elem:e}=e,e=U(this,v.$getNearestNodeFromDOMNode(e,void 0)),null!==e&&a.is(e)))return{x:g,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<b.length?a:b.length-1];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,
|
99
|
-
b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=v.$getNearestNodeFromDOMNode(a.elem);return
|
100
|
-
{
|
101
|
-
function ib({rows:a,columns:b,includeHeaders:c}){a=ka(Number(a),Number(b),c);h.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0}function jb(a){K(a.getParent())?a.isEmpty()&&a.append(v.$createParagraphNode()):a.remove()}function kb(a){L(a.getParent())?h.$unwrapAndFilterDescendants(a,
|
102
|
-
function lb(a){h.$unwrapAndFilterDescendants(a,K);let [b]=ra(a,null,null),c=b.reduce((e,f)=>Math.max(e,f.length),0);a=a.getChildren();for(let e=0;e<b.length;++e){let f=a[e];if(f){K(f)||
|
99
|
+
b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=v.$getNearestNodeFromDOMNode(a.elem);return C(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);if(!a)throw Error("Node at cords not TableCellNode.");return a}getRowStriping(){return!!this.getLatest().__rowStriping}setRowStriping(a){this.getWritable().__rowStriping=a}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){let a=this.getFirstChild();if(!a)return 0;let b=0;a.getChildren().forEach(c=>
|
100
|
+
{C(c)&&(b+=c.getColSpan())});return b}}function hb(a){let b=la();a.hasAttribute("data-lexical-row-striping")&&b.setRowStriping(!0);var c=a.querySelector(":scope > colgroup");if(c){a=[];for(let d of c.querySelectorAll(":scope > col")){c=d.style.width;if(!c||!ba.test(c)){a=void 0;break}a.push(parseFloat(c))}a&&b.setColWidths(a)}return{after:d=>h.$descendantsMatching(d,K),node:b}}function la(){return v.$applyNodeReplacement(new Z)}function L(a){return a instanceof Z}
|
101
|
+
function ib({rows:a,columns:b,includeHeaders:c}){a=ka(Number(a),Number(b),c);h.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0}function jb(a){K(a.getParent())?a.isEmpty()&&a.append(v.$createParagraphNode()):a.remove()}function kb(a){L(a.getParent())?h.$unwrapAndFilterDescendants(a,C):a.remove()}
|
102
|
+
function lb(a){h.$unwrapAndFilterDescendants(a,K);let [b]=ra(a,null,null),c=b.reduce((e,f)=>Math.max(e,f.length),0);a=a.getChildren();for(let e=0;e<b.length;++e){let f=a[e];if(f){K(f)||E(253,f.constructor.name,f.getType());var d=b[e].reduce((g,m)=>m?1+g:g,0);if(d!==c)for(;d<c;++d){let g=B();g.append(v.$createParagraphNode());f.append(g)}}}}exports.$computeTableMap=O;exports.$computeTableMapSkipCellCheck=ra;exports.$createTableCellNode=B;exports.$createTableNode=la;
|
103
103
|
exports.$createTableNodeWithDimensions=ka;exports.$createTableRowNode=J;exports.$createTableSelection=xa;exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(K(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
|
104
|
-
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||R(a)||
|
104
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||R(a)||E(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);var [e]=Q(a);let [f,g,m]=O(d,c,e);var {startColumn:p}=g;let {startRow:r,startColumn:k}=m;b=Math.min(p,k);var l=Math.max(p+c.__colSpan-1,k+e.__colSpan-1);a=l-b+1;if(f[0].length===l-b+1)d.selectPrevious(),d.remove();else{var n=f.length;for(let q=0;q<n;q++)for(let u=b;u<=l;u++){let {cell:t,startColumn:w}=f[q][u];w<b?u===b&&t.setColSpan(t.__colSpan-
|
105
105
|
Math.min(a,t.__colSpan-(b-w))):w+t.__colSpan-1>l?u===l&&t.setColSpan(t.__colSpan-(l-w+1)):t.remove()}l=f[r];e=p>k?l[p+c.__colSpan]:l[k+e.__colSpan];void 0!==e?({cell:p}=e,M(p)):({cell:p}=k<p?l[k-1]:l[p-1],M(p));if(p=d.getColWidths())p=[...p],p.splice(b,a),d.setColWidths(p)}};
|
106
|
-
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||R(a)||
|
107
|
-
(q===a&&
|
108
|
-
exports.$getTableAndElementByKey=ya;exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>
|
109
|
-
exports.$
|
106
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||R(a)||E(188);let [b,c]=a.isBackward()?[a.focus.getNode(),a.anchor.getNode()]:[a.anchor.getNode(),a.focus.getNode()],[d,,e]=Q(b);var [f]=Q(c);let [g,m,p]=O(e,d,f);({startRow:a}=m);var {startRow:r}=p;f=r+f.__rowSpan-1;if(g.length===f-a+1)e.remove();else{r=g[0].length;var k=d.__rowSpan,l=g[f+1],n=e.getChildAtIndex(f+1);for(let u=f;u>=a;u--){for(var q=r-1;0<=q;q--){let {cell:t,startRow:w,startColumn:D}=g[u][q];
|
107
|
+
if(D===q&&(u===a&&w<a&&t.setRowSpan(t.__rowSpan-Math.min(k,t.__rowSpan-(a-w))),w>=a&&w+t.__rowSpan-1>f)){t.setRowSpan(t.__rowSpan-(f-w+1));null===n&&E(122);let z=null;for(let A=0;A<q;A++){let G=l[A],H=G.cell;G.startRow===u+1&&(z=H);1<H.__colSpan&&(A+=H.__colSpan-1)}null===z?qa(n,t):z.insertAfter(t)}}q=e.getChildAtIndex(u);K(q)||E(206,String(u));q.remove()}void 0!==l?({cell:a}=l[0],M(a)):({cell:a}=g[a-1][0],M(a))}};exports.$findCellNode=Ma;exports.$findTableNode=Na;
|
108
|
+
exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());null===a&&E(230);return T(b,a)};exports.$getNodeTriplet=Q;exports.$getTableAndElementByKey=ya;exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableCellNodeRect=ta;exports.$getTableColumnIndexFromTableCellNode=function(a){return ma(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=na;
|
109
|
+
exports.$getTableRowIndexFromTableCellNode=function(a){let b=ma(a);return na(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ma;
|
110
|
+
exports.$insertTableColumn=function(a,b,c=!0,d,e){let f=a.getChildren(),g=[];for(let r=0;r<f.length;r++){let k=f[r];if(K(k))for(let l=0;l<d;l++){var m=k.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];C(m)||E(12);let {left:n,right:q}=oa(m,e);var p=x.NO_STATUS;if(n&&n.hasHeaderState(x.ROW)||q&&q.hasHeaderState(x.ROW))p|=x.ROW;p=B(p);p.append(v.$createParagraphNode());g.push({newTableCell:p,targetCell:m})}}g.forEach(({newTableCell:r,targetCell:k})=>{c?
|
110
111
|
k.insertAfter(r):k.insertBefore(r)});return a};
|
111
|
-
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(l=x.NO_STATUS){l=
|
112
|
-
K(k)||
|
113
|
-
exports.$insertTableRow=function(a,b,c=!0,d,e){var f=a.getChildren();if(b>=f.length||0>b)throw Error("Table row target index out of range");b=f[b];if(K(b))for(f=0;f<d;f++){let m=b.getChildren(),p=m.length,r=J();for(let k=0;k<p;k++){var g=m[k];
|
112
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(l=x.NO_STATUS){l=B(l).append(v.$createParagraphNode());null===r&&(r=l);return l}var c=v.$getSelection();v.$isRangeSelection(c)||R(c)||E(188);var d=c.anchor.getNode();c=c.focus.getNode();[d]=Q(d);let [e,,f]=Q(c),[g,m,p]=O(f,e,d);d=g.length;c=a?Math.max(m.startColumn,p.startColumn):Math.min(m.startColumn,p.startColumn);a=a?c+e.__colSpan-1:c-1;c=f.getFirstChild();K(c)||E(120);let r=null;var k=c;a:for(c=0;c<d;c++){0!==c&&(k=k.getNextSibling(),
|
113
|
+
K(k)||E(121));let l=g[c],n=pa(l[0>a?0:a].cell.__headerState,x.ROW);if(0>a){qa(k,b(n));continue}let {cell:q,startColumn:u,startRow:t}=l[a];if(u+q.__colSpan-1<=a){let w=q,D=t,z=a;for(;D!==c&&1<w.__rowSpan;)if(z-=q.__colSpan,0<=z){let {cell:A,startRow:G}=l[z];w=A;D=G}else{k.append(b(n));continue a}w.insertAfter(b(n))}else q.setColSpan(q.__colSpan+1)}null!==r&&M(r);if(d=f.getColWidths())d=[...d],a=0>a?0:a,d.splice(a,0,d[a]),f.setColWidths(d);return r};
|
114
|
+
exports.$insertTableRow=function(a,b,c=!0,d,e){var f=a.getChildren();if(b>=f.length||0>b)throw Error("Table row target index out of range");b=f[b];if(K(b))for(f=0;f<d;f++){let m=b.getChildren(),p=m.length,r=J();for(let k=0;k<p;k++){var g=m[k];C(g)||E(12);let {above:l,below:n}=oa(g,e);g=x.NO_STATUS;let q=l&&l.getWidth()||n&&n.getWidth()||void 0;if(l&&l.hasHeaderState(x.COLUMN)||n&&n.hasHeaderState(x.COLUMN))g|=x.COLUMN;g=B(g,1,q);g.append(v.$createParagraphNode());r.append(g)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
|
114
115
|
return a};
|
115
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=v.$getSelection();v.$isRangeSelection(b)||R(b)||
|
116
|
-
a=J();for(p=0;p<b;p++){let {cell:k,startRow:l}=m[p];l===g?(r=pa(m[p].cell.__headerState,x.COLUMN),a.append(
|
116
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=v.$getSelection();v.$isRangeSelection(b)||R(b)||E(188);b=b.focus.getNode();let [c,,d]=Q(b),[e,f]=O(d,c,c);b=e[0].length;var {startRow:g}=f;if(a){a=g+c.__rowSpan-1;var m=e[a];g=J();for(var p=0;p<b;p++){let {cell:k,startRow:l}=m[p];if(l+k.__rowSpan-1<=a){var r=pa(m[p].cell.__headerState,x.COLUMN);g.append(B(r).append(v.$createParagraphNode()))}else k.setRowSpan(k.__rowSpan+1)}b=d.getChildAtIndex(a);K(b)||E(145);b.insertAfter(g);b=g}else{m=e[g];
|
117
|
+
a=J();for(p=0;p<b;p++){let {cell:k,startRow:l}=m[p];l===g?(r=pa(m[p].cell.__headerState,x.COLUMN),a.append(B(r).append(v.$createParagraphNode()))):k.setRowSpan(k.__rowSpan+1)}b=d.getChildAtIndex(g);K(b)||E(145);b.insertBefore(a);b=a}return b};exports.$isScrollableTablesActive=$a;exports.$isTableCellNode=C;exports.$isTableNode=L;exports.$isTableRowNode=K;exports.$isTableSelection=R;
|
117
118
|
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};
|
118
|
-
exports.$unmergeCell=function(){var a=v.$getSelection();v.$isRangeSelection(a)||R(a)||
|
119
|
-
if(1<a){for(var q=1;q<a;q++)b.insertAfter(
|
119
|
+
exports.$unmergeCell=function(){var a=v.$getSelection();v.$isRangeSelection(a)||R(a)||E(188);a=a.anchor.getNode();let [b,c,d]=Q(a);a=b.__colSpan;let e=b.__rowSpan;if(1!==a||1!==e){var [f,g]=O(d,b,b),{startColumn:m,startRow:p}=g,r=b.__headerState&x.COLUMN,k=Array.from({length:a},(w,D)=>{w=r;for(let z=0;0!==w&&z<f.length;z++)w&=f[z][D+m].cell.__headerState;return w}),l=b.__headerState&x.ROW,n=Array.from({length:e},(w,D)=>{w=l;for(let z=0;0!==w&&z<f[0].length;z++)w&=f[D+p][z].cell.__headerState;return w});
|
120
|
+
if(1<a){for(var q=1;q<a;q++)b.insertAfter(B(k[q]|n[0]).append(v.$createParagraphNode()));b.setColSpan(1)}if(1<e){let w;for(q=1;q<e;q++){var u=p+q;let D=f[u];w=(w||c).getNextSibling();K(w)||E(125);var t=null;for(let z=0;z<m;z++){let A=D[z],G=A.cell;A.startRow===u&&(t=G);1<G.__colSpan&&(z+=G.__colSpan-1)}if(null===t)for(t=a-1;0<=t;t--)qa(w,B(k[t]|n[q]).append(v.$createParagraphNode()));else for(u=a-1;0<=u;u--)t.insertAfter(B(k[u]|n[q]).append(v.$createParagraphNode()))}b.setRowSpan(1)}}};
|
120
121
|
exports.INSERT_TABLE_COMMAND=ea;exports.TableCellHeaderStates=x;exports.TableCellNode=y;exports.TableNode=Z;exports.TableObserver=za;exports.TableRowNode=I;exports.applyTableHandlers=Ea;exports.getDOMCellFromTarget=Ha;exports.getTableElement=S;exports.getTableObserverFromTableElement=Ga;
|
121
|
-
exports.registerTableCellUnmergeTransform=function(a){return a.registerNodeTransform(y,b=>{if(1<b.getColSpan()||1<b.getRowSpan()){var [,,c]=Q(b);[b]=O(c,b,b);let e=b.length,f=b[0].length;c=c.getFirstChild();K(c)||
|
122
|
-
h.$insertFirst(c,d)}}for(let m of g)m.setColSpan(1),m.setRowSpan(1)}})};exports.registerTablePlugin=function(a){a.hasNodes([Z])||
|
122
|
+
exports.registerTableCellUnmergeTransform=function(a){return a.registerNodeTransform(y,b=>{if(1<b.getColSpan()||1<b.getRowSpan()){var [,,c]=Q(b);[b]=O(c,b,b);let e=b.length,f=b[0].length;c=c.getFirstChild();K(c)||E(175);let g=[];for(let m=0;m<e;m++){0!==m&&(c=c.getNextSibling(),K(c)||E(175));let p=null;for(let r=0;r<f;r++){var d=b[m][r];let k=d.cell;if(d.startRow===m&&d.startColumn===r)p=k,g.push(k);else if(1<k.getColSpan()||1<k.getRowSpan())C(k)||E(176),d=B(k.__headerState),null!==p?p.insertAfter(d):
|
123
|
+
h.$insertFirst(c,d)}}for(let m of g)m.setColSpan(1),m.setRowSpan(1)}})};exports.registerTablePlugin=function(a){a.hasNodes([Z])||E(254);return h.mergeRegister(a.registerCommand(ea,ib,v.COMMAND_PRIORITY_EDITOR),a.registerNodeTransform(Z,lb),a.registerNodeTransform(I,kb),a.registerNodeTransform(y,jb))};
|
123
124
|
exports.registerTableSelectionObserver=function(a,b=!0){let c=new Map,d=(f,g,m)=>{m=S(f,m);f=Ea(f,m,a,b);c.set(g,[f,m])},e=a.registerMutationListener(Z,f=>{a.getEditorState().read(()=>{for(const [g,m]of f){const p=c.get(g);if("created"===m||"updated"===m){const {tableNode:r,tableElement:k}=ya(g);void 0===p?d(r,g,k):k!==p[1]&&(p[0].removeListeners(),c.delete(g),d(r,g,k))}else"destroyed"===m&&void 0!==p&&(p[0].removeListeners(),c.delete(g))}},{editor:a})},{skipInitialization:!1});return()=>{e();for(let [,
|
124
125
|
[f]]of c)f.removeListeners()}};exports.setScrollableTablesActive=function(a,b){b?gb.add(a):gb.delete(a)}
|
package/LexicalTable.prod.mjs
CHANGED
@@ -6,4 +6,4 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$unwrapAndFilterDescendants as a}from"@lexical/utils";import{ElementNode as u,isHTMLElement as h,$createParagraphNode as d,$isElementNode as g,$isLineBreakNode as f,$isTextNode as m,$applyNodeReplacement as p,createCommand as C,$createTextNode as S,$getSelection as _,$isRangeSelection as w,$createPoint as b,$isParagraphNode as y,$normalizeSelection__EXPERIMENTAL as N,isCurrentlyReadOnlyMode as x,TEXT_TYPE_TO_FORMAT as T,$getNodeByKey as v,$getEditor as R,$setSelection as O,SELECTION_CHANGE_COMMAND as F,getDOMSelection as k,$createRangeSelection as E,$getRoot as K,COMMAND_PRIORITY_HIGH as M,KEY_ESCAPE_COMMAND as A,COMMAND_PRIORITY_CRITICAL as $,CUT_COMMAND as L,FORMAT_TEXT_COMMAND as P,FORMAT_ELEMENT_COMMAND as H,CONTROLLED_TEXT_INSERTION_COMMAND as W,KEY_TAB_COMMAND as B,FOCUS_COMMAND as D,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as U,$getNearestNodeFromDOMNode as z,$createRangeSelectionFromDom as Y,INSERT_PARAGRAPH_COMMAND as q,$isRootOrShadowRoot as X,$isDecoratorNode as J,KEY_ARROW_DOWN_COMMAND as j,KEY_ARROW_UP_COMMAND as V,KEY_ARROW_LEFT_COMMAND as G,KEY_ARROW_RIGHT_COMMAND as Q,DELETE_WORD_COMMAND as Z,DELETE_LINE_COMMAND as ee,DELETE_CHARACTER_COMMAND as te,KEY_BACKSPACE_COMMAND as ne,KEY_DELETE_COMMAND as oe,setDOMUnmanaged as re,COMMAND_PRIORITY_EDITOR as le}from"lexical";import{copyToClipboard as se,$getClipboardDataFromSelection as ie}from"@lexical/clipboard";const ce=/^(\d+(?:\.\d+)?)px$/,ae={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ue extends u{static getType(){return"tablecell"}static clone(e){return new ue(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor}static importDOM(){return{td:e=>({conversion:he,priority:0}),th:e=>({conversion:he,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return de(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=ae.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 t=super.exportDOM(e);if(t.element&&h(t.element)){const e=t.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="top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return 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.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=ae.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}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!==ae.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 he(e){const t=e,n=e.nodeName.toLowerCase();let o;ce.test(t.style.width)&&(o=parseFloat(t.style.width));const r=de("th"===n?ae.ROW:ae.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style,i=(s&&s.textDecoration||"").split(" "),c="700"===s.fontWeight||"bold"===s.fontWeight,a=i.includes("line-through"),u="italic"===s.fontStyle,h=i.includes("underline");return{after:e=>(0===e.length&&e.push(d()),e),forChild:(e,t)=>{if(ge(t)&&!g(e)){const t=d();return f(e)&&"\n"===e.getTextContent()?null:(m(e)&&(c&&e.toggleFormat("bold"),a&&e.toggleFormat("strikethrough"),u&&e.toggleFormat("italic"),h&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function de(e=ae.NO_STATUS,t=1,n){return p(new ue(e,t,n))}function ge(e){return e instanceof ue}const fe=C("INSERT_TABLE_COMMAND");function me(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pe=me((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.`)}));class Ce extends u{static getType(){return"tablerow"}static clone(e){return new Ce(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:Se,priority:0})}}static importJSON(e){return _e(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}extractWithChild(e,t,n){return"html"===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 Se(e){const n=e;let o;return ce.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,ge),node:_e(o)}}function _e(e){return p(new Ce(e))}function we(e){return e instanceof Ce}const be="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ye=be&&"documentMode"in document?document.documentMode:null,Ne=be&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function xe(e,t,n=!0){const o=Dt();for(let r=0;r<e;r++){const e=_e();for(let o=0;o<t;o++){let t=ae.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=ae.ROW),0===o&&n.columns&&(t|=ae.COLUMN)):n&&(0===r&&(t|=ae.ROW),0===o&&(t|=ae.COLUMN));const l=de(t),s=d();s.append(S()),l.append(s),e.append(l)}o.append(e)}return o}function Te(e){const t=n(e,(e=>ge(e)));return ge(t)?t:null}function ve(e){const t=n(e,(e=>we(e)));if(we(t))return t;throw new Error("Expected table cell to be inside of table row.")}function Re(e){const t=n(e,(e=>It(e)));if(It(t))return t;throw new Error("Expected table cell to be inside of table.")}function Oe(e){const t=ve(e);return Re(t).getChildren().findIndex((e=>e.is(t)))}function Fe(e){return ve(e).getChildren().findIndex((t=>t.is(e)))}function ke(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 Ee(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 Ke(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 s=l[t];if(!we(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=_e();for(let n=0;n<t;n++){const t=e[n];ge(t)||pe(12);const{above:l,below:s}=ke(t,r);let i=ae.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(ae.COLUMN)||s&&s.hasHeaderState(ae.COLUMN))&&(i|=ae.COLUMN);const a=de(i,1,c);a.append(d()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}be&&"InputEvent"in window&&!ye&&new window.InputEvent("input");const Me=(e,t)=>e===ae.BOTH||e===t?t:ae.NO_STATUS;function Ae(e=!0){const t=_();w(t)||Ve(t)||pe(188);const n=t.focus.getNode(),[o,,r]=Ye(n),[l,s]=Ue(r,o,o),i=l[0].length,{startRow:c}=s;let a=null;if(e){const e=c+o.__rowSpan-1,t=l[e],n=_e();for(let o=0;o<i;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Me(e,ae.COLUMN);n.append(de(r).append(d()))}else r.setRowSpan(r.__rowSpan+1)}const s=r.getChildAtIndex(e);we(s)||pe(145),s.insertAfter(n),a=n}else{const e=l[c],t=_e();for(let n=0;n<i;n++){const{cell:o,startRow:r}=e[n];if(r===c){const o=e[n].cell.__headerState,r=Me(o,ae.COLUMN);t.append(de(r).append(d()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(c);we(n)||pe(145),n.insertBefore(t),a=t}return a}function $e(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(we(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];ge(o)||pe(12);const{left:l,right:i}=ke(o,r);let c=ae.NO_STATUS;(l&&l.hasHeaderState(ae.ROW)||i&&i.hasHeaderState(ae.ROW))&&(c|=ae.ROW);const a=de(c);a.append(d()),s.push({newTableCell:a,targetCell:o})}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Le(e=!0){const t=_();w(t)||Ve(t)||pe(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ye(n),[l,,s]=Ye(o),[i,c,a]=Ue(s,l,r),u=i.length,h=e?Math.max(c.startColumn,a.startColumn):Math.min(c.startColumn,a.startColumn),g=e?h+l.__colSpan-1:h-1,f=s.getFirstChild();we(f)||pe(120);let m=null;function p(e=ae.NO_STATUS){const t=de(e).append(d());return null===m&&(m=t),t}let C=f;e:for(let e=0;e<u;e++){if(0!==e){const e=C.getNextSibling();we(e)||pe(121),C=e}const t=i[e],n=t[g<0?0:g].cell.__headerState,o=Me(n,ae.ROW);if(g<0){De(C,p(o));continue}const{cell:r,startColumn:l,startRow:s}=t[g];if(l+r.__colSpan-1<=g){let n=r,l=s,i=g;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){C.append(p(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(p(o))}else r.setColSpan(r.__colSpan+1)}null!==m&&Be(m);const S=s.getColWidths();if(S){const e=[...S],t=g<0?0:g,n=e[t];e.splice(t,0,n),s.setColWidths(e)}return m}function Pe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(we(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 He(){const e=_();w(e)||Ve(e)||pe(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Ye(t),[l]=Ye(n),[s,i,c]=Ue(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,g=s[h+1],f=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>h))if(n.setRowSpan(n.__rowSpan-(h-o+1)),null===f&&pe(122),0===t)De(f,n);else{const{cell:e}=g[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);we(t)||pe(206,String(e)),t.remove()}if(void 0!==g){const{cell:e}=g[0];Be(e)}else{const e=s[a-1],{cell:t}=e[0];Be(t)}}function We(){const e=_();w(e)||Ve(e)||pe(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ye(t),[l]=Ye(n),[s,i,c]=Ue(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),g=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),f=g-d+1;if(s[0].length===g-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=g;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(f,n.__colSpan-e))}}else if(o+n.__colSpan-1>g){if(t===g){const e=g-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;Be(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Be(t)}const S=r.getColWidths();if(S){const e=[...S];e.splice(d,f),r.setColWidths(e)}}function Be(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function De(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ie(){const e=_();w(e)||Ve(e)||pe(188);const t=e.anchor.getNode(),[n,o,r]=Ye(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[i,c]=Ue(r,n,n),{startColumn:a,startRow:u}=c,h=n.__headerState&ae.COLUMN,g=Array.from({length:l},((e,t)=>{let n=h;for(let e=0;0!==n&&e<i.length;e++)n&=i[e][t+a].cell.__headerState;return n})),f=n.__headerState&ae.ROW,m=Array.from({length:s},((e,t)=>{let n=f;for(let e=0;0!==n&&e<i[0].length;e++)n&=i[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(de(g[e]|m[0]).append(d()));n.setColSpan(1)}if(s>1){let e;for(let t=1;t<s;t++){const n=u+t,r=i[n];e=(e||o).getNextSibling(),we(e)||pe(125);let s=null;for(let e=0;e<a;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 n=l-1;n>=0;n--)De(e,de(g[n]|m[t]).append(d()));else for(let e=l-1;e>=0;e--)s.insertAfter(de(g[e]|m[t]).append(d()))}n.setRowSpan(1)}}function Ue(e,t,n){const[o,r,l]=ze(e,t,n);return null===r&&pe(207),null===l&&pe(208),[o,r,l]}function ze(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];we(o)||pe(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){ge(c)||pe(147);const o=s(e);for(;void 0!==o[a];)a++;const u={cell:c,startColumn:a,startRow:e},{__rowSpan:h,__colSpan:d}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[a+e]=u}null!==t&&null===r&&t.is(c)&&(r=u),null!==n&&null===l&&n.is(c)&&(l=u)}}return[o,r,l]}function Ye(e){let t;if(e instanceof ue)t=e;else if("__type"in e){const o=n(e,ge);ge(o)||pe(148),t=o}else{const o=n(e.getNode(),ge);ge(o)||pe(148),t=o}const o=t.getParent();we(o)||pe(149);const r=o.getParent();return It(r)||pe(210),[t,o,r]}function qe(e,t,n){let o=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),l=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),s=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1),i=o,c=r,a=o,u=r;function h(e){const{cell:t,startColumn:n,startRow:i}=e;o=Math.min(o,n),r=Math.min(r,i),l=Math.max(l,n+t.__colSpan-1),s=Math.max(s,i+t.__rowSpan-1)}for(;o<i||r<c||l>a||s>u;){if(o<i){const t=u-c,n=i-1;for(let o=0;o<=t;o++)h(e[c+o][n]);i=n}if(r<c){const t=a-i,n=c-1;for(let o=0;o<=t;o++)h(e[n][i+o]);c=n}if(l>a){const t=u-c,n=a+1;for(let o=0;o<=t;o++)h(e[c+o][n]);a=n}if(s>u){const t=a-i,n=u+1;for(let o=0;o<=t;o++)h(e[n][i+o]);u=n}}return{maxColumn:l,maxRow:s,minColumn:o,minRow:r}}function Xe(e){const[t,,n]=Ye(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,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Je(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=n(o,ge);ge(r)||pe(238,t,o.getKey(),o.getType());const l=r.getParent();we(l)||pe(239,t);const s=l.getParent();return It(s)||pe(240,t),[o,r,l,s]}));return l.is(a)||pe(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class je{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(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Ve(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 je(this.tableKey,b(this.anchor.key,this.anchor.offset,this.anchor.type),b(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(ge).forEach((e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())}));const n=T[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();g(t)||pe(151);N(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Je(this),n=Xe(e);null===n&&pe(153);const o=Xe(t);null===o&&pe(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:t,anchorCell:n,focusCell:o}=Je(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&pe(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&pe(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Ue(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=qe(l,s,i),d=new Map([[t.getKey(),t]]);let g=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();we(o)||pe(160),o!==g&&(d.set(o.getKey(),o),g=o),d.has(n.getKey())||Qe(n,(e=>{d.set(e.getKey(),e)}))}const f=Array.from(d.values());return x()||(this._cachedNodes=f),f}getTextContent(){const e=this.getNodes().filter((e=>ge(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 Ve(e){return e instanceof je}function Ge(){const e=b("root",0,"element"),t=b("root",0,"element");return new je("root",e,t)}function Qe(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&g(o)&&n.push(o.getChildren())}}function Ze(e,t=R()){const n=v(e);It(n)||pe(231,e);const o=ot(n,t.getElementByKey(e));return null===o&&pe(232,e),{tableElement:o,tableNode:n}}class et{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.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return Ze(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=dt(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=dt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})}),{editor:this.editor})}$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();const{tableNode:t,tableElement:n}=this.$lookup();gt(e,dt(t,n),null),null!==_()&&(O(null),e.dispatchCommand(F,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&pe(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),gt(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=k(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Kt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=function(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=_(),r=Ve(o)?o.clone():Ge();return r.set(e.getKey(),t.getKey(),n.getKey()),r}(o,this.$getAnchorTableCellOrThrow(),t),O(this.tableSelection),n.dispatchCommand(F,void 0),gt(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&pe(234),e}$getFocusTableCell(){return this.focusCellNodeKey?v(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&pe(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Kt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ge(),this.anchorCellNodeKey=e}}$formatCells(e){const t=_();Ve(t)||pe(236);const n=E(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ge);l.length>0||pe(237);const s=l[0].getFirstChild(),i=y(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)})),O(t),this.editor.dispatchCommand(F,void 0)}$clearText(){const{editor:e}=this,t=v(this.tableNodeKey);if(!It(t))throw new Error("Expected TableNode.");const n=_();Ve(n)||pe(11);const o=n.getNodes().filter(ge);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(g(e)){const t=d(),n=S();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),gt(e,this.table,null),O(null),e.dispatchCommand(F,void 0);else{t.selectPrevious(),t.remove();K().selectStart()}}}const tt="__lexicalTableSelection",nt=e=>!(1&~e.buttons);function ot(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&pe(245,t.nodeName),n}function rt(e){return e._window}function lt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ge(n)&&(o=n)}return null}const st=[[j,"down"],[V,"up"],[G,"backward"],[Q,"forward"]],it=[Z,ee,te],ct=[ne,oe];function at(e,t,o,l){const s=o.getRootElement(),i=rt(o);null!==s&&null!==i||pe(246);const c=new et(o,e.getKey()),a=ot(e,t);!function(e,t){null!==ut(e)&&pe(205);e[tt]=t}(a,c),c.listenersToRemove.add((()=>function(e,t){ut(e)===t&&delete e[tt]}(a,c)));a.addEventListener("mousedown",(t=>{if(0!==t.button)return;if(!i)return;const n=ht(t.target);null!==n&&o.update((()=>{const o=U();if(Ne&&t.shiftKey&&bt(o,e)&&(w(o)||Ve(o))){const r=o.anchor.getNode(),l=lt(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(Et(c,l)),c.$setFocusCellForSelection(n),Ot(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else c.$setAnchorCellForSelection(n)})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("mouseup",e),i.removeEventListener("mousemove",t)},t=n=>{if(!nt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("mouseup",e),void i.removeEventListener("mousemove",t);const r=!a.contains(n.target);let l=null;if(r){for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(l=a.contains(e)?ht(e):null,l)break}else l=ht(n.target);!l||null!==c.focusCell&&l.elem===c.focusCell.elem||(c.setNextFocus({focusCell:l,override:r}),o.dispatchCommand(F,void 0))};c.isSelecting=!0,i.addEventListener("mouseup",e,c.listenerOptions),i.addEventListener("mousemove",t,c.listenerOptions)})()}),c.listenerOptions);i.addEventListener("mousedown",(e=>{0===e.button&&o.update((()=>{const t=_(),n=e.target;Ve(t)&&t.tableKey===c.tableNodeKey&&s.contains(n)&&c.$clearHighlight()}))}),c.listenerOptions);for(const[t,n]of st)c.listenersToRemove.add(o.registerCommand(t,(t=>Rt(o,t,n,e,c)),M));c.listenersToRemove.add(o.registerCommand(A,(t=>{const n=_();if(Ve(n)){const o=lt(e,n.focus.getNode());if(null!==o)return Ot(t),o.selectEnd(),!0}return!1}),M));const u=t=>()=>{const o=_();if(!bt(o,e))return!1;if(Ve(o))return c.$clearText(),!0;if(w(o)){if(!ge(lt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=n(o.anchor.getNode(),(e=>g(e))),u=a&&n(a,(e=>g(e)&&ge(e.getParent())));if(!g(u)||!g(a))return!1;if(t===ee&&null===u.getPreviousSibling())return!0}return!1};for(const e of it)c.listenersToRemove.add(o.registerCommand(e,u(e),$));const h=t=>{const n=_();if(!Ve(n)&&!w(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!Ve(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0)};for(const e of ct)c.listenersToRemove.add(o.registerCommand(e,h,$));return c.listenersToRemove.add(o.registerCommand(L,(e=>{const t=_();if(t){if(!Ve(t)&&!w(t))return!1;se(o,r(e,ClipboardEvent)?e:null,ie(t));const n=h(e);return w(t)?(t.removeText(),!0):n}return!1}),$)),c.listenersToRemove.add(o.registerCommand(P,(t=>{const o=_();if(!bt(o,e))return!1;if(Ve(o))return c.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),(e=>ge(e)));if(!ge(e))return!1}return!1}),$)),c.listenersToRemove.add(o.registerCommand(H,(t=>{const n=_();if(!Ve(n)||!bt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ge(o)||!ge(r))return!1;const[l,s,i]=Ue(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];g(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),$)),c.listenersToRemove.add(o.registerCommand(W,(t=>{const r=_();if(!bt(r,e))return!1;if(Ve(r))return c.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),(e=>ge(e)));if(!ge(l))return!1;if("string"==typeof t){const n=kt(o,r,e);if(n)return Ft(n,e,[S(t)]),!0}}return!1}),$)),l&&c.listenersToRemove.add(o.registerCommand(B,(t=>{const o=_();if(!w(o)||!o.isCollapsed()||!bt(o,e))return!1;const r=Tt(o.anchor.getNode());return!(null===r||!e.is(vt(r)))&&(Ot(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(g(l))return l.selectEnd();const s=n(e,we);null===s&&pe(247);for(let e=s[o]();we(e);e=e[o]()){const t=e[r]();if(g(t))return t.selectEnd()}const i=n(s,It);null===i&&pe(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)}),$)),c.listenersToRemove.add(o.registerCommand(D,(t=>e.isSelected()),M)),c.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=Ve(o),s=w(o)&&null!==n(o.anchor.getNode(),(e=>ge(e)))&&null!==n(o.focus.getNode(),(e=>ge(e)))||l;if(1!==t.length||!It(t[0])||!s||null===r)return!1;const[i]=r,c=t[0],a=c.getChildren(),u=c.getFirstChildOrThrow().getChildrenSize(),h=c.getChildrenSize(),g=n(i.getNode(),(e=>ge(e))),f=g&&n(g,(e=>we(e))),p=f&&n(f,(e=>It(e)));if(!ge(g)||!we(f)||!It(p))return!1;const C=f.getIndexWithinParent(),S=Math.min(p.getChildrenSize()-1,C+h-1),_=g.getIndexWithinParent(),b=Math.min(f.getChildrenSize()-1,_+u-1),y=Math.min(_,b),N=Math.min(C,S),x=Math.max(_,b),T=Math.max(C,S),v=p.getChildren();let R=0;for(let e=N;e<=T;e++){const t=v[e];if(!we(t))return!1;const n=a[R];if(!we(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ge(t))return!1;const n=r[l];if(!ge(n))return!1;const s=t.getChildren();n.getChildren().forEach((e=>{if(m(e)){d().append(e),t.append(e)}else t.append(e)})),s.forEach((e=>e.remove())),l++}R++}return!0}),$)),c.listenersToRemove.add(o.registerCommand(F,(()=>{const t=_(),r=U(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(Ve(t)&&t.tableKey===c.tableNodeKey)return(n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&bt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&w(r)&&w(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=Tt(o);if(null!==l&&we(r)){const t=r.getFirstChild();if(ge(t)&&e.is(n(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if(w(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Tt(l),a=Tt(s),u=!(!i||!e.is(vt(i))),h=!(!a||!e.is(vt(a))),d=u!==h,g=u&&h,f=t.isBackward();if(d){const n=t.clone();if(h){const[t]=Ue(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(f?o.getKey():r.getKey(),f?o.getChildrenSize():r.getChildrenSize(),"element")}else if(u){const[t]=Ue(e,i,i),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(f?r.getKey():o.getKey(),f?r.getChildrenSize():0,"element")}O(n),mt(o,c)}else g&&(i.is(a)||(c.$setAnchorCellForSelection(Et(c,i)),c.$setFocusCellForSelection(Et(c,a),!0)))}else if(t&&Ve(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=k(i);if(n&&n.anchorNode&&n.focusNode){const r=z(n.focusNode),l=r&&!e.isParentOf(r),s=z(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=Y(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),O(r))}}}return t&&!t.is(r)&&(Ve(t)||Ve(r))&&c.tableSelection&&!c.tableSelection.is(r)?(Ve(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!Ve(t)&&Ve(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),ft(t.table,(t=>{const n=t.elem;t.highlighted=!1,xt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&mt(o,c),!1)}),$)),c.listenersToRemove.add(o.registerCommand(q,(()=>{const t=_();if(!w(t)||!t.isCollapsed()||!bt(t,e))return!1;const n=kt(o,t,e);return!!n&&(Ft(n,e),!0)}),$)),c}function ut(e){return e[tt]||null}function ht(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 dt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=ot(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 gt(e,t,n){const o=new Set(n?n.getNodes():[]);ft(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Nt(e,t)):(t.highlighted=!1,xt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function ft(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=z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function mt(e,t){t.$disableHighlightStyle(),ft(t.table,(t=>{t.highlighted=!0,Nt(e,t)}))}const pt=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?yt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?yt(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?yt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?yt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Ct(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 St([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function _t(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&pe(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&pe(250,n,String(s)),i}function wt(e,t,n,o,r){const l=qe(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Ct(e,t);return null===n&&pe(249,t.cell.getKey()),n}(l,n),[d,g]=St(h);let f=l[d],m=l[g];"forward"===r?f+="maxColumn"===d?1:c:"backward"===r?f-="minColumn"===d?1:u:"down"===r?m+="maxRow"===g?1:i:"up"===r&&(m-="minRow"===g?1:a);const p=t[m];if(void 0===p)return!1;const C=p[f];if(void 0===C)return!1;const[S,_]=function(e,t,n){const o=qe(e,t,n),r=Ct(o,t);if(r)return[_t(e,o,r),_t(e,o,St(r))];const l=Ct(o,n);if(l)return[_t(e,o,St(l)),_t(e,o,l)];const s=["minColumn","minRow"];return[_t(e,o,s),_t(e,o,St(s))]}(t,n,C),w=Et(e,S.cell),b=Et(e,_.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function bt(e,t){if(w(e)||Ve(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function yt(e,t){t?e.selectStart():e.selectEnd()}function Nt(t,n){const o=n.elem,r=t._config.theme;ge(z(o))||pe(131),e(o,r.tableCellSelected)}function xt(e,t){const n=t.elem;ge(z(n))||pe(131);const r=e._config.theme;o(n,r.tableCellSelected)}function Tt(e){const t=n(e,ge);return ge(t)?t:null}function vt(e){const t=n(e,It);return It(t)?t:null}function Rt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=_();if(!bt(s,r)){if(w(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(g(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!It(n)&&(Ot(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=n(e,(e=>It(e)));if(ge(l)&&(l=n(l,It)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let c=0;"up"===o&&g(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&g(i)){const e=i.getLastChild();a=e||i,c=m(a)?a.getTextContentSize():0}const u=s.clone();return u.focus.set(a.getKey(),c,m(a)?"text":"element"),O(u),Ot(t),!0}if(X(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==lt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ye(e),[o]=Ye(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,(e=>g(e)&&!e.isInline()));if(ge(r)&&(r=n(r,It)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(It(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[r]=Ye(e),[l]=Ye(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Ot(t),O(c),!0}}}}return"down"===o&&Lt(e)&&l.setShouldCheckSelection(),!1}if(w(s)&&s.isCollapsed()){const{anchor:i,focus:c}=s,a=n(i.getNode(),ge),u=n(c.getNode(),ge);if(!ge(a)||!a.is(u))return!1;const h=vt(a);if(h!==r&&null!=h){const n=ot(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=dt(h,n),Rt(e,t,o,h,l)}if("backward"===o||"forward"===o){const e=i.type,l=i.offset,c=i.getNode();if(!c)return!1;const u=s.getNodes();return(1!==u.length||!J(u[0]))&&(!!function(e,t,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,t,o,r){const l=n(o,(e=>g(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===t:t===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,t,o,r)}(e,l,c,o)&&function(e,t,o,r,l){const[s,i]=Ue(r,o,o);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,i,l))return!1;const c=function(e,t,o){const r=n(e,(e=>g(e)&&!e.isInline()));if(!r)return;const l="backward"===t?r.getPreviousSibling():r.getNextSibling();return l&&It(l)?l:"backward"===t?o.getPreviousSibling():o.getNextSibling()}(t,l,r);if(!c||It(c))return!1;Ot(e),"backward"===l?c.selectEnd():c.selectStart();return!0}(t,c,a,r,o))}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return!1;let m;if("element"===i.type)m=f.getBoundingClientRect();else{const t=k(rt(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?a.getFirstChild():a.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){Ot(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return pt(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(Ve(s)){const{anchor:i,focus:c}=s,a=n(i.getNode(),ge),u=n(c.getNode(),ge),[h]=s.getNodes();It(h)||pe(251);const d=ot(h,e.getElementByKey(h.getKey()));if(!ge(a)||!ge(u)||!It(h)||null==d)return!1;l.$updateTableTableSelection(s);const g=dt(h,d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.$setAnchorCellForSelection(m),Ot(t),t.shiftKey){const[e,t,n]=Ue(r,a,u);return wt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function Ot(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ft(e,t,n){const o=d();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function kt(e,t,o){const r=o.getParent();if(!r)return;const l=k(rt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=ot(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),(e=>ge(e)));if(!a)return;const u=n(a,(e=>It(e)));if(!It(u)||!u.is(o))return;const[h,d]=Ue(o,a,a),g=h[0][0],f=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===g.startRow&&p===g.startColumn,S=m===f.startRow&&p===f.startColumn;return C?"first":S?"last":void 0}function Et(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Kt(e,t,n){return lt(e,z(t,n))}function Mt(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function At(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}const $t=new WeakSet;function Lt(e=R()){return $t.has(e)}function Pt(e,t){t?$t.add(e):$t.delete(e)}class Ht extends u{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 Ht(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:Bt,priority:1})}}static importJSON(e){const t=Dt();return t.__rowStriping=e.rowStriping||!1,t.__colWidths=e.colWidths,t}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&pe(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");if(o.appendChild(r),Mt(o,0,this.getColumnCount(),this.getColWidths()),re(r),e(o,t.theme.table),this.__rowStriping&&At(o,t,!0),Lt(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&At(t,n,this.__rowStriping),Mt(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:e=>{if(t.after&&(e=t.after(e)),e&&l(e)&&"TABLE"!==e.nodeName&&(e=e.querySelector("table")),!e||!l(e))return null;const[n]=ze(this,null,null),o=new Map;for(const e of n)for(const t of e){const e=t.cell.getKey();o.has(e)||o.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const r=new Set;for(const t of e.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const e=t.getAttribute("data-temporary-table-cell-lexical-key");if(e){const n=o.get(e);if(t.removeAttribute("data-temporary-table-cell-lexical-key"),n){o.delete(e);for(let e=0;e<n.colSpan;e++)r.add(e+n.startColumn)}}}const s=e.querySelector(":scope > colgroup");if(s){const t=Array.from(e.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>r.has(t)));s.replaceChildren(...t)}const i=e.querySelectorAll(":scope > tr");if(i.length>0){const t=document.createElement("tbody");for(const e of i)t.appendChild(e);e.append(t)}return e},element:n&&l(n)&&"TABLE"!==n.nodeName?n.querySelector("table"):n}}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=Kt(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,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=z(o.elem);return ge(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}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){this.getWritable().__rowStriping=e}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{ge(e)&&(t+=e.getColSpan())})),t}}function Wt(e,t){const n=e.getElementByKey(t.getKey());return null===n&&pe(230),dt(t,n)}function Bt(e){const n=Dt();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!ce.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,we),node:n}}function Dt(){return p(new Ht)}function It(e){return e instanceof Ht}function Ut({rows:e,columns:t,includeHeaders:n}){const o=xe(Number(e),Number(t),n);c(o);const r=o.getFirstDescendant();return m(r)&&r.select(),!0}function zt(e){we(e.getParent())?e.isEmpty()&&e.append(d()):e.remove()}function Yt(e){It(e.getParent())?a(e,ge):e.remove()}function qt(e){a(e,we);const[t]=ze(e,null,null),n=t.reduce(((e,t)=>Math.max(e,t.length)),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;we(r)||pe(253,r.constructor.name,r.getType());const l=t[e].reduce(((e,t)=>t?1+e:e),0);if(l!==n)for(let e=l;e<n;++e){const e=de();e.append(d()),r.append(e)}}}function Xt(e){return e.registerNodeTransform(ue,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Ye(e),[n]=Ue(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();we(l)||pe(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),we(l)||pe(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){ge(c)||pe(176);const e=de(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))}function Jt(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=ot(o,l),i=at(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(Ht,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Ze(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}}),{editor:e})}),{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}}function jt(e){return e.hasNodes([Ht])||pe(254),i(e.registerCommand(fe,Ut,le),e.registerNodeTransform(Ht,qt),e.registerNodeTransform(Ce,Yt),e.registerNodeTransform(ue,zt))}export{Ue as $computeTableMap,ze as $computeTableMapSkipCellCheck,de as $createTableCellNode,Dt as $createTableNode,xe as $createTableNodeWithDimensions,_e as $createTableRowNode,Ge as $createTableSelection,Pe as $deleteTableColumn,We as $deleteTableColumn__EXPERIMENTAL,He as $deleteTableRow__EXPERIMENTAL,Tt as $findCellNode,vt as $findTableNode,Wt as $getElementForTableNode,Ye as $getNodeTriplet,Ze as $getTableAndElementByKey,Te as $getTableCellNodeFromLexicalNode,Xe as $getTableCellNodeRect,Fe as $getTableColumnIndexFromTableCellNode,Re as $getTableNodeFromLexicalNodeOrThrow,Oe as $getTableRowIndexFromTableCellNode,ve as $getTableRowNodeFromTableCellNodeOrThrow,$e as $insertTableColumn,Le as $insertTableColumn__EXPERIMENTAL,Ke as $insertTableRow,Ae as $insertTableRow__EXPERIMENTAL,Lt as $isScrollableTablesActive,ge as $isTableCellNode,It as $isTableNode,we as $isTableRowNode,Ve as $isTableSelection,Ee as $removeTableRowAtIndex,Ie as $unmergeCell,fe as INSERT_TABLE_COMMAND,ae as TableCellHeaderStates,ue as TableCellNode,Ht as TableNode,et as TableObserver,Ce as TableRowNode,at as applyTableHandlers,ht as getDOMCellFromTarget,ot as getTableElement,ut as getTableObserverFromTableElement,Xt as registerTableCellUnmergeTransform,jt as registerTablePlugin,Jt as registerTableSelectionObserver,Pt as setScrollableTablesActive};
|
9
|
+
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$unwrapAndFilterDescendants as a}from"@lexical/utils";import{ElementNode as u,isHTMLElement as h,$createParagraphNode as d,$isElementNode as g,$isLineBreakNode as f,$isTextNode as m,$applyNodeReplacement as p,createCommand as S,$createTextNode as C,$getSelection as _,$isRangeSelection as w,$createPoint as b,$isParagraphNode as y,$normalizeSelection__EXPERIMENTAL as N,isCurrentlyReadOnlyMode as x,TEXT_TYPE_TO_FORMAT as T,$getNodeByKey as v,$getEditor as R,$setSelection as O,SELECTION_CHANGE_COMMAND as F,getDOMSelection as k,$createRangeSelection as E,$getRoot as K,COMMAND_PRIORITY_HIGH as M,KEY_ESCAPE_COMMAND as A,COMMAND_PRIORITY_CRITICAL as $,CUT_COMMAND as L,FORMAT_TEXT_COMMAND as P,FORMAT_ELEMENT_COMMAND as H,CONTROLLED_TEXT_INSERTION_COMMAND as W,KEY_TAB_COMMAND as B,FOCUS_COMMAND as D,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as U,$getNearestNodeFromDOMNode as z,$createRangeSelectionFromDom as Y,INSERT_PARAGRAPH_COMMAND as q,$isRootOrShadowRoot as X,$isDecoratorNode as J,KEY_ARROW_DOWN_COMMAND as j,KEY_ARROW_UP_COMMAND as V,KEY_ARROW_LEFT_COMMAND as G,KEY_ARROW_RIGHT_COMMAND as Q,DELETE_WORD_COMMAND as Z,DELETE_LINE_COMMAND as ee,DELETE_CHARACTER_COMMAND as te,KEY_BACKSPACE_COMMAND as ne,KEY_DELETE_COMMAND as oe,setDOMUnmanaged as re,COMMAND_PRIORITY_EDITOR as le}from"lexical";import{copyToClipboard as se,$getClipboardDataFromSelection as ie}from"@lexical/clipboard";const ce=/^(\d+(?:\.\d+)?)px$/,ae={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ue extends u{static getType(){return"tablecell"}static clone(e){return new ue(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor}static importDOM(){return{td:e=>({conversion:he,priority:0}),th:e=>({conversion:he,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return de(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=ae.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 t=super.exportDOM(e);if(t.element&&h(t.element)){const e=t.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="top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return 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.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=ae.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}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!==ae.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 he(e){const t=e,n=e.nodeName.toLowerCase();let o;ce.test(t.style.width)&&(o=parseFloat(t.style.width));const r=de("th"===n?ae.ROW:ae.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style,i=(s&&s.textDecoration||"").split(" "),c="700"===s.fontWeight||"bold"===s.fontWeight,a=i.includes("line-through"),u="italic"===s.fontStyle,h=i.includes("underline");return{after:e=>(0===e.length&&e.push(d()),e),forChild:(e,t)=>{if(ge(t)&&!g(e)){const t=d();return f(e)&&"\n"===e.getTextContent()?null:(m(e)&&(c&&e.toggleFormat("bold"),a&&e.toggleFormat("strikethrough"),u&&e.toggleFormat("italic"),h&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function de(e=ae.NO_STATUS,t=1,n){return p(new ue(e,t,n))}function ge(e){return e instanceof ue}const fe=S("INSERT_TABLE_COMMAND");function me(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pe=me((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.`)}));class Se extends u{static getType(){return"tablerow"}static clone(e){return new Se(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:Ce,priority:0})}}static importJSON(e){return _e(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}extractWithChild(e,t,n){return"html"===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 Ce(e){const n=e;let o;return ce.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,ge),node:_e(o)}}function _e(e){return p(new Se(e))}function we(e){return e instanceof Se}const be="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ye=be&&"documentMode"in document?document.documentMode:null,Ne=be&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function xe(e,t,n=!0){const o=Dt();for(let r=0;r<e;r++){const e=_e();for(let o=0;o<t;o++){let t=ae.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=ae.ROW),0===o&&n.columns&&(t|=ae.COLUMN)):n&&(0===r&&(t|=ae.ROW),0===o&&(t|=ae.COLUMN));const l=de(t),s=d();s.append(C()),l.append(s),e.append(l)}o.append(e)}return o}function Te(e){const t=n(e,(e=>ge(e)));return ge(t)?t:null}function ve(e){const t=n(e,(e=>we(e)));if(we(t))return t;throw new Error("Expected table cell to be inside of table row.")}function Re(e){const t=n(e,(e=>It(e)));if(It(t))return t;throw new Error("Expected table cell to be inside of table.")}function Oe(e){const t=ve(e);return Re(t).getChildren().findIndex((e=>e.is(t)))}function Fe(e){return ve(e).getChildren().findIndex((t=>t.is(e)))}function ke(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 Ee(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 Ke(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 s=l[t];if(!we(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=_e();for(let n=0;n<t;n++){const t=e[n];ge(t)||pe(12);const{above:l,below:s}=ke(t,r);let i=ae.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(ae.COLUMN)||s&&s.hasHeaderState(ae.COLUMN))&&(i|=ae.COLUMN);const a=de(i,1,c);a.append(d()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}be&&"InputEvent"in window&&!ye&&new window.InputEvent("input");const Me=(e,t)=>e===ae.BOTH||e===t?t:ae.NO_STATUS;function Ae(e=!0){const t=_();w(t)||Ve(t)||pe(188);const n=t.focus.getNode(),[o,,r]=Ye(n),[l,s]=Ue(r,o,o),i=l[0].length,{startRow:c}=s;let a=null;if(e){const e=c+o.__rowSpan-1,t=l[e],n=_e();for(let o=0;o<i;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Me(e,ae.COLUMN);n.append(de(r).append(d()))}else r.setRowSpan(r.__rowSpan+1)}const s=r.getChildAtIndex(e);we(s)||pe(145),s.insertAfter(n),a=n}else{const e=l[c],t=_e();for(let n=0;n<i;n++){const{cell:o,startRow:r}=e[n];if(r===c){const o=e[n].cell.__headerState,r=Me(o,ae.COLUMN);t.append(de(r).append(d()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(c);we(n)||pe(145),n.insertBefore(t),a=t}return a}function $e(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(we(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];ge(o)||pe(12);const{left:l,right:i}=ke(o,r);let c=ae.NO_STATUS;(l&&l.hasHeaderState(ae.ROW)||i&&i.hasHeaderState(ae.ROW))&&(c|=ae.ROW);const a=de(c);a.append(d()),s.push({newTableCell:a,targetCell:o})}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Le(e=!0){const t=_();w(t)||Ve(t)||pe(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ye(n),[l,,s]=Ye(o),[i,c,a]=Ue(s,l,r),u=i.length,h=e?Math.max(c.startColumn,a.startColumn):Math.min(c.startColumn,a.startColumn),g=e?h+l.__colSpan-1:h-1,f=s.getFirstChild();we(f)||pe(120);let m=null;function p(e=ae.NO_STATUS){const t=de(e).append(d());return null===m&&(m=t),t}let S=f;e:for(let e=0;e<u;e++){if(0!==e){const e=S.getNextSibling();we(e)||pe(121),S=e}const t=i[e],n=t[g<0?0:g].cell.__headerState,o=Me(n,ae.ROW);if(g<0){De(S,p(o));continue}const{cell:r,startColumn:l,startRow:s}=t[g];if(l+r.__colSpan-1<=g){let n=r,l=s,i=g;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){S.append(p(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(p(o))}else r.setColSpan(r.__colSpan+1)}null!==m&&Be(m);const C=s.getColWidths();if(C){const e=[...C],t=g<0?0:g,n=e[t];e.splice(t,0,n),s.setColWidths(e)}return m}function Pe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(we(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 He(){const e=_();w(e)||Ve(e)||pe(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Ye(t),[l]=Ye(n),[s,i,c]=Ue(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,g=o.__rowSpan,f=s[h+1],m=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(e===a&&o<a){const e=a-o;n.setRowSpan(n.__rowSpan-Math.min(g,n.__rowSpan-e))}if(o>=a&&o+n.__rowSpan-1>h){n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&pe(122);let r=null;for(let n=0;n<t;n++){const t=f[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?De(m,n):r.insertAfter(n)}}}const t=r.getChildAtIndex(e);we(t)||pe(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];Be(e)}else{const e=s[a-1],{cell:t}=e[0];Be(t)}}function We(){const e=_();w(e)||Ve(e)||pe(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ye(t),[l]=Ye(n),[s,i,c]=Ue(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),g=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),f=g-d+1;if(s[0].length===g-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=g;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(f,n.__colSpan-e))}}else if(o+n.__colSpan-1>g){if(t===g){const e=g-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],S=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==S){const{cell:e}=S;Be(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Be(t)}const C=r.getColWidths();if(C){const e=[...C];e.splice(d,f),r.setColWidths(e)}}function Be(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function De(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ie(){const e=_();w(e)||Ve(e)||pe(188);const t=e.anchor.getNode(),[n,o,r]=Ye(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[i,c]=Ue(r,n,n),{startColumn:a,startRow:u}=c,h=n.__headerState&ae.COLUMN,g=Array.from({length:l},((e,t)=>{let n=h;for(let e=0;0!==n&&e<i.length;e++)n&=i[e][t+a].cell.__headerState;return n})),f=n.__headerState&ae.ROW,m=Array.from({length:s},((e,t)=>{let n=f;for(let e=0;0!==n&&e<i[0].length;e++)n&=i[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(de(g[e]|m[0]).append(d()));n.setColSpan(1)}if(s>1){let e;for(let t=1;t<s;t++){const n=u+t,r=i[n];e=(e||o).getNextSibling(),we(e)||pe(125);let s=null;for(let e=0;e<a;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 n=l-1;n>=0;n--)De(e,de(g[n]|m[t]).append(d()));else for(let e=l-1;e>=0;e--)s.insertAfter(de(g[e]|m[t]).append(d()))}n.setRowSpan(1)}}function Ue(e,t,n){const[o,r,l]=ze(e,t,n);return null===r&&pe(207),null===l&&pe(208),[o,r,l]}function ze(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];we(o)||pe(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){ge(c)||pe(147);const o=s(e);for(;void 0!==o[a];)a++;const u={cell:c,startColumn:a,startRow:e},{__rowSpan:h,__colSpan:d}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[a+e]=u}null!==t&&null===r&&t.is(c)&&(r=u),null!==n&&null===l&&n.is(c)&&(l=u)}}return[o,r,l]}function Ye(e){let t;if(e instanceof ue)t=e;else if("__type"in e){const o=n(e,ge);ge(o)||pe(148),t=o}else{const o=n(e.getNode(),ge);ge(o)||pe(148),t=o}const o=t.getParent();we(o)||pe(149);const r=o.getParent();return It(r)||pe(210),[t,o,r]}function qe(e,t,n){let o=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),l=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),s=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1),i=o,c=r,a=o,u=r;function h(e){const{cell:t,startColumn:n,startRow:i}=e;o=Math.min(o,n),r=Math.min(r,i),l=Math.max(l,n+t.__colSpan-1),s=Math.max(s,i+t.__rowSpan-1)}for(;o<i||r<c||l>a||s>u;){if(o<i){const t=u-c,n=i-1;for(let o=0;o<=t;o++)h(e[c+o][n]);i=n}if(r<c){const t=a-i,n=c-1;for(let o=0;o<=t;o++)h(e[n][i+o]);c=n}if(l>a){const t=u-c,n=a+1;for(let o=0;o<=t;o++)h(e[c+o][n]);a=n}if(s>u){const t=a-i,n=u+1;for(let o=0;o<=t;o++)h(e[n][i+o]);u=n}}return{maxColumn:l,maxRow:s,minColumn:o,minRow:r}}function Xe(e){const[t,,n]=Ye(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,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Je(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=n(o,ge);ge(r)||pe(238,t,o.getKey(),o.getType());const l=r.getParent();we(l)||pe(239,t);const s=l.getParent();return It(s)||pe(240,t),[o,r,l,s]}));return l.is(a)||pe(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class je{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(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Ve(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 je(this.tableKey,b(this.anchor.key,this.anchor.offset,this.anchor.type),b(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(ge).forEach((e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())}));const n=T[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();g(t)||pe(151);N(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Je(this),n=Xe(e);null===n&&pe(153);const o=Xe(t);null===o&&pe(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:t,anchorCell:n,focusCell:o}=Je(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&pe(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&pe(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Ue(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=qe(l,s,i),d=new Map([[t.getKey(),t]]);let g=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();we(o)||pe(160),o!==g&&(d.set(o.getKey(),o),g=o),d.has(n.getKey())||Qe(n,(e=>{d.set(e.getKey(),e)}))}const f=Array.from(d.values());return x()||(this._cachedNodes=f),f}getTextContent(){const e=this.getNodes().filter((e=>ge(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 Ve(e){return e instanceof je}function Ge(){const e=b("root",0,"element"),t=b("root",0,"element");return new je("root",e,t)}function Qe(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&g(o)&&n.push(o.getChildren())}}function Ze(e,t=R()){const n=v(e);It(n)||pe(231,e);const o=ot(n,t.getElementByKey(e));return null===o&&pe(232,e),{tableElement:o,tableNode:n}}class et{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.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return Ze(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=dt(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=dt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})}),{editor:this.editor})}$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();const{tableNode:t,tableElement:n}=this.$lookup();gt(e,dt(t,n),null),null!==_()&&(O(null),e.dispatchCommand(F,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&pe(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),gt(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=k(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Kt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=function(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=_(),r=Ve(o)?o.clone():Ge();return r.set(e.getKey(),t.getKey(),n.getKey()),r}(o,this.$getAnchorTableCellOrThrow(),t),O(this.tableSelection),n.dispatchCommand(F,void 0),gt(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&pe(234),e}$getFocusTableCell(){return this.focusCellNodeKey?v(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&pe(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Kt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ge(),this.anchorCellNodeKey=e}}$formatCells(e){const t=_();Ve(t)||pe(236);const n=E(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ge);l.length>0||pe(237);const s=l[0].getFirstChild(),i=y(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)})),O(t),this.editor.dispatchCommand(F,void 0)}$clearText(){const{editor:e}=this,t=v(this.tableNodeKey);if(!It(t))throw new Error("Expected TableNode.");const n=_();Ve(n)||pe(11);const o=n.getNodes().filter(ge);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(g(e)){const t=d(),n=C();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),gt(e,this.table,null),O(null),e.dispatchCommand(F,void 0);else{t.selectPrevious(),t.remove();K().selectStart()}}}const tt="__lexicalTableSelection",nt=e=>!(1&~e.buttons);function ot(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&pe(245,t.nodeName),n}function rt(e){return e._window}function lt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ge(n)&&(o=n)}return null}const st=[[j,"down"],[V,"up"],[G,"backward"],[Q,"forward"]],it=[Z,ee,te],ct=[ne,oe];function at(e,t,o,l){const s=o.getRootElement(),i=rt(o);null!==s&&null!==i||pe(246);const c=new et(o,e.getKey()),a=ot(e,t);!function(e,t){null!==ut(e)&&pe(205);e[tt]=t}(a,c),c.listenersToRemove.add((()=>function(e,t){ut(e)===t&&delete e[tt]}(a,c)));a.addEventListener("mousedown",(t=>{if(0!==t.button)return;if(!i)return;const n=ht(t.target);null!==n&&o.update((()=>{const o=U();if(Ne&&t.shiftKey&&bt(o,e)&&(w(o)||Ve(o))){const r=o.anchor.getNode(),l=lt(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(Et(c,l)),c.$setFocusCellForSelection(n),Ot(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else c.$setAnchorCellForSelection(n)})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("mouseup",e),i.removeEventListener("mousemove",t)},t=n=>{if(!nt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("mouseup",e),void i.removeEventListener("mousemove",t);const r=!a.contains(n.target);let l=null;if(r){for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(l=a.contains(e)?ht(e):null,l)break}else l=ht(n.target);!l||null!==c.focusCell&&l.elem===c.focusCell.elem||(c.setNextFocus({focusCell:l,override:r}),o.dispatchCommand(F,void 0))};c.isSelecting=!0,i.addEventListener("mouseup",e,c.listenerOptions),i.addEventListener("mousemove",t,c.listenerOptions)})()}),c.listenerOptions);i.addEventListener("mousedown",(e=>{0===e.button&&o.update((()=>{const t=_(),n=e.target;Ve(t)&&t.tableKey===c.tableNodeKey&&s.contains(n)&&c.$clearHighlight()}))}),c.listenerOptions);for(const[t,n]of st)c.listenersToRemove.add(o.registerCommand(t,(t=>Rt(o,t,n,e,c)),M));c.listenersToRemove.add(o.registerCommand(A,(t=>{const n=_();if(Ve(n)){const o=lt(e,n.focus.getNode());if(null!==o)return Ot(t),o.selectEnd(),!0}return!1}),M));const u=t=>()=>{const o=_();if(!bt(o,e))return!1;if(Ve(o))return c.$clearText(),!0;if(w(o)){if(!ge(lt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=n(o.anchor.getNode(),(e=>g(e))),u=a&&n(a,(e=>g(e)&&ge(e.getParent())));if(!g(u)||!g(a))return!1;if(t===ee&&null===u.getPreviousSibling())return!0}return!1};for(const e of it)c.listenersToRemove.add(o.registerCommand(e,u(e),$));const h=t=>{const n=_();if(!Ve(n)&&!w(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!Ve(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0)};for(const e of ct)c.listenersToRemove.add(o.registerCommand(e,h,$));return c.listenersToRemove.add(o.registerCommand(L,(e=>{const t=_();if(t){if(!Ve(t)&&!w(t))return!1;se(o,r(e,ClipboardEvent)?e:null,ie(t));const n=h(e);return w(t)?(t.removeText(),!0):n}return!1}),$)),c.listenersToRemove.add(o.registerCommand(P,(t=>{const o=_();if(!bt(o,e))return!1;if(Ve(o))return c.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),(e=>ge(e)));if(!ge(e))return!1}return!1}),$)),c.listenersToRemove.add(o.registerCommand(H,(t=>{const n=_();if(!Ve(n)||!bt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ge(o)||!ge(r))return!1;const[l,s,i]=Ue(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];g(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),$)),c.listenersToRemove.add(o.registerCommand(W,(t=>{const r=_();if(!bt(r,e))return!1;if(Ve(r))return c.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),(e=>ge(e)));if(!ge(l))return!1;if("string"==typeof t){const n=kt(o,r,e);if(n)return Ft(n,e,[C(t)]),!0}}return!1}),$)),l&&c.listenersToRemove.add(o.registerCommand(B,(t=>{const o=_();if(!w(o)||!o.isCollapsed()||!bt(o,e))return!1;const r=Tt(o.anchor.getNode());return!(null===r||!e.is(vt(r)))&&(Ot(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(g(l))return l.selectEnd();const s=n(e,we);null===s&&pe(247);for(let e=s[o]();we(e);e=e[o]()){const t=e[r]();if(g(t))return t.selectEnd()}const i=n(s,It);null===i&&pe(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)}),$)),c.listenersToRemove.add(o.registerCommand(D,(t=>e.isSelected()),M)),c.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=Ve(o),s=w(o)&&null!==n(o.anchor.getNode(),(e=>ge(e)))&&null!==n(o.focus.getNode(),(e=>ge(e)))||l;if(1!==t.length||!It(t[0])||!s||null===r)return!1;const[i]=r,c=t[0],a=c.getChildren(),u=c.getFirstChildOrThrow().getChildrenSize(),h=c.getChildrenSize(),g=n(i.getNode(),(e=>ge(e))),f=g&&n(g,(e=>we(e))),p=f&&n(f,(e=>It(e)));if(!ge(g)||!we(f)||!It(p))return!1;const S=f.getIndexWithinParent(),C=Math.min(p.getChildrenSize()-1,S+h-1),_=g.getIndexWithinParent(),b=Math.min(f.getChildrenSize()-1,_+u-1),y=Math.min(_,b),N=Math.min(S,C),x=Math.max(_,b),T=Math.max(S,C),v=p.getChildren();let R=0;for(let e=N;e<=T;e++){const t=v[e];if(!we(t))return!1;const n=a[R];if(!we(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ge(t))return!1;const n=r[l];if(!ge(n))return!1;const s=t.getChildren();n.getChildren().forEach((e=>{if(m(e)){d().append(e),t.append(e)}else t.append(e)})),s.forEach((e=>e.remove())),l++}R++}return!0}),$)),c.listenersToRemove.add(o.registerCommand(F,(()=>{const t=_(),r=U(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(Ve(t)&&t.tableKey===c.tableNodeKey)return(n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&bt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&w(r)&&w(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=Tt(o);if(null!==l&&we(r)){const t=r.getFirstChild();if(ge(t)&&e.is(n(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if(w(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Tt(l),a=Tt(s),u=!(!i||!e.is(vt(i))),h=!(!a||!e.is(vt(a))),d=u!==h,g=u&&h,f=t.isBackward();if(d){const n=t.clone();if(h){const[t]=Ue(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(f?o.getKey():r.getKey(),f?o.getChildrenSize():r.getChildrenSize(),"element")}else if(u){const[t]=Ue(e,i,i),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(f?r.getKey():o.getKey(),f?r.getChildrenSize():0,"element")}O(n),mt(o,c)}else g&&(i.is(a)||(c.$setAnchorCellForSelection(Et(c,i)),c.$setFocusCellForSelection(Et(c,a),!0)))}else if(t&&Ve(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=k(i);if(n&&n.anchorNode&&n.focusNode){const r=z(n.focusNode),l=r&&!e.isParentOf(r),s=z(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=Y(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),O(r))}}}return t&&!t.is(r)&&(Ve(t)||Ve(r))&&c.tableSelection&&!c.tableSelection.is(r)?(Ve(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!Ve(t)&&Ve(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),ft(t.table,(t=>{const n=t.elem;t.highlighted=!1,xt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&mt(o,c),!1)}),$)),c.listenersToRemove.add(o.registerCommand(q,(()=>{const t=_();if(!w(t)||!t.isCollapsed()||!bt(t,e))return!1;const n=kt(o,t,e);return!!n&&(Ft(n,e),!0)}),$)),c}function ut(e){return e[tt]||null}function ht(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 dt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=ot(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 gt(e,t,n){const o=new Set(n?n.getNodes():[]);ft(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Nt(e,t)):(t.highlighted=!1,xt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function ft(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=z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function mt(e,t){t.$disableHighlightStyle(),ft(t.table,(t=>{t.highlighted=!0,Nt(e,t)}))}const pt=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?yt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?yt(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?yt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?yt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function St(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 Ct([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function _t(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&pe(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&pe(250,n,String(s)),i}function wt(e,t,n,o,r){const l=qe(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=St(e,t);return null===n&&pe(249,t.cell.getKey()),n}(l,n),[d,g]=Ct(h);let f=l[d],m=l[g];"forward"===r?f+="maxColumn"===d?1:c:"backward"===r?f-="minColumn"===d?1:u:"down"===r?m+="maxRow"===g?1:i:"up"===r&&(m-="minRow"===g?1:a);const p=t[m];if(void 0===p)return!1;const S=p[f];if(void 0===S)return!1;const[C,_]=function(e,t,n){const o=qe(e,t,n),r=St(o,t);if(r)return[_t(e,o,r),_t(e,o,Ct(r))];const l=St(o,n);if(l)return[_t(e,o,Ct(l)),_t(e,o,l)];const s=["minColumn","minRow"];return[_t(e,o,s),_t(e,o,Ct(s))]}(t,n,S),w=Et(e,C.cell),b=Et(e,_.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function bt(e,t){if(w(e)||Ve(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function yt(e,t){t?e.selectStart():e.selectEnd()}function Nt(t,n){const o=n.elem,r=t._config.theme;ge(z(o))||pe(131),e(o,r.tableCellSelected)}function xt(e,t){const n=t.elem;ge(z(n))||pe(131);const r=e._config.theme;o(n,r.tableCellSelected)}function Tt(e){const t=n(e,ge);return ge(t)?t:null}function vt(e){const t=n(e,It);return It(t)?t:null}function Rt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=_();if(!bt(s,r)){if(w(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(g(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!It(n)&&(Ot(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=n(e,(e=>It(e)));if(ge(l)&&(l=n(l,It)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let c=0;"up"===o&&g(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&g(i)){const e=i.getLastChild();a=e||i,c=m(a)?a.getTextContentSize():0}const u=s.clone();return u.focus.set(a.getKey(),c,m(a)?"text":"element"),O(u),Ot(t),!0}if(X(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==lt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ye(e),[o]=Ye(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,(e=>g(e)&&!e.isInline()));if(ge(r)&&(r=n(r,It)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(It(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[r]=Ye(e),[l]=Ye(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Ot(t),O(c),!0}}}}return"down"===o&&Lt(e)&&l.setShouldCheckSelection(),!1}if(w(s)&&s.isCollapsed()){const{anchor:i,focus:c}=s,a=n(i.getNode(),ge),u=n(c.getNode(),ge);if(!ge(a)||!a.is(u))return!1;const h=vt(a);if(h!==r&&null!=h){const n=ot(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=dt(h,n),Rt(e,t,o,h,l)}if("backward"===o||"forward"===o){const e=i.type,l=i.offset,c=i.getNode();if(!c)return!1;const u=s.getNodes();return(1!==u.length||!J(u[0]))&&(!!function(e,t,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,t,o,r){const l=n(o,(e=>g(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===t:t===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,t,o,r)}(e,l,c,o)&&function(e,t,o,r,l){const[s,i]=Ue(r,o,o);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,i,l))return!1;const c=function(e,t,o){const r=n(e,(e=>g(e)&&!e.isInline()));if(!r)return;const l="backward"===t?r.getPreviousSibling():r.getNextSibling();return l&&It(l)?l:"backward"===t?o.getPreviousSibling():o.getNextSibling()}(t,l,r);if(!c||It(c))return!1;Ot(e),"backward"===l?c.selectEnd():c.selectStart();return!0}(t,c,a,r,o))}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return!1;let m;if("element"===i.type)m=f.getBoundingClientRect();else{const t=k(rt(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?a.getFirstChild():a.getLastChild();if(null==p)return!1;const S=e.getElementByKey(p.__key);if(null==S)return!1;const C=S.getBoundingClientRect();if("up"===o?C.top>m.top-m.height:m.bottom+m.height>C.bottom){Ot(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return pt(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(Ve(s)){const{anchor:i,focus:c}=s,a=n(i.getNode(),ge),u=n(c.getNode(),ge),[h]=s.getNodes();It(h)||pe(251);const d=ot(h,e.getElementByKey(h.getKey()));if(!ge(a)||!ge(u)||!It(h)||null==d)return!1;l.$updateTableTableSelection(s);const g=dt(h,d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.$setAnchorCellForSelection(m),Ot(t),t.shiftKey){const[e,t,n]=Ue(r,a,u);return wt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function Ot(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ft(e,t,n){const o=d();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function kt(e,t,o){const r=o.getParent();if(!r)return;const l=k(rt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=ot(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),(e=>ge(e)));if(!a)return;const u=n(a,(e=>It(e)));if(!It(u)||!u.is(o))return;const[h,d]=Ue(o,a,a),g=h[0][0],f=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,S=m===g.startRow&&p===g.startColumn,C=m===f.startRow&&p===f.startColumn;return S?"first":C?"last":void 0}function Et(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Kt(e,t,n){return lt(e,z(t,n))}function Mt(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function At(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}const $t=new WeakSet;function Lt(e=R()){return $t.has(e)}function Pt(e,t){t?$t.add(e):$t.delete(e)}class Ht extends u{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 Ht(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:Bt,priority:1})}}static importJSON(e){const t=Dt();return t.__rowStriping=e.rowStriping||!1,t.__colWidths=e.colWidths,t}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&pe(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");if(o.appendChild(r),Mt(o,0,this.getColumnCount(),this.getColWidths()),re(r),e(o,t.theme.table),this.__rowStriping&&At(o,t,!0),Lt(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&At(t,n,this.__rowStriping),Mt(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:e=>{if(t.after&&(e=t.after(e)),e&&l(e)&&"TABLE"!==e.nodeName&&(e=e.querySelector("table")),!e||!l(e))return null;const[n]=ze(this,null,null),o=new Map;for(const e of n)for(const t of e){const e=t.cell.getKey();o.has(e)||o.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const r=new Set;for(const t of e.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const e=t.getAttribute("data-temporary-table-cell-lexical-key");if(e){const n=o.get(e);if(t.removeAttribute("data-temporary-table-cell-lexical-key"),n){o.delete(e);for(let e=0;e<n.colSpan;e++)r.add(e+n.startColumn)}}}const s=e.querySelector(":scope > colgroup");if(s){const t=Array.from(e.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>r.has(t)));s.replaceChildren(...t)}const i=e.querySelectorAll(":scope > tr");if(i.length>0){const t=document.createElement("tbody");for(const e of i)t.appendChild(e);e.append(t)}return e},element:n&&l(n)&&"TABLE"!==n.nodeName?n.querySelector("table"):n}}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=Kt(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,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=z(o.elem);return ge(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}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){this.getWritable().__rowStriping=e}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{ge(e)&&(t+=e.getColSpan())})),t}}function Wt(e,t){const n=e.getElementByKey(t.getKey());return null===n&&pe(230),dt(t,n)}function Bt(e){const n=Dt();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!ce.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,we),node:n}}function Dt(){return p(new Ht)}function It(e){return e instanceof Ht}function Ut({rows:e,columns:t,includeHeaders:n}){const o=xe(Number(e),Number(t),n);c(o);const r=o.getFirstDescendant();return m(r)&&r.select(),!0}function zt(e){we(e.getParent())?e.isEmpty()&&e.append(d()):e.remove()}function Yt(e){It(e.getParent())?a(e,ge):e.remove()}function qt(e){a(e,we);const[t]=ze(e,null,null),n=t.reduce(((e,t)=>Math.max(e,t.length)),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;we(r)||pe(253,r.constructor.name,r.getType());const l=t[e].reduce(((e,t)=>t?1+e:e),0);if(l!==n)for(let e=l;e<n;++e){const e=de();e.append(d()),r.append(e)}}}function Xt(e){return e.registerNodeTransform(ue,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Ye(e),[n]=Ue(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();we(l)||pe(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),we(l)||pe(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){ge(c)||pe(176);const e=de(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))}function Jt(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=ot(o,l),i=at(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(Ht,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Ze(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}}),{editor:e})}),{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}}function jt(e){return e.hasNodes([Ht])||pe(254),i(e.registerCommand(fe,Ut,le),e.registerNodeTransform(Ht,qt),e.registerNodeTransform(Se,Yt),e.registerNodeTransform(ue,zt))}export{Ue as $computeTableMap,ze as $computeTableMapSkipCellCheck,de as $createTableCellNode,Dt as $createTableNode,xe as $createTableNodeWithDimensions,_e as $createTableRowNode,Ge as $createTableSelection,Pe as $deleteTableColumn,We as $deleteTableColumn__EXPERIMENTAL,He as $deleteTableRow__EXPERIMENTAL,Tt as $findCellNode,vt as $findTableNode,Wt as $getElementForTableNode,Ye as $getNodeTriplet,Ze as $getTableAndElementByKey,Te as $getTableCellNodeFromLexicalNode,Xe as $getTableCellNodeRect,Fe as $getTableColumnIndexFromTableCellNode,Re as $getTableNodeFromLexicalNodeOrThrow,Oe as $getTableRowIndexFromTableCellNode,ve as $getTableRowNodeFromTableCellNodeOrThrow,$e as $insertTableColumn,Le as $insertTableColumn__EXPERIMENTAL,Ke as $insertTableRow,Ae as $insertTableRow__EXPERIMENTAL,Lt as $isScrollableTablesActive,ge as $isTableCellNode,It as $isTableNode,we as $isTableRowNode,Ve as $isTableSelection,Ee as $removeTableRowAtIndex,Ie as $unmergeCell,fe as INSERT_TABLE_COMMAND,ae as TableCellHeaderStates,ue as TableCellNode,Ht as TableNode,et as TableObserver,Se as TableRowNode,at as applyTableHandlers,ht as getDOMCellFromTarget,ot as getTableElement,ut as getTableObserverFromTableElement,Xt as registerTableCellUnmergeTransform,jt as registerTablePlugin,Jt as registerTableSelectionObserver,Pt as setScrollableTablesActive};
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.21.1-nightly.
|
11
|
+
"version": "0.21.1-nightly.20241213.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/clipboard": "0.21.1-nightly.
|
16
|
-
"@lexical/utils": "0.21.1-nightly.
|
17
|
-
"lexical": "0.21.1-nightly.
|
15
|
+
"@lexical/clipboard": "0.21.1-nightly.20241213.0",
|
16
|
+
"@lexical/utils": "0.21.1-nightly.20241213.0",
|
17
|
+
"lexical": "0.21.1-nightly.20241213.0"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|