feat(editor): point handle, size slider with core minimum, move mode
HandleLayer: its own svg over the overlay, not aria-hidden; the selected
point (or link circle) gets a focusable « Point {nom} » handle whose hit
circle (data-handle) the press machine reads, sized in CSS px under zoom
(R-9, read once from any-pointer: coarse). The Task 2 stand-in (the
selected marker as its own handle) is removed.
Keys on the handle: arrows step 0.5 % of the frame (Shift x10) as a
stamped series, Enter or blur commit once, Escape drops it (R-11, R-13).
SizeSlider in the strip for a selected point and for the Point tool (A5):
the view's sizes as ticks, the core minimum as a red mark, snap 8 px,
arrows 1 %, Page Up/Down next size, one commit on release, Enter or blur;
a refusal restores the size and draws the refused place in red dashes.
« Déplacer le point » opens the move mode (board 06 B): drag anywhere or
four arrows move a preview only, clicks select nothing, « Valider la
position » commits once, « Annuler » and Escape restore; the focus comes
back to the button. Escape follows board 32 (escapeAction). The overlay
reads the preview from the work store and draws the old place in grey
dashes. Ctrl+Z now also works from a slider (not a text field).
Rewritten assertions:
- editor-annotations-tab « a finger drags the selected point »:
drag(marker('anno-a')) -> drag(pointHandle()), same expected geometry.
- editor-geometry.spec « a point inherited out of its frame is repaired
through the geometry group » (cx/cy typed 200) -> « ... repaired with
the move mode »: a partial move refused and restored (cx 110, issue
kept), then a move inside kept (issue gone, fewer errors).
This commit is contained in:
1 parent
2882821661
commit
91e94952f0
23 files changed
+1679
-149
No files matched your search
@@ -3,12 +3,16 @@ import Button from '@/components/ui/Button'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
Annotation,
|
||||
Geometry,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
||||
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
||||
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
||||
import { parseFrame, type Frame } from '@/editor/annotations/frame'
|
||||
import { newPointSize } from '@/editor/annotations/pointSize'
|
||||
import { guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import { usePointEdit } from '@/editor/annotations/usePointEdit'
|
||||
import { endMode, useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { isEditable } from '@/editor/annotations/geometryEdit'
|
||||
import { useSelectionEscape } from '@/editor/annotations/deselect'
|
||||
import { usePlacement } from '@/editor/annotations/usePlacement'
|
||||
@@ -37,6 +41,12 @@ import type { EditorPlaceProps } from '@/editor/tabs'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import AnnotationCanvas from './AnnotationCanvas'
|
||||
import { annotationName } from './AnnotationList'
|
||||
import {
|
||||
SelectionPointCommands,
|
||||
ToolSize,
|
||||
useMoveFocusReturn,
|
||||
} from './PointCommands'
|
||||
import CreationPanel from './CreationPanel'
|
||||
import EditStrip, { type StripNotice } from './EditStrip'
|
||||
import GestureMessage from './GestureMessage'
|
||||
@@ -134,36 +144,70 @@ function useCommitContext(): CommitContext {
|
||||
return { t, locale }
|
||||
}
|
||||
|
||||
/** The tab's work: the commit context, the line under the drawing and the placement. */
|
||||
/**
|
||||
* The tab's work: the commit context, the line under the drawing, the placement and the
|
||||
* point editing (handle keys, slider, move mode) on the movable selected circle.
|
||||
*/
|
||||
function useWork(scene: Scene) {
|
||||
const context = useCommitContext()
|
||||
const message = useGestureMessage()
|
||||
const placement = usePlacement({ ...scene, context, message })
|
||||
return { context, message, placement }
|
||||
const target = circleTargetOf(scene.selected, scene.model, scene.ui.tool)
|
||||
const edit = usePointEdit({
|
||||
target,
|
||||
frame: scene.frame,
|
||||
onDrop: placement.onDrop,
|
||||
})
|
||||
useModeFollowsSelection(scene.ui.selectedId)
|
||||
useDroppedNotice(message)
|
||||
return { context, message, placement, edit, target }
|
||||
}
|
||||
|
||||
type Work = ReturnType<typeof useWork>
|
||||
|
||||
/**
|
||||
* The move mode belongs to the selection: another selection (a list row, a view change)
|
||||
* ends it. A read-only flip keeps the body and its selection, so it suspends the mode
|
||||
* instead (R-14).
|
||||
*/
|
||||
function useModeFollowsSelection(selectedId: string | null) {
|
||||
const modeId = useAnnotationWork((s) => s.mode?.annotationId ?? null)
|
||||
useEffect(() => {
|
||||
if (modeId !== null && modeId !== selectedId) endMode()
|
||||
}, [modeId, selectedId])
|
||||
}
|
||||
|
||||
/** R-13: a started mode a change made elsewhere dropped is said on the line. */
|
||||
function useDroppedNotice(message: GestureMessages) {
|
||||
const t = useT()
|
||||
const dropped = useAnnotationWork((s) => s.dropped)
|
||||
const show = message.show
|
||||
useEffect(() => {
|
||||
if (dropped === null) return
|
||||
useAnnotationWork.setState({ dropped: null })
|
||||
const text = t(`editor.annotations.dropped.${dropped}`)
|
||||
show(text, { undo: false, tone: 'info' })
|
||||
}, [dropped, show, t])
|
||||
}
|
||||
|
||||
export default function EditableAnnotations(props: Props) {
|
||||
const scene = useScene(props)
|
||||
const { context, message, placement } = useWork(scene)
|
||||
const work = useWork(scene)
|
||||
const { ui, selected } = scene
|
||||
const visible = usePlaceVisible()
|
||||
const { asideRef, byDrawing } = useSelectionEscape(
|
||||
selected?.id ?? null,
|
||||
() => scene.dispatch({ type: 'select', id: null }),
|
||||
visible && selected !== undefined && ui.tracing === null && !ui.pending,
|
||||
visible && selected !== undefined && ui.tracing === null,
|
||||
{ editable: true, creating: ui.pending !== null },
|
||||
)
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<SceneStrip scene={scene} placement={placement} message={message} />
|
||||
<SceneStrip scene={scene} work={work} />
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<CanvasColumn
|
||||
scene={scene}
|
||||
placement={placement}
|
||||
message={message}
|
||||
onDeselect={byDrawing}
|
||||
/>
|
||||
<CanvasColumn scene={scene} work={work} onDeselect={byDrawing} />
|
||||
<aside ref={asideRef}>
|
||||
<SidePanel scene={scene} context={context} />
|
||||
<SidePanel scene={scene} context={work.context} />
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
@@ -172,15 +216,18 @@ export default function EditableAnnotations(props: Props) {
|
||||
|
||||
type Placement = ReturnType<typeof usePlacement>
|
||||
|
||||
/** A move that drops the drawing's work asks first (R-12): the action runs once allowed. */
|
||||
const guarded = (action: () => void) => () => {
|
||||
if (guardDrawing(action)) action()
|
||||
}
|
||||
|
||||
function CanvasColumn({
|
||||
scene,
|
||||
placement,
|
||||
message,
|
||||
work,
|
||||
onDeselect,
|
||||
}: {
|
||||
scene: Scene
|
||||
placement: Placement
|
||||
message: GestureMessages
|
||||
work: Work
|
||||
onDeselect: () => void
|
||||
}) {
|
||||
const { doc, dispatch, model } = scene
|
||||
@@ -190,37 +237,49 @@ function CanvasColumn({
|
||||
<ViewSwitcher
|
||||
views={doc.views}
|
||||
current={scene.viewId}
|
||||
onSelect={(id) => dispatch({ type: 'view', viewId: id })}
|
||||
onSelect={(id) =>
|
||||
guarded(() => dispatch({ type: 'view', viewId: id }))()
|
||||
}
|
||||
/>
|
||||
<CanvasStage
|
||||
scene={scene}
|
||||
placement={placement}
|
||||
onDeselect={onDeselect}
|
||||
/>
|
||||
<GestureMessage messages={message}>
|
||||
<CanvasStage scene={scene} work={work} onDeselect={onDeselect} />
|
||||
<GestureMessage messages={work.message}>
|
||||
<KeyboardAdd
|
||||
disabled={!model.measured || noCategory || scene.frame === null}
|
||||
linkDisabled={model.children.length === 0}
|
||||
onAdd={(kind) => addAtCentre(kind, scene)}
|
||||
onAdd={(kind) => guarded(() => addAtCentre(kind, scene))()}
|
||||
/>
|
||||
</GestureMessage>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The point handle of the movable selected circle, named « Point {nom} ». */
|
||||
function useHandle(target: Annotation | null, doc: AnatomicalSheetDocument) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
if (!target?.geometry) return null
|
||||
const name = annotationName(target, doc.views, locale)
|
||||
return {
|
||||
annotationId: target.id,
|
||||
label: t('editor.annotations.handle.point').replace('{name}', () => name),
|
||||
stored: target.geometry,
|
||||
}
|
||||
}
|
||||
|
||||
function CanvasStage({
|
||||
scene,
|
||||
placement,
|
||||
work,
|
||||
onDeselect,
|
||||
}: {
|
||||
scene: Scene
|
||||
placement: Placement
|
||||
work: Work
|
||||
onDeselect: () => void
|
||||
}) {
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
// Hidden (the editor is read-only): no drag in flight survives, none is committed.
|
||||
const shown = usePlaceVisible()
|
||||
const { doc, ui, dispatch, model, frame, selected } = scene
|
||||
const handle = useHandle(shown ? work.target : null, doc)
|
||||
const view = doc.views.find((v) => v.id === scene.viewId)
|
||||
const blocked = !model.measured || doc.categories.length === 0
|
||||
if (!view) return null
|
||||
@@ -231,19 +290,24 @@ function CanvasStage({
|
||||
tool={ui.tool}
|
||||
selectedId={ui.selectedId}
|
||||
moveTarget={shown ? moveTargetOf(selected, model, ui.tool) : null}
|
||||
overlay={overlayOf(ui, selected, frame)}
|
||||
overlay={overlayOf(ui, selected, frame, work.message.message?.place)}
|
||||
handles={{
|
||||
handle,
|
||||
onKeyDown: work.edit.onHandleKey,
|
||||
onBlur: work.edit.onHandleBlur,
|
||||
}}
|
||||
tools={{
|
||||
tool: ui.tool,
|
||||
onTool: (tool) => dispatch({ type: 'tool', tool }),
|
||||
onTool: (tool) => guarded(() => 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}
|
||||
onPlace={work.placement.onPlace}
|
||||
onDrop={work.placement.onDrop}
|
||||
onDeselect={onDeselect}
|
||||
onTraceKey={placement.onTraceKey}
|
||||
onTraceKey={work.placement.onTraceKey}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -266,6 +330,8 @@ function SidePanel({
|
||||
context: CommitContext
|
||||
}) {
|
||||
const { doc, ui, dispatch, model, frame, selected } = scene
|
||||
// During the move mode the panel offers no deselect: only the mode's own exits.
|
||||
const moving = useAnnotationWork((s) => s.mode?.kind === 'move')
|
||||
if (ui.pending) {
|
||||
return (
|
||||
<CreationPanel
|
||||
@@ -304,7 +370,7 @@ function SidePanel({
|
||||
context={context}
|
||||
navigate={scene.navigate}
|
||||
onShowAll={() => dispatch({ type: 'select', id: null })}
|
||||
busy={ui.tracing !== null}
|
||||
busy={ui.tracing !== null || moving}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -320,13 +386,26 @@ function moveTargetOf(
|
||||
: null
|
||||
}
|
||||
|
||||
/** The selected point or link circle, when it can be moved now (R-9: its handle). */
|
||||
function circleTargetOf(
|
||||
selected: Annotation | undefined,
|
||||
model: ViewModel,
|
||||
tool: ToolId,
|
||||
): Annotation | null {
|
||||
const movable = moveTargetOf(selected, model, tool) !== null
|
||||
return movable && selected?.geometry?.type === 'circle' ? selected : null
|
||||
}
|
||||
|
||||
function overlayOf(
|
||||
ui: UiState,
|
||||
selected: Annotation | undefined,
|
||||
frame: Frame | null,
|
||||
refused: Geometry | null | undefined,
|
||||
) {
|
||||
return {
|
||||
frame,
|
||||
selectedId: selected?.id ?? null,
|
||||
refused: refused ?? null,
|
||||
selected: selected?.geometry ?? null,
|
||||
pending: ui.pending?.geometry ?? null,
|
||||
tracing: ui.tracing?.points ?? null,
|
||||
@@ -334,33 +413,65 @@ function overlayOf(
|
||||
}
|
||||
}
|
||||
|
||||
/** The strip of the edit body: the lead of the scene, its notice, the tracing commands. */
|
||||
function SceneStrip({
|
||||
scene,
|
||||
placement,
|
||||
message,
|
||||
}: {
|
||||
scene: Scene
|
||||
placement: Placement
|
||||
message: GestureMessages
|
||||
}) {
|
||||
/**
|
||||
* The strip of the edit body: the lead of the scene (the move mode's own while it runs),
|
||||
* its notice, the commands.
|
||||
*/
|
||||
function SceneStrip({ scene, work }: { scene: Scene; work: Work }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const notice = useStripNotice(scene, message.message)
|
||||
const notice = useStripNotice(scene, work.message.message)
|
||||
const moving = useAnnotationWork((s) => s.mode?.kind === 'move')
|
||||
useMoveFocusReturn(moving)
|
||||
const { ui, selected, doc } = scene
|
||||
const lead = moving
|
||||
? {
|
||||
title: t('editor.annotations.move.point'),
|
||||
detail: t('editor.annotations.move.hint'),
|
||||
icon: 'move' as const,
|
||||
}
|
||||
: stripLeadOf(ui, selected, doc, { t, locale })
|
||||
return (
|
||||
<EditStrip
|
||||
lead={stripLeadOf(ui, selected, doc, { t, locale })}
|
||||
lead={lead}
|
||||
notice={notice}
|
||||
commands={
|
||||
ui.tracing && (
|
||||
<TracingCommands
|
||||
count={ui.tracing.points.length}
|
||||
placement={placement}
|
||||
onCancel={() => scene.dispatch({ type: 'trace_cancel' })}
|
||||
/>
|
||||
)
|
||||
}
|
||||
commands={<SceneCommands scene={scene} work={work} />}
|
||||
commandsKey={commandsKeyOf(ui, moving, work.target !== null)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function commandsKeyOf(ui: UiState, moving: boolean, point: boolean) {
|
||||
if (ui.tracing) return 'tracing'
|
||||
if (moving) return 'move'
|
||||
return point ? 'point' : `tool-${ui.tool}`
|
||||
}
|
||||
|
||||
/** A tracing's commands, a movable point's, or the Point tool's size (A5). */
|
||||
function SceneCommands({ scene, work }: { scene: Scene; work: Work }) {
|
||||
const { ui, doc, viewId, frame, dispatch } = scene
|
||||
if (ui.tracing) {
|
||||
return (
|
||||
<TracingCommands
|
||||
count={ui.tracing.points.length}
|
||||
placement={work.placement}
|
||||
onCancel={() => dispatch({ type: 'trace_cancel' })}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (work.target) {
|
||||
const props = { doc, viewId, frame, edit: work.edit }
|
||||
return <SelectionPointCommands annotation={work.target} {...props} />
|
||||
}
|
||||
if (ui.tool !== 'point' || ui.pending || !frame) return null
|
||||
const size = ui.size
|
||||
return (
|
||||
<ToolSize
|
||||
doc={doc}
|
||||
viewId={viewId}
|
||||
frame={frame}
|
||||
size={size}
|
||||
dispatch={dispatch}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user