@react-fabric/lexical 1.0.0-beta.47 → 1.0.0-beta.48

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.
Files changed (62) hide show
  1. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  2. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
  4. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
  5. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
  6. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
  7. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
  8. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
  9. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  10. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
  11. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
  12. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
  13. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
  14. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
  15. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
  16. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
  17. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  18. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  19. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
  20. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  21. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
  22. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
  23. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
  24. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
  25. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
  26. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
  27. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
  28. package/dist/cjs/node_modules/prismjs/prism.js +1 -1
  29. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +1 -1
  30. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
  31. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  32. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  33. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
  34. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
  35. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
  36. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
  37. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
  38. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  39. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
  40. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
  41. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
  42. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
  43. package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
  44. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
  45. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
  46. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  47. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
  48. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
  49. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
  50. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
  51. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
  52. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
  53. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
  54. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
  55. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
  56. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  57. package/dist/esm/node_modules/prismjs/prism.js +1 -1
  58. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +1 -1
  59. package/package.json +7 -8
  60. package/src/components/StickyComponent.tsx +1 -1
  61. package/src/editor/LexicalEditor.tsx +25 -21
  62. package/src/plugins/ToolbarPlugin.tsx +20 -4
@@ -11,7 +11,7 @@ import * as LexicalTable_prod from './LexicalTable.prod.js';
11
11
  *
12
12
  */
13
13
 
14
- const mod = process.env.NODE_ENV === 'development' ? LexicalTable_dev : LexicalTable_prod;
14
+ const mod = process.env.NODE_ENV !== 'production' ? LexicalTable_dev : LexicalTable_prod;
15
15
  const $isTableNode = mod.$isTableNode;
16
16
  const TableCellNode = mod.TableCellNode;
17
17
  const TableNode = mod.TableNode;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
- import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement } from '../utils/LexicalUtils.js';
4
- import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $getNodeByKey, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode } from 'lexical';
3
+ import { addClassNamesToElement, $descendantsMatching, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement as isHTMLElement$1, $insertFirst, mergeRegister, $insertNodeToNearestRoot, $unwrapAndFilterDescendants } from '../utils/LexicalUtils.js';
4
+ import { ElementNode, isHTMLElement, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $getNodeByKey, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $isParagraphNode, $isRootNode, INSERT_PARAGRAPH_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_CRITICAL, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $getNearestNodeFromDOMNode, $createRangeSelectionFromDom, $isRootOrShadowRoot, setDOMUnmanaged, COMMAND_PRIORITY_EDITOR, CLICK_COMMAND, TEXT_TYPE_TO_FORMAT, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, isDOMNode, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isSiblingCaret, $isChildCaret, $getChildCaret, $getSiblingCaret, $normalizeCaret, $setPointFromCaret, $getAdjacentChildCaret } from 'lexical';
5
5
  import { copyToClipboard, $getClipboardDataFromSelection } from '../clipboard/LexicalClipboard.js';
6
6
 
7
7
  /**
@@ -12,6 +12,6 @@ import { copyToClipboard, $getClipboardDataFromSelection } from '../clipboard/Le
12
12
  *
13
13
  */
14
14
 
15
- const G=/^(\d+(?:\.\d+)?)px$/,Q={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class V extends ElementNode{static getType(){return "tablecell"}static clone(e){const t=new V(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return {td:e=>({conversion:Z,priority:0}),th:e=>({conversion:Z,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=ee(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=Q.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null;}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5");}return {element:t}}exportJSON(){return {...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){return this.getWritable().__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){return this.getWritable().__width=e,this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e;}toggleHeaderStyle(e){const t=this.getWritable();return (t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return (this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Q.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return !0}collapseAtStart(){return !0}canBeEmpty(){return !1}canIndent(){return !1}}function Z(e){const t=e,n=e.nodeName.toLowerCase();let o;G.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ee("th"===n?Q.ROW:Q.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const d=t.style,u=d.textDecoration.split(" "),h="700"===d.fontWeight||"bold"===d.fontWeight,g=u.includes("line-through"),f="italic"===d.fontStyle,m=u.includes("underline");return {after:e=>(0===e.length&&e.push($createParagraphNode()),e),forChild:(e,t)=>{if(te(t)&&!$isElementNode(e)){const t=$createParagraphNode();return $isLineBreakNode(e)&&"\n"===e.getTextContent()?null:($isTextNode(e)&&(h&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function ee(e,t=1,n){return $applyNodeReplacement(new V(e,t,n))}function te(e){return e instanceof V}const ne=createCommand("INSERT_TABLE_COMMAND");class oe extends ElementNode{static getType(){return "tablerow"}static clone(e){return new oe(e.__height,e.__key)}static importDOM(){return {tr:e=>({conversion:re,priority:0})}}static importJSON(e){return le(e.height)}constructor(e,t){super(t),this.__height=e;}exportJSON(){return {...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),addClassNamesToElement(n,t.theme.tableRow),n}isShadowRoot(){return !0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return !1}canIndent(){return !1}}function re(e){const t=e;let n;return G.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:le(n)}}function le(e){return $applyNodeReplacement(new oe(e))}function se(e){return e instanceof oe}function ie(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ce=ie((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function de(e,t,n=!0){const o=at();for(let r=0;r<e;r++){const e=le();for(let o=0;o<t;o++){let t=Q.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Q.ROW),0===o&&n.columns&&(t|=Q.COLUMN)):n&&(0===r&&(t|=Q.ROW),0===o&&(t|=Q.COLUMN));const l=ee(t),i=$createParagraphNode();i.append($createTextNode()),l.append(i),e.append(l);}o.append(e);}return o}function ue(e){const n=$findMatchingParent(e,(e=>te(e)));return te(n)?n:null}function he(e){const n=$findMatchingParent(e,(e=>se(e)));if(se(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ge(e){const n=$findMatchingParent(e,(e=>dt(e)));if(dt(n))return n;throw new Error("Expected table cell to be inside of table.")}function fe(e){const t=he(e);return ge(t).getChildren().findIndex((e=>e.is(t)))}function me(e){return he(e).getChildren().findIndex((t=>t.is(e)))}function pe(e,t){const n=ge(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return {above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function Ce(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 Se(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const i=l[t];if(!se(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=le();for(let n=0;n<t;n++){const t=e[n];te(t)||ce(12);const{above:l,below:i}=pe(t,r);let c=Q.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Q.COLUMN)||i&&i.hasHeaderState(Q.COLUMN))&&(c|=Q.COLUMN);const d=ee(c,1,a);d.append($createParagraphNode()),o.append(d);}n?i.insertAfter(o):i.insertBefore(o);}return e}const _e=(e,t)=>e===Q.BOTH||e===t?t:Q.NO_STATUS;function we(e=!0){const t=$getSelection();$isRangeSelection(t)||Ae(t)||ce(188);const n=t.focus.getNode(),[o,,r]=Ke(n),[l,i]=Me(r,o,o),c=l[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=l[e],n=le();for(let o=0;o<c;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=_e(e,Q.COLUMN);n.append(ee(r).append($createParagraphNode()));}else r.setRowSpan(r.__rowSpan+1);}const i=r.getChildAtIndex(e);se(i)||ce(145),i.insertAfter(n);}else {const e=l[a],t=le();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=_e(o,Q.COLUMN);t.append(ee(r).append($createParagraphNode()));}else o.setRowSpan(o.__rowSpan+1);}const n=r.getChildAtIndex(a);se(n)||ce(145),n.insertBefore(t);}}function be(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(se(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];te(o)||ce(12);const{left:l,right:c}=pe(o,r);let a=Q.NO_STATUS;(l&&l.hasHeaderState(Q.ROW)||c&&c.hasHeaderState(Q.ROW))&&(a|=Q.ROW);const d=ee(a);d.append($createParagraphNode()),i.push({newTableCell:d,targetCell:o});}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e);})),e}function ye(e=!0){const t=$getSelection();$isRangeSelection(t)||Ae(t)||ce(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ke(n),[l,,i]=Ke(o),[c,a,d]=Me(i,l,r),u=c.length,h=e?Math.max(a.startColumn,d.startColumn):Math.min(a.startColumn,d.startColumn),m=e?h+l.__colSpan-1:h-1,p=i.getFirstChild();se(p)||ce(120);let C=null;function S(e=Q.NO_STATUS){const t=ee(e).append($createParagraphNode());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<u;e++){if(0!==e){const e=_.getNextSibling();se(e)||ce(121),_=e;}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=_e(n,Q.ROW);if(m<0){Ee(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(S(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o;}}n.insertAfter(S(o));}else r.setColSpan(r.__colSpan+1);}null!==C&&ve(C);}function Ne(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(se(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 Te(){const e=$getSelection();$isRangeSelection(e)||Ae(e)||ce(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ke(t),[l]=Ke(n),[s,i,c]=Me(r,o,l),{startRow:a}=i,{startRow:d}=c,u=d+l.__rowSpan-1;if(s.length===u-a+1)return void r.remove();const h=s[0].length,m=s[u+1],p=r.getChildAtIndex(u+1);for(let e=u;e>=a;e--){for(let t=h-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>u))if(n.setRowSpan(n.__rowSpan-(u-o+1)),null===p&&ce(122),0===t)Ee(p,n);else {const{cell:e}=m[t-1];e.insertAfter(n);}}const t=r.getChildAtIndex(e);se(t)||ce(123,String(e)),t.remove();}if(void 0!==m){const{cell:e}=m[0];ve(e);}else {const e=s[a-1],{cell:t}=e[0];ve(t);}}function xe(){const e=$getSelection();$isRangeSelection(e)||Ae(e)||ce(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ke(t),[l]=Ke(n),[s,i,c]=Me(r,o,l),{startColumn:a}=i,{startRow:d,startColumn:u}=c,h=Math.min(a,u),m=Math.max(a+o.__colSpan-1,u+l.__colSpan-1),p=m-h+1;if(s[0].length===m-h+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=h;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<h){if(t===h){const e=h-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=s[d],_=a>u?S[a+o.__colSpan]:S[u+l.__colSpan];if(void 0!==_){const{cell:e}=_;ve(e);}else {const e=u<a?S[u-1]:S[a-1],{cell:t}=e;ve(t);}}function ve(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart();}function Ee(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t);}function Oe(){const e=$getSelection();$isRangeSelection(e)||Ae(e)||ce(188);const t=e.anchor.getNode(),[n,o,r]=Ke(t),l=n.__colSpan,i=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(ee(Q.NO_STATUS).append($createParagraphNode()));n.setColSpan(1);}if(i>1){const[e,t]=Me(r,n,n),{startColumn:c,startRow:a}=t;let d;for(let t=1;t<i;t++){const n=a+t,r=e[n];d=(d||o).getNextSibling(),se(d)||ce(125);let i=null;for(let e=0;e<c;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1);}if(null===i)for(let e=0;e<l;e++)Ee(d,ee(Q.NO_STATUS).append($createParagraphNode()));else for(let e=0;e<l;e++)i.insertAfter(ee(Q.NO_STATUS).append($createParagraphNode()));}n.setRowSpan(1);}}function Me(e,t,n){const[o,r,l]=Re(e,t,n);return null===r&&ce(110),null===l&&ce(111),[o,r,l]}function Re(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const c={cell:i,startColumn:s,startRow:e},a=i.__rowSpan,d=i.__colSpan;for(let t=0;t<a;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<d;n++)o[e+t][s+n]=c;}null!==t&&t.is(i)&&(r=c),null!==n&&n.is(i)&&(l=c);}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const c=e.getChildren();for(let e=0;e<c.length;e++){const t=c[e];se(t)||ce(146);const n=t.getChildren();let o=0;for(const t of n){for(te(t)||ce(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan;}}return [o,r,l]}function Ke(e){let n;if(e instanceof V)n=e;else if("__type"in e){const o=$findMatchingParent(e,te);te(o)||ce(148),n=o;}else {const o=$findMatchingParent(e.getNode(),te);te(o)||ce(148),n=o;}const o=n.getParent();se(o)||ce(149);const r=o.getParent();return dt(r)||ce(150),[n,o,r]}function Fe(e){const[t,,n]=Ke(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return {colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c;}}return null}class ke{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e;}getStartEndPoints(){return [this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e;}is(e){return !!Ae(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null;}clone(){return new ke(this.tableKey,this.anchor,this.focus)}isCollapsed(){return !1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();$isElementNode(t)||ce(151);$normalizeSelection__EXPERIMENTAL(t.select(0,t.getChildrenSize())).insertNodes(e);}getShape(){const e=$getNodeByKey(this.anchor.key);te(e)||ce(152);const t=Fe(e);null===t&&ce(153);const n=$getNodeByKey(this.focus.key);te(n)||ce(154);const o=Fe(n);null===o&&ce(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex,o.columnIndex),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex,o.rowIndex);return {fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=$findMatchingParent(n,te),l=$findMatchingParent(o,te);te(r)||ce(152),te(l)||ce(154);const s=r.getParent();se(s)||ce(156);const i=s.getParent();dt(i)||ce(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&ce(159),this.set(this.tableKey,l.getKey(),e.getKey());}else {const e=i.getParent();null==e&&ce(158),this.set(this.tableKey,e.getKey(),l.getKey());}return this.getNodes()}const[a,d,u]=Me(i,r,l);let h=Math.min(d.startColumn,u.startColumn),g=Math.min(d.startRow,u.startRow),f=Math.max(d.startColumn+d.cell.__colSpan-1,u.startColumn+u.cell.__colSpan-1),m=Math.max(d.startRow+d.cell.__rowSpan-1,u.startRow+u.cell.__rowSpan-1),p=h,C=g,_=h,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;h=Math.min(h,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1);}for(;h<p||g<C||f>_||m>w;){if(h<p){const e=w-C,t=p-1;for(let n=0;n<=e;n++)b(a[C+n][t]);p=t;}if(g<C){const e=_-p,t=C-1;for(let n=0;n<=e;n++)b(a[t][p+n]);C=t;}if(f>_){const e=w-C,t=_+1;for(let n=0;n<=e;n++)b(a[C+n][t]);_=t;}if(m>w){const e=_-p,t=w+1;for(let n=0;n<=e;n++)b(a[t][p+n]);w=t;}}const y=[i];let N=null;for(let e=g;e<=m;e++)for(let t=h;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();se(o)||ce(160),o!==N&&y.push(o),y.push(n,...De(n)),N=o;}return isCurrentlyReadOnlyMode()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes().filter((e=>te(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 Ae(e){return e instanceof ke}function He(){const e=$createPoint("root",0,"element"),t=$createPoint("root",0,"element");return new ke("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&ce(112),$isElementNode(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o);}return t}class Pe{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.trackTable(),this.isSelecting=!1;}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach((e=>e()));}trackTable(){const e=new MutationObserver((e=>{this.editor.update((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const n=this.editor.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");this.table=ze(n);}));}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=ze(t),e.observe(t,{attributes:!0,childList:!0,subtree:!0});}));}clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),e.update((()=>{if(!dt($getNodeByKey(this.tableNodeKey)))throw new Error("Expected TableNode.");const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");const n=ze(t);Ye(e,n,null),$setSelection(null),e.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0);}));}enableHighlightStyle(){const e=this.editor;e.update((()=>{const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");removeClassNamesFromElement(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1;}));}disableHighlightStyle(){const t=this.editor;t.update((()=>{const n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");addClassNamesToElement(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0;}));}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ye(t,this.table,this.tableSelection);}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e));}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const o=$getNodeByKey(this.tableNodeKey);if(!dt(o))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");const r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=Le(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0);}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=$getNearestNodeFromDOMNode(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&te(t)&&o.is(tt(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||He(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),$setSelection(this.tableSelection),n.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0),Ye(n,this.table,this.tableSelection);}}}));}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=$getNearestNodeFromDOMNode(e.elem);if(te(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():He(),this.anchorCellNodeKey=e;}}));}formatCells(e){this.editor.update((()=>{const t=$getSelection();Ae(t)||ce(11);const n=$createRangeSelection(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{te(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e));})),$setSelection(t),this.editor.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0);}));}clearText(){const e=this.editor;e.update((()=>{const t=$getNodeByKey(this.tableNodeKey);if(!dt(t))throw new Error("Expected TableNode.");const n=$getSelection();Ae(n)||ce(11);const o=n.getNodes().filter(te);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if($isElementNode(e)){const t=$createParagraphNode(),n=$createTextNode();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove();}));}})),Ye(e,this.table,null),$setSelection(null),e.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0);else {t.selectPrevious(),t.remove();$getRoot().selectStart();}}));}}const Be="__lexicalTableSelection",Le=e=>ae?(e||window).getSelection():null;function Ie(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const d=new Pe(r,e.getKey()),u=r._window||window;!function(e,t){e[Be]=t;}(n,d);const m=()=>{const e=()=>{d.isSelecting=!1,u.removeEventListener("mouseup",e),u.removeEventListener("mousemove",t);},t=n=>{setTimeout((()=>{if(1&~n.buttons&&d.isSelecting)return d.isSelecting=!1,u.removeEventListener("mouseup",e),void u.removeEventListener("mousemove",t);const o=Ue(n.target);null===o||d.anchorX===o.x&&d.anchorY===o.y||(n.preventDefault(),d.setFocusCellForSelection(o));}),0);};return {onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!u)return;const t=Ue(e.target);null!==t&&(ot(e),d.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=m();d.isSelecting=!0,u.addEventListener("mouseup",n),u.addEventListener("mousemove",o);}),0);}));const p=e=>{0===e.button&&r.update((()=>{const t=$getSelection(),n=e.target;Ae(t)&&t.tableKey===d.tableNodeKey&&c.contains(n)&&d.clearHighlight();}));};u.addEventListener("mousedown",p),d.listenersToRemove.add((()=>u.removeEventListener("mousedown",p))),d.listenersToRemove.add(r.registerCommand(KEY_ARROW_DOWN_COMMAND,(t=>nt(r,t,"down",e,d)),COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(r.registerCommand(KEY_ARROW_UP_COMMAND,(t=>nt(r,t,"up",e,d)),COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(r.registerCommand(KEY_ARROW_LEFT_COMMAND,(t=>nt(r,t,"backward",e,d)),COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(r.registerCommand(KEY_ARROW_RIGHT_COMMAND,(t=>nt(r,t,"forward",e,d)),COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(r.registerCommand(KEY_ESCAPE_COMMAND,(e=>{const n=$getSelection();if(Ae(n)){const o=$findMatchingParent(n.focus.getNode(),te);if(te(o))return ot(e),o.selectEnd(),!0}return !1}),COMMAND_PRIORITY_HIGH));[DELETE_WORD_COMMAND,DELETE_LINE_COMMAND,DELETE_CHARACTER_COMMAND].forEach((n=>{d.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=$getSelection();if(!qe(o,e))return !1;if(Ae(o))return d.clearText(),!0;if($isRangeSelection(o)){const r=$findMatchingParent(o.anchor.getNode(),(e=>te(e)));if(!te(r))return !1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return d.clearText(),!0;const u=$findMatchingParent(o.anchor.getNode(),(e=>$isElementNode(e))),h=u&&$findMatchingParent(u,(e=>$isElementNode(e)&&te(e.getParent())));if(!$isElementNode(h)||!$isElementNode(u))return !1;if(n===DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return !0}return !1})(n),COMMAND_PRIORITY_CRITICAL));}));const C=n=>{const o=$getSelection();if(!qe(o,e)){const e=o?o.getNodes():null;if(e){const t=e.find((e=>dt(e)&&e.getKey()===d.tableNodeKey));if(dt(t)){if(!t.getParent())return !1;t.remove();}}return !1}if(Ae(o))return n&&(n.preventDefault(),n.stopPropagation()),d.clearText(),!0;if($isRangeSelection(o)){const e=$findMatchingParent(o.anchor.getNode(),(e=>te(e)));if(!te(e))return !1}return !1};function S(t){const n=e.getCordsFromCellNode(t,d.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,d.table)}return d.listenersToRemove.add(r.registerCommand(KEY_BACKSPACE_COMMAND,C,COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(KEY_DELETE_COMMAND,C,COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(CUT_COMMAND,(e=>{const t=$getSelection();if(t){if(!Ae(t)&&!$isRangeSelection(t))return !1;copyToClipboard(r,objectKlassEquals(e,ClipboardEvent)?e:null,$getClipboardDataFromSelection(t));const n=C(e);return $isRangeSelection(t)&&t.removeText(),n}return !1}),COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(FORMAT_TEXT_COMMAND,(n=>{const o=$getSelection();if(!qe(o,e))return !1;if(Ae(o))return d.formatCells(n),!0;if($isRangeSelection(o)){const e=$findMatchingParent(o.anchor.getNode(),(e=>te(e)));if(!te(e))return !1}return !1}),COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(FORMAT_ELEMENT_COMMAND,(t=>{const n=$getSelection();if(!Ae(n)||!qe(n,e))return !1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!te(o)||!te(r))return !1;const[l,s,c]=Me(e,o,r),a=Math.max(s.startRow,c.startRow),d=Math.max(s.startColumn,c.startColumn),u=Math.min(s.startRow,c.startRow),h=Math.min(s.startColumn,c.startColumn);for(let e=u;e<=a;e++)for(let n=h;n<=d;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];$isElementNode(n)&&!n.isInline()&&n.setFormat(t);}}return !0}),COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND,(n=>{const o=$getSelection();if(!qe(o,e))return !1;if(Ae(o))return d.clearHighlight(),!1;if($isRangeSelection(o)){const l=$findMatchingParent(o.anchor.getNode(),(e=>te(e)));if(!te(l))return !1;if("string"==typeof n){const t=lt(r,o,e);if(t)return rt(t,e,[$createTextNode(n)]),!0}}return !1}),COMMAND_PRIORITY_CRITICAL)),l&&d.listenersToRemove.add(r.registerCommand(KEY_TAB_COMMAND,(t=>{const n=$getSelection();if(!$isRangeSelection(n)||!n.isCollapsed()||!qe(n,e))return !1;const o=et(n.anchor.getNode());if(null===o)return !1;ot(t);const r=e.getCordsFromCellNode(o,d.table);return $e(d,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(FOCUS_COMMAND,(t=>e.isSelected()),COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(r.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=Ae(o),i=$isRangeSelection(o)&&null!==$findMatchingParent(o.anchor.getNode(),(e=>te(e)))&&null!==$findMatchingParent(o.focus.getNode(),(e=>te(e)))||l;if(1!==n.length||!dt(n[0])||!i||null===r)return !1;const[c]=r,d=n[0],u=d.getChildren(),h=d.getFirstChildOrThrow().getChildrenSize(),g=d.getChildrenSize(),m=$findMatchingParent(c.getNode(),(e=>te(e))),p=m&&$findMatchingParent(m,(e=>se(e))),C=p&&$findMatchingParent(p,(e=>dt(e)));if(!te(m)||!se(p)||!dt(C))return !1;const S=p.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),w=m.getIndexWithinParent(),b=Math.min(p.getChildrenSize()-1,w+h-1),y=Math.min(w,b),N=Math.min(S,_),T=Math.max(w,b),x=Math.max(S,_),v=C.getChildren();let E=0;for(let e=N;e<=x;e++){const t=v[e];if(!se(t))return !1;const n=u[E];if(!se(n))return !1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=T;e++){const t=o[e];if(!te(t))return !1;const n=r[l];if(!te(n))return !1;const i=t.getChildren();n.getChildren().forEach((e=>{if($isTextNode(e)){$createParagraphNode().append(e),t.append(e);}else t.append(e);})),i.forEach((e=>e.remove())),l++;}E++;}return !0}),COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(SELECTION_CHANGE_COMMAND,(()=>{const t=$getSelection(),n=$getPreviousSelection();if($isRangeSelection(t)){const{anchor:n,focus:o}=t,l=n.getNode(),s=o.getNode(),i=et(l),c=et(s),a=!(!i||!e.is(tt(i))),h=!(!c||!e.is(tt(c))),g=a!==h,f=a&&h,p=t.isBackward();if(g){const n=t.clone();if(h){const[t]=Me(e,c,c),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element");}$setSelection(n),Je(r,d);}else f&&(i.is(c)||(d.setAnchorCellForSelection(S(i)),d.setFocusCellForSelection(S(c),!0),d.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=m();d.isSelecting=!0,u.addEventListener("mouseup",e),u.addEventListener("mousemove",t);}),0)));}else if(t&&Ae(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Le(r._window);if(n&&n.anchorNode&&n.focusNode){const o=$getNearestNodeFromDOMNode(n.focusNode),l=o&&!e.is(tt(o)),s=$getNearestNodeFromDOMNode(n.anchorNode),i=s&&e.is(tt(s));if(l&&i&&n.rangeCount>0){const o=$createRangeSelectionFromDom(n,r);o&&(o.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),$setSelection(o));}}}return t&&!t.is(n)&&(Ae(t)||Ae(n))&&d.tableSelection&&!d.tableSelection.is(n)?(Ae(t)&&t.tableKey===d.tableNodeKey?d.updateTableTableSelection(t):!Ae(t)&&Ae(n)&&n.tableKey===d.tableNodeKey&&d.updateTableTableSelection(null),!1):(d.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Xe(t.table,(t=>{const n=t.elem;t.highlighted=!1,Ze(e,t),n.getAttribute("style")||n.removeAttribute("style");}));}(r,d):!d.hasHijackedSelectionStyles&&e.isSelected()&&Je(r,d),!1)}),COMMAND_PRIORITY_CRITICAL)),d.listenersToRemove.add(r.registerCommand(INSERT_PARAGRAPH_COMMAND,(()=>{const t=$getSelection();if(!$isRangeSelection(t)||!t.isCollapsed()||!qe(t,e))return !1;const n=lt(r,t,e);return !!n&&(rt(n,e),!0)}),COMMAND_PRIORITY_CRITICAL)),d}function We(e){return e[Be]}function Ue(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 ze(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.firstChild,r=0,l=0;for(t.length=0;null!=o;){const e=o.nodeName;if("TD"===e||"TH"===e){const e={elem:o,hasBackgroundColor:""!==o.style.backgroundColor,highlighted:!1,x:r,y:l};o._cell=e;let n=t[l];void 0===n&&(n=t[l]=[]),n[r]=e;}else {const e=o.firstChild;if(null!=e){o=e;continue}}const n=o.nextSibling;if(null!=n){r++,o=n;continue}const s=o.parentNode;if(null!=s){const e=s.nextSibling;if(null==e)break;l++,r=0,o=e;}}return n.columns=r+1,n.rows=l+1,n}function Ye(e,t,n){const o=new Set(n?n.getNodes():[]);Xe(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Ve(e,t)):(t.highlighted=!1,Ze(e,t),r.getAttribute("style")||r.removeAttribute("style"));}));}function Xe(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=$getNearestNodeFromDOMNode(r.elem);null!==l&&t(r,l,{x:n,y:e});}}}function Je(e,t){t.disableHighlightStyle(),Xe(t.table,(t=>{t.highlighted=!0,Ve(e,t);}));}const $e=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ge(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ge(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?Ge(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ge(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return !1}},je=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return !1}};function qe(e,t){if($isRangeSelection(e)||Ae(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return !1}function Ge(e,t){t?e.selectStart():e.selectEnd();}const Qe="172,206,247";function Ve(e,t){const n=t.elem,o=$getNearestNodeFromDOMNode(n);te(o)||ce(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Qe})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Qe},0.85), rgba(${Qe},0.85))`),n.style.setProperty("caret-color","transparent");}function Ze(e,t){const n=t.elem,o=$getNearestNodeFromDOMNode(n);te(o)||ce(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color");}function et(e){const n=$findMatchingParent(e,te);return te(n)?n:null}function tt(e){const n=$findMatchingParent(e,dt);return dt(n)?n:null}function nt(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return !1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return !1;const s=$getSelection();if(!qe(s,r)){if($isRangeSelection(s)){if(s.isCollapsed()&&"backward"===o){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return !1;const r=s.anchor.getNode();if(!r)return !1;const l=$findMatchingParent(r,(e=>$isElementNode(e)&&!e.isInline()));if(!l)return !1;const c=l.getPreviousSibling();return !(!c||!dt(c))&&(ot(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if($isRootOrShadowRoot(e)){const e=s.getNodes()[0];if(e){const n=$findMatchingParent(e,te);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return !1;const[n]=Ke(e),[o]=Ke(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.setAnchorCellForSelection(c),l.setFocusCellForSelection(a,!0),!0}}return !1}{const n=$findMatchingParent(e,(e=>$isElementNode(e)&&!e.isInline()));if(!n)return !1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(dt(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return !1;const[n]=Ke(e),[l]=Ke(t),i=s.clone();return i.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),$setSelection(i),!0}}}}return !1}if($isRangeSelection(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,d=$findMatchingParent(c.getNode(),te),u=$findMatchingParent(a.getNode(),te);if(!te(d)||!d.is(u))return !1;const h=tt(d);if(h!==r&&null!=h){const t=e.getElementByKey(h.getKey());if(null!=t)return l.table=ze(t),nt(e,n,o,h,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return !1;const d=s.getNodes();return (1!==d.length||!$isDecoratorNode(d[0]))&&(!!function(e,n,o,r){return function(e,t,n){return "element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=$findMatchingParent(o,(e=>$isElementNode(e)&&!e.isInline()));if(!l)return !1;const s="backward"===r?0===n:n===o.getTextContentSize();return "text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=$findMatchingParent(n,te);if(!te(l))return !1;const[s,c]=Me(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return "backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,c,r))return !1;const a=function(e,n,o){const r=$findMatchingParent(e,(e=>$isElementNode(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&dt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||dt(a))return !1;ot(e),"backward"===r?a.selectEnd():a.selectStart();return !0}(n,a,r,o))}const g=e.getElementByKey(d.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return !1;let m;if("element"===c.type)m=f.getBoundingClientRect();else {const e=window.getSelection();if(null===e||0===e.rangeCount)return !1;m=e.getRangeAt(0).getBoundingClientRect();}const p="up"===o?d.getFirstChild():d.getLastChild();if(null==p)return !1;const C=e.getElementByKey(p.__key);if(null==C)return !1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){ot(n);const e=r.getCordsFromCellNode(d,l.table);if(!n.shiftKey)return $e(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(Ae(s)){const{anchor:i,focus:c}=s,a=$findMatchingParent(i.getNode(),te),d=$findMatchingParent(c.getNode(),te),[u]=s.getNodes(),h=e.getElementByKey(u.getKey());if(!te(a)||!te(d)||!dt(u)||null==h)return !1;l.updateTableTableSelection(s);const g=ze(h),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),ot(n),n.shiftKey){const e=r.getCordsFromCellNode(d,g);return je(l,u,e.x,e.y,o)}return d.selectEnd(),!0}return !1}function ot(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation();}function rt(e,t,n){const o=$createParagraphNode();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd();}function lt(e,n,o){const r=o.getParent();if(!r)return;const l=e.getElementByKey(r.getKey());if(!l)return;const s=window.getSelection();if(!s||s.anchorNode!==l)return;const i=$findMatchingParent(n.anchor.getNode(),(e=>te(e)));if(!i)return;const c=$findMatchingParent(i,(e=>dt(e)));if(!dt(c)||!c.is(o))return;const[a,d]=Me(o,i,i),u=a[0][0],h=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=d,m=g===u.startRow&&f===u.startColumn,p=g===h.startRow&&f===h.startColumn;return m?"first":p?"last":void 0}class st extends ElementNode{static getType(){return "table"}static clone(e){return new st(e.__key)}static importDOM(){return {table:e=>({conversion:ct,priority:1})}}static importJSON(e){return at()}constructor(e){super(e);}exportJSON(){return {...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return addClassNamesToElement(o,t.theme.table),o}updateDOM(){return !1}exportDOM(e){return {...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),o=document.createElement("tbody");isHTMLElement(e)&&o.append(...e.children);const l=this.getFirstChildOrThrow();if(!se(l))throw new Error("Expected to find row node.");const s=l.getChildrenSize();for(let e=0;e<s;e++){const e=document.createElement("col");n.append(e);}return t.replaceChildren(n,o),t}}}}canBeEmpty(){return !1}isShadowRoot(){return !0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return $getNearestNodeFromDOMNode(n)===e}));if(-1!==r)return {x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=$getNearestNodeFromDOMNode(o.elem);return te(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}canSelectBefore(){return !0}canIndent(){return !1}}function it(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return ze(n)}function ct(e){return {node:at()}}function at(){return $applyNodeReplacement(new st)}function dt(e){return e instanceof st}
15
+ const Se=/^(\d+(?:\.\d+)?)px$/,we={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class be extends ElementNode{static getType(){return "tablecell"}static clone(e){return new be(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;}static importDOM(){return {td:e=>({conversion:Ne,priority:0}),th:e=>({conversion:Ne,priority:0})}}static importJSON(e){return xe().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=we.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=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),ye(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(isHTMLElement(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(),...ye(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=we.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!==we.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 ye(e){return "middle"===e||"bottom"===e}function Ne(e){const t=e,n=e.nodeName.toLowerCase();let o;Se.test(t.style.width)&&(o=parseFloat(t.style.width));const r=xe("th"===n?we.ROW:we.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;ye(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return {after:e=>(0===e.length&&e.push($createParagraphNode()),e),forChild:(e,t)=>{if(ve(t)&&!$isElementNode(e)){const t=$createParagraphNode();return $isLineBreakNode(e)&&"\n"===e.getTextContent()?null:($isTextNode(e)&&(a&&e.toggleFormat("bold"),u&&e.toggleFormat("strikethrough"),h&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function xe(e=we.NO_STATUS,t=1,n){return $applyNodeReplacement(new be(e,t,n))}function ve(e){return e instanceof be}const Te=createCommand("INSERT_TABLE_COMMAND");function Re(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 Fe extends ElementNode{static getType(){return "tablerow"}static clone(e){return new Fe(e.__height,e.__key)}static importDOM(){return {tr:e=>({conversion:Ae,priority:0})}}static importJSON(e){return Oe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e;}exportJSON(){const e=this.getHeight();return {...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),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 Ae(e){const n=e;let o;return Se.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>$descendantsMatching(e,ve),node:Oe(o)}}function Oe(e){return $applyNodeReplacement(new Fe(e))}function Ke(e){return e instanceof Fe}const Ee="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ke=Ee&&"documentMode"in document?document.documentMode:null,Me=Ee&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function $e(e,t,n=!0){const o=rn();for(let r=0;r<e;r++){const e=Oe();for(let o=0;o<t;o++){let t=we.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=we.ROW),0===o&&n.columns&&(t|=we.COLUMN)):n&&(0===r&&(t|=we.ROW),0===o&&(t|=we.COLUMN));const l=xe(t),s=$createParagraphNode();s.append($createTextNode()),l.append(s),e.append(l);}o.append(e);}return o}function Le(e){const t=$findMatchingParent(e,(e=>ve(e)));return ve(t)?t:null}function ze(e){const t=$findMatchingParent(e,(e=>Ke(e)));if(Ke(t))return t;throw new Error("Expected table cell to be inside of table row.")}function We(e){const t=$findMatchingParent(e,(e=>ln(e)));if(ln(t))return t;throw new Error("Expected table cell to be inside of table.")}function He(e){const t=ze(e);return We(t).getChildren().findIndex((e=>e.is(t)))}function Be(e){return ze(e).getChildren().findIndex((t=>t.is(e)))}function Pe(e,t){const n=We(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return {above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function De(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 Ie(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!Ke(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=Oe();for(let n=0;n<t;n++){const t=e[n];ve(t)||Re(12);const{above:l,below:s}=Pe(t,r);let i=we.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(we.COLUMN)||s&&s.hasHeaderState(we.COLUMN))&&(i|=we.COLUMN);const a=xe(i,1,c);a.append($createParagraphNode()),o.append(a);}n?s.insertAfter(o):s.insertBefore(o);}return e}Ee&&"InputEvent"in window&&!ke&&new window.InputEvent("input");const Ue=(e,t)=>e===we.BOTH||e===t?t:we.NO_STATUS;function Je(e=!0){const t=$getSelection();$isRangeSelection(t)||it(t)||Re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i[0].length,{startRow:h}=a,{startRow:f}=c;let g=null;if(e){const e=Math.max(f+l.__rowSpan,h+r.__rowSpan)-1,t=i[e],n=Oe();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append($createParagraphNode()));}else r.setRowSpan(r.__rowSpan+1);}const o=s.getChildAtIndex(e);Ke(o)||Re(256),o.insertAfter(n),g=n;}else {const e=Math.min(f,h),t=i[e],n=Oe();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l===e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append($createParagraphNode()));}else r.setRowSpan(r.__rowSpan+1);}const o=s.getChildAtIndex(e);Ke(o)||Re(257),o.insertBefore(n),g=n;}return g}function Ye(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Ke(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];ve(o)||Re(12);const{left:l,right:i}=Pe(o,r);let c=we.NO_STATUS;(l&&l.hasHeaderState(we.ROW)||i&&i.hasHeaderState(we.ROW))&&(c|=we.ROW);const a=xe(c);a.append($createParagraphNode()),s.push({newTableCell:a,targetCell:o});}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e);})),e}function qe(e=!0){const t=$getSelection();$isRangeSelection(t)||it(t)||Re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i.length,h=e?Math.max(c.startColumn,a.startColumn):Math.min(c.startColumn,a.startColumn),f=e?h+l.__colSpan-1:h-1,g=s.getFirstChild();Ke(g)||Re(120);let m=null;function p(e=we.NO_STATUS){const t=xe(e).append($createParagraphNode());return null===m&&(m=t),t}let C=g;e:for(let e=0;e<u;e++){if(0!==e){const e=C.getNextSibling();Ke(e)||Re(121),C=e;}const t=i[e],n=t[f<0?0:f].cell.__headerState,o=Ue(n,we.ROW);if(f<0){Qe(C,p(o));continue}const{cell:r,startColumn:l,startRow:s}=t[f];if(l+r.__colSpan-1<=f){let n=r,l=s,i=f;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){C.append(p(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o;}}n.insertAfter(p(o));}else r.setColSpan(r.__colSpan+1);}null!==m&&Ge(m);const _=s.getColWidths();if(_){const e=[..._],t=f<0?0:f,n=e[t];e.splice(t,0,n),s.setColWidths(e);}return m}function Xe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Ke(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 je(){const e=$getSelection();$isRangeSelection(e)||it(e)||Re(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=o.__rowSpan,g=s[h+1],m=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(e===a&&o<a){const e=a-o;n.setRowSpan(n.__rowSpan-Math.min(f,n.__rowSpan-e));}if(o>=a&&o+n.__rowSpan-1>h){n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&Re(122);let r=null;for(let n=0;n<t;n++){const t=g[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1);}null===r?Qe(m,n):r.insertAfter(n);}}}const t=r.getChildAtIndex(e);Ke(t)||Re(206,String(e)),t.remove();}if(void 0!==g){const{cell:e}=g[0];Ge(e);}else {const e=s[a-1],{cell:t}=e[0];Ge(t);}}function Ve(){const e=$getSelection();$isRangeSelection(e)||it(e)||Re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e));}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e);}}else n.remove();}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;Ge(e);}else {const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Ge(t);}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e);}}function Ge(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart();}function Qe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t);}function Ze(){const e=$getSelection();$isRangeSelection(e)||it(e)||Re(188);const t=e.anchor.getNode(),[n,o,r]=nt(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[i,c]=et(r,n,n),{startColumn:a,startRow:u}=c,h=n.__headerState&we.COLUMN,f=Array.from({length:l},((e,t)=>{let n=h;for(let e=0;0!==n&&e<i.length;e++)n&=i[e][t+a].cell.__headerState;return n})),g=n.__headerState&we.ROW,m=Array.from({length:s},((e,t)=>{let n=g;for(let e=0;0!==n&&e<i[0].length;e++)n&=i[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(xe(f[e]|m[0]).append($createParagraphNode()));n.setColSpan(1);}if(s>1){let e;for(let t=1;t<s;t++){const n=u+t,r=i[n];e=(e||o).getNextSibling(),Ke(e)||Re(125);let s=null;for(let e=0;e<a;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1);}if(null===s)for(let n=l-1;n>=0;n--)Qe(e,xe(f[n]|m[t]).append($createParagraphNode()));else for(let e=l-1;e>=0;e--)s.insertAfter(xe(f[e]|m[t]).append($createParagraphNode()));}n.setRowSpan(1);}}function et(e,t,n){const[o,r,l]=tt(e,t,n);return null===r&&Re(207),null===l&&Re(208),[o,r,l]}function tt(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];Ke(o)||Re(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(ve(a)||Re(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===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o);}}return [o,r,l]}function nt(e){let t;if(e instanceof be)t=e;else if("__type"in e){const o=$findMatchingParent(e,ve);ve(o)||Re(148),t=o;}else {const o=$findMatchingParent(e.getNode(),ve);ve(o)||Re(148),t=o;}const o=t.getParent();Ke(o)||Re(149);const r=o.getParent();return ln(r)||Re(210),[t,o,r]}function ot(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 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>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0);}}}while(o);return {maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function rt(e){const[t,,n]=nt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return {colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c;}}return null}function lt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=$findMatchingParent(o,ve);ve(r)||Re(238,t,o.getKey(),o.getType());const l=r.getParent();Ke(l)||Re(239,t);const s=l.getParent();return ln(s)||Re(240,t),[o,r,l,s]}));return l.is(a)||Re(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class st{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e;}getStartEndPoints(){return [this.anchor,this.focus]}isValid(){return "root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e;}is(e){return it(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 st(this.tableKey,$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return !1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(ve).forEach((e=>{const n=e.getFirstChild();$isParagraphNode(n)&&(t|=n.getTextFormat());}));const n=TEXT_TYPE_TO_FORMAT[e];return !!(t&n)}insertNodes(e){const t=this.focus.getNode();$isElementNode(t)||Re(151);$normalizeSelection__EXPERIMENTAL(t.select(0,t.getChildrenSize())).insertNodes(e);}getShape(){const{anchorCell:e,focusCell:t}=lt(this),n=rt(e);null===n&&Re(153);const o=rt(t);null===o&&Re(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return {fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return [];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=lt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Re(159),this.set(this.tableKey,o.getKey(),e.getKey());}else {const e=t.getParent();null==e&&Re(158),this.set(this.tableKey,e.getKey(),o.getKey());}return this.getNodes()}const[l,s,i]=et(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=ot(l,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}=l[e][t],o=n.getParent();Ke(o)||Re(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||ut(n,(e=>{d.set(e.getKey(),e);}));}const g=Array.from(d.values());return isCurrentlyReadOnlyMode()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter((e=>ve(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 it(e){return e instanceof st}function ct(){const e=$createPoint("root",0,"element"),t=$createPoint("root",0,"element");return new st("root",e,t)}function at(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=$getSelection(),r=it(o)?o.clone():ct();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function ut(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)&&$isElementNode(o)&&n.push(o.getChildren());}}function ht(e,t=$getEditor()){const n=$getNodeByKey(e);ln(n)||Re(231,e);const o=mt(n,t.getElementByKey(e));return null===o&&Re(232,e),{tableElement:o,tableNode:n}}class dt{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.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable();}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear();}$lookup(){return ht(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=vt(n,o);}),{editor:this.editor});}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=vt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0});}),{editor:this.editor});}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();Tt(e,vt(t,n),null),null!==$getSelection()&&($setSelection(null),e.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0));}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();removeClassNamesFromElement(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1;}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0;}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Re(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Tt(t,this.table,this.tableSelection);}else this.$clearHighlight();}setShouldCheckSelection(){this.shouldCheckSelection=!0;}getAndClearShouldCheckSelection(){return !!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e;}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges();}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return !1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Yt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=at(o,this.$getAnchorTableCellOrThrow(),t),$setSelection(this.tableSelection),n.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0),Tt(n,this.table,this.tableSelection),!0}return !1}$getAnchorTableCell(){return this.anchorCellNodeKey?$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Re(234),e}$getFocusTableCell(){return this.focusCellNodeKey?$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Re(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Yt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ct(),this.anchorCellNodeKey=e;}}$formatCells(e){const t=$getSelection();it(t)||Re(236);const n=$createRangeSelection(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ve);l.length>0||Re(237);const s=l[0].getFirstChild(),i=$isParagraphNode(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i);})),$setSelection(t),this.editor.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0);}$clearText(){const{editor:e}=this,t=$getNodeByKey(this.tableNodeKey);if(!ln(t))throw new Error("Expected TableNode.");const n=$getSelection();it(n)||Re(253);const o=n.getNodes().filter(ve);if(o.length===this.table.columns*this.table.rows){t.selectPrevious();const n=t.getParent();return t.remove(),void($isRootNode(n)&&n.isEmpty()&&e.dispatchCommand(INSERT_PARAGRAPH_COMMAND,void 0))}o.forEach((e=>{if($isElementNode(e)){const t=$createParagraphNode(),n=$createTextNode();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove();}));}})),Tt(e,this.table,null),$setSelection(null),e.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0);}}const ft="__lexicalTableSelection",gt=e=>!(1&~e.buttons);function mt(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return "TABLE"!==n.nodeName&&Re(245,t.nodeName),n}function pt(e){return e._window}function Ct(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ve(n)&&(o=n);}return null}const _t=[[KEY_ARROW_DOWN_COMMAND,"down"],[KEY_ARROW_UP_COMMAND,"up"],[KEY_ARROW_LEFT_COMMAND,"backward"],[KEY_ARROW_RIGHT_COMMAND,"forward"]],St=[DELETE_WORD_COMMAND,DELETE_LINE_COMMAND,DELETE_CHARACTER_COMMAND],wt=[KEY_BACKSPACE_COMMAND,KEY_DELETE_COMMAND];function bt(e,t,o,l){const s=o.getRootElement(),i=pt(o);null!==s&&null!==i||Re(246);const c=new dt(o,e.getKey()),a=mt(e,t);!function(e,t){null!==yt(e)&&Re(205);e[ft]=t;}(a,c),c.listenersToRemove.add((()=>function(e,t){yt(e)===t&&delete e[ft];}(a,c)));const u=t=>{if(c.pointerType=t.pointerType,0!==t.button||!isDOMNode(t.target)||!i)return;const n=Nt(t.target);null!==n&&o.update((()=>{const o=$getPreviousSelection();if(Me&&t.shiftKey&&Mt(o,e)&&($isRangeSelection(o)||it(o))){const r=o.anchor.getNode(),l=Ct(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(Jt(c,l)),c.$setFocusCellForSelection(n),Dt(t);else {(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type);}}else c.$setAnchorCellForSelection(n);})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("pointerup",e),i.removeEventListener("pointermove",t);},t=n=>{if(!gt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("pointerup",e),void i.removeEventListener("pointermove",t);if(!isDOMNode(n.target))return;let r=null;const l=!(Me||a.contains(n.target));if(l)r=xt(a,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(r=xt(a,e),r)break;!r||null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(SELECTION_CHANGE_COMMAND,void 0));};c.isSelecting=!0,i.addEventListener("pointerup",e,c.listenerOptions),i.addEventListener("pointermove",t,c.listenerOptions);})();};a.addEventListener("pointerdown",u,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("pointerdown",u);}));const h=e=>{if(e.detail>=3&&isDOMNode(e.target)){null!==Nt(e.target)&&e.preventDefault();}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("mousedown",h);}));const g=e=>{const t=e.target;0===e.button&&isDOMNode(t)&&o.update((()=>{const e=$getSelection();it(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight();}));};i.addEventListener("pointerdown",g,c.listenerOptions),c.listenersToRemove.add((()=>{i.removeEventListener("pointerdown",g);}));for(const[t,n]of _t)c.listenersToRemove.add(o.registerCommand(t,(t=>Pt(o,t,n,e,c)),COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(o.registerCommand(KEY_ESCAPE_COMMAND,(t=>{const n=$getSelection();if(it(n)){const o=Ct(e,n.focus.getNode());if(null!==o)return Dt(t),o.selectEnd(),!0}return !1}),COMMAND_PRIORITY_HIGH));const p=t=>()=>{const o=$getSelection();if(!Mt(o,e))return !1;if(it(o))return c.$clearText(),!0;if($isRangeSelection(o)){if(!ve(Ct(e,o.anchor.getNode())))return !1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=$findMatchingParent(o.anchor.getNode(),(e=>$isElementNode(e))),u=a&&$findMatchingParent(a,(e=>$isElementNode(e)&&ve(e.getParent())));if(!$isElementNode(u)||!$isElementNode(a))return !1;if(t===DELETE_LINE_COMMAND&&null===u.getPreviousSibling())return !0}return !1};for(const e of St)c.listenersToRemove.add(o.registerCommand(e,p(e),COMMAND_PRIORITY_CRITICAL));const C=t=>{const n=$getSelection();if(!it(n)&&!$isRangeSelection(n))return !1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return !!Mt(n,e)&&(!!it(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of wt)c.listenersToRemove.add(o.registerCommand(e,C,COMMAND_PRIORITY_CRITICAL));return c.listenersToRemove.add(o.registerCommand(CUT_COMMAND,(e=>{const t=$getSelection();if(t){if(!it(t)&&!$isRangeSelection(t))return !1;copyToClipboard(o,objectKlassEquals(e,ClipboardEvent)?e:null,$getClipboardDataFromSelection(t));const n=C(e);return $isRangeSelection(t)?(t.removeText(),!0):n}return !1}),COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(FORMAT_TEXT_COMMAND,(t=>{const o=$getSelection();if(!Mt(o,e))return !1;if(it(o))return c.$formatCells(t),!0;if($isRangeSelection(o)){const e=$findMatchingParent(o.anchor.getNode(),(e=>ve(e)));if(!ve(e))return !1}return !1}),COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(FORMAT_ELEMENT_COMMAND,(t=>{const n=$getSelection();if(!it(n)||!Mt(n,e))return !1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ve(o)||!ve(r))return !1;if(function(e,t){if(it(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=et(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[l,s,i]=et(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];$isElementNode(n)&&!n.isInline()&&n.setFormat(t);}}return !0}),COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND,(t=>{const r=$getSelection();if(!Mt(r,e))return !1;if(it(r))return c.$clearHighlight(),!1;if($isRangeSelection(r)){const l=$findMatchingParent(r.anchor.getNode(),(e=>ve(e)));if(!ve(l))return !1;if("string"==typeof t){const n=Ut(o,r,e);if(n)return It(n,e,[$createTextNode(t)]),!0}}return !1}),COMMAND_PRIORITY_CRITICAL)),l&&c.listenersToRemove.add(o.registerCommand(KEY_TAB_COMMAND,(t=>{const o=$getSelection();if(!$isRangeSelection(o)||!o.isCollapsed()||!Mt(o,e))return !1;const r=Wt(o.anchor.getNode());return !(null===r||!e.is(Ht(r)))&&(Dt(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if($isElementNode(l))return l.selectEnd();const s=$findMatchingParent(e,Ke);null===s&&Re(247);for(let e=s[o]();Ke(e);e=e[o]()){const t=e[r]();if($isElementNode(t))return t.selectEnd()}const i=$findMatchingParent(s,ln);null===i&&Re(248);"next"===t?i.selectNext():i.selectPrevious();}(r,t.shiftKey?"previous":"next"),!0)}),COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(FOCUS_COMMAND,(t=>e.isSelected()),COMMAND_PRIORITY_HIGH)),c.listenersToRemove.add(o.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(e=>{const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=it(o),s=$isRangeSelection(o)&&null!==$findMatchingParent(o.anchor.getNode(),(e=>ve(e)))&&null!==$findMatchingParent(o.focus.getNode(),(e=>ve(e)))||l;if(1!==t.length||!ln(t[0])||!s||null===r)return !1;const[i]=r,c=t[0],a=c.getChildren(),u=c.getFirstChildOrThrow().getChildrenSize(),h=c.getChildrenSize(),f=$findMatchingParent(i.getNode(),(e=>ve(e))),g=f&&$findMatchingParent(f,(e=>Ke(e))),p=g&&$findMatchingParent(g,(e=>ln(e)));if(!ve(f)||!Ke(g)||!ln(p))return !1;const C=g.getIndexWithinParent(),_=Math.min(p.getChildrenSize()-1,C+h-1),S=f.getIndexWithinParent(),b=Math.min(g.getChildrenSize()-1,S+u-1),y=Math.min(S,b),N=Math.min(C,_),x=Math.max(S,b),v=Math.max(C,_),T=p.getChildren();let R=0;for(let e=N;e<=v;e++){const t=T[e];if(!Ke(t))return !1;const n=a[R];if(!Ke(n))return !1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ve(t))return !1;const n=r[l];if(!ve(n))return !1;const s=t.getChildren();n.getChildren().forEach((e=>{if($isTextNode(e)){$createParagraphNode().append(e),t.append(e);}else t.append(e);})),s.forEach((e=>e.remove())),l++;}R++;}return !0}),COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(SELECTION_CHANGE_COMMAND,(()=>{const t=$getSelection(),r=$getPreviousSelection(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(it(t)&&t.tableKey===c.tableNodeKey)return (n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&Mt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&$isRangeSelection(r)&&$isRangeSelection(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=Wt(o);if(null!==l&&Ke(r)){const t=r.getFirstChild();if(ve(t)&&e.is($findMatchingParent(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if($isRangeSelection(t)){const{anchor:n,focus:l}=t,s=n.getNode(),i=l.getNode(),a=Wt(s),u=Wt(i),h=!(!a||!e.is(Ht(a))),d=!(!u||!e.is(Ht(u))),f=h!==d,g=h&&d,m=t.isBackward();if(f){const n=t.clone();if(d){const[t]=et(e,u,u),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(m?o.getKey():r.getKey(),m?o.getChildrenSize():r.getChildrenSize(),"element");}else if(h){const[t]=et(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(m?r.getKey():o.getKey(),m?r.getChildrenSize():0,"element");}$setSelection(n),Ft(o,c);}else if(g&&(a.is(u)||(c.$setAnchorCellForSelection(Jt(c,a)),c.$setFocusCellForSelection(Jt(c,u),!0)),"touch"===c.pointerType&&t.isCollapsed()&&$isRangeSelection(r)&&r.isCollapsed())){const e=Wt(r.anchor.getNode());e&&!e.is(u)&&(c.$setAnchorCellForSelection(Jt(c,e)),c.$setFocusCellForSelection(Jt(c,u),!0),c.pointerType=null);}}else if(t&&it(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=getDOMSelection(i);if(n&&n.anchorNode&&n.focusNode){const r=$getNearestNodeFromDOMNode(n.focusNode),l=r&&!e.isParentOf(r),s=$getNearestNodeFromDOMNode(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=$createRangeSelectionFromDom(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),$setSelection(r));}}}return t&&!t.is(r)&&(it(t)||it(r))&&c.tableSelection&&!c.tableSelection.is(r)?(it(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!it(t)&&it(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),Rt(t.table,(t=>{const n=t.elem;t.highlighted=!1,zt(e,t),n.getAttribute("style")||n.removeAttribute("style");}));}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Ft(o,c),!1)}),COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(INSERT_PARAGRAPH_COMMAND,(()=>{const t=$getSelection();if(!$isRangeSelection(t)||!t.isCollapsed()||!Mt(t,e))return !1;const n=Ut(o,t,e);return !!n&&(It(n,e),!0)}),COMMAND_PRIORITY_CRITICAL)),c}function yt(e){return e[ft]||null}function Nt(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 xt(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 vt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=mt(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 Tt(e,t,n){const o=new Set(n?n.getNodes():[]);Rt(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Lt(e,t)):(t.highlighted=!1,zt(e,t),r.getAttribute("style")||r.removeAttribute("style"));}));}function Rt(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=$getNearestNodeFromDOMNode(r.elem);null!==l&&t(r,l,{x:n,y:e});}}}function Ft(e,t){t.$disableHighlightStyle(),Rt(t.table,(t=>{t.highlighted=!0,Lt(e,t);}));}const At=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?$t(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?$t(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?$t(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?$t(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return !1}};function Ot(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 Kt([e,t]){return ["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Et(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Re(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Re(250,n,String(s)),i}function kt(e,t,n,o,r){const l=ot(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return {bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Ot(e,t);return null===n&&Re(249,t.cell.getKey()),n}(l,n),[d,f]=Kt(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(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=ot(e,t,n),r=Ot(o,t);if(r)return [Et(e,o,r),Et(e,o,Kt(r))];const l=Ot(o,n);if(l)return [Et(e,o,Kt(l)),Et(e,o,l)];const s=["minColumn","minRow"];return [Et(e,o,s),Et(e,o,Kt(s))]}(t,n,C),w=Jt(e,_.cell),b=Jt(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Mt(e,t){if($isRangeSelection(e)||it(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return !1}function $t(e,t){t?e.selectStart():e.selectEnd();}function Lt(t,n){const o=n.elem,r=t._config.theme;ve($getNearestNodeFromDOMNode(o))||Re(131),addClassNamesToElement(o,r.tableCellSelected);}function zt(e,t){const n=t.elem;ve($getNearestNodeFromDOMNode(n))||Re(131);const r=e._config.theme;removeClassNamesFromElement(n,r.tableCellSelected);}function Wt(e){const t=$findMatchingParent(e,ve);return ve(t)?t:null}function Ht(e){const t=$findMatchingParent(e,ln);return ln(t)?t:null}function Bt(e,t,o,r,l,s,i){const c=$caretFromPoint(o.focus,l?"previous":"next");if($isExtendableTextPointCaret(c))return !1;let a=c;for(const e of $extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!$isSiblingCaret(e)||!$isElementNode(e.origin))return !1;a=e;}const u=a.getParentAtCaret();if(!ve(u))return !1;const h=u,d=function(e){for(const t of $extendCaretToRange(e).iterNodeCarets("root")){const{origin:n}=t;if(ve(n)){if($isChildCaret(t))return $getChildCaret(n,e.direction)}else if(!Ke(n))break}return null}($getSiblingCaret(h,a.direction)),g=$findMatchingParent(h,ln);if(!g||!g.is(s))return !1;const m=e.getElementByKey(h.getKey()),p=Nt(m);if(!m||!p)return !1;const C=nn(e,g);if(i.table=C,d)if("extend"===r){const t=Nt(e.getElementByKey(d.origin.getKey()));if(!t)return !1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(t,!0);}else {const e=$normalizeCaret(d);$setPointFromCaret(o.anchor,e),$setPointFromCaret(o.focus,e);}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else {const e=function(e){const t=$getAdjacentChildCaret(e);return $isChildCaret(t)?$normalizeCaret(t):e}($getSiblingCaret(g,c.direction));$setPointFromCaret(o.anchor,e),$setPointFromCaret(o.focus,e);}return Dt(t),!0}function Pt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return !1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return !1;const s=$getSelection();if(!Mt(s,r)){if($isRangeSelection(s)){if("backward"===o){if(s.focus.offset>0)return !1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if($isElementNode(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return !1;const n=e.getPreviousSibling();return !!ln(n)&&(Dt(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=$findMatchingParent(e,(e=>ln(e)));if(ve(l)&&(l=$findMatchingParent(l,ln)),l!==r)return !1;if(!l)return !1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return !1;let c=0;"up"===o&&$isElementNode(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&$isElementNode(i)){const e=i.getLastChild();a=e||i,c=$isTextNode(a)?a.getTextContentSize():0;}const u=s.clone();return u.focus.set(a.getKey(),c,$isTextNode(a)?"text":"element"),$setSelection(u),Dt(t),!0}if($isRootOrShadowRoot(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Ct(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return !1;const[n]=nt(e),[o]=nt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return !1}{let r=$findMatchingParent(e,(e=>$isElementNode(e)&&!e.isInline()));if(ve(r)&&(r=$findMatchingParent(r,ln)),!r)return !1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(ln(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return !1;const[r]=nt(e),[l]=nt(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Dt(t),$setSelection(c),!0}}}}return "down"===o&&Zt(e)&&l.setShouldCheckSelection(),!1}if($isRangeSelection(s)){if("backward"===o||"forward"===o){return Bt(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=$findMatchingParent(i.getNode(),ve),u=$findMatchingParent(c.getNode(),ve);if(!ve(a)||!a.is(u))return !1;const h=Ht(a);if(h!==r&&null!=h){const n=mt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=vt(h,n),Pt(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return !1;let g;if("element"===i.type)g=f.getBoundingClientRect();else {const t=getDOMSelection(pt(e));if(null===t||0===t.rangeCount)return !1;g=t.getRangeAt(0).getBoundingClientRect();}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return !1;const p=e.getElementByKey(m.__key);if(null==p)return !1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){Dt(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return At(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(it(s)){const{anchor:i,focus:c}=s,a=$findMatchingParent(i.getNode(),ve),u=$findMatchingParent(c.getNode(),ve),[h]=s.getNodes();ln(h)||Re(251);const d=mt(h,e.getElementByKey(h.getKey()));if(!ve(a)||!ve(u)||!ln(h)||null==d)return !1;l.$updateTableTableSelection(s);const f=vt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),Dt(t),t.shiftKey){const[e,t,n]=et(r,a,u);return kt(l,e,t,n,o)}return u.selectEnd(),!0}return !1}function Dt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation();}function It(e,t,n){const o=$createParagraphNode();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd();}function Ut(e,t,o){const r=o.getParent();if(!r)return;const l=getDOMSelection(pt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=mt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=$findMatchingParent(t.anchor.getNode(),(e=>ve(e)));if(!a)return;const u=$findMatchingParent(a,(e=>ln(e)));if(!ln(u)||!u.is(o))return;const[h,d]=et(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function Jt(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Yt(e,t,n){return Ct(e,$getNearestNodeFromDOMNode(t,n))}function qt(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t);}r.replaceChildren(...l);}function Xt(t,n,r){r?(addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"));}function jt(t,n,r){r>0?(addClassNamesToElement(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(removeClassNamesFromElement(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"));}function Vt(t,n,r){r>0?(addClassNamesToElement(t,n.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(removeClassNamesFromElement(t,n.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"));}function Gt(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of ["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t);}removeClassNamesFromElement(t,...l),addClassNamesToElement(t,...s);}const Qt=new WeakSet;function Zt(e=$getEditor()){return Qt.has(e)}function en(e,t){t?Qt.add(e):Qt.delete(e);}class tn extends ElementNode{static getType(){return "table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new tn(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:on,priority:1})}}static importJSON(e){return rn().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;}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="TABLE"!==e.nodeName&&e.querySelector("table")||e;return "TABLE"!==t.nodeName&&Re(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&(o.style.cssText=this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),qt(o,0,this.getColumnCount(),this.getColWidths()),setDOMUnmanaged(r),addClassNamesToElement(o,t.theme.table),Gt(o,t,this.getFormatType()),this.__frozenColumnCount&&jt(o,t,this.__frozenColumnCount),this.__frozenRowCount&&Vt(o,t,this.__frozenRowCount),this.__rowStriping&&Xt(o,t,!0),Zt(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?addClassNamesToElement(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){e.__rowStriping!==this.__rowStriping&&Xt(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&jt(t,n,this.__frozenColumnCount),e.__frozenRowCount!==this.__frozenRowCount&&Vt(t,n,this.__frozenRowCount),qt(t,0,this.getColumnCount(),this.getColWidths());const o=this.getDOMSlot(t).element;return e.__style!==this.__style&&(o.style.cssText=this.__style),Gt(o,n,this.getFormatType()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return {after:n=>{if(t.after&&(n=t.after(n),this.__format&&Gt(n,e._config,this.getFormatType())),isHTMLElement$1(n)&&"TABLE"!==n.nodeName&&(n=n.querySelector("table")),!isHTMLElement$1(n))return null;const[o]=tt(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn});}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn);}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>s.has(t)));i.replaceChildren(...e);}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e);}return n},element:isHTMLElement$1(n)&&"TABLE"!==n.nodeName?n.querySelector("table"):n}}canBeEmpty(){return !1}isShadowRoot(){return !0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=Yt(this,l);if(null!==s&&e.is(s))return {x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=$getNearestNodeFromDOMNode(o.elem);return ve(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){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(!e)return 0;let t=0;return e.getChildren().forEach((e=>{ve(e)&&(t+=e.getColSpan());})),t}}function nn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Re(230),vt(t,n)}function on(e){const n=rn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Se.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n));}e&&n.setColWidths(e);}return {after:e=>$descendantsMatching(e,Ke),node:n}}function rn(){return $applyNodeReplacement(new tn)}function ln(e){return e instanceof tn}function sn({rows:e,columns:t,includeHeaders:n}){const o=$getSelection();if(!o||!$isRangeSelection(o))return !1;if(Ht(o.anchor.getNode()))return !1;const r=$e(Number(e),Number(t),n);$insertNodeToNearestRoot(r);const l=r.getFirstDescendant();return $isTextNode(l)&&l.select(),!0}function cn(e){Ke(e.getParent())?e.isEmpty()&&e.append($createParagraphNode()):e.remove();}function an(e){ln(e.getParent())?$unwrapAndFilterDescendants(e,ve):e.remove();}function un(e){$unwrapAndFilterDescendants(e,Ke);const[t]=tt(e,null,null),n=t.reduce(((e,t)=>Math.max(e,t.length)),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;Ke(r)||Re(254,r.constructor.name,r.getType());const l=t[e].reduce(((e,t)=>t?1+e:e),0);if(l!==n)for(let e=l;e<n;++e){const e=xe();e.append($createParagraphNode()),r.append(e);}}}function hn(e){if(e.detail<3||!isDOMNode(e.target))return !1;const t=$getNearestNodeFromDOMNode(e.target);if(null===t)return !1;const o=$findMatchingParent(t,(e=>$isElementNode(e)&&!e.isInline()));if(null===o)return !1;return !!ve(o.getParent())&&(o.select(0),!0)}function dn(e){return e.registerNodeTransform(be,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=nt(e),[n]=et(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Ke(l)||Re(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Ke(l)||Re(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){ve(c)||Re(176);const e=xe(c.__headerState);null!==t?t.insertAfter(e):$insertFirst(l,e);}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1);}}))}function fn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=mt(o,l),i=bt(o,s,e,t);n.set(r,[i,s]);},r=e.registerMutationListener(tn,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=ht(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l));}else "destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e));}}),{editor:e});}),{skipInitialization:!1});return ()=>{r();for(const[,[e]]of n)e.removeListeners();}}function gn(e){return e.hasNodes([tn])||Re(255),mergeRegister(e.registerCommand(Te,sn,COMMAND_PRIORITY_EDITOR),e.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(({nodes:e,selection:t})=>{if(!$isRangeSelection(t))return !1;return null!==Ht(t.anchor.getNode())&&e.some(ln)}),COMMAND_PRIORITY_EDITOR),e.registerCommand(CLICK_COMMAND,hn,COMMAND_PRIORITY_EDITOR),e.registerNodeTransform(tn,un),e.registerNodeTransform(Fe,an),e.registerNodeTransform(be,cn))}
16
16
 
17
- export { Me as $computeTableMap, Re as $computeTableMapSkipCellCheck, ee as $createTableCellNode, at as $createTableNode, de as $createTableNodeWithDimensions, le as $createTableRowNode, He as $createTableSelection, Ne as $deleteTableColumn, xe as $deleteTableColumn__EXPERIMENTAL, Te as $deleteTableRow__EXPERIMENTAL, et as $findCellNode, tt as $findTableNode, it as $getElementForTableNode, Ke as $getNodeTriplet, ue as $getTableCellNodeFromLexicalNode, Fe as $getTableCellNodeRect, me as $getTableColumnIndexFromTableCellNode, ge as $getTableNodeFromLexicalNodeOrThrow, fe as $getTableRowIndexFromTableCellNode, he as $getTableRowNodeFromTableCellNodeOrThrow, be as $insertTableColumn, ye as $insertTableColumn__EXPERIMENTAL, Se as $insertTableRow, we as $insertTableRow__EXPERIMENTAL, te as $isTableCellNode, dt as $isTableNode, se as $isTableRowNode, Ae as $isTableSelection, Ce as $removeTableRowAtIndex, Oe as $unmergeCell, ne as INSERT_TABLE_COMMAND, Q as TableCellHeaderStates, V as TableCellNode, st as TableNode, Pe as TableObserver, oe as TableRowNode, Ie as applyTableHandlers, Ue as getDOMCellFromTarget, We as getTableObserverFromTableElement };
17
+ export { et as $computeTableMap, tt as $computeTableMapSkipCellCheck, xe as $createTableCellNode, rn as $createTableNode, $e as $createTableNodeWithDimensions, Oe as $createTableRowNode, ct as $createTableSelection, at as $createTableSelectionFrom, Xe as $deleteTableColumn, Ve as $deleteTableColumn__EXPERIMENTAL, je as $deleteTableRow__EXPERIMENTAL, Wt as $findCellNode, Ht as $findTableNode, nn as $getElementForTableNode, nt as $getNodeTriplet, ht as $getTableAndElementByKey, Le as $getTableCellNodeFromLexicalNode, rt as $getTableCellNodeRect, Be as $getTableColumnIndexFromTableCellNode, We as $getTableNodeFromLexicalNodeOrThrow, He as $getTableRowIndexFromTableCellNode, ze as $getTableRowNodeFromTableCellNodeOrThrow, Ye as $insertTableColumn, qe as $insertTableColumn__EXPERIMENTAL, Ie as $insertTableRow, Je as $insertTableRow__EXPERIMENTAL, Zt as $isScrollableTablesActive, ve as $isTableCellNode, ln as $isTableNode, Ke as $isTableRowNode, it as $isTableSelection, De as $removeTableRowAtIndex, Ze as $unmergeCell, Te as INSERT_TABLE_COMMAND, we as TableCellHeaderStates, be as TableCellNode, tn as TableNode, dt as TableObserver, Fe as TableRowNode, bt as applyTableHandlers, Nt as getDOMCellFromTarget, mt as getTableElement, yt as getTableObserverFromTableElement, dn as registerTableCellUnmergeTransform, gn as registerTablePlugin, fn as registerTableSelectionObserver, en as setScrollableTablesActive };