@lexical/table 0.7.2 → 0.7.3

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.
@@ -306,7 +306,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
306
306
  *
307
307
  */
308
308
 
309
- const getDOMSelection = () => CAN_USE_DOM ? window.getSelection() : null;
309
+ const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
310
310
 
311
311
  if (CAN_USE_DOM) {
312
312
  const disableNativeSelectionUi = document.createElement('style');
@@ -498,7 +498,7 @@ class TableSelection {
498
498
  this.focusCell = cell;
499
499
 
500
500
  if (this.anchorCell !== null) {
501
- const domSelection = getDOMSelection(); // Collapse the selection
501
+ const domSelection = getDOMSelection(this.editor._window); // Collapse the selection
502
502
 
503
503
  if (domSelection) {
504
504
  domSelection.setBaseAndExtent(this.anchorCell.elem, 0, this.focusCell.elem, 0);
@@ -18,8 +18,8 @@ class I{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=thi
18
18
  {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.isHighlightingCells=!1;this.focusY=
19
19
  this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();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);L(a,null);d.$setSelection(null);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,
20
20
  void 0)})}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!=
21
- a&&a.gridKey===this.tableNodeKey?(this.gridSelection=a,this.isHighlightingCells=!0,this.disableHighlightStyle(),L(this.grid,this.gridSelection)):null==a&&this.clearHighlight()}setFocusCellForSelection(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=H?window.getSelection():
22
- null;c&&c.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&h===this.focusY)return;this.focusX=e;this.focusY=h;this.isHighlightingCells&&(e=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(e)&&(e=e.getKey(),this.gridSelection=this.gridSelection.clone()||d.DEPRECATED_$createGridSelection(),
21
+ a&&a.gridKey===this.tableNodeKey?(this.gridSelection=a,this.isHighlightingCells=!0,this.disableHighlightStyle(),L(this.grid,this.gridSelection)):null==a&&this.clearHighlight()}setFocusCellForSelection(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=H?(this.editor._window||
22
+ window).getSelection():null;c&&c.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&h===this.focusY)return;this.focusX=e;this.focusY=h;this.isHighlightingCells&&(e=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(e)&&(e=e.getKey(),this.gridSelection=this.gridSelection.clone()||d.DEPRECATED_$createGridSelection(),
23
23
  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.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=d.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=
24
24
  b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(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.");
25
25
  var b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(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))})}}
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.7.2",
11
+ "version": "0.7.3",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.7.2"
14
+ "lexical": "0.7.3"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.7.2"
17
+ "@lexical/utils": "0.7.3"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",