@lexical/table 0.16.0 → 0.16.1-nightly.20240610.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 +2 -2
- package/LexicalTable.dev.mjs +2 -2
- package/LexicalTable.prod.js +42 -42
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalTable.dev.js
CHANGED
@@ -839,14 +839,14 @@ function $deleteTableColumn__EXPERIMENTAL() {
|
|
839
839
|
}
|
840
840
|
}
|
841
841
|
const focusRowMap = gridMap[focusStartRow];
|
842
|
-
const nextColumn = focusRowMap[focusStartColumn + focusCell.__colSpan];
|
842
|
+
const nextColumn = anchorStartColumn > focusStartColumn ? focusRowMap[anchorStartColumn + anchorCell.__colSpan] : focusRowMap[focusStartColumn + focusCell.__colSpan];
|
843
843
|
if (nextColumn !== undefined) {
|
844
844
|
const {
|
845
845
|
cell
|
846
846
|
} = nextColumn;
|
847
847
|
$moveSelectionToCell(cell);
|
848
848
|
} else {
|
849
|
-
const previousRow = focusRowMap[focusStartColumn - 1];
|
849
|
+
const previousRow = focusStartColumn < anchorStartColumn ? focusRowMap[focusStartColumn - 1] : focusRowMap[anchorStartColumn - 1];
|
850
850
|
const {
|
851
851
|
cell
|
852
852
|
} = previousRow;
|
package/LexicalTable.dev.mjs
CHANGED
@@ -837,14 +837,14 @@ function $deleteTableColumn__EXPERIMENTAL() {
|
|
837
837
|
}
|
838
838
|
}
|
839
839
|
const focusRowMap = gridMap[focusStartRow];
|
840
|
-
const nextColumn = focusRowMap[focusStartColumn + focusCell.__colSpan];
|
840
|
+
const nextColumn = anchorStartColumn > focusStartColumn ? focusRowMap[anchorStartColumn + anchorCell.__colSpan] : focusRowMap[focusStartColumn + focusCell.__colSpan];
|
841
841
|
if (nextColumn !== undefined) {
|
842
842
|
const {
|
843
843
|
cell
|
844
844
|
} = nextColumn;
|
845
845
|
$moveSelectionToCell(cell);
|
846
846
|
} else {
|
847
|
-
const previousRow = focusRowMap[focusStartColumn - 1];
|
847
|
+
const previousRow = focusStartColumn < anchorStartColumn ? focusRowMap[focusStartColumn - 1] : focusRowMap[anchorStartColumn - 1];
|
848
848
|
const {
|
849
849
|
cell
|
850
850
|
} = previousRow;
|
package/LexicalTable.prod.js
CHANGED
@@ -6,27 +6,27 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
'use strict';var h=require("@lexical/utils"),u=require("lexical");let aa=/^(\d+(?:\.\d+)?)px$/,
|
10
|
-
class
|
9
|
+
'use strict';var h=require("@lexical/utils"),u=require("lexical");let aa=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
10
|
+
class y extends u.ElementNode{static getType(){return"tablecell"}static clone(a){let b=new y(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:ba,priority:0}),th:()=>({conversion:ba,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=z(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=x.NO_STATUS,b=1,c,d){super(d);
|
11
11
|
this.__colSpan=b;this.__rowSpan=1;this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);h.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
|
12
12
|
if(a){a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||75}px`;a.style.verticalAlign="top";a.style.textAlign="start";let b=this.getBackgroundColor();null!==b?a.style.backgroundColor=b:this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,
|
13
13
|
rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(a){this.getWritable().__colSpan=a;return this}getRowSpan(){return this.__rowSpan}setRowSpan(a){this.getWritable().__rowSpan=a;return this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=
|
14
|
-
a}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!==
|
15
|
-
function ba(a){var b=a.nodeName.toLowerCase(),c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("th"===b?
|
16
|
-
!u.$isElementNode(m)){q=u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),e&&m.toggleFormat("strikethrough"),g&&m.toggleFormat("italic"),f&&m.toggleFormat("underline"));q.append(m);return q}return m},node:b}}function z(a,b=1,c){return u.$applyNodeReplacement(new
|
14
|
+
a}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||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}}
|
15
|
+
function ba(a){var b=a.nodeName.toLowerCase(),c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("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"),g="italic"===a.fontStyle,f=c.includes("underline");return{after:m=>{0===m.length&&m.push(u.$createParagraphNode());return m},forChild:(m,q)=>{if(A(q)&&
|
16
|
+
!u.$isElementNode(m)){q=u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),e&&m.toggleFormat("strikethrough"),g&&m.toggleFormat("italic"),f&&m.toggleFormat("underline"));q.append(m);return q}return m},node:b}}function z(a,b=1,c){return u.$applyNodeReplacement(new y(a,b,c))}function A(a){return a instanceof y}let ca=u.createCommand("INSERT_TABLE_COMMAND");
|
17
17
|
class C extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:da,priority:0})}}static importJSON(a){return D(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,
|
18
18
|
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 da(a){let b=void 0;aa.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:D(b)}}function D(a){return u.$applyNodeReplacement(new C(a))}function H(a){return a instanceof C}var J;
|
19
19
|
function K(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.");}J=K&&K.__esModule&&Object.prototype.hasOwnProperty.call(K,"default")?K["default"]:K;let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
20
20
|
function ia(a){a=h.$findMatchingParent(a,b=>H(b));if(H(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>N(b));if(N(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:e}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,e-1,b),below:c.getCellNodeFromCords(d,e+1,b),left:c.getCellNodeFromCords(d-1,e,b),right:c.getCellNodeFromCords(d+1,e,b)}}
|
21
|
-
let la=(a,b)=>a===
|
22
|
-
function na(a,b,c){let d=[],e=null,g=null;a=a.getChildren();for(let t=0;t<a.length;t++){var f=a[t];H(f)||J(146);var m=f.getChildren();f=0;for(let k of m){for(A(k)||J(147);void 0!==d[t]&&void 0!==d[t][f];)f++;m=t;var q=f,
|
23
|
-
function Q(a){a instanceof
|
24
|
-
function oa(a){let [b,,c]=Q(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let g=Array(d);for(var f=0;f<d;f++)g[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let q=0;q<f.length;q++){for(;g[e][m];)m++;let
|
21
|
+
let la=(a,b)=>a===x.BOTH||a===b?b:x.NO_STATUS;function O(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function P(a,b,c){let [d,e,g]=na(a,b,c);null===e&&J(110);null===g&&J(111);return[d,e,g]}
|
22
|
+
function na(a,b,c){let d=[],e=null,g=null;a=a.getChildren();for(let t=0;t<a.length;t++){var f=a[t];H(f)||J(146);var m=f.getChildren();f=0;for(let k of m){for(A(k)||J(147);void 0!==d[t]&&void 0!==d[t][f];)f++;m=t;var q=f,p=k;let l={cell:p,startColumn:q,startRow:m},n=p.__rowSpan,r=p.__colSpan;for(let v=0;v<n;v++){void 0===d[m+v]&&(d[m+v]=[]);for(let w=0;w<r;w++)d[m+v][q+w]=l}null!==b&&b.is(p)&&(e=l);null!==c&&c.is(p)&&(g=l);f+=k.__colSpan}}return[d,e,g]}
|
23
|
+
function Q(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,A),A(a)||J(148)):(a=h.$findMatchingParent(a.getNode(),A),A(a)||J(148)));let b=a.getParent();H(b)||J(149);let c=b.getParent();N(c)||J(150);return[a,b,c]}
|
24
|
+
function oa(a){let [b,,c]=Q(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let g=Array(d);for(var f=0;f<d;f++)g[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let q=0;q<f.length;q++){for(;g[e][m];)m++;let p=f[q],t=p.__rowSpan||1,k=p.__colSpan||1;for(let l=0;l<t;l++)for(let n=0;n<k;n++)g[e+l][m+n]=p;if(b===p)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:t};m+=k}}return null}
|
25
25
|
class pa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return R(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
|
26
26
|
this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||J(151);u.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=u.$getNodeByKey(this.anchor.key);A(a)||J(152);a=oa(a);null===a&&J(153);var b=u.$getNodeByKey(this.focus.key);A(b)||J(154);let c=oa(b);null===c&&J(155);b=Math.min(a.columnIndex,
|
27
|
-
c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(v){let {cell:
|
28
|
-
A);A(d)||J(152);A(c)||J(154);b=d.getParent();H(b)||J(156);b=b.getParent();N(b)||J(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&J(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&J(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [g,f,m]=P(b,d,c),q=Math.min(f.startColumn,m.startColumn),
|
29
|
-
f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=
|
27
|
+
c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(v){let {cell:w,startColumn:B,startRow:E}=v;q=Math.min(q,B);p=Math.min(p,E);t=Math.max(t,B+w.__colSpan-1);k=Math.max(k,E+w.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=h.$findMatchingParent(c,A);c=h.$findMatchingParent(b,
|
28
|
+
A);A(d)||J(152);A(c)||J(154);b=d.getParent();H(b)||J(156);b=b.getParent();N(b)||J(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&J(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&J(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [g,f,m]=P(b,d,c),q=Math.min(f.startColumn,m.startColumn),p=Math.min(f.startRow,m.startRow),t=Math.max(f.startColumn+f.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),k=Math.max(f.startRow+
|
29
|
+
f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=p;e=q;for(var l=p;q<c||p<d||t>e||k>l;){if(q<c){var n=l-d;--c;for(var r=0;r<=n;r++)a(g[d+r][c])}if(p<d)for(n=e-c,--d,r=0;r<=n;r++)a(g[d][c+r]);if(t>e)for(n=l-d,e+=1,r=0;r<=n;r++)a(g[d+r][e]);if(k>l)for(n=e-c,l+=1,r=0;r<=n;r++)a(g[l][c+r])}b=[b];c=null;for(d=p;d<=k;d++)for(e=q;e<=t;e++)({cell:l}=g[d][e]),n=l.getParent(),H(n)||J(160),n!==c&&b.push(n),b.push(l,...qa(l)),c=n;u.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=u.$createPoint("root",0,"element"),b=u.$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&&J(112);u.$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
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,{childList:!0,subtree:!0})})}clearHighlight(){let a=
|
@@ -46,49 +46,49 @@ a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.sele
|
|
46
46
|
d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(u.$isRangeSelection(a)||R(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
|
47
47
|
function wa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);A(b)||J(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
|
48
48
|
function xa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);A(b)||J(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Da(a){a=h.$findMatchingParent(a,A);return A(a)?a:null}function T(a){a=h.$findMatchingParent(a,N);return N(a)?a:null}
|
49
|
-
function V(a,b,c,d,e){if(("up"===c||"down"===c)&&Ea(a))return!1;var g=u.$getSelection();if(!U(g,d)){if("backward"===c&&u.$isRangeSelection(g)&&g.isCollapsed()){c=g.anchor.type;d=g.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=g.anchor.getNode();if(!c)return!1;c=h.$findMatchingParent(c,
|
50
|
-
g;var f=h.$findMatchingParent(
|
49
|
+
function V(a,b,c,d,e){if(("up"===c||"down"===c)&&Ea(a))return!1;var g=u.$getSelection();if(!U(g,d)){if("backward"===c&&u.$isRangeSelection(g)&&g.isCollapsed()){c=g.anchor.type;d=g.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=g.anchor.getNode();if(!c)return!1;c=h.$findMatchingParent(c,p=>u.$isElementNode(p)&&!p.isInline());if(!c)return!1;c=c.getPreviousSibling();if(!c||!N(c))return!1;Z(b);c.selectEnd();return!0}return!1}if(u.$isRangeSelection(g)&&g.isCollapsed()){let {anchor:p,focus:t}=
|
50
|
+
g;var f=h.$findMatchingParent(p.getNode(),A),m=h.$findMatchingParent(t.getNode(),A);if(!A(f)||!f.is(m))return!1;m=T(f);if(m!==d&&null!=m){var q=a.getElementByKey(m.getKey());if(null!=q)return e.table=S(q),V(a,b,c,m,e)}if("backward"===c||"forward"===c){e=p.type;a=p.offset;f=p.getNode();if(!f)return!1;g=g.getNodes();return 1===g.length&&u.$isDecoratorNode(g[0])?!1:Fa(e,a,f,c)?Ga(b,f,d,c):!1}g=a.getElementByKey(f.__key);m=a.getElementByKey(p.key);if(null==m||null==g)return!1;if("element"===p.type)g=
|
51
51
|
m.getBoundingClientRect();else{g=window.getSelection();if(null===g||0===g.rangeCount)return!1;g=g.getRangeAt(0).getBoundingClientRect()}m="up"===c?f.getFirstChild():f.getLastChild();if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>g.top-g.height:g.bottom+g.height>a.bottom){Z(b);g=d.getCordsFromCellNode(f,e.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(g.x,g.y,e.table),e.setAnchorCellForSelection(b),e.setFocusCellForSelection(b,
|
52
|
-
!0);else return Aa(e,d,g.x,g.y,c);return!0}}else if(R(g)){let {anchor:
|
52
|
+
!0);else return Aa(e,d,g.x,g.y,c);return!0}}else if(R(g)){let {anchor:p,focus:t}=g;q=h.$findMatchingParent(p.getNode(),A);m=h.$findMatchingParent(t.getNode(),A);[f]=g.getNodes();a=a.getElementByKey(f.getKey());if(!A(q)||!A(m)||!N(f)||null==a)return!1;e.updateTableTableSelection(g);g=S(a);a=d.getCordsFromCellNode(q,g);a=d.getDOMCellFromCordsOrThrow(a.x,a.y,g);e.setAnchorCellForSelection(a);Z(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,g),Ba(e,f,b.x,b.y,c);m.selectEnd();return!0}return!1}
|
53
53
|
function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}function Ea(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function Fa(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||Ha(a,b,c,d)}
|
54
54
|
function Ha(a,b,c,d){let e=h.$findMatchingParent(c,g=>u.$isElementNode(g)&&!g.isInline());if(!e)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===e.getPreviousSibling():null===e.getNextSibling())}
|
55
|
-
function Ga(a,b,c,d){var e=h.$findMatchingParent(b,A);if(!A(e))return!1;let [g,f]=P(c,e,e);e=g[0][0];let m=g[g.length-1][g[0].length-1],{startColumn:q,startRow:
|
55
|
+
function Ga(a,b,c,d){var e=h.$findMatchingParent(b,A);if(!A(e))return!1;let [g,f]=P(c,e,e);e=g[0][0];let m=g[g.length-1][g[0].length-1],{startColumn:q,startRow:p}=f;if("backward"===d?q!==e.startColumn||p!==e.startRow:q!==m.startColumn||p!==m.startRow)return!1;b=Ia(b,d,c);if(!b||N(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
|
56
56
|
function Ia(a,b,c){if(a=h.$findMatchingParent(a,d=>u.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&N(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function Ja(a,b,c){let d=u.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
|
57
57
|
function Ka(a,b,c){var d=c.getParent();if(d&&(a=a.getElementByKey(d.getKey()))&&(d=window.getSelection())&&d.anchorNode===a&&(b=h.$findMatchingParent(b.anchor.getNode(),q=>A(q)))&&(a=h.$findMatchingParent(b,q=>N(q)),N(a)&&a.is(c))){var [e,g]=P(c,b,b);c=e[0][0];b=e[e.length-1][e[0].length-1];var {startRow:f,startColumn:m}=g;if(f===c.startRow&&m===c.startColumn)return"first";if(f===b.startRow&&m===b.startColumn)return"last"}}
|
58
58
|
class La extends u.ElementNode{static getType(){return"table"}static clone(a){return new La(a.__key)}static importDOM(){return{table:()=>({conversion:Ma,priority:1})}}static importJSON(){return Na()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");h.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),d=document.createElement("colgroup"),
|
59
59
|
e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!H(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let g=0;g<b;g++){let f=document.createElement("col");d.append(f)}c.replaceChildren(d,e);return c}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var e=d[b];if(null!=e&&(e=e.findIndex(g=>{if(g)return{elem:g}=g,u.$getNearestNodeFromDOMNode(g)===a}),
|
60
60
|
-1!==e))return{x:e,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getDOMCellFromCordsOrThrow(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=u.$getNearestNodeFromDOMNode(a.elem);return A(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);
|
61
61
|
if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function Ma(){return{node:Na()}}function Na(){return u.$applyNodeReplacement(new La)}function N(a){return a instanceof La}exports.$computeTableMap=P;exports.$computeTableMapSkipCellCheck=na;exports.$createTableCellNode=z;exports.$createTableNode=Na;
|
62
|
-
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Na();for(let g=0;g<a;g++){let f=D();for(let m=0;m<b;m++){var e=
|
62
|
+
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Na();for(let g=0;g<a;g++){let f=D();for(let m=0;m<b;m++){var e=x.NO_STATUS;"object"===typeof c?(0===g&&c.rows&&(e|=x.ROW),0===m&&c.columns&&(e|=x.COLUMN)):c&&(0===g&&(e|=x.ROW),0===m&&(e|=x.COLUMN));e=z(e);let q=u.$createParagraphNode();q.append(u.$createTextNode());e.append(q);f.append(e)}d.append(f)}return d};exports.$createTableRowNode=D;exports.$createTableSelection=ra;
|
63
63
|
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(H(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
|
64
|
-
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[
|
65
|
-
Math.min(
|
66
|
-
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[a]=Q(a);let [e,g,f]=P(d,c,a);({startRow:b}=g);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var q=e[a+1],
|
67
|
-
1>a))if(l.setRowSpan(l.__rowSpan-(a-n+1)),null===
|
64
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[a]=Q(a);let [e,g,f]=P(d,c,a);({startColumn:b}=g);let {startRow:m,startColumn:q}=f;var p=Math.min(b,q);let t=Math.max(b+c.__colSpan-1,q+a.__colSpan-1),k=t-p+1;if(e[0].length===t-p+1)d.selectPrevious(),d.remove();else{var l=e.length;for(let n=0;n<l;n++)for(let r=p;r<=t;r++){let {cell:v,startColumn:w}=e[n][r];w<p?r===p&&v.setColSpan(v.__colSpan-
|
65
|
+
Math.min(k,v.__colSpan-(p-w))):w+v.__colSpan-1>t?r===t&&v.setColSpan(v.__colSpan-(t-w+1)):v.remove()}p=e[m];a=b>q?p[b+c.__colSpan]:p[q+a.__colSpan];void 0!==a?({cell:b}=a,O(b)):({cell:b}=q<b?p[q-1]:p[b-1],O(b))}};
|
66
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[a]=Q(a);let [e,g,f]=P(d,c,a);({startRow:b}=g);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var q=e[a+1],p=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var t=m-1;0<=t;t--){let {cell:l,startRow:n,startColumn:r}=e[k][t];if(r===t&&(k===b&&n<b&&l.setRowSpan(l.__rowSpan-(n-b)),n>=b&&n+l.__rowSpan-
|
67
|
+
1>a))if(l.setRowSpan(l.__rowSpan-(a-n+1)),null===p&&J(122),0===t)ma(p,l);else{let {cell:v}=q[t-1];v.insertAfter(l)}}t=d.getChildAtIndex(k);H(t)||J(123,String(k));t.remove()}void 0!==q?({cell:b}=q[0],O(b)):({cell:b}=e[b-1][0],O(b))}};exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return S(a)};exports.$getNodeTriplet=Q;
|
68
68
|
exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>A(b));return A(a)?a:null};exports.$getTableCellNodeRect=oa;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
|
69
|
-
exports.$insertTableColumn=function(a,b,c=!0,d,e){let g=a.getChildren(),f=[];for(let
|
70
|
-
t.insertAfter(
|
71
|
-
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=
|
72
|
-
H(t)||J(121));let k=f[c],l=la(k[0>a?0:a].cell.__headerState,
|
73
|
-
exports.$insertTableRow=function(a,b,c=!0,d,e){var g=a.getChildren();if(b>=g.length||0>b)throw Error("Table row target index out of range");b=g[b];if(H(b))for(g=0;g<d;g++){let m=b.getChildren(),q=m.length,
|
69
|
+
exports.$insertTableColumn=function(a,b,c=!0,d,e){let g=a.getChildren(),f=[];for(let p=0;p<g.length;p++){let t=g[p];if(H(t))for(let k=0;k<d;k++){var m=t.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];A(m)||J(12);let {left:l,right:n}=ka(m,e);var q=x.NO_STATUS;if(l&&l.hasHeaderState(x.ROW)||n&&n.hasHeaderState(x.ROW))q|=x.ROW;q=z(q);q.append(u.$createParagraphNode());f.push({newTableCell:q,targetCell:m})}}f.forEach(({newTableCell:p,targetCell:t})=>{c?
|
70
|
+
t.insertAfter(p):t.insertBefore(p)});return a};
|
71
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=x.NO_STATUS){k=z(k).append(u.$createParagraphNode());null===p&&(p=k);return k}var c=u.$getSelection();u.$isRangeSelection(c)||R(c)||J(118);var d=c.anchor.getNode();c=c.focus.getNode();[d]=Q(d);let [e,,g]=Q(c),[f,m,q]=P(g,e,d);d=f.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);a=a?c+e.__colSpan-1:c-1;c=g.getFirstChild();H(c)||J(120);let p=null;var t=c;a:for(c=0;c<d;c++){0!==c&&(t=t.getNextSibling(),
|
72
|
+
H(t)||J(121));let k=f[c],l=la(k[0>a?0:a].cell.__headerState,x.ROW);if(0>a){ma(t,b(l));continue}let {cell:n,startColumn:r,startRow:v}=k[a];if(r+n.__colSpan-1<=a){let w=n,B=v,E=a;for(;B!==c&&1<w.__rowSpan;)if(E-=n.__colSpan,0<=E){let {cell:F,startRow:G}=k[E];w=F;B=G}else{t.append(b(l));continue a}w.insertAfter(b(l))}else n.setColSpan(n.__colSpan+1)}null!==p&&O(p)};
|
73
|
+
exports.$insertTableRow=function(a,b,c=!0,d,e){var g=a.getChildren();if(b>=g.length||0>b)throw Error("Table row target index out of range");b=g[b];if(H(b))for(g=0;g<d;g++){let m=b.getChildren(),q=m.length,p=D();for(let t=0;t<q;t++){var f=m[t];A(f)||J(12);let {above:k,below:l}=ka(f,e);f=x.NO_STATUS;let n=k&&k.getWidth()||l&&l.getWidth()||void 0;if(k&&k.hasHeaderState(x.COLUMN)||l&&l.hasHeaderState(x.COLUMN))f|=x.COLUMN;f=z(f,1,n);f.append(u.$createParagraphNode());p.append(f)}c?b.insertAfter(p):b.insertBefore(p)}else throw Error("Row before insertion index does not exist.");
|
74
74
|
return a};
|
75
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||R(b)||J(118);b=b.focus.getNode();let [c,,d]=Q(b),[e,g]=P(d,c,c);b=e[0].length;var {startRow:f}=g;if(a){a=f+c.__rowSpan-1;var m=e[a];f=D();for(var q=0;q<b;q++){let {cell:t,startRow:k}=m[q];if(k+t.__rowSpan-1<=a){var
|
76
|
-
a=D();for(q=0;q<b;q++){let {cell:t,startRow:k}=m[q];k===f?(
|
77
|
-
exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);a=a.anchor.getNode();let [b,c,d]=Q(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var g=1;g<a;g++)b.insertAfter(z(
|
78
|
-
a;m++)ma(l,z(
|
75
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||R(b)||J(118);b=b.focus.getNode();let [c,,d]=Q(b),[e,g]=P(d,c,c);b=e[0].length;var {startRow:f}=g;if(a){a=f+c.__rowSpan-1;var m=e[a];f=D();for(var q=0;q<b;q++){let {cell:t,startRow:k}=m[q];if(k+t.__rowSpan-1<=a){var p=la(m[q].cell.__headerState,x.COLUMN);f.append(z(p).append(u.$createParagraphNode()))}else t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(a);H(b)||J(145);b.insertAfter(f)}else{m=e[f];
|
76
|
+
a=D();for(q=0;q<b;q++){let {cell:t,startRow:k}=m[q];k===f?(p=la(m[q].cell.__headerState,x.COLUMN),a.append(z(p).append(u.$createParagraphNode()))):t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(f);H(b)||J(145);b.insertBefore(a)}};exports.$isTableCellNode=A;exports.$isTableNode=N;exports.$isTableRowNode=H;exports.$isTableSelection=R;exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
|
77
|
+
exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(118);a=a.anchor.getNode();let [b,c,d]=Q(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var g=1;g<a;g++)b.insertAfter(z(x.NO_STATUS));b.setColSpan(1)}if(1<e){let [q,p]=P(d,b,b),{startColumn:t,startRow:k}=p,l;for(g=1;g<e;g++){var f=k+g;let n=q[f];l=(l||c).getNextSibling();H(l)||J(125);var m=null;for(let r=0;r<t;r++){let v=n[r],w=v.cell;v.startRow===f&&(m=w);1<w.__colSpan&&(r+=w.__colSpan-1)}if(null===m)for(m=0;m<
|
78
|
+
a;m++)ma(l,z(x.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(x.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ca;exports.TableCellHeaderStates=x;exports.TableCellNode=y;exports.TableNode=La;exports.TableObserver=sa;exports.TableRowNode=C;
|
79
79
|
exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,f.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,f.table)}let g=c.getRootElement();if(null===g)throw Error("No root element.");let f=new sa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;let q=()=>{const k=()=>{f.isSelecting=!1;m.removeEventListener("mouseup",k);m.removeEventListener("mousemove",l)},l=n=>{setTimeout(()=>{if(1!==(n.buttons&1)&&f.isSelecting)f.isSelecting=!1,m.removeEventListener("mouseup",
|
80
|
-
k),m.removeEventListener("mousemove",l);else{var
|
81
|
-
{const l=u.$getSelection(),n=k.target;R(l)&&l.tableKey===f.tableNodeKey&&g.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",
|
80
|
+
k),m.removeEventListener("mousemove",l);else{var r=ua(n.target);null===r||f.anchorX===r.x&&f.anchorY===r.y||(n.preventDefault(),f.setFocusCellForSelection(r))}},0)};return{onMouseMove:l,onMouseUp:k}};b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=ua(k.target);null!==l&&(Z(k),f.setAnchorCellForSelection(l));var {onMouseUp:n,onMouseMove:r}=q();f.isSelecting=!0;m.addEventListener("mouseup",n);m.addEventListener("mousemove",r)}},0)});let p=k=>{0===k.button&&c.update(()=>
|
81
|
+
{const l=u.$getSelection(),n=k.target;R(l)&&l.tableKey===f.tableNodeKey&&g.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",p);f.listenersToRemove.add(()=>m.removeEventListener("mousedown",p));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_DOWN_COMMAND,k=>V(c,k,"down",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_UP_COMMAND,k=>V(c,k,"up",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_LEFT_COMMAND,
|
82
82
|
k=>V(c,k,"backward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_RIGHT_COMMAND,k=>V(c,k,"forward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ESCAPE_COMMAND,k=>{var l=u.$getSelection();return R(l)&&(l=h.$findMatchingParent(l.focus.getNode(),A),A(l))?(Z(k),l.selectEnd(),!0):!1},u.COMMAND_PRIORITY_HIGH));let t=k=>()=>{var l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return f.clearText(),!0;if(u.$isRangeSelection(l)){var n=
|
83
|
-
h.$findMatchingParent(l.anchor.getNode(),v=>A(v));if(!A(n))return!1;var
|
83
|
+
h.$findMatchingParent(l.anchor.getNode(),v=>A(v));if(!A(n))return!1;var r=l.anchor.getNode();n=l.focus.getNode();r=a.isParentOf(r);n=a.isParentOf(n);if(r&&!n||n&&!r)return f.clearText(),!0;n=(l=h.$findMatchingParent(l.anchor.getNode(),v=>u.$isElementNode(v)))&&h.$findMatchingParent(l,v=>u.$isElementNode(v)&&A(v.getParent()));if(!u.$isElementNode(n)||!u.$isElementNode(l))return!1;if(k===u.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0}return!1};[u.DELETE_WORD_COMMAND,u.DELETE_LINE_COMMAND,
|
84
84
|
u.DELETE_CHARACTER_COMMAND].forEach(k=>{f.listenersToRemove.add(c.registerCommand(k,t(k),u.COMMAND_PRIORITY_CRITICAL))});b=k=>{const l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return k.preventDefault(),k.stopPropagation(),f.clearText(),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>A(n)),A(k));return!1};f.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.KEY_DELETE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));
|
85
|
-
f.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,k=>{let l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return f.formatCells(k),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>A(n)),A(k));return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,k=>{var l=u.$getSelection();if(!R(l)||!U(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!A(n)||!A(l))return!1;let [
|
86
|
-
|
87
|
-
else if(u.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),
|
88
|
-
"forward");return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var
|
89
|
-
k,
|
90
|
-
E[B];if(!H(ea))return!1;var fa=k[G];if(!H(fa))return!1;ea=ea.getChildren();fa=fa.getChildren();let I=0;for(let W=
|
91
|
-
()=>{let k=u.$getSelection(),l=u.$getPreviousSelection();if(u.$isRangeSelection(k)){let {anchor:B,focus:E}=k;var n=B.getNode(),
|
92
|
-
f.setFocusCellForSelection(e(v),!0),f.isSelecting||setTimeout(()=>{let {onMouseUp:L,onMouseMove:M}=q();f.isSelecting=!0;m.addEventListener("mouseup",L);m.addEventListener("mousemove",M)},0))}else k&&R(k)&&k.is(l)&&k.tableKey===a.getKey()&&(n=ha?(c._window||window).getSelection():null)&&n.anchorNode&&n.focusNode&&(
|
93
|
-
(
|
85
|
+
f.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,k=>{let l=u.$getSelection();if(!U(l,a))return!1;if(R(l))return f.formatCells(k),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>A(n)),A(k));return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,k=>{var l=u.$getSelection();if(!R(l)||!U(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!A(n)||!A(l))return!1;let [r,v,w]=P(a,n,l);n=Math.max(v.startRow,
|
86
|
+
w.startRow);l=Math.max(v.startColumn,w.startColumn);var B=Math.min(v.startRow,w.startRow);let E=Math.min(v.startColumn,w.startColumn);for(;B<=n;B++)for(let G=E;G<=l;G++){var F=r[B][G].cell;F.setFormat(k);F=F.getChildren();for(let L=0;L<F.length;L++){let M=F[L];u.$isElementNode(M)&&!M.isInline()&&M.setFormat(k)}}return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=u.$getSelection();if(!U(l,a))return!1;if(R(l))f.clearHighlight();
|
87
|
+
else if(u.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),r=>A(r));if(!A(n))return!1;if("string"===typeof k&&(l=Ka(c,l,a)))return Ja(l,a,[u.$createTextNode(k)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));d&&f.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,k=>{var l=u.$getSelection();if(!u.$isRangeSelection(l)||!l.isCollapsed()||!U(l,a))return!1;l=Da(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,f.table);Aa(f,a,l.x,l.y,k.shiftKey?"backward":
|
88
|
+
"forward");return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var r=R(n);r=u.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),I=>A(I))&&null!==h.$findMatchingParent(n.focus.getNode(),I=>A(I))||r;if(1!==l.length||!N(l[0])||!r||null===k)return!1;var [v]=
|
89
|
+
k,w=l[0];k=w.getChildren();r=w.getFirstChildOrThrow().getChildrenSize();w=w.getChildrenSize();var B=h.$findMatchingParent(v.getNode(),I=>A(I)),E=(v=B&&h.$findMatchingParent(B,I=>H(I)))&&h.$findMatchingParent(v,I=>N(I));if(!A(B)||!H(v)||!N(E))return!1;var F=v.getIndexWithinParent(),G=Math.min(E.getChildrenSize()-1,F+w-1);w=B.getIndexWithinParent();B=Math.min(v.getChildrenSize()-1,w+r-1);r=Math.min(w,B);v=Math.min(F,G);w=Math.max(w,B);F=Math.max(F,G);E=E.getChildren();G=0;let L,M;for(B=v;B<=F;B++){var ea=
|
90
|
+
E[B];if(!H(ea))return!1;var fa=k[G];if(!H(fa))return!1;ea=ea.getChildren();fa=fa.getChildren();let I=0;for(let W=r;W<=w;W++){let X=ea[W];if(!A(X))return!1;let Ca=fa[I];if(!A(Ca))return!1;B===v&&W===r?L=X.getKey():B===F&&W===w&&(M=X.getKey());let Oa=X.getChildren();Ca.getChildren().forEach(Y=>{u.$isTextNode(Y)&&u.$createParagraphNode().append(Y);X.append(Y)});Oa.forEach(Y=>Y.remove());I++}G++}L&&M&&(k=ra(),k.set(l[0].getKey(),L,M),u.$setSelection(k));return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,
|
91
|
+
()=>{let k=u.$getSelection(),l=u.$getPreviousSelection();if(u.$isRangeSelection(k)){let {anchor:B,focus:E}=k;var n=B.getNode(),r=E.getNode();n=Da(n);var v=Da(r),w=!(!n||!a.is(T(n)));r=!(!v||!a.is(T(v)));let F=w!==r,G=w&&r;w=k.isBackward();F?(n=k.clone(),r?n.focus.set(a.getParentOrThrow().getKey(),a.getIndexWithinParent(),"element"):n.anchor.set(a.getParentOrThrow().getKey(),w?a.getIndexWithinParent()+1:a.getIndexWithinParent(),"element"),u.$setSelection(n),ya(c,f)):G&&!n.is(v)&&(f.setAnchorCellForSelection(e(n)),
|
92
|
+
f.setFocusCellForSelection(e(v),!0),f.isSelecting||setTimeout(()=>{let {onMouseUp:L,onMouseMove:M}=q();f.isSelecting=!0;m.addEventListener("mouseup",L);m.addEventListener("mousemove",M)},0))}else k&&R(k)&&k.is(l)&&k.tableKey===a.getKey()&&(n=ha?(c._window||window).getSelection():null)&&n.anchorNode&&n.focusNode&&(r=(r=u.$getNearestNodeFromDOMNode(n.focusNode))&&!a.is(T(r)),v=(v=u.$getNearestNodeFromDOMNode(n.anchorNode))&&a.is(T(v)),r&&v&&0<n.rangeCount&&(r=u.$createRangeSelectionFromDom(n,c)))&&
|
93
|
+
(r.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),n.removeAllRanges(),u.$setSelection(r));if(k&&!k.is(l)&&(R(k)||R(l))&&f.tableSelection&&!f.tableSelection.is(l))return R(k)&&k.tableKey===f.tableNodeKey?f.updateTableTableSelection(k):!R(k)&&R(l)&&l.tableKey===f.tableNodeKey&&f.updateTableTableSelection(null),!1;f.hasHijackedSelectionStyles&&!a.isSelected()?za(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&ya(c,f);return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,
|
94
94
|
()=>{var k=u.$getSelection();return u.$isRangeSelection(k)&&k.isCollapsed()&&U(k,a)?(k=Ka(c,k,a))?(Ja(k,a),!0):!1:!1},u.COMMAND_PRIORITY_CRITICAL));return f};exports.getDOMCellFromTarget=ua;exports.getTableObserverFromTableElement=function(a){return a.__lexicalTableSelection}
|
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 h,$createTextNode as u,$getSelection as d,$isRangeSelection as g,$createPoint as f,$normalizeSelection__EXPERIMENTAL as m,$getNodeByKey as p,isCurrentlyReadOnlyMode as S,$setSelection as C,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 k,KEY_BACKSPACE_COMMAND as F,KEY_DELETE_COMMAND as A,FORMAT_TEXT_COMMAND as H,FORMAT_ELEMENT_COMMAND as P,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as D,FOCUS_COMMAND as L,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as Y,$isDecoratorNode as X}from"lexical";const z=/^(\d+(?:\.\d+)?)px$/,J={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class $ extends r{static getType(){return"tablecell"}static clone(e){const t=new $(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:j,priority:0}),th:e=>({conversion:j,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=q(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=J.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!==J.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 j(e){const t=e,n=e.nodeName.toLowerCase();let o;z.test(t.style.width)&&(o=parseFloat(t.style.width));const r=q("th"===n?J.ROW:J.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const a=t.style.backgroundColor;""!==a&&(r.__backgroundColor=a);const h=t.style,u=h.textDecoration.split(" "),d="700"===h.fontWeight||"bold"===h.fontWeight,g=u.includes("line-through"),f="italic"===h.fontStyle,m=u.includes("underline");return{after:e=>(0===e.length&&e.push(l()),e),forChild:(e,t)=>{if(G(t)&&!s(e)){const t=l();return i(e)&&"\n"===e.getTextContent()?null:(c(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function q(e,t=1,n){return a(new $(e,t,n))}function G(e){return e instanceof $}const Q=h("INSERT_TABLE_COMMAND");class V extends r{static getType(){return"tablerow"}static clone(e){return new V(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:Z,priority:0})}}static importJSON(e){return ee(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 Z(e){const t=e;let n;return z.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:ee(n)}}function ee(e){return a(new V(e))}function te(e){return e instanceof V}function ne(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var oe=ne((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 re="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function le(e,t,n=!0){const o=rt();for(let r=0;r<e;r++){const e=ee();for(let o=0;o<t;o++){let t=J.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=J.ROW),0===o&&n.columns&&(t|=J.COLUMN)):n&&(0===r&&(t|=J.ROW),0===o&&(t|=J.COLUMN));const s=q(t),i=l();i.append(u()),s.append(i),e.append(s)}o.append(e)}return o}function se(e){const n=t(e,(e=>G(e)));return G(n)?n:null}function ie(e){const n=t(e,(e=>te(e)));if(te(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ce(e){const n=t(e,(e=>lt(e)));if(lt(n))return n;throw new Error("Expected table cell to be inside of table.")}function ae(e){const t=ie(e);return ce(t).getChildren().findIndex((e=>e.is(t)))}function he(e){return ie(e).getChildren().findIndex((t=>t.is(e)))}function ue(e,t){const n=ce(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function de(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function ge(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(!te(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=ee();for(let n=0;n<t;n++){const t=e[n];G(t)||oe(12);const{above:s,below:i}=ue(t,r);let c=J.NO_STATUS;const a=s&&s.getWidth()||i&&i.getWidth()||void 0;(s&&s.hasHeaderState(J.COLUMN)||i&&i.hasHeaderState(J.COLUMN))&&(c|=J.COLUMN);const h=q(c,1,a);h.append(l()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const fe=(e,t)=>e===J.BOTH||e===t?t:J.NO_STATUS;function me(e=!0){const t=d();g(t)||Me(t)||oe(118);const n=t.focus.getNode(),[o,,r]=ve(n),[s,i]=Te(r,o,o),c=s[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=s[e],n=ee();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=fe(e,J.COLUMN);n.append(q(r).append(l()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);te(i)||oe(145),i.insertAfter(n)}else{const e=s[a],t=ee();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=fe(o,J.COLUMN);t.append(q(r).append(l()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);te(n)||oe(145),n.insertBefore(t)}}function pe(e,t,n=!0,o,r){const s=e.getChildren(),i=[];for(let e=0;e<s.length;e++){const n=s[e];if(te(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];G(o)||oe(12);const{left:s,right:c}=ue(o,r);let a=J.NO_STATUS;(s&&s.hasHeaderState(J.ROW)||c&&c.hasHeaderState(J.ROW))&&(a|=J.ROW);const h=q(a);h.append(l()),i.push({newTableCell:h,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Se(e=!0){const t=d();g(t)||Me(t)||oe(118);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=ve(n),[s,,i]=ve(o),[c,a,h]=Te(i,s,r),u=c.length,f=e?Math.max(a.startColumn,h.startColumn):Math.min(a.startColumn,h.startColumn),m=e?f+s.__colSpan-1:f-1,p=i.getFirstChild();te(p)||oe(120);let S=null;function C(e=J.NO_STATUS){const t=q(e).append(l());return null===S&&(S=t),t}let _=p;e:for(let e=0;e<u;e++){if(0!==e){const e=_.getNextSibling();te(e)||oe(121),_=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=fe(n,J.ROW);if(m<0){ye(_,C(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(C(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(C(o))}else r.setColSpan(r.__colSpan+1)}null!==S&&be(S)}function Ce(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(te(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 _e(){const e=d();g(e)||Me(e)||oe(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ve(t),[l]=ve(n),[s,i,c]=Te(r,o,l),{startRow:a}=i,{startRow:h}=c,u=h+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&&oe(122),0===t)ye(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);te(t)||oe(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];be(e)}else{const e=s[a-1],{cell:t}=e[0];be(t)}}function we(){const e=d();g(e)||Me(e)||oe(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ve(t),[l]=ve(n),[s,i,c]=Te(r,o,l),{startColumn:a}=i,{startRow:h,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 S=s.length;for(let e=0;e<S;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 C=s[h],_=C[u+l.__colSpan];if(void 0!==_){const{cell:e}=_;be(e)}else{const e=C[u-1],{cell:t}=e;be(t)}}function be(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function ye(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ne(){const e=d();g(e)||Me(e)||oe(118);const t=e.anchor.getNode(),[n,o,r]=ve(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(q(J.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=Te(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(),te(a)||oe(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++)ye(a,q(J.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(q(J.NO_STATUS))}n.setRowSpan(1)}}function Te(e,t,n){const[o,r,l]=xe(e,t,n);return null===r&&oe(110),null===l&&oe(111),[o,r,l]}function xe(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,h=i.__colSpan;for(let t=0;t<a;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<h;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];te(t)||oe(146);const n=t.getChildren();let o=0;for(const t of n){for(G(t)||oe(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function ve(e){let n;if(e instanceof $)n=e;else if("__type"in e){const o=t(e,G);G(o)||oe(148),n=o}else{const o=t(e.getNode(),G);G(o)||oe(148),n=o}const o=n.getParent();te(o)||oe(149);const r=o.getParent();return lt(r)||oe(150),[n,o,r]}function Ee(e){const[t,,n]=ve(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 Oe{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!!Me(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 Oe(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)||oe(151);m(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=p(this.anchor.key);G(e)||oe(152);const t=Ee(e);null===t&&oe(153);const n=p(this.focus.key);G(n)||oe(154);const o=Ee(n);null===o&&oe(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,G),l=t(o,G);G(r)||oe(152),G(l)||oe(154);const s=r.getParent();te(s)||oe(156);const i=s.getParent();lt(i)||oe(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&oe(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&oe(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,h,u]=Te(i,r,l);let d=Math.min(h.startColumn,u.startColumn),g=Math.min(h.startRow,u.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,u.startColumn+u.cell.__colSpan-1),m=Math.max(h.startRow+h.cell.__rowSpan-1,u.startRow+u.cell.__rowSpan-1),p=d,C=g,_=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),m=Math.max(m,o+t.__rowSpan-1)}for(;d<p||g<C||f>_||m>w;){if(d<p){const e=w-C,t=p-1;for(let n=0;n<=e;n++)b(a[C+n][t]);p=t}if(g<C){const e=_-p,t=C-1;for(let n=0;n<=e;n++)b(a[t][p+n]);C=t}if(f>_){const e=w-C,t=_+1;for(let n=0;n<=e;n++)b(a[C+n][t]);_=t}if(m>w){const e=_-p,t=w+1;for(let n=0;n<=e;n++)b(a[t][p+n]);w=t}}const y=[i];let N=null;for(let e=g;e<=m;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();te(o)||oe(160),o!==N&&y.push(o),y.push(n,...Ke(n)),N=o}return S()||(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 Me(e){return e instanceof Oe}function Re(){const e=f("root",0,"element"),t=f("root",0,"element");return new Oe("root",e,t)}function Ke(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&oe(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=De(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=De(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(!lt(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=De(t);Le(e,n,null),C(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(),Le(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(!lt(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=Ae(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&&G(t)&&o.is(Ge(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Re(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),C(this.tableSelection),n.dispatchCommand(_,void 0),Le(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(G(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Re(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=d();Me(t)||oe(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{G(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),C(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=p(this.tableNodeKey);if(!lt(t))throw new Error("Expected TableNode.");const n=d();Me(n)||oe(11);const o=n.getNodes().filter(G);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()}))}})),Le(e,this.table,null),C(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const Fe="__lexicalTableSelection",Ae=e=>re?(e||window).getSelection():null;function He(e,n,o,r){const i=o.getRootElement();if(null===i)throw new Error("No root element.");const a=new ke(o,e.getKey()),h=o._window||window;!function(e,t){e[Fe]=t}(n,a);const f=()=>{const e=()=>{a.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&a.isSelecting)return a.isSelecting=!1,h.removeEventListener("mouseup",e),void h.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(!h)return;const t=Be(e.target);null!==t&&(Ve(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();a.isSelecting=!0,h.addEventListener("mouseup",n),h.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=d(),n=e.target;Me(t)&&t.tableKey===a.tableNodeKey&&i.contains(n)&&a.clearHighlight()}))};h.addEventListener("mousedown",m),a.listenersToRemove.add((()=>h.removeEventListener("mousedown",m))),a.listenersToRemove.add(o.registerCommand(N,(t=>Qe(o,t,"down",e,a)),T)),a.listenersToRemove.add(o.registerCommand(x,(t=>Qe(o,t,"up",e,a)),T)),a.listenersToRemove.add(o.registerCommand(v,(t=>Qe(o,t,"backward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(E,(t=>Qe(o,t,"forward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=d();if(Me(n)){const o=t(n.focus.getNode(),G);if(G(o))return Ve(e),o.selectEnd(),!0}return!1}),T));[M,R,K].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=d();if(!Xe(o,e))return!1;if(Me(o))return a.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>G(e)));if(!G(r))return!1;const l=o.anchor.getNode(),i=o.focus.getNode(),c=e.isParentOf(l),h=e.isParentOf(i);if(c&&!h||h&&!c)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>s(e))),d=u&&t(u,(e=>s(e)&&G(e.getParent())));if(!s(d)||!s(u))return!1;if(n===R&&null===d.getPreviousSibling())return!0}return!1})(n),k))}));const p=n=>{const o=d();if(!Xe(o,e))return!1;if(Me(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>G(e)));if(!G(e))return!1}return!1};function S(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(F,p,k)),a.listenersToRemove.add(o.registerCommand(A,p,k)),a.listenersToRemove.add(o.registerCommand(H,(n=>{const o=d();if(!Xe(o,e))return!1;if(Me(o))return a.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>G(e)));if(!G(e))return!1}return!1}),k)),a.listenersToRemove.add(o.registerCommand(P,(t=>{const n=d();if(!Me(n)||!Xe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!G(o)||!G(r))return!1;const[l,i,c]=Te(e,o,r),a=Math.max(i.startRow,c.startRow),h=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<=h;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}),k)),a.listenersToRemove.add(o.registerCommand(B,(n=>{const r=d();if(!Xe(r,e))return!1;if(Me(r))return a.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>G(e)));if(!G(l))return!1;if("string"==typeof n){const t=et(o,r,e);if(t)return Ze(t,e,[u(n)]),!0}}return!1}),k)),r&&a.listenersToRemove.add(o.registerCommand(D,(t=>{const n=d();if(!g(n)||!n.isCollapsed()||!Xe(n,e))return!1;const o=qe(n.anchor.getNode());if(null===o)return!1;Ve(t);const r=e.getCordsFromCellNode(o,a.table);return Ue(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),k)),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=Me(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>G(e)))&&null!==t(o.focus.getNode(),(e=>G(e)))||s;if(1!==n.length||!lt(n[0])||!i||null===r)return!1;const[a]=r,h=n[0],u=h.getChildren(),d=h.getFirstChildOrThrow().getChildrenSize(),f=h.getChildrenSize(),m=t(a.getNode(),(e=>G(e))),p=m&&t(m,(e=>te(e))),S=p&&t(p,(e=>lt(e)));if(!G(m)||!te(p)||!lt(S))return!1;const _=p.getIndexWithinParent(),w=Math.min(S.getChildrenSize()-1,_+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+d-1),N=Math.min(b,y),T=Math.min(_,w),x=Math.max(b,y),v=Math.max(_,w),E=S.getChildren();let O,M,R=0;for(let e=T;e<=v;e++){const t=E[e];if(!te(t))return!1;const n=u[R];if(!te(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(!G(n))return!1;const i=r[s];if(!G(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=Re();e.set(n[0].getKey(),O,M),C(e)}return!0}),k)),a.listenersToRemove.add(o.registerCommand(_,(()=>{const t=d(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=qe(l),c=qe(s),u=!(!i||!e.is(Ge(i))),d=!(!c||!e.is(Ge(c))),g=u!==d,m=u&&d,p=t.isBackward();if(g){const n=t.clone();d?n.focus.set(e.getParentOrThrow().getKey(),e.getIndexWithinParent(),"element"):n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element"),C(n),We(o,a)}else m&&(i.is(c)||(a.setAnchorCellForSelection(S(i)),a.setFocusCellForSelection(S(c),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();a.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&Me(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ae(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is(Ge(r)),s=w(n.anchorNode),i=s&&e.is(Ge(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(),C(r))}}}return t&&!t.is(n)&&(Me(t)||Me(n))&&a.tableSelection&&!a.tableSelection.is(n)?(Me(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!Me(t)&&Me(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Ie(t.table,(t=>{const n=t.elem;t.highlighted=!1,je(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&We(o,a),!1)}),k)),a.listenersToRemove.add(o.registerCommand(Y,(()=>{const t=d();if(!g(t)||!t.isCollapsed()||!Xe(t,e))return!1;const n=et(o,t,e);return!!n&&(Ze(n,e),!0)}),k)),a}function Pe(e){return e[Fe]}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 De(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 Le(e,t,n){const o=new Set(n?n.getNodes():[]);Ie(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,$e(e,t)):(t.highlighted=!1,je(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Ie(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 We(e,t){t.disableHighlightStyle(),Ie(t.table,(t=>{t.highlighted=!0,$e(e,t)}))}const Ue=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ze(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ze(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?ze(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ze(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)||Me(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function ze(e,t){t?e.selectStart():e.selectEnd()}const Je="172,206,247";function $e(e,t){const n=t.elem,o=w(n);G(o)||oe(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Je})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Je},0.85), rgba(${Je},0.85))`),n.style.setProperty("caret-color","transparent")}function je(e,t){const n=t.elem,o=w(n);G(o)||oe(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function qe(e){const n=t(e,G);return G(n)?n:null}function Ge(e){const n=t(e,lt);return lt(n)?n:null}function Qe(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=d();if(!Xe(i,r)){if("backward"===o&&g(i)&&i.isCollapsed()){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||!lt(c))&&(Ve(n),c.selectEnd(),!0)}return!1}if(g(i)&&i.isCollapsed()){const{anchor:c,focus:a}=i,h=t(c.getNode(),G),u=t(a.getNode(),G);if(!G(h)||!h.is(u))return!1;const d=Ge(h);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=De(t),Qe(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 h=i.getNodes();return(1!==h.length||!X(h[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,G);if(!G(l))return!1;const[i,c]=Te(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&<(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||lt(a))return!1;Ve(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(h.__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?h.getFirstChild():h.getLastChild();if(null==p)return!1;const S=e.getElementByKey(p.__key);if(null==S)return!1;const C=S.getBoundingClientRect();if("up"===o?C.top>m.top-m.height:m.bottom+m.height>C.bottom){Ve(n);const e=r.getCordsFromCellNode(h,l.table);if(!n.shiftKey)return Ue(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(Me(i)){const{anchor:s,focus:c}=i,a=t(s.getNode(),G),h=t(c.getNode(),G),[u]=i.getNodes(),d=e.getElementByKey(u.getKey());if(!G(a)||!G(h)||!lt(u)||null==d)return!1;l.updateTableTableSelection(i);const g=De(d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Ve(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return Ye(l,u,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function Ve(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ze(e,t,n){const o=l();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function et(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=>G(e)));if(!i)return;const c=t(i,(e=>lt(e)));if(!lt(c)||!c.is(o))return;const[a,h]=Te(o,i,i),u=a[0][0],d=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=h,m=g===u.startRow&&f===u.startColumn,p=g===d.startRow&&f===d.startColumn;return m?"first":p?"last":void 0}class tt extends r{static getType(){return"table"}static clone(e){return new tt(e.__key)}static importDOM(){return{table:e=>({conversion:ot,priority:1})}}static importJSON(e){return rt()}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(!te(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 G(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 nt(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return De(n)}function ot(e){return{node:rt()}}function rt(){return a(new tt)}function lt(e){return e instanceof tt}export{Te as $computeTableMap,xe as $computeTableMapSkipCellCheck,q as $createTableCellNode,rt as $createTableNode,le as $createTableNodeWithDimensions,ee as $createTableRowNode,Re as $createTableSelection,Ce as $deleteTableColumn,we as $deleteTableColumn__EXPERIMENTAL,_e as $deleteTableRow__EXPERIMENTAL,nt as $getElementForTableNode,ve as $getNodeTriplet,se as $getTableCellNodeFromLexicalNode,Ee as $getTableCellNodeRect,he as $getTableColumnIndexFromTableCellNode,ce as $getTableNodeFromLexicalNodeOrThrow,ae as $getTableRowIndexFromTableCellNode,ie as $getTableRowNodeFromTableCellNodeOrThrow,pe as $insertTableColumn,Se as $insertTableColumn__EXPERIMENTAL,ge as $insertTableRow,me as $insertTableRow__EXPERIMENTAL,G as $isTableCellNode,lt as $isTableNode,te as $isTableRowNode,Me as $isTableSelection,de as $removeTableRowAtIndex,Ne as $unmergeCell,Q as INSERT_TABLE_COMMAND,J as TableCellHeaderStates,$ as TableCellNode,tt as TableNode,ke as TableObserver,V as TableRowNode,He as applyTableHandlers,Be as getDOMCellFromTarget,Pe 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 h,$createTextNode as u,$getSelection as d,$isRangeSelection as g,$createPoint as f,$normalizeSelection__EXPERIMENTAL as m,$getNodeByKey as p,isCurrentlyReadOnlyMode as S,$setSelection as _,SELECTION_CHANGE_COMMAND as C,$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 k,KEY_BACKSPACE_COMMAND as F,KEY_DELETE_COMMAND as A,FORMAT_TEXT_COMMAND as H,FORMAT_ELEMENT_COMMAND as P,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as D,FOCUS_COMMAND as L,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as Y,$isDecoratorNode as X}from"lexical";const z=/^(\d+(?:\.\d+)?)px$/,J={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class $ extends r{static getType(){return"tablecell"}static clone(e){const t=new $(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:j,priority:0}),th:e=>({conversion:j,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=q(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=J.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!==J.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 j(e){const t=e,n=e.nodeName.toLowerCase();let o;z.test(t.style.width)&&(o=parseFloat(t.style.width));const r=q("th"===n?J.ROW:J.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const a=t.style.backgroundColor;""!==a&&(r.__backgroundColor=a);const h=t.style,u=h.textDecoration.split(" "),d="700"===h.fontWeight||"bold"===h.fontWeight,g=u.includes("line-through"),f="italic"===h.fontStyle,m=u.includes("underline");return{after:e=>(0===e.length&&e.push(l()),e),forChild:(e,t)=>{if(G(t)&&!s(e)){const t=l();return i(e)&&"\n"===e.getTextContent()?null:(c(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function q(e,t=1,n){return a(new $(e,t,n))}function G(e){return e instanceof $}const Q=h("INSERT_TABLE_COMMAND");class V extends r{static getType(){return"tablerow"}static clone(e){return new V(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:Z,priority:0})}}static importJSON(e){return ee(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 Z(e){const t=e;let n;return z.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:ee(n)}}function ee(e){return a(new V(e))}function te(e){return e instanceof V}function ne(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var oe=ne((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 re="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function le(e,t,n=!0){const o=rt();for(let r=0;r<e;r++){const e=ee();for(let o=0;o<t;o++){let t=J.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=J.ROW),0===o&&n.columns&&(t|=J.COLUMN)):n&&(0===r&&(t|=J.ROW),0===o&&(t|=J.COLUMN));const s=q(t),i=l();i.append(u()),s.append(i),e.append(s)}o.append(e)}return o}function se(e){const n=t(e,(e=>G(e)));return G(n)?n:null}function ie(e){const n=t(e,(e=>te(e)));if(te(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ce(e){const n=t(e,(e=>lt(e)));if(lt(n))return n;throw new Error("Expected table cell to be inside of table.")}function ae(e){const t=ie(e);return ce(t).getChildren().findIndex((e=>e.is(t)))}function he(e){return ie(e).getChildren().findIndex((t=>t.is(e)))}function ue(e,t){const n=ce(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function de(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function ge(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(!te(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=ee();for(let n=0;n<t;n++){const t=e[n];G(t)||oe(12);const{above:s,below:i}=ue(t,r);let c=J.NO_STATUS;const a=s&&s.getWidth()||i&&i.getWidth()||void 0;(s&&s.hasHeaderState(J.COLUMN)||i&&i.hasHeaderState(J.COLUMN))&&(c|=J.COLUMN);const h=q(c,1,a);h.append(l()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const fe=(e,t)=>e===J.BOTH||e===t?t:J.NO_STATUS;function me(e=!0){const t=d();g(t)||Me(t)||oe(118);const n=t.focus.getNode(),[o,,r]=ve(n),[s,i]=Te(r,o,o),c=s[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=s[e],n=ee();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=fe(e,J.COLUMN);n.append(q(r).append(l()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);te(i)||oe(145),i.insertAfter(n)}else{const e=s[a],t=ee();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=fe(o,J.COLUMN);t.append(q(r).append(l()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);te(n)||oe(145),n.insertBefore(t)}}function pe(e,t,n=!0,o,r){const s=e.getChildren(),i=[];for(let e=0;e<s.length;e++){const n=s[e];if(te(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];G(o)||oe(12);const{left:s,right:c}=ue(o,r);let a=J.NO_STATUS;(s&&s.hasHeaderState(J.ROW)||c&&c.hasHeaderState(J.ROW))&&(a|=J.ROW);const h=q(a);h.append(l()),i.push({newTableCell:h,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Se(e=!0){const t=d();g(t)||Me(t)||oe(118);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=ve(n),[s,,i]=ve(o),[c,a,h]=Te(i,s,r),u=c.length,f=e?Math.max(a.startColumn,h.startColumn):Math.min(a.startColumn,h.startColumn),m=e?f+s.__colSpan-1:f-1,p=i.getFirstChild();te(p)||oe(120);let S=null;function _(e=J.NO_STATUS){const t=q(e).append(l());return null===S&&(S=t),t}let C=p;e:for(let e=0;e<u;e++){if(0!==e){const e=C.getNextSibling();te(e)||oe(121),C=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=fe(n,J.ROW);if(m<0){ye(C,_(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)){C.append(_(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(_(o))}else r.setColSpan(r.__colSpan+1)}null!==S&&be(S)}function _e(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(te(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 Ce(){const e=d();g(e)||Me(e)||oe(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ve(t),[l]=ve(n),[s,i,c]=Te(r,o,l),{startRow:a}=i,{startRow:h}=c,u=h+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&&oe(122),0===t)ye(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);te(t)||oe(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];be(e)}else{const e=s[a-1],{cell:t}=e[0];be(t)}}function we(){const e=d();g(e)||Me(e)||oe(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ve(t),[l]=ve(n),[s,i,c]=Te(r,o,l),{startColumn:a}=i,{startRow:h,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 S=s.length;for(let e=0;e<S;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[h],C=a>u?_[a+o.__colSpan]:_[u+l.__colSpan];if(void 0!==C){const{cell:e}=C;be(e)}else{const e=u<a?_[u-1]:_[a-1],{cell:t}=e;be(t)}}function be(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function ye(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ne(){const e=d();g(e)||Me(e)||oe(118);const t=e.anchor.getNode(),[n,o,r]=ve(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(q(J.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=Te(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(),te(a)||oe(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++)ye(a,q(J.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(q(J.NO_STATUS))}n.setRowSpan(1)}}function Te(e,t,n){const[o,r,l]=xe(e,t,n);return null===r&&oe(110),null===l&&oe(111),[o,r,l]}function xe(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,h=i.__colSpan;for(let t=0;t<a;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<h;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];te(t)||oe(146);const n=t.getChildren();let o=0;for(const t of n){for(G(t)||oe(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function ve(e){let n;if(e instanceof $)n=e;else if("__type"in e){const o=t(e,G);G(o)||oe(148),n=o}else{const o=t(e.getNode(),G);G(o)||oe(148),n=o}const o=n.getParent();te(o)||oe(149);const r=o.getParent();return lt(r)||oe(150),[n,o,r]}function Ee(e){const[t,,n]=ve(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 Oe{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!!Me(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 Oe(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)||oe(151);m(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=p(this.anchor.key);G(e)||oe(152);const t=Ee(e);null===t&&oe(153);const n=p(this.focus.key);G(n)||oe(154);const o=Ee(n);null===o&&oe(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,G),l=t(o,G);G(r)||oe(152),G(l)||oe(154);const s=r.getParent();te(s)||oe(156);const i=s.getParent();lt(i)||oe(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&oe(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&oe(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,h,u]=Te(i,r,l);let d=Math.min(h.startColumn,u.startColumn),g=Math.min(h.startRow,u.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,u.startColumn+u.cell.__colSpan-1),m=Math.max(h.startRow+h.cell.__rowSpan-1,u.startRow+u.cell.__rowSpan-1),p=d,_=g,C=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),m=Math.max(m,o+t.__rowSpan-1)}for(;d<p||g<_||f>C||m>w;){if(d<p){const e=w-_,t=p-1;for(let n=0;n<=e;n++)b(a[_+n][t]);p=t}if(g<_){const e=C-p,t=_-1;for(let n=0;n<=e;n++)b(a[t][p+n]);_=t}if(f>C){const e=w-_,t=C+1;for(let n=0;n<=e;n++)b(a[_+n][t]);C=t}if(m>w){const e=C-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=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();te(o)||oe(160),o!==N&&y.push(o),y.push(n,...Ke(n)),N=o}return S()||(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 Me(e){return e instanceof Oe}function Re(){const e=f("root",0,"element"),t=f("root",0,"element");return new Oe("root",e,t)}function Ke(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&oe(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=De(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=De(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(!lt(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=De(t);Le(e,n,null),_(null),e.dispatchCommand(C,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(),Le(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(!lt(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=Ae(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&&G(t)&&o.is(Ge(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Re(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),_(this.tableSelection),n.dispatchCommand(C,void 0),Le(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(G(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Re(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=d();Me(t)||oe(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{G(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),_(t),this.editor.dispatchCommand(C,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=p(this.tableNodeKey);if(!lt(t))throw new Error("Expected TableNode.");const n=d();Me(n)||oe(11);const o=n.getNodes().filter(G);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()}))}})),Le(e,this.table,null),_(null),e.dispatchCommand(C,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const Fe="__lexicalTableSelection",Ae=e=>re?(e||window).getSelection():null;function He(e,n,o,r){const i=o.getRootElement();if(null===i)throw new Error("No root element.");const a=new ke(o,e.getKey()),h=o._window||window;!function(e,t){e[Fe]=t}(n,a);const f=()=>{const e=()=>{a.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&a.isSelecting)return a.isSelecting=!1,h.removeEventListener("mouseup",e),void h.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(!h)return;const t=Be(e.target);null!==t&&(Ve(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();a.isSelecting=!0,h.addEventListener("mouseup",n),h.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=d(),n=e.target;Me(t)&&t.tableKey===a.tableNodeKey&&i.contains(n)&&a.clearHighlight()}))};h.addEventListener("mousedown",m),a.listenersToRemove.add((()=>h.removeEventListener("mousedown",m))),a.listenersToRemove.add(o.registerCommand(N,(t=>Qe(o,t,"down",e,a)),T)),a.listenersToRemove.add(o.registerCommand(x,(t=>Qe(o,t,"up",e,a)),T)),a.listenersToRemove.add(o.registerCommand(v,(t=>Qe(o,t,"backward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(E,(t=>Qe(o,t,"forward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=d();if(Me(n)){const o=t(n.focus.getNode(),G);if(G(o))return Ve(e),o.selectEnd(),!0}return!1}),T));[M,R,K].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=d();if(!Xe(o,e))return!1;if(Me(o))return a.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>G(e)));if(!G(r))return!1;const l=o.anchor.getNode(),i=o.focus.getNode(),c=e.isParentOf(l),h=e.isParentOf(i);if(c&&!h||h&&!c)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>s(e))),d=u&&t(u,(e=>s(e)&&G(e.getParent())));if(!s(d)||!s(u))return!1;if(n===R&&null===d.getPreviousSibling())return!0}return!1})(n),k))}));const p=n=>{const o=d();if(!Xe(o,e))return!1;if(Me(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>G(e)));if(!G(e))return!1}return!1};function S(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(F,p,k)),a.listenersToRemove.add(o.registerCommand(A,p,k)),a.listenersToRemove.add(o.registerCommand(H,(n=>{const o=d();if(!Xe(o,e))return!1;if(Me(o))return a.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>G(e)));if(!G(e))return!1}return!1}),k)),a.listenersToRemove.add(o.registerCommand(P,(t=>{const n=d();if(!Me(n)||!Xe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!G(o)||!G(r))return!1;const[l,i,c]=Te(e,o,r),a=Math.max(i.startRow,c.startRow),h=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<=h;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}),k)),a.listenersToRemove.add(o.registerCommand(B,(n=>{const r=d();if(!Xe(r,e))return!1;if(Me(r))return a.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>G(e)));if(!G(l))return!1;if("string"==typeof n){const t=et(o,r,e);if(t)return Ze(t,e,[u(n)]),!0}}return!1}),k)),r&&a.listenersToRemove.add(o.registerCommand(D,(t=>{const n=d();if(!g(n)||!n.isCollapsed()||!Xe(n,e))return!1;const o=qe(n.anchor.getNode());if(null===o)return!1;Ve(t);const r=e.getCordsFromCellNode(o,a.table);return Ue(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),k)),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=Me(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>G(e)))&&null!==t(o.focus.getNode(),(e=>G(e)))||s;if(1!==n.length||!lt(n[0])||!i||null===r)return!1;const[a]=r,h=n[0],u=h.getChildren(),d=h.getFirstChildOrThrow().getChildrenSize(),f=h.getChildrenSize(),m=t(a.getNode(),(e=>G(e))),p=m&&t(m,(e=>te(e))),S=p&&t(p,(e=>lt(e)));if(!G(m)||!te(p)||!lt(S))return!1;const C=p.getIndexWithinParent(),w=Math.min(S.getChildrenSize()-1,C+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+d-1),N=Math.min(b,y),T=Math.min(C,w),x=Math.max(b,y),v=Math.max(C,w),E=S.getChildren();let O,M,R=0;for(let e=T;e<=v;e++){const t=E[e];if(!te(t))return!1;const n=u[R];if(!te(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(!G(n))return!1;const i=r[s];if(!G(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=Re();e.set(n[0].getKey(),O,M),_(e)}return!0}),k)),a.listenersToRemove.add(o.registerCommand(C,(()=>{const t=d(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=qe(l),c=qe(s),u=!(!i||!e.is(Ge(i))),d=!(!c||!e.is(Ge(c))),g=u!==d,m=u&&d,p=t.isBackward();if(g){const n=t.clone();d?n.focus.set(e.getParentOrThrow().getKey(),e.getIndexWithinParent(),"element"):n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element"),_(n),We(o,a)}else m&&(i.is(c)||(a.setAnchorCellForSelection(S(i)),a.setFocusCellForSelection(S(c),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();a.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&Me(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ae(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is(Ge(r)),s=w(n.anchorNode),i=s&&e.is(Ge(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(),_(r))}}}return t&&!t.is(n)&&(Me(t)||Me(n))&&a.tableSelection&&!a.tableSelection.is(n)?(Me(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!Me(t)&&Me(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Ie(t.table,(t=>{const n=t.elem;t.highlighted=!1,je(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&We(o,a),!1)}),k)),a.listenersToRemove.add(o.registerCommand(Y,(()=>{const t=d();if(!g(t)||!t.isCollapsed()||!Xe(t,e))return!1;const n=et(o,t,e);return!!n&&(Ze(n,e),!0)}),k)),a}function Pe(e){return e[Fe]}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 De(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 Le(e,t,n){const o=new Set(n?n.getNodes():[]);Ie(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,$e(e,t)):(t.highlighted=!1,je(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Ie(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 We(e,t){t.disableHighlightStyle(),Ie(t.table,(t=>{t.highlighted=!0,$e(e,t)}))}const Ue=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ze(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ze(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?ze(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ze(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)||Me(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function ze(e,t){t?e.selectStart():e.selectEnd()}const Je="172,206,247";function $e(e,t){const n=t.elem,o=w(n);G(o)||oe(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Je})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Je},0.85), rgba(${Je},0.85))`),n.style.setProperty("caret-color","transparent")}function je(e,t){const n=t.elem,o=w(n);G(o)||oe(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function qe(e){const n=t(e,G);return G(n)?n:null}function Ge(e){const n=t(e,lt);return lt(n)?n:null}function Qe(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=d();if(!Xe(i,r)){if("backward"===o&&g(i)&&i.isCollapsed()){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||!lt(c))&&(Ve(n),c.selectEnd(),!0)}return!1}if(g(i)&&i.isCollapsed()){const{anchor:c,focus:a}=i,h=t(c.getNode(),G),u=t(a.getNode(),G);if(!G(h)||!h.is(u))return!1;const d=Ge(h);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=De(t),Qe(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 h=i.getNodes();return(1!==h.length||!X(h[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,G);if(!G(l))return!1;const[i,c]=Te(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&<(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||lt(a))return!1;Ve(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(h.__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?h.getFirstChild():h.getLastChild();if(null==p)return!1;const S=e.getElementByKey(p.__key);if(null==S)return!1;const _=S.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){Ve(n);const e=r.getCordsFromCellNode(h,l.table);if(!n.shiftKey)return Ue(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(Me(i)){const{anchor:s,focus:c}=i,a=t(s.getNode(),G),h=t(c.getNode(),G),[u]=i.getNodes(),d=e.getElementByKey(u.getKey());if(!G(a)||!G(h)||!lt(u)||null==d)return!1;l.updateTableTableSelection(i);const g=De(d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Ve(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return Ye(l,u,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function Ve(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ze(e,t,n){const o=l();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function et(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=>G(e)));if(!i)return;const c=t(i,(e=>lt(e)));if(!lt(c)||!c.is(o))return;const[a,h]=Te(o,i,i),u=a[0][0],d=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=h,m=g===u.startRow&&f===u.startColumn,p=g===d.startRow&&f===d.startColumn;return m?"first":p?"last":void 0}class tt extends r{static getType(){return"table"}static clone(e){return new tt(e.__key)}static importDOM(){return{table:e=>({conversion:ot,priority:1})}}static importJSON(e){return rt()}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(!te(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 G(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 nt(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return De(n)}function ot(e){return{node:rt()}}function rt(){return a(new tt)}function lt(e){return e instanceof tt}export{Te as $computeTableMap,xe as $computeTableMapSkipCellCheck,q as $createTableCellNode,rt as $createTableNode,le as $createTableNodeWithDimensions,ee as $createTableRowNode,Re as $createTableSelection,_e as $deleteTableColumn,we as $deleteTableColumn__EXPERIMENTAL,Ce as $deleteTableRow__EXPERIMENTAL,nt as $getElementForTableNode,ve as $getNodeTriplet,se as $getTableCellNodeFromLexicalNode,Ee as $getTableCellNodeRect,he as $getTableColumnIndexFromTableCellNode,ce as $getTableNodeFromLexicalNodeOrThrow,ae as $getTableRowIndexFromTableCellNode,ie as $getTableRowNodeFromTableCellNodeOrThrow,pe as $insertTableColumn,Se as $insertTableColumn__EXPERIMENTAL,ge as $insertTableRow,me as $insertTableRow__EXPERIMENTAL,G as $isTableCellNode,lt as $isTableNode,te as $isTableRowNode,Me as $isTableSelection,de as $removeTableRowAtIndex,Ne as $unmergeCell,Q as INSERT_TABLE_COMMAND,J as TableCellHeaderStates,$ as TableCellNode,tt as TableNode,ke as TableObserver,V as TableRowNode,He as applyTableHandlers,Be as getDOMCellFromTarget,Pe as getTableObserverFromTableElement};
|
package/package.json
CHANGED
@@ -8,12 +8,12 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.16.0",
|
11
|
+
"version": "0.16.1-nightly.20240610.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/utils": "0.16.0",
|
16
|
-
"lexical": "0.16.0"
|
15
|
+
"@lexical/utils": "0.16.1-nightly.20240610.0",
|
16
|
+
"lexical": "0.16.1-nightly.20240610.0"
|
17
17
|
},
|
18
18
|
"repository": {
|
19
19
|
"type": "git",
|