mirror of
https://github.com/facebook/lexical.git
synced 2025-08-06 16:39:33 +08:00
[lexical-playground] Chore: Remove shared imports from playground (#7368)
This commit is contained in:
@ -26,9 +26,9 @@ import {SelectionAlwaysOnDisplay} from '@lexical/react/LexicalSelectionAlwaysOnD
|
|||||||
import {TabIndentationPlugin} from '@lexical/react/LexicalTabIndentationPlugin';
|
import {TabIndentationPlugin} from '@lexical/react/LexicalTabIndentationPlugin';
|
||||||
import {TablePlugin} from '@lexical/react/LexicalTablePlugin';
|
import {TablePlugin} from '@lexical/react/LexicalTablePlugin';
|
||||||
import {useLexicalEditable} from '@lexical/react/useLexicalEditable';
|
import {useLexicalEditable} from '@lexical/react/useLexicalEditable';
|
||||||
|
import {CAN_USE_DOM} from '@lexical/utils';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {useEffect, useState} from 'react';
|
import {useEffect, useState} from 'react';
|
||||||
import {CAN_USE_DOM} from 'shared/canUseDOM';
|
|
||||||
|
|
||||||
import {createWebsocketProvider} from './collaboration';
|
import {createWebsocketProvider} from './collaboration';
|
||||||
import {useSettings} from './context/SettingsContext';
|
import {useSettings} from './context/SettingsContext';
|
||||||
|
@ -21,8 +21,7 @@ import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
|
|||||||
import {calculateZoomLevel} from '@lexical/utils';
|
import {calculateZoomLevel} from '@lexical/utils';
|
||||||
import {$getNodeByKey} from 'lexical';
|
import {$getNodeByKey} from 'lexical';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {useEffect, useRef} from 'react';
|
import {useEffect, useLayoutEffect, useRef} from 'react';
|
||||||
import useLayoutEffect from 'shared/useLayoutEffect';
|
|
||||||
|
|
||||||
import {createWebsocketProvider} from '../collaboration';
|
import {createWebsocketProvider} from '../collaboration';
|
||||||
import {useSharedHistoryContext} from '../context/SharedHistoryContext';
|
import {useSharedHistoryContext} from '../context/SharedHistoryContext';
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {IS_CHROME} from '@lexical/utils';
|
||||||
import {
|
import {
|
||||||
$getSiblingCaret,
|
$getSiblingCaret,
|
||||||
$isElementNode,
|
$isElementNode,
|
||||||
@ -23,8 +24,6 @@ import {
|
|||||||
SerializedElementNode,
|
SerializedElementNode,
|
||||||
Spread,
|
Spread,
|
||||||
} from 'lexical';
|
} from 'lexical';
|
||||||
import {IS_CHROME} from 'shared/environment';
|
|
||||||
import invariant from 'shared/invariant';
|
|
||||||
|
|
||||||
import {setDomHiddenUntilFound} from './CollapsibleUtils';
|
import {setDomHiddenUntilFound} from './CollapsibleUtils';
|
||||||
|
|
||||||
@ -113,10 +112,9 @@ export class CollapsibleContainerNode extends ElementNode {
|
|||||||
// details is not well supported in Chrome #5582
|
// details is not well supported in Chrome #5582
|
||||||
if (IS_CHROME) {
|
if (IS_CHROME) {
|
||||||
const contentDom = dom.children[1];
|
const contentDom = dom.children[1];
|
||||||
invariant(
|
if (!isHTMLElement(contentDom)) {
|
||||||
isHTMLElement(contentDom),
|
throw new Error('Expected contentDom to be an HTMLElement');
|
||||||
'Expected contentDom to be an HTMLElement',
|
}
|
||||||
);
|
|
||||||
if (currentOpen) {
|
if (currentOpen) {
|
||||||
dom.setAttribute('open', '');
|
dom.setAttribute('open', '');
|
||||||
contentDom.hidden = false;
|
contentDom.hidden = false;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {IS_CHROME} from '@lexical/utils';
|
||||||
import {
|
import {
|
||||||
DOMConversionMap,
|
DOMConversionMap,
|
||||||
DOMConversionOutput,
|
DOMConversionOutput,
|
||||||
@ -16,8 +17,6 @@ import {
|
|||||||
LexicalNode,
|
LexicalNode,
|
||||||
SerializedElementNode,
|
SerializedElementNode,
|
||||||
} from 'lexical';
|
} from 'lexical';
|
||||||
import {IS_CHROME} from 'shared/environment';
|
|
||||||
import invariant from 'shared/invariant';
|
|
||||||
|
|
||||||
import {$isCollapsibleContainerNode} from './CollapsibleContainerNode';
|
import {$isCollapsibleContainerNode} from './CollapsibleContainerNode';
|
||||||
import {domOnBeforeMatch, setDomHiddenUntilFound} from './CollapsibleUtils';
|
import {domOnBeforeMatch, setDomHiddenUntilFound} from './CollapsibleUtils';
|
||||||
@ -48,10 +47,11 @@ export class CollapsibleContentNode extends ElementNode {
|
|||||||
if (IS_CHROME) {
|
if (IS_CHROME) {
|
||||||
editor.getEditorState().read(() => {
|
editor.getEditorState().read(() => {
|
||||||
const containerNode = this.getParentOrThrow();
|
const containerNode = this.getParentOrThrow();
|
||||||
invariant(
|
if (!$isCollapsibleContainerNode(containerNode)) {
|
||||||
$isCollapsibleContainerNode(containerNode),
|
throw new Error(
|
||||||
'Expected parent node to be a CollapsibleContainerNode',
|
'Expected parent node to be a CollapsibleContainerNode',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
if (!containerNode.__open) {
|
if (!containerNode.__open) {
|
||||||
setDomHiddenUntilFound(dom);
|
setDomHiddenUntilFound(dom);
|
||||||
}
|
}
|
||||||
@ -59,10 +59,11 @@ export class CollapsibleContentNode extends ElementNode {
|
|||||||
domOnBeforeMatch(dom, () => {
|
domOnBeforeMatch(dom, () => {
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
const containerNode = this.getParentOrThrow().getLatest();
|
const containerNode = this.getParentOrThrow().getLatest();
|
||||||
invariant(
|
if (!$isCollapsibleContainerNode(containerNode)) {
|
||||||
$isCollapsibleContainerNode(containerNode),
|
throw new Error(
|
||||||
'Expected parent node to be a CollapsibleContainerNode',
|
'Expected parent node to be a CollapsibleContainerNode',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
if (!containerNode.__open) {
|
if (!containerNode.__open) {
|
||||||
containerNode.toggleOpen();
|
containerNode.toggleOpen();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {IS_CHROME} from '@lexical/utils';
|
||||||
import {
|
import {
|
||||||
$createParagraphNode,
|
$createParagraphNode,
|
||||||
$isElementNode,
|
$isElementNode,
|
||||||
@ -18,8 +19,6 @@ import {
|
|||||||
RangeSelection,
|
RangeSelection,
|
||||||
SerializedElementNode,
|
SerializedElementNode,
|
||||||
} from 'lexical';
|
} from 'lexical';
|
||||||
import {IS_CHROME} from 'shared/environment';
|
|
||||||
import invariant from 'shared/invariant';
|
|
||||||
|
|
||||||
import {$isCollapsibleContainerNode} from './CollapsibleContainerNode';
|
import {$isCollapsibleContainerNode} from './CollapsibleContainerNode';
|
||||||
import {$isCollapsibleContentNode} from './CollapsibleContentNode';
|
import {$isCollapsibleContentNode} from './CollapsibleContentNode';
|
||||||
@ -51,10 +50,11 @@ export class CollapsibleTitleNode extends ElementNode {
|
|||||||
dom.addEventListener('click', () => {
|
dom.addEventListener('click', () => {
|
||||||
editor.update(() => {
|
editor.update(() => {
|
||||||
const collapsibleContainer = this.getLatest().getParentOrThrow();
|
const collapsibleContainer = this.getLatest().getParentOrThrow();
|
||||||
invariant(
|
if (!$isCollapsibleContainerNode(collapsibleContainer)) {
|
||||||
$isCollapsibleContainerNode(collapsibleContainer),
|
throw new Error(
|
||||||
'Expected parent node to be a CollapsibleContainerNode',
|
'Expected parent node to be a CollapsibleContainerNode',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
collapsibleContainer.toggleOpen();
|
collapsibleContainer.toggleOpen();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -85,10 +85,9 @@ export class CollapsibleTitleNode extends ElementNode {
|
|||||||
|
|
||||||
static transform(): (node: LexicalNode) => void {
|
static transform(): (node: LexicalNode) => void {
|
||||||
return (node: LexicalNode) => {
|
return (node: LexicalNode) => {
|
||||||
invariant(
|
if (!$isCollapsibleTitleNode(node)) {
|
||||||
$isCollapsibleTitleNode(node),
|
throw new Error('node is not a CollapsibleTitleNode');
|
||||||
'node is not a CollapsibleTitleNode',
|
}
|
||||||
);
|
|
||||||
if (node.isEmpty()) {
|
if (node.isEmpty()) {
|
||||||
node.remove();
|
node.remove();
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,16 @@ import {
|
|||||||
getDOMSelection,
|
getDOMSelection,
|
||||||
KEY_ESCAPE_COMMAND,
|
KEY_ESCAPE_COMMAND,
|
||||||
} from 'lexical';
|
} 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 * as React from 'react';
|
||||||
import {createPortal} from 'react-dom';
|
import {createPortal} from 'react-dom';
|
||||||
import useLayoutEffect from 'shared/useLayoutEffect';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -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
|
//disable eslint sorting rule for quick reference to shortcuts
|
||||||
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
||||||
|
@ -49,7 +49,6 @@ import {
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {ReactPortal, useCallback, useEffect, useRef, useState} from 'react';
|
import {ReactPortal, useCallback, useEffect, useRef, useState} from 'react';
|
||||||
import {createPortal} from 'react-dom';
|
import {createPortal} from 'react-dom';
|
||||||
import invariant from 'shared/invariant';
|
|
||||||
|
|
||||||
import useModal from '../../hooks/useModal';
|
import useModal from '../../hooks/useModal';
|
||||||
import ColorPicker from '../../ui/ColorPicker';
|
import ColorPicker from '../../ui/ColorPicker';
|
||||||
@ -243,10 +242,11 @@ function TableActionMenu({
|
|||||||
editor.getElementByKey(tableNode.getKey()),
|
editor.getElementByKey(tableNode.getKey()),
|
||||||
);
|
);
|
||||||
|
|
||||||
invariant(
|
if (tableElement === null) {
|
||||||
tableElement !== null,
|
throw new Error(
|
||||||
'TableActionMenu: Expected to find tableElement in DOM',
|
'TableActionMenu: Expected to find tableElement in DOM',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const tableObserver = getTableObserverFromTableElement(tableElement);
|
const tableObserver = getTableObserverFromTableElement(tableElement);
|
||||||
if (tableObserver !== null) {
|
if (tableObserver !== null) {
|
||||||
@ -886,10 +886,11 @@ function TableCellActionMenuContainer({
|
|||||||
editor.getElementByKey(tableNode.getKey()),
|
editor.getElementByKey(tableNode.getKey()),
|
||||||
);
|
);
|
||||||
|
|
||||||
invariant(
|
if (tableElement === null) {
|
||||||
tableElement !== null,
|
throw new Error(
|
||||||
'TableActionMenu: Expected to find tableElement in DOM',
|
'TableActionMenu: Expected to find tableElement in DOM',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
tableObserver = getTableObserverFromTableElement(tableElement);
|
tableObserver = getTableObserverFromTableElement(tableElement);
|
||||||
setTableMenuCellNode(tableCellNodeFromSelection);
|
setTableMenuCellNode(tableCellNodeFromSelection);
|
||||||
@ -897,19 +898,19 @@ function TableCellActionMenuContainer({
|
|||||||
const anchorNode = $getTableCellNodeFromLexicalNode(
|
const anchorNode = $getTableCellNodeFromLexicalNode(
|
||||||
selection.anchor.getNode(),
|
selection.anchor.getNode(),
|
||||||
);
|
);
|
||||||
invariant(
|
if (!$isTableCellNode(anchorNode)) {
|
||||||
$isTableCellNode(anchorNode),
|
throw new Error('TableSelection anchorNode must be a TableCellNode');
|
||||||
'TableSelection anchorNode must be a TableCellNode',
|
}
|
||||||
);
|
|
||||||
const tableNode = $getTableNodeFromLexicalNodeOrThrow(anchorNode);
|
const tableNode = $getTableNodeFromLexicalNodeOrThrow(anchorNode);
|
||||||
const tableElement = getTableElement(
|
const tableElement = getTableElement(
|
||||||
tableNode,
|
tableNode,
|
||||||
editor.getElementByKey(tableNode.getKey()),
|
editor.getElementByKey(tableNode.getKey()),
|
||||||
);
|
);
|
||||||
invariant(
|
if (tableElement === null) {
|
||||||
tableElement !== null,
|
throw new Error(
|
||||||
'TableActionMenu: Expected to find tableElement in DOM',
|
'TableActionMenu: Expected to find tableElement in DOM',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
tableObserver = getTableObserverFromTableElement(tableElement);
|
tableObserver = getTableObserverFromTableElement(tableElement);
|
||||||
tableCellParentNodeDOM = editor.getElementByKey(anchorNode.getKey());
|
tableCellParentNodeDOM = editor.getElementByKey(anchorNode.getKey());
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import {
|
|||||||
} from '@lexical/table';
|
} from '@lexical/table';
|
||||||
import {EditorThemeClasses, Klass, LexicalEditor, LexicalNode} from 'lexical';
|
import {EditorThemeClasses, Klass, LexicalEditor, LexicalNode} from 'lexical';
|
||||||
import {createContext, useContext, useEffect, useMemo, useState} from 'react';
|
import {createContext, useContext, useEffect, useMemo, useState} from 'react';
|
||||||
import invariant from 'shared/invariant';
|
|
||||||
|
|
||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
import {DialogActions} from '../ui/Dialog';
|
import {DialogActions} from '../ui/Dialog';
|
||||||
@ -147,8 +146,7 @@ export function TablePlugin({
|
|||||||
const cellContext = useContext(CellContext);
|
const cellContext = useContext(CellContext);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor.hasNodes([TableNode, TableRowNode, TableCellNode])) {
|
if (!editor.hasNodes([TableNode, TableRowNode, TableCellNode])) {
|
||||||
invariant(
|
throw new Error(
|
||||||
false,
|
|
||||||
'TablePlugin: TableNode, TableRowNode, or TableCellNode is not registered on editor',
|
'TablePlugin: TableNode, TableRowNode, or TableCellNode is not registered on editor',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import type {BaseSelection, LexicalEditor} from 'lexical';
|
|||||||
import type {JSX} from 'react';
|
import type {JSX} from 'react';
|
||||||
|
|
||||||
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
||||||
|
import {IS_APPLE} from '@lexical/utils';
|
||||||
import {
|
import {
|
||||||
$createParagraphNode,
|
$createParagraphNode,
|
||||||
$createTextNode,
|
$createTextNode,
|
||||||
@ -17,9 +18,7 @@ import {
|
|||||||
getDOMSelection,
|
getDOMSelection,
|
||||||
} from 'lexical';
|
} from 'lexical';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {useCallback, useEffect, useRef, useState} from 'react';
|
import {useCallback, useEffect, useLayoutEffect, useRef, useState} from 'react';
|
||||||
import {IS_APPLE} from 'shared/environment';
|
|
||||||
import useLayoutEffect from 'shared/useLayoutEffect';
|
|
||||||
|
|
||||||
const copy = (text: string | null) => {
|
const copy = (text: string | null) => {
|
||||||
const textArea = document.createElement('textarea');
|
const textArea = document.createElement('textarea');
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
$findMatchingParent,
|
$findMatchingParent,
|
||||||
$getNearestNodeOfType,
|
$getNearestNodeOfType,
|
||||||
$isEditorIsNestedEditor,
|
$isEditorIsNestedEditor,
|
||||||
|
IS_APPLE,
|
||||||
mergeRegister,
|
mergeRegister,
|
||||||
} from '@lexical/utils';
|
} from '@lexical/utils';
|
||||||
import {
|
import {
|
||||||
@ -54,7 +55,6 @@ import {
|
|||||||
} from 'lexical';
|
} from 'lexical';
|
||||||
import {Dispatch, useCallback, useEffect, useState} from 'react';
|
import {Dispatch, useCallback, useEffect, useState} from 'react';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {IS_APPLE} from 'shared/environment';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
blockTypeToBlockName,
|
blockTypeToBlockName,
|
||||||
|
@ -7,18 +7,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {EditorThemeClasses} from 'lexical';
|
import {EditorThemeClasses} from 'lexical';
|
||||||
import invariant from 'shared/invariant';
|
|
||||||
|
|
||||||
export function getThemeSelector(
|
export function getThemeSelector(
|
||||||
getTheme: () => EditorThemeClasses | null | undefined,
|
getTheme: () => EditorThemeClasses | null | undefined,
|
||||||
name: keyof EditorThemeClasses,
|
name: keyof EditorThemeClasses,
|
||||||
): string {
|
): string {
|
||||||
const className = getTheme()?.[name];
|
const className = getTheme()?.[name];
|
||||||
invariant(
|
if (typeof className !== 'string') {
|
||||||
typeof className === 'string',
|
throw new Error(
|
||||||
'getThemeClass: required theme property %s not defined',
|
`getThemeClass: required theme property ${name} not defined`,
|
||||||
String(name),
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return className
|
return className
|
||||||
.split(/\s+/g)
|
.split(/\s+/g)
|
||||||
.map((cls) => `.${cls}`)
|
.map((cls) => `.${cls}`)
|
||||||
|
Reference in New Issue
Block a user