diff --git a/apps/app/src/components/editor/annotations/AccessCommands.tsx b/apps/app/src/components/editor/annotations/AccessCommands.tsx new file mode 100644 index 00000000..67a9fad8 --- /dev/null +++ b/apps/app/src/components/editor/annotations/AccessCommands.tsx @@ -0,0 +1,84 @@ +import Button from '@/components/ui/Button' +import { useT } from '@/i18n/useT' +import EditorGlyph from '../EditorGlyph' +import { PropertiesButton } from './SelectionCommands' + +const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9' + +export interface AccessCommandsProps { + onOpen?: (button: HTMLElement) => void + onRecrop?: (button: HTMLElement) => void + onMove?: () => void + onRedraw?: () => void + onProperties?: () => void +} + +/** + * The strip's commands of a selected access (A2, D14): « Ouvrir la vue », « Recadrer la + * vue », « Déplacer l'accès », « Redessiner » for a polygon, « Propriétés » (deletion + * stays there). A command whose handler is absent is not rendered, so each task that + * wires one leaves a working strip. + */ +export default function AccessCommands({ + onOpen, + onRecrop, + onMove, + onRedraw, + onProperties, +}: AccessCommandsProps) { + const t = useT() + return ( + <> + {onOpen && ( + + )} + {onRecrop && ( + + )} + {onMove && ( + + )} + {onRedraw && ( + + )} + {onProperties && } + + ) +} diff --git a/apps/app/src/components/editor/annotations/SceneStrip.tsx b/apps/app/src/components/editor/annotations/SceneStrip.tsx index 0ceb76d3..845ab40d 100644 --- a/apps/app/src/components/editor/annotations/SceneStrip.tsx +++ b/apps/app/src/components/editor/annotations/SceneStrip.tsx @@ -20,6 +20,7 @@ import { useT } from '@/i18n/useT' import { useLocaleStore } from '@/state/localeStore' import type { Scene, Work } from './EditableAnnotations' import AccessShapeChoice from './AccessShapeChoice' +import AccessCommands from './AccessCommands' import CreationCommands from './CreationCommands' import EditStrip, { type StripNotice } from './EditStrip' import { @@ -29,6 +30,7 @@ import { useModeFocusReturn, } from './PointCommands' import FrameCommands from './FrameCommands' +import MoveModeBar from './MoveModeBar' import SelectionCommands from './SelectionCommands' import TracingCommands from './TracingCommands' import ViewCommands from './ViewCommands' @@ -115,6 +117,7 @@ function commandsKeyOf( if (creation?.resumed) return `creation-${creation.pending.geometry.type}` if (tracing) return 'tracing' if (moving) return 'move' + if (showsAccessCommands(target, chosen)) return 'access' if (target?.geometry?.type === 'polygon') return `zone-${chosen !== null}` if (target?.kind === 'point') return 'point' if (ui.selectedId !== null) return `selected-${target?.kind}` @@ -127,10 +130,59 @@ function frameKeyOf(frame: FrameWork) { return frame.box === null ? 'frame-draw' : 'frame-adjust' } +/** + * A selected access offers its own commands (A2), unless a vertex of its polygon is chosen: + * then the vertex commands show, as for a zone. + */ +function showsAccessCommands( + target: Annotation | null, + chosen: number | null, +): boolean { + if (target?.kind !== 'detail_trigger' || chosen !== null) return false + return isEditable(target.geometry) +} + +/** The access's commands, or the move mode's bar while it runs on the access. */ +function AccessStrip({ annotation, work, scene }: AccessStripProps) { + const inMode = useAnnotationWork( + (s) => s.mode?.kind === 'move' && s.mode.annotationId === annotation.id, + ) + const { edit } = work + if (inMode) { + return ( + + ) + } + const polygon = annotation.geometry?.type === 'polygon' + return ( + beginRedraw(annotation.id, scene.dispatch) : undefined + } + onProperties={() => scene.onOpen(annotation.id, 'button')} + /> + ) +} + +interface AccessStripProps { + annotation: Annotation + work: Work + scene: Scene +} + /** The selection's own commands: a polygon's, a movable point's (R-10: a link circle none). */ function ShapeCommands({ scene, work }: { scene: Scene; work: Work }) { const t = useT() const { doc, viewId, frame, dispatch, selected, model } = scene + const chosen = useChosenVertex(work.target?.id) + if (work.target && showsAccessCommands(work.target, chosen)) { + return + } if (work.target?.geometry?.type === 'polygon') { const edit = work.edit return ( @@ -207,6 +259,8 @@ function SceneCommands({ dispatch({ type: 'select', id: null }), ) const framing = useAnnotationWork((s) => s.frame) + const chosen = useChosenVertex(selected?.id) + const accessOwnsProperties = showsAccessCommands(work.target, chosen) if (framing) return // The dialog shown: its own actions; hidden after it was shown: board 04 C. if (creation?.dialog) return null @@ -249,7 +303,11 @@ function SceneCommands({ {/* During the move mode only the mode's own exits (its bar). */} {!moving && ( scene.onOpen(selected.id, 'button')} + onProperties={ + accessOwnsProperties + ? undefined + : () => scene.onOpen(selected.id, 'button') + } onDeselect={byButton} /> )} diff --git a/apps/app/src/components/editor/annotations/SelectionCommands.tsx b/apps/app/src/components/editor/annotations/SelectionCommands.tsx index c5a5e80f..909b49de 100644 --- a/apps/app/src/components/editor/annotations/SelectionCommands.tsx +++ b/apps/app/src/components/editor/annotations/SelectionCommands.tsx @@ -4,32 +4,41 @@ import EditorGlyph from '../EditorGlyph' const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9' +/** « Propriétés »: opens the dialog (A1). */ +export function PropertiesButton({ onClick }: { onClick: () => void }) { + const t = useT() + return ( + + ) +} + /** * The strip's commands of any selection, after its own (boards 33 C to E): « Propriétés » - * opens the dialog (A1), « Désélectionner » leaves the selection. + * unless the selection's own commands already hold it (an access), « Désélectionner » + * leaves the selection. */ export default function SelectionCommands({ onProperties, onDeselect, }: { - onProperties: () => void + onProperties?: () => void onDeselect: () => void }) { const t = useT() return ( <> - + {onProperties && }