diff --git a/packages/lexical-playground/src/commenting/index.ts b/packages/lexical-playground/src/commenting/index.ts index c37469ba5e8..71c70220cee 100644 --- a/packages/lexical-playground/src/commenting/index.ts +++ b/packages/lexical-playground/src/commenting/index.ts @@ -8,6 +8,7 @@ import type {LexicalEditor} from 'lexical'; +import {createUID} from '@lexical/utils'; import {Provider, TOGGLE_CONNECT_COMMAND} from '@lexical/yjs'; import {COMMAND_PRIORITY_LOW} from 'lexical'; import {useEffect, useState} from 'react'; @@ -37,13 +38,6 @@ export type Thread = { export type Comments = Array; -function createUID(): string { - return Math.random() - .toString(36) - .replace(/[^a-z]+/g, '') - .substring(0, 5); -} - export function createComment( content: string, author: string, diff --git a/packages/lexical-playground/src/nodes/PollNode.tsx b/packages/lexical-playground/src/nodes/PollNode.tsx index 3e066b4f5f8..5a7d033cb25 100644 --- a/packages/lexical-playground/src/nodes/PollNode.tsx +++ b/packages/lexical-playground/src/nodes/PollNode.tsx @@ -8,7 +8,7 @@ import type {JSX} from 'react'; -import {makeStateWrapper} from '@lexical/utils'; +import {createUID, makeStateWrapper} from '@lexical/utils'; import { createState, DecoratorNode, @@ -31,13 +31,6 @@ export type Option = Readonly<{ const PollComponent = React.lazy(() => import('./PollComponent')); -function createUID(): string { - return Math.random() - .toString(36) - .replace(/[^a-z]+/g, '') - .substring(0, 5); -} - export function createPollOption(text = ''): Option { return { text, diff --git a/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx b/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx index c2f94339fbb..02610763ebe 100644 --- a/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/AutocompletePlugin/index.tsx @@ -11,7 +11,7 @@ import type {JSX} from 'react'; import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; import {$isAtNodeEnd} from '@lexical/selection'; -import {mergeRegister} from '@lexical/utils'; +import {createUID, mergeRegister} from '@lexical/utils'; import { $addUpdateTag, $createTextNode, @@ -48,10 +48,7 @@ type SearchPromise = { promise: Promise; }; -export const uuid = Math.random() - .toString(36) - .replace(/[^a-z]+/g, '') - .substring(0, 5); +export const uuid = createUID(); // TODO lookup should be custom function $search(selection: null | BaseSelection): [boolean, string] { diff --git a/packages/lexical-utils/src/index.ts b/packages/lexical-utils/src/index.ts index b90176435a1..12191b0354f 100644 --- a/packages/lexical-utils/src/index.ts +++ b/packages/lexical-utils/src/index.ts @@ -65,6 +65,7 @@ export {default as positionNodeOnRange} from './positionNodeOnRange'; export {default as selectionAlwaysOnDisplay} from './selectionAlwaysOnDisplay'; export { $splitNode, + createUID, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, diff --git a/packages/lexical/src/index.ts b/packages/lexical/src/index.ts index 21a6edc2ff7..a31718432e4 100644 --- a/packages/lexical/src/index.ts +++ b/packages/lexical/src/index.ts @@ -239,6 +239,7 @@ export { $setCompositionKey, $setSelection, $splitNode, + createUID, getDOMOwnerDocument, getDOMSelection, getDOMSelectionFromTarget,