@lexical/table 0.16.2-nightly.20240801.0 → 0.17.1-nightly.20240802.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalTable.dev.js +1 -0
- package/LexicalTable.dev.mjs +1 -0
- package/LexicalTable.prod.js +9 -9
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalTable.dev.js
CHANGED
package/LexicalTable.dev.mjs
CHANGED
package/LexicalTable.prod.js
CHANGED
@@ -29,15 +29,15 @@ A);A(d)||I(152);A(c)||I(154);b=d.getParent();G(b)||I(156);b=b.getParent();N(b)||
|
|
29
29
|
g.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=r;d=p;e=r;for(var l=p;r<c||p<d||t>e||k>l;){if(r<c){var n=l-d;--c;for(var q=0;q<=n;q++)a(f[d+q][c])}if(p<d)for(n=e-c,--d,q=0;q<=n;q++)a(f[d][c+q]);if(t>e)for(n=l-d,e+=1,q=0;q<=n;q++)a(f[d+q][e]);if(k>l)for(n=e-c,l+=1,q=0;q<=n;q++)a(f[l][c+q])}b=[b];c=null;for(d=p;d<=k;d++)for(e=r;e<=t;e++)({cell:l}=f[d][e]),n=l.getParent(),G(n)||I(160),n!==c&&b.push(n),b.push(l,...qa(l)),c=n;v.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
|
30
30
|
this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function R(a){return a instanceof pa}function ra(){let a=v.$createPoint("root",0,"element"),b=v.$createPoint("root",0,"element");return new pa("root",a,b)}function qa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&I(112);v.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
|
31
31
|
class sa{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTable();this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTable(){let a=
|
32
|
-
new MutationObserver(b=>{this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TBODY"===e||"THEAD"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=S(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.table=S(b);a.observe(b,{
|
33
|
-
this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=v.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=S(b);ta(a,
|
34
|
-
void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");
|
35
|
-
this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();ta(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=v.$getNodeByKey(this.tableNodeKey);
|
36
|
-
var e=a.x;let f=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=ea?(c._window||window).getSelection():null;g&&g.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&f===this.focusY)return;this.focusX=
|
37
|
-
A(e)&&d.is(T(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||ra(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),v.$setSelection(this.tableSelection),c.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0),ta(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells
|
38
|
-
A(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=v.$getSelection();R(b)||I(11);let c=v.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(f=>{A(f)&&0!==f.getTextContentSize()&&(d.set(f.getKey(),0,"element"),e.set(f.getKey(),f.getChildrenSize(),
|
39
|
-
this.editor;a.update(()=>{let b=v.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");var c=v.$getSelection();R(c)||I(11);c=c.getNodes().filter(A);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),v.$getRoot().selectStart()):(c.forEach(d=>{if(v.$isElementNode(d)){let e=v.$createParagraphNode(),f=v.$createTextNode();
|
40
|
-
void 0))})}}function ua(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
32
|
+
new MutationObserver(b=>{this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TBODY"===e||"THEAD"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=S(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.table=S(b);a.observe(b,{attributes:!0,childList:!0,
|
33
|
+
subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=v.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=S(b);ta(a,
|
34
|
+
b,null);v.$setSelection(null);a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");
|
35
|
+
h.addClassNamesToElement(b,a._config.theme.tableSelection);this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();ta(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=v.$getNodeByKey(this.tableNodeKey);
|
36
|
+
if(!N(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");var e=a.x;let f=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=ea?(c._window||window).getSelection():null;g&&g.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&f===this.focusY)return;this.focusX=
|
37
|
+
e;this.focusY=f;this.isHighlightingCells&&(e=v.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&A(e)&&d.is(T(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||ra(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),v.$setSelection(this.tableSelection),c.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0),ta(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=
|
38
|
+
!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=v.$getNearestNodeFromDOMNode(a.elem);A(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=v.$getSelection();R(b)||I(11);let c=v.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(f=>{A(f)&&0!==f.getTextContentSize()&&(d.set(f.getKey(),0,"element"),e.set(f.getKey(),f.getChildrenSize(),
|
39
|
+
"element"),c.formatText(a))});v.$setSelection(b);this.editor.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=v.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");var c=v.$getSelection();R(c)||I(11);c=c.getNodes().filter(A);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),v.$getRoot().selectStart()):(c.forEach(d=>{if(v.$isElementNode(d)){let e=v.$createParagraphNode(),f=v.$createTextNode();
|
40
|
+
e.append(f);d.append(e);d.getChildren().forEach(g=>{g!==e&&g.remove()})}}),ta(a,this.table,null),v.$setSelection(null),a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0))})}}function ua(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
41
41
|
function S(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.firstChild;let e=a=0;for(b.length=0;null!=d;){var f=d.nodeName;if("TD"===f||"TH"===f){f=d;f={elem:f,hasBackgroundColor:""!==f.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=f;let g=b[e];void 0===g&&(g=b[e]=[]);g[a]=f}else if(f=d.firstChild,null!=f){d=f;continue}f=d.nextSibling;if(null!=f)a++,d=f;else if(f=d.parentNode,null!=f){d=f.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
|
42
42
|
function ta(a,b,c){let d=new Set(c?c.getNodes():[]);va(b,(e,f)=>{let g=e.elem;d.has(f)?(e.highlighted=!0,wa(a,e)):(e.highlighted=!1,xa(a,e),g.getAttribute("style")||g.removeAttribute("style"))})}function va(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let f=d[e];if(!f)continue;let g=v.$getNearestNodeFromDOMNode(f.elem);null!==g&&b(f,g,{x:e,y:c})}}}function ya(a,b){b.disableHighlightStyle();va(b.table,c=>{c.highlighted=!0;wa(a,c)})}
|
43
43
|
function za(a,b){b.enableHighlightStyle();va(b.table,c=>{let d=c.elem;c.highlighted=!1;xa(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
|
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,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 H,FORMAT_ELEMENT_COMMAND as P,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=He(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",He=e=>le?(e||window).getSelection():null;function Pe(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)){if(!t.getParent())return!1;t.remove()}}return!1}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(H,(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(P,(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=He(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,Pe 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 H,FORMAT_ELEMENT_COMMAND as P,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,{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(!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=He(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",He=e=>le?(e||window).getSelection():null;function Pe(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)){if(!t.getParent())return!1;t.remove()}}return!1}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(H,(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(P,(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=He(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,Pe 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.
|
11
|
+
"version": "0.17.1-nightly.20240802.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/utils": "0.
|
16
|
-
"lexical": "0.
|
15
|
+
"@lexical/utils": "0.17.1-nightly.20240802.0",
|
16
|
+
"lexical": "0.17.1-nightly.20240802.0"
|
17
17
|
},
|
18
18
|
"repository": {
|
19
19
|
"type": "git",
|