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