Files
faunosteo/apps/app/src/components/editor/EditorWorkspace.tsx
T
bchanot 6689827a8d feat(editor): kept-mounted tabs, sections and references panel
Each visited tab, Annotations section and the references panel stay
mounted in a KeptPlace (hidden, nested visibility). Composed canvases
detach while hidden. One JSON.parse per document text. Focus requests
reach only their owning place.

Rewritten assertions (R-24):
- editor-route.test.tsx:127: annotations testid toBeNull -> not.toBeVisible
- editor-sections.test.tsx: place('annotations.drawing') toBeNull -> not.toBeVisible
- editor-journey.spec.ts:311: page-wide getByLabel('Nom (FR)') -> scoped to place 'general'
- editor-tabs-lists.test.tsx: ReferencesPanel `open` prop dropped (the wrapper hides it)
- editor-annotations-tab, editor-focus-request, editor-sections tests: props gain `visited`
No assertion removed.
2026-11-06 20:50:40 +01:00

113 lines
3.9 KiB
TypeScript

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 (
<Notice tone="error">
{saveFailureMessage(t, failure, { unsaved, copyWritten })}
</Notice>
)
}
/**
* 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 (
<div className="space-y-4">
<DraftHeader
sheet={sheet}
mode={mode}
referencesOpen={state.references.open}
onToggleReferences={toggleReferences}
/>
<ModeNotice mode={mode} sheet={sheet} />
<SaveFailureNotice />
<RecoveryNotice />
<CopyIssueNotice />
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
<FocusConsumedContext value={nav.consumed}>
<AnnounceContext value={nav.announce}>
{state.referencesMounted && (
<KeptPlace name="references" visible={state.references.open}>
<ReferencesPanel
readOnly={readOnly}
focus={ownedBy(state.focus, 'references')}
onClose={nav.closeReferences}
/>
</KeptPlace>
)}
<EditorTabBody
tab={state.tab}
visited={state.visitedTabs}
readOnly={readOnly}
navigate={nav.navigate}
focus={state.focus}
reloadSheet={reloadSheet}
annotations={{
section: state.section,
visited: state.visitedSections,
onOpenSection: nav.openSection,
onBack: nav.backToDrawing,
}}
/>
</AnnounceContext>
</FocusConsumedContext>
<p aria-live="polite" className="sr-only">
{nav.live}
</p>
<ConflictDialog />
</div>
)
}