@lexical/table 0.6.1-next.0 → 0.6.2

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.
@@ -189,7 +189,7 @@ function convertTableCellNodeElement(domNode) {
189
189
  };
190
190
  }
191
191
  function $createTableCellNode(headerState, colSpan = 1, width) {
192
- return new TableCellNode(headerState, colSpan, width);
192
+ return lexical.$applyNodeReplacement(new TableCellNode(headerState, colSpan, width));
193
193
  }
194
194
  function $isTableCellNode(node) {
195
195
  return node instanceof TableCellNode;
@@ -283,7 +283,7 @@ function convertTableRowElement(domNode) {
283
283
  };
284
284
  }
285
285
  function $createTableRowNode(height) {
286
- return new TableRowNode(height);
286
+ return lexical.$applyNodeReplacement(new TableRowNode(height));
287
287
  }
288
288
  function $isTableRowNode(node) {
289
289
  return node instanceof TableRowNode;
@@ -1636,7 +1636,7 @@ function convertTableElement(_domNode) {
1636
1636
  };
1637
1637
  }
1638
1638
  function $createTableNode() {
1639
- return new TableNode();
1639
+ return lexical.$applyNodeReplacement(new TableNode());
1640
1640
  }
1641
1641
  function $isTableNode(node) {
1642
1642
  return node instanceof TableNode;
@@ -9,9 +9,9 @@ class t extends d.DEPRECATED_GridCellNode{static getType(){return"tablecell"}sta
9
9
  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,
10
10
  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()&
11
11
  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}}
12
- 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}
12
+ 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 d.$applyNodeReplacement(new t(a,b,e))}function B(a){return a instanceof t}
13
13
  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=
14
- 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 G(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
+ 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 d.$applyNodeReplacement(new C(a))}function F(a){return a instanceof C}function G(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.");}
15
15
  let H="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
16
16
  if(H){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)}
17
17
  class I{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.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=>
@@ -34,7 +34,7 @@ function T(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let
34
34
  class U extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new U(a.__key)}static importDOM(){return{table:()=>({conversion:V,priority:1})}}static importJSON(){return W()}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"),
35
35
  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)===
36
36
  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.");
37
- return a}canSelectBefore(){return!0}canIndent(){return!1}}function V(){return{node:W()}}function W(){return new U}function K(a){return a instanceof U}function X(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.");}
37
+ return a}canSelectBefore(){return!0}canIndent(){return!1}}function V(){return{node:W()}}function W(){return d.$applyNodeReplacement(new U)}function K(a){return a instanceof U}function X(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.");}
38
38
  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 aa=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=z;exports.$createTableNode=W;
39
39
  exports.$createTableNodeWithDimensions=function(a,b,e=!0){let h=W();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;
40
40
  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};
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.6.1-next.0",
11
+ "version": "0.6.2",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.6.1-next.0"
14
+ "lexical": "0.6.2"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.6.1-next.0"
17
+ "@lexical/utils": "0.6.2"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",