Skip to content

Commit

Permalink
Removed deprecated from table package functions
Browse files Browse the repository at this point in the history
  • Loading branch information
icrosil committed Dec 12, 2023
1 parent 6f77827 commit d00c753
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
$getTableRowIndexFromTableCellNode,
$insertTableColumn__EXPERIMENTAL,
$insertTableRow__EXPERIMENTAL,
$isGridSelection,
$isTableCellNode,
$isTableRowNode,
$unmergeCell,
DEPRECATED_$isGridSelection,
getTableSelectionFromTableElement,
GridSelection,
HTMLTableElementWithWithTableSelectionState,
Expand Down Expand Up @@ -110,9 +110,8 @@ function $canUnmerge(): boolean {
const selection = $getSelection();
if (
($isRangeSelection(selection) && !selection.isCollapsed()) ||
(DEPRECATED_$isGridSelection(selection) &&
!selection.anchor.is(selection.focus)) ||
(!$isRangeSelection(selection) && !DEPRECATED_$isGridSelection(selection))
($isGridSelection(selection) && !selection.anchor.is(selection.focus)) ||
(!$isRangeSelection(selection) && !$isGridSelection(selection))
) {
return false;
}
Expand Down Expand Up @@ -145,10 +144,7 @@ function $selectLastDescendant(node: ElementNode): void {
function currentCellBackgroundColor(editor: LexicalEditor): null | string {
return editor.getEditorState().read(() => {
const selection = $getSelection();
if (
$isRangeSelection(selection) ||
DEPRECATED_$isGridSelection(selection)
) {
if ($isRangeSelection(selection) || $isGridSelection(selection)) {
const [cell] = DEPRECATED_$getNodeTriplet(selection.anchor);
if ($isTableCellNode(cell)) {
return cell.getBackgroundColor();
Expand Down Expand Up @@ -209,7 +205,7 @@ function TableActionMenu({
editor.getEditorState().read(() => {
const selection = $getSelection();
// Merge cells
if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
const currentSelectionCounts = computeSelectionCount(selection);
updateSelectionCounts(computeSelectionCount(selection));
setCanMergeCells(
Expand Down Expand Up @@ -304,7 +300,7 @@ function TableActionMenu({
const mergeTableCellsAtSelection = () => {
editor.update(() => {
const selection = $getSelection();
if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
const {columns, rows} = computeSelectionCount(selection);
const nodes = selection.getNodes();
let firstCell: null | DEPRECATED_GridCellNode = null;
Expand Down Expand Up @@ -472,16 +468,13 @@ function TableActionMenu({
(value: string) => {
editor.update(() => {
const selection = $getSelection();
if (
$isRangeSelection(selection) ||
DEPRECATED_$isGridSelection(selection)
) {
if ($isRangeSelection(selection) || $isGridSelection(selection)) {
const [cell] = DEPRECATED_$getNodeTriplet(selection.anchor);
if ($isTableCellNode(cell)) {
cell.setBackgroundColor(value);
}

if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
const nodes = selection.getNodes();

for (let i = 0; i < nodes.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
$getTableColumnIndexFromTableCellNode,
$getTableNodeFromLexicalNodeOrThrow,
$getTableRowIndexFromTableCellNode,
$isGridSelection,
$isTableCellNode,
$isTableRowNode,
DEPRECATED_$isGridSelection,
getCellFromTarget,
TableCellNode,
} from '@lexical/table';
Expand Down Expand Up @@ -69,7 +69,7 @@ function TableCellResizer({editor}: {editor: LexicalEditor}): JSX.Element {
SELECTION_CHANGE_COMMAND,
(payload) => {
const selection = $getSelection();
const isGridSelection = DEPRECATED_$isGridSelection(selection);
const isGridSelection = $isGridSelection(selection);

if (isSelectingGrid !== isGridSelection) {
updateIsSelectingGrid(isGridSelection);
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-react/src/LexicalTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
import {$generateHtmlFromNodes} from '@lexical/html';
import {$isLinkNode, LinkNode} from '@lexical/link';
import {$isMarkNode} from '@lexical/mark';
import {DEPRECATED_$isGridSelection, GridSelection} from '@lexical/table';
import {$isGridSelection, GridSelection} from '@lexical/table';
import {mergeRegister} from '@lexical/utils';
import {
$getRoot,
Expand Down Expand Up @@ -428,7 +428,7 @@ function generateContent(
? ': null'
: $isRangeSelection(selection)
? printRangeSelection(selection)
: DEPRECATED_$isGridSelection(selection)
: $isGridSelection(selection)
? printGridSelection(selection)
: printNodeSelection(selection);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-table/flow/LexicalTable.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ declare export class GridSelection implements BaseSelection {
setCachedNodes(nodes: null | Array<LexicalNode>): void;
}

declare export function DEPRECATED_$isGridSelection(
declare export function $isGridSelection(
x: ?mixed,
): boolean %checks(x instanceof GridSelection);

declare export function DEPRECATED_$createGridSelection(): GridSelection;
declare export function $createGridSelection(): GridSelection;
6 changes: 3 additions & 3 deletions packages/lexical-table/src/LexicalGridSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class GridSelection extends INTERNAL_PointSelection {
}

is(selection: null | BaseSelection): boolean {
if (!DEPRECATED_$isGridSelection(selection)) {
if (!$isGridSelection(selection)) {
return false;
}
return (
Expand Down Expand Up @@ -319,11 +319,11 @@ export class GridSelection extends INTERNAL_PointSelection {
}
}

export function DEPRECATED_$isGridSelection(x: unknown): x is GridSelection {
export function $isGridSelection(x: unknown): x is GridSelection {
return x instanceof GridSelection;
}

export function DEPRECATED_$createGridSelection(): GridSelection {
export function $createGridSelection(): GridSelection {
const anchor = $createPoint('root', 0, 'element');
const focus = $createPoint('root', 0, 'element');
return new GridSelection('root', anchor, focus);
Expand Down
12 changes: 6 additions & 6 deletions packages/lexical-table/src/LexicalTableSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import invariant from 'shared/invariant';

import {
type GridSelection,
DEPRECATED_$createGridSelection,
DEPRECATED_$isGridSelection,
$createGridSelection,
$isGridSelection,
} from './LexicalGridSelection';
import {$isTableCellNode} from './LexicalTableCellNode';
import {$isTableNode} from './LexicalTableNode';
Expand Down Expand Up @@ -291,7 +291,7 @@ export class TableSelection {
const focusNodeKey = focusTableCellNode.getKey();

this.gridSelection =
this.gridSelection.clone() || DEPRECATED_$createGridSelection();
this.gridSelection.clone() || $createGridSelection();

this.focusCellNodeKey = focusNodeKey;
this.gridSelection.set(
Expand Down Expand Up @@ -324,7 +324,7 @@ export class TableSelection {
this.gridSelection =
this.gridSelection != null
? this.gridSelection.clone()
: DEPRECATED_$createGridSelection();
: $createGridSelection();
this.anchorCellNodeKey = anchorNodeKey;
}
});
Expand All @@ -334,7 +334,7 @@ export class TableSelection {
this.editor.update(() => {
const selection = $getSelection();

if (!DEPRECATED_$isGridSelection(selection)) {
if (!$isGridSelection(selection)) {
invariant(false, 'Expected grid selection');
}

Expand Down Expand Up @@ -368,7 +368,7 @@ export class TableSelection {

const selection = $getSelection();

if (!DEPRECATED_$isGridSelection(selection)) {
if (!$isGridSelection(selection)) {
invariant(false, 'Expected grid selection');
}

Expand Down
32 changes: 14 additions & 18 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ import {
} from 'lexical';
import invariant from 'shared/invariant';

import {
DEPRECATED_$createGridSelection,
DEPRECATED_$isGridSelection,
} from './LexicalGridSelection';
import {$createGridSelection, $isGridSelection} from './LexicalGridSelection';
import {$isTableCellNode} from './LexicalTableCellNode';
import {$isTableNode} from './LexicalTableNode';
import {TableSelection} from './LexicalTableSelection';
Expand Down Expand Up @@ -130,7 +127,7 @@ export function applyTableHandlers(
const selection = $getSelection();
const target = event.target as Node;
if (
DEPRECATED_$isGridSelection(selection) &&
$isGridSelection(selection) &&
selection.gridKey === tableSelection.tableNodeKey &&
rootElement.contains(target)
) {
Expand Down Expand Up @@ -186,7 +183,7 @@ export function applyTableHandlers(
KEY_ESCAPE_COMMAND,
(event) => {
const selection = $getSelection();
if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
const focusCellNode = $findMatchingParent(
selection.focus.getNode(),
$isTableCellNode,
Expand All @@ -211,7 +208,7 @@ export function applyTableHandlers(
return false;
}

if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
tableSelection.clearText();

return true;
Expand Down Expand Up @@ -305,7 +302,7 @@ export function applyTableHandlers(
return false;
}

if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
event.preventDefault();
event.stopPropagation();
tableSelection.clearText();
Expand Down Expand Up @@ -351,7 +348,7 @@ export function applyTableHandlers(
return false;
}

if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
tableSelection.formatCells(payload);

return true;
Expand Down Expand Up @@ -382,7 +379,7 @@ export function applyTableHandlers(
return false;
}

if (DEPRECATED_$isGridSelection(selection)) {
if ($isGridSelection(selection)) {
tableSelection.clearHighlight();

return false;
Expand Down Expand Up @@ -590,7 +587,7 @@ export function applyTableHandlers(
newRowIdx++;
}
if (newAnchorCellKey && newFocusCellKey) {
const newGridSelection = DEPRECATED_$createGridSelection();
const newGridSelection = $createGridSelection();
newGridSelection.set(
nodes[0].getKey(),
newAnchorCellKey,
Expand Down Expand Up @@ -654,19 +651,18 @@ export function applyTableHandlers(
if (
selection &&
!selection.is(prevSelection) &&
(DEPRECATED_$isGridSelection(selection) ||
DEPRECATED_$isGridSelection(prevSelection)) &&
($isGridSelection(selection) || $isGridSelection(prevSelection)) &&
tableSelection.gridSelection &&
!tableSelection.gridSelection.is(prevSelection)
) {
if (
DEPRECATED_$isGridSelection(selection) &&
$isGridSelection(selection) &&
selection.gridKey === tableSelection.tableNodeKey
) {
tableSelection.updateTableGridSelection(selection);
} else if (
!DEPRECATED_$isGridSelection(selection) &&
DEPRECATED_$isGridSelection(prevSelection) &&
!$isGridSelection(selection) &&
$isGridSelection(prevSelection) &&
prevSelection.gridKey === tableSelection.tableNodeKey
) {
tableSelection.updateTableGridSelection(null);
Expand Down Expand Up @@ -1026,7 +1022,7 @@ function $isSelectionInTable(
selection: null | BaseSelection,
tableNode: TableNode,
): boolean {
if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {
if ($isRangeSelection(selection) || $isGridSelection(selection)) {
const isAnchorInside = tableNode.isParentOf(selection.anchor.getNode());
const isFocusInside = tableNode.isParentOf(selection.focus.getNode());

Expand Down Expand Up @@ -1208,7 +1204,7 @@ function $handleArrowKey(

return true;
}
} else if (DEPRECATED_$isGridSelection(selection)) {
} else if ($isGridSelection(selection)) {
const {anchor, focus} = selection;
const anchorCellNode = $findMatchingParent(
anchor.getNode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import {DEPRECATED_$createGridSelection} from '@lexical/table';
import {$createGridSelection} from '@lexical/table';
import {
type LexicalEditor,
$createParagraphNode,
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('grid selection', () => {
await update(() => {
const paragraph = $createParagraphNode();
originalText = $createTextNode('Hello world');
const selection = DEPRECATED_$createGridSelection();
const selection = $createGridSelection();
selection.set(
originalText.getKey(),
originalText.getKey(),
Expand Down
5 changes: 1 addition & 4 deletions packages/lexical-table/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import type {LexicalCommand} from 'lexical';
import {createCommand} from 'lexical';

export type {GridSelection, GridSelectionShape} from './LexicalGridSelection';
export {
DEPRECATED_$createGridSelection,
DEPRECATED_$isGridSelection,
} from './LexicalGridSelection';
export {$createGridSelection, $isGridSelection} from './LexicalGridSelection';
export type {SerializedTableCellNode} from './LexicalTableCellNode';
export {
$createTableCellNode,
Expand Down

0 comments on commit d00c753

Please sign in to comment.