@lexical/table
Advanced tools
Comparing version 0.20.1-nightly.20241126.0 to 0.20.1-nightly.20241127.0
@@ -29,3 +29,3 @@ /** | ||
function ra(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let f=Array(d);for(var g=0;g<d;g++)f[g]=Array(e);for(e=0;e<d;e++){g=a[e].getChildren();let n=0;for(let q=0;q<g.length;q++){for(;f[e][n];)n++;let r=g[q],l=r.__rowSpan||1,k=r.__colSpan||1;for(let m=0;m<l;m++)for(let p=0;p<k;p++)f[e+m][n+p]=r;if(b===r)return{colSpan:k,columnIndex:n,rowIndex:e,rowSpan:l};n+=k}}return null} | ||
function sa(a){let [[b,c,d,e],[f,g,n,q]]=["anchor","focus"].map(r=>{const l=a[r].getNode(),k=h.$findMatchingParent(l,C);C(k)||E(238,r,l.getKey(),l.getType());const m=k.getParent();J(m)||E(239,r);const p=m.getParent();K(p)||E(240,r);return[l,k,m,p]});e.is(q)||E(241);return{anchorCell:c,anchorNode:b,anchorRow:d,anchorTable:e,focusCell:g,focusNode:f,focusRow:n,focusTable:q}} | ||
function sa(a){let [[b,c,d,e],[f,g,n,q]]=["anchor","focus"].map(r=>{const l=a[r].getNode(),k=h.$findMatchingParent(l,C);C(k)||E(229,r,l.getKey(),l.getType());const m=k.getParent();J(m)||E(230,r);const p=m.getParent();K(p)||E(231,r);return[l,k,m,p]});e.is(q)||E(232);return{anchorCell:c,anchorNode:b,anchorRow:d,anchorTable:e,focusCell:g,focusNode:f,focusRow:n,focusTable:q}} | ||
class ta{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return Q(a)&&this.tableKey=== | ||
@@ -37,3 +37,3 @@ a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus)}set(a,b,c){this.dirty=this.dirty||a!==this.tableKey||b!==this.anchor.key||c!==this.focus.key;this.tableKey=a;this.anchor.key=b;this.focus.key=c;this._cachedNodes=null}clone(){return new ta(this.tableKey,w.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),w.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b= | ||
a[c],e=d.__parent,f=(a[c+1]||{}).__parent;b+=d.getTextContent()+(f!==e?"\n":"\t")}return b}}function Q(a){return a instanceof ta}function va(){let a=w.$createPoint("root",0,"element"),b=w.$createPoint("root",0,"element");return new ta("root",a,b)}function ua(a,b){a=[[a]];for(var c=a.at(-1);void 0!==c&&0<a.length;c=a.at(-1))c=c.pop(),void 0===c?a.pop():!1!==b(c)&&w.$isElementNode(c)&&a.push(c.getChildren())} | ||
function wa(a,b=w.$getEditor()){let c=w.$getNodeByKey(a);K(c)||E(231,a);b=R(c,b.getElementByKey(a));null===b&&E(232,a);return{tableElement:b,tableNode:c}} | ||
function wa(a,b=w.$getEditor()){let c=w.$getNodeByKey(a);K(c)||E(238,a);b=R(c,b.getElementByKey(a));null===b&&E(239,a);return{tableElement:b,tableNode:c}} | ||
class xa{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.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.shouldCheckSelection=this.isSelecting=this.hasHijackedSelectionStyles=!1;this.abortController=new AbortController;this.listenerOptions={signal:this.abortController.signal};this.nextFocus= | ||
@@ -43,7 +43,7 @@ null;this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners");Array.from(this.listenersToRemove).forEach(a=>a());this.listenersToRemove.clear()}$lookup(){return wa(this.tableNodeKey,this.editor)}trackTable(){let a=new MutationObserver(b=>{this.editor.getEditorState().read(()=>{let c=!1;for(let f=0;f<b.length;f++){const g=b[f].target.nodeName;if("TABLE"===g||"TBODY"===g||"THEAD"===g||"TR"===g){c=!0;break}}if(c){var {tableNode:d,tableElement:e}= | ||
let {tableNode:b,tableElement:c}=this.$lookup(),d=S(b,c);ya(a,d,null);null!==w.$getSelection()&&(w.$setSelection(null),a.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){let a=this.editor,{tableElement:b}=this.$lookup();h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){let {tableElement:a}=this.$lookup();h.addClassNamesToElement(a,this.editor._config.theme.tableSelection); | ||
this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(a){if(null!==a){a.tableKey!==this.tableNodeKey&&E(233,a.tableKey,this.tableNodeKey);let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.$disableHighlightStyle();this.updateDOMSelection();ya(b,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return this.shouldCheckSelection?(this.shouldCheckSelection=!1,!0):!1}setNextFocus(a){this.nextFocus= | ||
this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(a){if(null!==a){a.tableKey!==this.tableNodeKey&&E(240,a.tableKey,this.tableNodeKey);let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.$disableHighlightStyle();this.updateDOMSelection();ya(b,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return this.shouldCheckSelection?(this.shouldCheckSelection=!1,!0):!1}setNextFocus(a){this.nextFocus= | ||
a}getAndClearNextFocus(){let {nextFocus:a}=this;null!==a&&(this.nextFocus=null);return a}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){let a=w.getDOMSelection(this.editor._window);a&&0<a.rangeCount&&a.removeAllRanges()}}$setFocusCellForSelection(a,b=!1){let c=this.editor,{tableNode:d}=this.$lookup();var e=a.x;let f=a.y;this.focusCell=a;if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.$disableHighlightStyle();else if(e=== | ||
this.focusX&&f===this.focusY)return!1;this.focusX=e;this.focusY=f;return this.isHighlightingCells&&(b=w.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&C(b)&&d.is(T(b)))?(this.focusCellNodeKey=b.getKey(),a=this.$getAnchorTableCellOrThrow(),d.getKey(),a.getKey(),b.getKey(),e=w.$getSelection(),e=Q(e)?e.clone():va(),e.set(d.getKey(),a.getKey(),b.getKey()),this.tableSelection=e,w.$setSelection(this.tableSelection),c.dispatchCommand(w.SELECTION_CHANGE_COMMAND, | ||
void 0),ya(c,this.table,this.tableSelection),!0):!1}$getAnchorTableCell(){return this.anchorCellNodeKey?w.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){let a=this.$getAnchorTableCell();null===a&&E(234);return a}$getFocusTableCell(){return this.focusCellNodeKey?w.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){let a=this.$getFocusTableCell();null===a&&E(235);return a}$setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX= | ||
a.x;this.anchorY=a.y;a=w.$getNearestNodeFromDOMNode(a.elem);C(a)&&(a=a.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():va(),this.anchorCellNodeKey=a)}$formatCells(a){let b=w.$getSelection();Q(b)||E(236);let c=w.$createRangeSelection(),d=c.anchor,e=c.focus,f=b.getNodes().filter(C);0<f.length||E(237);let g=f[0].getFirstChild(),n=w.$isParagraphNode(g)?g.getFormatFlags(a,null):null;f.forEach(q=>{d.set(q.getKey(),0,"element");e.set(q.getKey(),q.getChildrenSize(),"element"); | ||
void 0),ya(c,this.table,this.tableSelection),!0):!1}$getAnchorTableCell(){return this.anchorCellNodeKey?w.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){let a=this.$getAnchorTableCell();null===a&&E(241);return a}$getFocusTableCell(){return this.focusCellNodeKey?w.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){let a=this.$getFocusTableCell();null===a&&E(242);return a}$setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX= | ||
a.x;this.anchorY=a.y;a=w.$getNearestNodeFromDOMNode(a.elem);C(a)&&(a=a.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():va(),this.anchorCellNodeKey=a)}$formatCells(a){let b=w.$getSelection();Q(b)||E(243);let c=w.$createRangeSelection(),d=c.anchor,e=c.focus,f=b.getNodes().filter(C);0<f.length||E(244);let g=f[0].getFirstChild(),n=w.$isParagraphNode(g)?g.getFormatFlags(a,null):null;f.forEach(q=>{d.set(q.getKey(),0,"element");e.set(q.getKey(),q.getChildrenSize(),"element"); | ||
c.formatText(a,n)});w.$setSelection(b);this.editor.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){let {editor:a}=this,b=w.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");var c=w.$getSelection();Q(c)||E(11);c=c.getNodes().filter(C);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),w.$getRoot().selectStart()):(c.forEach(d=>{if(w.$isElementNode(d)){let e=w.$createParagraphNode(),f=w.$createTextNode();e.append(f);d.append(e);d.getChildren().forEach(g=> | ||
@@ -78,3 +78,3 @@ {g!==e&&g.remove()})}}),ya(a,this.table,null),w.$setSelection(null),a.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0))}}function R(a,b){if(!b)return b;a="TABLE"===b.nodeName?b:a.getDOMSlot(b).element;"TABLE"!==a.nodeName&&E(245,b.nodeName);return a}function za(a,b){for(let c=b,d=null;null!==c;c=c.getParent()){if(a.is(c))return d;C(c)&&(d=c)}return null} | ||
class bb extends w.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(a){let b=this.getWritable();b.__colWidths=a;return b}static clone(a){return new bb(a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__colWidths=a.__colWidths;this.__rowStriping=a.__rowStriping}static importDOM(){return{table:()=>({conversion:cb,priority:1})}}static importJSON(a){let b=db();b.__rowStriping=a.rowStriping||!1;b.__colWidths=a.colWidths;return b}constructor(a){super(a); | ||
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&E(229);return super.getDOMSlot(a).withAfter(a.querySelector("colgroup"))}createDOM(a,b){let c=document.createElement("table"),d=document.createElement("colgroup");c.appendChild(d);Za(c,a,this.getColumnCount(),this.getColWidths());w.setDOMUnmanaged(d); | ||
this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&E(236);return super.getDOMSlot(a).withAfter(a.querySelector("colgroup"))}createDOM(a,b){let c=document.createElement("table"),d=document.createElement("colgroup");c.appendChild(d);Za(c,a,this.getColumnCount(),this.getColWidths());w.setDOMUnmanaged(d); | ||
h.addClassNamesToElement(c,a.theme.table);this.__rowStriping&&$a(c,a,!0);return Sa(b)?(b=document.createElement("div"),(a=a.theme.tableScrollableWrapper)?h.addClassNamesToElement(b,a):b.style.cssText="overflow-x: auto;",b.appendChild(c),b):c}updateDOM(a,b,c){a.__rowStriping!==this.__rowStriping&&$a(b,c,this.__rowStriping);Za(b,c,this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{b&&h.isHTMLElement(b)&&"TABLE"!==b.nodeName&&(b=b.querySelector("table")); | ||
@@ -90,3 +90,3 @@ if(!b||!h.isHTMLElement(b))return null;let c=b.querySelectorAll(":scope > tr");if(0<c.length){let d=document.createElement("tbody");d.append(...c);b.append(d)}return b}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var e=d[b];if(null!=e&&(e=e.findIndex(f=>{if(f)return{elem:f}=f,w.$getNearestNodeFromDOMNode(f)===a}),-1!==e))return{x:e,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b]; | ||
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);let [b,c]=a.isBackward()?[a.focus.getNode(),a.anchor.getNode()]:[a.anchor.getNode(),a.focus.getNode()],[d,,e]=P(b);var [f]=P(c);let [g,n,q]=N(e,d,f);({startRow:a}=n);var {startRow:r}=q;f=r+f.__rowSpan-1;if(g.length===f-a+1)e.remove();else{r=g[0].length;var l=g[f+1],k=e.getChildAtIndex(f+1);for(let p=f;p>=a;p--){for(var m=r-1;0<=m;m--){let {cell:u,startRow:t,startColumn:v}=g[p][m];if(v===m&& | ||
(p===a&&t<a&&u.setRowSpan(u.__rowSpan-(t-a)),t>=a&&t+u.__rowSpan-1>f))if(u.setRowSpan(u.__rowSpan-(f-t+1)),null===k&&E(122),0===m)oa(k,u);else{let {cell:B}=l[m-1];B.insertAfter(u)}}m=e.getChildAtIndex(p);J(m)||E(206,String(p));m.remove()}void 0!==l?({cell:a}=l[0],M(a)):({cell:a}=g[a-1][0],M(a))}};exports.$findCellNode=X;exports.$findTableNode=T;exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());null===a&&E(230);return S(b,a)};exports.$getNodeTriplet=P; | ||
(p===a&&t<a&&u.setRowSpan(u.__rowSpan-(t-a)),t>=a&&t+u.__rowSpan-1>f))if(u.setRowSpan(u.__rowSpan-(f-t+1)),null===k&&E(122),0===m)oa(k,u);else{let {cell:B}=l[m-1];B.insertAfter(u)}}m=e.getChildAtIndex(p);J(m)||E(206,String(p));m.remove()}void 0!==l?({cell:a}=l[0],M(a)):({cell:a}=g[a-1][0],M(a))}};exports.$findCellNode=X;exports.$findTableNode=T;exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());null===a&&E(237);return S(b,a)};exports.$getNodeTriplet=P; | ||
exports.$getTableAndElementByKey=wa;exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableCellNodeRect=ra;exports.$getTableColumnIndexFromTableCellNode=function(a){return ka(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=la;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ka(a);return la(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ka; | ||
@@ -93,0 +93,0 @@ exports.$insertTableColumn=function(a,b,c=!0,d,e){let f=a.getChildren(),g=[];for(let r=0;r<f.length;r++){let l=f[r];if(J(l))for(let k=0;k<d;k++){var n=l.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];C(n)||E(12);let {left:m,right:p}=ma(n,e);var q=x.NO_STATUS;if(m&&m.hasHeaderState(x.ROW)||p&&p.hasHeaderState(x.ROW))q|=x.ROW;q=A(q);q.append(w.$createParagraphNode());g.push({newTableCell:q,targetCell:n})}}g.forEach(({newTableCell:r,targetCell:l})=>{c? |
@@ -11,9 +11,9 @@ { | ||
"license": "MIT", | ||
"version": "0.20.1-nightly.20241126.0", | ||
"version": "0.20.1-nightly.20241127.0", | ||
"main": "LexicalTable.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/clipboard": "0.20.1-nightly.20241126.0", | ||
"@lexical/utils": "0.20.1-nightly.20241126.0", | ||
"lexical": "0.20.1-nightly.20241126.0" | ||
"@lexical/clipboard": "0.20.1-nightly.20241127.0", | ||
"@lexical/utils": "0.20.1-nightly.20241127.0", | ||
"lexical": "0.20.1-nightly.20241127.0" | ||
}, | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
+ Added@lexical/clipboard@0.20.1-nightly.20241127.0(transitive)
+ Added@lexical/html@0.20.1-nightly.20241127.0(transitive)
+ Added@lexical/list@0.20.1-nightly.20241127.0(transitive)
+ Added@lexical/selection@0.20.1-nightly.20241127.0(transitive)
+ Added@lexical/utils@0.20.1-nightly.20241127.0(transitive)
+ Addedlexical@0.20.1-nightly.20241127.0(transitive)
- Removed@lexical/clipboard@0.20.1-nightly.20241126.0(transitive)
- Removed@lexical/html@0.20.1-nightly.20241126.0(transitive)
- Removed@lexical/list@0.20.1-nightly.20241126.0(transitive)
- Removed@lexical/selection@0.20.1-nightly.20241126.0(transitive)
- Removed@lexical/utils@0.20.1-nightly.20241126.0(transitive)
- Removedlexical@0.20.1-nightly.20241126.0(transitive)