feat: edit road parameters by number as well as by drag
The map had one input device. A drag projects a pointer onto the manifest's axis; there was no way to state a value, read one, or withdraw one. Both channels now meet at the same three exits in App.tsx — draftValue() previews, settleValue() commits one undoable command, abandonGesture() puts the settled state back — so nothing about the constraint, the debounce or the previewSeq arbitration is implemented twice. EditSession is untouched: focus and blur land on the gesture boundary that pointerdown and pointerup already used, which is why typing 1.53 is one undo step rather than four. Three rules the two devices do not share: - Live drag values bypass React and write the input's value directly, per direct-edit-client.md §7. A layout effect re-applies them after a mid-drag preview replaces the manifest, and drops the override once the manifest reports the value the drag asked for. - Typed values out of range are refused, not clamped. A pointer cannot state an intent it never reached, so a drag clamps; typed text is an intent, and a clamped typo reads as a plausible value that can go unnoticed. The offered extremes round inward — a real max of 2.925 renders as 2.93 under nearest-rounding, which the range it came from would then reject. - Reset disables the constraint rather than deleting it: validateEditDocument() rejects an operation naming a constraint that is not in the document. This is the one edit a drag cannot express, since a drag can set a value but never withdraw one. Interval editing stays behind intervalEditingSupported, which is still false — compileGeometry() does not read profile.interval, and a control that changes nothing is worse than no control. The conversions are implemented and tested so the row appears when the flag flips. Probing a live manifest turned up a defect that is not from this change and is not fixed here: an edge offset advertises ±2.925 while the solver rejects past about ±1. Evidence is in the task's research/, and the requirement moved to 08-31-constraint-range-validation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5e4e42c46f
commit
1c27501534
17 files changed
+1335
-15
No files matched your search
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Download, RefreshCw, Save, Upload } from 'lucide-react';
|
||||
import { api, isVersionConflict } from './lib/api';
|
||||
import { MapCanvas } from './components/MapCanvas';
|
||||
import { ParameterPanel, type ParameterPanelHandle } from './components/ParameterPanel';
|
||||
import { directEditEnabled, intervalEditingSupported } from './edit/flag';
|
||||
import { PreviewRequester, type PreviewDraft } from './edit/preview-request';
|
||||
import { anchorSnapshotFor, constraintValueFor, draftConstraint, operationFor } from './edit/projection';
|
||||
@@ -161,6 +162,10 @@ function App() {
|
||||
const [editDiagnostics, setEditDiagnostics] = useState<EditDiagnostic[]>([]);
|
||||
const sessionRef = useRef<EditSession | null>(null);
|
||||
if (directEditEnabled && !sessionRef.current) sessionRef.current = new EditSession();
|
||||
// Per-frame drag feedback reaches the panel through this rather than through
|
||||
// state, for the same reason the ghost writes its own source: a setState on
|
||||
// every pointermove re-renders all of App.
|
||||
const panelRef = useRef<ParameterPanelHandle>(null);
|
||||
// The session is a mutable object in a ref, so React cannot see it change.
|
||||
// Bumping this after every mutation is what keeps the buttons in step with it.
|
||||
const [editRevision, setEditRevision] = useState(0);
|
||||
@@ -268,6 +273,60 @@ function App() {
|
||||
const fragment = session?.fragment();
|
||||
if (fragment) requester?.flush(fragment);
|
||||
};
|
||||
/**
|
||||
* A live value from either channel: preview it, do not commit.
|
||||
*
|
||||
* Dragging and typing differ only in how the number is made. From here down the
|
||||
* two share everything — the draft, the debounce, the previewSeq arbitration —
|
||||
* so there is one implementation rather than a parallel one per input device.
|
||||
*/
|
||||
const draftValue = (handle: EditHandle, value: number) => {
|
||||
const draft = draftFor(handle, value);
|
||||
if (draft) requester?.schedule(draft);
|
||||
};
|
||||
/** Neither channel committed: release the id and put the settled state back. */
|
||||
const abandonGesture = () => {
|
||||
gesture.current = null;
|
||||
panelRef.current?.clearLive();
|
||||
previewSession();
|
||||
};
|
||||
/** A settled value from either channel: one undoable command, or nothing. */
|
||||
const settleValue = (handle: EditHandle, value: number) => {
|
||||
const draft = draftFor(handle, value);
|
||||
if (draft) commitGesture(draft, [`constraint:${handle.handleId}`]);
|
||||
else abandonGesture();
|
||||
};
|
||||
/**
|
||||
* Reset: put a parameter back on the compiler's baseline.
|
||||
*
|
||||
* The constraint is disabled rather than removed. `validateEditDocument()`
|
||||
* rejects an operation naming a constraint that is not in the document, so a
|
||||
* deletion would have to record an operation about nothing; disabling is also
|
||||
* what design.md already sanctions for undoing saved work, and it keeps the
|
||||
* history readable. The solver skips `enabled === false` and then publishes the
|
||||
* handle without a `constraintId`, so the row reports itself unmodified again.
|
||||
*
|
||||
* This is the one edit dragging cannot express — a drag can set a value, never
|
||||
* withdraw one.
|
||||
*/
|
||||
const resetHandle = (handle: EditHandle) => {
|
||||
const base = session?.fragment();
|
||||
const constraintId = handle.constraintId;
|
||||
if (!session || !base || !constraintId) return;
|
||||
const identity = gestureIdentity();
|
||||
const operation = {
|
||||
id: identity.operationId,
|
||||
createdAt: identity.createdAt,
|
||||
constraintIds: [constraintId],
|
||||
};
|
||||
commitGesture(
|
||||
{
|
||||
constraints: base.constraints.map((item) => (item.id === constraintId ? { ...item, enabled: false } : item)),
|
||||
operations: [...base.operations.filter((item) => item.id !== operation.id), operation],
|
||||
},
|
||||
[constraintId],
|
||||
);
|
||||
};
|
||||
const undoEdit = () => {
|
||||
// A saved gesture cannot be un-applied — persisted history is append-only — so
|
||||
// it is reversed by an inverse operation, which needs its own identity.
|
||||
@@ -296,6 +355,10 @@ function App() {
|
||||
};
|
||||
const saveDirectEdits = async () => {
|
||||
if (!session) return;
|
||||
// A field still being typed in holds an uncommitted value. Blur fires before
|
||||
// click so the button press would settle it anyway, but that ordering is not
|
||||
// something to depend on for whether an edit is persisted.
|
||||
panelRef.current?.settleOpenEdit();
|
||||
const fragment = session.fragment();
|
||||
let version: number;
|
||||
try {
|
||||
@@ -493,10 +556,12 @@ function App() {
|
||||
preview={preview}
|
||||
ghostPending={session?.degraded ?? false}
|
||||
onHandleDrag={(handle, value) => {
|
||||
const draft = draftFor(handle, value);
|
||||
if (draft) requester?.schedule(draft);
|
||||
// Straight to the DOM, like the ghost writes straight to its source:
|
||||
// a per-pointermove setState re-renders this whole component.
|
||||
panelRef.current?.showLive(handle.handleId, value);
|
||||
draftValue(handle, value);
|
||||
}}
|
||||
onHandleDragEnd={(handle, value) => commitGesture(draftFor(handle, value), [`constraint:${handle.handleId}`])}
|
||||
onHandleDragEnd={settleValue}
|
||||
onHandleBlocked={(_handle, reason) => setStatus(reason)}
|
||||
onRangeDrag={(range, anchor) => {
|
||||
const draft = rangeDraftFor(range, anchor);
|
||||
@@ -514,15 +579,28 @@ function App() {
|
||||
commitGesture(draft, touched);
|
||||
}}
|
||||
/>
|
||||
<Inspector
|
||||
road={selected}
|
||||
state={state}
|
||||
staged={staged}
|
||||
marking={marking}
|
||||
stage={stage}
|
||||
status={setStatus}
|
||||
setState={setState}
|
||||
/>
|
||||
<aside className="inspector">
|
||||
{directEditEnabled ? (
|
||||
<ParameterPanel
|
||||
handles={editHandles}
|
||||
hasSelection={Boolean(selected)}
|
||||
ref={panelRef}
|
||||
onDraft={draftValue}
|
||||
onSettle={settleValue}
|
||||
onAbandon={abandonGesture}
|
||||
onReset={resetHandle}
|
||||
/>
|
||||
) : null}
|
||||
<Inspector
|
||||
road={selected}
|
||||
state={state}
|
||||
staged={staged}
|
||||
marking={marking}
|
||||
stage={stage}
|
||||
status={setStatus}
|
||||
setState={setState}
|
||||
/>
|
||||
</aside>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
@@ -609,8 +687,10 @@ function Inspector({
|
||||
};
|
||||
const signalUid = typeof marking?.signal_uid === 'string' ? marking.signal_uid : '';
|
||||
const signal = state.trafficSignals.assemblies.features.find((item) => item.properties?.signal_uid === signalUid);
|
||||
// The `.inspector` aside now belongs to the layout in `main`, so the parameter
|
||||
// panel can share the column. Same markup, one level up.
|
||||
return (
|
||||
<aside className="inspector">
|
||||
<>
|
||||
<h1>当前道路设置</h1>
|
||||
{road ? (
|
||||
<form
|
||||
@@ -762,7 +842,7 @@ function Inspector({
|
||||
)}
|
||||
</pre>
|
||||
</details>
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
function MarkingEditor({
|
||||
|
||||
Reference in new issue
Block a user