@floless/app 0.142.0 → 0.144.0
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 +218260 -189290
- package/dist/schemas/steel.model.v2.schema.json +50 -2
- package/dist/schemas/tekla.model.v1.schema.json +66 -0
- package/dist/schemas/tekla.model.v2.schema.json +69 -0
- package/dist/schemas/tekla.source-package.v1.schema.json +37 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +24 -1
- package/dist/skills/floless-app-workflows/SKILL.md +8 -2
- package/dist/skills/floless-app-workflows/references/workspace-data.md +25 -4
- package/dist/templates/floless-workspace-model-report.flo +27 -23
- package/dist/templates/revit-model.flo +6 -2
- package/dist/templates/tekla-model-report.flo +60 -0
- package/dist/templates/tekla-parser.flo +61 -0
- package/dist/web/app.css +89 -2
- package/dist/web/app.js +5 -4
- package/dist/web/aware.js +441 -47
- package/dist/web/chat.css +2 -0
- package/dist/web/chat.js +37 -3
- package/dist/web/commands-revit.js +4 -0
- package/dist/web/commands-shell.js +136 -3
- package/dist/web/commands-steel.js +8 -2
- package/dist/web/commands-tekla-parser.js +48 -0
- package/dist/web/commands.js +1 -1
- package/dist/web/filter-ai-context.js +35 -6
- package/dist/web/filter-ai-proposal.js +40 -4
- package/dist/web/grid-core.js +15 -0
- package/dist/web/index.html +40 -2
- package/dist/web/instructor.js +26 -14
- package/dist/web/left-pane.js +160 -10
- package/dist/web/model-artifact-loader.js +15 -0
- package/dist/web/model-display-units.js +89 -0
- package/dist/web/model-editor-revit-adapter.js +21 -4
- package/dist/web/model-editor.css +4 -2
- package/dist/web/model-measure.js +10 -6
- package/dist/web/model-panel-bridge.js +46 -3
- package/dist/web/model-pointer-dock.js +21 -1
- package/dist/web/model-property-display.js +91 -0
- package/dist/web/model-revit-module.js +9 -0
- package/dist/web/model-selection-tools.js +11 -0
- package/dist/web/model-spatial-panel.js +52 -21
- package/dist/web/model-structural-grid-view.js +334 -0
- package/dist/web/model-tekla-selection.js +32 -0
- package/dist/web/model-viewport-revit-adapter.js +119 -32
- package/dist/web/revit-editor.css +11 -1
- package/dist/web/revit-editor.html +4 -3
- package/dist/web/revit-editor.js +589 -111
- package/dist/web/steel-3d-view.js +58 -372
- package/dist/web/steel-editor.html +258 -17
- package/dist/web/steel-filter.html +17 -3
- package/dist/web/tekla-editor.html +71 -0
- package/dist/web/tekla-structural-grid-adapter.js +56 -0
- package/dist/web/workspaces.js +872 -97
- package/distribution-profile-production.mjs +4 -0
- package/distribution-resource-inventory.mjs +4 -2
- package/package.json +5 -2
package/dist/web/index.html
CHANGED
|
@@ -241,6 +241,10 @@
|
|
|
241
241
|
</header>
|
|
242
242
|
<div class="left-section-body model-section-body">
|
|
243
243
|
<div id="left-model-tabs" class="left-model-tabs" role="tablist" aria-label="Model tabs"></div>
|
|
244
|
+
<div id="left-model-search" class="left-model-search">
|
|
245
|
+
<input id="left-model-search-input" data-command-id="shell.model-search" type="search" placeholder="Search objects" autocomplete="off" spellcheck="false" maxlength="200">
|
|
246
|
+
<button id="left-model-search-clear" data-command-id="shell.model-search-clear" type="button" aria-label="Clear object search" data-tip="Clear object search" hidden>×</button>
|
|
247
|
+
</div>
|
|
244
248
|
<div id="left-model-index-header" class="left-model-index-header">
|
|
245
249
|
<span id="left-model-index-label">Browse model</span>
|
|
246
250
|
<label class="left-model-follow" data-tip="Keep the Model tree aligned with the single object selected in the 3D view">
|
|
@@ -362,7 +366,7 @@
|
|
|
362
366
|
<!-- Source-step placeholder: a workspace app with NO filter iframe (vectorize) shows this
|
|
363
367
|
where steel shows its filter. Attach/replace-to-re-trace is #ws-attach-revision,
|
|
364
368
|
at the end of the step-tabs row; this pane explains the Source step. Toggled by setStep() in workspaces.js. -->
|
|
365
|
-
<div class="ws-source-placeholder" id="ws-source-placeholder" hidden>
|
|
369
|
+
<div class="ws-source-placeholder" id="ws-source-placeholder" tabindex="-1" hidden>
|
|
366
370
|
<div class="ws-source-inner">
|
|
367
371
|
<span class="ws-source-ico" aria-hidden="true">▨</span>
|
|
368
372
|
<!-- Shown INSTEAD of the glyph while data-importing is true (a Revit import in flight), so
|
|
@@ -838,7 +842,7 @@
|
|
|
838
842
|
|
|
839
843
|
<!-- HTML Viewer — renders the report HTML an exec node returned, in-app.
|
|
840
844
|
Double-click a report node on the canvas to run it and open this. -->
|
|
841
|
-
<div class="modal-backdrop report-backdrop" id="report-modal">
|
|
845
|
+
<div class="modal-backdrop report-backdrop" id="report-modal" role="dialog" aria-modal="true" aria-labelledby="report-title" aria-describedby="report-sub">
|
|
842
846
|
<div class="modal report-viewer">
|
|
843
847
|
<div class="report-head">
|
|
844
848
|
<div class="report-titles">
|
|
@@ -848,12 +852,24 @@
|
|
|
848
852
|
<div class="report-actions">
|
|
849
853
|
<button data-command-id="shell.report-stop" id="report-stop" class="ghost report-stop" hidden data-tip="Stop the live session — the report stops updating on each change">■ Stop run</button>
|
|
850
854
|
<button data-command-id="shell.report-share" id="report-share" class="ghost" hidden data-tip="Share this report as a link anyone can view — hosted on floless.io">↗ Share</button>
|
|
855
|
+
<button data-command-id="shell.report-download" id="report-download" class="ghost" hidden data-tip="Download the complete read-only model property report">↓ Download complete report</button>
|
|
851
856
|
<button data-command-id="shell.report-open-file" id="report-open-file" class="ghost" hidden data-tip="Open the saved file in its default app">⧉ Open file</button>
|
|
852
857
|
<button data-command-id="shell.report-reveal-file" id="report-reveal-file" class="ghost" hidden data-tip="Show the saved file in its folder">▤ Reveal in folder</button>
|
|
853
858
|
<button data-command-id="shell.report-open" id="report-open" class="ghost" data-tip="Open the report in a new browser tab">↗ Open</button>
|
|
854
859
|
<button data-command-id="shell.dialog-close#the report" id="report-close" data-tip="Close">×</button>
|
|
855
860
|
</div>
|
|
856
861
|
</div>
|
|
862
|
+
<nav class="report-nav" id="report-nav" aria-label="Report sections" hidden>
|
|
863
|
+
<button type="button" data-command-id="shell.report-first-section" id="report-first-section" class="ghost" aria-label="First report section">First</button>
|
|
864
|
+
<button type="button" data-command-id="shell.report-previous-section" id="report-previous-section" class="ghost" aria-label="Previous report section">Previous</button>
|
|
865
|
+
<span id="report-section-status" class="report-section-status" role="status" aria-live="polite" aria-atomic="true" tabindex="-1"></span>
|
|
866
|
+
<button type="button" data-command-id="shell.report-next-section" id="report-next-section" class="ghost" aria-label="Next report section">Next</button>
|
|
867
|
+
<button type="button" data-command-id="shell.report-last-section" id="report-last-section" class="ghost" aria-label="Last report section">Last</button>
|
|
868
|
+
<label for="report-object-number">Go to object</label>
|
|
869
|
+
<input type="text" data-command-id="shell.report-object-number" id="report-object-number" inputmode="numeric" autocomplete="off" aria-describedby="report-object-error">
|
|
870
|
+
<button type="button" data-command-id="shell.report-go-object" id="report-go-object" class="ghost">Go</button>
|
|
871
|
+
<span id="report-object-error" class="report-object-error" hidden></span>
|
|
872
|
+
</nav>
|
|
857
873
|
<div class="report-stage" id="report-stage">
|
|
858
874
|
<!-- sandbox flags, each load-bearing:
|
|
859
875
|
• allow-same-origin — REQUIRED. Without it the srcdoc document gets an
|
|
@@ -984,6 +1000,27 @@
|
|
|
984
1000
|
</div>
|
|
985
1001
|
</div>
|
|
986
1002
|
|
|
1003
|
+
<div class="modal-backdrop" id="tekla-source-modal" role="dialog" aria-modal="true"
|
|
1004
|
+
aria-labelledby="tekla-source-title" aria-describedby="tekla-source-sub">
|
|
1005
|
+
<div class="modal tekla-source-dialog" tabindex="-1">
|
|
1006
|
+
<div class="modal-title" id="tekla-source-title">Choose Tekla model</div>
|
|
1007
|
+
<div class="modal-sub" id="tekla-source-sub">Choose a Tekla model folder or a ZIP containing one. FloLess copies the selected source for a read-only import; it never changes the original model. Tekla does not need to be installed or open.</div>
|
|
1008
|
+
<div class="tekla-source-readonly"><strong>Read-only</strong><span>The source Tekla model is never changed.</span></div>
|
|
1009
|
+
<div class="tekla-source-choices">
|
|
1010
|
+
<button type="button" id="tekla-source-folder" data-command-id="shell.tekla-source-folder">
|
|
1011
|
+
<strong>Folder</strong><span>Choose the Tekla model folder.</span>
|
|
1012
|
+
</button>
|
|
1013
|
+
<button type="button" id="tekla-source-zip" data-command-id="shell.tekla-source-zip">
|
|
1014
|
+
<strong>ZIP archive</strong><span>Choose a ZIP that contains the Tekla model folder.</span>
|
|
1015
|
+
</button>
|
|
1016
|
+
</div>
|
|
1017
|
+
<div class="tekla-source-status" id="tekla-source-status" role="status" aria-live="polite" hidden></div>
|
|
1018
|
+
<div class="modal-actions">
|
|
1019
|
+
<button type="button" id="tekla-source-cancel" data-command-id="shell.dialog-cancel#Tekla source selection">Cancel</button>
|
|
1020
|
+
</div>
|
|
1021
|
+
</div>
|
|
1022
|
+
</div>
|
|
1023
|
+
|
|
987
1024
|
<!-- Company Knowledge stays an extension of the existing project Knowledge step. The project
|
|
988
1025
|
accepts project copies; this dialog never turns the company folder into automatic project context. -->
|
|
989
1026
|
<div class="modal-backdrop" id="company-knowledge-modal" role="dialog" aria-modal="true"
|
|
@@ -1575,6 +1612,7 @@
|
|
|
1575
1612
|
lexically scoped inside steel-editor.html's main() and stay there. -->
|
|
1576
1613
|
<script src="commands-steel.js"></script>
|
|
1577
1614
|
<script src="commands-revit.js"></script>
|
|
1615
|
+
<script src="commands-tekla-parser.js"></script>
|
|
1578
1616
|
<!-- The other three child surfaces, for the same reason. Each declares its own surface, so
|
|
1579
1617
|
the `?` sheet can put whichever one is on screen first — see Commands.surfaceScope, and
|
|
1580
1618
|
activeSurface() in instructor.js for the consumer. -->
|
package/dist/web/instructor.js
CHANGED
|
@@ -426,7 +426,6 @@
|
|
|
426
426
|
binding must never eat a literal "?" the user meant to type. */
|
|
427
427
|
|
|
428
428
|
var lastHovered = null;
|
|
429
|
-
var lastHoveredAt = 0;
|
|
430
429
|
var lastHoveredOrder = 0;
|
|
431
430
|
var lastFocused = null;
|
|
432
431
|
var lastFocusedOrder = 0;
|
|
@@ -445,10 +444,13 @@
|
|
|
445
444
|
|
|
446
445
|
function recordHoverIntent(e) {
|
|
447
446
|
lastHovered = e && e.target;
|
|
448
|
-
lastHoveredAt = Date.now();
|
|
449
447
|
lastHoveredOrder = ++intentOrder;
|
|
450
448
|
}
|
|
451
449
|
|
|
450
|
+
function clearHoverIntent() {
|
|
451
|
+
lastHovered = null;
|
|
452
|
+
}
|
|
453
|
+
|
|
452
454
|
function recordFocusIntent(e) {
|
|
453
455
|
lastFocused = e && e.target;
|
|
454
456
|
lastFocusedOrder = ++intentOrder;
|
|
@@ -462,6 +464,7 @@
|
|
|
462
464
|
if (!doc || typeof doc.addEventListener !== 'function' || remembersIntentDocument(doc)) return;
|
|
463
465
|
rememberIntentDocument(doc);
|
|
464
466
|
doc.addEventListener('mouseover', recordHoverIntent, true);
|
|
467
|
+
doc.addEventListener('mouseleave', clearHoverIntent, true);
|
|
465
468
|
doc.addEventListener('focusin', recordFocusIntent, true);
|
|
466
469
|
}
|
|
467
470
|
|
|
@@ -488,9 +491,9 @@
|
|
|
488
491
|
• Hover-first would explain whatever the mouse was last parked over,
|
|
489
492
|
which is meaningless for someone tabbing through with the keyboard.
|
|
490
493
|
|
|
491
|
-
The
|
|
492
|
-
|
|
493
|
-
|
|
494
|
+
The last intent wins. A pointer that remains over a control does not become
|
|
495
|
+
irrelevant after an arbitrary timeout; leaving the document or moving focus
|
|
496
|
+
by keyboard retires that pointer intent. */
|
|
494
497
|
|
|
495
498
|
/* A model editor's panel tabs are its own controls, moved into the main window's #left-model-panel frame
|
|
496
499
|
(web/model-panel-bridge.js): a third document, searched after the editor's own. */
|
|
@@ -530,18 +533,18 @@
|
|
|
530
533
|
var hasActive = active && active !== document.body;
|
|
531
534
|
/* A control can disappear while the pointer remains parked at its old coordinates. The revision
|
|
532
535
|
result does exactly that: Apply is hidden, then focus moves to Close. Treating the hidden Apply
|
|
533
|
-
as
|
|
536
|
+
as pointer intent makes `?` narrate an action that is no longer on screen. The same goes for
|
|
534
537
|
one a full-window overlay has since covered (#1445): it keeps its layout but is inert. */
|
|
535
538
|
var hoveredIsRendered = lastHovered && lastHovered.isConnected && isOnScreen(lastHovered);
|
|
536
|
-
var
|
|
539
|
+
var pointerIntent = hoveredIsRendered;
|
|
537
540
|
var focusedOrder = lastFocused === active ? lastFocusedOrder : 0;
|
|
538
541
|
|
|
539
|
-
var el = hasActive ? active : (
|
|
542
|
+
var el = hasActive ? active : (pointerIntent ? lastHovered : null);
|
|
540
543
|
/* Most recent intentional target wins. This keeps pointer-over-another-control
|
|
541
|
-
useful, but a later Tab/Shift+Tab transition must beat the
|
|
544
|
+
useful, but a later Tab/Shift+Tab transition must beat the earlier hover
|
|
542
545
|
left by a prior click. Programmatic focus in the browser emits focusin too,
|
|
543
546
|
so replacements that restore focus participate in the same ordering. */
|
|
544
|
-
if (
|
|
547
|
+
if (pointerIntent && lastHovered !== active && focusFor(lastHovered)
|
|
545
548
|
&& (!hasActive || !focusedOrder || lastHoveredOrder > focusedOrder)) {
|
|
546
549
|
el = lastHovered;
|
|
547
550
|
}
|
|
@@ -770,11 +773,11 @@
|
|
|
770
773
|
var GROUP_ORDER = [
|
|
771
774
|
// the shell
|
|
772
775
|
'In the header', 'In the workflow picker', 'In the project picker', 'In the project list',
|
|
773
|
-
'In the Workspace directory dialog', 'In the new project dialog', 'In the project workspace', 'In the Revit workspace', 'In Company knowledge',
|
|
776
|
+
'In the Workspace directory dialog', 'In Tekla source selection', 'In the new project dialog', 'In the project workspace', 'In the Revit workspace', 'In the Tekla Parser workspace', 'In Company knowledge',
|
|
774
777
|
'On the workflow canvas', 'In workflow setup dialogs',
|
|
775
778
|
// The Informed by row sits at the top of the canvas column, so it is read right after the canvas.
|
|
776
779
|
'In the Informed by row', 'In Set inputs',
|
|
777
|
-
'At the left edge of the workspace', 'At the edge of the left or Inspect panel', 'In the left panel', 'Between AI Chat and Model', 'In the Model section of the left panel',
|
|
780
|
+
'At the left edge of the workspace', 'At the edge of the left or Inspect panel', 'In the left panel', 'Between AI Chat and Model', 'In the Model section of the left panel', 'In the Grid object in the Model section',
|
|
778
781
|
'In AI Chat', 'In AI Chat history', 'In AI Chat settings', 'In the node Inspect panel', 'In the Instructor strip',
|
|
779
782
|
'In the ≡ menu', 'In the account menu', 'In the footer',
|
|
780
783
|
'In the contract editor', 'In the report viewer', 'In the Knowledge Base viewer', 'In the guide',
|
|
@@ -798,7 +801,8 @@
|
|
|
798
801
|
'In the Connections dialog', 'In the reference-model dialogs', 'In the connection-import dialog',
|
|
799
802
|
'In the confidence report', 'In the Ask AI panel', 'In the Ask AI dialog', 'In the Favourites dialog',
|
|
800
803
|
// the read-only Revit model editor
|
|
801
|
-
'In the Revit model header', 'In the Revit model toolbar', 'In the Revit model coordinate HUD', 'In the Revit model selection bar', 'In the Revit model snapping bar',
|
|
804
|
+
'In the Revit model header', 'In the Revit model toolbar', 'In the Revit model coordinate HUD', 'In the Revit model selection bar', 'In the Revit model snapping bar', 'In the Revit spatial controls',
|
|
805
|
+
'In the Tekla Parser header', 'In the Tekla Parser model toolbar', 'In the Tekla Parser coordinate HUD', 'In the Tekla Parser selection bar', 'In the Tekla Parser snapping bar', 'In the Tekla Parser spatial controls', 'In the Tekla Parser Audit pane',
|
|
802
806
|
// the drawing filter
|
|
803
807
|
'In the Drawing Filter header', 'In a Drawing Filter message',
|
|
804
808
|
'In the Drawing Filter panel', 'On the Drawing Filter canvas',
|
|
@@ -1451,7 +1455,6 @@
|
|
|
1451
1455
|
// control elsewhere remains the user's valid pointer intent after a keyboard close.
|
|
1452
1456
|
if (lastHovered && lastHovered.closest && lastHovered.closest('#command-sheet')) {
|
|
1453
1457
|
lastHovered = null;
|
|
1454
|
-
lastHoveredAt = 0;
|
|
1455
1458
|
}
|
|
1456
1459
|
setBackgroundInert(false);
|
|
1457
1460
|
if (coveredDialogAriaBefore) {
|
|
@@ -1604,6 +1607,15 @@
|
|
|
1604
1607
|
} catch (e) { return; }
|
|
1605
1608
|
|
|
1606
1609
|
snapshot.child = childSnap || null;
|
|
1610
|
+
/* Async child state can remove a command without moving focus (the display-unit
|
|
1611
|
+
Retry button is the first case). The reporter names commands that disappeared,
|
|
1612
|
+
so the producer can retire only the exact captured entry instead of either
|
|
1613
|
+
narrating dead UI or clearing unrelated shell guidance. */
|
|
1614
|
+
var hiddenCommands = childSnap && Array.isArray(childSnap.hiddenCommands) ? childSnap.hiddenCommands : [];
|
|
1615
|
+
if (snapshot.focus && hiddenCommands.indexOf(snapshot.focus.commandId) !== -1) {
|
|
1616
|
+
snapshot.focus = null;
|
|
1617
|
+
if (typeof window.flolessGraftInstructorClear === 'function') window.flolessGraftInstructorClear();
|
|
1618
|
+
}
|
|
1607
1619
|
paint();
|
|
1608
1620
|
|
|
1609
1621
|
// shell → child: hand back what the producer made.
|
package/dist/web/left-pane.js
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
const split = document.getElementById('left-pane-split');
|
|
14
14
|
const status = document.getElementById('left-pane-status');
|
|
15
15
|
const modelTabs = document.getElementById('left-model-tabs');
|
|
16
|
+
const modelSearch = document.getElementById('left-model-search');
|
|
17
|
+
const modelSearchInput = document.getElementById('left-model-search-input');
|
|
18
|
+
const modelSearchClear = document.getElementById('left-model-search-clear');
|
|
16
19
|
const modelIndexLabel = document.getElementById('left-model-index-label');
|
|
17
20
|
const followSelection = document.getElementById('left-model-follow-selection');
|
|
18
21
|
const modelContent = document.getElementById('left-model-content');
|
|
@@ -25,7 +28,7 @@
|
|
|
25
28
|
// controls leave with it. No src: the frame's first about:blank document is this origin and stays put.
|
|
26
29
|
const panelSlot = document.getElementById('left-model-panel-slot');
|
|
27
30
|
let panelFrame = document.getElementById('left-model-panel');
|
|
28
|
-
if (!frame || !pane || !stack || !split || !status || !modelTabs || !modelIndexLabel || !followSelection || !modelContent || !collapsedHost || !empty || !modelContext
|
|
31
|
+
if (!frame || !pane || !stack || !split || !status || !modelTabs || !modelSearch || !modelSearchInput || !modelSearchClear || !modelIndexLabel || !followSelection || !modelContent || !collapsedHost || !empty || !modelContext
|
|
29
32
|
|| !modelIndexHeader || !panelSlot || !panelFrame) return;
|
|
30
33
|
|
|
31
34
|
const sections = {
|
|
@@ -73,6 +76,8 @@
|
|
|
73
76
|
let panelShown = null; // the panel tab the editor was last told it is showing (null: none)
|
|
74
77
|
let chosenByPerson = false; // true only while a click on a tab renders: the editor is told a person chose it
|
|
75
78
|
let displacedTab = null; // a chosen tab the snapshot stopped offering (a 3D-only tab while in 2D); it comes back with it
|
|
79
|
+
let searchTimer = null;
|
|
80
|
+
let lastSearchAnnouncement = '';
|
|
76
81
|
|
|
77
82
|
const panelTabsOf = (snapshot) => (Array.isArray(snapshot?.panelTabs) ? snapshot.panelTabs : [])
|
|
78
83
|
.filter((tab) => typeof tab?.key === 'string' && typeof tab?.label === 'string');
|
|
@@ -101,6 +106,25 @@
|
|
|
101
106
|
if (state.followSelection) revealSelectedEntity();
|
|
102
107
|
if (followsTab(state.tab)) { panelShown = null; renderModel(); } // the editor draws the following, so it is told again
|
|
103
108
|
});
|
|
109
|
+
const searchContext = (query) => ({ generation: state.generation, datasetKey: state.datasetKey, tab: state.tab, query: String(query).slice(0, 200) });
|
|
110
|
+
const requestSearch = (context) => {
|
|
111
|
+
if (context.generation !== state.generation || context.datasetKey !== state.datasetKey || context.tab !== state.tab
|
|
112
|
+
|| isPanelTab(context.tab) || !context.datasetKey) return false;
|
|
113
|
+
const requestId = sendAction({ action: 'search', tab: context.tab, query: context.query, datasetKey: context.datasetKey });
|
|
114
|
+
if (requestId) pendingActions.set(requestId, { kind: 'search', tab: context.tab });
|
|
115
|
+
return !!requestId;
|
|
116
|
+
};
|
|
117
|
+
const clearSearch = () => {
|
|
118
|
+
clearTimeout(searchTimer); modelSearchInput.value = ''; modelSearchClear.hidden = true;
|
|
119
|
+
requestSearch(searchContext('')); modelSearchInput.focus();
|
|
120
|
+
};
|
|
121
|
+
modelSearchInput.addEventListener('input', () => {
|
|
122
|
+
modelSearchClear.hidden = !modelSearchInput.value;
|
|
123
|
+
const context = searchContext(modelSearchInput.value);
|
|
124
|
+
clearTimeout(searchTimer); searchTimer = setTimeout(() => requestSearch(context), 120);
|
|
125
|
+
});
|
|
126
|
+
modelSearchInput.addEventListener('keydown', (event) => { if (event.key === 'Escape' && modelSearchInput.value) { event.preventDefault(); clearSearch(); } });
|
|
127
|
+
modelSearchClear.addEventListener('click', clearSearch);
|
|
104
128
|
|
|
105
129
|
function available(key) { return key === 'narrative' || state.modelAvailable; }
|
|
106
130
|
function shown(key) { return available(key) && (state.visible[key] || sessionVisible[key]); }
|
|
@@ -441,8 +465,66 @@
|
|
|
441
465
|
|
|
442
466
|
function renderNodes(nodes, host) {
|
|
443
467
|
const scrollTop = host.scrollTop;
|
|
468
|
+
let objectRowIndex = 0;
|
|
444
469
|
host.replaceChildren();
|
|
445
470
|
if (!Array.isArray(nodes) || !nodes.length) { const empty = document.createElement('div'); empty.className = 'left-model-empty'; empty.textContent = 'No objects in this index.'; host.append(empty); return; }
|
|
471
|
+
const renderGridVisibility = (control) => {
|
|
472
|
+
const levels = Array.isArray(control?.levels) ? control.levels.filter((level) => level && typeof level.key === 'string'
|
|
473
|
+
&& Number.isFinite(level.mm) && typeof level.visible === 'boolean').sort((left, right) => left.mm - right.mm) : [];
|
|
474
|
+
if (!levels.length) return null;
|
|
475
|
+
const fieldset = document.createElement('fieldset'); fieldset.className = 'left-grid-visibility';
|
|
476
|
+
fieldset.setAttribute('aria-label', 'Grid visibility');
|
|
477
|
+
const legend = document.createElement('legend'); legend.textContent = 'Grid visibility'; fieldset.append(legend);
|
|
478
|
+
const rows = [];
|
|
479
|
+
const option = ({ key, primary, secondary = '', checked, master = false }) => {
|
|
480
|
+
const row = document.createElement('label'); row.className = `left-grid-level${master ? ' left-grid-level-all' : ''}`;
|
|
481
|
+
const input = document.createElement('input'); input.type = 'checkbox'; input.checked = checked;
|
|
482
|
+
input.dataset.gridLevelKey = key; input.dataset.commandId = `shell.grid-elevation#${commandInstance(key)}`;
|
|
483
|
+
const name = document.createElement('span'); name.className = 'left-grid-level-name'; name.textContent = primary;
|
|
484
|
+
row.append(input, name);
|
|
485
|
+
if (secondary) { const value = document.createElement('span'); value.className = 'left-grid-level-value'; value.textContent = secondary; row.append(value); }
|
|
486
|
+
fieldset.append(row); rows.push({ input, level: key === '*' ? null : levels.find((level) => level.key === key) });
|
|
487
|
+
return input;
|
|
488
|
+
};
|
|
489
|
+
const visibleCount = levels.filter((level) => level.visible).length;
|
|
490
|
+
const master = option({ key: '*', primary: 'All elevations', secondary: `${visibleCount} of ${levels.length}`, checked: visibleCount === levels.length, master: true });
|
|
491
|
+
master.indeterminate = visibleCount > 0 && visibleCount < levels.length;
|
|
492
|
+
master.setAttribute('aria-checked', master.indeterminate ? 'mixed' : String(master.checked));
|
|
493
|
+
for (const level of levels) {
|
|
494
|
+
const primary = String(level.authored || level.label || 'Grid plane').trim() || 'Grid plane';
|
|
495
|
+
const display = String(level.display || `${Math.round(level.mm)} mm`).trim();
|
|
496
|
+
const comparable = (value) => value.toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, '');
|
|
497
|
+
option({ key: level.key, primary, secondary: comparable(display) === comparable(primary) ? '' : display, checked: level.visible });
|
|
498
|
+
}
|
|
499
|
+
const note = document.createElement('p'); note.className = 'left-grid-visibility-status'; fieldset.append(note);
|
|
500
|
+
const repaint = (announce = false) => {
|
|
501
|
+
const individual = rows.filter((item) => item.level); const shown = individual.filter((item) => item.input.checked);
|
|
502
|
+
master.checked = shown.length === individual.length; master.indeterminate = shown.length > 0 && shown.length < individual.length;
|
|
503
|
+
master.setAttribute('aria-checked', master.indeterminate ? 'mixed' : String(master.checked));
|
|
504
|
+
master.dataset.commandInstanceLabel = `all elevations — ${master.indeterminate ? 'mixed' : master.checked ? 'shown' : 'hidden'}`;
|
|
505
|
+
for (const item of individual) {
|
|
506
|
+
const authored = String(item.level.authored || item.level.label || item.level.display || 'grid plane').trim();
|
|
507
|
+
item.input.dataset.commandInstanceLabel = `${authored} — ${item.input.checked ? 'shown' : 'hidden'}`;
|
|
508
|
+
}
|
|
509
|
+
const count = master.closest('label')?.querySelector('.left-grid-level-value'); if (count) count.textContent = `${shown.length} of ${individual.length}`;
|
|
510
|
+
note.textContent = shown.length ? `Bubbles at lowest shown elevation: ${String(shown[0].level.authored || shown[0].level.label || shown[0].level.display).trim()}.`
|
|
511
|
+
: 'Grid hidden at all elevations. Check an elevation to show it.';
|
|
512
|
+
if (announce) status.textContent = note.textContent;
|
|
513
|
+
const active = document.activeElement;
|
|
514
|
+
if (rows.some((item) => item.input === active)) window.Instructor?.refreshCarrier?.(active);
|
|
515
|
+
};
|
|
516
|
+
const sendVisibility = (levelKey, visible, input) => {
|
|
517
|
+
const requestId = sendAction({ action: 'grid-visibility', levelKey, visible, datasetKey: state.datasetKey });
|
|
518
|
+
if (requestId) pendingActions.set(requestId, { kind: 'grid-visibility', commandId: input.dataset.commandId });
|
|
519
|
+
};
|
|
520
|
+
master.addEventListener('change', () => {
|
|
521
|
+
for (const item of rows) if (item.level) item.input.checked = master.checked;
|
|
522
|
+
repaint(true); sendVisibility(null, master.checked, master);
|
|
523
|
+
});
|
|
524
|
+
for (const item of rows) if (item.level) item.input.addEventListener('change', () => { repaint(true); sendVisibility(item.level.key, item.input.checked, item.input); });
|
|
525
|
+
repaint();
|
|
526
|
+
return fieldset;
|
|
527
|
+
};
|
|
446
528
|
const append = (items, parent) => {
|
|
447
529
|
for (const node of items) {
|
|
448
530
|
if (!node || typeof node.label !== 'string') continue;
|
|
@@ -455,17 +537,48 @@
|
|
|
455
537
|
? `shell.model-item#${commandInstance(instance)}`
|
|
456
538
|
: `shell.model-group#${commandInstance(instance)}`;
|
|
457
539
|
row.dataset.commandInstanceLabel = node.label;
|
|
458
|
-
const accessibleLabel = node.count == null ? node.label : `${node.label}, ${node.count}`;
|
|
459
|
-
row.setAttribute('aria-label', accessibleLabel);
|
|
460
540
|
if (typeof node.tip === 'string' && node.tip) row.dataset.tip = node.tip;
|
|
461
|
-
const label = document.createElement('span'); label.className = 'row-label'; label.textContent = node.label;
|
|
541
|
+
const label = document.createElement('span'); label.className = 'row-label'; label.textContent = node.label;
|
|
542
|
+
if (node.entityId && node.objectFields && ['name', 'profile', 'id'].every((key) => node.objectFields[key] == null || typeof node.objectFields[key] === 'string')) {
|
|
543
|
+
row.classList.add('model-object-row');
|
|
544
|
+
const summary = document.createElement('span'); summary.className = 'model-object-summary';
|
|
545
|
+
const fieldId = `left-model-object-${++objectRowIndex}`;
|
|
546
|
+
label.classList.add('model-object-name'); label.id = `${fieldId}-name`;
|
|
547
|
+
if (node.objectFields.name != null) { label.dataset.objectField = 'name'; label.textContent = node.objectFields.name; }
|
|
548
|
+
summary.append(label); row.setAttribute('aria-labelledby', label.id);
|
|
549
|
+
const details = document.createElement('span'); details.className = 'model-object-details'; details.id = `${fieldId}-details`;
|
|
550
|
+
for (const [key, caption] of [['profile', 'Profile'], ['id', 'ID']]) {
|
|
551
|
+
if (node.objectFields[key] == null) continue;
|
|
552
|
+
const field = document.createElement('span'); field.className = 'model-object-field';
|
|
553
|
+
const fieldLabel = document.createElement('span'); fieldLabel.className = 'model-object-field-label'; fieldLabel.textContent = `${caption}: `;
|
|
554
|
+
const value = document.createElement('span'); value.dataset.objectField = key; value.textContent = node.objectFields[key];
|
|
555
|
+
field.append(fieldLabel, value); details.append(field);
|
|
556
|
+
}
|
|
557
|
+
if (details.children.length) { summary.append(details); row.setAttribute('aria-describedby', details.id); }
|
|
558
|
+
row.append(summary);
|
|
559
|
+
} else {
|
|
560
|
+
row.setAttribute('aria-label', node.count == null ? node.label : `${node.label}, ${node.count}`);
|
|
561
|
+
row.append(label);
|
|
562
|
+
}
|
|
462
563
|
if (node.count != null) { const count = document.createElement('span'); count.className = 'explorer-count'; count.textContent = String(node.count); row.append(count); }
|
|
463
564
|
if (node.entityId) {
|
|
464
565
|
row.dataset.entityId = node.entityId;
|
|
465
566
|
row.classList.toggle('selected', selectedIdsOf(state.snapshot).includes(node.entityId));
|
|
466
567
|
if (node.entityId === state.snapshot?.selectedId) row.setAttribute('aria-current', 'true');
|
|
467
|
-
|
|
468
|
-
const item = document.createElement('div'); item.setAttribute('role', 'listitem');
|
|
568
|
+
const gridControl = state.snapshot?.gridVisibility?.entityId === node.entityId ? renderGridVisibility(state.snapshot.gridVisibility) : null;
|
|
569
|
+
const item = document.createElement('div'); item.setAttribute('role', 'listitem');
|
|
570
|
+
if (gridControl) {
|
|
571
|
+
item.className = 'left-model-branch left-grid-object';
|
|
572
|
+
const disclosureKey = `${state.datasetKey}:${state.tab}:grid-visibility:${node.entityId}`;
|
|
573
|
+
const searching = !!state.snapshot?.searches?.[state.tab]?.query;
|
|
574
|
+
const expanded = searching || (groupDisclosure.has(disclosureKey) ? groupDisclosure.get(disclosureKey) : true);
|
|
575
|
+
row.setAttribute('aria-expanded', String(expanded)); gridControl.hidden = !expanded;
|
|
576
|
+
row.addEventListener('click', (event) => {
|
|
577
|
+
const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); gridControl.hidden = !open;
|
|
578
|
+
groupDisclosure.set(disclosureKey, open); selectRow(node.entityId, event);
|
|
579
|
+
});
|
|
580
|
+
item.append(row, gridControl);
|
|
581
|
+
} else { row.addEventListener('click', (event) => selectRow(node.entityId, event)); item.append(row); }
|
|
469
582
|
parent.append(item); continue;
|
|
470
583
|
}
|
|
471
584
|
if (Array.isArray(node.children)) {
|
|
@@ -487,6 +600,7 @@
|
|
|
487
600
|
if (node.lazy && !node.children.length) { requestLazyChildren(); return; }
|
|
488
601
|
const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); children.hidden = !open;
|
|
489
602
|
groupDisclosure.set(disclosureKey, open);
|
|
603
|
+
if (node.selectable === true) sendAction({ action: 'select-group', groupId: node.groupId, datasetKey: state.datasetKey });
|
|
490
604
|
});
|
|
491
605
|
branch.append(row, children); parent.append(branch);
|
|
492
606
|
if (expanded && node.lazy && !node.children.length) requestLazyChildren();
|
|
@@ -509,10 +623,14 @@
|
|
|
509
623
|
}
|
|
510
624
|
const selectedId = selectedIds[0];
|
|
511
625
|
pendingRevealId = selectedId;
|
|
512
|
-
|
|
626
|
+
const followTab = state.snapshot.tabs.find((tab) => tab.key === 'model')?.key || state.snapshot.tabs[0]?.key;
|
|
627
|
+
if (followTab && state.tab !== followTab) { state.tab = followTab; renderModel(); }
|
|
513
628
|
const row = [...modelContent.querySelectorAll('[data-entity-id]')]
|
|
514
629
|
.find((candidate) => candidate.dataset.entityId === selectedId);
|
|
515
|
-
if (!row)
|
|
630
|
+
if (!row) {
|
|
631
|
+
if (state.snapshot?.searches?.[state.tab]?.query) status.textContent = 'The selected object is hidden by search. Clear the search to reveal it.';
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
516
634
|
let children = row.closest('.left-model-children');
|
|
517
635
|
while (children) {
|
|
518
636
|
children.hidden = false;
|
|
@@ -525,6 +643,8 @@
|
|
|
525
643
|
}
|
|
526
644
|
children = branch?.parentElement?.closest('.left-model-children') || null;
|
|
527
645
|
}
|
|
646
|
+
const gridControl = row.parentElement?.querySelector(':scope > .left-grid-visibility');
|
|
647
|
+
if (gridControl) { row.setAttribute('aria-expanded', 'true'); gridControl.hidden = false; }
|
|
528
648
|
const sequence = ++revealSequence;
|
|
529
649
|
const generation = state.generation;
|
|
530
650
|
const revision = state.revision;
|
|
@@ -581,6 +701,7 @@
|
|
|
581
701
|
if (!button.dataset.leftPaneBound) {
|
|
582
702
|
button.dataset.leftPaneBound = 'true';
|
|
583
703
|
button.addEventListener('click', () => {
|
|
704
|
+
clearTimeout(searchTimer); searchTimer = null;
|
|
584
705
|
state.tab = button.dataset.modelTabKey; displacedTab = null; save();
|
|
585
706
|
chosenByPerson = true; try { renderModel(); } finally { chosenByPerson = false; }
|
|
586
707
|
button.focus();
|
|
@@ -601,7 +722,7 @@
|
|
|
601
722
|
if (focusedKey) buttons.find((button) => button.dataset.modelTabKey === focusedKey)?.focus({ preventScroll: true });
|
|
602
723
|
// A PANEL tab: the editor draws it in the frame; this side only shows the slot and says which tab.
|
|
603
724
|
const panel = isPanelTab(state.tab) ? state.tab : null;
|
|
604
|
-
modelIndexHeader.hidden = !!panel && !followsTab(panel); modelContent.hidden = !!panel; panelSlot.hidden = !panel;
|
|
725
|
+
modelSearch.hidden = !!panel; modelIndexHeader.hidden = !!panel && !followsTab(panel); modelContent.hidden = !!panel; panelSlot.hidden = !panel;
|
|
605
726
|
if (panel) {
|
|
606
727
|
if (followsTab(panel)) modelIndexLabel.textContent = tabs.find((tab) => tab.key === panel).label;
|
|
607
728
|
panelSlot.setAttribute('aria-labelledby', `left-model-tab-${panel}`);
|
|
@@ -613,12 +734,27 @@
|
|
|
613
734
|
if (requestId) { panelShown = panel; pendingActions.set(requestId, { kind: 'panel', key: panel }); }
|
|
614
735
|
}
|
|
615
736
|
if (panel) return;
|
|
737
|
+
const activeSearch = snapshot.searches?.[state.tab] || {};
|
|
738
|
+
const nextQuery = typeof activeSearch.query === 'string' ? activeSearch.query : '';
|
|
739
|
+
if (document.activeElement !== modelSearchInput) modelSearchInput.value = nextQuery;
|
|
740
|
+
modelSearchInput.setAttribute('aria-label', `Search objects in ${tabs.find((tab) => tab.key === state.tab)?.label || 'model'}`);
|
|
741
|
+
modelSearchClear.hidden = !modelSearchInput.value;
|
|
616
742
|
modelContent.setAttribute('aria-labelledby', `left-model-tab-${state.tab}`);
|
|
617
743
|
const focusedCommand = modelContent.contains(document.activeElement)
|
|
618
744
|
? document.activeElement?.closest?.('[data-command-id]')?.getAttribute('data-command-id') : null;
|
|
619
745
|
const body = Array.isArray(snapshot.bodies?.[state.tab]) ? snapshot.bodies[state.tab] : [];
|
|
620
746
|
const headingIndex = body.findIndex((node) => node?.kind === 'label');
|
|
621
|
-
|
|
747
|
+
const indexLabel = headingIndex >= 0 ? body[headingIndex].label : `Browse by ${tabs.find((tab) => tab.key === state.tab)?.label?.toLowerCase() || 'model'}`;
|
|
748
|
+
modelIndexLabel.textContent = Number.isFinite(activeSearch.shown) && Number.isFinite(activeSearch.total) && nextQuery
|
|
749
|
+
? `${indexLabel} · ${activeSearch.shown} of ${activeSearch.total}` : indexLabel;
|
|
750
|
+
const announcementKey = nextQuery && Number.isFinite(activeSearch.shown) && Number.isFinite(activeSearch.total)
|
|
751
|
+
? `${state.datasetKey}:${state.tab}:${nextQuery}:${activeSearch.shown}:${activeSearch.total}` : '';
|
|
752
|
+
if (announcementKey && announcementKey !== lastSearchAnnouncement) {
|
|
753
|
+
status.textContent = activeSearch.shown > 0
|
|
754
|
+
? `${activeSearch.shown} of ${activeSearch.total} objects.`
|
|
755
|
+
: `No objects match “${nextQuery}”.`;
|
|
756
|
+
lastSearchAnnouncement = announcementKey;
|
|
757
|
+
} else if (!announcementKey) lastSearchAnnouncement = '';
|
|
622
758
|
renderNodes(headingIndex >= 0 ? body.filter((_node, index) => index !== headingIndex) : body, modelContent);
|
|
623
759
|
if (focusedCommand) [...modelContent.querySelectorAll('[data-command-id]')]
|
|
624
760
|
.find((item) => item.getAttribute('data-command-id') === focusedCommand)?.focus({ preventScroll: true });
|
|
@@ -686,6 +822,16 @@
|
|
|
686
822
|
if (currentChildren) currentChildren.hidden = false;
|
|
687
823
|
}
|
|
688
824
|
}
|
|
825
|
+
if (pending?.kind === 'grid-visibility' && !data.ok) {
|
|
826
|
+
const refreshRollback = document.activeElement?.dataset?.commandId === pending.commandId;
|
|
827
|
+
renderModel();
|
|
828
|
+
if (refreshRollback) {
|
|
829
|
+
const restored = [...modelContent.querySelectorAll('[data-command-id]')]
|
|
830
|
+
.find((row) => row.dataset.commandId === pending.commandId);
|
|
831
|
+
if (restored) { restored.focus(); window.Instructor?.refreshCarrier?.(restored); }
|
|
832
|
+
else window.Instructor?.clear?.();
|
|
833
|
+
}
|
|
834
|
+
}
|
|
689
835
|
if (!data.ok) status.textContent = data.message || 'That model action is no longer available.';
|
|
690
836
|
// The frame stays empty, so say so where the tab would be — for the tab still shown, not an earlier one.
|
|
691
837
|
if (pending?.kind === 'panel' && !data.ok && pending.key === panelShown) {
|
|
@@ -715,6 +861,10 @@
|
|
|
715
861
|
state.snapshot.selectedId = typeof data.selectedId === 'string' ? data.selectedId : null;
|
|
716
862
|
state.snapshot.selectedIds = Array.isArray(data.selectedIds) ? data.selectedIds.filter((id) => typeof id === 'string') : (state.snapshot.selectedId ? [state.snapshot.selectedId] : []);
|
|
717
863
|
state.snapshot.selectionOrigin = data.selectionOrigin || 'tree';
|
|
864
|
+
if (Array.isArray(data.geometrySelectionIds)) {
|
|
865
|
+
state.snapshot.focusEntityId = typeof data.focusEntityId === 'string' ? data.focusEntityId : null;
|
|
866
|
+
state.snapshot.geometrySelectionIds = data.geometrySelectionIds.filter((id) => typeof id === 'string');
|
|
867
|
+
}
|
|
718
868
|
state.snapshot.subjects = data.subjects && typeof data.subjects === 'object' ? data.subjects : null;
|
|
719
869
|
}
|
|
720
870
|
announceSelection();
|
|
@@ -56,6 +56,21 @@ export async function readModelJsonArtifact({ url, receipt, rowKey, expectedItem
|
|
|
56
56
|
return { document, rows, bytes: bytes.byteLength };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** Fetch and authenticate a signed JSON document whose receipt counts something other than a top-level row array. */
|
|
60
|
+
export async function readModelJsonDocument({ url, receipt, fetchImpl = fetch, cryptoImpl = crypto, signal = undefined }) {
|
|
61
|
+
preflightModelJsonReceipt(receipt);
|
|
62
|
+
const response = await fetchImpl(url, { credentials: 'same-origin', signal });
|
|
63
|
+
if (!response.ok) throw new Error(`Model artifact request failed (${response.status}).`);
|
|
64
|
+
const bytes = await readBoundedBytes(response, receipt, MODEL_VIEWER_MAX_JSON_BYTES);
|
|
65
|
+
if (bytes.byteLength !== receipt.bytes) throw new Error('The model artifact byte length does not match its signed receipt.');
|
|
66
|
+
const digest = hex(new Uint8Array(await cryptoImpl.subtle.digest('SHA-256', bytes)));
|
|
67
|
+
if (digest !== receipt.digest) throw new Error('The model artifact digest does not match its signed receipt.');
|
|
68
|
+
let document;
|
|
69
|
+
try { document = JSON.parse(new TextDecoder().decode(bytes)); } catch { throw new Error('The authenticated model artifact is not valid JSON.'); }
|
|
70
|
+
if (!document || typeof document !== 'object' || Array.isArray(document)) throw new Error('The authenticated model artifact is not a JSON object.');
|
|
71
|
+
return { document, bytes: bytes.byteLength };
|
|
72
|
+
}
|
|
73
|
+
|
|
59
74
|
/** Fetch and authenticate one signed binary model artifact without exceeding its bounded receipt. */
|
|
60
75
|
export async function readModelBinaryArtifact({ url, receipt, maxBytes, fetchImpl = fetch, cryptoImpl = crypto, signal = undefined }) {
|
|
61
76
|
if (!receipt || !Number.isSafeInteger(receipt.bytes) || receipt.bytes < 0 || receipt.bytes > maxBytes || !SHA256.test(receipt.digest)) throw new Error('The model artifact has no safe signed byte receipt.');
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { DEFAULT_DISPLAY_UNITS, formatLength, FT_IN, MM } from './display-units.js';
|
|
2
|
+
|
|
3
|
+
const valid = (value) => value === FT_IN || value === MM;
|
|
4
|
+
|
|
5
|
+
/** The parser viewers share Steel's project preference and its single length formatter. */
|
|
6
|
+
export function mountModelDisplayUnits({ host, doc, projectId, commandPrefix, request, onChange, onError,
|
|
7
|
+
wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }) {
|
|
8
|
+
let units = null, saving = false, destroyed = false, generation = 0, readGeneration = 0, connectionGeneration = 0, connected = true, stale = false;
|
|
9
|
+
const controls = [];
|
|
10
|
+
host.setAttribute('role', 'group'); host.setAttribute('aria-label', 'Display units');
|
|
11
|
+
const label = doc.createElement('span'); label.textContent = 'Units'; host.append(label);
|
|
12
|
+
const status = doc.createElement('span'); status.className = 'model-units-status'; status.setAttribute('role', 'status');
|
|
13
|
+
const retry = doc.createElement('button'); retry.type = 'button'; retry.className = 'model-units-retry'; retry.textContent = 'Retry'; retry.dataset.commandId = `${commandPrefix}.display-units-retry`; retry.setAttribute('aria-label', 'Retry loading project display units');
|
|
14
|
+
retry.addEventListener('click', () => load());
|
|
15
|
+
const paint = () => {
|
|
16
|
+
for (const [value, button] of controls) {
|
|
17
|
+
button.disabled = units === null || saving;
|
|
18
|
+
button.setAttribute('aria-pressed', String(value === units));
|
|
19
|
+
button.dataset.tip = units === null ? 'Loading this project’s display units…'
|
|
20
|
+
: saving ? 'Saving this project’s display units…' : `Display lengths in ${value === MM ? 'millimetres' : 'feet and inches'}`;
|
|
21
|
+
}
|
|
22
|
+
status.hidden = connected && !stale;
|
|
23
|
+
status.textContent = stale ? (units === null ? 'Units unavailable (ft-in)' : 'Units may be stale') : connected ? '' : 'Offline';
|
|
24
|
+
status.dataset.tip = units === null ? 'Project units could not be confirmed. Feet and inches are shown until Retry succeeds.' : 'The last confirmed units are shown. Retry to read the current project setting.';
|
|
25
|
+
status.setAttribute('aria-label', status.hidden ? '' : units === null ? 'Project display units unavailable; showing feet and inches' : 'Display units may be out of date');
|
|
26
|
+
retry.hidden = !stale; retry.disabled = saving;
|
|
27
|
+
const instructorState = doc.defaultView?.__revitInstructorState;
|
|
28
|
+
if (instructorState && typeof instructorState === 'object') {
|
|
29
|
+
doc.defaultView.__revitInstructorState = {
|
|
30
|
+
...instructorState,
|
|
31
|
+
hiddenCommands: retry.hidden ? [retry.dataset.commandId] : [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
doc.defaultView?.__instructor?.notifyChanged?.();
|
|
35
|
+
};
|
|
36
|
+
const confirm = (value) => { if (!valid(value) || destroyed) return; const changed = units !== value; units = value; paint(); if (changed) onChange(units); };
|
|
37
|
+
const adopt = (value) => { if (!valid(value) || destroyed) return; generation += 1; confirm(value); };
|
|
38
|
+
const url = `/api/projects/${encodeURIComponent(projectId)}/display-units`;
|
|
39
|
+
const choose = async (value) => {
|
|
40
|
+
if (saving || units === null || units === value || destroyed) return;
|
|
41
|
+
const started = generation;
|
|
42
|
+
saving = true; paint();
|
|
43
|
+
try {
|
|
44
|
+
const body = await request(url, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ displayUnits: value }) });
|
|
45
|
+
if (!valid(body.displayUnits)) throw new Error('Unknown confirmed display units');
|
|
46
|
+
if (generation === started) { stale = false; confirm(body.displayUnits); }
|
|
47
|
+
else await load(); // A live event arrived during the write; ask the server which value won.
|
|
48
|
+
} catch { if (!destroyed) { await load(); onError('Could not confirm the unit change. Showing the last confirmed units.'); } }
|
|
49
|
+
finally { saving = false; if (!destroyed) paint(); }
|
|
50
|
+
};
|
|
51
|
+
for (const value of [FT_IN, MM]) {
|
|
52
|
+
const button = doc.createElement('button'); button.type = 'button'; button.textContent = value;
|
|
53
|
+
button.dataset.unitChoice = value;
|
|
54
|
+
button.dataset.commandId = `${commandPrefix}.display-units#${value}`;
|
|
55
|
+
button.setAttribute('aria-label', `Display units: ${value}`);
|
|
56
|
+
button.addEventListener('click', () => choose(value)); controls.push([value, button]); host.append(button);
|
|
57
|
+
}
|
|
58
|
+
host.append(status, retry);
|
|
59
|
+
paint();
|
|
60
|
+
async function load() {
|
|
61
|
+
const requestGeneration = ++readGeneration;
|
|
62
|
+
for (const backoff of [100, 250, 500]) {
|
|
63
|
+
await wait(backoff);
|
|
64
|
+
if (destroyed || requestGeneration !== readGeneration) return false;
|
|
65
|
+
const started = generation;
|
|
66
|
+
try {
|
|
67
|
+
const body = await request(url); if (!valid(body.displayUnits)) throw new Error('Unknown display units');
|
|
68
|
+
if (destroyed || requestGeneration !== readGeneration) return false;
|
|
69
|
+
// Every event is an observation epoch, even when the displayed units did not change.
|
|
70
|
+
// Retry until the GET completed without an intervening cross-tab observation.
|
|
71
|
+
if (generation !== started) continue;
|
|
72
|
+
stale = false; confirm(body.displayUnits); return true;
|
|
73
|
+
} catch { /* Retry the same bounded reconciliation pass. */ }
|
|
74
|
+
}
|
|
75
|
+
if (!destroyed && requestGeneration === readGeneration) {
|
|
76
|
+
stale = true; paint(); onError(units === null ? 'Could not read this project’s display units. Showing feet and inches.' : 'Project units could not be refreshed. Showing the last confirmed units.');
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
load,
|
|
82
|
+
connectionLost() { connectionGeneration++; connected = false; paint(); },
|
|
83
|
+
async reconnect() { const attempt = ++connectionGeneration; const confirmed = await load(); if (!destroyed && attempt === connectionGeneration) { connected = confirmed; paint(); } },
|
|
84
|
+
adopt,
|
|
85
|
+
units: () => units ?? DEFAULT_DISPLAY_UNITS,
|
|
86
|
+
length(mm) { const value = units ?? DEFAULT_DISPLAY_UNITS; return formatLength(mm, value) + (value === MM ? ' mm' : ''); },
|
|
87
|
+
destroy() { destroyed = true; host.replaceChildren(); },
|
|
88
|
+
};
|
|
89
|
+
}
|