fix(app): annotations tab split, editor-wide undo keys, keyboard point fits, typed radius message
This commit is contained in:
1 parent
447d0a4272
commit
3f15762d95
25 files changed
+1398
-653
No files matched your search
@@ -62,24 +62,11 @@ export function closingActions(
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* What a click, a key or a drop does with the current tool. Every geometry it proposes is
|
||||
* arithmetic over F; the core decides at « Créer » or at the commit of an existing one.
|
||||
*/
|
||||
export function usePlacement(input: PlacementInput) {
|
||||
const t = useT()
|
||||
const { ui, dispatch, frame, doc, context } = input
|
||||
|
||||
const placePoint = (frame: Frame, at: XY) => {
|
||||
const outcome = pendingForClick(frame, at)
|
||||
if (outcome.kind === 'pending') {
|
||||
return dispatch({ type: 'pending_new', pending: outcome.pending })
|
||||
}
|
||||
dispatch({ type: 'hint', hint: t('editor.annotations.outside') })
|
||||
}
|
||||
/** Tracing with the zone and link tools: vertices, closing, Enter and Escape. */
|
||||
function tracingActions(input: PlacementInput) {
|
||||
const { ui, dispatch, frame } = input
|
||||
const closeTracing = () =>
|
||||
closingActions(ui.tracing, doc, context).forEach(dispatch)
|
||||
|
||||
closingActions(ui.tracing, input.doc, input.context).forEach(dispatch)
|
||||
const trace = (tool: Exclude<ToolId, 'select' | 'point'>, at: XY) => {
|
||||
if (!frame) return
|
||||
if (ui.tracing && nearFirstVertex(ui.tracing, at, frame)) {
|
||||
@@ -89,21 +76,48 @@ export function usePlacement(input: PlacementInput) {
|
||||
dispatch({ type: 'trace_start', target: TOOL_TARGET[tool] })
|
||||
dispatch({ type: 'trace_add', point: asPoint(at) })
|
||||
}
|
||||
const onPlace = (at: XY) => {
|
||||
if (ui.tool === 'point' && frame) placePoint(frame, at)
|
||||
else if (ui.tool === 'zone' || ui.tool === 'link') trace(ui.tool, at)
|
||||
}
|
||||
const onDrop = (id: string, geometry: Geometry) => {
|
||||
const annotation = doc.annotations.find((a) => a.id === id)
|
||||
if (!annotation) return
|
||||
const result = updateGeometry(annotation, geometry, context)
|
||||
const hint = result.ok ? null : result.messages.join(' ')
|
||||
dispatch({ type: 'hint', hint })
|
||||
}
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
const onTraceKey = (event: KeyboardEvent) => {
|
||||
if (!ui.tracing) return
|
||||
if (event.key === 'Enter') closeTracing()
|
||||
if (event.key === 'Escape') dispatch({ type: 'trace_cancel' })
|
||||
}
|
||||
return { onPlace, onDrop, onKeyDown, closeTracing }
|
||||
return { closeTracing, trace, onTraceKey }
|
||||
}
|
||||
|
||||
/** A drop commits one update; the hint holds the core's words on a refusal. */
|
||||
function dropAction(input: PlacementInput) {
|
||||
return (id: string, geometry: Geometry) => {
|
||||
const annotation = input.doc.annotations.find((a) => a.id === id)
|
||||
if (!annotation) return
|
||||
const result = updateGeometry(annotation, geometry, input.context)
|
||||
const hint = result.ok ? null : result.messages.join(' ')
|
||||
input.dispatch({ type: 'hint', hint })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What a click, a key or a drop does with the current tool. Every geometry it proposes is
|
||||
* arithmetic over F; the core decides at « Créer » or at the commit of an existing one.
|
||||
* `onTraceKey` is for the canvas viewport only (a key from a button is the button's).
|
||||
*/
|
||||
export function usePlacement(input: PlacementInput) {
|
||||
const t = useT()
|
||||
const tracing = tracingActions(input)
|
||||
const { ui, dispatch, frame } = input
|
||||
const onPlace = (at: XY) => {
|
||||
if (ui.tool === 'zone' || ui.tool === 'link')
|
||||
return tracing.trace(ui.tool, at)
|
||||
if (ui.tool !== 'point' || !frame) return
|
||||
const outcome = pendingForClick(frame, at)
|
||||
if (outcome.kind === 'pending') {
|
||||
return dispatch({ type: 'pending_new', pending: outcome.pending })
|
||||
}
|
||||
dispatch({ type: 'hint', hint: t('editor.annotations.outside') })
|
||||
}
|
||||
return {
|
||||
onPlace,
|
||||
onDrop: dropAction(input),
|
||||
onTraceKey: tracing.onTraceKey,
|
||||
closeTracing: tracing.closeTracing,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user