import type { OfficialSheetAdmin } from '@faunosteo/supabase' import Notice from '@/components/ui/Notice' import { AnnounceContext, FocusConsumedContext, ownedBy, } from '@/editor/focusRequest' import { saveFailureMessage } from '@/editor/messages' import type { EditorMode } from '@/editor/mode' import { useEditorStore } from '@/editor/state/editorStore' import { initialTab } from '@/editor/tabs' import { useEditorNavigation } from '@/editor/useEditorNavigation' import type { TabTier } from '@/editor/useViewport' import { useT } from '@/i18n/useT' import ConflictDialog from './ConflictDialog' import CopyIssueNotice from './CopyIssueNotice' import DraftHeader from './DraftHeader' import EditorTabBody from './EditorTabBody' import EditorTabs from './EditorTabs' import KeptPlace from './KeptPlace' import ModeNotice from './ModeNotice' import RecoveryNotice from './RecoveryNotice' import ReferencesPanel from './references/ReferencesPanel' interface Props { sheet: OfficialSheetAdmin mode: EditorMode /** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */ readOnly: boolean tier: TabTier reloadSheet: () => void } /** A refused save under the header, phrased from the closed kind and the copy's real flag. */ function SaveFailureNotice() { const t = useT() const failure = useEditorStore((s) => s.saveFailure) const unsaved = useEditorStore((s) => s.unsaved) const copyWritten = useEditorStore((s) => s.copyWritten) const conflictOpen = useEditorStore((s) => s.conflict !== null) if (failure === null || (failure === 'draft_conflict' && conflictOpen)) return null return ( {saveFailureMessage(t, failure, { unsaved, copyWritten })} ) } /** * The draft page once the version is ready: header, notices, tab row, the references * panel and the shown place. Owns the navigation state, so the first tab is known at * mount (`initialTab`) and later edits never move the user off their tab. */ export default function EditorWorkspace(props: Props) { const { sheet, mode, readOnly, tier, reloadSheet } = props const previewState = useEditorStore((s) => s.previewState) const nav = useEditorNavigation( previewState ? initialTab(previewState, tier) : 'annotations', ) const { state } = nav const toggleReferences = (opener: HTMLElement) => state.references.open ? nav.closeReferences() : nav.openReferences(null, opener) return (
{state.referencesMounted && ( )}

{nav.live}

) }