Skip to content

Commit

Permalink
reuse guid method
Browse files Browse the repository at this point in the history
  • Loading branch information
ivailop7 committed Mar 4, 2025
1 parent 7931e11 commit f0c883d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
8 changes: 1 addition & 7 deletions packages/lexical-playground/src/commenting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -37,13 +38,6 @@ export type Thread = {

export type Comments = Array<Thread | Comment>;

function createUID(): string {
return Math.random()
.toString(36)
.replace(/[^a-z]+/g, '')
.substring(0, 5);
}

export function createComment(
content: string,
author: string,
Expand Down
9 changes: 1 addition & 8 deletions packages/lexical-playground/src/nodes/PollNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type {JSX} from 'react';

import {makeStateWrapper} from '@lexical/utils';
import {createUID, makeStateWrapper} from '@lexical/utils';
import {
createState,
DecoratorNode,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -48,10 +48,7 @@ type SearchPromise = {
promise: Promise<null | string>;
};

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] {
Expand Down
1 change: 1 addition & 0 deletions packages/lexical-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export {default as positionNodeOnRange} from './positionNodeOnRange';
export {default as selectionAlwaysOnDisplay} from './selectionAlwaysOnDisplay';
export {
$splitNode,
createUID,
isBlockDomNode,
isHTMLAnchorElement,
isHTMLElement,
Expand Down
1 change: 1 addition & 0 deletions packages/lexical/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export {
$setCompositionKey,
$setSelection,
$splitNode,
createUID,
getDOMOwnerDocument,
getDOMSelection,
getDOMSelectionFromTarget,
Expand Down

0 comments on commit f0c883d

Please sign in to comment.