fix(app): annotations tab split, editor-wide undo keys, keyboard point fits, typed radius message

This commit is contained in:
bchanot committed 2026-11-04 14:00:57 +01:00
1 parent 447d0a4272
commit 3f15762d95
25 files changed
+1398 -653

No files matched your search

@@ -3,52 +3,68 @@ import { buildView } from '@/components/catalogue/CatalogueCanvas'
import { coreRuntime } from '@/core/runtime'
import { useEditorStore } from '../state/editorStore'
/** The composed root's own attributes, read as text (never `baseVal`). */
/** The composed root's own attributes, read as text (never `baseVal`), and its view. */
export interface RootAttributes {
/** The view this build was made for: a frame is never paired with another view's. */
viewId: string
viewBox: string | null
ratio: string
}
export type CanvasFailure = 'engine' | 'view'
interface Built {
root: RootAttributes | null
failure: CanvasFailure | null
}
const ANNOTATED = '[data-anno-id]'
function rootOf(viewId: string, svg: Element): RootAttributes {
return {
viewId,
viewBox: svg.getAttribute('viewBox'),
ratio: svg.getAttribute('preserveAspectRatio') ?? 'xMidYMid meet',
}
}
/** What the canvas rebuilds on: the handle and its version counter. */
function useHandle() {
const preview = useEditorStore((s) => s.preview)
const version = useEditorStore((s) => s.handleVersion)
return { preview, version }
}
/**
* Builds the core's composed view into `host`, again on every accepted handle change or
* retry (plan « Rendering and canvas »): the edit canvas follows the handle. Reports the
* root's attributes; a failure is the engine notice (retry) or the view notice.
* retry (plan « Rendering and canvas »): the edit canvas follows the handle. Root and
* failure come from the same build; a failure is the engine notice (retry) or the view
* notice.
*/
export function useCanvasBuild(viewId: string) {
const preview = useEditorStore((s) => s.preview)
const handleVersion = useEditorStore((s) => s.handleVersion)
const handle = useHandle()
const host = useRef<HTMLDivElement | null>(null)
const [attempt, setAttempt] = useState(0)
const [root, setRoot] = useState<RootAttributes | null>(null)
const [failure, setFailure] = useState<CanvasFailure | null>(null)
const [built, setBuilt] = useState<Built>({ root: null, failure: null })
useEffect(() => {
const element = host.current
if (!element || !preview) return
const built = buildView(preview, viewId)
element.replaceChildren(...(built.ok ? [built.svg] : []))
setFailure(built.ok ? null : built.failure)
setRoot(
built.ok
? {
viewBox: built.svg.getAttribute('viewBox'),
ratio:
built.svg.getAttribute('preserveAspectRatio') ?? 'xMidYMid meet',
}
: null,
if (!element || !handle.preview) return
const result = buildView(handle.preview, viewId)
element.replaceChildren(...(result.ok ? [result.svg] : []))
setBuilt(
result.ok
? { root: rootOf(viewId, result.svg), failure: null }
: { root: null, failure: result.failure },
)
}, [preview, viewId, handleVersion, attempt])
}, [handle.preview, viewId, handle.version, attempt])
const retry = useCallback(() => {
void coreRuntime()
.retry()
.finally(() => setAttempt((n) => n + 1))
}, [])
return { host, root, failure, retry, handleVersion }
return { host, ...built, retry }
}
/** The selected annotation's markers wear `data-state="current"`, restyled in place. */