Skip to content
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
2 changes: 1 addition & 1 deletion packages/lexical-playground/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {SelectionAlwaysOnDisplay} from '@lexical/react/LexicalSelectionAlwaysOnD
import {TabIndentationPlugin} from '@lexical/react/LexicalTabIndentationPlugin';
import {TablePlugin} from '@lexical/react/LexicalTablePlugin';
import {useLexicalEditable} from '@lexical/react/useLexicalEditable';
import {CAN_USE_DOM} from '@lexical/utils';
import * as React from 'react';
import {useEffect, useState} from 'react';
import {CAN_USE_DOM} from 'shared/canUseDOM';

import {createWebsocketProvider} from './collaboration';
import {useSettings} from './context/SettingsContext';
Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-playground/src/nodes/StickyComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
import {calculateZoomLevel} from '@lexical/utils';
import {$getNodeByKey} from 'lexical';
import * as React from 'react';
import {useEffect, useRef} from 'react';
import useLayoutEffect from 'shared/useLayoutEffect';
import {useEffect, useLayoutEffect, useRef} from 'react';

import {createWebsocketProvider} from '../collaboration';
import {useSharedHistoryContext} from '../context/SharedHistoryContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

import {IS_CHROME} from '@lexical/utils';
import {
$getSiblingCaret,
$isElementNode,
Expand All @@ -23,8 +24,6 @@ import {
SerializedElementNode,
Spread,
} from 'lexical';
import {IS_CHROME} from 'shared/environment';
import invariant from 'shared/invariant';

import {setDomHiddenUntilFound} from './CollapsibleUtils';

Expand Down Expand Up @@ -113,10 +112,9 @@ export class CollapsibleContainerNode extends ElementNode {
// details is not well supported in Chrome #5582
if (IS_CHROME) {
const contentDom = dom.children[1];
invariant(
isHTMLElement(contentDom),
'Expected contentDom to be an HTMLElement',
);
if (!isHTMLElement(contentDom)) {
throw new Error('Expected contentDom to be an HTMLElement');
}
if (currentOpen) {
dom.setAttribute('open', '');
contentDom.hidden = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

import {IS_CHROME} from '@lexical/utils';
import {
DOMConversionMap,
DOMConversionOutput,
Expand All @@ -16,8 +17,6 @@ import {
LexicalNode,
SerializedElementNode,
} from 'lexical';
import {IS_CHROME} from 'shared/environment';
import invariant from 'shared/invariant';

import {$isCollapsibleContainerNode} from './CollapsibleContainerNode';
import {domOnBeforeMatch, setDomHiddenUntilFound} from './CollapsibleUtils';
Expand Down Expand Up @@ -48,21 +47,23 @@ export class CollapsibleContentNode extends ElementNode {
if (IS_CHROME) {
editor.getEditorState().read(() => {
const containerNode = this.getParentOrThrow();
invariant(
$isCollapsibleContainerNode(containerNode),
'Expected parent node to be a CollapsibleContainerNode',
);
if (!$isCollapsibleContainerNode(containerNode)) {
throw new Error(
'Expected parent node to be a CollapsibleContainerNode',
);
}
if (!containerNode.__open) {
setDomHiddenUntilFound(dom);
}
});
domOnBeforeMatch(dom, () => {
editor.update(() => {
const containerNode = this.getParentOrThrow().getLatest();
invariant(
$isCollapsibleContainerNode(containerNode),
'Expected parent node to be a CollapsibleContainerNode',
);
if (!$isCollapsibleContainerNode(containerNode)) {
throw new Error(
'Expected parent node to be a CollapsibleContainerNode',
);
}
if (!containerNode.__open) {
containerNode.toggleOpen();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

import {IS_CHROME} from '@lexical/utils';
import {
$createParagraphNode,
$isElementNode,
Expand All @@ -18,8 +19,6 @@ import {
RangeSelection,
SerializedElementNode,
} from 'lexical';
import {IS_CHROME} from 'shared/environment';
import invariant from 'shared/invariant';

import {$isCollapsibleContainerNode} from './CollapsibleContainerNode';
import {$isCollapsibleContentNode} from './CollapsibleContentNode';
Expand Down Expand Up @@ -51,10 +50,11 @@ export class CollapsibleTitleNode extends ElementNode {
dom.addEventListener('click', () => {
editor.update(() => {
const collapsibleContainer = this.getLatest().getParentOrThrow();
invariant(
$isCollapsibleContainerNode(collapsibleContainer),
'Expected parent node to be a CollapsibleContainerNode',
);
if (!$isCollapsibleContainerNode(collapsibleContainer)) {
throw new Error(
'Expected parent node to be a CollapsibleContainerNode',
);
}
collapsibleContainer.toggleOpen();
});
});
Expand Down Expand Up @@ -85,10 +85,9 @@ export class CollapsibleTitleNode extends ElementNode {

static transform(): (node: LexicalNode) => void {
return (node: LexicalNode) => {
invariant(
$isCollapsibleTitleNode(node),
'node is not a CollapsibleTitleNode',
);
if (!$isCollapsibleTitleNode(node)) {
throw new Error('node is not a CollapsibleTitleNode');
}
if (node.isEmpty()) {
node.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ import {
getDOMSelection,
KEY_ESCAPE_COMMAND,
} from 'lexical';
import {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react';
import * as React from 'react';
import {createPortal} from 'react-dom';
import useLayoutEffect from 'shared/useLayoutEffect';

import {
Comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import {IS_APPLE} from 'shared/environment';
import {IS_APPLE} from '@lexical/utils';

//disable eslint sorting rule for quick reference to shortcuts
/* eslint-disable sort-keys-fix/sort-keys-fix */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
import * as React from 'react';
import {ReactPortal, useCallback, useEffect, useRef, useState} from 'react';
import {createPortal} from 'react-dom';
import invariant from 'shared/invariant';

import useModal from '../../hooks/useModal';
import ColorPicker from '../../ui/ColorPicker';
Expand Down Expand Up @@ -243,10 +242,11 @@ function TableActionMenu({
editor.getElementByKey(tableNode.getKey()),
);

invariant(
tableElement !== null,
'TableActionMenu: Expected to find tableElement in DOM',
);
if (tableElement === null) {
throw new Error(
'TableActionMenu: Expected to find tableElement in DOM',
);
}

const tableObserver = getTableObserverFromTableElement(tableElement);
if (tableObserver !== null) {
Expand Down Expand Up @@ -886,30 +886,31 @@ function TableCellActionMenuContainer({
editor.getElementByKey(tableNode.getKey()),
);

invariant(
tableElement !== null,
'TableActionMenu: Expected to find tableElement in DOM',
);
if (tableElement === null) {
throw new Error(
'TableActionMenu: Expected to find tableElement in DOM',
);
}

tableObserver = getTableObserverFromTableElement(tableElement);
setTableMenuCellNode(tableCellNodeFromSelection);
} else if ($isTableSelection(selection)) {
const anchorNode = $getTableCellNodeFromLexicalNode(
selection.anchor.getNode(),
);
invariant(
$isTableCellNode(anchorNode),
'TableSelection anchorNode must be a TableCellNode',
);
if (!$isTableCellNode(anchorNode)) {
throw new Error('TableSelection anchorNode must be a TableCellNode');
}
const tableNode = $getTableNodeFromLexicalNodeOrThrow(anchorNode);
const tableElement = getTableElement(
tableNode,
editor.getElementByKey(tableNode.getKey()),
);
invariant(
tableElement !== null,
'TableActionMenu: Expected to find tableElement in DOM',
);
if (tableElement === null) {
throw new Error(
'TableActionMenu: Expected to find tableElement in DOM',
);
}
tableObserver = getTableObserverFromTableElement(tableElement);
tableCellParentNodeDOM = editor.getElementByKey(anchorNode.getKey());

Expand Down
4 changes: 1 addition & 3 deletions packages/lexical-playground/src/plugins/TablePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '@lexical/table';
import {EditorThemeClasses, Klass, LexicalEditor, LexicalNode} from 'lexical';
import {createContext, useContext, useEffect, useMemo, useState} from 'react';
import invariant from 'shared/invariant';

import Button from '../ui/Button';
import {DialogActions} from '../ui/Dialog';
Expand Down Expand Up @@ -147,8 +146,7 @@ export function TablePlugin({
const cellContext = useContext(CellContext);
useEffect(() => {
if (!editor.hasNodes([TableNode, TableRowNode, TableCellNode])) {
invariant(
false,
throw new Error(
'TablePlugin: TableNode, TableRowNode, or TableCellNode is not registered on editor',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import type {BaseSelection, LexicalEditor} from 'lexical';
import type {JSX} from 'react';

import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {IS_APPLE} from '@lexical/utils';
import {
$createParagraphNode,
$createTextNode,
$getRoot,
getDOMSelection,
} from 'lexical';
import * as React from 'react';
import {useCallback, useEffect, useRef, useState} from 'react';
import {IS_APPLE} from 'shared/environment';
import useLayoutEffect from 'shared/useLayoutEffect';
import {useCallback, useEffect, useLayoutEffect, useRef, useState} from 'react';

const copy = (text: string | null) => {
const textArea = document.createElement('textarea');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
$findMatchingParent,
$getNearestNodeOfType,
$isEditorIsNestedEditor,
IS_APPLE,
mergeRegister,
} from '@lexical/utils';
import {
Expand All @@ -54,7 +55,6 @@ import {
} from 'lexical';
import {Dispatch, useCallback, useEffect, useState} from 'react';
import * as React from 'react';
import {IS_APPLE} from 'shared/environment';

import {
blockTypeToBlockName,
Expand Down
11 changes: 5 additions & 6 deletions packages/lexical-playground/src/utils/getThemeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
*/

import {EditorThemeClasses} from 'lexical';
import invariant from 'shared/invariant';

export function getThemeSelector(
getTheme: () => EditorThemeClasses | null | undefined,
name: keyof EditorThemeClasses,
): string {
const className = getTheme()?.[name];
invariant(
typeof className === 'string',
'getThemeClass: required theme property %s not defined',
String(name),
);
if (typeof className !== 'string') {
throw new Error(
`getThemeClass: required theme property ${name} not defined`,
);
}
return className
.split(/\s+/g)
.map((cls) => `.${cls}`)
Expand Down