feat(editor): kept-mounted tabs, sections and references panel

Each visited tab, Annotations section and the references panel stay
mounted in a KeptPlace (hidden, nested visibility). Composed canvases
detach while hidden. One JSON.parse per document text. Focus requests
reach only their owning place.

Rewritten assertions (R-24):
- editor-route.test.tsx:127: annotations testid toBeNull -> not.toBeVisible
- editor-sections.test.tsx: place('annotations.drawing') toBeNull -> not.toBeVisible
- editor-journey.spec.ts:311: page-wide getByLabel('Nom (FR)') -> scoped to place 'general'
- editor-tabs-lists.test.tsx: ReferencesPanel `open` prop dropped (the wrapper hides it)
- editor-annotations-tab, editor-focus-request, editor-sections tests: props gain `visited`
No assertion removed.
This commit is contained in:
bchanot committed 2026-11-06 20:50:40 +01:00
1 parent ca184da4d9
commit 6689827a8d
18 files changed
+847 -81

No files matched your search

@@ -1,5 +1,6 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { buildView } from '@/components/catalogue/CatalogueCanvas'
import { usePlaceVisible } from '@/components/editor/KeptPlace'
import { coreRuntime } from '@/core/runtime'
import { useEditorStore } from '../state/editorStore'
@@ -28,11 +29,11 @@ function rootOf(viewId: string, svg: Element): RootAttributes {
}
}
/** What the canvas rebuilds on: the handle and its version counter. */
/** What the canvas rebuilds on: the handle, its version counter and its place shown. */
function useHandle() {
const preview = useEditorStore((s) => s.preview)
const version = useEditorStore((s) => s.handleVersion)
return { preview, version }
return { preview, version, visible: usePlaceVisible() }
}
/**
@@ -50,6 +51,8 @@ export function useCanvasBuild(viewId: string) {
useEffect(() => {
const element = host.current
if (!element || !handle.preview) return
// One composed copy of a view in the page: the ids repeat otherwise.
if (!handle.visible) return element.replaceChildren()
const result = buildView(handle.preview, viewId)
element.replaceChildren(...(result.ok ? [result.svg] : []))
setBuilt(
@@ -57,7 +60,7 @@ export function useCanvasBuild(viewId: string) {
? { root: rootOf(viewId, result.svg), failure: null }
: { root: null, failure: result.failure },
)
}, [handle.preview, viewId, handle.version, attempt])
}, [handle.preview, viewId, handle.version, attempt, handle.visible])
const retry = useCallback(() => {
void coreRuntime()
+21 -7
View File
@@ -8,16 +8,30 @@ import type {
import type { Locale } from '@/i18n/types'
import { useEditorStore } from './state/editorStore'
/**
* The last text parsed and its document. Every kept place reads the document, so one parse
* serves them all per commit. A single entry: the store holds one document at a time.
*/
let lastParse: { text: string; doc: AnatomicalSheetDocument | null } | null =
null
function parseDocument(text: string): AnatomicalSheetDocument | null {
if (text === '') return null
if (lastParse?.text === text) return lastParse.doc
let doc: AnatomicalSheetDocument | null = null
try {
doc = JSON.parse(text) as AnatomicalSheetDocument
} catch {
doc = null
}
lastParse = { text, doc }
return doc
}
/** The edited document, read from the store's text; null while nothing is loaded. */
export function useSheetDocument(): AnatomicalSheetDocument | null {
const text = useEditorStore((s) => s.documentText)
return useMemo(() => {
try {
return text === '' ? null : (JSON.parse(text) as AnatomicalSheetDocument)
} catch {
return null
}
}, [text])
return useMemo(() => parseDocument(text), [text])
}
export const isBlank = (value: string): boolean => value.trim() === ''