diff --git a/workbench/client/src/App.tsx b/workbench/client/src/App.tsx index 53dcf45..62f8dcf 100644 --- a/workbench/client/src/App.tsx +++ b/workbench/client/src/App.tsx @@ -192,6 +192,21 @@ function App() { const segmentOf = (roadId: string) => state.compiled.model.roads.find((road) => road.id === roadId)?.segmentId; return handlesForSegment(manifest, selected?.segmentId ?? null, segmentOf); }, [editMode, manifest, selected, state]); + // JunctionTools owns the three shape constraints for an ordinary node. Keep + // the same manifest objects and callbacks as the main parameter panel so + // number entry and dragging share one preview/undo protocol. + const junctionHandles = useMemo(() => { + if (!editMode || !junctionDescriptor || junctionDescriptor.ref.type !== 'node' || !manifest) return []; + const nodeIds = new Set(junctionDescriptor.nodeIds.map(String)); + return manifest.handles.filter( + (handle) => + (handle.kind === 'junction-approach-width' || + handle.kind === 'junction-cutback' || + handle.kind === 'junction-corner-radius') && + 'nodeId' in handle.anchor && + nodeIds.has(String(handle.anchor.nodeId)), + ); + }, [editMode, junctionDescriptor, manifest]); // A greyed handle without a reason reads as a bug rather than an ownership // boundary, so the first blocked handle explains itself in the header. const blockedHandle = editHandles.find((handle) => !handle.editable); @@ -700,6 +715,14 @@ function App() { (filter === 'candidates' ? Boolean(item.manualCandidates?.length) : !item.manualCandidates?.length)), ); const openJunction = (ref: JunctionRef) => { + // Seed direct-edit selection with the first approach so the existing + // manifest request loads junction shape handles before the workspace opens. + const descriptor = state ? hotspotAt(junctionDescriptors(state), ref) : null; + const approach = descriptor?.approachRoadIds[0]; + if (approach) { + const road = state?.compiled.model.roads.find((item) => item.id === approach); + if (road) setSelected(road); + } window.history.pushState({}, '', `/junction/${ref.type}/${encodeURIComponent(ref.id)}`); setJunctionRoute(ref); }; @@ -855,8 +878,12 @@ function App() { visible={layers} scene={scene} junctionHotspots={junctionHotspots} - onJunctionHotspot={(ref: JunctionRef) => { + onJunctionHotspot={(ref: JunctionRef, _coordinate, descriptor) => { openJunction(ref); + const approachRoad = descriptor.approachRoadIds + .map((roadId) => state.compiled.model.roads.find((road) => road.id === roadId)) + .find((road): road is Road => Boolean(road)); + if (approachRoad) setSelected(approachRoad); setStatus(ref.type === 'node' ? `已定位路口节点 ${ref.id}(可编辑)` : `已定位路口 ${ref.id}(只读)`); }} onSelectRoad={setSelected} @@ -983,6 +1010,17 @@ function App() { setStatus((error as Error).message); } }} + handles={junctionHandles} + onDraft={draftValue} + onSettle={(handle, value) => { + settleValue(handle, value); + setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current)); + }} + onAbandon={abandonGesture} + onReset={(handle) => { + resetHandle(handle); + setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current)); + }} /> ) : null} diff --git a/workbench/client/src/junction/JunctionWorkspace.tsx b/workbench/client/src/junction/JunctionWorkspace.tsx index d288cd5..8699f23 100644 --- a/workbench/client/src/junction/JunctionWorkspace.tsx +++ b/workbench/client/src/junction/JunctionWorkspace.tsx @@ -2,6 +2,8 @@ import { useMemo } from 'react'; import type { JunctionDescriptor } from './hotspots'; import { canEditJunction, type JunctionSession } from './workspace'; import { Button } from '../ui/button'; +import { ParameterPanel } from '../components/ParameterPanel'; +import type { EditHandle } from '../edit/types'; interface Props { descriptor: JunctionDescriptor; @@ -10,9 +12,26 @@ interface Props { onApply: () => void; onDiscard: () => void; onSave: () => void; + handles?: EditHandle[]; + onDraft?: (handle: EditHandle, value: number) => void; + onSettle?: (handle: EditHandle, value: number) => void; + onAbandon?: () => void; + onReset?: (handle: EditHandle) => void; } -export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDiscard, onSave }: Props) { +export function JunctionWorkspace({ + descriptor, + session, + onClose, + onApply, + onDiscard, + onSave, + handles = [], + onDraft, + onSettle, + onAbandon, + onReset, +}: Props) { const editable = useMemo(() => canEditJunction(descriptor), [descriptor]); return (
@@ -41,17 +60,27 @@ export function JunctionWorkspace({ descriptor, session, onClose, onApply, onDis {editable ? ( -
- - - -
+ <> + undefined)} + onSettle={onSettle ?? (() => undefined)} + onAbandon={onAbandon ?? (() => undefined)} + onReset={onReset ?? (() => undefined)} + /> +
+ + + +
+ ) : null}