@lexical/table 0.47.1-nightly.20260716.0 → 0.48.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/dist/LexicalTable.dev.js
CHANGED
|
@@ -3015,6 +3015,30 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler, tableObse
|
|
|
3015
3015
|
editor.dispatchCommand(lexical.PASTE_COMMAND, event);
|
|
3016
3016
|
}
|
|
3017
3017
|
}));
|
|
3018
|
+
|
|
3019
|
+
// In read-only mode (contentEditable=false), Firefox fires the native copy
|
|
3020
|
+
// event on the document rather than on the root element, so the core
|
|
3021
|
+
// PASS_THROUGH copy listener never sees it. We intercept at the document
|
|
3022
|
+
// level and forward to COPY_COMMAND. Unlike the paste listener above, we
|
|
3023
|
+
// skip events whose target is inside the rootElement — those are already
|
|
3024
|
+
// handled by the core copy listener which runs regardless of isEditable.
|
|
3025
|
+
tableObserver.listenersToRemove.add(lexical.registerEventListener(doc, 'copy', event => {
|
|
3026
|
+
if (event.defaultPrevented) {
|
|
3027
|
+
return;
|
|
3028
|
+
}
|
|
3029
|
+
const target = lexical.getComposedEventTarget(event);
|
|
3030
|
+
if (target === rootElement || lexical.isDOMNode(target) && rootElement.contains(target)) {
|
|
3031
|
+
return;
|
|
3032
|
+
}
|
|
3033
|
+
const shouldIntercept = editor.read('latest', () => {
|
|
3034
|
+
const selection = lexical.$getSelection();
|
|
3035
|
+
return rootElement.contains(lexical.getActiveElement(rootElement)) && $isTableSelection(selection) && $isSelectionInTable(selection, tableNode);
|
|
3036
|
+
});
|
|
3037
|
+
if (shouldIntercept) {
|
|
3038
|
+
event.preventDefault();
|
|
3039
|
+
editor.dispatchCommand(lexical.COPY_COMMAND, event);
|
|
3040
|
+
}
|
|
3041
|
+
}));
|
|
3018
3042
|
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, payload => {
|
|
3019
3043
|
const selection = lexical.$getSelection();
|
|
3020
3044
|
if (!$isSelectionInTable(selection, tableNode)) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { ElementNode, $getDocument, addClassNamesToElement, isHTMLElement, $isInlineElementOrDecoratorNode, $isTextNode, $isLineBreakNode, $createParagraphNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $findMatchingParent, $isParagraphNode, $createPoint, $getNodeByKey, $isElementNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, removeClassNamesFromElement, getDOMSelection, $createRangeSelection, $isRootNode, INSERT_PARAGRAPH_COMMAND, registerEventListener, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, PASTE_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, $getNearestNodeFromDOMNode,
|
|
9
|
+
import { ElementNode, $getDocument, addClassNamesToElement, isHTMLElement, $isInlineElementOrDecoratorNode, $isTextNode, $isLineBreakNode, $createParagraphNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $findMatchingParent, $isParagraphNode, $createPoint, $getNodeByKey, $isElementNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, removeClassNamesFromElement, getDOMSelection, $createRangeSelection, $isRootNode, INSERT_PARAGRAPH_COMMAND, registerEventListener, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, PASTE_COMMAND, getComposedEventTarget, isDOMNode, getActiveElement, COPY_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, $getNearestNodeFromDOMNode, $isRootOrShadowRoot, getDOMSelectionRange, getDOMSelectionPoints, $getPreviousSelection, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isSiblingCaret, $getSiblingCaret, $setPointFromCaret, $normalizeCaret, $createRangeSelectionFromDom, $isChildCaret, $getChildCaret, $getAdjacentChildCaret, IS_FIREFOX, $getNodeByKeyOrThrow, isDOMDocumentNode, isDOMShadowRoot, setDOMStyleFromCSS, setDOMUnmanaged, mergeRegister, COMMAND_PRIORITY_EDITOR, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, $getRoot, isHTMLTableRowElement, IS_BOLD, IS_ITALIC, IS_UNDERLINE, IS_STRIKETHROUGH, defineExtension, $fullReconcile, configExtension, safeCast } from 'lexical';
|
|
10
10
|
import { signal, effect, namedSignals } from '@lexical/extension';
|
|
11
11
|
import { defineImportRule, sel, ImportTextFormat, ImportTextStyle, contextValue, $propagateTextAlignToBlockChildren, CoreImportExtension, DOMImportExtension } from '@lexical/html';
|
|
12
12
|
import { $descendantsMatching, objectKlassEquals, $insertFirst as $insertFirst$1, $insertNodeToNearestRoot, $dfs, $unwrapAndFilterDescendants } from '@lexical/utils';
|
|
@@ -3013,6 +3013,30 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler, tableObse
|
|
|
3013
3013
|
editor.dispatchCommand(PASTE_COMMAND, event);
|
|
3014
3014
|
}
|
|
3015
3015
|
}));
|
|
3016
|
+
|
|
3017
|
+
// In read-only mode (contentEditable=false), Firefox fires the native copy
|
|
3018
|
+
// event on the document rather than on the root element, so the core
|
|
3019
|
+
// PASS_THROUGH copy listener never sees it. We intercept at the document
|
|
3020
|
+
// level and forward to COPY_COMMAND. Unlike the paste listener above, we
|
|
3021
|
+
// skip events whose target is inside the rootElement — those are already
|
|
3022
|
+
// handled by the core copy listener which runs regardless of isEditable.
|
|
3023
|
+
tableObserver.listenersToRemove.add(registerEventListener(doc, 'copy', event => {
|
|
3024
|
+
if (event.defaultPrevented) {
|
|
3025
|
+
return;
|
|
3026
|
+
}
|
|
3027
|
+
const target = getComposedEventTarget(event);
|
|
3028
|
+
if (target === rootElement || isDOMNode(target) && rootElement.contains(target)) {
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
const shouldIntercept = editor.read('latest', () => {
|
|
3032
|
+
const selection = $getSelection();
|
|
3033
|
+
return rootElement.contains(getActiveElement(rootElement)) && $isTableSelection(selection) && $isSelectionInTable(selection, tableNode);
|
|
3034
|
+
});
|
|
3035
|
+
if (shouldIntercept) {
|
|
3036
|
+
event.preventDefault();
|
|
3037
|
+
editor.dispatchCommand(COPY_COMMAND, event);
|
|
3038
|
+
}
|
|
3039
|
+
}));
|
|
3016
3040
|
tableObserver.listenersToRemove.add(editor.registerCommand(FORMAT_TEXT_COMMAND, payload => {
|
|
3017
3041
|
const selection = $getSelection();
|
|
3018
3042
|
if (!$isSelectionInTable(selection, tableNode)) {
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html"),o=require("@lexical/utils"),r=require("@lexical/clipboard");const l=/^(\d+(?:\.\d+)?)px$/,s={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class i extends e.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new i(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:c,priority:0}),th:e=>({conversion:c,priority:0})}}static importJSON(e){return u().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=s.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=e.$getDocument().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),a(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(t){const n=super.exportDOM(t);if(e.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...a(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=s.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==s.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function a(e){return"middle"===e||"bottom"===e}function c(t){const n=t,o=t.nodeName.toLowerCase();let r;l.test(n.style.width)&&(r=parseFloat(n.style.width));let i=s.NO_STATUS;if("th"===o){const t=n.getAttribute("scope");if("col"===t)i=s.COLUMN;else if("row"===t)i=s.ROW;else{const t=n.parentElement,o=e.isHTMLElement(t)&&"tr"===t.nodeName.toLowerCase()&&e.isHTMLElement(t.parentElement)&&("thead"===t.parentElement.nodeName.toLowerCase()||0===t.rowIndex),r=0===n.cellIndex;o&&(i|=s.ROW),r&&(i|=s.COLUMN),i===s.NO_STATUS&&(i=s.ROW)}}const c=u(i,n.colSpan,r);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;a(h)&&(c.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,p=f.includes("line-through"),C="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:t=>{const n=[];let o=null;const r=()=>{if(o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)if(e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)){if(e.$isTextNode(l)&&(m&&l.toggleFormat("bold"),p&&l.toggleFormat("strikethrough"),C&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(e.$createParagraphNode()),n},node:c}}function u(t=s.NO_STATUS,n=1,o){return e.$applyNodeReplacement(new i(t,n,o))}function d(e){return e instanceof i}const h=/* @__PURE__ */e.createCommand("INSERT_TABLE_COMMAND");function g(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class f extends e.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new f(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:m,priority:0})}}static importJSON(e){return p().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=e.$getDocument().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 m(e){const t=e;let n;return l.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>o.$descendantsMatching(e,d),node:p(n)}}function p(t){return e.$applyNodeReplacement(new f(t))}function C(e){return e instanceof f}function _(t,n,o=!0){const r=qe();for(let l=0;l<t;l++){const t=p();for(let r=0;r<n;r++){let n=s.NO_STATUS;"object"==typeof o?(0===l&&o.rows&&(n|=s.ROW),0===r&&o.columns&&(n|=s.COLUMN)):o&&(0===l&&(n|=s.ROW),0===r&&(n|=s.COLUMN));const i=u(n),a=e.$createParagraphNode();a.append(e.$createTextNode()),i.append(a),t.append(i)}r.append(t)}return r}function S(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function N(t){const n=e.$findMatchingParent(t,e=>Ge(e));if(Ge(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(e,t){const n=N(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)}}const w=(e,t)=>e===s.BOTH||e===t?t:s.NO_STATUS;function T(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||q(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=H(i,s,l),{startRow:u}=c,{startRow:d}=a;return t?y(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):y(d<u?s:l,!1)}const $=T;function y(t,n=!0){const[,,o]=L(t),[r,l]=H(o,t,t),i=r[0].length,{startRow:a}=l;let c=null;if(n){const n=a+t.__rowSpan-1,l=r[n],d=p();for(let t=0;t<i;t++){const{cell:o,startRow:r}=l[t];if(r+o.__rowSpan-1<=n){const n=l[t].cell.__headerState,o=w(n,s.COLUMN);d.append(u(o).append(e.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const h=o.getChildAtIndex(n);C(h)||g(256),h.insertAfter(d),c=d}else{const t=a,n=r[t],l=p();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===t){const t=n[o].cell.__headerState,r=w(t,s.COLUMN);l.append(u(r).append(e.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(t);C(d)||g(257),d.insertBefore(l),c=l}return c}function R(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||q(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=H(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return t?M(u+l.__colSpan>d+s.__colSpan?l:s,!0):M(d<u?s:l,!1)}const x=R;function M(t,n=!0,o=!0){const[,,r]=L(t),[l,i]=H(r,t,t),a=l.length,{startColumn:c}=i,d=n?c+t.__colSpan-1:c-1,h=r.getFirstChild();C(h)||g(120);let f=null;function m(t=s.NO_STATUS){const n=u(t).append(e.$createParagraphNode());return null===f&&(f=n),n}let p=h;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||g(121),p=e}const t=l[e],n=t[d<0?0:d].cell.__headerState,o=w(n,s.ROW);if(d<0){P(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&F(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function O(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const[n,o]=t.isBackward()?[t.focus.getNode(),t.anchor.getNode()]:[t.anchor.getNode(),t.focus.getNode()],[r,,l]=L(n),[s]=L(o),[i,a,c]=H(l,r,s),{startRow:u}=a,{startRow:d}=c,h=d+s.__rowSpan-1;if(i.length===h-u+1)return void l.remove();const f=i[0].length,m=i[h+1],p=l.getChildAtIndex(h+1);for(let e=h;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>h){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>h&&e===h){C(p)||g(387);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?P(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||g(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];F(e)}else{const e=i[u-1],{cell:t}=e[0];F(t)}}const E=O;function A(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r,,l]=L(n),[s]=L(o),[i,a,c]=H(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:h}=c,f=Math.min(u,h),m=Math.max(u+r.__colSpan-1,h+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 _=i[d],S=u>h?_[u+r.__colSpan]:_[h+s.__colSpan];if(void 0!==S){const{cell:e}=S;F(e)}else{const e=h<u?_[h-1]:_[u-1],{cell:t}=e;F(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}}const v=A;function F(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function P(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function D(t){if(0===t.length)return null;const n=N(t[0]),[o]=k(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const e of o)for(const n of e){if(!n||!n.cell)continue;const e=n.cell.getKey();if(!a.has(e)&&t.some(e=>e.is(n.cell))){a.add(e);const t=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,t),l=Math.max(l,t+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);K(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(e.$createParagraphNode()),h}function K(t){if(1!==t.getChildrenSize())return!1;const n=t.getFirstChildOrThrow();return!(!e.$isParagraphNode(n)||!n.isEmpty())}function I(t){const[n,o,r]=L(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[a,c]=H(r,n,n),{startColumn:d,startRow:h}=c,f=n.__headerState&s.COLUMN,m=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&s.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+h][e].cell.__headerState;return n});if(l>1){for(let t=1;t<l;t++)n.insertAfter(u(m[t]|_[0]).append(e.$createParagraphNode()));n.setColSpan(1)}if(i>1){let t;for(let n=1;n<i;n++){const r=h+n,s=a[r];t=(t||o).getNextSibling(),C(t)||g(125);let i=null;for(let e=0;e<d;e++){const t=s[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=l-1;o>=0;o--)P(t,u(m[o]|_[n]).append(e.$createParagraphNode()));else for(let t=l-1;t>=0;t--)i.insertAfter(u(m[t]|_[n]).append(e.$createParagraphNode()))}n.setRowSpan(1)}}function H(e,t,n){const[o,r,l]=k(e,t,n);return null===r&&g(207),null===l&&g(208),[o,r,l]}function k(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||g(209);const a=s(e);for(let c=o.getFirstChild(),u=0;null!=c;c=c.getNextSibling()){for(d(c)||g(147);void 0!==a[u];)u++;const o={cell:c,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:f}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[u+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function L(t){let n;if(t instanceof i)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,d);d(o)||g(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),d);d(o)||g(148),n=o}const o=n.getParent();C(o)||g(149);const r=o.getParent();return Ge(r)||g(210),[n,o,r]}function W(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function B(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!d(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function z(e){const[t,,n]=L(e),o=n.getChildren().filter(C),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().filter(d);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 Y(t,n){const o=n.getStartEndPoints(),r=q(n);if(null===o)return!1;const[l,s]=o,[i,a,c]=L(l),u=e.$findMatchingParent(s.getNode(),e=>d(e));if(!(d(i)&&d(u)&&C(a)&&Ge(c)))return!1;const[h,g,f]=H(c,i,u),[m]=k(t,null,null),p=h.length,_=p>0?h[0].length:0;let S=g.startRow,N=g.startColumn,b=m.length,w=b>0?m[0].length:0;if(r){const e=W(h,g,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,N=e.minColumn,b=Math.min(b,t),w=Math.min(w,n)}let T=!1;const $=Math.min(p,S+b)-1,R=Math.min(_,N+w)-1,x=new Set;for(let e=S;e<=$;e++)for(let t=N;t<=R;t++){const n=h[e][t];x.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(I(n.cell),x.add(n.cell.getKey()),T=!0))}let[O]=k(c.getWritable(),null,null);const E=b-p+S;for(let e=0;e<E;e++){y(O[p-1][0].cell)}const A=w-_+N;for(let e=0;e<A;e++){M(O[0][_-1].cell,!0,!1)}[O]=k(c.getWritable(),null,null);for(let t=S;t<S+b;t++)for(let n=N;n<N+w;n++){const o=t-S,r=n-N,l=m[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const e=[],o=Math.min(t+s.__rowSpan,S+b)-1,r=Math.min(n+s.__colSpan,N+w)-1;for(let l=t;l<=o;l++)for(let t=n;t<=r;t++){const n=O[l][t];e.push(n.cell)}D(e),T=!0}const{cell:i}=O[t][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(t=>{if(e.$isTextNode(t)){e.$createParagraphNode().append(t),i.append(t)}else i.append(t)}),c.forEach(e=>e.remove())}if(r&&T){const[e]=k(c.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function U(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,d);d(r)||g(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||g(239,n);const s=l.getParent();return Ge(s)||g(240,n),[o,r,l,s]});return l.is(c)||g(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class X{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const t=e.$getNodeByKey(this.tableKey),n=e.$getNodeByKey(this.anchor.key),o=e.$getNodeByKey(this.focus.key);return null!==t&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return q(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new X(this.tableKey,e.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),e.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(t){if(""===t)return;const n=(t.endsWith("\n")?t.slice(0,-1):t).split("\n").map(e=>e.split("\t")),o=qe();for(const t of n){const n=p();for(const o of t){const t=u(s.NO_STATUS),r=e.$createParagraphNode();o&&r.append(e.$createTextNode(o)),t.append(r),n.append(t)}o.append(n)}const{anchorCell:r}=U(this);Y(o,r.select(0,r.getChildrenSize()))}insertText(){}hasFormat(t){let n=0;this.getNodes().filter(d).forEach(t=>{const o=t.getFirstChild();e.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=e.TEXT_TYPE_TO_FORMAT[t];return 0!==(n&o)}insertNodes(t){const n=this.focus.getNode();e.$isElementNode(n)||g(151);e.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(t)}getShape(){const{anchorCell:e,focusCell:t}=U(this),n=z(e);null===n&&g(153);const o=z(t);null===o&&g(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 t=this._cachedNodes;if(null!==t)return t;const{anchorTable:n,anchorCell:o,focusCell:r}=U(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&g(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&g(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=H(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:h}=W(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=h;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||g(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||j(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return e.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>d(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function q(e){return e instanceof X}function G(){const t=e.$createPoint("root",0,"element"),n=e.$createPoint("root",0,"element");return new X("root",t,n)}function J(t,n,o){t.getKey(),n.getKey(),o.getKey();const r=e.$getSelection(),l=q(r)?r.clone():G();return l.set(t.getKey(),n.getKey(),o.getKey()),l}function j(t,n){const o=[[t]];for(let t=o.at(-1);void 0!==t&&o.length>0;t=o.at(-1)){const r=t.pop();void 0===r?o.pop():!1!==n(r)&&e.$isElementNode(r)&&o.push(r.getChildren())}}function V(t,n=e.$getEditor()){const o=e.$getNodeByKey(t);Ge(o)||g(231,t);const r=le(o,n.getElementByKey(t));return null===r&&g(232,t),{tableElement:r,tableNode:o}}class Q{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return void 0!==t&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const t=[];for(const[n,[o]]of Array.from(this.observers.entries())){const r=e.$getNodeByKey(n);Ge(r)?t.push([r,o]):this.removeObserver(n)}return t}}class Z{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return V(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.read("latest",()=>{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=_e(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=_e(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(t=!0){const n=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:o,tableElement:r}=this.$lookup();Se(n,_e(o,r),null),t&&null!==e.$getSelection()&&(e.$setSelection(null),n.dispatchCommand(e.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&&g(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Se(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const t=e.getDOMSelection(this.editor._window);t&&t.rangeCount>0&&t.removeAllRanges()}}$setFocusCellForSelection(t,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=t.x,s=t.y;if(this.focusCell=t,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=He(r,t.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let t=i;if(null===t&&n&&(t=r.getCellNodeFromCords(l,s,this.table)),null!==t){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=t.getKey(),this.tableSelection=J(r,n,t),e.$setSelection(this.tableSelection),o.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0),Se(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const t=this.anchorCellNodeKey?e.$getNodeByKey(this.anchorCellNodeKey):null;return d(t)?t:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&g(234),e}$getFocusTableCell(){const t=this.focusCellNodeKey?e.$getNodeByKey(this.focusCellNodeKey):null;return d(t)?t:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&g(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=He(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=J(t,n,n),this.anchorCellNodeKey=e}}$formatCells(t){const n=e.$getSelection();q(n)||g(236);const o=e.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(d);s.length>0||g(237);const i=s[0].getFirstChild(),a=e.$isParagraphNode(i)?i.getFormatFlags(t,null):null;s.forEach(e=>{r.set(e.getKey(),0,"element"),l.set(e.getKey(),e.getChildrenSize(),"element"),o.formatText(t,a)}),e.$setSelection(n),this.editor.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:t}=this,n=e.$getNodeByKey(this.tableNodeKey);if(!Ge(n))throw new Error("Expected TableNode.");const o=e.$getSelection();q(o)||g(253);const r=o.getNodes().filter(d),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(e.$isRootNode(o)&&o.isEmpty()&&t.dispatchCommand(e.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(t=>{if(e.$isElementNode(t)){const n=e.$createParagraphNode(),o=e.$createTextNode();n.append(o),t.append(n),t.getChildren().forEach(e=>{e!==n&&e.remove()})}}),Se(t,this.table,null),e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}}const ee="__lexicalTableSelection";function te(t){const n=e.$getNodeByKeyOrThrow(t);return Ge(n)||g(386,t),n}const ne=40;function oe(e,t,n){const o=e=>Math.max(1,Math.ceil(Math.min(ne,e)/ne*18));return e<=t+ne?-o(t+ne-e):e>=n-ne?o(e-(n-ne)):0}function re(t){return e.isHTMLElement(t)&&"TABLE"===t.nodeName}function le(e,t){if(!t)return t;const n=re(t)?t:t.querySelector("table");return re(n)||g(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function se(e){return e._window}function ie(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;d(n)&&(o=n)}return null}const ae=[[e.KEY_ARROW_DOWN_COMMAND,"down"],[e.KEY_ARROW_UP_COMMAND,"up"],[e.KEY_ARROW_LEFT_COMMAND,"backward"],[e.KEY_ARROW_RIGHT_COMMAND,"forward"]],ce=[e.DELETE_WORD_COMMAND,e.DELETE_LINE_COMMAND,e.DELETE_CHARACTER_COMMAND],ue=[e.KEY_BACKSPACE_COMMAND,e.KEY_DELETE_COMMAND];function de(t,n){return t.registerRootListener(o=>{if(null===o)return;const r=t._window;if(null===r)return;return e.registerEventListener(r,"pointerdown",r=>{const l=e.getComposedEventTarget(r);if(0!==r.button||!e.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=pe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&ee in n&&n[ee])return{cellElement:t,tableElement:n,tableObserver:n[ee]};n=n.parentNode}return null}(l);t.update(()=>{if(q(e.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(t,n,o,r,l,s){const i=t._window;if(!i)return;const a=o=>{if(l.isSelecting)return;l.isSelecting=!0,null!==o&&null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(o)});let a=n.clientX,c=n.clientY,u=null;const d=()=>{l.isSelecting=!1,null!==u&&(i.cancelAnimationFrame(u),u=null),i.removeEventListener("pointerup",N),i.removeEventListener("pointermove",b)},h=(t,n)=>{const o=r.getRootNode();if(!e.isDOMDocumentNode(o)&&!e.isDOMShadowRoot(o))return null;for(const e of o.elementsFromPoint(t,n)){const t=Ce(r,e);if(t)return t}return null},g=(n,o)=>{null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&n.elem===l.focusCell.elem||(s.setNextFocus({focusCell:n,override:o,tableKey:l.tableNodeKey}),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0))},f=e=>{for(let t=r.parentElement;t;t=t.parentElement){if("x"===e?t.scrollWidth>t.clientWidth:t.scrollHeight>t.clientHeight){const n=i.getComputedStyle(t),o="x"===e?n.overflowX:n.overflowY;if("auto"===o||"scroll"===o)return t}}return null},m=(e,t,n)=>{let o,r;if(null===e)o=0,r="x"===n?i.innerWidth:i.innerHeight;else{const t=e.getBoundingClientRect();o="x"===n?t.left:t.top,r="x"===n?t.right:t.bottom}const l=oe(t,o,r);if(0===l)return!1;if(null===e){const e="x"===n?i.scrollX:i.scrollY;return i.scrollBy("x"===n?l:0,"x"===n?0:l),("x"===n?i.scrollX:i.scrollY)!==e}if("x"===n){const t=e.scrollLeft;return e.scrollLeft+=l,e.scrollLeft!==t}const s=e.scrollTop;return e.scrollTop+=l,e.scrollTop!==s},p=(e,t)=>{let n=a,o=c;if(null===e)n=Math.min(Math.max(n,1),i.innerWidth-1);else{const t=e.getBoundingClientRect();n=Math.min(Math.max(n,t.left+1),t.right-1)}if(null===t)o=Math.min(Math.max(o,1),i.innerHeight-1);else{const e=t.getBoundingClientRect();o=Math.min(Math.max(o,e.top+1),e.bottom-1)}return[n,o]},C=()=>{const e=f("x");if(null!==e){const t=e.getBoundingClientRect();if(0!==oe(a,t.left,t.right))return!0}const t=f("y"),n=null===t?0:t.getBoundingClientRect().top,o=null===t?i.innerHeight:t.getBoundingClientRect().bottom;return 0!==oe(c,n,o)},_=()=>{if(u=null,!l.isSelecting)return;const e=f("x"),t=f("y"),n=null!==e&&m(e,a,"x"),o=m(t,c,"y");if(n||o){const[n,o]=p(e,t),r=h(n,o);r&&g(r,!1),u=i.requestAnimationFrame(_)}},S=()=>{null===u&&"touch"!==l.pointerType&&C()&&(u=i.requestAnimationFrame(_))},N=()=>{d()},b=t=>{if(!(e=>!(1&~e.buttons))(t)&&l.isSelecting)return void d();const n=e.getComposedEventTarget(t);if(!e.isDOMNode(n))return;a=t.clientX,c=t.clientY;let o=null;const s=!(e.IS_FIREFOX||r.contains(n));o=s?Ce(r,n):h(t.clientX,t.clientY),o&&g(o,s),S()};i.addEventListener("pointerup",N,l.listenerOptions),i.addEventListener("pointermove",b,l.listenerOptions)};l.pointerType=n.pointerType;const c=te(l.tableNodeKey),u=e.$getPreviousSelection();if(e.IS_FIREFOX&&n.shiftKey&&Re(u,c)&&(e.$isRangeSelection(u)||q(u))){const e=u.anchor.getNode(),t=ie(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Ie(l,t)),l.$setFocusCellForSelection(o),Pe(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(t,r,i,l,o,n)})})})}function he(t,n,l,s,i){const a=l.getRootElement(),c=se(l);null!==a&&null!==c||g(246);const u=new Z(l,t.getKey()),h=le(t,n);!function(e,t){null!==me(e)&&g(205);e[ee]=t}(h,u),u.listenersToRemove.add(()=>function(e,t){me(e)===t&&delete e[ee]}(h,u));u.listenersToRemove.add(e.registerEventListener(h,"mousedown",t=>{const n=e.getComposedEventTarget(t);if(t.detail>=3&&e.isDOMNode(n)){null!==pe(n)&&t.preventDefault()}},u.listenerOptions));for(const[n,o]of ae)u.listenersToRemove.add(l.registerCommand(n,e=>Fe(l,e,o,t,u,i),e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.KEY_ESCAPE_COMMAND,n=>{const o=e.$getSelection();if(q(o)){const e=ie(t,o.focus.getNode());if(null!==e)return Pe(n),e.selectEnd(),!0}return!1},e.COMMAND_PRIORITY_HIGH));const f=n=>()=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$clearText(),!0;if(e.$isRangeSelection(o)){if(!d(ie(t,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=t.isParentOf(r),i=t.isParentOf(l);if(s&&!i||i&&!s)return u.$clearText(),!0;const a=e.$findMatchingParent(o.anchor.getNode(),t=>e.$isElementNode(t)),c=a&&e.$findMatchingParent(a,t=>e.$isElementNode(t)&&d(t.getParent()));if(!e.$isElementNode(c)||!e.$isElementNode(a))return!1;if(n===e.DELETE_LINE_COMMAND&&null===c.getPreviousSibling())return!0}return!1};for(const t of ce)u.listenersToRemove.add(l.registerCommand(t,f(t),e.COMMAND_PRIORITY_HIGH));const m=n=>{const o=e.$getSelection();if(!q(o)&&!e.$isRangeSelection(o))return!1;const r=t.isParentOf(o.anchor.getNode());if(r!==t.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",n=r?"focus":"anchor",{key:l,offset:s,type:i}=o[n];return t[o[e].isBefore(o[n])?"selectPrevious":"selectNext"]()[n].set(l,s,i),!1}return!!Re(o,t)&&(!!q(o)&&(n&&(n.preventDefault(),n.stopPropagation()),u.$clearText(),!0))};for(const t of ue)u.listenersToRemove.add(l.registerCommand(t,m,e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.CUT_COMMAND,t=>{const n=e.$getSelection();if(n){if(!q(n)&&!e.$isRangeSelection(n))return!1;r.copyToClipboard(l,o.objectKlassEquals(t,ClipboardEvent)?t:null,r.$getClipboardDataFromSelection(n));const s=m(t);return e.$isRangeSelection(n)?(n.removeText(),!0):s}return!1},e.COMMAND_PRIORITY_HIGH));const p=a.ownerDocument;return u.listenersToRemove.add(e.registerEventListener(p,"paste",n=>{if(n.defaultPrevented)return;l.read("latest",()=>{const n=e.$getSelection();return a.contains(p.activeElement)&&q(n)&&Re(n,t)})&&(n.preventDefault(),l.dispatchCommand(e.PASTE_COMMAND,n))})),u.listenersToRemove.add(l.registerCommand(e.FORMAT_TEXT_COMMAND,n=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$formatCells(n),!0;if(e.$isRangeSelection(o)){const t=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(t))return!1}return!1},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FORMAT_ELEMENT_COMMAND,n=>{const o=e.$getSelection();if(!q(o)||!Re(o,t))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!d(r)||!d(l))return!1;if(function(e,t){if(q(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=H(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,t))return t.setFormat(n),!0;const[s,i,a]=H(t,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),u=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let t=h;t<=c;t++)for(let o=g;o<=u;o++){const r=s[t][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(n);const l=r.getChildren();for(let t=0;t<l.length;t++){const o=l[t];e.$isElementNode(o)&&!o.isInline()&&o.setFormat(n)}}return!0},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.CONTROLLED_TEXT_INSERTION_COMMAND,n=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$clearHighlight(),!1;if(e.$isRangeSelection(o)){const r=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(r))return!1;if("string"==typeof n){const r=Ke(l,o,t);if(r)return De(r,t,[e.$createTextNode(n)]),!0}}return!1},e.COMMAND_PRIORITY_HIGH)),s&&u.listenersToRemove.add(l.registerCommand(e.KEY_TAB_COMMAND,n=>{const o=e.$getSelection();if(!e.$isRangeSelection(o)||!o.isCollapsed()||!Re(o,t))return!1;const r=Ee(o.anchor.getNode());return!(null===r||!t.is(Ae(r)))&&(Pe(n),function(t,n){const o="next"===n?"getNextSibling":"getPreviousSibling",r="next"===n?"getFirstChild":"getLastChild",l=t[o]();if(e.$isElementNode(l))return l.selectEnd();const s=e.$findMatchingParent(t,C);null===s&&g(247);for(let t=s[o]();C(t);t=t[o]()){const n=t[r]();if(e.$isElementNode(n))return n.selectEnd()}const i=e.$findMatchingParent(s,Ge);null===i&&g(248);"next"===n?i.selectNext():i.selectPrevious()}(r,n.shiftKey?"previous":"next"),!0)},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FOCUS_COMMAND,e=>t.isSelected(),e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>{const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed()||!Re(n,t))return!1;const o=Ke(l,n,t);return!!o&&(De(o,t),!0)},e.COMMAND_PRIORITY_HIGH)),u}function ge(t,n){const o=e.$getSelection(),r=e.$getPreviousSelection(),l=t.getAndClearNextFocus();if(null!==l){const{tableKey:e,focusCell:n}=l,r=t.observers.get(e);r||g(335,e);const[s]=r;if(q(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=t.getAndClearShouldCheckSelectionForTable();if(s&&e.$isRangeSelection(r)&&e.$isRangeSelection(o)&&o.isCollapsed()){const t=e.$getNodeByKey(s);if(Ge(t)){const n=o.anchor.getNode(),r=t.getFirstChild(),l=Ee(n);if(null!==l&&C(r)){const n=r.getFirstChild();if(d(n)&&t.is(e.$findMatchingParent(l,e=>e.is(t)||e.is(n))))return n.selectStart(),!0}}}q(o)&&function(t,n){const o=se(t),r=e.$getPreviousSelection();if(!n.is(r))return;const l=te(n.tableKey),s=e.getDOMSelection(o),i=s&&e.getDOMSelectionPoints(s,t.getRootElement());if(s&&i&&i.anchorNode&&i.focusNode){const o=e.$getNearestNodeFromDOMNode(i.focusNode),r=o&&!l.isParentOf(o),a=e.$getNearestNodeFromDOMNode(i.anchorNode),c=a&&l.isParentOf(a);if(r&&c&&s.rangeCount>0){const o=e.$createRangeSelectionFromDom(s,t);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),e.$setSelection(o))}}}(n,o),e.$isRangeSelection(o)&&function(t,n){const o=e.$getPreviousSelection(),{anchor:r,focus:l}=t,s=r.getNode(),i=l.getNode(),a=Ee(s),c=Ee(i),u=a?Ae(a):null,d=c?Ae(c):null,h=t.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),p=u&&(!d||d.isParentOf(u));if(m){const n=t.clone(),[o]=H(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(h?r.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),e.$setSelection(n)}else if(p){const n=t.clone(),[o]=H(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(h?l.getKey():r.getKey(),h?l.getChildrenSize():0,"element"),e.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||g(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Ie(l,a)),l.$setFocusCellForSelection(Ie(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&t.isCollapsed()&&e.$isRangeSelection(o)&&o.isCollapsed()){const e=Ee(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Ie(l,e)),l.$setFocusCellForSelection(Ie(l,c),!0),l.pointerType=null)}}}(o,t);for(const[e,o]of t.$getTableNodesAndObservers())fe(n,e,o);return!1}function fe(t,n,o){const r=e.$getSelection(),l=e.$getPreviousSelection();r&&!r.is(l)&&(q(r)||q(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(q(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!q(r)&&q(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),Ne(t.table,t=>{const n=t.elem;t.highlighted=!1,Oe(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(t,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),Ne(t.table,t=>{t.highlighted=!0,Me(e,t)})}(t,o)}function me(e){return e[ee]||null}function pe(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 Ce(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function _e(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=le(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 Se(e,t,n){const o=new Set(n?n.getNodes():[]);Ne(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Me(e,t)):(t.highlighted=!1,Oe(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Ne(t,n){const{domRows:o}=t;for(let t=0;t<o.length;t++){const r=o[t];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=e.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:t})}}}const be=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?xe(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?xe(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?xe(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?xe(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function we(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 $e(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&g(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&g(250,n,String(s)),i}function ye(e,t,n,o,r){const l=W(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=we(e,t);return null===n&&g(249,t.cell.getKey()),n}(l,n),[h,f]=Te(d);let m=l[h],p=l[f];"forward"===r?m+="maxColumn"===h?1:a:"backward"===r?m-="minColumn"===h?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 _=C[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=W(e,t,n),r=we(o,t);if(r)return[$e(e,o,r),$e(e,o,Te(r))];const l=we(o,n);if(l)return[$e(e,o,Te(l)),$e(e,o,l)];const s=["minColumn","minRow"];return[$e(e,o,s),$e(e,o,Te(s))]}(t,n,_),b=Ie(e,S.cell),w=Ie(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function Re(t,n){if(e.$isRangeSelection(t)||q(t)){const e=n.isParentOf(t.anchor.getNode()),o=n.isParentOf(t.focus.getNode());return e&&o}return!1}function xe(e,t){t?e.selectStart():e.selectEnd()}function Me(t,n){const o=n.elem,r=t._config.theme;d(e.$getNearestNodeFromDOMNode(o))||g(131),e.addClassNamesToElement(o,r.tableCellSelected)}function Oe(t,n){const o=n.elem;d(e.$getNearestNodeFromDOMNode(o))||g(131);const r=t._config.theme;e.removeClassNamesFromElement(o,r.tableCellSelected)}function Ee(t){const n=e.$findMatchingParent(t,d);return d(n)?n:null}function Ae(t){const n=e.$findMatchingParent(t,Ge);return Ge(n)?n:null}function ve(t,n,o,r,l,s,i){const a=e.$caretFromPoint(o.focus,l?"previous":"next");if(e.$isExtendableTextPointCaret(a))return!1;let c=a;for(const t of e.$extendCaretToRange(a).iterNodeCarets("shadowRoot")){if(!e.$isSiblingCaret(t)||!e.$isElementNode(t.origin))return!1;c=t}const u=c.getParentAtCaret();if(!d(u))return!1;const h=u,g=function(t){for(const n of e.$extendCaretToRange(t).iterNodeCarets("root")){const{origin:o}=n;if(d(o)){if(e.$isChildCaret(n))return e.$getChildCaret(o,t.direction)}else if(!C(o))break}return null}(e.$getSiblingCaret(h,c.direction)),f=e.$findMatchingParent(h,Ge);if(!f||!f.is(s))return!1;const m=t.getElementByKey(h.getKey()),p=pe(m);if(!m||!p)return!1;const _=Ue(t,f);if(i.table=_,g)if("extend"===r){const e=pe(t.getElementByKey(g.origin.getKey()));if(!e)return!1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(e,!0)}else{const t=e.$normalizeCaret(g);e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else{const t=function(t){const n=e.$getAdjacentChildCaret(t);return e.$isChildCaret(n)?e.$normalizeCaret(n):t}(e.$getSiblingCaret(f,a.direction));e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}return Pe(n),!0}function Fe(t,n,o,r,l,s){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(t))return!1;const i=e.$getSelection();if(!Re(i,r)){if(e.$isRangeSelection(i)){if("backward"===o){if(i.focus.offset>0)return!1;const t=function(t){for(let n=t,o=t;null!==o;n=o,o=o.getParent())if(e.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!t)return!1;const o=t.getPreviousSibling();return!!Ge(o)&&(Pe(n),n.shiftKey?i.focus.set(o.getParentOrThrow().getKey(),o.getIndexWithinParent(),"element"):o.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const t=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=e.$findMatchingParent(t,e=>Ge(e));if(d(l)&&(l=e.$findMatchingParent(l,Ge)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let a=0;"up"===o&&e.$isElementNode(s)&&(a=s.getChildrenSize());let c=s;if("up"===o&&e.$isElementNode(s)){const t=s.getLastChild();c=t||s,a=e.$isTextNode(c)?c.getTextContentSize():0}const u=i.clone();return u.focus.set(c.getKey(),a,e.$isTextNode(c)?"text":"element"),e.$setSelection(u),Pe(n),!0}if(e.$isRootOrShadowRoot(t)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==ie(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=L(e),[o]=L(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),a=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),c=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(a),l.$setFocusCellForSelection(c,!0),!0}}return!1}{let r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());if(d(r)&&(r=e.$findMatchingParent(r,Ge)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Ge(s)&&l.tableNodeKey===s.getKey()){const t=s.getFirstDescendant(),r=s.getLastDescendant();if(!t||!r)return!1;const[l]=L(t),[a]=L(r),c=i.clone();return c.focus.set(("up"===o?l:a).getKey(),"up"===o?0:a.getChildrenSize(),"element"),Pe(n),e.$setSelection(c),!0}}}}return"down"===o&&Be(t)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(e.$isRangeSelection(i)){if("backward"===o||"forward"===o){return ve(t,n,i,n.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:a,focus:c}=i,u=e.$findMatchingParent(a.getNode(),d),h=e.$findMatchingParent(c.getNode(),d);if(!d(u)||!u.is(h))return!1;const g=Ae(u);if(g!==r&&null!=g){const e=le(g,t.getElementByKey(g.getKey()));if(null!=e)return l.table=_e(g,e),Fe(t,n,o,g,l,s)}const f=t.getElementByKey(u.__key),m=t.getElementByKey(a.key);if(null==m||null==f)return!1;let p;if("element"===a.type)p=m.getBoundingClientRect();else{const n=e.getDOMSelection(se(t));if(null===n||0===n.rangeCount)return!1;const o=e.getDOMSelectionRange(n,t.getRootElement());if(null===o)return!1;p=o.getBoundingClientRect()}const C="up"===o?u.getFirstChild():u.getLastChild();if(null==C)return!1;const _=t.getElementByKey(C.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===o?S.top>p.top-p.height:p.bottom+p.height>S.bottom){Pe(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return be(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(q(i)){const{anchor:s,focus:a,tableKey:c}=i;if(c!==r.getKey())return!1;const u=e.$findMatchingParent(s.getNode(),d),h=e.$findMatchingParent(a.getNode(),d),[f]=i.getNodes();Ge(f)||g(251);const m=le(f,t.getElementByKey(f.getKey()));if(!d(u)||!d(h)||!Ge(f)||null==m)return!1;l.$updateTableTableSelection(i);const p=_e(f,m),C=r.getCordsFromCellNode(u,p),_=r.getDOMCellFromCordsOrThrow(C.x,C.y,p);if(l.$setAnchorCellForSelection(_),Pe(n),n.shiftKey){const[e,t,n]=H(r,u,h);return ye(l,e,t,n,o)}return h.selectEnd(),!0}return!1}function Pe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function De(t,n,o){const r=e.$createParagraphNode();"first"===t?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Ke(t,n,o){const r=o.getParent();if(!r)return;const l=e.getDOMSelection(se(t));if(!l)return;const s=e.getDOMSelectionPoints(l,t.getRootElement()).anchorNode,i=t.getElementByKey(r.getKey()),a=le(o,t.getElementByKey(o.getKey()));if(!s||!i||!a||!i.contains(s)||a.contains(s))return;const c=e.$findMatchingParent(n.anchor.getNode(),e=>d(e));if(!c)return;const u=e.$findMatchingParent(c,e=>Ge(e));if(!Ge(u)||!u.is(o))return;const[h,g]=H(o,c,c),f=h[0][0],m=h[h.length-1][h[0].length-1],{startRow:p,startColumn:C}=g,_=p===f.startRow&&C===f.startColumn,S=p===m.startRow&&C===m.startColumn;return _?"first":S?"last":void 0}function Ie(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function He(t,n,o){return ie(t,e.$getNearestNodeFromDOMNode(n,o))}function ke(t,n,o){const r=t.querySelector("colgroup");if(!r)return;const l=[];for(let t=0;t<n;t++){const n=e.$getDocument().createElement("col"),r=o&&o[t];r&&(n.style.width=`${r}px`),l.push(n)}r.replaceChildren(...l)}function Le(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const We=new WeakSet;function Be(t=e.$getEditor()){return We.has(t)}function ze(e,t){t?We.add(e):We.delete(e)}class Ye extends e.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Ye(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Xe,priority:1})}}static importJSON(e){return qe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=re(e)?e:e.querySelector("table");return re(t)||g(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=e.$getDocument().createElement("table");this.__style&&e.setDOMStyleFromCSS(o.style,this.__style);const r=e.$getDocument().createElement("colgroup");if(o.appendChild(r),e.setDOMUnmanaged(r),e.addClassNamesToElement(o,t.theme.table),this.updateTableElement(null,o,t),Be(n)){const n=e.$getDocument().createElement("div"),r=t.theme.tableScrollableWrapper;return r?e.addClassNamesToElement(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(t,n,o){this.__style!==(t?t.__style:"")&&e.setDOMStyleFromCSS(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,o,this.__rowStriping);const r=t?t.getColumnCount():0,l=t?t.__colWidths:void 0;this.getColumnCount()===r&&this.getColWidths()===l||ke(n,this.getColumnCount(),this.getColWidths()),Le(n,o,this.getFormatType())}updateDOM(t,n,o){const r=le(this,n);return n===r===Be()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;ke(le(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!re(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!re(o))return null;Le(o,t._config,this.getFormatType());const[r]=k(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const t=e.$getDocument().createElement("tbody");for(const e of a)t.appendChild(e);o.append(t)}return o},element:!re(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=He(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(t,n,o){const r=this.getDOMCellFromCords(t,n,o);if(null==r)return null;const l=e.$getNearestNodeFromDOMNode(r.elem);return d(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!C(e))return 0;let t=0;return e.getChildren().forEach(e=>{d(e)&&(t+=e.getColSpan())}),t}}function Ue(e,t){const n=e.getElementByKey(t.getKey());return null===n&&g(230),_e(t,n)}function Xe(e){const t=qe();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&t.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&t.setFrozenRows(1);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>o.$descendantsMatching(e,C),node:t}}function qe(){return e.$applyNodeReplacement(new Ye)}function Ge(e){return e instanceof Ye}function Je(t){C(t.getParent())?t.isEmpty()&&t.append(e.$createParagraphNode()):t.remove()}function je(e){Ge(e.getParent())?o.$unwrapAndFilterDescendants(e,d):e.remove()}function Ve(t){o.$unwrapAndFilterDescendants(t,C);const[n]=k(t,null,null),r=n.reduce((e,t)=>Math.max(e,t.length),0),l=t.getChildren();for(let t=0;t<n.length;++t){const o=l[t];if(!o)continue;C(o)||g(254,o.constructor.name,o.getType());const s=n[t].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let t=s;t<r;++t){const t=u();t.append(e.$createParagraphNode()),o.append(t)}}const s=t.getColWidths(),i=t.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}t.setColWidths(e)}}function Qe(t){if(t.detail<3||!e.isDOMNode(t.target))return!1;const n=e.$getNearestNodeFromDOMNode(t.target);if(null===n)return!1;const o=e.$findMatchingParent(n,t=>e.$isElementNode(t)&&!t.isInline());if(null===o)return!1;return!!d(o.getParent())&&(o.select(0),!0)}function Ze(){const t=e.$getSelection();if(!e.$isRangeSelection(t))return!1;const n=Ae(t.anchor.getNode());if(null===n)return!1;const o=e.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=k(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=J(n,l.cell,i.cell);return e.$setSelection(a),!0}function et(e){return e.registerNodeTransform(i,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=L(e),[n]=H(t,e,e),r=n.length,l=n[0].length;let s=t.getFirstChild();C(s)||g(175);const i=[];for(let e=0;e<r;e++){0!==e&&(s=s.getNextSibling(),C(s)||g(175));let t=null;for(let r=0;r<l;r++){const l=n[e][r],a=l.cell;if(l.startRow===e&&l.startColumn===r)t=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){d(a)||g(176);const e=u(a.__headerState);null!==t?t.insertAfter(e):o.$insertFirst(s,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function tt(t,n=!0){const o=new Q,r=(e,r,l)=>{const s=le(e,l),i=he(e,s,t,n,o);o.observers.set(r,[i,s])};return e.mergeRegister(de(t,o),t.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>ge(o,t),e.COMMAND_PRIORITY_HIGH),t.registerMutationListener(Ye,e=>{t.read("latest",()=>{for(const[t,n]of e){const e=o.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:l}=V(t);void 0===e?r(n,t,l):l!==e[1]&&(o.removeObserver(t),r(n,t,l))}else"destroyed"===n&&o.removeObserver(t)}})},{skipInitialization:!1}),()=>{o.removeAllObservers()})}function nt(n,r){n.hasNodes([Ye])||g(255);const{hasNestedTables:l=t.signal(!1)}=r??{};return e.mergeRegister(n.registerCommand(h,t=>function({rows:t,columns:n,includeHeaders:r},l){const s=e.$getSelection()||e.$getPreviousSelection();if(!s||!e.$isRangeSelection(s))return!1;if(!l&&Ae(s.anchor.getNode()))return!1;const i=_(Number(t),Number(n),r);o.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return e.$isTextNode(a)&&a.select(),!0}(t,l.peek()),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(t,r)=>n===r&&function(t,n){const{nodes:r,selection:l}=t;if(!r.some(e=>Ge(e)||o.$dfs(e).some(e=>Ge(e.node)))){if(q(l)){let t="",n=!1;for(const o of r){const r=e.$isElementNode(o)&&!o.isInline();t.length>0&&(r||n)&&(t+="\n"),t+=o.getTextContent(),n=r}return l.insertRawText(t),!0}return!1}const s=q(l),i=e.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>d(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>d(e))||s))return!1;if(1===r.length&&Ge(r[0]))return Y(r[0],l);if(i&&n.peek()&&!function(t){if(q(t)&&!t.focus.getNode().is(t.anchor.getNode()))return!0;if(e.$isRangeSelection(t)&&d(t.anchor.getNode())&&!t.anchor.getNode().is(t.focus.getNode()))return!0;return!1}(l))return!1;return!0}(t,l),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECT_ALL_COMMAND,Ze,e.COMMAND_PRIORITY_LOW),n.registerCommand(e.CLICK_COMMAND,Qe,e.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(Ye,Ve),n.registerNodeTransform(f,je),n.registerNodeTransform(i,Je))}const ot={$accepts:C,$packageRun:e=>e.every(d)?[p().splice(0,0,e)]:[],name:"TableSchema"},rt={$accepts:d,name:"TableRowSchema"},lt=[/* @__PURE__ */n.defineImportRule({$import:(e,t)=>{const n=qe();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return[n.splice(0,0,o.$descendantsMatching(e.$importChildren(t),C))]},match:n.sel.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */n.defineImportRule({$import:(e,t)=>[p(l.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,o.$descendantsMatching(e.$importChildren(t),d))],match:n.sel.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */n.defineImportRule({$import:(t,o)=>{const r="TH"===o.nodeName,i=l.test(o.style.width)?parseFloat(o.style.width):void 0;let a=s.NO_STATUS;if(r){const t=o.getAttribute("scope");if("col"===t)a=s.COLUMN;else if("row"===t)a=s.ROW;else{const t=o.parentElement,n=e.isHTMLTableRowElement(t)&&(t.parentElement&&"THEAD"===t.parentElement.nodeName||0===t.rowIndex),r=0===o.cellIndex;n&&(a|=s.ROW),r&&(a|=s.COLUMN),a===s.NO_STATUS&&(a=s.ROW)}}const c=u(a,o.colSpan,i);c.__rowSpan=o.rowSpan;const d=o.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=o.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(c.__verticalAlign=h);const g=t.get(n.ImportTextFormat),f=g|function(t){let n=0;const o=t.fontWeight;"700"!==o&&"bold"!==o||(n|=e.IS_BOLD),"italic"===t.fontStyle&&(n|=e.IS_ITALIC);const r=(t.textDecoration||"").split(" ");return r.includes("underline")&&(n|=e.IS_UNDERLINE),r.includes("line-through")&&(n|=e.IS_STRIKETHROUGH),n}(o.style),m=t.get(n.ImportTextStyle),p=o.style.color,C=p?{...m,color:p}:m,_=[];f!==g&&_.push(n.contextValue(n.ImportTextFormat,f)),C!==m&&_.push(n.contextValue(n.ImportTextStyle,C));const S=function(t){const n=[];let o=null;const r=()=>{if(null!==o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)?null!==o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o)):(r(),o=null,n.push(l));return r(),0===n.length&&n.push(e.$createParagraphNode()),n}(t.$importChildren(o,{context:_})),N=r?S:n.$propagateTextAlignToBlockChildren(S,o);return[c.splice(0,0,N)]},match:n.sel.tag("td","th"),name:"@lexical/table/cell"})],st=/* @__PURE__ */e.defineExtension({build:(e,n,o)=>t.namedSignals(n),config:/* @__PURE__ */e.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[n.CoreImportExtension,/* @__PURE__ */e.configExtension(n.DOMImportExtension,{rules:lt})],name:"@lexical/table/Table",nodes:()=>[Ye,f,i],register(n,o,r){const l=r.getOutput();return e.mergeRegister(t.effect(()=>{const t=l.hasHorizontalScroll.value;Be(n)!==t&&(ze(n,t),n.update(e.$fullReconcile))}),nt(n,l),t.effect(()=>tt(n,l.hasTabHandler.value)),t.effect(()=>l.hasCellMerge.value?void 0:et(n)),t.effect(()=>l.hasCellBackgroundColor.value?void 0:n.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),it=/* @__PURE__ */e.defineExtension({dependencies:[st],name:"@lexical/table/Import"});exports.$computeTableMap=H,exports.$computeTableMapSkipCellCheck=k,exports.$createTableCellNode=u,exports.$createTableNode=qe,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=p,exports.$createTableSelection=G,exports.$createTableSelectionFrom=J,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=A,exports.$deleteTableColumn__EXPERIMENTAL=v,exports.$deleteTableRowAtSelection=O,exports.$deleteTableRow__EXPERIMENTAL=E,exports.$findCellNode=Ee,exports.$findTableNode=Ae,exports.$getElementForTableNode=Ue,exports.$getNodeTriplet=L,exports.$getTableAndElementByKey=V,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>d(e));return d(n)?n:null},exports.$getTableCellNodeRect=z,exports.$getTableColumnIndexFromTableCellNode=function(e){return S(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=N,exports.$getTableRowIndexFromTableCellNode=function(e){const t=S(e);return N(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=S,exports.$insertTableColumn=function(t,n,o=!0,r,l){const i=t.getChildren(),a=[];for(let t=0;t<i.length;t++){const o=i[t];if(C(o))for(let t=0;t<r;t++){const t=o.getChildren();if(n>=t.length||n<0)throw new Error("Table column target index out of range");const r=t[n];d(r)||g(12);const{left:i,right:c}=b(r,l);let h=s.NO_STATUS;(i&&i.hasHeaderState(s.ROW)||c&&c.hasHeaderState(s.ROW))&&(h|=s.ROW);const f=u(h);f.append(e.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),t},exports.$insertTableColumnAtNode=M,exports.$insertTableColumnAtSelection=R,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(t,n,o=!0,r,l){const i=t.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let t=0;t<r;t++){const t=a.getChildren(),n=t.length,r=p();for(let o=0;o<n;o++){const n=t[o];d(n)||g(12);const{above:i,below:a}=b(n,l);let c=s.NO_STATUS;const h=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(s.COLUMN)||a&&a.hasHeaderState(s.COLUMN))&&(c|=s.COLUMN);const f=u(c,1,h);f.append(e.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return t},exports.$insertTableRowAtNode=y,exports.$insertTableRowAtSelection=T,exports.$insertTableRow__EXPERIMENTAL=$,exports.$isScrollableTablesActive=Be,exports.$isSimpleTable=B,exports.$isTableCellNode=d,exports.$isTableNode=Ge,exports.$isTableRowNode=C,exports.$isTableSelection=q,exports.$mergeCells=D,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!B(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$moveTableRow=function(e,t,n){if(t===n)return;const o=e.getChildren().filter(C),r=o.length;if(t<0||t>=r||n<0||n>=r)return;if(!B(e))return;const l=o[t],s=o[n];n>t?s.insertAfter(l):s.insertBefore(l)},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.$setTableColumnIsHeader=function(e,t,n){const[o]=k(e,null,null);o.length>0&&t>=0&&t<o[0].length||g(397,String(t));const r=n?s.COLUMN:s.NO_STATUS,l=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(l.has(n.cell)||(l.add(n.cell),n.cell.setHeaderStyles(r,s.COLUMN)))}},exports.$setTableRowIsHeader=function(e,t,n){const[o]=k(e,null,null);t>=0&&t<o.length||g(396,String(t));const r=o[t],l=n?s.ROW:s.NO_STATUS,i=new Set;for(let e=0;e<r.length;e++){const t=r[e];null!=t&&(i.has(t.cell)||(i.add(t.cell),t.cell.setHeaderStyles(l,s.ROW)))}},exports.$unmergeCell=function(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const n=t.anchor.getNode(),o=e.$findMatchingParent(n,d);return d(o)||g(148),I(o)},exports.$unmergeCellNode=I,exports.INSERT_TABLE_COMMAND=h,exports.TableCellHeaderStates=s,exports.TableCellNode=i,exports.TableExtension=st,exports.TableImportExtension=it,exports.TableImportRules=lt,exports.TableNode=Ye,exports.TableObserver=Z,exports.TableRowNode=f,exports.TableRowSchema=rt,exports.TableSchema=ot,exports.applyTableHandlers=he,exports.getDOMCellFromTarget=pe,exports.getTableElement=le,exports.getTableObserverFromTableElement=me,exports.registerTableCellUnmergeTransform=et,exports.registerTablePlugin=nt,exports.registerTableSelectionObserver=tt,exports.setScrollableTablesActive=ze;
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html"),o=require("@lexical/utils"),r=require("@lexical/clipboard");const l=/^(\d+(?:\.\d+)?)px$/,s={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class i extends e.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new i(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:c,priority:0}),th:e=>({conversion:c,priority:0})}}static importJSON(e){return u().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=s.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=e.$getDocument().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),a(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(t){const n=super.exportDOM(t);if(e.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...a(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=s.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==s.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function a(e){return"middle"===e||"bottom"===e}function c(t){const n=t,o=t.nodeName.toLowerCase();let r;l.test(n.style.width)&&(r=parseFloat(n.style.width));let i=s.NO_STATUS;if("th"===o){const t=n.getAttribute("scope");if("col"===t)i=s.COLUMN;else if("row"===t)i=s.ROW;else{const t=n.parentElement,o=e.isHTMLElement(t)&&"tr"===t.nodeName.toLowerCase()&&e.isHTMLElement(t.parentElement)&&("thead"===t.parentElement.nodeName.toLowerCase()||0===t.rowIndex),r=0===n.cellIndex;o&&(i|=s.ROW),r&&(i|=s.COLUMN),i===s.NO_STATUS&&(i=s.ROW)}}const c=u(i,n.colSpan,r);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;a(h)&&(c.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,p=f.includes("line-through"),C="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:t=>{const n=[];let o=null;const r=()=>{if(o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)if(e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)){if(e.$isTextNode(l)&&(m&&l.toggleFormat("bold"),p&&l.toggleFormat("strikethrough"),C&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(e.$createParagraphNode()),n},node:c}}function u(t=s.NO_STATUS,n=1,o){return e.$applyNodeReplacement(new i(t,n,o))}function d(e){return e instanceof i}const h=/* @__PURE__ */e.createCommand("INSERT_TABLE_COMMAND");function g(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class f extends e.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new f(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:m,priority:0})}}static importJSON(e){return p().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=e.$getDocument().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 m(e){const t=e;let n;return l.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>o.$descendantsMatching(e,d),node:p(n)}}function p(t){return e.$applyNodeReplacement(new f(t))}function C(e){return e instanceof f}function _(t,n,o=!0){const r=qe();for(let l=0;l<t;l++){const t=p();for(let r=0;r<n;r++){let n=s.NO_STATUS;"object"==typeof o?(0===l&&o.rows&&(n|=s.ROW),0===r&&o.columns&&(n|=s.COLUMN)):o&&(0===l&&(n|=s.ROW),0===r&&(n|=s.COLUMN));const i=u(n),a=e.$createParagraphNode();a.append(e.$createTextNode()),i.append(a),t.append(i)}r.append(t)}return r}function S(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function N(t){const n=e.$findMatchingParent(t,e=>Ge(e));if(Ge(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(e,t){const n=N(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)}}const w=(e,t)=>e===s.BOTH||e===t?t:s.NO_STATUS;function T(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||q(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=H(i,s,l),{startRow:u}=c,{startRow:d}=a;return t?y(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):y(d<u?s:l,!1)}const $=T;function y(t,n=!0){const[,,o]=L(t),[r,l]=H(o,t,t),i=r[0].length,{startRow:a}=l;let c=null;if(n){const n=a+t.__rowSpan-1,l=r[n],d=p();for(let t=0;t<i;t++){const{cell:o,startRow:r}=l[t];if(r+o.__rowSpan-1<=n){const n=l[t].cell.__headerState,o=w(n,s.COLUMN);d.append(u(o).append(e.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const h=o.getChildAtIndex(n);C(h)||g(256),h.insertAfter(d),c=d}else{const t=a,n=r[t],l=p();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===t){const t=n[o].cell.__headerState,r=w(t,s.COLUMN);l.append(u(r).append(e.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(t);C(d)||g(257),d.insertBefore(l),c=l}return c}function R(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||q(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=H(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return t?M(u+l.__colSpan>d+s.__colSpan?l:s,!0):M(d<u?s:l,!1)}const x=R;function M(t,n=!0,o=!0){const[,,r]=L(t),[l,i]=H(r,t,t),a=l.length,{startColumn:c}=i,d=n?c+t.__colSpan-1:c-1,h=r.getFirstChild();C(h)||g(120);let f=null;function m(t=s.NO_STATUS){const n=u(t).append(e.$createParagraphNode());return null===f&&(f=n),n}let p=h;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||g(121),p=e}const t=l[e],n=t[d<0?0:d].cell.__headerState,o=w(n,s.ROW);if(d<0){P(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&F(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function O(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const[n,o]=t.isBackward()?[t.focus.getNode(),t.anchor.getNode()]:[t.anchor.getNode(),t.focus.getNode()],[r,,l]=L(n),[s]=L(o),[i,a,c]=H(l,r,s),{startRow:u}=a,{startRow:d}=c,h=d+s.__rowSpan-1;if(i.length===h-u+1)return void l.remove();const f=i[0].length,m=i[h+1],p=l.getChildAtIndex(h+1);for(let e=h;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>h){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>h&&e===h){C(p)||g(387);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?P(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||g(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];F(e)}else{const e=i[u-1],{cell:t}=e[0];F(t)}}const E=O;function A(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r,,l]=L(n),[s]=L(o),[i,a,c]=H(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:h}=c,f=Math.min(u,h),m=Math.max(u+r.__colSpan-1,h+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 _=i[d],S=u>h?_[u+r.__colSpan]:_[h+s.__colSpan];if(void 0!==S){const{cell:e}=S;F(e)}else{const e=h<u?_[h-1]:_[u-1],{cell:t}=e;F(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}}const v=A;function F(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function P(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function D(t){if(0===t.length)return null;const n=N(t[0]),[o]=k(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const e of o)for(const n of e){if(!n||!n.cell)continue;const e=n.cell.getKey();if(!a.has(e)&&t.some(e=>e.is(n.cell))){a.add(e);const t=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,t),l=Math.max(l,t+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);K(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(e.$createParagraphNode()),h}function K(t){if(1!==t.getChildrenSize())return!1;const n=t.getFirstChildOrThrow();return!(!e.$isParagraphNode(n)||!n.isEmpty())}function I(t){const[n,o,r]=L(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[a,c]=H(r,n,n),{startColumn:d,startRow:h}=c,f=n.__headerState&s.COLUMN,m=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&s.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+h][e].cell.__headerState;return n});if(l>1){for(let t=1;t<l;t++)n.insertAfter(u(m[t]|_[0]).append(e.$createParagraphNode()));n.setColSpan(1)}if(i>1){let t;for(let n=1;n<i;n++){const r=h+n,s=a[r];t=(t||o).getNextSibling(),C(t)||g(125);let i=null;for(let e=0;e<d;e++){const t=s[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=l-1;o>=0;o--)P(t,u(m[o]|_[n]).append(e.$createParagraphNode()));else for(let t=l-1;t>=0;t--)i.insertAfter(u(m[t]|_[n]).append(e.$createParagraphNode()))}n.setRowSpan(1)}}function H(e,t,n){const[o,r,l]=k(e,t,n);return null===r&&g(207),null===l&&g(208),[o,r,l]}function k(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||g(209);const a=s(e);for(let c=o.getFirstChild(),u=0;null!=c;c=c.getNextSibling()){for(d(c)||g(147);void 0!==a[u];)u++;const o={cell:c,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:f}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[u+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function L(t){let n;if(t instanceof i)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,d);d(o)||g(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),d);d(o)||g(148),n=o}const o=n.getParent();C(o)||g(149);const r=o.getParent();return Ge(r)||g(210),[n,o,r]}function W(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function B(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!d(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function z(e){const[t,,n]=L(e),o=n.getChildren().filter(C),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().filter(d);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 Y(t,n){const o=n.getStartEndPoints(),r=q(n);if(null===o)return!1;const[l,s]=o,[i,a,c]=L(l),u=e.$findMatchingParent(s.getNode(),e=>d(e));if(!(d(i)&&d(u)&&C(a)&&Ge(c)))return!1;const[h,g,f]=H(c,i,u),[m]=k(t,null,null),p=h.length,_=p>0?h[0].length:0;let S=g.startRow,N=g.startColumn,b=m.length,w=b>0?m[0].length:0;if(r){const e=W(h,g,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,N=e.minColumn,b=Math.min(b,t),w=Math.min(w,n)}let T=!1;const $=Math.min(p,S+b)-1,R=Math.min(_,N+w)-1,x=new Set;for(let e=S;e<=$;e++)for(let t=N;t<=R;t++){const n=h[e][t];x.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(I(n.cell),x.add(n.cell.getKey()),T=!0))}let[O]=k(c.getWritable(),null,null);const E=b-p+S;for(let e=0;e<E;e++){y(O[p-1][0].cell)}const A=w-_+N;for(let e=0;e<A;e++){M(O[0][_-1].cell,!0,!1)}[O]=k(c.getWritable(),null,null);for(let t=S;t<S+b;t++)for(let n=N;n<N+w;n++){const o=t-S,r=n-N,l=m[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const e=[],o=Math.min(t+s.__rowSpan,S+b)-1,r=Math.min(n+s.__colSpan,N+w)-1;for(let l=t;l<=o;l++)for(let t=n;t<=r;t++){const n=O[l][t];e.push(n.cell)}D(e),T=!0}const{cell:i}=O[t][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(t=>{if(e.$isTextNode(t)){e.$createParagraphNode().append(t),i.append(t)}else i.append(t)}),c.forEach(e=>e.remove())}if(r&&T){const[e]=k(c.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function U(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,d);d(r)||g(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||g(239,n);const s=l.getParent();return Ge(s)||g(240,n),[o,r,l,s]});return l.is(c)||g(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class X{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const t=e.$getNodeByKey(this.tableKey),n=e.$getNodeByKey(this.anchor.key),o=e.$getNodeByKey(this.focus.key);return null!==t&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return q(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new X(this.tableKey,e.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),e.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(t){if(""===t)return;const n=(t.endsWith("\n")?t.slice(0,-1):t).split("\n").map(e=>e.split("\t")),o=qe();for(const t of n){const n=p();for(const o of t){const t=u(s.NO_STATUS),r=e.$createParagraphNode();o&&r.append(e.$createTextNode(o)),t.append(r),n.append(t)}o.append(n)}const{anchorCell:r}=U(this);Y(o,r.select(0,r.getChildrenSize()))}insertText(){}hasFormat(t){let n=0;this.getNodes().filter(d).forEach(t=>{const o=t.getFirstChild();e.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=e.TEXT_TYPE_TO_FORMAT[t];return 0!==(n&o)}insertNodes(t){const n=this.focus.getNode();e.$isElementNode(n)||g(151);e.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(t)}getShape(){const{anchorCell:e,focusCell:t}=U(this),n=z(e);null===n&&g(153);const o=z(t);null===o&&g(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 t=this._cachedNodes;if(null!==t)return t;const{anchorTable:n,anchorCell:o,focusCell:r}=U(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&g(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&g(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=H(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:h}=W(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=h;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||g(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||j(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return e.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>d(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function q(e){return e instanceof X}function G(){const t=e.$createPoint("root",0,"element"),n=e.$createPoint("root",0,"element");return new X("root",t,n)}function J(t,n,o){t.getKey(),n.getKey(),o.getKey();const r=e.$getSelection(),l=q(r)?r.clone():G();return l.set(t.getKey(),n.getKey(),o.getKey()),l}function j(t,n){const o=[[t]];for(let t=o.at(-1);void 0!==t&&o.length>0;t=o.at(-1)){const r=t.pop();void 0===r?o.pop():!1!==n(r)&&e.$isElementNode(r)&&o.push(r.getChildren())}}function V(t,n=e.$getEditor()){const o=e.$getNodeByKey(t);Ge(o)||g(231,t);const r=le(o,n.getElementByKey(t));return null===r&&g(232,t),{tableElement:r,tableNode:o}}class Q{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return void 0!==t&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const t=[];for(const[n,[o]]of Array.from(this.observers.entries())){const r=e.$getNodeByKey(n);Ge(r)?t.push([r,o]):this.removeObserver(n)}return t}}class Z{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return V(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.read("latest",()=>{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=_e(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=_e(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(t=!0){const n=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:o,tableElement:r}=this.$lookup();Se(n,_e(o,r),null),t&&null!==e.$getSelection()&&(e.$setSelection(null),n.dispatchCommand(e.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&&g(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Se(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const t=e.getDOMSelection(this.editor._window);t&&t.rangeCount>0&&t.removeAllRanges()}}$setFocusCellForSelection(t,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=t.x,s=t.y;if(this.focusCell=t,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=He(r,t.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let t=i;if(null===t&&n&&(t=r.getCellNodeFromCords(l,s,this.table)),null!==t){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=t.getKey(),this.tableSelection=J(r,n,t),e.$setSelection(this.tableSelection),o.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0),Se(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const t=this.anchorCellNodeKey?e.$getNodeByKey(this.anchorCellNodeKey):null;return d(t)?t:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&g(234),e}$getFocusTableCell(){const t=this.focusCellNodeKey?e.$getNodeByKey(this.focusCellNodeKey):null;return d(t)?t:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&g(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=He(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=J(t,n,n),this.anchorCellNodeKey=e}}$formatCells(t){const n=e.$getSelection();q(n)||g(236);const o=e.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(d);s.length>0||g(237);const i=s[0].getFirstChild(),a=e.$isParagraphNode(i)?i.getFormatFlags(t,null):null;s.forEach(e=>{r.set(e.getKey(),0,"element"),l.set(e.getKey(),e.getChildrenSize(),"element"),o.formatText(t,a)}),e.$setSelection(n),this.editor.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:t}=this,n=e.$getNodeByKey(this.tableNodeKey);if(!Ge(n))throw new Error("Expected TableNode.");const o=e.$getSelection();q(o)||g(253);const r=o.getNodes().filter(d),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(e.$isRootNode(o)&&o.isEmpty()&&t.dispatchCommand(e.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(t=>{if(e.$isElementNode(t)){const n=e.$createParagraphNode(),o=e.$createTextNode();n.append(o),t.append(n),t.getChildren().forEach(e=>{e!==n&&e.remove()})}}),Se(t,this.table,null),e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}}const ee="__lexicalTableSelection";function te(t){const n=e.$getNodeByKeyOrThrow(t);return Ge(n)||g(386,t),n}const ne=40;function oe(e,t,n){const o=e=>Math.max(1,Math.ceil(Math.min(ne,e)/ne*18));return e<=t+ne?-o(t+ne-e):e>=n-ne?o(e-(n-ne)):0}function re(t){return e.isHTMLElement(t)&&"TABLE"===t.nodeName}function le(e,t){if(!t)return t;const n=re(t)?t:t.querySelector("table");return re(n)||g(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function se(e){return e._window}function ie(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;d(n)&&(o=n)}return null}const ae=[[e.KEY_ARROW_DOWN_COMMAND,"down"],[e.KEY_ARROW_UP_COMMAND,"up"],[e.KEY_ARROW_LEFT_COMMAND,"backward"],[e.KEY_ARROW_RIGHT_COMMAND,"forward"]],ce=[e.DELETE_WORD_COMMAND,e.DELETE_LINE_COMMAND,e.DELETE_CHARACTER_COMMAND],ue=[e.KEY_BACKSPACE_COMMAND,e.KEY_DELETE_COMMAND];function de(t,n){return t.registerRootListener(o=>{if(null===o)return;const r=t._window;if(null===r)return;return e.registerEventListener(r,"pointerdown",r=>{const l=e.getComposedEventTarget(r);if(0!==r.button||!e.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=pe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&ee in n&&n[ee])return{cellElement:t,tableElement:n,tableObserver:n[ee]};n=n.parentNode}return null}(l);t.update(()=>{if(q(e.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(t,n,o,r,l,s){const i=t._window;if(!i)return;const a=o=>{if(l.isSelecting)return;l.isSelecting=!0,null!==o&&null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(o)});let a=n.clientX,c=n.clientY,u=null;const d=()=>{l.isSelecting=!1,null!==u&&(i.cancelAnimationFrame(u),u=null),i.removeEventListener("pointerup",N),i.removeEventListener("pointermove",b)},h=(t,n)=>{const o=r.getRootNode();if(!e.isDOMDocumentNode(o)&&!e.isDOMShadowRoot(o))return null;for(const e of o.elementsFromPoint(t,n)){const t=Ce(r,e);if(t)return t}return null},g=(n,o)=>{null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&n.elem===l.focusCell.elem||(s.setNextFocus({focusCell:n,override:o,tableKey:l.tableNodeKey}),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0))},f=e=>{for(let t=r.parentElement;t;t=t.parentElement){if("x"===e?t.scrollWidth>t.clientWidth:t.scrollHeight>t.clientHeight){const n=i.getComputedStyle(t),o="x"===e?n.overflowX:n.overflowY;if("auto"===o||"scroll"===o)return t}}return null},m=(e,t,n)=>{let o,r;if(null===e)o=0,r="x"===n?i.innerWidth:i.innerHeight;else{const t=e.getBoundingClientRect();o="x"===n?t.left:t.top,r="x"===n?t.right:t.bottom}const l=oe(t,o,r);if(0===l)return!1;if(null===e){const e="x"===n?i.scrollX:i.scrollY;return i.scrollBy("x"===n?l:0,"x"===n?0:l),("x"===n?i.scrollX:i.scrollY)!==e}if("x"===n){const t=e.scrollLeft;return e.scrollLeft+=l,e.scrollLeft!==t}const s=e.scrollTop;return e.scrollTop+=l,e.scrollTop!==s},p=(e,t)=>{let n=a,o=c;if(null===e)n=Math.min(Math.max(n,1),i.innerWidth-1);else{const t=e.getBoundingClientRect();n=Math.min(Math.max(n,t.left+1),t.right-1)}if(null===t)o=Math.min(Math.max(o,1),i.innerHeight-1);else{const e=t.getBoundingClientRect();o=Math.min(Math.max(o,e.top+1),e.bottom-1)}return[n,o]},C=()=>{const e=f("x");if(null!==e){const t=e.getBoundingClientRect();if(0!==oe(a,t.left,t.right))return!0}const t=f("y"),n=null===t?0:t.getBoundingClientRect().top,o=null===t?i.innerHeight:t.getBoundingClientRect().bottom;return 0!==oe(c,n,o)},_=()=>{if(u=null,!l.isSelecting)return;const e=f("x"),t=f("y"),n=null!==e&&m(e,a,"x"),o=m(t,c,"y");if(n||o){const[n,o]=p(e,t),r=h(n,o);r&&g(r,!1),u=i.requestAnimationFrame(_)}},S=()=>{null===u&&"touch"!==l.pointerType&&C()&&(u=i.requestAnimationFrame(_))},N=()=>{d()},b=t=>{if(!(e=>!(1&~e.buttons))(t)&&l.isSelecting)return void d();const n=e.getComposedEventTarget(t);if(!e.isDOMNode(n))return;a=t.clientX,c=t.clientY;let o=null;const s=!(e.IS_FIREFOX||r.contains(n));o=s?Ce(r,n):h(t.clientX,t.clientY),o&&g(o,s),S()};i.addEventListener("pointerup",N,l.listenerOptions),i.addEventListener("pointermove",b,l.listenerOptions)};l.pointerType=n.pointerType;const c=te(l.tableNodeKey),u=e.$getPreviousSelection();if(e.IS_FIREFOX&&n.shiftKey&&Re(u,c)&&(e.$isRangeSelection(u)||q(u))){const e=u.anchor.getNode(),t=ie(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Ie(l,t)),l.$setFocusCellForSelection(o),Pe(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(t,r,i,l,o,n)})})})}function he(t,n,l,s,i){const a=l.getRootElement(),c=se(l);null!==a&&null!==c||g(246);const u=new Z(l,t.getKey()),h=le(t,n);!function(e,t){null!==me(e)&&g(205);e[ee]=t}(h,u),u.listenersToRemove.add(()=>function(e,t){me(e)===t&&delete e[ee]}(h,u));u.listenersToRemove.add(e.registerEventListener(h,"mousedown",t=>{const n=e.getComposedEventTarget(t);if(t.detail>=3&&e.isDOMNode(n)){null!==pe(n)&&t.preventDefault()}},u.listenerOptions));for(const[n,o]of ae)u.listenersToRemove.add(l.registerCommand(n,e=>Fe(l,e,o,t,u,i),e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.KEY_ESCAPE_COMMAND,n=>{const o=e.$getSelection();if(q(o)){const e=ie(t,o.focus.getNode());if(null!==e)return Pe(n),e.selectEnd(),!0}return!1},e.COMMAND_PRIORITY_HIGH));const f=n=>()=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$clearText(),!0;if(e.$isRangeSelection(o)){if(!d(ie(t,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=t.isParentOf(r),i=t.isParentOf(l);if(s&&!i||i&&!s)return u.$clearText(),!0;const a=e.$findMatchingParent(o.anchor.getNode(),t=>e.$isElementNode(t)),c=a&&e.$findMatchingParent(a,t=>e.$isElementNode(t)&&d(t.getParent()));if(!e.$isElementNode(c)||!e.$isElementNode(a))return!1;if(n===e.DELETE_LINE_COMMAND&&null===c.getPreviousSibling())return!0}return!1};for(const t of ce)u.listenersToRemove.add(l.registerCommand(t,f(t),e.COMMAND_PRIORITY_HIGH));const m=n=>{const o=e.$getSelection();if(!q(o)&&!e.$isRangeSelection(o))return!1;const r=t.isParentOf(o.anchor.getNode());if(r!==t.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",n=r?"focus":"anchor",{key:l,offset:s,type:i}=o[n];return t[o[e].isBefore(o[n])?"selectPrevious":"selectNext"]()[n].set(l,s,i),!1}return!!Re(o,t)&&(!!q(o)&&(n&&(n.preventDefault(),n.stopPropagation()),u.$clearText(),!0))};for(const t of ue)u.listenersToRemove.add(l.registerCommand(t,m,e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.CUT_COMMAND,t=>{const n=e.$getSelection();if(n){if(!q(n)&&!e.$isRangeSelection(n))return!1;r.copyToClipboard(l,o.objectKlassEquals(t,ClipboardEvent)?t:null,r.$getClipboardDataFromSelection(n));const s=m(t);return e.$isRangeSelection(n)?(n.removeText(),!0):s}return!1},e.COMMAND_PRIORITY_HIGH));const p=a.ownerDocument;return u.listenersToRemove.add(e.registerEventListener(p,"paste",n=>{if(n.defaultPrevented)return;l.read("latest",()=>{const n=e.$getSelection();return a.contains(p.activeElement)&&q(n)&&Re(n,t)})&&(n.preventDefault(),l.dispatchCommand(e.PASTE_COMMAND,n))})),u.listenersToRemove.add(e.registerEventListener(p,"copy",n=>{if(n.defaultPrevented)return;const o=e.getComposedEventTarget(n);if(o===a||e.isDOMNode(o)&&a.contains(o))return;l.read("latest",()=>{const n=e.$getSelection();return a.contains(e.getActiveElement(a))&&q(n)&&Re(n,t)})&&(n.preventDefault(),l.dispatchCommand(e.COPY_COMMAND,n))})),u.listenersToRemove.add(l.registerCommand(e.FORMAT_TEXT_COMMAND,n=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$formatCells(n),!0;if(e.$isRangeSelection(o)){const t=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(t))return!1}return!1},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FORMAT_ELEMENT_COMMAND,n=>{const o=e.$getSelection();if(!q(o)||!Re(o,t))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!d(r)||!d(l))return!1;if(function(e,t){if(q(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=H(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,t))return t.setFormat(n),!0;const[s,i,a]=H(t,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),u=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let t=h;t<=c;t++)for(let o=g;o<=u;o++){const r=s[t][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(n);const l=r.getChildren();for(let t=0;t<l.length;t++){const o=l[t];e.$isElementNode(o)&&!o.isInline()&&o.setFormat(n)}}return!0},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.CONTROLLED_TEXT_INSERTION_COMMAND,n=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$clearHighlight(),!1;if(e.$isRangeSelection(o)){const r=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(r))return!1;if("string"==typeof n){const r=Ke(l,o,t);if(r)return De(r,t,[e.$createTextNode(n)]),!0}}return!1},e.COMMAND_PRIORITY_HIGH)),s&&u.listenersToRemove.add(l.registerCommand(e.KEY_TAB_COMMAND,n=>{const o=e.$getSelection();if(!e.$isRangeSelection(o)||!o.isCollapsed()||!Re(o,t))return!1;const r=Ee(o.anchor.getNode());return!(null===r||!t.is(Ae(r)))&&(Pe(n),function(t,n){const o="next"===n?"getNextSibling":"getPreviousSibling",r="next"===n?"getFirstChild":"getLastChild",l=t[o]();if(e.$isElementNode(l))return l.selectEnd();const s=e.$findMatchingParent(t,C);null===s&&g(247);for(let t=s[o]();C(t);t=t[o]()){const n=t[r]();if(e.$isElementNode(n))return n.selectEnd()}const i=e.$findMatchingParent(s,Ge);null===i&&g(248);"next"===n?i.selectNext():i.selectPrevious()}(r,n.shiftKey?"previous":"next"),!0)},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FOCUS_COMMAND,e=>t.isSelected(),e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>{const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed()||!Re(n,t))return!1;const o=Ke(l,n,t);return!!o&&(De(o,t),!0)},e.COMMAND_PRIORITY_HIGH)),u}function ge(t,n){const o=e.$getSelection(),r=e.$getPreviousSelection(),l=t.getAndClearNextFocus();if(null!==l){const{tableKey:e,focusCell:n}=l,r=t.observers.get(e);r||g(335,e);const[s]=r;if(q(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=t.getAndClearShouldCheckSelectionForTable();if(s&&e.$isRangeSelection(r)&&e.$isRangeSelection(o)&&o.isCollapsed()){const t=e.$getNodeByKey(s);if(Ge(t)){const n=o.anchor.getNode(),r=t.getFirstChild(),l=Ee(n);if(null!==l&&C(r)){const n=r.getFirstChild();if(d(n)&&t.is(e.$findMatchingParent(l,e=>e.is(t)||e.is(n))))return n.selectStart(),!0}}}q(o)&&function(t,n){const o=se(t),r=e.$getPreviousSelection();if(!n.is(r))return;const l=te(n.tableKey),s=e.getDOMSelection(o),i=s&&e.getDOMSelectionPoints(s,t.getRootElement());if(s&&i&&i.anchorNode&&i.focusNode){const o=e.$getNearestNodeFromDOMNode(i.focusNode),r=o&&!l.isParentOf(o),a=e.$getNearestNodeFromDOMNode(i.anchorNode),c=a&&l.isParentOf(a);if(r&&c&&s.rangeCount>0){const o=e.$createRangeSelectionFromDom(s,t);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),e.$setSelection(o))}}}(n,o),e.$isRangeSelection(o)&&function(t,n){const o=e.$getPreviousSelection(),{anchor:r,focus:l}=t,s=r.getNode(),i=l.getNode(),a=Ee(s),c=Ee(i),u=a?Ae(a):null,d=c?Ae(c):null,h=t.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),p=u&&(!d||d.isParentOf(u));if(m){const n=t.clone(),[o]=H(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(h?r.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),e.$setSelection(n)}else if(p){const n=t.clone(),[o]=H(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(h?l.getKey():r.getKey(),h?l.getChildrenSize():0,"element"),e.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||g(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Ie(l,a)),l.$setFocusCellForSelection(Ie(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&t.isCollapsed()&&e.$isRangeSelection(o)&&o.isCollapsed()){const e=Ee(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Ie(l,e)),l.$setFocusCellForSelection(Ie(l,c),!0),l.pointerType=null)}}}(o,t);for(const[e,o]of t.$getTableNodesAndObservers())fe(n,e,o);return!1}function fe(t,n,o){const r=e.$getSelection(),l=e.$getPreviousSelection();r&&!r.is(l)&&(q(r)||q(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(q(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!q(r)&&q(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),Ne(t.table,t=>{const n=t.elem;t.highlighted=!1,Oe(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(t,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),Ne(t.table,t=>{t.highlighted=!0,Me(e,t)})}(t,o)}function me(e){return e[ee]||null}function pe(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 Ce(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function _e(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=le(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 Se(e,t,n){const o=new Set(n?n.getNodes():[]);Ne(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Me(e,t)):(t.highlighted=!1,Oe(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Ne(t,n){const{domRows:o}=t;for(let t=0;t<o.length;t++){const r=o[t];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=e.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:t})}}}const be=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?xe(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?xe(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?xe(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?xe(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function we(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 $e(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&g(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&g(250,n,String(s)),i}function ye(e,t,n,o,r){const l=W(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=we(e,t);return null===n&&g(249,t.cell.getKey()),n}(l,n),[h,f]=Te(d);let m=l[h],p=l[f];"forward"===r?m+="maxColumn"===h?1:a:"backward"===r?m-="minColumn"===h?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 _=C[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=W(e,t,n),r=we(o,t);if(r)return[$e(e,o,r),$e(e,o,Te(r))];const l=we(o,n);if(l)return[$e(e,o,Te(l)),$e(e,o,l)];const s=["minColumn","minRow"];return[$e(e,o,s),$e(e,o,Te(s))]}(t,n,_),b=Ie(e,S.cell),w=Ie(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function Re(t,n){if(e.$isRangeSelection(t)||q(t)){const e=n.isParentOf(t.anchor.getNode()),o=n.isParentOf(t.focus.getNode());return e&&o}return!1}function xe(e,t){t?e.selectStart():e.selectEnd()}function Me(t,n){const o=n.elem,r=t._config.theme;d(e.$getNearestNodeFromDOMNode(o))||g(131),e.addClassNamesToElement(o,r.tableCellSelected)}function Oe(t,n){const o=n.elem;d(e.$getNearestNodeFromDOMNode(o))||g(131);const r=t._config.theme;e.removeClassNamesFromElement(o,r.tableCellSelected)}function Ee(t){const n=e.$findMatchingParent(t,d);return d(n)?n:null}function Ae(t){const n=e.$findMatchingParent(t,Ge);return Ge(n)?n:null}function ve(t,n,o,r,l,s,i){const a=e.$caretFromPoint(o.focus,l?"previous":"next");if(e.$isExtendableTextPointCaret(a))return!1;let c=a;for(const t of e.$extendCaretToRange(a).iterNodeCarets("shadowRoot")){if(!e.$isSiblingCaret(t)||!e.$isElementNode(t.origin))return!1;c=t}const u=c.getParentAtCaret();if(!d(u))return!1;const h=u,g=function(t){for(const n of e.$extendCaretToRange(t).iterNodeCarets("root")){const{origin:o}=n;if(d(o)){if(e.$isChildCaret(n))return e.$getChildCaret(o,t.direction)}else if(!C(o))break}return null}(e.$getSiblingCaret(h,c.direction)),f=e.$findMatchingParent(h,Ge);if(!f||!f.is(s))return!1;const m=t.getElementByKey(h.getKey()),p=pe(m);if(!m||!p)return!1;const _=Ue(t,f);if(i.table=_,g)if("extend"===r){const e=pe(t.getElementByKey(g.origin.getKey()));if(!e)return!1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(e,!0)}else{const t=e.$normalizeCaret(g);e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else{const t=function(t){const n=e.$getAdjacentChildCaret(t);return e.$isChildCaret(n)?e.$normalizeCaret(n):t}(e.$getSiblingCaret(f,a.direction));e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}return Pe(n),!0}function Fe(t,n,o,r,l,s){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(t))return!1;const i=e.$getSelection();if(!Re(i,r)){if(e.$isRangeSelection(i)){if("backward"===o){if(i.focus.offset>0)return!1;const t=function(t){for(let n=t,o=t;null!==o;n=o,o=o.getParent())if(e.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!t)return!1;const o=t.getPreviousSibling();return!!Ge(o)&&(Pe(n),n.shiftKey?i.focus.set(o.getParentOrThrow().getKey(),o.getIndexWithinParent(),"element"):o.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const t=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=e.$findMatchingParent(t,e=>Ge(e));if(d(l)&&(l=e.$findMatchingParent(l,Ge)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let a=0;"up"===o&&e.$isElementNode(s)&&(a=s.getChildrenSize());let c=s;if("up"===o&&e.$isElementNode(s)){const t=s.getLastChild();c=t||s,a=e.$isTextNode(c)?c.getTextContentSize():0}const u=i.clone();return u.focus.set(c.getKey(),a,e.$isTextNode(c)?"text":"element"),e.$setSelection(u),Pe(n),!0}if(e.$isRootOrShadowRoot(t)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==ie(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=L(e),[o]=L(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),a=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),c=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(a),l.$setFocusCellForSelection(c,!0),!0}}return!1}{let r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());if(d(r)&&(r=e.$findMatchingParent(r,Ge)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Ge(s)&&l.tableNodeKey===s.getKey()){const t=s.getFirstDescendant(),r=s.getLastDescendant();if(!t||!r)return!1;const[l]=L(t),[a]=L(r),c=i.clone();return c.focus.set(("up"===o?l:a).getKey(),"up"===o?0:a.getChildrenSize(),"element"),Pe(n),e.$setSelection(c),!0}}}}return"down"===o&&Be(t)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(e.$isRangeSelection(i)){if("backward"===o||"forward"===o){return ve(t,n,i,n.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:a,focus:c}=i,u=e.$findMatchingParent(a.getNode(),d),h=e.$findMatchingParent(c.getNode(),d);if(!d(u)||!u.is(h))return!1;const g=Ae(u);if(g!==r&&null!=g){const e=le(g,t.getElementByKey(g.getKey()));if(null!=e)return l.table=_e(g,e),Fe(t,n,o,g,l,s)}const f=t.getElementByKey(u.__key),m=t.getElementByKey(a.key);if(null==m||null==f)return!1;let p;if("element"===a.type)p=m.getBoundingClientRect();else{const n=e.getDOMSelection(se(t));if(null===n||0===n.rangeCount)return!1;const o=e.getDOMSelectionRange(n,t.getRootElement());if(null===o)return!1;p=o.getBoundingClientRect()}const C="up"===o?u.getFirstChild():u.getLastChild();if(null==C)return!1;const _=t.getElementByKey(C.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===o?S.top>p.top-p.height:p.bottom+p.height>S.bottom){Pe(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return be(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(q(i)){const{anchor:s,focus:a,tableKey:c}=i;if(c!==r.getKey())return!1;const u=e.$findMatchingParent(s.getNode(),d),h=e.$findMatchingParent(a.getNode(),d),[f]=i.getNodes();Ge(f)||g(251);const m=le(f,t.getElementByKey(f.getKey()));if(!d(u)||!d(h)||!Ge(f)||null==m)return!1;l.$updateTableTableSelection(i);const p=_e(f,m),C=r.getCordsFromCellNode(u,p),_=r.getDOMCellFromCordsOrThrow(C.x,C.y,p);if(l.$setAnchorCellForSelection(_),Pe(n),n.shiftKey){const[e,t,n]=H(r,u,h);return ye(l,e,t,n,o)}return h.selectEnd(),!0}return!1}function Pe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function De(t,n,o){const r=e.$createParagraphNode();"first"===t?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Ke(t,n,o){const r=o.getParent();if(!r)return;const l=e.getDOMSelection(se(t));if(!l)return;const s=e.getDOMSelectionPoints(l,t.getRootElement()).anchorNode,i=t.getElementByKey(r.getKey()),a=le(o,t.getElementByKey(o.getKey()));if(!s||!i||!a||!i.contains(s)||a.contains(s))return;const c=e.$findMatchingParent(n.anchor.getNode(),e=>d(e));if(!c)return;const u=e.$findMatchingParent(c,e=>Ge(e));if(!Ge(u)||!u.is(o))return;const[h,g]=H(o,c,c),f=h[0][0],m=h[h.length-1][h[0].length-1],{startRow:p,startColumn:C}=g,_=p===f.startRow&&C===f.startColumn,S=p===m.startRow&&C===m.startColumn;return _?"first":S?"last":void 0}function Ie(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function He(t,n,o){return ie(t,e.$getNearestNodeFromDOMNode(n,o))}function ke(t,n,o){const r=t.querySelector("colgroup");if(!r)return;const l=[];for(let t=0;t<n;t++){const n=e.$getDocument().createElement("col"),r=o&&o[t];r&&(n.style.width=`${r}px`),l.push(n)}r.replaceChildren(...l)}function Le(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const We=new WeakSet;function Be(t=e.$getEditor()){return We.has(t)}function ze(e,t){t?We.add(e):We.delete(e)}class Ye extends e.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Ye(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Xe,priority:1})}}static importJSON(e){return qe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=re(e)?e:e.querySelector("table");return re(t)||g(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=e.$getDocument().createElement("table");this.__style&&e.setDOMStyleFromCSS(o.style,this.__style);const r=e.$getDocument().createElement("colgroup");if(o.appendChild(r),e.setDOMUnmanaged(r),e.addClassNamesToElement(o,t.theme.table),this.updateTableElement(null,o,t),Be(n)){const n=e.$getDocument().createElement("div"),r=t.theme.tableScrollableWrapper;return r?e.addClassNamesToElement(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(t,n,o){this.__style!==(t?t.__style:"")&&e.setDOMStyleFromCSS(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,o,this.__rowStriping);const r=t?t.getColumnCount():0,l=t?t.__colWidths:void 0;this.getColumnCount()===r&&this.getColWidths()===l||ke(n,this.getColumnCount(),this.getColWidths()),Le(n,o,this.getFormatType())}updateDOM(t,n,o){const r=le(this,n);return n===r===Be()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;ke(le(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!re(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!re(o))return null;Le(o,t._config,this.getFormatType());const[r]=k(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const t=e.$getDocument().createElement("tbody");for(const e of a)t.appendChild(e);o.append(t)}return o},element:!re(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=He(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(t,n,o){const r=this.getDOMCellFromCords(t,n,o);if(null==r)return null;const l=e.$getNearestNodeFromDOMNode(r.elem);return d(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!C(e))return 0;let t=0;return e.getChildren().forEach(e=>{d(e)&&(t+=e.getColSpan())}),t}}function Ue(e,t){const n=e.getElementByKey(t.getKey());return null===n&&g(230),_e(t,n)}function Xe(e){const t=qe();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&t.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&t.setFrozenRows(1);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>o.$descendantsMatching(e,C),node:t}}function qe(){return e.$applyNodeReplacement(new Ye)}function Ge(e){return e instanceof Ye}function Je(t){C(t.getParent())?t.isEmpty()&&t.append(e.$createParagraphNode()):t.remove()}function je(e){Ge(e.getParent())?o.$unwrapAndFilterDescendants(e,d):e.remove()}function Ve(t){o.$unwrapAndFilterDescendants(t,C);const[n]=k(t,null,null),r=n.reduce((e,t)=>Math.max(e,t.length),0),l=t.getChildren();for(let t=0;t<n.length;++t){const o=l[t];if(!o)continue;C(o)||g(254,o.constructor.name,o.getType());const s=n[t].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let t=s;t<r;++t){const t=u();t.append(e.$createParagraphNode()),o.append(t)}}const s=t.getColWidths(),i=t.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}t.setColWidths(e)}}function Qe(t){if(t.detail<3||!e.isDOMNode(t.target))return!1;const n=e.$getNearestNodeFromDOMNode(t.target);if(null===n)return!1;const o=e.$findMatchingParent(n,t=>e.$isElementNode(t)&&!t.isInline());if(null===o)return!1;return!!d(o.getParent())&&(o.select(0),!0)}function Ze(){const t=e.$getSelection();if(!e.$isRangeSelection(t))return!1;const n=Ae(t.anchor.getNode());if(null===n)return!1;const o=e.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=k(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=J(n,l.cell,i.cell);return e.$setSelection(a),!0}function et(e){return e.registerNodeTransform(i,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=L(e),[n]=H(t,e,e),r=n.length,l=n[0].length;let s=t.getFirstChild();C(s)||g(175);const i=[];for(let e=0;e<r;e++){0!==e&&(s=s.getNextSibling(),C(s)||g(175));let t=null;for(let r=0;r<l;r++){const l=n[e][r],a=l.cell;if(l.startRow===e&&l.startColumn===r)t=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){d(a)||g(176);const e=u(a.__headerState);null!==t?t.insertAfter(e):o.$insertFirst(s,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function tt(t,n=!0){const o=new Q,r=(e,r,l)=>{const s=le(e,l),i=he(e,s,t,n,o);o.observers.set(r,[i,s])};return e.mergeRegister(de(t,o),t.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>ge(o,t),e.COMMAND_PRIORITY_HIGH),t.registerMutationListener(Ye,e=>{t.read("latest",()=>{for(const[t,n]of e){const e=o.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:l}=V(t);void 0===e?r(n,t,l):l!==e[1]&&(o.removeObserver(t),r(n,t,l))}else"destroyed"===n&&o.removeObserver(t)}})},{skipInitialization:!1}),()=>{o.removeAllObservers()})}function nt(n,r){n.hasNodes([Ye])||g(255);const{hasNestedTables:l=t.signal(!1)}=r??{};return e.mergeRegister(n.registerCommand(h,t=>function({rows:t,columns:n,includeHeaders:r},l){const s=e.$getSelection()||e.$getPreviousSelection();if(!s||!e.$isRangeSelection(s))return!1;if(!l&&Ae(s.anchor.getNode()))return!1;const i=_(Number(t),Number(n),r);o.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return e.$isTextNode(a)&&a.select(),!0}(t,l.peek()),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(t,r)=>n===r&&function(t,n){const{nodes:r,selection:l}=t;if(!r.some(e=>Ge(e)||o.$dfs(e).some(e=>Ge(e.node)))){if(q(l)){let t="",n=!1;for(const o of r){const r=e.$isElementNode(o)&&!o.isInline();t.length>0&&(r||n)&&(t+="\n"),t+=o.getTextContent(),n=r}return l.insertRawText(t),!0}return!1}const s=q(l),i=e.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>d(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>d(e))||s))return!1;if(1===r.length&&Ge(r[0]))return Y(r[0],l);if(i&&n.peek()&&!function(t){if(q(t)&&!t.focus.getNode().is(t.anchor.getNode()))return!0;if(e.$isRangeSelection(t)&&d(t.anchor.getNode())&&!t.anchor.getNode().is(t.focus.getNode()))return!0;return!1}(l))return!1;return!0}(t,l),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECT_ALL_COMMAND,Ze,e.COMMAND_PRIORITY_LOW),n.registerCommand(e.CLICK_COMMAND,Qe,e.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(Ye,Ve),n.registerNodeTransform(f,je),n.registerNodeTransform(i,Je))}const ot={$accepts:C,$packageRun:e=>e.every(d)?[p().splice(0,0,e)]:[],name:"TableSchema"},rt={$accepts:d,name:"TableRowSchema"},lt=[/* @__PURE__ */n.defineImportRule({$import:(e,t)=>{const n=qe();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return[n.splice(0,0,o.$descendantsMatching(e.$importChildren(t),C))]},match:n.sel.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */n.defineImportRule({$import:(e,t)=>[p(l.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,o.$descendantsMatching(e.$importChildren(t),d))],match:n.sel.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */n.defineImportRule({$import:(t,o)=>{const r="TH"===o.nodeName,i=l.test(o.style.width)?parseFloat(o.style.width):void 0;let a=s.NO_STATUS;if(r){const t=o.getAttribute("scope");if("col"===t)a=s.COLUMN;else if("row"===t)a=s.ROW;else{const t=o.parentElement,n=e.isHTMLTableRowElement(t)&&(t.parentElement&&"THEAD"===t.parentElement.nodeName||0===t.rowIndex),r=0===o.cellIndex;n&&(a|=s.ROW),r&&(a|=s.COLUMN),a===s.NO_STATUS&&(a=s.ROW)}}const c=u(a,o.colSpan,i);c.__rowSpan=o.rowSpan;const d=o.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=o.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(c.__verticalAlign=h);const g=t.get(n.ImportTextFormat),f=g|function(t){let n=0;const o=t.fontWeight;"700"!==o&&"bold"!==o||(n|=e.IS_BOLD),"italic"===t.fontStyle&&(n|=e.IS_ITALIC);const r=(t.textDecoration||"").split(" ");return r.includes("underline")&&(n|=e.IS_UNDERLINE),r.includes("line-through")&&(n|=e.IS_STRIKETHROUGH),n}(o.style),m=t.get(n.ImportTextStyle),p=o.style.color,C=p?{...m,color:p}:m,_=[];f!==g&&_.push(n.contextValue(n.ImportTextFormat,f)),C!==m&&_.push(n.contextValue(n.ImportTextStyle,C));const S=function(t){const n=[];let o=null;const r=()=>{if(null!==o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)?null!==o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o)):(r(),o=null,n.push(l));return r(),0===n.length&&n.push(e.$createParagraphNode()),n}(t.$importChildren(o,{context:_})),N=r?S:n.$propagateTextAlignToBlockChildren(S,o);return[c.splice(0,0,N)]},match:n.sel.tag("td","th"),name:"@lexical/table/cell"})],st=/* @__PURE__ */e.defineExtension({build:(e,n,o)=>t.namedSignals(n),config:/* @__PURE__ */e.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[n.CoreImportExtension,/* @__PURE__ */e.configExtension(n.DOMImportExtension,{rules:lt})],name:"@lexical/table/Table",nodes:()=>[Ye,f,i],register(n,o,r){const l=r.getOutput();return e.mergeRegister(t.effect(()=>{const t=l.hasHorizontalScroll.value;Be(n)!==t&&(ze(n,t),n.update(e.$fullReconcile))}),nt(n,l),t.effect(()=>tt(n,l.hasTabHandler.value)),t.effect(()=>l.hasCellMerge.value?void 0:et(n)),t.effect(()=>l.hasCellBackgroundColor.value?void 0:n.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),it=/* @__PURE__ */e.defineExtension({dependencies:[st],name:"@lexical/table/Import"});exports.$computeTableMap=H,exports.$computeTableMapSkipCellCheck=k,exports.$createTableCellNode=u,exports.$createTableNode=qe,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=p,exports.$createTableSelection=G,exports.$createTableSelectionFrom=J,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=A,exports.$deleteTableColumn__EXPERIMENTAL=v,exports.$deleteTableRowAtSelection=O,exports.$deleteTableRow__EXPERIMENTAL=E,exports.$findCellNode=Ee,exports.$findTableNode=Ae,exports.$getElementForTableNode=Ue,exports.$getNodeTriplet=L,exports.$getTableAndElementByKey=V,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>d(e));return d(n)?n:null},exports.$getTableCellNodeRect=z,exports.$getTableColumnIndexFromTableCellNode=function(e){return S(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=N,exports.$getTableRowIndexFromTableCellNode=function(e){const t=S(e);return N(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=S,exports.$insertTableColumn=function(t,n,o=!0,r,l){const i=t.getChildren(),a=[];for(let t=0;t<i.length;t++){const o=i[t];if(C(o))for(let t=0;t<r;t++){const t=o.getChildren();if(n>=t.length||n<0)throw new Error("Table column target index out of range");const r=t[n];d(r)||g(12);const{left:i,right:c}=b(r,l);let h=s.NO_STATUS;(i&&i.hasHeaderState(s.ROW)||c&&c.hasHeaderState(s.ROW))&&(h|=s.ROW);const f=u(h);f.append(e.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),t},exports.$insertTableColumnAtNode=M,exports.$insertTableColumnAtSelection=R,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(t,n,o=!0,r,l){const i=t.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let t=0;t<r;t++){const t=a.getChildren(),n=t.length,r=p();for(let o=0;o<n;o++){const n=t[o];d(n)||g(12);const{above:i,below:a}=b(n,l);let c=s.NO_STATUS;const h=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(s.COLUMN)||a&&a.hasHeaderState(s.COLUMN))&&(c|=s.COLUMN);const f=u(c,1,h);f.append(e.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return t},exports.$insertTableRowAtNode=y,exports.$insertTableRowAtSelection=T,exports.$insertTableRow__EXPERIMENTAL=$,exports.$isScrollableTablesActive=Be,exports.$isSimpleTable=B,exports.$isTableCellNode=d,exports.$isTableNode=Ge,exports.$isTableRowNode=C,exports.$isTableSelection=q,exports.$mergeCells=D,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!B(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$moveTableRow=function(e,t,n){if(t===n)return;const o=e.getChildren().filter(C),r=o.length;if(t<0||t>=r||n<0||n>=r)return;if(!B(e))return;const l=o[t],s=o[n];n>t?s.insertAfter(l):s.insertBefore(l)},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.$setTableColumnIsHeader=function(e,t,n){const[o]=k(e,null,null);o.length>0&&t>=0&&t<o[0].length||g(397,String(t));const r=n?s.COLUMN:s.NO_STATUS,l=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(l.has(n.cell)||(l.add(n.cell),n.cell.setHeaderStyles(r,s.COLUMN)))}},exports.$setTableRowIsHeader=function(e,t,n){const[o]=k(e,null,null);t>=0&&t<o.length||g(396,String(t));const r=o[t],l=n?s.ROW:s.NO_STATUS,i=new Set;for(let e=0;e<r.length;e++){const t=r[e];null!=t&&(i.has(t.cell)||(i.add(t.cell),t.cell.setHeaderStyles(l,s.ROW)))}},exports.$unmergeCell=function(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const n=t.anchor.getNode(),o=e.$findMatchingParent(n,d);return d(o)||g(148),I(o)},exports.$unmergeCellNode=I,exports.INSERT_TABLE_COMMAND=h,exports.TableCellHeaderStates=s,exports.TableCellNode=i,exports.TableExtension=st,exports.TableImportExtension=it,exports.TableImportRules=lt,exports.TableNode=Ye,exports.TableObserver=Z,exports.TableRowNode=f,exports.TableRowSchema=rt,exports.TableSchema=ot,exports.applyTableHandlers=he,exports.getDOMCellFromTarget=pe,exports.getTableElement=le,exports.getTableObserverFromTableElement=me,exports.registerTableCellUnmergeTransform=et,exports.registerTablePlugin=nt,exports.registerTableSelectionObserver=tt,exports.setScrollableTablesActive=ze;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{ElementNode as e,$getDocument as t,addClassNamesToElement as n,isHTMLElement as o,$isInlineElementOrDecoratorNode as l,$isTextNode as r,$isLineBreakNode as s,$createParagraphNode as i,$applyNodeReplacement as c,createCommand as a,$createTextNode as u,$getSelection as h,$isRangeSelection as d,$findMatchingParent as f,$isParagraphNode as g,$createPoint as m,$getNodeByKey as p,$isElementNode as C,$normalizeSelection__EXPERIMENTAL as _,isCurrentlyReadOnlyMode as S,TEXT_TYPE_TO_FORMAT as b,$getEditor as w,$setSelection as y,SELECTION_CHANGE_COMMAND as N,removeClassNamesFromElement as x,getDOMSelection as v,$createRangeSelection as T,$isRootNode as R,INSERT_PARAGRAPH_COMMAND as F,registerEventListener as O,KEY_ARROW_DOWN_COMMAND as A,KEY_ARROW_UP_COMMAND as K,KEY_ARROW_LEFT_COMMAND as k,KEY_ARROW_RIGHT_COMMAND as M,COMMAND_PRIORITY_HIGH as E,KEY_ESCAPE_COMMAND as $,DELETE_WORD_COMMAND as W,DELETE_LINE_COMMAND as z,DELETE_CHARACTER_COMMAND as H,KEY_BACKSPACE_COMMAND as B,KEY_DELETE_COMMAND as L,CUT_COMMAND as P,PASTE_COMMAND as D,FORMAT_TEXT_COMMAND as I,FORMAT_ELEMENT_COMMAND as U,CONTROLLED_TEXT_INSERTION_COMMAND as X,KEY_TAB_COMMAND as Y,FOCUS_COMMAND as J,$getNearestNodeFromDOMNode as q,getComposedEventTarget as j,isDOMNode as V,$isRootOrShadowRoot as G,getDOMSelectionRange as Q,getDOMSelectionPoints as Z,$getPreviousSelection as ee,$caretFromPoint as te,$isExtendableTextPointCaret as ne,$extendCaretToRange as oe,$isSiblingCaret as le,$getSiblingCaret as re,$setPointFromCaret as se,$normalizeCaret as ie,$createRangeSelectionFromDom as ce,$isChildCaret as ae,$getChildCaret as ue,$getAdjacentChildCaret as he,IS_FIREFOX as de,$getNodeByKeyOrThrow as fe,isDOMDocumentNode as ge,isDOMShadowRoot as me,setDOMStyleFromCSS as pe,setDOMUnmanaged as Ce,mergeRegister as _e,COMMAND_PRIORITY_EDITOR as Se,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as be,SELECT_ALL_COMMAND as we,COMMAND_PRIORITY_LOW as ye,CLICK_COMMAND as Ne,$getRoot as xe,isHTMLTableRowElement as ve,IS_BOLD as Te,IS_ITALIC as Re,IS_UNDERLINE as Fe,IS_STRIKETHROUGH as Oe,defineExtension as Ae,$fullReconcile as Ke,configExtension as ke,safeCast as Me}from"lexical";import{signal as Ee,effect as $e,namedSignals as We}from"@lexical/extension";import{defineImportRule as ze,sel as He,ImportTextFormat as Be,ImportTextStyle as Le,contextValue as Pe,$propagateTextAlignToBlockChildren as De,CoreImportExtension as Ie,DOMImportExtension as Ue}from"@lexical/html";import{$descendantsMatching as Xe,objectKlassEquals as Ye,$insertFirst as Je,$insertNodeToNearestRoot as qe,$dfs as je,$unwrapAndFilterDescendants as Ve}from"@lexical/utils";import{copyToClipboard as Ge,$getClipboardDataFromSelection as Qe}from"@lexical/clipboard";const Ze=/^(\d+(?:\.\d+)?)px$/,et={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class tt extends e{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new tt(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:ot,priority:0}),th:e=>({conversion:ot,priority:0})}}static importJSON(e){return lt().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=et.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(e){const o=t().createElement(this.getTag());return this.__width&&(o.style.width=`${this.__width}px`),this.__colSpan>1&&(o.colSpan=this.__colSpan),this.__rowSpan>1&&(o.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(o.style.backgroundColor=this.__backgroundColor),nt(this.__verticalAlign)&&(o.style.verticalAlign=this.__verticalAlign),n(o,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader),o}exportDOM(e){const t=super.exportDOM(e);if(o(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...nt(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=et.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==et.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function nt(e){return"middle"===e||"bottom"===e}function ot(e){const t=e,n=e.nodeName.toLowerCase();let c;Ze.test(t.style.width)&&(c=parseFloat(t.style.width));let a=et.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)a=et.COLUMN;else if("row"===e)a=et.ROW;else{const e=t.parentElement,n=o(e)&&"tr"===e.nodeName.toLowerCase()&&o(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),l=0===t.cellIndex;n&&(a|=et.ROW),l&&(a|=et.COLUMN),a===et.NO_STATUS&&(a=et.ROW)}}const u=lt(a,t.colSpan,c);u.__rowSpan=t.rowSpan;const h=t.style.backgroundColor;""!==h&&(u.__backgroundColor=h);const d=t.style.verticalAlign;nt(d)&&(u.__verticalAlign=d);const f=t.style,g=(f&&f.textDecoration||"").split(" "),m="700"===f.fontWeight||"bold"===f.fontWeight,p=g.includes("line-through"),C="italic"===f.fontStyle,_=g.includes("underline"),S=f.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)if(l(c)||r(c)||s(c)){if(r(c)&&(m&&c.toggleFormat("bold"),p&&c.toggleFormat("strikethrough"),C&&c.toggleFormat("italic"),_&&c.toggleFormat("underline"),S)){const e=c.getStyle();e.includes("color:")||c.setStyle(e+`color: ${S};`)}n?n.append(c):(n=i().append(c),t.push(n))}else t.push(c),o(),n=null;return o(),0===t.length&&t.push(i()),t},node:u}}function lt(e=et.NO_STATUS,t=1,n){return c(new tt(e,t,n))}function rt(e){return e instanceof tt}const st=/* @__PURE__ */a("INSERT_TABLE_COMMAND");function it(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class ct extends e{__height;static getType(){return"tablerow"}static clone(e){return new ct(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:at,priority:0})}}static importJSON(e){return ut().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(e){const o=t().createElement("tr");return this.__height&&(o.style.height=`${this.__height}px`),n(o,e.theme.tableRow),o}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 at(e){const t=e;let n;return Ze.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>Xe(e,rt),node:ut(n)}}function ut(e){return c(new ct(e))}function ht(e){return e instanceof ct}function dt(e,t,n=!0){const o=eo();for(let l=0;l<e;l++){const e=ut();for(let o=0;o<t;o++){let t=et.NO_STATUS;"object"==typeof n?(0===l&&n.rows&&(t|=et.ROW),0===o&&n.columns&&(t|=et.COLUMN)):n&&(0===l&&(t|=et.ROW),0===o&&(t|=et.COLUMN));const r=lt(t),s=i();s.append(u()),r.append(s),e.append(r)}o.append(e)}return o}function ft(e){const t=f(e,e=>rt(e));return rt(t)?t:null}function gt(e){const t=f(e,e=>ht(e));if(ht(t))return t;throw new Error("Expected table cell to be inside of table row.")}function mt(e){const t=f(e,e=>to(e));if(to(t))return t;throw new Error("Expected table cell to be inside of table.")}function pt(e){const t=gt(e);return mt(t).getChildren().findIndex(e=>e.is(t))}function Ct(e){return gt(e).getChildren().findIndex(t=>t.is(e))}function _t(e,t){const n=mt(e),{x:o,y:l}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,l-1,t),below:n.getCellNodeFromCords(o,l+1,t),left:n.getCellNodeFromCords(o-1,l,t),right:n.getCellNodeFromCords(o+1,l,t)}}function St(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function bt(e,t,n=!0,o,l){const r=e.getChildren();if(t>=r.length||t<0)throw new Error("Table row target index out of range");const s=r[t];if(!ht(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=ut();for(let n=0;n<t;n++){const t=e[n];rt(t)||it(12);const{above:r,below:s}=_t(t,l);let c=et.NO_STATUS;const a=r&&r.getWidth()||s&&s.getWidth()||void 0;(r&&r.hasHeaderState(et.COLUMN)||s&&s.hasHeaderState(et.COLUMN))&&(c|=et.COLUMN);const u=lt(c,1,a);u.append(i()),o.append(u)}n?s.insertAfter(o):s.insertBefore(o)}return e}const wt=(e,t)=>e===et.BOTH||e===t?t:et.NO_STATUS;function yt(e=!0){const t=h();d(t)||Zt(t)||it(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[l]=Dt(n),[r,,s]=Dt(o),[,i,c]=Lt(s,r,l),{startRow:a}=c,{startRow:u}=i;return e?xt(a+l.__rowSpan>u+r.__rowSpan?l:r,!0):xt(u<a?r:l,!1)}const Nt=yt;function xt(e,t=!0){const[,,n]=Dt(e),[o,l]=Lt(n,e,e),r=o[0].length,{startRow:s}=l;let c=null;if(t){const t=s+e.__rowSpan-1,l=o[t],a=ut();for(let e=0;e<r;e++){const{cell:n,startRow:o}=l[e];if(o+n.__rowSpan-1<=t){const t=l[e].cell.__headerState,n=wt(t,et.COLUMN);a.append(lt(n).append(i()))}else n.setRowSpan(n.__rowSpan+1)}const u=n.getChildAtIndex(t);ht(u)||it(256),u.insertAfter(a),c=a}else{const e=s,t=o[e],l=ut();for(let n=0;n<r;n++){const{cell:o,startRow:r}=t[n];if(r===e){const e=t[n].cell.__headerState,o=wt(e,et.COLUMN);l.append(lt(o).append(i()))}else o.setRowSpan(o.__rowSpan+1)}const a=n.getChildAtIndex(e);ht(a)||it(257),a.insertBefore(l),c=l}return c}function vt(e,t,n=!0,o,l){const r=e.getChildren(),s=[];for(let e=0;e<r.length;e++){const n=r[e];if(ht(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];rt(o)||it(12);const{left:r,right:c}=_t(o,l);let a=et.NO_STATUS;(r&&r.hasHeaderState(et.ROW)||c&&c.hasHeaderState(et.ROW))&&(a|=et.ROW);const u=lt(a);u.append(i()),s.push({newTableCell:u,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function Tt(e=!0){const t=h();d(t)||Zt(t)||it(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[l]=Dt(n),[r,,s]=Dt(o),[,i,c]=Lt(s,r,l),{startColumn:a}=c,{startColumn:u}=i;return e?Ft(a+l.__colSpan>u+r.__colSpan?l:r,!0):Ft(u<a?r:l,!1)}const Rt=Tt;function Ft(e,t=!0,n=!0){const[,,o]=Dt(e),[l,r]=Lt(o,e,e),s=l.length,{startColumn:c}=r,a=t?c+e.__colSpan-1:c-1,u=o.getFirstChild();ht(u)||it(120);let h=null;function d(e=et.NO_STATUS){const t=lt(e).append(i());return null===h&&(h=t),t}let f=u;e:for(let e=0;e<s;e++){if(0!==e){const e=f.getNextSibling();ht(e)||it(121),f=e}const t=l[e],n=t[a<0?0:a].cell.__headerState,o=wt(n,et.ROW);if(a<0){$t(f,d(o));continue}const{cell:r,startColumn:s,startRow:i}=t[a];if(s+r.__colSpan-1<=a){let n=r,l=i,s=a;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){f.append(d(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(d(o))}else r.setColSpan(r.__colSpan+1)}null!==h&&n&&Et(h);const g=o.getColWidths();if(g){const e=[...g],t=a<0?0:a,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return h}function Ot(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ht(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function At(){const e=h();d(e)||Zt(e)||it(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,l]=Dt(t),[r]=Dt(n),[s,i,c]=Lt(l,o,r),{startRow:a}=i,{startRow:u}=c,f=u+r.__rowSpan-1;if(s.length===f-a+1)return void l.remove();const g=s[0].length,m=s[f+1],p=l.getChildAtIndex(f+1);for(let e=f;e>=a;e--){for(let t=g-1;t>=0;t--){const{cell:n,startRow:o,startColumn:l}=s[e][t];if(l===t){if(o<a||o+n.__rowSpan-1>f){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,f),l=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-l)}if(o>=a&&o+n.__rowSpan-1>f&&e===f){ht(p)||it(387);let o=null;for(let n=0;n<t;n++){const t=m[n],l=t.cell;t.startRow===e+1&&(o=l),l.__colSpan>1&&(n+=l.__colSpan-1)}null===o?$t(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);ht(t)||it(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Et(e)}else{const e=s[a-1],{cell:t}=e[0];Et(t)}}const Kt=At;function kt(){const e=h();d(e)||Zt(e)||it(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,l]=Dt(t),[r]=Dt(n),[s,i,c]=Lt(l,o,r),{startColumn:a}=i,{startRow:u,startColumn:f}=c,g=Math.min(a,f),m=Math.max(a+o.__colSpan-1,f+r.__colSpan-1),p=m-g+1;if(s[0].length===m-g+1)return l.selectPrevious(),void l.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=g;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<g){if(t===g){const e=g-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[u],S=a>f?_[a+o.__colSpan]:_[f+r.__colSpan];if(void 0!==S){const{cell:e}=S;Et(e)}else{const e=f<a?_[f-1]:_[a-1],{cell:t}=e;Et(t)}const b=l.getColWidths();if(b){const e=[...b];e.splice(g,p),l.setColWidths(e)}}const Mt=kt;function Et(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function $t(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Wt(e){if(0===e.length)return null;const t=mt(e[0]),[n]=Pt(t,null,null);let o=1/0,l=-1/0,r=1/0,s=-1/0;const c=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!c.has(t)&&e.some(e=>e.is(n.cell))){c.add(t);const e=n.startRow,i=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),l=Math.max(l,e+a-1),r=Math.min(r,i),s=Math.max(s,i+u-1)}}if(o===1/0||r===1/0)return null;const a=l-o+1,u=s-r+1,h=n[o][r];if(!h.cell)return null;const d=h.cell;d.setColSpan(u),d.setRowSpan(a);const f=new Set([d.getKey()]);for(let e=o;e<=l;e++)for(let t=r;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const l=o.cell,r=l.getKey();if(!f.has(r)){f.add(r);zt(l)||d.append(...l.getChildren()),l.remove()}}return 0===d.getChildrenSize()&&d.append(i()),d}function zt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!g(t)||!t.isEmpty())}function Ht(){const e=h();d(e)||Zt(e)||it(188);const t=e.anchor.getNode(),n=f(t,rt);return rt(n)||it(148),Bt(n)}function Bt(e){const[t,n,o]=Dt(e),l=t.__colSpan,r=t.__rowSpan;if(1===l&&1===r)return;const[s,c]=Lt(o,t,t),{startColumn:a,startRow:u}=c,h=t.__headerState&et.COLUMN,d=Array.from({length:l},(e,t)=>{let n=h;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+a].cell.__headerState;return n}),f=t.__headerState&et.ROW,g=Array.from({length:r},(e,t)=>{let n=f;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+u][e].cell.__headerState;return n});if(l>1){for(let e=1;e<l;e++)t.insertAfter(lt(d[e]|g[0]).append(i()));t.setColSpan(1)}if(r>1){let e;for(let t=1;t<r;t++){const o=u+t,r=s[o];e=(e||n).getNextSibling(),ht(e)||it(125);let c=null;for(let e=0;e<a;e++){const t=r[e],n=t.cell;t.startRow===o&&(c=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===c)for(let n=l-1;n>=0;n--)$t(e,lt(d[n]|g[t]).append(i()));else for(let e=l-1;e>=0;e--)c.insertAfter(lt(d[e]|g[t]).append(i()))}t.setRowSpan(1)}}function Lt(e,t,n){const[o,l,r]=Pt(e,t,n);return null===l&&it(207),null===r&&it(208),[o,l,r]}function Pt(e,t,n){const o=[];let l=null,r=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];ht(o)||it(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(rt(a)||it(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===l&&t.is(a)&&(l=o),null!==n&&null===r&&n.is(a)&&(r=o)}}return[o,l,r]}function Dt(e){let t;if(e instanceof tt)t=e;else if("__type"in e){const n=f(e,rt);rt(n)||it(148),t=n}else{const n=f(e.getNode(),rt);rt(n)||it(148),t=n}const n=t.getParent();ht(n)||it(149);const o=n.getParent();return to(o)||it(210),[t,n,o]}function It(e,t,n){let o,l=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=l,d=c.startRow<=i&&u>=r;if(h&&d){const e=Math.min(l,c.startColumn),t=Math.max(s,a),n=Math.min(r,c.startRow),h=Math.max(i,u);e===l&&t===s&&n===r&&h===i||(l=e,s=t,r=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:l,minRow:r}}function Ut(e){const t=e.getChildren();let n=null;for(const e of t){if(!ht(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!rt(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function Xt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Ut(e))return;e.getChildren().filter(ht).forEach(e=>{const o=e.getChildren(),[l]=o.splice(t,1);o.splice(n,0,l),e.splice(0,o.length,o)});const l=e.getColWidths();if(l&&l.length===o){const o=[...l],[r]=o.splice(t,1);o.splice(n,0,r),e.setColWidths(o)}}function Yt(e,t,n){if(t===n)return;const o=e.getChildren().filter(ht),l=o.length;if(t<0||t>=l||n<0||n>=l)return;if(!Ut(e))return;const r=o[t],s=o[n];n>t?s.insertAfter(r):s.insertBefore(r)}function Jt(e){const[t,,n]=Dt(e),o=n.getChildren().filter(ht),l=o.length,r=o[0].getChildren().length,s=new Array(l);for(let e=0;e<l;e++)s[e]=new Array(r);for(let e=0;e<l;e++){const n=o[e].getChildren().filter(rt);let l=0;for(let o=0;o<n.length;o++){for(;s[e][l];)l++;const r=n[o],i=r.__rowSpan||1,c=r.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][l+n]=r;if(t===r)return{colSpan:c,columnIndex:l,rowIndex:e,rowSpan:i};l+=c}}return null}function qt(e,t){const n=t.getStartEndPoints(),o=Zt(t);if(null===n)return!1;const[l,s]=n,[c,a,u]=Dt(l),h=f(s.getNode(),e=>rt(e));if(!(rt(c)&&rt(h)&&ht(a)&&to(u)))return!1;const[d,g,m]=Lt(u,c,h),[p]=Pt(e,null,null),C=d.length,_=C>0?d[0].length:0;let S=g.startRow,b=g.startColumn,w=p.length,y=w>0?p[0].length:0;if(o){const e=It(d,g,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let N=!1;const x=Math.min(C,S+w)-1,v=Math.min(_,b+y)-1,T=new Set;for(let e=S;e<=x;e++)for(let t=b;t<=v;t++){const n=d[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(Bt(n.cell),T.add(n.cell.getKey()),N=!0))}let[R]=Pt(u.getWritable(),null,null);const F=w-C+S;for(let e=0;e<F;e++){xt(R[C-1][0].cell)}const O=y-_+b;for(let e=0;e<O;e++){Ft(R[0][_-1].cell,!0,!1)}[R]=Pt(u.getWritable(),null,null);for(let e=S;e<S+w;e++)for(let t=b;t<b+y;t++){const n=e-S,o=t-b,l=p[n][o];if(l.startRow!==n||l.startColumn!==o)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const n=[],o=Math.min(e+s.__rowSpan,S+w)-1,l=Math.min(t+s.__colSpan,b+y)-1;for(let r=e;r<=o;r++)for(let e=t;e<=l;e++){const t=R[r][e];n.push(t.cell)}Wt(n),N=!0}const{cell:c}=R[e][t],a=s.getBackgroundColor();null!=a&&c.setBackgroundColor(a);const u=c.getChildren();s.getChildren().forEach(e=>{if(r(e)){i().append(e),c.append(e)}else c.append(e)}),u.forEach(e=>e.remove())}if(o&&N){const[e]=Pt(u.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function jt(e,t,n){const[o]=Pt(e,null,null);t>=0&&t<o.length||it(396,String(t));const l=o[t],r=n?et.ROW:et.NO_STATUS,s=new Set;for(let e=0;e<l.length;e++){const t=l[e];null!=t&&(s.has(t.cell)||(s.add(t.cell),t.cell.setHeaderStyles(r,et.ROW)))}}function Vt(e,t,n){const[o]=Pt(e,null,null);o.length>0&&t>=0&&t<o[0].length||it(397,String(t));const l=n?et.COLUMN:et.NO_STATUS,r=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(r.has(n.cell)||(r.add(n.cell),n.cell.setHeaderStyles(l,et.COLUMN)))}}function Gt(e){const[[t,n,o,l],[r,s,i,c]]=["anchor","focus"].map(t=>{const n=e[t].getNode(),o=f(n,rt);rt(o)||it(238,t,n.getKey(),n.getType());const l=o.getParent();ht(l)||it(239,t);const r=l.getParent();return to(r)||it(240,t),[n,o,l,r]});return l.is(c)||it(241),{anchorCell:n,anchorNode:t,anchorRow:o,anchorTable:l,focusCell:s,focusNode:r,focusRow:i,focusTable:c}}class Qt{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=p(this.tableKey),t=p(this.anchor.key),n=p(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Zt(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 Qt(this.tableKey,m(this.anchor.key,this.anchor.offset,this.anchor.type),m(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){if(""===e)return;const t=(e.endsWith("\n")?e.slice(0,-1):e).split("\n").map(e=>e.split("\t")),n=eo();for(const e of t){const t=ut();for(const n of e){const e=lt(et.NO_STATUS),o=i();n&&o.append(u(n)),e.append(o),t.append(e)}n.append(t)}const{anchorCell:o}=Gt(this);qt(n,o.select(0,o.getChildrenSize()))}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(rt).forEach(e=>{const n=e.getFirstChild();g(n)&&(t|=n.getTextFormat())});const n=b[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();C(t)||it(151);_(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Gt(this),n=Jt(e);null===n&&it(153);const o=Jt(t);null===o&&it(155);const l=Math.min(n.columnIndex,o.columnIndex),r=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(l,r),fromY:Math.min(s,i),toX:Math.max(l,r),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Gt(this),l=o.getParents()[1];if(l!==t){if(t.isParentOf(o)){const e=l.getParent();null==e&&it(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&it(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[r,s,i]=Lt(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=It(r,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=r[e][t],o=n.getParent();ht(o)||it(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||nn(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return S()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>rt(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],l=o.__parent,r=(e[n+1]||{}).__parent;t+=o.getTextContent()+(r!==l?"\n":"\t")}return t}}function Zt(e){return e instanceof Qt}function en(){const e=m("root",0,"element"),t=m("root",0,"element");return new Qt("root",e,t)}function tn(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=h(),l=Zt(o)?o.clone():en();return l.set(e.getKey(),t.getKey(),n.getKey()),l}function nn(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&C(o)&&n.push(o.getChildren())}}function on(e,t=w()){const n=p(e);to(n)||it(231,e);const o=dn(n,t.getElementByKey(e));return null===o&&it(232,e),{tableElement:o,tableNode:n}}class ln{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return void 0!==t&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const e=[];for(const[t,[n]]of Array.from(this.observers.entries())){const o=p(t);to(o)?e.push([o,n]):this.removeObserver(t)}return e}}class rn{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return on(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.read("latest",()=>{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=vn(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=vn(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(e=!0){const t=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();Tn(t,vn(n,o),null),e&&null!==h()&&(y(null),t.dispatchCommand(N,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();x(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:e}=this.$lookup();n(e,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&it(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Tn(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=v(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),l=e.x,r=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==l||this.anchorY!==r||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&r===this.focusY)return!1;if(this.focusX=l,this.focusY=r,this.isHighlightingCells){const s=Xn(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(l,r,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=tn(o,t,e),y(this.tableSelection),n.dispatchCommand(N,void 0),Tn(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const e=this.anchorCellNodeKey?p(this.anchorCellNodeKey):null;return rt(e)?e:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&it(234),e}$getFocusTableCell(){const e=this.focusCellNodeKey?p(this.focusCellNodeKey):null;return rt(e)?e:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&it(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=Xn(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=tn(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=h();Zt(t)||it(236);const n=T(),o=n.anchor,l=n.focus,r=t.getNodes().filter(rt);r.length>0||it(237);const s=r[0].getFirstChild(),i=g(s)?s.getFormatFlags(e,null):null;r.forEach(t=>{o.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),y(t),this.editor.dispatchCommand(N,void 0)}$clearText(){const{editor:e}=this,t=p(this.tableNodeKey);if(!to(t))throw new Error("Expected TableNode.");const n=h();Zt(n)||it(253);const o=n.getNodes().filter(rt),l=t.getFirstChild(),r=t.getLastChild();if(o.length>0&&null!==l&&null!==r&&ht(l)&&ht(r)&&o[0]===l.getFirstChild()&&o[o.length-1]===r.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(R(n)&&n.isEmpty()&&e.dispatchCommand(F,void 0))}o.forEach(e=>{if(C(e)){const t=i(),n=u();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),Tn(e,this.table,null),y(null),e.dispatchCommand(N,void 0)}}const sn="__lexicalTableSelection";function cn(e){const t=fe(e);return to(t)||it(386,e),t}const an=40;function un(e,t,n){const o=e=>Math.max(1,Math.ceil(Math.min(an,e)/an*18));return e<=t+an?-o(t+an-e):e>=n-an?o(e-(n-an)):0}function hn(e){return o(e)&&"TABLE"===e.nodeName}function dn(e,t){if(!t)return t;const n=hn(t)?t:t.querySelector("table");return hn(n)||it(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function fn(e){return e._window}function gn(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;rt(n)&&(o=n)}return null}const mn=[[A,"down"],[K,"up"],[k,"backward"],[M,"forward"]],pn=[W,z,H],Cn=[B,L];function _n(e,t){return e.registerRootListener(n=>{if(null===n)return;const o=e._window;if(null===o)return;return O(o,"pointerdown",o=>{const l=j(o);if(0!==o.button||!V(l)||!n.contains(l))return;const r=function(e){const t=Nn(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&sn in n&&n[sn])return{cellElement:t,tableElement:n,tableObserver:n[sn]};n=n.parentNode}return null}(l);e.update(()=>{if(Zt(h())){for(const[e]of t.observers.values())e.$clearHighlight(!1);y(null),e.dispatchCommand(N,void 0)}if(!r)return;const{tableObserver:n,tableElement:l,cellElement:s}=r;!function(e,t,n,o,l,r){const s=e._window;if(!s)return;const i=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});let i=t.clientX,c=t.clientY,a=null;const u=()=>{l.isSelecting=!1,null!==a&&(s.cancelAnimationFrame(a),a=null),s.removeEventListener("pointerup",S),s.removeEventListener("pointermove",b)},h=(e,t)=>{const n=o.getRootNode();if(!ge(n)&&!me(n))return null;for(const l of n.elementsFromPoint(e,t)){const e=xn(o,l);if(e)return e}return null},d=(t,n)=>{null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(t)}),null!==l.focusCell&&t.elem===l.focusCell.elem||(r.setNextFocus({focusCell:t,override:n,tableKey:l.tableNodeKey}),e.dispatchCommand(N,void 0))},f=e=>{for(let t=o.parentElement;t;t=t.parentElement){if("x"===e?t.scrollWidth>t.clientWidth:t.scrollHeight>t.clientHeight){const n=s.getComputedStyle(t),o="x"===e?n.overflowX:n.overflowY;if("auto"===o||"scroll"===o)return t}}return null},g=(e,t,n)=>{let o,l;if(null===e)o=0,l="x"===n?s.innerWidth:s.innerHeight;else{const t=e.getBoundingClientRect();o="x"===n?t.left:t.top,l="x"===n?t.right:t.bottom}const r=un(t,o,l);if(0===r)return!1;if(null===e){const e="x"===n?s.scrollX:s.scrollY;return s.scrollBy("x"===n?r:0,"x"===n?0:r),("x"===n?s.scrollX:s.scrollY)!==e}if("x"===n){const t=e.scrollLeft;return e.scrollLeft+=r,e.scrollLeft!==t}const i=e.scrollTop;return e.scrollTop+=r,e.scrollTop!==i},m=(e,t)=>{let n=i,o=c;if(null===e)n=Math.min(Math.max(n,1),s.innerWidth-1);else{const t=e.getBoundingClientRect();n=Math.min(Math.max(n,t.left+1),t.right-1)}if(null===t)o=Math.min(Math.max(o,1),s.innerHeight-1);else{const e=t.getBoundingClientRect();o=Math.min(Math.max(o,e.top+1),e.bottom-1)}return[n,o]},p=()=>{const e=f("x");if(null!==e){const t=e.getBoundingClientRect();if(0!==un(i,t.left,t.right))return!0}const t=f("y"),n=null===t?0:t.getBoundingClientRect().top,o=null===t?s.innerHeight:t.getBoundingClientRect().bottom;return 0!==un(c,n,o)},C=()=>{if(a=null,!l.isSelecting)return;const e=f("x"),t=f("y"),n=null!==e&&g(e,i,"x"),o=g(t,c,"y");if(n||o){const[n,o]=m(e,t),l=h(n,o);l&&d(l,!1),a=s.requestAnimationFrame(C)}},_=()=>{null===a&&"touch"!==l.pointerType&&p()&&(a=s.requestAnimationFrame(C))},S=()=>{u()},b=e=>{if(!(e=>!(1&~e.buttons))(e)&&l.isSelecting)return void u();const t=j(e);if(!V(t))return;i=e.clientX,c=e.clientY;let n=null;const r=!(de||o.contains(t));n=r?xn(o,t):h(e.clientX,e.clientY),n&&d(n,r),_()};s.addEventListener("pointerup",S,l.listenerOptions),s.addEventListener("pointermove",b,l.listenerOptions)};l.pointerType=t.pointerType;const c=cn(l.tableNodeKey),a=ee();if(de&&t.shiftKey&&Mn(a,c)&&(d(a)||Zt(a))){const e=a.anchor.getNode(),o=gn(c,a.anchor.getNode());if(o)l.$setAnchorCellForSelection(Un(l,o)),l.$setFocusCellForSelection(n),Pn(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&l.$setAnchorCellForSelection(n);i(n)}(e,o,s,l,n,t)})})})}function Sn(e,t,n,o,l){const r=n.getRootElement(),s=fn(n);null!==r&&null!==s||it(246);const i=new rn(n,e.getKey()),c=dn(e,t);!function(e,t){null!==yn(e)&&it(205);e[sn]=t}(c,i),i.listenersToRemove.add(()=>function(e,t){yn(e)===t&&delete e[sn]}(c,i));i.listenersToRemove.add(O(c,"mousedown",e=>{const t=j(e);if(e.detail>=3&&V(t)){null!==Nn(t)&&e.preventDefault()}},i.listenerOptions));for(const[t,o]of mn)i.listenersToRemove.add(n.registerCommand(t,t=>Ln(n,t,o,e,i,l),E));i.listenersToRemove.add(n.registerCommand($,t=>{const n=h();if(Zt(n)){const o=gn(e,n.focus.getNode());if(null!==o)return Pn(t),o.selectEnd(),!0}return!1},E));const a=t=>()=>{const n=h();if(!Mn(n,e))return!1;if(Zt(n))return i.$clearText(),!0;if(d(n)){if(!rt(gn(e,n.anchor.getNode())))return!1;const o=n.anchor.getNode(),l=n.focus.getNode(),r=e.isParentOf(o),s=e.isParentOf(l);if(r&&!s||s&&!r)return i.$clearText(),!0;const c=f(n.anchor.getNode(),e=>C(e)),a=c&&f(c,e=>C(e)&&rt(e.getParent()));if(!C(a)||!C(c))return!1;if(t===z&&null===a.getPreviousSibling())return!0}return!1};for(const e of pn)i.listenersToRemove.add(n.registerCommand(e,a(e),E));const g=t=>{const n=h();if(!Zt(n)&&!d(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",l=o?"focus":"anchor",{key:r,offset:s,type:i}=n[l];return e[n[t].isBefore(n[l])?"selectPrevious":"selectNext"]()[l].set(r,s,i),!1}return!!Mn(n,e)&&(!!Zt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),i.$clearText(),!0))};for(const e of Cn)i.listenersToRemove.add(n.registerCommand(e,g,E));i.listenersToRemove.add(n.registerCommand(P,e=>{const t=h();if(t){if(!Zt(t)&&!d(t))return!1;Ge(n,Ye(e,ClipboardEvent)?e:null,Qe(t));const o=g(e);return d(t)?(t.removeText(),!0):o}return!1},E));const m=r.ownerDocument;return i.listenersToRemove.add(O(m,"paste",t=>{if(t.defaultPrevented)return;n.read("latest",()=>{const t=h();return r.contains(m.activeElement)&&Zt(t)&&Mn(t,e)})&&(t.preventDefault(),n.dispatchCommand(D,t))})),i.listenersToRemove.add(n.registerCommand(I,t=>{const n=h();if(!Mn(n,e))return!1;if(Zt(n))return i.$formatCells(t),!0;if(d(n)){const e=f(n.anchor.getNode(),e=>rt(e));if(!rt(e))return!1}return!1},E)),i.listenersToRemove.add(n.registerCommand(U,t=>{const n=h();if(!Zt(n)||!Mn(n,e))return!1;const o=n.anchor.getNode(),l=n.focus.getNode();if(!rt(o)||!rt(l))return!1;if(function(e,t){if(Zt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Lt(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[r,s,i]=Lt(e,o,l),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),d=Math.min(s.startColumn,i.startColumn),f=new Set;for(let e=u;e<=c;e++)for(let n=d;n<=a;n++){const o=r[e][n].cell;if(f.has(o))continue;f.add(o),o.setFormat(t);const l=o.getChildren();for(let e=0;e<l.length;e++){const n=l[e];C(n)&&!n.isInline()&&n.setFormat(t)}}return!0},E)),i.listenersToRemove.add(n.registerCommand(X,t=>{const o=h();if(!Mn(o,e))return!1;if(Zt(o))return i.$clearHighlight(),!1;if(d(o)){const l=f(o.anchor.getNode(),e=>rt(e));if(!rt(l))return!1;if("string"==typeof t){const l=In(n,o,e);if(l)return Dn(l,e,[u(t)]),!0}}return!1},E)),o&&i.listenersToRemove.add(n.registerCommand(Y,t=>{const n=h();if(!d(n)||!n.isCollapsed()||!Mn(n,e))return!1;const o=zn(n.anchor.getNode());return!(null===o||!e.is(Hn(o)))&&(Pn(t),function(e,t){const n="next"===t?"getNextSibling":"getPreviousSibling",o="next"===t?"getFirstChild":"getLastChild",l=e[n]();if(C(l))return l.selectEnd();const r=f(e,ht);null===r&&it(247);for(let e=r[n]();ht(e);e=e[n]()){const t=e[o]();if(C(t))return t.selectEnd()}const s=f(r,to);null===s&&it(248);"next"===t?s.selectNext():s.selectPrevious()}(o,t.shiftKey?"previous":"next"),!0)},E)),i.listenersToRemove.add(n.registerCommand(J,t=>e.isSelected(),E)),i.listenersToRemove.add(n.registerCommand(F,()=>{const t=h();if(!d(t)||!t.isCollapsed()||!Mn(t,e))return!1;const o=In(n,t,e);return!!o&&(Dn(o,e),!0)},E)),i}function bn(e,t){const n=h(),o=ee(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:o}=l,r=e.observers.get(t);r||it(335,t);const[s]=r;if(Zt(n)&&n.tableKey===s.tableNodeKey)return(o.x!==s.focusX||o.y!==s.focusY)&&(s.$setFocusCellForSelection(o),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&o.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(o,!0),!0}const r=e.getAndClearShouldCheckSelectionForTable();if(r&&d(o)&&d(n)&&n.isCollapsed()){const e=p(r);if(to(e)){const t=n.anchor.getNode(),o=e.getFirstChild(),l=zn(t);if(null!==l&&ht(o)){const t=o.getFirstChild();if(rt(t)&&e.is(f(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}}Zt(n)&&function(e,t){const n=fn(e),o=ee();if(!t.is(o))return;const l=cn(t.tableKey),r=v(n),s=r&&Z(r,e.getRootElement());if(r&&s&&s.anchorNode&&s.focusNode){const n=q(s.focusNode),o=n&&!l.isParentOf(n),i=q(s.anchorNode),c=i&&l.isParentOf(i);if(o&&c&&r.rangeCount>0){const n=ce(r,e);n&&(n.anchor.set(l.getKey(),t.isBackward()?l.getChildrenSize():0,"element"),r.removeAllRanges(),y(n))}}}(t,n),d(n)&&function(e,t){const n=ee(),{anchor:o,focus:l}=e,r=o.getNode(),s=l.getNode(),i=zn(r),c=zn(s),a=i?Hn(i):null,u=c?Hn(c):null,h=e.isBackward(),f=i&&c&&a&&u&&a.is(u),g=u&&(!a||a.isParentOf(u)),m=a&&(!u||u.isParentOf(a));if(g){const t=e.clone(),[n]=Lt(u,c,c),o=n[0][0].cell,l=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),y(t)}else if(m){const t=e.clone(),[n]=Lt(a,i,i),o=n[0][0].cell,l=n[n.length-1].at(-1).cell;t.anchor.set(h?l.getKey():o.getKey(),h?l.getChildrenSize():0,"element"),y(t)}else if(f){const o=t.observers.get(a.getKey());o||it(335,a.getKey());const[l]=o;if(i.is(c)||(l.$setAnchorCellForSelection(Un(l,i)),l.$setFocusCellForSelection(Un(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&d(n)&&n.isCollapsed()){const e=zn(n.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Un(l,e)),l.$setFocusCellForSelection(Un(l,c),!0),l.pointerType=null)}}}(n,e);for(const[n,o]of e.$getTableNodesAndObservers())wn(t,n,o);return!1}function wn(e,t,n){const o=h(),l=ee();o&&!o.is(l)&&(Zt(o)||Zt(l))&&n.tableSelection&&!n.tableSelection.is(l)&&(Zt(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Zt(o)&&Zt(l)&&l.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),Rn(t.table,t=>{const n=t.elem;t.highlighted=!1,Wn(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),Rn(t.table,t=>{t.highlighted=!0,$n(e,t)})}(e,n)}function yn(e){return e[sn]||null}function Nn(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 xn(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function vn(e,t){const n=[],o={columns:0,domRows:n,rows:0};let l=dn(e,t).querySelector("tr"),r=0,s=0;for(n.length=0;null!=l;){const e=l.nodeName;if("TD"===e||"TH"===e){const e={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:r,y:s};l._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[r]=e}else{const e=l.firstChild;if(null!=e){l=e;continue}}const t=l.nextSibling;if(null!=t){r++,l=t;continue}const o=l.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,r=0,l=e}}return o.columns=r+1,o.rows=s+1,o}function Tn(e,t,n){const o=new Set(n?n.getNodes():[]);Rn(t,(t,n)=>{const l=t.elem;o.has(n)?(t.highlighted=!0,$n(e,t)):(t.highlighted=!1,Wn(e,t),l.getAttribute("style")||l.removeAttribute("style"))})}function Rn(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const l=o[n];if(!l)continue;const r=q(l.elem);null!==r&&t(l,r,{x:n,y:e})}}}const Fn=(e,t,n,o,l)=>{const r="forward"===l;switch(l){case"backward":case"forward":return n!==(r?e.table.columns-1:0)?En(t.getCellNodeFromCordsOrThrow(n+(r?1:-1),o,e.table),r):o!==(r?e.table.rows-1:0)?En(t.getCellNodeFromCordsOrThrow(r?0:e.table.columns-1,o+(r?1:-1),e.table),r):r?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?En(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?En(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function On(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 An([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Kn(e,t,[n,o]){const l=t[o],r=e[l];void 0===r&&it(250,o,String(l));const s=t[n],i=r[s];return void 0===i&&it(250,n,String(s)),i}function kn(e,t,n,o,l){const r=It(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:l,maxRow:r}=t;let s=1,i=1,c=1,a=1;const u=e[l],h=e[r];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=l;t<=r;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,r),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=On(e,t);return null===n&&it(249,t.cell.getKey()),n}(r,n),[d,f]=An(h);let g=r[d],m=r[f];"forward"===l?g+="maxColumn"===d?1:c:"backward"===l?g-="minColumn"===d?1:u:"down"===l?m+="maxRow"===f?1:i:"up"===l&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=It(e,t,n),l=On(o,t);if(l)return[Kn(e,o,l),Kn(e,o,An(l))];const r=On(o,n);if(r)return[Kn(e,o,An(r)),Kn(e,o,r)];const s=["minColumn","minRow"];return[Kn(e,o,s),Kn(e,o,An(s))]}(t,n,C),b=Un(e,_.cell),w=Un(e,S.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function Mn(e,t){if(d(e)||Zt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function En(e,t){t?e.selectStart():e.selectEnd()}function $n(e,t){const o=t.elem,l=e._config.theme;rt(q(o))||it(131),n(o,l.tableCellSelected)}function Wn(e,t){const n=t.elem;rt(q(n))||it(131);const o=e._config.theme;x(n,o.tableCellSelected)}function zn(e){const t=f(e,rt);return rt(t)?t:null}function Hn(e){const t=f(e,to);return to(t)?t:null}function Bn(e,t,n,o,l,r,s){const i=te(n.focus,l?"previous":"next");if(ne(i))return!1;let c=i;for(const e of oe(i).iterNodeCarets("shadowRoot")){if(!le(e)||!C(e.origin))return!1;c=e}const a=c.getParentAtCaret();if(!rt(a))return!1;const u=a,h=function(e){for(const t of oe(e).iterNodeCarets("root")){const{origin:n}=t;if(rt(n)){if(ae(t))return ue(n,e.direction)}else if(!ht(n))break}return null}(re(u,c.direction)),d=f(u,to);if(!d||!d.is(r))return!1;const g=e.getElementByKey(u.getKey()),m=Nn(g);if(!g||!m)return!1;const p=Qn(e,d);if(s.table=p,h)if("extend"===o){const t=Nn(e.getElementByKey(h.origin.getKey()));if(!t)return!1;s.$setAnchorCellForSelection(m),s.$setFocusCellForSelection(t,!0)}else{const e=ie(h);se(n.anchor,e),se(n.focus,e)}else if("extend"===o)s.$setAnchorCellForSelection(m),s.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=he(e);return ae(t)?ie(t):e}(re(d,i.direction));se(n.anchor,e),se(n.focus,e)}return Pn(t),!0}function Ln(e,t,n,o,l,s){if(("up"===n||"down"===n)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=h();if(!Mn(i,o)){if(d(i)){if("backward"===n){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(C(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!to(n)&&(Pn(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===n||"down"===n)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===n&&!i.isBackward()||"down"===n&&i.isBackward())){let l=f(e,e=>to(e));if(rt(l)&&(l=f(l,to)),l!==o)return!1;if(!l)return!1;const s="down"===n?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===n&&C(s)&&(c=s.getChildrenSize());let a=s;if("up"===n&&C(s)){const e=s.getLastChild();a=e||s,c=r(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,r(a)?"text":"element"),y(u),Pn(t),!0}if(G(e)){const e="up"===n?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==gn(o,e)){const e=o.getFirstDescendant(),t=o.getLastDescendant();if(!e||!t)return!1;const[n]=Dt(e),[r]=Dt(t),s=o.getCordsFromCellNode(n,l.table),i=o.getCordsFromCellNode(r,l.table),c=o.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=o.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let o=f(e,e=>C(e)&&!e.isInline());if(rt(o)&&(o=f(o,to)),!o)return!1;const r="down"===n?o.getNextSibling():o.getPreviousSibling();if(to(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),o=r.getLastDescendant();if(!e||!o)return!1;const[l]=Dt(e),[s]=Dt(o),c=i.clone();return c.focus.set(("up"===n?l:s).getKey(),"up"===n?0:s.getChildrenSize(),"element"),Pn(t),y(c),!0}}}}return"down"===n&&jn(e)&&s.setShouldCheckSelectionForTable(o.getKey()),!1}if(d(i)){if("backward"===n||"forward"===n){return Bn(e,t,i,t.shiftKey?"extend":"move","backward"===n,o,l)}if(i.isCollapsed()){const{anchor:r,focus:c}=i,a=f(r.getNode(),rt),u=f(c.getNode(),rt);if(!rt(a)||!a.is(u))return!1;const h=Hn(a);if(h!==o&&null!=h){const o=dn(h,e.getElementByKey(h.getKey()));if(null!=o)return l.table=vn(h,o),Ln(e,t,n,h,l,s)}const d=e.getElementByKey(a.__key),g=e.getElementByKey(r.key);if(null==g||null==d)return!1;let m;if("element"===r.type)m=g.getBoundingClientRect();else{const t=v(fn(e));if(null===t||0===t.rangeCount)return!1;const n=Q(t,e.getRootElement());if(null===n)return!1;m=n.getBoundingClientRect()}const p="up"===n?a.getFirstChild():a.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===n?_.top>m.top-m.height:m.bottom+m.height>_.bottom){Pn(t);const e=o.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return Fn(l,o,e.x,e.y,n);{const t=o.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(Zt(i)){const{anchor:r,focus:s,tableKey:c}=i;if(c!==o.getKey())return!1;const a=f(r.getNode(),rt),u=f(s.getNode(),rt),[h]=i.getNodes();to(h)||it(251);const d=dn(h,e.getElementByKey(h.getKey()));if(!rt(a)||!rt(u)||!to(h)||null==d)return!1;l.$updateTableTableSelection(i);const g=vn(h,d),m=o.getCordsFromCellNode(a,g),p=o.getDOMCellFromCordsOrThrow(m.x,m.y,g);if(l.$setAnchorCellForSelection(p),Pn(t),t.shiftKey){const[e,t,r]=Lt(o,a,u);return kn(l,e,t,r,n)}return u.selectEnd(),!0}return!1}function Pn(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Dn(e,t,n){const o=i();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function In(e,t,n){const o=n.getParent();if(!o)return;const l=v(fn(e));if(!l)return;const r=Z(l,e.getRootElement()).anchorNode,s=e.getElementByKey(o.getKey()),i=dn(n,e.getElementByKey(n.getKey()));if(!r||!s||!i||!s.contains(r)||i.contains(r))return;const c=f(t.anchor.getNode(),e=>rt(e));if(!c)return;const a=f(c,e=>to(e));if(!to(a)||!a.is(n))return;const[u,h]=Lt(n,c,c),d=u[0][0],g=u[u.length-1][u[0].length-1],{startRow:m,startColumn:p}=h,C=m===d.startRow&&p===d.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function Un(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Xn(e,t,n){return gn(e,q(t,n))}function Yn(e,n,o){const l=e.querySelector("colgroup");if(!l)return;const r=[];for(let e=0;e<n;e++){const n=t().createElement("col"),l=o&&o[e];l&&(n.style.width=`${l}px`),r.push(n)}l.replaceChildren(...r)}function Jn(e,t,o){if(!t.theme.tableAlignment)return;const l=[],r=[];for(const e of["center","right"]){const n=t.theme.tableAlignment[e];n&&(e===o?r:l).push(n)}x(e,...l),n(e,...r)}const qn=new WeakSet;function jn(e=w()){return qn.has(e)}function Vn(e,t){t?qn.add(e):qn.delete(e)}class Gn extends e{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Gn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Zn,priority:1})}}static importJSON(e){return eo().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=hn(e)?e:e.querySelector("table");return hn(t)||it(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(e,o){const l=t().createElement("table");this.__style&&pe(l.style,this.__style);const r=t().createElement("colgroup");if(l.appendChild(r),Ce(r),n(l,e.theme.table),this.updateTableElement(null,l,e),jn(o)){const o=t().createElement("div"),r=e.theme.tableScrollableWrapper;return r?n(o,r):o.style.overflowX="auto",o.appendChild(l),this.updateTableWrapper(null,o,l,e),o}return l}updateTableWrapper(e,t,o,l){this.__frozenColumnCount!==(e?e.__frozenColumnCount:0)&&function(e,t,o,l){l>0?(n(e,o.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(x(e,o.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}(t,o,l,this.__frozenColumnCount),this.__frozenRowCount!==(e?e.__frozenRowCount:0)&&function(e,t,o,l){l>0?(n(e,o.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(x(e,o.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}(t,o,l,this.__frozenRowCount)}updateTableElement(e,t,o){this.__style!==(e?e.__style:"")&&pe(t.style,this.__style,e?e.__style:""),this.__rowStriping!==(!!e&&e.__rowStriping)&&function(e,t,o){o?(n(e,t.theme.tableRowStriping),e.setAttribute("data-lexical-row-striping","true")):(x(e,t.theme.tableRowStriping),e.removeAttribute("data-lexical-row-striping"))}(t,o,this.__rowStriping);const l=e?e.getColumnCount():0,r=e?e.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===r||Yn(t,this.getColumnCount(),this.getColWidths()),Jn(t,o,this.getFormatType())}updateDOM(e,t,n){const l=dn(this,t);return t===l===jn()||(o(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,l,n),this.updateTableElement(e,l,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Yn(dn(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const n=super.exportDOM(e),{element:l}=n;return{after:l=>{if(n.after&&(l=n.after(l)),!hn(l)&&o(l)&&(l=l.querySelector("table")),!hn(l))return null;Jn(l,e._config,this.getFormatType());const[r]=Pt(this,null,null),s=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();s.has(e)||s.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const i=new Set;for(const e of l.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=s.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){s.delete(t);for(let e=0;e<n.colSpan;e++)i.add(e+n.startColumn)}}}const c=l.querySelector(":scope > colgroup");if(c){const e=Array.from(l.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>i.has(t));c.replaceChildren(...e)}const a=l.querySelectorAll(":scope > tr");if(a.length>0){const e=t().createElement("tbody");for(const t of a)e.appendChild(t);l.append(e)}return l},element:!hn(l)&&o(l)?l.querySelector("table"):l}}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 l=n[o];if(null==l)continue;const{elem:r}=l,s=Xn(this,r);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,l=o[t];if(null==l)return null;const r=l[e<l.length?e:l.length-1];return null==r?null:r}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const l=q(o.elem);return rt(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!ht(e))return 0;let t=0;return e.getChildren().forEach(e=>{rt(e)&&(t+=e.getColSpan())}),t}}function Qn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&it(230),vn(t,n)}function Zn(e){const t=eo();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&t.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&t.setFrozenRows(1);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Ze.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>Xe(e,ht),node:t}}function eo(){return c(new Gn)}function to(e){return e instanceof Gn}function no(e){ht(e.getParent())?e.isEmpty()&&e.append(i()):e.remove()}function oo(e){to(e.getParent())?Ve(e,rt):e.remove()}function lo(e){Ve(e,ht);const[t]=Pt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const l=o[e];if(!l)continue;ht(l)||it(254,l.constructor.name,l.getType());const r=t[e].reduce((e,t)=>t?1+e:e,0);if(r!==n)for(let e=r;e<n;++e){const e=lt();e.append(i()),l.append(e)}}const l=e.getColWidths(),r=e.getColumnCount();if(l&&l.length!==r){let t;if(r<l.length)t=l.slice(0,r);else if(l.length>0){const e=l[l.length-1];t=[...l,...Array(r-l.length).fill(e)]}e.setColWidths(t)}}function ro(e){if(e.detail<3||!V(e.target))return!1;const t=q(e.target);if(null===t)return!1;const n=f(t,e=>C(e)&&!e.isInline());if(null===n)return!1;return!!rt(n.getParent())&&(n.select(0),!0)}function so(){const e=h();if(!d(e))return!1;const t=Hn(e.anchor.getNode());if(null===t)return!1;const n=xe();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=Pt(t,null,null);if(0===o.length||0===o[0].length)return!1;const l=o[0][0];if(!l||!l.cell)return!1;const r=o[o.length-1],s=r[r.length-1];if(!s||!s.cell)return!1;const i=tn(t,l.cell,s.cell);return y(i),!0}function io(e){return e.registerNodeTransform(tt,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Dt(e),[n]=Lt(t,e,e),o=n.length,l=n[0].length;let r=t.getFirstChild();ht(r)||it(175);const s=[];for(let e=0;e<o;e++){0!==e&&(r=r.getNextSibling(),ht(r)||it(175));let t=null;for(let o=0;o<l;o++){const l=n[e][o],i=l.cell;if(l.startRow===e&&l.startColumn===o)t=i,s.push(i);else if(i.getColSpan()>1||i.getRowSpan()>1){rt(i)||it(176);const e=lt(i.__headerState);null!==t?t.insertAfter(e):Je(r,e)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}})}function co(e,t=!0){const n=new ln,o=(o,l,r)=>{const s=dn(o,r),i=Sn(o,s,e,t,n);n.observers.set(l,[i,s])};return _e(_n(e,n),e.registerCommand(N,()=>bn(n,e),E),e.registerMutationListener(Gn,t=>{e.read("latest",()=>{for(const[e,l]of t){const t=n.observers.get(e);if("created"===l||"updated"===l){const{tableNode:l,tableElement:r}=on(e);void 0===t?o(l,e,r):r!==t[1]&&(n.removeObserver(e),o(l,e,r))}else"destroyed"===l&&n.removeObserver(e)}})},{skipInitialization:!1}),()=>{n.removeAllObservers()})}function ao(e,t){e.hasNodes([Gn])||it(255);const{hasNestedTables:n=Ee(!1)}=t??{};return _e(e.registerCommand(st,e=>function({rows:e,columns:t,includeHeaders:n},o){const l=h()||ee();if(!l||!d(l))return!1;if(!o&&Hn(l.anchor.getNode()))return!1;const s=dt(Number(e),Number(t),n);qe(s);const i=s.getFirstDescendant();return r(i)&&i.select(),!0}(e,n.peek()),Se),e.registerCommand(be,(t,o)=>e===o&&function(e,t){const{nodes:n,selection:o}=e;if(!n.some(e=>to(e)||je(e).some(e=>to(e.node)))){if(Zt(o)){let e="",t=!1;for(const o of n){const n=C(o)&&!o.isInline();e.length>0&&(n||t)&&(e+="\n"),e+=o.getTextContent(),t=n}return o.insertRawText(e),!0}return!1}const l=Zt(o),r=d(o);if(!(r&&null!==f(o.anchor.getNode(),e=>rt(e))&&null!==f(o.focus.getNode(),e=>rt(e))||l))return!1;if(1===n.length&&to(n[0]))return qt(n[0],o);if(r&&t.peek()&&!function(e){if(Zt(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(d(e)&&rt(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(o))return!1;return!0}(t,n),Se),e.registerCommand(we,so,ye),e.registerCommand(Ne,ro,Se),e.registerNodeTransform(Gn,lo),e.registerNodeTransform(ct,oo),e.registerNodeTransform(tt,no))}const uo={$accepts:ht,$packageRun:e=>e.every(rt)?[ut().splice(0,0,e)]:[],name:"TableSchema"},ho={$accepts:rt,name:"TableRowSchema"},fo=[/* @__PURE__ */ze({$import:(e,t)=>{const n=eo();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Ze.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return[n.splice(0,0,Xe(e.$importChildren(t),ht))]},match:He.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */ze({$import:(e,t)=>[ut(Ze.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,Xe(e.$importChildren(t),rt))],match:He.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */ze({$import:(e,t)=>{const n="TH"===t.nodeName,o=Ze.test(t.style.width)?parseFloat(t.style.width):void 0;let c=et.NO_STATUS;if(n){const e=t.getAttribute("scope");if("col"===e)c=et.COLUMN;else if("row"===e)c=et.ROW;else{const e=t.parentElement,n=ve(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),o=0===t.cellIndex;n&&(c|=et.ROW),o&&(c|=et.COLUMN),c===et.NO_STATUS&&(c=et.ROW)}}const a=lt(c,t.colSpan,o);a.__rowSpan=t.rowSpan;const u=t.style.backgroundColor;""!==u&&(a.__backgroundColor=u);const h=t.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(a.__verticalAlign=h);const d=e.get(Be),f=d|function(e){let t=0;const n=e.fontWeight;"700"!==n&&"bold"!==n||(t|=Te),"italic"===e.fontStyle&&(t|=Re);const o=(e.textDecoration||"").split(" ");return o.includes("underline")&&(t|=Fe),o.includes("line-through")&&(t|=Oe),t}(t.style),g=e.get(Le),m=t.style.color,p=m?{...g,color:m}:g,C=[];f!==d&&C.push(Pe(Be,f)),p!==g&&C.push(Pe(Le,p));const _=function(e){const t=[];let n=null;const o=()=>{if(null!==n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)l(c)||r(c)||s(c)?null!==n?n.append(c):(n=i().append(c),t.push(n)):(o(),n=null,t.push(c));return o(),0===t.length&&t.push(i()),t}(e.$importChildren(t,{context:C})),S=n?_:De(_,t);return[a.splice(0,0,S)]},match:He.tag("td","th"),name:"@lexical/table/cell"})],go=/* @__PURE__ */Ae({build:(e,t,n)=>We(t),config:/* @__PURE__ */Me({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[Ie,/* @__PURE__ */ke(Ue,{rules:fo})],name:"@lexical/table/Table",nodes:()=>[Gn,ct,tt],register(e,t,n){const o=n.getOutput();return _e($e(()=>{const t=o.hasHorizontalScroll.value;jn(e)!==t&&(Vn(e,t),e.update(Ke))}),ao(e,o),$e(()=>co(e,o.hasTabHandler.value)),$e(()=>o.hasCellMerge.value?void 0:io(e)),$e(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(tt,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),mo=/* @__PURE__ */Ae({dependencies:[go],name:"@lexical/table/Import"});export{Lt as $computeTableMap,Pt as $computeTableMapSkipCellCheck,lt as $createTableCellNode,eo as $createTableNode,dt as $createTableNodeWithDimensions,ut as $createTableRowNode,en as $createTableSelection,tn as $createTableSelectionFrom,Ot as $deleteTableColumn,kt as $deleteTableColumnAtSelection,Mt as $deleteTableColumn__EXPERIMENTAL,At as $deleteTableRowAtSelection,Kt as $deleteTableRow__EXPERIMENTAL,zn as $findCellNode,Hn as $findTableNode,Qn as $getElementForTableNode,Dt as $getNodeTriplet,on as $getTableAndElementByKey,ft as $getTableCellNodeFromLexicalNode,Jt as $getTableCellNodeRect,Ct as $getTableColumnIndexFromTableCellNode,mt as $getTableNodeFromLexicalNodeOrThrow,pt as $getTableRowIndexFromTableCellNode,gt as $getTableRowNodeFromTableCellNodeOrThrow,vt as $insertTableColumn,Ft as $insertTableColumnAtNode,Tt as $insertTableColumnAtSelection,Rt as $insertTableColumn__EXPERIMENTAL,bt as $insertTableRow,xt as $insertTableRowAtNode,yt as $insertTableRowAtSelection,Nt as $insertTableRow__EXPERIMENTAL,jn as $isScrollableTablesActive,Ut as $isSimpleTable,rt as $isTableCellNode,to as $isTableNode,ht as $isTableRowNode,Zt as $isTableSelection,Wt as $mergeCells,Xt as $moveTableColumn,Yt as $moveTableRow,St as $removeTableRowAtIndex,Vt as $setTableColumnIsHeader,jt as $setTableRowIsHeader,Ht as $unmergeCell,Bt as $unmergeCellNode,st as INSERT_TABLE_COMMAND,et as TableCellHeaderStates,tt as TableCellNode,go as TableExtension,mo as TableImportExtension,fo as TableImportRules,Gn as TableNode,rn as TableObserver,ct as TableRowNode,ho as TableRowSchema,uo as TableSchema,Sn as applyTableHandlers,Nn as getDOMCellFromTarget,dn as getTableElement,yn as getTableObserverFromTableElement,io as registerTableCellUnmergeTransform,ao as registerTablePlugin,co as registerTableSelectionObserver,Vn as setScrollableTablesActive};
|
|
9
|
+
import{ElementNode as e,$getDocument as t,addClassNamesToElement as n,isHTMLElement as o,$isInlineElementOrDecoratorNode as l,$isTextNode as r,$isLineBreakNode as s,$createParagraphNode as i,$applyNodeReplacement as c,createCommand as a,$createTextNode as u,$getSelection as h,$isRangeSelection as d,$findMatchingParent as f,$isParagraphNode as g,$createPoint as m,$getNodeByKey as p,$isElementNode as C,$normalizeSelection__EXPERIMENTAL as _,isCurrentlyReadOnlyMode as S,TEXT_TYPE_TO_FORMAT as b,$getEditor as w,$setSelection as y,SELECTION_CHANGE_COMMAND as N,removeClassNamesFromElement as x,getDOMSelection as v,$createRangeSelection as T,$isRootNode as R,INSERT_PARAGRAPH_COMMAND as F,registerEventListener as O,KEY_ARROW_DOWN_COMMAND as A,KEY_ARROW_UP_COMMAND as K,KEY_ARROW_LEFT_COMMAND as k,KEY_ARROW_RIGHT_COMMAND as M,COMMAND_PRIORITY_HIGH as E,KEY_ESCAPE_COMMAND as $,DELETE_WORD_COMMAND as W,DELETE_LINE_COMMAND as z,DELETE_CHARACTER_COMMAND as H,KEY_BACKSPACE_COMMAND as B,KEY_DELETE_COMMAND as L,CUT_COMMAND as P,PASTE_COMMAND as D,getComposedEventTarget as I,isDOMNode as U,getActiveElement as X,COPY_COMMAND as Y,FORMAT_TEXT_COMMAND as J,FORMAT_ELEMENT_COMMAND as q,CONTROLLED_TEXT_INSERTION_COMMAND as j,KEY_TAB_COMMAND as V,FOCUS_COMMAND as G,$getNearestNodeFromDOMNode as Q,$isRootOrShadowRoot as Z,getDOMSelectionRange as ee,getDOMSelectionPoints as te,$getPreviousSelection as ne,$caretFromPoint as oe,$isExtendableTextPointCaret as le,$extendCaretToRange as re,$isSiblingCaret as se,$getSiblingCaret as ie,$setPointFromCaret as ce,$normalizeCaret as ae,$createRangeSelectionFromDom as ue,$isChildCaret as he,$getChildCaret as de,$getAdjacentChildCaret as fe,IS_FIREFOX as ge,$getNodeByKeyOrThrow as me,isDOMDocumentNode as pe,isDOMShadowRoot as Ce,setDOMStyleFromCSS as _e,setDOMUnmanaged as Se,mergeRegister as be,COMMAND_PRIORITY_EDITOR as we,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as ye,SELECT_ALL_COMMAND as Ne,COMMAND_PRIORITY_LOW as xe,CLICK_COMMAND as ve,$getRoot as Te,isHTMLTableRowElement as Re,IS_BOLD as Fe,IS_ITALIC as Oe,IS_UNDERLINE as Ae,IS_STRIKETHROUGH as Ke,defineExtension as ke,$fullReconcile as Me,configExtension as Ee,safeCast as $e}from"lexical";import{signal as We,effect as ze,namedSignals as He}from"@lexical/extension";import{defineImportRule as Be,sel as Le,ImportTextFormat as Pe,ImportTextStyle as De,contextValue as Ie,$propagateTextAlignToBlockChildren as Ue,CoreImportExtension as Xe,DOMImportExtension as Ye}from"@lexical/html";import{$descendantsMatching as Je,objectKlassEquals as qe,$insertFirst as je,$insertNodeToNearestRoot as Ve,$dfs as Ge,$unwrapAndFilterDescendants as Qe}from"@lexical/utils";import{copyToClipboard as Ze,$getClipboardDataFromSelection as et}from"@lexical/clipboard";const tt=/^(\d+(?:\.\d+)?)px$/,nt={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ot extends e{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new ot(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:rt,priority:0}),th:e=>({conversion:rt,priority:0})}}static importJSON(e){return st().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=nt.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(e){const o=t().createElement(this.getTag());return this.__width&&(o.style.width=`${this.__width}px`),this.__colSpan>1&&(o.colSpan=this.__colSpan),this.__rowSpan>1&&(o.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(o.style.backgroundColor=this.__backgroundColor),lt(this.__verticalAlign)&&(o.style.verticalAlign=this.__verticalAlign),n(o,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader),o}exportDOM(e){const t=super.exportDOM(e);if(o(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...lt(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=nt.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==nt.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function lt(e){return"middle"===e||"bottom"===e}function rt(e){const t=e,n=e.nodeName.toLowerCase();let c;tt.test(t.style.width)&&(c=parseFloat(t.style.width));let a=nt.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)a=nt.COLUMN;else if("row"===e)a=nt.ROW;else{const e=t.parentElement,n=o(e)&&"tr"===e.nodeName.toLowerCase()&&o(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),l=0===t.cellIndex;n&&(a|=nt.ROW),l&&(a|=nt.COLUMN),a===nt.NO_STATUS&&(a=nt.ROW)}}const u=st(a,t.colSpan,c);u.__rowSpan=t.rowSpan;const h=t.style.backgroundColor;""!==h&&(u.__backgroundColor=h);const d=t.style.verticalAlign;lt(d)&&(u.__verticalAlign=d);const f=t.style,g=(f&&f.textDecoration||"").split(" "),m="700"===f.fontWeight||"bold"===f.fontWeight,p=g.includes("line-through"),C="italic"===f.fontStyle,_=g.includes("underline"),S=f.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)if(l(c)||r(c)||s(c)){if(r(c)&&(m&&c.toggleFormat("bold"),p&&c.toggleFormat("strikethrough"),C&&c.toggleFormat("italic"),_&&c.toggleFormat("underline"),S)){const e=c.getStyle();e.includes("color:")||c.setStyle(e+`color: ${S};`)}n?n.append(c):(n=i().append(c),t.push(n))}else t.push(c),o(),n=null;return o(),0===t.length&&t.push(i()),t},node:u}}function st(e=nt.NO_STATUS,t=1,n){return c(new ot(e,t,n))}function it(e){return e instanceof ot}const ct=/* @__PURE__ */a("INSERT_TABLE_COMMAND");function at(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class ut extends e{__height;static getType(){return"tablerow"}static clone(e){return new ut(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:ht,priority:0})}}static importJSON(e){return dt().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(e){const o=t().createElement("tr");return this.__height&&(o.style.height=`${this.__height}px`),n(o,e.theme.tableRow),o}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 ht(e){const t=e;let n;return tt.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>Je(e,it),node:dt(n)}}function dt(e){return c(new ut(e))}function ft(e){return e instanceof ut}function gt(e,t,n=!0){const o=no();for(let l=0;l<e;l++){const e=dt();for(let o=0;o<t;o++){let t=nt.NO_STATUS;"object"==typeof n?(0===l&&n.rows&&(t|=nt.ROW),0===o&&n.columns&&(t|=nt.COLUMN)):n&&(0===l&&(t|=nt.ROW),0===o&&(t|=nt.COLUMN));const r=st(t),s=i();s.append(u()),r.append(s),e.append(r)}o.append(e)}return o}function mt(e){const t=f(e,e=>it(e));return it(t)?t:null}function pt(e){const t=f(e,e=>ft(e));if(ft(t))return t;throw new Error("Expected table cell to be inside of table row.")}function Ct(e){const t=f(e,e=>oo(e));if(oo(t))return t;throw new Error("Expected table cell to be inside of table.")}function _t(e){const t=pt(e);return Ct(t).getChildren().findIndex(e=>e.is(t))}function St(e){return pt(e).getChildren().findIndex(t=>t.is(e))}function bt(e,t){const n=Ct(e),{x:o,y:l}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,l-1,t),below:n.getCellNodeFromCords(o,l+1,t),left:n.getCellNodeFromCords(o-1,l,t),right:n.getCellNodeFromCords(o+1,l,t)}}function wt(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function yt(e,t,n=!0,o,l){const r=e.getChildren();if(t>=r.length||t<0)throw new Error("Table row target index out of range");const s=r[t];if(!ft(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=dt();for(let n=0;n<t;n++){const t=e[n];it(t)||at(12);const{above:r,below:s}=bt(t,l);let c=nt.NO_STATUS;const a=r&&r.getWidth()||s&&s.getWidth()||void 0;(r&&r.hasHeaderState(nt.COLUMN)||s&&s.hasHeaderState(nt.COLUMN))&&(c|=nt.COLUMN);const u=st(c,1,a);u.append(i()),o.append(u)}n?s.insertAfter(o):s.insertBefore(o)}return e}const Nt=(e,t)=>e===nt.BOTH||e===t?t:nt.NO_STATUS;function xt(e=!0){const t=h();d(t)||tn(t)||at(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[l]=Ut(n),[r,,s]=Ut(o),[,i,c]=Dt(s,r,l),{startRow:a}=c,{startRow:u}=i;return e?Tt(a+l.__rowSpan>u+r.__rowSpan?l:r,!0):Tt(u<a?r:l,!1)}const vt=xt;function Tt(e,t=!0){const[,,n]=Ut(e),[o,l]=Dt(n,e,e),r=o[0].length,{startRow:s}=l;let c=null;if(t){const t=s+e.__rowSpan-1,l=o[t],a=dt();for(let e=0;e<r;e++){const{cell:n,startRow:o}=l[e];if(o+n.__rowSpan-1<=t){const t=l[e].cell.__headerState,n=Nt(t,nt.COLUMN);a.append(st(n).append(i()))}else n.setRowSpan(n.__rowSpan+1)}const u=n.getChildAtIndex(t);ft(u)||at(256),u.insertAfter(a),c=a}else{const e=s,t=o[e],l=dt();for(let n=0;n<r;n++){const{cell:o,startRow:r}=t[n];if(r===e){const e=t[n].cell.__headerState,o=Nt(e,nt.COLUMN);l.append(st(o).append(i()))}else o.setRowSpan(o.__rowSpan+1)}const a=n.getChildAtIndex(e);ft(a)||at(257),a.insertBefore(l),c=l}return c}function Rt(e,t,n=!0,o,l){const r=e.getChildren(),s=[];for(let e=0;e<r.length;e++){const n=r[e];if(ft(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];it(o)||at(12);const{left:r,right:c}=bt(o,l);let a=nt.NO_STATUS;(r&&r.hasHeaderState(nt.ROW)||c&&c.hasHeaderState(nt.ROW))&&(a|=nt.ROW);const u=st(a);u.append(i()),s.push({newTableCell:u,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function Ft(e=!0){const t=h();d(t)||tn(t)||at(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[l]=Ut(n),[r,,s]=Ut(o),[,i,c]=Dt(s,r,l),{startColumn:a}=c,{startColumn:u}=i;return e?At(a+l.__colSpan>u+r.__colSpan?l:r,!0):At(u<a?r:l,!1)}const Ot=Ft;function At(e,t=!0,n=!0){const[,,o]=Ut(e),[l,r]=Dt(o,e,e),s=l.length,{startColumn:c}=r,a=t?c+e.__colSpan-1:c-1,u=o.getFirstChild();ft(u)||at(120);let h=null;function d(e=nt.NO_STATUS){const t=st(e).append(i());return null===h&&(h=t),t}let f=u;e:for(let e=0;e<s;e++){if(0!==e){const e=f.getNextSibling();ft(e)||at(121),f=e}const t=l[e],n=t[a<0?0:a].cell.__headerState,o=Nt(n,nt.ROW);if(a<0){zt(f,d(o));continue}const{cell:r,startColumn:s,startRow:i}=t[a];if(s+r.__colSpan-1<=a){let n=r,l=i,s=a;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){f.append(d(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(d(o))}else r.setColSpan(r.__colSpan+1)}null!==h&&n&&Wt(h);const g=o.getColWidths();if(g){const e=[...g],t=a<0?0:a,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return h}function Kt(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ft(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function kt(){const e=h();d(e)||tn(e)||at(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,l]=Ut(t),[r]=Ut(n),[s,i,c]=Dt(l,o,r),{startRow:a}=i,{startRow:u}=c,f=u+r.__rowSpan-1;if(s.length===f-a+1)return void l.remove();const g=s[0].length,m=s[f+1],p=l.getChildAtIndex(f+1);for(let e=f;e>=a;e--){for(let t=g-1;t>=0;t--){const{cell:n,startRow:o,startColumn:l}=s[e][t];if(l===t){if(o<a||o+n.__rowSpan-1>f){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,f),l=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-l)}if(o>=a&&o+n.__rowSpan-1>f&&e===f){ft(p)||at(387);let o=null;for(let n=0;n<t;n++){const t=m[n],l=t.cell;t.startRow===e+1&&(o=l),l.__colSpan>1&&(n+=l.__colSpan-1)}null===o?zt(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);ft(t)||at(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Wt(e)}else{const e=s[a-1],{cell:t}=e[0];Wt(t)}}const Mt=kt;function Et(){const e=h();d(e)||tn(e)||at(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,l]=Ut(t),[r]=Ut(n),[s,i,c]=Dt(l,o,r),{startColumn:a}=i,{startRow:u,startColumn:f}=c,g=Math.min(a,f),m=Math.max(a+o.__colSpan-1,f+r.__colSpan-1),p=m-g+1;if(s[0].length===m-g+1)return l.selectPrevious(),void l.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=g;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<g){if(t===g){const e=g-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[u],S=a>f?_[a+o.__colSpan]:_[f+r.__colSpan];if(void 0!==S){const{cell:e}=S;Wt(e)}else{const e=f<a?_[f-1]:_[a-1],{cell:t}=e;Wt(t)}const b=l.getColWidths();if(b){const e=[...b];e.splice(g,p),l.setColWidths(e)}}const $t=Et;function Wt(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function zt(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ht(e){if(0===e.length)return null;const t=Ct(e[0]),[n]=It(t,null,null);let o=1/0,l=-1/0,r=1/0,s=-1/0;const c=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!c.has(t)&&e.some(e=>e.is(n.cell))){c.add(t);const e=n.startRow,i=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),l=Math.max(l,e+a-1),r=Math.min(r,i),s=Math.max(s,i+u-1)}}if(o===1/0||r===1/0)return null;const a=l-o+1,u=s-r+1,h=n[o][r];if(!h.cell)return null;const d=h.cell;d.setColSpan(u),d.setRowSpan(a);const f=new Set([d.getKey()]);for(let e=o;e<=l;e++)for(let t=r;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const l=o.cell,r=l.getKey();if(!f.has(r)){f.add(r);Bt(l)||d.append(...l.getChildren()),l.remove()}}return 0===d.getChildrenSize()&&d.append(i()),d}function Bt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!g(t)||!t.isEmpty())}function Lt(){const e=h();d(e)||tn(e)||at(188);const t=e.anchor.getNode(),n=f(t,it);return it(n)||at(148),Pt(n)}function Pt(e){const[t,n,o]=Ut(e),l=t.__colSpan,r=t.__rowSpan;if(1===l&&1===r)return;const[s,c]=Dt(o,t,t),{startColumn:a,startRow:u}=c,h=t.__headerState&nt.COLUMN,d=Array.from({length:l},(e,t)=>{let n=h;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+a].cell.__headerState;return n}),f=t.__headerState&nt.ROW,g=Array.from({length:r},(e,t)=>{let n=f;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+u][e].cell.__headerState;return n});if(l>1){for(let e=1;e<l;e++)t.insertAfter(st(d[e]|g[0]).append(i()));t.setColSpan(1)}if(r>1){let e;for(let t=1;t<r;t++){const o=u+t,r=s[o];e=(e||n).getNextSibling(),ft(e)||at(125);let c=null;for(let e=0;e<a;e++){const t=r[e],n=t.cell;t.startRow===o&&(c=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===c)for(let n=l-1;n>=0;n--)zt(e,st(d[n]|g[t]).append(i()));else for(let e=l-1;e>=0;e--)c.insertAfter(st(d[e]|g[t]).append(i()))}t.setRowSpan(1)}}function Dt(e,t,n){const[o,l,r]=It(e,t,n);return null===l&&at(207),null===r&&at(208),[o,l,r]}function It(e,t,n){const o=[];let l=null,r=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];ft(o)||at(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(it(a)||at(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===l&&t.is(a)&&(l=o),null!==n&&null===r&&n.is(a)&&(r=o)}}return[o,l,r]}function Ut(e){let t;if(e instanceof ot)t=e;else if("__type"in e){const n=f(e,it);it(n)||at(148),t=n}else{const n=f(e.getNode(),it);it(n)||at(148),t=n}const n=t.getParent();ft(n)||at(149);const o=n.getParent();return oo(o)||at(210),[t,n,o]}function Xt(e,t,n){let o,l=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=l,d=c.startRow<=i&&u>=r;if(h&&d){const e=Math.min(l,c.startColumn),t=Math.max(s,a),n=Math.min(r,c.startRow),h=Math.max(i,u);e===l&&t===s&&n===r&&h===i||(l=e,s=t,r=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:l,minRow:r}}function Yt(e){const t=e.getChildren();let n=null;for(const e of t){if(!ft(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!it(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function Jt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Yt(e))return;e.getChildren().filter(ft).forEach(e=>{const o=e.getChildren(),[l]=o.splice(t,1);o.splice(n,0,l),e.splice(0,o.length,o)});const l=e.getColWidths();if(l&&l.length===o){const o=[...l],[r]=o.splice(t,1);o.splice(n,0,r),e.setColWidths(o)}}function qt(e,t,n){if(t===n)return;const o=e.getChildren().filter(ft),l=o.length;if(t<0||t>=l||n<0||n>=l)return;if(!Yt(e))return;const r=o[t],s=o[n];n>t?s.insertAfter(r):s.insertBefore(r)}function jt(e){const[t,,n]=Ut(e),o=n.getChildren().filter(ft),l=o.length,r=o[0].getChildren().length,s=new Array(l);for(let e=0;e<l;e++)s[e]=new Array(r);for(let e=0;e<l;e++){const n=o[e].getChildren().filter(it);let l=0;for(let o=0;o<n.length;o++){for(;s[e][l];)l++;const r=n[o],i=r.__rowSpan||1,c=r.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][l+n]=r;if(t===r)return{colSpan:c,columnIndex:l,rowIndex:e,rowSpan:i};l+=c}}return null}function Vt(e,t){const n=t.getStartEndPoints(),o=tn(t);if(null===n)return!1;const[l,s]=n,[c,a,u]=Ut(l),h=f(s.getNode(),e=>it(e));if(!(it(c)&&it(h)&&ft(a)&&oo(u)))return!1;const[d,g,m]=Dt(u,c,h),[p]=It(e,null,null),C=d.length,_=C>0?d[0].length:0;let S=g.startRow,b=g.startColumn,w=p.length,y=w>0?p[0].length:0;if(o){const e=Xt(d,g,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let N=!1;const x=Math.min(C,S+w)-1,v=Math.min(_,b+y)-1,T=new Set;for(let e=S;e<=x;e++)for(let t=b;t<=v;t++){const n=d[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(Pt(n.cell),T.add(n.cell.getKey()),N=!0))}let[R]=It(u.getWritable(),null,null);const F=w-C+S;for(let e=0;e<F;e++){Tt(R[C-1][0].cell)}const O=y-_+b;for(let e=0;e<O;e++){At(R[0][_-1].cell,!0,!1)}[R]=It(u.getWritable(),null,null);for(let e=S;e<S+w;e++)for(let t=b;t<b+y;t++){const n=e-S,o=t-b,l=p[n][o];if(l.startRow!==n||l.startColumn!==o)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const n=[],o=Math.min(e+s.__rowSpan,S+w)-1,l=Math.min(t+s.__colSpan,b+y)-1;for(let r=e;r<=o;r++)for(let e=t;e<=l;e++){const t=R[r][e];n.push(t.cell)}Ht(n),N=!0}const{cell:c}=R[e][t],a=s.getBackgroundColor();null!=a&&c.setBackgroundColor(a);const u=c.getChildren();s.getChildren().forEach(e=>{if(r(e)){i().append(e),c.append(e)}else c.append(e)}),u.forEach(e=>e.remove())}if(o&&N){const[e]=It(u.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function Gt(e,t,n){const[o]=It(e,null,null);t>=0&&t<o.length||at(396,String(t));const l=o[t],r=n?nt.ROW:nt.NO_STATUS,s=new Set;for(let e=0;e<l.length;e++){const t=l[e];null!=t&&(s.has(t.cell)||(s.add(t.cell),t.cell.setHeaderStyles(r,nt.ROW)))}}function Qt(e,t,n){const[o]=It(e,null,null);o.length>0&&t>=0&&t<o[0].length||at(397,String(t));const l=n?nt.COLUMN:nt.NO_STATUS,r=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(r.has(n.cell)||(r.add(n.cell),n.cell.setHeaderStyles(l,nt.COLUMN)))}}function Zt(e){const[[t,n,o,l],[r,s,i,c]]=["anchor","focus"].map(t=>{const n=e[t].getNode(),o=f(n,it);it(o)||at(238,t,n.getKey(),n.getType());const l=o.getParent();ft(l)||at(239,t);const r=l.getParent();return oo(r)||at(240,t),[n,o,l,r]});return l.is(c)||at(241),{anchorCell:n,anchorNode:t,anchorRow:o,anchorTable:l,focusCell:s,focusNode:r,focusRow:i,focusTable:c}}class en{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=p(this.tableKey),t=p(this.anchor.key),n=p(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return tn(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 en(this.tableKey,m(this.anchor.key,this.anchor.offset,this.anchor.type),m(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){if(""===e)return;const t=(e.endsWith("\n")?e.slice(0,-1):e).split("\n").map(e=>e.split("\t")),n=no();for(const e of t){const t=dt();for(const n of e){const e=st(nt.NO_STATUS),o=i();n&&o.append(u(n)),e.append(o),t.append(e)}n.append(t)}const{anchorCell:o}=Zt(this);Vt(n,o.select(0,o.getChildrenSize()))}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(it).forEach(e=>{const n=e.getFirstChild();g(n)&&(t|=n.getTextFormat())});const n=b[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();C(t)||at(151);_(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Zt(this),n=jt(e);null===n&&at(153);const o=jt(t);null===o&&at(155);const l=Math.min(n.columnIndex,o.columnIndex),r=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(l,r),fromY:Math.min(s,i),toX:Math.max(l,r),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Zt(this),l=o.getParents()[1];if(l!==t){if(t.isParentOf(o)){const e=l.getParent();null==e&&at(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&at(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[r,s,i]=Dt(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=Xt(r,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=r[e][t],o=n.getParent();ft(o)||at(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||ln(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return S()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>it(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],l=o.__parent,r=(e[n+1]||{}).__parent;t+=o.getTextContent()+(r!==l?"\n":"\t")}return t}}function tn(e){return e instanceof en}function nn(){const e=m("root",0,"element"),t=m("root",0,"element");return new en("root",e,t)}function on(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=h(),l=tn(o)?o.clone():nn();return l.set(e.getKey(),t.getKey(),n.getKey()),l}function ln(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&C(o)&&n.push(o.getChildren())}}function rn(e,t=w()){const n=p(e);oo(n)||at(231,e);const o=gn(n,t.getElementByKey(e));return null===o&&at(232,e),{tableElement:o,tableNode:n}}class sn{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return void 0!==t&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const e=[];for(const[t,[n]]of Array.from(this.observers.entries())){const o=p(t);oo(o)?e.push([o,n]):this.removeObserver(t)}return e}}class cn{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return rn(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.read("latest",()=>{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=Rn(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Rn(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(e=!0){const t=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();Fn(t,Rn(n,o),null),e&&null!==h()&&(y(null),t.dispatchCommand(N,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();x(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:e}=this.$lookup();n(e,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&at(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Fn(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=v(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),l=e.x,r=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==l||this.anchorY!==r||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&r===this.focusY)return!1;if(this.focusX=l,this.focusY=r,this.isHighlightingCells){const s=Jn(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(l,r,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=on(o,t,e),y(this.tableSelection),n.dispatchCommand(N,void 0),Fn(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const e=this.anchorCellNodeKey?p(this.anchorCellNodeKey):null;return it(e)?e:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&at(234),e}$getFocusTableCell(){const e=this.focusCellNodeKey?p(this.focusCellNodeKey):null;return it(e)?e:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&at(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=Jn(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=on(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=h();tn(t)||at(236);const n=T(),o=n.anchor,l=n.focus,r=t.getNodes().filter(it);r.length>0||at(237);const s=r[0].getFirstChild(),i=g(s)?s.getFormatFlags(e,null):null;r.forEach(t=>{o.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),y(t),this.editor.dispatchCommand(N,void 0)}$clearText(){const{editor:e}=this,t=p(this.tableNodeKey);if(!oo(t))throw new Error("Expected TableNode.");const n=h();tn(n)||at(253);const o=n.getNodes().filter(it),l=t.getFirstChild(),r=t.getLastChild();if(o.length>0&&null!==l&&null!==r&&ft(l)&&ft(r)&&o[0]===l.getFirstChild()&&o[o.length-1]===r.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(R(n)&&n.isEmpty()&&e.dispatchCommand(F,void 0))}o.forEach(e=>{if(C(e)){const t=i(),n=u();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),Fn(e,this.table,null),y(null),e.dispatchCommand(N,void 0)}}const an="__lexicalTableSelection";function un(e){const t=me(e);return oo(t)||at(386,e),t}const hn=40;function dn(e,t,n){const o=e=>Math.max(1,Math.ceil(Math.min(hn,e)/hn*18));return e<=t+hn?-o(t+hn-e):e>=n-hn?o(e-(n-hn)):0}function fn(e){return o(e)&&"TABLE"===e.nodeName}function gn(e,t){if(!t)return t;const n=fn(t)?t:t.querySelector("table");return fn(n)||at(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function mn(e){return e._window}function pn(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;it(n)&&(o=n)}return null}const Cn=[[A,"down"],[K,"up"],[k,"backward"],[M,"forward"]],_n=[W,z,H],Sn=[B,L];function bn(e,t){return e.registerRootListener(n=>{if(null===n)return;const o=e._window;if(null===o)return;return O(o,"pointerdown",o=>{const l=I(o);if(0!==o.button||!U(l)||!n.contains(l))return;const r=function(e){const t=vn(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&an in n&&n[an])return{cellElement:t,tableElement:n,tableObserver:n[an]};n=n.parentNode}return null}(l);e.update(()=>{if(tn(h())){for(const[e]of t.observers.values())e.$clearHighlight(!1);y(null),e.dispatchCommand(N,void 0)}if(!r)return;const{tableObserver:n,tableElement:l,cellElement:s}=r;!function(e,t,n,o,l,r){const s=e._window;if(!s)return;const i=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});let i=t.clientX,c=t.clientY,a=null;const u=()=>{l.isSelecting=!1,null!==a&&(s.cancelAnimationFrame(a),a=null),s.removeEventListener("pointerup",S),s.removeEventListener("pointermove",b)},h=(e,t)=>{const n=o.getRootNode();if(!pe(n)&&!Ce(n))return null;for(const l of n.elementsFromPoint(e,t)){const e=Tn(o,l);if(e)return e}return null},d=(t,n)=>{null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(t)}),null!==l.focusCell&&t.elem===l.focusCell.elem||(r.setNextFocus({focusCell:t,override:n,tableKey:l.tableNodeKey}),e.dispatchCommand(N,void 0))},f=e=>{for(let t=o.parentElement;t;t=t.parentElement){if("x"===e?t.scrollWidth>t.clientWidth:t.scrollHeight>t.clientHeight){const n=s.getComputedStyle(t),o="x"===e?n.overflowX:n.overflowY;if("auto"===o||"scroll"===o)return t}}return null},g=(e,t,n)=>{let o,l;if(null===e)o=0,l="x"===n?s.innerWidth:s.innerHeight;else{const t=e.getBoundingClientRect();o="x"===n?t.left:t.top,l="x"===n?t.right:t.bottom}const r=dn(t,o,l);if(0===r)return!1;if(null===e){const e="x"===n?s.scrollX:s.scrollY;return s.scrollBy("x"===n?r:0,"x"===n?0:r),("x"===n?s.scrollX:s.scrollY)!==e}if("x"===n){const t=e.scrollLeft;return e.scrollLeft+=r,e.scrollLeft!==t}const i=e.scrollTop;return e.scrollTop+=r,e.scrollTop!==i},m=(e,t)=>{let n=i,o=c;if(null===e)n=Math.min(Math.max(n,1),s.innerWidth-1);else{const t=e.getBoundingClientRect();n=Math.min(Math.max(n,t.left+1),t.right-1)}if(null===t)o=Math.min(Math.max(o,1),s.innerHeight-1);else{const e=t.getBoundingClientRect();o=Math.min(Math.max(o,e.top+1),e.bottom-1)}return[n,o]},p=()=>{const e=f("x");if(null!==e){const t=e.getBoundingClientRect();if(0!==dn(i,t.left,t.right))return!0}const t=f("y"),n=null===t?0:t.getBoundingClientRect().top,o=null===t?s.innerHeight:t.getBoundingClientRect().bottom;return 0!==dn(c,n,o)},C=()=>{if(a=null,!l.isSelecting)return;const e=f("x"),t=f("y"),n=null!==e&&g(e,i,"x"),o=g(t,c,"y");if(n||o){const[n,o]=m(e,t),l=h(n,o);l&&d(l,!1),a=s.requestAnimationFrame(C)}},_=()=>{null===a&&"touch"!==l.pointerType&&p()&&(a=s.requestAnimationFrame(C))},S=()=>{u()},b=e=>{if(!(e=>!(1&~e.buttons))(e)&&l.isSelecting)return void u();const t=I(e);if(!U(t))return;i=e.clientX,c=e.clientY;let n=null;const r=!(ge||o.contains(t));n=r?Tn(o,t):h(e.clientX,e.clientY),n&&d(n,r),_()};s.addEventListener("pointerup",S,l.listenerOptions),s.addEventListener("pointermove",b,l.listenerOptions)};l.pointerType=t.pointerType;const c=un(l.tableNodeKey),a=ne();if(ge&&t.shiftKey&&$n(a,c)&&(d(a)||tn(a))){const e=a.anchor.getNode(),o=pn(c,a.anchor.getNode());if(o)l.$setAnchorCellForSelection(Yn(l,o)),l.$setFocusCellForSelection(n),In(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&l.$setAnchorCellForSelection(n);i(n)}(e,o,s,l,n,t)})})})}function wn(e,t,n,o,l){const r=n.getRootElement(),s=mn(n);null!==r&&null!==s||at(246);const i=new cn(n,e.getKey()),c=gn(e,t);!function(e,t){null!==xn(e)&&at(205);e[an]=t}(c,i),i.listenersToRemove.add(()=>function(e,t){xn(e)===t&&delete e[an]}(c,i));i.listenersToRemove.add(O(c,"mousedown",e=>{const t=I(e);if(e.detail>=3&&U(t)){null!==vn(t)&&e.preventDefault()}},i.listenerOptions));for(const[t,o]of Cn)i.listenersToRemove.add(n.registerCommand(t,t=>Dn(n,t,o,e,i,l),E));i.listenersToRemove.add(n.registerCommand($,t=>{const n=h();if(tn(n)){const o=pn(e,n.focus.getNode());if(null!==o)return In(t),o.selectEnd(),!0}return!1},E));const a=t=>()=>{const n=h();if(!$n(n,e))return!1;if(tn(n))return i.$clearText(),!0;if(d(n)){if(!it(pn(e,n.anchor.getNode())))return!1;const o=n.anchor.getNode(),l=n.focus.getNode(),r=e.isParentOf(o),s=e.isParentOf(l);if(r&&!s||s&&!r)return i.$clearText(),!0;const c=f(n.anchor.getNode(),e=>C(e)),a=c&&f(c,e=>C(e)&&it(e.getParent()));if(!C(a)||!C(c))return!1;if(t===z&&null===a.getPreviousSibling())return!0}return!1};for(const e of _n)i.listenersToRemove.add(n.registerCommand(e,a(e),E));const g=t=>{const n=h();if(!tn(n)&&!d(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",l=o?"focus":"anchor",{key:r,offset:s,type:i}=n[l];return e[n[t].isBefore(n[l])?"selectPrevious":"selectNext"]()[l].set(r,s,i),!1}return!!$n(n,e)&&(!!tn(n)&&(t&&(t.preventDefault(),t.stopPropagation()),i.$clearText(),!0))};for(const e of Sn)i.listenersToRemove.add(n.registerCommand(e,g,E));i.listenersToRemove.add(n.registerCommand(P,e=>{const t=h();if(t){if(!tn(t)&&!d(t))return!1;Ze(n,qe(e,ClipboardEvent)?e:null,et(t));const o=g(e);return d(t)?(t.removeText(),!0):o}return!1},E));const m=r.ownerDocument;return i.listenersToRemove.add(O(m,"paste",t=>{if(t.defaultPrevented)return;n.read("latest",()=>{const t=h();return r.contains(m.activeElement)&&tn(t)&&$n(t,e)})&&(t.preventDefault(),n.dispatchCommand(D,t))})),i.listenersToRemove.add(O(m,"copy",t=>{if(t.defaultPrevented)return;const o=I(t);if(o===r||U(o)&&r.contains(o))return;n.read("latest",()=>{const t=h();return r.contains(X(r))&&tn(t)&&$n(t,e)})&&(t.preventDefault(),n.dispatchCommand(Y,t))})),i.listenersToRemove.add(n.registerCommand(J,t=>{const n=h();if(!$n(n,e))return!1;if(tn(n))return i.$formatCells(t),!0;if(d(n)){const e=f(n.anchor.getNode(),e=>it(e));if(!it(e))return!1}return!1},E)),i.listenersToRemove.add(n.registerCommand(q,t=>{const n=h();if(!tn(n)||!$n(n,e))return!1;const o=n.anchor.getNode(),l=n.focus.getNode();if(!it(o)||!it(l))return!1;if(function(e,t){if(tn(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Dt(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[r,s,i]=Dt(e,o,l),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),d=Math.min(s.startColumn,i.startColumn),f=new Set;for(let e=u;e<=c;e++)for(let n=d;n<=a;n++){const o=r[e][n].cell;if(f.has(o))continue;f.add(o),o.setFormat(t);const l=o.getChildren();for(let e=0;e<l.length;e++){const n=l[e];C(n)&&!n.isInline()&&n.setFormat(t)}}return!0},E)),i.listenersToRemove.add(n.registerCommand(j,t=>{const o=h();if(!$n(o,e))return!1;if(tn(o))return i.$clearHighlight(),!1;if(d(o)){const l=f(o.anchor.getNode(),e=>it(e));if(!it(l))return!1;if("string"==typeof t){const l=Xn(n,o,e);if(l)return Un(l,e,[u(t)]),!0}}return!1},E)),o&&i.listenersToRemove.add(n.registerCommand(V,t=>{const n=h();if(!d(n)||!n.isCollapsed()||!$n(n,e))return!1;const o=Bn(n.anchor.getNode());return!(null===o||!e.is(Ln(o)))&&(In(t),function(e,t){const n="next"===t?"getNextSibling":"getPreviousSibling",o="next"===t?"getFirstChild":"getLastChild",l=e[n]();if(C(l))return l.selectEnd();const r=f(e,ft);null===r&&at(247);for(let e=r[n]();ft(e);e=e[n]()){const t=e[o]();if(C(t))return t.selectEnd()}const s=f(r,oo);null===s&&at(248);"next"===t?s.selectNext():s.selectPrevious()}(o,t.shiftKey?"previous":"next"),!0)},E)),i.listenersToRemove.add(n.registerCommand(G,t=>e.isSelected(),E)),i.listenersToRemove.add(n.registerCommand(F,()=>{const t=h();if(!d(t)||!t.isCollapsed()||!$n(t,e))return!1;const o=Xn(n,t,e);return!!o&&(Un(o,e),!0)},E)),i}function yn(e,t){const n=h(),o=ne(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:o}=l,r=e.observers.get(t);r||at(335,t);const[s]=r;if(tn(n)&&n.tableKey===s.tableNodeKey)return(o.x!==s.focusX||o.y!==s.focusY)&&(s.$setFocusCellForSelection(o),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&o.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(o,!0),!0}const r=e.getAndClearShouldCheckSelectionForTable();if(r&&d(o)&&d(n)&&n.isCollapsed()){const e=p(r);if(oo(e)){const t=n.anchor.getNode(),o=e.getFirstChild(),l=Bn(t);if(null!==l&&ft(o)){const t=o.getFirstChild();if(it(t)&&e.is(f(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}}tn(n)&&function(e,t){const n=mn(e),o=ne();if(!t.is(o))return;const l=un(t.tableKey),r=v(n),s=r&&te(r,e.getRootElement());if(r&&s&&s.anchorNode&&s.focusNode){const n=Q(s.focusNode),o=n&&!l.isParentOf(n),i=Q(s.anchorNode),c=i&&l.isParentOf(i);if(o&&c&&r.rangeCount>0){const n=ue(r,e);n&&(n.anchor.set(l.getKey(),t.isBackward()?l.getChildrenSize():0,"element"),r.removeAllRanges(),y(n))}}}(t,n),d(n)&&function(e,t){const n=ne(),{anchor:o,focus:l}=e,r=o.getNode(),s=l.getNode(),i=Bn(r),c=Bn(s),a=i?Ln(i):null,u=c?Ln(c):null,h=e.isBackward(),f=i&&c&&a&&u&&a.is(u),g=u&&(!a||a.isParentOf(u)),m=a&&(!u||u.isParentOf(a));if(g){const t=e.clone(),[n]=Dt(u,c,c),o=n[0][0].cell,l=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),y(t)}else if(m){const t=e.clone(),[n]=Dt(a,i,i),o=n[0][0].cell,l=n[n.length-1].at(-1).cell;t.anchor.set(h?l.getKey():o.getKey(),h?l.getChildrenSize():0,"element"),y(t)}else if(f){const o=t.observers.get(a.getKey());o||at(335,a.getKey());const[l]=o;if(i.is(c)||(l.$setAnchorCellForSelection(Yn(l,i)),l.$setFocusCellForSelection(Yn(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&d(n)&&n.isCollapsed()){const e=Bn(n.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Yn(l,e)),l.$setFocusCellForSelection(Yn(l,c),!0),l.pointerType=null)}}}(n,e);for(const[n,o]of e.$getTableNodesAndObservers())Nn(t,n,o);return!1}function Nn(e,t,n){const o=h(),l=ne();o&&!o.is(l)&&(tn(o)||tn(l))&&n.tableSelection&&!n.tableSelection.is(l)&&(tn(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!tn(o)&&tn(l)&&l.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),On(t.table,t=>{const n=t.elem;t.highlighted=!1,Hn(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),On(t.table,t=>{t.highlighted=!0,zn(e,t)})}(e,n)}function xn(e){return e[an]||null}function vn(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 Tn(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function Rn(e,t){const n=[],o={columns:0,domRows:n,rows:0};let l=gn(e,t).querySelector("tr"),r=0,s=0;for(n.length=0;null!=l;){const e=l.nodeName;if("TD"===e||"TH"===e){const e={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:r,y:s};l._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[r]=e}else{const e=l.firstChild;if(null!=e){l=e;continue}}const t=l.nextSibling;if(null!=t){r++,l=t;continue}const o=l.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,r=0,l=e}}return o.columns=r+1,o.rows=s+1,o}function Fn(e,t,n){const o=new Set(n?n.getNodes():[]);On(t,(t,n)=>{const l=t.elem;o.has(n)?(t.highlighted=!0,zn(e,t)):(t.highlighted=!1,Hn(e,t),l.getAttribute("style")||l.removeAttribute("style"))})}function On(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const l=o[n];if(!l)continue;const r=Q(l.elem);null!==r&&t(l,r,{x:n,y:e})}}}const An=(e,t,n,o,l)=>{const r="forward"===l;switch(l){case"backward":case"forward":return n!==(r?e.table.columns-1:0)?Wn(t.getCellNodeFromCordsOrThrow(n+(r?1:-1),o,e.table),r):o!==(r?e.table.rows-1:0)?Wn(t.getCellNodeFromCordsOrThrow(r?0:e.table.columns-1,o+(r?1:-1),e.table),r):r?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Wn(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Wn(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Kn(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 kn([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Mn(e,t,[n,o]){const l=t[o],r=e[l];void 0===r&&at(250,o,String(l));const s=t[n],i=r[s];return void 0===i&&at(250,n,String(s)),i}function En(e,t,n,o,l){const r=Xt(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:l,maxRow:r}=t;let s=1,i=1,c=1,a=1;const u=e[l],h=e[r];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=l;t<=r;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,r),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Kn(e,t);return null===n&&at(249,t.cell.getKey()),n}(r,n),[d,f]=kn(h);let g=r[d],m=r[f];"forward"===l?g+="maxColumn"===d?1:c:"backward"===l?g-="minColumn"===d?1:u:"down"===l?m+="maxRow"===f?1:i:"up"===l&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=Xt(e,t,n),l=Kn(o,t);if(l)return[Mn(e,o,l),Mn(e,o,kn(l))];const r=Kn(o,n);if(r)return[Mn(e,o,kn(r)),Mn(e,o,r)];const s=["minColumn","minRow"];return[Mn(e,o,s),Mn(e,o,kn(s))]}(t,n,C),b=Yn(e,_.cell),w=Yn(e,S.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function $n(e,t){if(d(e)||tn(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Wn(e,t){t?e.selectStart():e.selectEnd()}function zn(e,t){const o=t.elem,l=e._config.theme;it(Q(o))||at(131),n(o,l.tableCellSelected)}function Hn(e,t){const n=t.elem;it(Q(n))||at(131);const o=e._config.theme;x(n,o.tableCellSelected)}function Bn(e){const t=f(e,it);return it(t)?t:null}function Ln(e){const t=f(e,oo);return oo(t)?t:null}function Pn(e,t,n,o,l,r,s){const i=oe(n.focus,l?"previous":"next");if(le(i))return!1;let c=i;for(const e of re(i).iterNodeCarets("shadowRoot")){if(!se(e)||!C(e.origin))return!1;c=e}const a=c.getParentAtCaret();if(!it(a))return!1;const u=a,h=function(e){for(const t of re(e).iterNodeCarets("root")){const{origin:n}=t;if(it(n)){if(he(t))return de(n,e.direction)}else if(!ft(n))break}return null}(ie(u,c.direction)),d=f(u,oo);if(!d||!d.is(r))return!1;const g=e.getElementByKey(u.getKey()),m=vn(g);if(!g||!m)return!1;const p=eo(e,d);if(s.table=p,h)if("extend"===o){const t=vn(e.getElementByKey(h.origin.getKey()));if(!t)return!1;s.$setAnchorCellForSelection(m),s.$setFocusCellForSelection(t,!0)}else{const e=ae(h);ce(n.anchor,e),ce(n.focus,e)}else if("extend"===o)s.$setAnchorCellForSelection(m),s.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=fe(e);return he(t)?ae(t):e}(ie(d,i.direction));ce(n.anchor,e),ce(n.focus,e)}return In(t),!0}function Dn(e,t,n,o,l,s){if(("up"===n||"down"===n)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=h();if(!$n(i,o)){if(d(i)){if("backward"===n){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(C(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!oo(n)&&(In(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===n||"down"===n)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===n&&!i.isBackward()||"down"===n&&i.isBackward())){let l=f(e,e=>oo(e));if(it(l)&&(l=f(l,oo)),l!==o)return!1;if(!l)return!1;const s="down"===n?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===n&&C(s)&&(c=s.getChildrenSize());let a=s;if("up"===n&&C(s)){const e=s.getLastChild();a=e||s,c=r(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,r(a)?"text":"element"),y(u),In(t),!0}if(Z(e)){const e="up"===n?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==pn(o,e)){const e=o.getFirstDescendant(),t=o.getLastDescendant();if(!e||!t)return!1;const[n]=Ut(e),[r]=Ut(t),s=o.getCordsFromCellNode(n,l.table),i=o.getCordsFromCellNode(r,l.table),c=o.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=o.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let o=f(e,e=>C(e)&&!e.isInline());if(it(o)&&(o=f(o,oo)),!o)return!1;const r="down"===n?o.getNextSibling():o.getPreviousSibling();if(oo(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),o=r.getLastDescendant();if(!e||!o)return!1;const[l]=Ut(e),[s]=Ut(o),c=i.clone();return c.focus.set(("up"===n?l:s).getKey(),"up"===n?0:s.getChildrenSize(),"element"),In(t),y(c),!0}}}}return"down"===n&&Gn(e)&&s.setShouldCheckSelectionForTable(o.getKey()),!1}if(d(i)){if("backward"===n||"forward"===n){return Pn(e,t,i,t.shiftKey?"extend":"move","backward"===n,o,l)}if(i.isCollapsed()){const{anchor:r,focus:c}=i,a=f(r.getNode(),it),u=f(c.getNode(),it);if(!it(a)||!a.is(u))return!1;const h=Ln(a);if(h!==o&&null!=h){const o=gn(h,e.getElementByKey(h.getKey()));if(null!=o)return l.table=Rn(h,o),Dn(e,t,n,h,l,s)}const d=e.getElementByKey(a.__key),g=e.getElementByKey(r.key);if(null==g||null==d)return!1;let m;if("element"===r.type)m=g.getBoundingClientRect();else{const t=v(mn(e));if(null===t||0===t.rangeCount)return!1;const n=ee(t,e.getRootElement());if(null===n)return!1;m=n.getBoundingClientRect()}const p="up"===n?a.getFirstChild():a.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===n?_.top>m.top-m.height:m.bottom+m.height>_.bottom){In(t);const e=o.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return An(l,o,e.x,e.y,n);{const t=o.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(tn(i)){const{anchor:r,focus:s,tableKey:c}=i;if(c!==o.getKey())return!1;const a=f(r.getNode(),it),u=f(s.getNode(),it),[h]=i.getNodes();oo(h)||at(251);const d=gn(h,e.getElementByKey(h.getKey()));if(!it(a)||!it(u)||!oo(h)||null==d)return!1;l.$updateTableTableSelection(i);const g=Rn(h,d),m=o.getCordsFromCellNode(a,g),p=o.getDOMCellFromCordsOrThrow(m.x,m.y,g);if(l.$setAnchorCellForSelection(p),In(t),t.shiftKey){const[e,t,r]=Dt(o,a,u);return En(l,e,t,r,n)}return u.selectEnd(),!0}return!1}function In(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Un(e,t,n){const o=i();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Xn(e,t,n){const o=n.getParent();if(!o)return;const l=v(mn(e));if(!l)return;const r=te(l,e.getRootElement()).anchorNode,s=e.getElementByKey(o.getKey()),i=gn(n,e.getElementByKey(n.getKey()));if(!r||!s||!i||!s.contains(r)||i.contains(r))return;const c=f(t.anchor.getNode(),e=>it(e));if(!c)return;const a=f(c,e=>oo(e));if(!oo(a)||!a.is(n))return;const[u,h]=Dt(n,c,c),d=u[0][0],g=u[u.length-1][u[0].length-1],{startRow:m,startColumn:p}=h,C=m===d.startRow&&p===d.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function Yn(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Jn(e,t,n){return pn(e,Q(t,n))}function qn(e,n,o){const l=e.querySelector("colgroup");if(!l)return;const r=[];for(let e=0;e<n;e++){const n=t().createElement("col"),l=o&&o[e];l&&(n.style.width=`${l}px`),r.push(n)}l.replaceChildren(...r)}function jn(e,t,o){if(!t.theme.tableAlignment)return;const l=[],r=[];for(const e of["center","right"]){const n=t.theme.tableAlignment[e];n&&(e===o?r:l).push(n)}x(e,...l),n(e,...r)}const Vn=new WeakSet;function Gn(e=w()){return Vn.has(e)}function Qn(e,t){t?Vn.add(e):Vn.delete(e)}class Zn extends e{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Zn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:to,priority:1})}}static importJSON(e){return no().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=fn(e)?e:e.querySelector("table");return fn(t)||at(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(e,o){const l=t().createElement("table");this.__style&&_e(l.style,this.__style);const r=t().createElement("colgroup");if(l.appendChild(r),Se(r),n(l,e.theme.table),this.updateTableElement(null,l,e),Gn(o)){const o=t().createElement("div"),r=e.theme.tableScrollableWrapper;return r?n(o,r):o.style.overflowX="auto",o.appendChild(l),this.updateTableWrapper(null,o,l,e),o}return l}updateTableWrapper(e,t,o,l){this.__frozenColumnCount!==(e?e.__frozenColumnCount:0)&&function(e,t,o,l){l>0?(n(e,o.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(x(e,o.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}(t,o,l,this.__frozenColumnCount),this.__frozenRowCount!==(e?e.__frozenRowCount:0)&&function(e,t,o,l){l>0?(n(e,o.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(x(e,o.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}(t,o,l,this.__frozenRowCount)}updateTableElement(e,t,o){this.__style!==(e?e.__style:"")&&_e(t.style,this.__style,e?e.__style:""),this.__rowStriping!==(!!e&&e.__rowStriping)&&function(e,t,o){o?(n(e,t.theme.tableRowStriping),e.setAttribute("data-lexical-row-striping","true")):(x(e,t.theme.tableRowStriping),e.removeAttribute("data-lexical-row-striping"))}(t,o,this.__rowStriping);const l=e?e.getColumnCount():0,r=e?e.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===r||qn(t,this.getColumnCount(),this.getColWidths()),jn(t,o,this.getFormatType())}updateDOM(e,t,n){const l=gn(this,t);return t===l===Gn()||(o(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,l,n),this.updateTableElement(e,l,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;qn(gn(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const n=super.exportDOM(e),{element:l}=n;return{after:l=>{if(n.after&&(l=n.after(l)),!fn(l)&&o(l)&&(l=l.querySelector("table")),!fn(l))return null;jn(l,e._config,this.getFormatType());const[r]=It(this,null,null),s=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();s.has(e)||s.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const i=new Set;for(const e of l.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=s.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){s.delete(t);for(let e=0;e<n.colSpan;e++)i.add(e+n.startColumn)}}}const c=l.querySelector(":scope > colgroup");if(c){const e=Array.from(l.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>i.has(t));c.replaceChildren(...e)}const a=l.querySelectorAll(":scope > tr");if(a.length>0){const e=t().createElement("tbody");for(const t of a)e.appendChild(t);l.append(e)}return l},element:!fn(l)&&o(l)?l.querySelector("table"):l}}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 l=n[o];if(null==l)continue;const{elem:r}=l,s=Jn(this,r);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,l=o[t];if(null==l)return null;const r=l[e<l.length?e:l.length-1];return null==r?null:r}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const l=Q(o.elem);return it(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!ft(e))return 0;let t=0;return e.getChildren().forEach(e=>{it(e)&&(t+=e.getColSpan())}),t}}function eo(e,t){const n=e.getElementByKey(t.getKey());return null===n&&at(230),Rn(t,n)}function to(e){const t=no();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&t.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&t.setFrozenRows(1);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!tt.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>Je(e,ft),node:t}}function no(){return c(new Zn)}function oo(e){return e instanceof Zn}function lo(e){ft(e.getParent())?e.isEmpty()&&e.append(i()):e.remove()}function ro(e){oo(e.getParent())?Qe(e,it):e.remove()}function so(e){Qe(e,ft);const[t]=It(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const l=o[e];if(!l)continue;ft(l)||at(254,l.constructor.name,l.getType());const r=t[e].reduce((e,t)=>t?1+e:e,0);if(r!==n)for(let e=r;e<n;++e){const e=st();e.append(i()),l.append(e)}}const l=e.getColWidths(),r=e.getColumnCount();if(l&&l.length!==r){let t;if(r<l.length)t=l.slice(0,r);else if(l.length>0){const e=l[l.length-1];t=[...l,...Array(r-l.length).fill(e)]}e.setColWidths(t)}}function io(e){if(e.detail<3||!U(e.target))return!1;const t=Q(e.target);if(null===t)return!1;const n=f(t,e=>C(e)&&!e.isInline());if(null===n)return!1;return!!it(n.getParent())&&(n.select(0),!0)}function co(){const e=h();if(!d(e))return!1;const t=Ln(e.anchor.getNode());if(null===t)return!1;const n=Te();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=It(t,null,null);if(0===o.length||0===o[0].length)return!1;const l=o[0][0];if(!l||!l.cell)return!1;const r=o[o.length-1],s=r[r.length-1];if(!s||!s.cell)return!1;const i=on(t,l.cell,s.cell);return y(i),!0}function ao(e){return e.registerNodeTransform(ot,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Ut(e),[n]=Dt(t,e,e),o=n.length,l=n[0].length;let r=t.getFirstChild();ft(r)||at(175);const s=[];for(let e=0;e<o;e++){0!==e&&(r=r.getNextSibling(),ft(r)||at(175));let t=null;for(let o=0;o<l;o++){const l=n[e][o],i=l.cell;if(l.startRow===e&&l.startColumn===o)t=i,s.push(i);else if(i.getColSpan()>1||i.getRowSpan()>1){it(i)||at(176);const e=st(i.__headerState);null!==t?t.insertAfter(e):je(r,e)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}})}function uo(e,t=!0){const n=new sn,o=(o,l,r)=>{const s=gn(o,r),i=wn(o,s,e,t,n);n.observers.set(l,[i,s])};return be(bn(e,n),e.registerCommand(N,()=>yn(n,e),E),e.registerMutationListener(Zn,t=>{e.read("latest",()=>{for(const[e,l]of t){const t=n.observers.get(e);if("created"===l||"updated"===l){const{tableNode:l,tableElement:r}=rn(e);void 0===t?o(l,e,r):r!==t[1]&&(n.removeObserver(e),o(l,e,r))}else"destroyed"===l&&n.removeObserver(e)}})},{skipInitialization:!1}),()=>{n.removeAllObservers()})}function ho(e,t){e.hasNodes([Zn])||at(255);const{hasNestedTables:n=We(!1)}=t??{};return be(e.registerCommand(ct,e=>function({rows:e,columns:t,includeHeaders:n},o){const l=h()||ne();if(!l||!d(l))return!1;if(!o&&Ln(l.anchor.getNode()))return!1;const s=gt(Number(e),Number(t),n);Ve(s);const i=s.getFirstDescendant();return r(i)&&i.select(),!0}(e,n.peek()),we),e.registerCommand(ye,(t,o)=>e===o&&function(e,t){const{nodes:n,selection:o}=e;if(!n.some(e=>oo(e)||Ge(e).some(e=>oo(e.node)))){if(tn(o)){let e="",t=!1;for(const o of n){const n=C(o)&&!o.isInline();e.length>0&&(n||t)&&(e+="\n"),e+=o.getTextContent(),t=n}return o.insertRawText(e),!0}return!1}const l=tn(o),r=d(o);if(!(r&&null!==f(o.anchor.getNode(),e=>it(e))&&null!==f(o.focus.getNode(),e=>it(e))||l))return!1;if(1===n.length&&oo(n[0]))return Vt(n[0],o);if(r&&t.peek()&&!function(e){if(tn(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(d(e)&&it(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(o))return!1;return!0}(t,n),we),e.registerCommand(Ne,co,xe),e.registerCommand(ve,io,we),e.registerNodeTransform(Zn,so),e.registerNodeTransform(ut,ro),e.registerNodeTransform(ot,lo))}const fo={$accepts:ft,$packageRun:e=>e.every(it)?[dt().splice(0,0,e)]:[],name:"TableSchema"},go={$accepts:it,name:"TableRowSchema"},mo=[/* @__PURE__ */Be({$import:(e,t)=>{const n=no();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!tt.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return[n.splice(0,0,Je(e.$importChildren(t),ft))]},match:Le.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */Be({$import:(e,t)=>[dt(tt.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,Je(e.$importChildren(t),it))],match:Le.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */Be({$import:(e,t)=>{const n="TH"===t.nodeName,o=tt.test(t.style.width)?parseFloat(t.style.width):void 0;let c=nt.NO_STATUS;if(n){const e=t.getAttribute("scope");if("col"===e)c=nt.COLUMN;else if("row"===e)c=nt.ROW;else{const e=t.parentElement,n=Re(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),o=0===t.cellIndex;n&&(c|=nt.ROW),o&&(c|=nt.COLUMN),c===nt.NO_STATUS&&(c=nt.ROW)}}const a=st(c,t.colSpan,o);a.__rowSpan=t.rowSpan;const u=t.style.backgroundColor;""!==u&&(a.__backgroundColor=u);const h=t.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(a.__verticalAlign=h);const d=e.get(Pe),f=d|function(e){let t=0;const n=e.fontWeight;"700"!==n&&"bold"!==n||(t|=Fe),"italic"===e.fontStyle&&(t|=Oe);const o=(e.textDecoration||"").split(" ");return o.includes("underline")&&(t|=Ae),o.includes("line-through")&&(t|=Ke),t}(t.style),g=e.get(De),m=t.style.color,p=m?{...g,color:m}:g,C=[];f!==d&&C.push(Ie(Pe,f)),p!==g&&C.push(Ie(De,p));const _=function(e){const t=[];let n=null;const o=()=>{if(null!==n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)l(c)||r(c)||s(c)?null!==n?n.append(c):(n=i().append(c),t.push(n)):(o(),n=null,t.push(c));return o(),0===t.length&&t.push(i()),t}(e.$importChildren(t,{context:C})),S=n?_:Ue(_,t);return[a.splice(0,0,S)]},match:Le.tag("td","th"),name:"@lexical/table/cell"})],po=/* @__PURE__ */ke({build:(e,t,n)=>He(t),config:/* @__PURE__ */$e({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[Xe,/* @__PURE__ */Ee(Ye,{rules:mo})],name:"@lexical/table/Table",nodes:()=>[Zn,ut,ot],register(e,t,n){const o=n.getOutput();return be(ze(()=>{const t=o.hasHorizontalScroll.value;Gn(e)!==t&&(Qn(e,t),e.update(Me))}),ho(e,o),ze(()=>uo(e,o.hasTabHandler.value)),ze(()=>o.hasCellMerge.value?void 0:ao(e)),ze(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(ot,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),Co=/* @__PURE__ */ke({dependencies:[po],name:"@lexical/table/Import"});export{Dt as $computeTableMap,It as $computeTableMapSkipCellCheck,st as $createTableCellNode,no as $createTableNode,gt as $createTableNodeWithDimensions,dt as $createTableRowNode,nn as $createTableSelection,on as $createTableSelectionFrom,Kt as $deleteTableColumn,Et as $deleteTableColumnAtSelection,$t as $deleteTableColumn__EXPERIMENTAL,kt as $deleteTableRowAtSelection,Mt as $deleteTableRow__EXPERIMENTAL,Bn as $findCellNode,Ln as $findTableNode,eo as $getElementForTableNode,Ut as $getNodeTriplet,rn as $getTableAndElementByKey,mt as $getTableCellNodeFromLexicalNode,jt as $getTableCellNodeRect,St as $getTableColumnIndexFromTableCellNode,Ct as $getTableNodeFromLexicalNodeOrThrow,_t as $getTableRowIndexFromTableCellNode,pt as $getTableRowNodeFromTableCellNodeOrThrow,Rt as $insertTableColumn,At as $insertTableColumnAtNode,Ft as $insertTableColumnAtSelection,Ot as $insertTableColumn__EXPERIMENTAL,yt as $insertTableRow,Tt as $insertTableRowAtNode,xt as $insertTableRowAtSelection,vt as $insertTableRow__EXPERIMENTAL,Gn as $isScrollableTablesActive,Yt as $isSimpleTable,it as $isTableCellNode,oo as $isTableNode,ft as $isTableRowNode,tn as $isTableSelection,Ht as $mergeCells,Jt as $moveTableColumn,qt as $moveTableRow,wt as $removeTableRowAtIndex,Qt as $setTableColumnIsHeader,Gt as $setTableRowIsHeader,Lt as $unmergeCell,Pt as $unmergeCellNode,ct as INSERT_TABLE_COMMAND,nt as TableCellHeaderStates,ot as TableCellNode,po as TableExtension,Co as TableImportExtension,mo as TableImportRules,Zn as TableNode,cn as TableObserver,ut as TableRowNode,go as TableRowSchema,fo as TableSchema,wn as applyTableHandlers,vn as getDOMCellFromTarget,gn as getTableElement,xn as getTableObserverFromTableElement,ao as registerTableCellUnmergeTransform,ho as registerTablePlugin,uo as registerTableSelectionObserver,Qn as setScrollableTablesActive};
|
package/package.json
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
"table"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.48.0",
|
|
12
12
|
"main": "./dist/LexicalTable.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/internal": "0.
|
|
19
|
-
"@lexical/utils": "0.
|
|
20
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/extension": "0.48.0",
|
|
16
|
+
"@lexical/html": "0.48.0",
|
|
17
|
+
"@lexical/clipboard": "0.48.0",
|
|
18
|
+
"@lexical/internal": "0.48.0",
|
|
19
|
+
"@lexical/utils": "0.48.0",
|
|
20
|
+
"lexical": "0.48.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
type ChildCaret,
|
|
44
44
|
COMMAND_PRIORITY_HIGH,
|
|
45
45
|
CONTROLLED_TEXT_INSERTION_COMMAND,
|
|
46
|
+
COPY_COMMAND,
|
|
46
47
|
CUT_COMMAND,
|
|
47
48
|
DELETE_CHARACTER_COMMAND,
|
|
48
49
|
DELETE_LINE_COMMAND,
|
|
@@ -52,6 +53,7 @@ import {
|
|
|
52
53
|
FOCUS_COMMAND,
|
|
53
54
|
FORMAT_ELEMENT_COMMAND,
|
|
54
55
|
FORMAT_TEXT_COMMAND,
|
|
56
|
+
getActiveElement,
|
|
55
57
|
getComposedEventTarget,
|
|
56
58
|
getDOMSelection,
|
|
57
59
|
getDOMSelectionPoints,
|
|
@@ -858,6 +860,39 @@ export function applyTableHandlers(
|
|
|
858
860
|
}),
|
|
859
861
|
);
|
|
860
862
|
|
|
863
|
+
// In read-only mode (contentEditable=false), Firefox fires the native copy
|
|
864
|
+
// event on the document rather than on the root element, so the core
|
|
865
|
+
// PASS_THROUGH copy listener never sees it. We intercept at the document
|
|
866
|
+
// level and forward to COPY_COMMAND. Unlike the paste listener above, we
|
|
867
|
+
// skip events whose target is inside the rootElement — those are already
|
|
868
|
+
// handled by the core copy listener which runs regardless of isEditable.
|
|
869
|
+
tableObserver.listenersToRemove.add(
|
|
870
|
+
registerEventListener(doc, 'copy', (event: ClipboardEvent) => {
|
|
871
|
+
if (event.defaultPrevented) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
const target = getComposedEventTarget(event);
|
|
875
|
+
if (
|
|
876
|
+
target === rootElement ||
|
|
877
|
+
(isDOMNode(target) && rootElement.contains(target))
|
|
878
|
+
) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
const shouldIntercept = editor.read('latest', () => {
|
|
882
|
+
const selection = $getSelection();
|
|
883
|
+
return (
|
|
884
|
+
rootElement.contains(getActiveElement(rootElement)) &&
|
|
885
|
+
$isTableSelection(selection) &&
|
|
886
|
+
$isSelectionInTable(selection, tableNode)
|
|
887
|
+
);
|
|
888
|
+
});
|
|
889
|
+
if (shouldIntercept) {
|
|
890
|
+
event.preventDefault();
|
|
891
|
+
editor.dispatchCommand(COPY_COMMAND, event);
|
|
892
|
+
}
|
|
893
|
+
}),
|
|
894
|
+
);
|
|
895
|
+
|
|
861
896
|
tableObserver.listenersToRemove.add(
|
|
862
897
|
editor.registerCommand(
|
|
863
898
|
FORMAT_TEXT_COMMAND,
|