@floless/app 0.134.0 → 0.134.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +6129 -2881
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +310 -9
- package/dist/skills/steel-drawing-abbreviations/SKILL.md +18 -1
- package/dist/web/app.css +34 -8
- package/dist/web/aware.js +590 -102
- package/dist/web/commands-filter.js +82 -5
- package/dist/web/commands-shell.js +98 -11
- package/dist/web/commands-steel.js +37 -9
- package/dist/web/commands.js +4 -0
- package/dist/web/connection-review-client.js +120 -0
- package/dist/web/index.html +23 -16
- package/dist/web/instructor.js +109 -40
- package/dist/web/steel-3d-core.js +336 -3
- package/dist/web/steel-3d-view.js +923 -160
- package/dist/web/steel-canvas-guidance.js +9 -1
- package/dist/web/steel-editor.html +1408 -68
- package/dist/web/steel-filter-core.js +220 -16
- package/dist/web/steel-filter.html +1261 -50
- package/dist/web/steel-model-commands.js +23 -2
- package/dist/web/steel-model-v2-client-validation.js +6 -0
- package/dist/web/steel-model-v2-commands.js +124 -0
- package/dist/web/workspaces.js +456 -81
- package/package.json +2 -1
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
it into --shadow-lg would de-sync this one from them */
|
|
42
42
|
--backdrop:rgba(2,8,23,.62);
|
|
43
43
|
--brand-wash:rgba(59,130,246,.16); /* a selected row */
|
|
44
|
-
--brand-wash-soft:rgba(59,130,246,.12); /* a "you just navigated here" flash */
|
|
45
44
|
--brand-wash-faint:rgba(59,130,246,.08);/* an open accordion header */
|
|
46
45
|
--brand-wash-strong:rgba(59,130,246,.28);/* the .mck switch track when on */
|
|
47
46
|
--ink-max:#fff; /* the hover "brighten" one step past --text */
|
|
@@ -83,7 +82,7 @@
|
|
|
83
82
|
--shadow-xl:0 24px 70px rgba(15,23,42,.20);
|
|
84
83
|
--shadow-tip:0 8px 22px rgba(15,23,42,.14);
|
|
85
84
|
--backdrop:rgba(15,23,42,.42);
|
|
86
|
-
--brand-wash:rgba(37,99,235,.14)
|
|
85
|
+
--brand-wash:rgba(37,99,235,.14);
|
|
87
86
|
--brand-wash-faint:rgba(37,99,235,.07);--brand-wash-strong:rgba(37,99,235,.22);
|
|
88
87
|
--ink-max:#0f172a;
|
|
89
88
|
/* The ink/fill/edge swap named in :root, applied: ink is the -700/-800 stop (AA on --panel), the fill
|
|
@@ -148,7 +147,7 @@
|
|
|
148
147
|
--shadow-sm:0 2px 8px rgba(0,0,0,.45);--shadow-float:0 4px 14px rgba(0,0,0,.45);
|
|
149
148
|
--shadow-modal:0 20px 60px rgba(0,0,0,.6);--shadow-xl:0 24px 70px rgba(0,0,0,.7);
|
|
150
149
|
--shadow-tip:0 8px 22px rgba(0,0,0,.5);--backdrop:rgba(2,8,23,.62);
|
|
151
|
-
--brand-wash:rgba(59,130,246,.16)
|
|
150
|
+
--brand-wash:rgba(59,130,246,.16);
|
|
152
151
|
--brand-wash-faint:rgba(59,130,246,.08);--brand-wash-strong:rgba(59,130,246,.28);
|
|
153
152
|
--ink-max:#fff;
|
|
154
153
|
--warn:#fbbf24;--warn-soft:#fcd34d;--warn-bg:#713f12;--warn-edge:#713f12;
|
|
@@ -710,6 +709,35 @@
|
|
|
710
709
|
#moreMenu .mhint{color:var(--mut);font-size:11px;line-height:1.4;padding:4px 12px 6px;max-width:230px;white-space:normal}
|
|
711
710
|
#rfiStat{cursor:pointer;text-decoration:underline dotted} #rfiStat:hover b{color:var(--ink-max)}
|
|
712
711
|
#endsStat{color:var(--mut)} #endsStat.has{color:var(--warn)} #endsStat.has b{color:var(--warn)}
|
|
712
|
+
/* Connection review, in the header — the ONLY place the state is visible in Plan (2D), where the
|
|
713
|
+
inspector, the breadcrumb and the 3D scene all do not exist.
|
|
714
|
+
`#reviewStat` goes amber when non-zero, exactly like #endsStat. `#untrackedStat` has NO `.has` rule
|
|
715
|
+
and stays --mut at any count, deliberately: every pre-existing connection is untracked, and a legacy
|
|
716
|
+
model lighting up amber on open would teach people to ignore the colour. */
|
|
717
|
+
#reviewStat{color:var(--mut)} #reviewStat.has{color:var(--warn)} #reviewStat.has b{color:var(--warn)}
|
|
718
|
+
#untrackedStat{color:var(--mut)}
|
|
719
|
+
#reviewUnavailStat{color:var(--cyan)}
|
|
720
|
+
/* These two are real buttons rather than the plain <span>s the older stats use, because they open a
|
|
721
|
+
list and must be reachable by keyboard. The reset keeps them visually identical to their siblings. */
|
|
722
|
+
button.stat{background:none;border:0;padding:0;font:inherit;color:inherit;cursor:pointer}
|
|
723
|
+
button.stat:focus-visible{outline:2px solid var(--brand);outline-offset:2px;border-radius:3px}
|
|
724
|
+
/* The list itself borrows #selFly's recipe wholesale — same popover, new id. A capped, scrollable
|
|
725
|
+
popover hanging off a stat is not the "full review list panel" the design ruled out. */
|
|
726
|
+
#reviewFly{position:fixed;z-index:46;min-width:250px;background:var(--panel);border:1px solid var(--line);border-radius:10px;box-shadow:0 10px 30px rgba(0,0,0,.55);padding:6px;display:none}
|
|
727
|
+
#reviewFly.open{display:block}
|
|
728
|
+
#reviewFly .fhdr{display:flex;align-items:baseline;justify-content:space-between;padding:4px 8px 6px}
|
|
729
|
+
#reviewFly .fhdr b{font-size:12px;font-weight:600;letter-spacing:.02em}
|
|
730
|
+
#reviewFly .fhdr .cnt{font-size:11px;color:var(--mut);font-variant-numeric:tabular-nums}
|
|
731
|
+
#reviewFly .frow{display:flex;align-items:center;gap:9px;width:100%;padding:6px 8px;border:0;border-radius:6px;background:transparent;color:var(--text);cursor:pointer;font:13px system-ui;text-align:left}
|
|
732
|
+
#reviewFly .frow:hover{background:rgba(148,163,184,.12)}
|
|
733
|
+
#reviewFly .frow:focus-visible{outline:2px solid var(--brand);outline-offset:-2px}
|
|
734
|
+
#reviewFly .frow .nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
735
|
+
#reviewFly .frow .sub{font-size:11px;color:var(--mut);flex:none}
|
|
736
|
+
#reviewFly .fempty{padding:6px 8px;color:var(--mut);font-size:12px}
|
|
737
|
+
#reviewFly .flist{max-height:230px;overflow:auto;scrollbar-width:thin;scrollbar-color:var(--scroll) transparent}
|
|
738
|
+
#reviewFly .flist::-webkit-scrollbar{width:8px}
|
|
739
|
+
#reviewFly .flist::-webkit-scrollbar-thumb{background:var(--scroll);border-radius:4px}
|
|
740
|
+
#reviewFly .flist::-webkit-scrollbar-track{background:transparent}
|
|
713
741
|
body.member-end-review #stage{cursor:default}
|
|
714
742
|
#panel .mer-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;margin-bottom:4px}
|
|
715
743
|
#panel .mer-title{font-size:10px;font-weight:700;line-height:1.35;letter-spacing:.08em;text-transform:uppercase;color:var(--text)}
|
|
@@ -1785,6 +1813,12 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
1785
1813
|
<span class=stat id=rfiStat data-tip="Click to list members with an unresolved size (RFI — Request for Information)">RFI <b id=rc>0</b></span>
|
|
1786
1814
|
<span class=stat id=dupStat data-tip="Overlapping/duplicate members (same geometry)">Dup <b id=dpc>0</b></span>
|
|
1787
1815
|
<span class=stat id=endsStat data-tip="Member ends that may stop at a support face instead of its centerline.">Ends <b id=endsCount>—</b></span>
|
|
1816
|
+
<button data-command-id="steel.review-list" class=stat id=reviewStat data-tip="Imported connections whose steel has moved since they were placed — click to list them" aria-haspopup="true" aria-expanded="false" aria-controls="reviewFly" hidden>Review <b id=reviewCount>0</b></button>
|
|
1817
|
+
<button data-command-id="steel.untracked-list" class=stat id=untrackedStat data-tip="Imported connections that are not being watched for moved steel — click to list them" aria-haspopup="true" aria-expanded="false" aria-controls="reviewFly" hidden>Untracked <b id=untrackedCount>0</b></button>
|
|
1818
|
+
<!-- Hidden at zero rather than shown as "0", matching the readouts above: a readout that is wrong is
|
|
1819
|
+
worse than one that is absent. But BOTH hidden while the server could not derive the state would
|
|
1820
|
+
read as "all clear", so that one condition gets its own neutral marker instead of silence. -->
|
|
1821
|
+
<span class=stat id=reviewUnavailStat data-tip="The server could not check connections for moved steel this time" hidden>Review check unavailable</span>
|
|
1788
1822
|
<span class=stat id=csStat data-tip="Coordinate system — Global by default. Set a local frame from the ⋯ menu for skewed framing.">Axes <b>Global</b></span>
|
|
1789
1823
|
<span class=stat id=snapStat style="display:none" data-tip="Snap restricted for this operation — right-click the canvas to change; click here or press Esc to clear">Snap <b>—</b></span>
|
|
1790
1824
|
<span class=stat id=confStat data-tip="Confidence report — AI-read score vs. target. Click to review element evidence." style="display:none">Confidence <b id=confPct>—</b><span id=confTgt></span></span>
|
|
@@ -1845,7 +1879,7 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
1845
1879
|
to 16 — then jumped on the first drag. One authority on what a legal size is. -->
|
|
1846
1880
|
<div class=mrow><span class=mlbl>Grid label size</span><input data-command-id="steel.grid-label-size" id=gridLabelSize type=range min=14 max=48 step=1 aria-label="Grid label size in pixels" data-tip="How big the grid bubbles are drawn, in both 2D and 3D. Like a CAD drawing they hold this size on screen however far you zoom in or out."><span id=gridLabelSizeV class=mval>26 px</span></div>
|
|
1847
1881
|
<button data-command-id="steel.show-member-length" id=lenToggleB class=dtog role=menuitemcheckbox aria-checked=false data-tip="Show the length of each selected member in 2D and 3D"><span class=mck aria-hidden=true></span>Member length</button>
|
|
1848
|
-
<button data-command-id="steel.position-gizmo" id=posGizmoToggleB class=dtog role=menuitemcheckbox aria-checked=false data-tip="Show a drag handle on the selected member for
|
|
1882
|
+
<button data-command-id="steel.position-gizmo" id=posGizmoToggleB class=dtog role=menuitemcheckbox aria-checked=false data-tip="Show a drag handle on the selected member for moving it and rolling its section right in the 3D view"><span class=mck aria-hidden=true></span>Position handle</button>
|
|
1849
1883
|
<button data-command-id="steel.show-property-labels" id=plToggleB class=dtog role=menuitemcheckbox aria-checked=true data-tip="Show or hide property labels in the 2D plan (the property selection is shared with 3D — this hides them here only)"><span class=mck aria-hidden=true></span>Property labels</button>
|
|
1850
1884
|
<button data-command-id="steel.show-reference-sheet" id=refToggleB class=dtog role=menuitemcheckbox aria-checked=true data-tip="Show or hide the traced reference sheet (the PDF/SVG drawing under the model). Hidden, it also stops contributing snap points."><span class=mck aria-hidden=true></span>Reference sheet</button>
|
|
1851
1885
|
<button data-command-id="steel.grid" id=gridEditB data-tip="Grid lines — a plan reference with structural bay spacings (n*d repeats a bay). Shows in 2D and 3D; drawing and drags snap to its lines and intersections.">Grid lines…</button>
|
|
@@ -2063,6 +2097,12 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
|
|
|
2063
2097
|
</div>
|
|
2064
2098
|
</div>
|
|
2065
2099
|
<div id=selFly role=menu aria-label="Selectable types"></div>
|
|
2100
|
+
<!-- The connection-review list. One popover serves BOTH stats; its header says which list is open. -->
|
|
2101
|
+
<div id=reviewFly role=menu aria-label="Connections needing attention">
|
|
2102
|
+
<div class=fhdr><b id=reviewFlyTitle>Needs review</b><span class=cnt id=reviewFlyCount></span></div>
|
|
2103
|
+
<div class=flist id=reviewFlyList></div>
|
|
2104
|
+
<div class=fempty id=reviewFlyMore hidden></div>
|
|
2105
|
+
</div>
|
|
2066
2106
|
</div>
|
|
2067
2107
|
<div id=panelResizer role=separator aria-orientation=vertical aria-label="Resize properties panel" tabindex=0 data-tip="Drag to resize · double-click to reset"></div>
|
|
2068
2108
|
<span id=connectionTruthStatus class=sr-only role=status aria-live=polite aria-atomic=true></span>
|
|
@@ -2442,6 +2482,7 @@ let ViewGen = null; // steel-view-generation.js pure F11 helpers — loaded befo
|
|
|
2442
2482
|
let ModelCmd = null; // steel-model-commands.js — the model boundary's WRITE half (unit 5, P3a); the read half is steel-model-adapter.js
|
|
2443
2483
|
let V2Projection = null, V2Commands = null, V2Validation = null, FilterCore = null;
|
|
2444
2484
|
let PlanXf = null; // steel-plan-transform.js — the px↔world registration boundary. Already in the module graph (V2Projection imports it); named here so the classic script can read a sheet's registration angle and fit scale when it draws a rolled section footprint.
|
|
2485
|
+
let ReviewClient = null; // connection-review-client.js — how one observation of the connection review state is ordered against the one on screen, and when a refresh cycle may stop. A module because its totality has to be unit-testable; see its header.
|
|
2445
2486
|
let V2_SCHEMA = null, V2_SESSION = null, V2_PROJECTION = null;
|
|
2446
2487
|
let V2_PROJECTIONS = new Map();
|
|
2447
2488
|
let DetailRefs = null; // steel-detail-refs.js — what detail callouts a plan carries (details[] ∪ callouts[]); the ⌖ pick tool, the Connection-detail combobox and the Details list must all read the SAME answer (#397)
|
|
@@ -2497,6 +2538,42 @@ const DEFAULT_PAL=['#60a5fa','#94a3b8','#f59e0b','#34d399','#f472b6','#a78bfa','
|
|
|
2497
2538
|
// wasted traffic and makes the pill flicker in a way that reads as broken rather than informative.
|
|
2498
2539
|
let serverEtag = null;
|
|
2499
2540
|
let serverRevision = -1;
|
|
2541
|
+
/**
|
|
2542
|
+
* How many times the VISIBLE document has changed. Not a save counter — `saveSeq` already is one, and
|
|
2543
|
+
* that is exactly why it cannot serve here: `flushContract` bumps `saveSeq` as well as `scheduleSave`
|
|
2544
|
+
* does, so it counts save INTENTS, and a flush would invalidate its own capture.
|
|
2545
|
+
*
|
|
2546
|
+
* WHAT IT IS FOR. `If-Match` proves which generation the SERVER had, never which one the user LOOKED AT.
|
|
2547
|
+
* `flushContract` adopts its reply's tag unconditionally, so an edit landing mid-flight leaves
|
|
2548
|
+
* `serverEtag` naming generation A while the document on screen is B — the precondition passes and its
|
|
2549
|
+
* meaning is false, recording a human acceptance of a state nobody reviewed. That is the precise failure
|
|
2550
|
+
* the review feature exists to prevent, arriving through the one verb that grants authority.
|
|
2551
|
+
*
|
|
2552
|
+
* IT IS ONE OF THREE TRIPWIRES, DELIBERATELY, because a counter is only as total as the list of places
|
|
2553
|
+
* it is bumped from — and the first draft of that list was wrong. It had `scheduleSave` and
|
|
2554
|
+
* `installMemberEndContract` and argued a visible change that schedules no save is already a data-loss
|
|
2555
|
+
* bug. `applyRevalidation` falsifies it: it deletes joints from `C.joints`, calls `persist()` and
|
|
2556
|
+
* deliberately NOT `scheduleSave()` (the durable copy already holds the change), and it runs inside
|
|
2557
|
+
* `flushContract`'s own success branch — the very window being policed. So sign-off checks all three:
|
|
2558
|
+
*
|
|
2559
|
+
* serverEtag !== the flushed tag → some write LANDED after the flush
|
|
2560
|
+
* saveT !== null → an unsaved USER edit is pending (only scheduleSave sets it)
|
|
2561
|
+
* this counter moved → a server-applied IN-PLACE mutation neither of those can see
|
|
2562
|
+
*
|
|
2563
|
+
* Any one of them refuses. If a fourth in-place applier is ever added and nobody bumps this, the other
|
|
2564
|
+
* two still catch it, which is the property a bare counter could not offer.
|
|
2565
|
+
*
|
|
2566
|
+
* IT DELIBERATELY MOVES FOR EDITS THAT CANNOT AFFECT STEEL — a profile colour, a saved view, a label
|
|
2567
|
+
* toggle. Review raised that as over-refusal, and it is: recolouring a profile while a sign-off is in
|
|
2568
|
+
* flight refuses a physically valid review. Kept anyway, because the two errors are not symmetric. A
|
|
2569
|
+
* false refusal costs one more click and says why. A missed refusal records a human accepting steel
|
|
2570
|
+
* nobody looked at, silently, which is the single failure this feature exists to prevent. Narrowing it
|
|
2571
|
+
* would also mean maintaining a list of “geometry-relevant” edits — exactly the enumeration whose
|
|
2572
|
+
* incompleteness produced this three-tripwire design in the first place, and which would go stale with
|
|
2573
|
+
* nothing to notice. The window is one round trip wide.
|
|
2574
|
+
*/
|
|
2575
|
+
let modelEditGeneration = 0;
|
|
2576
|
+
const bumpModelEditGeneration = () => { modelEditGeneration++; };
|
|
2500
2577
|
let contractEventEpoch = 0;
|
|
2501
2578
|
let contractEventReady = false;
|
|
2502
2579
|
let contractEventWatermark = null;
|
|
@@ -2506,13 +2583,38 @@ const CONTRACT_EVENT_BOOTSTRAP_ATTEMPTS = 3;
|
|
|
2506
2583
|
const CONTRACT_EVENT_BOOTSTRAP_RETRY_MS = 250;
|
|
2507
2584
|
|
|
2508
2585
|
function contractEventMatches(m){return m&&typeof m==='object'&&m.type==='contract-changed'&&m.appId===APP_ID&&((m.project||'')===PROJECT);}
|
|
2586
|
+
/* ── The connection review watermark ───────────────────────────────────────────────────────────────
|
|
2587
|
+
A SECOND, independent watermark beside serverRevision, because a sign-off deliberately moves neither
|
|
2588
|
+
the contract ETag nor the store revision (design §6.3) — so every ordering rule above, which keys on
|
|
2589
|
+
storeRevision and suppresses anything that did not increase, would discard it as a duplicate.
|
|
2590
|
+
|
|
2591
|
+
What is ordered is the PAIR (storeRevision, reviewRevision). The revision alone cannot do it: it moves
|
|
2592
|
+
only when the sidecar rows change, while the summary is derived from live geometry, so an ordinary
|
|
2593
|
+
member move changes what the summary says without moving the revision at all. The comparison itself
|
|
2594
|
+
lives in connection-review-client.js so its totality can be unit-tested — five drafts of this rule had
|
|
2595
|
+
a case fall through during plan review.
|
|
2596
|
+
|
|
2597
|
+
A review frame is a SEPARATE type and takes a SEPARATE buffer slot: contractEventWatermark is keyed on
|
|
2598
|
+
a storeRevision that a review frame does not carry, so one slot would let the two evict each other. */
|
|
2599
|
+
let reviewAt = { storeRevision: -1, reviewRevision: -1 }; // the pair currently on screen
|
|
2600
|
+
let reviewSummary = null; // the last installed summary, or null before boot
|
|
2601
|
+
let reviewUnavailable = false; // the server could not derive it — a presentation, never silence
|
|
2602
|
+
let reviewEventWatermark = null; // a review frame that arrived before the tab was ready
|
|
2603
|
+
let reviewCycle = null; // the in-flight refresh: { bounds, attempts, late }
|
|
2604
|
+
function reviewEventMatches(m){return m&&typeof m==='object'&&m.type==='review-changed'&&m.appId===APP_ID&&((m.project||'')===PROJECT);}
|
|
2605
|
+
function reviewFrameOrderable(m){return Number.isSafeInteger(m.reviewRevision)&&m.reviewRevision>=0;}
|
|
2509
2606
|
function editorHasUnsavedWork(){const sv=document.getElementById('saveStat');return !!sv&&(sv.classList.contains('dirty')||sv.classList.contains('err')||sv.classList.contains('conflict'));}
|
|
2510
2607
|
function parkDraftForExternalChange(){const parked=flushLocalDraft?flushLocalDraft():false;if(!parked)console.warn('steel-editor: pending edits could not be parked before an external model update');return parked;}
|
|
2511
2608
|
function handleContractChanged(m){
|
|
2512
2609
|
if(!contractEventMatches(m))return;
|
|
2513
2610
|
if(!Number.isSafeInteger(m.storeRevision)||m.storeRevision<0||typeof m.etag!=='string'){console.warn('steel-editor: ignored an unorderable contract event');return;}
|
|
2514
2611
|
const own=m.mutationId?ownWrites.indexOf(m.mutationId):-1;
|
|
2515
|
-
|
|
2612
|
+
/* THE TAB'S OWN WRITE. It is suppressed for contract purposes — but the review summary still has to be
|
|
2613
|
+
re-read, and this is the trigger that makes the feature work at all: an ordinary member move can flip
|
|
2614
|
+
a connection from clean to needs-review WITHOUT touching the sidecar, so no `review-changed` is
|
|
2615
|
+
emitted and reviewRevision does not move. Nothing else would ever ask. In Plan view, where the 3D
|
|
2616
|
+
scene does not exist, this is the only path that keeps the count honest. */
|
|
2617
|
+
if(own>=0){const newest=own===ownWrites.length-1;ownWrites.splice(0,own+1);if(newest&&m.storeRevision>serverRevision){const prev=serverEtag;serverEtag=m.etag;serverRevision=m.storeRevision;restampDraftBase(prev,m.etag);}reviewRefreshForOwnWrite();return;}
|
|
2516
2618
|
if(m.storeRevision<=serverRevision)return;
|
|
2517
2619
|
if(window.invalidateMemberEndReview)window.invalidateMemberEndReview('The model changed — check member ends again.');
|
|
2518
2620
|
if(editorHasUnsavedWork()){
|
|
@@ -2526,6 +2628,120 @@ function bufferContractEvent(m){
|
|
|
2526
2628
|
if(!contractEventWatermark||m.storeRevision>=contractEventWatermark.storeRevision)contractEventWatermark=m;
|
|
2527
2629
|
}
|
|
2528
2630
|
function drainContractEvents(epoch){if(epoch!==contractEventEpoch||!contractEventReady)return;const row=contractEventWatermark;contractEventWatermark=null;if(row)handleContractChanged(row);}
|
|
2631
|
+
/* The review buffer's own drain. A SIBLING of drainContractEvents rather than a line inside it: the two
|
|
2632
|
+
watermarks are independent all the way down, and keeping the drains separate means neither function
|
|
2633
|
+
carries the other's state — which is also what lets each be lifted and tested in isolation. */
|
|
2634
|
+
function drainReviewEvents(epoch){if(epoch!==contractEventEpoch||!contractEventReady)return;const row=reviewEventWatermark;reviewEventWatermark=null;if(row)handleReviewChanged(row);}
|
|
2635
|
+
/* Install one observation, or say why not. The ONLY place the watermark moves.
|
|
2636
|
+
Returns 'installed' | 'recovered' | 'noop' | 'unavailable' | 'rejected' | 'stale', or the shape name
|
|
2637
|
+
('dominated' | 'incomparable') when the caller must reconcile. */
|
|
2638
|
+
function installReviewSummary(summary,storeRevision,epoch){
|
|
2639
|
+
if(epoch!==contractEventEpoch)return 'stale';
|
|
2640
|
+
/* `signedOff` is checked like its two siblings, and its absence is a REJECTION rather than a shrug.
|
|
2641
|
+
The server always sends it — the unavailable path sends an empty one deliberately — so a summary
|
|
2642
|
+
without it is a protocol violation. Accepting one looked harmless and was not: `reviewSignedOff`
|
|
2643
|
+
would answer false for everything, so every ✓ chip and every Reopen button would vanish model-wide,
|
|
2644
|
+
silently, and the user who had just signed off would be shown "Imported geometry" instead. Rejecting
|
|
2645
|
+
routes it to the reconciliation path, which says "unavailable" out loud. (Found by review.) */
|
|
2646
|
+
if(!ReviewClient||!summary||!Array.isArray(summary.needsReview)||!Array.isArray(summary.untracked)
|
|
2647
|
+
||!Array.isArray(summary.signedOff)
|
|
2648
|
+
||!Number.isSafeInteger(storeRevision)||!Number.isSafeInteger(summary.reviewRevision)){
|
|
2649
|
+
console.warn('steel-editor: ignored an unorderable review summary');return 'rejected';}
|
|
2650
|
+
/* -1 is the server saying it could not derive this AT ALL (§2.3). A presentation, never a generation:
|
|
2651
|
+
it must not become the watermark, and the last valid pair is retained so a later EQUAL snapshot —
|
|
2652
|
+
the only thing a transient failure can be followed by — can clear it again. */
|
|
2653
|
+
if(ReviewClient.isUnavailableRevision(summary.reviewRevision)){reviewUnavailable=true;repaintReviewSurface();return 'unavailable';}
|
|
2654
|
+
const incoming={storeRevision,reviewRevision:summary.reviewRevision};
|
|
2655
|
+
const shape=ReviewClient.classifyReviewPair(incoming,reviewAt);
|
|
2656
|
+
if(shape==='advancing'){reviewAt=incoming;reviewSummary=summary;reviewUnavailable=false;repaintReviewSurface();return 'installed';}
|
|
2657
|
+
if(shape==='equal'){
|
|
2658
|
+
// Nothing to do in normal state — and an ordinary reconnect returns exactly this, so treating it as a
|
|
2659
|
+
// failure would paint "unavailable" over a perfectly healthy tab. While unavailable it is the recovery.
|
|
2660
|
+
if(reviewUnavailable){reviewUnavailable=false;reviewSummary=summary;repaintReviewSurface();return 'recovered';}
|
|
2661
|
+
return 'noop';}
|
|
2662
|
+
return shape;}
|
|
2663
|
+
/* One named seam for "a snapshot arrived — take its review half", used by boot and by reconnect. It
|
|
2664
|
+
exists as its own function so the reconnect reader keeps ONE review dependency rather than three, and
|
|
2665
|
+
so the project-scoped guard lives in exactly one place. */
|
|
2666
|
+
function installReviewFromSnapshot(snap,epoch){if(PROJECT&&snap&&snap.review)installReviewSummary(snap.review,snap.storeRevision,epoch);}
|
|
2667
|
+
const reviewBoundsMax=(a,b)=>({storeRevision:Math.max(a.storeRevision,b.storeRevision),reviewRevision:Math.max(a.reviewRevision,b.reviewRevision)});
|
|
2668
|
+
/* Ask for a refresh. Coalesced, and the latch is COMPOSITE: a trigger is recorded as lower bounds on
|
|
2669
|
+
BOTH axes, because the review verbs move reviewRevision while leaving storeRevision alone — a
|
|
2670
|
+
store-only latch would drop a sign-off that arrived mid-fetch and never look again. */
|
|
2671
|
+
function markReviewDirty(bounds){
|
|
2672
|
+
if(!PROJECT||!ReviewClient)return;
|
|
2673
|
+
if(!reviewCycle){reviewCycle={bounds,attempts:0,finalStarted:false,late:null};runReviewCycle(contractEventEpoch);return;}
|
|
2674
|
+
/* A trigger that lands after the final attempt has ALREADY started reading belongs to nobody: this
|
|
2675
|
+
cycle cannot go back and look again, and clearing it with this cycle would lose the event outright.
|
|
2676
|
+
It is handed to a fresh cycle instead. Termination comes from the attempt counter; not losing an
|
|
2677
|
+
update comes from this hand-off. Neither mechanism is asked to do both. */
|
|
2678
|
+
if(reviewCycle.finalStarted){reviewCycle.late=reviewCycle.late?reviewBoundsMax(reviewCycle.late,bounds):bounds;return;}
|
|
2679
|
+
reviewCycle.bounds=reviewBoundsMax(reviewCycle.bounds,bounds);}
|
|
2680
|
+
/* The whole loop is wrapped, because a throw ANYWHERE in it would leave reviewCycle non-null forever —
|
|
2681
|
+
after which markReviewDirty only ever merges bounds into a cycle that will never run again, and the
|
|
2682
|
+
counts stop updating for the rest of the session with nothing on screen to say so. That silent freeze
|
|
2683
|
+
is exactly what the unavailable presentation exists to replace, so a throw ends in unavailable. */
|
|
2684
|
+
async function runReviewCycle(epoch){
|
|
2685
|
+
try{await runReviewCycleInner(epoch);}
|
|
2686
|
+
catch(e){
|
|
2687
|
+
/* Release FIRST and unconditionally: if this handler throws, a still-held reviewCycle would freeze the
|
|
2688
|
+
surface for the session, which is the exact failure the wrapper exists to prevent. */
|
|
2689
|
+
reviewCycle=null;
|
|
2690
|
+
reviewUnavailable=true;
|
|
2691
|
+
/* And repaint in its own try, because the painter is a plausible source of the original throw — calling
|
|
2692
|
+
it again here would rethrow out of the catch and undo everything above. */
|
|
2693
|
+
try{repaintReviewSurface();}catch(_){/* the state is set; the surface will catch up on the next paint */}
|
|
2694
|
+
try{console.warn('steel-editor: the review refresh cycle failed',e&&e.message?e.message:e);}catch(_){}
|
|
2695
|
+
}}
|
|
2696
|
+
async function runReviewCycleInner(epoch){
|
|
2697
|
+
const cycle=reviewCycle;
|
|
2698
|
+
/* Clear the slot ONLY if it is still ours. An obsolete run that nulls the global unconditionally
|
|
2699
|
+
would delete a newer cycle that had already replaced it — and that newer cycle's bounds go with it,
|
|
2700
|
+
which is the lost update the hand-off exists to prevent. */
|
|
2701
|
+
const release=()=>{if(reviewCycle===cycle)reviewCycle=null;};
|
|
2702
|
+
const finish=()=>{release();const late=cycle.late;if(late)markReviewDirty(late);};
|
|
2703
|
+
while(cycle===reviewCycle){
|
|
2704
|
+
cycle.attempts++;
|
|
2705
|
+
if(cycle.attempts>=ReviewClient.REVIEW_MAX_ATTEMPTS)cycle.finalStarted=true;
|
|
2706
|
+
let snap=null;
|
|
2707
|
+
try{const res=await fetch('/api/contract/'+encodeURIComponent(APP_ID)+'/snapshot'+CONTRACT_QS);if(res.ok)snap=await res.json();}
|
|
2708
|
+
catch(e){console.warn('steel-editor: review snapshot failed',e&&e.message?e.message:e);}
|
|
2709
|
+
if(epoch!==contractEventEpoch){release();return;} // a reconnect owns the tab now; it will drain and start its own cycle
|
|
2710
|
+
const outcome=snap?installReviewSummary(snap.review,snap.storeRevision,epoch):'rejected';
|
|
2711
|
+
if(outcome==='stale'){release();return;}
|
|
2712
|
+
// Entering unavailable SETTLES the cycle. Without this the -1 sentinel (which deliberately retains the
|
|
2713
|
+
// watermark) and the bounds check spin against each other forever, hammering a server already failing.
|
|
2714
|
+
if(outcome==='unavailable'){finish();return;}
|
|
2715
|
+
if(outcome==='dominated'||outcome==='incomparable'||outcome==='rejected'){
|
|
2716
|
+
if(!cycle.finalStarted)continue; // exactly one reconciliation…
|
|
2717
|
+
reviewUnavailable=true;repaintReviewSurface();finish();return;} // …then stop, through either door
|
|
2718
|
+
const settle=ReviewClient.settleCycle({installed:reviewAt,bounds:cycle.bounds,attempts:cycle.attempts,arrivedAfterFinalAttempt:cycle.late});
|
|
2719
|
+
if(settle.retry)continue;
|
|
2720
|
+
// Advanced-but-not-far-enough is NOT a success: rendering its number as if it were leaves a confident
|
|
2721
|
+
// stale count that nothing marks and no further trigger is guaranteed to correct.
|
|
2722
|
+
if(settle.state==='unavailable'){reviewUnavailable=true;repaintReviewSurface();}
|
|
2723
|
+
finish();return;}}
|
|
2724
|
+
/* The transport lives out here; the SURFACE lives inside main(), because it needs esc/C/selIds/
|
|
2725
|
+
render()/viewMode — all of which are main()'s closure and are not visible from this scope. main()
|
|
2726
|
+
publishes the real one on window, exactly as it already does for flushContract and
|
|
2727
|
+
invalidateMemberEndReview. Before main() runs there is nothing on screen to repaint, so the
|
|
2728
|
+
no-op is correct rather than merely tolerable. */
|
|
2729
|
+
function repaintReviewSurface(){if(window.renderReviewSurface)window.renderReviewSurface();}
|
|
2730
|
+
/* The own-write trigger. The store advanced, so the DERIVED state may have changed even though the
|
|
2731
|
+
sidecar did not — ask for at least this store revision, and for no less review than already held. */
|
|
2732
|
+
/* NOT gated on reviewSummary. A boot snapshot carrying the -1 sentinel leaves it null, and gating on it
|
|
2733
|
+
there would disable the own-write trigger — the one thing that makes the feature work — for the rest of
|
|
2734
|
+
the session, with the header stuck on "unavailable" and no user action able to retry. The bounds come
|
|
2735
|
+
from serverRevision and reviewAt, both valid before any summary lands. */
|
|
2736
|
+
function reviewRefreshForOwnWrite(){if(PROJECT&&ReviewClient)markReviewDirty({storeRevision:serverRevision,reviewRevision:reviewAt.reviewRevision});}
|
|
2737
|
+
function handleReviewChanged(m){
|
|
2738
|
+
if(!reviewEventMatches(m))return;
|
|
2739
|
+
if(!reviewFrameOrderable(m)){console.warn('steel-editor: ignored an unorderable review event');return;}
|
|
2740
|
+
if(m.reviewRevision<=reviewAt.reviewRevision&&!reviewUnavailable)return; // already seen
|
|
2741
|
+
/* NEVER location.reload() here. That is handleContractChanged's answer to an external GEOMETRY change;
|
|
2742
|
+
applying it to a sign-off would throw away the user's unsaved edits because another tab clicked a
|
|
2743
|
+
button. A review generation moving is not a reason to lose work. */
|
|
2744
|
+
markReviewDirty({storeRevision:reviewAt.storeRevision,reviewRevision:m.reviewRevision});}
|
|
2529
2745
|
async function rebootstrapContractEvents(epoch,attempt=0){
|
|
2530
2746
|
if(epoch!==contractEventEpoch)return;contractEventReady=false;
|
|
2531
2747
|
try{
|
|
@@ -2542,7 +2758,10 @@ async function rebootstrapContractEvents(epoch,attempt=0){
|
|
|
2542
2758
|
showAiUpdateBanner(parked?'A newer model is available. Your edits are still here. Resolve the model update, then check member ends again.':'Live updates reconnected, but this browser could not save your edits. Copy them out before reloading.',parked?undefined:{noReload:true});
|
|
2543
2759
|
}else{location.reload();return;}
|
|
2544
2760
|
}
|
|
2545
|
-
|
|
2761
|
+
// The reconnect snapshot carries the review summary too, and installing it here is what stops a
|
|
2762
|
+
// sign-off that landed while the tab was disconnected from being invisible until an unrelated edit.
|
|
2763
|
+
installReviewFromSnapshot(snap,epoch);
|
|
2764
|
+
if(epoch!==contractEventEpoch)return;contractEventReady=true;drainContractEvents(epoch);drainReviewEvents(epoch);
|
|
2546
2765
|
}catch(e){
|
|
2547
2766
|
if(epoch!==contractEventEpoch)return;
|
|
2548
2767
|
contractEventReady=false;
|
|
@@ -2568,7 +2787,14 @@ function startContractEvents(){
|
|
|
2568
2787
|
if(!contractBootSnapshotInstalled)return;
|
|
2569
2788
|
contractEventEpoch++;contractEventReady=false;contractEventWatermark=null;rebootstrapContractEvents(contractEventEpoch);
|
|
2570
2789
|
};
|
|
2571
|
-
source.onmessage=e=>{if(source!==contractEventSource)return;let m;try{m=JSON.parse(e.data);}catch{return;}
|
|
2790
|
+
source.onmessage=e=>{if(source!==contractEventSource)return;let m;try{m=JSON.parse(e.data);}catch{return;}
|
|
2791
|
+
/* Two frame types, two paths, and they must not cross: a review frame carries no storeRevision, so
|
|
2792
|
+
handleContractChanged would reject it as unorderable, and a contract frame carries no
|
|
2793
|
+
reviewRevision. SSE is plain fan-out with no replay buffer, so anything arriving before the tab has
|
|
2794
|
+
installed its first snapshot is buffered — in its OWN slot, since contractEventWatermark is keyed
|
|
2795
|
+
on a storeRevision a review frame does not have. */
|
|
2796
|
+
if(reviewEventMatches(m)){if(!contractEventReady){if(reviewFrameOrderable(m)&&(!reviewEventWatermark||m.reviewRevision>=reviewEventWatermark.reviewRevision))reviewEventWatermark=m;}else handleReviewChanged(m);return;}
|
|
2797
|
+
if(!contractEventMatches(m))return;if(!contractEventReady)bufferContractEvent(m);else handleContractChanged(m);};
|
|
2572
2798
|
source.onerror=()=>{if(source!==contractEventSource)return;contractEventReady=false;if(source.readyState===EventSource.CLOSED){ownWrites.length=0;console.warn('steel-editor: SSE channel closed — live updates paused');showAiUpdateBanner('Live updates disconnected — reload to resume change detection.');}};
|
|
2573
2799
|
}catch(e){console.warn('steel-editor: could not open live updates',e&&e.message?e.message:e);}
|
|
2574
2800
|
}
|
|
@@ -2579,7 +2805,55 @@ let conflicted = false;
|
|
|
2579
2805
|
// themselves, potentially aborting Approve. `saveSeq` only decides which response owns the pill; it
|
|
2580
2806
|
// never stopped the overlap. vector-editor already queues; this brings the steel editor in line.
|
|
2581
2807
|
let writeQueue = Promise.resolve();
|
|
2582
|
-
|
|
2808
|
+
/**
|
|
2809
|
+
* THE WRITE GATE — one transaction's exclusive hold on this tab's contract writes.
|
|
2810
|
+
*
|
|
2811
|
+
* "Place again" has to publish the OLD placement, mark the joint untracked, and only THEN move the
|
|
2812
|
+
* geometry. A debounced autosave scheduled by an earlier edit would otherwise fire in the middle of
|
|
2813
|
+
* that and publish the NEW geometry ahead of the command, which is the torn sequence the whole
|
|
2814
|
+
* transaction exists to prevent (it leaves a row reading CLEAN over the wrong steel — `failClosed`
|
|
2815
|
+
* never fires, because the tear happens before anything stages).
|
|
2816
|
+
*
|
|
2817
|
+
* IT NEEDS AN OWNER-ONLY BYPASS, OR IT DEADLOCKS AGAINST ITSELF. The drain and the fail-closed save are
|
|
2818
|
+
* both writes issued BY the transaction that closed the gate; a gate that simply blocked the queue would
|
|
2819
|
+
* leave each waiting on a gate only it can open. So the gate carries the owning transaction's token and
|
|
2820
|
+
* admits writes bearing it.
|
|
2821
|
+
*
|
|
2822
|
+
* A deferred non-owner write waits OUTSIDE the FIFO and joins it only once the gate opens. That ordering
|
|
2823
|
+
* is load-bearing rather than incidental: parking it IN the queue would put it ahead of the owner's own
|
|
2824
|
+
* drain, so the drain would queue behind the very writes it closed the gate to exclude.
|
|
2825
|
+
*
|
|
2826
|
+
* A LEAKED GATE DISABLES SAVING FOR THE SESSION — worse than the bug it fixes — so its release is
|
|
2827
|
+
* asserted on every path, including throw, and `openWriteGate` is token-checked so a settling
|
|
2828
|
+
* transaction can never clear a gate a newer one installed.
|
|
2829
|
+
*/
|
|
2830
|
+
let writeGateToken = null, writeGateOpen = null, writeGateRelease = null;
|
|
2831
|
+
/**
|
|
2832
|
+
* REFUSES to close over a gate that is already held, and that refusal is the mechanism rather than a
|
|
2833
|
+
* caller's manners. Overwriting `writeGateRelease` would strand every write parked on the OLD gate's
|
|
2834
|
+
* promise — permanently, because nothing can resolve a release nobody holds any more. That is the same
|
|
2835
|
+
* "saving is dead for the session" failure the gate exists to avoid, arriving through the gate itself.
|
|
2836
|
+
* Callers read the answer instead of pre-checking `writeGateToken`, so there is one statement of the
|
|
2837
|
+
* rule and no window between the check and the act.
|
|
2838
|
+
*/
|
|
2839
|
+
function closeWriteGate(token){
|
|
2840
|
+
if (writeGateToken) return false;
|
|
2841
|
+
writeGateToken = token; writeGateOpen = new Promise((resolve) => { writeGateRelease = resolve; });
|
|
2842
|
+
return true;
|
|
2843
|
+
}
|
|
2844
|
+
function openWriteGate(token){
|
|
2845
|
+
if (writeGateToken !== token) return false; // a newer transaction owns it; clearing here would strand that one
|
|
2846
|
+
writeGateToken = null;
|
|
2847
|
+
const release = writeGateRelease; writeGateRelease = null; writeGateOpen = null;
|
|
2848
|
+
if (release) release();
|
|
2849
|
+
return true;
|
|
2850
|
+
}
|
|
2851
|
+
const queueWrite = (fn, token) => {
|
|
2852
|
+
// Re-entrant on purpose: if a NEW gate closed while this write was parked, it parks again rather than
|
|
2853
|
+
// slipping through. Gates are bounded by one user transaction, so this terminates.
|
|
2854
|
+
if (writeGateToken && token !== writeGateToken) return writeGateOpen.then(() => queueWrite(fn, token));
|
|
2855
|
+
return (writeQueue = writeQueue.then(fn, fn));
|
|
2856
|
+
};
|
|
2583
2857
|
/**
|
|
2584
2858
|
* The full-screen "there is nothing to show" state.
|
|
2585
2859
|
*
|
|
@@ -2733,12 +3007,12 @@ async function boot() {
|
|
|
2733
3007
|
if (!APP_ID) { showEmpty('⊞', 'No workflow selected', 'Open a workflow in the FloLess canvas, then open the contract editor from that workflow’s node.'); return; }
|
|
2734
3008
|
armEarlyViewToggle(); // BEFORE the first await — that is the whole point; see above
|
|
2735
3009
|
startContractEvents(); // subscribe first; contract events buffer until the atomic snapshot is installed
|
|
2736
|
-
[SteelCore, ViewGen, ModelCmd, DetailRefs, V2Projection, V2Commands, V2Validation, SplitView, FilterCore, PlanXf, CatalogPicker] = await Promise.all([
|
|
3010
|
+
[SteelCore, ViewGen, ModelCmd, DetailRefs, V2Projection, V2Commands, V2Validation, SplitView, FilterCore, PlanXf, CatalogPicker, ReviewClient] = await Promise.all([
|
|
2737
3011
|
import('./steel-3d-core.js'), import('./steel-view-generation.js'), import('./steel-model-commands.js'),
|
|
2738
3012
|
import('./steel-detail-refs.js'), import('./steel-model-v2-projection.js'),
|
|
2739
3013
|
import('./steel-model-v2-commands.js'), import('./steel-model-v2-client-validation.js'),
|
|
2740
3014
|
import('./steel-split-view.js'), import('./steel-filter-core.js'), import('./steel-plan-transform.js'),
|
|
2741
|
-
import('./steel-catalog-picker.js'),
|
|
3015
|
+
import('./steel-catalog-picker.js'), import('./connection-review-client.js'),
|
|
2742
3016
|
]);
|
|
2743
3017
|
const res = await fetch('/api/contract/' + encodeURIComponent(APP_ID) + '/snapshot' + CONTRACT_QS);
|
|
2744
3018
|
// 204 = the project-scoped "nothing stored yet", the quiet twin of the generic 404 below. It carries
|
|
@@ -2852,6 +3126,11 @@ async function boot() {
|
|
|
2852
3126
|
// land on top of someone else's is refused instead of silently winning.
|
|
2853
3127
|
serverEtag = snapshotPayload.etag || res.headers.get('ETag');
|
|
2854
3128
|
serverRevision = Number.isSafeInteger(snapshotPayload.storeRevision) ? snapshotPayload.storeRevision : -1;
|
|
3129
|
+
/* The review summary rides the SAME envelope, read atomically with the contract under the project lock,
|
|
3130
|
+
and is installed INDEPENDENTLY of the contract revision — a sign-off leaves storeRevision exactly
|
|
3131
|
+
where it was, so gating this on `storeRevision > serverRevision` (as the reconnect path does for the
|
|
3132
|
+
contract) would discard every review update that mattered. */
|
|
3133
|
+
installReviewFromSnapshot(snapshotPayload, contractEventEpoch);
|
|
2855
3134
|
// The confidence target is a workflow INPUT (target_confidence), not contract data. Read its declared
|
|
2856
3135
|
// default only for an app-scoped editor: a project owns its contract independently of the installed
|
|
2857
3136
|
// workflow, so asking /api/app/<id> there can only add a normal 404 to the console. A project-specific
|
|
@@ -2888,19 +3167,23 @@ async function boot() {
|
|
|
2888
3167
|
// AISC catalogue weight for any tabulated designation the contract's weights map does not carry.
|
|
2889
3168
|
C.custom_details = C.custom_details || {};
|
|
2890
3169
|
C.profile_colors = C.profile_colors || {};
|
|
2891
|
-
if(!C.member_styles||typeof C.member_styles!=='object'||Array.isArray(C.member_styles))C.member_styles={}; // F5: per member-type 2D line style {weight,dash} — model-global, draft-only (stripped at bake like prop_labels). boot() only object-guards;
|
|
3170
|
+
if(!C.member_styles||typeof C.member_styles!=='object'||Array.isArray(C.member_styles))C.member_styles={}; // F5: per member-type 2D line style {weight,dash} — model-global, draft-only (stripped at bake like prop_labels). boot() only object-guards; the token/key sanitise (sanitizeMemberStyles, which lives in main()'s scope) runs where the UNVALIDATED input arrives — the draft restore (#851). The contract itself reaches here schema-validated.
|
|
2892
3171
|
if(!Array.isArray(C.member_types))C.member_types=[];
|
|
2893
3172
|
if(!Array.isArray(C.dims3d))C.dims3d=[]; // model-global draft-only 3D dimensions
|
|
2894
3173
|
if(!Array.isArray(C.detail_placements))C.detail_placements=[]; // model-global draft-only placed detail images (Slice 4)
|
|
2895
3174
|
if(!C.dim_overlays||typeof C.dim_overlays!=='object'||Array.isArray(C.dim_overlays))C.dim_overlays={bolt_pitch:true,edge_clearance:true,cope_size:true,base_plate:true,anchor_depth:true}; // model-global legend DIMENSIONS toggles — all on by default
|
|
2896
|
-
if(!C.dim_style||typeof C.dim_style!=='object'||Array.isArray(C.dim_style))C.dim_style={}; // model-global dimension-style defaults
|
|
2897
|
-
if(!Array.isArray(C.views))C.views=[]; // model-global saved views (Views Organizer): ensure an array in boot()'s OUTER scope (like dims3d/detail_placements above)
|
|
3175
|
+
if(!C.dim_style||typeof C.dim_style!=='object'||Array.isArray(C.dim_style))C.dim_style={}; // model-global dimension-style defaults. This object-guard is the ONLY normalisation on the load path: `sanitizeDimStyle()` has no production call site (#851). Harmless as it stands — `dimStyle()` re-checks every key against DIM_DEF on each read, and the schema types dim_style `additionalProperties:true` with no enums, so junk here can neither reach the canvas nor refuse a save.
|
|
3176
|
+
if(!Array.isArray(C.views))C.views=[]; // model-global saved views (Views Organizer): ensure an array in boot()'s OUTER scope (like dims3d/detail_placements above). `sanitizeViews()` likewise has no production call site, and CANNOT simply be given one: it always writes `projection`, which `$defs.view` (additionalProperties:false) forbids, so calling it would refuse the next save. See the note in applyDraftFields (#851).
|
|
2898
3177
|
// Reference models (#278) are always a model-level array in the native contract.
|
|
2899
3178
|
if(!Array.isArray(C.reference_models))C.reference_models=[];
|
|
2900
3179
|
main(); // (C.prop_labels is normalised inside main(), right after the PROP_DEFS/sanitizePropLabels registry is defined — see ~"normalise the contract's incoming value" — since that helper isn't in scope out here in boot())
|
|
2901
3180
|
contractBootSnapshotInstalled=true;
|
|
2902
3181
|
contractEventReady=true;
|
|
2903
3182
|
drainContractEvents(contractEventEpoch);
|
|
3183
|
+
// …and the review buffer, which has its own slot. Missing this was a real lost update: a sign-off
|
|
3184
|
+
// landing between the snapshot read and the tab becoming ready would sit in reviewEventWatermark
|
|
3185
|
+
// forever, because SSE is plain fan-out with no replay. The reconnect path already drained both.
|
|
3186
|
+
drainReviewEvents(contractEventEpoch);
|
|
2904
3187
|
}
|
|
2905
3188
|
|
|
2906
3189
|
/**
|
|
@@ -3159,6 +3442,7 @@ function installMemberEndContract(doc,etag,revision){
|
|
|
3159
3442
|
// A server command replaces the model underneath the editor's local history. Retaining those snapshots
|
|
3160
3443
|
// would let Ctrl+Z resurrect pre-command geometry without the server-owned decision/audit metadata.
|
|
3161
3444
|
undo.length=0;redo.length=0;updUR();
|
|
3445
|
+
bumpModelEditGeneration(); // the server replaced the document under the editor; nothing captured before this describes what is now on screen
|
|
3162
3446
|
const prev=serverEtag;serverEtag=etag;serverRevision=revision;restampDraftBase(prev,etag);conflicted=false;render();sync3D();
|
|
3163
3447
|
}
|
|
3164
3448
|
async function memberEndRequest(path,body){
|
|
@@ -3401,7 +3685,13 @@ function commitPositionEdit(members,userPatch,source){const captured=positionAut
|
|
|
3401
3685
|
prepared.push({m,patch:Object.assign({},patch,userPatch)});}
|
|
3402
3686
|
if(blockers.length)return positionRefuse('No changes made — '+blockers.join('; ')+'. Resolve every blocker, or set Depth and Width to Middle in each stored frame first.',source);
|
|
3403
3687
|
const current=positionAuthoringBasis();if(current.generation!==captured.generation)return positionRefuse('Frame changed — review the refreshed Profile Position and try again.',source);
|
|
3404
|
-
edit(
|
|
3688
|
+
// Return what edit() ACTUALLY did, not an unconditional true. edit() catches a V2CommandError, toasts it
|
|
3689
|
+
// and returns false; discarding that made a refusal read to the caller as success, and the 3D gizmo keys
|
|
3690
|
+
// its "put the live preview back" branch on exactly this boolean (steel-3d-view.js onUp), so a refused
|
|
3691
|
+
// commit left the moved mesh on screen over an unchanged model. Of the callers here only
|
|
3692
|
+
// commitMemberPosition propagates the value — every other one ignores it in statement position — so this
|
|
3693
|
+
// reaches precisely the consumer that wanted the truth. (slice 3b.1)
|
|
3694
|
+
return edit(()=>{for(const row of prepared)ModelCmd.patchMember(row.m,row.patch);})===true;}
|
|
3405
3695
|
/*
|
|
3406
3696
|
* Read-only snapshot the 3D Profile Position gizmo (slice 3a) renders from. The editor owns the
|
|
3407
3697
|
* semantics; the 3D view only draws the arrows and reports back an ABSOLUTE new value, which
|
|
@@ -3433,14 +3723,126 @@ function memberPositionGizmoState(id){
|
|
|
3433
3723
|
}
|
|
3434
3724
|
const f=SteelCore.positionGizmoFrame(input.from,input.to,captured);
|
|
3435
3725
|
if(!f)return{available:false,reason:m.id+' has no Profile Position frame in the current view'};
|
|
3726
|
+
const effRot=positionAuthoringRoll(m);
|
|
3436
3727
|
return{available:true,id,anchor:[...input.from],xAxis:[...f.x],yAxis:[...f.y],zAxis:[...f.z],
|
|
3437
|
-
|
|
3728
|
+
// The member's PROFILE axes — the part frame turned by the authored roll. ONE source, computed here,
|
|
3729
|
+
// because the gizmo now DRAWS depth/width on them AND moves the work points along them: if the drawing
|
|
3730
|
+
// and the drag scalar ever re-derived this separately, the steel would travel somewhere the arrow does
|
|
3731
|
+
// not point. Every consumer (draw, pick, screen probe, drag math, leader, typed entry, live state)
|
|
3732
|
+
// reads st.profile. Slide and both swings deliberately stay on the UNROLLED frame above — an elevation
|
|
3733
|
+
// swing about a rolled y is not a tilt.
|
|
3734
|
+
profile:SteelCore.rolledProfileAxes(f,effRot),
|
|
3735
|
+
positionOffset:+m.positionOffset||0,positionHOffset:+m.positionHOffset||0,rot:effRot,degenerate:!!f.degenerate,
|
|
3736
|
+
// slice 3b.1 — the reference-line handles need the FAR work point and the basis UP vector as well, plus a
|
|
3737
|
+
// drag-start FINGERPRINT. The fingerprint has to be captured HERE, when the gesture starts, because that
|
|
3738
|
+
// is the state the drag's arithmetic is frozen against; taking it again at commit time would compare the
|
|
3739
|
+
// live member with itself and the staleness guard could never fire (found in review).
|
|
3740
|
+
end:[...input.to],up:positionBasisUp(captured),fingerprint:V2Commands.memberFingerprint(input.canonical),
|
|
3741
|
+
handles:refLineHandleAvailability(m,f,input.from,input.to,positionBasisUp(captured))};}
|
|
3742
|
+
/*
|
|
3743
|
+
* The authoring basis' up vector — world Z under the global basis, else x × y. This is the PLAN-SWING
|
|
3744
|
+
* AXIS, and deliberately not the member's own tilted zAxis: rotating about up leaves both the rise and the
|
|
3745
|
+
* run untouched, so the slope is invariant, the rebuilt part frame equals the rigid preview exactly, and
|
|
3746
|
+
* the swing is provably immune to the 30° depth-face fold. Rotating about the body z would change the
|
|
3747
|
+
* slope on any sloped member and make preview and commit disagree.
|
|
3748
|
+
*/
|
|
3749
|
+
function positionBasisUp(basis){
|
|
3750
|
+
if(!basis||basis.kind==='global')return[0,0,1];
|
|
3751
|
+
const x=basis.x,y=basis.y;
|
|
3752
|
+
return[x[1]*y[2]-x[2]*y[1],x[2]*y[0]-x[0]*y[2],x[0]*y[1]-x[1]*y[0]];}
|
|
3753
|
+
/*
|
|
3754
|
+
* Which reference-line handles this member can actually take, decided from GEOMETRY rather than from its
|
|
3755
|
+
* role alone, each with the reason it is refused.
|
|
3756
|
+
*
|
|
3757
|
+
* The slide is representable for EVERY member, a plumb column included — there it is raise/lower, and the
|
|
3758
|
+
* model stores exactly that. The swings are not: a v2 column is plumb by construction (both work points
|
|
3759
|
+
* share the plan point; only the elevations differ), so a tilt has nowhere to live. And on a DEGENERATE
|
|
3760
|
+
* start frame — partFrame's seeded branch — the closed-form plumb barrier does not apply at all, because
|
|
3761
|
+
* `yAxis` is projected from `upX` there and need not be perpendicular to up. A plan swing additionally
|
|
3762
|
+
* preserves the member's distance from the degeneracy cone, so a member that starts inside it can never
|
|
3763
|
+
* leave: the handle would be permanently inert rather than merely awkward. Refuse both, and say why.
|
|
3764
|
+
*/
|
|
3765
|
+
function refLineHandleAvailability(m,f,from,to,up){
|
|
3766
|
+
const col=m.role==='column';
|
|
3767
|
+
const swing=col?{available:false,reason:'A column stays plumb — set its elevations in the Inspect panel.'}
|
|
3768
|
+
:f.degenerate?{available:false,reason:'This member is plumb — there is no direction to swing it from.'}
|
|
3769
|
+
:{available:true};
|
|
3770
|
+
// A member that is NEARLY plumb is not degenerate, so the check above lets it through — but its two plumb
|
|
3771
|
+
// barriers then sit on the same side of zero, leaving no legal travel one way. A handle that refuses every
|
|
3772
|
+
// drag is worse than one that is not drawn, so require a whole snap step each side and say why. (Review:
|
|
3773
|
+
// without this, a Shift-held tilt on such a member committed roughly a degree in the OPPOSITE direction.)
|
|
3774
|
+
const elev=swing.available&&!SteelCore.swingHasTravel(
|
|
3775
|
+
SteelCore.swingBarriers(from,to,f.y,up,SteelCore.POSITION_SWING_MARGIN_RAD),SteelCore.POSITION_ROT_SNAP_DEG*Math.PI/180)
|
|
3776
|
+
?{available:false,reason:'This member is within a degree of plumb — set its elevations in the Inspect panel.'}
|
|
3777
|
+
:swing;
|
|
3778
|
+
// depth/width are TRANSLATIONS of the whole line along the profile axes, so like the axial slide they
|
|
3779
|
+
// are representable for every member the gizmo shows at all — including a plumb column, where they move
|
|
3780
|
+
// it in plan. They are listed rather than left out so all five moving handles come from ONE map: the
|
|
3781
|
+
// typed-entry path asks `st.handles[axis]` for every handle it opens, and an axis missing from the map
|
|
3782
|
+
// would read as "not available" rather than as "always available".
|
|
3783
|
+
return{depth:{available:true},width:{available:true},slide:{available:true},swingPlan:swing,swingElev:elev};}
|
|
3438
3784
|
/*
|
|
3439
3785
|
* The gizmo's one write path: the 3D view hands back an absolute new offset (mm) or roll (deg) for a
|
|
3440
3786
|
* single member; this routes it through `commitPositionEdit`, which rebases to the current frame,
|
|
3441
3787
|
* applies the edit, and produces exactly one undo entry. Returns a boolean (false = refused).
|
|
3442
3788
|
*/
|
|
3443
3789
|
function commitMemberPosition(id,patch,source){const m=byId(id);if(!m)return positionRefuse('That member is no longer in the model.',source);return commitPositionEdit([m],patch,source||null);}
|
|
3790
|
+
/*
|
|
3791
|
+
* The reference-line handles' one write path (slice 3b.1): the 3D view hands back ABSOLUTE new work points
|
|
3792
|
+
* in world mm, and this commits them as a single undoable edit.
|
|
3793
|
+
*
|
|
3794
|
+
* Deliberately separate from `commitMemberPosition`. That one rebases the stored placement into the current
|
|
3795
|
+
* authoring frame before applying an offset/roll; an endpoint move needs none of that dance, because it does
|
|
3796
|
+
* not change the authoring frame at all — `m.rot` and `m.positionBasis` stay untouched and the displayed
|
|
3797
|
+
* roll re-derives on the new part frame through `positionAuthoringRoll`.
|
|
3798
|
+
*
|
|
3799
|
+
* WHAT THIS OWNS, and what the model command re-checks underneath it:
|
|
3800
|
+
* - the authoring basis must not have drifted since the gesture began (the same generation compare the
|
|
3801
|
+
* panel commit does);
|
|
3802
|
+
* - the candidate points are QUANTISED here, before anything is decided from them, because the depth-face
|
|
3803
|
+
* fold is a threshold test and an unquantised preview can land on the other side of it from what is
|
|
3804
|
+
* actually stored;
|
|
3805
|
+
* - the depth-face pin is computed HERE, from current canonical state, through the same shared helper the
|
|
3806
|
+
* command verifies with — so the two can never drift apart;
|
|
3807
|
+
* - FRAME-BRANCH STABILITY. A swing must land on partFrame's ordinary branch. A slide must merely keep the
|
|
3808
|
+
* branch it started on, IN BOTH DIRECTIONS: a slide is not frame-preserving to the bit (each endpoint
|
|
3809
|
+
* quantises independently, perturbing the direction by ~1e-9), so near the cone it can nudge a member
|
|
3810
|
+
* OUT of the seeded branch as easily as into it — and leaving the cone rebuilds a different section
|
|
3811
|
+
* frame than the rigid preview showed.
|
|
3812
|
+
*
|
|
3813
|
+
* Returns a plain boolean. The pin, when one is applied, is announced here and only AFTER the write lands,
|
|
3814
|
+
* so a refused commit can never announce a pin that was never stored.
|
|
3815
|
+
*/
|
|
3816
|
+
function commitMemberEndpoints(id,spec,source){
|
|
3817
|
+
const m=byId(id);if(!m)return positionRefuse('That member is no longer in the model.',source);
|
|
3818
|
+
const captured=positionAuthoringBasis();if(!captured.ok)return positionRefuse(captured.message,source);
|
|
3819
|
+
const input=positionRebaseInput(m);if(!input)return positionRefuse(m.id+' has incomplete work points.',source);
|
|
3820
|
+
const q=(p)=>[SteelCore.quantizeMm(p[0]),SteelCore.quantizeMm(p[1]),SteelCore.quantizeMm(p[2])];
|
|
3821
|
+
const from=spec&&spec.from?q(spec.from):[...input.from],to=spec&&spec.to?q(spec.to):[...input.to];
|
|
3822
|
+
if(![...from,...to].every(Number.isFinite))return positionRefuse('That move produced a coordinate the model cannot store.',source);
|
|
3823
|
+
const before=SteelCore.positionGizmoFrame(input.from,input.to,captured);
|
|
3824
|
+
const after=SteelCore.positionGizmoFrame(from,to,captured);
|
|
3825
|
+
if(!after)return positionRefuse('That move leaves the member with no length.',source);
|
|
3826
|
+
const gesture=spec&&spec.gesture;
|
|
3827
|
+
// A gesture that moves the line RIGIDLY (the axial slide, and since the redesign the two lateral
|
|
3828
|
+
// translates) must merely KEEP partFrame's branch, in both directions; a swing re-aims the member and
|
|
3829
|
+
// has to land on the ordinary branch. This is a shared VALIDATION policy, not a claim that the two
|
|
3830
|
+
// translations are numerically identical: each endpoint quantises independently, so near the degeneracy
|
|
3831
|
+
// cone either one can cross the branch through rounding alone — which is exactly what this rejects.
|
|
3832
|
+
if(SteelCore.directionPreservingGesture(gesture)?(!!after.degenerate!==!!(before&&before.degenerate))
|
|
3833
|
+
:after.degenerate)return positionRefuse('That move would leave the section with no usable frame — try a smaller change.',source);
|
|
3834
|
+
const pin=SteelCore.requiredDepthPin(input.canonical,{from:input.from,to:input.to},{from,to}).pin;
|
|
3835
|
+
const current=positionAuthoringBasis();if(current.generation!==captured.generation)return positionRefuse('Frame changed — review the refreshed Profile Position and try again.',source);
|
|
3836
|
+
const ok=edit(()=>{MC().moveWorkPoints(m,{
|
|
3837
|
+
points:{from:{x:from[0],y:from[1],z:from[2]},to:{x:to[0],y:to[1],z:to[2]}},
|
|
3838
|
+
// The DRAG-START fingerprint when the caller froze one (every gesture does, via the gizmo state); only
|
|
3839
|
+
// the typed path falls back to a fresh read, and there the endpoints are derived from that same fresh
|
|
3840
|
+
// read, so the two agree by construction. Recomputing it here for a drag would compare the live member
|
|
3841
|
+
// against itself and render the staleness guard inert.
|
|
3842
|
+
expect:(spec&&spec.expect)||V2Commands.memberFingerprint(input.canonical),
|
|
3843
|
+
...(pin===undefined?{}:{position:pin})});})===true;
|
|
3844
|
+
if(ok&&pin!==undefined)toast('Depth face pinned to “'+pin+'” so the steel stays where you put it.',false,5200);
|
|
3845
|
+
return ok;}
|
|
3444
3846
|
/*
|
|
3445
3847
|
* ONE row of the Profile Position section: heading + offset box on the first line, named faces on the
|
|
3446
3848
|
* second. The mockup drew all three on one line; at 280 px — ~246 px of content once the rail's padding and
|
|
@@ -4007,7 +4409,74 @@ function confirmDanger({title,body,confirmLabel}){
|
|
|
4007
4409
|
// exact tag, so a deliberate overwrite still cannot create a store out of nothing. Only the explicit
|
|
4008
4410
|
// "Overwrite and save" confirm passes it. (This said "skips the precondition" until P1c made a write
|
|
4009
4411
|
// without one a 428; it was already inaccurate, and would now describe an impossible request.)
|
|
4010
|
-
|
|
4412
|
+
// The write-boundary connection revalidation report (server/contract-gateway.ts) → ONE plain-English toast.
|
|
4413
|
+
// The server decides the fate of every shear-plate/brace-gusset joint a member move could have affected and
|
|
4414
|
+
// has already stored the result; this only TELLS the user, in their words, what changed. Kept-only is silent.
|
|
4415
|
+
// Marks where the model has them (byId(id).mark), else the id. Capped at three clauses so a big move is a
|
|
4416
|
+
// sentence, not a wall. No barrier, no re-install: the local model keeps its own undo history.
|
|
4417
|
+
// The server revalidated connections at the write boundary and reported what it did. Apply that report to
|
|
4418
|
+
// the LIVE joints and tell the user. Applying is not cosmetic: the durable contract already holds the
|
|
4419
|
+
// removal/repoint, but the browser's `C.joints` still carries the stale joint — and because the endpoints
|
|
4420
|
+
// no longer change on the NEXT save, revalidation would be a no-op there and the server would faithfully
|
|
4421
|
+
// persist the stale joint the client re-sent, silently resurrecting it. So we must reconcile `C.joints`.
|
|
4422
|
+
// It is SURGICAL — only the joints the report names are touched — so it needs no full-contract install and
|
|
4423
|
+
// therefore never clears the undo stack (unlike installMemberEndContract): on the ordinary move (the common
|
|
4424
|
+
// case) one Ctrl+Z restores the pre-move snapshot (endpoints AND the original joint), and revalidation
|
|
4425
|
+
// re-derives idempotently from there. The one exception is a move that ALSO invalidates a retained work-point
|
|
4426
|
+
// decision: that write returns the transformed contract, so the caller runs installMemberEndContract FIRST
|
|
4427
|
+
// (which does clear undo, for its own server-owned-decision reason) and this reconcile is then a redundant
|
|
4428
|
+
// no-op — the joints are still correct, only the undo affordance is lost, in that rare combined case.
|
|
4429
|
+
// Guarded by the caller on `seq===saveSeq`: a report is only applied while `C` still equals what was sent.
|
|
4430
|
+
function applyRevalidation(rv){
|
|
4431
|
+
if(!rv)return;
|
|
4432
|
+
const mk=id=>{const m=byId(id);return (m&&(m.mark||m.id))||id;};
|
|
4433
|
+
const KIND={'shear-plate':'Shear plate','brace-gusset':'Brace gusset'};
|
|
4434
|
+
const kindLabel=k=>KIND[k]||'Connection';
|
|
4435
|
+
const rm=rv.removed||[],rp=rv.repointed||[],df=rv.deferred||[];
|
|
4436
|
+
/* The connection whose members are being named right now is EXCLUDED from the flagged clause. The
|
|
4437
|
+
placement command is about to record the very relationship "may need review" would be asking
|
|
4438
|
+
about, so the warning is both noise and untrue at that moment — and it lands on the shared #toast,
|
|
4439
|
+
erasing the only complete statement of how to confirm or skip the pick. */
|
|
4440
|
+
const fl=(rv.flagged||[]).filter(f=>!(connMemberPick&&f&&f.id===connMemberPick.id));
|
|
4441
|
+
const clauses=[];
|
|
4442
|
+
if(rm.length)clauses.push(rm.length===1?(kindLabel(rm[0].kind)+' removed — no supporting member'):(rm.length+' connections removed — no supporting member'));
|
|
4443
|
+
if(rp.length){
|
|
4444
|
+
if(rp.length===1){const j=(C.joints||[]).find(x=>x.id===rp[0].id);clauses.push(kindLabel(j&&j.kind)+' re-seated onto '+mk(rp[0].to));}
|
|
4445
|
+
else clauses.push(rp.length+' connections re-seated onto new supports');
|
|
4446
|
+
}
|
|
4447
|
+
if(fl.length)clauses.push(fl.length===1?'Custom connection may need review':(fl.length+' custom connections may need review'));
|
|
4448
|
+
if(df.length)clauses.push(df.length+' connection'+(df.length===1?'':'s')+' left unchanged — geometry unresolved');
|
|
4449
|
+
// Reconcile the live joints with the server's authoritative result (removed dropped, repointed re-bound).
|
|
4450
|
+
// The report is server-authored but consumed defensively (a malformed entry must not write `undefined`
|
|
4451
|
+
// into a live binding): only well-shaped ids/targets are applied, the rest are logged and skipped.
|
|
4452
|
+
const removedIds=new Set(rm.filter(r=>r&&typeof r.id==='string').map(r=>r.id));
|
|
4453
|
+
const repoints=rp.filter(r=>r&&typeof r.id==='string'&&typeof r.to==='string');
|
|
4454
|
+
if(removedIds.size||repoints.length){
|
|
4455
|
+
C.joints=(C.joints||[]).filter(j=>!removedIds.has(j.id));
|
|
4456
|
+
for(const r of repoints){const j=(C.joints||[]).find(x=>x.id===r.id);if(j)j.secondaries=[r.to];}
|
|
4457
|
+
bumpModelEditGeneration(); // the VISIBLE document just changed without scheduling a save — a sign-off captured before this must not pass its generation check
|
|
4458
|
+
persist();render();sync3D(); // persist() rewrites the localStorage draft; the durable copy already holds this
|
|
4459
|
+
}
|
|
4460
|
+
if(rm.length!==removedIds.size||rp.length!==repoints.length)console.warn('steel-editor: a malformed revalidation report entry was skipped',rv);
|
|
4461
|
+
if(clauses.length)toast(clauses.slice(0,3).join(' · '));
|
|
4462
|
+
}
|
|
4463
|
+
// THE CLIENT NEVER DECIDES A JOINT'S FATE — THE SERVER DOES, AND IT NEEDS NOTHING FROM US TO DO IT.
|
|
4464
|
+
//
|
|
4465
|
+
// Normally the server's revalidation report rides the write response and `applyRevalidation` mirrors it into
|
|
4466
|
+
// `C.joints`. Some responses this tab cannot safely apply: a STALE one (a newer edit landed while the PUT was
|
|
4467
|
+
// in flight, so the report's delta no longer describes the live `C`), an UNREADABLE body, or one LOST after
|
|
4468
|
+
// the write committed. On those legs we simply do nothing — no merge, no bookkeeping, no guessing.
|
|
4469
|
+
//
|
|
4470
|
+
// That is safe because of where the guarantee actually lives: the server re-decides every joint a write
|
|
4471
|
+
// INTRODUCES (present in the incoming contract, absent from the stored one), and a joint this tab kept after
|
|
4472
|
+
// missing its removal is exactly that shape. So the next ordinary save re-decides it and removes it again,
|
|
4473
|
+
// authoritatively, with the user told in the usual toast. Undo behaves correctly for free — it restores the
|
|
4474
|
+
// endpoint too, so the support is valid again and the joint is simply `kept`.
|
|
4475
|
+
//
|
|
4476
|
+
// This replaced a client-side merge (fingerprints, ownership rules, etag-generation heuristics) that four
|
|
4477
|
+
// adversarial review rounds kept finding concurrency bugs in: reconciling a server-authoritative transform
|
|
4478
|
+
// against a concurrently-edited local copy is a CRDT-class problem, and the way to win it was not to play.
|
|
4479
|
+
async function persistServer(force,token){const seq=saveSeq;
|
|
4011
4480
|
// Once conflicted, stop firing doomed PUTs; re-surface the explanation instead of hammering the
|
|
4012
4481
|
// network every debounce tick. Cleared only by a reload or a confirmed overwrite.
|
|
4013
4482
|
if(conflicted&&!force){showConflictBanner();return;}
|
|
@@ -4047,13 +4516,26 @@ async function persistServer(force){const seq=saveSeq;
|
|
|
4047
4516
|
// write is usually still in flight — the server broadcasts before it replies — so releasing here would
|
|
4048
4517
|
// make the tab read its OWN echo as external and reload itself mid-edit. The id is released when the
|
|
4049
4518
|
// echo consumes it, when the write fails, or when the SSE channel closes (nothing can echo after that).
|
|
4050
|
-
if(res.ok){
|
|
4519
|
+
if(res.ok){let d={},bodyReadable=true;try{d=await res.json();}catch(_){bodyReadable=false;}const t=d.etag||res.headers.get('ETag');if(d.contract&&t&&Number.isSafeInteger(d.storeRevision))installMemberEndContract(d.contract,t,d.storeRevision);else{if(t){const pv=serverEtag;serverEtag=t;restampDraftBase(pv,t);}if(Number.isSafeInteger(d.storeRevision))serverRevision=Math.max(serverRevision,d.storeRevision);}conflicted=false;
|
|
4520
|
+
// The write COMMITTED. Apply its revalidation report ONLY when we can prove it describes the live `C`:
|
|
4521
|
+
// the body was readable AND `seq===saveSeq` (no newer edit landed while this PUT was in flight). Otherwise
|
|
4522
|
+
// do NOTHING — no merge, no bookkeeping. That is safe because a joint whose removal we then miss is
|
|
4523
|
+
// re-INTRODUCED by the next save, and the server re-decides every introduced joint.
|
|
4524
|
+
const usable=!!t||Number.isSafeInteger(d.storeRevision);
|
|
4525
|
+
// Apply ONLY a report we can prove is current; otherwise do nothing — the server re-decides an
|
|
4526
|
+
// introduced joint on the next save, so a missed removal cannot survive (see the note above).
|
|
4527
|
+
if(bodyReadable&&usable&&seq===saveSeq)applyRevalidation(d.revalidation);
|
|
4528
|
+
} // chain the next edit off the new tag, and install any server-staled endpoint authority instead of leaving the browser on bytes the server deliberately transformed; then tell the user what the write-boundary revalidation did to their connections
|
|
4051
4529
|
else releaseMutation(mid); // 400/500: nothing was written, so nothing will echo
|
|
4052
4530
|
if(seq===saveSeq)setSaved(res.ok?'ok':'err'); // only the latest save owns the pill (a stale late response must not clobber a newer verdict)
|
|
4053
4531
|
if(!res.ok)console.error('server save rejected ('+res.status+')',await res.text().catch(()=>'')); // 400 = schema reject: edits won't be what Approve bakes
|
|
4054
|
-
}catch(e){releaseMutation(mid);if(seq===saveSeq)setSaved('err');console.error('server save failed',e);
|
|
4055
|
-
|
|
4056
|
-
|
|
4532
|
+
}catch(e){releaseMutation(mid);if(seq===saveSeq)setSaved('err');console.error('server save failed',e);
|
|
4533
|
+
// The write may have committed even though we never saw the response — nothing to do here. `C.joints` can
|
|
4534
|
+
// then still carry a joint the store removed, and the NEXT save re-introduces it, which is exactly the
|
|
4535
|
+
// shape the server always re-decides. So the removal simply happens again, authoritatively.
|
|
4536
|
+
}
|
|
4537
|
+
},token);}
|
|
4538
|
+
function scheduleSave(){if(memberEndStatus.known||memberEndReview)invalidateMemberEndReview();bumpModelEditGeneration();setSaved('dirty');++saveSeq;clearTimeout(saveT);saveT=setTimeout(()=>{saveT=null;persist();persistServer();},500);} // clear the handle as it fires: `saveT !== null` is read as "a write is still pending" (the project send refuses on it), and a spent timer id would read as pending forever // ++saveSeq: a fresh edit is a new save intent — it invalidates any still-in-flight PUT so that PUT's late response can't flip the pill to a stale 'Saved ✓' while this edit is still unsaved (persistServer below captures this same intent id)
|
|
4057
4539
|
// The boot-scope SSE handler's seam into that debounce — see `flushLocalDraft` for why the handler
|
|
4058
4540
|
// cannot reach `persist()` itself.
|
|
4059
4541
|
//
|
|
@@ -4070,13 +4552,27 @@ flushLocalDraft = () => persist(); // the RESULT is load-bearing at the call s
|
|
|
4070
4552
|
// server right now. The parent (aware.js #contract-editor-approve) awaits this before
|
|
4071
4553
|
// POSTing approve, so Approve always bakes the latest edits — not a stale debounce
|
|
4072
4554
|
// snapshot. Throws on a non-2xx response so the parent can abort and show the warn toast.
|
|
4073
|
-
|
|
4555
|
+
/**
|
|
4556
|
+
* It RESOLVES TO `{ etag, generation }`, and both halves are the sign-off precondition (§5.2).
|
|
4557
|
+
*
|
|
4558
|
+
* `etag` is the tag this write produced — the one the sign-off must send as `If-Match`, rather than
|
|
4559
|
+
* re-reading `serverEtag`, which by dispatch time may already name a LATER write. `generation` is
|
|
4560
|
+
* `modelEditGeneration` captured synchronously beside `JSON.stringify(C)`, so it names the document
|
|
4561
|
+
* that was actually published rather than whatever is on screen a round trip later.
|
|
4562
|
+
*
|
|
4563
|
+
* `token` admits this flush past a closed write gate when the flush IS the gate's owner — see the gate.
|
|
4564
|
+
* Every pre-existing caller (Approve, memberEndRequest, placeConnection, detailRequest) only awaits the
|
|
4565
|
+
* promise, so widening the resolution value breaks nothing.
|
|
4566
|
+
*/
|
|
4567
|
+
async function flushContractWith(token) {
|
|
4074
4568
|
clearTimeout(saveT); saveT = null; // the debounced write is being taken over by this flush, so it is no longer pending
|
|
4075
4569
|
// Behind the SAME queue as autosave — Approve awaits this, and a flush racing an in-flight autosave
|
|
4076
4570
|
// was the self-conflict path that could abort Approve for no reason.
|
|
4077
4571
|
return queueWrite(async () => {
|
|
4078
4572
|
const mid = newMutationId(); claimMutation(mid); // same own-echo identity as persistServer — see there
|
|
4079
4573
|
const seq = ++saveSeq;
|
|
4574
|
+
let adoptedTag = null; // the tag THIS write produced, reported back for the sign-off's precondition
|
|
4575
|
+
let publishedGeneration = modelEditGeneration;
|
|
4080
4576
|
let res;
|
|
4081
4577
|
try {
|
|
4082
4578
|
// Conditional like every other write, and it MUST refresh the tag on success. Getting this wrong is
|
|
@@ -4086,12 +4582,15 @@ window.flushContract = async () => {
|
|
|
4086
4582
|
const headers = { 'content-type': 'application/json', 'x-floless-mutation-id': mid };
|
|
4087
4583
|
// Same total rule as persistServer — see the comment there for why "no tag" means If-None-Match: *.
|
|
4088
4584
|
if (serverEtag) headers['if-match'] = serverEtag; else headers['if-none-match'] = '*';
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4585
|
+
// Captured HERE, in the same synchronous expression that serialises the body, so it names the
|
|
4586
|
+
// document this PUT actually carried — not one an edit produced while the request was in flight.
|
|
4587
|
+
publishedGeneration = modelEditGeneration;
|
|
4588
|
+
res = await fetch('/api/contract/' + encodeURIComponent(APP_ID) + PROJECT_QS, { method: 'PUT', headers, body: JSON.stringify(C) });
|
|
4092
4589
|
} catch (e) {
|
|
4093
4590
|
releaseMutation(mid); // nothing was written, so no broadcast will ever carry this id
|
|
4094
4591
|
if (seq === saveSeq) setSaved('err'); // B9: a network rejection must show "Save failed", not leave the pill stuck on "Saving…" (this fn cancels the debounced persistServer that would otherwise flag it)
|
|
4592
|
+
// Parity with persistServer: a lost response needs no bookkeeping here — a joint whose removal we missed
|
|
4593
|
+
// is re-introduced by the next save, and the server always re-decides an introduced joint.
|
|
4095
4594
|
throw e; // still reject so the parent (Approve) aborts — regardless of seq
|
|
4096
4595
|
}
|
|
4097
4596
|
if (res.status === 428) { // same cause as persistServer's 428 branch — a writer sent no precondition
|
|
@@ -4110,11 +4609,43 @@ window.flushContract = async () => {
|
|
|
4110
4609
|
showConflictBanner();
|
|
4111
4610
|
throw new Error('save conflict');
|
|
4112
4611
|
}
|
|
4113
|
-
if (res.ok) {
|
|
4612
|
+
if (res.ok) { let d = {}, bodyReadable = true; try { d = await res.json(); } catch (_) { bodyReadable = false; } const t = d.etag || res.headers.get('ETag'); adoptedTag = t || null; if (d.contract && t && Number.isSafeInteger(d.storeRevision)) installMemberEndContract(d.contract, t, d.storeRevision); else { if (t) { const pv = serverEtag; serverEtag = t; restampDraftBase(pv, t); } if (Number.isSafeInteger(d.storeRevision)) serverRevision = Math.max(serverRevision, d.storeRevision); } conflicted = false;
|
|
4613
|
+
// The flush committed. Same rule as persistServer: apply the report only when the body was readable and
|
|
4614
|
+
// `seq===saveSeq` (Approve awaits this flush, so the user CAN edit meanwhile and make it stale). Otherwise
|
|
4615
|
+
// do nothing — the next save re-introduces any joint whose removal we missed, and the server re-decides it.
|
|
4616
|
+
const usable = !!t || Number.isSafeInteger(d.storeRevision);
|
|
4617
|
+
if (bodyReadable && usable && seq === saveSeq) applyRevalidation(d.revalidation); }
|
|
4114
4618
|
else releaseMutation(mid);
|
|
4115
4619
|
if (seq === saveSeq) setSaved(res.ok ? 'ok' : 'err'); // only the latest save owns the pill
|
|
4116
4620
|
if (!res.ok) throw new Error('save failed (' + res.status + ')');
|
|
4117
|
-
}
|
|
4621
|
+
return { etag: adoptedTag, generation: publishedGeneration };
|
|
4622
|
+
}, token);
|
|
4623
|
+
}
|
|
4624
|
+
/**
|
|
4625
|
+
* A flush is a WHOLE-DOCUMENT publish, and it must never queue behind a human.
|
|
4626
|
+
*
|
|
4627
|
+
* Approve (`aware.js`) awaits this inside a `try/finally` that re-enables its button — so a flush that
|
|
4628
|
+
* parks on the re-placement gate leaves Approve stuck on "Baking…" for as long as the member pick stays
|
|
4629
|
+
* armed, which is indefinitely: naming members is a human action with no time limit and no other tab is
|
|
4630
|
+
* going to end it. `detailRequest` and `memberEndRequest` await it too and would silently do nothing.
|
|
4631
|
+
* (Found by review.)
|
|
4632
|
+
*
|
|
4633
|
+
* So an outside flush SETTLES the placement rather than waiting on it, in the direction this design
|
|
4634
|
+
* already prefers: abandoning lands the joint untracked, which is visible and correctable, where
|
|
4635
|
+
* waiting looks exactly like a hung server. The abandon resolves the transaction, whose `finally`
|
|
4636
|
+
* opens the gate, and this flush — parked for that one turn — then proceeds.
|
|
4637
|
+
*
|
|
4638
|
+
* Only for a NON-owner flush. The transaction's own flush carries the token and must go straight
|
|
4639
|
+
* through; abandoning there would have it settle itself halfway.
|
|
4640
|
+
*/
|
|
4641
|
+
window.flushContract = () => {
|
|
4642
|
+
if (writeGateToken) {
|
|
4643
|
+
const v = window.Steel3DView;
|
|
4644
|
+
if (v && v.abandonConnMemberPick && v.connMemberPickJoint && v.connMemberPickJoint() !== null) {
|
|
4645
|
+
v.abandonConnMemberPick('flush-requested');
|
|
4646
|
+
}
|
|
4647
|
+
}
|
|
4648
|
+
return flushContractWith(null);
|
|
4118
4649
|
};
|
|
4119
4650
|
/**
|
|
4120
4651
|
* The server's reference list, wearing the draft's display and placement wherever the ids still match.
|
|
@@ -4172,13 +4703,93 @@ function reconcileReferences(server,draft){
|
|
|
4172
4703
|
function applyDraftFields(d){
|
|
4173
4704
|
const candidate=structuredClone(C);
|
|
4174
4705
|
const rootKeys=['members','grid','custom_details','profile_colors','member_styles','member_types','target_confidence','dims3d','dim_overlays','dim_style','prop_labels','joints','connections','detail_placements','views'];
|
|
4175
|
-
|
|
4176
|
-
//
|
|
4177
|
-
//
|
|
4178
|
-
//
|
|
4179
|
-
//
|
|
4180
|
-
//
|
|
4181
|
-
|
|
4706
|
+
// A draft is unvalidated localStorage, and this restore runs AFTER the boot-time sanitise — so a raw
|
|
4707
|
+
// copy re-introduces exactly the shapes the sanitisers exist to prevent, one link past the guard.
|
|
4708
|
+
// `prop_labels` was wired for that reason (#614) and the others were not (#851): `sanitizeConnections`
|
|
4709
|
+
// had NO call site anywhere in the repo, and `sanitizeMemberStyles`/`sanitizeDims3d` only a self-test —
|
|
4710
|
+
// three sanitisers written for THIS site and never reached from it. The registry replaces the loop's
|
|
4711
|
+
// blanket clone so the wiring lives with the key list: a rootKey that grows a sanitiser can no longer
|
|
4712
|
+
// be added to one and silently skipped by the other, which is how all three came to be dead.
|
|
4713
|
+
//
|
|
4714
|
+
// WHAT IT ACTUALLY COSTS — measured, and not what #851 predicted. The issue expected an id-less
|
|
4715
|
+
// `connections` row to SAIL PAST the client and refuse every save server-side. It does not:
|
|
4716
|
+
// `checkModelReferences` really is blind to it (it indexes the row as `null` and flags only DUPLICATE
|
|
4717
|
+
// and UNRESOLVED ids, never a missing one), but `validationProblems()` in steel-model-v2-commands.js
|
|
4718
|
+
// runs the SCHEMA as well, and `connections[].id` is required — so the restore itself is refused,
|
|
4719
|
+
// atomically. The row was never what was at risk. THE USER'S WHOLE DRAFT WAS: one unusable row and
|
|
4720
|
+
// every edit in that session is discarded, with one console line as the only trace. Sanitising first
|
|
4721
|
+
// turns "throw all of it away" into "drop the row that was unreachable anyway" — an id-less row
|
|
4722
|
+
// resolves from nothing, since every `ends[].conn` / `joints[].conn` looks up BY id. `member_styles`
|
|
4723
|
+
// (bogus weight/dash token) and `dims3d` (degenerate `axisDir`, whose own doc says "run at every point
|
|
4724
|
+
// a dims3d array is assigned") are the same story with the same cost.
|
|
4725
|
+
//
|
|
4726
|
+
// `views` is DELIBERATELY ABSENT and must stay absent until `sanitizeViews` is fixed: it always writes
|
|
4727
|
+
// `projection`, and `$defs.view` is `additionalProperties:false` with no such key, so wiring it here
|
|
4728
|
+
// would CAUSE the refused save this block exists to prevent (it also writes `camera`/`clips`/`objects`
|
|
4729
|
+
// as `null`, which the schema types as objects). Filed separately — do not "finish the set" here.
|
|
4730
|
+
// EACH ENTRY ENFORCES THE SCHEMA AND NOTHING ELSE. A guard here may reject what the schema cannot
|
|
4731
|
+
// hold — that is the whole job, since anything else refuses the restore or the next save — and may
|
|
4732
|
+
// never impose an opinion of its own, because the draft is the user's data and the loss is silent.
|
|
4733
|
+
// A guard returns `undefined` for a drafted value whose ROOT is the wrong type, and that key is then
|
|
4734
|
+
// LEFT ALONE — the document's own value stands. It is the only outcome that saves the rest of the
|
|
4735
|
+
// draft. Substituting an empty collection looks tidy and is not: with `connections:{}` in the draft,
|
|
4736
|
+
// an empty library orphans every `ends[].conn` / `joints[].conn` the document already holds, so the
|
|
4737
|
+
// whole restore is refused and every unrelated edit dies with it — the exact failure this block
|
|
4738
|
+
// exists to prevent. Passing the malformed value through refuses just as hard (the schema types these
|
|
4739
|
+
// roots), so neither substitute works and only skipping does. A wrong-typed root is corruption, never
|
|
4740
|
+
// a user state: emptying a collection is legitimately drafted as `[]`/`{}`, which is well-typed and
|
|
4741
|
+
// restores normally. (Codex, #853.)
|
|
4742
|
+
const unusableRoots=[];
|
|
4743
|
+
const arr=v=>Array.isArray(v)?v:undefined;
|
|
4744
|
+
const rec=v=>(v&&typeof v==='object'&&!Array.isArray(v))?v:undefined;
|
|
4745
|
+
// ASK THE SCHEMA, DO NOT RESTATE IT. Every regression in this block came from a guard holding an
|
|
4746
|
+
// opinion about the contract that the contract did not hold — narrower six times (a clamped id, a
|
|
4747
|
+
// trimmed id, a rebuilt recipe, a rebuilt note, a deleted style entry, a filtered props token) and,
|
|
4748
|
+
// once the search finally ran in the other direction, WIDER too: `sanitizeDims3d` only canonicalises
|
|
4749
|
+
// `axisDir`, so a dim with no `id`, a bogus `axis`, a missing `b` or an extra key sailed straight
|
|
4750
|
+
// through and refused the whole restore. Rather than write those four rules out here — the seventh
|
|
4751
|
+
// restatement of a rule the schema already owns — each row is put to `$defs.dim3` itself, through the
|
|
4752
|
+
// same subset interpreter the server validates with. `$defs` rides along so `#/$defs/point3` resolves.
|
|
4753
|
+
const rowSchema=name=>(V2_SCHEMA&&V2_SCHEMA.$defs&&V2_SCHEMA.$defs[name])?{...V2_SCHEMA.$defs[name],$defs:V2_SCHEMA.$defs}:null;
|
|
4754
|
+
const rowsOk=(list,name)=>{const node=rowSchema(name);
|
|
4755
|
+
return node?list.filter(r=>V2Validation.validateSchemaSubset(r,node).valid):list;}; // no schema yet → keep everything; a guard must never be the thing that loses data
|
|
4756
|
+
const DRAFT_SANITIZERS={
|
|
4757
|
+
prop_labels:v=>rec(v)&&sanitizePropLabels(v), // $defs.propLabels is CLOSED and this emits exactly its six keys
|
|
4758
|
+
connections:v=>arr(v)&&sanitizeConnections(v),
|
|
4759
|
+
// NOT `sanitizeMemberStyles`. `member_styles` is `additionalProperties:true` and otherwise
|
|
4760
|
+
// UNCONSTRAINED, so the only thing the schema can refuse is a non-object — which is all this guards.
|
|
4761
|
+
// #851 asked for the full sanitiser here and its premise does not survive contact with the schema:
|
|
4762
|
+
// a bogus weight/dash token and an un-normalised type key both validate FINE, so no corrupt style
|
|
4763
|
+
// can refuse a save and there is nothing for a clamp to save the user from. Wiring it cost instead
|
|
4764
|
+
// of gained — `{beam:{weight:'med',dash:'solid',vendor:'AceSteel'}}` is schema-valid and came back
|
|
4765
|
+
// as `{}` (an all-default entry is deleted), taking `vendor` with it, permanently on the next
|
|
4766
|
+
// autosave. The renderer already tolerates junk tokens (`memberLineStyle` falls back per token), so
|
|
4767
|
+
// nothing downstream needed the clamp either. (Codex, #853.)
|
|
4768
|
+
member_styles:rec,
|
|
4769
|
+
// canonicalise axisDir (SteelCore, resolved at call time — boot() awaits the module before main()),
|
|
4770
|
+
// then let $defs.dim3 itself reject the rows it cannot hold: id/a/b/axis are required, id is
|
|
4771
|
+
// minLength 1, axis is an enum and the row is additionalProperties:false, NONE of which
|
|
4772
|
+
// sanitizeDims3d checks — so any of them used to cost the entire draft.
|
|
4773
|
+
dims3d:v=>arr(v)&&rowsOk(SteelCore.sanitizeDims3d(v),'dim3'),
|
|
4774
|
+
};
|
|
4775
|
+
for(const key of rootKeys)if(key in d){
|
|
4776
|
+
const raw=structuredClone(d[key]),clean=DRAFT_SANITIZERS[key];
|
|
4777
|
+
if(clean){
|
|
4778
|
+
const val=clean(raw);
|
|
4779
|
+
if(val===undefined){unusableRoots.push(key);continue;} // wrong-typed root → keep the document's value
|
|
4780
|
+
candidate[key]=val;
|
|
4781
|
+
}else candidate[key]=raw;
|
|
4782
|
+
// Dropping a row silently is the half that makes this dangerous — the draft the user asked for came
|
|
4783
|
+
// back short and nothing said so. Warn per key, with the count, so a short restore has a local trail.
|
|
4784
|
+
// Only `connections` can shorten today (the others map 1:1 or are objects), but the guard is written
|
|
4785
|
+
// against the LENGTH rather than the key, so a sanitiser that starts dropping keeps its trail too.
|
|
4786
|
+
if(clean&&Array.isArray(raw)&&Array.isArray(candidate[key])&&candidate[key].length<raw.length)
|
|
4787
|
+
console.warn('steel-editor: dropped '+(raw.length-candidate[key].length)+' unusable '+key+' row(s) restoring the browser draft — the rest of the draft was kept');
|
|
4788
|
+
}
|
|
4789
|
+
// Louder than a dropped row, because a whole collection did not come back: whatever the user changed
|
|
4790
|
+
// under these keys is not on screen, and the document's version is showing in its place.
|
|
4791
|
+
if(unusableRoots.length)
|
|
4792
|
+
console.warn('steel-editor: the browser draft held a malformed '+unusableRoots.join(', ')+' — that key was NOT restored and the model’s own value is being shown; the rest of the draft was applied');
|
|
4182
4793
|
// REFERENCES ARE RECONCILED, NEVER REPLACED — and this is not tidiness, it is a reference that
|
|
4183
4794
|
// vanished in front of me. Which references EXIST is the server's answer: insert and remove are
|
|
4184
4795
|
// routes that write the contract themselves, and `adoptReferenceWrite` then re-points this draft at
|
|
@@ -4353,9 +4964,16 @@ function memberLineStyle(m){const s=C.member_styles&&C.member_styles[memberTypeO
|
|
|
4353
4964
|
function setMemberLineStyle(tk,prop,val){edit(()=>{const cur=(C.member_styles[tk]&&typeof C.member_styles[tk]==='object')?C.member_styles[tk]:{};
|
|
4354
4965
|
const next={weight:cur.weight||'med',dash:cur.dash||'solid'};next[prop]=val;
|
|
4355
4966
|
if(next.weight==='med'&&next.dash==='solid')delete C.member_styles[tk];else C.member_styles[tk]=next;});}
|
|
4356
|
-
// F5:
|
|
4357
|
-
//
|
|
4358
|
-
//
|
|
4967
|
+
// F5: canonicalise a member_styles map to valid tokens + normalised type keys, and drop all-default entries
|
|
4968
|
+
// — the same shape `setMemberLineStyle` writes, so this is the WRITE-side canonical form.
|
|
4969
|
+
//
|
|
4970
|
+
// IT IS NOT THE DRAFT-RESTORE GUARD, and the reason it reads like one is that its original rationale was
|
|
4971
|
+
// wrong: "a bogus token would fail validation on save" is false. `member_styles` is `additionalProperties:
|
|
4972
|
+
// true` and otherwise unconstrained, so `{beam:{weight:'bogus'}}` validates, and the only member_styles the
|
|
4973
|
+
// schema refuses is a non-object. Nothing here protects a save. Running it over a restored draft only
|
|
4974
|
+
// destroyed data — a schema-valid entry carrying an unknown key came back stripped, or, if its tokens were
|
|
4975
|
+
// the defaults, deleted outright — so `applyDraftFields` guards that key with a plain object-check instead
|
|
4976
|
+
// and this stays on the write path. See DRAFT_SANITIZERS (Codex, #853).
|
|
4359
4977
|
function sanitizeMemberStyles(ms){if(!ms||typeof ms!=='object'||Array.isArray(ms))return {};
|
|
4360
4978
|
const WOK={thin:1,med:1,thick:1},DOK={solid:1,dashed:1,dotted:1,dashdot:1},out={};
|
|
4361
4979
|
const nk=k=>String(k||'').trim().toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^-+|-+$/g,'').slice(0,48); // mirrors normMemberTypeKey (a const defined later → inlined so this stays callable at boot-time init)
|
|
@@ -4369,22 +4987,36 @@ function sanitizeMemberStyles(ms){if(!ms||typeof ms!=='object'||Array.isArray(ms
|
|
|
4369
4987
|
// anyway and keeping it would only let a later save write a contract the schema rejects (id is required).
|
|
4370
4988
|
// The recipe/notes/image keys carry each detail's meaning, so they are preserved but shape-checked —
|
|
4371
4989
|
// detail-recipes.ts already refuses a malformed recipe, and this keeps junk from reaching it at all.
|
|
4990
|
+
//
|
|
4991
|
+
// THE ID IS NEITHER TRUNCATED NOR TRIMMED-AND-JUDGED, unlike every other string here — it is taken
|
|
4992
|
+
// verbatim or the row is dropped, and the ONLY rejections are "not a string" and "" (which the schema's
|
|
4993
|
+
// `minLength:1` forbids outright, so no valid document can hold one). An id is IDENTITY, matched by exact
|
|
4994
|
+
// string, and every narrowing of it is the same bug wearing a different hat: `ends[].conn` / `joints[].conn`
|
|
4995
|
+
// keep the ORIGINAL value, `checkModelReferences` then reports conn-unresolved, and the restore is refused
|
|
4996
|
+
// WHOLESALE — the precise atomic draft loss this sanitiser was wired up to prevent. Two such narrowings
|
|
4997
|
+
// have been caught here already (Codex, #853): a `slice(0,120)` clamp, which broke any id over 120 chars,
|
|
4998
|
+
// and a `.trim()` test, which dropped a whitespace-only id like " " that is schema-valid, reference-clean
|
|
4999
|
+
// and resolves perfectly well. Bound the text fields; never touch the key they are found by.
|
|
4372
5000
|
function sanitizeConnections(rows){if(!Array.isArray(rows))return [];
|
|
4373
|
-
|
|
4374
|
-
|
|
5001
|
+
// ROWS ARE DROPPED, NEVER RESHAPED. This function used to rebuild `recipe` from {kind,params,schedule}
|
|
5002
|
+
// and each note from {text,source}, clamping several of them — which quietly DELETED every other key.
|
|
5003
|
+
// `connections[].items` is `required:['id']` with `additionalProperties:true`, deliberately: a row carries
|
|
5004
|
+
// whatever a vendor's detail means, so `recipe.vendor`, `recipe.partNumber`, a note's `author` or `rfi`
|
|
5005
|
+
// are all valid data. Restoring a draft therefore stripped them, and — unlike a refused restore, which at
|
|
5006
|
+
// least leaves the server copy intact — the NEXT ordinary autosave wrote the stripped version back, making
|
|
5007
|
+
// the loss permanent and silent. Third narrowing caught in review here (Codex, #853), after the id clamp
|
|
5008
|
+
// and the id trim, and the same lesson each time: this guard may not hold an opinion the schema does not.
|
|
5009
|
+
//
|
|
5010
|
+
// What is left is only what is load-bearing — the two shapes the schema genuinely cannot hold, each of
|
|
5011
|
+
// which would refuse every save from the moment it lands. Shape-checking `recipe` was belt-and-braces on
|
|
5012
|
+
// top of detail-recipes.ts, which resolves a recipe to a NAMED refusal rather than trusting it.
|
|
5013
|
+
//
|
|
5014
|
+
// Rows are returned by reference; the DRAFT_SANITIZERS call site structuredClones its input first.
|
|
4375
5015
|
const out=[];
|
|
4376
|
-
for(const r of rows){
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
if(rec){const kind=txt(rec.kind,64);
|
|
4381
|
-
row.recipe={...(kind?{kind}:{}),...(obj(rec.params)?{params:obj(rec.params)}:{}),
|
|
4382
|
-
...(Array.isArray(rec.schedule)?{schedule:rec.schedule.filter(s=>s&&typeof s==='object'&&!Array.isArray(s)).slice(0,200)}:{})};
|
|
4383
|
-
}else if('recipe' in row)delete row.recipe;
|
|
4384
|
-
if(Array.isArray(r.notes))row.notes=r.notes.filter(n=>n&&typeof n==='object'&&typeof n.text==='string')
|
|
4385
|
-
.slice(0,200).map(n=>({text:n.text.slice(0,2000),...(typeof n.source==='string'?{source:n.source.slice(0,32)}:{})}));
|
|
4386
|
-
else if('notes' in row)delete row.notes;
|
|
4387
|
-
out.push(row);}
|
|
5016
|
+
for(const r of rows){
|
|
5017
|
+
if(!r||typeof r!=='object'||Array.isArray(r))continue; // items: {type:'object'}
|
|
5018
|
+
if(typeof r.id!=='string'||r.id==='')continue; // id: required, minLength 1 — '' only
|
|
5019
|
+
out.push(r);}
|
|
4388
5020
|
return out;}
|
|
4389
5021
|
function len(a,b){return Math.hypot(a[0]-b[0],a[1]-b[1]);}
|
|
4390
5022
|
// ── Column profile sections ─────────────────────────────────────────────────────────────────────
|
|
@@ -5592,6 +6224,7 @@ function anyToolActive(){
|
|
|
5592
6224
|
if(dimMode||dimChain||dimSplitMode||geoMode||csaxisMode||gridMode||gridPick||gridLinePick||dimStyleMode||mode==='add'||picking||cmTool||qdPick)return true; // 2D tools armed (cmTool = Move/Copy; qdPick = the F7 grid station pick)
|
|
5593
6225
|
if(view3d&&window.Steel3DView){if(window.Steel3DView.clipMode&&window.Steel3DView.clipMode())return true;
|
|
5594
6226
|
if(window.Steel3DView.refMeasureState&&window.Steel3DView.refMeasureState().armed)return true; // the reference measure owns the left-click too, so Space/Enter must not re-invoke the last command over it
|
|
6227
|
+
if(window.Steel3DView.connMemberPick&&window.Steel3DView.connMemberPick())return true; // the member pick owns ENTER (it confirms) — without this, Enter also fires repeatLast() and arms an unrelated tool behind the user
|
|
5595
6228
|
const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))return true;} // 3D dim/clip armed
|
|
5596
6229
|
return false;
|
|
5597
6230
|
}
|
|
@@ -5955,6 +6588,159 @@ function doDup(){const arr=sel2d();if(!arr.length)return;const o=12,pv=snapshot(
|
|
|
5955
6588
|
mc.replaceEndpoints(c,[[s.wp[0][0]+o,s.wp[0][1]+o],[s.wp[1][0]+o,s.wp[1][1]+o]]); // replaces the wp array wholesale, as `c.wp=[[…],[…]]` did
|
|
5956
6589
|
mc.addMembers(P,[c]);ns.add(c.id);}
|
|
5957
6590
|
selIds=ns;selDimIds.clear();mode='sel';setMode();pushUndo(pv);render();}
|
|
6591
|
+
/* Matches REF_TREE_CAP / RC_CAP deliberately rather than minting a second cap number for the codebase.
|
|
6592
|
+
Past it the list says "Showing N of M" — a silent truncation would read as "that is all of them". */
|
|
6593
|
+
const REVIEW_LIST_CAP=300;
|
|
6594
|
+
let reviewFlyKind=null; // 'needs-review' | 'untracked' while the list is open
|
|
6595
|
+
function reviewCountsOf(){
|
|
6596
|
+
return {review:reviewSummary&&Array.isArray(reviewSummary.needsReview)?reviewSummary.needsReview.length:0,
|
|
6597
|
+
untracked:reviewSummary&&Array.isArray(reviewSummary.untracked)?reviewSummary.untracked.length:0};}
|
|
6598
|
+
/* Paint the two header counts. THE header surface, because in Plan (2D) the inspector, the breadcrumb and
|
|
6599
|
+
the 3D scene do not exist — this is the only place the state can appear there. */
|
|
6600
|
+
function renderReviewSurface(){
|
|
6601
|
+
const rs=document.getElementById('reviewStat'),us=document.getElementById('untrackedStat'),un=document.getElementById('reviewUnavailStat');
|
|
6602
|
+
if(!rs||!us||!un)return;
|
|
6603
|
+
// Unavailable hides both counts (a zero would be a claim the server did not make) and says so plainly,
|
|
6604
|
+
// because two hidden counts on their own are indistinguishable from a clean model.
|
|
6605
|
+
// The early return still has to carry the other surfaces: when the state becomes unavailable the amber
|
|
6606
|
+
// has to come OFF the 3D parts too, or the model keeps asserting a review state the server just
|
|
6607
|
+
// disclaimed. Returning before the sync was the same disagreement this whole function exists to avoid.
|
|
6608
|
+
if(reviewUnavailable||!reviewSummary){un.hidden=!reviewUnavailable;rs.hidden=true;us.hidden=true;closeReviewFly();syncReviewToScene();return;}
|
|
6609
|
+
un.hidden=true;
|
|
6610
|
+
const c=reviewCountsOf();
|
|
6611
|
+
rs.hidden=c.review===0;rs.classList.toggle('has',c.review>0);
|
|
6612
|
+
const rc=document.getElementById('reviewCount');if(rc)rc.textContent=String(c.review);
|
|
6613
|
+
us.hidden=c.untracked===0;
|
|
6614
|
+
const uc=document.getElementById('untrackedCount');if(uc)uc.textContent=String(c.untracked);
|
|
6615
|
+
// A list left open over a count that just went to zero would be a list of nothing.
|
|
6616
|
+
if(reviewFlyKind==='needs-review'&&!c.review)closeReviewFly();
|
|
6617
|
+
if(reviewFlyKind==='untracked'&&!c.untracked)closeReviewFly();
|
|
6618
|
+
if(reviewFlyKind)paintReviewFly(reviewFlyKind);
|
|
6619
|
+
syncReviewToScene();}
|
|
6620
|
+
/* The other two surfaces. The header is not the only place this state shows, and the review state can
|
|
6621
|
+
move without the geometry moving — so a repaint that updated only the counts would leave the 3D parts
|
|
6622
|
+
wearing their old colour and a selected connection's chip asserting the old state. Three surfaces
|
|
6623
|
+
derived from one summary must not be allowed to disagree. */
|
|
6624
|
+
function syncReviewToScene(){
|
|
6625
|
+
const v=window.Steel3DView;
|
|
6626
|
+
if(v&&v.setConnReview&&v.isReady&&v.isReady()){
|
|
6627
|
+
const map=new Map();
|
|
6628
|
+
if(reviewSummary&&!reviewUnavailable){
|
|
6629
|
+
for(const e of reviewSummary.needsReview||[])map.set(e.jointId,'needs-review');
|
|
6630
|
+
for(const e of reviewSummary.untracked||[])map.set(e.jointId,'untracked');
|
|
6631
|
+
}
|
|
6632
|
+
v.setConnReview(map);
|
|
6633
|
+
}
|
|
6634
|
+
/* Repaint the inspector ONLY when a whole custom connection is showing — that is the only view whose
|
|
6635
|
+
chip can go stale. Narrow on purpose: panel() rebuilds the inspector, and rebuilding it while the
|
|
6636
|
+
user is typing in one of its fields would discard the keystrokes. */
|
|
6637
|
+
const cs=(typeof connSelInfo==='function')?connSelInfo():null;
|
|
6638
|
+
if(cs&&cs.whole&&cs.joint&&cs.joint.kind==='custom')panel();}
|
|
6639
|
+
/* What the review record says about ONE joint, for the inspector. Reads the summary the transport
|
|
6640
|
+
installed — never the scene — so it is the same answer in Plan view, where no scene exists. */
|
|
6641
|
+
function reviewStateOf(jointId){
|
|
6642
|
+
if(reviewUnavailable)return 'unavailable';
|
|
6643
|
+
if(!reviewSummary)return 'clean';
|
|
6644
|
+
if((reviewSummary.needsReview||[]).some(r=>r.jointId===jointId))return 'needs-review';
|
|
6645
|
+
if((reviewSummary.untracked||[]).some(r=>r.jointId===jointId))return 'untracked';
|
|
6646
|
+
/* CLEAN-AND-ACCEPTED is its own state, not a decoration on clean. Reopen review is offered only here,
|
|
6647
|
+
and a chip that still read "Imported geometry" beside it would leave the user no on-screen evidence
|
|
6648
|
+
that anything was ever reviewed. Read from the SUMMARY, never from client history: a second tab, a
|
|
6649
|
+
reload and a reconnect would each get a remembered sign-off wrong. */
|
|
6650
|
+
if(reviewSignedOff(jointId))return 'signed-off';
|
|
6651
|
+
return 'clean';}
|
|
6652
|
+
/* The server reports which clean joints a human explicitly accepted, because only the store knows.
|
|
6653
|
+
Gated on the derived state being clean too (the server already does this) — a stale acceptance must
|
|
6654
|
+
never keep "Reopen review" on screen over a joint that is currently asking for review. */
|
|
6655
|
+
function reviewSignedOff(jointId){
|
|
6656
|
+
return !!(reviewSummary&&Array.isArray(reviewSummary.signedOff)&&reviewSummary.signedOff.indexOf(jointId)!==-1);}
|
|
6657
|
+
/* The custom-connection chip. It REPLACES the old neutral one rather than sitting beside it — this slot
|
|
6658
|
+
already was "what kind of connection is this", and a second chip would make the row say two things.
|
|
6659
|
+
Amber only for needs-review: untracked keeps the neutral colours and changes only its leading word, so
|
|
6660
|
+
it is distinguishable on read without ever suggesting a fault. */
|
|
6661
|
+
function reviewChipFor(jointId){
|
|
6662
|
+
const st=reviewStateOf(jointId);
|
|
6663
|
+
if(st==='needs-review')return '<span class=chip style="border-color:var(--warn-edge);color:var(--warn)" data-tip="The steel this connection is watching has moved since it was placed">Needs review — the steel it sits on moved</span>';
|
|
6664
|
+
if(st==='untracked')return '<span class=chip style="border-color:var(--line);color:var(--mut)" data-tip="Steel moving under this connection will not be flagged — place it again to start watching it">Untracked — move / replace only</span>';
|
|
6665
|
+
// Not grey: grey would be indistinguishable from clean and would claim a confidence the server did not
|
|
6666
|
+
// give. Cyan is this file's existing "informational, not an error" idiom.
|
|
6667
|
+
if(st==='unavailable')return '<span class=chip style="border-color:var(--cyan-edge);color:var(--cyan);background:var(--cyan-soft)" data-tip="The server could not check this connection for moved steel this time">Review status unavailable</span>';
|
|
6668
|
+
/* Green, through the EXISTING `.chip.verified` recipe whose token is already commented "human-confirmed"
|
|
6669
|
+
— the same idea, so it gets the same colour rather than a new one. */
|
|
6670
|
+
if(st==='signed-off')return '<span class="chip verified" data-tip="Someone confirmed this connection against the steel it sits on — it is still being watched">✓ Reviewed — checked against this steel</span>';
|
|
6671
|
+
// The clean state gets a tooltip too. Every other state explains itself on hover, and a chip that is
|
|
6672
|
+
// the only silent one reads as an oversight rather than a decision.
|
|
6673
|
+
return '<span class=chip style="border-color:var(--line);color:var(--mut)" data-tip="This connection is being watched — the steel it was placed against has not moved">Imported geometry — move / replace only</span>';}
|
|
6674
|
+
/* The DRILLED-PART chip. It names the connection explicitly, because the part's own kind (Bolt, Plate…)
|
|
6675
|
+
is the first thing on screen and a bare "Needs review" there would read as "this bolt needs review".
|
|
6676
|
+
Shown only for needs-review and unavailable: 3D selection out-ranks the amber lift, so without this the
|
|
6677
|
+
warning would disappear entirely while a part is selected. Untracked is omitted on purpose — it never
|
|
6678
|
+
had a lift to lose, and repeating it on every bolt of a legacy connection is noise. */
|
|
6679
|
+
function partReviewChipFor(jointId){
|
|
6680
|
+
const st=reviewStateOf(jointId);
|
|
6681
|
+
if(st==='needs-review')return '<div class=row style="margin:2px 0 4px"><span class=chip style="border-color:var(--warn-edge);color:var(--warn)" data-tip="The parent connection is flagged — step back to it to act">Connection needs review</span></div>';
|
|
6682
|
+
if(st==='unavailable')return '<div class=row style="margin:2px 0 4px"><span class=chip style="border-color:var(--cyan-edge);color:var(--cyan);background:var(--cyan-soft)">Connection review unavailable</span></div>';
|
|
6683
|
+
return '';}
|
|
6684
|
+
function closeReviewFly(){
|
|
6685
|
+
const fly=document.getElementById('reviewFly');if(fly)fly.classList.remove('open');
|
|
6686
|
+
for(const id of ['reviewStat','untrackedStat']){const b=document.getElementById(id);if(b)b.setAttribute('aria-expanded','false');}
|
|
6687
|
+
reviewFlyKind=null;}
|
|
6688
|
+
function paintReviewFly(kind){
|
|
6689
|
+
const list=document.getElementById('reviewFlyList'),title=document.getElementById('reviewFlyTitle'),
|
|
6690
|
+
cnt=document.getElementById('reviewFlyCount'),more=document.getElementById('reviewFlyMore');
|
|
6691
|
+
if(!list||!reviewSummary)return;
|
|
6692
|
+
const rows=kind==='needs-review'?(reviewSummary.needsReview||[]):(reviewSummary.untracked||[]);
|
|
6693
|
+
title.textContent=kind==='needs-review'?'Needs review':'Not watched';
|
|
6694
|
+
cnt.textContent=String(rows.length);
|
|
6695
|
+
const shown=rows.slice(0,REVIEW_LIST_CAP);
|
|
6696
|
+
list.innerHTML=shown.map(r=>{
|
|
6697
|
+
const j=(Array.isArray(C.joints)?C.joints:[]).find(x=>x&&x.id===r.jointId);
|
|
6698
|
+
const nm=esc((j&&j.name)||r.jointId);
|
|
6699
|
+
const sub=kind==='needs-review'?esc((r.memberIds||[]).length+' member'+((r.memberIds||[]).length===1?'':'s')):'not watched';
|
|
6700
|
+
// The instance key names what the row acts on, so the guidance band reads "Selects <that connection>"
|
|
6701
|
+
// rather than printing "{instance}" verbatim. Escaped — a connection is user-named.
|
|
6702
|
+
// The instance LABEL as well as the key: an unnamed joint would otherwise have `?` narrate its raw id.
|
|
6703
|
+
return '<button data-command-id="steel.review-select#'+esc((j&&j.name)||r.jointId)+'" data-command-instance-label="'+esc((j&&j.name)||('connection '+r.jointId))+'" class=frow data-joint="'+esc(r.jointId)+'"><span class=nm>'+nm+'</span><span class=sub>'+sub+'</span></button>';
|
|
6704
|
+
}).join('');
|
|
6705
|
+
more.hidden=rows.length<=REVIEW_LIST_CAP;
|
|
6706
|
+
if(!more.hidden)more.textContent='Showing '+shown.length+' of '+rows.length+'.';
|
|
6707
|
+
for(const b of list.querySelectorAll('.frow'))b.onclick=()=>selectReviewedJoint(b.getAttribute('data-joint'),kind);}
|
|
6708
|
+
function openReviewFly(kind,trigger){
|
|
6709
|
+
if(!reviewSummary||reviewUnavailable)return;
|
|
6710
|
+
if(reviewFlyKind===kind){closeReviewFly();return;} // the trigger toggles
|
|
6711
|
+
reviewFlyKind=kind;paintReviewFly(kind);
|
|
6712
|
+
const fly=document.getElementById('reviewFly');if(!fly||!trigger)return;
|
|
6713
|
+
const r=trigger.getBoundingClientRect();fly.style.left=Math.max(8,Math.min(r.left,window.innerWidth-266))+'px';fly.style.top=(r.bottom+6)+'px';
|
|
6714
|
+
fly.classList.add('open');
|
|
6715
|
+
for(const id of ['reviewStat','untrackedStat']){const b=document.getElementById(id);if(b)b.setAttribute('aria-expanded',String(id===(kind==='needs-review'?'reviewStat':'untrackedStat')));}
|
|
6716
|
+
const first=fly.querySelector('.frow');if(first)first.focus();}
|
|
6717
|
+
/* A needs-review row selects the MEMBERS the user named — they exist in the contract, so this works in
|
|
6718
|
+
Plan view where the joint itself has no representation. An untracked row has no members recorded, so
|
|
6719
|
+
the only thing it can point at is the joint, which is a 3D-only object. */
|
|
6720
|
+
async function selectReviewedJoint(jointId,kind){
|
|
6721
|
+
const entry=kind==='needs-review'?(reviewSummary.needsReview||[]).find(r=>r.jointId===jointId):null;
|
|
6722
|
+
closeReviewFly();
|
|
6723
|
+
if(entry&&(entry.memberIds||[]).length){selIds=new Set(entry.memberIds);selDimIds.clear();sel3dDimIds.clear();selGridIds.clear();render();return;}
|
|
6724
|
+
/* No members recorded, so the joint itself is the only thing to point at — and a custom connection is a
|
|
6725
|
+
3D-only object, with no representation in the plan. Switch first, then select.
|
|
6726
|
+
|
|
6727
|
+
THROUGH setView, and NOT through applyViewState. applyViewState is the chrome half — it flips the
|
|
6728
|
+
toggle and swaps the panes. setView is the half that calls init(), show() and awaits rebuild(). Going
|
|
6729
|
+
round it left the pane blank and frozen (no meshes to select, no render loop), and stuck: viewMode was
|
|
6730
|
+
already '3d', so a later setView('3d') is a no-op and no edit repairs it, because sync3D gates on
|
|
6731
|
+
view3dShown && view3dReady. This is the COMMON path — every pre-existing connection is untracked. */
|
|
6732
|
+
if(viewMode==='2d')await setView('3d');
|
|
6733
|
+
/* And only select if we ACTUALLY got there. setView has its own refusal path — no renderer, or a newer
|
|
6734
|
+
view request superseding this one — after which it leaves the tab in 2D. Selecting anyway would put a
|
|
6735
|
+
selection somewhere the user cannot see and cannot clear. */
|
|
6736
|
+
if(viewMode!=='3d'){toast('Open the 3D view to see this connection');return;}
|
|
6737
|
+
if(window.Steel3DView&&window.Steel3DView.selectWholeConn)window.Steel3DView.selectWholeConn(jointId);}
|
|
6738
|
+
/* Publish the renderer for the boot-scope transport, and paint ONCE right now.
|
|
6739
|
+
The initial paint is not optional: boot() installs the snapshot's review summary BEFORE main() runs,
|
|
6740
|
+
so that first repaint finds no renderer on `window` and is a no-op. Without this line the counts stay
|
|
6741
|
+
hidden until something else happens to move the review state — which on a quiet model is never. */
|
|
6742
|
+
window.renderReviewSurface=renderReviewSurface;
|
|
6743
|
+
renderReviewSurface();
|
|
5958
6744
|
function esc(s){return String(s).replace(/[<>&"]/g,c=>({'<':'<','>':'>','&':'&','"':'"'}[c]));}
|
|
5959
6745
|
function memberEndReviewSvg(){
|
|
5960
6746
|
if(!memberEndReview||NO_PLAN_VIEW||!P||!P.members)return '';
|
|
@@ -6495,10 +7281,27 @@ function panel(){
|
|
|
6495
7281
|
if(j.kind==='custom'){
|
|
6496
7282
|
const nm=j.name?esc(j.name):'Imported connection';
|
|
6497
7283
|
const onLine=j.main?`On <button data-command-id="steel.connection-select-member" class=pilllink id=cmpMember data-tip="Select ${esc(j.main)}">${esc(j.main)}</button> · `:'';
|
|
7284
|
+
/* THE REVIEW ACTIONS GET THEIR OWN ROW, above the connection-management one. Not tidiness: the row
|
|
7285
|
+
below ends with a destructive Delete, and the review actions are the most-clicked thing on this
|
|
7286
|
+
pane while a connection is flagged — a single six-wide wrapping row would land them adjacent. The
|
|
7287
|
+
row break is what keeps Delete structurally isolated rather than incidentally distant.
|
|
7288
|
+
|
|
7289
|
+
HIDDEN, never disabled, when they do not apply — the house rule. Mark-as-reviewed and Reopen are
|
|
7290
|
+
mutually exclusive by construction (a joint cannot be both needs-review and clean-and-accepted),
|
|
7291
|
+
so this row is at most two buttons wide. Neither shows while the state is `unavailable`: letting
|
|
7292
|
+
someone assert an acceptance over a baseline the server could not even report would be a worse
|
|
7293
|
+
claim than showing nothing. */
|
|
7294
|
+
const rst=reviewStateOf(j.id);
|
|
7295
|
+
const reviewRow=[
|
|
7296
|
+
rst==='needs-review'?`<button data-command-id="steel.connection-sign-off" class=ghostw id=cmpSign data-tip="Confirms this connection still fits the steel it sits on now. This is a sign-off record, not a model edit — Ctrl+Z will not undo it.">✓ Mark as reviewed</button>`:'',
|
|
7297
|
+
rst==='signed-off'?`<button data-command-id="steel.connection-reopen" class=ghostw id=cmpReopen data-tip="Clears the sign-off, so this connection asks to be checked again. Also a record rather than a model edit — Ctrl+Z will not undo it.">Reopen review</button>`:'',
|
|
7298
|
+
`<button data-command-id="steel.connection-replace" class="ghostw${connReplaceArm===j.id?' on':''}" id=cmpAgain data-tip="Click where this connection sits, then name the members it joins — the only way to start watching an untracked one. It stops being watched until you finish.">⌖ Place again…</button>`,
|
|
7299
|
+
].join('');
|
|
6498
7300
|
p.innerHTML=`<span class=badge>Custom connection</span>
|
|
6499
|
-
<div class=row style="margin:0 0 6px"
|
|
7301
|
+
<div class=row style="margin:0 0 6px">${reviewChipFor(j.id)}</div>
|
|
6500
7302
|
<div class="row hint" style="margin:0 0 2px">${onLine}${cs.childIds.length} parts · ${nm}</div>
|
|
6501
7303
|
<div class="row hint" style="margin:0 0 6px;font-size:11px">Read from IFC — opaque tessellated geometry (no per-dimension edit). <b>Esc</b> steps back.</div>
|
|
7304
|
+
<div class="row f" style="gap:6px;flex-wrap:wrap;margin:0 0 8px">${reviewRow}</div>
|
|
6502
7305
|
<div class=divrow><hr></div>
|
|
6503
7306
|
<div class="row f" style="gap:6px;flex-wrap:wrap">
|
|
6504
7307
|
<button data-command-id="steel.connection-modify-request" class=ghostw id=cmpAsk data-tip="Record a request for your terminal AI to move / replace this connection">Modify connection…</button>
|
|
@@ -6506,6 +7309,9 @@ function panel(){
|
|
|
6506
7309
|
<button data-command-id="steel.connection-favourite" class=ghostw id=cmpFav data-tip="Save this imported geometry to your Favourites — drops in place, will not re-fit">★ Save to Favourites</button>
|
|
6507
7310
|
</div>`;
|
|
6508
7311
|
{const b=document.getElementById('cmpMember');if(b)b.onclick=()=>{if(window.Steel3DView&&window.Steel3DView.clearConnSel)window.Steel3DView.clearConnSel();selIds=new Set([j.main]);selDimIds.clear();sel3dDimIds.clear();selGridIds.clear();render();};}
|
|
7312
|
+
{const b=document.getElementById('cmpSign');if(b)b.onclick=()=>signOffConnection(j.id);}
|
|
7313
|
+
{const b=document.getElementById('cmpReopen');if(b)b.onclick=()=>reopenConnectionReview(j.id);}
|
|
7314
|
+
{const b=document.getElementById('cmpAgain');if(b)b.onclick=()=>armConnectionReplace(j.id);}
|
|
6509
7315
|
{const b=document.getElementById('cmpAsk');if(b)b.onclick=()=>connModifyRequest(j);}
|
|
6510
7316
|
{const b=document.getElementById('cmpDel');if(b)b.onclick=()=>edit(()=>{C.joints=(C.joints||[]).filter(x=>x!==j);selIds.clear();});}
|
|
6511
7317
|
{const b=document.getElementById('cmpFav');if(b)b.onclick=()=>openFavModalFor(j);}
|
|
@@ -6598,6 +7404,7 @@ function panel(){
|
|
|
6598
7404
|
else if(pk==='aplate')body=sec('Anchor plate')+kv('Width',dim(el&&el.width))+kv('Height',dim(el&&el.depth))+kv('Thickness',dim(el&&el.thickness));
|
|
6599
7405
|
else body=sec(kindName+'')+kv('Width',dim(el&&el.width))+kv('Height',dim(el&&el.depth))+kv('Thickness',dim(el&&el.thickness));
|
|
6600
7406
|
p.innerHTML=`<h3>${esc(head)} <span style="color:var(--mut);font-weight:400">· ${loc}</span></h3>
|
|
7407
|
+
${partReviewChipFor(j.id)}
|
|
6601
7408
|
<div class="row hint" style="margin-top:2px">Read-only — auto-detailed on <b>${esc(j.main)}</b>; edit its parameters on the member.</div>
|
|
6602
7409
|
${lbl?`<div class="row" style="margin:3px 0 0;font-size:12px;color:var(--brand);font-variant-numeric:tabular-nums">${esc(lbl)}</div>`:''}
|
|
6603
7410
|
${body}
|
|
@@ -7499,13 +8306,26 @@ const PROP_DEFS=[
|
|
|
7499
8306
|
{key:'col_detail',label:'Detail', get:m=>m.role==='column'?(m.col?(m.col.detail||''):undefined):undefined, fmt:v=>v==null?'':String(v)},
|
|
7500
8307
|
];
|
|
7501
8308
|
const PROP_KEYS=new Set(PROP_DEFS.map(d=>d.key));
|
|
7502
|
-
//
|
|
8309
|
+
// Normalise persisted/incoming prop_labels to what `$defs.propLabels` ACTUALLY permits — not to what this
|
|
8310
|
+
// build happens to understand. The distinction cost data twice here (Codex, #853):
|
|
8311
|
+
//
|
|
8312
|
+
// - `props` is `items:{type:'string'}`, so ANY string is valid. Filtering it to `PROP_KEYS` deleted a
|
|
8313
|
+
// token this build does not know — exactly what a NEWER build's draft carries — and the next autosave
|
|
8314
|
+
// persisted the loss, silently reaching back and unpicking a selection made elsewhere. Unknown tokens
|
|
8315
|
+
// are inert to every reader (`propLabelLinesFor` walks PROP_DEFS), so carrying them costs nothing.
|
|
8316
|
+
// - `ids` is `items:{minLength:1}`, and the old `typeof v==='string'` test let `''` through — the mirror
|
|
8317
|
+
// mistake, a guard under-enforcing, which refuses every save (`expected at least 1 characters`).
|
|
8318
|
+
//
|
|
8319
|
+
// `placement` (an enum) and the three booleans ARE schema-constrained, so clamping those is this
|
|
8320
|
+
// function's job rather than an opinion.
|
|
7503
8321
|
function sanitizePropLabels(x){const o=(x&&typeof x==='object'&&!Array.isArray(x))?x:{};
|
|
7504
|
-
return {props:Array.isArray(o.props)?o.props.filter(k=>
|
|
8322
|
+
return {props:Array.isArray(o.props)?o.props.filter(k=>typeof k==='string'):[],
|
|
7505
8323
|
placement:['start','mid','end'].includes(o.placement)?o.placement:'mid',
|
|
7506
8324
|
selected_only:o.selected_only===true,
|
|
7507
8325
|
vis2d:o.vis2d!==false,vis3d:o.vis3d!==false, // per-view label VISIBILITY (B1): default ON; the property SELECTION (props) stays shared across 2D+3D — only show/hide is independent
|
|
7508
|
-
ids:Array.isArray(o.ids)?o.ids.filter(v=>typeof v==='string'):[]};}
|
|
8326
|
+
ids:Array.isArray(o.ids)?o.ids.filter(v=>typeof v==='string'&&v!==''):[]};}
|
|
8327
|
+
/** How many selected props this build can actually draw — `props` may carry tokens minted by a newer one. */
|
|
8328
|
+
const knownPropCount=pl=>(pl&&Array.isArray(pl.props)?pl.props.filter(k=>PROP_KEYS.has(k)).length:0);
|
|
7509
8329
|
// Normalise the optional property-label object before any renderer reads it. Every key written here is
|
|
7510
8330
|
// part of the native schema, including the independent 2D/3D visibility flags.
|
|
7511
8331
|
C.prop_labels=sanitizePropLabels(C.prop_labels);
|
|
@@ -7670,7 +8490,9 @@ function renderPropPop(){const el=document.getElementById('propPop');if(!el||!el
|
|
|
7670
8490
|
if(propPopConn){renderConnTree(el);return;} // connection / mixed-selection tree view
|
|
7671
8491
|
const arr=selArr(),pl=C.prop_labels,q=(el.querySelector('#ppSearch').value||'').trim().toLowerCase();
|
|
7672
8492
|
el.querySelector('#ppTitle').textContent='Properties'; // short title so the header never clips it; the selection count moved to the roomy scope line below
|
|
7673
|
-
|
|
8493
|
+
// Counts what this build can DRAW, not what `props` holds — a token from a newer build is carried through
|
|
8494
|
+
// the restore now (see sanitizePropLabels) and would otherwise be counted as a label nobody can see.
|
|
8495
|
+
{const n=knownPropCount(pl);el.querySelector('#ppLabeled').textContent=n?n+' labeled':'';}
|
|
7674
8496
|
el.querySelector('#ppScope').textContent=arr.length+(arr.length===1?' member · ':' members · ')+(pl.selected_only?'labels apply to the selected':'labels apply to all on this plan');
|
|
7675
8497
|
el.querySelectorAll('#ppPlace button').forEach(b=>b.classList.toggle('on',b.dataset.pl===pl.placement));
|
|
7676
8498
|
el.querySelector('#ppSel').checked=pl.selected_only;
|
|
@@ -8225,7 +9047,16 @@ function openPositionHud(id,axis,scr){
|
|
|
8225
9047
|
if(!st||!st.available){ // a double-click on a VISIBLE handle that opens nothing is confusing — the view picked it from a cached snapshot, but a fresh read can disagree (a mid-flight external write, a roll that became unresolvable). Surface it instead of a silent return (mirrors currentPositionGizmoState's console.debug + the drag bail).
|
|
8226
9048
|
console.debug('steel: position HUD not opened —',st&&st.reason);
|
|
8227
9049
|
toast('Can’t edit this handle right now'+(st&&st.reason?' — '+st.reason:'')+'. Try the Inspect panel.');return;}
|
|
8228
|
-
|
|
9050
|
+
// Every handle that MOVES THE REFERENCE LINE types a DELTA — how far to translate, how far to swing — so
|
|
9051
|
+
// its “current value” hint is 0. Since the redesign that is all five of them: the depth and width arrows
|
|
9052
|
+
// moved from writing a profile offset to translating the line, and their hint moved with them. The roll arc
|
|
9053
|
+
// is the only handle whose current ABSOLUTE value is still the hint, because it is the only one that still
|
|
9054
|
+
// writes a stored member field. A handle the member cannot take never opens a HUD either, or the user would
|
|
9055
|
+
// type a value into something that can only refuse it.
|
|
9056
|
+
const refline=axis!=='rot';
|
|
9057
|
+
if(refline&&!(st.handles&&st.handles[axis]&&st.handles[axis].available)){
|
|
9058
|
+
toast((st.handles&&st.handles[axis]&&st.handles[axis].reason)||'That handle isn’t available on this member.');return;}
|
|
9059
|
+
const cur=refline?0:st.rot;
|
|
8229
9060
|
posHudTarget={id,axis,cur};
|
|
8230
9061
|
if(view3d&&window.Steel3DView&&window.Steel3DView.setPositionTyping)window.Steel3DView.setPositionTyping(true);
|
|
8231
9062
|
cmHudShow('',{consumer:'position',scr});
|
|
@@ -8240,12 +9071,17 @@ function cmHudSyncPill(){if(!cmHudEl)return;const pill=cmHudEl.querySelector('#c
|
|
|
8240
9071
|
pill.classList.toggle('locked',cmHudLock); // Add 1st point → ABS only, REL hidden (not disabled)
|
|
8241
9072
|
pill.querySelectorAll('.cmHudSeg').forEach(s=>{const on=((s.dataset.mode==='abs')===cmHudAbs);s.setAttribute('aria-checked',on?'true':'false');s.tabIndex=on?0:-1;s.classList.toggle('on',on);}); // roving tabindex: only the selected radio is Tab-reachable
|
|
8242
9073
|
const abs=pill.querySelector('.cmHudSeg[data-mode="abs"]');if(abs)abs.setAttribute('data-tip',cmHudLock?'First point has no anchor to offset from — absolute only':'Absolute — X′,Y′,Z′ in the local frame (X,Y,Z if none)');}
|
|
9074
|
+
function posHudAngular(){return !!(cmHudConsumer==='position'&&posHudTarget&&(posHudTarget.axis==='rot'||posHudTarget.axis==='swingPlan'||posHudTarget.axis==='swingElev'));} // roll + the two swing arcs type DEGREES; every other handle types a length
|
|
8243
9075
|
function cmHudPlaceholder(){if(!cmHudEl)return;const inp=cmHudEl.querySelector('input');if(!inp)return;
|
|
8244
|
-
if(cmHudConsumer==='position'){
|
|
9076
|
+
if(cmHudConsumer==='position'){const ang=posHudAngular();
|
|
9077
|
+
inp.placeholder=posHudTarget?(ang?(String(+(+posHudTarget.cur||0).toFixed(2))+'°'):(posOffDisp(posHudTarget.cur)||'0"')):'';return;} // 3b.3: the current value is the hint (HUD opens empty). 3b.1: a reference-line handle types a DELTA, so its hint is 0.
|
|
8245
9078
|
inp.placeholder=cmHudAbs?(cmHudPrimed?"X′,Y′ · or X′,Y′,Z′":"X,Y · or X,Y,Z"):(cmHudConsumer==='add'?"dx,dy · or dx,dy,dz":"12'-6 · or dx,dy");}
|
|
8246
9079
|
function cmHudEcho(){const inp=cmHudEl.querySelector('input'),lbl=cmHudEl.querySelector('#cmHudLbl');
|
|
8247
9080
|
const pv=parseVec(inp.value),n=(cmTool==='copy'&&!cmArrayMode&&cmCount>1)?(' ×'+cmCount):'';let txt='';
|
|
8248
|
-
|
|
9081
|
+
// An ANGLE is not a length. Echoing it through fmtFtIn turned "45" into "= 3'-9"" on the roll and swing
|
|
9082
|
+
// handles — the placeholder already knew better, so the two halves of the same HUD contradicted each other.
|
|
9083
|
+
if(pv&&posHudAngular()){txt=pv.dist!=null?('= '+String(+(+pv.dist).toFixed(2))+'°'):'';}
|
|
9084
|
+
else if(pv){if(pv.dist!=null){txt='= '+fmtFtIn(pv.dist);}
|
|
8249
9085
|
else{const ax=!view3d?['','','']:(cmHudAbs?(cmHudPrimed?['X′','Y′','Z′']:['X','Y','Z']):['Δx','Δy','Δz']); // 3D echo carries the ′ prime + axis so the space is never ambiguous; 2D stays plain (unchanged)
|
|
8250
9086
|
txt='= '+pv.comp.map((c,i)=>pv.provided[i]?((ax[i]?ax[i]+' ':'')+fmtFtIn(c)):null).filter(Boolean).join(', ');}}
|
|
8251
9087
|
lbl.textContent=(txt?txt+n:n.trim());
|
|
@@ -8290,11 +9126,54 @@ function cmHudCommit(str){
|
|
|
8290
9126
|
if(cmHudConsumer==='position'){ // 3b.3: single scalar → commitMemberPosition (same path as a drag: absolute value, one undo entry). Typed values BYPASS the ¼"/5° snap.
|
|
8291
9127
|
const t=String(str==null?'':str).trim();
|
|
8292
9128
|
if(t===''||!posHudTarget){cmHudClose();return;} // empty = no-op close
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
9129
|
+
// Every handle that moves the reference LINE takes a typed DELTA and commits ABSOLUTE work points.
|
|
9130
|
+
// Since the redesign that is all of them but the roll: the depth and width arrows translate the line
|
|
9131
|
+
// along the member's rolled profile axes instead of writing a profile offset, so they type a distance
|
|
9132
|
+
// to move, exactly as the axial slide always has.
|
|
9133
|
+
if(posHudTarget.axis!=='rot'){
|
|
9134
|
+
const st=memberPositionGizmoState(posHudTarget.id);
|
|
9135
|
+
if(!st||!st.available){cmHudEl.classList.add('err');toast('Can’t move this member right now'+(st&&st.reason?' — '+st.reason:'')+'.');return;}
|
|
9136
|
+
const ax=posHudTarget.axis;
|
|
9137
|
+
let spec=null;
|
|
9138
|
+
if(ax==='slide'||ax==='depth'||ax==='width'){
|
|
9139
|
+
const inch=parseLen(t);if(inch==null||!isFinite(inch)){cmHudEl.classList.add('err');toast('Couldn’t read “'+t+'” as a length — try 3 1/2" or 1\'-3 1/2".');return;}
|
|
9140
|
+
if(Math.abs(inch)<1e-9){cmHudClose();return;} // typing 0 is "never mind", not an error — close quietly rather than toasting the command's inert-move refusal
|
|
9141
|
+
// The axis is the ONLY difference between the three: the member axis for a slide, and st.profile —
|
|
9142
|
+
// the same rolled axes the arrows are drawn along — for depth and width, so a typed value travels
|
|
9143
|
+
// exactly where dragging that arrow would.
|
|
9144
|
+
const tax=ax==='slide'?st.xAxis:ax==='depth'?(st.profile&&st.profile.z):(st.profile&&st.profile.y);
|
|
9145
|
+
const r=SteelCore.translateEndpoints(st.anchor,st.end,tax,inch*25.4);
|
|
9146
|
+
if(!r){cmHudEl.classList.add('err');toast('That move can’t be applied to this member.');return;}
|
|
9147
|
+
spec={from:r.from,to:r.to,gesture:ax==='slide'?'slide':'translate'};
|
|
9148
|
+
}else{
|
|
9149
|
+
const deg=Number(t.replace(',','.'));if(!isFinite(deg)){cmHudEl.classList.add('err');toast('Enter an angle in degrees, e.g. 45 or -90.');return;}
|
|
9150
|
+
let theta=deg*Math.PI/180;
|
|
9151
|
+
const swingAxis=ax==='swingPlan'?st.up:st.yAxis;
|
|
9152
|
+
if(ax==='swingElev'){
|
|
9153
|
+
// A typed value bypasses the SNAP — that is the shipped 3b.3 contract — but it does not bypass
|
|
9154
|
+
// geometry. 'typed' mode REFUSES rather than silently rewriting the number the user asked for; the
|
|
9155
|
+
// HUD stays open in its error state so they can see nothing was committed and pick another angle.
|
|
9156
|
+
const bars=SteelCore.swingBarriers(st.anchor,st.end,st.yAxis,st.up,SteelCore.POSITION_SWING_MARGIN_RAD); // ONE constant shared with the drag path — if they drift, typing a number the drag allowed gets refused
|
|
9157
|
+
const c=bars&&SteelCore.clampSwingTheta(theta,bars,'typed',0);
|
|
9158
|
+
if(!c){cmHudEl.classList.add('err');toast('That angle would tilt the member through plumb — nothing was committed. Try a smaller angle.');return;}
|
|
9159
|
+
theta=c.theta;
|
|
9160
|
+
}
|
|
9161
|
+
const to=SteelCore.swingEndpoint(st.anchor,st.end,swingAxis,theta);
|
|
9162
|
+
if(!to){cmHudEl.classList.add('err');toast('That swing can’t be applied to this member.');return;}
|
|
9163
|
+
spec={to,gesture:ax};
|
|
9164
|
+
}
|
|
9165
|
+
const okRef=commitMemberEndpoints(posHudTarget.id,spec,cmHudEl);
|
|
9166
|
+
if(!okRef){cmHudEl.classList.add('err');return;}
|
|
9167
|
+
cmHudClose();return;
|
|
9168
|
+
}
|
|
9169
|
+
// ONLY the roll reaches here now. It is the last gizmo handle that writes a stored member field rather
|
|
9170
|
+
// than moving the work points, so it is the last caller of commitMemberPosition from the 3D view; the
|
|
9171
|
+
// depth and width arrows used to land here and set positionOffset / positionHOffset, and those two are
|
|
9172
|
+
// panel-only numbers from here on.
|
|
9173
|
+
let val=Number(t.replace(',','.'));
|
|
9174
|
+
if(!isFinite(val)){cmHudEl.classList.add('err');toast('Enter an angle in degrees, e.g. 45 or -90.');return;}
|
|
9175
|
+
val=SteelCore.rollCommitNorm(val);
|
|
9176
|
+
const ok=commitMemberPosition(posHudTarget.id,{rot:val},cmHudEl); // refused (frame drift) toasts its own reason; keep the HUD open + .err so the user can retry. Passing cmHudEl as `source` is safe ONLY because #cmHud is not focusable — positionRefuse calls source.focus(), a no-op on a plain <div>; giving #cmHud a tabindex/contenteditable would blur the input, fire the blur handler, and wrongly discard+toast.
|
|
8298
9177
|
if(!ok){cmHudEl.classList.add('err');return;}
|
|
8299
9178
|
cmHudClose();return;
|
|
8300
9179
|
}
|
|
@@ -8765,7 +9644,7 @@ function updRefToggle(){const b=document.getElementById('refToggleB');if(!b)retu
|
|
|
8765
9644
|
// that flag — the reader writes it and Steel Filter only dims the row. So say it here, on the one
|
|
8766
9645
|
// control a user consults to reason about the backdrop, instead of leaving the omission silent.
|
|
8767
9646
|
const n=hiddenLayerCount();
|
|
8768
|
-
b.setAttribute('data-tip',REF_TIP+(n?(' '+n+' layer'+(n===1?'':'s')+' marked “listed but not drawn” '+(n===1?'is':'are')+' always excluded — review them in
|
|
9647
|
+
b.setAttribute('data-tip',REF_TIP+(n?(' '+n+' layer'+(n===1?'':'s')+' marked “listed but not drawn” '+(n===1?'is':'are')+' always excluded — review them in Drawing Filter.'):''));}
|
|
8769
9648
|
document.getElementById('refToggleB').onclick=e=>{e.stopPropagation();refSheetOn=!refSheetOn;try{localStorage.setItem('steel:refSheet:v2',refSheetOn?'1':'0');}catch(_){}updRefToggle();render();};
|
|
8770
9649
|
document.getElementById('gridEditB').onclick=()=>{setGridMode(!gridMode);render();};
|
|
8771
9650
|
document.getElementById('dimStyleB').onclick=()=>{setDimStyleMode(!dimStyleMode);render();};
|
|
@@ -9153,6 +10032,27 @@ selFly.addEventListener('click',e=>{const row=e.target.closest('.frow');if(!row)
|
|
|
9153
10032
|
const k=row.dataset.k;def.store[k]=!(def.store[k]!==false);
|
|
9154
10033
|
saveSelFilter();reflectSelFilter();render();});
|
|
9155
10034
|
document.addEventListener('click',e=>{if(selFly.classList.contains('open')&&!selFly.contains(e.target)&&!selBar.contains(e.target))closeSelFly();});
|
|
10035
|
+
/* The two review stats open the same popover. Wired here beside #selFly's own wiring because they are the
|
|
10036
|
+
same interaction — a stat that toggles a capped list — and a second, differently-behaving popover in the
|
|
10037
|
+
header is exactly the drift the baseline is meant to prevent. */
|
|
10038
|
+
{const rf=document.getElementById('reviewFly');
|
|
10039
|
+
for(const [id,kind] of [['reviewStat','needs-review'],['untrackedStat','untracked']]){
|
|
10040
|
+
const b=document.getElementById(id);if(b)b.onclick=(e)=>{e.stopPropagation();openReviewFly(kind,b);};}
|
|
10041
|
+
// Esc returns focus to the trigger it came from, so a keyboard user is not dropped at the top of the page.
|
|
10042
|
+
/* ONE Esc, ONE action. Without stopPropagation the global Escape ladder still runs to its terminal
|
|
10043
|
+
rung and clears the selection (and steps out of a drilled connection) — so dismissing this list would
|
|
10044
|
+
silently throw away what the user had selected. Every other capture-phase Esc in this file stops. */
|
|
10045
|
+
document.addEventListener('keydown',e=>{
|
|
10046
|
+
if(e.key!=='Escape'||!rf||!rf.classList.contains('open'))return;
|
|
10047
|
+
/* Consume it ONLY while the popover or its trigger owns focus. Swallowing every Escape just because the
|
|
10048
|
+
list happens to be open would steal it from whatever the user Tabbed to next. */
|
|
10049
|
+
const back=reviewFlyKind==='needs-review'?'reviewStat':'untrackedStat',t=document.getElementById(back);
|
|
10050
|
+
const mine=rf.contains(document.activeElement)||document.activeElement===t;
|
|
10051
|
+
closeReviewFly();
|
|
10052
|
+
if(!mine)return;
|
|
10053
|
+
e.stopPropagation();e.preventDefault();
|
|
10054
|
+
if(t)t.focus();},true);
|
|
10055
|
+
document.addEventListener('click',e=>{if(rf&&rf.classList.contains('open')&&!rf.contains(e.target))closeReviewFly();});}
|
|
9156
10056
|
Promise.resolve().then(()=>{selFilterReady=true;reflectSelFilter();}).catch(e=>console.warn('selFilter: initial reflect failed',e)); // defer the first paint: memberTypeRecords() reads BASE_MEMBER_TYPES, a const declared later in main() — run once main() has fully initialized (microtask flushes before paint, so no flash). Arm selFilterReady BEFORE the first reflect so a throw here can't permanently disable render()'s per-edit sync (reflectSelFilter is idempotent — arm-then-run is safe). Log a throw rather than swallow it: a silent failure leaves the bar in its inert default HTML state while selFilter is still active.
|
|
9157
10057
|
// --- Move/Copy split-button dropdowns: same open/close discipline as the ⋯ menu ---
|
|
9158
10058
|
function wireCmMenu(caretId,menuId){const b=document.getElementById(caretId),m=document.getElementById(menuId);
|
|
@@ -9520,6 +10420,7 @@ const view3dApi={
|
|
|
9520
10420
|
onMoveMember:(id,newWp)=>{edit(()=>{const m=byId(id);if(m)MC().replaceEndpoints(m,newWp);});}, // 3D drag → write wp (undoable, autosaves, syncs 2D/chip/BOM). NOTE: the Select filter gates SELECTION (pick/marquee/Ctrl+A), NOT direct 3D drag-manipulation — gating here would strand the renderer's live preview (the mesh is already moved), so a filtered member is still directly draggable in 3D by design.
|
|
9521
10421
|
positionGizmoState:(id)=>memberPositionGizmoState(id), // 3D Profile Position gizmo (slice 3a): read-only frame axes + current-frame offset/roll for one member
|
|
9522
10422
|
commitMemberPosition:(id,patch,source)=>commitMemberPosition(id,patch,source), // gizmo drag/type → absolute {positionOffset|positionHOffset|rot} through the shipped commitPositionEdit (one undo entry)
|
|
10423
|
+
commitMemberEndpoints:(id,spec,source)=>commitMemberEndpoints(id,spec,source), // slice 3b.1: reference-line handles → absolute world-mm work points through moveWorkPoints (one undo entry, connections revalidate at the server write boundary)
|
|
9523
10424
|
openPositionHud:(id,axis,scr)=>openPositionHud(id,axis,scr), // 3b.3: double-click a handle → dock the shared #cmHud typed-entry HUD at it, commit bypasses snap
|
|
9524
10425
|
showHandleTip:(txt,x,y)=>{if(window.__tip)window.__tip.showText(txt,x,y);}, // 3b.3: canvas gizmo handles carry no DOM data-tip — route through the shared themed #tooltip programmatically
|
|
9525
10426
|
hideHandleTip:()=>{if(window.__tip)window.__tip.hide();},
|
|
@@ -9624,7 +10525,10 @@ const view3dApi={
|
|
|
9624
10525
|
onClipsChange:()=>{const v=window.Steel3DView;if(v&&v.selectedClips&&v.selectedClips().length)clearWholeReferenceSelection();build3DLegend();}, // a clip added / removed / toggled → its renderer-side selection also takes the one action target, then rebuild the legend's Clip section
|
|
9625
10526
|
beginClipEdit:()=>pushUndo(snapshot()), // a clip / work-area manipulation → push a pre-edit snapshot so Ctrl+Z/Y restores it
|
|
9626
10527
|
onClipModeChange:(m)=>{const b=document.getElementById('m3dClip');if(b){b.classList.toggle('on',!!m);b.textContent=m?'Clip ✕':'Clip ▾';}}, // armed → button fills brand-blue + becomes a cancel target (✕ = cancel)
|
|
9627
|
-
onInsertModeChange:(on)=>{const b=document.getElementById('m3dInsert');if(b){b.classList.toggle('on',!!on);b.textContent=on?'✕ Cancel insert':'Insert…';} if(!on)favDisarmed();
|
|
10528
|
+
onInsertModeChange:(on)=>{const b=document.getElementById('m3dInsert');if(b){b.classList.toggle('on',!!on);b.textContent=on?'✕ Cancel insert':'Insert…';} if(!on)favDisarmed();
|
|
10529
|
+
/* Esc at the crosshair cancels a re-placement before ANY of it happened — nothing was untracked and
|
|
10530
|
+
nothing moved, so the only thing to undo is the button's armed look. */
|
|
10531
|
+
if(!on&&connReplaceArm){connReplaceArm=null;panel();}}, // armed → cancel target; disarm also clears any armed favourite (the pinned bar + the .armed row)
|
|
9628
10532
|
// A canvas click selected (or deselected) a whole reference model. Without this the binding is
|
|
9629
10533
|
// one-way — the panel drives the 3D view but a pick in the 3D view leaves the panel showing the
|
|
9630
10534
|
// previous row, which is worse than no highlight because it is confidently wrong. Found by clicking
|
|
@@ -9668,6 +10572,24 @@ const view3dApi={
|
|
|
9668
10572
|
pushReferences();if(legendTab==='refs')renderRefsTab();if(refSelectedObjIdx!==null)panel();
|
|
9669
10573
|
toast('Could not draw the new geometry for “'+((refById(id)||{}).name||id)+'” — keeping the previous view');
|
|
9670
10574
|
},
|
|
10575
|
+
onConnMemberPickChange:()=>{}, // the chosen set shows as the 3D selection + the chip's live count; nothing else to reflect
|
|
10576
|
+
onConnMemberPickAbandon:(jointId,reason)=>{ // left the pick without answering it (focus moved, left 3D, pane went inactive)
|
|
10577
|
+
const nm=(connMemberPick&&connMemberPick.id===jointId?connMemberPick.name:null)||'connection';
|
|
10578
|
+
connMemberPick=null; // MUST clear, or applyRevalidation goes on suppressing this joint's warning forever
|
|
10579
|
+
console.warn('steel-editor: connection member pick abandoned',{jointId,reason});
|
|
10580
|
+
/* A re-placement transaction is WAITING on this pick, and abandoning is one of its four settle paths —
|
|
10581
|
+
it fires on focus moves and pane switches, which the 3D view's own comment calls "all ordinary user
|
|
10582
|
+
actions". Handing it to the transaction is what releases the write gate; without this the gate leaks
|
|
10583
|
+
and saving is disabled for the rest of the session. It also owns the message on that path. */
|
|
10584
|
+
if(settleConnPick(jointId,{commit:false,reason}))return;
|
|
10585
|
+
toast('“'+nm+'” placed — no members named, so it is not being watched');
|
|
10586
|
+
},
|
|
10587
|
+
/* Enter AND Esc both arrive here (steel-3d-view.js) — Esc as `skipped` with an empty list, not as an
|
|
10588
|
+
abandon. So this is the transaction's ordinary settle path, and the plain placement path underneath. */
|
|
10589
|
+
onConnMemberPickCommit:(jointId,memberIds,skipped)=>{
|
|
10590
|
+
if(settleConnPick(jointId,{commit:true,memberIds,skipped}))return;
|
|
10591
|
+
placeConnection(jointId,memberIds,skipped);
|
|
10592
|
+
},
|
|
9671
10593
|
onBasePickModeChange:()=>{}, // Mode B armed state shows via the 3D crosshair + elevation readout; nothing else to reflect
|
|
9672
10594
|
onBasePick:(p)=>{ // Mode B: retarget the armed column's base to the picked elevation (world mm → inches), ONE undo entry
|
|
9673
10595
|
const m=byId(basePickColId); if(!m||m.role!=='column'||!m.col){toast('No column to trim');return;}
|
|
@@ -9686,6 +10608,11 @@ const view3dApi={
|
|
|
9686
10608
|
toast('Column '+m.id+' base '+dir+' to '+where+' — base plate re-seated');
|
|
9687
10609
|
},
|
|
9688
10610
|
onInsertPlace:(pick,pending)=>{
|
|
10611
|
+
/* FIRST, because it is the one branch that must not mint a new id: "Place again" re-commits the
|
|
10612
|
+
EXISTING joint through the transaction that untracks it before anything moves (§5.3). Not awaited —
|
|
10613
|
+
the 3D view disarms the crosshair the moment this returns, which is exactly what we want while the
|
|
10614
|
+
transaction runs. */
|
|
10615
|
+
if(pending&&pending.kind==='connection-replace'&&pending.jointId){connReplaceArm=null;replaceConnectionAt(pending.jointId,pick);return;}
|
|
9689
10616
|
if(pending&&pending.kind==='favourite'&&pending.favourite){const f=pending.favourite;
|
|
9690
10617
|
// Slice F1: apply a saved favourite. base-plate → a column; shear-plate → the nearest beam end; custom → drop the
|
|
9691
10618
|
// mesh at the pick. Wrong target → a corrective toast + no-op (the sticky arm stays on for a retry). Reuses the
|
|
@@ -9728,7 +10655,7 @@ const view3dApi={
|
|
|
9728
10655
|
const joint={id,kind:'custom',name:f.name||'Imported connection',place:pick.point,geometry:f.geometry,source:'user'};
|
|
9729
10656
|
if(pick.anchorId)joint.main=pick.anchorId;
|
|
9730
10657
|
edit(()=>{if(!Array.isArray(C.joints))C.joints=[];C.joints.push(joint);selIds=new Set(f.geometry.map((gg,i)=>id+':'+(gg.id||'m'+i)));});
|
|
9731
|
-
|
|
10658
|
+
armConnMemberPick(id,pick.anchorId,f.name||'Imported connection');return;
|
|
9732
10659
|
}
|
|
9733
10660
|
toast('That favourite has no geometry to place');return;
|
|
9734
10661
|
}
|
|
@@ -9774,8 +10701,11 @@ const view3dApi={
|
|
|
9774
10701
|
const joint={id,kind:'custom',name:conn.name||'Imported connection',place:pick.point,geometry:conn.geometry,source:'user'};
|
|
9775
10702
|
if(pick.anchorId)joint.main=pick.anchorId; // snapped to a member face → record it for the inspector's "on member" line
|
|
9776
10703
|
edit(()=>{if(!Array.isArray(C.joints))C.joints=[];C.joints.push(joint);selIds=new Set(conn.geometry.map((g,i)=>id+':'+(g.id||'m'+i)));});
|
|
9777
|
-
toast
|
|
9778
|
-
|
|
10704
|
+
// ONE toast: toast() sets textContent on a single shared element, so a recipe hint fired here would be
|
|
10705
|
+
// erased by the pick instruction in the same tick — and the hint is the actionable half (how to get an
|
|
10706
|
+
// editable connection instead of a frozen mesh). It rides the pick's own sentence instead.
|
|
10707
|
+
armConnMemberPick(id,pick.anchorId,conn.name||'Imported connection',
|
|
10708
|
+
rc?('It can be an editable '+(rc.kind==='shear-plate'?'shear plate — drop it on a beam end':'base plate — drop it on a column')):null);
|
|
9779
10709
|
return;
|
|
9780
10710
|
}
|
|
9781
10711
|
toast('That connection has no geometry to place');return;
|
|
@@ -9816,6 +10746,416 @@ function armConnectionInsert(connection){if(!connection||!Array.isArray(connecti
|
|
|
9816
10746
|
const recognized=connection.recipe&&connection.recipe.kind==='base-plate';
|
|
9817
10747
|
toast(recognized?('Click a column to place “'+nm+'” as an editable base plate — Esc to cancel')
|
|
9818
10748
|
:('Click in the model to place “'+nm+'” — Esc to cancel'));}
|
|
10749
|
+
let connMemberPick=null; // {id,name} of the connection whose members are being named, or null
|
|
10750
|
+
/* After a CUSTOM connection is placed, ask which members it joins (connection review, design §5.1).
|
|
10751
|
+
The geometry is already committed locally at this point — this step records the RELATIONSHIP, which
|
|
10752
|
+
cannot be recovered from the frozen mesh afterwards. The member the placement click snapped to is
|
|
10753
|
+
pre-picked, because that is the member the user already chose by snapping to its face.
|
|
10754
|
+
Outside a project there is nowhere to record it (the store is per-project), so the step is skipped
|
|
10755
|
+
entirely rather than asking a question whose answer would be dropped. */
|
|
10756
|
+
/* RETURNS whether it actually armed. The re-placement transaction awaits this pick's settlement, so an
|
|
10757
|
+
arm that refused would leave a promise nobody can ever resolve — and the write gate held behind it. */
|
|
10758
|
+
function armConnMemberPick(jointId,anchorId,name,hint){
|
|
10759
|
+
const nm=name||'connection';
|
|
10760
|
+
// Skipping the RECORDING outside a project is correct — the store is per-project. Skipping the
|
|
10761
|
+
// CONFIRMATION is not: the user would see geometry appear and be told nothing at all.
|
|
10762
|
+
if(!PROJECT){toast('“'+nm+'” placed — open this model from a project to have its steel watched');return false;}
|
|
10763
|
+
if(!(window.Steel3DView&&window.Steel3DView.setConnMemberPick)){
|
|
10764
|
+
console.warn('steel-editor: no 3D member pick — this connection will not be watched');
|
|
10765
|
+
toast('“'+nm+'” placed, but what it joins can’t be recorded here — it is not being watched');
|
|
10766
|
+
return false;
|
|
10767
|
+
}
|
|
10768
|
+
connMemberPick={id:jointId,name:name||'connection'};
|
|
10769
|
+
window.Steel3DView.setConnMemberPick({jointId,chosen:anchorId?[anchorId]:[]});
|
|
10770
|
+
toast('Click each member “'+connMemberPick.name+'” joins — Enter to confirm, Esc to skip'+(hint?' · '+hint:''));
|
|
10771
|
+
return true;
|
|
10772
|
+
}
|
|
10773
|
+
/* The awaited member pick, as ONE slot.
|
|
10774
|
+
Keyed on the joint id as well as its presence: a pick settling for a DIFFERENT joint than the one this
|
|
10775
|
+
transaction armed must fall through to the ordinary path, not resolve somebody else's await with an
|
|
10776
|
+
answer about the wrong connection. Returns whether it consumed the event, so the caller knows whether
|
|
10777
|
+
it still owns the message. */
|
|
10778
|
+
let connPickSettle=null; // {jointId, resolve} while a transaction is awaiting the pick
|
|
10779
|
+
function settleConnPick(jointId,outcome){
|
|
10780
|
+
const w=connPickSettle;
|
|
10781
|
+
if(!w||w.jointId!==jointId)return false;
|
|
10782
|
+
connPickSettle=null;
|
|
10783
|
+
w.resolve(outcome);
|
|
10784
|
+
return true;
|
|
10785
|
+
}
|
|
10786
|
+
/**
|
|
10787
|
+
* The awaited pick, plus a watchdog for the case where nobody ever answers it.
|
|
10788
|
+
*
|
|
10789
|
+
* THE ROOT CAUSE IS FIXED AT THE SOURCE — `dispose()` in steel-3d-view.js used to drop `connPick`
|
|
10790
|
+
* without firing either callback, so this promise never settled and the write gate stayed held for the
|
|
10791
|
+
* session. This is the belt to that fix's braces, and it earns its place rather than duplicating it:
|
|
10792
|
+
* the transaction is awaiting an event owned by ANOTHER module, and a leaked gate is severe enough
|
|
10793
|
+
* that "every teardown remembers to call the callback" is too fragile an invariant to rest it on. The
|
|
10794
|
+
* watchdog asks a question the editor can answer for itself — is that pick still armed? — so a future
|
|
10795
|
+
* teardown that forgets costs one polling interval instead of the session's saves.
|
|
10796
|
+
*
|
|
10797
|
+
* Deliberately NOT a plain timeout: naming the members is a human action with no time limit, and a
|
|
10798
|
+
* timer would settle a transaction the user is still working through.
|
|
10799
|
+
*/
|
|
10800
|
+
function awaitConnPick(jointId){
|
|
10801
|
+
return new Promise(resolve=>{
|
|
10802
|
+
connPickSettle={jointId,resolve};
|
|
10803
|
+
/* THIS joint's pick, not "a" pick. `connMemberPick()` returns the chosen ids and never says whose
|
|
10804
|
+
they are, so a pick replaced by another joint's would read as still-armed and the watchdog would
|
|
10805
|
+
poll forever over a transaction nobody can settle — a hole in the very backstop that exists so a
|
|
10806
|
+
hole like it cannot be fatal. (Found by review.) */
|
|
10807
|
+
const armed=()=>{
|
|
10808
|
+
const v=window.Steel3DView;
|
|
10809
|
+
return !!(v&&v.connMemberPickJoint&&v.connMemberPickJoint()===jointId);
|
|
10810
|
+
};
|
|
10811
|
+
const tick=()=>{
|
|
10812
|
+
if(!connPickSettle||connPickSettle.jointId!==jointId)return; // settled normally; nothing to do
|
|
10813
|
+
if(armed()){setTimeout(tick,500);return;}
|
|
10814
|
+
console.warn('steel-editor: the member pick vanished without settling — releasing the re-placement',{jointId});
|
|
10815
|
+
settleConnPick(jointId,{commit:false,reason:'pick-lost'});
|
|
10816
|
+
};
|
|
10817
|
+
setTimeout(tick,500);
|
|
10818
|
+
});
|
|
10819
|
+
}
|
|
10820
|
+
/* Commit the placement through the command that establishes a baseline. Flush FIRST: an in-flight
|
|
10821
|
+
debounced autosave would otherwise race this write, and a later stale whole-contract PUT could
|
|
10822
|
+
overwrite its result. The flush's ETag is the precondition, so a genuinely concurrent write is
|
|
10823
|
+
refused rather than silently clobbered. */
|
|
10824
|
+
/* RE-COMMITTING AN EXISTING JOINT ID IS SAFE ONLY THROUGH `replaceConnectionAt`, AND THAT IS WHY IT
|
|
10825
|
+
EXISTS. This path on its own is not: the flush below publishes the geometry as an ordinary client
|
|
10826
|
+
write first, and if the joint's `self` is unchanged (only the named members differ) the previous
|
|
10827
|
+
baseline still corroborates — so a failure before the command stages leaves a stale row reading CLEAN
|
|
10828
|
+
over the wrong steel, with `failClosed` never firing because nothing staged. `replaceConnectionAt`
|
|
10829
|
+
closes that by marking the joint untracked BEFORE the geometry moves, so a torn re-placement degrades
|
|
10830
|
+
to "not being watched" instead of to a confident lie. Reaching a re-commit by any other route would
|
|
10831
|
+
re-open the hole.
|
|
10832
|
+
|
|
10833
|
+
RETURNS whether the command actually staged, so the transaction knows whether it still owes a
|
|
10834
|
+
fail-closed save. `token` admits its flush past the transaction's own write gate. */
|
|
10835
|
+
async function placeConnection(jointId,memberIds,skipped,token){
|
|
10836
|
+
const name=(connMemberPick&&connMemberPick.id===jointId?connMemberPick.name:null)||'connection';
|
|
10837
|
+
if(!PROJECT){connMemberPick=null;return false;}
|
|
10838
|
+
const joint=(Array.isArray(C.joints)?C.joints:[]).find(j=>j&&j.id===jointId);
|
|
10839
|
+
if(!joint){connMemberPick=null;toast('That connection is no longer in the model');return false;}
|
|
10840
|
+
let mid=null;
|
|
10841
|
+
try{
|
|
10842
|
+
await flushContractWith(token||null);
|
|
10843
|
+
mid=newMutationId();claimMutation(mid);
|
|
10844
|
+
const headers={'content-type':'application/json','x-floless-mutation-id':mid};
|
|
10845
|
+
if(serverEtag)headers['if-match']=serverEtag;
|
|
10846
|
+
const res=await fetch('/api/projects/'+encodeURIComponent(PROJECT)+'/connections/place',{method:'POST',headers,body:JSON.stringify({joint,memberIds})});
|
|
10847
|
+
const d=await res.json().catch(()=>({}));
|
|
10848
|
+
if(!res.ok){
|
|
10849
|
+
releaseMutation(mid);
|
|
10850
|
+
console.warn('steel-editor: placement command refused',{status:res.status,code:d.code,error:d.error});
|
|
10851
|
+
// 428 is the client failing to send a precondition, which is a FloLess bug, not something the user
|
|
10852
|
+
// can act on — never show its header vocabulary. "Place it again" IS now a real action (the
|
|
10853
|
+
// inspector's Place again…), so the sentence names the recovery instead of stopping at the fault.
|
|
10854
|
+
const why=(res.status===428||!d.error)?'what it joins could not be recorded':String(d.error);
|
|
10855
|
+
toast('“'+name+'” is placed — '+why+', so it is not being watched. Use Place again… to start watching it.');
|
|
10856
|
+
return false;
|
|
10857
|
+
}
|
|
10858
|
+
// Adopt the tag; do NOT re-install the contract. installMemberEndContract clears undo/redo, and design
|
|
10859
|
+
// §5.0 is explicit that undoing a placement must keep working ("one Ctrl+Z restores the joint") — the
|
|
10860
|
+
// same reason server/index.ts deliberately does not return the contract on an ordinary move. Nothing is
|
|
10861
|
+
// lost by skipping it: the client flushed this document a moment ago and the route only upserts the very
|
|
10862
|
+
// joint the client sent, so C already matches what was published. It also avoids shipping a
|
|
10863
|
+
// tens-of-megabyte contract back into the page on every placement.
|
|
10864
|
+
const hdrTag=d.etag||res.headers.get('ETag'),rev=Number.isSafeInteger(d.storeRevision)?d.storeRevision:null;
|
|
10865
|
+
/* Adopt the tag and the revision TOGETHER, and only when this reply is at least as new as what the tab
|
|
10866
|
+
already holds. This POST is outside the save queue, so an autosave can land while it is in flight;
|
|
10867
|
+
taking the tag unconditionally while keeping the newer revision would leave the pair torn and make
|
|
10868
|
+
the user's own next save a false 412. Older reply → keep both, the newer save already owns them. */
|
|
10869
|
+
if(hdrTag&&rev!==null&&rev>=serverRevision){const pv=serverEtag;serverEtag=hdrTag;restampDraftBase(pv,hdrTag);serverRevision=rev;}
|
|
10870
|
+
else console.warn('steel-editor: placement reply not adopted (a newer save owns the tab, or the reply was incomplete)',{etag:hdrTag,storeRevision:d.storeRevision,held:serverRevision});
|
|
10871
|
+
const n=(d.memberIds||memberIds||[]).length;
|
|
10872
|
+
// Never claim it is watched when it is not: skipping is legitimate, and saying so plainly is what
|
|
10873
|
+
// stops "placed ✓" being read as "this connection is being checked".
|
|
10874
|
+
toast(skipped||!n
|
|
10875
|
+
? '“'+name+'” placed — no members named, so it is not being watched'
|
|
10876
|
+
: '“'+name+'” placed on '+n+' member'+(n===1?'':'s')+' — you will be told if that steel moves');
|
|
10877
|
+
return true; // the command STAGED, whatever it decided about members — the caller owes no fail-closed save
|
|
10878
|
+
}catch(e){
|
|
10879
|
+
if(mid)releaseMutation(mid);
|
|
10880
|
+
console.warn('steel-editor: placement command failed',e);
|
|
10881
|
+
toast('“'+name+'” is placed, but what it joins could not be recorded');
|
|
10882
|
+
return false;
|
|
10883
|
+
}finally{
|
|
10884
|
+
/* UNCONDITIONAL, and after the flush rather than before it. This handle suppresses the joint's
|
|
10885
|
+
"may need review" clause while it is being answered, so a path that leaves it set would silence
|
|
10886
|
+
that warning for the rest of the page's life — on the one connection that is provably not watched.
|
|
10887
|
+
Clearing it in `finally` is what stops a future early return re-introducing that. */
|
|
10888
|
+
connMemberPick=null;
|
|
10889
|
+
}
|
|
10890
|
+
}
|
|
10891
|
+
/* -- The review VERBS (design 5.1). One dispatcher, because they differ only in what they do to a
|
|
10892
|
+
single sidecar row and share their preconditions, their 409 and their reply shape. All three take
|
|
10893
|
+
`reviewRevision`; only sign-off takes `If-Match`, because only sign-off can manufacture an
|
|
10894
|
+
acceptance - reopen and untrack both move the state conservatively, and refusing them on a stale tag
|
|
10895
|
+
would make the safe action harder to take than the dangerous one. */
|
|
10896
|
+
async function reviewVerb(verb,jointId,opts){
|
|
10897
|
+
const o=opts||{};
|
|
10898
|
+
if(!PROJECT)throw new Error('this model is not open from a project');
|
|
10899
|
+
const rev=Number.isSafeInteger(o.reviewRevision)?o.reviewRevision:reviewAt.reviewRevision;
|
|
10900
|
+
if(!Number.isSafeInteger(rev)||rev<0)throw new Error('the review state has not loaded yet');
|
|
10901
|
+
const headers={'content-type':'application/json'};
|
|
10902
|
+
if(o.ifMatch)headers['if-match']=o.ifMatch;
|
|
10903
|
+
let res;
|
|
10904
|
+
/* A `fetch` rejection is not prose for a user — "Failed to fetch" and "NetworkError when attempting to
|
|
10905
|
+
fetch resource" are the browser talking to a developer. Marked so the caller can say something the
|
|
10906
|
+
user can act on instead. (Found by review.) */
|
|
10907
|
+
try{res=await fetch('/api/projects/'+encodeURIComponent(PROJECT)+'/connections/'+encodeURIComponent(jointId)+'/'+verb,
|
|
10908
|
+
{method:'POST',headers,body:JSON.stringify({reviewRevision:rev})});}
|
|
10909
|
+
catch(e){const err=new Error('the server could not be reached');err.transport=true;throw err;}
|
|
10910
|
+
const d=await res.json().catch(()=>{console.warn('steel-editor: a review reply was not readable JSON',{verb,status:res.status});return {};});
|
|
10911
|
+
if(!res.ok){
|
|
10912
|
+
const err=new Error(d.error||('the review action failed ('+res.status+')'));
|
|
10913
|
+
err.code=d.code;err.status=res.status;throw err;
|
|
10914
|
+
}
|
|
10915
|
+
return d;
|
|
10916
|
+
}
|
|
10917
|
+
/* Take a verb's reply. The verbs return the FULL summary with the contract tag UNCHANGED, so it is
|
|
10918
|
+
installable directly - but only while the document it describes is still the one on screen. When it
|
|
10919
|
+
is not, the reply is discarded and the refresh cycle fetches the post-save snapshot instead; the
|
|
10920
|
+
server's success is kept either way, because it happened. */
|
|
10921
|
+
function installVerbReply(d,describesVisible){
|
|
10922
|
+
if(describesVisible&&d&&d.review&&Number.isSafeInteger(d.storeRevision)){
|
|
10923
|
+
const outcome=installReviewSummary(d.review,d.storeRevision,contractEventEpoch);
|
|
10924
|
+
if(outcome==='installed'||outcome==='recovered'||outcome==='noop'||outcome==='unavailable')return true;
|
|
10925
|
+
}
|
|
10926
|
+
/* THE REPLY DID NOT DESCRIBE WHAT IS ON SCREEN — so asking the server again RIGHT NOW gets the same
|
|
10927
|
+
wrong answer, not a better one. The store still holds the pre-edit document, its summary satisfies
|
|
10928
|
+
the bounds, and the cycle would settle on it: sign-off's "✓ Reviewed" painted over steel the user
|
|
10929
|
+
has just moved and nobody has reviewed. That is the manufactured approval this whole feature exists
|
|
10930
|
+
to prevent, arriving through the guard meant to stop it.
|
|
10931
|
+
|
|
10932
|
+
So when a write is already pending, say nothing and let it answer. Its own-write refresh fires when
|
|
10933
|
+
it lands, with a summary derived from the document the user is actually looking at. And if that
|
|
10934
|
+
write FAILS, the surface keeps the pre-verb state — needs-review — which is the conservative
|
|
10935
|
+
direction and the right one to be stuck in. (Codex code review.) */
|
|
10936
|
+
if(!serverHasVisibleDocument())return false;
|
|
10937
|
+
markReviewDirty({storeRevision:serverRevision,
|
|
10938
|
+
reviewRevision:Number.isSafeInteger(d&&d.reviewRevision)?d.reviewRevision:reviewAt.reviewRevision});
|
|
10939
|
+
return false;
|
|
10940
|
+
}
|
|
10941
|
+
/* A refused verb, said in the user's terms. 409 is the ordinary two-tab outcome and gets its own
|
|
10942
|
+
sentence - it is not a fault, and the surface is about to correct itself. */
|
|
10943
|
+
function reviewVerbFailed(e,fallback){
|
|
10944
|
+
console.warn('steel-editor: review action refused',{code:e&&e.code,status:e&&e.status,message:e&&e.message});
|
|
10945
|
+
/* 409 deliberately keeps its unguarded re-read. The sidecar demonstrably moved, so the `+1` bound can
|
|
10946
|
+
only be satisfied by a genuinely newer generation — unlike the fall-through above, this cannot
|
|
10947
|
+
settle on the pre-edit snapshot. The asymmetry is the point, not an oversight. */
|
|
10948
|
+
if(e&&e.status===409){toast('Someone else already reviewed this connection — its status just updated');markReviewDirty({storeRevision:reviewAt.storeRevision,reviewRevision:reviewAt.reviewRevision+1});return;}
|
|
10949
|
+
/* The server's own 4xx prose is written FOR the user and names what to do; anything else — a transport
|
|
10950
|
+
failure, a 5xx behind an HTML error page — is not, so the caller's sentence wins, because it is the
|
|
10951
|
+
only one that names the connection. */
|
|
10952
|
+
const speakable=e&&!e.transport&&e.status>=400&&e.status<500&&e.message;
|
|
10953
|
+
toast(speakable?String(e.message)
|
|
10954
|
+
:(fallback+' — '+((e&&e.transport)?'the server could not be reached':'try again in a moment')));
|
|
10955
|
+
}
|
|
10956
|
+
/* Is the document on screen still the one that flush published? THREE tripwires, each answering a
|
|
10957
|
+
different question, because no one of them is total on its own - see `modelEditGeneration`. */
|
|
10958
|
+
function visibleDocumentIs(flushed){
|
|
10959
|
+
return serverEtag===flushed.etag && saveT===null && modelEditGeneration===flushed.generation;
|
|
10960
|
+
}
|
|
10961
|
+
/* MARK AS REVIEWED - the one verb that grants authority, so it is the one with the generation guard.
|
|
10962
|
+
5.2: `If-Match` proves which generation the SERVER had, never which one the user LOOKED AT. The three
|
|
10963
|
+
tripwires above decide whether the flushed document is still the visible one; any one of them
|
|
10964
|
+
refuses, because recording an acceptance of a state nobody reviewed is the exact failure this feature
|
|
10965
|
+
exists to prevent. */
|
|
10966
|
+
async function signOffConnection(jointId){
|
|
10967
|
+
const j=(Array.isArray(C.joints)?C.joints:[]).find(x=>x&&x.id===jointId);
|
|
10968
|
+
const name=(j&&j.name)||'This connection';
|
|
10969
|
+
if(!PROJECT||!ReviewClient||reviewUnavailable||!reviewSummary){toast('The review state is not available right now — try again in a moment');return;}
|
|
10970
|
+
let flushed;
|
|
10971
|
+
try{flushed=await flushContractWith(null);}
|
|
10972
|
+
catch(e){console.warn('steel-editor: could not flush before sign-off',e);toast('Your latest edits could not be saved, so “'+name+'” was not marked reviewed');return;}
|
|
10973
|
+
// No tag means no precondition, and an unconditional sign-off would assert exactly the authority the
|
|
10974
|
+
// precondition exists to withhold. Refuse rather than send one.
|
|
10975
|
+
if(!flushed||!flushed.etag){toast('Could not confirm which version you are looking at — “'+name+'” was not marked reviewed');return;}
|
|
10976
|
+
if(!visibleDocumentIs(flushed)){toast('The model changed while that was saving — check “'+name+'” again, then mark it reviewed');return;}
|
|
10977
|
+
let d;
|
|
10978
|
+
try{d=await reviewVerb('sign-off',jointId,{ifMatch:flushed.etag,reviewRevision:reviewSummary.reviewRevision});}
|
|
10979
|
+
catch(e){reviewVerbFailed(e,'“'+name+'” could not be marked reviewed');return;}
|
|
10980
|
+
/* GUARD THE REPLY TOO, or the window is moved rather than closed: an edit that landed while the
|
|
10981
|
+
request was in flight makes the returned summary describe the OLDER contract. The sign-off itself
|
|
10982
|
+
stands - the server took it against the generation we proved - but its summary must not be painted
|
|
10983
|
+
over a document it does not describe. */
|
|
10984
|
+
/* THE TOAST HAS TO MATCH THE SURFACE. When the reply is declined the chip stays amber and the
|
|
10985
|
+
button stays on screen, so the flat sentence would have the two disagreeing — and the obvious
|
|
10986
|
+
response to that is to press the button again. (Found by review.) */
|
|
10987
|
+
const painted=installVerbReply(d,visibleDocumentIs(flushed));
|
|
10988
|
+
toast(painted
|
|
10989
|
+
? '“'+name+'” marked reviewed — Ctrl+Z will not undo this'
|
|
10990
|
+
: '“'+name+'” marked reviewed — Ctrl+Z will not undo this, and the chip catches up once your latest edit saves');
|
|
10991
|
+
}
|
|
10992
|
+
/* Is a pending write going to re-ask this question for us? Only `scheduleSave` sets `saveT`, and the
|
|
10993
|
+
write it schedules ends in the own-write refresh — so when one is pending, asking NOW can only ever
|
|
10994
|
+
get the pre-edit answer back. */
|
|
10995
|
+
/**
|
|
10996
|
+
* Does the STORE hold the document that is on screen?
|
|
10997
|
+
*
|
|
10998
|
+
* The one question both verbs need, stated positively on purpose. An earlier spelling asked "is a
|
|
10999
|
+
* refresh already coming?", which named a DIFFERENT fact and was wrong in the `err`/`conflict` case —
|
|
11000
|
+
* there the document is unsaved and no refresh is coming at all, so the name promised something the
|
|
11001
|
+
* predicate could not deliver.
|
|
11002
|
+
*
|
|
11003
|
+
* `saveT` alone will not do: `scheduleSave` nulls it the moment the timer fires, so for the whole time
|
|
11004
|
+
* the PUT is actually on the wire it reads false — the middle of the very window this covers. The pill
|
|
11005
|
+
* spans all of it, because `setSaved('dirty')` goes up with the debounce and only the settling response
|
|
11006
|
+
* takes it down. (Both found by review.)
|
|
11007
|
+
*
|
|
11008
|
+
* WHERE THE ANSWER IS "no", NOTHING IS PROMISED. A pending write's refresh rides its own SSE echo, so
|
|
11009
|
+
* with the stream down nothing re-asks and the surface stays as it was — which is why neither verb
|
|
11010
|
+
* DEPENDS on a refresh arriving: reopen drops its acceptance locally, and sign-off's toast says the chip
|
|
11011
|
+
* will catch up. This decides only whether asking the server right now could tell us anything new.
|
|
11012
|
+
*/
|
|
11013
|
+
function serverHasVisibleDocument(){
|
|
11014
|
+
return saveT===null&&!editorHasUnsavedWork();
|
|
11015
|
+
}
|
|
11016
|
+
/* REOPEN - the reversal of sign-off, and the reason it must exist: sign-off writes no `edit()` entry, so
|
|
11017
|
+
Ctrl+Z does not undo it. No flush and no `If-Match`: it moves the state back toward needing review,
|
|
11018
|
+
which is the conservative direction, so a slightly stale view of the steel cannot do harm. */
|
|
11019
|
+
async function reopenConnectionReview(jointId){
|
|
11020
|
+
const j=(Array.isArray(C.joints)?C.joints:[]).find(x=>x&&x.id===jointId);
|
|
11021
|
+
const name=(j&&j.name)||'This connection';
|
|
11022
|
+
if(!PROJECT||!ReviewClient||reviewUnavailable||!reviewSummary){toast('The review state is not available right now — try again in a moment');return;}
|
|
11023
|
+
/* Reopen publishes nothing, so it needs no flush and no `If-Match` — but the user can still edit while
|
|
11024
|
+
the request is in flight, and the reply would then describe the older document. The verb is safe to
|
|
11025
|
+
take on a stale view (it moves the state conservatively); PAINTING its summary is what is not. Same
|
|
11026
|
+
question as sign-off, so the same guard rather than a second rule. (Codex code review.) */
|
|
11027
|
+
const at={etag:serverEtag,generation:modelEditGeneration};
|
|
11028
|
+
let d;
|
|
11029
|
+
try{d=await reviewVerb('reopen',jointId,{reviewRevision:reviewSummary.reviewRevision});}
|
|
11030
|
+
catch(e){reviewVerbFailed(e,'“'+name+'” could not be reopened');return;}
|
|
11031
|
+
/* DROP THE ACCEPTANCE LOCALLY, FIRST, AND UNCONDITIONALLY.
|
|
11032
|
+
The first cut of this guard simply reused sign-off's rule — install the reply only while it still
|
|
11033
|
+
describes the visible document — and that inverted the safety argument. For sign-off, declining to
|
|
11034
|
+
paint leaves NEEDS-REVIEW on screen, which is the conservative direction. For reopen, the pre-verb
|
|
11035
|
+
state is "✓ Reviewed": declining to paint leaves the surface asserting a human acceptance the server
|
|
11036
|
+
has just erased, and it stands until the next save's echo — forever if that save fails or the live
|
|
11037
|
+
channel is down. That is the manufactured approval this feature exists to prevent, arriving through
|
|
11038
|
+
the guard written to stop it. (Found by review.)
|
|
11039
|
+
Applying it locally is safe in a way applying a sign-off never is: reopen only ever REMOVES an
|
|
11040
|
+
acceptance, so a local copy of it cannot overstate what the server holds. */
|
|
11041
|
+
if(reviewSummary&&Array.isArray(reviewSummary.signedOff)&&reviewSummary.signedOff.indexOf(jointId)!==-1){
|
|
11042
|
+
reviewSummary={...reviewSummary,signedOff:reviewSummary.signedOff.filter(id=>id!==jointId)};
|
|
11043
|
+
repaintReviewSurface();
|
|
11044
|
+
}
|
|
11045
|
+
toast('“'+name+'” reopened — it will ask to be checked again');
|
|
11046
|
+
/* BOTH halves, and the second is what a flush would otherwise have bought. Sign-off can settle for
|
|
11047
|
+
"unchanged since I published it", because its flush guarantees the store holds what the user saw.
|
|
11048
|
+
Reopen never publishes, so the store may have been behind before the request was even sent — and
|
|
11049
|
+
then "unchanged since dispatch" is true while the reply still describes an older document.
|
|
11050
|
+
Asserted by test: an in-flight save at dispatch passes `visibleDocumentIs` and must NOT install. */
|
|
11051
|
+
installVerbReply(d,serverHasVisibleDocument()&&visibleDocumentIs(at));
|
|
11052
|
+
}
|
|
11053
|
+
/* -- PLACE AGAIN - ONE TRANSACTION (design 5.3), and the riskiest thing in this feature.
|
|
11054
|
+
|
|
11055
|
+
The hazard it exists for: the placement command's flush publishes the geometry as an ORDINARY write
|
|
11056
|
+
before the command stages, and if the joint's `self` is unchanged the previous baseline still
|
|
11057
|
+
corroborates. So a tear anywhere between the flush and the staging leaves the row reading CLEAN over
|
|
11058
|
+
steel it was never checked against - and `failClosed` does NOT fire, because nothing staged.
|
|
11059
|
+
|
|
11060
|
+
The answer is to mark the joint untracked BEFORE the geometry moves. Then every torn outcome degrades
|
|
11061
|
+
to "not being watched", which is visible and correctable, instead of to a confident lie.
|
|
11062
|
+
|
|
11063
|
+
armed (crosshair) the joint stays TRACKED. Esc here cancels and nothing was untracked.
|
|
11064
|
+
point accepted gate the write queue FIRST; cancel the debounce; drain what was already queued
|
|
11065
|
+
against the OLD placement; flush it. THEN untrack. Failure => ABORT, C unmutated.
|
|
11066
|
+
untrack ok move the geometry; arm the member pick.
|
|
11067
|
+
settle commit | Esc | abandon | arming failure | throw - ALL through ONE finally that
|
|
11068
|
+
releases the gate and refreshes the summary.
|
|
11069
|
+
|
|
11070
|
+
SUPPRESSION BEGINS BEFORE THE UNTRACK, not after: a timer scheduled by an EARLIER edit would otherwise
|
|
11071
|
+
fire after the re-placement mutation and publish the new geometry ahead of the command, which is the
|
|
11072
|
+
very sequence being prevented.
|
|
11073
|
+
|
|
11074
|
+
NO ROLLBACK, and that is a consequence of the ordering rather than an omission. Because the untrack
|
|
11075
|
+
precedes the only mutation, the pre-untrack failures moved nothing, and every post-untrack failure
|
|
11076
|
+
lands in exactly one state - moved geometry, untracked, no members. The finally's persist() +
|
|
11077
|
+
scheduleSave() are what make that state reach the draft and the server rather than living only here. */
|
|
11078
|
+
let connReplaceArm=null; // the joint id whose re-placement crosshair is armed, for the button's live .on state
|
|
11079
|
+
function armConnectionReplace(jointId){
|
|
11080
|
+
const j=(Array.isArray(C.joints)?C.joints:[]).find(x=>x&&x.id===jointId);
|
|
11081
|
+
if(!j||j.kind!=='custom'){toast('That connection is no longer in the model');return;}
|
|
11082
|
+
const nm=j.name||'Imported connection';
|
|
11083
|
+
if(!PROJECT){toast('Open this model from a project to re-place “'+nm+'”');return;}
|
|
11084
|
+
if(!view3d){toast('Switch to the 3D view to place this connection again');return;}
|
|
11085
|
+
if(!(window.Steel3DView&&window.Steel3DView.setInsertMode)){toast('The 3D view is not ready yet');return;}
|
|
11086
|
+
/* SAY NO BEFORE THE USER COMMITS TO A POINT. The transaction needs a review generation to untrack
|
|
11087
|
+
against, and without this check it discovers that only AFTER closing the gate and PUTting the whole
|
|
11088
|
+
contract — a wasted write, and a refusal arriving once the user has already chosen where it goes.
|
|
11089
|
+
The other two verbs check their preconditions up front; this one now does too. (Found by review.) */
|
|
11090
|
+
if(!ReviewClient||reviewUnavailable||!Number.isSafeInteger(reviewAt.reviewRevision)||reviewAt.reviewRevision<0){
|
|
11091
|
+
toast('The review state is not available right now — “'+nm+'” cannot be re-placed until it loads');return;}
|
|
11092
|
+
if(writeGateToken){toast('A placement is still finishing — try again in a moment');return;}
|
|
11093
|
+
connReplaceArm=jointId;
|
|
11094
|
+
window.Steel3DView.setInsertMode(true,{kind:'connection-replace',jointId,name:nm});
|
|
11095
|
+
panel(); // the button it was pressed on now reads as armed
|
|
11096
|
+
toast('Click where “'+nm+'” should sit — Esc to cancel');
|
|
11097
|
+
}
|
|
11098
|
+
async function replaceConnectionAt(jointId,pick){
|
|
11099
|
+
const joint=(Array.isArray(C.joints)?C.joints:[]).find(j=>j&&j.id===jointId);
|
|
11100
|
+
const name=(joint&&joint.name)||'Imported connection';
|
|
11101
|
+
if(!joint||joint.kind!=='custom'){toast('That connection is no longer in the model');return;}
|
|
11102
|
+
if(!PROJECT){toast('Open this model from a project to re-place “'+name+'”');return;}
|
|
11103
|
+
const token={};
|
|
11104
|
+
let mutated=false,placed=false;
|
|
11105
|
+
/* Capture the queue tail and close the gate in the SAME synchronous block - an await between them
|
|
11106
|
+
would let a write slip in that is neither grandfathered nor blocked. */
|
|
11107
|
+
const grandfathered=writeQueue;
|
|
11108
|
+
if(!closeWriteGate(token)){toast('A placement is still finishing — try again in a moment');return;}
|
|
11109
|
+
try{
|
|
11110
|
+
clearTimeout(saveT);saveT=null; // the debounce is taken over by the flush below
|
|
11111
|
+
await grandfathered.catch(()=>{}); // drain what was already queued, against the OLD placement
|
|
11112
|
+
await flushContractWith(token); // ...and publish it, so nothing pending can publish the NEW one
|
|
11113
|
+
await reviewVerb('untrack',jointId,{reviewRevision:reviewAt.reviewRevision});
|
|
11114
|
+
/* RE-RESOLVE, because `joint` was read before two awaits. `flushContractWith` installs the server's
|
|
11115
|
+
contract when the reply carries one, and that REPLACES the document — after which the object
|
|
11116
|
+
captured above is detached, and mutating it would move nothing while the toast claimed it had.
|
|
11117
|
+
Cheap, and the alternative is a lie about geometry. (Codex code review.) */
|
|
11118
|
+
const live=(Array.isArray(C.joints)?C.joints:[]).find(j=>j&&j.id===jointId);
|
|
11119
|
+
if(!live||live.kind!=='custom')throw new Error('the connection is no longer in this model');
|
|
11120
|
+
mutated=true; // only now may C move
|
|
11121
|
+
/* `edit()` SOFT-FAILS: a V2CommandError is caught, toasted, and reported by a `false` RETURN rather
|
|
11122
|
+
than a throw. Discarding that return was the one hole in the no-rollback argument — the
|
|
11123
|
+
transaction would carry on arming the pick and committing a baseline over geometry that never
|
|
11124
|
+
moved, which is a state the argument says is unreachable. (Found by review.) */
|
|
11125
|
+
if(!edit(()=>{
|
|
11126
|
+
live.place=pick.point;
|
|
11127
|
+
if(pick.anchorId)live.main=pick.anchorId;else delete live.main;
|
|
11128
|
+
selIds=new Set((live.geometry||[]).map((g,i)=>jointId+':'+(g.id||'m'+i)));
|
|
11129
|
+
}))throw new Error('the connection could not be moved');
|
|
11130
|
+
if(!armConnMemberPick(jointId,pick.anchorId,name))throw new Error('the member pick could not be armed');
|
|
11131
|
+
const out=await awaitConnPick(jointId);
|
|
11132
|
+
if(out&&out.commit)placed=await placeConnection(jointId,out.memberIds,out.skipped,token);
|
|
11133
|
+
/* THE ABANDON PATH HAS TO SPEAK. Consuming the settlement takes the message away from
|
|
11134
|
+
`onConnMemberPickAbandon`, which is the only thing that would otherwise have said anything — so
|
|
11135
|
+
without this the user switches panes, the connection silently stops being watched, and the only
|
|
11136
|
+
words on screen are the now-false instruction to name its members. Found by the regression test
|
|
11137
|
+
for the vanished-pick case; it was equally true of an ordinary pane switch, and my own browser
|
|
11138
|
+
pass had walked straight past the stale toast. */
|
|
11139
|
+
else toast('“'+name+'” was moved but no members were named, so it is no longer being watched — use Place again… to start watching it');
|
|
11140
|
+
}catch(e){
|
|
11141
|
+
console.warn('steel-editor: re-placement failed',e);
|
|
11142
|
+
toast(mutated
|
|
11143
|
+
? '“'+name+'” was moved but is no longer being watched — use Place again… to start watching it'
|
|
11144
|
+
: '“'+name+'” was not moved — '+((e&&e.message)?String(e.message):'the model could not be saved first'));
|
|
11145
|
+
}finally{
|
|
11146
|
+
/* THE SINGLE MOST IMPORTANT ASSERTION IN THIS FEATURE. A leaked gate disables saving for the rest of
|
|
11147
|
+
the session, which is worse than the bug the gate fixes - so it is released on every path,
|
|
11148
|
+
including throw, and token-checked so a settling transaction cannot clear a newer one's gate. */
|
|
11149
|
+
if(connPickSettle&&connPickSettle.jointId===jointId)connPickSettle=null;
|
|
11150
|
+
openWriteGate(token);
|
|
11151
|
+
try{persist();}catch(_){/* setSaved('err') already fired inside persist */}
|
|
11152
|
+
// An un-placed mutation still has to reach the server - untracked and honest - rather than living
|
|
11153
|
+
// only in this browser. A placed one already published through the command; saying it twice would
|
|
11154
|
+
// move the store revision for nothing.
|
|
11155
|
+
if(mutated&&!placed)scheduleSave();
|
|
11156
|
+
reviewRefreshForOwnWrite();
|
|
11157
|
+
}
|
|
11158
|
+
}
|
|
9819
11159
|
async function detailRequest(intent,place,note){
|
|
9820
11160
|
// flushContract PUTs C to the server so the terminal AI reads the latest contract — but it clears the
|
|
9821
11161
|
// debounced autosave (saveT) WITHOUT writing localStorage, which would drop the just-placed detail from
|