import React from 'react'; import { type RootKey, withMountedPresentation } from '../../facade'; import { failInvariant } from '../../internal/failInvariant'; import { getCompiledPlatePlugin, getPlateRuntime, } from '../../internal/plugin/compilePlateModel'; import { getPlateDecorationSources } from '../../internal/plugin/getPlateDecorationSources'; import { getPlateEditorInstanceKey } from '../internal/getPlateEditorInstanceKey'; import { PlateMountedView, usePlateModel } from '../internal/plate-context'; import { EditorRoot, useEditorContext } from '../internal/plite-components'; import { usePlateModelRevision } from '../internal/usePlateModelRevision'; /** * Plite runtime with Plate plugins. * * - Change callbacks * - `slots.wrapRoot` */ export function PlateRoot({ children, editableRef: providedEditableRef, readOnly, root, }: { children: React.ReactNode; editableRef?: React.RefObject; readOnly?: boolean; root?: RootKey; }) { const emptyEditableRef = React.useRef(null); const editableRef = providedEditableRef ?? emptyEditableRef; const { editor, readOnly: modelReadOnly } = usePlateModel(); const rootView = useEditorContext(); const surfaceEditor = React.useMemo( () => withMountedPresentation(editor, rootView), [editor, rootView] ); const modelRevision = usePlateModelRevision(editor); const decorations = React.useMemo(() => { void modelRevision; return getPlateDecorationSources(editor); }, [editor, modelRevision]); let rootContent = children; getPlateRuntime(editor).pluginCache.slots.wrapRoot.forEach((name) => { const plugin = getCompiledPlatePlugin(editor, name) ?? failInvariant('Expected value to be defined'); const WrapRoot = plugin.slots.wrapRoot ?? failInvariant('Expected value to be defined'); rootContent = {rootContent}; }); return ( {rootContent} ); }