Socket
Socket
Sign inDemoInstall

@lexical/table

Package Overview
Dependencies
Maintainers
6
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/table - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

245

LexicalTable.dev.js

@@ -27,3 +27,3 @@ /**

/** @noInheritDoc */
class TableCellNode extends lexical.GridCellNode {
class TableCellNode extends lexical.DEPRECATED_GridCellNode {
/** @internal */

@@ -154,2 +154,6 @@

isShadowRoot() {
return true;
}
collapseAtStart() {

@@ -205,3 +209,3 @@ return true;

/** @noInheritDoc */
class TableRowNode extends lexical.GridRowNode {
class TableRowNode extends lexical.DEPRECATED_GridRowNode {
/** @internal */

@@ -252,2 +256,6 @@ static getType() {

isShadowRoot() {
return true;
}
setHeight(height) {

@@ -477,19 +485,10 @@ const self = this.getWritable();

updateTableGridSelection(selection) {
if (selection != null) {
if (selection != null && selection.gridKey === this.tableNodeKey) {
this.gridSelection = selection;
this.isHighlightingCells = true;
this.disableHighlightStyle();
const anchorElement = this.editor.getElementByKey(selection.anchor.key);
const focusElement = this.editor.getElementByKey(selection.focus.key);
$updateDOMForSelection(this.grid, this.gridSelection);
}
if (anchorElement && focusElement) {
const domSelection = getDOMSelection();
if (domSelection) {
domSelection.setBaseAndExtent(anchorElement, 0, focusElement, 0);
}
}
$updateDOMForSelection(this.grid, this.gridSelection);
} else {
if (selection == null) {
this.clearHighlight();

@@ -516,8 +515,8 @@ }

this.focusCell = cell;
const domSelection = getDOMSelection();
if (this.anchorCell !== null) {
// Collapse the selection
const domSelection = getDOMSelection(); // Collapse the selection
if (domSelection) {
domSelection.setBaseAndExtent(this.anchorCell.elem, 0, cell.elem, 0);
domSelection.setBaseAndExtent(this.anchorCell.elem, 0, this.anchorCell.elem, 0);
}

@@ -541,3 +540,3 @@ }

const focusNodeKey = focusTableCellNode.getKey();
this.gridSelection = lexical.$createGridSelection();
this.gridSelection = lexical.DEPRECATED_$createGridSelection();
this.focusCellNodeKey = focusNodeKey;

@@ -555,11 +554,13 @@ this.gridSelection.set(this.tableNodeKey, this.anchorCellNodeKey, this.focusCellNodeKey);

this.editor.update(() => {
if (this.anchorCell === cell && this.isHighlightingCells) {
const domSelection = getDOMSelection(); // Collapse the selection
if (domSelection) {
domSelection.setBaseAndExtent(cell.elem, 0, cell.elem, 0);
}
}
this.anchorCell = cell;
this.startX = cell.x;
this.startY = cell.y;
const domSelection = getDOMSelection();
if (domSelection) {
domSelection.setBaseAndExtent(cell.elem, 0, cell.elem, 0);
}
const anchorTableCellNode = lexical.$getNearestNodeFromDOMNode(cell.elem);

@@ -569,3 +570,3 @@

const anchorNodeKey = anchorTableCellNode.getKey();
this.gridSelection = lexical.$createGridSelection();
this.gridSelection = lexical.DEPRECATED_$createGridSelection();
this.anchorCellNodeKey = anchorNodeKey;

@@ -580,3 +581,3 @@ }

if (!lexical.$isGridSelection(selection)) {
if (!lexical.DEPRECATED_$isGridSelection(selection)) {
{

@@ -612,3 +613,3 @@ throw Error(`Expected grid selection`);

if (!lexical.$isGridSelection(selection)) {
if (!lexical.DEPRECATED_$isGridSelection(selection)) {
{

@@ -625,3 +626,4 @@ throw Error(`Expected grid selection`);

tableNode.remove();
this.clearHighlight();
const rootNode = lexical.$getRoot();
rootNode.selectStart();
return;

@@ -692,9 +694,6 @@ }

if (cell !== null) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
tableSelection.setAnchorCellForSelection(cell);
document.addEventListener('mouseup', () => {
isMouseDown = false;
}, {
capture: true,
once: true
});
}

@@ -725,7 +724,2 @@ }, 0);

}
});
tableElement.addEventListener('mouseup', () => {
if (isMouseDown) {
isMouseDown = false;
}
}); // Select entire table at this point, when grid selection is ready.

@@ -749,3 +743,3 @@

if (lexical.$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(event.target)) {
if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(event.target)) {
return tableSelection.clearHighlight();

@@ -759,4 +753,9 @@ }

const mouseUpCallback = () => {
isMouseDown = false;
const mouseUpCallback = event => {
if (isMouseDown) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
isMouseDown = false;
}
};

@@ -766,2 +765,4 @@

tableSelection.listenersToRemove.add(() => window.removeEventListener('mouseup', mouseUpCallback));
tableSelection.listenersToRemove.add(() => tableElement.addEventListener('mouseup', mouseUpCallback));
tableSelection.listenersToRemove.add(() => tableElement.removeEventListener('mouseup', mouseUpCallback));
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {

@@ -807,3 +808,3 @@ const selection = lexical.$getSelection();

}
} else if (lexical.$isGridSelection(selection) && event.shiftKey) {
} else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
const tableCellNode = selection.focus.getNode();

@@ -864,3 +865,3 @@

}
} else if (lexical.$isGridSelection(selection) && event.shiftKey) {
} else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
const tableCellNode = selection.focus.getNode();

@@ -918,3 +919,3 @@

}
} else if (lexical.$isGridSelection(selection) && event.shiftKey) {
} else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
const tableCellNode = selection.focus.getNode();

@@ -972,3 +973,3 @@

}
} else if (lexical.$isGridSelection(selection) && event.shiftKey) {
} else if (lexical.DEPRECATED_$isGridSelection(selection) && event.shiftKey) {
const tableCellNode = selection.focus.getNode();

@@ -989,3 +990,4 @@

}, lexical.COMMAND_PRIORITY_CRITICAL));
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, () => {
const deleteTextHandler = command => () => {
const selection = lexical.$getSelection();

@@ -997,3 +999,3 @@

if (lexical.$isGridSelection(selection)) {
if (lexical.DEPRECATED_$isGridSelection(selection)) {
tableSelection.clearText();

@@ -1008,16 +1010,57 @@ return true;

const paragraphNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isParagraphNode(n));
const anchorNode = selection.anchor.getNode();
const focusNode = selection.focus.getNode();
const isAnchorInside = tableNode.isParentOf(anchorNode);
const isFocusInside = tableNode.isParentOf(focusNode);
const selectionContainsPartialTable = isAnchorInside && !isFocusInside || isFocusInside && !isAnchorInside;
if (!lexical.$isParagraphNode(paragraphNode)) {
if (selectionContainsPartialTable) {
tableSelection.clearText();
return true;
}
const parentElementNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isElementNode(n) && $isTableCellNode(n.getParent()));
const nearestElementNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isElementNode(n));
if (!lexical.$isElementNode(parentElementNode) || !lexical.$isElementNode(nearestElementNode)) {
return false;
}
if (selection.isCollapsed() && selection.anchor.offset === 0 && paragraphNode.getPreviousSiblings().length === 0) {
const clearCell = () => {
const newParagraphNode = lexical.$createParagraphNode();
const textNode = lexical.$createTextNode();
newParagraphNode.append(textNode);
tableCellNode.append(newParagraphNode);
tableCellNode.getChildren().forEach(child => {
if (child !== newParagraphNode) {
child.remove();
}
});
};
if (command === lexical.DELETE_LINE_COMMAND && parentElementNode.getPreviousSibling() === null) {
clearCell();
return true;
}
if (command === lexical.DELETE_CHARACTER_COMMAND || command === lexical.DELETE_WORD_COMMAND) {
if (selection.isCollapsed() && selection.anchor.offset === 0 && parentElementNode === nearestElementNode && parentElementNode.getPreviousSibling() === null) {
return true;
}
if (!lexical.$isParagraphNode(parentElementNode) && parentElementNode.getTextContentSize() === 0) {
clearCell();
return true;
}
}
}
return false;
}, lexical.COMMAND_PRIORITY_CRITICAL));
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
};
[lexical.DELETE_WORD_COMMAND, lexical.DELETE_LINE_COMMAND, lexical.DELETE_CHARACTER_COMMAND].forEach(command => {
tableSelection.listenersToRemove.add(editor.registerCommand(command, deleteTextHandler(command), lexical.COMMAND_PRIORITY_CRITICAL));
});
const deleteCellHandler = event => {
const selection = lexical.$getSelection();

@@ -1029,3 +1072,3 @@

if (lexical.$isGridSelection(selection)) {
if (lexical.DEPRECATED_$isGridSelection(selection)) {
event.preventDefault();

@@ -1044,3 +1087,6 @@ event.stopPropagation();

return false;
}, lexical.COMMAND_PRIORITY_CRITICAL));
};
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_DELETE_COMMAND, deleteCellHandler, lexical.COMMAND_PRIORITY_CRITICAL));
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, payload => {

@@ -1053,3 +1099,3 @@ const selection = lexical.$getSelection();

if (lexical.$isGridSelection(selection)) {
if (lexical.DEPRECATED_$isGridSelection(selection)) {
tableSelection.formatCells(payload);

@@ -1074,3 +1120,3 @@ return true;

if (lexical.$isGridSelection(selection)) {
if (lexical.DEPRECATED_$isGridSelection(selection)) {
tableSelection.clearHighlight();

@@ -1119,7 +1165,2 @@ return false;

if (selection !== prevSelection && (lexical.$isGridSelection(selection) || lexical.$isGridSelection(prevSelection)) && tableSelection.gridSelection !== selection) {
tableSelection.updateTableGridSelection(lexical.$isGridSelection(selection) && tableNode.isSelected() ? selection : null);
return false;
}
if (selection && lexical.$isRangeSelection(selection) && !selection.isCollapsed()) {

@@ -1130,12 +1171,11 @@ const anchorNode = selection.anchor.getNode();

const isFocusInside = tableNode.isParentOf(focusNode);
const containsPartialTable = isAnchorInside && !isFocusInside || isFocusInside && !isAnchorInside;
const selectionContainsPartialTable = isAnchorInside && !isFocusInside || isFocusInside && !isAnchorInside;
const selectionIsInsideTable = isAnchorInside && isFocusInside && !tableNode.isSelected();
if (containsPartialTable) {
if (selectionContainsPartialTable) {
const isBackward = selection.isBackward();
const modifiedSelection = lexical.$createRangeSelection();
const tableIndex = tableNode.getIndexWithinParent();
const parentKey = tableNode.getParentOrThrow().getKey();
modifiedSelection.anchor.set(selection.anchor.key, selection.anchor.offset, selection.anchor.type); // Set selection to before or after table on the root node.
modifiedSelection.focus.set(parentKey, isBackward ? tableIndex - 1 : tableIndex + 1, 'element');
const tableKey = tableNode.getKey();
modifiedSelection.anchor.set(selection.anchor.key, selection.anchor.offset, selection.anchor.type);
modifiedSelection.focus.set(tableKey, isBackward ? 0 : tableNode.getChildrenSize(), 'element');
isRangeSelectionHijacked = true;

@@ -1145,5 +1185,33 @@ lexical.$setSelection(modifiedSelection);

return true;
} else if (selectionIsInsideTable) {
const {
grid
} = tableSelection;
if (selection.getNodes().filter($isTableCellNode).length === grid.rows * grid.columns) {
const gridSelection = lexical.DEPRECATED_$createGridSelection();
const tableKey = tableNode.getKey();
const firstCell = tableNode.getFirstChildOrThrow().getFirstChild();
const lastCell = tableNode.getLastChildOrThrow().getLastChild();
if (firstCell != null && lastCell != null) {
gridSelection.set(tableKey, firstCell.getKey(), lastCell.getKey());
lexical.$setSelection(gridSelection);
tableSelection.updateTableGridSelection(gridSelection);
return true;
}
}
}
}
if (selection && !selection.is(prevSelection) && (lexical.DEPRECATED_$isGridSelection(selection) || lexical.DEPRECATED_$isGridSelection(prevSelection)) && tableSelection.gridSelection && !tableSelection.gridSelection.is(prevSelection)) {
if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey) {
tableSelection.updateTableGridSelection(selection);
} else if (!lexical.DEPRECATED_$isGridSelection(selection) && lexical.DEPRECATED_$isGridSelection(prevSelection) && prevSelection.gridKey === tableSelection.tableNodeKey) {
tableSelection.updateTableGridSelection(null);
}
return false;
}
if (tableSelection.hasHijackedSelectionStyles && !tableNode.isSelected()) {

@@ -1399,3 +1467,3 @@ $removeHighlightStyleToTable(tableSelection);

function $isSelectionInTable(selection, tableNode) {
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
if (lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection)) {
const isAnchorInside = tableNode.isParentOf(selection.anchor.getNode());

@@ -1428,3 +1496,3 @@ const isFocusInside = tableNode.isParentOf(selection.focus.getNode());

/** @noInheritDoc */
class TableNode extends lexical.GridNode {
class TableNode extends lexical.DEPRECATED_GridNode {
/** @internal */

@@ -1443,3 +1511,3 @@ static getType() {

conversion: convertTableElement,
priority: 0
priority: 1
})

@@ -1510,2 +1578,6 @@ };

isShadowRoot() {
return true;
}
getCordsFromCellNode(tableCellNode, grid) {

@@ -1770,3 +1842,3 @@ const {

}
function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, columnCount) {
function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, columnCount, grid) {
const tableRows = tableNode.getChildren();

@@ -1779,5 +1851,21 @@

for (let c = 0; c < columnCount; c++) {
const tableRowChildren = currentTableRowNode.getChildren();
if (targetIndex >= tableRowChildren.length || targetIndex < 0) {
throw new Error('Table column target index out of range');
}
const targetCell = tableRowChildren[targetIndex];
if (!$isTableCellNode(targetCell)) {
throw Error(`Expected table cell`);
}
const {
left,
right
} = $getTableCellSiblingsFromTableCellNode(targetCell, grid);
let headerState = TableCellHeaderStates.NO_STATUS;
if (r === 0) {
if (left && left.hasHeaderState(TableCellHeaderStates.ROW) || right && right.hasHeaderState(TableCellHeaderStates.ROW)) {
headerState |= TableCellHeaderStates.ROW;

@@ -1788,10 +1876,3 @@ }

newTableCell.append(lexical.$createParagraphNode());
const tableRowChildren = currentTableRowNode.getChildren();
if (targetIndex >= tableRowChildren.length || targetIndex < 0) {
throw new Error('Table column target index out of range');
}
const targetCell = tableRowChildren[targetIndex];
if (shouldInsertAfter) {

@@ -1798,0 +1879,0 @@ targetCell.insertAfter(newTableCell);

@@ -7,54 +7,58 @@ /**

*/
'use strict';var f=require("lexical"),p=require("@lexical/utils");let q={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
class t extends f.GridCellNode{static getType(){return"tablecell"}static clone(a){return new t(a.__headerState,a.__colSpan,a.__width,a.__key)}static importDOM(){return{td:()=>({conversion:w,priority:0}),th:()=>({conversion:w,priority:0})}}static importJSON(a){return x(a.headerState,a.colSpan,a.width||void 0)}constructor(a=q.NO_STATUS,b=1,d,k){super(b,k);this.__headerState=a;this.__width=d}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);p.addClassNamesToElement(b,
a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));if(a){let b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),colSpan:super.__colSpan,headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}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}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!==q.NO_STATUS}updateDOM(a){return a.__headerState!==
this.__headerState||a.__width!==this.__width}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function w(a){a=a.nodeName.toLowerCase();return{forChild:(b,d)=>{if(y(d)&&!f.$isElementNode(b)){d=f.$createParagraphNode();if(f.$isLineBreakNode(b)&&"\n"===b.getTextContent())return null;d.append(b);return d}return b},node:x("th"===a?q.ROW:q.NO_STATUS)}}function x(a,b=1,d){return new t(a,b,d)}function y(a){return a instanceof t}
class z extends f.GridRowNode{static getType(){return"tablerow"}static clone(a){return new z(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:A,priority:0})}}static importJSON(a){return B(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);p.addClassNamesToElement(b,a.theme.tableRow);return b}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 A(){return{node:B()}}function B(a){return new z(a)}function C(a){return a instanceof z}function D(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
'use strict';var d=require("lexical"),n=require("@lexical/utils");let q={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
class t extends d.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){return new t(a.__headerState,a.__colSpan,a.__width,a.__key)}static importDOM(){return{td:()=>({conversion:x,priority:0}),th:()=>({conversion:x,priority:0})}}static importJSON(a){return z(a.headerState,a.colSpan,a.width||void 0)}constructor(a=q.NO_STATUS,b=1,e,h){super(b,h);this.__headerState=a;this.__width=e}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);
n.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));if(a){let b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),colSpan:super.__colSpan,headerState:this.__headerState,
type:"tablecell",width:this.getWidth()}}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}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!==q.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
function x(a){a=a.nodeName.toLowerCase();return{forChild:(b,e)=>{if(B(e)&&!d.$isElementNode(b)){e=d.$createParagraphNode();if(d.$isLineBreakNode(b)&&"\n"===b.getTextContent())return null;e.append(b);return e}return b},node:z("th"===a?q.ROW:q.NO_STATUS)}}function z(a,b=1,e){return new t(a,b,e)}function B(a){return a instanceof t}
class C extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:D,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);n.addClassNamesToElement(b,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 D(){return{node:E()}}function E(a){return new C(a)}function F(a){return a instanceof C}function H(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
if("undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement){let a=document.createElement("style");a.innerHTML="\n table.disable-selection {\n -webkit-touch-callout: none;\n -webkit-user-select: none; \n -khtml-user-select: none; \n -moz-user-select: none; \n -ms-user-select: none; \n user-select: none;\n }\n \n .disable-selection span::selection{\n background-color: transparent;\n }\n .disable-selection br::selection{\n background-color: transparent;\n }\n ";
document.body&&document.body.append(a)}
class E{constructor(a,b){this.isHighlightingCells=!1;this.currentY=this.currentX=this.startY=this.startX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
{this.editor.update(()=>{var d=!1;for(let k=0;k<b.length;k++){const c=b[k].target.nodeName;if("TABLE"===c||"TR"===c){d=!0;break}}if(d){d=this.editor.getElementByKey(this.tableNodeKey);if(!d)throw Error("Expected to find TableElement in DOM");this.grid=F(d)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=F(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){this.editor.update(()=>{var a=f.$getNodeByKey(this.tableNodeKey);
if(!G(a))throw Error("Expected TableNode.");a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a=F(a);this.isHighlightingCells=!1;this.currentY=this.currentX=this.startY=this.startX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;H(a,null);f.$setSelection(null);this.editor.dispatchCommand(f.SELECTION_CHANGE_COMMAND,void 0);this.enableHighlightStyle()})}enableHighlightStyle(){this.editor.update(()=>
{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.add("disable-selection");this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){if(null!=a){this.gridSelection=a;this.isHighlightingCells=
!0;this.disableHighlightStyle();let b=this.editor.getElementByKey(a.anchor.key);a=this.editor.getElementByKey(a.focus.key);if(b&&a){let d=window.getSelection();d&&d.setBaseAndExtent(b,0,a,0)}H(this.grid,this.gridSelection)}else this.clearHighlight()}adjustFocusCellForSelection(a,b=!1){this.editor.update(()=>{var d=f.$getNodeByKey(this.tableNodeKey);if(!G(d))throw Error("Expected TableNode.");if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");d=a.x;
let k=a.y;this.focusCell=a;let c=window.getSelection();null!==this.anchorCell&&c&&c.setBaseAndExtent(this.anchorCell.elem,0,a.elem,0);if(!this.isHighlightingCells&&(this.startX!==d||this.startY!==k||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(d===this.currentX&&k===this.currentY)return;this.currentX=d;this.currentY=k;this.isHighlightingCells&&(d=f.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&y(d)&&(d=d.getKey(),this.gridSelection=
f.$createGridSelection(),this.focusCellNodeKey=d,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),f.$setSelection(this.gridSelection),this.editor.dispatchCommand(f.SELECTION_CHANGE_COMMAND,void 0),H(this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.editor.update(()=>{this.anchorCell=a;this.startX=a.x;this.startY=a.y;var b=window.getSelection();b&&b.setBaseAndExtent(a.elem,0,a.elem,0);b=f.$getNearestNodeFromDOMNode(a.elem);y(b)&&(b=b.getKey(),
this.gridSelection=f.$createGridSelection(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=f.$getSelection();f.$isGridSelection(b)||D(11);let d=f.$createRangeSelection(),k=d.anchor,c=d.focus;b.getNodes().forEach(h=>{y(h)&&0!==h.getTextContentSize()&&(k.set(h.getKey(),0,"element"),c.set(h.getKey(),h.getChildrenSize(),"element"),d.formatText(a))});f.$setSelection(b);this.editor.dispatchCommand(f.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){this.editor.update(()=>{let a=f.$getNodeByKey(this.tableNodeKey);
if(!G(a))throw Error("Expected TableNode.");var b=f.$getSelection();f.$isGridSelection(b)||D(11);b=b.getNodes().filter(y);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),this.clearHighlight()):(b.forEach(d=>{if(f.$isElementNode(d)){let k=f.$createParagraphNode(),c=f.$createTextNode();k.append(c);d.append(k);d.getChildren().forEach(h=>{h!==k&&h.remove()})}}),H(this.grid,null),f.$setSelection(null),this.editor.dispatchCommand(f.SELECTION_CHANGE_COMMAND,void 0))})}}
function I(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}
function F(a){let b=[],d={cells:b,columns:0,rows:0};var k=a.firstChild;let c=a=0;for(b.length=0;null!=k;){var h=k.nodeName;if("TD"===h||"TH"===h)h={elem:k,highlighted:!1,x:a,y:c},k._cell=h,void 0===b[c]&&(b[c]=[]),b[c][a]=h;else if(h=k.firstChild,null!=h){k=h;continue}h=k.nextSibling;if(null!=h)a++,k=h;else if(h=k.parentNode,null!=h){k=h.nextSibling;if(null==k)break;c++;a=0}}d.columns=a+1;d.rows=c+1;return d}
function H(a,b){let d=[],k=new Set(b?b.getNodes():[]);J(a,(c,h)=>{let n=c.elem;k.has(h)?(c.highlighted=!0,n.style.setProperty("background-color","rgb(172, 206, 247)"),n.style.setProperty("caret-color","transparent"),d.push(c)):(c.highlighted=!1,n.style.removeProperty("background-color"),n.style.removeProperty("caret-color"),n.getAttribute("style")||n.removeAttribute("style"))});return d}
function J(a,b){({cells:a}=a);for(let d=0;d<a.length;d++){let k=a[d];for(let c=0;c<k.length;c++){let h=k[c],n=f.$getNearestNodeFromDOMNode(h.elem);null!==n&&b(h,n,{x:c,y:d})}}}function K(a){a.disableHighlightStyle();J(a.grid,b=>{let d=b.elem;b.highlighted=!0;d.style.setProperty("background-color","rgb(172, 206, 247)");d.style.setProperty("caret-color","transparent")})}
function O(a){a.enableHighlightStyle();J(a.grid,b=>{let d=b.elem;b.highlighted=!1;d.style.removeProperty("background-color");d.style.removeProperty("caret-color");d.getAttribute("style")||d.removeAttribute("style")})}
let Q=(a,b,d,k,c)=>{const h="forward"===c;switch(c){case "backward":case "forward":return d!==(h?a.grid.columns-1:0)?P(b.getCellNodeFromCordsOrThrow(d+(h?1:-1),k,a.grid)):k!==(h?a.grid.rows-1:0)?P(b.getCellNodeFromCordsOrThrow(h?0:a.grid.columns-1,k+(h?1:-1),a.grid)):h?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==k?P(b.getCellNodeFromCordsOrThrow(d,k-1,a.grid)):b.selectPrevious(),!0;case "down":return k!==a.grid.rows-1?P(b.getCellNodeFromCordsOrThrow(d,k+1,a.grid)):b.selectNext(),!0;
default:return!1}},R=(a,b,d,k,c)=>{const h="forward"===c;switch(c){case "backward":case "forward":return d!==(h?a.grid.columns-1:0)&&a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(d+(h?1:-1),k,a.grid)),!0;case "up":return 0!==k?(a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(d,k-1,a.grid)),!0):!1;case "down":return k!==a.grid.rows-1?(a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(d,k+1,a.grid)),!0):!1;default:return!1}};
function S(a,b){if(f.$isRangeSelection(a)||f.$isGridSelection(a)){let d=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return d&&a}return!1}function P(a){let b=a.getChildren().find(d=>f.$isParagraphNode(d));f.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
class T extends f.GridNode{static getType(){return"table"}static clone(a){return new T(a.__key)}static importDOM(){return{table:()=>({conversion:U,priority:0})}}static importJSON(){return V()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");p.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let d=b.cloneNode(),k=document.createElement("colgroup"),
c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();if(!C(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let h=0;h<b;h++){let n=document.createElement("col");k.append(n)}d.replaceChildren(k,c);return d}}}}canExtractContents(){return!1}canBeEmpty(){return!1}getCordsFromCellNode(a,b){let {rows:d,cells:k}=b;for(b=0;b<d;b++){var c=k[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:h})=>f.$getNearestNodeFromDOMNode(h)===
a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,d){({cells:d}=d);b=d[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,d){a=this.getCellFromCords(a,b,d);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,d){a=this.getCellFromCords(a,b,d);if(null==a)return null;a=f.$getNearestNodeFromDOMNode(a.elem);return y(a)?a:null}getCellNodeFromCordsOrThrow(a,b,d){a=this.getCellNodeFromCords(a,b,d);if(!a)throw Error("Node at cords not TableCellNode.");
return a}canSelectBefore(){return!0}canIndent(){return!1}}function U(){return{node:V()}}function V(){return new T}function G(a){return a instanceof T}function W(a){a=p.$findMatchingParent(a,b=>C(b));if(C(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=p.$findMatchingParent(a,b=>G(b));if(G(a))return a;throw Error("Expected table cell to be inside of table.");}let Y=f.createCommand();exports.$createTableCellNode=x;exports.$createTableNode=V;
exports.$createTableNodeWithDimensions=function(a,b,d=!0){let k=V();for(let h=0;h<a;h++){let n=B();for(let r=0;r<b;r++){var c=q.NO_STATUS;d&&(0===h&&(c|=q.ROW),0===r&&(c|=q.COLUMN));c=x(c);let v=f.$createParagraphNode();v.append(f.$createTextNode());c.append(v);n.append(c)}k.append(n)}return k};exports.$createTableRowNode=B;
exports.$deleteTableColumn=function(a,b){let d=a.getChildren();for(let c=0;c<d.length;c++){var k=d[c];if(C(k)){k=k.getChildren();if(b>=k.length||0>b)throw Error("Table column target index out of range");k[b].remove()}}return a};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return F(a)};exports.$getTableCellNodeFromLexicalNode=function(a){a=p.$findMatchingParent(a,b=>y(b));return y(a)?a:null};
exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=X;exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return X(b).getChildren().findIndex(d=>d.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
exports.$insertTableColumn=function(a,b,d=!0,k){let c=a.getChildren();for(let r=0;r<c.length;r++){let v=c[r];if(C(v))for(let g=0;g<k;g++){var h=q.NO_STATUS;0===r&&(h|=q.ROW);h=x(h);h.append(f.$createParagraphNode());var n=v.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];d?n.insertAfter(h):n.insertBefore(h)}}return a};
exports.$insertTableRow=function(a,b,d=!0,k,c){var h=a.getChildren();if(b>=h.length||0>b)throw Error("Table row target index out of range");b=h[b];if(C(b))for(h=0;h<k;h++){let v=b.getChildren(),g=v.length,e=B();for(let l=0;l<g;l++){var n=v[l];y(n)||D(12);var r=c;let m=X(n),{x:u,y:L}=m.getCordsFromCellNode(n,r);n={above:m.getCellNodeFromCords(u,L-1,r),below:m.getCellNodeFromCords(u,L+1,r),left:m.getCellNodeFromCords(u-1,L,r),right:m.getCellNodeFromCords(u+1,L,r)};let {above:M,below:N}=n;n=q.NO_STATUS;
r=M&&M.getWidth()||N&&N.getWidth()||void 0;if(M&&M.hasHeaderState(q.COLUMN)||N&&N.hasHeaderState(q.COLUMN))n|=q.COLUMN;n=x(n,1,r);n.append(f.$createParagraphNode());e.append(n)}d?b.insertAfter(e):b.insertBefore(e)}else throw Error("Row before insertion index does not exist.");return a};exports.$isTableCellNode=y;exports.$isTableNode=G;exports.$isTableRowNode=C;
exports.$removeTableRowAtIndex=function(a,b){let d=a.getChildren();if(b>=d.length||0>b)throw Error("Expected table cell to be inside of table row.");d[b].remove();return a};exports.INSERT_TABLE_COMMAND=Y;exports.TableCellHeaderStates=q;exports.TableCellNode=t;exports.TableNode=T;exports.TableRowNode=z;exports.TableSelection=E;
exports.applyTableHandlers=function(a,b,d){let k=d.getRootElement();if(null===k)throw Error("No root element.");let c=new E(d,a.getKey());b.__lexicalTableSelection=c;let h=!1,n=!1;b.addEventListener("dblclick",g=>{let e=I(g.target);null!==e&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),c.setAnchorCellForSelection(e),c.adjustFocusCellForSelection(e,!0),h=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var e=I(g.target);null!==e&&(c.setAnchorCellForSelection(e),
document.addEventListener("mouseup",()=>{h=!1},{capture:!0,once:!0}))}},0)});b.addEventListener("mousemove",g=>{n&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(h){let e=I(g.target);if(null!==e){let l=e.x,m=e.y;h&&(c.startX!==l||c.startY!==m||c.isHighlightingCells)&&(g.preventDefault(),h=!0,c.adjustFocusCellForSelection(e))}}});b.addEventListener("mouseup",()=>{h&&(h=!1)});b.addEventListener("mouseleave",()=>{});let r=g=>{h=!0;0===g.button&&d.update(()=>{const e=f.$getSelection();
if(f.$isGridSelection(e)&&e.gridKey===c.tableNodeKey&&k.contains(g.target))return c.clearHighlight()})};window.addEventListener("mousedown",r);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",r));let v=()=>{h=!1};window.addEventListener("mouseup",v);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",v));c.listenersToRemove.add(d.registerCommand(f.KEY_ARROW_DOWN_COMMAND,g=>{var e=f.$getSelection();if(!S(e,a))return!1;if(f.$isRangeSelection(e)){if(e.isCollapsed()){var l=
p.$findMatchingParent(e.anchor.getNode(),u=>y(u));if(!y(l))return!1;var m=a.getCordsFromCellNode(l,c.grid);e=p.$findMatchingParent(e.anchor.getNode(),u=>f.$isElementNode(u));if(null==e)throw Error("Expected BlockNode Parent");if((l=l.getLastChild())&&e.isParentOf(l)||e===l||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),R(c,a,m.x,m.y,"down")):Q(c,a,m.x,m.y,"down")}}else if(f.$isGridSelection(e)&&
g.shiftKey){m=e.focus.getNode();if(!y(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,m.x,m.y,"down")}return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.KEY_ARROW_UP_COMMAND,g=>{var e=f.$getSelection();if(!S(e,a))return!1;if(f.$isRangeSelection(e)){if(e.isCollapsed()){var l=p.$findMatchingParent(e.anchor.getNode(),u=>y(u));if(!y(l))return!1;var m=a.getCordsFromCellNode(l,c.grid);e=p.$findMatchingParent(e.anchor.getNode(),
u=>f.$isElementNode(u));if(null==e)throw Error("Expected BlockNode Parent");if((l=l.getLastChild())&&e.isParentOf(l)||e===l||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),R(c,a,m.x,m.y,"up")):Q(c,a,m.x,m.y,"up")}}else if(f.$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!y(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();
return R(c,a,m.x,m.y,"up")}return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.KEY_ARROW_LEFT_COMMAND,g=>{var e=f.$getSelection();if(!S(e,a))return!1;if(f.$isRangeSelection(e)){if(e.isCollapsed()){var l=p.$findMatchingParent(e.anchor.getNode(),m=>y(m));if(!y(l))return!1;l=a.getCordsFromCellNode(l,c.grid);if(null==p.$findMatchingParent(e.anchor.getNode(),m=>f.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===e.anchor.offset||g.shiftKey)return g.preventDefault(),
g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,l.y,c.grid)),R(c,a,l.x,l.y,"backward")):Q(c,a,l.x,l.y,"backward")}}else if(f.$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!y(e))return!1;e=a.getCordsFromCellNode(e,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,e.x,e.y,"backward")}return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.KEY_ARROW_RIGHT_COMMAND,
g=>{var e=f.$getSelection();if(!S(e,a))return!1;if(f.$isRangeSelection(e)){if(e.isCollapsed()){var l=p.$findMatchingParent(e.anchor.getNode(),m=>y(m));if(!y(l))return!1;l=a.getCordsFromCellNode(l,c.grid);if(null==p.$findMatchingParent(e.anchor.getNode(),m=>f.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(e.anchor.offset===e.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,
l.y,c.grid)),R(c,a,l.x,l.y,"forward")):Q(c,a,l.x,l.y,"forward")}}else if(f.$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!y(e))return!1;e=a.getCordsFromCellNode(e,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,e.x,e.y,"forward")}return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.DELETE_CHARACTER_COMMAND,()=>{let g=f.$getSelection();if(!S(g,a))return!1;if(f.$isGridSelection(g))return c.clearText(),!0;if(f.$isRangeSelection(g)){var e=
p.$findMatchingParent(g.anchor.getNode(),l=>y(l));if(!y(e))return!1;e=p.$findMatchingParent(g.anchor.getNode(),l=>f.$isParagraphNode(l));if(!f.$isParagraphNode(e))return!1;if(g.isCollapsed()&&0===g.anchor.offset&&0===e.getPreviousSiblings().length)return!0}return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.KEY_BACKSPACE_COMMAND,g=>{let e=f.$getSelection();if(!S(e,a))return!1;if(f.$isGridSelection(e))return g.preventDefault(),g.stopPropagation(),c.clearText(),!0;f.$isRangeSelection(e)&&
(g=p.$findMatchingParent(e.anchor.getNode(),l=>y(l)),y(g));return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.FORMAT_TEXT_COMMAND,g=>{let e=f.$getSelection();if(!S(e,a))return!1;if(f.$isGridSelection(e))return c.formatCells(g),!0;f.$isRangeSelection(e)&&(g=p.$findMatchingParent(e.anchor.getNode(),l=>y(l)),y(g));return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=f.$getSelection();if(!S(g,
a))return!1;f.$isGridSelection(g)?c.clearHighlight():f.$isRangeSelection(g)&&(g=p.$findMatchingParent(g.anchor.getNode(),e=>y(e)),y(g));return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.KEY_TAB_COMMAND,g=>{var e=f.$getSelection();if(!S(e,a))return!1;if(f.$isRangeSelection(e)){let l=p.$findMatchingParent(e.anchor.getNode(),m=>y(m));if(!y(l))return!1;if(e.isCollapsed())return e=a.getCordsFromCellNode(l,c.grid),g.preventDefault(),Q(c,a,e.x,e.y,g.shiftKey?"backward":
"forward"),!0}return!1},f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.FOCUS_COMMAND,()=>a.isSelected(),f.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(d.registerCommand(f.SELECTION_CHANGE_COMMAND,()=>{let g=f.$getSelection();var e=f.$getPreviousSelection();if(g!==e&&(f.$isGridSelection(g)||f.$isGridSelection(e))&&c.gridSelection!==g)return c.updateTableGridSelection(f.$isGridSelection(g)&&a.isSelected()?g:null),!1;if(g&&f.$isRangeSelection(g)&&!g.isCollapsed()){var l=
g.anchor.getNode();e=g.focus.getNode();l=a.isParentOf(l);e=a.isParentOf(e);if(l&&!e||e&&!l){e=g.isBackward();l=f.$createRangeSelection();let m=a.getIndexWithinParent(),u=a.getParentOrThrow().getKey();l.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type);l.focus.set(u,e?m-1:m+1,"element");n=!0;f.$setSelection(l);K(c);return!0}}c.hasHijackedSelectionStyles&&!a.isSelected()?(O(c),n=!1):!c.hasHijackedSelectionStyles&&a.isSelected()&&K(c);return!1},f.COMMAND_PRIORITY_CRITICAL));return c};
exports.getCellFromTarget=I;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
class I{constructor(a,b){this.isHighlightingCells=!1;this.currentY=this.currentX=this.startY=this.startX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
{this.editor.update(()=>{var e=!1;for(let h=0;h<b.length;h++){const c=b[h].target.nodeName;if("TABLE"===c||"TR"===c){e=!0;break}}if(e){e=this.editor.getElementByKey(this.tableNodeKey);if(!e)throw Error("Expected to find TableElement in DOM");this.grid=J(e)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=J(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){this.editor.update(()=>{var a=d.$getNodeByKey(this.tableNodeKey);
if(!K(a))throw Error("Expected TableNode.");a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a=J(a);this.isHighlightingCells=!1;this.currentY=this.currentX=this.startY=this.startX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;L(a,null);d.$setSelection(null);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0);this.enableHighlightStyle()})}enableHighlightStyle(){this.editor.update(()=>
{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.add("disable-selection");this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){null!=a&&a.gridKey===this.tableNodeKey&&(this.gridSelection=
a,this.isHighlightingCells=!0,this.disableHighlightStyle(),L(this.grid,this.gridSelection));null==a&&this.clearHighlight()}adjustFocusCellForSelection(a,b=!1){this.editor.update(()=>{var e=d.$getNodeByKey(this.tableNodeKey);if(!K(e))throw Error("Expected TableNode.");if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");e=a.x;let h=a.y;this.focusCell=a;if(null!==this.anchorCell){let c=window.getSelection();c&&c.setBaseAndExtent(this.anchorCell.elem,
0,this.anchorCell.elem,0)}if(!this.isHighlightingCells&&(this.startX!==e||this.startY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.currentX&&h===this.currentY)return;this.currentX=e;this.currentY=h;this.isHighlightingCells&&(e=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(e)&&(e=e.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),this.focusCellNodeKey=e,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,
this.focusCellNodeKey),d.$setSelection(this.gridSelection),this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),L(this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.editor.update(()=>{if(this.anchorCell===a&&this.isHighlightingCells){var b=window.getSelection();b&&b.setBaseAndExtent(a.elem,0,a.elem,0)}this.anchorCell=a;this.startX=a.x;this.startY=a.y;b=d.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=
b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||H(11);let e=d.$createRangeSelection(),h=e.anchor,c=e.focus;b.getNodes().forEach(l=>{B(l)&&0!==l.getTextContentSize()&&(h.set(l.getKey(),0,"element"),c.set(l.getKey(),l.getChildrenSize(),"element"),e.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){this.editor.update(()=>{let a=d.$getNodeByKey(this.tableNodeKey);if(!K(a))throw Error("Expected TableNode.");
var b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||H(11);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),d.$getRoot().selectStart()):(b.forEach(e=>{if(d.$isElementNode(e)){let h=d.$createParagraphNode(),c=d.$createTextNode();h.append(c);e.append(h);e.getChildren().forEach(l=>{l!==h&&l.remove()})}}),L(this.grid,null),d.$setSelection(null),this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}
function M(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}
function J(a){let b=[],e={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var l=h.nodeName;if("TD"===l||"TH"===l)l={elem:h,highlighted:!1,x:a,y:c},h._cell=l,void 0===b[c]&&(b[c]=[]),b[c][a]=l;else if(l=h.firstChild,null!=l){h=l;continue}l=h.nextSibling;if(null!=l)a++,h=l;else if(l=h.parentNode,null!=l){h=l.nextSibling;if(null==h)break;c++;a=0}}e.columns=a+1;e.rows=c+1;return e}
function L(a,b){let e=[],h=new Set(b?b.getNodes():[]);N(a,(c,l)=>{let p=c.elem;h.has(l)?(c.highlighted=!0,p.style.setProperty("background-color","rgb(172, 206, 247)"),p.style.setProperty("caret-color","transparent"),e.push(c)):(c.highlighted=!1,p.style.removeProperty("background-color"),p.style.removeProperty("caret-color"),p.getAttribute("style")||p.removeAttribute("style"))});return e}
function N(a,b){({cells:a}=a);for(let e=0;e<a.length;e++){let h=a[e];for(let c=0;c<h.length;c++){let l=h[c],p=d.$getNearestNodeFromDOMNode(l.elem);null!==p&&b(l,p,{x:c,y:e})}}}function O(a){a.disableHighlightStyle();N(a.grid,b=>{let e=b.elem;b.highlighted=!0;e.style.setProperty("background-color","rgb(172, 206, 247)");e.style.setProperty("caret-color","transparent")})}
function P(a){a.enableHighlightStyle();N(a.grid,b=>{let e=b.elem;b.highlighted=!1;e.style.removeProperty("background-color");e.style.removeProperty("caret-color");e.getAttribute("style")||e.removeAttribute("style")})}
let R=(a,b,e,h,c)=>{const l="forward"===c;switch(c){case "backward":case "forward":return e!==(l?a.grid.columns-1:0)?Q(b.getCellNodeFromCordsOrThrow(e+(l?1:-1),h,a.grid)):h!==(l?a.grid.rows-1:0)?Q(b.getCellNodeFromCordsOrThrow(l?0:a.grid.columns-1,h+(l?1:-1),a.grid)):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?Q(b.getCellNodeFromCordsOrThrow(e,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?Q(b.getCellNodeFromCordsOrThrow(e,h+1,a.grid)):b.selectNext(),!0;
default:return!1}},S=(a,b,e,h,c)=>{const l="forward"===c;switch(c){case "backward":case "forward":return e!==(l?a.grid.columns-1:0)&&a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(e+(l?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(e,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(e,h+1,a.grid)),!0):!1;default:return!1}};
function T(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let e=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return e&&a}return!1}function Q(a){let b=a.getChildren().find(e=>d.$isParagraphNode(e));d.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
class U extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new U(a.__key)}static importDOM(){return{table:()=>({conversion:aa,priority:1})}}static importJSON(){return V()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");n.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let e=b.cloneNode(),h=document.createElement("colgroup"),
c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let p=document.createElement("col");h.append(p)}e.replaceChildren(h,c);return e}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:e,cells:h}=b;for(b=0;b<e;b++){var c=h[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:l})=>d.$getNearestNodeFromDOMNode(l)===
a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,e){({cells:e}=e);b=e[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,e){a=this.getCellFromCords(a,b,e);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,e){a=this.getCellFromCords(a,b,e);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,e){a=this.getCellNodeFromCords(a,b,e);if(!a)throw Error("Node at cords not TableCellNode.");
return a}canSelectBefore(){return!0}canIndent(){return!1}}function aa(){return{node:V()}}function V(){return new U}function K(a){return a instanceof U}function W(a){a=n.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function Y(a){a=n.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}
function Z(a,b){let e=Y(a),{x:h,y:c}=e.getCordsFromCellNode(a,b);return{above:e.getCellNodeFromCords(h,c-1,b),below:e.getCellNodeFromCords(h,c+1,b),left:e.getCellNodeFromCords(h-1,c,b),right:e.getCellNodeFromCords(h+1,c,b)}}let ba=d.createCommand();exports.$createTableCellNode=z;exports.$createTableNode=V;
exports.$createTableNodeWithDimensions=function(a,b,e=!0){let h=V();for(let l=0;l<a;l++){let p=E();for(let u=0;u<b;u++){var c=q.NO_STATUS;e&&(0===l&&(c|=q.ROW),0===u&&(c|=q.COLUMN));c=z(c);let v=d.$createParagraphNode();v.append(d.$createTextNode());c.append(v);p.append(c)}h.append(p)}return h};exports.$createTableRowNode=E;
exports.$deleteTableColumn=function(a,b){let e=a.getChildren();for(let c=0;c<e.length;c++){var h=e[c];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return J(a)};exports.$getTableCellNodeFromLexicalNode=function(a){a=n.$findMatchingParent(a,b=>B(b));return B(a)?a:null};
exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=Y;exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return Y(b).getChildren().findIndex(e=>e.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
exports.$insertTableColumn=function(a,b,e=!0,h,c){let l=a.getChildren();for(let v=0;v<l.length;v++){let A=l[v];if(F(A))for(let y=0;y<h;y++){var p=A.getChildren();if(b>=p.length||0>b)throw Error("Table column target index out of range");p=p[b];B(p)||H(12);let {left:g,right:f}=Z(p,c);var u=q.NO_STATUS;if(g&&g.hasHeaderState(q.ROW)||f&&f.hasHeaderState(q.ROW))u|=q.ROW;u=z(u);u.append(d.$createParagraphNode());e?p.insertAfter(u):p.insertBefore(u)}}return a};
exports.$insertTableRow=function(a,b,e=!0,h,c){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<h;l++){let u=b.getChildren(),v=u.length,A=E();for(let y=0;y<v;y++){var p=u[y];B(p)||H(12);let {above:g,below:f}=Z(p,c);p=q.NO_STATUS;let k=g&&g.getWidth()||f&&f.getWidth()||void 0;if(g&&g.hasHeaderState(q.COLUMN)||f&&f.hasHeaderState(q.COLUMN))p|=q.COLUMN;p=z(p,1,k);p.append(d.$createParagraphNode());A.append(p)}e?b.insertAfter(A):b.insertBefore(A)}else throw Error("Row before insertion index does not exist.");
return a};exports.$isTableCellNode=B;exports.$isTableNode=K;exports.$isTableRowNode=F;exports.$removeTableRowAtIndex=function(a,b){let e=a.getChildren();if(b>=e.length||0>b)throw Error("Expected table cell to be inside of table row.");e[b].remove();return a};exports.INSERT_TABLE_COMMAND=ba;exports.TableCellHeaderStates=q;exports.TableCellNode=t;exports.TableNode=U;exports.TableRowNode=C;exports.TableSelection=I;
exports.applyTableHandlers=function(a,b,e){let h=e.getRootElement();if(null===h)throw Error("No root element.");let c=new I(e,a.getKey());b.__lexicalTableSelection=c;let l=!1,p=!1;b.addEventListener("dblclick",g=>{let f=M(g.target);null!==f&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),c.setAnchorCellForSelection(f),c.adjustFocusCellForSelection(f,!0),l=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var f=M(g.target);null!==f&&(g.preventDefault(),
g.stopPropagation(),g.stopImmediatePropagation(),c.setAnchorCellForSelection(f))}},0)});b.addEventListener("mousemove",g=>{p&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(l){let f=M(g.target);if(null!==f){let k=f.x,m=f.y;l&&(c.startX!==k||c.startY!==m||c.isHighlightingCells)&&(g.preventDefault(),l=!0,c.adjustFocusCellForSelection(f))}}});b.addEventListener("mouseleave",()=>{});let u=g=>{l=!0;0===g.button&&e.update(()=>{const f=d.$getSelection();if(d.DEPRECATED_$isGridSelection(f)&&
f.gridKey===c.tableNodeKey&&h.contains(g.target))return c.clearHighlight()})};window.addEventListener("mousedown",u);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",u));let v=g=>{l&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation(),l=!1)};window.addEventListener("mouseup",v);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",v));c.listenersToRemove.add(()=>b.addEventListener("mouseup",v));c.listenersToRemove.add(()=>b.removeEventListener("mouseup",
v));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_DOWN_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=n.$findMatchingParent(f.anchor.getNode(),r=>B(r));if(!B(k))return!1;var m=a.getCordsFromCellNode(k,c.grid);f=n.$findMatchingParent(f.anchor.getNode(),r=>d.$isElementNode(r));if(null==f)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&f.isParentOf(k)||f===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),
g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),S(c,a,m.x,m.y,"down")):R(c,a,m.x,m.y,"down")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){m=f.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,m.x,m.y,"down")}return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_UP_COMMAND,g=>{var f=d.$getSelection();
if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=n.$findMatchingParent(f.anchor.getNode(),r=>B(r));if(!B(k))return!1;var m=a.getCordsFromCellNode(k,c.grid);f=n.$findMatchingParent(f.anchor.getNode(),r=>d.$isElementNode(r));if(null==f)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&f.isParentOf(k)||f===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,
m.y,c.grid)),S(c,a,m.x,m.y,"up")):R(c,a,m.x,m.y,"up")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){m=f.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,m.x,m.y,"up")}return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_LEFT_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=n.$findMatchingParent(f.anchor.getNode(),
m=>B(m));if(!B(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==n.$findMatchingParent(f.anchor.getNode(),m=>d.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===f.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),S(c,a,k.x,k.y,"backward")):R(c,a,k.x,k.y,"backward")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){f=f.focus.getNode();if(!B(f))return!1;
f=a.getCordsFromCellNode(f,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,f.x,f.y,"backward")}return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=n.$findMatchingParent(f.anchor.getNode(),m=>B(m));if(!B(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==n.$findMatchingParent(f.anchor.getNode(),m=>
d.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(f.anchor.offset===f.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),S(c,a,k.x,k.y,"forward")):R(c,a,k.x,k.y,"forward")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){f=f.focus.getNode();if(!B(f))return!1;f=a.getCordsFromCellNode(f,c.grid);g.preventDefault();g.stopImmediatePropagation();
g.stopPropagation();return S(c,a,f.x,f.y,"forward")}return!1},d.COMMAND_PRIORITY_CRITICAL));let A=g=>()=>{const f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return c.clearText(),!0;if(d.$isRangeSelection(f)){const r=n.$findMatchingParent(f.anchor.getNode(),w=>B(w));if(!B(r))return!1;var k=f.anchor.getNode(),m=f.focus.getNode();k=a.isParentOf(k);m=a.isParentOf(m);if(k&&!m||m&&!k)return c.clearText(),!0;m=n.$findMatchingParent(f.anchor.getNode(),w=>d.$isElementNode(w)&&
B(w.getParent()));k=n.$findMatchingParent(f.anchor.getNode(),w=>d.$isElementNode(w));if(!d.$isElementNode(m)||!d.$isElementNode(k))return!1;const G=()=>{const w=d.$createParagraphNode(),ca=d.$createTextNode();w.append(ca);r.append(w);r.getChildren().forEach(X=>{X!==w&&X.remove()})};if(g===d.DELETE_LINE_COMMAND&&null===m.getPreviousSibling())return G(),!0;if(g===d.DELETE_CHARACTER_COMMAND||g===d.DELETE_WORD_COMMAND){if(f.isCollapsed()&&0===f.anchor.offset&&m===k&&null===m.getPreviousSibling())return!0;
if(!d.$isParagraphNode(m)&&0===m.getTextContentSize())return G(),!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(g=>{c.listenersToRemove.add(e.registerCommand(g,A(g),d.COMMAND_PRIORITY_CRITICAL))});let y=g=>{const f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return g.preventDefault(),g.stopPropagation(),c.clearText(),!0;d.$isRangeSelection(f)&&(g=n.$findMatchingParent(f.anchor.getNode(),k=>B(k)),B(g));return!1};c.listenersToRemove.add(e.registerCommand(d.KEY_BACKSPACE_COMMAND,
y,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_DELETE_COMMAND,y,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.FORMAT_TEXT_COMMAND,g=>{let f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return c.formatCells(g),!0;d.$isRangeSelection(f)&&(g=n.$findMatchingParent(f.anchor.getNode(),k=>B(k)),B(g));return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,
()=>{var g=d.$getSelection();if(!T(g,a))return!1;d.DEPRECATED_$isGridSelection(g)?c.clearHighlight():d.$isRangeSelection(g)&&(g=n.$findMatchingParent(g.anchor.getNode(),f=>B(f)),B(g));return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_TAB_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){let k=n.$findMatchingParent(f.anchor.getNode(),m=>B(m));if(!B(k))return!1;if(f.isCollapsed())return f=a.getCordsFromCellNode(k,c.grid),g.preventDefault(),
R(c,a,f.x,f.y,g.shiftKey?"backward":"forward"),!0}return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>{let g=d.$getSelection();var f=d.$getPreviousSelection();if(g&&d.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),m=g.focus.getNode();k=a.isParentOf(k);var r=a.isParentOf(m);m=k&&!r||r&&!k;k=k&&r&&!a.isSelected();if(m)return f=
g.isBackward(),k=d.$createRangeSelection(),m=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(m,f?0:a.getChildrenSize(),"element"),p=!0,d.$setSelection(k),O(c),!0;if(k&&({grid:k}=c,g.getNodes().filter(B).length===k.rows*k.columns)){k=d.DEPRECATED_$createGridSelection();m=a.getKey();r=a.getFirstChildOrThrow().getFirstChild();let G=a.getLastChildOrThrow().getLastChild();if(null!=r&&null!=G)return k.set(m,r.getKey(),G.getKey()),d.$setSelection(k),c.updateTableGridSelection(k),
!0}}if(g&&!g.is(f)&&(d.DEPRECATED_$isGridSelection(g)||d.DEPRECATED_$isGridSelection(f))&&c.gridSelection&&!c.gridSelection.is(f))return d.DEPRECATED_$isGridSelection(g)&&g.gridKey===c.tableNodeKey?c.updateTableGridSelection(g):!d.DEPRECATED_$isGridSelection(g)&&d.DEPRECATED_$isGridSelection(f)&&f.gridKey===c.tableNodeKey&&c.updateTableGridSelection(null),!1;c.hasHijackedSelectionStyles&&!a.isSelected()?(P(c),p=!1):!c.hasHijackedSelectionStyles&&a.isSelected()&&O(c);return!1},d.COMMAND_PRIORITY_CRITICAL));
return c};exports.getCellFromTarget=M;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}

@@ -9,3 +9,3 @@ /**

import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedGridCellNode, Spread } from 'lexical';
import { GridCellNode } from 'lexical';
import { DEPRECATED_GridCellNode } from 'lexical';
export declare const TableCellHeaderStates: {

@@ -24,3 +24,3 @@ BOTH: number;

/** @noInheritDoc */
export declare class TableCellNode extends GridCellNode {
export declare class TableCellNode extends DEPRECATED_GridCellNode {
/** @internal */

@@ -47,2 +47,3 @@ __headerState: TableCellHeaderState;

updateDOM(prevNode: TableCellNode): boolean;
isShadowRoot(): boolean;
collapseAtStart(): true;

@@ -49,0 +50,0 @@ canBeEmpty(): false;

@@ -11,3 +11,3 @@ /**

import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from 'lexical';
import { GridNode } from 'lexical';
import { DEPRECATED_GridNode } from 'lexical';
export declare type SerializedTableNode = Spread<{

@@ -18,3 +18,3 @@ type: 'table';

/** @noInheritDoc */
export declare class TableNode extends GridNode {
export declare class TableNode extends DEPRECATED_GridNode {
/** @internal */

@@ -33,2 +33,3 @@ __grid?: Grid;

canBeEmpty(): false;
isShadowRoot(): boolean;
getCordsFromCellNode(tableCellNode: TableCellNode, grid: Grid): {

@@ -35,0 +36,0 @@ x: number;

@@ -9,3 +9,3 @@ /**

import type { Spread } from 'lexical';
import { DOMConversionMap, DOMConversionOutput, EditorConfig, GridRowNode, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
import { DEPRECATED_GridRowNode, DOMConversionMap, DOMConversionOutput, EditorConfig, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
export declare type SerializedTableRowNode = Spread<{

@@ -17,3 +17,3 @@ height: number;

/** @noInheritDoc */
export declare class TableRowNode extends GridRowNode {
export declare class TableRowNode extends DEPRECATED_GridRowNode {
/** @internal */

@@ -28,2 +28,3 @@ __height?: number;

createDOM(config: EditorConfig): HTMLElement;
isShadowRoot(): boolean;
setHeight(height: number): number | null | undefined;

@@ -30,0 +31,0 @@ getHeight(): number | null | undefined;

@@ -28,3 +28,3 @@ /**

export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode;
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number): TableNode;
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number, grid: Grid): TableNode;
export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode;

@@ -11,9 +11,9 @@ {

"license": "MIT",
"version": "0.4.1",
"version": "0.5.0",
"main": "LexicalTable.js",
"peerDependencies": {
"lexical": "0.4.1"
"lexical": "0.5.0"
},
"dependencies": {
"@lexical/utils": "0.4.1"
"@lexical/utils": "0.5.0"
},

@@ -20,0 +20,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc