diff --git a/packages/core/src/lib/utils/pipeInjectNodeProps.tsx b/packages/core/src/lib/utils/pipeInjectNodeProps.tsx index 98df8bcd80..dedaa46466 100644 --- a/packages/core/src/lib/utils/pipeInjectNodeProps.tsx +++ b/packages/core/src/lib/utils/pipeInjectNodeProps.tsx @@ -1,3 +1,6 @@ +import type { TElement, TText } from '@udecode/slate'; +import type { Path } from 'slate'; + import clsx from 'clsx'; import type { SlateEditor } from '../editor'; @@ -5,10 +8,19 @@ import type { SlateEditor } from '../editor'; import { pluginInjectNodeProps } from './pluginInjectNodeProps'; /** Inject plugin props, editor. */ -export const pipeInjectNodeProps = (editor: SlateEditor, nodeProps: any) => { +export const pipeInjectNodeProps = ( + editor: SlateEditor, + nodeProps: any, + getElementPath: (node: TElement | TText) => Path +) => { editor.pluginList.forEach((plugin) => { if (plugin.inject.nodeProps) { - const newProps = pluginInjectNodeProps(editor, plugin, nodeProps); + const newProps = pluginInjectNodeProps( + editor, + plugin, + nodeProps, + getElementPath + ); if (!newProps) return; diff --git a/packages/core/src/lib/utils/pluginInjectNodeProps.ts b/packages/core/src/lib/utils/pluginInjectNodeProps.ts index 06a41c6402..9ff1f0ca72 100644 --- a/packages/core/src/lib/utils/pluginInjectNodeProps.ts +++ b/packages/core/src/lib/utils/pluginInjectNodeProps.ts @@ -1,6 +1,7 @@ -import { findNode } from '@udecode/slate'; -import { findNodePath } from '@udecode/slate-react'; -import { IS_SERVER, isDefined } from '@udecode/utils'; +import type { TElement, TText } from '@udecode/slate'; +import type { Path } from 'slate'; + +import { isDefined } from '@udecode/utils'; import type { SlateEditor } from '../../lib/editor'; import type { @@ -25,7 +26,8 @@ import { getInjectMatch } from '../../lib/utils/getInjectMatch'; export const pluginInjectNodeProps = ( editor: SlateEditor, plugin: EditorPlugin, - nodeProps: GetInjectNodePropsOptions + nodeProps: GetInjectNodePropsOptions, + getElementPath: (node: TElement | TText) => Path ): GetInjectNodePropsReturnType | undefined => { const { key, @@ -54,13 +56,7 @@ export const pluginInjectNodeProps = ( const injectMatch = getInjectMatch(editor, plugin); - const elementPath = findNode(editor, { match: (n) => n === node })?.[1]; - - if (IS_SERVER) { - if (!elementPath || !injectMatch(node, elementPath)) return; - } else { - if (!injectMatch(node, findNodePath(editor, node)!)) return; - } + if (!injectMatch(node, getElementPath(node))) return; const queryResult = query?.({ ...injectNodeProps, diff --git a/packages/core/src/react/utils/getRenderNodeProps.ts b/packages/core/src/react/utils/getRenderNodeProps.ts index 79beab171f..dc2a9246db 100644 --- a/packages/core/src/react/utils/getRenderNodeProps.ts +++ b/packages/core/src/react/utils/getRenderNodeProps.ts @@ -1,5 +1,6 @@ import type { AnyObject } from '@udecode/utils'; +import { findNodePath } from '@udecode/slate-react'; import { clsx } from 'clsx'; import type { PlateEditor } from '../editor'; @@ -37,7 +38,11 @@ export const getRenderNodeProps = ({ className: clsx(getSlateClass(plugin?.node.type), className), }; - nodeProps = pipeInjectNodeProps(editor, nodeProps) as PlateRenderNodeProps; + nodeProps = pipeInjectNodeProps( + editor, + nodeProps, + (node) => findNodePath(editor, node)! + ) as PlateRenderNodeProps; if (nodeProps.style && Object.keys(nodeProps.style).length === 0) { delete nodeProps.style;