import type { ElementKey, PreviewState } from '@faunosteo/core-wasm/types' import type { EditorTarget, EditorView, FocusRequest } from './navigation' import { unmeasuredViews } from './issues' import type { TabTier } from './useViewport' import type { Guards } from './useEditorNavigation' import type { AddedReference } from './useReferenceMoves' export const EDITOR_TABS = [ 'general', 'annotations', 'findings', 'references', 'verification', ] as const export type EditorTabId = (typeof EDITOR_TABS)[number] /** The tabs shown beside « Plus » at each width; the rest sit under « Plus », in tab order. */ const SHOWN: Record = { wide: EDITOR_TABS, medium: EDITOR_TABS, small: ['general', 'annotations'], } 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. Both are shown at every width. */ export function initialTab(state: PreviewState): EditorTabId { const unmeasured = unmeasuredViews(state) const measurable = state.document.views.some((v) => !unmeasured.has(v.id)) return measurable ? 'annotations' : 'general' } /** * What Constats needs of the navigation for its dialog (R2F-3): the layer the view * holds and the moves on it. A user close answers false when a form refused it. */ export interface FindingLayer { view: EditorView['finding'] guards: Guards open: (key: ElementKey) => void start: (kind: string, parent: ElementKey | null) => void close: (forced?: boolean) => boolean replace: (key: ElementKey | null, text?: string) => void openCitations: (citedBy: ElementKey, opener?: HTMLElement | null) => void announce: (text: string) => void } /** * What the References tab and the reference dialog need of the navigation (R2F-5, R2F-6): * the layer and the filter the view holds, and the moves on them. */ export interface ReferenceLayer { view: EditorView['reference'] /** The finding whose citations the library lists; null for the whole bibliography. */ filter: ElementKey | null guards: Guards open: (id: string, opener?: HTMLElement | null) => void start: (opener?: HTMLElement | null) => void close: (forced?: boolean) => boolean replace: (id: string | null, text?: string) => void created: (id: string) => void added: AddedReference | null opener: () => HTMLElement | null clearFilter: (text?: string) => void backToFinding: (key: ElementKey) => void announce: (text: string) => void } /** Props of every place (tab body, Annotations section). */ 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. */ navigate: (target: EditorTarget) => void /** « Aller à … » with an element: the place seeds its own selection from it once. */ focus?: FocusRequest /** The finding dialog and the citations sheet over it (only Constats has them). */ layer?: FindingLayer /** The reference dialog and the filter (only the References tab and the sheet use them). */ references?: ReferenceLayer /** Bumped by « Tout afficher »: the references library resets its search once per bump. */ libraryReset?: number /** 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'