R2F-5 and R2F-6: the reference dialog is a view layer above the References tab or the citations sheet (local draft, one command per changed save, creation entry becomes the reference's own). Tiles only read. « Tout afficher » filters the library by the finding, « Revenir au constat » pops or pushes. Inline tile edit, draft tile and their guards removed.
101 lines
3.9 KiB
TypeScript
101 lines
3.9 KiB
TypeScript
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]
|
|
|
|
/** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */
|
|
const SHOWN: Record<TabTier, readonly EditorTabId[]> = {
|
|
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'
|
|
}
|
|
|
|
/**
|
|
* 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'
|