@lexical/table 0.16.2-nightly.20240711.0 → 0.16.2-nightly.20240715.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2310,8 +2310,8 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2310
2310
  siblingNode.selectEnd();
2311
2311
  return true;
2312
2312
  } else if (event.shiftKey && (direction === 'up' || direction === 'down')) {
2313
- const anchorNode = selection.anchor.getNode();
2314
- if (lexical.$isRootOrShadowRoot(anchorNode)) {
2313
+ const focusNode = selection.focus.getNode();
2314
+ if (lexical.$isRootOrShadowRoot(focusNode)) {
2315
2315
  const selectedNode = selection.getNodes()[0];
2316
2316
  if (selectedNode) {
2317
2317
  const tableCellNode = utils.$findMatchingParent(selectedNode, $isTableCellNode);
@@ -2334,11 +2334,11 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2334
2334
  }
2335
2335
  return false;
2336
2336
  } else {
2337
- const anchorParentNode = utils.$findMatchingParent(anchorNode, n => lexical.$isElementNode(n) && !n.isInline());
2338
- if (!anchorParentNode) {
2337
+ const focusParentNode = utils.$findMatchingParent(focusNode, n => lexical.$isElementNode(n) && !n.isInline());
2338
+ if (!focusParentNode) {
2339
2339
  return false;
2340
2340
  }
2341
- const sibling = direction === 'down' ? anchorParentNode.getNextSibling() : anchorParentNode.getPreviousSibling();
2341
+ const sibling = direction === 'down' ? focusParentNode.getNextSibling() : focusParentNode.getPreviousSibling();
2342
2342
  if ($isTableNode(sibling) && tableObserver.tableNodeKey === sibling.getKey()) {
2343
2343
  const firstDescendant = sibling.getFirstDescendant();
2344
2344
  const lastDescendant = sibling.getLastDescendant();
@@ -2308,8 +2308,8 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2308
2308
  siblingNode.selectEnd();
2309
2309
  return true;
2310
2310
  } else if (event.shiftKey && (direction === 'up' || direction === 'down')) {
2311
- const anchorNode = selection.anchor.getNode();
2312
- if ($isRootOrShadowRoot(anchorNode)) {
2311
+ const focusNode = selection.focus.getNode();
2312
+ if ($isRootOrShadowRoot(focusNode)) {
2313
2313
  const selectedNode = selection.getNodes()[0];
2314
2314
  if (selectedNode) {
2315
2315
  const tableCellNode = $findMatchingParent(selectedNode, $isTableCellNode);
@@ -2332,11 +2332,11 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2332
2332
  }
2333
2333
  return false;
2334
2334
  } else {
2335
- const anchorParentNode = $findMatchingParent(anchorNode, n => $isElementNode(n) && !n.isInline());
2336
- if (!anchorParentNode) {
2335
+ const focusParentNode = $findMatchingParent(focusNode, n => $isElementNode(n) && !n.isInline());
2336
+ if (!focusParentNode) {
2337
2337
  return false;
2338
2338
  }
2339
- const sibling = direction === 'down' ? anchorParentNode.getNextSibling() : anchorParentNode.getPreviousSibling();
2339
+ const sibling = direction === 'down' ? focusParentNode.getNextSibling() : focusParentNode.getPreviousSibling();
2340
2340
  if ($isTableNode(sibling) && tableObserver.tableNodeKey === sibling.getKey()) {
2341
2341
  const firstDescendant = sibling.getFirstDescendant();
2342
2342
  const lastDescendant = sibling.getLastDescendant();
@@ -46,7 +46,7 @@ a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.sele
46
46
  d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(v.$isRangeSelection(a)||R(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
47
47
  function wa(a,b){a=b.elem;b=v.$getNearestNodeFromDOMNode(a);A(b)||I(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
48
48
  function xa(a,b){a=b.elem;b=v.$getNearestNodeFromDOMNode(a);A(b)||I(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Da(a){a=h.$findMatchingParent(a,A);return A(a)?a:null}function T(a){a=h.$findMatchingParent(a,N);return N(a)?a:null}
49
- function V(a,b,c,d,e){if(("up"===c||"down"===c)&&Ea(a))return!1;var f=v.$getSelection();if(!U(f,d)){if(v.$isRangeSelection(f)){if(f.isCollapsed()&&"backward"===c){e=f.anchor.type;d=f.anchor.offset;if("element"!==e&&("text"!==e||0!==d))return!1;e=f.anchor.getNode();if(!e)return!1;e=h.$findMatchingParent(e,p=>v.$isElementNode(p)&&!p.isInline());if(!e)return!1;e=e.getPreviousSibling();if(!e||!N(e))return!1;Z(b);e.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c))if(b=f.anchor.getNode(),v.$isRootOrShadowRoot(b)){if((c=
49
+ function V(a,b,c,d,e){if(("up"===c||"down"===c)&&Ea(a))return!1;var f=v.$getSelection();if(!U(f,d)){if(v.$isRangeSelection(f)){if(f.isCollapsed()&&"backward"===c){e=f.anchor.type;d=f.anchor.offset;if("element"!==e&&("text"!==e||0!==d))return!1;e=f.anchor.getNode();if(!e)return!1;e=h.$findMatchingParent(e,p=>v.$isElementNode(p)&&!p.isInline());if(!e)return!1;e=e.getPreviousSibling();if(!e||!N(e))return!1;Z(b);e.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c))if(b=f.focus.getNode(),v.$isRootOrShadowRoot(b)){if((c=
50
50
  f.getNodes()[0])&&(c=h.$findMatchingParent(c,A))&&d.isParentOf(c)){b=d.getFirstDescendant();c=d.getLastDescendant();if(!b||!c)return!1;[b]=Q(b);[c]=Q(c);b=d.getCordsFromCellNode(b,e.table);c=d.getCordsFromCellNode(c,e.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,e.table);d=d.getDOMCellFromCordsOrThrow(c.x,c.y,e.table);e.setAnchorCellForSelection(b);e.setFocusCellForSelection(d,!0);return!0}}else{d=h.$findMatchingParent(b,p=>v.$isElementNode(p)&&!p.isInline());if(!d)return!1;d="down"===c?d.getNextSibling():
51
51
  d.getPreviousSibling();if(N(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();d=d.getLastDescendant();if(!e||!d)return!1;[e]=Q(e);[d]=Q(d);b=f.clone();b.focus.set(("up"===c?e:d).getKey(),"up"===c?0:d.getChildrenSize(),"element");v.$setSelection(b);return!0}}}return!1}if(v.$isRangeSelection(f)&&f.isCollapsed()){let {anchor:p,focus:t}=f;var g=h.$findMatchingParent(p.getNode(),A),m=h.$findMatchingParent(t.getNode(),A);if(!A(g)||!g.is(m))return!1;m=T(g);if(m!==d&&null!=m){var r=a.getElementByKey(m.getKey());
52
52
  if(null!=r)return e.table=S(r),V(a,b,c,m,e)}if("backward"===c||"forward"===c){e=p.type;a=p.offset;g=p.getNode();if(!g)return!1;f=f.getNodes();return 1===f.length&&v.$isDecoratorNode(f[0])?!1:Fa(e,a,g,c)?Ga(b,g,d,c):!1}f=a.getElementByKey(g.__key);m=a.getElementByKey(p.key);if(null==m||null==f)return!1;if("element"===p.type)f=m.getBoundingClientRect();else{f=window.getSelection();if(null===f||0===f.rangeCount)return!1;f=f.getRangeAt(0).getBoundingClientRect()}m="up"===c?g.getFirstChild():g.getLastChild();
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,isHTMLElement as o}from"@lexical/utils";import{ElementNode as r,$createParagraphNode as l,$isElementNode as s,$isLineBreakNode as i,$isTextNode as c,$applyNodeReplacement as a,createCommand as d,$createTextNode as u,$getSelection as h,$isRangeSelection as g,$createPoint as f,$normalizeSelection__EXPERIMENTAL as m,$getNodeByKey as p,isCurrentlyReadOnlyMode as C,$setSelection as S,SELECTION_CHANGE_COMMAND as _,$getNearestNodeFromDOMNode as w,$createRangeSelection as b,$getRoot as y,KEY_ARROW_DOWN_COMMAND as N,COMMAND_PRIORITY_HIGH as T,KEY_ARROW_UP_COMMAND as x,KEY_ARROW_LEFT_COMMAND as v,KEY_ARROW_RIGHT_COMMAND as E,KEY_ESCAPE_COMMAND as O,DELETE_WORD_COMMAND as M,DELETE_LINE_COMMAND as R,DELETE_CHARACTER_COMMAND as K,COMMAND_PRIORITY_CRITICAL as F,KEY_BACKSPACE_COMMAND as k,KEY_DELETE_COMMAND as A,FORMAT_TEXT_COMMAND as P,FORMAT_ELEMENT_COMMAND as H,CONTROLLED_TEXT_INSERTION_COMMAND as D,KEY_TAB_COMMAND as B,FOCUS_COMMAND as L,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as z,$isRootOrShadowRoot as Y,$isDecoratorNode as X}from"lexical";const J=/^(\d+(?:\.\d+)?)px$/,$={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class j extends r{static getType(){return"tablecell"}static clone(e){const t=new j(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:q,priority:0}),th:e=>({conversion:q,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=G(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=$.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__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!==$.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 q(e){const t=e,n=e.nodeName.toLowerCase();let o;J.test(t.style.width)&&(o=parseFloat(t.style.width));const r=G("th"===n?$.ROW:$.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const a=t.style.backgroundColor;""!==a&&(r.__backgroundColor=a);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(l()),e),forChild:(e,t)=>{if(Q(t)&&!s(e)){const t=l();return i(e)&&"\n"===e.getTextContent()?null:(c(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 G(e,t=1,n){return a(new j(e,t,n))}function Q(e){return e instanceof j}const V=d("INSERT_TABLE_COMMAND");class Z extends r{static getType(){return"tablerow"}static clone(e){return new Z(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ee,priority:0})}}static importJSON(e){return te(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function ee(e){const t=e;let n;return J.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:te(n)}}function te(e){return a(new Z(e))}function ne(e){return e instanceof Z}function oe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var re=oe((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 le="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function se(e,t,n=!0){const o=lt();for(let r=0;r<e;r++){const e=te();for(let o=0;o<t;o++){let t=$.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=$.ROW),0===o&&n.columns&&(t|=$.COLUMN)):n&&(0===r&&(t|=$.ROW),0===o&&(t|=$.COLUMN));const s=G(t),i=l();i.append(u()),s.append(i),e.append(s)}o.append(e)}return o}function ie(e){const n=t(e,(e=>Q(e)));return Q(n)?n:null}function ce(e){const n=t(e,(e=>ne(e)));if(ne(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ae(e){const n=t(e,(e=>st(e)));if(st(n))return n;throw new Error("Expected table cell to be inside of table.")}function de(e){const t=ce(e);return ae(t).getChildren().findIndex((e=>e.is(t)))}function ue(e){return ce(e).getChildren().findIndex((t=>t.is(e)))}function he(e,t){const n=ae(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 ge(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 fe(e,t,n=!0,o,r){const s=e.getChildren();if(t>=s.length||t<0)throw new Error("Table row target index out of range");const i=s[t];if(!ne(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=te();for(let n=0;n<t;n++){const t=e[n];Q(t)||re(12);const{above:s,below:i}=he(t,r);let c=$.NO_STATUS;const a=s&&s.getWidth()||i&&i.getWidth()||void 0;(s&&s.hasHeaderState($.COLUMN)||i&&i.hasHeaderState($.COLUMN))&&(c|=$.COLUMN);const d=G(c,1,a);d.append(l()),o.append(d)}n?i.insertAfter(o):i.insertBefore(o)}return e}const me=(e,t)=>e===$.BOTH||e===t?t:$.NO_STATUS;function pe(e=!0){const t=h();g(t)||Re(t)||re(188);const n=t.focus.getNode(),[o,,r]=Ee(n),[s,i]=xe(r,o,o),c=s[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=s[e],n=te();for(let o=0;o<c;o++){const{cell:r,startRow:s}=t[o];if(s+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=me(e,$.COLUMN);n.append(G(r).append(l()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ne(i)||re(145),i.insertAfter(n)}else{const e=s[a],t=te();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=me(o,$.COLUMN);t.append(G(r).append(l()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ne(n)||re(145),n.insertBefore(t)}}function Ce(e,t,n=!0,o,r){const s=e.getChildren(),i=[];for(let e=0;e<s.length;e++){const n=s[e];if(ne(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];Q(o)||re(12);const{left:s,right:c}=he(o,r);let a=$.NO_STATUS;(s&&s.hasHeaderState($.ROW)||c&&c.hasHeaderState($.ROW))&&(a|=$.ROW);const d=G(a);d.append(l()),i.push({newTableCell:d,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Se(e=!0){const t=h();g(t)||Re(t)||re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ee(n),[s,,i]=Ee(o),[c,a,d]=xe(i,s,r),u=c.length,f=e?Math.max(a.startColumn,d.startColumn):Math.min(a.startColumn,d.startColumn),m=e?f+s.__colSpan-1:f-1,p=i.getFirstChild();ne(p)||re(120);let C=null;function S(e=$.NO_STATUS){const t=G(e).append(l());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<u;e++){if(0!==e){const e=_.getNextSibling();ne(e)||re(121),_=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=me(n,$.ROW);if(m<0){Ne(_,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&&ye(C)}function _e(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ne(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 we(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ee(t),[l]=Ee(n),[s,i,c]=xe(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 f=s[0].length,m=s[u+1],p=r.getChildAtIndex(u+1);for(let e=u;e>=a;e--){for(let t=f-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&&re(122),0===t)Ne(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ne(t)||re(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];ye(e)}else{const e=s[a-1],{cell:t}=e[0];ye(t)}}function be(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ee(t),[l]=Ee(n),[s,i,c]=xe(r,o,l),{startColumn:a}=i,{startRow:d,startColumn:u}=c,f=Math.min(a,u),m=Math.max(a+o.__colSpan-1,u+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[d],_=a>u?S[a+o.__colSpan]:S[u+l.__colSpan];if(void 0!==_){const{cell:e}=_;ye(e)}else{const e=u<a?S[u-1]:S[a-1],{cell:t}=e;ye(t)}}function ye(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ne(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Te(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),[n,o,r]=Ee(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(G($.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=xe(r,n,n),{startColumn:i,startRow:c}=t;let a;for(let t=1;t<s;t++){const n=c+t,r=e[n];a=(a||o).getNextSibling(),ne(a)||re(125);let s=null;for(let e=0;e<i;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 e=0;e<l;e++)Ne(a,G($.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(G($.NO_STATUS))}n.setRowSpan(1)}}function xe(e,t,n){const[o,r,l]=ve(e,t,n);return null===r&&re(110),null===l&&re(111),[o,r,l]}function ve(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];ne(t)||re(146);const n=t.getChildren();let o=0;for(const t of n){for(Q(t)||re(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function Ee(e){let n;if(e instanceof j)n=e;else if("__type"in e){const o=t(e,Q);Q(o)||re(148),n=o}else{const o=t(e.getNode(),Q);Q(o)||re(148),n=o}const o=n.getParent();ne(o)||re(149);const r=o.getParent();return st(r)||re(150),[n,o,r]}function Oe(e){const[t,,n]=Ee(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 Me{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!!Re(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 Me(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();s(t)||re(151);m(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=p(this.anchor.key);Q(e)||re(152);const t=Oe(e);null===t&&re(153);const n=p(this.focus.key);Q(n)||re(154);const o=Oe(n);null===o&&re(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=t(n,Q),l=t(o,Q);Q(r)||re(152),Q(l)||re(154);const s=r.getParent();ne(s)||re(156);const i=s.getParent();st(i)||re(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&re(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&re(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,d,u]=xe(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,S=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<S||f>_||m>w;){if(h<p){const e=w-S,t=p-1;for(let n=0;n<=e;n++)b(a[S+n][t]);p=t}if(g<S){const e=_-p,t=S-1;for(let n=0;n<=e;n++)b(a[t][p+n]);S=t}if(f>_){const e=w-S,t=_+1;for(let n=0;n<=e;n++)b(a[S+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();ne(o)||re(160),o!==N&&y.push(o),y.push(n,...Fe(n)),N=o}return C()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function Re(e){return e instanceof Me}function Ke(){const e=f("root",0,"element"),t=f("root",0,"element");return new Me("root",e,t)}function Fe(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&re(112),s(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class ke{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=Le(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Le(t),e.observe(t,{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(!st(p(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=Le(t);Ie(e,n,null),S(null),e.dispatchCommand(_,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");n(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");e(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(),Ie(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=p(this.tableNodeKey);if(!st(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=Pe(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=w(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&Q(t)&&o.is(Qe(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Ke(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),S(this.tableSelection),n.dispatchCommand(_,void 0),Ie(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=w(e.elem);if(Q(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ke(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=h();Re(t)||re(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{Q(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),S(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=p(this.tableNodeKey);if(!st(t))throw new Error("Expected TableNode.");const n=h();Re(n)||re(11);const o=n.getNodes().filter(Q);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(s(e)){const t=l(),n=u();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ie(e,this.table,null),S(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const Ae="__lexicalTableSelection",Pe=e=>le?(e||window).getSelection():null;function He(e,n,o,r){const i=o.getRootElement();if(null===i)throw new Error("No root element.");const a=new ke(o,e.getKey()),d=o._window||window;!function(e,t){e[Ae]=t}(n,a);const f=()=>{const e=()=>{a.isSelecting=!1,d.removeEventListener("mouseup",e),d.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&a.isSelecting)return a.isSelecting=!1,d.removeEventListener("mouseup",e),void d.removeEventListener("mousemove",t);const o=Be(n.target);null===o||a.anchorX===o.x&&a.anchorY===o.y||(n.preventDefault(),a.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!d)return;const t=Be(e.target);null!==t&&(Ze(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();a.isSelecting=!0,d.addEventListener("mouseup",n),d.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=h(),n=e.target;Re(t)&&t.tableKey===a.tableNodeKey&&i.contains(n)&&a.clearHighlight()}))};d.addEventListener("mousedown",m),a.listenersToRemove.add((()=>d.removeEventListener("mousedown",m))),a.listenersToRemove.add(o.registerCommand(N,(t=>Ve(o,t,"down",e,a)),T)),a.listenersToRemove.add(o.registerCommand(x,(t=>Ve(o,t,"up",e,a)),T)),a.listenersToRemove.add(o.registerCommand(v,(t=>Ve(o,t,"backward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(E,(t=>Ve(o,t,"forward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=h();if(Re(n)){const o=t(n.focus.getNode(),Q);if(Q(o))return Ze(e),o.selectEnd(),!0}return!1}),T));[M,R,K].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=h();if(!Xe(o,e))return!1;if(Re(o))return a.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(r))return!1;const l=o.anchor.getNode(),i=o.focus.getNode(),c=e.isParentOf(l),d=e.isParentOf(i);if(c&&!d||d&&!c)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>s(e))),h=u&&t(u,(e=>s(e)&&Q(e.getParent())));if(!s(h)||!s(u))return!1;if(n===R&&null===h.getPreviousSibling())return!0}return!1})(n),F))}));const p=n=>{const o=h();if(!Xe(o,e)){const e=o?o.getNodes():null;if(e){const t=e.find((e=>st(e)&&e.getKey()===a.tableNodeKey));if(st(t)){const e=t.getParent();if(!e)return!1;const n=t.getNextSibling()||t.getPreviousSibling();t.remove(),n?n.selectStart():e.selectStart()}}return!0}if(Re(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(e))return!1}return!1};function C(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(k,p,F)),a.listenersToRemove.add(o.registerCommand(A,p,F)),a.listenersToRemove.add(o.registerCommand(P,(n=>{const o=h();if(!Xe(o,e))return!1;if(Re(o))return a.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(e))return!1}return!1}),F)),a.listenersToRemove.add(o.registerCommand(H,(t=>{const n=h();if(!Re(n)||!Xe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Q(o)||!Q(r))return!1;const[l,i,c]=xe(e,o,r),a=Math.max(i.startRow,c.startRow),d=Math.max(i.startColumn,c.startColumn),u=Math.min(i.startRow,c.startRow),g=Math.min(i.startColumn,c.startColumn);for(let e=u;e<=a;e++)for(let n=g;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];s(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),F)),a.listenersToRemove.add(o.registerCommand(D,(n=>{const r=h();if(!Xe(r,e))return!1;if(Re(r))return a.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>Q(e)));if(!Q(l))return!1;if("string"==typeof n){const t=tt(o,r,e);if(t)return et(t,e,[u(n)]),!0}}return!1}),F)),r&&a.listenersToRemove.add(o.registerCommand(B,(t=>{const n=h();if(!g(n)||!n.isCollapsed()||!Xe(n,e))return!1;const o=Ge(n.anchor.getNode());if(null===o)return!1;Ze(t);const r=e.getCordsFromCellNode(o,a.table);return ze(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),F)),a.listenersToRemove.add(o.registerCommand(L,(t=>e.isSelected()),T)),a.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),s=Re(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>Q(e)))&&null!==t(o.focus.getNode(),(e=>Q(e)))||s;if(1!==n.length||!st(n[0])||!i||null===r)return!1;const[a]=r,d=n[0],u=d.getChildren(),h=d.getFirstChildOrThrow().getChildrenSize(),f=d.getChildrenSize(),m=t(a.getNode(),(e=>Q(e))),p=m&&t(m,(e=>ne(e))),C=p&&t(p,(e=>st(e)));if(!Q(m)||!ne(p)||!st(C))return!1;const _=p.getIndexWithinParent(),w=Math.min(C.getChildrenSize()-1,_+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+h-1),N=Math.min(b,y),T=Math.min(_,w),x=Math.max(b,y),v=Math.max(_,w),E=C.getChildren();let O,M,R=0;for(let e=T;e<=v;e++){const t=E[e];if(!ne(t))return!1;const n=u[R];if(!ne(n))return!1;const o=t.getChildren(),r=n.getChildren();let s=0;for(let t=N;t<=x;t++){const n=o[t];if(!Q(n))return!1;const i=r[s];if(!Q(i))return!1;e===T&&t===N?O=n.getKey():e===v&&t===x&&(M=n.getKey());const a=n.getChildren();i.getChildren().forEach((e=>{if(c(e)){l().append(e),n.append(e)}else n.append(e)})),a.forEach((e=>e.remove())),s++}R++}if(O&&M){const e=Ke();e.set(n[0].getKey(),O,M),S(e)}return!0}),F)),a.listenersToRemove.add(o.registerCommand(_,(()=>{const t=h(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Ge(l),c=Ge(s),u=!(!i||!e.is(Qe(i))),h=!(!c||!e.is(Qe(c))),g=u!==h,m=u&&h,p=t.isBackward();if(g){const n=t.clone();if(h){const[t]=xe(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")}else n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element");S(n),Ue(o,a)}else m&&(i.is(c)||(a.setAnchorCellForSelection(C(i)),a.setFocusCellForSelection(C(c),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();a.isSelecting=!0,d.addEventListener("mouseup",e),d.addEventListener("mousemove",t)}),0)))}else if(t&&Re(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Pe(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is(Qe(r)),s=w(n.anchorNode),i=s&&e.is(Qe(s));if(l&&i&&n.rangeCount>0){const r=U(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),S(r))}}}return t&&!t.is(n)&&(Re(t)||Re(n))&&a.tableSelection&&!a.tableSelection.is(n)?(Re(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!Re(t)&&Re(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),We(t.table,(t=>{const n=t.elem;t.highlighted=!1,qe(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&Ue(o,a),!1)}),F)),a.listenersToRemove.add(o.registerCommand(z,(()=>{const t=h();if(!g(t)||!t.isCollapsed()||!Xe(t,e))return!1;const n=tt(o,t,e);return!!n&&(et(n,e),!0)}),F)),a}function De(e){return e[Ae]}function Be(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 Le(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 Ie(e,t,n){const o=new Set(n?n.getNodes():[]);We(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,je(e,t)):(t.highlighted=!1,qe(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function We(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=w(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ue(e,t){t.disableHighlightStyle(),We(t.table,(t=>{t.highlighted=!0,je(e,t)}))}const ze=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Je(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Je(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?Je(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Je(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ye=(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 Xe(e,t){if(g(e)||Re(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Je(e,t){t?e.selectStart():e.selectEnd()}const $e="172,206,247";function je(e,t){const n=t.elem,o=w(n);Q(o)||re(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${$e})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${$e},0.85), rgba(${$e},0.85))`),n.style.setProperty("caret-color","transparent")}function qe(e,t){const n=t.elem,o=w(n);Q(o)||re(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function Ge(e){const n=t(e,Q);return Q(n)?n:null}function Qe(e){const n=t(e,st);return st(n)?n:null}function Ve(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 i=h();if(!Xe(i,r)){if(g(i)){if(i.isCollapsed()&&"backward"===o){const e=i.anchor.type,o=i.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=i.anchor.getNode();if(!r)return!1;const l=t(r,(e=>s(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!st(c))&&(Ze(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=i.anchor.getNode();if(Y(e)){const e=i.getNodes()[0];if(e){const n=t(e,Q);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ee(e),[o]=Ee(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=t(e,(e=>s(e)&&!e.isInline()));if(!n)return!1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(st(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ee(e),[l]=Ee(t),s=i.clone();return s.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),S(s),!0}}}}return!1}if(g(i)&&i.isCollapsed()){const{anchor:c,focus:a}=i,d=t(c.getNode(),Q),u=t(a.getNode(),Q);if(!Q(d)||!d.is(u))return!1;const h=Qe(d);if(h!==r&&null!=h){const t=e.getElementByKey(h.getKey());if(null!=t)return l.table=Le(t),Ve(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=i.getNodes();return(1!==d.length||!X(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=t(o,(e=>s(e)&&!e.isInline()));if(!l)return!1;const i="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&i&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,Q);if(!Q(l))return!1;const[i,c]=xe(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}(i,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>s(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&st(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||st(a))return!1;Ze(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){Ze(n);const e=r.getCordsFromCellNode(d,l.table);if(!n.shiftKey)return ze(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.setAnchorCellForSelection(t),l.setFocusCellForSelection(t,!0)}return!0}}else if(Re(i)){const{anchor:s,focus:c}=i,a=t(s.getNode(),Q),d=t(c.getNode(),Q),[u]=i.getNodes(),h=e.getElementByKey(u.getKey());if(!Q(a)||!Q(d)||!st(u)||null==h)return!1;l.updateTableTableSelection(i);const g=Le(h),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Ze(n),n.shiftKey){const e=r.getCordsFromCellNode(d,g);return Ye(l,u,e.x,e.y,o)}return d.selectEnd(),!0}return!1}function Ze(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function et(e,t,n){const o=l();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function tt(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=t(n.anchor.getNode(),(e=>Q(e)));if(!i)return;const c=t(i,(e=>st(e)));if(!st(c)||!c.is(o))return;const[a,d]=xe(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 nt extends r{static getType(){return"table"}static clone(e){return new nt(e.__key)}static importDOM(){return{table:e=>({conversion:rt,priority:1})}}static importJSON(e){return lt()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(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"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!ne(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,r),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 w(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];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=w(o.elem);return Q(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 ot(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Le(n)}function rt(e){return{node:lt()}}function lt(){return a(new nt)}function st(e){return e instanceof nt}export{xe as $computeTableMap,ve as $computeTableMapSkipCellCheck,G as $createTableCellNode,lt as $createTableNode,se as $createTableNodeWithDimensions,te as $createTableRowNode,Ke as $createTableSelection,_e as $deleteTableColumn,be as $deleteTableColumn__EXPERIMENTAL,we as $deleteTableRow__EXPERIMENTAL,Ge as $findCellNode,Qe as $findTableNode,ot as $getElementForTableNode,Ee as $getNodeTriplet,ie as $getTableCellNodeFromLexicalNode,Oe as $getTableCellNodeRect,ue as $getTableColumnIndexFromTableCellNode,ae as $getTableNodeFromLexicalNodeOrThrow,de as $getTableRowIndexFromTableCellNode,ce as $getTableRowNodeFromTableCellNodeOrThrow,Ce as $insertTableColumn,Se as $insertTableColumn__EXPERIMENTAL,fe as $insertTableRow,pe as $insertTableRow__EXPERIMENTAL,Q as $isTableCellNode,st as $isTableNode,ne as $isTableRowNode,Re as $isTableSelection,ge as $removeTableRowAtIndex,Te as $unmergeCell,V as INSERT_TABLE_COMMAND,$ as TableCellHeaderStates,j as TableCellNode,nt as TableNode,ke as TableObserver,Z as TableRowNode,He as applyTableHandlers,Be as getDOMCellFromTarget,De as getTableObserverFromTableElement};
9
+ import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,isHTMLElement as o}from"@lexical/utils";import{ElementNode as r,$createParagraphNode as l,$isElementNode as s,$isLineBreakNode as i,$isTextNode as c,$applyNodeReplacement as a,createCommand as d,$createTextNode as u,$getSelection as h,$isRangeSelection as g,$createPoint as f,$normalizeSelection__EXPERIMENTAL as m,$getNodeByKey as p,isCurrentlyReadOnlyMode as C,$setSelection as S,SELECTION_CHANGE_COMMAND as _,$getNearestNodeFromDOMNode as w,$createRangeSelection as b,$getRoot as y,KEY_ARROW_DOWN_COMMAND as N,COMMAND_PRIORITY_HIGH as T,KEY_ARROW_UP_COMMAND as x,KEY_ARROW_LEFT_COMMAND as v,KEY_ARROW_RIGHT_COMMAND as E,KEY_ESCAPE_COMMAND as O,DELETE_WORD_COMMAND as M,DELETE_LINE_COMMAND as R,DELETE_CHARACTER_COMMAND as K,COMMAND_PRIORITY_CRITICAL as F,KEY_BACKSPACE_COMMAND as k,KEY_DELETE_COMMAND as A,FORMAT_TEXT_COMMAND as P,FORMAT_ELEMENT_COMMAND as H,CONTROLLED_TEXT_INSERTION_COMMAND as D,KEY_TAB_COMMAND as B,FOCUS_COMMAND as L,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as z,$isRootOrShadowRoot as Y,$isDecoratorNode as X}from"lexical";const J=/^(\d+(?:\.\d+)?)px$/,$={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class j extends r{static getType(){return"tablecell"}static clone(e){const t=new j(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:q,priority:0}),th:e=>({conversion:q,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=G(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=$.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__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!==$.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 q(e){const t=e,n=e.nodeName.toLowerCase();let o;J.test(t.style.width)&&(o=parseFloat(t.style.width));const r=G("th"===n?$.ROW:$.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const a=t.style.backgroundColor;""!==a&&(r.__backgroundColor=a);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(l()),e),forChild:(e,t)=>{if(Q(t)&&!s(e)){const t=l();return i(e)&&"\n"===e.getTextContent()?null:(c(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 G(e,t=1,n){return a(new j(e,t,n))}function Q(e){return e instanceof j}const V=d("INSERT_TABLE_COMMAND");class Z extends r{static getType(){return"tablerow"}static clone(e){return new Z(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ee,priority:0})}}static importJSON(e){return te(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function ee(e){const t=e;let n;return J.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:te(n)}}function te(e){return a(new Z(e))}function ne(e){return e instanceof Z}function oe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var re=oe((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 le="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function se(e,t,n=!0){const o=lt();for(let r=0;r<e;r++){const e=te();for(let o=0;o<t;o++){let t=$.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=$.ROW),0===o&&n.columns&&(t|=$.COLUMN)):n&&(0===r&&(t|=$.ROW),0===o&&(t|=$.COLUMN));const s=G(t),i=l();i.append(u()),s.append(i),e.append(s)}o.append(e)}return o}function ie(e){const n=t(e,(e=>Q(e)));return Q(n)?n:null}function ce(e){const n=t(e,(e=>ne(e)));if(ne(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ae(e){const n=t(e,(e=>st(e)));if(st(n))return n;throw new Error("Expected table cell to be inside of table.")}function de(e){const t=ce(e);return ae(t).getChildren().findIndex((e=>e.is(t)))}function ue(e){return ce(e).getChildren().findIndex((t=>t.is(e)))}function he(e,t){const n=ae(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 ge(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 fe(e,t,n=!0,o,r){const s=e.getChildren();if(t>=s.length||t<0)throw new Error("Table row target index out of range");const i=s[t];if(!ne(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=te();for(let n=0;n<t;n++){const t=e[n];Q(t)||re(12);const{above:s,below:i}=he(t,r);let c=$.NO_STATUS;const a=s&&s.getWidth()||i&&i.getWidth()||void 0;(s&&s.hasHeaderState($.COLUMN)||i&&i.hasHeaderState($.COLUMN))&&(c|=$.COLUMN);const d=G(c,1,a);d.append(l()),o.append(d)}n?i.insertAfter(o):i.insertBefore(o)}return e}const me=(e,t)=>e===$.BOTH||e===t?t:$.NO_STATUS;function pe(e=!0){const t=h();g(t)||Re(t)||re(188);const n=t.focus.getNode(),[o,,r]=Ee(n),[s,i]=xe(r,o,o),c=s[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=s[e],n=te();for(let o=0;o<c;o++){const{cell:r,startRow:s}=t[o];if(s+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=me(e,$.COLUMN);n.append(G(r).append(l()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ne(i)||re(145),i.insertAfter(n)}else{const e=s[a],t=te();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=me(o,$.COLUMN);t.append(G(r).append(l()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ne(n)||re(145),n.insertBefore(t)}}function Ce(e,t,n=!0,o,r){const s=e.getChildren(),i=[];for(let e=0;e<s.length;e++){const n=s[e];if(ne(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];Q(o)||re(12);const{left:s,right:c}=he(o,r);let a=$.NO_STATUS;(s&&s.hasHeaderState($.ROW)||c&&c.hasHeaderState($.ROW))&&(a|=$.ROW);const d=G(a);d.append(l()),i.push({newTableCell:d,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Se(e=!0){const t=h();g(t)||Re(t)||re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ee(n),[s,,i]=Ee(o),[c,a,d]=xe(i,s,r),u=c.length,f=e?Math.max(a.startColumn,d.startColumn):Math.min(a.startColumn,d.startColumn),m=e?f+s.__colSpan-1:f-1,p=i.getFirstChild();ne(p)||re(120);let C=null;function S(e=$.NO_STATUS){const t=G(e).append(l());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<u;e++){if(0!==e){const e=_.getNextSibling();ne(e)||re(121),_=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=me(n,$.ROW);if(m<0){Ne(_,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&&ye(C)}function _e(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ne(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 we(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ee(t),[l]=Ee(n),[s,i,c]=xe(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 f=s[0].length,m=s[u+1],p=r.getChildAtIndex(u+1);for(let e=u;e>=a;e--){for(let t=f-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&&re(122),0===t)Ne(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ne(t)||re(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];ye(e)}else{const e=s[a-1],{cell:t}=e[0];ye(t)}}function be(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ee(t),[l]=Ee(n),[s,i,c]=xe(r,o,l),{startColumn:a}=i,{startRow:d,startColumn:u}=c,f=Math.min(a,u),m=Math.max(a+o.__colSpan-1,u+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[d],_=a>u?S[a+o.__colSpan]:S[u+l.__colSpan];if(void 0!==_){const{cell:e}=_;ye(e)}else{const e=u<a?S[u-1]:S[a-1],{cell:t}=e;ye(t)}}function ye(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ne(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Te(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),[n,o,r]=Ee(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(G($.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=xe(r,n,n),{startColumn:i,startRow:c}=t;let a;for(let t=1;t<s;t++){const n=c+t,r=e[n];a=(a||o).getNextSibling(),ne(a)||re(125);let s=null;for(let e=0;e<i;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 e=0;e<l;e++)Ne(a,G($.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(G($.NO_STATUS))}n.setRowSpan(1)}}function xe(e,t,n){const[o,r,l]=ve(e,t,n);return null===r&&re(110),null===l&&re(111),[o,r,l]}function ve(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];ne(t)||re(146);const n=t.getChildren();let o=0;for(const t of n){for(Q(t)||re(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function Ee(e){let n;if(e instanceof j)n=e;else if("__type"in e){const o=t(e,Q);Q(o)||re(148),n=o}else{const o=t(e.getNode(),Q);Q(o)||re(148),n=o}const o=n.getParent();ne(o)||re(149);const r=o.getParent();return st(r)||re(150),[n,o,r]}function Oe(e){const[t,,n]=Ee(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 Me{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!!Re(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 Me(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();s(t)||re(151);m(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=p(this.anchor.key);Q(e)||re(152);const t=Oe(e);null===t&&re(153);const n=p(this.focus.key);Q(n)||re(154);const o=Oe(n);null===o&&re(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=t(n,Q),l=t(o,Q);Q(r)||re(152),Q(l)||re(154);const s=r.getParent();ne(s)||re(156);const i=s.getParent();st(i)||re(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&re(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&re(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,d,u]=xe(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,S=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<S||f>_||m>w;){if(h<p){const e=w-S,t=p-1;for(let n=0;n<=e;n++)b(a[S+n][t]);p=t}if(g<S){const e=_-p,t=S-1;for(let n=0;n<=e;n++)b(a[t][p+n]);S=t}if(f>_){const e=w-S,t=_+1;for(let n=0;n<=e;n++)b(a[S+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();ne(o)||re(160),o!==N&&y.push(o),y.push(n,...Fe(n)),N=o}return C()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function Re(e){return e instanceof Me}function Ke(){const e=f("root",0,"element"),t=f("root",0,"element");return new Me("root",e,t)}function Fe(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&re(112),s(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class ke{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=Le(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Le(t),e.observe(t,{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(!st(p(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=Le(t);Ie(e,n,null),S(null),e.dispatchCommand(_,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");n(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");e(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(),Ie(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=p(this.tableNodeKey);if(!st(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=Pe(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=w(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&Q(t)&&o.is(Qe(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Ke(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),S(this.tableSelection),n.dispatchCommand(_,void 0),Ie(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=w(e.elem);if(Q(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ke(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=h();Re(t)||re(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{Q(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),S(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=p(this.tableNodeKey);if(!st(t))throw new Error("Expected TableNode.");const n=h();Re(n)||re(11);const o=n.getNodes().filter(Q);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(s(e)){const t=l(),n=u();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ie(e,this.table,null),S(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const Ae="__lexicalTableSelection",Pe=e=>le?(e||window).getSelection():null;function He(e,n,o,r){const i=o.getRootElement();if(null===i)throw new Error("No root element.");const a=new ke(o,e.getKey()),d=o._window||window;!function(e,t){e[Ae]=t}(n,a);const f=()=>{const e=()=>{a.isSelecting=!1,d.removeEventListener("mouseup",e),d.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&a.isSelecting)return a.isSelecting=!1,d.removeEventListener("mouseup",e),void d.removeEventListener("mousemove",t);const o=Be(n.target);null===o||a.anchorX===o.x&&a.anchorY===o.y||(n.preventDefault(),a.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!d)return;const t=Be(e.target);null!==t&&(Ze(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();a.isSelecting=!0,d.addEventListener("mouseup",n),d.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=h(),n=e.target;Re(t)&&t.tableKey===a.tableNodeKey&&i.contains(n)&&a.clearHighlight()}))};d.addEventListener("mousedown",m),a.listenersToRemove.add((()=>d.removeEventListener("mousedown",m))),a.listenersToRemove.add(o.registerCommand(N,(t=>Ve(o,t,"down",e,a)),T)),a.listenersToRemove.add(o.registerCommand(x,(t=>Ve(o,t,"up",e,a)),T)),a.listenersToRemove.add(o.registerCommand(v,(t=>Ve(o,t,"backward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(E,(t=>Ve(o,t,"forward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=h();if(Re(n)){const o=t(n.focus.getNode(),Q);if(Q(o))return Ze(e),o.selectEnd(),!0}return!1}),T));[M,R,K].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=h();if(!Xe(o,e))return!1;if(Re(o))return a.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(r))return!1;const l=o.anchor.getNode(),i=o.focus.getNode(),c=e.isParentOf(l),d=e.isParentOf(i);if(c&&!d||d&&!c)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>s(e))),h=u&&t(u,(e=>s(e)&&Q(e.getParent())));if(!s(h)||!s(u))return!1;if(n===R&&null===h.getPreviousSibling())return!0}return!1})(n),F))}));const p=n=>{const o=h();if(!Xe(o,e)){const e=o?o.getNodes():null;if(e){const t=e.find((e=>st(e)&&e.getKey()===a.tableNodeKey));if(st(t)){const e=t.getParent();if(!e)return!1;const n=t.getNextSibling()||t.getPreviousSibling();t.remove(),n?n.selectStart():e.selectStart()}}return!0}if(Re(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(e))return!1}return!1};function C(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(k,p,F)),a.listenersToRemove.add(o.registerCommand(A,p,F)),a.listenersToRemove.add(o.registerCommand(P,(n=>{const o=h();if(!Xe(o,e))return!1;if(Re(o))return a.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(e))return!1}return!1}),F)),a.listenersToRemove.add(o.registerCommand(H,(t=>{const n=h();if(!Re(n)||!Xe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Q(o)||!Q(r))return!1;const[l,i,c]=xe(e,o,r),a=Math.max(i.startRow,c.startRow),d=Math.max(i.startColumn,c.startColumn),u=Math.min(i.startRow,c.startRow),g=Math.min(i.startColumn,c.startColumn);for(let e=u;e<=a;e++)for(let n=g;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];s(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),F)),a.listenersToRemove.add(o.registerCommand(D,(n=>{const r=h();if(!Xe(r,e))return!1;if(Re(r))return a.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>Q(e)));if(!Q(l))return!1;if("string"==typeof n){const t=tt(o,r,e);if(t)return et(t,e,[u(n)]),!0}}return!1}),F)),r&&a.listenersToRemove.add(o.registerCommand(B,(t=>{const n=h();if(!g(n)||!n.isCollapsed()||!Xe(n,e))return!1;const o=Ge(n.anchor.getNode());if(null===o)return!1;Ze(t);const r=e.getCordsFromCellNode(o,a.table);return ze(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),F)),a.listenersToRemove.add(o.registerCommand(L,(t=>e.isSelected()),T)),a.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),s=Re(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>Q(e)))&&null!==t(o.focus.getNode(),(e=>Q(e)))||s;if(1!==n.length||!st(n[0])||!i||null===r)return!1;const[a]=r,d=n[0],u=d.getChildren(),h=d.getFirstChildOrThrow().getChildrenSize(),f=d.getChildrenSize(),m=t(a.getNode(),(e=>Q(e))),p=m&&t(m,(e=>ne(e))),C=p&&t(p,(e=>st(e)));if(!Q(m)||!ne(p)||!st(C))return!1;const _=p.getIndexWithinParent(),w=Math.min(C.getChildrenSize()-1,_+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+h-1),N=Math.min(b,y),T=Math.min(_,w),x=Math.max(b,y),v=Math.max(_,w),E=C.getChildren();let O,M,R=0;for(let e=T;e<=v;e++){const t=E[e];if(!ne(t))return!1;const n=u[R];if(!ne(n))return!1;const o=t.getChildren(),r=n.getChildren();let s=0;for(let t=N;t<=x;t++){const n=o[t];if(!Q(n))return!1;const i=r[s];if(!Q(i))return!1;e===T&&t===N?O=n.getKey():e===v&&t===x&&(M=n.getKey());const a=n.getChildren();i.getChildren().forEach((e=>{if(c(e)){l().append(e),n.append(e)}else n.append(e)})),a.forEach((e=>e.remove())),s++}R++}if(O&&M){const e=Ke();e.set(n[0].getKey(),O,M),S(e)}return!0}),F)),a.listenersToRemove.add(o.registerCommand(_,(()=>{const t=h(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Ge(l),c=Ge(s),u=!(!i||!e.is(Qe(i))),h=!(!c||!e.is(Qe(c))),g=u!==h,m=u&&h,p=t.isBackward();if(g){const n=t.clone();if(h){const[t]=xe(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")}else n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element");S(n),Ue(o,a)}else m&&(i.is(c)||(a.setAnchorCellForSelection(C(i)),a.setFocusCellForSelection(C(c),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();a.isSelecting=!0,d.addEventListener("mouseup",e),d.addEventListener("mousemove",t)}),0)))}else if(t&&Re(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Pe(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is(Qe(r)),s=w(n.anchorNode),i=s&&e.is(Qe(s));if(l&&i&&n.rangeCount>0){const r=U(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),S(r))}}}return t&&!t.is(n)&&(Re(t)||Re(n))&&a.tableSelection&&!a.tableSelection.is(n)?(Re(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!Re(t)&&Re(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),We(t.table,(t=>{const n=t.elem;t.highlighted=!1,qe(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&Ue(o,a),!1)}),F)),a.listenersToRemove.add(o.registerCommand(z,(()=>{const t=h();if(!g(t)||!t.isCollapsed()||!Xe(t,e))return!1;const n=tt(o,t,e);return!!n&&(et(n,e),!0)}),F)),a}function De(e){return e[Ae]}function Be(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 Le(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 Ie(e,t,n){const o=new Set(n?n.getNodes():[]);We(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,je(e,t)):(t.highlighted=!1,qe(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function We(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=w(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ue(e,t){t.disableHighlightStyle(),We(t.table,(t=>{t.highlighted=!0,je(e,t)}))}const ze=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Je(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Je(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?Je(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Je(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ye=(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 Xe(e,t){if(g(e)||Re(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Je(e,t){t?e.selectStart():e.selectEnd()}const $e="172,206,247";function je(e,t){const n=t.elem,o=w(n);Q(o)||re(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${$e})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${$e},0.85), rgba(${$e},0.85))`),n.style.setProperty("caret-color","transparent")}function qe(e,t){const n=t.elem,o=w(n);Q(o)||re(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function Ge(e){const n=t(e,Q);return Q(n)?n:null}function Qe(e){const n=t(e,st);return st(n)?n:null}function Ve(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 i=h();if(!Xe(i,r)){if(g(i)){if(i.isCollapsed()&&"backward"===o){const e=i.anchor.type,o=i.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=i.anchor.getNode();if(!r)return!1;const l=t(r,(e=>s(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!st(c))&&(Ze(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=i.focus.getNode();if(Y(e)){const e=i.getNodes()[0];if(e){const n=t(e,Q);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ee(e),[o]=Ee(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=t(e,(e=>s(e)&&!e.isInline()));if(!n)return!1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(st(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ee(e),[l]=Ee(t),s=i.clone();return s.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),S(s),!0}}}}return!1}if(g(i)&&i.isCollapsed()){const{anchor:c,focus:a}=i,d=t(c.getNode(),Q),u=t(a.getNode(),Q);if(!Q(d)||!d.is(u))return!1;const h=Qe(d);if(h!==r&&null!=h){const t=e.getElementByKey(h.getKey());if(null!=t)return l.table=Le(t),Ve(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=i.getNodes();return(1!==d.length||!X(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=t(o,(e=>s(e)&&!e.isInline()));if(!l)return!1;const i="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&i&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,Q);if(!Q(l))return!1;const[i,c]=xe(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}(i,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>s(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&st(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||st(a))return!1;Ze(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){Ze(n);const e=r.getCordsFromCellNode(d,l.table);if(!n.shiftKey)return ze(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.setAnchorCellForSelection(t),l.setFocusCellForSelection(t,!0)}return!0}}else if(Re(i)){const{anchor:s,focus:c}=i,a=t(s.getNode(),Q),d=t(c.getNode(),Q),[u]=i.getNodes(),h=e.getElementByKey(u.getKey());if(!Q(a)||!Q(d)||!st(u)||null==h)return!1;l.updateTableTableSelection(i);const g=Le(h),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Ze(n),n.shiftKey){const e=r.getCordsFromCellNode(d,g);return Ye(l,u,e.x,e.y,o)}return d.selectEnd(),!0}return!1}function Ze(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function et(e,t,n){const o=l();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function tt(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=t(n.anchor.getNode(),(e=>Q(e)));if(!i)return;const c=t(i,(e=>st(e)));if(!st(c)||!c.is(o))return;const[a,d]=xe(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 nt extends r{static getType(){return"table"}static clone(e){return new nt(e.__key)}static importDOM(){return{table:e=>({conversion:rt,priority:1})}}static importJSON(e){return lt()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(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"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!ne(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,r),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 w(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];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=w(o.elem);return Q(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 ot(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Le(n)}function rt(e){return{node:lt()}}function lt(){return a(new nt)}function st(e){return e instanceof nt}export{xe as $computeTableMap,ve as $computeTableMapSkipCellCheck,G as $createTableCellNode,lt as $createTableNode,se as $createTableNodeWithDimensions,te as $createTableRowNode,Ke as $createTableSelection,_e as $deleteTableColumn,be as $deleteTableColumn__EXPERIMENTAL,we as $deleteTableRow__EXPERIMENTAL,Ge as $findCellNode,Qe as $findTableNode,ot as $getElementForTableNode,Ee as $getNodeTriplet,ie as $getTableCellNodeFromLexicalNode,Oe as $getTableCellNodeRect,ue as $getTableColumnIndexFromTableCellNode,ae as $getTableNodeFromLexicalNodeOrThrow,de as $getTableRowIndexFromTableCellNode,ce as $getTableRowNodeFromTableCellNodeOrThrow,Ce as $insertTableColumn,Se as $insertTableColumn__EXPERIMENTAL,fe as $insertTableRow,pe as $insertTableRow__EXPERIMENTAL,Q as $isTableCellNode,st as $isTableNode,ne as $isTableRowNode,Re as $isTableSelection,ge as $removeTableRowAtIndex,Te as $unmergeCell,V as INSERT_TABLE_COMMAND,$ as TableCellHeaderStates,j as TableCellNode,nt as TableNode,ke as TableObserver,Z as TableRowNode,He as applyTableHandlers,Be as getDOMCellFromTarget,De as getTableObserverFromTableElement};
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.16.2-nightly.20240711.0",
11
+ "version": "0.16.2-nightly.20240715.0",
12
12
  "main": "LexicalTable.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.16.2-nightly.20240711.0",
16
- "lexical": "0.16.2-nightly.20240711.0"
15
+ "@lexical/utils": "0.16.2-nightly.20240715.0",
16
+ "lexical": "0.16.2-nightly.20240715.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",