Skip to content

Commit

Permalink
[lexical][lexical-table] Chore: Replace references to old GridSelecti…
Browse files Browse the repository at this point in the history
…on with TableSelection (#6366)
  • Loading branch information
etrepum authored Jul 2, 2024
1 parent 131feee commit 55cc980
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/lexical-devtools/src/serializeEditorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function serializeEditorState(
typeof selection.anchor === 'object' &&
selection.anchor != null
) {
// remove _selection.anchor._selection property if present in RangeSelection or GridSelection
// remove _selection.anchor._selection property if present in RangeSelection or TableSelection
// otherwise, the recursive structure makes the selection object unserializable
selection.anchor = serializePoint(selection.anchor);
}
Expand All @@ -76,7 +76,7 @@ export function serializeEditorState(
typeof selection.focus === 'object' &&
selection.focus != null
) {
// remove _selection.anchor._selection property if present in RangeSelection or GridSelection
// remove _selection.anchor._selection property if present in RangeSelection or TableSelection
// otherwise, the recursive structure makes the selection object unserializable
selection.focus = serializePoint(selection.focus);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/lexical-table/src/LexicalTableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function $insertTableRow__EXPERIMENTAL(insertAfter = true): void {
const selection = $getSelection();
invariant(
$isRangeSelection(selection) || $isTableSelection(selection),
'Expected a RangeSelection or GridSelection',
'Expected a RangeSelection or TableSelection',
);
const focus = selection.focus.getNode();
const [focusCell, , grid] = $getNodeTriplet(focus);
Expand Down Expand Up @@ -377,7 +377,7 @@ export function $insertTableColumn__EXPERIMENTAL(insertAfter = true): void {
const selection = $getSelection();
invariant(
$isRangeSelection(selection) || $isTableSelection(selection),
'Expected a RangeSelection or GridSelection',
'Expected a RangeSelection or TableSelection',
);
const anchor = selection.anchor.getNode();
const focus = selection.focus.getNode();
Expand Down Expand Up @@ -500,7 +500,7 @@ export function $deleteTableRow__EXPERIMENTAL(): void {
const selection = $getSelection();
invariant(
$isRangeSelection(selection) || $isTableSelection(selection),
'Expected a RangeSelection or GridSelection',
'Expected a RangeSelection or TableSelection',
);
const anchor = selection.anchor.getNode();
const focus = selection.focus.getNode();
Expand Down Expand Up @@ -576,7 +576,7 @@ export function $deleteTableColumn__EXPERIMENTAL(): void {
const selection = $getSelection();
invariant(
$isRangeSelection(selection) || $isTableSelection(selection),
'Expected a RangeSelection or GridSelection',
'Expected a RangeSelection or TableSelection',
);
const anchor = selection.anchor.getNode();
const focus = selection.focus.getNode();
Expand Down Expand Up @@ -667,7 +667,7 @@ export function $unmergeCell(): void {
const selection = $getSelection();
invariant(
$isRangeSelection(selection) || $isTableSelection(selection),
'Expected a RangeSelection or GridSelection',
'Expected a RangeSelection or TableSelection',
);
const anchor = selection.anchor.getNode();
const [cell, row, grid] = $getNodeTriplet(anchor);
Expand Down
18 changes: 10 additions & 8 deletions packages/lexical-website/docs/concepts/selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ In Lexical, there are four types of selection possible:

- `RangeSelection`
- `NodeSelection`
- `GridSelection`
- `TableSelection` (implemented in `@lexical/table`)
- `null`

It is possible, but not generally recommended, to implement your own selection types that implement `BaseSelection`.

### `RangeSelection`

This is the most common type of selection, and is a normalization of the browser's DOM Selection and Range APIs.
Expand All @@ -35,17 +37,17 @@ NodeSelection represents a selection of multiple arbitrary nodes. For example, t

- `getNodes()` returns an array containing the selected LexicalNodes

### `GridSelection`
### `TableSelection`

GridSelection represents a grid-like selection like tables. It stores the key of the parent node where the selection takes place and the start and end points.
`GridSelection` consists of three main properties:
TableSelection represents a grid-like selection like tables. It stores the key of the parent node where the selection takes place and the start and end points.
`TableSelection` consists of three main properties:

- `gridKey` representing the parent node key where the selection takes place
- `anchor` representing a `GridSelection` point
- `focus` reprensenting a `GridSelection` point
- `tableKey` representing the parent node key where the selection takes place
- `anchor` representing a `TableSelection` point
- `focus` reprensenting a `TableSelection` point

For example, a table where you select row = 1 col = 1 to row 2 col = 2 could be stored as follows:
- `gridKey = 2` table key
- `tableKey = 2` table key
- `anchor = 4` table cell (key may vary)
- `focus = 10` table cell (key may vary)

Expand Down

0 comments on commit 55cc980

Please sign in to comment.