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,7 +3,7 @@ import type {
AnatomicalSheetDocument,
Annotation,
} from '@faunosteo/core-wasm/types'
import { type CommitContext } from '@/editor/annotations/annotationCommit'
import type { CommitContext } from '@/editor/annotations/annotationCommit'
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
import { parseFrame, type Frame } from '@/editor/annotations/frame'
import { isEditable } from '@/editor/annotations/geometryEdit'
@@ -15,9 +15,9 @@ import {
type UiAction,
type UiState,
} from '@/editor/annotations/uiState'
import type { RootAttributes } from '@/editor/annotations/useCanvasBuild'
import {
mainViewId,
useUndoShortcuts,
useViewModel,
type ViewModel,
} from '@/editor/annotations/useViewModel'
@@ -38,59 +38,75 @@ interface Props {
onSelectTab: EditorTabProps['onSelectTab']
}
export default function EditableAnnotations({ doc, onSelectTab }: Props) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
/** What both columns read: the tab's state, the view, its frame and its selection. */
interface Scene {
doc: AnatomicalSheetDocument
ui: UiState
dispatch: Dispatch<UiAction>
viewId: string
model: ViewModel
/** F of the current view, only while the core measures it and the build is its own. */
frame: Frame | null
selected: Annotation | undefined
setRoot: (root: RootAttributes | null) => void
onSelectTab: EditorTabProps['onSelectTab']
}
function useScene({ doc, onSelectTab }: Props): Scene {
const [ui, dispatch] = useReducer(uiReducer, initialUi)
const [viewBox, setViewBox] = useState<string | null>(null)
const [root, setRoot] = useState<RootAttributes | null>(null)
const viewId = ui.viewId ?? mainViewId(doc)
const model = useViewModel(doc, viewId)
const frame = model.measured ? parseFrame(viewBox) : null
const context: CommitContext = { t, locale }
const placement = usePlacement({ ui, dispatch, frame, doc, context })
useUndoShortcuts()
const selected = model.annotations.find((a) => a.id === ui.selectedId)
const scene = { doc, ui, dispatch, model, frame, selected, onSelectTab }
const own = model.measured && root?.viewId === viewId
return {
doc,
ui,
dispatch,
viewId,
model,
frame: own ? parseFrame(root.viewBox) : null,
selected: model.annotations.find((a) => a.id === ui.selectedId),
setRoot,
onSelectTab,
}
}
function useCommitContext(): CommitContext {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
return { t, locale }
}
export default function EditableAnnotations(props: Props) {
const scene = useScene(props)
const context = useCommitContext()
const placement = usePlacement({ ...scene, context })
return (
<div className="grid gap-4 xl:grid-cols-[minmax(0,1fr)_22rem]">
<CanvasColumn {...scene} placement={placement} onRoot={setViewBox} />
<CanvasColumn scene={scene} placement={placement} />
<aside>
<SidePanel {...scene} viewId={viewId} context={context} />
<SidePanel scene={scene} context={context} />
</aside>
</div>
)
}
/** What both columns read: the document, the tab's state, the view and its frame. */
interface Scene extends Props {
ui: UiState
dispatch: Dispatch<UiAction>
model: ViewModel
frame: Frame | null
selected: Annotation | undefined
}
type Placement = ReturnType<typeof usePlacement>
function CanvasColumn({
scene,
placement,
onRoot,
...scene
}: Scene & {
placement: ReturnType<typeof usePlacement>
onRoot: (viewBox: string | null) => void
}: {
scene: Scene
placement: Placement
}) {
const locale = useLocaleStore((s) => s.locale)
const { doc, ui, dispatch, model, frame, selected } = scene
const viewId = ui.viewId ?? mainViewId(doc)
const view = doc.views.find((v) => v.id === viewId)
const { doc, ui, dispatch, model, selected } = scene
const noCategory = doc.categories.length === 0
const blocked = !model.measured || noCategory
const select = (id: string) => dispatch({ type: 'select', id })
if (!view) return null
return (
<div className="min-w-0 space-y-3" onKeyDown={placement.onKeyDown}>
<div className="min-w-0 space-y-3">
<ViewSwitcher
views={doc.views}
current={viewId}
current={scene.viewId}
onSelect={(id) => dispatch({ type: 'view', viewId: id })}
/>
<ToolNotes
@@ -100,30 +116,8 @@ function CanvasColumn({
noCategory={noCategory}
onSelectTab={scene.onSelectTab}
/>
{selected && (
<SelectionTag
kind={selected.kind}
name={annotationName(selected, doc.views, locale)}
/>
)}
<AnnotationCanvas
viewId={viewId}
viewName={view.name[locale]}
tool={ui.tool}
selectedId={ui.selectedId}
moveTarget={moveTargetOf(selected, model, ui.tool)}
overlay={overlayOf(ui, selected, frame)}
tools={{
tool: ui.tool,
onTool: (tool) => dispatch({ type: 'tool', tool }),
drawingDisabled: blocked,
linkDisabled: model.children.length === 0,
}}
onRoot={onRoot}
onSelect={select}
onPlace={placement.onPlace}
onDrop={placement.onDrop}
/>
{selected && <TagOf annotation={selected} doc={doc} />}
<CanvasStage scene={scene} placement={placement} />
{ui.tracing && (
<TracingBar
count={ui.tracing.points.length}
@@ -132,20 +126,71 @@ function CanvasColumn({
/>
)}
<KeyboardAdd
disabled={blocked || frame === null}
disabled={!model.measured || noCategory || scene.frame === null}
linkDisabled={model.children.length === 0}
onAdd={(kind) => addAtCentre(kind, frame, dispatch)}
onAdd={(kind) => addAtCentre(kind, scene.frame, dispatch)}
/>
<AnnotationList
annotations={model.annotations}
views={doc.views}
selectedId={ui.selectedId}
onSelect={select}
onSelect={(id) => dispatch({ type: 'select', id })}
/>
</div>
)
}
function TagOf({
annotation,
doc,
}: {
annotation: Annotation
doc: AnatomicalSheetDocument
}) {
const locale = useLocaleStore((s) => s.locale)
return (
<SelectionTag
kind={annotation.kind}
name={annotationName(annotation, doc.views, locale)}
/>
)
}
function CanvasStage({
scene,
placement,
}: {
scene: Scene
placement: Placement
}) {
const locale = useLocaleStore((s) => s.locale)
const { doc, ui, dispatch, model, frame, selected } = scene
const view = doc.views.find((v) => v.id === scene.viewId)
const blocked = !model.measured || doc.categories.length === 0
if (!view) return null
return (
<AnnotationCanvas
viewId={scene.viewId}
viewName={view.name[locale]}
tool={ui.tool}
selectedId={ui.selectedId}
moveTarget={moveTargetOf(selected, model, ui.tool)}
overlay={overlayOf(ui, selected, frame)}
tools={{
tool: ui.tool,
onTool: (tool) => dispatch({ type: 'tool', tool }),
drawingDisabled: blocked,
linkDisabled: model.children.length === 0,
}}
onRoot={scene.setRoot}
onSelect={(id) => dispatch({ type: 'select', id })}
onPlace={placement.onPlace}
onDrop={placement.onDrop}
onTraceKey={placement.onTraceKey}
/>
)
}
function addAtCentre(
kind: NewKind,
frame: Frame | null,
@@ -157,10 +202,12 @@ function addAtCentre(
/** The creation panel while an element is pending, else the selection's properties. */
function SidePanel({
viewId,
scene,
context,
...scene
}: Scene & { viewId: string; context: CommitContext }) {
}: {
scene: Scene
context: CommitContext
}) {
const t = useT()
const { doc, ui, dispatch, model, frame, selected } = scene
if (ui.pending) {
@@ -168,7 +215,7 @@ function SidePanel({
<CreationPanel
key={ui.serial}
pending={ui.pending}
viewId={viewId}
viewId={scene.viewId}
doc={doc}
frame={frame}
dispatch={dispatch}