From ec9134ceda7bb40356ebe41c5947d86341623c70 Mon Sep 17 00:00:00 2001 From: John Flockton Date: Mon, 27 Jun 2022 20:48:59 +0100 Subject: [PATCH] Export Klass from Lexical root (#2533) --- packages/lexical-headless/src/index.ts | 2 +- .../src/nodes/PlaygroundNodes.ts | 3 +-- .../lexical-react/src/DEPRECATED_useLexical.ts | 2 +- packages/lexical-react/src/LexicalComposer.tsx | 2 +- .../lexical-react/src/useLexicalTextEntity.ts | 3 +-- packages/lexical-text/src/index.ts | 9 +++++++-- packages/lexical-utils/src/index.ts | 2 +- packages/lexical/src/LexicalEditor.ts | 6 +++++- packages/lexical/src/LexicalNode.ts | 2 +- packages/lexical/src/LexicalUtils.ts | 2 +- packages/lexical/src/index.ts | 1 + packages/shared/types.d.ts | 15 --------------- tsconfig.json | 3 +-- 13 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 packages/shared/types.d.ts diff --git a/packages/lexical-headless/src/index.ts b/packages/lexical-headless/src/index.ts index e84b0fec27f..b03d1147b55 100644 --- a/packages/lexical-headless/src/index.ts +++ b/packages/lexical-headless/src/index.ts @@ -9,10 +9,10 @@ import type { EditorState, EditorThemeClasses, + Klass, LexicalEditor, LexicalNode, } from 'lexical'; -import type {Klass} from 'shared/types'; import {createEditor} from 'lexical'; diff --git a/packages/lexical-playground/src/nodes/PlaygroundNodes.ts b/packages/lexical-playground/src/nodes/PlaygroundNodes.ts index ee7d7dfa631..3b7defef2c0 100644 --- a/packages/lexical-playground/src/nodes/PlaygroundNodes.ts +++ b/packages/lexical-playground/src/nodes/PlaygroundNodes.ts @@ -6,8 +6,7 @@ * */ -import type {LexicalNode} from 'lexical'; -import type {Klass} from 'shared/types'; +import type {Klass, LexicalNode} from 'lexical'; import {CodeHighlightNode, CodeNode} from '@lexical/code'; import {HashtagNode} from '@lexical/hashtag'; diff --git a/packages/lexical-react/src/DEPRECATED_useLexical.ts b/packages/lexical-react/src/DEPRECATED_useLexical.ts index 104ac6e6407..6bf707284af 100644 --- a/packages/lexical-react/src/DEPRECATED_useLexical.ts +++ b/packages/lexical-react/src/DEPRECATED_useLexical.ts @@ -9,10 +9,10 @@ import type { EditorState, EditorThemeClasses, + Klass, LexicalEditor, LexicalNode, } from 'lexical'; -import type {Klass} from 'shared/types'; import {createEditor} from 'lexical'; import {useMemo} from 'react'; diff --git a/packages/lexical-react/src/LexicalComposer.tsx b/packages/lexical-react/src/LexicalComposer.tsx index 8ad25142ece..976faed7adb 100644 --- a/packages/lexical-react/src/LexicalComposer.tsx +++ b/packages/lexical-react/src/LexicalComposer.tsx @@ -7,6 +7,7 @@ */ import type {LexicalComposerContextType} from '@lexical/react/LexicalComposerContext'; +import type {Klass} from 'lexical'; import { createLexicalComposerContext, @@ -22,7 +23,6 @@ import { } from 'lexical'; import {useMemo} from 'react'; import * as React from 'react'; -import {Klass} from 'shared/types'; import useLayoutEffect from 'shared/useLayoutEffect'; const HISTORY_MERGE_OPTIONS = {tag: 'history-merge'}; diff --git a/packages/lexical-react/src/useLexicalTextEntity.ts b/packages/lexical-react/src/useLexicalTextEntity.ts index 239e0519be0..3548c56f958 100644 --- a/packages/lexical-react/src/useLexicalTextEntity.ts +++ b/packages/lexical-react/src/useLexicalTextEntity.ts @@ -7,13 +7,12 @@ */ import type {EntityMatch} from '@lexical/text'; -import type {TextNode} from 'lexical'; +import type {Klass, TextNode} from 'lexical'; import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; import {registerLexicalTextEntity} from '@lexical/text'; import {mergeRegister} from '@lexical/utils'; import {useEffect} from 'react'; -import {Klass} from 'shared/types'; export function useLexicalTextEntity( getMatch: (text: string) => null | EntityMatch, diff --git a/packages/lexical-text/src/index.ts b/packages/lexical-text/src/index.ts index d39203ec0fc..5a6b6f6e364 100644 --- a/packages/lexical-text/src/index.ts +++ b/packages/lexical-text/src/index.ts @@ -6,8 +6,13 @@ * */ -import type {ElementNode, LexicalEditor, LexicalNode, RootNode} from 'lexical'; -import type {Klass} from 'shared/types'; +import type { + ElementNode, + Klass, + LexicalEditor, + LexicalNode, + RootNode, +} from 'lexical'; import { $createTextNode, diff --git a/packages/lexical-utils/src/index.ts b/packages/lexical-utils/src/index.ts index 5a8ec2952bc..6419efe72e9 100644 --- a/packages/lexical-utils/src/index.ts +++ b/packages/lexical-utils/src/index.ts @@ -9,11 +9,11 @@ import type { EditorState, ElementNode, + Klass, LexicalEditor, LexicalNode, NodeKey, } from 'lexical'; -import type {Klass} from 'shared/types'; import { $getRoot, diff --git a/packages/lexical/src/LexicalEditor.ts b/packages/lexical/src/LexicalEditor.ts index 1d2335e4550..a966132ad21 100644 --- a/packages/lexical/src/LexicalEditor.ts +++ b/packages/lexical/src/LexicalEditor.ts @@ -8,7 +8,6 @@ import type {EditorState, SerializedEditorState} from './LexicalEditorState'; import type {DOMConversion, LexicalNode, NodeKey} from './LexicalNode'; -import type {Klass} from 'shared/types'; import getDOMSelection from 'shared/getDOMSelection'; import invariant from 'shared/invariant'; @@ -33,6 +32,11 @@ import {RootNode} from './nodes/LexicalRootNode'; export type Spread = Omit & T1; +export type Klass = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + new (...args: any[]): T; +} & Omit; + export type EditorThemeClassName = string; export type TextNodeThemeClasses = { diff --git a/packages/lexical/src/LexicalNode.ts b/packages/lexical/src/LexicalNode.ts index 039cdae85b6..8b1479cd43b 100644 --- a/packages/lexical/src/LexicalNode.ts +++ b/packages/lexical/src/LexicalNode.ts @@ -9,7 +9,7 @@ /* eslint-disable no-constant-condition */ import type {EditorConfig, LexicalEditor} from './LexicalEditor'; import type {RangeSelection} from './LexicalSelection'; -import type {Klass} from 'shared/types'; +import type {Klass} from 'lexical'; import invariant from 'shared/invariant'; diff --git a/packages/lexical/src/LexicalUtils.ts b/packages/lexical/src/LexicalUtils.ts index d2bfa95f734..953e6665a0e 100644 --- a/packages/lexical/src/LexicalUtils.ts +++ b/packages/lexical/src/LexicalUtils.ts @@ -9,6 +9,7 @@ import type { EditorThemeClasses, IntentionallyMarkedAsDirtyElement, + Klass, LexicalCommand, MutatedNodes, MutationListeners, @@ -26,7 +27,6 @@ import type { } from './LexicalSelection'; import type {RootNode} from './nodes/LexicalRootNode'; import type {TextFormatType, TextNode} from './nodes/LexicalTextNode'; -import type {Klass} from 'shared/types'; import {IS_APPLE, IS_IOS, IS_SAFARI} from 'shared/environment'; import getDOMSelection from 'shared/getDOMSelection'; diff --git a/packages/lexical/src/index.ts b/packages/lexical/src/index.ts index 1ec346710c2..bde377699da 100644 --- a/packages/lexical/src/index.ts +++ b/packages/lexical/src/index.ts @@ -11,6 +11,7 @@ export type { EditorConfig, EditorThemeClasses, IntentionallyMarkedAsDirtyElement, + Klass, LexicalCommand, LexicalEditor, NodeMutation, diff --git a/packages/shared/types.d.ts b/packages/shared/types.d.ts deleted file mode 100644 index 9b7aafd60c3..00000000000 --- a/packages/shared/types.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - */ - -import {LexicalNode} from 'lexical'; - -import {SerializedLexicalNode} from 'lexical'; - -export type Klass = { - new (...args: any[]): T; -} & Omit; diff --git a/tsconfig.json b/tsconfig.json index 79f1463d920..f2241642f95 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -179,8 +179,7 @@ "shared/invariant": ["./packages/shared/src/invariant.ts"], "shared/warnOnlyOnce": ["./packages/shared/src/warnOnlyOnce.ts"], "shared/environment": ["./packages/shared/src/environment.ts"], - "shared/useLayoutEffect": ["./packages/shared/src/useLayoutEffect.ts"], - "shared/types": ["./packages/shared/src/types.d.ts"] + "shared/useLayoutEffect": ["./packages/shared/src/useLayoutEffect.ts"] } }, "include": ["./libdefs", "./packages"],