@lexical/table 0.12.6 → 0.13.0

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.
@@ -5,47 +5,48 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { LexicalEditor, NodeKey, TextFormatType } from 'lexical';
9
- import { type GridSelection } from './LexicalGridSelection';
10
- export type Cell = {
11
- elem: HTMLElement;
12
- highlighted: boolean;
13
- hasBackgroundColor: boolean;
14
- x: number;
15
- y: number;
8
+ import { BaseSelection, LexicalNode, NodeKey, PointType } from 'lexical';
9
+ import { TableCellNode } from './LexicalTableCellNode';
10
+ export type TableSelectionShape = {
11
+ fromX: number;
12
+ fromY: number;
13
+ toX: number;
14
+ toY: number;
16
15
  };
17
- export type Cells = Array<Array<Cell | undefined> | undefined>;
18
- export type Grid = {
19
- cells: Cells;
20
- columns: number;
21
- rows: number;
16
+ export type TableMapValueType = {
17
+ cell: TableCellNode;
18
+ startRow: number;
19
+ startColumn: number;
22
20
  };
23
- export declare class TableSelection {
24
- focusX: number;
25
- focusY: number;
26
- listenersToRemove: Set<() => void>;
27
- grid: Grid;
28
- isHighlightingCells: boolean;
29
- anchorX: number;
30
- anchorY: number;
31
- tableNodeKey: NodeKey;
32
- anchorCell: Cell | null;
33
- focusCell: Cell | null;
34
- anchorCellNodeKey: NodeKey | null;
35
- focusCellNodeKey: NodeKey | null;
36
- editor: LexicalEditor;
37
- gridSelection: GridSelection | null;
38
- hasHijackedSelectionStyles: boolean;
39
- constructor(editor: LexicalEditor, tableNodeKey: string);
40
- getGrid(): Grid;
41
- removeListeners(): void;
42
- trackTableGrid(): void;
43
- clearHighlight(): void;
44
- enableHighlightStyle(): void;
45
- disableHighlightStyle(): void;
46
- updateTableGridSelection(selection: GridSelection | null): void;
47
- setFocusCellForSelection(cell: Cell, ignoreStart?: boolean): void;
48
- setAnchorCellForSelection(cell: Cell): void;
49
- formatCells(type: TextFormatType): void;
50
- clearText(): void;
21
+ export type TableMapType = Array<Array<TableMapValueType>>;
22
+ export declare class TableSelection implements BaseSelection {
23
+ tableKey: NodeKey;
24
+ anchor: PointType;
25
+ focus: PointType;
26
+ _cachedNodes: Array<LexicalNode> | null;
27
+ dirty: boolean;
28
+ constructor(tableKey: NodeKey, anchor: PointType, focus: PointType);
29
+ getStartEndPoints(): [PointType, PointType];
30
+ /**
31
+ * Returns whether the Selection is "backwards", meaning the focus
32
+ * logically precedes the anchor in the EditorState.
33
+ * @returns true if the Selection is backwards, false otherwise.
34
+ */
35
+ isBackward(): boolean;
36
+ getCachedNodes(): LexicalNode[] | null;
37
+ setCachedNodes(nodes: LexicalNode[] | null): void;
38
+ is(selection: null | BaseSelection): boolean;
39
+ set(tableKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
40
+ clone(): TableSelection;
41
+ isCollapsed(): boolean;
42
+ extract(): Array<LexicalNode>;
43
+ insertRawText(text: string): void;
44
+ insertText(): void;
45
+ insertNodes(nodes: Array<LexicalNode>): void;
46
+ getShape(): TableSelectionShape;
47
+ getNodes(): Array<LexicalNode>;
48
+ getTextContent(): string;
51
49
  }
50
+ export declare function $isTableSelection(x: unknown): x is TableSelection;
51
+ export declare function $createTableSelection(): TableSelection;
52
+ export declare function $getChildrenRecursively(node: LexicalNode): Array<LexicalNode>;
@@ -5,24 +5,24 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { GridSelection } from './LexicalGridSelection';
9
8
  import type { TableNode } from './LexicalTableNode';
10
- import type { Cell, Grid } from './LexicalTableSelection';
9
+ import type { TableDOMCell } from './LexicalTableObserver';
10
+ import type { TableSelection } from './LexicalTableSelection';
11
11
  import type { LexicalEditor, LexicalNode, RangeSelection } from 'lexical';
12
- import { TableSelection } from './LexicalTableSelection';
12
+ import { TableDOMTable, TableObserver } from './LexicalTableObserver';
13
13
  declare const LEXICAL_ELEMENT_KEY = "__lexicalTableSelection";
14
- export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor, hasTabHandler: boolean): TableSelection;
15
- export type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableSelection>;
16
- export declare function attachTableSelectionToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableSelection: TableSelection): void;
17
- export declare function getTableSelectionFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableSelection | null;
18
- export declare function getCellFromTarget(node: Node): Cell | null;
14
+ export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor, hasTabHandler: boolean): TableObserver;
15
+ export type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableObserver>;
16
+ export declare function attachTableObserverToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableObserver: TableObserver): void;
17
+ export declare function getTableObserverFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableObserver | null;
18
+ export declare function getDOMCellFromTarget(node: Node): TableDOMCell | null;
19
19
  export declare function doesTargetContainText(node: Node): boolean;
20
- export declare function getTableGrid(tableElement: HTMLElement): Grid;
21
- export declare function $updateDOMForSelection(editor: LexicalEditor, grid: Grid, selection: GridSelection | RangeSelection | null): void;
22
- export declare function $forEachGridCell(grid: Grid, cb: (cell: Cell, lexicalNode: LexicalNode, cords: {
20
+ export declare function getTable(tableElement: HTMLElement): TableDOMTable;
21
+ export declare function $updateDOMForSelection(editor: LexicalEditor, table: TableDOMTable, selection: TableSelection | RangeSelection | null): void;
22
+ export declare function $forEachTableCell(grid: TableDOMTable, cb: (cell: TableDOMCell, lexicalNode: LexicalNode, cords: {
23
23
  x: number;
24
24
  y: number;
25
25
  }) => void): void;
26
- export declare function $addHighlightStyleToTable(editor: LexicalEditor, tableSelection: TableSelection): void;
27
- export declare function $removeHighlightStyleToTable(editor: LexicalEditor, tableSelection: TableSelection): void;
26
+ export declare function $addHighlightStyleToTable(editor: LexicalEditor, tableSelection: TableObserver): void;
27
+ export declare function $removeHighlightStyleToTable(editor: LexicalEditor, tableObserver: TableObserver): void;
28
28
  export {};
@@ -5,11 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { Grid } from './LexicalTableSelection';
8
+ import type { TableMapType, TableMapValueType } from './LexicalTableSelection';
9
+ import type { PointType } from 'lexical';
9
10
  import { LexicalNode } from 'lexical';
10
11
  import { InsertTableCommandPayloadHeaders } from '.';
11
12
  import { TableCellNode } from './LexicalTableCellNode';
12
13
  import { TableNode } from './LexicalTableNode';
14
+ import { TableDOMTable } from './LexicalTableObserver';
13
15
  import { TableRowNode } from './LexicalTableRowNode';
14
16
  export declare function $createTableNodeWithDimensions(rowCount: number, columnCount: number, includeHeaders?: InsertTableCommandPayloadHeaders): TableNode;
15
17
  export declare function $getTableCellNodeFromLexicalNode(startingNode: LexicalNode): TableCellNode | null;
@@ -23,13 +25,21 @@ export type TableCellSiblings = {
23
25
  left: TableCellNode | null | undefined;
24
26
  right: TableCellNode | null | undefined;
25
27
  };
26
- export declare function $getTableCellSiblingsFromTableCellNode(tableCellNode: TableCellNode, grid: Grid): TableCellSiblings;
28
+ export declare function $getTableCellSiblingsFromTableCellNode(tableCellNode: TableCellNode, table: TableDOMTable): TableCellSiblings;
27
29
  export declare function $removeTableRowAtIndex(tableNode: TableNode, indexToDelete: number): TableNode;
28
- export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode;
30
+ export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, table: TableDOMTable): TableNode;
29
31
  export declare function $insertTableRow__EXPERIMENTAL(insertAfter?: boolean): void;
30
- export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number, grid: Grid): TableNode;
32
+ export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number, table: TableDOMTable): TableNode;
31
33
  export declare function $insertTableColumn__EXPERIMENTAL(insertAfter?: boolean): void;
32
34
  export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode;
33
35
  export declare function $deleteTableRow__EXPERIMENTAL(): void;
34
36
  export declare function $deleteTableColumn__EXPERIMENTAL(): void;
35
37
  export declare function $unmergeCell(): void;
38
+ export declare function $computeTableMap(grid: TableNode, cellA: TableCellNode, cellB: TableCellNode): [TableMapType, TableMapValueType, TableMapValueType];
39
+ export declare function $getNodeTriplet(source: PointType | LexicalNode | TableCellNode): [TableCellNode, TableRowNode, TableNode];
40
+ export declare function $getTableCellNodeRect(tableCellNode: TableCellNode): {
41
+ rowIndex: number;
42
+ columnIndex: number;
43
+ rowSpan: number;
44
+ colSpan: number;
45
+ } | null;
package/index.d.ts CHANGED
@@ -6,27 +6,18 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
8
  */
9
- import type { LexicalCommand } from 'lexical';
10
- export type { GridSelection, GridSelectionShape } from './LexicalGridSelection';
11
- export { $createGridSelection, $isGridSelection } from './LexicalGridSelection';
12
9
  export type { SerializedTableCellNode } from './LexicalTableCellNode';
13
10
  export { $createTableCellNode, $isTableCellNode, TableCellHeaderStates, TableCellNode, } from './LexicalTableCellNode';
11
+ export type { InsertTableCommandPayload, InsertTableCommandPayloadHeaders, } from './LexicalTableCommands';
12
+ export { INSERT_TABLE_COMMAND } from './LexicalTableCommands';
14
13
  export type { SerializedTableNode } from './LexicalTableNode';
15
- export { $createTableNode, $getElementGridForTableNode, $isTableNode, TableNode, } from './LexicalTableNode';
14
+ export { $createTableNode, $getElementForTableNode, $isTableNode, TableNode, } from './LexicalTableNode';
15
+ export type { TableDOMCell } from './LexicalTableObserver';
16
+ export { TableObserver } from './LexicalTableObserver';
16
17
  export type { SerializedTableRowNode } from './LexicalTableRowNode';
17
18
  export { $createTableRowNode, $isTableRowNode, TableRowNode, } from './LexicalTableRowNode';
18
- export type { Cell } from './LexicalTableSelection';
19
- export { TableSelection } from './LexicalTableSelection';
19
+ export type { TableSelection, TableSelectionShape, } from './LexicalTableSelection';
20
+ export { $createTableSelection, $isTableSelection, } from './LexicalTableSelection';
20
21
  export type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
21
- export { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement, } from './LexicalTableSelectionHelpers';
22
- export { $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
23
- export type InsertTableCommandPayloadHeaders = Readonly<{
24
- rows: boolean;
25
- columns: boolean;
26
- }> | boolean;
27
- export type InsertTableCommandPayload = Readonly<{
28
- columns: string;
29
- rows: string;
30
- includeHeaders?: InsertTableCommandPayloadHeaders;
31
- }>;
32
- export declare const INSERT_TABLE_COMMAND: LexicalCommand<InsertTableCommandPayload>;
22
+ export { applyTableHandlers, getDOMCellFromTarget, getTableObserverFromTableElement, } from './LexicalTableSelectionHelpers';
23
+ export { $computeTableMap, $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.12.6",
11
+ "version": "0.13.0",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.12.6"
14
+ "lexical": "0.13.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.12.6"
17
+ "@lexical/utils": "0.13.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -1,34 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import { BaseSelection, INTERNAL_PointSelection, LexicalNode, NodeKey, PointType } from 'lexical';
9
- export type GridSelectionShape = {
10
- fromX: number;
11
- fromY: number;
12
- toX: number;
13
- toY: number;
14
- };
15
- export declare class GridSelection extends INTERNAL_PointSelection {
16
- gridKey: NodeKey;
17
- constructor(gridKey: NodeKey, anchor: PointType, focus: PointType);
18
- getCachedNodes(): LexicalNode[] | null;
19
- setCachedNodes(nodes: LexicalNode[] | null): void;
20
- is(selection: null | BaseSelection): boolean;
21
- set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
22
- clone(): GridSelection;
23
- isCollapsed(): boolean;
24
- extract(): Array<LexicalNode>;
25
- insertRawText(text: string): void;
26
- insertText(): void;
27
- insertNodes(nodes: Array<LexicalNode>): void;
28
- getShape(): GridSelectionShape;
29
- getNodes(): Array<LexicalNode>;
30
- getTextContent(): string;
31
- }
32
- export declare function $isGridSelection(x: unknown): x is GridSelection;
33
- export declare function $createGridSelection(): GridSelection;
34
- export declare function $getChildrenRecursively(node: LexicalNode): Array<LexicalNode>;