'use client' import type { ContentEditorMode } from '@admin/utils/editor/content-editor-mode' import { Card, CardContent } from '@admin/components/ui/card' import { useContentEditor } from '@admin/hooks/content-editor/use-content-editor' import { useContentEditorTableAddControls } from '@admin/hooks/content-editor/use-content-editor-table-add-controls' import { cn } from '@admin/utils/shared/cn' import { EditorContext } from '@tiptap/react' import { ContentEditorFocusView } from './content-editor-focus-view' import { ContentEditorPreview } from './content-editor-preview' import { ContentEditorRichBody } from './content-editor-rich-body' import { ContentEditorStaticBody } from './content-editor-static-body' import { EditorToolbar } from './editor-toolbar' import { MainToolbarContent } from './main-toolbar-content' import { ModeToggleButton } from './mode-toggle-button' import { SourceMode } from './source-mode' export interface ContentEditorProps { value?: string onChange?: (value: string) => void placeholder?: string disabled?: boolean className?: string defaultMode: ContentEditorMode label?: string } // Desktop renders the editor card in the form. Phones get the preview card in its place and write // in `ContentEditorFocusView`, which takes over the ProseMirror view while it is open. Both render // before Tiptap has built the editor (it only exists after hydration): the card server-renders the // value (`ContentEditorStaticBody`) under the real toolbar (its controls disabled until there is an // editor) until the live editor replaces it, and the // preview reads the value directly, so the field never pops in after the rest of the form. export function ContentEditor({ value = '', onChange, placeholder, disabled = false, className, defaultMode, label = 'Content' }: ContentEditorProps) { const state = useContentEditor({ value, onChange, placeholder, disabled, defaultMode }) const { editor, handleModeChange, isFocusViewOpen, mode } = state const isSourceMode = mode === 'source' const tableAddControls = useContentEditorTableAddControls( !editor || isSourceMode || isFocusViewOpen ? null : editor ) return ( {!editor && !isSourceMode ? ( <> ) : !editor || isFocusViewOpen ? null : isSourceMode ? ( } className="max-h-none min-h-0 flex-1 resize-none border-0" /> ) : ( <> )} {editor && isFocusViewOpen ? ( ) : null} ) }