'use client' import * as React from 'react' import type { useContentEditor } from '@admin/hooks/content-editor/use-content-editor' import type { Editor } from '@tiptap/react' import { Button } from '@admin/components/ui/button' import { useContentEditorBlockMode } from '@admin/hooks/content-editor/use-content-editor-block-mode' import { useContentEditorFocusBlock } from '@admin/hooks/content-editor/use-content-editor-focus-block' import { useContentEditorFocusViewport } from '@admin/hooks/content-editor/use-content-editor-focus-viewport' import { useContentEditorTableAddControls } from '@admin/hooks/content-editor/use-content-editor-table-add-controls' import { useContentEditorTextStyle } from '@admin/hooks/content-editor/use-content-editor-text-style' import { ContentEditorBlockDock } from './content-editor-block-dock' import { ContentEditorBlockHandle } from './content-editor-block-handle' import { ContentEditorFocusToolbar } from './content-editor-focus-toolbar' import { ContentEditorLinkSheet } from './content-editor-link-sheet' import { ContentEditorModeSwitch } from './content-editor-mode-switch' import { ContentEditorMoreSheet } from './content-editor-more-sheet' import { ContentEditorRichBody } from './content-editor-rich-body' import { ContentEditorTextStyleSheet } from './content-editor-text-style-sheet' import { SourceMode } from './source-mode' // The phone writing screen (Paper `Posts / New ยท Writing / Mobile` and its `Block`, `Text style` // and `Markdown` states), designed for the keyboard always being open: its card runs from under the // page header to the bottom of the screen, behind the keyboard, so Safari's translucent bars never // show the form through, and bottom padding (`useVisualViewportInset`, since iOS Safari does not // shrink the layout viewport for the keyboard) lifts its content to the keyboard's top edge; when iOS // pans the visible area, the view, `Done` and the header follow it (`useContentEditorFocusViewport`). It // stacks over the form's fixed phone action bar. `Done` sits in the // header's right corner, a typed `/` opens the text-style sheet instead of the slash popup (picking // a type or dismissing the sheet takes the `/` back), the text always sits 12px in with the block handle in a 40px right // gutter (so focusing never reflows a line), the focus bar holds the full-width `Rich text / Markdown` switch, and the // dock right above the keyboard shows the formatting keys, or the selected block's actions after a // tap on its handle. export function ContentEditorFocusView({ editor, state, placeholder, disabled }: { editor: Editor state: ReturnType placeholder?: string disabled: boolean }) { const [isTextStyleOpen, setIsTextStyleOpen] = React.useState(false) const [focusSheet, setFocusSheet] = React.useState<'link' | 'more' | null>(null) const isSourceMode = state.mode === 'source' const tableAddControls = useContentEditorTableAddControls(isSourceMode ? null : editor) const { block, containerRef, isFocused } = useContentEditorFocusBlock( isSourceMode ? null : editor ) const { activeStyle, applyStyle } = useContentEditorTextStyle(editor) const { isBlockMode, enterBlockMode, exitBlockMode } = useContentEditorBlockMode( isSourceMode ? null : editor ) const viewportInset = useContentEditorFocusViewport() const showBlockHandle = block !== null && (isFocused || isTextStyleOpen || isBlockMode) return (
{isSourceMode ? ( ) : ( <> {showBlockHandle && block ? ( ) : null} {isBlockMode && block ? ( setIsTextStyleOpen(true)} onClose={exitBlockMode} /> ) : ( setIsTextStyleOpen(true)} onLinkOpen={() => setFocusSheet('link')} onMoreOpen={() => setFocusSheet('more')} /> )} {focusSheet === 'link' ? ( setFocusSheet(null)} /> ) : null} {focusSheet === 'more' ? ( setFocusSheet(null)} /> ) : null} {isTextStyleOpen || state.slashMenu !== null ? ( { setIsTextStyleOpen(false) if (state.slashMenu) state.dismissSlashMenu() }} activeStyle={activeStyle} onStyleSelect={(style) => { if (state.slashMenu) state.dismissSlashMenu() applyStyle(style) }} /> ) : null} )}
) }