diff --git a/packages/richtext-lexical/src/features/blocks/client/nodes/BlocksNode.tsx b/packages/richtext-lexical/src/features/blocks/client/nodes/BlocksNode.tsx index 3cb2abc1e9b..41fdf44b81f 100644 --- a/packages/richtext-lexical/src/features/blocks/client/nodes/BlocksNode.tsx +++ b/packages/richtext-lexical/src/features/blocks/client/nodes/BlocksNode.tsx @@ -1,7 +1,11 @@ 'use client' -import type { EditorConfig, LexicalEditor, LexicalNode } from 'lexical' - import ObjectID from 'bson-objectid' +import { + $applyNodeReplacement, + type EditorConfig, + type LexicalEditor, + type LexicalNode, +} from 'lexical' import React, { type JSX } from 'react' import type { BlockFieldsOptionalID, SerializedBlockNode } from '../../server/nodes/BlocksNode.js' @@ -50,12 +54,14 @@ export class BlockNode extends ServerBlockNode { } export function $createBlockNode(fields: BlockFieldsOptionalID): BlockNode { - return new BlockNode({ - fields: { - ...fields, - id: fields?.id || new ObjectID.default().toHexString(), - }, - }) + return $applyNodeReplacement( + new BlockNode({ + fields: { + ...fields, + id: fields?.id || new ObjectID.default().toHexString(), + }, + }), + ) } export function $isBlockNode(node: BlockNode | LexicalNode | null | undefined): node is BlockNode { diff --git a/packages/richtext-lexical/src/features/blocks/client/nodes/InlineBlocksNode.tsx b/packages/richtext-lexical/src/features/blocks/client/nodes/InlineBlocksNode.tsx index 19836c188a0..f7f628d99d4 100644 --- a/packages/richtext-lexical/src/features/blocks/client/nodes/InlineBlocksNode.tsx +++ b/packages/richtext-lexical/src/features/blocks/client/nodes/InlineBlocksNode.tsx @@ -1,7 +1,11 @@ 'use client' -import type { EditorConfig, LexicalEditor, LexicalNode } from 'lexical' - import ObjectID from 'bson-objectid' +import { + $applyNodeReplacement, + type EditorConfig, + type LexicalEditor, + type LexicalNode, +} from 'lexical' import React, { type JSX } from 'react' import type { @@ -47,12 +51,14 @@ export class InlineBlockNode extends ServerInlineBlockNode { } export function $createInlineBlockNode(fields: Exclude): InlineBlockNode { - return new InlineBlockNode({ - fields: { - ...fields, - id: fields?.id || new ObjectID.default().toHexString(), - }, - }) + return $applyNodeReplacement( + new InlineBlockNode({ + fields: { + ...fields, + id: fields?.id || new ObjectID.default().toHexString(), + }, + }), + ) } export function $isInlineBlockNode( diff --git a/packages/richtext-lexical/src/features/blocks/server/nodes/BlocksNode.tsx b/packages/richtext-lexical/src/features/blocks/server/nodes/BlocksNode.tsx index facc6446a7c..104431e10d8 100644 --- a/packages/richtext-lexical/src/features/blocks/server/nodes/BlocksNode.tsx +++ b/packages/richtext-lexical/src/features/blocks/server/nodes/BlocksNode.tsx @@ -1,18 +1,19 @@ import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js' -import type { - DOMConversionMap, - DOMExportOutput, - EditorConfig, - ElementFormatType, - LexicalEditor, - LexicalNode, - NodeKey, -} from 'lexical' import type { JsonObject } from 'payload' import type { JSX } from 'react' import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js' import ObjectID from 'bson-objectid' +import { + $applyNodeReplacement, + type DOMConversionMap, + type DOMExportOutput, + type EditorConfig, + type ElementFormatType, + type LexicalEditor, + type LexicalNode, + type NodeKey, +} from 'lexical' import type { StronglyTypedLeafNode } from '../../../../nodeTypes.js' @@ -134,12 +135,14 @@ export class ServerBlockNode extends DecoratorBlockNode { } export function $createServerBlockNode(fields: BlockFieldsOptionalID): ServerBlockNode { - return new ServerBlockNode({ - fields: { - ...fields, - id: fields?.id || new ObjectID.default().toHexString(), - }, - }) + return $applyNodeReplacement( + new ServerBlockNode({ + fields: { + ...fields, + id: fields?.id || new ObjectID.default().toHexString(), + }, + }), + ) } export function $isServerBlockNode( diff --git a/packages/richtext-lexical/src/features/blocks/server/nodes/InlineBlocksNode.tsx b/packages/richtext-lexical/src/features/blocks/server/nodes/InlineBlocksNode.tsx index 9351f2c7821..d50b3d1b649 100644 --- a/packages/richtext-lexical/src/features/blocks/server/nodes/InlineBlocksNode.tsx +++ b/packages/richtext-lexical/src/features/blocks/server/nodes/InlineBlocksNode.tsx @@ -12,7 +12,7 @@ import type React from 'react' import type { JSX } from 'react' import ObjectID from 'bson-objectid' -import { DecoratorNode } from 'lexical' +import { $applyNodeReplacement, DecoratorNode } from 'lexical' import type { StronglyTypedLeafNode } from '../../../../nodeTypes.js' @@ -131,12 +131,14 @@ export class ServerInlineBlockNode extends DecoratorNode, ): ServerInlineBlockNode { - return new ServerInlineBlockNode({ - fields: { - ...fields, - id: fields?.id || new ObjectID.default().toHexString(), - }, - }) + return $applyNodeReplacement( + new ServerInlineBlockNode({ + fields: { + ...fields, + id: fields?.id || new ObjectID.default().toHexString(), + }, + }), + ) } export function $isServerInlineBlockNode( diff --git a/packages/richtext-lexical/src/features/link/nodes/AutoLinkNode.ts b/packages/richtext-lexical/src/features/link/nodes/AutoLinkNode.ts index 788a0b6f44e..05fc40ce287 100644 --- a/packages/richtext-lexical/src/features/link/nodes/AutoLinkNode.ts +++ b/packages/richtext-lexical/src/features/link/nodes/AutoLinkNode.ts @@ -11,7 +11,7 @@ import { LinkNode } from './LinkNode.js' export class AutoLinkNode extends LinkNode { static override clone(node: AutoLinkNode): AutoLinkNode { - return new AutoLinkNode({ id: '', fields: node.__fields, key: node.__key }) + return new this({ id: '', fields: node.__fields, key: node.__key }) } static override getType(): string { diff --git a/packages/richtext-lexical/src/features/link/nodes/LinkNode.ts b/packages/richtext-lexical/src/features/link/nodes/LinkNode.ts index 28a0bc2f350..80cca82a486 100644 --- a/packages/richtext-lexical/src/features/link/nodes/LinkNode.ts +++ b/packages/richtext-lexical/src/features/link/nodes/LinkNode.ts @@ -51,7 +51,7 @@ export class LinkNode extends ElementNode { } static override clone(node: LinkNode): LinkNode { - return new LinkNode({ + return new this({ id: node.__id, fields: node.__fields, key: node.__key, diff --git a/packages/richtext-lexical/src/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.tsx b/packages/richtext-lexical/src/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.tsx index 5c91da20123..635fd502d85 100644 --- a/packages/richtext-lexical/src/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.tsx +++ b/packages/richtext-lexical/src/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.tsx @@ -2,7 +2,7 @@ import type { EditorConfig, LexicalNode, NodeKey, SerializedLexicalNode, Spread import type { JSX } from 'react' import { addClassNamesToElement } from '@lexical/utils' -import { DecoratorNode } from 'lexical' +import { $applyNodeReplacement, DecoratorNode } from 'lexical' import * as React from 'react' export type UnknownConvertedNodeData = { @@ -33,7 +33,7 @@ export class UnknownConvertedNode extends DecoratorNode { } static override clone(node: UnknownConvertedNode): UnknownConvertedNode { - return new UnknownConvertedNode({ + return new this({ data: node.__data, key: node.__key, }) @@ -90,9 +90,11 @@ export function $createUnknownConvertedNode({ }: { data: UnknownConvertedNodeData }): UnknownConvertedNode { - return new UnknownConvertedNode({ - data, - }) + return $applyNodeReplacement( + new UnknownConvertedNode({ + data, + }), + ) } export function $isUnknownConvertedNode( diff --git a/packages/richtext-lexical/src/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.tsx b/packages/richtext-lexical/src/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.tsx index 5c91da20123..635fd502d85 100644 --- a/packages/richtext-lexical/src/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.tsx +++ b/packages/richtext-lexical/src/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.tsx @@ -2,7 +2,7 @@ import type { EditorConfig, LexicalNode, NodeKey, SerializedLexicalNode, Spread import type { JSX } from 'react' import { addClassNamesToElement } from '@lexical/utils' -import { DecoratorNode } from 'lexical' +import { $applyNodeReplacement, DecoratorNode } from 'lexical' import * as React from 'react' export type UnknownConvertedNodeData = { @@ -33,7 +33,7 @@ export class UnknownConvertedNode extends DecoratorNode { } static override clone(node: UnknownConvertedNode): UnknownConvertedNode { - return new UnknownConvertedNode({ + return new this({ data: node.__data, key: node.__key, }) @@ -90,9 +90,11 @@ export function $createUnknownConvertedNode({ }: { data: UnknownConvertedNodeData }): UnknownConvertedNode { - return new UnknownConvertedNode({ - data, - }) + return $applyNodeReplacement( + new UnknownConvertedNode({ + data, + }), + ) } export function $isUnknownConvertedNode( diff --git a/packages/richtext-lexical/src/features/relationship/client/nodes/RelationshipNode.tsx b/packages/richtext-lexical/src/features/relationship/client/nodes/RelationshipNode.tsx index 3c2d7c65779..92f2a02ae9d 100644 --- a/packages/richtext-lexical/src/features/relationship/client/nodes/RelationshipNode.tsx +++ b/packages/richtext-lexical/src/features/relationship/client/nodes/RelationshipNode.tsx @@ -1,13 +1,14 @@ 'use client' -import type { - DOMConversionMap, - DOMConversionOutput, - EditorConfig, - LexicalEditor, - LexicalNode, -} from 'lexical' import type { JSX } from 'react' +import { + $applyNodeReplacement, + type DOMConversionMap, + type DOMConversionOutput, + type EditorConfig, + type LexicalEditor, + type LexicalNode, +} from 'lexical' import * as React from 'react' import type { @@ -94,9 +95,11 @@ export class RelationshipNode extends RelationshipServerNode { } export function $createRelationshipNode(data: RelationshipData): RelationshipNode { - return new RelationshipNode({ - data, - }) + return $applyNodeReplacement( + new RelationshipNode({ + data, + }), + ) } export function $isRelationshipNode( diff --git a/packages/richtext-lexical/src/features/relationship/server/nodes/RelationshipNode.tsx b/packages/richtext-lexical/src/features/relationship/server/nodes/RelationshipNode.tsx index 6370e6bfb85..a36586f0fa3 100644 --- a/packages/richtext-lexical/src/features/relationship/server/nodes/RelationshipNode.tsx +++ b/packages/richtext-lexical/src/features/relationship/server/nodes/RelationshipNode.tsx @@ -1,18 +1,19 @@ import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js' -import type { - DOMConversionMap, - DOMConversionOutput, - DOMExportOutput, - EditorConfig, - ElementFormatType, - LexicalEditor, - LexicalNode, - NodeKey, -} from 'lexical' import type { CollectionSlug, DataFromCollectionSlug } from 'payload' import type { JSX } from 'react' import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js' +import { + $applyNodeReplacement, + type DOMConversionMap, + type DOMConversionOutput, + type DOMExportOutput, + type EditorConfig, + type ElementFormatType, + type LexicalEditor, + type LexicalNode, + type NodeKey, +} from 'lexical' import type { StronglyTypedLeafNode } from '../../../../nodeTypes.js' @@ -144,9 +145,11 @@ export class RelationshipServerNode extends DecoratorBlockNode { } export function $createServerRelationshipNode(data: RelationshipData): RelationshipServerNode { - return new RelationshipServerNode({ - data, - }) + return $applyNodeReplacement( + new RelationshipServerNode({ + data, + }), + ) } export function $isServerRelationshipNode( diff --git a/packages/richtext-lexical/src/features/upload/client/plugin/index.tsx b/packages/richtext-lexical/src/features/upload/client/plugin/index.tsx index 5009a08e817..691473acafa 100644 --- a/packages/richtext-lexical/src/features/upload/client/plugin/index.tsx +++ b/packages/richtext-lexical/src/features/upload/client/plugin/index.tsx @@ -290,7 +290,7 @@ export const UploadPlugin: PluginComponent = ({ client if ($isRangeSelection(selection)) { for (const file of files) { - const pendingUploadNode = new UploadNode({ + const pendingUploadNode = $createUploadNode({ data: { pending: { formID: file.formID, @@ -363,7 +363,7 @@ export const UploadPlugin: PluginComponent = ({ client $setSelection(selection) for (const file of files) { - const pendingUploadNode = new UploadNode({ + const pendingUploadNode = $createUploadNode({ data: { pending: { formID: file.formID,