@lexical/table 0.3.5 → 0.3.8

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.
@@ -45,7 +45,7 @@ class TableCellNode extends lexical.GridCellNode {
45
45
  }
46
46
 
47
47
  static importJSON(serializedNode) {
48
- return $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width);
48
+ return $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width || undefined);
49
49
  }
50
50
 
51
51
  constructor(headerState = TableCellHeaderStates.NO_STATUS, colSpan = 1, width, key) {
@@ -471,7 +471,10 @@ class TableSelection {
471
471
 
472
472
  if (anchorElement && focusElement) {
473
473
  const domSelection = getDOMSelection();
474
- domSelection.setBaseAndExtent(anchorElement, 0, focusElement, 0);
474
+
475
+ if (domSelection) {
476
+ domSelection.setBaseAndExtent(anchorElement, 0, focusElement, 0);
477
+ }
475
478
  }
476
479
 
477
480
  $updateDOMForSelection(this.grid, this.gridSelection);
@@ -501,7 +504,9 @@ class TableSelection {
501
504
 
502
505
  if (this.anchorCell !== null) {
503
506
  // Collapse the selection
504
- domSelection.setBaseAndExtent(this.anchorCell.elem, 0, cell.elem, 0);
507
+ if (domSelection) {
508
+ domSelection.setBaseAndExtent(this.anchorCell.elem, 0, cell.elem, 0);
509
+ }
505
510
  }
506
511
 
507
512
  if (!this.isHighlightingCells && (this.startX !== cellX || this.startY !== cellY || ignoreStart)) {
@@ -536,7 +541,11 @@ class TableSelection {
536
541
  this.startX = cell.x;
537
542
  this.startY = cell.y;
538
543
  const domSelection = getDOMSelection();
539
- domSelection.setBaseAndExtent(cell.elem, 0, cell.elem, 0);
544
+
545
+ if (domSelection) {
546
+ domSelection.setBaseAndExtent(cell.elem, 0, cell.elem, 0);
547
+ }
548
+
540
549
  const anchorTableCellNode = lexical.$getNearestNodeFromDOMNode(cell.elem);
541
550
 
542
551
  if ($isTableCellNode(anchorTableCellNode)) {
@@ -1689,7 +1698,7 @@ function $insertTableRow(tableNode, targetIndex, shouldInsertAfter = true, rowCo
1689
1698
  below
1690
1699
  } = $getTableCellSiblingsFromTableCellNode(tableCellFromTargetRow, grid);
1691
1700
  let headerState = TableCellHeaderStates.NO_STATUS;
1692
- const width = above && above.getWidth() || below && below.getWidth() || null;
1701
+ const width = above && above.getWidth() || below && below.getWidth() || undefined;
1693
1702
 
1694
1703
  if (above && above.hasHeaderState(TableCellHeaderStates.COLUMN) || below && below.hasHeaderState(TableCellHeaderStates.COLUMN)) {
1695
1704
  headerState |= TableCellHeaderStates.COLUMN;
@@ -218,7 +218,6 @@ declare export class TableSelection {
218
218
  currentX: number;
219
219
  currentY: number;
220
220
  listenersToRemove: Set<() => void>;
221
- domListeners: Set<() => void>;
222
221
  grid: Grid;
223
222
  isHighlightingCells: boolean;
224
223
  isMouseDown: boolean;
@@ -5,23 +5,23 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var f=require("lexical"),p=require("@lexical/utils");let q={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
- 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)}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,
8
+ 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,
9
9
  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()?
10
10
  "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!==
11
11
  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}
12
12
  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=
13
- 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}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
13
+ 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.");}
14
14
  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 ";
15
15
  document.body&&document.body.append(a)}
16
16
  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=>
17
17
  {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);
18
18
  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(()=>
19
19
  {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=
20
- !0;this.disableHighlightStyle();let b=this.editor.getElementByKey(a.anchor.key);a=this.editor.getElementByKey(a.focus.key);b&&a&&window.getSelection().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=
21
- a;let c=window.getSelection();null!==this.anchorCell&&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(),
22
- 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;window.getSelection().setBaseAndExtent(a.elem,0,a.elem,0);var b=f.$getNearestNodeFromDOMNode(a.elem);y(b)&&(b=b.getKey(),this.gridSelection=f.$createGridSelection(),
23
- 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.");
24
- 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))})}}
20
+ !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;
21
+ 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=
22
+ 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(),
23
+ 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);
24
+ 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))})}}
25
25
  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}
26
26
  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}
27
27
  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}
@@ -39,7 +39,7 @@ exports.$deleteTableColumn=function(a,b){let d=a.getChildren();for(let c=0;c<d.l
39
39
  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;
40
40
  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};
41
41
  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;
42
- r=M&&M.getWidth()||N&&N.getWidth()||null;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;
42
+ 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;
43
43
  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;
44
44
  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),
45
45
  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();
@@ -17,11 +17,11 @@ export declare type TableCellHeaderState = typeof TableCellHeaderStates[keyof ty
17
17
  export declare type SerializedTableCellNode = Spread<{
18
18
  headerState: TableCellHeaderState;
19
19
  type: 'tablecell';
20
- width: number;
20
+ width?: number;
21
21
  }, SerializedGridCellNode>;
22
22
  export declare class TableCellNode extends GridCellNode {
23
23
  __headerState: TableCellHeaderState;
24
- __width: number;
24
+ __width?: number;
25
25
  static getType(): 'tablecell';
26
26
  static clone(node: TableCellNode): TableCellNode;
27
27
  static importDOM(): DOMConversionMap | null;
@@ -33,8 +33,8 @@ export declare class TableCellNode extends GridCellNode {
33
33
  getTag(): string;
34
34
  setHeaderStyles(headerState: TableCellHeaderState): TableCellHeaderState;
35
35
  getHeaderStyles(): TableCellHeaderState;
36
- setWidth(width: number): number;
37
- getWidth(): number;
36
+ setWidth(width: number): number | null | undefined;
37
+ getWidth(): number | undefined;
38
38
  toggleHeaderStyle(headerStateToToggle: TableCellHeaderState): TableCellNode;
39
39
  hasHeaderState(headerState: TableCellHeaderState): boolean;
40
40
  hasHeader(): boolean;
@@ -14,7 +14,7 @@ export declare type SerializedTableNode = Spread<{
14
14
  version: 1;
15
15
  }, SerializedElementNode>;
16
16
  export declare class TableNode extends GridNode {
17
- __grid: Grid;
17
+ __grid?: Grid;
18
18
  static getType(): 'table';
19
19
  static clone(node: TableNode): TableNode;
20
20
  static importDOM(): DOMConversionMap | null;
@@ -13,7 +13,7 @@ export declare type SerializedTableRowNode = Spread<{
13
13
  version: 1;
14
14
  }, SerializedElementNode>;
15
15
  export declare class TableRowNode extends GridRowNode {
16
- __height: number;
16
+ __height?: number;
17
17
  static getType(): 'tablerow';
18
18
  static clone(node: TableRowNode): TableRowNode;
19
19
  static importDOM(): DOMConversionMap | null;
@@ -21,8 +21,8 @@ export declare class TableRowNode extends GridRowNode {
21
21
  constructor(height?: number, key?: NodeKey);
22
22
  exportJSON(): SerializedElementNode;
23
23
  createDOM(config: EditorConfig): HTMLElement;
24
- setHeight(height: number): number;
25
- getHeight(): number;
24
+ setHeight(height: number): number | null | undefined;
25
+ getHeight(): number | null | undefined;
26
26
  updateDOM(prevNode: TableRowNode): boolean;
27
27
  canBeEmpty(): false;
28
28
  canIndent(): false;
@@ -22,7 +22,6 @@ export declare class TableSelection {
22
22
  currentX: number;
23
23
  currentY: number;
24
24
  listenersToRemove: Set<() => void>;
25
- domListeners: Set<() => void>;
26
25
  grid: Grid;
27
26
  isHighlightingCells: boolean;
28
27
  startX: number;
@@ -9,9 +9,11 @@ import type { TableNode } from './LexicalTableNode';
9
9
  import type { Cell, Grid } from './LexicalTableSelection';
10
10
  import type { GridSelection, LexicalEditor, LexicalNode, RangeSelection } from 'lexical';
11
11
  import { TableSelection } from './LexicalTableSelection';
12
- export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLElement, editor: LexicalEditor): TableSelection;
13
- export declare function attachTableSelectionToTableElement(tableElement: HTMLElement, tableSelection: TableSelection): void;
14
- export declare function getTableSelectionFromTableElement(tableElement: HTMLElement): TableSelection;
12
+ declare const LEXICAL_ELEMENT_KEY = "__lexicalTableSelection";
13
+ export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor): TableSelection;
14
+ export declare type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableSelection>;
15
+ export declare function attachTableSelectionToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableSelection: TableSelection): void;
16
+ export declare function getTableSelectionFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableSelection | null;
15
17
  export declare function getCellFromTarget(node: Node): Cell | null;
16
18
  export declare function getTableGrid(tableElement: HTMLElement): Grid;
17
19
  export declare function $updateDOMForSelection(grid: Grid, selection: GridSelection | RangeSelection | null): Array<Cell>;
@@ -21,3 +23,4 @@ export declare function $forEachGridCell(grid: Grid, cb: (cell: Cell, lexicalNod
21
23
  }) => void): void;
22
24
  export declare function $addHighlightStyleToTable(tableSelection: TableSelection): void;
23
25
  export declare function $removeHighlightStyleToTable(tableSelection: TableSelection): void;
26
+ export {};
@@ -24,6 +24,6 @@ export declare type TableCellSiblings = {
24
24
  };
25
25
  export declare function $getTableCellSiblingsFromTableCellNode(tableCellNode: TableCellNode, grid: Grid): TableCellSiblings;
26
26
  export declare function $removeTableRowAtIndex(tableNode: TableNode, indexToDelete: number): TableNode;
27
- export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, rowCount: number, grid: Grid): TableNode;
28
- export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, columnCount: number): TableNode;
27
+ export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode;
28
+ export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number): TableNode;
29
29
  export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode;
package/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  *
7
7
  */
8
8
  import type { Cell } from './LexicalTableSelection';
9
+ import type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
9
10
  import type { LexicalCommand } from 'lexical';
10
11
  import { $createTableCellNode, $isTableCellNode, TableCellHeaderStates, TableCellNode } from './LexicalTableCellNode';
11
12
  import { $createTableNode, $getElementGridForTableNode, $isTableNode, TableNode } from './LexicalTableNode';
@@ -13,7 +14,7 @@ import { $createTableRowNode, $isTableRowNode, TableRowNode } from './LexicalTab
13
14
  import { TableSelection } from './LexicalTableSelection';
14
15
  import { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement } from './LexicalTableSelectionHelpers';
15
16
  import { $createTableNodeWithDimensions, $deleteTableColumn, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableRow, $removeTableRowAtIndex } from './LexicalTableUtils';
16
- export { $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $deleteTableColumn, $getElementGridForTableNode, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableRow, $isTableCellNode, $isTableNode, $isTableRowNode, $removeTableRowAtIndex, applyTableHandlers, Cell, getCellFromTarget, getTableSelectionFromTableElement, TableCellHeaderStates, TableCellNode, TableNode, TableRowNode, TableSelection, };
17
+ export { $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $deleteTableColumn, $getElementGridForTableNode, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableRow, $isTableCellNode, $isTableNode, $isTableRowNode, $removeTableRowAtIndex, applyTableHandlers, Cell, getCellFromTarget, getTableSelectionFromTableElement, HTMLTableElementWithWithTableSelectionState, TableCellHeaderStates, TableCellNode, TableNode, TableRowNode, TableSelection, };
17
18
  export declare type InsertTableCommandPayload = Readonly<{
18
19
  columns: string;
19
20
  rows: string;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.5",
11
+ "version": "0.3.8",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.5"
14
+ "lexical": "0.3.8"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.5"
17
+ "@lexical/utils": "0.3.8"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
package/utils.d.ts CHANGED
@@ -24,6 +24,6 @@ export declare type TableCellSiblings = {
24
24
  };
25
25
  export declare function $getTableCellSiblingsFromTableCellNode(tableCellNode: TableCellNode, grid: Grid): TableCellSiblings;
26
26
  export declare function $removeTableRowAtIndex(tableNode: TableNode, indexToDelete: number): TableNode;
27
- export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, rowCount: number, grid: Grid): TableNode;
28
- export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, columnCount: number): TableNode;
27
+ export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode;
28
+ export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number): TableNode;
29
29
  export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode;