feat(editor): creation on the drawing then the creation dialog
U2 Task 7 (A2, A4, A5, A7, A12, A15; R-3, R-4, R-12, R-13, R-14). The work store's `creation` owns the new shape, its form, its view and F: a click with the point tool, a closed tracing or a keyboard « Ajouter … » opens « Nouveau point / zone / accès », a modal without a history layer over the right column, mounted beside EditOnly so a read-only flip keeps it (« Créer », « Replacer », « Reprendre » off). A new zone or link is a creation from its first vertex. The ghost takes the form's category colour; the point tool previews under a mouse; the canvas carries data-creating (other markers dimmed, unselectable). « Replacer le point » / « Reprendre le tracé » hide the dialog and keep the form; the strip offers « Revenir aux propriétés », « Retirer le dernier sommet », « Abandonner ». « Créer »: one insert, tool back to « Sélectionner », the new element selected, « Point créé · Défaire », focus on its row. ✕, Échap, « Abandonner » and Back always ask « Abandonner la création ? » (DiscardConfirm inside the dialog; DrawingGuardDialog elsewhere); answerDrawing drops the creation. Undo, its shortcuts and the line's « Défaire » are inactive during a creation. missingFields replaces formProblem (MissingSummary shared with the edit form); the C26 notice has no numbers. CreationPanel, formProblem, withGeometry and the keys required.fields, required.names and create_cancel are gone; GeometryGroup is imported by RepairDialog only. Removed or rewritten assertions: - tab « holds a point at the frame centre »: « Centre x » = 50 -> the ghost circle cx = 50; plus tool back to Sélectionner, « Point créé », one undo step. - tab « refuses a creation without laterality »: the general line « Choisissez la catégorie et la latéralité » -> only « Choisissez une latéralité. » and « À compléter : Latéralité. », focus on it. - tab « applies the geometry group to a pending zone »: removed (A8, no coordinate field) -> « places a triangle at the centre: the ghost shows it, Créer inserts it »; vertex edits after Créer are the e2e keyboard test. - tab C26 « proposes C »: « x = 15, y = 15 » in the notice -> the R-4 text, the notice inside the dialog; cancel test « Centre x » = 0 -> ghost cx = 0. - tab « offers the correction when the core refuses a pending point » (typed cx 98): removed, no typed coordinate is possible; the verdict path stays covered by the C26 click tests and correctionFor units. - tab H5 « a typed radius shows the core issue »: removed (A8); the size refusal is the slider's (Task 4 tests). - tab H6 « a second click moves the pending point »: -> « Replacer le point », then the click moves the ghost, the form kept. - tab H7 « Centre x/y » = 30/50 -> ghost cx/cy. - tab tracing Enter: « x du sommet 3 » -> ghost points; « drops the tracing on Escape » -> Escape asks first (board 32 row 3), Continuer keeps, Abandonner drops; new « Annuler le tracé acts at once ». - keep-alive « a pending creation is kept and focused » and « a tracing … is kept and focused »: the tab now asks first (R-12) -> « Continuer » keeps the tracing / the form, « Abandonner » goes. - sections « its panel takes the focus » -> its dialog's [data-creation-focus] takes it. - no-loss « pending creation with its name » (hidden with the body) -> the dialog stays across the crossing, read-only, Créer off (R-14). - point-edit A5 « Rayon » = 7 / 9 -> ghost r = 7 / 9. - e2e editor-annotations keyboard test « numeric position » (cx field 250) -> UX_TESTS Keyboard: zone added, vertex added and removed, moved by the move mode, validated, saved. The « Fermer le tracé » step runs under expectNoShift again (shortcut removed). - e2e editor-geometry C26: the proposed x, y read from the notice text -> from the overlay's correction circle; the R-4 text checked in the dialog. - e2e editor-deselect « Escape cancels the tracing only » -> Escape asks, « Abandonner » cancels it, the selection kept. - e2e editor-shell-crossing « keeps its tool and its pending creation » (field hidden) -> the dialog stays read-only, Créer off, then editable on widening.
This commit is contained in:
1 parent
2d58da7d01
commit
4d2c64f57f
50 files changed
+3050
-1181
No files matched your search
@@ -31,22 +31,7 @@ export interface PendingElement {
|
||||
wantedRadius?: number
|
||||
}
|
||||
|
||||
/** The pending element with a geometry the user typed: C and the proposal lapse with it. */
|
||||
export function withGeometry(
|
||||
pending: PendingElement,
|
||||
geometry: EditableGeometry,
|
||||
): PendingElement {
|
||||
const kept =
|
||||
geometry.type === 'circle' && geometry.r === pending.proposedRadius
|
||||
return {
|
||||
...pending,
|
||||
geometry,
|
||||
correction: null,
|
||||
proposedRadius: kept ? pending.proposedRadius : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
/** What the creation panel collects (no default labels: names and laterality are typed). */
|
||||
/** What the creation dialog collects (no default labels: names and laterality are typed). */
|
||||
export interface CreationForm {
|
||||
fr: string
|
||||
en: string
|
||||
@@ -107,23 +92,8 @@ export function keyboardPending(
|
||||
return { kind, geometry: { type: 'polygon', points: centreTriangle(frame) } }
|
||||
}
|
||||
|
||||
export type FormProblem = 'names' | 'fields'
|
||||
|
||||
const blank = (value: string) => value.trim() === ''
|
||||
|
||||
/** Input shape only: what the core requires to exist, collected before the insert. */
|
||||
export function formProblem(
|
||||
kind: NewKind,
|
||||
form: CreationForm,
|
||||
): FormProblem | null {
|
||||
if (form.categoryId === '' || form.laterality === '') return 'fields'
|
||||
if (kind === 'detail_trigger') {
|
||||
if (form.opensViewId === '') return 'fields'
|
||||
return blank(form.fr) !== blank(form.en) ? 'names' : null
|
||||
}
|
||||
return blank(form.fr) || blank(form.en) ? 'names' : null
|
||||
}
|
||||
|
||||
const orNull = (value: string): string | null => (blank(value) ? null : value)
|
||||
|
||||
/** The annotation the form and the pending geometry describe, under a given id. */
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { landAfterModalsClosed } from '@/components/ui/afterModalsClosed'
|
||||
import { visibleElement } from '../focusRequest'
|
||||
import { guardDrawing } from './drawingGuard'
|
||||
import type { NewKind } from './creation'
|
||||
import { useAnnotationWork, type Creation } from './workStore'
|
||||
|
||||
const TOOL_OF: Record<NewKind, string> = {
|
||||
point: 'point',
|
||||
zone: 'zone',
|
||||
detail_trigger: 'link',
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the focus goes once a creation is abandoned (board 32): the tool's button, or the
|
||||
* keyboard « Ajouter … » button that started it.
|
||||
*/
|
||||
export function creationOpener(work: Creation): HTMLElement | null {
|
||||
const { kind } = work.pending
|
||||
if (work.origin === 'keyboard') {
|
||||
return visibleElement(`[data-add-kind="${kind}"]`)
|
||||
}
|
||||
return visibleElement(`[data-tool="${TOOL_OF[kind]}"]`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape or « Abandonner » outside the dialog (a tracing, a point being replaced): the
|
||||
* guard is always armed (A12), « Abandonner la création ? » asks; its « Abandonner »
|
||||
* drops the creation and the focus goes back to what started it.
|
||||
*/
|
||||
export function askCreation(): void {
|
||||
const work = useAnnotationWork.getState().creation
|
||||
if (!work) return
|
||||
guardDrawing(() => landAfterModalsClosed(() => creationOpener(work)?.focus()))
|
||||
}
|
||||
@@ -12,12 +12,12 @@ import {
|
||||
} from './correction'
|
||||
import {
|
||||
annotationOf,
|
||||
formProblem,
|
||||
type CreationForm,
|
||||
type PendingElement,
|
||||
} from './creation'
|
||||
import { defaultRadius, type Frame } from './frame'
|
||||
import type { EditableGeometry } from './geometryEdit'
|
||||
import { missingFields, type MissingField } from './missingFields'
|
||||
|
||||
/** What « Créer » or the confirmation of C works from. */
|
||||
export interface CreationInput {
|
||||
@@ -28,7 +28,10 @@ export interface CreationInput {
|
||||
context: CommitContext
|
||||
}
|
||||
|
||||
export type Attempt = PointAttempt | { status: 'invalid'; problem: string }
|
||||
/** `invalid`: the fields R-3 names as missing, nothing tried. */
|
||||
export type Attempt =
|
||||
| PointAttempt
|
||||
| { status: 'invalid'; missing: MissingField[] }
|
||||
|
||||
/** The insert of the pending element under a given geometry, through `accept`. */
|
||||
function inserterOf(input: CreationInput, form: CreationForm) {
|
||||
@@ -46,8 +49,8 @@ export function createAttempt(
|
||||
form: CreationForm,
|
||||
): Attempt {
|
||||
const { pending, frame } = input
|
||||
const problem = formProblem(pending.kind, form)
|
||||
if (problem) return { status: 'invalid', problem }
|
||||
const missing = missingFields(pending.kind, form)
|
||||
if (missing.length > 0) return { status: 'invalid', missing }
|
||||
const insert = inserterOf(input, form)
|
||||
const { geometry } = pending
|
||||
if (pending.kind === 'point' && geometry.type === 'circle' && frame) {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
import type { Point } from '@faunosteo/core-wasm/types'
|
||||
import type { CreationForm, NewKind, PendingElement } from './creation'
|
||||
import type { Correction } from './correction'
|
||||
import type { Frame } from './frame'
|
||||
import type { Tracing } from './uiState'
|
||||
import { useAnnotationWork, type Creation } from './workStore'
|
||||
|
||||
/** Where a creation starts: its view, F, how it began, and the form it starts with. */
|
||||
export interface CreationStart {
|
||||
viewId: string
|
||||
frame: Frame | null
|
||||
origin: Creation['origin']
|
||||
form: CreationForm
|
||||
}
|
||||
|
||||
const creation = () => useAnnotationWork.getState().creation
|
||||
|
||||
function patch(change: Partial<Creation>): void {
|
||||
const current = creation()
|
||||
if (current)
|
||||
useAnnotationWork.setState({ creation: { ...current, ...change } })
|
||||
}
|
||||
|
||||
/**
|
||||
* A placed point or a keyboard shape: the dialog opens (A2). A creation of the same kind
|
||||
* keeps its form (« Replacer le point »: the next click moves the ghost).
|
||||
*/
|
||||
export function placePending(
|
||||
start: CreationStart,
|
||||
pending: PendingElement,
|
||||
): void {
|
||||
const kept = creation()
|
||||
const same = kept !== null && kept.pending.kind === pending.kind
|
||||
useAnnotationWork.setState({
|
||||
creation: {
|
||||
...start,
|
||||
form: same ? kept.form : start.form,
|
||||
resumed: same ? kept.resumed : false,
|
||||
pending,
|
||||
closed: true,
|
||||
dialog: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const polygonOf = (kind: NewKind, points: Point[]): PendingElement => ({
|
||||
kind,
|
||||
geometry: { type: 'polygon', points },
|
||||
})
|
||||
|
||||
/** The open tracing's vertices; none when no tracing of a new shape is open. */
|
||||
const tracedPoints = (work: Creation | null): Point[] | null =>
|
||||
work && !work.closed && work.pending.geometry.type === 'polygon'
|
||||
? work.pending.geometry.points
|
||||
: null
|
||||
|
||||
/** A vertex of a new zone or link: the first one starts the creation (A12). */
|
||||
export function traceVertex(
|
||||
start: CreationStart,
|
||||
kind: NewKind,
|
||||
point: Point,
|
||||
): void {
|
||||
const points = tracedPoints(creation())
|
||||
if (points) return patch({ pending: polygonOf(kind, [...points, point]) })
|
||||
useAnnotationWork.setState({
|
||||
creation: {
|
||||
...start,
|
||||
pending: polygonOf(kind, [point]),
|
||||
closed: false,
|
||||
dialog: false,
|
||||
resumed: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** Backspace or « Retirer le dernier sommet »; a fresh tracing left empty is no creation. */
|
||||
export function popVertex(): void {
|
||||
const work = creation()
|
||||
const points = tracedPoints(work)
|
||||
if (!work || !points) return
|
||||
const left = points.slice(0, -1)
|
||||
if (left.length === 0 && !work.resumed) return dropCreation()
|
||||
patch({ pending: polygonOf(work.pending.kind, left) })
|
||||
}
|
||||
|
||||
/** The tracing closes (three vertices at least): « Nouvelle zone » opens. */
|
||||
export function closeTrace(): boolean {
|
||||
const points = tracedPoints(creation())
|
||||
if (!points || points.length < 3) return false
|
||||
patch({ closed: true, dialog: true })
|
||||
return true
|
||||
}
|
||||
|
||||
/** « Reprendre le tracé »: the dialog hides, the vertices and the form are kept. */
|
||||
export function resumeTrace(): void {
|
||||
patch({ closed: false, dialog: false, resumed: true })
|
||||
}
|
||||
|
||||
/** « Replacer le point »: the dialog hides; the next click moves the ghost. */
|
||||
export function replacePoint(): void {
|
||||
patch({ dialog: false, resumed: true })
|
||||
}
|
||||
|
||||
/** « Revenir aux propriétés »: a resumed tracing closes again, a point shows its dialog. */
|
||||
export function backToProperties(): boolean {
|
||||
const work = creation()
|
||||
if (!work) return false
|
||||
if (work.closed) {
|
||||
patch({ dialog: true })
|
||||
return true
|
||||
}
|
||||
return closeTrace()
|
||||
}
|
||||
|
||||
export function patchForm(change: Partial<CreationForm>): void {
|
||||
const work = creation()
|
||||
if (work) patch({ form: { ...work.form, ...change } })
|
||||
}
|
||||
|
||||
/** Candidate C offered by the core's verdict (C26), or withdrawn. */
|
||||
export function setCorrection(correction: Correction | null): void {
|
||||
const work = creation()
|
||||
if (work) patch({ pending: { ...work.pending, correction } })
|
||||
}
|
||||
|
||||
/** « Abandonner », or a guard's « Abandonner »: nothing of the creation is left. */
|
||||
export function dropCreation(): void {
|
||||
useAnnotationWork.setState({ creation: null })
|
||||
}
|
||||
|
||||
/** « Créer » succeeded: the creation ends, the drawing selects `id` (A7). */
|
||||
export function finishCreation(id: string, kind: NewKind): void {
|
||||
useAnnotationWork.setState({ creation: null, created: { id, kind } })
|
||||
}
|
||||
|
||||
/** The open tracing of a new shape on `viewId`, as the drawing reads a tracing. */
|
||||
export function creationTracing(
|
||||
work: Creation | null,
|
||||
viewId: string,
|
||||
): Tracing | null {
|
||||
const points = tracedPoints(work)
|
||||
if (!work || !points || work.viewId !== viewId) return null
|
||||
return {
|
||||
target: work.pending.kind,
|
||||
annotationId: null,
|
||||
points,
|
||||
refused: false,
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@/editor/focusRequest'
|
||||
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { askCreation } from './creationAsk'
|
||||
import { commitFocusedSeries } from './drawingGuard'
|
||||
import { escapeAction, type EscapeAction } from './escape'
|
||||
import { endMode, useAnnotationWork } from './workStore'
|
||||
@@ -121,8 +122,9 @@ function runEscape(action: EscapeAction, deselect: () => boolean): boolean {
|
||||
else if (action === 'drop_mode') endMode()
|
||||
else if (action === 'unchoose') useAnnotationWork.setState({ chosen: null })
|
||||
else if (action === 'deselect') return deselect()
|
||||
// `ask_creation`: the creation dialog asks (U2 Task 7); nothing here yet.
|
||||
return action !== null && action !== 'ask_creation'
|
||||
// The dialog hidden (a tracing, a point being replaced): « Abandonner la création ? ».
|
||||
else if (action === 'ask_creation') askCreation()
|
||||
return action !== null
|
||||
}
|
||||
|
||||
/** Where Escape applies: the editable body runs the work order; the read-only twin deselects. */
|
||||
|
||||
@@ -28,21 +28,30 @@ function endModeOnly(): void {
|
||||
* (false).
|
||||
*/
|
||||
export function guardDrawing(proceed: () => void): boolean {
|
||||
const work = guardWork(useAnnotationWork.getState())
|
||||
const state = useAnnotationWork.getState()
|
||||
const work = guardWork(state)
|
||||
if (work === null) {
|
||||
commitFocusedSeries()
|
||||
endModeOnly()
|
||||
return true
|
||||
}
|
||||
useAnnotationWork.setState({ question: { work, proceed } })
|
||||
// A question already open keeps its own move (a Back over it is not replayed).
|
||||
if (state.question === null) {
|
||||
useAnnotationWork.setState({ question: { work, proceed } })
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** « Continuer » keeps the work as it is; « Abandonner » drops it and makes the move. */
|
||||
/**
|
||||
* « Continuer » keeps the work as it is; « Abandonner » drops the work the question
|
||||
* named (the mode, or the whole creation) and makes the move.
|
||||
*/
|
||||
export function answerDrawing(discard: boolean): void {
|
||||
const { question } = useAnnotationWork.getState()
|
||||
useAnnotationWork.setState({ question: null })
|
||||
if (!discard || !question) return
|
||||
endMode()
|
||||
if (question.work === 'creation')
|
||||
useAnnotationWork.setState({ creation: null })
|
||||
else endMode()
|
||||
question.proceed()
|
||||
}
|
||||
@@ -35,13 +35,13 @@ export interface DrawingState {
|
||||
}
|
||||
|
||||
const BUSY_TARGET = {
|
||||
creation: '[data-creation-heading]',
|
||||
creation: '[data-creation-focus]',
|
||||
tracing: '[data-testid="tracing-commands"]',
|
||||
} as const
|
||||
|
||||
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
|
||||
|
||||
/** A creation or tracing in progress keeps the request: focus its panel, say why. */
|
||||
/** A creation or tracing in progress keeps the request: focus its dialog or the strip, say why. */
|
||||
function keepBusy(
|
||||
busy: NonNullable<DrawingState['busy']>,
|
||||
announce: (text: string) => void,
|
||||
|
||||
@@ -10,7 +10,8 @@ import type { Locale } from '@/i18n/types'
|
||||
import { pluralKey } from '../plural'
|
||||
import type { PendingElement } from './creation'
|
||||
import { HANDLE_CAP } from './polygonEdit'
|
||||
import type { ToolId, Tracing, UiState } from './uiState'
|
||||
import type { ToolId, Tracing } from './uiState'
|
||||
import type { Creation } from './workStore'
|
||||
|
||||
/** The strip's left part: what is selected or in progress, then its type and detail. */
|
||||
export interface StripLead {
|
||||
@@ -130,6 +131,27 @@ function pendingLead(pending: PendingElement, ctx: LeadContext): StripLead {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A creation whose dialog is shown or was (board 04 C): placed or closed, waiting for its
|
||||
* properties; a point being replaced says where to click; a resumed tracing says the
|
||||
* input is kept. A fresh tracing reads as a tracing.
|
||||
*/
|
||||
function creationLead(work: Creation, ctx: LeadContext): StripLead | null {
|
||||
const { pending } = work
|
||||
const title = ctx.t(`editor.annotations.new.${pending.kind}`)
|
||||
const icon = ICON[pending.kind]
|
||||
if (work.closed && !work.dialog && pending.geometry.type === 'circle') {
|
||||
return {
|
||||
title,
|
||||
detail: ctx.t('editor.annotations.strip.place_point'),
|
||||
icon,
|
||||
}
|
||||
}
|
||||
if (work.closed) return pendingLead(pending, ctx)
|
||||
if (!work.resumed) return null
|
||||
return { title, detail: ctx.t('editor.annotations.strip.resumed'), icon }
|
||||
}
|
||||
|
||||
const TOOL_LEAD: Record<
|
||||
ToolId,
|
||||
{ title: string; detail: string; icon: GlyphName }
|
||||
@@ -156,14 +178,22 @@ const TOOL_LEAD: Record<
|
||||
},
|
||||
}
|
||||
|
||||
/** What the strip reads of the drawing: the tool, the tracing shown, the creation. */
|
||||
export interface LeadState {
|
||||
tool: ToolId
|
||||
tracing: Tracing | null
|
||||
creation?: Creation | null
|
||||
}
|
||||
|
||||
/** What the strip leads with: a creation, then a tracing, then the selection, then the tool. */
|
||||
export function stripLeadOf(
|
||||
ui: UiState,
|
||||
ui: LeadState,
|
||||
selected: Annotation | undefined,
|
||||
doc: AnatomicalSheetDocument,
|
||||
ctx: LeadContext,
|
||||
): StripLead {
|
||||
if (ui.pending) return pendingLead(ui.pending, ctx)
|
||||
const creation = ui.creation ? creationLead(ui.creation, ctx) : null
|
||||
if (creation) return creation
|
||||
if (ui.tracing) {
|
||||
const replaced = doc.annotations.find(
|
||||
(a) => a.id === ui.tracing?.annotationId,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import type { Point } from '@faunosteo/core-wasm/types'
|
||||
import type { NewKind, PendingElement } from './creation'
|
||||
import type { NewKind } from './creation'
|
||||
|
||||
export type ToolId = 'select' | 'point' | 'zone' | 'link'
|
||||
|
||||
/** A tracing in progress: a new zone or link, or a polygon replacing a geometry. */
|
||||
/**
|
||||
* A tracing in progress: a new zone or link, or a polygon replacing a geometry. Only a
|
||||
* redraw's tracing is the reducer's; a new shape's lives in the creation (work store).
|
||||
*/
|
||||
export interface Tracing {
|
||||
target: NewKind | 'replace'
|
||||
/** The annotation whose geometry the tracing replaces (target `replace`). */
|
||||
@@ -17,9 +20,6 @@ export interface UiState {
|
||||
viewId: string | null
|
||||
tool: ToolId
|
||||
selectedId: string | null
|
||||
pending: PendingElement | null
|
||||
/** Bumped by every new pending element: keys the creation form's own state. */
|
||||
serial: number
|
||||
tracing: Tracing | null
|
||||
hint: string | null
|
||||
/** The overview's « Filtrer par nom » term: it outlives a selection, not a view. */
|
||||
@@ -32,9 +32,6 @@ export type UiAction =
|
||||
| { type: 'view'; viewId: string }
|
||||
| { type: 'tool'; tool: ToolId }
|
||||
| { type: 'select'; id: string | null }
|
||||
| { type: 'pending_new'; pending: PendingElement }
|
||||
| { type: 'pending_update'; pending: PendingElement }
|
||||
| { type: 'pending_drop' }
|
||||
| { type: 'trace_start'; target: Tracing['target']; annotationId?: string }
|
||||
| { type: 'trace_add'; point: Point }
|
||||
| { type: 'trace_pop' }
|
||||
@@ -48,8 +45,6 @@ export const initialUi: UiState = {
|
||||
viewId: null,
|
||||
tool: 'select',
|
||||
selectedId: null,
|
||||
pending: null,
|
||||
serial: 0,
|
||||
tracing: null,
|
||||
hint: null,
|
||||
filter: '',
|
||||
@@ -88,32 +83,13 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
|
||||
...state,
|
||||
tool: toolAfterTracing(state),
|
||||
selectedId: action.id,
|
||||
pending: null,
|
||||
tracing: null,
|
||||
hint: null,
|
||||
}
|
||||
case 'pending_new':
|
||||
return {
|
||||
...state,
|
||||
pending: action.pending,
|
||||
// A second click with the same kind keeps the typed fields (same panel).
|
||||
serial:
|
||||
state.pending?.kind === action.pending.kind
|
||||
? state.serial
|
||||
: state.serial + 1,
|
||||
selectedId: null,
|
||||
tracing: null,
|
||||
hint: null,
|
||||
}
|
||||
case 'pending_update':
|
||||
return state.pending ? { ...state, pending: action.pending } : state
|
||||
case 'pending_drop':
|
||||
return { ...state, pending: null, hint: null }
|
||||
case 'trace_start':
|
||||
return {
|
||||
...state,
|
||||
tool: TOOL_OF[action.target],
|
||||
pending: null,
|
||||
hint: null,
|
||||
tracing: {
|
||||
target: action.target,
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { useEffect, useRef, type Dispatch } from 'react'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import { landAfterModalsClosed } from '@/components/ui/afterModalsClosed'
|
||||
import type { NewKind } from './creation'
|
||||
import { dropCreation } from './creationWork'
|
||||
import { focusRowOrDrawing } from './deselect'
|
||||
import type { ToolId, UiAction, UiState } from './uiState'
|
||||
import type { GestureMessages } from './useGestureMessage'
|
||||
import { useAnnotationWork, type Creation } from './workStore'
|
||||
|
||||
const TOOL_OF: Record<NewKind, ToolId> = {
|
||||
point: 'point',
|
||||
zone: 'zone',
|
||||
detail_trigger: 'link',
|
||||
}
|
||||
|
||||
export interface CreationFollow {
|
||||
doc: AnatomicalSheetDocument
|
||||
ui: UiState
|
||||
dispatch: Dispatch<UiAction>
|
||||
creation: Creation | null
|
||||
message: Pick<GestureMessages, 'show'>
|
||||
t: (key: string) => string
|
||||
}
|
||||
|
||||
/**
|
||||
* The drawing kept in step with the creation: nothing selected once its shape is placed, its tool
|
||||
* on while the dialog is hidden (« Replacer le point » places with the point tool, a
|
||||
* resumed tracing traces), and dropped when its view no longer exists.
|
||||
*/
|
||||
function useDrawingFollows({ doc, ui, dispatch, creation }: CreationFollow) {
|
||||
const wanted =
|
||||
creation && !creation.dialog ? TOOL_OF[creation.pending.kind] : null
|
||||
// A placed or closed shape takes the stage; a fresh tracing keeps the selection under
|
||||
// it, as before, so abandoning it gives the selection back.
|
||||
const selected = creation?.closed === true && ui.selectedId !== null
|
||||
const gone =
|
||||
creation !== null && !doc.views.some((v) => v.id === creation.viewId)
|
||||
useEffect(() => {
|
||||
if (wanted && wanted !== ui.tool) dispatch({ type: 'tool', tool: wanted })
|
||||
}, [wanted, ui.tool, dispatch])
|
||||
useEffect(() => {
|
||||
if (selected) dispatch({ type: 'select', id: null })
|
||||
}, [selected, dispatch])
|
||||
useEffect(() => {
|
||||
if (gone) dropCreation()
|
||||
}, [gone])
|
||||
}
|
||||
|
||||
/**
|
||||
* « Créer » succeeded (A7): the tool goes back to « Sélectionner », the new annotation is
|
||||
* selected, the line under the drawing says « Point créé · Défaire » and the focus goes to
|
||||
* its row once the dialog has closed (board 32).
|
||||
*/
|
||||
function useCreatedFollows({ dispatch, message, t }: CreationFollow) {
|
||||
const created = useAnnotationWork((s) => s.created)
|
||||
const latest = useRef({ message, t })
|
||||
latest.current = { message, t }
|
||||
useEffect(() => {
|
||||
if (!created) return
|
||||
useAnnotationWork.setState({ created: null })
|
||||
dispatch({ type: 'tool', tool: 'select' })
|
||||
dispatch({ type: 'select', id: created.id })
|
||||
const text = latest.current.t(
|
||||
`editor.annotations.message.created.${created.kind}`,
|
||||
)
|
||||
latest.current.message.show(text, { undo: true, tone: 'info' })
|
||||
landAfterModalsClosed(() => void focusRowOrDrawing(created.id))
|
||||
}, [created, dispatch])
|
||||
}
|
||||
|
||||
export function useCreationFollow(input: CreationFollow): void {
|
||||
useDrawingFollows(input)
|
||||
useCreatedFollows(input)
|
||||
}
|
||||
@@ -7,7 +7,15 @@ import type {
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { updateGeometry, type CommitContext } from './annotationCommit'
|
||||
import { pendingForClick, type NewKind } from './creation'
|
||||
import { emptyForm, pendingForClick, type NewKind } from './creation'
|
||||
import {
|
||||
closeTrace,
|
||||
placePending,
|
||||
popVertex,
|
||||
traceVertex,
|
||||
type CreationStart,
|
||||
} from './creationWork'
|
||||
import { askCreation } from './creationAsk'
|
||||
import { round2, type Frame, type XY } from './frame'
|
||||
import { newPointSize } from './pointSize'
|
||||
import { endMode, useAnnotationWork } from './workStore'
|
||||
@@ -22,6 +30,8 @@ const TOOL_TARGET: Record<Exclude<ToolId, 'select'>, NewKind> = {
|
||||
|
||||
export interface PlacementInput {
|
||||
ui: UiState
|
||||
/** The tracing shown: a redraw's (the reducer's) or a new shape's (the creation's). */
|
||||
tracing: Tracing | null
|
||||
dispatch: Dispatch<UiAction>
|
||||
frame: Frame | null
|
||||
doc: AnatomicalSheetDocument
|
||||
@@ -64,44 +74,52 @@ function closeRedraw(input: PlacementInput, tracing: Tracing): void {
|
||||
input.message.show(text, { undo: true, tone: 'info' })
|
||||
}
|
||||
|
||||
/** Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. */
|
||||
/** Where a creation on this view starts: F, the origin, a fresh form (A4). */
|
||||
export const creationStart = (
|
||||
{ viewId, frame, doc }: Pick<PlacementInput, 'viewId' | 'frame' | 'doc'>,
|
||||
origin: CreationStart['origin'],
|
||||
): CreationStart => ({ viewId, frame, origin, form: emptyForm(doc) })
|
||||
|
||||
const isRedraw = (tracing: Tracing | null) => tracing?.target === 'replace'
|
||||
|
||||
/**
|
||||
* Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. A
|
||||
* redraw's tracing is the reducer's; a new shape's is the creation's (A12): its Escape
|
||||
* asks « Abandonner la création ? » (board 32 row 3).
|
||||
*/
|
||||
function tracingActions(input: PlacementInput) {
|
||||
const { ui, dispatch } = input
|
||||
const { tracing, dispatch } = input
|
||||
const closeTracing = () => {
|
||||
const tracing = ui.tracing
|
||||
if (!tracing || tracing.points.length < 3) return
|
||||
if (tracing.target === 'replace') return closeRedraw(input, tracing)
|
||||
const pending = {
|
||||
kind: tracing.target,
|
||||
geometry: { type: 'polygon' as const, points: tracing.points },
|
||||
}
|
||||
dispatch({ type: 'pending_new', pending })
|
||||
if (isRedraw(tracing)) return closeRedraw(input, tracing)
|
||||
closeTrace()
|
||||
}
|
||||
const trace = (
|
||||
tool: Exclude<ToolId, 'select' | 'point'>,
|
||||
at: XY,
|
||||
reach: number,
|
||||
) => {
|
||||
if (ui.tracing && nearFirstVertex(ui.tracing, at, reach)) {
|
||||
return closeTracing()
|
||||
}
|
||||
if (!ui.tracing)
|
||||
dispatch({ type: 'trace_start', target: TOOL_TARGET[tool] })
|
||||
dispatch({ type: 'trace_add', point: asPoint(at) })
|
||||
if (tracing && nearFirstVertex(tracing, at, reach)) return closeTracing()
|
||||
if (isRedraw(tracing))
|
||||
return dispatch({ type: 'trace_add', point: asPoint(at) })
|
||||
traceVertex(creationStart(input, 'tool'), TOOL_TARGET[tool], asPoint(at))
|
||||
}
|
||||
const pop = () =>
|
||||
isRedraw(tracing) ? dispatch({ type: 'trace_pop' }) : popVertex()
|
||||
const onTraceKey = (event: KeyboardEvent) => {
|
||||
if (!ui.tracing) return
|
||||
if (!tracing) return
|
||||
if (event.key === 'Enter') closeTracing()
|
||||
if (event.key === 'Backspace') {
|
||||
event.preventDefault()
|
||||
dispatch({ type: 'trace_pop' })
|
||||
pop()
|
||||
}
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault()
|
||||
dispatch({ type: 'trace_cancel' })
|
||||
if (isRedraw(tracing)) dispatch({ type: 'trace_cancel' })
|
||||
else askCreation()
|
||||
}
|
||||
}
|
||||
return { closeTracing, trace, onTraceKey }
|
||||
return { closeTracing, trace, onTraceKey, pop }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +192,8 @@ export function usePlacement(input: PlacementInput) {
|
||||
const size = newPointSize(doc.annotations, viewId, frame, ui.size)
|
||||
const outcome = pendingForClick(frame, at, size)
|
||||
if (outcome.kind === 'pending') {
|
||||
return dispatch({ type: 'pending_new', pending: outcome.pending })
|
||||
dispatch({ type: 'hint', hint: null })
|
||||
return placePending(creationStart(input, 'tool'), outcome.pending)
|
||||
}
|
||||
dispatch({ type: 'hint', hint: t('editor.annotations.outside') })
|
||||
}
|
||||
@@ -183,6 +202,6 @@ export function usePlacement(input: PlacementInput) {
|
||||
onDrop: dropAction(input),
|
||||
onTraceKey: tracing.onTraceKey,
|
||||
closeTracing: tracing.closeTracing,
|
||||
popVertex: () => dispatch({ type: 'trace_pop' }),
|
||||
popVertex: tracing.pop,
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { create } from 'zustand'
|
||||
import type { Geometry } from '@faunosteo/core-wasm/types'
|
||||
import type { CreationForm, PendingElement } from './creation'
|
||||
import type { CreationForm, NewKind, PendingElement } from './creation'
|
||||
import type { Frame } from './frame'
|
||||
|
||||
/** A geometry shown but not committed, stamped with the document text it was computed on. */
|
||||
export interface Preview {
|
||||
@@ -14,13 +15,29 @@ export interface Chosen {
|
||||
vertex: number
|
||||
base: string
|
||||
}
|
||||
/**
|
||||
* A creation in progress (A12): the only owner of the new shape and of its form, read by
|
||||
* the drawing and by the creation dialog, which lives outside the edit-only body (R-14).
|
||||
*/
|
||||
export interface Creation {
|
||||
viewId: string
|
||||
/** F of the view when the shape was placed: the point's verdict works from it. */
|
||||
frame: Frame | null
|
||||
/** A tool on the drawing, or a keyboard « Ajouter … » (where the focus goes back). */
|
||||
origin: 'tool' | 'keyboard'
|
||||
/** 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
|
||||
/** The dialog was shown once: « Replacer le point » or « Reprendre le tracé » ran. */
|
||||
resumed: boolean
|
||||
}
|
||||
/** The annotation « Créer » just inserted: the drawing selects it and says so (A7). */
|
||||
export interface Created {
|
||||
id: string
|
||||
kind: NewKind
|
||||
}
|
||||
/**
|
||||
* A move mode or a redraw, stamped with the document text it started on; `started` once
|
||||
@@ -42,6 +59,7 @@ export interface DrawingQuestion {
|
||||
}
|
||||
interface Work {
|
||||
creation: Creation | null
|
||||
created: Created | null
|
||||
mode: ModeWork | null
|
||||
preview: Preview | null
|
||||
chosen: Chosen | null
|
||||
@@ -51,6 +69,7 @@ interface Work {
|
||||
}
|
||||
const NO_WORK: Work = {
|
||||
creation: null,
|
||||
created: null,
|
||||
mode: null,
|
||||
preview: null,
|
||||
chosen: null,
|
||||
|
||||
Reference in new issue
Block a user