@lexical/table 0.1.12 → 0.1.13

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.
@@ -98,6 +98,17 @@ function $findMatchingParent(startingNode, findFn) {
98
98
  return null;
99
99
  }
100
100
 
101
+ /**
102
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
103
+ *
104
+ * This source code is licensed under the MIT license found in the
105
+ * LICENSE file in the root directory of this source tree.
106
+ *
107
+ *
108
+ */
109
+ const getSelection = window.getSelection;
110
+ var getDOMSelection = getSelection;
111
+
101
112
  /**
102
113
  * Copyright (c) Meta Platforms, Inc. and affiliates.
103
114
  *
@@ -298,9 +309,14 @@ function $applyCustomTableHandlers(tableNode, tableElement, editor) {
298
309
 
299
310
  if (!isHighlightingCells && (startX !== cellX || startY !== cellY)) {
300
311
  event.preventDefault();
301
- const windowSelection = window.getSelection(); // Collapse the selection
312
+ const domSelection = getDOMSelection();
313
+ const anchorNode = domSelection.anchorNode;
314
+
315
+ if (anchorNode !== null) {
316
+ // Collapse the selection
317
+ domSelection.setBaseAndExtent(anchorNode, 0, anchorNode, 0);
318
+ }
302
319
 
303
- windowSelection.setBaseAndExtent(windowSelection.anchorNode, 0, windowSelection.anchorNode, 0);
304
320
  isHighlightingCells = true;
305
321
 
306
322
  if (document.body) {
@@ -4,27 +4,27 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var p=require("lexical");function y(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})}
8
- class z extends p.GridCellNode{static getType(){return"tablecell"}static clone(a){return new z(!1,a.__colSpan,a.__key)}constructor(a=!1,b=1,c){super(b,c);this.__isHeader=a}getTag(){return this.__isHeader?"th":"td"}createDOM(a){const b=document.createElement(this.getTag());y(b,a.theme.tableCell,!0===this.__isHeader&&a.theme.tableCellHeader);return b}updateDOM(){return!1}collapseAtStart(){return!0}canBeEmpty(){return!1}}function A(a){return new z(a)}function C(a){return a instanceof z}
9
- function D(a,b){for(;a!==p.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}const E=document.createElement("style");E.appendChild(document.createTextNode("::selection{background-color: transparent}"));function F(a){for(;null!=a;){const b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
10
- function G(a,b,c){const n=[],e={cells:n,columns:0,rows:0},q=()=>{var d=b.firstChild;let m=0,k=0;for(n.length=0;null!=d;){var g=d.nodeName;if("TD"===g||"TH"===g)g={elem:d,highlighted:!1,x:m,y:k},d._cell=g,void 0===n[k]&&(n[k]=[]),n[k][m]=g;else if(g=d.firstChild,null!=g){d=g;continue}g=d.nextSibling;if(null!=g)m++,d=g;else if(g=d.parentNode,null!=g){d=g.nextSibling;if(null==d)break;k++;m=0}}e.columns=m+1;e.rows=k+1;a.setGrid(e)};(new MutationObserver(d=>{c.update(()=>{let m=!1;for(let k=0;k<d.length;k++){const g=
7
+ var p=require("lexical");function z(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})}
8
+ class A extends p.GridCellNode{static getType(){return"tablecell"}static clone(a){return new A(!1,a.__colSpan,a.__key)}constructor(a=!1,b=1,c){super(b,c);this.__isHeader=a}getTag(){return this.__isHeader?"th":"td"}createDOM(a){const b=document.createElement(this.getTag());z(b,a.theme.tableCell,!0===this.__isHeader&&a.theme.tableCellHeader);return b}updateDOM(){return!1}collapseAtStart(){return!0}canBeEmpty(){return!1}}function B(a){return new A(a)}function C(a){return a instanceof A}
9
+ function D(a,b){for(;a!==p.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}var E=window.getSelection;const F=document.createElement("style");F.appendChild(document.createTextNode("::selection{background-color: transparent}"));function G(a){for(;null!=a;){const b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
10
+ function J(a,b,c){const n=[],e={cells:n,columns:0,rows:0},q=()=>{var d=b.firstChild;let m=0,k=0;for(n.length=0;null!=d;){var g=d.nodeName;if("TD"===g||"TH"===g)g={elem:d,highlighted:!1,x:m,y:k},d._cell=g,void 0===n[k]&&(n[k]=[]),n[k][m]=g;else if(g=d.firstChild,null!=g){d=g;continue}g=d.nextSibling;if(null!=g)m++,d=g;else if(g=d.parentNode,null!=g){d=g.nextSibling;if(null==d)break;k++;m=0}}e.columns=m+1;e.rows=k+1;a.setGrid(e)};(new MutationObserver(d=>{c.update(()=>{let m=!1;for(let k=0;k<d.length;k++){const g=
11
11
  d[k].target.nodeName;if("TABLE"===g||"TR"===g){m=!0;break}}m&&q()})})).observe(b,{childList:!0,subtree:!0});q();return e}
12
- function J(a,b,c,n,e){const q=[];for(let d=0;d<e.length;d++){const m=e[d];for(let k=0;k<m.length;k++){const g=m[k],u=g.elem.style;k>=a&&k<=b&&d>=c&&d<=n?(g.highlighted||(g.highlighted=!0,u.setProperty("background-color","rgb(163, 187, 255)"),u.setProperty("caret-color","transparent")),q.push(g)):g.highlighted&&(g.highlighted=!1,u.removeProperty("background-color"),u.removeProperty("caret-color"),g.elem.getAttribute("style")||g.elem.removeAttribute("style"))}}return q}
13
- function K(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.");}
14
- class L extends p.GridNode{static getType(){return"table"}static clone(a){return new L(a.__key,a.__selectionShape,a.__grid)}constructor(a,b,c){super(a);this.__selectionShape=b;this.__grid=c}createDOM(a){const b=document.createElement("table");y(b,a.theme.table);return b}updateDOM(){return!1}canExtractContents(){return!1}canBeEmpty(){return!1}setSelectionState(a){this.getWritable().__selectionShape=a;const b=this.getGrid();return null==b?[]:a?J(a.fromX,a.toX,a.fromY,a.toY,b.cells):J(-1,-1,-1,-1,b.cells)}getSelectionState(){return this.getLatest().__selectionShape}getCordsFromCellNode(a){var b=
15
- this.getGrid();b||K(55);const {rows:c,cells:n}=b;for(b=0;b<c;b++){var e=n[b];if(null==e)throw Error(`Row not found at y:${b}`);e=e.findIndex(({elem:q})=>p.$getNearestNodeFromDOMNode(q)===a);if(-1!==e)return{x:e,y:b}}throw Error("Cell not found in table.");}getCellNodeFromCords(a,b){var c=this.getGrid();c||K(55);({cells:c}=c);c=c[b];if(null==c)throw Error(`Table row x:"${b}" not found.`);c=c[a];if(null==c)throw Error(`Table cell y:"${a}" in row x:"${b}" not found.`);a=p.$getNearestNodeFromDOMNode(c.elem);
16
- if(C(a))return a;throw Error("Node at cords not TableCellNode.");}setGrid(a){const b=this.getWritable();b.__grid=a;return b}getGrid(){return this.getLatest().__grid}canSelectBefore(){return!0}}function M(){return new L}function N(a){return a instanceof L}
17
- class O extends p.GridRowNode{static getType(){return"tablerow"}static clone(a){return new O(a.__key)}constructor(a){super(a)}createDOM(a){const b=document.createElement("tr");y(b,a.theme.tableRow);return b}updateDOM(){return!1}canBeEmpty(){return!1}}function P(){return new O}function Q(a){return a instanceof O}function R(a){a=D(a,b=>Q(b));if(Q(a))return a;throw Error("Expected table cell to be inside of table row.");}
18
- function U(a){a=D(a,b=>N(b));if(N(a))return a;throw Error("Expected table cell to be inside of table.");}
19
- exports.$applyCustomTableHandlers=function(a,b,c){const n=c.getRootElement();if(null===n)throw Error("No root element.");G(a,b,c);const e=a.getGrid();let q=!1,d=!1,m=-1,k=-1,g=-1,u=-1,w=[];const H=new Set;let x=null;if(null==e)throw Error("Table grid not found.");b.addEventListener("mousemove",h=>{if(q){var f=F(h.target);if(null!==f){const l=f.x;f=f.y;if(!d&&(m!==l||k!==f))h.preventDefault(),h=window.getSelection(),h.setBaseAndExtent(h.anchorNode,0,h.anchorNode,0),d=!0,document.body&&document.body.appendChild(E),
20
- null===x&&(x=c.addListener("command",(t,v)=>{if("deleteCharacter"===t){if(w.length===e.columns*e.rows)return a.selectPrevious(),a.remove(),I(),!0;w.forEach(({elem:r})=>{r=p.$getNearestNodeFromDOMNode(r);if(p.$isElementNode(r)){const B=p.$createParagraphNode(),V=p.$createTextNode();B.append(V);r.append(B);r.getChildren().forEach(S=>{S!==B&&S.remove()})}});a.setSelectionState(null);p.$setSelection(null);return!0}if("formatText"===t)return W(v),!0;"insertText"===t&&I();return!1},1),H.add(x));else if(l===
21
- g&&f===u)return;g=l;u=f;if(d){const t=Math.min(m,g),v=Math.max(m,g),r=Math.min(k,u),B=Math.max(k,u);c.update(()=>{w=a.setSelectionState({fromX:t,fromY:r,toX:v,toY:B})})}}}});const I=()=>{c.update(()=>{q=d=!1;u=g=k=m=-1;c.update(()=>{a.setSelectionState(null)});w=[];null!==x&&(x(),x=null,H.delete(x));const h=E.parentNode;null!=h&&h.removeChild(E)})};b.addEventListener("mouseleave",()=>{});const W=h=>{let f=p.$getSelection();p.$isRangeSelection(f)||(f=p.$createRangeSelection());const l=f,t=l.anchor,
22
- v=l.focus;w.forEach(r=>{r=p.$getNearestNodeFromDOMNode(r.elem);p.$isElementNode(r)&&0!==r.getTextContentSize()&&(t.set(r.getKey(),0,"element"),v.set(r.getKey(),r.getChildrenSize(),"element"),l.formatText(h))});f.anchor.set(f.anchor.key,f.anchor.offset,f.anchor.type);f.focus.set(f.anchor.key,f.anchor.offset,f.anchor.type);p.$setSelection(f)};b.addEventListener("mousedown",h=>{q?d&&I():setTimeout(()=>{d&&I();const f=F(h.target);null!==f&&(q=!0,m=f.x,k=f.y,document.addEventListener("mouseup",()=>{q=
23
- !1},{capture:!0,once:!0}))},0)});window.addEventListener("click",h=>{0<w.length&&!b.contains(h.target)&&n.contains(h.target)&&c.update(()=>{a.setSelectionState(null)})});const T=(h,f,l)=>{switch(l){case "backward":case "forward":return l="forward"===l,h!==(l?e.columns-1:0)?a.getCellNodeFromCords(h+(l?1:-1),f).select():f!==(l?e.rows-1:0)?a.getCellNodeFromCords(l?0:e.columns-1,f+(l?1:-1)).select():l?a.selectNext():a.selectPrevious(),!0;case "up":return 0!==f?a.getCellNodeFromCords(h,f-1).select():a.selectPrevious(),
24
- !0;case "down":return f!==e.rows-1?a.getCellNodeFromCords(h,f+1).select():a.selectNext(),!0}return!1},X=c.addListener("command",(h,f)=>{var l=p.$getSelection();if(!p.$isRangeSelection(l))return!1;var t=D(l.anchor.getNode(),v=>C(v));if(!C(t))return!1;if("deleteCharacter"===h&&0===w.length&&l.isCollapsed()&&0===l.anchor.offset&&0===l.anchor.getNode().getPreviousSiblings().length)return!0;if("keyTab"===h&&l.isCollapsed()&&0===w.length)return t=a.getCordsFromCellNode(t),f.preventDefault(),T(t.x,t.y,f.shiftKey||
25
- "keyTab"!==h?"backward":"forward"),!0;if(("keyArrowDown"===h||"keyArrowUp"===h)&&l.isCollapsed()&&0===w.length){const v=a.getCordsFromCellNode(t);l=D(l.anchor.getNode(),r=>p.$isElementNode(r));if("keyArrowUp"===h&&l===t.getFirstChild()||"keyArrowDown"===h&&l===t.getLastChild())return f.preventDefault(),f.stopImmediatePropagation(),T(v.x,v.y,"keyArrowUp"===h?"up":"down"),!0}return!1},4);H.add(X);return()=>Array.from(H).forEach(h=>h?h():null)};exports.$createTableCellNode=A;
26
- exports.$createTableNode=M;exports.$createTableNodeWithDimensions=function(a,b,c=!0){const n=M();for(let e=0;e<a;e++){const q=P();for(let d=0;d<b;d++){const m=A(0===e&&c),k=p.$createParagraphNode();k.append(p.$createTextNode());m.append(k);q.append(m)}n.append(q)}return n};exports.$createTableRowNode=P;
27
- exports.$deleteTableColumn=function(a,b){const c=a.getChildren();for(let e=0;e<c.length;e++){var n=c[e];if(Q(n)){n=n.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n[b].remove()}}return a};exports.$getTableCellNodeFromLexicalNode=function(a){a=D(a,b=>C(b));return C(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return R(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=U;
28
- exports.$getTableRowIndexFromTableCellNode=function(a){const b=R(a);return U(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=R;exports.$insertTableColumn=function(a,b,c=!0,n){const e=a.getChildren();for(let d=0;d<e.length;d++){const m=e[d];if(Q(m))for(let k=0;k<n;k++){const g=A(0===d);g.append(p.$createParagraphNode());var q=m.getChildren();if(b>=q.length||0>b)throw Error("Table column target index out of range");q=q[b];c?q.insertAfter(g):q.insertBefore(g)}}return a};
29
- exports.$insertTableRow=function(a,b,c=!0,n){var e=a.getChildren();if(b>=e.length||0>b)throw Error("Table row target index out of range");b=e[b];if(Q(b))for(e=0;e<n;e++){const q=b.getChildren().length,d=P();for(let m=0;m<q;m++){const k=A(!1);k.append(p.$createParagraphNode());d.append(k)}c?b.insertAfter(d):b.insertBefore(d)}else throw Error("Row before insertion index does not exist.");return a};exports.$isTableCellNode=C;exports.$isTableNode=N;exports.$isTableRowNode=Q;
30
- exports.$removeTableRowAtIndex=function(a,b){const c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};exports.TableCellNode=z;exports.TableNode=L;exports.TableRowNode=O;
12
+ function K(a,b,c,n,e){const q=[];for(let d=0;d<e.length;d++){const m=e[d];for(let k=0;k<m.length;k++){const g=m[k],v=g.elem.style;k>=a&&k<=b&&d>=c&&d<=n?(g.highlighted||(g.highlighted=!0,v.setProperty("background-color","rgb(163, 187, 255)"),v.setProperty("caret-color","transparent")),q.push(g)):g.highlighted&&(g.highlighted=!1,v.removeProperty("background-color"),v.removeProperty("caret-color"),g.elem.getAttribute("style")||g.elem.removeAttribute("style"))}}return q}
13
+ function L(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.");}
14
+ class M extends p.GridNode{static getType(){return"table"}static clone(a){return new M(a.__key,a.__selectionShape,a.__grid)}constructor(a,b,c){super(a);this.__selectionShape=b;this.__grid=c}createDOM(a){const b=document.createElement("table");z(b,a.theme.table);return b}updateDOM(){return!1}canExtractContents(){return!1}canBeEmpty(){return!1}setSelectionState(a){this.getWritable().__selectionShape=a;const b=this.getGrid();return null==b?[]:a?K(a.fromX,a.toX,a.fromY,a.toY,b.cells):K(-1,-1,-1,-1,b.cells)}getSelectionState(){return this.getLatest().__selectionShape}getCordsFromCellNode(a){var b=
15
+ this.getGrid();b||L(55);const {rows:c,cells:n}=b;for(b=0;b<c;b++){var e=n[b];if(null==e)throw Error(`Row not found at y:${b}`);e=e.findIndex(({elem:q})=>p.$getNearestNodeFromDOMNode(q)===a);if(-1!==e)return{x:e,y:b}}throw Error("Cell not found in table.");}getCellNodeFromCords(a,b){var c=this.getGrid();c||L(55);({cells:c}=c);c=c[b];if(null==c)throw Error(`Table row x:"${b}" not found.`);c=c[a];if(null==c)throw Error(`Table cell y:"${a}" in row x:"${b}" not found.`);a=p.$getNearestNodeFromDOMNode(c.elem);
16
+ if(C(a))return a;throw Error("Node at cords not TableCellNode.");}setGrid(a){const b=this.getWritable();b.__grid=a;return b}getGrid(){return this.getLatest().__grid}canSelectBefore(){return!0}}function O(){return new M}function P(a){return a instanceof M}
17
+ class Q extends p.GridRowNode{static getType(){return"tablerow"}static clone(a){return new Q(a.__key)}constructor(a){super(a)}createDOM(a){const b=document.createElement("tr");z(b,a.theme.tableRow);return b}updateDOM(){return!1}canBeEmpty(){return!1}}function R(){return new Q}function S(a){return a instanceof Q}function V(a){a=D(a,b=>S(b));if(S(a))return a;throw Error("Expected table cell to be inside of table row.");}
18
+ function W(a){a=D(a,b=>P(b));if(P(a))return a;throw Error("Expected table cell to be inside of table.");}
19
+ exports.$applyCustomTableHandlers=function(a,b,c){const n=c.getRootElement();if(null===n)throw Error("No root element.");J(a,b,c);const e=a.getGrid();let q=!1,d=!1,m=-1,k=-1,g=-1,v=-1,w=[];const H=new Set;let x=null;if(null==e)throw Error("Table grid not found.");b.addEventListener("mousemove",h=>{if(q){var f=G(h.target);if(null!==f){const l=f.x;f=f.y;if(!d&&(m!==l||k!==f)){h.preventDefault();h=E();const r=h.anchorNode;null!==r&&h.setBaseAndExtent(r,0,r,0);d=!0;document.body&&document.body.appendChild(F);
20
+ null===x&&(x=c.addListener("command",(u,t)=>{if("deleteCharacter"===u){if(w.length===e.columns*e.rows)return a.selectPrevious(),a.remove(),I(),!0;w.forEach(({elem:y})=>{y=p.$getNearestNodeFromDOMNode(y);if(p.$isElementNode(y)){const N=p.$createParagraphNode(),X=p.$createTextNode();N.append(X);y.append(N);y.getChildren().forEach(T=>{T!==N&&T.remove()})}});a.setSelectionState(null);p.$setSelection(null);return!0}if("formatText"===u)return Y(t),!0;"insertText"===u&&I();return!1},1),H.add(x))}else if(l===
21
+ g&&f===v)return;g=l;v=f;if(d){const r=Math.min(m,g),u=Math.max(m,g),t=Math.min(k,v),y=Math.max(k,v);c.update(()=>{w=a.setSelectionState({fromX:r,fromY:t,toX:u,toY:y})})}}}});const I=()=>{c.update(()=>{q=d=!1;v=g=k=m=-1;c.update(()=>{a.setSelectionState(null)});w=[];null!==x&&(x(),x=null,H.delete(x));const h=F.parentNode;null!=h&&h.removeChild(F)})};b.addEventListener("mouseleave",()=>{});const Y=h=>{let f=p.$getSelection();p.$isRangeSelection(f)||(f=p.$createRangeSelection());const l=f,r=l.anchor,
22
+ u=l.focus;w.forEach(t=>{t=p.$getNearestNodeFromDOMNode(t.elem);p.$isElementNode(t)&&0!==t.getTextContentSize()&&(r.set(t.getKey(),0,"element"),u.set(t.getKey(),t.getChildrenSize(),"element"),l.formatText(h))});f.anchor.set(f.anchor.key,f.anchor.offset,f.anchor.type);f.focus.set(f.anchor.key,f.anchor.offset,f.anchor.type);p.$setSelection(f)};b.addEventListener("mousedown",h=>{q?d&&I():setTimeout(()=>{d&&I();const f=G(h.target);null!==f&&(q=!0,m=f.x,k=f.y,document.addEventListener("mouseup",()=>{q=
23
+ !1},{capture:!0,once:!0}))},0)});window.addEventListener("click",h=>{0<w.length&&!b.contains(h.target)&&n.contains(h.target)&&c.update(()=>{a.setSelectionState(null)})});const U=(h,f,l)=>{switch(l){case "backward":case "forward":return l="forward"===l,h!==(l?e.columns-1:0)?a.getCellNodeFromCords(h+(l?1:-1),f).select():f!==(l?e.rows-1:0)?a.getCellNodeFromCords(l?0:e.columns-1,f+(l?1:-1)).select():l?a.selectNext():a.selectPrevious(),!0;case "up":return 0!==f?a.getCellNodeFromCords(h,f-1).select():a.selectPrevious(),
24
+ !0;case "down":return f!==e.rows-1?a.getCellNodeFromCords(h,f+1).select():a.selectNext(),!0}return!1},Z=c.addListener("command",(h,f)=>{var l=p.$getSelection();if(!p.$isRangeSelection(l))return!1;var r=D(l.anchor.getNode(),u=>C(u));if(!C(r))return!1;if("deleteCharacter"===h&&0===w.length&&l.isCollapsed()&&0===l.anchor.offset&&0===l.anchor.getNode().getPreviousSiblings().length)return!0;if("keyTab"===h&&l.isCollapsed()&&0===w.length)return r=a.getCordsFromCellNode(r),f.preventDefault(),U(r.x,r.y,f.shiftKey||
25
+ "keyTab"!==h?"backward":"forward"),!0;if(("keyArrowDown"===h||"keyArrowUp"===h)&&l.isCollapsed()&&0===w.length){const u=a.getCordsFromCellNode(r);l=D(l.anchor.getNode(),t=>p.$isElementNode(t));if("keyArrowUp"===h&&l===r.getFirstChild()||"keyArrowDown"===h&&l===r.getLastChild())return f.preventDefault(),f.stopImmediatePropagation(),U(u.x,u.y,"keyArrowUp"===h?"up":"down"),!0}return!1},4);H.add(Z);return()=>Array.from(H).forEach(h=>h?h():null)};exports.$createTableCellNode=B;
26
+ exports.$createTableNode=O;exports.$createTableNodeWithDimensions=function(a,b,c=!0){const n=O();for(let e=0;e<a;e++){const q=R();for(let d=0;d<b;d++){const m=B(0===e&&c),k=p.$createParagraphNode();k.append(p.$createTextNode());m.append(k);q.append(m)}n.append(q)}return n};exports.$createTableRowNode=R;
27
+ exports.$deleteTableColumn=function(a,b){const c=a.getChildren();for(let e=0;e<c.length;e++){var n=c[e];if(S(n)){n=n.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n[b].remove()}}return a};exports.$getTableCellNodeFromLexicalNode=function(a){a=D(a,b=>C(b));return C(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return V(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=W;
28
+ exports.$getTableRowIndexFromTableCellNode=function(a){const b=V(a);return W(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=V;exports.$insertTableColumn=function(a,b,c=!0,n){const e=a.getChildren();for(let d=0;d<e.length;d++){const m=e[d];if(S(m))for(let k=0;k<n;k++){const g=B(0===d);g.append(p.$createParagraphNode());var q=m.getChildren();if(b>=q.length||0>b)throw Error("Table column target index out of range");q=q[b];c?q.insertAfter(g):q.insertBefore(g)}}return a};
29
+ exports.$insertTableRow=function(a,b,c=!0,n){var e=a.getChildren();if(b>=e.length||0>b)throw Error("Table row target index out of range");b=e[b];if(S(b))for(e=0;e<n;e++){const q=b.getChildren().length,d=R();for(let m=0;m<q;m++){const k=B(!1);k.append(p.$createParagraphNode());d.append(k)}c?b.insertAfter(d):b.insertBefore(d)}else throw Error("Row before insertion index does not exist.");return a};exports.$isTableCellNode=C;exports.$isTableNode=P;exports.$isTableRowNode=S;
30
+ exports.$removeTableRowAtIndex=function(a,b){const c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};exports.TableCellNode=A;exports.TableNode=M;exports.TableRowNode=Q;
package/package.json CHANGED
@@ -12,10 +12,10 @@
12
12
  "table"
13
13
  ],
14
14
  "license": "MIT",
15
- "version": "0.1.12",
15
+ "version": "0.1.13",
16
16
  "main": "LexicalTable.js",
17
17
  "peerDependencies": {
18
- "lexical": "0.1.12"
18
+ "lexical": "0.1.13"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",