@lexical/table 0.18.1-nightly.20241018.0 → 0.18.1-nightly.20241022.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LexicalTable.dev.js +1 -1
- package/LexicalTable.dev.mjs +1 -1
- package/LexicalTable.prod.js +2 -2
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +4 -4
package/LexicalTable.dev.js
CHANGED
@@ -231,7 +231,7 @@ function $convertTableCellNodeElement(domNode) {
|
|
231
231
|
tableCellNode.__backgroundColor = backgroundColor;
|
232
232
|
}
|
233
233
|
const style = domNode_.style;
|
234
|
-
const textDecoration = style.textDecoration.split(' ');
|
234
|
+
const textDecoration = (style && style.textDecoration || '').split(' ');
|
235
235
|
const hasBoldFontWeight = style.fontWeight === '700' || style.fontWeight === 'bold';
|
236
236
|
const hasLinethroughTextDecoration = textDecoration.includes('line-through');
|
237
237
|
const hasItalicFontStyle = style.fontStyle === 'italic';
|
package/LexicalTable.dev.mjs
CHANGED
@@ -229,7 +229,7 @@ function $convertTableCellNodeElement(domNode) {
|
|
229
229
|
tableCellNode.__backgroundColor = backgroundColor;
|
230
230
|
}
|
231
231
|
const style = domNode_.style;
|
232
|
-
const textDecoration = style.textDecoration.split(' ');
|
232
|
+
const textDecoration = (style && style.textDecoration || '').split(' ');
|
233
233
|
const hasBoldFontWeight = style.fontWeight === '700' || style.fontWeight === 'bold';
|
234
234
|
const hasLinethroughTextDecoration = textDecoration.includes('line-through');
|
235
235
|
const hasItalicFontStyle = style.fontStyle === 'italic';
|
package/LexicalTable.prod.js
CHANGED
@@ -13,8 +13,8 @@ super.exportDOM(a));if(a){a.style.border="1px solid black";1<this.__colSpan&&(a.
|
|
13
13
|
rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(a){let b=this.getWritable();b.__colSpan=a;return b}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(a){let b=this.getWritable();b.__rowSpan=a;return b}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a,b=x.BOTH){let c=this.getWritable();c.__headerState=a&b|c.__headerState&~b;return c}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){let b=this.getWritable();
|
14
14
|
b.__width=a;return b}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){let b=this.getWritable();b.__backgroundColor=a;return b}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==x.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||
|
15
15
|
a.__width!==this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
|
16
|
-
function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=a.textDecoration.split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),f="italic"===a.fontStyle,g=c.includes("underline");return{after:n=>{0===n.length&&n.push(w.$createParagraphNode());return n},forChild:(n,p)=>
|
17
|
-
|
16
|
+
function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=(a&&a.textDecoration||"").split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),f="italic"===a.fontStyle,g=c.includes("underline");return{after:n=>{0===n.length&&n.push(w.$createParagraphNode());return n},forChild:(n,p)=>
|
17
|
+
{if(C(p)&&!w.$isElementNode(n)){p=w.$createParagraphNode();if(w.$isLineBreakNode(n)&&"\n"===n.getTextContent())return null;w.$isTextNode(n)&&(d&&n.toggleFormat("bold"),e&&n.toggleFormat("strikethrough"),f&&n.toggleFormat("italic"),g&&n.toggleFormat("underline"));p.append(n);return p}return n},node:b}}function B(a,b=1,c){return w.$applyNodeReplacement(new y(a,b,c))}function C(a){return a instanceof y}let da=w.createCommand("INSERT_TABLE_COMMAND");var D;
|
18
18
|
function F(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}D=F&&F.__esModule&&Object.prototype.hasOwnProperty.call(F,"default")?F["default"]:F;let ea="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
19
19
|
class I extends w.ElementNode{static getType(){return"tablerow"}static clone(a){return new I(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return J(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);h.addClassNamesToElement(b,
|
20
20
|
a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function fa(a){let b=void 0;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:J(b)}}function J(a){return w.$applyNodeReplacement(new I(a))}function K(a){return a instanceof I}
|
package/LexicalTable.prod.mjs
CHANGED
@@ -6,4 +6,4 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as u,createCommand as h,$createTextNode as d,$getSelection as g,$isRangeSelection as f,$createPoint as p,$isParagraphNode as m,$normalizeSelection__EXPERIMENTAL as C,$getNodeByKey as S,isCurrentlyReadOnlyMode as _,TEXT_TYPE_TO_FORMAT as w,$setSelection as b,SELECTION_CHANGE_COMMAND as y,$getNearestNodeFromDOMNode as N,$createRangeSelection as x,$getRoot as T,KEY_ARROW_DOWN_COMMAND as v,COMMAND_PRIORITY_HIGH as O,KEY_ARROW_UP_COMMAND as E,KEY_ARROW_LEFT_COMMAND as R,KEY_ARROW_RIGHT_COMMAND as M,KEY_ESCAPE_COMMAND as F,DELETE_WORD_COMMAND as K,DELETE_LINE_COMMAND as k,DELETE_CHARACTER_COMMAND as A,COMMAND_PRIORITY_CRITICAL as B,KEY_BACKSPACE_COMMAND as H,KEY_DELETE_COMMAND as P,CUT_COMMAND as D,FORMAT_TEXT_COMMAND as W,FORMAT_ELEMENT_COMMAND as L,CONTROLLED_TEXT_INSERTION_COMMAND as I,KEY_TAB_COMMAND as U,FOCUS_COMMAND as z,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Y,$getPreviousSelection as X,$createRangeSelectionFromDom as $,INSERT_PARAGRAPH_COMMAND as J,$isRootOrShadowRoot as j,$isDecoratorNode as q}from"lexical";import{copyToClipboard as G,$getClipboardDataFromSelection as Q}from"@lexical/clipboard";const V=/^(\d+(?:\.\d+)?)px$/,Z={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ee extends l{static getType(){return"tablecell"}static clone(e){return new ee(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor}static importDOM(){return{td:e=>({conversion:te,priority:0}),th:e=>({conversion:te,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return ne(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=Z.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Z.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Z.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 te(e){const t=e,n=e.nodeName.toLowerCase();let o;V.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ne("th"===n?Z.ROW:Z.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const u=t.style,h=u.textDecoration.split(" "),d="700"===u.fontWeight||"bold"===u.fontWeight,g=h.includes("line-through"),f="italic"===u.fontStyle,p=h.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(oe(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function ne(e,t=1,n){return u(new ee(e,t,n))}function oe(e){return e instanceof ee}const re=h("INSERT_TABLE_COMMAND");function le(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var se=le((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 ie="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;class ce extends l{static getType(){return"tablerow"}static clone(e){return new ce(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ae,priority:0})}}static importJSON(e){return ue(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 ae(e){const t=e;let n;return V.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:ue(n)}}function ue(e){return u(new ce(e))}function he(e){return e instanceof ce}function de(e,t,n=!0){const o=gt();for(let r=0;r<e;r++){const e=ue();for(let o=0;o<t;o++){let t=Z.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Z.ROW),0===o&&n.columns&&(t|=Z.COLUMN)):n&&(0===r&&(t|=Z.ROW),0===o&&(t|=Z.COLUMN));const l=ne(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function ge(e){const n=t(e,(e=>oe(e)));return oe(n)?n:null}function fe(e){const n=t(e,(e=>he(e)));if(he(n))return n;throw new Error("Expected table cell to be inside of table row.")}function pe(e){const n=t(e,(e=>ft(e)));if(ft(n))return n;throw new Error("Expected table cell to be inside of table.")}function me(e){const t=fe(e);return pe(t).getChildren().findIndex((e=>e.is(t)))}function Ce(e){return fe(e).getChildren().findIndex((t=>t.is(e)))}function Se(e,t){const n=pe(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 _e(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 we(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(!he(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=ue();for(let n=0;n<t;n++){const t=e[n];oe(t)||se(12);const{above:l,below:i}=Se(t,r);let c=Z.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Z.COLUMN)||i&&i.hasHeaderState(Z.COLUMN))&&(c|=Z.COLUMN);const u=ne(c,1,a);u.append(s()),o.append(u)}n?i.insertAfter(o):i.insertBefore(o)}return e}const be=(e,t)=>e===Z.BOTH||e===t?t:Z.NO_STATUS;function ye(e=!0){const t=g();f(t)||He(t)||se(188);const n=t.focus.getNode(),[o,,r]=ke(n),[l,i]=Fe(r,o,o),c=l[0].length,{startRow:a}=i;let u=null;if(e){const e=a+o.__rowSpan-1,t=l[e],n=ue();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=be(e,Z.COLUMN);n.append(ne(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);he(i)||se(145),i.insertAfter(n),u=n}else{const e=l[a],t=ue();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=be(o,Z.COLUMN);t.append(ne(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);he(n)||se(145),n.insertBefore(t),u=t}return u}function Ne(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(he(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];oe(o)||se(12);const{left:l,right:c}=Se(o,r);let a=Z.NO_STATUS;(l&&l.hasHeaderState(Z.ROW)||c&&c.hasHeaderState(Z.ROW))&&(a|=Z.ROW);const u=ne(a);u.append(s()),i.push({newTableCell:u,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function xe(e=!0){const t=g();f(t)||He(t)||se(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=ke(n),[l,,i]=ke(o),[c,a,u]=Fe(i,l,r),h=c.length,d=e?Math.max(a.startColumn,u.startColumn):Math.min(a.startColumn,u.startColumn),p=e?d+l.__colSpan-1:d-1,m=i.getFirstChild();he(m)||se(120);let C=null;function S(e=Z.NO_STATUS){const t=ne(e).append(s());return null===C&&(C=t),t}let _=m;e:for(let e=0;e<h;e++){if(0!==e){const e=_.getNextSibling();he(e)||se(121),_=e}const t=c[e],n=t[p<0?0:p].cell.__headerState,o=be(n,Z.ROW);if(p<0){Re(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[p];if(l+r.__colSpan-1<=p){let n=r,l=s,i=p;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(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&&Ee(C);const w=i.getColWidths();if(w){const e=[...w],t=p<0?0:p,n=e[t];e.splice(t,0,n),i.setColWidths(e)}return C}function Te(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(he(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 ve(){const e=g();f(e)||He(e)||se(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=ke(t),[l]=ke(n),[s,i,c]=Fe(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,p=s[h+1],m=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>h))if(n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&se(122),0===t)Re(m,n);else{const{cell:e}=p[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);he(t)||se(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];Ee(e)}else{const e=s[a-1],{cell:t}=e[0];Ee(t)}}function Oe(){const e=g();f(e)||He(e)||se(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ke(t),[l]=ke(n),[s,i,c]=Fe(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),p=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),m=p-d+1;if(s[0].length===p-d+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=d;t<=p;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(m,n.__colSpan-e))}}else if(o+n.__colSpan-1>p){if(t===p){const e=p-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[u],_=a>h?S[a+o.__colSpan]:S[h+l.__colSpan];if(void 0!==_){const{cell:e}=_;Ee(e)}else{const e=h<a?S[h-1]:S[a-1],{cell:t}=e;Ee(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,m),r.setColWidths(e)}}function Ee(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Re(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Me(){const e=g();f(e)||He(e)||se(188);const t=e.anchor.getNode(),[n,o,r]=ke(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Fe(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&Z.COLUMN,p=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<c.length;e++)n&=c[e][t+u].cell.__headerState;return n})),m=n.__headerState&Z.ROW,C=Array.from({length:i},((e,t)=>{let n=m;for(let e=0;0!==n&&e<c[0].length;e++)n&=c[t+h][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(ne(p[e]|C[0]).append(s()));n.setColSpan(1)}if(i>1){let e;for(let t=1;t<i;t++){const n=h+t,r=c[n];e=(e||o).getNextSibling(),he(e)||se(125);let i=null;for(let e=0;e<u;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===i)for(let n=l-1;n>=0;n--)Re(e,ne(p[n]|C[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(ne(p[e]|C[t]).append(s()))}n.setRowSpan(1)}}function Fe(e,t,n){const[o,r,l]=Ke(e,t,n);return null===r&&se(207),null===l&&se(208),[o,r,l]}function Ke(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];he(o)||se(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){oe(c)||se(147);const o=s(e);for(;void 0!==o[a];)a++;const u={cell:c,startColumn:a,startRow:e},{__rowSpan:h,__colSpan:d}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[a+e]=u}null!==t&&null===r&&t.is(c)&&(r=u),null!==n&&null===l&&n.is(c)&&(l=u)}}return[o,r,l]}function ke(e){let n;if(e instanceof ee)n=e;else if("__type"in e){const o=t(e,oe);oe(o)||se(148),n=o}else{const o=t(e.getNode(),oe);oe(o)||se(148),n=o}const o=n.getParent();he(o)||se(149);const r=o.getParent();return ft(r)||se(210),[n,o,r]}function Ae(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 Be{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!!He(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 Be(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(oe).forEach((e=>{const n=e.getFirstChild();m(n)&&(t|=n.getTextFormat())}));const n=w[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();i(t)||se(151);C(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=S(this.anchor.key);oe(e)||se(152);const t=Ae(e);null===t&&se(153);const n=S(this.focus.key);oe(n)||se(154);const o=Ae(n);null===o&&se(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex+t.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex+t.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,oe),l=t(o,oe);oe(r)||se(152),oe(l)||se(154);const s=r.getParent();he(s)||se(156);const i=s.getParent();ft(i)||se(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&se(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&se(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,u,h]=Fe(i,r,l);let d=Math.min(u.startColumn,h.startColumn),g=Math.min(u.startRow,h.startRow),f=Math.max(u.startColumn+u.cell.__colSpan-1,h.startColumn+h.cell.__colSpan-1),p=Math.max(u.startRow+u.cell.__rowSpan-1,h.startRow+h.cell.__rowSpan-1),m=d,C=g,S=d,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;d=Math.min(d,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),p=Math.max(p,o+t.__rowSpan-1)}for(;d<m||g<C||f>S||p>w;){if(d<m){const e=w-C,t=m-1;for(let n=0;n<=e;n++)b(a[C+n][t]);m=t}if(g<C){const e=S-m,t=C-1;for(let n=0;n<=e;n++)b(a[t][m+n]);C=t}if(f>S){const e=w-C,t=S+1;for(let n=0;n<=e;n++)b(a[C+n][t]);S=t}if(p>w){const e=S-m,t=w+1;for(let n=0;n<=e;n++)b(a[t][m+n]);w=t}}const y=new Map([[i.getKey(),i]]);let N=null;for(let e=g;e<=p;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();he(o)||se(160),o!==N&&y.set(o.getKey(),o),y.set(n.getKey(),n);for(const e of De(n))y.set(e.getKey(),e);N=o}const x=Array.from(y.values());return _()||(this._cachedNodes=x),x}getTextContent(){const e=this.getNodes().filter((e=>oe(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 He(e){return e instanceof Be}function Pe(){const e=p("root",0,"element"),t=p("root",0,"element");return new Be("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&se(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class We{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,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal}}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}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=Xe(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Xe(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(!ft(S(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=Xe(t);$e(e,n,null),b(null),e.dispatchCommand(y,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(),$e(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=S(this.tableNodeKey);if(!ft(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=Ie(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=N(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&oe(t)&&o.is(ot(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Pe(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),b(this.tableSelection),n.dispatchCommand(y,void 0),$e(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=N(e.elem);if(oe(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Pe(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();He(t)||se(11);const n=x(),o=n.anchor,r=n.focus,l=t.getNodes().filter(oe),s=l[0].getFirstChild(),i=m(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)})),b(t),this.editor.dispatchCommand(y,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=S(this.tableNodeKey);if(!ft(t))throw new Error("Expected TableNode.");const n=g();He(n)||se(11);const o=n.getNodes().filter(oe);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),$e(e,this.table,null),b(null),e.dispatchCommand(y,void 0);else{t.selectPrevious(),t.remove();T().selectStart()}}))}}const Le="__lexicalTableSelection",Ie=e=>ie?(e||window).getSelection():null;function Ue(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const u=new We(r,e.getKey()),h=r._window||window;!function(e,t){null!==ze(e)&&se(205);e[Le]=t}(n,u),u.listenersToRemove.add((()=>function(e,t){ze(e)===t&&delete e[Le]}(n,u)));const p=()=>{const e=()=>{u.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&u.isSelecting)return u.isSelecting=!1,h.removeEventListener("mouseup",e),void h.removeEventListener("mousemove",t);const o=Ye(n.target);null===o||u.anchorX===o.x&&u.anchorY===o.y||(n.preventDefault(),u.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=Ye(e.target);null!==t&&(lt(e),u.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=p();u.isSelecting=!0,h.addEventListener("mouseup",n,u.listenerOptions),h.addEventListener("mousemove",o,u.listenerOptions)}),0)}),u.listenerOptions);h.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;He(t)&&t.tableKey===u.tableNodeKey&&c.contains(n)&&u.clearHighlight()}))}),u.listenerOptions),u.listenersToRemove.add(r.registerCommand(v,(t=>rt(r,t,"down",e,u)),O)),u.listenersToRemove.add(r.registerCommand(E,(t=>rt(r,t,"up",e,u)),O)),u.listenersToRemove.add(r.registerCommand(R,(t=>rt(r,t,"backward",e,u)),O)),u.listenersToRemove.add(r.registerCommand(M,(t=>rt(r,t,"forward",e,u)),O)),u.listenersToRemove.add(r.registerCommand(F,(e=>{const n=g();if(He(n)){const o=t(n.focus.getNode(),oe);if(oe(o))return lt(e),o.selectEnd(),!0}return!1}),O));[K,k,A].forEach((n=>{u.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!Qe(o,e))return!1;if(He(o))return u.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return u.clearText(),!0;const h=t(o.anchor.getNode(),(e=>i(e))),d=h&&t(h,(e=>i(e)&&oe(e.getParent())));if(!i(d)||!i(h))return!1;if(n===k&&null===d.getPreviousSibling())return!0}return!1})(n),B))}));const m=t=>{const n=g();if(!He(n)&&!f(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!He(n)&&(t&&(t.preventDefault(),t.stopPropagation()),u.clearText(),!0)};function C(t){const n=e.getCordsFromCellNode(t,u.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,u.table)}return u.listenersToRemove.add(r.registerCommand(H,m,B)),u.listenersToRemove.add(r.registerCommand(P,m,B)),u.listenersToRemove.add(r.registerCommand(D,(e=>{const t=g();if(t){if(!He(t)&&!f(t))return!1;G(r,o(e,ClipboardEvent)?e:null,Q(t));const n=m(e);return f(t)?(t.removeText(),!0):n}return!1}),B)),u.listenersToRemove.add(r.registerCommand(W,(n=>{const o=g();if(!Qe(o,e))return!1;if(He(o))return u.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(e))return!1}return!1}),B)),u.listenersToRemove.add(r.registerCommand(L,(t=>{const n=g();if(!He(n)||!Qe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!oe(o)||!oe(r))return!1;const[l,s,c]=Fe(e,o,r),a=Math.max(s.startRow,c.startRow),u=Math.max(s.startColumn,c.startColumn),h=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn);for(let e=h;e<=a;e++)for(let n=d;n<=u;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),B)),u.listenersToRemove.add(r.registerCommand(I,(n=>{const o=g();if(!Qe(o,e))return!1;if(He(o))return u.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(l))return!1;if("string"==typeof n){const t=it(r,o,e);if(t)return st(t,e,[d(n)]),!0}}return!1}),B)),l&&u.listenersToRemove.add(r.registerCommand(U,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!Qe(n,e))return!1;const o=nt(n.anchor.getNode());if(null===o)return!1;lt(t);const r=e.getCordsFromCellNode(o,u.table);return qe(u,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),B)),u.listenersToRemove.add(r.registerCommand(z,(t=>e.isSelected()),O)),u.listenersToRemove.add(r.registerCommand(Y,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=He(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>oe(e)))&&null!==t(o.focus.getNode(),(e=>oe(e)))||l;if(1!==n.length||!ft(n[0])||!i||null===r)return!1;const[c]=r,u=n[0],h=u.getChildren(),d=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),p=t(c.getNode(),(e=>oe(e))),m=p&&t(p,(e=>he(e))),C=m&&t(m,(e=>ft(e)));if(!oe(p)||!he(m)||!ft(C))return!1;const S=m.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),w=p.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(S,_),x=Math.max(w,b),T=Math.max(S,_),v=C.getChildren();let O=0;for(let e=N;e<=T;e++){const t=v[e];if(!he(t))return!1;const n=h[O];if(!he(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(!oe(t))return!1;const n=r[l];if(!oe(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}O++}return!0}),B)),u.listenersToRemove.add(r.registerCommand(y,(()=>{const t=g(),n=X();if(f(t)){const{anchor:n,focus:o}=t,l=n.getNode(),s=o.getNode(),i=nt(l),c=nt(s),a=!(!i||!e.is(ot(i))),d=!(!c||!e.is(ot(c))),g=a!==d,f=a&&d,m=t.isBackward();if(g){const n=t.clone();if(d){const[t]=Fe(e,c,c),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(a){const[t]=Fe(e,i,i),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")}b(n),je(r,u)}else f&&(i.is(c)||(u.setAnchorCellForSelection(C(i)),u.setFocusCellForSelection(C(c),!0),u.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=p();u.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&He(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ie(r._window);if(n&&n.anchorNode&&n.focusNode){const o=N(n.focusNode),l=o&&!e.is(ot(o)),s=N(n.anchorNode),i=s&&e.is(ot(s));if(l&&i&&n.rangeCount>0){const o=$(n,r);o&&(o.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),b(o))}}}return t&&!t.is(n)&&(He(t)||He(n))&&u.tableSelection&&!u.tableSelection.is(n)?(He(t)&&t.tableKey===u.tableNodeKey?u.updateTableTableSelection(t):!He(t)&&He(n)&&n.tableKey===u.tableNodeKey&&u.updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Je(t.table,(t=>{const n=t.elem;t.highlighted=!1,tt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,u):!u.hasHijackedSelectionStyles&&e.isSelected()&&je(r,u),!1)}),B)),u.listenersToRemove.add(r.registerCommand(J,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!Qe(t,e))return!1;const n=it(r,t,e);return!!n&&(st(n,e),!0)}),B)),u}function ze(e){return e[Le]||null}function Ye(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 Xe(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.querySelector("tr"),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 $e(e,t,n){const o=new Set(n?n.getNodes():[]);Je(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,et(e,t)):(t.highlighted=!1,tt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Je(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=N(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function je(e,t){t.disableHighlightStyle(),Je(t.table,(t=>{t.highlighted=!0,et(e,t)}))}const qe=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ve(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ve(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?Ve(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ve(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ge=(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(f(e)||He(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Ve(e,t){t?e.selectStart():e.selectEnd()}const Ze="172,206,247";function et(e,t){const n=t.elem,o=N(n);oe(o)||se(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Ze})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Ze},0.85), rgba(${Ze},0.85))`),n.style.setProperty("caret-color","transparent")}function tt(e,t){const n=t.elem,o=N(n);oe(o)||se(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function nt(e){const n=t(e,oe);return oe(n)?n:null}function ot(e){const n=t(e,ft);return ft(n)?n:null}function rt(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=g();if(!Qe(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!ft(c))&&(lt(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=t(e,(e=>ft(e)));if(oe(l)&&(l=t(l,ft)),l!==r)return!1;if(!l)return!1;const c="down"===o?l.getNextSibling():l.getPreviousSibling();if(!c)return!1;let u=0;"up"===o&&i(c)&&(u=c.getChildrenSize());let h=c;if("up"===o&&i(c)){const e=c.getLastChild();h=e||c,u=a(h)?h.getTextContentSize():0}const d=s.clone();return d.focus.set(h.getKey(),u,a(h)?"text":"element"),b(d),lt(n),!0}if(j(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){const n=t(e,oe);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}{let r=t(e,(e=>i(e)&&!e.isInline()));if(oe(r)&&(r=t(r,ft)),!r)return!1;const c="down"===o?r.getNextSibling():r.getPreviousSibling();if(ft(c)&&l.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),t=c.getLastDescendant();if(!e||!t)return!1;const[r]=ke(e),[l]=ke(t),i=s.clone();return i.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),lt(n),b(i),!0}}}}return!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,u=t(c.getNode(),oe),h=t(a.getNode(),oe);if(!oe(u)||!u.is(h))return!1;const d=ot(u);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=Xe(t),rt(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const u=s.getNodes();return(1!==u.length||!q(u[0]))&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,oe);if(!oe(l))return!1;const[s,c]=Fe(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&ft(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||ft(a))return!1;lt(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(u.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let p;if("element"===c.type)p=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const m="up"===o?u.getFirstChild():u.getLastChild();if(null==m)return!1;const C=e.getElementByKey(m.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>p.top-p.height:p.bottom+p.height>S.bottom){lt(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return qe(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(He(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),oe),u=t(c.getNode(),oe),[h]=s.getNodes(),d=e.getElementByKey(h.getKey());if(!oe(a)||!oe(u)||!ft(h)||null==d)return!1;l.updateTableTableSelection(s);const g=Xe(d),f=r.getCordsFromCellNode(a,g),p=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(p),lt(n),n.shiftKey){const e=r.getCordsFromCellNode(u,g);return Ge(l,h,e.x,e.y,o)}return u.selectEnd(),!0}return!1}function lt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function st(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function it(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=>oe(e)));if(!i)return;const c=t(i,(e=>ft(e)));if(!ft(c)||!c.is(o))return;const[a,u]=Fe(o,i,i),h=a[0][0],d=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=u,p=g===h.startRow&&f===h.startColumn,m=g===d.startRow&&f===d.startColumn;return p?"first":m?"last":void 0}function ct(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 at(t,o,r){r?(e(t,o.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(n(t,o.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}class ut extends l{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new ut(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:dt,priority:1})}}static importJSON(e){const t=gt();return t.__rowStriping=e.rowStriping||!1,t.__colWidths=e.colWidths,t}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");return o.appendChild(r),ct(o,0,this.getColumnCount(),this.getColWidths()),e(o,t.theme.table),this.__rowStriping&&at(o,t,!0),o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&at(t,n,this.__rowStriping),ct(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),o=document.createElement("tbody");if(r(e)){const t=e.querySelectorAll("col");n.append(...t);const r=e.querySelectorAll("tr");o.append(...r)}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 N(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=N(o.elem);return oe(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){this.getWritable().__rowStriping=e}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{oe(e)&&(t+=e.getColSpan())})),t}}function ht(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Xe(n)}function dt(e){const t=gt();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!V.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{node:t}}function gt(){return u(new ut)}function ft(e){return e instanceof ut}export{Fe as $computeTableMap,Ke as $computeTableMapSkipCellCheck,ne as $createTableCellNode,gt as $createTableNode,de as $createTableNodeWithDimensions,ue as $createTableRowNode,Pe as $createTableSelection,Te as $deleteTableColumn,Oe as $deleteTableColumn__EXPERIMENTAL,ve as $deleteTableRow__EXPERIMENTAL,nt as $findCellNode,ot as $findTableNode,ht as $getElementForTableNode,ke as $getNodeTriplet,ge as $getTableCellNodeFromLexicalNode,Ae as $getTableCellNodeRect,Ce as $getTableColumnIndexFromTableCellNode,pe as $getTableNodeFromLexicalNodeOrThrow,me as $getTableRowIndexFromTableCellNode,fe as $getTableRowNodeFromTableCellNodeOrThrow,Ne as $insertTableColumn,xe as $insertTableColumn__EXPERIMENTAL,we as $insertTableRow,ye as $insertTableRow__EXPERIMENTAL,oe as $isTableCellNode,ft as $isTableNode,he as $isTableRowNode,He as $isTableSelection,_e as $removeTableRowAtIndex,Me as $unmergeCell,re as INSERT_TABLE_COMMAND,Z as TableCellHeaderStates,ee as TableCellNode,ut as TableNode,We as TableObserver,ce as TableRowNode,Ue as applyTableHandlers,Ye as getDOMCellFromTarget,ze as getTableObserverFromTableElement};
|
9
|
+
import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as u,createCommand as h,$createTextNode as d,$getSelection as g,$isRangeSelection as f,$createPoint as p,$isParagraphNode as m,$normalizeSelection__EXPERIMENTAL as C,$getNodeByKey as S,isCurrentlyReadOnlyMode as _,TEXT_TYPE_TO_FORMAT as w,$setSelection as b,SELECTION_CHANGE_COMMAND as y,$getNearestNodeFromDOMNode as N,$createRangeSelection as x,$getRoot as T,KEY_ARROW_DOWN_COMMAND as v,COMMAND_PRIORITY_HIGH as O,KEY_ARROW_UP_COMMAND as E,KEY_ARROW_LEFT_COMMAND as R,KEY_ARROW_RIGHT_COMMAND as M,KEY_ESCAPE_COMMAND as F,DELETE_WORD_COMMAND as K,DELETE_LINE_COMMAND as k,DELETE_CHARACTER_COMMAND as A,COMMAND_PRIORITY_CRITICAL as B,KEY_BACKSPACE_COMMAND as H,KEY_DELETE_COMMAND as P,CUT_COMMAND as D,FORMAT_TEXT_COMMAND as W,FORMAT_ELEMENT_COMMAND as L,CONTROLLED_TEXT_INSERTION_COMMAND as I,KEY_TAB_COMMAND as U,FOCUS_COMMAND as z,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Y,$getPreviousSelection as X,$createRangeSelectionFromDom as $,INSERT_PARAGRAPH_COMMAND as J,$isRootOrShadowRoot as j,$isDecoratorNode as q}from"lexical";import{copyToClipboard as G,$getClipboardDataFromSelection as Q}from"@lexical/clipboard";const V=/^(\d+(?:\.\d+)?)px$/,Z={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ee extends l{static getType(){return"tablecell"}static clone(e){return new ee(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor}static importDOM(){return{td:e=>({conversion:te,priority:0}),th:e=>({conversion:te,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return ne(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=Z.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Z.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Z.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 te(e){const t=e,n=e.nodeName.toLowerCase();let o;V.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ne("th"===n?Z.ROW:Z.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const u=t.style,h=(u&&u.textDecoration||"").split(" "),d="700"===u.fontWeight||"bold"===u.fontWeight,g=h.includes("line-through"),f="italic"===u.fontStyle,p=h.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(oe(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function ne(e,t=1,n){return u(new ee(e,t,n))}function oe(e){return e instanceof ee}const re=h("INSERT_TABLE_COMMAND");function le(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var se=le((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 ie="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;class ce extends l{static getType(){return"tablerow"}static clone(e){return new ce(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ae,priority:0})}}static importJSON(e){return ue(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 ae(e){const t=e;let n;return V.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:ue(n)}}function ue(e){return u(new ce(e))}function he(e){return e instanceof ce}function de(e,t,n=!0){const o=gt();for(let r=0;r<e;r++){const e=ue();for(let o=0;o<t;o++){let t=Z.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Z.ROW),0===o&&n.columns&&(t|=Z.COLUMN)):n&&(0===r&&(t|=Z.ROW),0===o&&(t|=Z.COLUMN));const l=ne(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function ge(e){const n=t(e,(e=>oe(e)));return oe(n)?n:null}function fe(e){const n=t(e,(e=>he(e)));if(he(n))return n;throw new Error("Expected table cell to be inside of table row.")}function pe(e){const n=t(e,(e=>ft(e)));if(ft(n))return n;throw new Error("Expected table cell to be inside of table.")}function me(e){const t=fe(e);return pe(t).getChildren().findIndex((e=>e.is(t)))}function Ce(e){return fe(e).getChildren().findIndex((t=>t.is(e)))}function Se(e,t){const n=pe(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 _e(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 we(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(!he(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=ue();for(let n=0;n<t;n++){const t=e[n];oe(t)||se(12);const{above:l,below:i}=Se(t,r);let c=Z.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Z.COLUMN)||i&&i.hasHeaderState(Z.COLUMN))&&(c|=Z.COLUMN);const u=ne(c,1,a);u.append(s()),o.append(u)}n?i.insertAfter(o):i.insertBefore(o)}return e}const be=(e,t)=>e===Z.BOTH||e===t?t:Z.NO_STATUS;function ye(e=!0){const t=g();f(t)||He(t)||se(188);const n=t.focus.getNode(),[o,,r]=ke(n),[l,i]=Fe(r,o,o),c=l[0].length,{startRow:a}=i;let u=null;if(e){const e=a+o.__rowSpan-1,t=l[e],n=ue();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=be(e,Z.COLUMN);n.append(ne(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);he(i)||se(145),i.insertAfter(n),u=n}else{const e=l[a],t=ue();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=be(o,Z.COLUMN);t.append(ne(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);he(n)||se(145),n.insertBefore(t),u=t}return u}function Ne(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(he(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];oe(o)||se(12);const{left:l,right:c}=Se(o,r);let a=Z.NO_STATUS;(l&&l.hasHeaderState(Z.ROW)||c&&c.hasHeaderState(Z.ROW))&&(a|=Z.ROW);const u=ne(a);u.append(s()),i.push({newTableCell:u,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function xe(e=!0){const t=g();f(t)||He(t)||se(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=ke(n),[l,,i]=ke(o),[c,a,u]=Fe(i,l,r),h=c.length,d=e?Math.max(a.startColumn,u.startColumn):Math.min(a.startColumn,u.startColumn),p=e?d+l.__colSpan-1:d-1,m=i.getFirstChild();he(m)||se(120);let C=null;function S(e=Z.NO_STATUS){const t=ne(e).append(s());return null===C&&(C=t),t}let _=m;e:for(let e=0;e<h;e++){if(0!==e){const e=_.getNextSibling();he(e)||se(121),_=e}const t=c[e],n=t[p<0?0:p].cell.__headerState,o=be(n,Z.ROW);if(p<0){Re(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[p];if(l+r.__colSpan-1<=p){let n=r,l=s,i=p;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(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&&Ee(C);const w=i.getColWidths();if(w){const e=[...w],t=p<0?0:p,n=e[t];e.splice(t,0,n),i.setColWidths(e)}return C}function Te(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(he(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 ve(){const e=g();f(e)||He(e)||se(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=ke(t),[l]=ke(n),[s,i,c]=Fe(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,p=s[h+1],m=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>h))if(n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&se(122),0===t)Re(m,n);else{const{cell:e}=p[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);he(t)||se(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];Ee(e)}else{const e=s[a-1],{cell:t}=e[0];Ee(t)}}function Oe(){const e=g();f(e)||He(e)||se(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ke(t),[l]=ke(n),[s,i,c]=Fe(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),p=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),m=p-d+1;if(s[0].length===p-d+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=d;t<=p;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(m,n.__colSpan-e))}}else if(o+n.__colSpan-1>p){if(t===p){const e=p-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[u],_=a>h?S[a+o.__colSpan]:S[h+l.__colSpan];if(void 0!==_){const{cell:e}=_;Ee(e)}else{const e=h<a?S[h-1]:S[a-1],{cell:t}=e;Ee(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,m),r.setColWidths(e)}}function Ee(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Re(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Me(){const e=g();f(e)||He(e)||se(188);const t=e.anchor.getNode(),[n,o,r]=ke(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Fe(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&Z.COLUMN,p=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<c.length;e++)n&=c[e][t+u].cell.__headerState;return n})),m=n.__headerState&Z.ROW,C=Array.from({length:i},((e,t)=>{let n=m;for(let e=0;0!==n&&e<c[0].length;e++)n&=c[t+h][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(ne(p[e]|C[0]).append(s()));n.setColSpan(1)}if(i>1){let e;for(let t=1;t<i;t++){const n=h+t,r=c[n];e=(e||o).getNextSibling(),he(e)||se(125);let i=null;for(let e=0;e<u;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===i)for(let n=l-1;n>=0;n--)Re(e,ne(p[n]|C[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(ne(p[e]|C[t]).append(s()))}n.setRowSpan(1)}}function Fe(e,t,n){const[o,r,l]=Ke(e,t,n);return null===r&&se(207),null===l&&se(208),[o,r,l]}function Ke(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];he(o)||se(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){oe(c)||se(147);const o=s(e);for(;void 0!==o[a];)a++;const u={cell:c,startColumn:a,startRow:e},{__rowSpan:h,__colSpan:d}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[a+e]=u}null!==t&&null===r&&t.is(c)&&(r=u),null!==n&&null===l&&n.is(c)&&(l=u)}}return[o,r,l]}function ke(e){let n;if(e instanceof ee)n=e;else if("__type"in e){const o=t(e,oe);oe(o)||se(148),n=o}else{const o=t(e.getNode(),oe);oe(o)||se(148),n=o}const o=n.getParent();he(o)||se(149);const r=o.getParent();return ft(r)||se(210),[n,o,r]}function Ae(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 Be{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!!He(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 Be(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(oe).forEach((e=>{const n=e.getFirstChild();m(n)&&(t|=n.getTextFormat())}));const n=w[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();i(t)||se(151);C(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=S(this.anchor.key);oe(e)||se(152);const t=Ae(e);null===t&&se(153);const n=S(this.focus.key);oe(n)||se(154);const o=Ae(n);null===o&&se(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex+t.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex+t.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,oe),l=t(o,oe);oe(r)||se(152),oe(l)||se(154);const s=r.getParent();he(s)||se(156);const i=s.getParent();ft(i)||se(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&se(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&se(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,u,h]=Fe(i,r,l);let d=Math.min(u.startColumn,h.startColumn),g=Math.min(u.startRow,h.startRow),f=Math.max(u.startColumn+u.cell.__colSpan-1,h.startColumn+h.cell.__colSpan-1),p=Math.max(u.startRow+u.cell.__rowSpan-1,h.startRow+h.cell.__rowSpan-1),m=d,C=g,S=d,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;d=Math.min(d,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),p=Math.max(p,o+t.__rowSpan-1)}for(;d<m||g<C||f>S||p>w;){if(d<m){const e=w-C,t=m-1;for(let n=0;n<=e;n++)b(a[C+n][t]);m=t}if(g<C){const e=S-m,t=C-1;for(let n=0;n<=e;n++)b(a[t][m+n]);C=t}if(f>S){const e=w-C,t=S+1;for(let n=0;n<=e;n++)b(a[C+n][t]);S=t}if(p>w){const e=S-m,t=w+1;for(let n=0;n<=e;n++)b(a[t][m+n]);w=t}}const y=new Map([[i.getKey(),i]]);let N=null;for(let e=g;e<=p;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();he(o)||se(160),o!==N&&y.set(o.getKey(),o),y.set(n.getKey(),n);for(const e of De(n))y.set(e.getKey(),e);N=o}const x=Array.from(y.values());return _()||(this._cachedNodes=x),x}getTextContent(){const e=this.getNodes().filter((e=>oe(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 He(e){return e instanceof Be}function Pe(){const e=p("root",0,"element"),t=p("root",0,"element");return new Be("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&se(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class We{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,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal}}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}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=Xe(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Xe(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(!ft(S(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=Xe(t);$e(e,n,null),b(null),e.dispatchCommand(y,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(),$e(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=S(this.tableNodeKey);if(!ft(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=Ie(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=N(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&oe(t)&&o.is(ot(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Pe(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),b(this.tableSelection),n.dispatchCommand(y,void 0),$e(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=N(e.elem);if(oe(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Pe(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();He(t)||se(11);const n=x(),o=n.anchor,r=n.focus,l=t.getNodes().filter(oe),s=l[0].getFirstChild(),i=m(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)})),b(t),this.editor.dispatchCommand(y,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=S(this.tableNodeKey);if(!ft(t))throw new Error("Expected TableNode.");const n=g();He(n)||se(11);const o=n.getNodes().filter(oe);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),$e(e,this.table,null),b(null),e.dispatchCommand(y,void 0);else{t.selectPrevious(),t.remove();T().selectStart()}}))}}const Le="__lexicalTableSelection",Ie=e=>ie?(e||window).getSelection():null;function Ue(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const u=new We(r,e.getKey()),h=r._window||window;!function(e,t){null!==ze(e)&&se(205);e[Le]=t}(n,u),u.listenersToRemove.add((()=>function(e,t){ze(e)===t&&delete e[Le]}(n,u)));const p=()=>{const e=()=>{u.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&u.isSelecting)return u.isSelecting=!1,h.removeEventListener("mouseup",e),void h.removeEventListener("mousemove",t);const o=Ye(n.target);null===o||u.anchorX===o.x&&u.anchorY===o.y||(n.preventDefault(),u.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=Ye(e.target);null!==t&&(lt(e),u.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=p();u.isSelecting=!0,h.addEventListener("mouseup",n,u.listenerOptions),h.addEventListener("mousemove",o,u.listenerOptions)}),0)}),u.listenerOptions);h.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;He(t)&&t.tableKey===u.tableNodeKey&&c.contains(n)&&u.clearHighlight()}))}),u.listenerOptions),u.listenersToRemove.add(r.registerCommand(v,(t=>rt(r,t,"down",e,u)),O)),u.listenersToRemove.add(r.registerCommand(E,(t=>rt(r,t,"up",e,u)),O)),u.listenersToRemove.add(r.registerCommand(R,(t=>rt(r,t,"backward",e,u)),O)),u.listenersToRemove.add(r.registerCommand(M,(t=>rt(r,t,"forward",e,u)),O)),u.listenersToRemove.add(r.registerCommand(F,(e=>{const n=g();if(He(n)){const o=t(n.focus.getNode(),oe);if(oe(o))return lt(e),o.selectEnd(),!0}return!1}),O));[K,k,A].forEach((n=>{u.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!Qe(o,e))return!1;if(He(o))return u.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return u.clearText(),!0;const h=t(o.anchor.getNode(),(e=>i(e))),d=h&&t(h,(e=>i(e)&&oe(e.getParent())));if(!i(d)||!i(h))return!1;if(n===k&&null===d.getPreviousSibling())return!0}return!1})(n),B))}));const m=t=>{const n=g();if(!He(n)&&!f(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!He(n)&&(t&&(t.preventDefault(),t.stopPropagation()),u.clearText(),!0)};function C(t){const n=e.getCordsFromCellNode(t,u.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,u.table)}return u.listenersToRemove.add(r.registerCommand(H,m,B)),u.listenersToRemove.add(r.registerCommand(P,m,B)),u.listenersToRemove.add(r.registerCommand(D,(e=>{const t=g();if(t){if(!He(t)&&!f(t))return!1;G(r,o(e,ClipboardEvent)?e:null,Q(t));const n=m(e);return f(t)?(t.removeText(),!0):n}return!1}),B)),u.listenersToRemove.add(r.registerCommand(W,(n=>{const o=g();if(!Qe(o,e))return!1;if(He(o))return u.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(e))return!1}return!1}),B)),u.listenersToRemove.add(r.registerCommand(L,(t=>{const n=g();if(!He(n)||!Qe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!oe(o)||!oe(r))return!1;const[l,s,c]=Fe(e,o,r),a=Math.max(s.startRow,c.startRow),u=Math.max(s.startColumn,c.startColumn),h=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn);for(let e=h;e<=a;e++)for(let n=d;n<=u;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),B)),u.listenersToRemove.add(r.registerCommand(I,(n=>{const o=g();if(!Qe(o,e))return!1;if(He(o))return u.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(l))return!1;if("string"==typeof n){const t=it(r,o,e);if(t)return st(t,e,[d(n)]),!0}}return!1}),B)),l&&u.listenersToRemove.add(r.registerCommand(U,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!Qe(n,e))return!1;const o=nt(n.anchor.getNode());if(null===o)return!1;lt(t);const r=e.getCordsFromCellNode(o,u.table);return qe(u,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),B)),u.listenersToRemove.add(r.registerCommand(z,(t=>e.isSelected()),O)),u.listenersToRemove.add(r.registerCommand(Y,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=He(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>oe(e)))&&null!==t(o.focus.getNode(),(e=>oe(e)))||l;if(1!==n.length||!ft(n[0])||!i||null===r)return!1;const[c]=r,u=n[0],h=u.getChildren(),d=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),p=t(c.getNode(),(e=>oe(e))),m=p&&t(p,(e=>he(e))),C=m&&t(m,(e=>ft(e)));if(!oe(p)||!he(m)||!ft(C))return!1;const S=m.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),w=p.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(S,_),x=Math.max(w,b),T=Math.max(S,_),v=C.getChildren();let O=0;for(let e=N;e<=T;e++){const t=v[e];if(!he(t))return!1;const n=h[O];if(!he(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(!oe(t))return!1;const n=r[l];if(!oe(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}O++}return!0}),B)),u.listenersToRemove.add(r.registerCommand(y,(()=>{const t=g(),n=X();if(f(t)){const{anchor:n,focus:o}=t,l=n.getNode(),s=o.getNode(),i=nt(l),c=nt(s),a=!(!i||!e.is(ot(i))),d=!(!c||!e.is(ot(c))),g=a!==d,f=a&&d,m=t.isBackward();if(g){const n=t.clone();if(d){const[t]=Fe(e,c,c),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(a){const[t]=Fe(e,i,i),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")}b(n),je(r,u)}else f&&(i.is(c)||(u.setAnchorCellForSelection(C(i)),u.setFocusCellForSelection(C(c),!0),u.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=p();u.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&He(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ie(r._window);if(n&&n.anchorNode&&n.focusNode){const o=N(n.focusNode),l=o&&!e.is(ot(o)),s=N(n.anchorNode),i=s&&e.is(ot(s));if(l&&i&&n.rangeCount>0){const o=$(n,r);o&&(o.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),b(o))}}}return t&&!t.is(n)&&(He(t)||He(n))&&u.tableSelection&&!u.tableSelection.is(n)?(He(t)&&t.tableKey===u.tableNodeKey?u.updateTableTableSelection(t):!He(t)&&He(n)&&n.tableKey===u.tableNodeKey&&u.updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Je(t.table,(t=>{const n=t.elem;t.highlighted=!1,tt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,u):!u.hasHijackedSelectionStyles&&e.isSelected()&&je(r,u),!1)}),B)),u.listenersToRemove.add(r.registerCommand(J,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!Qe(t,e))return!1;const n=it(r,t,e);return!!n&&(st(n,e),!0)}),B)),u}function ze(e){return e[Le]||null}function Ye(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 Xe(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.querySelector("tr"),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 $e(e,t,n){const o=new Set(n?n.getNodes():[]);Je(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,et(e,t)):(t.highlighted=!1,tt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Je(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=N(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function je(e,t){t.disableHighlightStyle(),Je(t.table,(t=>{t.highlighted=!0,et(e,t)}))}const qe=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ve(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ve(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?Ve(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ve(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ge=(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(f(e)||He(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Ve(e,t){t?e.selectStart():e.selectEnd()}const Ze="172,206,247";function et(e,t){const n=t.elem,o=N(n);oe(o)||se(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Ze})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Ze},0.85), rgba(${Ze},0.85))`),n.style.setProperty("caret-color","transparent")}function tt(e,t){const n=t.elem,o=N(n);oe(o)||se(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function nt(e){const n=t(e,oe);return oe(n)?n:null}function ot(e){const n=t(e,ft);return ft(n)?n:null}function rt(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=g();if(!Qe(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!ft(c))&&(lt(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=t(e,(e=>ft(e)));if(oe(l)&&(l=t(l,ft)),l!==r)return!1;if(!l)return!1;const c="down"===o?l.getNextSibling():l.getPreviousSibling();if(!c)return!1;let u=0;"up"===o&&i(c)&&(u=c.getChildrenSize());let h=c;if("up"===o&&i(c)){const e=c.getLastChild();h=e||c,u=a(h)?h.getTextContentSize():0}const d=s.clone();return d.focus.set(h.getKey(),u,a(h)?"text":"element"),b(d),lt(n),!0}if(j(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){const n=t(e,oe);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}{let r=t(e,(e=>i(e)&&!e.isInline()));if(oe(r)&&(r=t(r,ft)),!r)return!1;const c="down"===o?r.getNextSibling():r.getPreviousSibling();if(ft(c)&&l.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),t=c.getLastDescendant();if(!e||!t)return!1;const[r]=ke(e),[l]=ke(t),i=s.clone();return i.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),lt(n),b(i),!0}}}}return!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,u=t(c.getNode(),oe),h=t(a.getNode(),oe);if(!oe(u)||!u.is(h))return!1;const d=ot(u);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=Xe(t),rt(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const u=s.getNodes();return(1!==u.length||!q(u[0]))&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,oe);if(!oe(l))return!1;const[s,c]=Fe(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&ft(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||ft(a))return!1;lt(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(u.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let p;if("element"===c.type)p=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const m="up"===o?u.getFirstChild():u.getLastChild();if(null==m)return!1;const C=e.getElementByKey(m.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>p.top-p.height:p.bottom+p.height>S.bottom){lt(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return qe(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(He(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),oe),u=t(c.getNode(),oe),[h]=s.getNodes(),d=e.getElementByKey(h.getKey());if(!oe(a)||!oe(u)||!ft(h)||null==d)return!1;l.updateTableTableSelection(s);const g=Xe(d),f=r.getCordsFromCellNode(a,g),p=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(p),lt(n),n.shiftKey){const e=r.getCordsFromCellNode(u,g);return Ge(l,h,e.x,e.y,o)}return u.selectEnd(),!0}return!1}function lt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function st(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function it(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=>oe(e)));if(!i)return;const c=t(i,(e=>ft(e)));if(!ft(c)||!c.is(o))return;const[a,u]=Fe(o,i,i),h=a[0][0],d=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=u,p=g===h.startRow&&f===h.startColumn,m=g===d.startRow&&f===d.startColumn;return p?"first":m?"last":void 0}function ct(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 at(t,o,r){r?(e(t,o.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(n(t,o.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}class ut extends l{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new ut(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:dt,priority:1})}}static importJSON(e){const t=gt();return t.__rowStriping=e.rowStriping||!1,t.__colWidths=e.colWidths,t}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");return o.appendChild(r),ct(o,0,this.getColumnCount(),this.getColWidths()),e(o,t.theme.table),this.__rowStriping&&at(o,t,!0),o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&at(t,n,this.__rowStriping),ct(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),o=document.createElement("tbody");if(r(e)){const t=e.querySelectorAll("col");n.append(...t);const r=e.querySelectorAll("tr");o.append(...r)}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 N(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=N(o.elem);return oe(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){this.getWritable().__rowStriping=e}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{oe(e)&&(t+=e.getColSpan())})),t}}function ht(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Xe(n)}function dt(e){const t=gt();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!V.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{node:t}}function gt(){return u(new ut)}function ft(e){return e instanceof ut}export{Fe as $computeTableMap,Ke as $computeTableMapSkipCellCheck,ne as $createTableCellNode,gt as $createTableNode,de as $createTableNodeWithDimensions,ue as $createTableRowNode,Pe as $createTableSelection,Te as $deleteTableColumn,Oe as $deleteTableColumn__EXPERIMENTAL,ve as $deleteTableRow__EXPERIMENTAL,nt as $findCellNode,ot as $findTableNode,ht as $getElementForTableNode,ke as $getNodeTriplet,ge as $getTableCellNodeFromLexicalNode,Ae as $getTableCellNodeRect,Ce as $getTableColumnIndexFromTableCellNode,pe as $getTableNodeFromLexicalNodeOrThrow,me as $getTableRowIndexFromTableCellNode,fe as $getTableRowNodeFromTableCellNodeOrThrow,Ne as $insertTableColumn,xe as $insertTableColumn__EXPERIMENTAL,we as $insertTableRow,ye as $insertTableRow__EXPERIMENTAL,oe as $isTableCellNode,ft as $isTableNode,he as $isTableRowNode,He as $isTableSelection,_e as $removeTableRowAtIndex,Me as $unmergeCell,re as INSERT_TABLE_COMMAND,Z as TableCellHeaderStates,ee as TableCellNode,ut as TableNode,We as TableObserver,ce as TableRowNode,Ue as applyTableHandlers,Ye as getDOMCellFromTarget,ze as getTableObserverFromTableElement};
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.18.1-nightly.
|
11
|
+
"version": "0.18.1-nightly.20241022.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/clipboard": "0.18.1-nightly.
|
16
|
-
"@lexical/utils": "0.18.1-nightly.
|
17
|
-
"lexical": "0.18.1-nightly.
|
15
|
+
"@lexical/clipboard": "0.18.1-nightly.20241022.0",
|
16
|
+
"@lexical/utils": "0.18.1-nightly.20241022.0",
|
17
|
+
"lexical": "0.18.1-nightly.20241022.0"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|