@lexical/table 0.20.1-nightly.20241114.0 → 0.20.1-nightly.20241118.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LexicalTable.dev.js +2 -1
- package/LexicalTable.dev.mjs +2 -1
- package/LexicalTable.prod.js +33 -33
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +4 -4
package/LexicalTable.dev.js
CHANGED
@@ -2110,7 +2110,8 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2110
2110
|
const anchorCell = $findCellNode(anchor);
|
2111
2111
|
if (anchorCell !== null && $isTableRowNode(firstRow)) {
|
2112
2112
|
const firstCell = firstRow.getFirstChild();
|
2113
|
-
if ($isTableCellNode(firstCell) &&
|
2113
|
+
if ($isTableCellNode(firstCell) && tableNode.is(utils.$findMatchingParent(anchorCell, node => node.is(tableNode) || node.is(firstCell)))) {
|
2114
|
+
// The selection moved to the table, but not in the first cell
|
2114
2115
|
firstCell.selectStart();
|
2115
2116
|
return true;
|
2116
2117
|
}
|
package/LexicalTable.dev.mjs
CHANGED
@@ -2108,7 +2108,8 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2108
2108
|
const anchorCell = $findCellNode(anchor);
|
2109
2109
|
if (anchorCell !== null && $isTableRowNode(firstRow)) {
|
2110
2110
|
const firstCell = firstRow.getFirstChild();
|
2111
|
-
if ($isTableCellNode(firstCell) &&
|
2111
|
+
if ($isTableCellNode(firstCell) && tableNode.is($findMatchingParent(anchorCell, node => node.is(tableNode) || node.is(firstCell)))) {
|
2112
|
+
// The selection moved to the table, but not in the first cell
|
2112
2113
|
firstCell.selectStart();
|
2113
2114
|
return true;
|
2114
2115
|
}
|
package/LexicalTable.prod.js
CHANGED
@@ -14,22 +14,22 @@ rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){retu
|
|
14
14
|
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!==y.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||
|
15
15
|
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
16
|
function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?y.ROW:y.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,f=c.includes("line-through"),e="italic"===a.fontStyle,g=c.includes("underline");return{after:m=>{0===m.length&&m.push(u.$createParagraphNode());return m},forChild:(m,p)=>
|
17
|
-
{if(C(p)&&!u.$isElementNode(m)){p=u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),f&&m.toggleFormat("strikethrough"),e&&m.toggleFormat("italic"),g&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function B(a,b=1,c){return u.$applyNodeReplacement(new z(a,b,c))}function C(a){return a instanceof z}let da=u.createCommand("INSERT_TABLE_COMMAND");var
|
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.");}
|
17
|
+
{if(C(p)&&!u.$isElementNode(m)){p=u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),f&&m.toggleFormat("strikethrough"),e&&m.toggleFormat("italic"),g&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function B(a,b=1,c){return u.$applyNodeReplacement(new z(a,b,c))}function C(a){return a instanceof z}let da=u.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;let ea="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
19
19
|
class fa extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new fa(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:ha,priority:0})}}static importJSON(a){return I(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
20
|
a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function ha(a){let b=void 0;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:I(b)}}function I(a){return u.$applyNodeReplacement(new fa(a))}function K(a){return a instanceof fa}
|
21
21
|
function ia(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>L(b));if(L(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:f}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,f-1,b),below:c.getCellNodeFromCords(d,f+1,b),left:c.getCellNodeFromCords(d-1,f,b),right:c.getCellNodeFromCords(d+1,f,b)}}
|
22
|
-
let la=(a,b)=>a===y.BOTH||a===b?b:y.NO_STATUS;function N(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function O(a,b,c){let [d,f,e]=na(a,b,c);null===f&&
|
23
|
-
function na(a,b,c){function d(p){let r=f[p];void 0===r&&(f[p]=r=[]);return r}let f=[],e=null,g=null;a=a.getChildren();for(let p=0;p<a.length;p++){var m=a[p];K(m)||
|
24
|
-
e,g]}function P(a){a instanceof z||("__type"in a?(a=h.$findMatchingParent(a,C),C(a)||
|
22
|
+
let la=(a,b)=>a===y.BOTH||a===b?b:y.NO_STATUS;function N(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function O(a,b,c){let [d,f,e]=na(a,b,c);null===f&&E(207);null===e&&E(208);return[d,f,e]}
|
23
|
+
function na(a,b,c){function d(p){let r=f[p];void 0===r&&(f[p]=r=[]);return r}let f=[],e=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(),v=0;null!=r;r=r.getNextSibling()){C(r)||E(147);for(m=d(p);void 0!==m[v];)v++;m={cell:r,startColumn:v,startRow:p};let {__rowSpan:w,__colSpan:l}=r;for(let k=0;k<w&&!(p+k>=a.length);k++){let n=d(p+k);for(let q=0;q<l;q++)n[v+q]=m}null!==b&&null===e&&b.is(r)&&(e=m);null!==c&&null===g&&c.is(r)&&(g=m)}}return[f,
|
24
|
+
e,g]}function P(a){a instanceof z||("__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]}
|
25
25
|
function oa(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var f=a[0].getChildren().length;let e=Array(d);for(var g=0;g<d;g++)e[g]=Array(f);for(f=0;f<d;f++){g=a[f].getChildren();let m=0;for(let p=0;p<g.length;p++){for(;e[f][m];)m++;let r=g[p],v=r.__rowSpan||1,w=r.__colSpan||1;for(let l=0;l<v;l++)for(let k=0;k<w;k++)e[f+l][m+k]=r;if(b===r)return{colSpan:w,columnIndex:m,rowIndex:f,rowSpan:v};m+=w}}return null}
|
26
26
|
class pa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return Q(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
|
27
|
-
this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b=0;this.getNodes().filter(C).forEach(c=>{c=c.getFirstChild();u.$isParagraphNode(c)&&(b|=c.getTextFormat())});return 0!==(b&u.TEXT_TYPE_TO_FORMAT[a])}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||
|
28
|
-
u.$getNodeByKey(this.anchor.key);C(a)||
|
29
|
-
Math.min(r,A);v=Math.min(v,
|
27
|
+
this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b=0;this.getNodes().filter(C).forEach(c=>{c=c.getFirstChild();u.$isParagraphNode(c)&&(b|=c.getTextFormat())});return 0!==(b&u.TEXT_TYPE_TO_FORMAT[a])}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||E(151);u.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=
|
28
|
+
u.$getNodeByKey(this.anchor.key);C(a)||E(152);a=oa(a);null===a&&E(153);var b=u.$getNodeByKey(this.focus.key);C(b)||E(154);let c=oa(b);null===c&&E(155);b=Math.min(a.columnIndex,c.columnIndex);let d=Math.max(a.columnIndex+a.colSpan-1,c.columnIndex+c.colSpan-1),f=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex+a.rowSpan-1,c.rowIndex+c.rowSpan-1);return{fromX:Math.min(b,d),fromY:Math.min(f,a),toX:Math.max(b,d),toY:Math.max(f,a)}}getNodes(){function a(t){let {cell:x,startColumn:A,startRow:D}=t;r=
|
29
|
+
Math.min(r,A);v=Math.min(v,D);w=Math.max(w,A+x.__colSpan-1);l=Math.max(l,D+x.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=h.$findMatchingParent(c,C);c=h.$findMatchingParent(b,C);C(d)||E(152);C(c)||E(154);b=d.getParent();K(b)||E(156);b=b.getParent();L(b)||E(157);var f=c.getParents()[1];if(f!==b){if(b.isParentOf(c)){var e=f.getParent();null==e&&E(159);this.set(this.tableKey,c.getKey(),e.getKey())}else e=b.getParent(),null==e&&E(158),
|
30
30
|
this.set(this.tableKey,e.getKey(),c.getKey());return this.getNodes()}let [g,m,p]=O(b,d,c),r=Math.min(m.startColumn,p.startColumn),v=Math.min(m.startRow,p.startRow),w=Math.max(m.startColumn+m.cell.__colSpan-1,p.startColumn+p.cell.__colSpan-1),l=Math.max(m.startRow+m.cell.__rowSpan-1,p.startRow+p.cell.__rowSpan-1);c=r;d=v;f=r;for(var k=v;r<c||v<d||w>f||l>k;){if(r<c){var n=k-d;--c;for(var q=0;q<=n;q++)a(g[d+q][c])}if(v<d)for(n=f-c,--d,q=0;q<=n;q++)a(g[d][c+q]);if(w>f)for(n=k-d,f+=1,q=0;q<=n;q++)a(g[d+
|
31
|
-
q][f]);if(l>k)for(n=f-c,k+=1,q=0;q<=n;q++)a(g[k][c+q])}b=new Map([[b.getKey(),b]]);c=null;for(d=v;d<=l;d++)for(f=r;f<=w;f++){({cell:k}=g[d][f]);n=k.getParent();K(n)||
|
32
|
-
(e!==f?"\n":"\t")}return b}}function Q(a){return a instanceof pa}function ra(){let a=u.$createPoint("root",0,"element"),b=u.$createPoint("root",0,"element");return new pa("root",a,b)}function qa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&
|
31
|
+
q][f]);if(l>k)for(n=f-c,k+=1,q=0;q<=n;q++)a(g[k][c+q])}b=new Map([[b.getKey(),b]]);c=null;for(d=v;d<=l;d++)for(f=r;f<=w;f++){({cell:k}=g[d][f]);n=k.getParent();K(n)||E(160);n!==c&&b.set(n.getKey(),n);b.set(k.getKey(),k);for(e of qa(k))b.set(e.getKey(),e);c=n}e=Array.from(b.values());u.isCurrentlyReadOnlyMode()||(this._cachedNodes=e);return e}getTextContent(){let a=this.getNodes().filter(c=>C(c)),b="";for(let c=0;c<a.length;c++){let d=a[c],f=d.__parent,e=(a[c+1]||{}).__parent;b+=d.getTextContent()+
|
32
|
+
(e!==f?"\n":"\t")}return b}}function Q(a){return a instanceof pa}function ra(){let a=u.$createPoint("root",0,"element"),b=u.$createPoint("root",0,"element");return new pa("root",a,b)}function qa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&E(112);u.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}function ta(a,b=u.$getEditor()){let c=u.$getNodeByKey(a);L(c)||E(231,a);b=R(c,b.getElementByKey(a));null===b&&E(232,a);return{tableElement:b,tableNode:c}}
|
33
33
|
class ua{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.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners");
|
34
34
|
Array.from(this.listenersToRemove).forEach(a=>a());this.listenersToRemove.clear()}$lookup(){return ta(this.tableNodeKey,this.editor)}trackTable(){let a=new MutationObserver(b=>{this.editor.getEditorState().read(()=>{let c=!1;for(let e=0;e<b.length;e++){const g=b[e].target.nodeName;if("TABLE"===g||"TBODY"===g||"THEAD"===g||"TR"===g){c=!0;break}}if(c){var {tableNode:d,tableElement:f}=this.$lookup();this.table=S(d,f)}},{editor:this.editor})});this.editor.getEditorState().read(()=>{let {tableNode:b,tableElement:c}=
|
35
35
|
this.$lookup();this.table=S(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();a.update(()=>{let {tableNode:b,tableElement:c}=this.$lookup(),d=S(b,c);va(a,d,null);u.$setSelection(null);a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
|
@@ -37,24 +37,24 @@ void 0)})}enableHighlightStyle(){let a=this.editor;a.getEditorState().read(()=>{
|
|
37
37
|
a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();va(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return this.shouldCheckSelection?(this.shouldCheckSelection=!1,!0):!1}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var {tableNode:d}=
|
38
38
|
this.$lookup(),f=a.x;let e=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=ea?(c._window||window).getSelection():null;g&&g.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==f||this.anchorY!==e||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(f===this.focusX&&e===this.focusY)return;this.focusX=f;this.focusY=e;this.isHighlightingCells&&(f=u.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&
|
39
39
|
C(f)&&d.is(T(f))&&(d=f.getKey(),this.tableSelection=this.tableSelection.clone()||ra(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),u.$setSelection(this.tableSelection),c.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0),va(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=u.$getNearestNodeFromDOMNode(a.elem);
|
40
|
-
C(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();Q(b)||
|
41
|
-
void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!L(b))throw Error("Expected TableNode.");var c=u.$getSelection();Q(c)||
|
42
|
-
a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))})}}function R(a,b){if(!b)return b;a="TABLE"===b.nodeName?b:a.getDOMSlot(b).element;"TABLE"!==a.nodeName&&
|
40
|
+
C(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();Q(b)||E(11);let c=u.$createRangeSelection(),d=c.anchor,f=c.focus,e=b.getNodes().filter(C),g=e[0].getFirstChild(),m=u.$isParagraphNode(g)?g.getFormatFlags(a,null):null;e.forEach(p=>{d.set(p.getKey(),0,"element");f.set(p.getKey(),p.getChildrenSize(),"element");c.formatText(a,m)});u.$setSelection(b);this.editor.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
|
41
|
+
void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!L(b))throw Error("Expected TableNode.");var c=u.$getSelection();Q(c)||E(11);c=c.getNodes().filter(C);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),u.$getRoot().selectStart()):(c.forEach(d=>{if(u.$isElementNode(d)){let f=u.$createParagraphNode(),e=u.$createTextNode();f.append(e);d.append(f);d.getChildren().forEach(g=>{g!==f&&g.remove()})}}),va(a,this.table,null),u.$setSelection(null),
|
42
|
+
a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))})}}function R(a,b){if(!b)return b;a="TABLE"===b.nodeName?b:a.getDOMSlot(b).element;"TABLE"!==a.nodeName&&E(233,b.nodeName);return a}function wa(a,b){null!==xa(a)&&E(205);a.__lexicalTableSelection=b}function xa(a){return a.__lexicalTableSelection||null}function ya(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}
|
43
43
|
function S(a,b){var c=R(a,b);a=[];b={columns:0,domRows:a,rows:0};var d=c.querySelector("tr");let f=c=0;for(a.length=0;null!=d;){var e=d.nodeName;if("TD"===e||"TH"===e){e=d;e={elem:e,hasBackgroundColor:""!==e.style.backgroundColor,highlighted:!1,x:c,y:f};d._cell=e;let g=a[f];void 0===g&&(g=a[f]=[]);g[c]=e}else if(e=d.firstChild,null!=e){d=e;continue}e=d.nextSibling;if(null!=e)c++,d=e;else if(e=d.parentNode,null!=e){d=e.nextSibling;if(null==d)break;f++;c=0}}b.columns=c+1;b.rows=f+1;return b}
|
44
44
|
function va(a,b,c){let d=new Set(c?c.getNodes():[]);za(b,(f,e)=>{let g=f.elem;d.has(e)?(f.highlighted=!0,Aa(a,f)):(f.highlighted=!1,Ba(a,f),g.getAttribute("style")||g.removeAttribute("style"))})}function za(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let f=0;f<d.length;f++){let e=d[f];if(!e)continue;let g=u.$getNearestNodeFromDOMNode(e.elem);null!==g&&b(e,g,{x:f,y:c})}}}function Ca(a,b){b.disableHighlightStyle();za(b.table,c=>{c.highlighted=!0;Aa(a,c)})}
|
45
45
|
function Da(a,b){b.enableHighlightStyle();za(b.table,c=>{let d=c.elem;c.highlighted=!1;Ba(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
|
46
46
|
let Ea=(a,b,c,d,f)=>{const e="forward"===f;switch(f){case "backward":case "forward":return c!==(e?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(e?1:-1),d,a.table),e?a.selectStart():a.selectEnd()):d!==(e?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(e?0:a.table.columns-1,d+(e?1:-1),a.table),e?a.selectStart():a.selectEnd()):e?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!==
|
47
47
|
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},Fa=(a,b,c,d,f)=>{const e="forward"===f;switch(f){case "backward":case "forward":return c!==(e?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(e?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
|
48
48
|
d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(u.$isRangeSelection(a)||Q(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
|
49
|
-
function Aa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);C(b)||
|
50
|
-
function Ba(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);C(b)||
|
49
|
+
function Aa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);C(b)||E(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
|
50
|
+
function Ba(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);C(b)||E(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function V(a){a=h.$findMatchingParent(a,C);return C(a)?a:null}function T(a){a=h.$findMatchingParent(a,L);return L(a)?a:null}
|
51
51
|
function W(a,b,c,d,f){if(("up"===c||"down"===c)&&Ga(a))return!1;var e=u.$getSelection();if(!U(e,d)){if(u.$isRangeSelection(e)){if(e.isCollapsed()&&"backward"===c){c=e.anchor.type;d=e.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=e.anchor.getNode();if(!c)return!1;c=h.$findMatchingParent(c,r=>u.$isElementNode(r)&&!r.isInline());if(!c)return!1;c=c.getPreviousSibling();if(!c||!L(c))return!1;X(b);c.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c)){var g=e.focus.getNode();if(!e.isCollapsed()&&
|
52
52
|
("up"===c&&!e.isBackward()||"down"===c&&e.isBackward())){f=h.$findMatchingParent(g,r=>L(r));C(f)&&(f=h.$findMatchingParent(f,L));if(f!==d||!f)return!1;d="down"===c?f.getNextSibling():f.getPreviousSibling();if(!d)return!1;f=0;"up"===c&&u.$isElementNode(d)&&(f=d.getChildrenSize());a=d;"up"===c&&u.$isElementNode(d)&&(a=(c=d.getLastChild())?c:d,f=u.$isTextNode(a)?a.getTextContentSize():0);c=e.clone();c.focus.set(a.getKey(),f,u.$isTextNode(a)?"text":"element");u.$setSelection(c);X(b);return!0}if(u.$isRootOrShadowRoot(g)){if((b=
|
53
53
|
"up"===c?e.getNodes()[e.getNodes().length-1]:e.getNodes()[0])&&(b=h.$findMatchingParent(b,C))&&d.isParentOf(b)){c=d.getFirstDescendant();b=d.getLastDescendant();if(!c||!b)return!1;[c]=P(c);[b]=P(b);c=d.getCordsFromCellNode(c,f.table);b=d.getCordsFromCellNode(b,f.table);c=d.getDOMCellFromCordsOrThrow(c.x,c.y,f.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,f.table);f.setAnchorCellForSelection(c);f.setFocusCellForSelection(b,!0);return!0}return!1}d=h.$findMatchingParent(g,r=>u.$isElementNode(r)&&!r.isInline());
|
54
54
|
C(d)&&(d=h.$findMatchingParent(d,L));if(!d)return!1;d="down"===c?d.getNextSibling():d.getPreviousSibling();if(L(d)&&f.tableNodeKey===d.getKey()){f=d.getFirstDescendant();a=d.getLastDescendant();if(!f||!a)return!1;[d]=P(f);[f]=P(a);e=e.clone();e.focus.set(("up"===c?d:f).getKey(),"up"===c?0:f.getChildrenSize(),"element");X(b);u.$setSelection(e);return!0}}}"down"===c&&Ha(a)&&f.setShouldCheckSelection();return!1}if(u.$isRangeSelection(e)&&e.isCollapsed()){let {anchor:r,focus:v}=e;g=h.$findMatchingParent(r.getNode(),
|
55
55
|
C);var m=h.$findMatchingParent(v.getNode(),C);if(!C(g)||!g.is(m))return!1;m=T(g);if(m!==d&&null!=m){var p=R(m,a.getElementByKey(m.getKey()));if(null!=p)return f.table=S(m,p),W(a,b,c,m,f)}if("backward"===c||"forward"===c){f=r.type;a=r.offset;g=r.getNode();if(!g)return!1;e=e.getNodes();return 1===e.length&&u.$isDecoratorNode(e[0])?!1:Ja(f,a,g,c)?Ka(b,g,d,c):!1}e=a.getElementByKey(g.__key);m=a.getElementByKey(r.key);if(null==m||null==e)return!1;if("element"===r.type)e=m.getBoundingClientRect();else{e=
|
56
56
|
window.getSelection();if(null===e||0===e.rangeCount)return!1;e=e.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>e.top-e.height:e.bottom+e.height>a.bottom){X(b);e=d.getCordsFromCellNode(g,f.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(e.x,e.y,f.table),f.setAnchorCellForSelection(b),f.setFocusCellForSelection(b,!0);else return Ea(f,d,e.x,e.y,
|
57
|
-
c);return!0}}else if(Q(e)){let {anchor:r,focus:v}=e;p=h.$findMatchingParent(r.getNode(),C);m=h.$findMatchingParent(v.getNode(),C);[g]=e.getNodes();L(g)||
|
57
|
+
c);return!0}}else if(Q(e)){let {anchor:r,focus:v}=e;p=h.$findMatchingParent(r.getNode(),C);m=h.$findMatchingParent(v.getNode(),C);[g]=e.getNodes();L(g)||E(234);a=R(g,a.getElementByKey(g.getKey()));if(!C(p)||!C(m)||!L(g)||null==a)return!1;f.updateTableTableSelection(e);e=S(g,a);a=d.getCordsFromCellNode(p,e);a=d.getDOMCellFromCordsOrThrow(a.x,a.y,e);f.setAnchorCellForSelection(a);X(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,e),Fa(f,g,b.x,b.y,c);m.selectEnd();return!0}return!1}
|
58
58
|
function X(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}function Ga(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function Ja(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||La(a,b,c,d)}
|
59
59
|
function La(a,b,c,d){let f=h.$findMatchingParent(c,e=>u.$isElementNode(e)&&!e.isInline());if(!f)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===f.getPreviousSibling():null===f.getNextSibling())}
|
60
60
|
function Ka(a,b,c,d){var f=h.$findMatchingParent(b,C);if(!C(f))return!1;let [e,g]=O(c,f,f);f=e[0][0];let m=e[e.length-1][e[0].length-1],{startColumn:p,startRow:r}=g;if("backward"===d?p!==f.startColumn||r!==f.startRow:p!==m.startColumn||r!==m.startRow)return!1;b=Ma(b,d,c);if(!b||L(b))return!1;X(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
|
@@ -62,7 +62,7 @@ function Ma(a,b,c){if(a=h.$findMatchingParent(a,d=>u.$isElementNode(d)&&!d.isInl
|
|
62
62
|
function Oa(a,b,c){var d=c.getParent();if(d){var f=window.getSelection();if(f&&(f=f.anchorNode,d=a.getElementByKey(d.getKey()),a=R(c,a.getElementByKey(c.getKey())),f&&d&&a&&d.contains(f)&&!a.contains(f)&&(b=h.$findMatchingParent(b.anchor.getNode(),r=>C(r))))&&(a=h.$findMatchingParent(b,r=>L(r)),L(a)&&a.is(c))){var [e,g]=O(c,b,b);c=e[0][0];b=e[e.length-1][e[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"}}}
|
63
63
|
function Pa(a,b,c,d){if(a=a.querySelector("colgroup")){b=[];for(let f=0;f<c;f++){let e=document.createElement("col"),g=d&&d[f];g&&(e.style.width=`${g}px`);b.push(e)}a.replaceChildren(...b)}}function Qa(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 Ra=new WeakSet;function Ha(a=u.$getEditor()){return Ra.has(a)}
|
64
64
|
class Sa extends u.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 Sa(a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__colWidths=a.__colWidths;this.__rowStriping=a.__rowStriping}static importDOM(){return{table:()=>({conversion:Ta,priority:1})}}static importJSON(a){let b=Ua();b.__rowStriping=a.rowStriping||!1;b.__colWidths=a.colWidths;return b}constructor(a){super(a);
|
65
|
-
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&
|
65
|
+
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}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);Pa(c,a,this.getColumnCount(),this.getColWidths());u.setDOMUnmanaged(d);
|
66
66
|
h.addClassNamesToElement(c,a.theme.table);this.__rowStriping&&Qa(c,a,!0);return Ha(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&&Qa(b,c,this.__rowStriping);Pa(b,c,this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{b&&h.isHTMLElement(b)&&"TABLE"!==b.nodeName&&(b=b.querySelector("table"));
|
67
67
|
if(!b||!h.isHTMLElement(b))return null;let c=b.querySelectorAll(":scope > tr");if(0<c.length){let d=document.createElement("tbody");d.append(...c);b.append(d)}return b}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var f=d[b];if(null!=f&&(f=f.findIndex(e=>{if(e)return{elem:e}=e,u.$getNearestNodeFromDOMNode(e)===a}),-1!==f))return{x:f,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];
|
68
68
|
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,b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=u.$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=
|
@@ -70,22 +70,22 @@ a}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){let a=this.ge
|
|
70
70
|
function Ua(){return u.$applyNodeReplacement(new Sa)}function L(a){return a instanceof Sa}exports.$computeTableMap=O;exports.$computeTableMapSkipCellCheck=na;exports.$createTableCellNode=B;exports.$createTableNode=Ua;
|
71
71
|
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Ua();for(let e=0;e<a;e++){let g=I();for(let m=0;m<b;m++){var f=y.NO_STATUS;"object"===typeof c?(0===e&&c.rows&&(f|=y.ROW),0===m&&c.columns&&(f|=y.COLUMN)):c&&(0===e&&(f|=y.ROW),0===m&&(f|=y.COLUMN));f=B(f);let p=u.$createParagraphNode();p.append(u.$createTextNode());f.append(p);g.append(f)}d.append(g)}return d};exports.$createTableRowNode=I;exports.$createTableSelection=ra;
|
72
72
|
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let f=0;f<c.length;f++){var d=c[f];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};
|
73
|
-
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||
|
73
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||E(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);var [f]=P(a);let [e,g,m]=O(d,c,f);var {startColumn:p}=g;let {startRow:r,startColumn:v}=m;b=Math.min(p,v);var w=Math.max(p+c.__colSpan-1,v+f.__colSpan-1);a=w-b+1;if(e[0].length===w-b+1)d.selectPrevious(),d.remove();else{var l=e.length;for(let k=0;k<l;k++)for(let n=b;n<=w;n++){let {cell:q,startColumn:t}=e[k][n];t<b?n===b&&q.setColSpan(q.__colSpan-
|
74
74
|
Math.min(a,q.__colSpan-(b-t))):t+q.__colSpan-1>w?n===w&&q.setColSpan(q.__colSpan-(w-t+1)):q.remove()}w=e[r];f=p>v?w[p+c.__colSpan]:w[v+f.__colSpan];void 0!==f?({cell:p}=f,N(p)):({cell:p}=v<p?w[v-1]:w[p-1],N(p));if(p=d.getColWidths())p=[...p],p.splice(b,a),d.setColWidths(p)}};
|
75
|
-
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||
|
76
|
-
(k===a&&q<a&&n.setRowSpan(n.__rowSpan-(q-a)),q>=a&&q+n.__rowSpan-1>e))if(n.setRowSpan(n.__rowSpan-(e-q+1)),null===w&&
|
75
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||E(188);let [b,c]=a.isBackward()?[a.focus.getNode(),a.anchor.getNode()]:[a.anchor.getNode(),a.focus.getNode()],[d,,f]=P(b);var [e]=P(c);let [g,m,p]=O(f,d,e);({startRow:a}=m);var {startRow:r}=p;e=r+e.__rowSpan-1;if(g.length===e-a+1)f.remove();else{r=g[0].length;var v=g[e+1],w=f.getChildAtIndex(e+1);for(let k=e;k>=a;k--){for(var l=r-1;0<=l;l--){let {cell:n,startRow:q,startColumn:t}=g[k][l];if(t===l&&
|
76
|
+
(k===a&&q<a&&n.setRowSpan(n.__rowSpan-(q-a)),q>=a&&q+n.__rowSpan-1>e))if(n.setRowSpan(n.__rowSpan-(e-q+1)),null===w&&E(122),0===l)ma(w,n);else{let {cell:x}=v[l-1];x.insertAfter(n)}}l=f.getChildAtIndex(k);K(l)||E(206,String(k));l.remove()}void 0!==v?({cell:a}=v[0],N(a)):({cell:a}=g[a-1][0],N(a))}};exports.$findCellNode=V;exports.$findTableNode=T;exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());null===a&&E(230);return S(b,a)};exports.$getNodeTriplet=P;
|
77
77
|
exports.$getTableAndElementByKey=ta;exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableCellNodeRect=oa;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
|
78
|
-
exports.$insertTableColumn=function(a,b,c=!0,d,f){let e=a.getChildren(),g=[];for(let r=0;r<e.length;r++){let v=e[r];if(K(v))for(let w=0;w<d;w++){var m=v.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];C(m)||
|
78
|
+
exports.$insertTableColumn=function(a,b,c=!0,d,f){let e=a.getChildren(),g=[];for(let r=0;r<e.length;r++){let v=e[r];if(K(v))for(let w=0;w<d;w++){var m=v.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:l,right:k}=ka(m,f);var p=y.NO_STATUS;if(l&&l.hasHeaderState(y.ROW)||k&&k.hasHeaderState(y.ROW))p|=y.ROW;p=B(p);p.append(u.$createParagraphNode());g.push({newTableCell:p,targetCell:m})}}g.forEach(({newTableCell:r,targetCell:v})=>{c?
|
79
79
|
v.insertAfter(r):v.insertBefore(r)});return a};
|
80
|
-
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(w=y.NO_STATUS){w=B(w).append(u.$createParagraphNode());null===r&&(r=w);return w}var c=u.$getSelection();u.$isRangeSelection(c)||Q(c)||
|
81
|
-
K(v)||
|
82
|
-
exports.$insertTableRow=function(a,b,c=!0,d,f){var e=a.getChildren();if(b>=e.length||0>b)throw Error("Table row target index out of range");b=e[b];if(K(b))for(e=0;e<d;e++){let m=b.getChildren(),p=m.length,r=I();for(let v=0;v<p;v++){var g=m[v];C(g)||
|
80
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(w=y.NO_STATUS){w=B(w).append(u.$createParagraphNode());null===r&&(r=w);return w}var c=u.$getSelection();u.$isRangeSelection(c)||Q(c)||E(188);var d=c.anchor.getNode();c=c.focus.getNode();[d]=P(d);let [f,,e]=P(c),[g,m,p]=O(e,f,d);d=g.length;c=a?Math.max(m.startColumn,p.startColumn):Math.min(m.startColumn,p.startColumn);a=a?c+f.__colSpan-1:c-1;c=e.getFirstChild();K(c)||E(120);let r=null;var v=c;a:for(c=0;c<d;c++){0!==c&&(v=v.getNextSibling(),
|
81
|
+
K(v)||E(121));let w=g[c],l=la(w[0>a?0:a].cell.__headerState,y.ROW);if(0>a){ma(v,b(l));continue}let {cell:k,startColumn:n,startRow:q}=w[a];if(n+k.__colSpan-1<=a){let t=k,x=q,A=a;for(;x!==c&&1<t.__rowSpan;)if(A-=k.__colSpan,0<=A){let {cell:D,startRow:G}=w[A];t=D;x=G}else{v.append(b(l));continue a}t.insertAfter(b(l))}else k.setColSpan(k.__colSpan+1)}null!==r&&N(r);if(d=e.getColWidths())d=[...d],a=0>a?0:a,d.splice(a,0,d[a]),e.setColWidths(d);return r};
|
82
|
+
exports.$insertTableRow=function(a,b,c=!0,d,f){var e=a.getChildren();if(b>=e.length||0>b)throw Error("Table row target index out of range");b=e[b];if(K(b))for(e=0;e<d;e++){let m=b.getChildren(),p=m.length,r=I();for(let v=0;v<p;v++){var g=m[v];C(g)||E(12);let {above:w,below:l}=ka(g,f);g=y.NO_STATUS;let k=w&&w.getWidth()||l&&l.getWidth()||void 0;if(w&&w.hasHeaderState(y.COLUMN)||l&&l.hasHeaderState(y.COLUMN))g|=y.COLUMN;g=B(g,1,k);g.append(u.$createParagraphNode());r.append(g)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
|
83
83
|
return a};
|
84
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||Q(b)||
|
85
|
-
a=I();for(p=0;p<b;p++){let {cell:v,startRow:w}=m[p];w===g?(r=la(m[p].cell.__headerState,y.COLUMN),a.append(B(r).append(u.$createParagraphNode()))):v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(g);K(b)||
|
84
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||Q(b)||E(188);b=b.focus.getNode();let [c,,d]=P(b),[f,e]=O(d,c,c);b=f[0].length;var {startRow:g}=e;if(a){a=g+c.__rowSpan-1;var m=f[a];g=I();for(var p=0;p<b;p++){let {cell:v,startRow:w}=m[p];if(w+v.__rowSpan-1<=a){var r=la(m[p].cell.__headerState,y.COLUMN);g.append(B(r).append(u.$createParagraphNode()))}else v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(a);K(b)||E(145);b.insertAfter(g);b=g}else{m=f[g];
|
85
|
+
a=I();for(p=0;p<b;p++){let {cell:v,startRow:w}=m[p];w===g?(r=la(m[p].cell.__headerState,y.COLUMN),a.append(B(r).append(u.$createParagraphNode()))):v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(g);K(b)||E(145);b.insertBefore(a);b=a}return b};exports.$isScrollableTablesActive=Ha;exports.$isTableCellNode=C;exports.$isTableNode=L;exports.$isTableRowNode=K;exports.$isTableSelection=Q;
|
86
86
|
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};
|
87
|
-
exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||
|
88
|
-
if(1<a){for(var k=1;k<a;k++)b.insertAfter(B(v[k]|l[0]).append(u.$createParagraphNode()));b.setColSpan(1)}if(1<f){let t;for(k=1;k<f;k++){var n=p+k;let x=e[n];t=(t||c).getNextSibling();K(t)||
|
87
|
+
exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||E(188);a=a.anchor.getNode();let [b,c,d]=P(a);a=b.__colSpan;let f=b.__rowSpan;if(1!==a||1!==f){var [e,g]=O(d,b,b),{startColumn:m,startRow:p}=g,r=b.__headerState&y.COLUMN,v=Array.from({length:a},(t,x)=>{t=r;for(let A=0;0!==t&&A<e.length;A++)t&=e[A][x+m].cell.__headerState;return t}),w=b.__headerState&y.ROW,l=Array.from({length:f},(t,x)=>{t=w;for(let A=0;0!==t&&A<e[0].length;A++)t&=e[x+p][A].cell.__headerState;return t});
|
88
|
+
if(1<a){for(var k=1;k<a;k++)b.insertAfter(B(v[k]|l[0]).append(u.$createParagraphNode()));b.setColSpan(1)}if(1<f){let t;for(k=1;k<f;k++){var n=p+k;let x=e[n];t=(t||c).getNextSibling();K(t)||E(125);var q=null;for(let A=0;A<m;A++){let D=x[A],G=D.cell;D.startRow===n&&(q=G);1<G.__colSpan&&(A+=G.__colSpan-1)}if(null===q)for(q=a-1;0<=q;q--)ma(t,B(v[q]|l[k]).append(u.$createParagraphNode()));else for(n=a-1;0<=n;n--)q.insertAfter(B(v[n]|l[k]).append(u.$createParagraphNode()))}b.setRowSpan(1)}}};
|
89
89
|
exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=y;exports.TableCellNode=z;exports.TableNode=Sa;exports.TableObserver=ua;exports.TableRowNode=fa;
|
90
90
|
exports.applyTableHandlers=function(a,b,c,d){function f(l){l=a.getCordsFromCellNode(l,g.table);return a.getDOMCellFromCordsOrThrow(l.x,l.y,g.table)}let e=c.getRootElement();if(null===e)throw Error("No root element.");let g=new ua(c,a.getKey()),m=c._window||window,p=R(a,b);wa(p,g);g.listenersToRemove.add(()=>{var l=g;xa(p)===l&&delete p.__lexicalTableSelection});let r=()=>{const l=()=>{g.isSelecting=!1;m.removeEventListener("mouseup",l);m.removeEventListener("mousemove",k)},k=n=>{setTimeout(()=>{if(1!==
|
91
91
|
(n.buttons&1)&&g.isSelecting)g.isSelecting=!1,m.removeEventListener("mouseup",l),m.removeEventListener("mousemove",k);else{var q=ya(n.target);null===q||g.anchorX===q.x&&g.anchorY===q.y||(n.preventDefault(),g.setFocusCellForSelection(q))}},0)};return{onMouseMove:k,onMouseUp:l}};p.addEventListener("mousedown",l=>{setTimeout(()=>{if(0===l.button&&m){var k=ya(l.target);null!==k&&(X(l),g.setAnchorCellForSelection(k));var {onMouseUp:n,onMouseMove:q}=r();g.isSelecting=!0;m.addEventListener("mouseup",n,g.listenerOptions);
|
@@ -95,13 +95,13 @@ h.$findMatchingParent(k.anchor.getNode(),t=>C(t));if(!C(n))return!1;var q=k.anch
|
|
95
95
|
u.DELETE_CHARACTER_COMMAND].forEach(l=>{g.listenersToRemove.add(c.registerCommand(l,v(l),u.COMMAND_PRIORITY_CRITICAL))});let w=l=>{const k=u.$getSelection();if(!Q(k)&&!u.$isRangeSelection(k))return!1;const n=a.isParentOf(k.anchor.getNode()),q=a.isParentOf(k.focus.getNode());if(n!==q){l=n?"focus":"anchor";const {key:t,offset:x,type:A}=k[l];a[k[n?"anchor":"focus"].isBefore(k[l])?"selectPrevious":"selectNext"]()[l].set(t,x,A);return!1}return Q(k)?(l&&(l.preventDefault(),l.stopPropagation()),g.clearText(),
|
96
96
|
!0):!1};g.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,w,u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.KEY_DELETE_COMMAND,w,u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.CUT_COMMAND,l=>{let k=u.$getSelection();if(k){if(!Q(k)&&!u.$isRangeSelection(k))return!1;void aa.copyToClipboard(c,h.objectKlassEquals(l,ClipboardEvent)?l:null,aa.$getClipboardDataFromSelection(k));l=w(l);return u.$isRangeSelection(k)?(k.removeText(),!0):l}return!1},
|
97
97
|
u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,l=>{let k=u.$getSelection();if(!U(k,a))return!1;if(Q(k))return g.formatCells(l),!0;u.$isRangeSelection(k)&&(l=h.$findMatchingParent(k.anchor.getNode(),n=>C(n)),C(l));return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,l=>{var k=u.$getSelection();if(!Q(k)||!U(k,a))return!1;var n=k.anchor.getNode();k=k.focus.getNode();if(!C(n)||!C(k))return!1;let [q,t,
|
98
|
-
x]=O(a,n,k);n=Math.max(t.startRow,x.startRow);k=Math.max(t.startColumn,x.startColumn);var A=Math.min(t.startRow,x.startRow);let
|
98
|
+
x]=O(a,n,k);n=Math.max(t.startRow,x.startRow);k=Math.max(t.startColumn,x.startColumn);var A=Math.min(t.startRow,x.startRow);let D=Math.min(t.startColumn,x.startColumn);for(;A<=n;A++)for(let J=D;J<=k;J++){var G=q[A][J].cell;G.setFormat(l);G=G.getChildren();for(let M=0;M<G.length;M++){let H=G[M];u.$isElementNode(H)&&!H.isInline()&&H.setFormat(l)}}return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,l=>{var k=u.$getSelection();if(!U(k,
|
99
99
|
a))return!1;if(Q(k))g.clearHighlight();else if(u.$isRangeSelection(k)){let n=h.$findMatchingParent(k.anchor.getNode(),q=>C(q));if(!C(n))return!1;if("string"===typeof l&&(k=Oa(c,k,a)))return Na(k,a,[u.$createTextNode(l)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));d&&g.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,l=>{var k=u.$getSelection();if(!u.$isRangeSelection(k)||!k.isCollapsed()||!U(k,a))return!1;k=V(k.anchor.getNode());if(null===k)return!1;X(l);k=a.getCordsFromCellNode(k,g.table);
|
100
100
|
Ea(g,a,k.x,k.y,l.shiftKey?"backward":"forward");return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,l=>{let {nodes:k,selection:n}=l;l=n.getStartEndPoints();var q=Q(n);q=u.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),H=>C(H))&&null!==h.$findMatchingParent(n.focus.getNode(),H=>C(H))||q;if(1!==k.length||
|
101
|
-
!L(k[0])||!q||null===l)return!1;var [t]=l,x=k[0];l=x.getChildren();q=x.getFirstChildOrThrow().getChildrenSize();x=x.getChildrenSize();var A=h.$findMatchingParent(t.getNode(),H=>C(H)),
|
102
|
-
for(J=0;
|
103
|
-
if(g.getAndClearShouldCheckSelection()&&u.$isRangeSelection(k)&&u.$isRangeSelection(l)&&l.isCollapsed()){var n=l.anchor.getNode(),q=a.getFirstChild();n=V(n);if(null!==n&&K(q)){let A=q.getFirstChild();if(C(A)
|
104
|
-
x[x.length-1].at(-1).cell,n.focus.set(q?t.getKey():x.getKey(),q?t.getChildrenSize():x.getChildrenSize(),"element")):G&&([x]=O(a,t,t),t=x[0][0].cell,x=x[x.length-1].at(-1).cell,n.anchor.set(q?x.getKey():t.getKey(),q?x.getChildrenSize():0,"element")),u.$setSelection(n),Ca(c,g)):M&&!t.is(x)&&(g.setAnchorCellForSelection(f(t)),g.setFocusCellForSelection(f(x),!0),g.isSelecting||setTimeout(()=>{let {onMouseUp:H,onMouseMove:Y}=r();g.isSelecting=!0;m.addEventListener("mouseup",H);m.addEventListener("mousemove",
|
101
|
+
!L(k[0])||!q||null===l)return!1;var [t]=l,x=k[0];l=x.getChildren();q=x.getFirstChildOrThrow().getChildrenSize();x=x.getChildrenSize();var A=h.$findMatchingParent(t.getNode(),H=>C(H)),D=A&&h.$findMatchingParent(A,H=>K(H)),G=D&&h.$findMatchingParent(D,H=>L(H));if(!C(A)||!K(D)||!L(G))return!1;t=D.getIndexWithinParent();var J=Math.min(G.getChildrenSize()-1,t+x-1);x=A.getIndexWithinParent();A=Math.min(D.getChildrenSize()-1,x+q-1);q=Math.min(x,A);D=Math.min(t,J);x=Math.max(x,A);t=Math.max(t,J);G=G.getChildren();
|
102
|
+
for(J=0;D<=t;D++){A=G[D];if(!K(A))return!1;var M=l[J];if(!K(M))return!1;A=A.getChildren();M=M.getChildren();let H=0;for(let Y=q;Y<=x;Y++){let sa=A[Y];if(!C(sa))return!1;let Ia=M[H];if(!C(Ia))return!1;let Va=sa.getChildren();Ia.getChildren().forEach(Z=>{u.$isTextNode(Z)&&u.$createParagraphNode().append(Z);sa.append(Z)});Va.forEach(Z=>Z.remove());H++}J++}return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,()=>{let l=u.$getSelection(),k=u.$getPreviousSelection();
|
103
|
+
if(g.getAndClearShouldCheckSelection()&&u.$isRangeSelection(k)&&u.$isRangeSelection(l)&&l.isCollapsed()){var n=l.anchor.getNode(),q=a.getFirstChild();n=V(n);if(null!==n&&K(q)){let A=q.getFirstChild();if(C(A)&&a.is(h.$findMatchingParent(n,D=>D.is(a)||D.is(A))))return A.selectStart(),!0}}if(u.$isRangeSelection(l)){let {anchor:A,focus:D}=l;n=A.getNode();q=D.getNode();var t=V(n),x=V(q);let G=!(!t||!a.is(T(t))),J=!(!x||!a.is(T(x)));n=G!==J;let M=G&&J;q=l.isBackward();n?(n=l.clone(),J?([x]=O(a,x,x),t=x[0][0].cell,
|
104
|
+
x=x[x.length-1].at(-1).cell,n.focus.set(q?t.getKey():x.getKey(),q?t.getChildrenSize():x.getChildrenSize(),"element")):G&&([x]=O(a,t,t),t=x[0][0].cell,x=x[x.length-1].at(-1).cell,n.anchor.set(q?x.getKey():t.getKey(),q?x.getChildrenSize():0,"element")),u.$setSelection(n),Ca(c,g)):M&&!t.is(x)&&(g.setAnchorCellForSelection(f(t)),g.setFocusCellForSelection(f(x),!0),g.isSelecting||setTimeout(()=>{let {onMouseUp:H,onMouseMove:Y}=r();g.isSelecting=!0;m.addEventListener("mouseup",H);m.addEventListener("mousemove",
|
105
105
|
Y)},0))}else l&&Q(l)&&l.is(k)&&l.tableKey===a.getKey()&&(q=ea?(c._window||window).getSelection():null)&&q.anchorNode&&q.focusNode&&(n=(n=u.$getNearestNodeFromDOMNode(q.focusNode))&&!a.is(T(n)),t=(t=u.$getNearestNodeFromDOMNode(q.anchorNode))&&a.is(T(t)),n&&t&&0<q.rangeCount&&(n=u.$createRangeSelectionFromDom(q,c)))&&(n.anchor.set(a.getKey(),l.isBackward()?a.getChildrenSize():0,"element"),q.removeAllRanges(),u.$setSelection(n));if(l&&!l.is(k)&&(Q(l)||Q(k))&&g.tableSelection&&!g.tableSelection.is(k))return Q(l)&&
|
106
106
|
l.tableKey===g.tableNodeKey?g.updateTableTableSelection(l):!Q(l)&&Q(k)&&k.tableKey===g.tableNodeKey&&g.updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?Da(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&Ca(c,g);return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,()=>{var l=u.$getSelection();return u.$isRangeSelection(l)&&l.isCollapsed()&&U(l,a)?(l=Oa(c,l,a))?(Na(l,a),!0):!1:!1},u.COMMAND_PRIORITY_CRITICAL));
|
107
107
|
return g};exports.getDOMCellFromTarget=ya;exports.getTableElement=R;exports.getTableObserverFromTableElement=xa;exports.setScrollableTablesActive=function(a,b){b?Ra.add(a):Ra.delete(a)}
|
package/LexicalTable.prod.mjs
CHANGED
@@ -6,4 +6,4 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as u,createCommand as h,$createTextNode as d,$getSelection as g,$isRangeSelection as f,$createPoint as p,$isParagraphNode as m,$normalizeSelection__EXPERIMENTAL as S,$getNodeByKey as C,isCurrentlyReadOnlyMode as _,TEXT_TYPE_TO_FORMAT as w,$getEditor as b,$setSelection as y,SELECTION_CHANGE_COMMAND as N,$getNearestNodeFromDOMNode as x,$createRangeSelection as v,$getRoot as T,KEY_ARROW_DOWN_COMMAND as O,COMMAND_PRIORITY_HIGH as R,KEY_ARROW_UP_COMMAND as k,KEY_ARROW_LEFT_COMMAND as E,KEY_ARROW_RIGHT_COMMAND as F,KEY_ESCAPE_COMMAND as M,DELETE_WORD_COMMAND as K,DELETE_LINE_COMMAND as A,DELETE_CHARACTER_COMMAND as B,COMMAND_PRIORITY_CRITICAL as H,KEY_BACKSPACE_COMMAND as P,KEY_DELETE_COMMAND as W,CUT_COMMAND as L,FORMAT_TEXT_COMMAND as D,FORMAT_ELEMENT_COMMAND as I,CONTROLLED_TEXT_INSERTION_COMMAND as U,KEY_TAB_COMMAND as $,FOCUS_COMMAND as z,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Y,$getPreviousSelection as X,$createRangeSelectionFromDom as J,INSERT_PARAGRAPH_COMMAND as j,$isRootOrShadowRoot as q,$isDecoratorNode as G,setDOMUnmanaged as Q}from"lexical";import{copyToClipboard as V,$getClipboardDataFromSelection as Z}from"@lexical/clipboard";const ee=/^(\d+(?:\.\d+)?)px$/,te={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ne extends l{static getType(){return"tablecell"}static clone(e){return new ne(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:oe,priority:0}),th:e=>({conversion:oe,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return re(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=te.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;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";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.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=te.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!==te.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 oe(e){const t=e,n=e.nodeName.toLowerCase();let o;ee.test(t.style.width)&&(o=parseFloat(t.style.width));const r=re("th"===n?te.ROW:te.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const u=t.style,h=(u&&u.textDecoration||"").split(" "),d="700"===u.fontWeight||"bold"===u.fontWeight,g=h.includes("line-through"),f="italic"===u.fontStyle,p=h.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(le(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function re(e,t=1,n){return u(new ne(e,t,n))}function le(e){return e instanceof ne}const se=h("INSERT_TABLE_COMMAND");function ie(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ce=ie((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;class ue extends l{static getType(){return"tablerow"}static clone(e){return new ue(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:he,priority:0})}}static importJSON(e){return de(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function he(e){const t=e;let n;return ee.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:de(n)}}function de(e){return u(new ue(e))}function ge(e){return e instanceof ue}function fe(e,t,n=!0){const o=wt();for(let r=0;r<e;r++){const e=de();for(let o=0;o<t;o++){let t=te.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=te.ROW),0===o&&n.columns&&(t|=te.COLUMN)):n&&(0===r&&(t|=te.ROW),0===o&&(t|=te.COLUMN));const l=re(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function pe(e){const n=t(e,(e=>le(e)));return le(n)?n:null}function me(e){const n=t(e,(e=>ge(e)));if(ge(n))return n;throw new Error("Expected table cell to be inside of table row.")}function Se(e){const n=t(e,(e=>bt(e)));if(bt(n))return n;throw new Error("Expected table cell to be inside of table.")}function Ce(e){const t=me(e);return Se(t).getChildren().findIndex((e=>e.is(t)))}function _e(e){return me(e).getChildren().findIndex((t=>t.is(e)))}function we(e,t){const n=Se(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 be(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 ye(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const i=l[t];if(!ge(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=de();for(let n=0;n<t;n++){const t=e[n];le(t)||ce(12);const{above:l,below:i}=we(t,r);let c=te.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(te.COLUMN)||i&&i.hasHeaderState(te.COLUMN))&&(c|=te.COLUMN);const u=re(c,1,a);u.append(s()),o.append(u)}n?i.insertAfter(o):i.insertBefore(o)}return e}const Ne=(e,t)=>e===te.BOTH||e===t?t:te.NO_STATUS;function xe(e=!0){const t=g();f(t)||We(t)||ce(188);const n=t.focus.getNode(),[o,,r]=Be(n),[l,i]=Ke(r,o,o),c=l[0].length,{startRow:a}=i;let u=null;if(e){const e=a+o.__rowSpan-1,t=l[e],n=de();for(let o=0;o<c;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Ne(e,te.COLUMN);n.append(re(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ge(i)||ce(145),i.insertAfter(n),u=n}else{const e=l[a],t=de();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=Ne(o,te.COLUMN);t.append(re(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ge(n)||ce(145),n.insertBefore(t),u=t}return u}function ve(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(ge(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];le(o)||ce(12);const{left:l,right:c}=we(o,r);let a=te.NO_STATUS;(l&&l.hasHeaderState(te.ROW)||c&&c.hasHeaderState(te.ROW))&&(a|=te.ROW);const u=re(a);u.append(s()),i.push({newTableCell:u,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Te(e=!0){const t=g();f(t)||We(t)||ce(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Be(n),[l,,i]=Be(o),[c,a,u]=Ke(i,l,r),h=c.length,d=e?Math.max(a.startColumn,u.startColumn):Math.min(a.startColumn,u.startColumn),p=e?d+l.__colSpan-1:d-1,m=i.getFirstChild();ge(m)||ce(120);let S=null;function C(e=te.NO_STATUS){const t=re(e).append(s());return null===S&&(S=t),t}let _=m;e:for(let e=0;e<h;e++){if(0!==e){const e=_.getNextSibling();ge(e)||ce(121),_=e}const t=c[e],n=t[p<0?0:p].cell.__headerState,o=Ne(n,te.ROW);if(p<0){Fe(_,C(o));continue}const{cell:r,startColumn:l,startRow:s}=t[p];if(l+r.__colSpan-1<=p){let n=r,l=s,i=p;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(C(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(C(o))}else r.setColSpan(r.__colSpan+1)}null!==S&&Ee(S);const w=i.getColWidths();if(w){const e=[...w],t=p<0?0:p,n=e[t];e.splice(t,0,n),i.setColWidths(e)}return S}function Oe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ge(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 Re(){const e=g();f(e)||We(e)||ce(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Be(t),[l]=Be(n),[s,i,c]=Ke(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,p=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&&(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===m&&ce(122),0===t)Fe(m,n);else{const{cell:e}=p[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ge(t)||ce(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];Ee(e)}else{const e=s[a-1],{cell:t}=e[0];Ee(t)}}function ke(){const e=g();f(e)||We(e)||ce(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Be(t),[l]=Be(n),[s,i,c]=Ke(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),p=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),m=p-d+1;if(s[0].length===p-d+1)return r.selectPrevious(),void r.remove();const S=s.length;for(let e=0;e<S;e++)for(let t=d;t<=p;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(m,n.__colSpan-e))}}else if(o+n.__colSpan-1>p){if(t===p){const e=p-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const C=s[u],_=a>h?C[a+o.__colSpan]:C[h+l.__colSpan];if(void 0!==_){const{cell:e}=_;Ee(e)}else{const e=h<a?C[h-1]:C[a-1],{cell:t}=e;Ee(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,m),r.setColWidths(e)}}function Ee(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Fe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Me(){const e=g();f(e)||We(e)||ce(188);const t=e.anchor.getNode(),[n,o,r]=Be(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Ke(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&te.COLUMN,p=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<c.length;e++)n&=c[e][t+u].cell.__headerState;return n})),m=n.__headerState&te.ROW,S=Array.from({length:i},((e,t)=>{let n=m;for(let e=0;0!==n&&e<c[0].length;e++)n&=c[t+h][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(re(p[e]|S[0]).append(s()));n.setColSpan(1)}if(i>1){let e;for(let t=1;t<i;t++){const n=h+t,r=c[n];e=(e||o).getNextSibling(),ge(e)||ce(125);let i=null;for(let e=0;e<u;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===i)for(let n=l-1;n>=0;n--)Fe(e,re(p[n]|S[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(re(p[e]|S[t]).append(s()))}n.setRowSpan(1)}}function Ke(e,t,n){const[o,r,l]=Ae(e,t,n);return null===r&&ce(207),null===l&&ce(208),[o,r,l]}function Ae(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];ge(o)||ce(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){le(c)||ce(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 Be(e){let n;if(e instanceof ne)n=e;else if("__type"in e){const o=t(e,le);le(o)||ce(148),n=o}else{const o=t(e.getNode(),le);le(o)||ce(148),n=o}const o=n.getParent();ge(o)||ce(149);const r=o.getParent();return bt(r)||ce(210),[n,o,r]}function He(e){const[t,,n]=Be(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,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}class Pe{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!We(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Pe(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(le).forEach((e=>{const n=e.getFirstChild();m(n)&&(t|=n.getTextFormat())}));const n=w[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();i(t)||ce(151);S(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=C(this.anchor.key);le(e)||ce(152);const t=He(e);null===t&&ce(153);const n=C(this.focus.key);le(n)||ce(154);const o=He(n);null===o&&ce(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex+t.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex+t.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(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,le),l=t(o,le);le(r)||ce(152),le(l)||ce(154);const s=r.getParent();ge(s)||ce(156);const i=s.getParent();bt(i)||ce(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&ce(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&ce(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,u,h]=Ke(i,r,l);let d=Math.min(u.startColumn,h.startColumn),g=Math.min(u.startRow,h.startRow),f=Math.max(u.startColumn+u.cell.__colSpan-1,h.startColumn+h.cell.__colSpan-1),p=Math.max(u.startRow+u.cell.__rowSpan-1,h.startRow+h.cell.__rowSpan-1),m=d,S=g,C=d,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;d=Math.min(d,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),p=Math.max(p,o+t.__rowSpan-1)}for(;d<m||g<S||f>C||p>w;){if(d<m){const e=w-S,t=m-1;for(let n=0;n<=e;n++)b(a[S+n][t]);m=t}if(g<S){const e=C-m,t=S-1;for(let n=0;n<=e;n++)b(a[t][m+n]);S=t}if(f>C){const e=w-S,t=C+1;for(let n=0;n<=e;n++)b(a[S+n][t]);C=t}if(p>w){const e=C-m,t=w+1;for(let n=0;n<=e;n++)b(a[t][m+n]);w=t}}const y=new Map([[i.getKey(),i]]);let N=null;for(let e=g;e<=p;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();ge(o)||ce(160),o!==N&&y.set(o.getKey(),o),y.set(n.getKey(),n);for(const e of De(n))y.set(e.getKey(),e);N=o}const x=Array.from(y.values());return _()||(this._cachedNodes=x),x}getTextContent(){const e=this.getNodes().filter((e=>le(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 We(e){return e instanceof Pe}function Le(){const e=p("root",0,"element"),t=p("root",0,"element");return new Pe("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&ce(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}function Ie(e,t=b()){const n=C(e);bt(n)||ce(231,e);const o=Ye(n,t.getElementByKey(e));return null===o&&ce(232,e),{tableElement:o,tableNode:n}}class Ue{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.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return Ie(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=qe(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=qe(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(),e.update((()=>{const{tableNode:t,tableElement:n}=this.$lookup(),o=qe(t,n);Ge(e,o,null),y(null),e.dispatchCommand(N,void 0)}))}enableHighlightStyle(){const e=this.editor;e.getEditorState().read((()=>{const{tableElement:t}=this.$lookup();n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}),{editor:e})}disableHighlightStyle(){const t=this.editor;t.getEditorState().read((()=>{const{tableElement:n}=this.$lookup();e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}),{editor:t})}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ge(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=ze(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=x(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&le(t)&&o.is(it(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Le(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),y(this.tableSelection),n.dispatchCommand(N,void 0),Ge(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=x(e.elem);if(le(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Le(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();We(t)||ce(11);const n=v(),o=n.anchor,r=n.focus,l=t.getNodes().filter(le),s=l[0].getFirstChild(),i=m(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)})),y(t),this.editor.dispatchCommand(N,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=C(this.tableNodeKey);if(!bt(t))throw new Error("Expected TableNode.");const n=g();We(n)||ce(11);const o=n.getNodes().filter(le);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ge(e,this.table,null),y(null),e.dispatchCommand(N,void 0);else{t.selectPrevious(),t.remove();T().selectStart()}}))}}const $e="__lexicalTableSelection",ze=e=>ae?(e||window).getSelection():null;function Ye(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&ce(233,t.nodeName),n}function Xe(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const u=new Ue(r,e.getKey()),h=r._window||window,p=Ye(e,n);!function(e,t){null!==Je(e)&&ce(205);e[$e]=t}(p,u),u.listenersToRemove.add((()=>function(e,t){Je(e)===t&&delete e[$e]}(p,u)));const m=()=>{const e=()=>{u.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&u.isSelecting)return u.isSelecting=!1,h.removeEventListener("mouseup",e),void h.removeEventListener("mousemove",t);const o=je(n.target);null===o||u.anchorX===o.x&&u.anchorY===o.y||(n.preventDefault(),u.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};p.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=je(e.target);null!==t&&(at(e),u.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=m();u.isSelecting=!0,h.addEventListener("mouseup",n,u.listenerOptions),h.addEventListener("mousemove",o,u.listenerOptions)}),0)}),u.listenerOptions);h.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;We(t)&&t.tableKey===u.tableNodeKey&&c.contains(n)&&u.clearHighlight()}))}),u.listenerOptions),u.listenersToRemove.add(r.registerCommand(O,(t=>ct(r,t,"down",e,u)),R)),u.listenersToRemove.add(r.registerCommand(k,(t=>ct(r,t,"up",e,u)),R)),u.listenersToRemove.add(r.registerCommand(E,(t=>ct(r,t,"backward",e,u)),R)),u.listenersToRemove.add(r.registerCommand(F,(t=>ct(r,t,"forward",e,u)),R)),u.listenersToRemove.add(r.registerCommand(M,(e=>{const n=g();if(We(n)){const o=t(n.focus.getNode(),le);if(le(o))return at(e),o.selectEnd(),!0}return!1}),R));[K,A,B].forEach((n=>{u.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!tt(o,e))return!1;if(We(o))return u.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>le(e)));if(!le(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return u.clearText(),!0;const h=t(o.anchor.getNode(),(e=>i(e))),d=h&&t(h,(e=>i(e)&&le(e.getParent())));if(!i(d)||!i(h))return!1;if(n===A&&null===d.getPreviousSibling())return!0}return!1})(n),H))}));const S=t=>{const n=g();if(!We(n)&&!f(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!!We(n)&&(t&&(t.preventDefault(),t.stopPropagation()),u.clearText(),!0)};function C(t){const n=e.getCordsFromCellNode(t,u.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,u.table)}return u.listenersToRemove.add(r.registerCommand(P,S,H)),u.listenersToRemove.add(r.registerCommand(W,S,H)),u.listenersToRemove.add(r.registerCommand(L,(e=>{const t=g();if(t){if(!We(t)&&!f(t))return!1;V(r,o(e,ClipboardEvent)?e:null,Z(t));const n=S(e);return f(t)?(t.removeText(),!0):n}return!1}),H)),u.listenersToRemove.add(r.registerCommand(D,(n=>{const o=g();if(!tt(o,e))return!1;if(We(o))return u.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>le(e)));if(!le(e))return!1}return!1}),H)),u.listenersToRemove.add(r.registerCommand(I,(t=>{const n=g();if(!We(n)||!tt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!le(o)||!le(r))return!1;const[l,s,c]=Ke(e,o,r),a=Math.max(s.startRow,c.startRow),u=Math.max(s.startColumn,c.startColumn),h=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn);for(let e=h;e<=a;e++)for(let n=d;n<=u;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),H)),u.listenersToRemove.add(r.registerCommand(U,(n=>{const o=g();if(!tt(o,e))return!1;if(We(o))return u.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>le(e)));if(!le(l))return!1;if("string"==typeof n){const t=ht(r,o,e);if(t)return ut(t,e,[d(n)]),!0}}return!1}),H)),l&&u.listenersToRemove.add(r.registerCommand($,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!tt(n,e))return!1;const o=st(n.anchor.getNode());if(null===o)return!1;at(t);const r=e.getCordsFromCellNode(o,u.table);return Ze(u,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),H)),u.listenersToRemove.add(r.registerCommand(z,(t=>e.isSelected()),R)),u.listenersToRemove.add(r.registerCommand(Y,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=We(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>le(e)))&&null!==t(o.focus.getNode(),(e=>le(e)))||l;if(1!==n.length||!bt(n[0])||!i||null===r)return!1;const[c]=r,u=n[0],h=u.getChildren(),d=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),p=t(c.getNode(),(e=>le(e))),m=p&&t(p,(e=>ge(e))),S=m&&t(m,(e=>bt(e)));if(!le(p)||!ge(m)||!bt(S))return!1;const C=m.getIndexWithinParent(),_=Math.min(S.getChildrenSize()-1,C+g-1),w=p.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(C,_),x=Math.max(w,b),v=Math.max(C,_),T=S.getChildren();let O=0;for(let e=N;e<=v;e++){const t=T[e];if(!ge(t))return!1;const n=h[O];if(!ge(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(!le(t))return!1;const n=r[l];if(!le(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}O++}return!0}),H)),u.listenersToRemove.add(r.registerCommand(N,(()=>{const n=g(),o=X();if(u.getAndClearShouldCheckSelection()&&f(o)&&f(n)&&n.isCollapsed()){const o=n.anchor.getNode(),r=e.getFirstChild(),l=st(o);if(null!==l&&ge(r)){const e=r.getFirstChild();if(le(e)&&!t(l,(t=>t.is(e))))return e.selectStart(),!0}}if(f(n)){const{anchor:t,focus:o}=n,l=t.getNode(),s=o.getNode(),i=st(l),c=st(s),a=!(!i||!e.is(it(i))),d=!(!c||!e.is(it(c))),g=a!==d,f=a&&d,p=n.isBackward();if(g){const t=n.clone();if(d){const[n]=Ke(e,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element")}else if(a){const[n]=Ke(e,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(p?r.getKey():o.getKey(),p?r.getChildrenSize():0,"element")}y(t),Ve(r,u)}else f&&(i.is(c)||(u.setAnchorCellForSelection(C(i)),u.setFocusCellForSelection(C(c),!0),u.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=m();u.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(n&&We(n)&&n.is(o)&&n.tableKey===e.getKey()){const t=ze(r._window);if(t&&t.anchorNode&&t.focusNode){const o=x(t.focusNode),l=o&&!e.is(it(o)),s=x(t.anchorNode),i=s&&e.is(it(s));if(l&&i&&t.rangeCount>0){const o=J(t,r);o&&(o.anchor.set(e.getKey(),n.isBackward()?e.getChildrenSize():0,"element"),t.removeAllRanges(),y(o))}}}return n&&!n.is(o)&&(We(n)||We(o))&&u.tableSelection&&!u.tableSelection.is(o)?(We(n)&&n.tableKey===u.tableNodeKey?u.updateTableTableSelection(n):!We(n)&&We(o)&&o.tableKey===u.tableNodeKey&&u.updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Qe(t.table,(t=>{const n=t.elem;t.highlighted=!1,lt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,u):!u.hasHijackedSelectionStyles&&e.isSelected()&&Ve(r,u),!1)}),H)),u.listenersToRemove.add(r.registerCommand(j,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!tt(t,e))return!1;const n=ht(r,t,e);return!!n&&(ut(n,e),!0)}),H)),u}function Je(e){return e[$e]||null}function je(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 qe(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Ye(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 Ge(e,t,n){const o=new Set(n?n.getNodes():[]);Qe(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,rt(e,t)):(t.highlighted=!1,lt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Qe(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=x(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ve(e,t){t.disableHighlightStyle(),Qe(t.table,(t=>{t.highlighted=!0,rt(e,t)}))}const Ze=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?nt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?nt(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?nt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?nt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},et=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function tt(e,t){if(f(e)||We(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function nt(e,t){t?e.selectStart():e.selectEnd()}const ot="172,206,247";function rt(e,t){const n=t.elem,o=x(n);le(o)||ce(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${ot})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${ot},0.85), rgba(${ot},0.85))`),n.style.setProperty("caret-color","transparent")}function lt(e,t){const n=t.elem,o=x(n);le(o)||ce(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function st(e){const n=t(e,le);return le(n)?n:null}function it(e){const n=t(e,bt);return bt(n)?n:null}function ct(e,n,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=g();if(!tt(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!bt(c))&&(at(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=t(e,(e=>bt(e)));if(le(l)&&(l=t(l,bt)),l!==r)return!1;if(!l)return!1;const c="down"===o?l.getNextSibling():l.getPreviousSibling();if(!c)return!1;let u=0;"up"===o&&i(c)&&(u=c.getChildrenSize());let h=c;if("up"===o&&i(c)){const e=c.getLastChild();h=e||c,u=a(h)?h.getTextContentSize():0}const d=s.clone();return d.focus.set(h.getKey(),u,a(h)?"text":"element"),y(d),at(n),!0}if(q(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){const n=t(e,le);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Be(e),[o]=Be(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=t(e,(e=>i(e)&&!e.isInline()));if(le(r)&&(r=t(r,bt)),!r)return!1;const c="down"===o?r.getNextSibling():r.getPreviousSibling();if(bt(c)&&l.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),t=c.getLastDescendant();if(!e||!t)return!1;const[r]=Be(e),[l]=Be(t),i=s.clone();return i.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),at(n),y(i),!0}}}}return"down"===o&&pt(e)&&l.setShouldCheckSelection(),!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,u=t(c.getNode(),le),h=t(a.getNode(),le);if(!le(u)||!u.is(h))return!1;const d=it(u);if(d!==r&&null!=d){const t=Ye(d,e.getElementByKey(d.getKey()));if(null!=t)return l.table=qe(d,t),ct(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const u=s.getNodes();return(1!==u.length||!G(u[0]))&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,le);if(!le(l))return!1;const[s,c]=Ke(o,l,l);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,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&bt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||bt(a))return!1;at(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(u.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let p;if("element"===c.type)p=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const m="up"===o?u.getFirstChild():u.getLastChild();if(null==m)return!1;const S=e.getElementByKey(m.__key);if(null==S)return!1;const C=S.getBoundingClientRect();if("up"===o?C.top>p.top-p.height:p.bottom+p.height>C.bottom){at(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return Ze(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(We(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),le),u=t(c.getNode(),le),[h]=s.getNodes();bt(h)||ce(234);const d=Ye(h,e.getElementByKey(h.getKey()));if(!le(a)||!le(u)||!bt(h)||null==d)return!1;l.updateTableTableSelection(s);const g=qe(h,d),f=r.getCordsFromCellNode(a,g),p=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(p),at(n),n.shiftKey){const e=r.getCordsFromCellNode(u,g);return et(l,h,e.x,e.y,o)}return u.selectEnd(),!0}return!1}function at(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function ut(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function ht(e,n,o){const r=o.getParent();if(!r)return;const l=window.getSelection();if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Ye(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=t(n.anchor.getNode(),(e=>le(e)));if(!a)return;const u=t(a,(e=>bt(e)));if(!bt(u)||!u.is(o))return;const[h,d]=Ke(o,a,a),g=h[0][0],f=h[h.length-1][h[0].length-1],{startRow:p,startColumn:m}=d,S=p===g.startRow&&m===g.startColumn,C=p===f.startRow&&m===f.startColumn;return S?"first":C?"last":void 0}function dt(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 gt(t,o,r){r?(e(t,o.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(n(t,o.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}const ft=new WeakSet;function pt(e=b()){return ft.has(e)}function mt(e,t){t?ft.add(e):ft.delete(e)}class St extends l{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 St(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:_t,priority:1})}}static importJSON(e){const t=wt();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}}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&ce(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");if(o.appendChild(r),dt(o,0,this.getColumnCount(),this.getColWidths()),Q(r),e(o,t.theme.table),this.__rowStriping&>(o,t,!0),pt(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&>(t,n,this.__rowStriping),dt(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e&&r(e)&&"TABLE"!==e.nodeName&&(e=e.querySelector("table")),!e||!r(e))return null;const t=e.querySelectorAll(":scope > tr");if(t.length>0){const n=document.createElement("tbody");n.append(...t),e.append(n)}return e}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return x(n)===e}));if(-1!==r)return{x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<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=x(o.elem);return le(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=>{le(e)&&(t+=e.getColSpan())})),t}}function Ct(e,t){const n=e.getElementByKey(t.getKey());return null===n&&ce(230),qe(t,n)}function _t(e){const t=wt();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!ee.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{node:t}}function wt(){return u(new St)}function bt(e){return e instanceof St}export{Ke as $computeTableMap,Ae as $computeTableMapSkipCellCheck,re as $createTableCellNode,wt as $createTableNode,fe as $createTableNodeWithDimensions,de as $createTableRowNode,Le as $createTableSelection,Oe as $deleteTableColumn,ke as $deleteTableColumn__EXPERIMENTAL,Re as $deleteTableRow__EXPERIMENTAL,st as $findCellNode,it as $findTableNode,Ct as $getElementForTableNode,Be as $getNodeTriplet,Ie as $getTableAndElementByKey,pe as $getTableCellNodeFromLexicalNode,He as $getTableCellNodeRect,_e as $getTableColumnIndexFromTableCellNode,Se as $getTableNodeFromLexicalNodeOrThrow,Ce as $getTableRowIndexFromTableCellNode,me as $getTableRowNodeFromTableCellNodeOrThrow,ve as $insertTableColumn,Te as $insertTableColumn__EXPERIMENTAL,ye as $insertTableRow,xe as $insertTableRow__EXPERIMENTAL,pt as $isScrollableTablesActive,le as $isTableCellNode,bt as $isTableNode,ge as $isTableRowNode,We as $isTableSelection,be as $removeTableRowAtIndex,Me as $unmergeCell,se as INSERT_TABLE_COMMAND,te as TableCellHeaderStates,ne as TableCellNode,St as TableNode,Ue as TableObserver,ue as TableRowNode,Xe as applyTableHandlers,je as getDOMCellFromTarget,Ye as getTableElement,Je as getTableObserverFromTableElement,mt as setScrollableTablesActive};
|
9
|
+
import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as u,createCommand as h,$createTextNode as d,$getSelection as g,$isRangeSelection as f,$createPoint as p,$isParagraphNode as m,$normalizeSelection__EXPERIMENTAL as S,$getNodeByKey as C,isCurrentlyReadOnlyMode as _,TEXT_TYPE_TO_FORMAT as w,$getEditor as b,$setSelection as y,SELECTION_CHANGE_COMMAND as N,$getNearestNodeFromDOMNode as x,$createRangeSelection as v,$getRoot as T,KEY_ARROW_DOWN_COMMAND as O,COMMAND_PRIORITY_HIGH as R,KEY_ARROW_UP_COMMAND as k,KEY_ARROW_LEFT_COMMAND as E,KEY_ARROW_RIGHT_COMMAND as F,KEY_ESCAPE_COMMAND as M,DELETE_WORD_COMMAND as K,DELETE_LINE_COMMAND as A,DELETE_CHARACTER_COMMAND as B,COMMAND_PRIORITY_CRITICAL as H,KEY_BACKSPACE_COMMAND as P,KEY_DELETE_COMMAND as W,CUT_COMMAND as L,FORMAT_TEXT_COMMAND as D,FORMAT_ELEMENT_COMMAND as I,CONTROLLED_TEXT_INSERTION_COMMAND as U,KEY_TAB_COMMAND as $,FOCUS_COMMAND as z,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Y,$getPreviousSelection as X,$createRangeSelectionFromDom as J,INSERT_PARAGRAPH_COMMAND as j,$isRootOrShadowRoot as q,$isDecoratorNode as G,setDOMUnmanaged as Q}from"lexical";import{copyToClipboard as V,$getClipboardDataFromSelection as Z}from"@lexical/clipboard";const ee=/^(\d+(?:\.\d+)?)px$/,te={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ne extends l{static getType(){return"tablecell"}static clone(e){return new ne(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:oe,priority:0}),th:e=>({conversion:oe,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return re(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=te.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;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";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.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=te.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!==te.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 oe(e){const t=e,n=e.nodeName.toLowerCase();let o;ee.test(t.style.width)&&(o=parseFloat(t.style.width));const r=re("th"===n?te.ROW:te.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const u=t.style,h=(u&&u.textDecoration||"").split(" "),d="700"===u.fontWeight||"bold"===u.fontWeight,g=h.includes("line-through"),f="italic"===u.fontStyle,p=h.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(le(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function re(e,t=1,n){return u(new ne(e,t,n))}function le(e){return e instanceof ne}const se=h("INSERT_TABLE_COMMAND");function ie(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ce=ie((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;class ue extends l{static getType(){return"tablerow"}static clone(e){return new ue(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:he,priority:0})}}static importJSON(e){return de(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function he(e){const t=e;let n;return ee.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:de(n)}}function de(e){return u(new ue(e))}function ge(e){return e instanceof ue}function fe(e,t,n=!0){const o=wt();for(let r=0;r<e;r++){const e=de();for(let o=0;o<t;o++){let t=te.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=te.ROW),0===o&&n.columns&&(t|=te.COLUMN)):n&&(0===r&&(t|=te.ROW),0===o&&(t|=te.COLUMN));const l=re(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function pe(e){const n=t(e,(e=>le(e)));return le(n)?n:null}function me(e){const n=t(e,(e=>ge(e)));if(ge(n))return n;throw new Error("Expected table cell to be inside of table row.")}function Se(e){const n=t(e,(e=>bt(e)));if(bt(n))return n;throw new Error("Expected table cell to be inside of table.")}function Ce(e){const t=me(e);return Se(t).getChildren().findIndex((e=>e.is(t)))}function _e(e){return me(e).getChildren().findIndex((t=>t.is(e)))}function we(e,t){const n=Se(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 be(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 ye(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const i=l[t];if(!ge(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=de();for(let n=0;n<t;n++){const t=e[n];le(t)||ce(12);const{above:l,below:i}=we(t,r);let c=te.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(te.COLUMN)||i&&i.hasHeaderState(te.COLUMN))&&(c|=te.COLUMN);const u=re(c,1,a);u.append(s()),o.append(u)}n?i.insertAfter(o):i.insertBefore(o)}return e}const Ne=(e,t)=>e===te.BOTH||e===t?t:te.NO_STATUS;function xe(e=!0){const t=g();f(t)||We(t)||ce(188);const n=t.focus.getNode(),[o,,r]=Be(n),[l,i]=Ke(r,o,o),c=l[0].length,{startRow:a}=i;let u=null;if(e){const e=a+o.__rowSpan-1,t=l[e],n=de();for(let o=0;o<c;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Ne(e,te.COLUMN);n.append(re(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ge(i)||ce(145),i.insertAfter(n),u=n}else{const e=l[a],t=de();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=Ne(o,te.COLUMN);t.append(re(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ge(n)||ce(145),n.insertBefore(t),u=t}return u}function ve(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(ge(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];le(o)||ce(12);const{left:l,right:c}=we(o,r);let a=te.NO_STATUS;(l&&l.hasHeaderState(te.ROW)||c&&c.hasHeaderState(te.ROW))&&(a|=te.ROW);const u=re(a);u.append(s()),i.push({newTableCell:u,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Te(e=!0){const t=g();f(t)||We(t)||ce(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Be(n),[l,,i]=Be(o),[c,a,u]=Ke(i,l,r),h=c.length,d=e?Math.max(a.startColumn,u.startColumn):Math.min(a.startColumn,u.startColumn),p=e?d+l.__colSpan-1:d-1,m=i.getFirstChild();ge(m)||ce(120);let S=null;function C(e=te.NO_STATUS){const t=re(e).append(s());return null===S&&(S=t),t}let _=m;e:for(let e=0;e<h;e++){if(0!==e){const e=_.getNextSibling();ge(e)||ce(121),_=e}const t=c[e],n=t[p<0?0:p].cell.__headerState,o=Ne(n,te.ROW);if(p<0){Fe(_,C(o));continue}const{cell:r,startColumn:l,startRow:s}=t[p];if(l+r.__colSpan-1<=p){let n=r,l=s,i=p;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(C(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(C(o))}else r.setColSpan(r.__colSpan+1)}null!==S&&Ee(S);const w=i.getColWidths();if(w){const e=[...w],t=p<0?0:p,n=e[t];e.splice(t,0,n),i.setColWidths(e)}return S}function Oe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ge(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 Re(){const e=g();f(e)||We(e)||ce(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Be(t),[l]=Be(n),[s,i,c]=Ke(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,p=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&&(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===m&&ce(122),0===t)Fe(m,n);else{const{cell:e}=p[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ge(t)||ce(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];Ee(e)}else{const e=s[a-1],{cell:t}=e[0];Ee(t)}}function ke(){const e=g();f(e)||We(e)||ce(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Be(t),[l]=Be(n),[s,i,c]=Ke(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),p=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),m=p-d+1;if(s[0].length===p-d+1)return r.selectPrevious(),void r.remove();const S=s.length;for(let e=0;e<S;e++)for(let t=d;t<=p;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(m,n.__colSpan-e))}}else if(o+n.__colSpan-1>p){if(t===p){const e=p-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const C=s[u],_=a>h?C[a+o.__colSpan]:C[h+l.__colSpan];if(void 0!==_){const{cell:e}=_;Ee(e)}else{const e=h<a?C[h-1]:C[a-1],{cell:t}=e;Ee(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,m),r.setColWidths(e)}}function Ee(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Fe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Me(){const e=g();f(e)||We(e)||ce(188);const t=e.anchor.getNode(),[n,o,r]=Be(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Ke(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&te.COLUMN,p=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<c.length;e++)n&=c[e][t+u].cell.__headerState;return n})),m=n.__headerState&te.ROW,S=Array.from({length:i},((e,t)=>{let n=m;for(let e=0;0!==n&&e<c[0].length;e++)n&=c[t+h][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(re(p[e]|S[0]).append(s()));n.setColSpan(1)}if(i>1){let e;for(let t=1;t<i;t++){const n=h+t,r=c[n];e=(e||o).getNextSibling(),ge(e)||ce(125);let i=null;for(let e=0;e<u;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===i)for(let n=l-1;n>=0;n--)Fe(e,re(p[n]|S[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(re(p[e]|S[t]).append(s()))}n.setRowSpan(1)}}function Ke(e,t,n){const[o,r,l]=Ae(e,t,n);return null===r&&ce(207),null===l&&ce(208),[o,r,l]}function Ae(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];ge(o)||ce(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){le(c)||ce(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 Be(e){let n;if(e instanceof ne)n=e;else if("__type"in e){const o=t(e,le);le(o)||ce(148),n=o}else{const o=t(e.getNode(),le);le(o)||ce(148),n=o}const o=n.getParent();ge(o)||ce(149);const r=o.getParent();return bt(r)||ce(210),[n,o,r]}function He(e){const[t,,n]=Be(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,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}class Pe{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!We(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Pe(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(le).forEach((e=>{const n=e.getFirstChild();m(n)&&(t|=n.getTextFormat())}));const n=w[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();i(t)||ce(151);S(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=C(this.anchor.key);le(e)||ce(152);const t=He(e);null===t&&ce(153);const n=C(this.focus.key);le(n)||ce(154);const o=He(n);null===o&&ce(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex+t.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex+t.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(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,le),l=t(o,le);le(r)||ce(152),le(l)||ce(154);const s=r.getParent();ge(s)||ce(156);const i=s.getParent();bt(i)||ce(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&ce(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&ce(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,u,h]=Ke(i,r,l);let d=Math.min(u.startColumn,h.startColumn),g=Math.min(u.startRow,h.startRow),f=Math.max(u.startColumn+u.cell.__colSpan-1,h.startColumn+h.cell.__colSpan-1),p=Math.max(u.startRow+u.cell.__rowSpan-1,h.startRow+h.cell.__rowSpan-1),m=d,S=g,C=d,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;d=Math.min(d,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),p=Math.max(p,o+t.__rowSpan-1)}for(;d<m||g<S||f>C||p>w;){if(d<m){const e=w-S,t=m-1;for(let n=0;n<=e;n++)b(a[S+n][t]);m=t}if(g<S){const e=C-m,t=S-1;for(let n=0;n<=e;n++)b(a[t][m+n]);S=t}if(f>C){const e=w-S,t=C+1;for(let n=0;n<=e;n++)b(a[S+n][t]);C=t}if(p>w){const e=C-m,t=w+1;for(let n=0;n<=e;n++)b(a[t][m+n]);w=t}}const y=new Map([[i.getKey(),i]]);let N=null;for(let e=g;e<=p;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();ge(o)||ce(160),o!==N&&y.set(o.getKey(),o),y.set(n.getKey(),n);for(const e of De(n))y.set(e.getKey(),e);N=o}const x=Array.from(y.values());return _()||(this._cachedNodes=x),x}getTextContent(){const e=this.getNodes().filter((e=>le(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 We(e){return e instanceof Pe}function Le(){const e=p("root",0,"element"),t=p("root",0,"element");return new Pe("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&ce(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}function Ie(e,t=b()){const n=C(e);bt(n)||ce(231,e);const o=Ye(n,t.getElementByKey(e));return null===o&&ce(232,e),{tableElement:o,tableNode:n}}class Ue{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.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return Ie(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=qe(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=qe(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(),e.update((()=>{const{tableNode:t,tableElement:n}=this.$lookup(),o=qe(t,n);Ge(e,o,null),y(null),e.dispatchCommand(N,void 0)}))}enableHighlightStyle(){const e=this.editor;e.getEditorState().read((()=>{const{tableElement:t}=this.$lookup();n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}),{editor:e})}disableHighlightStyle(){const t=this.editor;t.getEditorState().read((()=>{const{tableElement:n}=this.$lookup();e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}),{editor:t})}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ge(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=ze(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=x(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&le(t)&&o.is(it(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Le(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),y(this.tableSelection),n.dispatchCommand(N,void 0),Ge(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=x(e.elem);if(le(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Le(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();We(t)||ce(11);const n=v(),o=n.anchor,r=n.focus,l=t.getNodes().filter(le),s=l[0].getFirstChild(),i=m(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)})),y(t),this.editor.dispatchCommand(N,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=C(this.tableNodeKey);if(!bt(t))throw new Error("Expected TableNode.");const n=g();We(n)||ce(11);const o=n.getNodes().filter(le);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ge(e,this.table,null),y(null),e.dispatchCommand(N,void 0);else{t.selectPrevious(),t.remove();T().selectStart()}}))}}const $e="__lexicalTableSelection",ze=e=>ae?(e||window).getSelection():null;function Ye(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&ce(233,t.nodeName),n}function Xe(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const u=new Ue(r,e.getKey()),h=r._window||window,p=Ye(e,n);!function(e,t){null!==Je(e)&&ce(205);e[$e]=t}(p,u),u.listenersToRemove.add((()=>function(e,t){Je(e)===t&&delete e[$e]}(p,u)));const m=()=>{const e=()=>{u.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&u.isSelecting)return u.isSelecting=!1,h.removeEventListener("mouseup",e),void h.removeEventListener("mousemove",t);const o=je(n.target);null===o||u.anchorX===o.x&&u.anchorY===o.y||(n.preventDefault(),u.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};p.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=je(e.target);null!==t&&(at(e),u.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=m();u.isSelecting=!0,h.addEventListener("mouseup",n,u.listenerOptions),h.addEventListener("mousemove",o,u.listenerOptions)}),0)}),u.listenerOptions);h.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;We(t)&&t.tableKey===u.tableNodeKey&&c.contains(n)&&u.clearHighlight()}))}),u.listenerOptions),u.listenersToRemove.add(r.registerCommand(O,(t=>ct(r,t,"down",e,u)),R)),u.listenersToRemove.add(r.registerCommand(k,(t=>ct(r,t,"up",e,u)),R)),u.listenersToRemove.add(r.registerCommand(E,(t=>ct(r,t,"backward",e,u)),R)),u.listenersToRemove.add(r.registerCommand(F,(t=>ct(r,t,"forward",e,u)),R)),u.listenersToRemove.add(r.registerCommand(M,(e=>{const n=g();if(We(n)){const o=t(n.focus.getNode(),le);if(le(o))return at(e),o.selectEnd(),!0}return!1}),R));[K,A,B].forEach((n=>{u.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!tt(o,e))return!1;if(We(o))return u.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>le(e)));if(!le(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return u.clearText(),!0;const h=t(o.anchor.getNode(),(e=>i(e))),d=h&&t(h,(e=>i(e)&&le(e.getParent())));if(!i(d)||!i(h))return!1;if(n===A&&null===d.getPreviousSibling())return!0}return!1})(n),H))}));const S=t=>{const n=g();if(!We(n)&&!f(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!!We(n)&&(t&&(t.preventDefault(),t.stopPropagation()),u.clearText(),!0)};function C(t){const n=e.getCordsFromCellNode(t,u.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,u.table)}return u.listenersToRemove.add(r.registerCommand(P,S,H)),u.listenersToRemove.add(r.registerCommand(W,S,H)),u.listenersToRemove.add(r.registerCommand(L,(e=>{const t=g();if(t){if(!We(t)&&!f(t))return!1;V(r,o(e,ClipboardEvent)?e:null,Z(t));const n=S(e);return f(t)?(t.removeText(),!0):n}return!1}),H)),u.listenersToRemove.add(r.registerCommand(D,(n=>{const o=g();if(!tt(o,e))return!1;if(We(o))return u.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>le(e)));if(!le(e))return!1}return!1}),H)),u.listenersToRemove.add(r.registerCommand(I,(t=>{const n=g();if(!We(n)||!tt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!le(o)||!le(r))return!1;const[l,s,c]=Ke(e,o,r),a=Math.max(s.startRow,c.startRow),u=Math.max(s.startColumn,c.startColumn),h=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn);for(let e=h;e<=a;e++)for(let n=d;n<=u;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),H)),u.listenersToRemove.add(r.registerCommand(U,(n=>{const o=g();if(!tt(o,e))return!1;if(We(o))return u.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>le(e)));if(!le(l))return!1;if("string"==typeof n){const t=ht(r,o,e);if(t)return ut(t,e,[d(n)]),!0}}return!1}),H)),l&&u.listenersToRemove.add(r.registerCommand($,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!tt(n,e))return!1;const o=st(n.anchor.getNode());if(null===o)return!1;at(t);const r=e.getCordsFromCellNode(o,u.table);return Ze(u,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),H)),u.listenersToRemove.add(r.registerCommand(z,(t=>e.isSelected()),R)),u.listenersToRemove.add(r.registerCommand(Y,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=We(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>le(e)))&&null!==t(o.focus.getNode(),(e=>le(e)))||l;if(1!==n.length||!bt(n[0])||!i||null===r)return!1;const[c]=r,u=n[0],h=u.getChildren(),d=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),p=t(c.getNode(),(e=>le(e))),m=p&&t(p,(e=>ge(e))),S=m&&t(m,(e=>bt(e)));if(!le(p)||!ge(m)||!bt(S))return!1;const C=m.getIndexWithinParent(),_=Math.min(S.getChildrenSize()-1,C+g-1),w=p.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(C,_),x=Math.max(w,b),v=Math.max(C,_),T=S.getChildren();let O=0;for(let e=N;e<=v;e++){const t=T[e];if(!ge(t))return!1;const n=h[O];if(!ge(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(!le(t))return!1;const n=r[l];if(!le(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}O++}return!0}),H)),u.listenersToRemove.add(r.registerCommand(N,(()=>{const n=g(),o=X();if(u.getAndClearShouldCheckSelection()&&f(o)&&f(n)&&n.isCollapsed()){const o=n.anchor.getNode(),r=e.getFirstChild(),l=st(o);if(null!==l&&ge(r)){const n=r.getFirstChild();if(le(n)&&e.is(t(l,(t=>t.is(e)||t.is(n)))))return n.selectStart(),!0}}if(f(n)){const{anchor:t,focus:o}=n,l=t.getNode(),s=o.getNode(),i=st(l),c=st(s),a=!(!i||!e.is(it(i))),d=!(!c||!e.is(it(c))),g=a!==d,f=a&&d,p=n.isBackward();if(g){const t=n.clone();if(d){const[n]=Ke(e,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element")}else if(a){const[n]=Ke(e,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(p?r.getKey():o.getKey(),p?r.getChildrenSize():0,"element")}y(t),Ve(r,u)}else f&&(i.is(c)||(u.setAnchorCellForSelection(C(i)),u.setFocusCellForSelection(C(c),!0),u.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=m();u.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(n&&We(n)&&n.is(o)&&n.tableKey===e.getKey()){const t=ze(r._window);if(t&&t.anchorNode&&t.focusNode){const o=x(t.focusNode),l=o&&!e.is(it(o)),s=x(t.anchorNode),i=s&&e.is(it(s));if(l&&i&&t.rangeCount>0){const o=J(t,r);o&&(o.anchor.set(e.getKey(),n.isBackward()?e.getChildrenSize():0,"element"),t.removeAllRanges(),y(o))}}}return n&&!n.is(o)&&(We(n)||We(o))&&u.tableSelection&&!u.tableSelection.is(o)?(We(n)&&n.tableKey===u.tableNodeKey?u.updateTableTableSelection(n):!We(n)&&We(o)&&o.tableKey===u.tableNodeKey&&u.updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Qe(t.table,(t=>{const n=t.elem;t.highlighted=!1,lt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,u):!u.hasHijackedSelectionStyles&&e.isSelected()&&Ve(r,u),!1)}),H)),u.listenersToRemove.add(r.registerCommand(j,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!tt(t,e))return!1;const n=ht(r,t,e);return!!n&&(ut(n,e),!0)}),H)),u}function Je(e){return e[$e]||null}function je(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 qe(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Ye(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 Ge(e,t,n){const o=new Set(n?n.getNodes():[]);Qe(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,rt(e,t)):(t.highlighted=!1,lt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Qe(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=x(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ve(e,t){t.disableHighlightStyle(),Qe(t.table,(t=>{t.highlighted=!0,rt(e,t)}))}const Ze=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?nt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?nt(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?nt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?nt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},et=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function tt(e,t){if(f(e)||We(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function nt(e,t){t?e.selectStart():e.selectEnd()}const ot="172,206,247";function rt(e,t){const n=t.elem,o=x(n);le(o)||ce(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${ot})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${ot},0.85), rgba(${ot},0.85))`),n.style.setProperty("caret-color","transparent")}function lt(e,t){const n=t.elem,o=x(n);le(o)||ce(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function st(e){const n=t(e,le);return le(n)?n:null}function it(e){const n=t(e,bt);return bt(n)?n:null}function ct(e,n,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=g();if(!tt(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!bt(c))&&(at(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=t(e,(e=>bt(e)));if(le(l)&&(l=t(l,bt)),l!==r)return!1;if(!l)return!1;const c="down"===o?l.getNextSibling():l.getPreviousSibling();if(!c)return!1;let u=0;"up"===o&&i(c)&&(u=c.getChildrenSize());let h=c;if("up"===o&&i(c)){const e=c.getLastChild();h=e||c,u=a(h)?h.getTextContentSize():0}const d=s.clone();return d.focus.set(h.getKey(),u,a(h)?"text":"element"),y(d),at(n),!0}if(q(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){const n=t(e,le);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Be(e),[o]=Be(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=t(e,(e=>i(e)&&!e.isInline()));if(le(r)&&(r=t(r,bt)),!r)return!1;const c="down"===o?r.getNextSibling():r.getPreviousSibling();if(bt(c)&&l.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),t=c.getLastDescendant();if(!e||!t)return!1;const[r]=Be(e),[l]=Be(t),i=s.clone();return i.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),at(n),y(i),!0}}}}return"down"===o&&pt(e)&&l.setShouldCheckSelection(),!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,u=t(c.getNode(),le),h=t(a.getNode(),le);if(!le(u)||!u.is(h))return!1;const d=it(u);if(d!==r&&null!=d){const t=Ye(d,e.getElementByKey(d.getKey()));if(null!=t)return l.table=qe(d,t),ct(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const u=s.getNodes();return(1!==u.length||!G(u[0]))&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,le);if(!le(l))return!1;const[s,c]=Ke(o,l,l);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,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&bt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||bt(a))return!1;at(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(u.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let p;if("element"===c.type)p=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const m="up"===o?u.getFirstChild():u.getLastChild();if(null==m)return!1;const S=e.getElementByKey(m.__key);if(null==S)return!1;const C=S.getBoundingClientRect();if("up"===o?C.top>p.top-p.height:p.bottom+p.height>C.bottom){at(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return Ze(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(We(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),le),u=t(c.getNode(),le),[h]=s.getNodes();bt(h)||ce(234);const d=Ye(h,e.getElementByKey(h.getKey()));if(!le(a)||!le(u)||!bt(h)||null==d)return!1;l.updateTableTableSelection(s);const g=qe(h,d),f=r.getCordsFromCellNode(a,g),p=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(p),at(n),n.shiftKey){const e=r.getCordsFromCellNode(u,g);return et(l,h,e.x,e.y,o)}return u.selectEnd(),!0}return!1}function at(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function ut(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function ht(e,n,o){const r=o.getParent();if(!r)return;const l=window.getSelection();if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Ye(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=t(n.anchor.getNode(),(e=>le(e)));if(!a)return;const u=t(a,(e=>bt(e)));if(!bt(u)||!u.is(o))return;const[h,d]=Ke(o,a,a),g=h[0][0],f=h[h.length-1][h[0].length-1],{startRow:p,startColumn:m}=d,S=p===g.startRow&&m===g.startColumn,C=p===f.startRow&&m===f.startColumn;return S?"first":C?"last":void 0}function dt(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 gt(t,o,r){r?(e(t,o.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(n(t,o.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}const ft=new WeakSet;function pt(e=b()){return ft.has(e)}function mt(e,t){t?ft.add(e):ft.delete(e)}class St extends l{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 St(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:_t,priority:1})}}static importJSON(e){const t=wt();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}}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&ce(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");if(o.appendChild(r),dt(o,0,this.getColumnCount(),this.getColWidths()),Q(r),e(o,t.theme.table),this.__rowStriping&>(o,t,!0),pt(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&>(t,n,this.__rowStriping),dt(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e&&r(e)&&"TABLE"!==e.nodeName&&(e=e.querySelector("table")),!e||!r(e))return null;const t=e.querySelectorAll(":scope > tr");if(t.length>0){const n=document.createElement("tbody");n.append(...t),e.append(n)}return e}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return x(n)===e}));if(-1!==r)return{x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<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=x(o.elem);return le(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=>{le(e)&&(t+=e.getColSpan())})),t}}function Ct(e,t){const n=e.getElementByKey(t.getKey());return null===n&&ce(230),qe(t,n)}function _t(e){const t=wt();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!ee.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{node:t}}function wt(){return u(new St)}function bt(e){return e instanceof St}export{Ke as $computeTableMap,Ae as $computeTableMapSkipCellCheck,re as $createTableCellNode,wt as $createTableNode,fe as $createTableNodeWithDimensions,de as $createTableRowNode,Le as $createTableSelection,Oe as $deleteTableColumn,ke as $deleteTableColumn__EXPERIMENTAL,Re as $deleteTableRow__EXPERIMENTAL,st as $findCellNode,it as $findTableNode,Ct as $getElementForTableNode,Be as $getNodeTriplet,Ie as $getTableAndElementByKey,pe as $getTableCellNodeFromLexicalNode,He as $getTableCellNodeRect,_e as $getTableColumnIndexFromTableCellNode,Se as $getTableNodeFromLexicalNodeOrThrow,Ce as $getTableRowIndexFromTableCellNode,me as $getTableRowNodeFromTableCellNodeOrThrow,ve as $insertTableColumn,Te as $insertTableColumn__EXPERIMENTAL,ye as $insertTableRow,xe as $insertTableRow__EXPERIMENTAL,pt as $isScrollableTablesActive,le as $isTableCellNode,bt as $isTableNode,ge as $isTableRowNode,We as $isTableSelection,be as $removeTableRowAtIndex,Me as $unmergeCell,se as INSERT_TABLE_COMMAND,te as TableCellHeaderStates,ne as TableCellNode,St as TableNode,Ue as TableObserver,ue as TableRowNode,Xe as applyTableHandlers,je as getDOMCellFromTarget,Ye as getTableElement,Je as getTableObserverFromTableElement,mt as setScrollableTablesActive};
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.20.1-nightly.
|
11
|
+
"version": "0.20.1-nightly.20241118.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/clipboard": "0.20.1-nightly.
|
16
|
-
"@lexical/utils": "0.20.1-nightly.
|
17
|
-
"lexical": "0.20.1-nightly.
|
15
|
+
"@lexical/clipboard": "0.20.1-nightly.20241118.0",
|
16
|
+
"@lexical/utils": "0.20.1-nightly.20241118.0",
|
17
|
+
"lexical": "0.20.1-nightly.20241118.0"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|