import type { PreviewState } from '@faunosteo/core-wasm/types' import type { EditorTarget, FocusRequest } from './navigation' import { unmeasuredViews } from './issues' import type { TabTier } from './useViewport' export const EDITOR_TABS = [ 'general', 'annotations', 'findings', 'verification', ] as const export type EditorTabId = (typeof EDITOR_TABS)[number] /** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */ const SHOWN: Record = { wide: EDITOR_TABS, medium: EDITOR_TABS, small: ['annotations', 'verification'], } export function tabsFor(tier: TabTier): { shown: readonly EditorTabId[] more: readonly EditorTabId[] } { const shown = SHOWN[tier] return { shown, more: EDITOR_TABS.filter((tab) => !shown.includes(tab)) } } /** * The tab a version opens on: Annotations once a view can be annotated, Général while * there is nothing to annotate yet. A tier that does not list Général keeps Annotations. */ export function initialTab(state: PreviewState, tier: TabTier): EditorTabId { const unmeasured = unmeasuredViews(state) const measurable = state.document.views.some((v) => !unmeasured.has(v.id)) const wanted = measurable ? 'annotations' : 'general' return SHOWN[tier].includes(wanted) ? wanted : 'annotations' } /** Props of every place (tab body, Annotations section, references panel). */ export interface EditorPlaceProps { /** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */ readOnly: boolean /** « Aller à … » and any link between places; `opener` takes the focus back on return. */ navigate: (target: EditorTarget, opener?: HTMLElement | null) => void /** « Aller à … » with an element: the place seeds its own selection from it once. */ focus?: FocusRequest /** Reads the sheet's overview again (after a submission: the round freezes the draft). */ reloadSheet: () => void } export const tabDomId = (tab: EditorTabId) => `editor-tab-${tab}` export const panelDomId = (tab: EditorTabId) => `editor-panel-${tab}` /** The « Plus » disclosure button, focused when the active tab sits under it. */ export const MORE_BUTTON_ID = 'editor-tabs-more-button' /** The header button that toggles the references panel. */ export const REFERENCES_BUTTON_ID = 'editor-references-button'