@lexical/table
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -9,2 +9,3 @@ /** | ||
import type { Cell } from './LexicalTableSelection'; | ||
import type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers'; | ||
import type { LexicalCommand } from 'lexical'; | ||
@@ -17,3 +18,3 @@ import { $createTableCellNode, $isTableCellNode, TableCellHeaderStates, TableCellNode } from './LexicalTableCellNode'; | ||
import { $createTableNodeWithDimensions, $deleteTableColumn, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableRow, $removeTableRowAtIndex } from './LexicalTableUtils'; | ||
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, }; | ||
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, }; | ||
export declare type InsertTableCommandPayload = Readonly<{ | ||
@@ -20,0 +21,0 @@ columns: string; |
@@ -48,3 +48,3 @@ /** | ||
static importJSON(serializedNode) { | ||
return $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width); | ||
return $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width || undefined); | ||
} | ||
@@ -475,3 +475,6 @@ | ||
const domSelection = getDOMSelection(); | ||
domSelection.setBaseAndExtent(anchorElement, 0, focusElement, 0); | ||
if (domSelection) { | ||
domSelection.setBaseAndExtent(anchorElement, 0, focusElement, 0); | ||
} | ||
} | ||
@@ -506,3 +509,5 @@ | ||
// Collapse the selection | ||
domSelection.setBaseAndExtent(this.anchorCell.elem, 0, cell.elem, 0); | ||
if (domSelection) { | ||
domSelection.setBaseAndExtent(this.anchorCell.elem, 0, cell.elem, 0); | ||
} | ||
} | ||
@@ -542,3 +547,7 @@ | ||
const domSelection = getDOMSelection(); | ||
domSelection.setBaseAndExtent(cell.elem, 0, cell.elem, 0); | ||
if (domSelection) { | ||
domSelection.setBaseAndExtent(cell.elem, 0, cell.elem, 0); | ||
} | ||
const anchorTableCellNode = lexical.$getNearestNodeFromDOMNode(cell.elem); | ||
@@ -1696,3 +1705,3 @@ | ||
let headerState = TableCellHeaderStates.NO_STATUS; | ||
const width = above && above.getWidth() || below && below.getWidth() || null; | ||
const width = above && above.getWidth() || below && below.getWidth() || undefined; | ||
@@ -1699,0 +1708,0 @@ if (above && above.hasHeaderState(TableCellHeaderStates.COLUMN) || below && below.hasHeaderState(TableCellHeaderStates.COLUMN)) { |
@@ -8,3 +8,3 @@ /** | ||
'use strict';var f=require("lexical"),p=require("@lexical/utils");let q={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1}; | ||
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, | ||
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, | ||
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()? | ||
@@ -21,7 +21,7 @@ "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!== | ||
{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= | ||
!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= | ||
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(), | ||
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(), | ||
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."); | ||
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))})}} | ||
!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; | ||
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= | ||
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(), | ||
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); | ||
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))})}} | ||
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} | ||
@@ -44,3 +44,3 @@ 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} | ||
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; | ||
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; | ||
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; | ||
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; | ||
@@ -47,0 +47,0 @@ 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), |
@@ -20,7 +20,7 @@ /** | ||
type: 'tablecell'; | ||
width: number; | ||
width?: number; | ||
}, SerializedGridCellNode>; | ||
export declare class TableCellNode extends GridCellNode { | ||
__headerState: TableCellHeaderState; | ||
__width: number; | ||
__width?: number; | ||
static getType(): 'tablecell'; | ||
@@ -37,4 +37,4 @@ static clone(node: TableCellNode): TableCellNode; | ||
getHeaderStyles(): TableCellHeaderState; | ||
setWidth(width: number): number; | ||
getWidth(): number; | ||
setWidth(width: number): number | null | undefined; | ||
getWidth(): number | undefined; | ||
toggleHeaderStyle(headerStateToToggle: TableCellHeaderState): TableCellNode; | ||
@@ -41,0 +41,0 @@ hasHeaderState(headerState: TableCellHeaderState): boolean; |
@@ -17,3 +17,3 @@ /** | ||
export declare class TableNode extends GridNode { | ||
__grid: Grid; | ||
__grid?: Grid; | ||
static getType(): 'table'; | ||
@@ -20,0 +20,0 @@ static clone(node: TableNode): TableNode; |
@@ -16,3 +16,3 @@ /** | ||
export declare class TableRowNode extends GridRowNode { | ||
__height: number; | ||
__height?: number; | ||
static getType(): 'tablerow'; | ||
@@ -25,4 +25,4 @@ static clone(node: TableRowNode): TableRowNode; | ||
createDOM(config: EditorConfig): HTMLElement; | ||
setHeight(height: number): number; | ||
getHeight(): number; | ||
setHeight(height: number): number | null | undefined; | ||
getHeight(): number | null | undefined; | ||
updateDOM(prevNode: TableRowNode): boolean; | ||
@@ -29,0 +29,0 @@ canBeEmpty(): false; |
@@ -25,3 +25,2 @@ /** | ||
listenersToRemove: Set<() => void>; | ||
domListeners: Set<() => void>; | ||
grid: Grid; | ||
@@ -28,0 +27,0 @@ isHighlightingCells: boolean; |
@@ -12,5 +12,7 @@ /** | ||
import { TableSelection } from './LexicalTableSelection'; | ||
export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLElement, editor: LexicalEditor): TableSelection; | ||
export declare function attachTableSelectionToTableElement(tableElement: HTMLElement, tableSelection: TableSelection): void; | ||
export declare function getTableSelectionFromTableElement(tableElement: HTMLElement): TableSelection; | ||
declare const LEXICAL_ELEMENT_KEY = "__lexicalTableSelection"; | ||
export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor): TableSelection; | ||
export declare type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableSelection>; | ||
export declare function attachTableSelectionToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableSelection: TableSelection): void; | ||
export declare function getTableSelectionFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableSelection | null; | ||
export declare function getCellFromTarget(node: Node): Cell | null; | ||
@@ -25,1 +27,2 @@ export declare function getTableGrid(tableElement: HTMLElement): Grid; | ||
export declare function $removeHighlightStyleToTable(tableSelection: TableSelection): void; | ||
export {}; |
@@ -27,4 +27,4 @@ /** | ||
export declare function $removeTableRowAtIndex(tableNode: TableNode, indexToDelete: number): TableNode; | ||
export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, rowCount: number, grid: Grid): TableNode; | ||
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, columnCount: number): TableNode; | ||
export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode; | ||
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number): TableNode; | ||
export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode; |
@@ -11,9 +11,9 @@ { | ||
"license": "MIT", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"main": "LexicalTable.js", | ||
"peerDependencies": { | ||
"lexical": "0.3.5" | ||
"lexical": "0.3.6" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.3.5" | ||
"@lexical/utils": "0.3.6" | ||
}, | ||
@@ -20,0 +20,0 @@ "repository": { |
@@ -27,4 +27,4 @@ /** | ||
export declare function $removeTableRowAtIndex(tableNode: TableNode, indexToDelete: number): TableNode; | ||
export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, rowCount: number, grid: Grid): TableNode; | ||
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean, columnCount: number): TableNode; | ||
export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode; | ||
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number): TableNode; | ||
export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode; |
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
100603
1892
+ Added@lexical/list@0.3.6(transitive)
+ Added@lexical/utils@0.3.6(transitive)
+ Addedlexical@0.3.6(transitive)
- Removed@lexical/list@0.3.5(transitive)
- Removed@lexical/utils@0.3.5(transitive)
- Removedlexical@0.3.5(transitive)
Updated@lexical/utils@0.3.6