feat(editor): references dialog over the finding, view mode
A modal Dialog replaces the citations side sheet; families open it too (isCitable). The finding dialog shows only « Références citées » and « X références », also at zero; its edit form no longer carries reference_ids. A dirty form refusing « Aller à » or « Tout afficher » closes the clean references dialog first.
This commit is contained in:
1 parent
ff21b0315e
commit
abc781df52
29 files changed
+432
-858
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { FindingLayer, ReferenceLayer } from './tabs'
|
||||
import type { EditorNavigation } from './useEditorNavigation'
|
||||
|
||||
/** What Constats needs of the navigation for its dialog and the sheet over it. */
|
||||
/** What Constats needs of the navigation for its dialog and the citations dialog over it. */
|
||||
export function findingLayerOf(nav: EditorNavigation): FindingLayer {
|
||||
return {
|
||||
view: nav.state.finding,
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { create } from 'zustand'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
|
||||
/** The citations an open edit form holds, for the side sheet opened from that form. */
|
||||
interface CitationDraft {
|
||||
key: ElementKey
|
||||
ids: readonly string[]
|
||||
}
|
||||
|
||||
interface CitationDraftStore {
|
||||
draft: CitationDraft | null
|
||||
publish: (draft: CitationDraft | null) => void
|
||||
}
|
||||
|
||||
// shortcut: module-level store because the citations sheet is a sibling of the finding
|
||||
// dialog, so no React context reaches both. It holds one draft at a time (one edit form
|
||||
// is open at once). Upgrade path: a provider above the dialog and the sheet.
|
||||
export const useCitationDraft = create<CitationDraftStore>((set) => ({
|
||||
draft: null,
|
||||
publish: (draft) => set({ draft }),
|
||||
}))
|
||||
|
||||
/** The ids the sheet of `key` lists instead of the document's, null when none are staged. */
|
||||
export function draftIdsFor(
|
||||
draft: CitationDraft | null,
|
||||
key: ElementKey,
|
||||
): readonly string[] | null {
|
||||
if (!draft || JSON.stringify(draft.key) !== JSON.stringify(key)) return null
|
||||
return draft.ids
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import { MAX_FINDING_PATH } from '../findings/tree'
|
||||
import {
|
||||
ANNOTATION_SECTIONS,
|
||||
isFindingNode,
|
||||
isCitable,
|
||||
sameView,
|
||||
type AnnotationSection,
|
||||
type EditorView,
|
||||
@@ -67,18 +67,18 @@ function sanitizeCreation(raw: unknown): EditorView['finding'] {
|
||||
return { create: { kind, parent: key } }
|
||||
}
|
||||
|
||||
/** The finding layer of a view: its dialog, with its citations sheet over it. */
|
||||
/** The finding layer of a view: its dialog, with its citations dialog over it. */
|
||||
function sanitizeFinding(raw: unknown, forms: boolean): EditorView['finding'] {
|
||||
if (!isRecord(raw)) return null
|
||||
if ('create' in raw) return forms ? sanitizeCreation(raw) : null
|
||||
const key = sanitizeKey(raw.key)
|
||||
if (!key) return null
|
||||
const sheet = raw.citations === true && isFindingNode(key)
|
||||
return { key, citations: sheet }
|
||||
const citations = raw.citations === true && isCitable(key)
|
||||
return { key, citations }
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference dialog of a view: over the References tab, or over the citations sheet
|
||||
* The reference dialog of a view: over the References tab, or over the citations dialog
|
||||
* (the only other place that opens it). A form, so only read back where forms are kept;
|
||||
* whether the reference still exists is the dialog's own gone rule.
|
||||
*/
|
||||
@@ -88,17 +88,17 @@ function sanitizeReference(
|
||||
tab: unknown,
|
||||
): EditorView['reference'] {
|
||||
if (!isRecord(raw)) return null
|
||||
const sheet = !!finding && 'key' in finding && finding.citations
|
||||
const cited = !!finding && 'key' in finding && finding.citations
|
||||
if (raw.create === true) return tab === 'references' ? { create: true } : null
|
||||
const id = raw.edit
|
||||
if (!isId(id) || id === '') return null
|
||||
return tab === 'references' || sheet ? { edit: id } : null
|
||||
return tab === 'references' || cited ? { edit: id } : null
|
||||
}
|
||||
|
||||
/** The finding the References tab is filtered by: a finding node, on that tab only. */
|
||||
/** The element the References tab is filtered by: a family or a node, on that tab only. */
|
||||
function sanitizeFilter(raw: unknown, tab: unknown): ElementKey | null {
|
||||
const key = tab === 'references' ? sanitizeKey(raw) : null
|
||||
return key && isFindingNode(key) ? key : null
|
||||
return key && isCitable(key) ? key : null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,13 +166,13 @@ export function ownedEntry(
|
||||
export const entryState = (entry: HistoryEntry) => ({ [ENTRY_KEY]: entry })
|
||||
|
||||
/**
|
||||
* Layers over the place: the finding dialog and the citations sheet over it, the
|
||||
* Layers over the place: the finding dialog and the citations dialog over it, the
|
||||
* reference dialog, each count one.
|
||||
*/
|
||||
export function layerCount(view: EditorView): number {
|
||||
const { finding } = view
|
||||
const sheet = finding && 'key' in finding && finding.citations
|
||||
return (finding ? 1 : 0) + (sheet ? 1 : 0) + (view.reference ? 1 : 0)
|
||||
const cited = finding && 'key' in finding && finding.citations
|
||||
return (finding ? 1 : 0) + (cited ? 1 : 0) + (view.reference ? 1 : 0)
|
||||
}
|
||||
|
||||
/** An Annotations section other than the drawing is a step over it, like a layer. */
|
||||
@@ -192,7 +192,7 @@ function isRemoval(top: EditorView, view: EditorView): boolean {
|
||||
/** What a changed view asks of the history. */
|
||||
export type HistoryWrite = 'none' | 'push' | 'replace' | 'back'
|
||||
|
||||
/** True when `view` shows the finding `key` (its dialog, with or without the sheet). */
|
||||
/** True when `view` shows the finding `key` (its dialog, with or without its citations). */
|
||||
export function showsFinding(view: EditorView, key: ElementKey): boolean {
|
||||
const { finding } = view
|
||||
const shown = finding && 'key' in finding ? finding.key : null
|
||||
|
||||
@@ -211,14 +211,14 @@ function sameLayers(a: EditorView, b: EditorView): boolean {
|
||||
)
|
||||
}
|
||||
|
||||
/** The finding dialog a view shows, without its sheet: the sheet is no form. */
|
||||
/** The finding dialog a view shows, without its citations dialog: that one holds no form. */
|
||||
function dialogOf({ finding }: EditorView): unknown {
|
||||
return finding && 'key' in finding ? { key: finding.key } : finding
|
||||
}
|
||||
|
||||
/**
|
||||
* The layers holding a form that a POP from `from` to `to` takes away, top down: the
|
||||
* citations sheet alone is no such layer, so a Back that only closes it asks nothing.
|
||||
* citations dialog alone is no such layer, so a Back that only closes it asks nothing.
|
||||
*/
|
||||
function leavingLayers(from: EditorView, to: EditorView): LayerName[] {
|
||||
const same = (a: unknown, b: unknown) =>
|
||||
@@ -249,7 +249,7 @@ function refusal(
|
||||
return leaving.find((layer) => !nav.guards.ask(layer, false).allowed) ?? null
|
||||
}
|
||||
|
||||
/** The view under the finding dialog's sheet: what lies over it is clean, it goes. */
|
||||
/** The finding dialog alone: the clean citations and reference dialogs over it go. */
|
||||
function bareFinding(view: EditorView): EditorView {
|
||||
const { finding } = view
|
||||
const shown =
|
||||
@@ -278,7 +278,7 @@ function landOnForeign(ctx: PopContext): Landing | null {
|
||||
|
||||
/**
|
||||
* A POP refused (see `refusal`): the view stays, pushed again above the entry landed on.
|
||||
* When the finding dialog refused, the clean sheet and reference dialog over it close
|
||||
* When the finding dialog refused, the clean citations and reference dialogs over it close
|
||||
* first, so its question is not hidden under them. True when refused.
|
||||
*/
|
||||
function refusePop(ctx: PopContext, landed: HistoryEntry | null): boolean {
|
||||
|
||||
@@ -41,7 +41,7 @@ function leavesEditor(event: NavigateEventLike, path: string): boolean {
|
||||
interface Watch {
|
||||
guards: Guards
|
||||
/**
|
||||
* Closes the citations sheet and a reference dialog over it: they lie over the finding
|
||||
* Closes the citations dialog and a reference dialog over it: they lie over the finding
|
||||
* dialog, so its question would be hidden under them.
|
||||
*/
|
||||
clearAbove: () => void
|
||||
@@ -73,8 +73,8 @@ function jumpTo({ api, key, watch }: Jump, keep: () => void): void {
|
||||
|
||||
/**
|
||||
* `layer` asks « Abandonner les modifications ? » and holds the jump. Its « Abandonner »
|
||||
* closes it, with the citations sheet it may have been opened from (so the next question
|
||||
* is not hidden under the sheet), and the next dirty layer under it asks in turn; the
|
||||
* closes it, with the citations dialog it may have been opened from (so the next question
|
||||
* is not hidden under the citations dialog), and the next dirty layer under it asks in turn; the
|
||||
* last one lets the jump go. Any « Continuer la saisie » drops the jump. The finding
|
||||
* dialog asks once the layers over it are closed (they are clean: it is the top dirty one).
|
||||
*/
|
||||
@@ -113,7 +113,7 @@ type LeaveNav = Pick<
|
||||
'guards' | 'state' | 'closeCitations' | 'references'
|
||||
>
|
||||
|
||||
/** Closes the sheet and the reference dialog of the navigation `latest` holds, if open. */
|
||||
/** Closes the citations dialog and the reference dialog of the navigation `latest` holds, if open. */
|
||||
function clearerOf(latest: { current: LeaveNav }): () => void {
|
||||
return () => {
|
||||
const { state, closeCitations, references } = latest.current
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface FocusRequest {
|
||||
/**
|
||||
* What the browser history records of the editor (R2F-1): where the user is, never what
|
||||
* they typed. A layer (`finding`, `reference`) is a dialog over a place; `citations` is
|
||||
* the side sheet over the finding dialog; `reference` is the reference dialog above
|
||||
* the citations dialog over the finding dialog; `reference` is the reference dialog above
|
||||
* either; `referenceFilter` (only on the References tab) narrows the library to the
|
||||
* references a finding cites. The search text is a personal search: never part of a view.
|
||||
*/
|
||||
@@ -129,7 +129,7 @@ const DEFAULT_VIEW = {
|
||||
referenceFilter: null,
|
||||
} as const
|
||||
|
||||
/** The finding whose citations sheet the view shows, null when it shows none. */
|
||||
/** The finding whose citations dialog the view shows, null when it shows none. */
|
||||
export function citationsOfView(view: EditorView): ElementKey | null {
|
||||
const { finding } = view
|
||||
return finding && 'key' in finding && finding.citations ? finding.key : null
|
||||
@@ -191,20 +191,20 @@ function restoreView(
|
||||
}
|
||||
|
||||
/**
|
||||
* A finding node (kind `finding` below its family, path of two or more ids). A zone and a
|
||||
* family list their citations inline and have no panel.
|
||||
* An element that cites references: a family or a finding node (kind `finding`, a path of
|
||||
* one id or more). A zone cites none.
|
||||
*/
|
||||
export function isFindingNode(key: ElementKey): boolean {
|
||||
return key.kind === 'finding' && key.path.length > 1
|
||||
export function isCitable(key: ElementKey): boolean {
|
||||
return key.kind === 'finding' && key.path.length > 0
|
||||
}
|
||||
|
||||
/** Only a finding node has a citations sheet: any other key leaves the state as it is. */
|
||||
/** Only a citable element has a citations dialog: any other key leaves the state as it is. */
|
||||
function openCitations(state: NavigationState, citedBy: ElementKey) {
|
||||
const finding = { key: citedBy, citations: true }
|
||||
return isFindingNode(citedBy) ? shown({ ...state, finding }) : state
|
||||
return isCitable(citedBy) ? shown({ ...state, finding }) : state
|
||||
}
|
||||
|
||||
/** Closes the sheet only: the finding dialog under it stays. */
|
||||
/** Closes the citations dialog only: the finding dialog under it stays. */
|
||||
function closeCitations(state: NavigationState): NavigationState {
|
||||
const { finding } = state
|
||||
if (!finding || !('key' in finding)) return state
|
||||
@@ -217,7 +217,7 @@ function openFinding(state: NavigationState, key: ElementKey): NavigationState {
|
||||
return shown({ ...state, ...LEFT_REFERENCES, tab: 'findings', finding })
|
||||
}
|
||||
|
||||
/** The finding dialog closes with the reference dialog opened over its sheet. */
|
||||
/** The finding dialog closes with the citations and reference dialogs over it. */
|
||||
function closeFinding(state: NavigationState): NavigationState {
|
||||
const reference = state.finding ? null : state.reference
|
||||
return { ...state, finding: null, reference }
|
||||
@@ -262,7 +262,7 @@ function goTo(state: NavigationState, target: EditorTarget): NavigationState {
|
||||
|
||||
/**
|
||||
* « Tout afficher dans l'onglet Références »: the layers close, the library starts afresh
|
||||
* and lists what `filter` (the finding the sheet belongs to) cites.
|
||||
* and lists what `filter` (the finding the citations dialog belongs to) cites.
|
||||
*/
|
||||
function showAllReferences(
|
||||
state: NavigationState,
|
||||
@@ -286,7 +286,7 @@ function selectTab(state: NavigationState, tab: EditorTabId): NavigationState {
|
||||
return shown({ ...state, ...left, tab })
|
||||
}
|
||||
|
||||
/** The reference dialog of `id`, above the place (and the sheet) the view shows. */
|
||||
/** The reference dialog of `id`, above the place (and the citations dialog) the view shows. */
|
||||
function openReference(state: NavigationState, id: string): NavigationState {
|
||||
return shown({ ...state, reference: { edit: id } })
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ export interface EditorPlaceProps {
|
||||
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). */
|
||||
/** The finding dialog and the citations dialog over it (only Constats has them). */
|
||||
layer?: FindingLayer
|
||||
/** The reference dialog and the filter (only the References tab and the sheet use them). */
|
||||
/** The reference dialog and the filter (only the References tab and the citations dialog use them). */
|
||||
references?: ReferenceLayer
|
||||
/** Bumped by « Tout afficher »: the references library resets its search once per bump. */
|
||||
libraryReset?: number
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
import {
|
||||
citationsOfView,
|
||||
initialNavigation,
|
||||
isFindingNode,
|
||||
isCitable,
|
||||
navigationReducer,
|
||||
type AnnotationSection,
|
||||
type EditorTarget,
|
||||
@@ -125,20 +125,20 @@ export interface EditorNavigation {
|
||||
closeFinding: (forced?: boolean) => boolean
|
||||
/**
|
||||
* The finding layer becomes another view of itself, by replace (no Back entry): the new
|
||||
* element's dialog, or `null` for none (the reference dialog over its sheet goes too).
|
||||
* element's dialog, or `null` for none (the dialogs over it go too).
|
||||
* With `text`, a close the user did not ask for (the element vanished): forced, said
|
||||
* once the dialogs are closed.
|
||||
*/
|
||||
replaceFinding: (key: ElementKey | null, text?: string) => void
|
||||
/** Opens the citations sheet of a finding node; any other key is ignored. */
|
||||
/** Opens the citations dialog of a family or a node; any other key is ignored. */
|
||||
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
||||
/** A user close of the sheet; false when a tile in edit refused it. */
|
||||
/** A user close of the citations dialog. */
|
||||
closeCitations: () => boolean
|
||||
/** « X références », where the focus returns once the sheet is closed. */
|
||||
/** « X références », where the focus returns once the citations dialog is closed. */
|
||||
citationsTrigger: () => HTMLElement | null
|
||||
/**
|
||||
* « Tout afficher dans l'onglet Références »: layers closed, tab shown, library reset
|
||||
* and filtered by the finding the sheet belongs to.
|
||||
* and filtered by the finding the citations dialog belongs to.
|
||||
*/
|
||||
showAllReferences: (filter: ElementKey) => void
|
||||
/** The reference dialog and the References tab's filter. */
|
||||
@@ -278,7 +278,7 @@ function useMoveTrace() {
|
||||
}
|
||||
|
||||
interface Openers {
|
||||
/** The trigger that opened the citations sheet, and the finding it belongs to. */
|
||||
/** The trigger that opened the citations dialog, and the finding it belongs to. */
|
||||
citations: RefObject<HTMLElement | null>
|
||||
citedBy: RefObject<ElementKey | null>
|
||||
section: RefObject<HTMLElement | null>
|
||||
@@ -384,12 +384,12 @@ function useFindingClosing({ dispatch, announce, guards, mark }: LayerContext) {
|
||||
return { closeFinding, replaceFinding }
|
||||
}
|
||||
|
||||
/** The citations sheet over the finding dialog: opened from a finding node only. */
|
||||
function useSheetLayer(ctx: LayerContext, openers: Openers) {
|
||||
/** The citations dialog over the finding dialog: opened for a family or a node only. */
|
||||
function useCitationsLayer(ctx: LayerContext, openers: Openers) {
|
||||
const { dispatch, mark } = ctx
|
||||
const openCitations = useCallback(
|
||||
(citedBy: ElementKey, opener?: Opener) => {
|
||||
if (!isFindingNode(citedBy)) return
|
||||
if (!isCitable(citedBy)) return
|
||||
openers.citations.current = opener ?? null
|
||||
openers.citedBy.current = citedBy
|
||||
mark()
|
||||
@@ -405,24 +405,47 @@ function useSheetLayer(ctx: LayerContext, openers: Openers) {
|
||||
return { openCitations, closeCitations }
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks every layer, top down, before a move that leaves them all; true when none refused.
|
||||
* When the finding dialog is the top one to refuse, the clean dialogs over it close first
|
||||
* so its question is the one in view (as a refused Back, `bareFinding`).
|
||||
*/
|
||||
function useAskLeaving(ctx: LayerContext, state: NavigationState) {
|
||||
const { guards, dispatch, mark } = ctx
|
||||
const cited = citationsOfView(state) !== null
|
||||
const reference = state.reference !== null
|
||||
return useCallback((): boolean => {
|
||||
const refused = [...LAYERS]
|
||||
.reverse()
|
||||
.filter((layer) => !guards.ask(layer, false).allowed)
|
||||
if (refused[0] !== 'finding' || !(cited || reference)) {
|
||||
return refused.length === 0
|
||||
}
|
||||
mark()
|
||||
if (reference) dispatch({ type: 'close_reference' })
|
||||
if (cited) dispatch({ type: 'close_citations' })
|
||||
return false
|
||||
}, [guards, dispatch, mark, cited, reference])
|
||||
}
|
||||
|
||||
/** « Aller à » and « Tout afficher » leave every layer: a layer in edit may refuse. */
|
||||
function useLeavingMoves(go: Go, guards: Guards) {
|
||||
function useLeavingMoves(go: Go, askLeaving: () => boolean) {
|
||||
const t = useT()
|
||||
const moveText = useMoveText()
|
||||
const navigate = useCallback(
|
||||
(target: EditorTarget) => {
|
||||
if (!guards.askAll(false).allowed) return
|
||||
if (!askLeaving()) return
|
||||
go({ type: 'go_to', target }, 'go_to', moveText(target))
|
||||
},
|
||||
[go, guards, moveText],
|
||||
[go, askLeaving, moveText],
|
||||
)
|
||||
const showAllReferences = useCallback(
|
||||
(filter: ElementKey) => {
|
||||
if (!guards.askAll(false).allowed) return
|
||||
if (!askLeaving()) return
|
||||
const text = t('editor.tab.references')
|
||||
go({ type: 'show_all_references', filter }, 'show_all', text)
|
||||
},
|
||||
[go, guards, t],
|
||||
[go, askLeaving, t],
|
||||
)
|
||||
return { navigate, showAllReferences }
|
||||
}
|
||||
@@ -574,8 +597,8 @@ export function useEditorNavigation(
|
||||
selectTab: useTabSelect(base.dispatch, base.mark),
|
||||
...useSectionMoves(base.go, openers),
|
||||
...useFindingLayer(ctx),
|
||||
...useSheetLayer(ctx, openers),
|
||||
...useLeavingMoves(base.go, guards),
|
||||
...useCitationsLayer(ctx, openers),
|
||||
...useLeavingMoves(base.go, useAskLeaving(ctx, base.state)),
|
||||
references: useReferenceMoves(ctx, base.trace),
|
||||
citationsTrigger: useCallback(() => triggerOf(openers), [openers]),
|
||||
guards,
|
||||
|
||||
Reference in new issue
Block a user