press.ts (pure: slop per pointer kind, nearest handle, press target, click and drag actions, double click, stepPress) is now the editor canvas's only decider; useCanvasGestures no longer uses clickHandler, useEmptyTap, swallowClick nor useMoveGesture (deleted), and the box has no onClick. canPan = dragAction(press target).type === 'pan' at pointer-down; framing keys only when the box itself is the target. workStore.ts holds the U2 work with stale stamps: dropStale on every documentText change, reset on a new session (editorStore subscription). The catalogue keeps useFraming defaults and useEmptyTap, unchanged. Named change (A13): a finger drag on a selected zone's (or circle link's) interior moves nothing; the selected point is its own handle and still moves by any pointer. Second observable change: touch and pen taps are decided at the pointer-up from the press target, no longer from the following click (no browser touch adjustment toward a marker). tests/setup.ts: happy-dom has no elementsFromPoint; a shim answers the pointerdown target and its ancestors. Rewritten tests (editor-annotations-tab.test.tsx, D6b): - "a touch tap deselects in its own click, not at the pointer-up" -> "a touch tap deselects at the pointer-up" (deselected after pointerup) - "a touch tap whose click lands on a marker (adjustment) selects that marker" -> "a touch tap is decided by its press: a click adjusted toward a marker selects nothing" (deselected, announced, marker b not current) - "a pen tap deselects in its own click, like a touch tap" -> "a pen tap deselects at the pointer-up, like a mouse tap" - "a pen tap whose click lands on a marker selects that marker" -> "a pen tap is decided by its press: a click landing on a marker selects nothing" Added: "a finger drags the selected point (its handle), never a selected zone (A13)". Drive-only changes, assertions unchanged: canvas fireEvent.click(x, y) -> pressAt (pointerdown + pointerup) in the tab suite (C26, tracing, paths, H3, H6, H8, filter reselect), editor-keep-alive and editor-sections; drag moves carry buttons: 1 (C34, polygon block move, H8 lostpointercapture and read-only, editor-no-loss drag in flight), since a move without a button is a hover.
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import { create } from 'zustand'
|
|
import type { Geometry } from '@faunosteo/core-wasm/types'
|
|
import type { CreationForm, PendingElement } from './creation'
|
|
|
|
/** A geometry shown but not committed, stamped with the document text it was computed on. */
|
|
export interface Preview {
|
|
annotationId: string
|
|
geometry: Geometry
|
|
base: string
|
|
source: 'move' | 'size' | 'keys'
|
|
}
|
|
export interface Chosen {
|
|
annotationId: string
|
|
vertex: number
|
|
base: string
|
|
}
|
|
export interface Creation {
|
|
/** A new zone or link being traced lives here from its first vertex (`closed` false). */
|
|
pending: PendingElement
|
|
closed: boolean
|
|
form: CreationForm
|
|
/** The dialog is shown; false while the shape is replaced or the trace resumed. */
|
|
dialog: boolean
|
|
}
|
|
/** A move mode or a redraw; `started` once the position differs or a vertex is placed (R-12). */
|
|
export interface ModeWork {
|
|
kind: 'move' | 'redraw'
|
|
annotationId: string
|
|
started: boolean
|
|
}
|
|
interface Work {
|
|
creation: Creation | null
|
|
mode: ModeWork | null
|
|
preview: Preview | null
|
|
chosen: Chosen | null
|
|
}
|
|
const NO_WORK: Work = {
|
|
creation: null,
|
|
mode: null,
|
|
preview: null,
|
|
chosen: null,
|
|
}
|
|
|
|
export const useAnnotationWork = create<Work>(() => NO_WORK)
|
|
|
|
export type GuardWork = 'creation' | 'move' | 'redraw' | null
|
|
/** R-12: what a navigation must ask about; an unstarted mode asks nothing and simply ends. */
|
|
export function guardWork(work: Work): GuardWork {
|
|
if (work.creation !== null) return 'creation'
|
|
return work.mode?.started ? work.mode.kind : null
|
|
}
|
|
/** The end of a mode without a question (unstarted, or « Abandonner » answered). */
|
|
export function endMode(): void {
|
|
useAnnotationWork.setState({ mode: null, preview: null })
|
|
}
|
|
|
|
/** R-13: drop what was computed on another document text; the caller passes the current text. */
|
|
export function dropStale(text: string): void {
|
|
useAnnotationWork.setState((work) => ({
|
|
preview: work.preview && work.preview.base !== text ? null : work.preview,
|
|
chosen: work.chosen && work.chosen.base !== text ? null : work.chosen,
|
|
}))
|
|
}
|
|
|
|
/** Another sheet opened, or the editor closed: nothing of the previous one survives. */
|
|
export function resetWork(): void {
|
|
useAnnotationWork.setState(NO_WORK)
|
|
}
|