diff --git a/packages/lexical-utils/src/index.ts b/packages/lexical-utils/src/index.ts index 2c2e3fa9c45..82e195a435a 100644 --- a/packages/lexical-utils/src/index.ts +++ b/packages/lexical-utils/src/index.ts @@ -23,13 +23,15 @@ import { DEPRECATED_$isGridSelection, EditorState, ElementNode, + isHTMLAnchorElement, + isHTMLElement, Klass, LexicalEditor, LexicalNode, } from 'lexical'; import invariant from 'shared/invariant'; -export {$splitNode}; +export {$splitNode, isHTMLAnchorElement, isHTMLElement}; export type DFSNode = Readonly<{ depth: number; @@ -495,23 +497,6 @@ export function $wrapNodeInElement( return elementNode; } -/** - * @param x - The element being tested - * @returns Returns true if x is an HTML anchor tag, false otherwise - */ -export function isHTMLAnchorElement(x: Node): x is HTMLAnchorElement { - return isHTMLElement(x) && x.tagName === 'A'; -} - -/** - * @param x - The element being testing - * @returns Returns true if x is an HTML element, false otherwise. - */ -export function isHTMLElement(x: Node | EventTarget): x is HTMLElement { - // @ts-ignore-next-line - strict check on nodeType here should filter out non-Element EventTarget implementors - return x.nodeType === 1; -} - // eslint-disable-next-line @typescript-eslint/no-explicit-any type ObjectKlass = new (...args: any[]) => T; diff --git a/packages/lexical/src/LexicalUtils.ts b/packages/lexical/src/LexicalUtils.ts index 2168aff95b1..10e24a67461 100644 --- a/packages/lexical/src/LexicalUtils.ts +++ b/packages/lexical/src/LexicalUtils.ts @@ -1573,3 +1573,20 @@ export function $getChildrenRecursively(node: LexicalNode): Array { } return nodes; } + +/** + * @param x - The element being tested + * @returns Returns true if x is an HTML anchor tag, false otherwise + */ +export function isHTMLAnchorElement(x: Node): x is HTMLAnchorElement { + return isHTMLElement(x) && x.tagName === 'A'; +} + +/** + * @param x - The element being testing + * @returns Returns true if x is an HTML element, false otherwise. + */ +export function isHTMLElement(x: Node | EventTarget): x is HTMLElement { + // @ts-ignore-next-line - strict check on nodeType here should filter out non-Element EventTarget implementors + return x.nodeType === 1; +} diff --git a/packages/lexical/src/index.ts b/packages/lexical/src/index.ts index 2aa8b332044..9af9c332487 100644 --- a/packages/lexical/src/index.ts +++ b/packages/lexical/src/index.ts @@ -155,6 +155,8 @@ export { $setSelection, $splitNode, getNearestEditorFromDOMNode, + isHTMLAnchorElement, + isHTMLElement, isSelectionCapturedInDecoratorInput, isSelectionWithinEditor, } from './LexicalUtils'; diff --git a/packages/lexical/src/nodes/LexicalParagraphNode.ts b/packages/lexical/src/nodes/LexicalParagraphNode.ts index f526bb3e76c..d6dea905ed5 100644 --- a/packages/lexical/src/nodes/LexicalParagraphNode.ts +++ b/packages/lexical/src/nodes/LexicalParagraphNode.ts @@ -19,9 +19,11 @@ import type { } from './LexicalElementNode'; import type {RangeSelection} from 'lexical'; -import {isHTMLElement} from '@lexical/utils'; - -import {$applyNodeReplacement, getCachedClassNameArray} from '../LexicalUtils'; +import { + $applyNodeReplacement, + getCachedClassNameArray, + isHTMLElement, +} from '../LexicalUtils'; import {ElementNode} from './LexicalElementNode'; import {$isTextNode} from './LexicalTextNode'; diff --git a/packages/lexical/src/nodes/LexicalTextNode.ts b/packages/lexical/src/nodes/LexicalTextNode.ts index ffe57603e3d..1fc4a6cdac4 100644 --- a/packages/lexical/src/nodes/LexicalTextNode.ts +++ b/packages/lexical/src/nodes/LexicalTextNode.ts @@ -25,7 +25,6 @@ import type { RangeSelection, } from '../LexicalSelection'; -import {isHTMLElement} from '@lexical/utils'; import {IS_FIREFOX} from 'shared/environment'; import invariant from 'shared/invariant'; @@ -65,6 +64,7 @@ import { $setCompositionKey, getCachedClassNameArray, internalMarkSiblingsAsDirty, + isHTMLElement, toggleTextFormatType, } from '../LexicalUtils'; import {$createLineBreakNode} from './LexicalLineBreakNode';