feat(app): a click on the drawing deselects (R1, D6b)
The decision comes from the press (landed off a marker, moved <= 4 px, one pointer), not the click target: mouse and pen act at pointerup, touch in the tap's own click. The reader passes no onEmpty and is unchanged. No existing assertion rewritten.
This commit is contained in:
1 parent
bbb1668406
commit
bbdfd27311
9 files changed
+586
-21
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useCallback, useEffect, useRef, useState, type PointerEvent } from 'react'
|
||||
import { usePlaceVisible } from '@/lib/placeVisibility'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
@@ -6,6 +6,7 @@ import { coreRuntime, useCoreStopped } from '@/core/runtime'
|
||||
import { coreFailureMessage } from '@/core/failure'
|
||||
import type { CataloguePreview } from '@/catalogue/preview'
|
||||
import { transformOf } from '@/catalogue/framing'
|
||||
import { useEmptyTap } from '@/catalogue/useEmptyTap'
|
||||
import { useFraming } from '@/catalogue/useFraming'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
@@ -15,6 +16,8 @@ export interface CatalogueCanvasProps {
|
||||
viewName: string
|
||||
selectedId: string | null
|
||||
onAnnotation: (annotationId: string) => void
|
||||
/** A tap on the empty drawing; without it the canvas behaves as the reader always did. */
|
||||
onEmpty?: () => void
|
||||
}
|
||||
|
||||
type CanvasFailure = 'engine' | 'view'
|
||||
@@ -54,6 +57,7 @@ export default function CatalogueCanvas({
|
||||
viewName,
|
||||
selectedId,
|
||||
onAnnotation,
|
||||
onEmpty,
|
||||
}: CatalogueCanvasProps) {
|
||||
const t = useT()
|
||||
const viewport = useRef<HTMLDivElement | null>(null)
|
||||
@@ -66,6 +70,29 @@ export default function CatalogueCanvas({
|
||||
viewport,
|
||||
viewId,
|
||||
)
|
||||
const tap = useEmptyTap()
|
||||
const { takeClick } = tap
|
||||
const emptyHandlers = onEmpty
|
||||
? {
|
||||
onPointerDown: (e: PointerEvent) => {
|
||||
handlers.onPointerDown(e)
|
||||
tap.onPointerDown(e)
|
||||
},
|
||||
onPointerMove: (e: PointerEvent) => {
|
||||
handlers.onPointerMove(e)
|
||||
tap.onPointerMove(e)
|
||||
},
|
||||
onPointerUp: (e: PointerEvent) => {
|
||||
handlers.onPointerUp(e)
|
||||
if (tap.verdict(e) === 'now') onEmpty()
|
||||
},
|
||||
onPointerCancel: (e: PointerEvent) => {
|
||||
handlers.onPointerCancel(e)
|
||||
tap.onPointerCancel()
|
||||
},
|
||||
onContextMenu: tap.onPointerCancel,
|
||||
}
|
||||
: handlers
|
||||
|
||||
const retryEngine = useCallback(() => {
|
||||
void coreRuntime()
|
||||
@@ -98,13 +125,16 @@ export default function CatalogueCanvas({
|
||||
if (!element) return
|
||||
const onClick = (event: Event) => {
|
||||
if (swallowClick()) return
|
||||
const answer = onEmpty ? takeClick(event.target) : 'normal'
|
||||
if (answer === 'swallow') return
|
||||
if (answer === 'deselect') return onEmpty?.()
|
||||
const target = event.target instanceof Element ? event.target.closest(ANNOTATED) : null
|
||||
const id = target?.getAttribute('data-anno-id')
|
||||
if (id) onAnnotation(id)
|
||||
}
|
||||
element.addEventListener('click', onClick)
|
||||
return () => element.removeEventListener('click', onClick)
|
||||
}, [onAnnotation, swallowClick])
|
||||
}, [onAnnotation, onEmpty, swallowClick, takeClick])
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
@@ -118,7 +148,7 @@ export default function CatalogueCanvas({
|
||||
data-testid="catalogue-canvas"
|
||||
className="svg-canvas aspect-[4/3] w-full cursor-grab select-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--color-accent)] sm:aspect-[3/2]"
|
||||
style={{ touchAction: framing.scale === 1 ? 'pan-x pan-y' : 'none' }}
|
||||
{...handlers}
|
||||
{...emptyHandlers}
|
||||
>
|
||||
<div
|
||||
ref={host}
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface AnnotationCanvasProps {
|
||||
/** A click with a drawing tool, in drawing units. */
|
||||
onPlace: (at: XY) => void
|
||||
onDrop: (id: string, geometry: Geometry) => void
|
||||
onDeselect: () => void
|
||||
onTraceKey: (event: KeyboardEvent) => void
|
||||
}
|
||||
|
||||
|
||||
@@ -133,14 +133,18 @@ export default function EditableAnnotations(props: Props) {
|
||||
const placement = usePlacement({ ...scene, context })
|
||||
const { ui, selected } = scene
|
||||
const visible = usePlaceVisible()
|
||||
const asideRef = useSelectionEscape(
|
||||
const { asideRef, byDrawing } = useSelectionEscape(
|
||||
selected?.id ?? null,
|
||||
() => scene.dispatch({ type: 'select', id: null }),
|
||||
visible && selected !== undefined && ui.tracing === null && !ui.pending,
|
||||
)
|
||||
return (
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<CanvasColumn scene={scene} placement={placement} />
|
||||
<CanvasColumn
|
||||
scene={scene}
|
||||
placement={placement}
|
||||
onDeselect={byDrawing}
|
||||
/>
|
||||
<aside ref={asideRef}>
|
||||
<SidePanel scene={scene} context={context} />
|
||||
</aside>
|
||||
@@ -153,9 +157,11 @@ type Placement = ReturnType<typeof usePlacement>
|
||||
function CanvasColumn({
|
||||
scene,
|
||||
placement,
|
||||
onDeselect,
|
||||
}: {
|
||||
scene: Scene
|
||||
placement: Placement
|
||||
onDeselect: () => void
|
||||
}) {
|
||||
const { doc, ui, dispatch, model, selected } = scene
|
||||
const noCategory = doc.categories.length === 0
|
||||
@@ -175,7 +181,11 @@ function CanvasColumn({
|
||||
navigate={scene.navigate}
|
||||
/>
|
||||
{selected && <TagOf annotation={selected} doc={doc} />}
|
||||
<CanvasStage scene={scene} placement={placement} />
|
||||
<CanvasStage
|
||||
scene={scene}
|
||||
placement={placement}
|
||||
onDeselect={onDeselect}
|
||||
/>
|
||||
{ui.tracing && (
|
||||
<TracingBar
|
||||
count={ui.tracing.points.length}
|
||||
@@ -211,9 +221,11 @@ function TagOf({
|
||||
function CanvasStage({
|
||||
scene,
|
||||
placement,
|
||||
onDeselect,
|
||||
}: {
|
||||
scene: Scene
|
||||
placement: Placement
|
||||
onDeselect: () => void
|
||||
}) {
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
// Hidden (the editor is read-only): no drag in flight survives, none is committed.
|
||||
@@ -240,6 +252,7 @@ function CanvasStage({
|
||||
onSelect={(id) => dispatch({ type: 'select', id })}
|
||||
onPlace={placement.onPlace}
|
||||
onDrop={placement.onDrop}
|
||||
onDeselect={onDeselect}
|
||||
onTraceKey={placement.onTraceKey}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -166,7 +166,7 @@ function ReadOnlyAnnotations({
|
||||
const view = doc.views.find((v) => v.id === viewId)
|
||||
const selected = model.annotations.find((a) => a.id === selectedId)
|
||||
const visible = usePlaceVisible()
|
||||
const asideRef = useSelectionEscape(
|
||||
const { asideRef, byDrawing } = useSelectionEscape(
|
||||
selected?.id ?? null,
|
||||
() => setSelectedId(null),
|
||||
visible && selected !== undefined,
|
||||
@@ -195,6 +195,7 @@ function ReadOnlyAnnotations({
|
||||
viewName={view.name[locale]}
|
||||
selectedId={selectedId}
|
||||
onAnnotation={setSelectedId}
|
||||
onEmpty={byDrawing}
|
||||
/>
|
||||
</div>
|
||||
<aside ref={asideRef}>
|
||||
|
||||
Reference in new issue
Block a user