@lexical/table 0.20.1-nightly.20241112.0 → 0.20.1-nightly.20241114.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LexicalTable.dev.js +184 -67
- package/LexicalTable.dev.mjs +182 -69
- package/LexicalTable.js.flow +1 -0
- package/LexicalTable.mjs +5 -1
- package/LexicalTable.node.mjs +5 -1
- package/LexicalTable.prod.js +93 -91
- package/LexicalTable.prod.mjs +1 -1
- package/LexicalTableNode.d.ts +4 -2
- package/LexicalTableObserver.d.ts +25 -0
- package/LexicalTableSelectionHelpers.d.ts +5 -4
- package/index.d.ts +3 -3
- package/package.json +4 -4
package/LexicalTable.prod.js
CHANGED
@@ -6,100 +6,102 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
'use strict';var h=require("@lexical/utils"),
|
10
|
-
class
|
11
|
-
|
9
|
+
'use strict';var h=require("@lexical/utils"),u=require("lexical"),aa=require("@lexical/clipboard");let ba=/^(\d+(?:\.\d+)?)px$/,y={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
10
|
+
class z extends u.ElementNode{static getType(){return"tablecell"}static clone(a){return new z(a.__headerState,a.__colSpan,a.__width,a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__rowSpan=a.__rowSpan;this.__backgroundColor=a.__backgroundColor}static importDOM(){return{td:()=>({conversion:ca,priority:0}),th:()=>({conversion:ca,priority:0})}}static importJSON(a){let b=a.rowSpan||1;return B(a.headerState,a.colSpan||1,a.width||void 0).setRowSpan(b).setBackgroundColor(a.backgroundColor||null)}constructor(a=
|
11
|
+
y.NO_STATUS,b=1,c,d){super(d);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}=
|
12
12
|
super.exportDOM(a));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
|
-
rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(a){let b=this.getWritable();b.__colSpan=a;return b}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(a){let b=this.getWritable();b.__rowSpan=a;return b}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a,b=
|
14
|
-
b.__width=a;return b}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){let b=this.getWritable();b.__backgroundColor=a;return b}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==
|
13
|
+
rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(a){let b=this.getWritable();b.__colSpan=a;return b}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(a){let b=this.getWritable();b.__rowSpan=a;return b}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a,b=y.BOTH){let c=this.getWritable();c.__headerState=a&b|c.__headerState&~b;return c}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){let b=this.getWritable();
|
14
|
+
b.__width=a;return b}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){let b=this.getWritable();b.__backgroundColor=a;return b}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==y.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||
|
15
15
|
a.__width!==this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
|
16
|
-
function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?
|
17
|
-
{if(C(p)&&!
|
16
|
+
function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?y.ROW:y.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=(a&&a.textDecoration||"").split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,f=c.includes("line-through"),e="italic"===a.fontStyle,g=c.includes("underline");return{after:m=>{0===m.length&&m.push(u.$createParagraphNode());return m},forChild:(m,p)=>
|
17
|
+
{if(C(p)&&!u.$isElementNode(m)){p=u.$createParagraphNode();if(u.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;u.$isTextNode(m)&&(d&&m.toggleFormat("bold"),f&&m.toggleFormat("strikethrough"),e&&m.toggleFormat("italic"),g&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function B(a,b=1,c){return u.$applyNodeReplacement(new z(a,b,c))}function C(a){return a instanceof z}let da=u.createCommand("INSERT_TABLE_COMMAND");var D;
|
18
18
|
function F(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}D=F&&F.__esModule&&Object.prototype.hasOwnProperty.call(F,"default")?F["default"]:F;let ea="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
19
|
-
class
|
20
|
-
a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function
|
21
|
-
function
|
22
|
-
let
|
23
|
-
function
|
24
|
-
|
25
|
-
function
|
19
|
+
class fa extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new fa(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:ha,priority:0})}}static importJSON(a){return I(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);h.addClassNamesToElement(b,
|
20
|
+
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 ha(a){let b=void 0;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:I(b)}}function I(a){return u.$applyNodeReplacement(new fa(a))}function K(a){return a instanceof fa}
|
21
|
+
function ia(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>L(b));if(L(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:f}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,f-1,b),below:c.getCellNodeFromCords(d,f+1,b),left:c.getCellNodeFromCords(d-1,f,b),right:c.getCellNodeFromCords(d+1,f,b)}}
|
22
|
+
let la=(a,b)=>a===y.BOTH||a===b?b:y.NO_STATUS;function N(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 O(a,b,c){let [d,f,e]=na(a,b,c);null===f&&D(207);null===e&&D(208);return[d,f,e]}
|
23
|
+
function na(a,b,c){function d(p){let r=f[p];void 0===r&&(f[p]=r=[]);return r}let f=[],e=null,g=null;a=a.getChildren();for(let p=0;p<a.length;p++){var m=a[p];K(m)||D(209);for(let r=m.getFirstChild(),v=0;null!=r;r=r.getNextSibling()){C(r)||D(147);for(m=d(p);void 0!==m[v];)v++;m={cell:r,startColumn:v,startRow:p};let {__rowSpan:w,__colSpan:l}=r;for(let k=0;k<w&&!(p+k>=a.length);k++){let n=d(p+k);for(let q=0;q<l;q++)n[v+q]=m}null!==b&&null===e&&b.is(r)&&(e=m);null!==c&&null===g&&c.is(r)&&(g=m)}}return[f,
|
24
|
+
e,g]}function P(a){a instanceof z||("__type"in a?(a=h.$findMatchingParent(a,C),C(a)||D(148)):(a=h.$findMatchingParent(a.getNode(),C),C(a)||D(148)));let b=a.getParent();K(b)||D(149);let c=b.getParent();L(c)||D(210);return[a,b,c]}
|
25
|
+
function oa(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var f=a[0].getChildren().length;let e=Array(d);for(var g=0;g<d;g++)e[g]=Array(f);for(f=0;f<d;f++){g=a[f].getChildren();let m=0;for(let p=0;p<g.length;p++){for(;e[f][m];)m++;let r=g[p],v=r.__rowSpan||1,w=r.__colSpan||1;for(let l=0;l<v;l++)for(let k=0;k<w;k++)e[f+l][m+k]=r;if(b===r)return{colSpan:w,columnIndex:m,rowIndex:f,rowSpan:v};m+=w}}return null}
|
26
26
|
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 Q(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;
|
27
|
-
this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b=0;this.getNodes().filter(C).forEach(c=>{c=c.getFirstChild();
|
28
|
-
|
29
|
-
Math.min(
|
30
|
-
this.set(this.tableKey,
|
31
|
-
q][
|
32
|
-
(f
|
33
|
-
class
|
34
|
-
Array.from(this.listenersToRemove).forEach(a=>a());this.listenersToRemove.clear()}trackTable(){let a=new MutationObserver(b=>{this.editor.
|
35
|
-
this.table=
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
function
|
44
|
-
function
|
45
|
-
function
|
46
|
-
let
|
47
|
-
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},
|
48
|
-
d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(
|
49
|
-
function
|
50
|
-
function
|
51
|
-
function
|
52
|
-
("up"===c&&!
|
53
|
-
"up"===c?
|
54
|
-
C(d)&&(d=h.$findMatchingParent(d,
|
55
|
-
C);if(!C(g)||!g.is(
|
56
|
-
|
57
|
-
C);
|
58
|
-
function
|
59
|
-
function
|
60
|
-
function
|
61
|
-
function
|
62
|
-
function
|
63
|
-
function
|
64
|
-
class
|
65
|
-
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}createDOM(a){let
|
66
|
-
|
67
|
-
|
68
|
-
a:null}
|
69
|
-
function
|
70
|
-
|
71
|
-
exports.$
|
72
|
-
exports.$
|
73
|
-
|
74
|
-
|
75
|
-
(
|
76
|
-
|
77
|
-
exports.$
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
27
|
+
this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b=0;this.getNodes().filter(C).forEach(c=>{c=c.getFirstChild();u.$isParagraphNode(c)&&(b|=c.getTextFormat())});return 0!==(b&u.TEXT_TYPE_TO_FORMAT[a])}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||D(151);u.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=
|
28
|
+
u.$getNodeByKey(this.anchor.key);C(a)||D(152);a=oa(a);null===a&&D(153);var b=u.$getNodeByKey(this.focus.key);C(b)||D(154);let c=oa(b);null===c&&D(155);b=Math.min(a.columnIndex,c.columnIndex);let d=Math.max(a.columnIndex+a.colSpan-1,c.columnIndex+c.colSpan-1),f=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex+a.rowSpan-1,c.rowIndex+c.rowSpan-1);return{fromX:Math.min(b,d),fromY:Math.min(f,a),toX:Math.max(b,d),toY:Math.max(f,a)}}getNodes(){function a(t){let {cell:x,startColumn:A,startRow:E}=t;r=
|
29
|
+
Math.min(r,A);v=Math.min(v,E);w=Math.max(w,A+x.__colSpan-1);l=Math.max(l,E+x.__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,C);c=h.$findMatchingParent(b,C);C(d)||D(152);C(c)||D(154);b=d.getParent();K(b)||D(156);b=b.getParent();L(b)||D(157);var f=c.getParents()[1];if(f!==b){if(b.isParentOf(c)){var e=f.getParent();null==e&&D(159);this.set(this.tableKey,c.getKey(),e.getKey())}else e=b.getParent(),null==e&&D(158),
|
30
|
+
this.set(this.tableKey,e.getKey(),c.getKey());return this.getNodes()}let [g,m,p]=O(b,d,c),r=Math.min(m.startColumn,p.startColumn),v=Math.min(m.startRow,p.startRow),w=Math.max(m.startColumn+m.cell.__colSpan-1,p.startColumn+p.cell.__colSpan-1),l=Math.max(m.startRow+m.cell.__rowSpan-1,p.startRow+p.cell.__rowSpan-1);c=r;d=v;f=r;for(var k=v;r<c||v<d||w>f||l>k;){if(r<c){var n=k-d;--c;for(var q=0;q<=n;q++)a(g[d+q][c])}if(v<d)for(n=f-c,--d,q=0;q<=n;q++)a(g[d][c+q]);if(w>f)for(n=k-d,f+=1,q=0;q<=n;q++)a(g[d+
|
31
|
+
q][f]);if(l>k)for(n=f-c,k+=1,q=0;q<=n;q++)a(g[k][c+q])}b=new Map([[b.getKey(),b]]);c=null;for(d=v;d<=l;d++)for(f=r;f<=w;f++){({cell:k}=g[d][f]);n=k.getParent();K(n)||D(160);n!==c&&b.set(n.getKey(),n);b.set(k.getKey(),k);for(e of qa(k))b.set(e.getKey(),e);c=n}e=Array.from(b.values());u.isCurrentlyReadOnlyMode()||(this._cachedNodes=e);return e}getTextContent(){let a=this.getNodes().filter(c=>C(c)),b="";for(let c=0;c<a.length;c++){let d=a[c],f=d.__parent,e=(a[c+1]||{}).__parent;b+=d.getTextContent()+
|
32
|
+
(e!==f?"\n":"\t")}return b}}function Q(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&&D(112);u.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}function ta(a,b=u.$getEditor()){let c=u.$getNodeByKey(a);L(c)||D(231,a);b=R(c,b.getElementByKey(a));null===b&&D(232,a);return{tableElement:b,tableNode:c}}
|
33
|
+
class ua{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.shouldCheckSelection=this.isSelecting=this.hasHijackedSelectionStyles=!1;this.abortController=new AbortController;this.listenerOptions={signal:this.abortController.signal};this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners");
|
34
|
+
Array.from(this.listenersToRemove).forEach(a=>a());this.listenersToRemove.clear()}$lookup(){return ta(this.tableNodeKey,this.editor)}trackTable(){let a=new MutationObserver(b=>{this.editor.getEditorState().read(()=>{let c=!1;for(let e=0;e<b.length;e++){const g=b[e].target.nodeName;if("TABLE"===g||"TBODY"===g||"THEAD"===g||"TR"===g){c=!0;break}}if(c){var {tableNode:d,tableElement:f}=this.$lookup();this.table=S(d,f)}},{editor:this.editor})});this.editor.getEditorState().read(()=>{let {tableNode:b,tableElement:c}=
|
35
|
+
this.$lookup();this.table=S(b,c);a.observe(c,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}clearHighlight(){let a=this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{let {tableNode:b,tableElement:c}=this.$lookup(),d=S(b,c);va(a,d,null);u.$setSelection(null);a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
|
36
|
+
void 0)})}enableHighlightStyle(){let a=this.editor;a.getEditorState().read(()=>{let {tableElement:b}=this.$lookup();h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1},{editor:a})}disableHighlightStyle(){let a=this.editor;a.getEditorState().read(()=>{let {tableElement:b}=this.$lookup();h.addClassNamesToElement(b,a._config.theme.tableSelection);this.hasHijackedSelectionStyles=!0},{editor:a})}updateTableTableSelection(a){if(null!==
|
37
|
+
a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();va(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return this.shouldCheckSelection?(this.shouldCheckSelection=!1,!0):!1}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var {tableNode:d}=
|
38
|
+
this.$lookup(),f=a.x;let e=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=ea?(c._window||window).getSelection():null;g&&g.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==f||this.anchorY!==e||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(f===this.focusX&&e===this.focusY)return;this.focusX=f;this.focusY=e;this.isHighlightingCells&&(f=u.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&
|
39
|
+
C(f)&&d.is(T(f))&&(d=f.getKey(),this.tableSelection=this.tableSelection.clone()||ra(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),u.$setSelection(this.tableSelection),c.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0),va(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=u.$getNearestNodeFromDOMNode(a.elem);
|
40
|
+
C(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();Q(b)||D(11);let c=u.$createRangeSelection(),d=c.anchor,f=c.focus,e=b.getNodes().filter(C),g=e[0].getFirstChild(),m=u.$isParagraphNode(g)?g.getFormatFlags(a,null):null;e.forEach(p=>{d.set(p.getKey(),0,"element");f.set(p.getKey(),p.getChildrenSize(),"element");c.formatText(a,m)});u.$setSelection(b);this.editor.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
|
41
|
+
void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!L(b))throw Error("Expected TableNode.");var c=u.$getSelection();Q(c)||D(11);c=c.getNodes().filter(C);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),u.$getRoot().selectStart()):(c.forEach(d=>{if(u.$isElementNode(d)){let f=u.$createParagraphNode(),e=u.$createTextNode();f.append(e);d.append(f);d.getChildren().forEach(g=>{g!==f&&g.remove()})}}),va(a,this.table,null),u.$setSelection(null),
|
42
|
+
a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))})}}function R(a,b){if(!b)return b;a="TABLE"===b.nodeName?b:a.getDOMSlot(b).element;"TABLE"!==a.nodeName&&D(233,b.nodeName);return a}function wa(a,b){null!==xa(a)&&D(205);a.__lexicalTableSelection=b}function xa(a){return a.__lexicalTableSelection||null}function ya(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
43
|
+
function S(a,b){var c=R(a,b);a=[];b={columns:0,domRows:a,rows:0};var d=c.querySelector("tr");let f=c=0;for(a.length=0;null!=d;){var e=d.nodeName;if("TD"===e||"TH"===e){e=d;e={elem:e,hasBackgroundColor:""!==e.style.backgroundColor,highlighted:!1,x:c,y:f};d._cell=e;let g=a[f];void 0===g&&(g=a[f]=[]);g[c]=e}else if(e=d.firstChild,null!=e){d=e;continue}e=d.nextSibling;if(null!=e)c++,d=e;else if(e=d.parentNode,null!=e){d=e.nextSibling;if(null==d)break;f++;c=0}}b.columns=c+1;b.rows=f+1;return b}
|
44
|
+
function va(a,b,c){let d=new Set(c?c.getNodes():[]);za(b,(f,e)=>{let g=f.elem;d.has(e)?(f.highlighted=!0,Aa(a,f)):(f.highlighted=!1,Ba(a,f),g.getAttribute("style")||g.removeAttribute("style"))})}function za(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let f=0;f<d.length;f++){let e=d[f];if(!e)continue;let g=u.$getNearestNodeFromDOMNode(e.elem);null!==g&&b(e,g,{x:f,y:c})}}}function Ca(a,b){b.disableHighlightStyle();za(b.table,c=>{c.highlighted=!0;Aa(a,c)})}
|
45
|
+
function Da(a,b){b.enableHighlightStyle();za(b.table,c=>{let d=c.elem;c.highlighted=!1;Ba(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
|
46
|
+
let Ea=(a,b,c,d,f)=>{const e="forward"===f;switch(f){case "backward":case "forward":return c!==(e?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(e?1:-1),d,a.table),e?a.selectStart():a.selectEnd()):d!==(e?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(e?0:a.table.columns-1,d+(e?1:-1),a.table),e?a.selectStart():a.selectEnd()):e?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==d?b.getCellNodeFromCordsOrThrow(c,d-1,a.table).selectEnd():b.selectPrevious(),!0;case "down":return d!==
|
47
|
+
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},Fa=(a,b,c,d,f)=>{const e="forward"===f;switch(f){case "backward":case "forward":return c!==(e?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(e?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
|
48
|
+
d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(u.$isRangeSelection(a)||Q(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
|
49
|
+
function Aa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);C(b)||D(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")}
|
50
|
+
function Ba(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);C(b)||D(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function V(a){a=h.$findMatchingParent(a,C);return C(a)?a:null}function T(a){a=h.$findMatchingParent(a,L);return L(a)?a:null}
|
51
|
+
function W(a,b,c,d,f){if(("up"===c||"down"===c)&&Ga(a))return!1;var e=u.$getSelection();if(!U(e,d)){if(u.$isRangeSelection(e)){if(e.isCollapsed()&&"backward"===c){c=e.anchor.type;d=e.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=e.anchor.getNode();if(!c)return!1;c=h.$findMatchingParent(c,r=>u.$isElementNode(r)&&!r.isInline());if(!c)return!1;c=c.getPreviousSibling();if(!c||!L(c))return!1;X(b);c.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c)){var g=e.focus.getNode();if(!e.isCollapsed()&&
|
52
|
+
("up"===c&&!e.isBackward()||"down"===c&&e.isBackward())){f=h.$findMatchingParent(g,r=>L(r));C(f)&&(f=h.$findMatchingParent(f,L));if(f!==d||!f)return!1;d="down"===c?f.getNextSibling():f.getPreviousSibling();if(!d)return!1;f=0;"up"===c&&u.$isElementNode(d)&&(f=d.getChildrenSize());a=d;"up"===c&&u.$isElementNode(d)&&(a=(c=d.getLastChild())?c:d,f=u.$isTextNode(a)?a.getTextContentSize():0);c=e.clone();c.focus.set(a.getKey(),f,u.$isTextNode(a)?"text":"element");u.$setSelection(c);X(b);return!0}if(u.$isRootOrShadowRoot(g)){if((b=
|
53
|
+
"up"===c?e.getNodes()[e.getNodes().length-1]:e.getNodes()[0])&&(b=h.$findMatchingParent(b,C))&&d.isParentOf(b)){c=d.getFirstDescendant();b=d.getLastDescendant();if(!c||!b)return!1;[c]=P(c);[b]=P(b);c=d.getCordsFromCellNode(c,f.table);b=d.getCordsFromCellNode(b,f.table);c=d.getDOMCellFromCordsOrThrow(c.x,c.y,f.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,f.table);f.setAnchorCellForSelection(c);f.setFocusCellForSelection(b,!0);return!0}return!1}d=h.$findMatchingParent(g,r=>u.$isElementNode(r)&&!r.isInline());
|
54
|
+
C(d)&&(d=h.$findMatchingParent(d,L));if(!d)return!1;d="down"===c?d.getNextSibling():d.getPreviousSibling();if(L(d)&&f.tableNodeKey===d.getKey()){f=d.getFirstDescendant();a=d.getLastDescendant();if(!f||!a)return!1;[d]=P(f);[f]=P(a);e=e.clone();e.focus.set(("up"===c?d:f).getKey(),"up"===c?0:f.getChildrenSize(),"element");X(b);u.$setSelection(e);return!0}}}"down"===c&&Ha(a)&&f.setShouldCheckSelection();return!1}if(u.$isRangeSelection(e)&&e.isCollapsed()){let {anchor:r,focus:v}=e;g=h.$findMatchingParent(r.getNode(),
|
55
|
+
C);var m=h.$findMatchingParent(v.getNode(),C);if(!C(g)||!g.is(m))return!1;m=T(g);if(m!==d&&null!=m){var p=R(m,a.getElementByKey(m.getKey()));if(null!=p)return f.table=S(m,p),W(a,b,c,m,f)}if("backward"===c||"forward"===c){f=r.type;a=r.offset;g=r.getNode();if(!g)return!1;e=e.getNodes();return 1===e.length&&u.$isDecoratorNode(e[0])?!1:Ja(f,a,g,c)?Ka(b,g,d,c):!1}e=a.getElementByKey(g.__key);m=a.getElementByKey(r.key);if(null==m||null==e)return!1;if("element"===r.type)e=m.getBoundingClientRect();else{e=
|
56
|
+
window.getSelection();if(null===e||0===e.rangeCount)return!1;e=e.getRangeAt(0).getBoundingClientRect()}m="up"===c?g.getFirstChild():g.getLastChild();if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>e.top-e.height:e.bottom+e.height>a.bottom){X(b);e=d.getCordsFromCellNode(g,f.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(e.x,e.y,f.table),f.setAnchorCellForSelection(b),f.setFocusCellForSelection(b,!0);else return Ea(f,d,e.x,e.y,
|
57
|
+
c);return!0}}else if(Q(e)){let {anchor:r,focus:v}=e;p=h.$findMatchingParent(r.getNode(),C);m=h.$findMatchingParent(v.getNode(),C);[g]=e.getNodes();L(g)||D(234);a=R(g,a.getElementByKey(g.getKey()));if(!C(p)||!C(m)||!L(g)||null==a)return!1;f.updateTableTableSelection(e);e=S(g,a);a=d.getCordsFromCellNode(p,e);a=d.getDOMCellFromCordsOrThrow(a.x,a.y,e);f.setAnchorCellForSelection(a);X(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,e),Fa(f,g,b.x,b.y,c);m.selectEnd();return!0}return!1}
|
58
|
+
function X(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}function Ga(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function Ja(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||La(a,b,c,d)}
|
59
|
+
function La(a,b,c,d){let f=h.$findMatchingParent(c,e=>u.$isElementNode(e)&&!e.isInline());if(!f)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===f.getPreviousSibling():null===f.getNextSibling())}
|
60
|
+
function Ka(a,b,c,d){var f=h.$findMatchingParent(b,C);if(!C(f))return!1;let [e,g]=O(c,f,f);f=e[0][0];let m=e[e.length-1][e[0].length-1],{startColumn:p,startRow:r}=g;if("backward"===d?p!==f.startColumn||r!==f.startRow:p!==m.startColumn||r!==m.startRow)return!1;b=Ma(b,d,c);if(!b||L(b))return!1;X(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
|
61
|
+
function Ma(a,b,c){if(a=h.$findMatchingParent(a,d=>u.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&L(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function Na(a,b,c){let d=u.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
|
62
|
+
function Oa(a,b,c){var d=c.getParent();if(d){var f=window.getSelection();if(f&&(f=f.anchorNode,d=a.getElementByKey(d.getKey()),a=R(c,a.getElementByKey(c.getKey())),f&&d&&a&&d.contains(f)&&!a.contains(f)&&(b=h.$findMatchingParent(b.anchor.getNode(),r=>C(r))))&&(a=h.$findMatchingParent(b,r=>L(r)),L(a)&&a.is(c))){var [e,g]=O(c,b,b);c=e[0][0];b=e[e.length-1][e[0].length-1];var {startRow:m,startColumn:p}=g;if(m===c.startRow&&p===c.startColumn)return"first";if(m===b.startRow&&p===b.startColumn)return"last"}}}
|
63
|
+
function Pa(a,b,c,d){if(a=a.querySelector("colgroup")){b=[];for(let f=0;f<c;f++){let e=document.createElement("col"),g=d&&d[f];g&&(e.style.width=`${g}px`);b.push(e)}a.replaceChildren(...b)}}function Qa(a,b,c){c?(h.addClassNamesToElement(a,b.theme.tableRowStriping),a.setAttribute("data-lexical-row-striping","true")):(h.removeClassNamesFromElement(a,b.theme.tableRowStriping),a.removeAttribute("data-lexical-row-striping"))}let Ra=new WeakSet;function Ha(a=u.$getEditor()){return Ra.has(a)}
|
64
|
+
class Sa extends u.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(a){let b=this.getWritable();b.__colWidths=a;return b}static clone(a){return new Sa(a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__colWidths=a.__colWidths;this.__rowStriping=a.__rowStriping}static importDOM(){return{table:()=>({conversion:Ta,priority:1})}}static importJSON(a){let b=Ua();b.__rowStriping=a.rowStriping||!1;b.__colWidths=a.colWidths;return b}constructor(a){super(a);
|
65
|
+
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&D(229);return super.getDOMSlot(a).withAfter(a.querySelector("colgroup"))}createDOM(a,b){let c=document.createElement("table"),d=document.createElement("colgroup");c.appendChild(d);Pa(c,a,this.getColumnCount(),this.getColWidths());u.setDOMUnmanaged(d);
|
66
|
+
h.addClassNamesToElement(c,a.theme.table);this.__rowStriping&&Qa(c,a,!0);return Ha(b)?(b=document.createElement("div"),(a=a.theme.tableScrollableWrapper)?h.addClassNamesToElement(b,a):b.style.cssText="overflow-x: auto;",b.appendChild(c),b):c}updateDOM(a,b,c){a.__rowStriping!==this.__rowStriping&&Qa(b,c,this.__rowStriping);Pa(b,c,this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{b&&h.isHTMLElement(b)&&"TABLE"!==b.nodeName&&(b=b.querySelector("table"));
|
67
|
+
if(!b||!h.isHTMLElement(b))return null;let c=b.querySelectorAll(":scope > tr");if(0<c.length){let d=document.createElement("tbody");d.append(...c);b.append(d)}return b}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var f=d[b];if(null!=f&&(f=f.findIndex(e=>{if(e)return{elem:e}=e,u.$getNearestNodeFromDOMNode(e)===a}),-1!==f))return{x:f,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];
|
68
|
+
if(null==b)return null;a=b[a<b.length?a:b.length-1];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 C(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);if(!a)throw Error("Node at cords not TableCellNode.");return a}getRowStriping(){return!!this.getLatest().__rowStriping}setRowStriping(a){this.getWritable().__rowStriping=
|
69
|
+
a}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){let a=this.getFirstChild();if(!a)return 0;let b=0;a.getChildren().forEach(c=>{C(c)&&(b+=c.getColSpan())});return b}}function Ta(a){let b=Ua();a.hasAttribute("data-lexical-row-striping")&&b.setRowStriping(!0);var c=a.querySelector(":scope > colgroup");if(c){a=[];for(let d of c.querySelectorAll(":scope > col")){c=d.style.width;if(!c||!ba.test(c)){a=void 0;break}a.push(parseFloat(c))}a&&b.setColWidths(a)}return{node:b}}
|
70
|
+
function Ua(){return u.$applyNodeReplacement(new Sa)}function L(a){return a instanceof Sa}exports.$computeTableMap=O;exports.$computeTableMapSkipCellCheck=na;exports.$createTableCellNode=B;exports.$createTableNode=Ua;
|
71
|
+
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Ua();for(let e=0;e<a;e++){let g=I();for(let m=0;m<b;m++){var f=y.NO_STATUS;"object"===typeof c?(0===e&&c.rows&&(f|=y.ROW),0===m&&c.columns&&(f|=y.COLUMN)):c&&(0===e&&(f|=y.ROW),0===m&&(f|=y.COLUMN));f=B(f);let p=u.$createParagraphNode();p.append(u.$createTextNode());f.append(p);g.append(f)}d.append(g)}return d};exports.$createTableRowNode=I;exports.$createTableSelection=ra;
|
72
|
+
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let f=0;f<c.length;f++){var d=c[f];if(K(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
|
73
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||D(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);var [f]=P(a);let [e,g,m]=O(d,c,f);var {startColumn:p}=g;let {startRow:r,startColumn:v}=m;b=Math.min(p,v);var w=Math.max(p+c.__colSpan-1,v+f.__colSpan-1);a=w-b+1;if(e[0].length===w-b+1)d.selectPrevious(),d.remove();else{var l=e.length;for(let k=0;k<l;k++)for(let n=b;n<=w;n++){let {cell:q,startColumn:t}=e[k][n];t<b?n===b&&q.setColSpan(q.__colSpan-
|
74
|
+
Math.min(a,q.__colSpan-(b-t))):t+q.__colSpan-1>w?n===w&&q.setColSpan(q.__colSpan-(w-t+1)):q.remove()}w=e[r];f=p>v?w[p+c.__colSpan]:w[v+f.__colSpan];void 0!==f?({cell:p}=f,N(p)):({cell:p}=v<p?w[v-1]:w[p-1],N(p));if(p=d.getColWidths())p=[...p],p.splice(b,a),d.setColWidths(p)}};
|
75
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||D(188);let [b,c]=a.isBackward()?[a.focus.getNode(),a.anchor.getNode()]:[a.anchor.getNode(),a.focus.getNode()],[d,,f]=P(b);var [e]=P(c);let [g,m,p]=O(f,d,e);({startRow:a}=m);var {startRow:r}=p;e=r+e.__rowSpan-1;if(g.length===e-a+1)f.remove();else{r=g[0].length;var v=g[e+1],w=f.getChildAtIndex(e+1);for(let k=e;k>=a;k--){for(var l=r-1;0<=l;l--){let {cell:n,startRow:q,startColumn:t}=g[k][l];if(t===l&&
|
76
|
+
(k===a&&q<a&&n.setRowSpan(n.__rowSpan-(q-a)),q>=a&&q+n.__rowSpan-1>e))if(n.setRowSpan(n.__rowSpan-(e-q+1)),null===w&&D(122),0===l)ma(w,n);else{let {cell:x}=v[l-1];x.insertAfter(n)}}l=f.getChildAtIndex(k);K(l)||D(206,String(k));l.remove()}void 0!==v?({cell:a}=v[0],N(a)):({cell:a}=g[a-1][0],N(a))}};exports.$findCellNode=V;exports.$findTableNode=T;exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());null===a&&D(230);return S(b,a)};exports.$getNodeTriplet=P;
|
77
|
+
exports.$getTableAndElementByKey=ta;exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>C(b));return C(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;
|
78
|
+
exports.$insertTableColumn=function(a,b,c=!0,d,f){let e=a.getChildren(),g=[];for(let r=0;r<e.length;r++){let v=e[r];if(K(v))for(let w=0;w<d;w++){var m=v.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];C(m)||D(12);let {left:l,right:k}=ka(m,f);var p=y.NO_STATUS;if(l&&l.hasHeaderState(y.ROW)||k&&k.hasHeaderState(y.ROW))p|=y.ROW;p=B(p);p.append(u.$createParagraphNode());g.push({newTableCell:p,targetCell:m})}}g.forEach(({newTableCell:r,targetCell:v})=>{c?
|
79
|
+
v.insertAfter(r):v.insertBefore(r)});return a};
|
80
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(w=y.NO_STATUS){w=B(w).append(u.$createParagraphNode());null===r&&(r=w);return w}var c=u.$getSelection();u.$isRangeSelection(c)||Q(c)||D(188);var d=c.anchor.getNode();c=c.focus.getNode();[d]=P(d);let [f,,e]=P(c),[g,m,p]=O(e,f,d);d=g.length;c=a?Math.max(m.startColumn,p.startColumn):Math.min(m.startColumn,p.startColumn);a=a?c+f.__colSpan-1:c-1;c=e.getFirstChild();K(c)||D(120);let r=null;var v=c;a:for(c=0;c<d;c++){0!==c&&(v=v.getNextSibling(),
|
81
|
+
K(v)||D(121));let w=g[c],l=la(w[0>a?0:a].cell.__headerState,y.ROW);if(0>a){ma(v,b(l));continue}let {cell:k,startColumn:n,startRow:q}=w[a];if(n+k.__colSpan-1<=a){let t=k,x=q,A=a;for(;x!==c&&1<t.__rowSpan;)if(A-=k.__colSpan,0<=A){let {cell:E,startRow:G}=w[A];t=E;x=G}else{v.append(b(l));continue a}t.insertAfter(b(l))}else k.setColSpan(k.__colSpan+1)}null!==r&&N(r);if(d=e.getColWidths())d=[...d],a=0>a?0:a,d.splice(a,0,d[a]),e.setColWidths(d);return r};
|
82
|
+
exports.$insertTableRow=function(a,b,c=!0,d,f){var e=a.getChildren();if(b>=e.length||0>b)throw Error("Table row target index out of range");b=e[b];if(K(b))for(e=0;e<d;e++){let m=b.getChildren(),p=m.length,r=I();for(let v=0;v<p;v++){var g=m[v];C(g)||D(12);let {above:w,below:l}=ka(g,f);g=y.NO_STATUS;let k=w&&w.getWidth()||l&&l.getWidth()||void 0;if(w&&w.hasHeaderState(y.COLUMN)||l&&l.hasHeaderState(y.COLUMN))g|=y.COLUMN;g=B(g,1,k);g.append(u.$createParagraphNode());r.append(g)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
|
82
83
|
return a};
|
83
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=
|
84
|
-
a=
|
84
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||Q(b)||D(188);b=b.focus.getNode();let [c,,d]=P(b),[f,e]=O(d,c,c);b=f[0].length;var {startRow:g}=e;if(a){a=g+c.__rowSpan-1;var m=f[a];g=I();for(var p=0;p<b;p++){let {cell:v,startRow:w}=m[p];if(w+v.__rowSpan-1<=a){var r=la(m[p].cell.__headerState,y.COLUMN);g.append(B(r).append(u.$createParagraphNode()))}else v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(a);K(b)||D(145);b.insertAfter(g);b=g}else{m=f[g];
|
85
|
+
a=I();for(p=0;p<b;p++){let {cell:v,startRow:w}=m[p];w===g?(r=la(m[p].cell.__headerState,y.COLUMN),a.append(B(r).append(u.$createParagraphNode()))):v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(g);K(b)||D(145);b.insertBefore(a);b=a}return b};exports.$isScrollableTablesActive=Ha;exports.$isTableCellNode=C;exports.$isTableNode=L;exports.$isTableRowNode=K;exports.$isTableSelection=Q;
|
85
86
|
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};
|
86
|
-
exports.$unmergeCell=function(){var a=
|
87
|
-
if(1<a){for(var
|
88
|
-
exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=
|
89
|
-
exports.applyTableHandlers=function(a,b,c,d){function
|
90
|
-
1)&&g.isSelecting)g.isSelecting=!1,
|
91
|
-
|
92
|
-
|
93
|
-
h.$findMatchingParent(
|
94
|
-
|
95
|
-
!0):!1};g.listenersToRemove.add(c.registerCommand(
|
96
|
-
|
97
|
-
|
98
|
-
a))return!1;if(Q(
|
99
|
-
|
100
|
-
!
|
101
|
-
for(
|
102
|
-
if(
|
103
|
-
g)):
|
104
|
-
(
|
105
|
-
g.listenersToRemove.add(c.registerCommand(
|
87
|
+
exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||D(188);a=a.anchor.getNode();let [b,c,d]=P(a);a=b.__colSpan;let f=b.__rowSpan;if(1!==a||1!==f){var [e,g]=O(d,b,b),{startColumn:m,startRow:p}=g,r=b.__headerState&y.COLUMN,v=Array.from({length:a},(t,x)=>{t=r;for(let A=0;0!==t&&A<e.length;A++)t&=e[A][x+m].cell.__headerState;return t}),w=b.__headerState&y.ROW,l=Array.from({length:f},(t,x)=>{t=w;for(let A=0;0!==t&&A<e[0].length;A++)t&=e[x+p][A].cell.__headerState;return t});
|
88
|
+
if(1<a){for(var k=1;k<a;k++)b.insertAfter(B(v[k]|l[0]).append(u.$createParagraphNode()));b.setColSpan(1)}if(1<f){let t;for(k=1;k<f;k++){var n=p+k;let x=e[n];t=(t||c).getNextSibling();K(t)||D(125);var q=null;for(let A=0;A<m;A++){let E=x[A],G=E.cell;E.startRow===n&&(q=G);1<G.__colSpan&&(A+=G.__colSpan-1)}if(null===q)for(q=a-1;0<=q;q--)ma(t,B(v[q]|l[k]).append(u.$createParagraphNode()));else for(n=a-1;0<=n;n--)q.insertAfter(B(v[n]|l[k]).append(u.$createParagraphNode()))}b.setRowSpan(1)}}};
|
89
|
+
exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=y;exports.TableCellNode=z;exports.TableNode=Sa;exports.TableObserver=ua;exports.TableRowNode=fa;
|
90
|
+
exports.applyTableHandlers=function(a,b,c,d){function f(l){l=a.getCordsFromCellNode(l,g.table);return a.getDOMCellFromCordsOrThrow(l.x,l.y,g.table)}let e=c.getRootElement();if(null===e)throw Error("No root element.");let g=new ua(c,a.getKey()),m=c._window||window,p=R(a,b);wa(p,g);g.listenersToRemove.add(()=>{var l=g;xa(p)===l&&delete p.__lexicalTableSelection});let r=()=>{const l=()=>{g.isSelecting=!1;m.removeEventListener("mouseup",l);m.removeEventListener("mousemove",k)},k=n=>{setTimeout(()=>{if(1!==
|
91
|
+
(n.buttons&1)&&g.isSelecting)g.isSelecting=!1,m.removeEventListener("mouseup",l),m.removeEventListener("mousemove",k);else{var q=ya(n.target);null===q||g.anchorX===q.x&&g.anchorY===q.y||(n.preventDefault(),g.setFocusCellForSelection(q))}},0)};return{onMouseMove:k,onMouseUp:l}};p.addEventListener("mousedown",l=>{setTimeout(()=>{if(0===l.button&&m){var k=ya(l.target);null!==k&&(X(l),g.setAnchorCellForSelection(k));var {onMouseUp:n,onMouseMove:q}=r();g.isSelecting=!0;m.addEventListener("mouseup",n,g.listenerOptions);
|
92
|
+
m.addEventListener("mousemove",q,g.listenerOptions)}},0)},g.listenerOptions);m.addEventListener("mousedown",l=>{0===l.button&&c.update(()=>{const k=u.$getSelection(),n=l.target;Q(k)&&k.tableKey===g.tableNodeKey&&e.contains(n)&&g.clearHighlight()})},g.listenerOptions);g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_DOWN_COMMAND,l=>W(c,l,"down",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_UP_COMMAND,l=>W(c,l,"up",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_LEFT_COMMAND,
|
93
|
+
l=>W(c,l,"backward",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_RIGHT_COMMAND,l=>W(c,l,"forward",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ESCAPE_COMMAND,l=>{var k=u.$getSelection();return Q(k)&&(k=h.$findMatchingParent(k.focus.getNode(),C),C(k))?(X(l),k.selectEnd(),!0):!1},u.COMMAND_PRIORITY_HIGH));let v=l=>()=>{var k=u.$getSelection();if(!U(k,a))return!1;if(Q(k))return g.clearText(),!0;if(u.$isRangeSelection(k)){var n=
|
94
|
+
h.$findMatchingParent(k.anchor.getNode(),t=>C(t));if(!C(n))return!1;var q=k.anchor.getNode();n=k.focus.getNode();q=a.isParentOf(q);n=a.isParentOf(n);if(q&&!n||n&&!q)return g.clearText(),!0;n=(k=h.$findMatchingParent(k.anchor.getNode(),t=>u.$isElementNode(t)))&&h.$findMatchingParent(k,t=>u.$isElementNode(t)&&C(t.getParent()));if(!u.$isElementNode(n)||!u.$isElementNode(k))return!1;if(l===u.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0}return!1};[u.DELETE_WORD_COMMAND,u.DELETE_LINE_COMMAND,
|
95
|
+
u.DELETE_CHARACTER_COMMAND].forEach(l=>{g.listenersToRemove.add(c.registerCommand(l,v(l),u.COMMAND_PRIORITY_CRITICAL))});let w=l=>{const k=u.$getSelection();if(!Q(k)&&!u.$isRangeSelection(k))return!1;const n=a.isParentOf(k.anchor.getNode()),q=a.isParentOf(k.focus.getNode());if(n!==q){l=n?"focus":"anchor";const {key:t,offset:x,type:A}=k[l];a[k[n?"anchor":"focus"].isBefore(k[l])?"selectPrevious":"selectNext"]()[l].set(t,x,A);return!1}return Q(k)?(l&&(l.preventDefault(),l.stopPropagation()),g.clearText(),
|
96
|
+
!0):!1};g.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,w,u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.KEY_DELETE_COMMAND,w,u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.CUT_COMMAND,l=>{let k=u.$getSelection();if(k){if(!Q(k)&&!u.$isRangeSelection(k))return!1;void aa.copyToClipboard(c,h.objectKlassEquals(l,ClipboardEvent)?l:null,aa.$getClipboardDataFromSelection(k));l=w(l);return u.$isRangeSelection(k)?(k.removeText(),!0):l}return!1},
|
97
|
+
u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,l=>{let k=u.$getSelection();if(!U(k,a))return!1;if(Q(k))return g.formatCells(l),!0;u.$isRangeSelection(k)&&(l=h.$findMatchingParent(k.anchor.getNode(),n=>C(n)),C(l));return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,l=>{var k=u.$getSelection();if(!Q(k)||!U(k,a))return!1;var n=k.anchor.getNode();k=k.focus.getNode();if(!C(n)||!C(k))return!1;let [q,t,
|
98
|
+
x]=O(a,n,k);n=Math.max(t.startRow,x.startRow);k=Math.max(t.startColumn,x.startColumn);var A=Math.min(t.startRow,x.startRow);let E=Math.min(t.startColumn,x.startColumn);for(;A<=n;A++)for(let J=E;J<=k;J++){var G=q[A][J].cell;G.setFormat(l);G=G.getChildren();for(let M=0;M<G.length;M++){let H=G[M];u.$isElementNode(H)&&!H.isInline()&&H.setFormat(l)}}return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,l=>{var k=u.$getSelection();if(!U(k,
|
99
|
+
a))return!1;if(Q(k))g.clearHighlight();else if(u.$isRangeSelection(k)){let n=h.$findMatchingParent(k.anchor.getNode(),q=>C(q));if(!C(n))return!1;if("string"===typeof l&&(k=Oa(c,k,a)))return Na(k,a,[u.$createTextNode(l)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));d&&g.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,l=>{var k=u.$getSelection();if(!u.$isRangeSelection(k)||!k.isCollapsed()||!U(k,a))return!1;k=V(k.anchor.getNode());if(null===k)return!1;X(l);k=a.getCordsFromCellNode(k,g.table);
|
100
|
+
Ea(g,a,k.x,k.y,l.shiftKey?"backward":"forward");return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,l=>{let {nodes:k,selection:n}=l;l=n.getStartEndPoints();var q=Q(n);q=u.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),H=>C(H))&&null!==h.$findMatchingParent(n.focus.getNode(),H=>C(H))||q;if(1!==k.length||
|
101
|
+
!L(k[0])||!q||null===l)return!1;var [t]=l,x=k[0];l=x.getChildren();q=x.getFirstChildOrThrow().getChildrenSize();x=x.getChildrenSize();var A=h.$findMatchingParent(t.getNode(),H=>C(H)),E=A&&h.$findMatchingParent(A,H=>K(H)),G=E&&h.$findMatchingParent(E,H=>L(H));if(!C(A)||!K(E)||!L(G))return!1;t=E.getIndexWithinParent();var J=Math.min(G.getChildrenSize()-1,t+x-1);x=A.getIndexWithinParent();A=Math.min(E.getChildrenSize()-1,x+q-1);q=Math.min(x,A);E=Math.min(t,J);x=Math.max(x,A);t=Math.max(t,J);G=G.getChildren();
|
102
|
+
for(J=0;E<=t;E++){A=G[E];if(!K(A))return!1;var M=l[J];if(!K(M))return!1;A=A.getChildren();M=M.getChildren();let H=0;for(let Y=q;Y<=x;Y++){let sa=A[Y];if(!C(sa))return!1;let Ia=M[H];if(!C(Ia))return!1;let Va=sa.getChildren();Ia.getChildren().forEach(Z=>{u.$isTextNode(Z)&&u.$createParagraphNode().append(Z);sa.append(Z)});Va.forEach(Z=>Z.remove());H++}J++}return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,()=>{let l=u.$getSelection(),k=u.$getPreviousSelection();
|
103
|
+
if(g.getAndClearShouldCheckSelection()&&u.$isRangeSelection(k)&&u.$isRangeSelection(l)&&l.isCollapsed()){var n=l.anchor.getNode(),q=a.getFirstChild();n=V(n);if(null!==n&&K(q)){let A=q.getFirstChild();if(C(A)&&!h.$findMatchingParent(n,E=>E.is(A)))return A.selectStart(),!0}}if(u.$isRangeSelection(l)){let {anchor:A,focus:E}=l;n=A.getNode();q=E.getNode();var t=V(n),x=V(q);let G=!(!t||!a.is(T(t))),J=!(!x||!a.is(T(x)));n=G!==J;let M=G&&J;q=l.isBackward();n?(n=l.clone(),J?([x]=O(a,x,x),t=x[0][0].cell,x=
|
104
|
+
x[x.length-1].at(-1).cell,n.focus.set(q?t.getKey():x.getKey(),q?t.getChildrenSize():x.getChildrenSize(),"element")):G&&([x]=O(a,t,t),t=x[0][0].cell,x=x[x.length-1].at(-1).cell,n.anchor.set(q?x.getKey():t.getKey(),q?x.getChildrenSize():0,"element")),u.$setSelection(n),Ca(c,g)):M&&!t.is(x)&&(g.setAnchorCellForSelection(f(t)),g.setFocusCellForSelection(f(x),!0),g.isSelecting||setTimeout(()=>{let {onMouseUp:H,onMouseMove:Y}=r();g.isSelecting=!0;m.addEventListener("mouseup",H);m.addEventListener("mousemove",
|
105
|
+
Y)},0))}else l&&Q(l)&&l.is(k)&&l.tableKey===a.getKey()&&(q=ea?(c._window||window).getSelection():null)&&q.anchorNode&&q.focusNode&&(n=(n=u.$getNearestNodeFromDOMNode(q.focusNode))&&!a.is(T(n)),t=(t=u.$getNearestNodeFromDOMNode(q.anchorNode))&&a.is(T(t)),n&&t&&0<q.rangeCount&&(n=u.$createRangeSelectionFromDom(q,c)))&&(n.anchor.set(a.getKey(),l.isBackward()?a.getChildrenSize():0,"element"),q.removeAllRanges(),u.$setSelection(n));if(l&&!l.is(k)&&(Q(l)||Q(k))&&g.tableSelection&&!g.tableSelection.is(k))return Q(l)&&
|
106
|
+
l.tableKey===g.tableNodeKey?g.updateTableTableSelection(l):!Q(l)&&Q(k)&&k.tableKey===g.tableNodeKey&&g.updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?Da(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&Ca(c,g);return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,()=>{var l=u.$getSelection();return u.$isRangeSelection(l)&&l.isCollapsed()&&U(l,a)?(l=Oa(c,l,a))?(Na(l,a),!0):!1:!1},u.COMMAND_PRIORITY_CRITICAL));
|
107
|
+
return g};exports.getDOMCellFromTarget=ya;exports.getTableElement=R;exports.getTableObserverFromTableElement=xa;exports.setScrollableTablesActive=function(a,b){b?Ra.add(a):Ra.delete(a)}
|