@floless/app 0.138.2 → 0.139.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/autostart.mjs +6 -2
- package/desktop-access-production-manifest.mjs +7 -0
- package/dist/floless-server.cjs +157202 -70901
- package/dist/schemas/model.continuation.v1.schema.json +19 -0
- package/dist/schemas/model.continuation.v2.schema.json +19 -0
- package/dist/schemas/model.query-response.v1.schema.json +95 -0
- package/dist/schemas/model.query-response.v2.schema.json +80 -0
- package/dist/schemas/model.query.v1.schema.json +87 -0
- package/dist/schemas/model.query.v2.schema.json +87 -0
- package/dist/schemas/model.snap-candidate.v1.schema.json +48 -0
- package/dist/schemas/model.snap-constraint.v1.schema.json +18 -0
- package/dist/schemas/model.snap-query.v1.schema.json +24 -0
- package/dist/schemas/model.snap-result.v1.schema.json +33 -0
- package/dist/schemas/model.snapshot.v1.schema.json +136 -0
- package/dist/schemas/revit.model.v1.schema.json +24 -0
- package/dist/schemas/steel.model.v2.schema.json +45 -6
- package/dist/skills/floless-app-approval/SKILL.md +19 -5
- package/dist/skills/floless-app-bridge/SKILL.md +19 -6
- package/dist/skills/floless-app-knowledge/SKILL.md +22 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +31 -27
- package/dist/skills/floless-app-new-workflow/references/build-and-verify.md +13 -12
- package/dist/skills/floless-app-onboarding/SKILL.md +3 -3
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +16 -9
- package/dist/skills/floless-app-steel-model/SKILL.md +11 -2
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +95 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +142 -21
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +19 -0
- package/dist/skills/floless-app-tweak-contract/SKILL.md +42 -8
- package/dist/skills/floless-app-vectorize/SKILL.md +19 -6
- package/dist/skills/floless-app-workflows/SKILL.md +30 -3
- package/dist/skills/floless-app-workflows/references/workspace-data.md +77 -4
- package/dist/templates/floless-workspace-model-report.flo +77 -0
- package/dist/templates/revit-model.flo +111 -0
- package/dist/web/app.css +415 -177
- package/dist/web/app.js +302 -51
- package/dist/web/aware.js +1357 -1032
- package/dist/web/chat.css +692 -0
- package/dist/web/chat.js +2651 -0
- package/dist/web/commands-revit.js +42 -0
- package/dist/web/commands-shell.js +531 -70
- package/dist/web/commands-steel.js +344 -146
- package/dist/web/commands.js +1 -1
- package/dist/web/index.html +283 -77
- package/dist/web/instructor.js +217 -36
- package/dist/web/left-pane.js +636 -0
- package/dist/web/model-artifact-loader.js +75 -0
- package/dist/web/model-authoring-gestures.js +141 -0
- package/dist/web/model-cad-tools.js +20 -0
- package/dist/web/model-clip-gesture.js +148 -0
- package/dist/web/model-clip-list.js +156 -0
- package/dist/web/model-clip-session.js +274 -0
- package/dist/web/model-clip-three-overlay.js +295 -0
- package/dist/web/model-clip-three-preview.js +59 -0
- package/dist/web/model-editor-contract.js +519 -0
- package/dist/web/model-editor-revit-adapter.js +139 -0
- package/dist/web/model-editor-shell.js +271 -0
- package/dist/web/model-editor-state-recovery.js +44 -0
- package/dist/web/model-editor-steel-adapter.js +410 -0
- package/dist/web/model-editor.css +268 -0
- package/dist/web/model-frame.js +192 -0
- package/dist/web/model-inspector.js +128 -0
- package/dist/web/model-measure.js +390 -0
- package/dist/web/model-navigation-controls.js +246 -0
- package/dist/web/model-orientation-overlay.js +217 -0
- package/dist/web/model-panel-bridge.js +230 -0
- package/dist/web/model-pointer-dock.js +164 -0
- package/dist/web/model-revit-module.js +83 -0
- package/dist/web/model-selection-coordinator.js +151 -0
- package/dist/web/model-selection-tools.js +290 -0
- package/dist/web/model-snap-contract.js +267 -0
- package/dist/web/model-snapping.js +497 -0
- package/dist/web/model-spatial-panel.js +294 -0
- package/dist/web/model-spatial-tools.js +249 -0
- package/dist/web/model-tree.js +47 -0
- package/dist/web/model-viewport-lighting.js +166 -0
- package/dist/web/model-viewport-revit-adapter.js +1224 -0
- package/dist/web/model-viewport-state.js +505 -0
- package/dist/web/model-viewport-steel-adapter.js +150 -0
- package/dist/web/model-viewport-toolbar.js +516 -0
- package/dist/web/model-viewport.js +717 -0
- package/dist/web/panels.js +8 -15
- package/dist/web/renderers.js +3 -0
- package/dist/web/revit-editor.css +35 -0
- package/dist/web/revit-editor.html +74 -0
- package/dist/web/revit-editor.js +845 -0
- package/dist/web/steel-3d-core.js +16 -44
- package/dist/web/steel-3d-view.js +1384 -633
- package/dist/web/steel-canvas-guidance.js +3 -1
- package/dist/web/steel-editor.html +2121 -1253
- package/dist/web/steel-filter.html +5 -1
- package/dist/web/steel-model-v2-commands.js +72 -1
- package/dist/web/steel-split-view.js +5 -39
- package/dist/web/steel-view-generation.js +107 -17
- package/dist/web/vector-3d.html +12 -0
- package/dist/web/workspaces.js +2154 -283
- package/distribution-profile-active.mjs +2 -0
- package/distribution-profile-production.mjs +47 -0
- package/distribution-profile-shared.mjs +8 -0
- package/distribution-profile.mjs +18 -0
- package/distribution-resource-inventory.mjs +81 -0
- package/launch.mjs +18 -10
- package/log.mjs +2 -1
- package/managed-runtime-policy.mjs +104 -0
- package/model-reader-policy-active.mjs +7 -0
- package/network-policy-active.mjs +6 -0
- package/package.json +17 -2
- package/post-update-marker.mjs +3 -1
- package/rvt-production-uat-authority.mjs +60 -0
- package/teardown.mjs +4 -3
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* model-viewport-toolbar.js — renders the common 3D toolbar from a render plan.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS RETURNS A STRING RATHER THAN BUILDING DOM. Two static guards read the toolbar:
|
|
5
|
+
* `server/build/instructor-id-inventory.mjs` scans `web/*.html` and checks that every
|
|
6
|
+
* `data-command-id` names a registered command, announces something, and is still on the page its
|
|
7
|
+
* baseline says; `verify-command-registry` refuses an id with no definition. `#m3dBar` carries 40 of
|
|
8
|
+
* the first editor page's 395 carriers — a tenth of the page's accessibility coverage — and a
|
|
9
|
+
* runtime-built DOM tree would take all 40 out of both scans while the ratchet stayed green. The
|
|
10
|
+
* parent plan's locked decisions forbid exactly that ("the first implementation does not create a
|
|
11
|
+
* guard blind spot"). A pure string is something a guard can read without a browser, so the guards
|
|
12
|
+
* scan what this function returns for a module's plan, and stay whole.
|
|
13
|
+
*
|
|
14
|
+
* IT IS ALSO WHAT MAKES THIS TESTABLE AT ALL. The editor page's headless harness has no layout engine
|
|
15
|
+
* and no 3D view, so a DOM-building renderer could only ever be checked in a browser. A string is
|
|
16
|
+
* checked in node, and the browser is left to prove the things only a browser can.
|
|
17
|
+
*
|
|
18
|
+
* NEUTRAL BY CONSTRUCTION, NOT BY INTENTION. Nothing here knows a command vocabulary of any kind: the
|
|
19
|
+
* plan arrives with every command id already resolved by the module that built it. This file does not
|
|
20
|
+
* even name the module that calls it, and `server/model-editor-facade.test.ts` keeps it that way —
|
|
21
|
+
* naming one consumer is how a shared file starts reasoning about one.
|
|
22
|
+
*
|
|
23
|
+
* THE HOST OWNS THE CONTAINER. This returns the bar's INNER markup. `#m3dBar` itself keeps its
|
|
24
|
+
* `role=group`, its `aria-label`, and — load-bearing — its identity: `syncLegendClearance()` observes
|
|
25
|
+
* that exact element with a `ResizeObserver`, and replacing it rather than filling it would orphan
|
|
26
|
+
* the observer and freeze the Explorer's max-height at whatever it last measured.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Escape a value for HTML text or a double-quoted attribute.
|
|
31
|
+
*
|
|
32
|
+
* The bar is written with `innerHTML`, and labels, tips and command ids all arrive from a caller.
|
|
33
|
+
* Backtick is escaped too: it is inert in HTML but is an attribute delimiter in old IE and shows up
|
|
34
|
+
* in payloads that probe for exactly that, and escaping it costs nothing.
|
|
35
|
+
*/
|
|
36
|
+
export function escapeHtml(value) {
|
|
37
|
+
return String(value ?? '')
|
|
38
|
+
.replace(/&/g, '&')
|
|
39
|
+
.replace(/</g, '<')
|
|
40
|
+
.replace(/>/g, '>')
|
|
41
|
+
.replace(/"/g, '"')
|
|
42
|
+
.replace(/'/g, ''')
|
|
43
|
+
.replace(/`/g, '`');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `name="value"`, or nothing when the value is null/undefined. Booleans render bare (`checked`). */
|
|
47
|
+
function attr(name, value) {
|
|
48
|
+
if (value === null || value === undefined || value === false) return '';
|
|
49
|
+
if (value === true) return ` ${name}`;
|
|
50
|
+
return ` ${name}="${escapeHtml(value)}"`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The attributes every command-carrying element shares. */
|
|
54
|
+
function common(d) {
|
|
55
|
+
return attr('data-command-id', d.cmd) + attr('id', d.el) + attr('data-tip', d.tip)
|
|
56
|
+
+ attr('data-model-control', d.semantic);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Common model controls have one icon source. Adapters choose capabilities and commands; they do
|
|
61
|
+
* not draw a second projection cube or a slightly different eye. These are the glyphs captured from
|
|
62
|
+
* the pinned master model toolbar, expressed as inert SVG strings so the static command guards still
|
|
63
|
+
* inspect the complete rendered toolbar.
|
|
64
|
+
*/
|
|
65
|
+
const ICON = Object.freeze({
|
|
66
|
+
'model.projection': '<svg viewBox="0 0 16 16" aria-hidden="true" data-for="persp"><path d="M2.2 5.6h8.4v8.4H2.2z"/><path d="M9 3.2h4.6v4.6"/><path d="M2.2 5.6 9 3.2M10.6 5.6 13.6 3.2M10.6 14l3-6.2"/></svg><svg viewBox="0 0 16 16" aria-hidden="true" data-for="ortho"><path d="M2.2 6.4h7.4v7.4H2.2z"/><path d="M6 2.6h7.4V10"/><path d="M2.2 6.4 6 2.6M9.6 6.4 13.4 2.6M9.6 13.8 13.4 10"/></svg>',
|
|
67
|
+
'model.fit': '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 6V2h4M14 6V2h-4M2 10v4h4M14 10v4h-4"/></svg>',
|
|
68
|
+
'model.fit-selection': '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2 5.5V2h3.5M14 5.5V2h-3.5M2 10.5V14h3.5M14 10.5V14h-3.5"/><path d="M5.9 6.3h4.2v3.4H5.9z"/></svg>',
|
|
69
|
+
'model.display-mode': '<svg viewBox="0 0 16 16" aria-hidden="true" data-for="solid"><circle cx="8" cy="8" r="5.6" fill="currentColor" stroke="none"/></svg><svg viewBox="0 0 16 16" aria-hidden="true" data-for="wire"><circle cx="8" cy="8" r="5.7" stroke-width="1.05"/></svg><svg viewBox="0 0 16 16" aria-hidden="true" data-for="xray"><circle cx="8" cy="8" r="6.9" stroke-width="1.1"/><path d="M9.2 10.08A2.4 2.4 0 0 1 6.8 10.08L5.45 12.42A5.1 5.1 0 0 0 10.55 12.42Z" fill="currentColor" stroke="none"/><path d="M5.6 8A2.4 2.4 0 0 1 6.8 5.92L5.45 3.58A5.1 5.1 0 0 0 2.9 8Z" fill="currentColor" stroke="none"/><path d="M9.2 5.92A2.4 2.4 0 0 1 10.4 8L13.1 8A5.1 5.1 0 0 0 10.55 3.58Z" fill="currentColor" stroke="none"/><circle cx="8" cy="8" r="1.6" fill="currentColor" stroke="none"/></svg><svg viewBox="0 0 16 16" aria-hidden="true" data-for="realistic"><defs><radialGradient id="m3dSphere" cx="34%" cy="30%" r="78%"><stop offset="0" stop-color="currentColor" stop-opacity=".95"/><stop offset="1" stop-color="currentColor" stop-opacity=".15"/></radialGradient></defs><circle cx="8" cy="8" r="5.6" fill="url(#m3dSphere)" stroke="currentColor" stroke-width="1.3"/></svg><svg viewBox="0 0 16 16" aria-hidden="true" data-for="shadowed"><circle cx="8" cy="6.4" r="4.5" fill="currentColor" stroke="none"/><ellipse cx="8" cy="13.2" rx="5" ry="1.2" fill="currentColor" stroke="none" opacity=".45"/></svg>',
|
|
70
|
+
'model.visibility': '<svg viewBox="0 0 16 16" aria-hidden="true" data-iso="off"><path d="M1.6 8S4 3.6 8 3.6 14.4 8 14.4 8 12 12.4 8 12.4 1.6 8 1.6 8z"/><circle cx="8" cy="8" r="1.8"/></svg><svg viewBox="0 0 16 16" aria-hidden="true" data-iso="on"><path d="M1.6 8S4 3.6 8 3.6 14.4 8 14.4 8 12 12.4 8 12.4 1.6 8 1.6 8z"/><circle cx="8" cy="8" r="1.8"/><path d="M2.6 13.4 13.4 2.6" stroke-width="1.5"/></svg>',
|
|
71
|
+
'model.saved-views': '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2.2 3.2h11.6v9.6H2.2z"/><path d="m4.4 10 2.2-2.2 1.7 1.5 2.3-2.7 1.2 1.3"/><circle cx="5.2" cy="5.7" r=".8"/></svg>',
|
|
72
|
+
'model.clip': '<svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="4" cy="12.1" r="1.9"/><circle cx="12" cy="12.1" r="1.9"/><path d="M5.4 10.7 12.6 2.5M10.6 10.7 3.4 2.5"/></svg>',
|
|
73
|
+
'model.work-plane': '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M1.6 11.6 5.8 5.4h8.6l-4.2 6.2z"/></svg>',
|
|
74
|
+
'model.work-area': '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="m8 2.1 5.4 2.8v6.2L8 13.9l-5.4-2.8V4.9zM2.6 4.9 8 7.7l5.4-2.8M8 7.7v6.2" stroke-dasharray="3 2"/></svg>',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export function modelToolbarIcon(semantic) { return ICON[semantic] ?? ''; }
|
|
78
|
+
|
|
79
|
+
/** `style="display:none"` for a control that is hidden until something makes it relevant. */
|
|
80
|
+
const hidden = (on) => (on ? ' style="display:none"' : '');
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* THE ITEM VOCABULARY. These are the small set of shapes the live bar
|
|
84
|
+
* already contains. A generic renderer that could express anything would need a template language;
|
|
85
|
+
* one that can express exactly what this product has needs a list this short.
|
|
86
|
+
*/
|
|
87
|
+
const ITEM = {
|
|
88
|
+
/** A plain menu row. */
|
|
89
|
+
item: (d) => `<button${common(d)}${attr('class', d.class)}${attr('role', d.role)}`
|
|
90
|
+
// `aria-checked` only where the item DECLARED itself a radio. An exclusive choice whose active
|
|
91
|
+
// state lives in a CSS `::after` tick announces nothing at all to a screen reader, which is what
|
|
92
|
+
// this fixes; putting it on a plain action row instead would announce a state that has no meaning.
|
|
93
|
+
+ (d.role === 'menuitemradio' ? attr('aria-checked', String(d.checked === true)) : '')
|
|
94
|
+
+ Object.entries(d.data ?? {}).map(([k, v]) => attr(k, v)).join('')
|
|
95
|
+
+ `${hidden(d.hidden)}>${escapeHtml(d.label)}</button>`,
|
|
96
|
+
|
|
97
|
+
/** A rule between rows. `data-vis-divider` is toggled with the Show-all item above it. */
|
|
98
|
+
// `role` is for a rule that must NOT split a menu's radios into two announced sets (`role=none`).
|
|
99
|
+
divider: (d) => `<hr${attr('role', d.role)}${attr(d.mark, d.mark ? true : null)}${hidden(d.hidden)}>`,
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* A checkbox row. The command id sits on the LABEL, not on the input it wraps: the inventory reads
|
|
103
|
+
* the element the id is on, and a bare checkbox announces nothing while the words a user reads live
|
|
104
|
+
* on the label. Same reasoning as the Drawing Filter's match-on rows (#779).
|
|
105
|
+
*/
|
|
106
|
+
checkbox: (d) => `<label${attr('data-command-id', d.cmd)}${attr('data-tip', d.tip)}>`
|
|
107
|
+
+ `<input type="checkbox"${attr('id', d.el)}${attr('checked', d.checked === true)}> ${escapeHtml(d.label)}</label>`,
|
|
108
|
+
|
|
109
|
+
/** A checkable row that stays open when clicked, so the state flip is visible. */
|
|
110
|
+
toggle: (d) => `<button${common(d)} class="wtog" role="menuitemcheckbox"`
|
|
111
|
+
+ attr('aria-checked', String(d.checked === true))
|
|
112
|
+
+ attr('aria-label', d.ariaLabel)
|
|
113
|
+
+ Object.entries(d.data ?? {}).map(([k, v]) => attr(k, v)).join('') + hidden(d.hidden)
|
|
114
|
+
+ `><span class="mck" aria-hidden="true"></span>${escapeHtml(d.label)}</button>`,
|
|
115
|
+
|
|
116
|
+
/** A disclosure row used when a menu owns a secondary group of settings. */
|
|
117
|
+
disclosure: (d) => `<button${common(d)}${attr('class', d.class)} aria-expanded="false"`
|
|
118
|
+
+ attr('aria-controls', d.controls)
|
|
119
|
+
+ `>${escapeHtml(d.label)}<span class="pl-chevron" aria-hidden="true">▸</span></button>`,
|
|
120
|
+
|
|
121
|
+
/** Read-only context beneath a disclosure. */
|
|
122
|
+
context: (d) => `<div${attr('id', d.el)}${attr('class', d.class)}></div>`,
|
|
123
|
+
|
|
124
|
+
/** A nested group whose visibility is controlled by a disclosure. */
|
|
125
|
+
scope: (d) => `<div${attr('id', d.el)}${attr('class', d.class)}${attr('data-reveal-by', d.revealBy ? `#${d.revealBy}` : null)}${attr('hidden', d.hidden)}`
|
|
126
|
+
+ `>${d.items.map(renderItem).join('')}</div>`,
|
|
127
|
+
|
|
128
|
+
/** Dynamic explanatory text inside a nested menu group. */
|
|
129
|
+
note: (d) => `<div${attr('id', d.el)}${attr('class', d.class)}></div>`,
|
|
130
|
+
|
|
131
|
+
/** A semantic section inside a menu. */
|
|
132
|
+
section: (d) => `<div${attr('id', d.el)}${attr('class', d.class)}>`
|
|
133
|
+
+ `${d.items.map(renderItem).join('')}</div>`,
|
|
134
|
+
|
|
135
|
+
/** A section caption inside a menu. Carries no command — it is not a control. */
|
|
136
|
+
label: (d) => `<div class="mlabel">${escapeHtml(d.text)}</div>`,
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
* A container row of small controls — a principal-plane picker, a pair of bulk actions.
|
|
140
|
+
*
|
|
141
|
+
* The CLASS comes from the caller rather than being fixed here, and that is the seam: a shared
|
|
142
|
+
* renderer that knew the name `wpprow` would have learned a working-plane concept. It knows
|
|
143
|
+
* "some rows group their children"; the module names them.
|
|
144
|
+
*/
|
|
145
|
+
row: (d) => `<div${attr('id', d.el)}${attr('class', d.class)}>${d.items.map(renderItem).join('')}</div>`,
|
|
146
|
+
|
|
147
|
+
/** A free-text field inside a menu. */
|
|
148
|
+
input: (d) => `<input${attr('data-command-id', d.cmd)}${attr('aria-label', d.ariaLabel)}${attr('id', d.el)}`
|
|
149
|
+
+ attr('inputmode', d.inputmode) + attr('placeholder', d.placeholder) + ' autocomplete="off"'
|
|
150
|
+
+ attr('data-tip', d.tip) + '>',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
function renderItem(d) {
|
|
154
|
+
const fn = ITEM[d.kind];
|
|
155
|
+
if (!fn) {
|
|
156
|
+
throw new Error(`model-viewport-toolbar: no item kind "${d.kind}". The vocabulary is `
|
|
157
|
+
+ `${Object.keys(ITEM).join(', ')} — add a kind deliberately rather than emitting raw markup.`);
|
|
158
|
+
}
|
|
159
|
+
return fn(d);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A top-level control: a bare button, or a trigger plus the menu it opens. */
|
|
163
|
+
function renderControl(d) {
|
|
164
|
+
const text = String(d.label ?? '').replace(/\s*[▾▼]\s*$/, '');
|
|
165
|
+
const icon = d.icon ?? modelToolbarIcon(d.semantic);
|
|
166
|
+
const contents = icon ? `${icon}<span class="rlbl">${escapeHtml(text)}</span>` : escapeHtml(d.label);
|
|
167
|
+
const trigger = `<button${common(d)}`
|
|
168
|
+
+ Object.entries(d.data ?? {}).map(([k, v]) => attr(k, v)).join('')
|
|
169
|
+
+ (d.aria ? ` aria-haspopup="menu"${attr('aria-controls', d.menu)} aria-expanded="false"` : '')
|
|
170
|
+
+ (d.minWidth ? attr('style', `min-width:${d.minWidth}`) : '')
|
|
171
|
+
+ `>${contents}</button>`;
|
|
172
|
+
if (d.kind !== 'menu') return trigger;
|
|
173
|
+
// `data-reveal-by` names the trigger that opens this menu, so the Instructor can reveal a command inside a
|
|
174
|
+
// closed menu before focusing it (#1199). Every menu here is opened by its own trigger, so it is derived.
|
|
175
|
+
const menu = `<div${attr('id', d.menu)} class="m3dmenu" role="menu"${attr('data-reveal-by', d.el ? `#${d.el}` : null)}>${(d.items ?? []).map(renderItem).join('')}</div>`;
|
|
176
|
+
return `<div class="m3dwrap"${attr('id', d.wrap)}${hidden(d.wrapHidden)}>${trigger}${menu}</div>`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Render the bar's inner markup from a plan.
|
|
181
|
+
*
|
|
182
|
+
* `plan.clusters` is the output of `toolbarClusters()`: groups and module contributions in order,
|
|
183
|
+
* each saying whether a rule precedes it. Separators are GENERATED from that, never carried across
|
|
184
|
+
* as fixed elements — the page's three `<span class=tb-sep>` are hand-placed, so a provider that
|
|
185
|
+
* dropped the trailing group would have orphaned one against the end of the bar.
|
|
186
|
+
*/
|
|
187
|
+
export function renderToolbarMarkup(plan) {
|
|
188
|
+
const out = [];
|
|
189
|
+
for (const cluster of plan.clusters) {
|
|
190
|
+
if (cluster.separatorBefore) out.push('<span class="tb-sep"></span>');
|
|
191
|
+
for (const control of cluster.controls) out.push(renderControl(control));
|
|
192
|
+
}
|
|
193
|
+
return out.join('');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Every `data-command-id` the rendered bar will carry, in document order.
|
|
198
|
+
*
|
|
199
|
+
* Read back out of the MARKUP rather than recomputed from the plan, deliberately. Plan review caught
|
|
200
|
+
* the earlier design shipping two lists — a renderer taking caller-supplied ids beside a separately
|
|
201
|
+
* derived enumeration — which lets a guard validate one list while the page renders another. That is
|
|
202
|
+
* the drift `model-editor-contract.js` exists to prevent, so there is one artifact and both guards
|
|
203
|
+
* read it.
|
|
204
|
+
*/
|
|
205
|
+
/*
|
|
206
|
+
* The attribute name is a CONSTANT rather than a literal inside the pattern below, and that is not
|
|
207
|
+
* style. `verify-command-registry` greps every `web/*.js` for the carrier attribute followed by a
|
|
208
|
+
* quoted value and demands a registered command for whatever it captures — so a regex literal
|
|
209
|
+
* spelling the attribute out reads to the guard as a control declaration, and it fails on the
|
|
210
|
+
* capture group. Building the pattern from a constant keeps the guard strict instead of teaching it
|
|
211
|
+
* to ignore anything shaped like a regex, which is how a guard stops meaning anything.
|
|
212
|
+
*
|
|
213
|
+
* The guard scans RAW source, comments included, so prose here must not spell the attribute out
|
|
214
|
+
* either — this note says "the carrier attribute" for that reason, not out of coyness.
|
|
215
|
+
*/
|
|
216
|
+
const CARRIER_ATTR = 'data-command-id';
|
|
217
|
+
|
|
218
|
+
export function toolbarCarriers(plan) {
|
|
219
|
+
return [...renderToolbarMarkup(plan).matchAll(new RegExp(CARRIER_ATTR + '="([^"]+)"', 'g'))]
|
|
220
|
+
.map((m) => m[1].replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
221
|
+
.replace(/"/g, '"').replace(/'/g, "'").replace(/`/g, '`'));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* ───────────────────────────────────────────────────────────────────────────────────────────────
|
|
225
|
+
* TOOLBAR CHROME — the parts that need a live element rather than a string.
|
|
226
|
+
*
|
|
227
|
+
* The renderer above is deliberately DOM-free, which is what makes it testable in node and scannable
|
|
228
|
+
* by the static guards. But three things cannot be expressed in markup that is written once:
|
|
229
|
+
* `aria-expanded` has to track a menu that opens and closes, the roving tab stop has to follow focus,
|
|
230
|
+
* and both have to survive a control appearing or disappearing. So they mount over the rendered bar.
|
|
231
|
+
*
|
|
232
|
+
* WHY AN OBSERVER RATHER THAN TEN EDITS. A menu's open state is its `.open` class, set in seven
|
|
233
|
+
* separate closures in the page. Teaching each of them to also write `aria-expanded` is ten edits
|
|
234
|
+
* that the eleventh menu will forget. One rule that watches the class cannot drift, and it is less
|
|
235
|
+
* code than the edits it replaces.
|
|
236
|
+
*
|
|
237
|
+
* THE ITEM LIST IS RE-READ, NEVER CACHED. A module may reveal or hide a control as its own state
|
|
238
|
+
* changes - one of them appears only while something is selected - and a roving index into a stale
|
|
239
|
+
* list lands on a `display:none` element and loses focus silently.
|
|
240
|
+
* ─────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
241
|
+
|
|
242
|
+
/** The bar's top-level controls, in document order, skipping any that are currently not rendered. */
|
|
243
|
+
function defaultItems(toolbar) {
|
|
244
|
+
const out = [];
|
|
245
|
+
for (const child of toolbar.children) {
|
|
246
|
+
const el = child.tagName === 'BUTTON' ? child : child.querySelector(':scope > button');
|
|
247
|
+
// offsetParent is null for a display:none subtree — the honest "can the user reach this".
|
|
248
|
+
if (el && el.offsetParent !== null) out.push(el);
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Mount the live behaviour over a rendered toolbar. Returns `{ destroy() }`; call it and the bar is
|
|
255
|
+
* exactly as inert as it was before.
|
|
256
|
+
*
|
|
257
|
+
* `toolbar` is the container element. `getItems` may override which elements are the roving stops —
|
|
258
|
+
* it exists so a module with unusual chrome is not forced to fight the default, not because anything
|
|
259
|
+
* needs it today.
|
|
260
|
+
*/
|
|
261
|
+
/** @param {{ toolbar: any, getItems?: (toolbar: any) => any[], port?: any }} options */
|
|
262
|
+
export function mountToolbarChrome({ toolbar, getItems = defaultItems, port = null }) {
|
|
263
|
+
if (!toolbar) throw new Error('mountToolbarChrome: no toolbar element');
|
|
264
|
+
const doc = toolbar.ownerDocument ?? globalThis.document;
|
|
265
|
+
// The container's ROLE is not set here: the host owns the container (see this file's header), and a
|
|
266
|
+
// mount that rewrote it would be a second source for something that never changes.
|
|
267
|
+
|
|
268
|
+
/* aria-expanded follows the menu's own open class, for every menu, including the two that were
|
|
269
|
+
already maintaining it by hand — one rule beats seven, and the hand-written ones stay correct
|
|
270
|
+
because they set the same class this reads. */
|
|
271
|
+
const syncExpanded = () => {
|
|
272
|
+
for (const menu of toolbar.querySelectorAll('.m3dmenu')) {
|
|
273
|
+
const trigger = menu.parentElement && menu.parentElement.querySelector(':scope > button');
|
|
274
|
+
if (trigger && trigger.hasAttribute('aria-haspopup')) {
|
|
275
|
+
trigger.setAttribute('aria-expanded', String(menu.classList.contains('open')));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/* Every ordinary toolbar menu shares one lifecycle. Providers still decide what an item DOES, but
|
|
281
|
+
opening, outside dismissal, Escape, arrow movement and focus restoration cannot drift between
|
|
282
|
+
every model surface. Visibility is excluded because its live disabled rows need the richer state
|
|
283
|
+
machine below. */
|
|
284
|
+
const ordinaryMenus = [...toolbar.querySelectorAll('.m3dwrap > .m3dmenu')]
|
|
285
|
+
.filter((menu) => !menu.querySelector('[data-vis]'));
|
|
286
|
+
const menuTrigger = (menu) => menu.parentElement?.querySelector(':scope > button') ?? null;
|
|
287
|
+
const enabledMenuItems = (menu) => [...menu.querySelectorAll('button:not(:disabled),input:not(:disabled)')]
|
|
288
|
+
.filter((item) => item.offsetParent !== null);
|
|
289
|
+
const closeMenu = (menu, restoreFocus = false) => {
|
|
290
|
+
menu.classList.remove('open'); syncExpanded();
|
|
291
|
+
if (restoreFocus) menuTrigger(menu)?.focus();
|
|
292
|
+
};
|
|
293
|
+
const closeOrdinaryMenus = (except = null) => {
|
|
294
|
+
for (const menu of ordinaryMenus) if (menu !== except) closeMenu(menu);
|
|
295
|
+
};
|
|
296
|
+
const ordinaryCleanup = [];
|
|
297
|
+
const listenOrdinary = (target, type, listener) => {
|
|
298
|
+
target.addEventListener(type, listener);
|
|
299
|
+
ordinaryCleanup.push(() => target.removeEventListener(type, listener));
|
|
300
|
+
};
|
|
301
|
+
for (const menu of ordinaryMenus) {
|
|
302
|
+
const trigger = menuTrigger(menu);
|
|
303
|
+
if (!trigger) continue;
|
|
304
|
+
listenOrdinary(trigger, 'click', (event) => {
|
|
305
|
+
event.stopPropagation();
|
|
306
|
+
const opening = !menu.classList.contains('open');
|
|
307
|
+
closeOrdinaryMenus(menu); menu.classList.toggle('open', opening); syncExpanded();
|
|
308
|
+
});
|
|
309
|
+
listenOrdinary(trigger, 'keydown', (event) => {
|
|
310
|
+
if (event.key === 'Escape' && menu.classList.contains('open')) {
|
|
311
|
+
event.preventDefault(); event.stopPropagation(); closeMenu(menu, true); return;
|
|
312
|
+
}
|
|
313
|
+
if (!['ArrowDown', 'Enter', ' '].includes(event.key)) return;
|
|
314
|
+
event.preventDefault(); event.stopPropagation();
|
|
315
|
+
if (!menu.classList.contains('open')) { closeOrdinaryMenus(menu); menu.classList.add('open'); syncExpanded(); }
|
|
316
|
+
enabledMenuItems(menu)[0]?.focus();
|
|
317
|
+
});
|
|
318
|
+
listenOrdinary(menu, 'keydown', (event) => {
|
|
319
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeMenu(menu, true); return; }
|
|
320
|
+
const items = enabledMenuItems(menu); const at = items.indexOf(event.target); if (at < 0) return;
|
|
321
|
+
let next = null;
|
|
322
|
+
if (event.key === 'ArrowDown') next = (at + 1) % items.length;
|
|
323
|
+
else if (event.key === 'ArrowUp') next = (at - 1 + items.length) % items.length;
|
|
324
|
+
else if (event.key === 'Home') next = 0;
|
|
325
|
+
else if (event.key === 'End') next = items.length - 1;
|
|
326
|
+
if (next === null) return;
|
|
327
|
+
event.preventDefault(); event.stopPropagation(); items[next]?.focus();
|
|
328
|
+
});
|
|
329
|
+
listenOrdinary(menu, 'click', (event) => {
|
|
330
|
+
const item = event.target.closest('button');
|
|
331
|
+
if (!item || item.classList.contains('wtog') || item.classList.contains('pl-disclosure')) return;
|
|
332
|
+
// A click that REFUSED its input and put focus back on a field of this menu (an unreadable offset,
|
|
333
|
+
// say) is asking for a correction: closing now would hide the field it just marked.
|
|
334
|
+
const active = doc.activeElement;
|
|
335
|
+
if (active && active !== item && active.tagName === 'INPUT' && menu.contains(active)) return;
|
|
336
|
+
closeMenu(menu);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
const onOrdinaryOutside = (event) => {
|
|
340
|
+
for (const menu of ordinaryMenus) {
|
|
341
|
+
const trigger = menuTrigger(menu);
|
|
342
|
+
if (menu.classList.contains('open') && !menu.contains(event.target) && event.target !== trigger) closeMenu(menu);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
doc.addEventListener('mousedown', onOrdinaryOutside, true);
|
|
346
|
+
|
|
347
|
+
/* ONE tab stop for the whole bar. Which control holds it follows focus, so tabbing back in returns
|
|
348
|
+
to where the user was rather than to the start. */
|
|
349
|
+
let rovingAt = 0;
|
|
350
|
+
const applyRoving = () => {
|
|
351
|
+
const items = getItems(toolbar);
|
|
352
|
+
if (!items.length) return;
|
|
353
|
+
if (rovingAt >= items.length) rovingAt = 0;
|
|
354
|
+
items.forEach((el, i) => el.setAttribute('tabindex', i === rovingAt ? '0' : '-1'));
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Visibility is the one common menu whose rows change with live provider state. Its interaction
|
|
358
|
+
// belongs here so providers cannot drift into different click, keyboard, or focus rules.
|
|
359
|
+
const visibilityMenu = [...toolbar.querySelectorAll('.m3dmenu')].find((menu) => menu.querySelector('[data-vis="ghost"]')) ?? null;
|
|
360
|
+
const visibilityTrigger = visibilityMenu?.parentElement?.querySelector(':scope > button') ?? null;
|
|
361
|
+
const visibilityItems = () => visibilityMenu
|
|
362
|
+
? [...visibilityMenu.querySelectorAll('[data-vis]')].filter((item) => item.offsetParent !== null && !item.disabled)
|
|
363
|
+
: [];
|
|
364
|
+
const closeVisibility = (restoreFocus = false) => {
|
|
365
|
+
if (!visibilityMenu) return;
|
|
366
|
+
visibilityMenu.classList.remove('open'); syncExpanded();
|
|
367
|
+
if (restoreFocus) visibilityTrigger?.focus();
|
|
368
|
+
};
|
|
369
|
+
const openVisibility = () => {
|
|
370
|
+
if (!visibilityMenu) return;
|
|
371
|
+
visibilityMenu.classList.add('open'); syncExpanded();
|
|
372
|
+
visibilityItems()[0]?.focus();
|
|
373
|
+
};
|
|
374
|
+
const syncVisibility = (next = port?.getState?.()) => {
|
|
375
|
+
if (!visibilityMenu || !next) return;
|
|
376
|
+
const actionable = next.actionableVisibilitySelectionCount > 0;
|
|
377
|
+
const treated = next.hasVisibilityFilter === true || next.ghostUnselected === true;
|
|
378
|
+
const show = visibilityMenu.querySelector('[data-vis="show-all"]');
|
|
379
|
+
const divider = visibilityMenu.querySelector('[data-vis-divider]') ?? show?.nextElementSibling;
|
|
380
|
+
const isolate = visibilityMenu.querySelector('[data-vis="isolate"]');
|
|
381
|
+
const ghost = visibilityMenu.querySelector('[data-vis="ghost"]');
|
|
382
|
+
const hide = visibilityMenu.querySelector('[data-vis="hide"]');
|
|
383
|
+
const block = (item, disabled, reason) => {
|
|
384
|
+
if (!item) return;
|
|
385
|
+
item.disabled = disabled;
|
|
386
|
+
if (disabled) item.dataset.blockedReason = reason;
|
|
387
|
+
else delete item.dataset.blockedReason;
|
|
388
|
+
};
|
|
389
|
+
block(show, !treated, 'Nothing is hidden');
|
|
390
|
+
block(isolate, !actionable, 'Select objects first');
|
|
391
|
+
block(hide, !actionable, 'Select objects first');
|
|
392
|
+
if (show) show.style.display = '';
|
|
393
|
+
if (divider) divider.style.display = '';
|
|
394
|
+
if (ghost) {
|
|
395
|
+
ghost.classList.toggle('on', next.ghostUnselected === true);
|
|
396
|
+
ghost.setAttribute('aria-checked', String(next.ghostUnselected === true));
|
|
397
|
+
}
|
|
398
|
+
// Standing state is the corner dot, never the armed highlight: that one means "a click cancels a pick" (#1403).
|
|
399
|
+
visibilityTrigger?.toggleAttribute('data-state-on', treated);
|
|
400
|
+
const active = doc.activeElement;
|
|
401
|
+
if (active && visibilityMenu.contains(active) && (active.offsetParent === null || active.disabled)) {
|
|
402
|
+
(ghost?.offsetParent !== null ? ghost : visibilityTrigger)?.focus();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const onVisibilityTriggerClick = (event) => {
|
|
407
|
+
if (!visibilityMenu) return;
|
|
408
|
+
event.stopPropagation();
|
|
409
|
+
if (visibilityMenu.classList.contains('open')) closeVisibility(); else { syncVisibility(); openVisibility(); }
|
|
410
|
+
};
|
|
411
|
+
const onVisibilityTriggerKey = (event) => {
|
|
412
|
+
if (!visibilityMenu) return;
|
|
413
|
+
if (event.key === 'Escape' && visibilityMenu.classList.contains('open')) {
|
|
414
|
+
event.preventDefault(); event.stopPropagation(); closeVisibility(true); return;
|
|
415
|
+
}
|
|
416
|
+
if (!['ArrowDown', 'Enter', ' '].includes(event.key)) return;
|
|
417
|
+
event.preventDefault(); event.stopPropagation();
|
|
418
|
+
if (!visibilityMenu.classList.contains('open')) { syncVisibility(); openVisibility(); }
|
|
419
|
+
else visibilityItems()[0]?.focus();
|
|
420
|
+
};
|
|
421
|
+
const activateVisibility = (item) => {
|
|
422
|
+
if (item?.disabled) return;
|
|
423
|
+
const action = item?.dataset?.vis;
|
|
424
|
+
const command = action === 'show-all' ? 'model.show-all'
|
|
425
|
+
: action === 'isolate' ? 'model.isolate'
|
|
426
|
+
: action === 'ghost' ? 'model.ghost-unselected'
|
|
427
|
+
: action === 'hide' ? 'model.hide-selected' : null;
|
|
428
|
+
if (!command) return;
|
|
429
|
+
port?.dispatch?.(command);
|
|
430
|
+
if (action === 'ghost') { syncVisibility(); item.focus(); }
|
|
431
|
+
else closeVisibility(true);
|
|
432
|
+
};
|
|
433
|
+
const onVisibilityMenuClick = (event) => {
|
|
434
|
+
const item = event.target.closest('[data-vis]');
|
|
435
|
+
if (!item || item.offsetParent === null) return;
|
|
436
|
+
event.preventDefault(); event.stopPropagation(); activateVisibility(item);
|
|
437
|
+
};
|
|
438
|
+
const onVisibilityMenuKey = (event) => {
|
|
439
|
+
const items = visibilityItems(); const at = items.indexOf(event.target);
|
|
440
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeVisibility(true); return; }
|
|
441
|
+
if (at < 0) return;
|
|
442
|
+
let next = null;
|
|
443
|
+
if (event.key === 'ArrowDown') next = (at + 1) % items.length;
|
|
444
|
+
else if (event.key === 'ArrowUp') next = (at - 1 + items.length) % items.length;
|
|
445
|
+
else if (event.key === 'Home') next = 0;
|
|
446
|
+
else if (event.key === 'End') next = items.length - 1;
|
|
447
|
+
else if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); event.stopPropagation(); activateVisibility(event.target); return; }
|
|
448
|
+
if (next === null) return;
|
|
449
|
+
event.preventDefault(); event.stopPropagation(); items[next]?.focus();
|
|
450
|
+
};
|
|
451
|
+
const onVisibilityOutside = (event) => {
|
|
452
|
+
if (visibilityMenu?.classList.contains('open') && !visibilityMenu.contains(event.target) && event.target !== visibilityTrigger) closeVisibility();
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const onFocusIn = (e) => {
|
|
456
|
+
const items = getItems(toolbar);
|
|
457
|
+
const i = items.indexOf(e.target);
|
|
458
|
+
if (i >= 0) { rovingAt = i; applyRoving(); }
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const onKeyDown = (e) => {
|
|
462
|
+
// Inside an open menu the menu owns the keys: Up/Down move between its items and Escape closes
|
|
463
|
+
// it. Taking Left/Right here would be fine, but taking anything while focus is in the offset
|
|
464
|
+
// INPUT would eat the user's cursor keys mid-edit.
|
|
465
|
+
if (e.target.closest('.m3dmenu')) return;
|
|
466
|
+
const items = getItems(toolbar);
|
|
467
|
+
const at = items.indexOf(e.target);
|
|
468
|
+
if (at < 0) return;
|
|
469
|
+
const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;
|
|
470
|
+
let next = null;
|
|
471
|
+
if (step) next = (at + step + items.length) % items.length;
|
|
472
|
+
else if (e.key === 'Home') next = 0;
|
|
473
|
+
else if (e.key === 'End') next = items.length - 1;
|
|
474
|
+
if (next === null) return;
|
|
475
|
+
e.preventDefault();
|
|
476
|
+
e.stopPropagation(); // a host may bind arrow keys globally too; without this the camera pans as well
|
|
477
|
+
rovingAt = next;
|
|
478
|
+
applyRoving();
|
|
479
|
+
items[next].focus();
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const observer = typeof MutationObserver === 'undefined' ? null : new MutationObserver(() => { syncExpanded(); applyRoving(); });
|
|
483
|
+
if (observer) observer.observe(toolbar, { subtree: true, attributes: true, attributeFilter: ['class', 'style'] });
|
|
484
|
+
toolbar.addEventListener('focusin', onFocusIn);
|
|
485
|
+
toolbar.addEventListener('keydown', onKeyDown);
|
|
486
|
+
visibilityTrigger?.addEventListener('click', onVisibilityTriggerClick);
|
|
487
|
+
visibilityTrigger?.addEventListener('keydown', onVisibilityTriggerKey);
|
|
488
|
+
visibilityMenu?.addEventListener('click', onVisibilityMenuClick);
|
|
489
|
+
visibilityMenu?.addEventListener('keydown', onVisibilityMenuKey);
|
|
490
|
+
doc.addEventListener('mousedown', onVisibilityOutside, true);
|
|
491
|
+
let releaseVisibility = null;
|
|
492
|
+
if (visibilityMenu && port) {
|
|
493
|
+
for (const method of ['dispatch', 'getState', 'subscribe']) if (typeof port[method] !== 'function') throw new TypeError(`mountToolbarChrome: visibility port needs ${method}()`);
|
|
494
|
+
releaseVisibility = port.subscribe(syncVisibility);
|
|
495
|
+
}
|
|
496
|
+
syncExpanded();
|
|
497
|
+
applyRoving();
|
|
498
|
+
syncVisibility();
|
|
499
|
+
|
|
500
|
+
return {
|
|
501
|
+
destroy() {
|
|
502
|
+
if (observer) observer.disconnect();
|
|
503
|
+
toolbar.removeEventListener('focusin', onFocusIn);
|
|
504
|
+
toolbar.removeEventListener('keydown', onKeyDown);
|
|
505
|
+
visibilityTrigger?.removeEventListener('click', onVisibilityTriggerClick);
|
|
506
|
+
visibilityTrigger?.removeEventListener('keydown', onVisibilityTriggerKey);
|
|
507
|
+
visibilityMenu?.removeEventListener('click', onVisibilityMenuClick);
|
|
508
|
+
visibilityMenu?.removeEventListener('keydown', onVisibilityMenuKey);
|
|
509
|
+
doc.removeEventListener('mousedown', onVisibilityOutside, true);
|
|
510
|
+
doc.removeEventListener('mousedown', onOrdinaryOutside, true);
|
|
511
|
+
while (ordinaryCleanup.length) ordinaryCleanup.pop()();
|
|
512
|
+
releaseVisibility?.(); releaseVisibility = null;
|
|
513
|
+
for (const el of getItems(toolbar)) el.removeAttribute('tabindex');
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
}
|