@lexical/table 0.17.1-nightly.20240822.0 → 0.17.1-nightly.20240823.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 +23 -16
- package/LexicalTable.dev.mjs +25 -18
- package/LexicalTable.prod.js +81 -80
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalTable.dev.js
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
|
11
11
|
var utils = require('@lexical/utils');
|
12
12
|
var lexical = require('lexical');
|
13
|
+
var clipboard = require('@lexical/clipboard');
|
13
14
|
|
14
15
|
/**
|
15
16
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
@@ -1739,8 +1740,10 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1739
1740
|
return false;
|
1740
1741
|
}
|
1741
1742
|
if ($isTableSelection(selection)) {
|
1742
|
-
event
|
1743
|
-
|
1743
|
+
if (event) {
|
1744
|
+
event.preventDefault();
|
1745
|
+
event.stopPropagation();
|
1746
|
+
}
|
1744
1747
|
tableObserver.clearText();
|
1745
1748
|
return true;
|
1746
1749
|
} else if (lexical.$isRangeSelection(selection)) {
|
@@ -1753,6 +1756,24 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1753
1756
|
};
|
1754
1757
|
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, $deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
|
1755
1758
|
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.KEY_DELETE_COMMAND, $deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
|
1759
|
+
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.CUT_COMMAND, event => {
|
1760
|
+
const selection = lexical.$getSelection();
|
1761
|
+
if (selection) {
|
1762
|
+
if (lexical.$isNodeSelection(selection)) {
|
1763
|
+
return false;
|
1764
|
+
}
|
1765
|
+
clipboard.copyToClipboard(editor, utils.objectKlassEquals(event, ClipboardEvent) ? event : null);
|
1766
|
+
if ($isTableSelection(selection)) {
|
1767
|
+
$deleteCellHandler(event);
|
1768
|
+
return true;
|
1769
|
+
} else if (lexical.$isRangeSelection(selection)) {
|
1770
|
+
$deleteCellHandler(event);
|
1771
|
+
selection.removeText();
|
1772
|
+
return true;
|
1773
|
+
}
|
1774
|
+
}
|
1775
|
+
return false;
|
1776
|
+
}, lexical.COMMAND_PRIORITY_CRITICAL));
|
1756
1777
|
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, payload => {
|
1757
1778
|
const selection = lexical.$getSelection();
|
1758
1779
|
if (!$isSelectionInTable(selection, tableNode)) {
|
@@ -1878,8 +1899,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1878
1899
|
const toY = Math.max(startY, stopY);
|
1879
1900
|
const gridRowNodes = gridNode.getChildren();
|
1880
1901
|
let newRowIdx = 0;
|
1881
|
-
let newAnchorCellKey;
|
1882
|
-
let newFocusCellKey;
|
1883
1902
|
for (let r = fromY; r <= toY; r++) {
|
1884
1903
|
const currentGridRowNode = gridRowNodes[r];
|
1885
1904
|
if (!$isTableRowNode(currentGridRowNode)) {
|
@@ -1901,11 +1920,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1901
1920
|
if (!$isTableCellNode(newGridCellNode)) {
|
1902
1921
|
return false;
|
1903
1922
|
}
|
1904
|
-
if (r === fromY && c === fromX) {
|
1905
|
-
newAnchorCellKey = currentGridCellNode.getKey();
|
1906
|
-
} else if (r === toY && c === toX) {
|
1907
|
-
newFocusCellKey = currentGridCellNode.getKey();
|
1908
|
-
}
|
1909
1923
|
const originalChildren = currentGridCellNode.getChildren();
|
1910
1924
|
newGridCellNode.getChildren().forEach(child => {
|
1911
1925
|
if (lexical.$isTextNode(child)) {
|
@@ -1921,11 +1935,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1921
1935
|
}
|
1922
1936
|
newRowIdx++;
|
1923
1937
|
}
|
1924
|
-
if (newAnchorCellKey && newFocusCellKey) {
|
1925
|
-
const newTableSelection = $createTableSelection();
|
1926
|
-
newTableSelection.set(nodes[0].getKey(), newAnchorCellKey, newFocusCellKey);
|
1927
|
-
lexical.$setSelection(newTableSelection);
|
1928
|
-
}
|
1929
1938
|
return true;
|
1930
1939
|
}, lexical.COMMAND_PRIORITY_CRITICAL));
|
1931
1940
|
tableObserver.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, () => {
|
@@ -1954,8 +1963,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1954
1963
|
const firstCell = tableMap[0][0].cell;
|
1955
1964
|
const lastCell = tableMap[tableMap.length - 1].at(-1).cell;
|
1956
1965
|
newSelection.focus.set(isBackward ? firstCell.getKey() : lastCell.getKey(), isBackward ? firstCell.getChildrenSize() : lastCell.getChildrenSize(), 'element');
|
1957
|
-
} else {
|
1958
|
-
newSelection.anchor.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() + 1 : tableNode.getIndexWithinParent(), 'element');
|
1959
1966
|
}
|
1960
1967
|
lexical.$setSelection(newSelection);
|
1961
1968
|
$addHighlightStyleToTable(editor, tableObserver);
|
package/LexicalTable.dev.mjs
CHANGED
@@ -6,8 +6,9 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, isHTMLElement } from '@lexical/utils';
|
10
|
-
import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode } from 'lexical';
|
9
|
+
import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement } from '@lexical/utils';
|
10
|
+
import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, $isNodeSelection, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode } from 'lexical';
|
11
|
+
import { copyToClipboard } from '@lexical/clipboard';
|
11
12
|
|
12
13
|
/**
|
13
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
@@ -1737,8 +1738,10 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1737
1738
|
return false;
|
1738
1739
|
}
|
1739
1740
|
if ($isTableSelection(selection)) {
|
1740
|
-
event
|
1741
|
-
|
1741
|
+
if (event) {
|
1742
|
+
event.preventDefault();
|
1743
|
+
event.stopPropagation();
|
1744
|
+
}
|
1742
1745
|
tableObserver.clearText();
|
1743
1746
|
return true;
|
1744
1747
|
} else if ($isRangeSelection(selection)) {
|
@@ -1751,6 +1754,24 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1751
1754
|
};
|
1752
1755
|
tableObserver.listenersToRemove.add(editor.registerCommand(KEY_BACKSPACE_COMMAND, $deleteCellHandler, COMMAND_PRIORITY_CRITICAL));
|
1753
1756
|
tableObserver.listenersToRemove.add(editor.registerCommand(KEY_DELETE_COMMAND, $deleteCellHandler, COMMAND_PRIORITY_CRITICAL));
|
1757
|
+
tableObserver.listenersToRemove.add(editor.registerCommand(CUT_COMMAND, event => {
|
1758
|
+
const selection = $getSelection();
|
1759
|
+
if (selection) {
|
1760
|
+
if ($isNodeSelection(selection)) {
|
1761
|
+
return false;
|
1762
|
+
}
|
1763
|
+
copyToClipboard(editor, objectKlassEquals(event, ClipboardEvent) ? event : null);
|
1764
|
+
if ($isTableSelection(selection)) {
|
1765
|
+
$deleteCellHandler(event);
|
1766
|
+
return true;
|
1767
|
+
} else if ($isRangeSelection(selection)) {
|
1768
|
+
$deleteCellHandler(event);
|
1769
|
+
selection.removeText();
|
1770
|
+
return true;
|
1771
|
+
}
|
1772
|
+
}
|
1773
|
+
return false;
|
1774
|
+
}, COMMAND_PRIORITY_CRITICAL));
|
1754
1775
|
tableObserver.listenersToRemove.add(editor.registerCommand(FORMAT_TEXT_COMMAND, payload => {
|
1755
1776
|
const selection = $getSelection();
|
1756
1777
|
if (!$isSelectionInTable(selection, tableNode)) {
|
@@ -1876,8 +1897,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1876
1897
|
const toY = Math.max(startY, stopY);
|
1877
1898
|
const gridRowNodes = gridNode.getChildren();
|
1878
1899
|
let newRowIdx = 0;
|
1879
|
-
let newAnchorCellKey;
|
1880
|
-
let newFocusCellKey;
|
1881
1900
|
for (let r = fromY; r <= toY; r++) {
|
1882
1901
|
const currentGridRowNode = gridRowNodes[r];
|
1883
1902
|
if (!$isTableRowNode(currentGridRowNode)) {
|
@@ -1899,11 +1918,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1899
1918
|
if (!$isTableCellNode(newGridCellNode)) {
|
1900
1919
|
return false;
|
1901
1920
|
}
|
1902
|
-
if (r === fromY && c === fromX) {
|
1903
|
-
newAnchorCellKey = currentGridCellNode.getKey();
|
1904
|
-
} else if (r === toY && c === toX) {
|
1905
|
-
newFocusCellKey = currentGridCellNode.getKey();
|
1906
|
-
}
|
1907
1921
|
const originalChildren = currentGridCellNode.getChildren();
|
1908
1922
|
newGridCellNode.getChildren().forEach(child => {
|
1909
1923
|
if ($isTextNode(child)) {
|
@@ -1919,11 +1933,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1919
1933
|
}
|
1920
1934
|
newRowIdx++;
|
1921
1935
|
}
|
1922
|
-
if (newAnchorCellKey && newFocusCellKey) {
|
1923
|
-
const newTableSelection = $createTableSelection();
|
1924
|
-
newTableSelection.set(nodes[0].getKey(), newAnchorCellKey, newFocusCellKey);
|
1925
|
-
$setSelection(newTableSelection);
|
1926
|
-
}
|
1927
1936
|
return true;
|
1928
1937
|
}, COMMAND_PRIORITY_CRITICAL));
|
1929
1938
|
tableObserver.listenersToRemove.add(editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
@@ -1952,8 +1961,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1952
1961
|
const firstCell = tableMap[0][0].cell;
|
1953
1962
|
const lastCell = tableMap[tableMap.length - 1].at(-1).cell;
|
1954
1963
|
newSelection.focus.set(isBackward ? firstCell.getKey() : lastCell.getKey(), isBackward ? firstCell.getChildrenSize() : lastCell.getChildrenSize(), 'element');
|
1955
|
-
} else {
|
1956
|
-
newSelection.anchor.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() + 1 : tableNode.getIndexWithinParent(), 'element');
|
1957
1964
|
}
|
1958
1965
|
$setSelection(newSelection);
|
1959
1966
|
$addHighlightStyleToTable(editor, tableObserver);
|
package/LexicalTable.prod.js
CHANGED
@@ -6,91 +6,92 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
'use strict';var h=require("@lexical/utils"),
|
10
|
-
class y extends
|
9
|
+
'use strict';var h=require("@lexical/utils"),u=require("lexical"),aa=require("@lexical/clipboard");let ba=/^(\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:ca,priority:0}),th:()=>({conversion:ca,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=A(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
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
|
16
|
-
!
|
17
|
-
class
|
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
|
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.");}
|
20
|
-
function
|
21
|
-
let
|
22
|
-
function
|
23
|
-
function Q(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,
|
24
|
-
function
|
25
|
-
class
|
26
|
-
this._cachedNodes=null}clone(){return new
|
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(
|
28
|
-
|
29
|
-
g.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=
|
30
|
-
this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function R(a){return a instanceof
|
31
|
-
class
|
15
|
+
function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=A("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=a.textDecoration.split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),f="italic"===a.fontStyle,g=c.includes("underline");return{after:m=>{0===m.length&&m.push(u.$createParagraphNode());return m},forChild:(m,q)=>{if(B(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"),f&&m.toggleFormat("italic"),g&&m.toggleFormat("underline"));q.append(m);return q}return m},node:b}}function A(a,b=1,c){return u.$applyNodeReplacement(new y(a,b,c))}function B(a){return a instanceof y}let da=u.createCommand("INSERT_TABLE_COMMAND");
|
17
|
+
class D extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new D(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:ea,priority:0})}}static importJSON(a){return E(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
|
+
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 ea(a){let b=void 0;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:E(b)}}function E(a){return u.$applyNodeReplacement(new D(a))}function I(a){return a instanceof D}var J;
|
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 fa="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
20
|
+
function ha(a){a=h.$findMatchingParent(a,b=>I(b));if(I(a))return a;throw Error("Expected table cell to be inside of table row.");}function ia(a){a=h.$findMatchingParent(a,b=>N(b));if(N(a))return a;throw Error("Expected table cell to be inside of table.");}function ja(a,b){let c=ia(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 ka=(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 la(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function P(a,b,c){let [d,e,f]=oa(a,b,c);null===e&&J(110);null===f&&J(111);return[d,e,f]}
|
22
|
+
function oa(a,b,c){let d=[],e=null,f=null;a=a.getChildren();for(let r=0;r<a.length;r++){var g=a[r];I(g)||J(146);var m=g.getChildren();g=0;for(let w of m){for(B(w)||J(147);void 0!==d[r]&&void 0!==d[r][g];)g++;m=r;var q=g,p=w;let k={cell:p,startColumn:q,startRow:m},l=p.__rowSpan,n=p.__colSpan;for(let t=0;t<l;t++){void 0===d[m+t]&&(d[m+t]=[]);for(let v=0;v<n;v++)d[m+t][q+v]=k}null!==b&&b.is(p)&&(e=k);null!==c&&c.is(p)&&(f=k);g+=w.__colSpan}}return[d,e,f]}
|
23
|
+
function Q(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,B),B(a)||J(148)):(a=h.$findMatchingParent(a.getNode(),B),B(a)||J(148)));let b=a.getParent();I(b)||J(149);let c=b.getParent();N(c)||J(150);return[a,b,c]}
|
24
|
+
function pa(a){let [b,,c]=Q(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let f=Array(d);for(var g=0;g<d;g++)f[g]=Array(e);for(e=0;e<d;e++){g=a[e].getChildren();let m=0;for(let q=0;q<g.length;q++){for(;f[e][m];)m++;let p=g[q],r=p.__rowSpan||1,w=p.__colSpan||1;for(let k=0;k<r;k++)for(let l=0;l<w;l++)f[e+k][m+l]=p;if(b===p)return{colSpan:w,columnIndex:m,rowIndex:e,rowSpan:r};m+=w}}return null}
|
25
|
+
class qa{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
|
+
this._cachedNodes=null}clone(){return new qa(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);B(a)||J(152);a=pa(a);null===a&&J(153);var b=u.$getNodeByKey(this.focus.key);B(b)||J(154);let c=pa(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(t){let {cell:v,startColumn:z,startRow:C}=t;q=Math.min(q,z);p=Math.min(p,C);r=Math.max(r,z+v.__colSpan-1);w=Math.max(w,C+v.__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,B);c=h.$findMatchingParent(b,
|
28
|
+
B);B(d)||J(152);B(c)||J(154);b=d.getParent();I(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 [f,g,m]=P(b,d,c),q=Math.min(g.startColumn,m.startColumn),p=Math.min(g.startRow,m.startRow),r=Math.max(g.startColumn+g.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),w=Math.max(g.startRow+
|
29
|
+
g.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=p;e=q;for(var k=p;q<c||p<d||r>e||w>k;){if(q<c){var l=k-d;--c;for(var n=0;n<=l;n++)a(f[d+n][c])}if(p<d)for(l=e-c,--d,n=0;n<=l;n++)a(f[d][c+n]);if(r>e)for(l=k-d,e+=1,n=0;n<=l;n++)a(f[d+n][e]);if(w>k)for(l=e-c,k+=1,n=0;n<=l;n++)a(f[k][c+n])}b=[b];c=null;for(d=p;d<=w;d++)for(e=q;e<=r;e++)({cell:k}=f[d][e]),l=k.getParent(),I(l)||J(160),l!==c&&b.push(l),b.push(k,...ra(k)),c=l;u.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
|
30
|
+
this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function R(a){return a instanceof qa}function sa(){let a=u.$createPoint("root",0,"element"),b=u.$createPoint("root",0,"element");return new qa("root",a,b)}function ra(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
|
+
class ta{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,{attributes:!0,childList:!0,
|
33
|
-
subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=
|
34
|
-
b,null);
|
35
|
-
h.addClassNamesToElement(b,a._config.theme.tableSelection);this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();
|
36
|
-
if(!N(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");var e=a.x;let f=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=
|
37
|
-
e;this.focusY=f;this.isHighlightingCells&&(e=
|
38
|
-
!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=
|
39
|
-
"element"),c.formatText(a))});
|
40
|
-
e.append(f);d.append(e);d.getChildren().forEach(g=>{g!==e&&g.remove()})}}),
|
33
|
+
subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=u.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=S(b);T(a,
|
34
|
+
b,null);u.$setSelection(null);a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");
|
35
|
+
h.addClassNamesToElement(b,a._config.theme.tableSelection);this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();T(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=u.$getNodeByKey(this.tableNodeKey);
|
36
|
+
if(!N(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");var e=a.x;let f=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=fa?(c._window||window).getSelection():null;g&&g.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&f===this.focusY)return;this.focusX=
|
37
|
+
e;this.focusY=f;this.isHighlightingCells&&(e=u.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&B(e)&&d.is(U(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||sa(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),u.$setSelection(this.tableSelection),c.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0),T(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=
|
38
|
+
!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=u.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():sa(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();R(b)||J(11);let c=u.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(f=>{B(f)&&0!==f.getTextContentSize()&&(d.set(f.getKey(),0,"element"),e.set(f.getKey(),f.getChildrenSize(),
|
39
|
+
"element"),c.formatText(a))});u.$setSelection(b);this.editor.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");var c=u.$getSelection();R(c)||J(11);c=c.getNodes().filter(B);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),u.$getRoot().selectStart()):(c.forEach(d=>{if(u.$isElementNode(d)){let e=u.$createParagraphNode(),f=u.$createTextNode();
|
40
|
+
e.append(f);d.append(e);d.getChildren().forEach(g=>{g!==e&&g.remove()})}}),T(a,this.table,null),u.$setSelection(null),a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))})}}function ua(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
41
41
|
function S(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.firstChild;let e=a=0;for(b.length=0;null!=d;){var f=d.nodeName;if("TD"===f||"TH"===f){f=d;f={elem:f,hasBackgroundColor:""!==f.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=f;let g=b[e];void 0===g&&(g=b[e]=[]);g[a]=f}else if(f=d.firstChild,null!=f){d=f;continue}f=d.nextSibling;if(null!=f)a++,d=f;else if(f=d.parentNode,null!=f){d=f.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
|
42
|
-
function
|
42
|
+
function T(a,b,c){let d=new Set(c?c.getNodes():[]);va(b,(e,f)=>{let g=e.elem;d.has(f)?(e.highlighted=!0,wa(a,e)):(e.highlighted=!1,xa(a,e),g.getAttribute("style")||g.removeAttribute("style"))})}function va(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let f=d[e];if(!f)continue;let g=u.$getNearestNodeFromDOMNode(f.elem);null!==g&&b(f,g,{x:e,y:c})}}}function ya(a,b){b.disableHighlightStyle();va(b.table,c=>{c.highlighted=!0;wa(a,c)})}
|
43
43
|
function za(a,b){b.enableHighlightStyle();va(b.table,c=>{let d=c.elem;c.highlighted=!1;xa(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
|
44
|
-
let
|
45
|
-
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},
|
46
|
-
d+1,a.table)),!0):!1;default:return!1}};function
|
47
|
-
function wa(a,b){a=b.elem;b=
|
48
|
-
function xa(a,b){a=b.elem;b=
|
49
|
-
function
|
50
|
-
f.getNodes()[0])&&(c=h.$findMatchingParent(c,
|
51
|
-
d.getPreviousSibling();if(N(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();d=d.getLastDescendant();if(!e||!d)return!1;[e]=Q(e);[d]=Q(d);b=f.clone();b.focus.set(("up"===c?e:d).getKey(),"up"===c?0:d.getChildrenSize(),"element");
|
52
|
-
if(null!=
|
53
|
-
if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>f.top-f.height:f.bottom+f.height>a.bottom){Z(b);f=d.getCordsFromCellNode(g,e.table);if(b.shiftKey)d=d.getDOMCellFromCordsOrThrow(f.x,f.y,e.table),e.setAnchorCellForSelection(d),e.setFocusCellForSelection(d,!0);else return
|
54
|
-
a.getElementByKey(g.getKey());if(!
|
55
|
-
function
|
56
|
-
function
|
57
|
-
function
|
58
|
-
function
|
59
|
-
function
|
60
|
-
class
|
61
|
-
e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!
|
62
|
-
-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<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=
|
63
|
-
b,c);if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function
|
64
|
-
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=
|
65
|
-
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(
|
66
|
-
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=
|
67
|
-
Math.min(
|
68
|
-
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=
|
69
|
-
1>a))if(
|
70
|
-
exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>
|
71
|
-
exports.$insertTableColumn=function(a,b,c=!0,d,e){let f=a.getChildren(),g=[];for(let p=0;p<f.length;p++){let
|
72
|
-
|
73
|
-
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(
|
74
|
-
|
75
|
-
exports.$insertTableRow=function(a,b,c=!0,d,e){var f=a.getChildren();if(b>=f.length||0>b)throw Error("Table row target index out of range");b=f[b];if(
|
44
|
+
let Ba=(a,b,c,d,e)=>{const f="forward"===e;switch(e){case "backward":case "forward":return c!==(f?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(f?1:-1),d,a.table),f?a.selectStart():a.selectEnd()):d!==(f?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(f?0:a.table.columns-1,d+(f?1:-1),a.table),f?a.selectStart():a.selectEnd()):f?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!==
|
45
|
+
a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},Ca=(a,b,c,d,e)=>{const f="forward"===e;switch(e){case "backward":case "forward":return c!==(f?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(f?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,
|
46
|
+
d+1,a.table)),!0):!1;default:return!1}};function V(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
|
+
function wa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);B(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
|
+
function xa(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);B(b)||J(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function X(a){a=h.$findMatchingParent(a,B);return B(a)?a:null}function U(a){a=h.$findMatchingParent(a,N);return N(a)?a:null}
|
49
|
+
function Y(a,b,c,d,e){if(("up"===c||"down"===c)&&Da(a))return!1;var f=u.$getSelection();if(!V(f,d)){if(u.$isRangeSelection(f)){if(f.isCollapsed()&&"backward"===c){e=f.anchor.type;d=f.anchor.offset;if("element"!==e&&("text"!==e||0!==d))return!1;e=f.anchor.getNode();if(!e)return!1;e=h.$findMatchingParent(e,p=>u.$isElementNode(p)&&!p.isInline());if(!e)return!1;e=e.getPreviousSibling();if(!e||!N(e))return!1;Z(b);e.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c))if(b=f.focus.getNode(),u.$isRootOrShadowRoot(b)){if((c=
|
50
|
+
f.getNodes()[0])&&(c=h.$findMatchingParent(c,B))&&d.isParentOf(c)){b=d.getFirstDescendant();c=d.getLastDescendant();if(!b||!c)return!1;[b]=Q(b);[c]=Q(c);b=d.getCordsFromCellNode(b,e.table);c=d.getCordsFromCellNode(c,e.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,e.table);d=d.getDOMCellFromCordsOrThrow(c.x,c.y,e.table);e.setAnchorCellForSelection(b);e.setFocusCellForSelection(d,!0);return!0}}else{d=h.$findMatchingParent(b,p=>u.$isElementNode(p)&&!p.isInline());if(!d)return!1;d="down"===c?d.getNextSibling():
|
51
|
+
d.getPreviousSibling();if(N(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();d=d.getLastDescendant();if(!e||!d)return!1;[e]=Q(e);[d]=Q(d);b=f.clone();b.focus.set(("up"===c?e:d).getKey(),"up"===c?0:d.getChildrenSize(),"element");u.$setSelection(b);return!0}}}return!1}if(u.$isRangeSelection(f)&&f.isCollapsed()){let {anchor:p,focus:r}=f;var g=h.$findMatchingParent(p.getNode(),B),m=h.$findMatchingParent(r.getNode(),B);if(!B(g)||!g.is(m))return!1;m=U(g);if(m!==d&&null!=m){var q=a.getElementByKey(m.getKey());
|
52
|
+
if(null!=q)return e.table=S(q),Y(a,b,c,m,e)}if("backward"===c||"forward"===c){e=p.type;a=p.offset;g=p.getNode();if(!g)return!1;f=f.getNodes();return 1===f.length&&u.$isDecoratorNode(f[0])?!1:Ea(e,a,g,c)?Fa(b,g,d,c):!1}f=a.getElementByKey(g.__key);m=a.getElementByKey(p.key);if(null==m||null==f)return!1;if("element"===p.type)f=m.getBoundingClientRect();else{f=window.getSelection();if(null===f||0===f.rangeCount)return!1;f=f.getRangeAt(0).getBoundingClientRect()}m="up"===c?g.getFirstChild():g.getLastChild();
|
53
|
+
if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>f.top-f.height:f.bottom+f.height>a.bottom){Z(b);f=d.getCordsFromCellNode(g,e.table);if(b.shiftKey)d=d.getDOMCellFromCordsOrThrow(f.x,f.y,e.table),e.setAnchorCellForSelection(d),e.setFocusCellForSelection(d,!0);else return Ba(e,d,f.x,f.y,c);return!0}}else if(R(f)){let {anchor:p,focus:r}=f;q=h.$findMatchingParent(p.getNode(),B);m=h.$findMatchingParent(r.getNode(),B);[g]=f.getNodes();a=
|
54
|
+
a.getElementByKey(g.getKey());if(!B(q)||!B(m)||!N(g)||null==a)return!1;e.updateTableTableSelection(f);f=S(a);a=d.getCordsFromCellNode(q,f);a=d.getDOMCellFromCordsOrThrow(a.x,a.y,f);e.setAnchorCellForSelection(a);Z(b);if(b.shiftKey)return d=d.getCordsFromCellNode(m,f),Ca(e,g,d.x,d.y,c);m.selectEnd();return!0}return!1}function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
|
55
|
+
function Da(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function Ea(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||Ga(a,b,c,d)}
|
56
|
+
function Ga(a,b,c,d){let e=h.$findMatchingParent(c,f=>u.$isElementNode(f)&&!f.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())}
|
57
|
+
function Fa(a,b,c,d){var e=h.$findMatchingParent(b,B);if(!B(e))return!1;let [f,g]=P(c,e,e);e=f[0][0];let m=f[f.length-1][f[0].length-1],{startColumn:q,startRow:p}=g;if("backward"===d?q!==e.startColumn||p!==e.startRow:q!==m.startColumn||p!==m.startRow)return!1;b=Ha(b,d,c);if(!b||N(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
|
58
|
+
function Ha(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 Ia(a,b,c){let d=u.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
|
59
|
+
function Ja(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=>B(q)))&&(a=h.$findMatchingParent(b,q=>N(q)),N(a)&&a.is(c))){var [e,f]=P(c,b,b);c=e[0][0];b=e[e.length-1][e[0].length-1];var {startRow:g,startColumn:m}=f;if(g===c.startRow&&m===c.startColumn)return"first";if(g===b.startRow&&m===b.startColumn)return"last"}}
|
60
|
+
class Ka extends u.ElementNode{static getType(){return"table"}static clone(a){return new Ka(a.__key)}static importDOM(){return{table:()=>({conversion:La,priority:1})}}static importJSON(){return Ma()}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"),
|
61
|
+
e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!I(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let f=0;f<b;f++){let g=document.createElement("col");d.append(g)}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(f=>{if(f)return{elem:f}=f,u.$getNearestNodeFromDOMNode(f)===a}),
|
62
|
+
-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<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 B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,
|
63
|
+
b,c);if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function La(){return{node:Ma()}}function Ma(){return u.$applyNodeReplacement(new Ka)}function N(a){return a instanceof Ka}exports.$computeTableMap=P;exports.$computeTableMapSkipCellCheck=oa;exports.$createTableCellNode=A;exports.$createTableNode=Ma;
|
64
|
+
exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Ma();for(let f=0;f<a;f++){let g=E();for(let m=0;m<b;m++){var e=x.NO_STATUS;"object"===typeof c?(0===f&&c.rows&&(e|=x.ROW),0===m&&c.columns&&(e|=x.COLUMN)):c&&(0===f&&(e|=x.ROW),0===m&&(e|=x.COLUMN));e=A(e);let q=u.$createParagraphNode();q.append(u.$createTextNode());e.append(q);g.append(e)}d.append(g)}return d};exports.$createTableRowNode=E;exports.$createTableSelection=sa;
|
65
|
+
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(I(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
|
66
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[a]=Q(a);let [e,f,g]=P(d,c,a);({startColumn:b}=f);let {startRow:m,startColumn:q}=g;var p=Math.min(b,q);let r=Math.max(b+c.__colSpan-1,q+a.__colSpan-1),w=r-p+1;if(e[0].length===r-p+1)d.selectPrevious(),d.remove();else{var k=e.length;for(let l=0;l<k;l++)for(let n=p;n<=r;n++){let {cell:t,startColumn:v}=e[l][n];v<p?n===p&&t.setColSpan(t.__colSpan-
|
67
|
+
Math.min(w,t.__colSpan-(p-v))):v+t.__colSpan-1>r?n===r&&t.setColSpan(t.__colSpan-(r-v+1)):t.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))}};
|
68
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=Q(b);[a]=Q(a);let [e,f,g]=P(d,c,a);({startRow:b}=f);var {startRow:m}=g;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 w=a;w>=b;w--){for(var r=m-1;0<=r;r--){let {cell:k,startRow:l,startColumn:n}=e[w][r];if(n===r&&(w===b&&l<b&&k.setRowSpan(k.__rowSpan-(l-b)),l>=b&&l+k.__rowSpan-
|
69
|
+
1>a))if(k.setRowSpan(k.__rowSpan-(a-l+1)),null===p&&J(122),0===r)la(p,k);else{let {cell:t}=q[r-1];t.insertAfter(k)}}r=d.getChildAtIndex(w);I(r)||J(123,String(w));r.remove()}void 0!==q?({cell:b}=q[0],O(b)):({cell:b}=e[b-1][0],O(b))}};exports.$findCellNode=X;exports.$findTableNode=U;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;
|
70
|
+
exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>B(b));return B(a)?a:null};exports.$getTableCellNodeRect=pa;exports.$getTableColumnIndexFromTableCellNode=function(a){return ha(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ia;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ha(a);return ia(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ha;
|
71
|
+
exports.$insertTableColumn=function(a,b,c=!0,d,e){let f=a.getChildren(),g=[];for(let p=0;p<f.length;p++){let r=f[p];if(I(r))for(let w=0;w<d;w++){var m=r.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];B(m)||J(12);let {left:k,right:l}=ja(m,e);var q=x.NO_STATUS;if(k&&k.hasHeaderState(x.ROW)||l&&l.hasHeaderState(x.ROW))q|=x.ROW;q=A(q);q.append(u.$createParagraphNode());g.push({newTableCell:q,targetCell:m})}}g.forEach(({newTableCell:p,targetCell:r})=>{c?
|
72
|
+
r.insertAfter(p):r.insertBefore(p)});return a};
|
73
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(w=x.NO_STATUS){w=A(w).append(u.$createParagraphNode());null===p&&(p=w);return w}var c=u.$getSelection();u.$isRangeSelection(c)||R(c)||J(188);var d=c.anchor.getNode();c=c.focus.getNode();[d]=Q(d);let [e,,f]=Q(c),[g,m,q]=P(f,e,d);d=g.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);a=a?c+e.__colSpan-1:c-1;c=f.getFirstChild();I(c)||J(120);let p=null;var r=c;a:for(c=0;c<d;c++){0!==c&&(r=r.getNextSibling(),
|
74
|
+
I(r)||J(121));let w=g[c],k=ka(w[0>a?0:a].cell.__headerState,x.ROW);if(0>a){la(r,b(k));continue}let {cell:l,startColumn:n,startRow:t}=w[a];if(n+l.__colSpan-1<=a){let v=l,z=t,C=a;for(;z!==c&&1<v.__rowSpan;)if(C-=l.__colSpan,0<=C){let {cell:G,startRow:H}=w[C];v=G;z=H}else{r.append(b(k));continue a}v.insertAfter(b(k))}else l.setColSpan(l.__colSpan+1)}null!==p&&O(p)};
|
75
|
+
exports.$insertTableRow=function(a,b,c=!0,d,e){var f=a.getChildren();if(b>=f.length||0>b)throw Error("Table row target index out of range");b=f[b];if(I(b))for(f=0;f<d;f++){let m=b.getChildren(),q=m.length,p=E();for(let r=0;r<q;r++){var g=m[r];B(g)||J(12);let {above:w,below:k}=ja(g,e);g=x.NO_STATUS;let l=w&&w.getWidth()||k&&k.getWidth()||void 0;if(w&&w.hasHeaderState(x.COLUMN)||k&&k.hasHeaderState(x.COLUMN))g|=x.COLUMN;g=A(g,1,l);g.append(u.$createParagraphNode());p.append(g)}c?b.insertAfter(p):b.insertBefore(p)}else throw Error("Row before insertion index does not exist.");
|
76
76
|
return a};
|
77
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=
|
78
|
-
a=
|
79
|
-
exports.$unmergeCell=function(){var a=
|
80
|
-
a;m++)
|
81
|
-
exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,g.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,g.table)}let f=c.getRootElement();if(null===f)throw Error("No root element.");let g=new
|
82
|
-
k),m.removeEventListener("mousemove",l);else{var
|
83
|
-
{const l=
|
84
|
-
k=>
|
85
|
-
h.$findMatchingParent(l.anchor.getNode(),
|
86
|
-
|
87
|
-
|
88
|
-
!
|
89
|
-
|
90
|
-
l=
|
91
|
-
|
92
|
-
B)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
g.updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?za(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&ya(c,g);return!1},
|
77
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||R(b)||J(188);b=b.focus.getNode();let [c,,d]=Q(b),[e,f]=P(d,c,c);b=e[0].length;var {startRow:g}=f;if(a){a=g+c.__rowSpan-1;var m=e[a];g=E();for(var q=0;q<b;q++){let {cell:r,startRow:w}=m[q];if(w+r.__rowSpan-1<=a){var p=ka(m[q].cell.__headerState,x.COLUMN);g.append(A(p).append(u.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}b=d.getChildAtIndex(a);I(b)||J(145);b.insertAfter(g)}else{m=e[g];
|
78
|
+
a=E();for(q=0;q<b;q++){let {cell:r,startRow:w}=m[q];w===g?(p=ka(m[q].cell.__headerState,x.COLUMN),a.append(A(p).append(u.$createParagraphNode()))):r.setRowSpan(r.__rowSpan+1)}b=d.getChildAtIndex(g);I(b)||J(145);b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=N;exports.$isTableRowNode=I;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};
|
79
|
+
exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||R(a)||J(188);a=a.anchor.getNode();let [b,c,d]=Q(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var f=1;f<a;f++)b.insertAfter(A(x.NO_STATUS));b.setColSpan(1)}if(1<e){let [q,p]=P(d,b,b),{startColumn:r,startRow:w}=p,k;for(f=1;f<e;f++){var g=w+f;let l=q[g];k=(k||c).getNextSibling();I(k)||J(125);var m=null;for(let n=0;n<r;n++){let t=l[n],v=t.cell;t.startRow===g&&(m=v);1<v.__colSpan&&(n+=v.__colSpan-1)}if(null===m)for(m=0;m<
|
80
|
+
a;m++)la(k,A(x.NO_STATUS));else for(g=0;g<a;g++)m.insertAfter(A(x.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=x;exports.TableCellNode=y;exports.TableNode=Ka;exports.TableObserver=ta;exports.TableRowNode=D;
|
81
|
+
exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,g.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,g.table)}let f=c.getRootElement();if(null===f)throw Error("No root element.");let g=new ta(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=g;let q=()=>{const k=()=>{g.isSelecting=!1;m.removeEventListener("mouseup",k);m.removeEventListener("mousemove",l)},l=n=>{setTimeout(()=>{if(1!==(n.buttons&1)&&g.isSelecting)g.isSelecting=!1,m.removeEventListener("mouseup",
|
82
|
+
k),m.removeEventListener("mousemove",l);else{var t=ua(n.target);null===t||g.anchorX===t.x&&g.anchorY===t.y||(n.preventDefault(),g.setFocusCellForSelection(t))}},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),g.setAnchorCellForSelection(l));var {onMouseUp:n,onMouseMove:t}=q();g.isSelecting=!0;m.addEventListener("mouseup",n);m.addEventListener("mousemove",t)}},0)});let p=k=>{0===k.button&&c.update(()=>
|
83
|
+
{const l=u.$getSelection(),n=k.target;R(l)&&l.tableKey===g.tableNodeKey&&f.contains(n)&&g.clearHighlight()})};m.addEventListener("mousedown",p);g.listenersToRemove.add(()=>m.removeEventListener("mousedown",p));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_DOWN_COMMAND,k=>Y(c,k,"down",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_UP_COMMAND,k=>Y(c,k,"up",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_LEFT_COMMAND,
|
84
|
+
k=>Y(c,k,"backward",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_RIGHT_COMMAND,k=>Y(c,k,"forward",a,g),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.KEY_ESCAPE_COMMAND,k=>{var l=u.$getSelection();return R(l)&&(l=h.$findMatchingParent(l.focus.getNode(),B),B(l))?(Z(k),l.selectEnd(),!0):!1},u.COMMAND_PRIORITY_HIGH));let r=k=>()=>{var l=u.$getSelection();if(!V(l,a))return!1;if(R(l))return g.clearText(),!0;if(u.$isRangeSelection(l)){var n=
|
85
|
+
h.$findMatchingParent(l.anchor.getNode(),v=>B(v));if(!B(n))return!1;var t=l.anchor.getNode();n=l.focus.getNode();t=a.isParentOf(t);n=a.isParentOf(n);if(t&&!n||n&&!t)return g.clearText(),!0;n=(l=h.$findMatchingParent(l.anchor.getNode(),v=>u.$isElementNode(v)))&&h.$findMatchingParent(l,v=>u.$isElementNode(v)&&B(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,
|
86
|
+
u.DELETE_CHARACTER_COMMAND].forEach(k=>{g.listenersToRemove.add(c.registerCommand(k,r(k),u.COMMAND_PRIORITY_CRITICAL))});let w=k=>{const l=u.$getSelection();if(!V(l,a)){if(k=l?l.getNodes():null)if(k=k.find(n=>N(n)&&n.getKey()===g.tableNodeKey),N(k)){if(!k.getParent())return!1;k.remove()}return!1}if(R(l))return k&&(k.preventDefault(),k.stopPropagation()),g.clearText(),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>B(n)),B(k));return!1};g.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,
|
87
|
+
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,k=>{let l=u.$getSelection();if(l){if(u.$isNodeSelection(l))return!1;aa.copyToClipboard(c,h.objectKlassEquals(k,ClipboardEvent)?k:null);if(R(l))return w(k),!0;if(u.$isRangeSelection(l))return w(k),l.removeText(),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,
|
88
|
+
k=>{let l=u.$getSelection();if(!V(l,a))return!1;if(R(l))return g.formatCells(k),!0;u.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>B(n)),B(k));return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,k=>{var l=u.$getSelection();if(!R(l)||!V(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!B(n)||!B(l))return!1;let [t,v,z]=P(a,n,l);n=Math.max(v.startRow,z.startRow);l=Math.max(v.startColumn,z.startColumn);var C=Math.min(v.startRow,
|
89
|
+
z.startRow);let G=Math.min(v.startColumn,z.startColumn);for(;C<=n;C++)for(let L=G;L<=l;L++){var H=t[C][L].cell;H.setFormat(k);H=H.getChildren();for(let M=0;M<H.length;M++){let F=H[M];u.$isElementNode(F)&&!F.isInline()&&F.setFormat(k)}}return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=u.$getSelection();if(!V(l,a))return!1;if(R(l))g.clearHighlight();else if(u.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),
|
90
|
+
t=>B(t));if(!B(n))return!1;if("string"===typeof k&&(l=Ja(c,l,a)))return Ia(l,a,[u.$createTextNode(k)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));d&&g.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,k=>{var l=u.$getSelection();if(!u.$isRangeSelection(l)||!l.isCollapsed()||!V(l,a))return!1;l=X(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,g.table);Ba(g,a,l.x,l.y,k.shiftKey?"backward":"forward");return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,
|
91
|
+
()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var t=R(n);t=u.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),F=>B(F))&&null!==h.$findMatchingParent(n.focus.getNode(),F=>B(F))||t;if(1!==l.length||!N(l[0])||!t||null===k)return!1;var [v]=k,z=l[0];k=z.getChildren();t=z.getFirstChildOrThrow().getChildrenSize();z=z.getChildrenSize();var C=h.$findMatchingParent(v.getNode(),
|
92
|
+
F=>B(F)),G=C&&h.$findMatchingParent(C,F=>I(F)),H=G&&h.$findMatchingParent(G,F=>N(F));if(!B(C)||!I(G)||!N(H))return!1;v=G.getIndexWithinParent();var L=Math.min(H.getChildrenSize()-1,v+z-1);z=C.getIndexWithinParent();C=Math.min(G.getChildrenSize()-1,z+t-1);t=Math.min(z,C);G=Math.min(v,L);z=Math.max(z,C);v=Math.max(v,L);H=H.getChildren();for(L=0;G<=v;G++){C=H[G];if(!I(C))return!1;var M=k[L];if(!I(M))return!1;C=C.getChildren();M=M.getChildren();let F=0;for(let ma=t;ma<=z;ma++){let na=C[ma];if(!B(na))return!1;
|
93
|
+
let Aa=M[F];if(!B(Aa))return!1;let Na=na.getChildren();Aa.getChildren().forEach(W=>{u.$isTextNode(W)&&u.$createParagraphNode().append(W);na.append(W)});Na.forEach(W=>W.remove());F++}L++}return!0},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,()=>{let k=u.$getSelection(),l=u.$getPreviousSelection();if(u.$isRangeSelection(k)){let {anchor:C,focus:G}=k;var n=C.getNode(),t=G.getNode();n=X(n);var v=X(t);t=!(!n||!a.is(U(n)));var z=!(!v||!a.is(U(v)));let H=
|
94
|
+
t!==z,L=t&&z;t=k.isBackward();H?(n=k.clone(),z&&([z]=P(a,v,v),v=z[0][0].cell,z=z[z.length-1].at(-1).cell,n.focus.set(t?v.getKey():z.getKey(),t?v.getChildrenSize():z.getChildrenSize(),"element")),u.$setSelection(n),ya(c,g)):L&&!n.is(v)&&(g.setAnchorCellForSelection(e(n)),g.setFocusCellForSelection(e(v),!0),g.isSelecting||setTimeout(()=>{let {onMouseUp:M,onMouseMove:F}=q();g.isSelecting=!0;m.addEventListener("mouseup",M);m.addEventListener("mousemove",F)},0))}else k&&R(k)&&k.is(l)&&k.tableKey===a.getKey()&&
|
95
|
+
(t=fa?(c._window||window).getSelection():null)&&t.anchorNode&&t.focusNode&&(n=(n=u.$getNearestNodeFromDOMNode(t.focusNode))&&!a.is(U(n)),v=(v=u.$getNearestNodeFromDOMNode(t.anchorNode))&&a.is(U(v)),n&&v&&0<t.rangeCount&&(n=u.$createRangeSelectionFromDom(t,c)))&&(n.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),t.removeAllRanges(),u.$setSelection(n));if(k&&!k.is(l)&&(R(k)||R(l))&&g.tableSelection&&!g.tableSelection.is(l))return R(k)&&k.tableKey===g.tableNodeKey?g.updateTableTableSelection(k):
|
96
|
+
!R(k)&&R(l)&&l.tableKey===g.tableNodeKey&&g.updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?za(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&ya(c,g);return!1},u.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,()=>{var k=u.$getSelection();return u.$isRangeSelection(k)&&k.isCollapsed()&&V(k,a)?(k=Ja(c,k,a))?(Ia(k,a),!0):!1:!1},u.COMMAND_PRIORITY_CRITICAL));return g};exports.getDOMCellFromTarget=ua;
|
97
|
+
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 d,$createTextNode as u,$getSelection as h,$isRangeSelection as g,$createPoint as f,$normalizeSelection__EXPERIMENTAL as m,$getNodeByKey as p,isCurrentlyReadOnlyMode as C,$setSelection as S,SELECTION_CHANGE_COMMAND as _,$getNearestNodeFromDOMNode as w,$createRangeSelection as b,$getRoot as y,KEY_ARROW_DOWN_COMMAND as N,COMMAND_PRIORITY_HIGH as T,KEY_ARROW_UP_COMMAND as x,KEY_ARROW_LEFT_COMMAND as v,KEY_ARROW_RIGHT_COMMAND as E,KEY_ESCAPE_COMMAND as O,DELETE_WORD_COMMAND as M,DELETE_LINE_COMMAND as R,DELETE_CHARACTER_COMMAND as K,COMMAND_PRIORITY_CRITICAL as F,KEY_BACKSPACE_COMMAND as k,KEY_DELETE_COMMAND as A,FORMAT_TEXT_COMMAND as H,FORMAT_ELEMENT_COMMAND as P,CONTROLLED_TEXT_INSERTION_COMMAND as D,KEY_TAB_COMMAND as B,FOCUS_COMMAND as L,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as z,$isRootOrShadowRoot as Y,$isDecoratorNode as X}from"lexical";const J=/^(\d+(?:\.\d+)?)px$/,$={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class j extends r{static getType(){return"tablecell"}static clone(e){const t=new j(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:q,priority:0}),th:e=>({conversion:q,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=G(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=$.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){return this.getWritable().__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){return this.getWritable().__width=e,this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==$.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function q(e){const t=e,n=e.nodeName.toLowerCase();let o;J.test(t.style.width)&&(o=parseFloat(t.style.width));const r=G("th"===n?$.ROW:$.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const a=t.style.backgroundColor;""!==a&&(r.__backgroundColor=a);const d=t.style,u=d.textDecoration.split(" "),h="700"===d.fontWeight||"bold"===d.fontWeight,g=u.includes("line-through"),f="italic"===d.fontStyle,m=u.includes("underline");return{after:e=>(0===e.length&&e.push(l()),e),forChild:(e,t)=>{if(Q(t)&&!s(e)){const t=l();return i(e)&&"\n"===e.getTextContent()?null:(c(e)&&(h&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function G(e,t=1,n){return a(new j(e,t,n))}function Q(e){return e instanceof j}const V=d("INSERT_TABLE_COMMAND");class Z extends r{static getType(){return"tablerow"}static clone(e){return new Z(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ee,priority:0})}}static importJSON(e){return te(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function ee(e){const t=e;let n;return J.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:te(n)}}function te(e){return a(new Z(e))}function ne(e){return e instanceof Z}function oe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var re=oe((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const le="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function se(e,t,n=!0){const o=lt();for(let r=0;r<e;r++){const e=te();for(let o=0;o<t;o++){let t=$.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=$.ROW),0===o&&n.columns&&(t|=$.COLUMN)):n&&(0===r&&(t|=$.ROW),0===o&&(t|=$.COLUMN));const s=G(t),i=l();i.append(u()),s.append(i),e.append(s)}o.append(e)}return o}function ie(e){const n=t(e,(e=>Q(e)));return Q(n)?n:null}function ce(e){const n=t(e,(e=>ne(e)));if(ne(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ae(e){const n=t(e,(e=>st(e)));if(st(n))return n;throw new Error("Expected table cell to be inside of table.")}function de(e){const t=ce(e);return ae(t).getChildren().findIndex((e=>e.is(t)))}function ue(e){return ce(e).getChildren().findIndex((t=>t.is(e)))}function he(e,t){const n=ae(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function ge(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function fe(e,t,n=!0,o,r){const s=e.getChildren();if(t>=s.length||t<0)throw new Error("Table row target index out of range");const i=s[t];if(!ne(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=te();for(let n=0;n<t;n++){const t=e[n];Q(t)||re(12);const{above:s,below:i}=he(t,r);let c=$.NO_STATUS;const a=s&&s.getWidth()||i&&i.getWidth()||void 0;(s&&s.hasHeaderState($.COLUMN)||i&&i.hasHeaderState($.COLUMN))&&(c|=$.COLUMN);const d=G(c,1,a);d.append(l()),o.append(d)}n?i.insertAfter(o):i.insertBefore(o)}return e}const me=(e,t)=>e===$.BOTH||e===t?t:$.NO_STATUS;function pe(e=!0){const t=h();g(t)||Re(t)||re(188);const n=t.focus.getNode(),[o,,r]=Ee(n),[s,i]=xe(r,o,o),c=s[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=s[e],n=te();for(let o=0;o<c;o++){const{cell:r,startRow:s}=t[o];if(s+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=me(e,$.COLUMN);n.append(G(r).append(l()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ne(i)||re(145),i.insertAfter(n)}else{const e=s[a],t=te();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=me(o,$.COLUMN);t.append(G(r).append(l()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ne(n)||re(145),n.insertBefore(t)}}function Ce(e,t,n=!0,o,r){const s=e.getChildren(),i=[];for(let e=0;e<s.length;e++){const n=s[e];if(ne(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];Q(o)||re(12);const{left:s,right:c}=he(o,r);let a=$.NO_STATUS;(s&&s.hasHeaderState($.ROW)||c&&c.hasHeaderState($.ROW))&&(a|=$.ROW);const d=G(a);d.append(l()),i.push({newTableCell:d,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Se(e=!0){const t=h();g(t)||Re(t)||re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ee(n),[s,,i]=Ee(o),[c,a,d]=xe(i,s,r),u=c.length,f=e?Math.max(a.startColumn,d.startColumn):Math.min(a.startColumn,d.startColumn),m=e?f+s.__colSpan-1:f-1,p=i.getFirstChild();ne(p)||re(120);let C=null;function S(e=$.NO_STATUS){const t=G(e).append(l());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<u;e++){if(0!==e){const e=_.getNextSibling();ne(e)||re(121),_=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=me(n,$.ROW);if(m<0){Ne(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(S(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(S(o))}else r.setColSpan(r.__colSpan+1)}null!==C&&ye(C)}function _e(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ne(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function we(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ee(t),[l]=Ee(n),[s,i,c]=xe(r,o,l),{startRow:a}=i,{startRow:d}=c,u=d+l.__rowSpan-1;if(s.length===u-a+1)return void r.remove();const f=s[0].length,m=s[u+1],p=r.getChildAtIndex(u+1);for(let e=u;e>=a;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>u))if(n.setRowSpan(n.__rowSpan-(u-o+1)),null===p&&re(122),0===t)Ne(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ne(t)||re(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];ye(e)}else{const e=s[a-1],{cell:t}=e[0];ye(t)}}function be(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ee(t),[l]=Ee(n),[s,i,c]=xe(r,o,l),{startColumn:a}=i,{startRow:d,startColumn:u}=c,f=Math.min(a,u),m=Math.max(a+o.__colSpan-1,u+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[d],_=a>u?S[a+o.__colSpan]:S[u+l.__colSpan];if(void 0!==_){const{cell:e}=_;ye(e)}else{const e=u<a?S[u-1]:S[a-1],{cell:t}=e;ye(t)}}function ye(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ne(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Te(){const e=h();g(e)||Re(e)||re(188);const t=e.anchor.getNode(),[n,o,r]=Ee(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(G($.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=xe(r,n,n),{startColumn:i,startRow:c}=t;let a;for(let t=1;t<s;t++){const n=c+t,r=e[n];a=(a||o).getNextSibling(),ne(a)||re(125);let s=null;for(let e=0;e<i;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let e=0;e<l;e++)Ne(a,G($.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(G($.NO_STATUS))}n.setRowSpan(1)}}function xe(e,t,n){const[o,r,l]=ve(e,t,n);return null===r&&re(110),null===l&&re(111),[o,r,l]}function ve(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const c={cell:i,startColumn:s,startRow:e},a=i.__rowSpan,d=i.__colSpan;for(let t=0;t<a;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<d;n++)o[e+t][s+n]=c}null!==t&&t.is(i)&&(r=c),null!==n&&n.is(i)&&(l=c)}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const c=e.getChildren();for(let e=0;e<c.length;e++){const t=c[e];ne(t)||re(146);const n=t.getChildren();let o=0;for(const t of n){for(Q(t)||re(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function Ee(e){let n;if(e instanceof j)n=e;else if("__type"in e){const o=t(e,Q);Q(o)||re(148),n=o}else{const o=t(e.getNode(),Q);Q(o)||re(148),n=o}const o=n.getParent();ne(o)||re(149);const r=o.getParent();return st(r)||re(150),[n,o,r]}function Oe(e){const[t,,n]=Ee(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}class Me{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!Re(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Me(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();s(t)||re(151);m(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=p(this.anchor.key);Q(e)||re(152);const t=Oe(e);null===t&&re(153);const n=p(this.focus.key);Q(n)||re(154);const o=Oe(n);null===o&&re(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex,o.columnIndex),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex,o.rowIndex);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,Q),l=t(o,Q);Q(r)||re(152),Q(l)||re(154);const s=r.getParent();ne(s)||re(156);const i=s.getParent();st(i)||re(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&re(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&re(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,d,u]=xe(i,r,l);let h=Math.min(d.startColumn,u.startColumn),g=Math.min(d.startRow,u.startRow),f=Math.max(d.startColumn+d.cell.__colSpan-1,u.startColumn+u.cell.__colSpan-1),m=Math.max(d.startRow+d.cell.__rowSpan-1,u.startRow+u.cell.__rowSpan-1),p=h,S=g,_=h,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;h=Math.min(h,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1)}for(;h<p||g<S||f>_||m>w;){if(h<p){const e=w-S,t=p-1;for(let n=0;n<=e;n++)b(a[S+n][t]);p=t}if(g<S){const e=_-p,t=S-1;for(let n=0;n<=e;n++)b(a[t][p+n]);S=t}if(f>_){const e=w-S,t=_+1;for(let n=0;n<=e;n++)b(a[S+n][t]);_=t}if(m>w){const e=_-p,t=w+1;for(let n=0;n<=e;n++)b(a[t][p+n]);w=t}}const y=[i];let N=null;for(let e=g;e<=m;e++)for(let t=h;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();ne(o)||re(160),o!==N&&y.push(o),y.push(n,...Fe(n)),N=o}return C()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function Re(e){return e instanceof Me}function Ke(){const e=f("root",0,"element"),t=f("root",0,"element");return new Me("root",e,t)}function Fe(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&re(112),s(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class ke{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.trackTable(),this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach((e=>e()))}trackTable(){const e=new MutationObserver((e=>{this.editor.update((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const n=this.editor.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");this.table=Le(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Le(t),e.observe(t,{attributes:!0,childList:!0,subtree:!0})}))}clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),e.update((()=>{if(!st(p(this.tableNodeKey)))throw new Error("Expected TableNode.");const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");const n=Le(t);Ie(e,n,null),S(null),e.dispatchCommand(_,void 0)}))}enableHighlightStyle(){const e=this.editor;e.update((()=>{const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}))}disableHighlightStyle(){const t=this.editor;t.update((()=>{const n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}))}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ie(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const o=p(this.tableNodeKey);if(!st(o))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");const r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=He(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=w(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&Q(t)&&o.is(Qe(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Ke(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),S(this.tableSelection),n.dispatchCommand(_,void 0),Ie(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=w(e.elem);if(Q(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ke(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=h();Re(t)||re(11);const n=b(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{Q(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),S(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=p(this.tableNodeKey);if(!st(t))throw new Error("Expected TableNode.");const n=h();Re(n)||re(11);const o=n.getNodes().filter(Q);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(s(e)){const t=l(),n=u();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ie(e,this.table,null),S(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();y().selectStart()}}))}}const Ae="__lexicalTableSelection",He=e=>le?(e||window).getSelection():null;function Pe(e,n,o,r){const i=o.getRootElement();if(null===i)throw new Error("No root element.");const a=new ke(o,e.getKey()),d=o._window||window;!function(e,t){e[Ae]=t}(n,a);const f=()=>{const e=()=>{a.isSelecting=!1,d.removeEventListener("mouseup",e),d.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&a.isSelecting)return a.isSelecting=!1,d.removeEventListener("mouseup",e),void d.removeEventListener("mousemove",t);const o=Be(n.target);null===o||a.anchorX===o.x&&a.anchorY===o.y||(n.preventDefault(),a.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!d)return;const t=Be(e.target);null!==t&&(Ze(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=f();a.isSelecting=!0,d.addEventListener("mouseup",n),d.addEventListener("mousemove",o)}),0)}));const m=e=>{0===e.button&&o.update((()=>{const t=h(),n=e.target;Re(t)&&t.tableKey===a.tableNodeKey&&i.contains(n)&&a.clearHighlight()}))};d.addEventListener("mousedown",m),a.listenersToRemove.add((()=>d.removeEventListener("mousedown",m))),a.listenersToRemove.add(o.registerCommand(N,(t=>Ve(o,t,"down",e,a)),T)),a.listenersToRemove.add(o.registerCommand(x,(t=>Ve(o,t,"up",e,a)),T)),a.listenersToRemove.add(o.registerCommand(v,(t=>Ve(o,t,"backward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(E,(t=>Ve(o,t,"forward",e,a)),T)),a.listenersToRemove.add(o.registerCommand(O,(e=>{const n=h();if(Re(n)){const o=t(n.focus.getNode(),Q);if(Q(o))return Ze(e),o.selectEnd(),!0}return!1}),T));[M,R,K].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=h();if(!Xe(o,e))return!1;if(Re(o))return a.clearText(),!0;if(g(o)){const r=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(r))return!1;const l=o.anchor.getNode(),i=o.focus.getNode(),c=e.isParentOf(l),d=e.isParentOf(i);if(c&&!d||d&&!c)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>s(e))),h=u&&t(u,(e=>s(e)&&Q(e.getParent())));if(!s(h)||!s(u))return!1;if(n===R&&null===h.getPreviousSibling())return!0}return!1})(n),F))}));const p=n=>{const o=h();if(!Xe(o,e)){const e=o?o.getNodes():null;if(e){const t=e.find((e=>st(e)&&e.getKey()===a.tableNodeKey));if(st(t)){if(!t.getParent())return!1;t.remove()}}return!1}if(Re(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(e))return!1}return!1};function C(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(k,p,F)),a.listenersToRemove.add(o.registerCommand(A,p,F)),a.listenersToRemove.add(o.registerCommand(H,(n=>{const o=h();if(!Xe(o,e))return!1;if(Re(o))return a.formatCells(n),!0;if(g(o)){const e=t(o.anchor.getNode(),(e=>Q(e)));if(!Q(e))return!1}return!1}),F)),a.listenersToRemove.add(o.registerCommand(P,(t=>{const n=h();if(!Re(n)||!Xe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Q(o)||!Q(r))return!1;const[l,i,c]=xe(e,o,r),a=Math.max(i.startRow,c.startRow),d=Math.max(i.startColumn,c.startColumn),u=Math.min(i.startRow,c.startRow),g=Math.min(i.startColumn,c.startColumn);for(let e=u;e<=a;e++)for(let n=g;n<=d;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];s(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),F)),a.listenersToRemove.add(o.registerCommand(D,(n=>{const r=h();if(!Xe(r,e))return!1;if(Re(r))return a.clearHighlight(),!1;if(g(r)){const l=t(r.anchor.getNode(),(e=>Q(e)));if(!Q(l))return!1;if("string"==typeof n){const t=tt(o,r,e);if(t)return et(t,e,[u(n)]),!0}}return!1}),F)),r&&a.listenersToRemove.add(o.registerCommand(B,(t=>{const n=h();if(!g(n)||!n.isCollapsed()||!Xe(n,e))return!1;const o=Ge(n.anchor.getNode());if(null===o)return!1;Ze(t);const r=e.getCordsFromCellNode(o,a.table);return ze(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),F)),a.listenersToRemove.add(o.registerCommand(L,(t=>e.isSelected()),T)),a.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),s=Re(o),i=g(o)&&null!==t(o.anchor.getNode(),(e=>Q(e)))&&null!==t(o.focus.getNode(),(e=>Q(e)))||s;if(1!==n.length||!st(n[0])||!i||null===r)return!1;const[a]=r,d=n[0],u=d.getChildren(),h=d.getFirstChildOrThrow().getChildrenSize(),f=d.getChildrenSize(),m=t(a.getNode(),(e=>Q(e))),p=m&&t(m,(e=>ne(e))),C=p&&t(p,(e=>st(e)));if(!Q(m)||!ne(p)||!st(C))return!1;const _=p.getIndexWithinParent(),w=Math.min(C.getChildrenSize()-1,_+f-1),b=m.getIndexWithinParent(),y=Math.min(p.getChildrenSize()-1,b+h-1),N=Math.min(b,y),T=Math.min(_,w),x=Math.max(b,y),v=Math.max(_,w),E=C.getChildren();let O,M,R=0;for(let e=T;e<=v;e++){const t=E[e];if(!ne(t))return!1;const n=u[R];if(!ne(n))return!1;const o=t.getChildren(),r=n.getChildren();let s=0;for(let t=N;t<=x;t++){const n=o[t];if(!Q(n))return!1;const i=r[s];if(!Q(i))return!1;e===T&&t===N?O=n.getKey():e===v&&t===x&&(M=n.getKey());const a=n.getChildren();i.getChildren().forEach((e=>{if(c(e)){l().append(e),n.append(e)}else n.append(e)})),a.forEach((e=>e.remove())),s++}R++}if(O&&M){const e=Ke();e.set(n[0].getKey(),O,M),S(e)}return!0}),F)),a.listenersToRemove.add(o.registerCommand(_,(()=>{const t=h(),n=W();if(g(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Ge(l),c=Ge(s),u=!(!i||!e.is(Qe(i))),h=!(!c||!e.is(Qe(c))),g=u!==h,m=u&&h,p=t.isBackward();if(g){const n=t.clone();if(h){const[t]=xe(e,c,c),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element")}else n.anchor.set(e.getParentOrThrow().getKey(),p?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element");S(n),Ue(o,a)}else m&&(i.is(c)||(a.setAnchorCellForSelection(C(i)),a.setFocusCellForSelection(C(c),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=f();a.isSelecting=!0,d.addEventListener("mouseup",e),d.addEventListener("mousemove",t)}),0)))}else if(t&&Re(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=He(o._window);if(n&&n.anchorNode&&n.focusNode){const r=w(n.focusNode),l=r&&!e.is(Qe(r)),s=w(n.anchorNode),i=s&&e.is(Qe(s));if(l&&i&&n.rangeCount>0){const r=U(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),S(r))}}}return t&&!t.is(n)&&(Re(t)||Re(n))&&a.tableSelection&&!a.tableSelection.is(n)?(Re(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!Re(t)&&Re(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),We(t.table,(t=>{const n=t.elem;t.highlighted=!1,qe(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&Ue(o,a),!1)}),F)),a.listenersToRemove.add(o.registerCommand(z,(()=>{const t=h();if(!g(t)||!t.isCollapsed()||!Xe(t,e))return!1;const n=tt(o,t,e);return!!n&&(et(n,e),!0)}),F)),a}function De(e){return e[Ae]}function Be(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function Le(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.firstChild,r=0,l=0;for(t.length=0;null!=o;){const e=o.nodeName;if("TD"===e||"TH"===e){const e={elem:o,hasBackgroundColor:""!==o.style.backgroundColor,highlighted:!1,x:r,y:l};o._cell=e;let n=t[l];void 0===n&&(n=t[l]=[]),n[r]=e}else{const e=o.firstChild;if(null!=e){o=e;continue}}const n=o.nextSibling;if(null!=n){r++,o=n;continue}const s=o.parentNode;if(null!=s){const e=s.nextSibling;if(null==e)break;l++,r=0,o=e}}return n.columns=r+1,n.rows=l+1,n}function Ie(e,t,n){const o=new Set(n?n.getNodes():[]);We(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,je(e,t)):(t.highlighted=!1,qe(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function We(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=w(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ue(e,t){t.disableHighlightStyle(),We(t.table,(t=>{t.highlighted=!0,je(e,t)}))}const ze=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Je(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Je(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Je(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Je(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ye=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function Xe(e,t){if(g(e)||Re(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Je(e,t){t?e.selectStart():e.selectEnd()}const $e="172,206,247";function je(e,t){const n=t.elem,o=w(n);Q(o)||re(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${$e})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${$e},0.85), rgba(${$e},0.85))`),n.style.setProperty("caret-color","transparent")}function qe(e,t){const n=t.elem,o=w(n);Q(o)||re(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function Ge(e){const n=t(e,Q);return Q(n)?n:null}function Qe(e){const n=t(e,st);return st(n)?n:null}function Ve(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=h();if(!Xe(i,r)){if(g(i)){if(i.isCollapsed()&&"backward"===o){const e=i.anchor.type,o=i.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=i.anchor.getNode();if(!r)return!1;const l=t(r,(e=>s(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!st(c))&&(Ze(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=i.focus.getNode();if(Y(e)){const e=i.getNodes()[0];if(e){const n=t(e,Q);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ee(e),[o]=Ee(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.setAnchorCellForSelection(c),l.setFocusCellForSelection(a,!0),!0}}return!1}{const n=t(e,(e=>s(e)&&!e.isInline()));if(!n)return!1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(st(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ee(e),[l]=Ee(t),s=i.clone();return s.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),S(s),!0}}}}return!1}if(g(i)&&i.isCollapsed()){const{anchor:c,focus:a}=i,d=t(c.getNode(),Q),u=t(a.getNode(),Q);if(!Q(d)||!d.is(u))return!1;const h=Qe(d);if(h!==r&&null!=h){const t=e.getElementByKey(h.getKey());if(null!=t)return l.table=Le(t),Ve(e,n,o,h,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const d=i.getNodes();return(1!==d.length||!X(d[0]))&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>s(e)&&!e.isInline()));if(!l)return!1;const i="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&i&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,Q);if(!Q(l))return!1;const[i,c]=xe(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(i,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>s(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&st(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||st(a))return!1;Ze(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(d.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let m;if("element"===c.type)m=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;m=e.getRangeAt(0).getBoundingClientRect()}const p="up"===o?d.getFirstChild():d.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){Ze(n);const e=r.getCordsFromCellNode(d,l.table);if(!n.shiftKey)return ze(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.setAnchorCellForSelection(t),l.setFocusCellForSelection(t,!0)}return!0}}else if(Re(i)){const{anchor:s,focus:c}=i,a=t(s.getNode(),Q),d=t(c.getNode(),Q),[u]=i.getNodes(),h=e.getElementByKey(u.getKey());if(!Q(a)||!Q(d)||!st(u)||null==h)return!1;l.updateTableTableSelection(i);const g=Le(h),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),Ze(n),n.shiftKey){const e=r.getCordsFromCellNode(d,g);return Ye(l,u,e.x,e.y,o)}return d.selectEnd(),!0}return!1}function Ze(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function et(e,t,n){const o=l();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function tt(e,n,o){const r=o.getParent();if(!r)return;const l=e.getElementByKey(r.getKey());if(!l)return;const s=window.getSelection();if(!s||s.anchorNode!==l)return;const i=t(n.anchor.getNode(),(e=>Q(e)));if(!i)return;const c=t(i,(e=>st(e)));if(!st(c)||!c.is(o))return;const[a,d]=xe(o,i,i),u=a[0][0],h=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=d,m=g===u.startRow&&f===u.startColumn,p=g===h.startRow&&f===h.startColumn;return m?"first":p?"last":void 0}class nt extends r{static getType(){return"table"}static clone(e){return new nt(e.__key)}static importDOM(){return{table:e=>({conversion:rt,priority:1})}}static importJSON(e){return lt()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(o,t.theme.table),o}updateDOM(){return!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!ne(l))throw new Error("Expected to find row node.");const s=l.getChildrenSize();for(let e=0;e<s;e++){const e=document.createElement("col");n.append(e)}return t.replaceChildren(n,r),t}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return w(n)===e}));if(-1!==r)return{x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=w(o.elem);return Q(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}canSelectBefore(){return!0}canIndent(){return!1}}function ot(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Le(n)}function rt(e){return{node:lt()}}function lt(){return a(new nt)}function st(e){return e instanceof nt}export{xe as $computeTableMap,ve as $computeTableMapSkipCellCheck,G as $createTableCellNode,lt as $createTableNode,se as $createTableNodeWithDimensions,te as $createTableRowNode,Ke as $createTableSelection,_e as $deleteTableColumn,be as $deleteTableColumn__EXPERIMENTAL,we as $deleteTableRow__EXPERIMENTAL,Ge as $findCellNode,Qe as $findTableNode,ot as $getElementForTableNode,Ee as $getNodeTriplet,ie as $getTableCellNodeFromLexicalNode,Oe as $getTableCellNodeRect,ue as $getTableColumnIndexFromTableCellNode,ae as $getTableNodeFromLexicalNodeOrThrow,de as $getTableRowIndexFromTableCellNode,ce as $getTableRowNodeFromTableCellNodeOrThrow,Ce as $insertTableColumn,Se as $insertTableColumn__EXPERIMENTAL,fe as $insertTableRow,pe as $insertTableRow__EXPERIMENTAL,Q as $isTableCellNode,st as $isTableNode,ne as $isTableRowNode,Re as $isTableSelection,ge as $removeTableRowAtIndex,Te as $unmergeCell,V as INSERT_TABLE_COMMAND,$ as TableCellHeaderStates,j as TableCellNode,nt as TableNode,ke as TableObserver,Z as TableRowNode,Pe as applyTableHandlers,Be as getDOMCellFromTarget,De as getTableObserverFromTableElement};
|
9
|
+
import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as d,createCommand as u,$createTextNode as h,$getSelection as g,$isRangeSelection as f,$createPoint as m,$normalizeSelection__EXPERIMENTAL as p,$getNodeByKey as C,isCurrentlyReadOnlyMode as S,$setSelection as _,SELECTION_CHANGE_COMMAND as w,$getNearestNodeFromDOMNode as b,$createRangeSelection as y,$getRoot as N,KEY_ARROW_DOWN_COMMAND as T,COMMAND_PRIORITY_HIGH as x,KEY_ARROW_UP_COMMAND as v,KEY_ARROW_LEFT_COMMAND as E,KEY_ARROW_RIGHT_COMMAND as O,KEY_ESCAPE_COMMAND as M,DELETE_WORD_COMMAND as R,DELETE_LINE_COMMAND as K,DELETE_CHARACTER_COMMAND as F,COMMAND_PRIORITY_CRITICAL as k,KEY_BACKSPACE_COMMAND as A,KEY_DELETE_COMMAND as H,CUT_COMMAND as D,$isNodeSelection as P,FORMAT_TEXT_COMMAND as B,FORMAT_ELEMENT_COMMAND as L,CONTROLLED_TEXT_INSERTION_COMMAND as I,KEY_TAB_COMMAND as W,FOCUS_COMMAND as U,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as z,$getPreviousSelection as Y,$createRangeSelectionFromDom as X,INSERT_PARAGRAPH_COMMAND as J,$isRootOrShadowRoot as $,$isDecoratorNode as j}from"lexical";import{copyToClipboard as q}from"@lexical/clipboard";const G=/^(\d+(?:\.\d+)?)px$/,Q={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class V extends l{static getType(){return"tablecell"}static clone(e){const t=new V(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:Z,priority:0}),th:e=>({conversion:Z,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=ee(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=Q.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!==Q.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 Z(e){const t=e,n=e.nodeName.toLowerCase();let o;G.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ee("th"===n?Q.ROW:Q.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const d=t.style,u=d.textDecoration.split(" "),h="700"===d.fontWeight||"bold"===d.fontWeight,g=u.includes("line-through"),f="italic"===d.fontStyle,m=u.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(te(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(h&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function ee(e,t=1,n){return d(new V(e,t,n))}function te(e){return e instanceof V}const ne=u("INSERT_TABLE_COMMAND");class oe extends l{static getType(){return"tablerow"}static clone(e){return new oe(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:re,priority:0})}}static importJSON(e){return le(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 re(e){const t=e;let n;return G.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:le(n)}}function le(e){return d(new oe(e))}function se(e){return e instanceof oe}function ie(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ce=ie((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 ae="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function de(e,t,n=!0){const o=at();for(let r=0;r<e;r++){const e=le();for(let o=0;o<t;o++){let t=Q.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Q.ROW),0===o&&n.columns&&(t|=Q.COLUMN)):n&&(0===r&&(t|=Q.ROW),0===o&&(t|=Q.COLUMN));const l=ee(t),i=s();i.append(h()),l.append(i),e.append(l)}o.append(e)}return o}function ue(e){const n=t(e,(e=>te(e)));return te(n)?n:null}function he(e){const n=t(e,(e=>se(e)));if(se(n))return n;throw new Error("Expected table cell to be inside of table row.")}function ge(e){const n=t(e,(e=>dt(e)));if(dt(n))return n;throw new Error("Expected table cell to be inside of table.")}function fe(e){const t=he(e);return ge(t).getChildren().findIndex((e=>e.is(t)))}function me(e){return he(e).getChildren().findIndex((t=>t.is(e)))}function pe(e,t){const n=ge(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 Ce(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 Se(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const i=l[t];if(!se(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=le();for(let n=0;n<t;n++){const t=e[n];te(t)||ce(12);const{above:l,below:i}=pe(t,r);let c=Q.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Q.COLUMN)||i&&i.hasHeaderState(Q.COLUMN))&&(c|=Q.COLUMN);const d=ee(c,1,a);d.append(s()),o.append(d)}n?i.insertAfter(o):i.insertBefore(o)}return e}const _e=(e,t)=>e===Q.BOTH||e===t?t:Q.NO_STATUS;function we(e=!0){const t=g();f(t)||Ae(t)||ce(188);const n=t.focus.getNode(),[o,,r]=Ke(n),[l,i]=Me(r,o,o),c=l[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=l[e],n=le();for(let o=0;o<c;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=_e(e,Q.COLUMN);n.append(ee(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);se(i)||ce(145),i.insertAfter(n)}else{const e=l[a],t=le();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=_e(o,Q.COLUMN);t.append(ee(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);se(n)||ce(145),n.insertBefore(t)}}function be(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(se(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];te(o)||ce(12);const{left:l,right:c}=pe(o,r);let a=Q.NO_STATUS;(l&&l.hasHeaderState(Q.ROW)||c&&c.hasHeaderState(Q.ROW))&&(a|=Q.ROW);const d=ee(a);d.append(s()),i.push({newTableCell:d,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function ye(e=!0){const t=g();f(t)||Ae(t)||ce(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ke(n),[l,,i]=Ke(o),[c,a,d]=Me(i,l,r),u=c.length,h=e?Math.max(a.startColumn,d.startColumn):Math.min(a.startColumn,d.startColumn),m=e?h+l.__colSpan-1:h-1,p=i.getFirstChild();se(p)||ce(120);let C=null;function S(e=Q.NO_STATUS){const t=ee(e).append(s());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<u;e++){if(0!==e){const e=_.getNextSibling();se(e)||ce(121),_=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=_e(n,Q.ROW);if(m<0){Ee(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(S(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(S(o))}else r.setColSpan(r.__colSpan+1)}null!==C&&ve(C)}function Ne(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(se(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 Te(){const e=g();f(e)||Ae(e)||ce(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ke(t),[l]=Ke(n),[s,i,c]=Me(r,o,l),{startRow:a}=i,{startRow:d}=c,u=d+l.__rowSpan-1;if(s.length===u-a+1)return void r.remove();const h=s[0].length,m=s[u+1],p=r.getChildAtIndex(u+1);for(let e=u;e>=a;e--){for(let t=h-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&&ce(122),0===t)Ee(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);se(t)||ce(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];ve(e)}else{const e=s[a-1],{cell:t}=e[0];ve(t)}}function xe(){const e=g();f(e)||Ae(e)||ce(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ke(t),[l]=Ke(n),[s,i,c]=Me(r,o,l),{startColumn:a}=i,{startRow:d,startColumn:u}=c,h=Math.min(a,u),m=Math.max(a+o.__colSpan-1,u+l.__colSpan-1),p=m-h+1;if(s[0].length===m-h+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=h;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<h){if(t===h){const e=h-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[d],_=a>u?S[a+o.__colSpan]:S[u+l.__colSpan];if(void 0!==_){const{cell:e}=_;ve(e)}else{const e=u<a?S[u-1]:S[a-1],{cell:t}=e;ve(t)}}function ve(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ee(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Oe(){const e=g();f(e)||Ae(e)||ce(188);const t=e.anchor.getNode(),[n,o,r]=Ke(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(ee(Q.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=Me(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(),se(a)||ce(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++)Ee(a,ee(Q.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(ee(Q.NO_STATUS))}n.setRowSpan(1)}}function Me(e,t,n){const[o,r,l]=Re(e,t,n);return null===r&&ce(110),null===l&&ce(111),[o,r,l]}function Re(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const c={cell:i,startColumn:s,startRow:e},a=i.__rowSpan,d=i.__colSpan;for(let t=0;t<a;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<d;n++)o[e+t][s+n]=c}null!==t&&t.is(i)&&(r=c),null!==n&&n.is(i)&&(l=c)}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const c=e.getChildren();for(let e=0;e<c.length;e++){const t=c[e];se(t)||ce(146);const n=t.getChildren();let o=0;for(const t of n){for(te(t)||ce(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return[o,r,l]}function Ke(e){let n;if(e instanceof V)n=e;else if("__type"in e){const o=t(e,te);te(o)||ce(148),n=o}else{const o=t(e.getNode(),te);te(o)||ce(148),n=o}const o=n.getParent();se(o)||ce(149);const r=o.getParent();return dt(r)||ce(150),[n,o,r]}function Fe(e){const[t,,n]=Ke(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}class ke{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!!Ae(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 ke(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();i(t)||ce(151);p(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=C(this.anchor.key);te(e)||ce(152);const t=Fe(e);null===t&&ce(153);const n=C(this.focus.key);te(n)||ce(154);const o=Fe(n);null===o&&ce(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,te),l=t(o,te);te(r)||ce(152),te(l)||ce(154);const s=r.getParent();se(s)||ce(156);const i=s.getParent();dt(i)||ce(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&ce(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&ce(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,d,u]=Me(i,r,l);let h=Math.min(d.startColumn,u.startColumn),g=Math.min(d.startRow,u.startRow),f=Math.max(d.startColumn+d.cell.__colSpan-1,u.startColumn+u.cell.__colSpan-1),m=Math.max(d.startRow+d.cell.__rowSpan-1,u.startRow+u.cell.__rowSpan-1),p=h,C=g,_=h,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;h=Math.min(h,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1)}for(;h<p||g<C||f>_||m>w;){if(h<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=h;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();se(o)||ce(160),o!==N&&y.push(o),y.push(n,...De(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 Ae(e){return e instanceof ke}function He(){const e=m("root",0,"element"),t=m("root",0,"element");return new ke("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&ce(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class Pe{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=ze(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=ze(t),e.observe(t,{attributes:!0,childList:!0,subtree:!0})}))}clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),e.update((()=>{if(!dt(C(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=ze(t);Ye(e,n,null),_(null),e.dispatchCommand(w,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(),Ye(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=C(this.tableNodeKey);if(!dt(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=Le(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=b(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&te(t)&&o.is(tt(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||He(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),_(this.tableSelection),n.dispatchCommand(w,void 0),Ye(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=b(e.elem);if(te(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():He(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();Ae(t)||ce(11);const n=y(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{te(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),_(t),this.editor.dispatchCommand(w,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=C(this.tableNodeKey);if(!dt(t))throw new Error("Expected TableNode.");const n=g();Ae(n)||ce(11);const o=n.getNodes().filter(te);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=h();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ye(e,this.table,null),_(null),e.dispatchCommand(w,void 0);else{t.selectPrevious(),t.remove();N().selectStart()}}))}}const Be="__lexicalTableSelection",Le=e=>ae?(e||window).getSelection():null;function Ie(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const d=new Pe(r,e.getKey()),u=r._window||window;!function(e,t){e[Be]=t}(n,d);const m=()=>{const e=()=>{d.isSelecting=!1,u.removeEventListener("mouseup",e),u.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&d.isSelecting)return d.isSelecting=!1,u.removeEventListener("mouseup",e),void u.removeEventListener("mousemove",t);const o=Ue(n.target);null===o||d.anchorX===o.x&&d.anchorY===o.y||(n.preventDefault(),d.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!u)return;const t=Ue(e.target);null!==t&&(ot(e),d.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=m();d.isSelecting=!0,u.addEventListener("mouseup",n),u.addEventListener("mousemove",o)}),0)}));const p=e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;Ae(t)&&t.tableKey===d.tableNodeKey&&c.contains(n)&&d.clearHighlight()}))};u.addEventListener("mousedown",p),d.listenersToRemove.add((()=>u.removeEventListener("mousedown",p))),d.listenersToRemove.add(r.registerCommand(T,(t=>nt(r,t,"down",e,d)),x)),d.listenersToRemove.add(r.registerCommand(v,(t=>nt(r,t,"up",e,d)),x)),d.listenersToRemove.add(r.registerCommand(E,(t=>nt(r,t,"backward",e,d)),x)),d.listenersToRemove.add(r.registerCommand(O,(t=>nt(r,t,"forward",e,d)),x)),d.listenersToRemove.add(r.registerCommand(M,(e=>{const n=g();if(Ae(n)){const o=t(n.focus.getNode(),te);if(te(o))return ot(e),o.selectEnd(),!0}return!1}),x));[R,K,F].forEach((n=>{d.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!qe(o,e))return!1;if(Ae(o))return d.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>te(e)));if(!te(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return d.clearText(),!0;const u=t(o.anchor.getNode(),(e=>i(e))),h=u&&t(u,(e=>i(e)&&te(e.getParent())));if(!i(h)||!i(u))return!1;if(n===K&&null===h.getPreviousSibling())return!0}return!1})(n),k))}));const C=n=>{const o=g();if(!qe(o,e)){const e=o?o.getNodes():null;if(e){const t=e.find((e=>dt(e)&&e.getKey()===d.tableNodeKey));if(dt(t)){if(!t.getParent())return!1;t.remove()}}return!1}if(Ae(o))return n&&(n.preventDefault(),n.stopPropagation()),d.clearText(),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>te(e)));if(!te(e))return!1}return!1};function S(t){const n=e.getCordsFromCellNode(t,d.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,d.table)}return d.listenersToRemove.add(r.registerCommand(A,C,k)),d.listenersToRemove.add(r.registerCommand(H,C,k)),d.listenersToRemove.add(r.registerCommand(D,(e=>{const t=g();if(t){if(P(t))return!1;if(q(r,o(e,ClipboardEvent)?e:null),Ae(t))return C(e),!0;if(f(t))return C(e),t.removeText(),!0}return!1}),k)),d.listenersToRemove.add(r.registerCommand(B,(n=>{const o=g();if(!qe(o,e))return!1;if(Ae(o))return d.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>te(e)));if(!te(e))return!1}return!1}),k)),d.listenersToRemove.add(r.registerCommand(L,(t=>{const n=g();if(!Ae(n)||!qe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!te(o)||!te(r))return!1;const[l,s,c]=Me(e,o,r),a=Math.max(s.startRow,c.startRow),d=Math.max(s.startColumn,c.startColumn),u=Math.min(s.startRow,c.startRow),h=Math.min(s.startColumn,c.startColumn);for(let e=u;e<=a;e++)for(let n=h;n<=d;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),k)),d.listenersToRemove.add(r.registerCommand(I,(n=>{const o=g();if(!qe(o,e))return!1;if(Ae(o))return d.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>te(e)));if(!te(l))return!1;if("string"==typeof n){const t=lt(r,o,e);if(t)return rt(t,e,[h(n)]),!0}}return!1}),k)),l&&d.listenersToRemove.add(r.registerCommand(W,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!qe(n,e))return!1;const o=et(n.anchor.getNode());if(null===o)return!1;ot(t);const r=e.getCordsFromCellNode(o,d.table);return $e(d,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),k)),d.listenersToRemove.add(r.registerCommand(U,(t=>e.isSelected()),x)),d.listenersToRemove.add(r.registerCommand(z,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=Ae(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>te(e)))&&null!==t(o.focus.getNode(),(e=>te(e)))||l;if(1!==n.length||!dt(n[0])||!i||null===r)return!1;const[c]=r,d=n[0],u=d.getChildren(),h=d.getFirstChildOrThrow().getChildrenSize(),g=d.getChildrenSize(),m=t(c.getNode(),(e=>te(e))),p=m&&t(m,(e=>se(e))),C=p&&t(p,(e=>dt(e)));if(!te(m)||!se(p)||!dt(C))return!1;const S=p.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),w=m.getIndexWithinParent(),b=Math.min(p.getChildrenSize()-1,w+h-1),y=Math.min(w,b),N=Math.min(S,_),T=Math.max(w,b),x=Math.max(S,_),v=C.getChildren();let E=0;for(let e=N;e<=x;e++){const t=v[e];if(!se(t))return!1;const n=u[E];if(!se(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=T;e++){const t=o[e];if(!te(t))return!1;const n=r[l];if(!te(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}E++}return!0}),k)),d.listenersToRemove.add(r.registerCommand(w,(()=>{const t=g(),n=Y();if(f(t)){const{anchor:n,focus:o}=t,l=n.getNode(),s=o.getNode(),i=et(l),c=et(s),a=!(!i||!e.is(tt(i))),h=!(!c||!e.is(tt(c))),g=a!==h,f=a&&h,p=t.isBackward();if(g){const n=t.clone();if(h){const[t]=Me(e,c,c),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element")}_(n),Je(r,d)}else f&&(i.is(c)||(d.setAnchorCellForSelection(S(i)),d.setFocusCellForSelection(S(c),!0),d.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=m();d.isSelecting=!0,u.addEventListener("mouseup",e),u.addEventListener("mousemove",t)}),0)))}else if(t&&Ae(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Le(r._window);if(n&&n.anchorNode&&n.focusNode){const o=b(n.focusNode),l=o&&!e.is(tt(o)),s=b(n.anchorNode),i=s&&e.is(tt(s));if(l&&i&&n.rangeCount>0){const o=X(n,r);o&&(o.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),_(o))}}}return t&&!t.is(n)&&(Ae(t)||Ae(n))&&d.tableSelection&&!d.tableSelection.is(n)?(Ae(t)&&t.tableKey===d.tableNodeKey?d.updateTableTableSelection(t):!Ae(t)&&Ae(n)&&n.tableKey===d.tableNodeKey&&d.updateTableTableSelection(null),!1):(d.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Xe(t.table,(t=>{const n=t.elem;t.highlighted=!1,Ze(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,d):!d.hasHijackedSelectionStyles&&e.isSelected()&&Je(r,d),!1)}),k)),d.listenersToRemove.add(r.registerCommand(J,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!qe(t,e))return!1;const n=lt(r,t,e);return!!n&&(rt(n,e),!0)}),k)),d}function We(e){return e[Be]}function Ue(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 ze(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 Ye(e,t,n){const o=new Set(n?n.getNodes():[]);Xe(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Ve(e,t)):(t.highlighted=!1,Ze(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Xe(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=b(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Je(e,t){t.disableHighlightStyle(),Xe(t.table,(t=>{t.highlighted=!0,Ve(e,t)}))}const $e=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ge(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ge(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?Ge(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ge(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},je=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function qe(e,t){if(f(e)||Ae(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Ge(e,t){t?e.selectStart():e.selectEnd()}const Qe="172,206,247";function Ve(e,t){const n=t.elem,o=b(n);te(o)||ce(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Qe})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Qe},0.85), rgba(${Qe},0.85))`),n.style.setProperty("caret-color","transparent")}function Ze(e,t){const n=t.elem,o=b(n);te(o)||ce(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function et(e){const n=t(e,te);return te(n)?n:null}function tt(e){const n=t(e,dt);return dt(n)?n:null}function nt(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=g();if(!qe(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const c=l.getPreviousSibling();return!(!c||!dt(c))&&(ot(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if($(e)){const e=s.getNodes()[0];if(e){const n=t(e,te);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ke(e),[o]=Ke(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.setAnchorCellForSelection(c),l.setFocusCellForSelection(a,!0),!0}}return!1}{const n=t(e,(e=>i(e)&&!e.isInline()));if(!n)return!1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(dt(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Ke(e),[l]=Ke(t),i=s.clone();return i.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),_(i),!0}}}}return!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,d=t(c.getNode(),te),u=t(a.getNode(),te);if(!te(d)||!d.is(u))return!1;const h=tt(d);if(h!==r&&null!=h){const t=e.getElementByKey(h.getKey());if(null!=t)return l.table=ze(t),nt(e,n,o,h,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const d=s.getNodes();return(1!==d.length||!j(d[0]))&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,a,o)&&function(e,n,o,r){const l=t(n,te);if(!te(l))return!1;const[s,c]=Me(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,c,r))return!1;const a=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&dt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||dt(a))return!1;ot(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(d.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let m;if("element"===c.type)m=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;m=e.getRangeAt(0).getBoundingClientRect()}const p="up"===o?d.getFirstChild():d.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){ot(n);const e=r.getCordsFromCellNode(d,l.table);if(!n.shiftKey)return $e(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(Ae(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),te),d=t(c.getNode(),te),[u]=s.getNodes(),h=e.getElementByKey(u.getKey());if(!te(a)||!te(d)||!dt(u)||null==h)return!1;l.updateTableTableSelection(s);const g=ze(h),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),ot(n),n.shiftKey){const e=r.getCordsFromCellNode(d,g);return je(l,u,e.x,e.y,o)}return d.selectEnd(),!0}return!1}function ot(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function rt(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function lt(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=>te(e)));if(!i)return;const c=t(i,(e=>dt(e)));if(!dt(c)||!c.is(o))return;const[a,d]=Me(o,i,i),u=a[0][0],h=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=d,m=g===u.startRow&&f===u.startColumn,p=g===h.startRow&&f===h.startColumn;return m?"first":p?"last":void 0}class st extends l{static getType(){return"table"}static clone(e){return new st(e.__key)}static importDOM(){return{table:e=>({conversion:ct,priority:1})}}static importJSON(e){return at()}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"),o=document.createElement("tbody");r(e)&&o.append(...e.children);const l=this.getFirstChildOrThrow();if(!se(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,o),t}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null==n)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return b(n)===e}));if(-1!==r)return{x:r,y:t}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=b(o.elem);return te(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 it(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return ze(n)}function ct(e){return{node:at()}}function at(){return d(new st)}function dt(e){return e instanceof st}export{Me as $computeTableMap,Re as $computeTableMapSkipCellCheck,ee as $createTableCellNode,at as $createTableNode,de as $createTableNodeWithDimensions,le as $createTableRowNode,He as $createTableSelection,Ne as $deleteTableColumn,xe as $deleteTableColumn__EXPERIMENTAL,Te as $deleteTableRow__EXPERIMENTAL,et as $findCellNode,tt as $findTableNode,it as $getElementForTableNode,Ke as $getNodeTriplet,ue as $getTableCellNodeFromLexicalNode,Fe as $getTableCellNodeRect,me as $getTableColumnIndexFromTableCellNode,ge as $getTableNodeFromLexicalNodeOrThrow,fe as $getTableRowIndexFromTableCellNode,he as $getTableRowNodeFromTableCellNodeOrThrow,be as $insertTableColumn,ye as $insertTableColumn__EXPERIMENTAL,Se as $insertTableRow,we as $insertTableRow__EXPERIMENTAL,te as $isTableCellNode,dt as $isTableNode,se as $isTableRowNode,Ae as $isTableSelection,Ce as $removeTableRowAtIndex,Oe as $unmergeCell,ne as INSERT_TABLE_COMMAND,Q as TableCellHeaderStates,V as TableCellNode,st as TableNode,Pe as TableObserver,oe as TableRowNode,Ie as applyTableHandlers,Ue as getDOMCellFromTarget,We as getTableObserverFromTableElement};
|
package/package.json
CHANGED
@@ -8,12 +8,12 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.17.1-nightly.
|
11
|
+
"version": "0.17.1-nightly.20240823.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/utils": "0.17.1-nightly.
|
16
|
-
"lexical": "0.17.1-nightly.
|
15
|
+
"@lexical/utils": "0.17.1-nightly.20240823.0",
|
16
|
+
"lexical": "0.17.1-nightly.20240823.0"
|
17
17
|
},
|
18
18
|
"repository": {
|
19
19
|
"type": "git",
|