feat(editor): reference dialog, reading tiles and finding filter in the history
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.
This commit is contained in:
1 parent
e2d020bd3d
commit
8031e0078f
28 files changed
+1072
-1512
No files matched your search
@@ -68,11 +68,35 @@ function sanitizeFinding(raw: unknown, forms: boolean): EditorView['finding'] {
|
||||
return { key, citations: sheet }
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference dialog of a view: over the References tab, or over the citations sheet
|
||||
* (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.
|
||||
*/
|
||||
function sanitizeReference(
|
||||
raw: unknown,
|
||||
finding: EditorView['finding'],
|
||||
tab: unknown,
|
||||
): EditorView['reference'] {
|
||||
if (!isRecord(raw)) return null
|
||||
const sheet = !!finding && 'key' in finding && finding.citations
|
||||
if (raw.create === true) return tab === 'references' ? { create: true } : null
|
||||
const id = raw.edit
|
||||
if (typeof id !== 'string' || id === '') return null
|
||||
return tab === 'references' || sheet ? { edit: id } : null
|
||||
}
|
||||
|
||||
/** The finding the References tab is filtered by: a finding 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
|
||||
}
|
||||
|
||||
/**
|
||||
* A view read back from a history entry, or null when it is no view. The finding layer
|
||||
* must name a well-formed key and sit on the Constats tab; whether the element still
|
||||
* exists is the dialog's own gone rule. `forms` false drops the creation form (a reload
|
||||
* never reopens a form). The reference layer and the filter stay null until they exist.
|
||||
* exists is the dialog's own gone rule. `forms` false drops the forms (a creation, the
|
||||
* reference dialog): a reload never reopens a form.
|
||||
*/
|
||||
export function sanitizeView(raw: unknown, forms = true): EditorView | null {
|
||||
if (!isRecord(raw)) return null
|
||||
@@ -80,12 +104,15 @@ export function sanitizeView(raw: unknown, forms = true): EditorView | null {
|
||||
const known = ANNOTATION_SECTIONS.includes(raw.section as AnnotationSection)
|
||||
const finding =
|
||||
raw.tab === 'findings' ? sanitizeFinding(raw.finding, forms) : null
|
||||
const reference = forms
|
||||
? sanitizeReference(raw.reference, finding, raw.tab)
|
||||
: null
|
||||
return {
|
||||
tab: raw.tab as EditorTabId,
|
||||
section: known ? (raw.section as AnnotationSection) : 'drawing',
|
||||
finding,
|
||||
reference: null,
|
||||
referenceFilter: null,
|
||||
reference,
|
||||
referenceFilter: sanitizeFilter(raw.referenceFilter, raw.tab),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,19 +174,30 @@ 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). */
|
||||
export function showsFinding(view: EditorView, key: ElementKey): boolean {
|
||||
const { finding } = view
|
||||
const shown = finding && 'key' in finding ? finding.key : null
|
||||
return shown !== null && JSON.stringify(shown) === JSON.stringify(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* A user move to `view`. A layer taken away, or a section left for its drawing ("Retour
|
||||
* au dessin"), goes back when the entry holds the view the move lands on (the entry that
|
||||
* opened it), else it replaces; a layer, tab or section added pushes, unless the move
|
||||
* asked for a replace.
|
||||
* asked for a replace. `backTo` (« Revenir au constat ») goes back when the entry below
|
||||
* shows that finding.
|
||||
*/
|
||||
export function planWrite(
|
||||
top: HistoryEntry,
|
||||
view: EditorView,
|
||||
replace: boolean,
|
||||
backTo: ElementKey | null = null,
|
||||
): HistoryWrite {
|
||||
if (sameView(top.view, view)) return 'none'
|
||||
if (replace) return 'replace'
|
||||
// « Revenir au constat »: the entry below already shows that finding, a Back is the move.
|
||||
if (backTo && top.below && showsFinding(top.below, backTo)) return 'back'
|
||||
if (isRemoval(top.view, view)) {
|
||||
return top.below && sameView(top.below, view) ? 'back' : 'replace'
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user