Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR 1] Swap instance selection for BaseSelection in most cases #5280

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/lexical-clipboard/flow/LexicalClipboard.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import type {
BaseSelection,
GridSelection,
LexicalEditor,
NodeSelection,
RangeSelection,
LexicalNode,
} from 'lexical';
Expand Down Expand Up @@ -58,7 +58,7 @@ declare export function $generateJSONFromSelectedNodes<
SerializedNode: BaseSerializedNode,
>(
editor: LexicalEditor,
selection: RangeSelection | NodeSelection | GridSelection | null,
selection: BaseSelection | null,
): {
namespace: string,
nodes: Array<SerializedNode>,
Expand Down
6 changes: 3 additions & 3 deletions packages/lexical-clipboard/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
$isTextNode,
$parseSerializedNode,
$setSelection,
BaseSelection,
COMMAND_PRIORITY_CRITICAL,
COPY_COMMAND,
DEPRECATED_$createGridSelection,
Expand All @@ -37,7 +38,6 @@ import {
isSelectionWithinEditor,
LexicalEditor,
LexicalNode,
NodeSelection,
RangeSelection,
SELECTION_CHANGE_COMMAND,
SerializedTextNode,
Expand Down Expand Up @@ -435,7 +435,7 @@ function exportNodeToJSON<T extends LexicalNode>(node: T): BaseSerializedNode {

function $appendNodesToJSON(
editor: LexicalEditor,
selection: RangeSelection | NodeSelection | GridSelection | null,
selection: BaseSelection | null,
currentNode: LexicalNode,
targetArray: Array<BaseSerializedNode> = [],
): boolean {
Expand Down Expand Up @@ -518,7 +518,7 @@ export function $generateJSONFromSelectedNodes<
SerializedNode extends BaseSerializedNode,
>(
editor: LexicalEditor,
selection: RangeSelection | NodeSelection | GridSelection | null,
selection: BaseSelection | null,
): {
namespace: string;
nodes: Array<SerializedNode>;
Expand Down
7 changes: 2 additions & 5 deletions packages/lexical-code/src/CodeHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import type {
LexicalEditor,
LexicalNode,
RangeSelection,
NodeSelection,
LineBreakNode,
GridSelection,
NodeKey,
BaseSelection,
} from 'lexical';

import * as Prism from 'prismjs';
Expand Down Expand Up @@ -487,9 +486,7 @@ function isEqual(nodeA: LexicalNode, nodeB: LexicalNode): boolean {
);
}

function $isSelectionInCode(
selection: null | RangeSelection | NodeSelection | GridSelection,
): boolean {
function $isSelectionInCode(selection: null | BaseSelection): boolean {
if (!$isRangeSelection(selection)) {
return false;
}
Expand Down
10 changes: 2 additions & 8 deletions packages/lexical-history/flow/LexicalHistory.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@
*
* @flow strict
*/
import type {
EditorState,
GridSelection,
LexicalEditor,
NodeSelection,
RangeSelection,
} from 'lexical';
import type {EditorState, BaseSelection, LexicalEditor} from 'lexical';

export type HistoryStateEntry = {
editor: LexicalEditor,
editorState: EditorState,
undoSelection?: RangeSelection | NodeSelection | GridSelection | null,
undoSelection?: BaseSelection | null,
};
export type HistoryState = {
current: null | HistoryStateEntry,
Expand Down
6 changes: 2 additions & 4 deletions packages/lexical-html/flow/LexicalHtml.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
*/

import type {
BaseSelection,
LexicalEditor,
LexicalNode,
EditorState,
EditorThemeClasses,
RangeSelection,
NodeSelection,
GridSelection,
} from 'lexical';

export type FindCachedParentDOMNode = (
Expand All @@ -25,7 +23,7 @@ export type FindCachedParentDOMNodeSearchFn = (node: Node) => boolean;

declare export function $generateHtmlFromNodes(
editor: LexicalEditor,
selection?: RangeSelection | NodeSelection | GridSelection | null,
selection?: BaseSelection | null,
): string;

declare export function $generateNodesFromDOM(
Expand Down
8 changes: 3 additions & 5 deletions packages/lexical-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
*/

import type {
BaseSelection,
DOMChildConversion,
DOMConversion,
DOMConversionFn,
GridSelection,
LexicalEditor,
LexicalNode,
NodeSelection,
RangeSelection,
} from 'lexical';

import {
Expand Down Expand Up @@ -51,7 +49,7 @@ export function $generateNodesFromDOM(

export function $generateHtmlFromNodes(
editor: LexicalEditor,
selection?: RangeSelection | NodeSelection | GridSelection | null,
selection?: BaseSelection | null,
): string {
if (typeof document === 'undefined' || typeof window === 'undefined') {
throw new Error(
Expand All @@ -75,7 +73,7 @@ function $appendNodesToHTML(
editor: LexicalEditor,
currentNode: LexicalNode,
parentElement: HTMLElement | DocumentFragment,
selection: RangeSelection | NodeSelection | GridSelection | null = null,
selection: BaseSelection | null = null,
): boolean {
let shouldInclude =
selection != null ? currentNode.isSelected(selection) : true;
Expand Down
5 changes: 2 additions & 3 deletions packages/lexical-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
*/

import type {
BaseSelection,
DOMConversionMap,
DOMConversionOutput,
EditorConfig,
GridSelection,
LexicalCommand,
LexicalNode,
NodeKey,
NodeSelection,
RangeSelection,
SerializedElementNode,
} from 'lexical';
Expand Down Expand Up @@ -254,7 +253,7 @@ export class LinkNode extends ElementNode {

extractWithChild(
child: LexicalNode,
selection: RangeSelection | NodeSelection | GridSelection,
selection: BaseSelection,
destination: 'clone' | 'html',
): boolean {
if (!$isRangeSelection(selection)) {
Expand Down
8 changes: 2 additions & 6 deletions packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

import type {ListNode} from './';
import type {
BaseSelection,
DOMConversionMap,
DOMConversionOutput,
DOMExportOutput,
EditorConfig,
EditorThemeClasses,
GridSelection,
LexicalNode,
NodeKey,
NodeSelection,
ParagraphNode,
RangeSelection,
SerializedElementNode,
Expand Down Expand Up @@ -419,10 +418,7 @@ export class ListItemNode extends ElementNode {
return $isParagraphNode(node) || $isListItemNode(node);
}

extractWithChild(
child: LexicalNode,
selection: RangeSelection | NodeSelection | GridSelection,
): boolean {
extractWithChild(child: LexicalNode, selection: BaseSelection): boolean {
if (!$isRangeSelection(selection)) {
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/lexical-mark/src/MarkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
*/

import type {
BaseSelection,
EditorConfig,
GridSelection,
LexicalNode,
NodeKey,
NodeSelection,
RangeSelection,
SerializedElementNode,
Spread,
Expand Down Expand Up @@ -182,7 +181,7 @@ export class MarkNode extends ElementNode {

extractWithChild(
child: LexicalNode,
selection: RangeSelection | NodeSelection | GridSelection,
selection: BaseSelection,
destination: 'clone' | 'html',
): boolean {
if (!$isRangeSelection(selection) || destination === 'html') {
Expand Down
8 changes: 2 additions & 6 deletions packages/lexical-playground/src/nodes/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
*/

import type {
GridSelection,
BaseSelection,
LexicalCommand,
LexicalEditor,
NodeKey,
NodeSelection,
RangeSelection,
} from 'lexical';

import './ImageNode.css';
Expand Down Expand Up @@ -142,9 +140,7 @@ export default function ImageComponent({
const [isResizing, setIsResizing] = useState<boolean>(false);
const {isCollabActive} = useCollaborationContext();
const [editor] = useLexicalComposerContext();
const [selection, setSelection] = useState<
RangeSelection | NodeSelection | GridSelection | null
>(null);
const [selection, setSelection] = useState<BaseSelection | null>(null);
const activeEditorRef = useRef<LexicalEditor | null>(null);

const onDelete = useCallback(
Expand Down
12 changes: 2 additions & 10 deletions packages/lexical-playground/src/nodes/InlineImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
*
*/
import type {Position} from './InlineImageNode';
import type {
GridSelection,
LexicalEditor,
NodeKey,
NodeSelection,
RangeSelection,
} from 'lexical';
import type {BaseSelection, LexicalEditor, NodeKey} from 'lexical';

import './InlineImageNode.css';

Expand Down Expand Up @@ -207,9 +201,7 @@ export default function InlineImageComponent({
const [isSelected, setSelected, clearSelection] =
useLexicalNodeSelection(nodeKey);
const [editor] = useLexicalComposerContext();
const [selection, setSelection] = useState<
RangeSelection | NodeSelection | GridSelection | null
>(null);
const [selection, setSelection] = useState<BaseSelection | null>(null);
const activeEditorRef = useRef<LexicalEditor | null>(null);

const onDelete = useCallback(
Expand Down
8 changes: 2 additions & 6 deletions packages/lexical-playground/src/nodes/PollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import {
$getNodeByKey,
$getSelection,
$isNodeSelection,
BaseSelection,
CLICK_COMMAND,
COMMAND_PRIORITY_LOW,
GridSelection,
KEY_BACKSPACE_COMMAND,
KEY_DELETE_COMMAND,
NodeKey,
NodeSelection,
RangeSelection,
} from 'lexical';
import * as React from 'react';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
Expand Down Expand Up @@ -143,9 +141,7 @@ export default function PollComponent({
const totalVotes = useMemo(() => getTotalVotes(options), [options]);
const [isSelected, setSelected, clearSelection] =
useLexicalNodeSelection(nodeKey);
const [selection, setSelection] = useState<
RangeSelection | NodeSelection | GridSelection | null
>(null);
const [selection, setSelection] = useState<BaseSelection | null>(null);
const ref = useRef(null);

const onDelete = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
*
*/

import type {
GridSelection,
NodeKey,
NodeSelection,
RangeSelection,
} from 'lexical';
import type {BaseSelection, NodeKey} from 'lexical';

import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {$isAtNodeEnd} from '@lexical/selection';
Expand Down Expand Up @@ -47,9 +42,7 @@ export const uuid = Math.random()
.substr(0, 5);

// TODO lookup should be custom
function $search(
selection: null | RangeSelection | NodeSelection | GridSelection,
): [boolean, string] {
function $search(selection: null | BaseSelection): [boolean, string] {
if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
return [false, ''];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import {$findMatchingParent, mergeRegister} from '@lexical/utils';
import {
$getSelection,
$isRangeSelection,
BaseSelection,
CLICK_COMMAND,
COMMAND_PRIORITY_CRITICAL,
COMMAND_PRIORITY_HIGH,
COMMAND_PRIORITY_LOW,
GridSelection,
KEY_ESCAPE_COMMAND,
LexicalEditor,
NodeSelection,
RangeSelection,
SELECTION_CHANGE_COMMAND,
} from 'lexical';
import {Dispatch, useCallback, useEffect, useRef, useState} from 'react';
Expand Down Expand Up @@ -51,9 +49,9 @@ function FloatingLinkEditor({
const inputRef = useRef<HTMLInputElement>(null);
const [linkUrl, setLinkUrl] = useState('');
const [editedLinkUrl, setEditedLinkUrl] = useState('https://');
const [lastSelection, setLastSelection] = useState<
RangeSelection | GridSelection | NodeSelection | null
>(null);
const [lastSelection, setLastSelection] = useState<BaseSelection | null>(
null,
);

const updateLinkEditor = useCallback(() => {
const selection = $getSelection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
*
*/

import type {
GridSelection,
LexicalEditor,
NodeSelection,
RangeSelection,
} from 'lexical';
import type {BaseSelection, LexicalEditor} from 'lexical';

import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical';
Expand Down Expand Up @@ -159,9 +154,7 @@ function useTestRecorder(
const [isRecording, setIsRecording] = useState(false);
const [, setCurrentInnerHTML] = useState('');
const [templatedTest, setTemplatedTest] = useState('');
const previousSelectionRef = useRef<
RangeSelection | GridSelection | NodeSelection | null
>(null);
const previousSelectionRef = useRef<BaseSelection | null>(null);
const skipNextSelectionChangeRef = useRef(false);
const preRef = useRef<HTMLPreElement>(null);

Expand Down
Loading
Loading