@floless/app 0.140.0 → 0.141.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.
@@ -0,0 +1,87 @@
1
+ import { FACET_DIMS, MODE_ORDER, canonicalMode, facetKey } from './steel-filter-core.js';
2
+
3
+ /** A not-read layer has no lines behind its checkbox, even if a duplicate row has the same key. */
4
+ export function filterAiBlockedLayerKeys(filter) {
5
+ const blocked = new Set();
6
+ for (const row of filter.layers || []) {
7
+ if (row.notRead !== true) continue;
8
+ const key = facetKey('layer', row.name);
9
+ if (key !== undefined) blocked.add(key);
10
+ }
11
+ return blocked;
12
+ }
13
+
14
+ export function filterAiTouchesUnreadLayer(proposal, filter) {
15
+ const blocked = filterAiBlockedLayerKeys(filter);
16
+ return (proposal.changes || []).some(item => item.dimension === 'layer'
17
+ && blocked.has(facetKey('layer', item.value)));
18
+ }
19
+
20
+ /** Reject malformed or contradictory suggestions before any surface presents them. */
21
+ export function parseFilterAiProposalShape(answer) {
22
+ if (typeof answer !== 'string' || answer.length > 8_000) throw new Error('AI returned a suggestion that is too large. Ask about fewer layers.');
23
+ let value;
24
+ try { value = JSON.parse(answer); }
25
+ catch { throw new Error('AI did not return a usable selection. Ask it to try again.'); }
26
+ if (!value || Array.isArray(value) || typeof value !== 'object'
27
+ || Object.keys(value).sort().join(',') !== 'changes,explanation,mode'
28
+ || typeof value.explanation !== 'string' || !value.explanation.trim() || value.explanation.length > 500
29
+ || !Array.isArray(value.changes) || value.changes.length > 30
30
+ || (value.mode !== null && (typeof value.mode !== 'string'
31
+ || !value.mode || value.mode !== canonicalMode(value.mode.split('+'))))) {
32
+ throw new Error('AI returned a suggestion this filter cannot use. Ask it to try again.');
33
+ }
34
+ const seen = new Set();
35
+ for (const item of value.changes) {
36
+ if (!item || Array.isArray(item) || typeof item !== 'object'
37
+ || Object.keys(item).sort().join(',') !== 'dimension,on,value'
38
+ || !MODE_ORDER.includes(item.dimension) || typeof item.on !== 'boolean') {
39
+ throw new Error('AI named a change this filter cannot use. Ask it to try again.');
40
+ }
41
+ if (item.dimension === 'thickness' && (typeof item.value !== 'number' || !Number.isFinite(item.value))) {
42
+ throw new Error('AI named a value that is missing from this filter. Ask it to try again.');
43
+ }
44
+ if (item.dimension !== 'thickness' && typeof item.value !== 'string') {
45
+ throw new Error('AI named a value that is missing from this filter. Ask it to try again.');
46
+ }
47
+ const key = item.value;
48
+ const canonical = facetKey(item.dimension, key);
49
+ const identity = item.dimension + '\0' + String(canonical);
50
+ if (canonical === undefined || seen.has(identity)) {
51
+ throw new Error('AI named a value that is missing from this filter. Ask it to try again.');
52
+ }
53
+ seen.add(identity);
54
+ }
55
+ return { explanation:value.explanation.trim(), changes:value.changes, mode:value.mode };
56
+ }
57
+
58
+ /**
59
+ * Accept only control values present in this filter and shown to this AI request.
60
+ * @param {string} answer
61
+ * @param {{ layers?: Array<{name:string}>, thicknesses?: Array<{w:number}>, colors?: Array<{hex:string}> }} filter
62
+ * @param {Set<string> | null} allowedControls
63
+ */
64
+ export function parseFilterAiProposal(answer, filter, allowedControls = null) {
65
+ const value = parseFilterAiProposalShape(answer);
66
+ const known = new Map();
67
+ const blockedLayers = filterAiBlockedLayerKeys(filter);
68
+ for (const dim of MODE_ORDER) {
69
+ const descriptor = FACET_DIMS[dim];
70
+ for (const row of filter[descriptor.control] || []) {
71
+ const key = facetKey(dim, row[descriptor.rowKey]);
72
+ if (key === undefined) continue;
73
+ if (dim === 'layer' && blockedLayers.has(key)) continue;
74
+ known.set(dim + '\0' + String(key), key);
75
+ }
76
+ }
77
+ const changes = [];
78
+ for (const item of value.changes) {
79
+ const canonical = facetKey(item.dimension, item.value);
80
+ const identity = item.dimension + '\0' + String(canonical);
81
+ if (!known.has(identity) || (allowedControls && !allowedControls.has(identity))) {
82
+ throw new Error('AI named a value that is missing from this filter. Ask it to try again.');
83
+ }
84
+ changes.push({ dimension:item.dimension, value:known.get(identity), on:item.on });
85
+ }
86
+ return { explanation:value.explanation, changes, mode:value.mode };
87
+ }
@@ -0,0 +1,8 @@
1
+ /* Shared front-door wording for the Drawing Filter and its review checkpoint. */
2
+ (function (root) {
3
+ 'use strict';
4
+ root.FilterGuidance = Object.freeze({
5
+ scope: 'Select steel plus the clues needed to read it: member marks, grids, dimensions, and relevant detail callouts.',
6
+ canvas: 'Bright items may be used in the read. The dim drawing is context only.',
7
+ });
8
+ })(window);
@@ -154,16 +154,10 @@
154
154
  <button type="button" class="left-section-close" data-left-section-close="narrative" data-command-id="shell.left-section#AI Chat" data-command-instance-label="AI Chat" aria-label="Hide AI Chat" data-tip="Hide AI Chat">×</button>
155
155
  </header>
156
156
  <div class="left-section-body narrative-section-body">
157
- <div class="ai-chat-controls" role="toolbar" aria-label="Chat controls">
157
+ <div class="ai-chat-controls">
158
158
  <span class="narrative-tabs" role="tablist" aria-label="AI Chat content">
159
159
  <button data-command-id="shell.narrative-tab" type="button" class="narrative-tab active sr-only" id="narrative-tab" role="tab" aria-selected="true" aria-controls="messages">Chat <span class="answer-unread" id="chat-unread" hidden></span></button>
160
160
  </span>
161
- <span class="ai-chat-tab-actions">
162
- <button data-command-id="shell.chat-history" type="button" class="ai-chat-icon" id="chat-history-toggle" aria-expanded="false" aria-controls="chat-history" data-tip="Conversation history" aria-label="Conversation history">☷</button>
163
- <button data-command-id="shell.chat-new" type="button" class="ai-chat-icon" id="chat-new" data-tip="New conversation" aria-label="New conversation">+</button>
164
- <button data-command-id="shell.chat-refresh" type="button" class="ai-chat-icon" id="chat-refresh" data-tip="Refresh this chat session" aria-label="Refresh this chat session">↻</button>
165
- <button data-command-id="shell.chat-settings" type="button" class="ai-chat-icon" id="chat-settings-toggle" aria-expanded="false" aria-controls="chat-settings" data-tip="Chat settings" aria-label="Chat settings">⚙</button>
166
- </span>
167
161
  </div>
168
162
  <div class="messages ai-chat-host" id="messages" role="tabpanel" aria-labelledby="narrative-tab">
169
163
  <section class="ai-chat-shell" id="ai-chat-shell" aria-label="AI Chat">
@@ -172,6 +166,13 @@
172
166
  <div class="ai-chat-title-line"><strong id="chat-title">AI Chat</strong><button data-command-id="shell.chat-rename" type="button" class="ai-chat-rename" id="chat-rename" aria-label="Rename conversation" data-tip="Rename conversation">✎</button></div>
173
167
  <span id="chat-scope">Open a project or workflow</span>
174
168
  </div>
169
+ <!-- One header row: the conversation's name on the left, its controls on the right. -->
170
+ <span class="ai-chat-tab-actions" role="toolbar" aria-label="Chat controls">
171
+ <button data-command-id="shell.chat-history" type="button" class="ai-chat-icon" id="chat-history-toggle" aria-expanded="false" aria-controls="chat-history" data-tip="Conversation history" aria-label="Conversation history">☷</button>
172
+ <button data-command-id="shell.chat-new" type="button" class="ai-chat-icon" id="chat-new" data-tip="New conversation" aria-label="New conversation">+</button>
173
+ <button data-command-id="shell.chat-refresh" type="button" class="ai-chat-icon" id="chat-refresh" data-tip="Refresh this chat session" aria-label="Refresh this chat session">↻</button>
174
+ <button data-command-id="shell.chat-settings" type="button" class="ai-chat-icon" id="chat-settings-toggle" aria-expanded="false" aria-controls="chat-settings" data-tip="Chat settings" aria-label="Chat settings">⚙</button>
175
+ </span>
175
176
  </div>
176
177
  <div class="ai-chat-settings" id="chat-settings" hidden>
177
178
  <div class="ai-chat-setting ai-chat-provider" id="chat-provider" data-tip="FloLess uses whichever account is signed in to the Claude Code or Codex CLI on this computer. Signing in to the Claude desktop app or claude.ai does not change it. Switch account signs that CLI out first, then opens a window where you sign in."><span>Provider</span><strong aria-live="polite">—</strong><button data-command-id="shell.chat-switch-account" type="button" class="ai-chat-provider-switch" id="chat-switch-account" hidden>Switch account…</button></div>
@@ -188,6 +189,9 @@
188
189
  <div class="ai-chat-picker" id="chat-picker" role="listbox" hidden></div>
189
190
  <div class="ai-chat-history" id="chat-history" hidden aria-label="Conversation history"></div>
190
191
  <div class="ai-chat-feed" id="chat-feed" tabindex="-1"></div>
192
+ <div class="ai-chat-offscreen-activity" id="chat-offscreen-activity" hidden aria-hidden="true">
193
+ <span class="ai-chat-live-dots" aria-hidden="true"><i></i><i></i><i></i></span>
194
+ </div>
191
195
  <div class="ai-chat-recovery" id="chat-recovery" hidden>
192
196
  <span id="chat-recovery-copy">FloLess needs to check the last AI response before sending another message.</span>
193
197
  <button data-command-id="shell.chat-stop" type="button" id="chat-recovery-stop">Stop response</button>
@@ -195,8 +199,16 @@
195
199
  </div>
196
200
  <div class="ai-chat-attachments" id="chat-attachments" hidden></div>
197
201
  <div class="ai-chat-skills" id="chat-skills" role="listbox" hidden></div>
202
+ <div class="ai-chat-approval-tray" id="chat-approval-tray"></div>
198
203
  <div class="ai-chat-composer" id="chat-composer">
204
+ <div class="ai-chat-tekla-context" id="chat-tekla-context" hidden></div>
199
205
  <textarea data-command-id="shell.chat-input" id="chat-input" rows="1" maxlength="131072" placeholder="Message AI…" aria-label="Message AI"></textarea>
206
+ <!-- The data-handling disclosure gets its OWN node in the composer, not a line in
207
+ #chat-compose-hint: that hint is one mutable string chosen by a priority chain,
208
+ so anything else needing the slot would silently overwrite the disclosure. This
209
+ sits in the composer's rigid grid row, so no conversation-area height can take
210
+ it away (#1501). -->
211
+ <p class="ai-chat-composer-disclosure" id="chat-composer-disclosure" hidden>Messages and attachments are sent to Claude or Codex through your account.</p>
200
212
  <div class="ai-chat-compose-actions">
201
213
  <input data-command-id="shell.chat-attach-input" id="chat-file" type="file" accept="image/png,image/jpeg,image/webp,application/pdf" multiple hidden>
202
214
  <button data-command-id="shell.chat-attach" type="button" class="ai-chat-icon" id="chat-attach" data-tip="Attach image or PDF" aria-label="Attach image or PDF">+</button>
@@ -204,7 +216,9 @@
204
216
  <button data-command-id="shell.chat-stop" type="button" class="ai-chat-stop" id="chat-stop" hidden>Stop</button>
205
217
  <button data-command-id="shell.chat-send" type="button" class="ai-chat-send" id="chat-send">Send</button>
206
218
  </div>
207
- <div class="ai-chat-compose-context" id="chat-compose-context" aria-live="polite"></div>
219
+ <!-- What goes with each message is the Send tooltip, and is read to screen readers, rather than a
220
+ line of text under the composer. -->
221
+ <div class="ai-chat-compose-context sr-only" id="chat-compose-context" aria-live="polite"></div>
208
222
  </div>
209
223
  <span class="sr-only" id="chat-status" role="status" aria-live="polite"></span>
210
224
  </section>
@@ -1160,7 +1174,7 @@
1160
1174
  <div class="request-help-steps" id="request-help-steps">
1161
1175
  <div class="request-help-step"><span>1</span><p>Open Claude Code, Codex, or OpenCode in your project folder.</p></div>
1162
1176
  <div class="request-help-step"><span>2</span><p>Paste the copied request. It will read the drawing and prepare the Drawing Filter.</p></div>
1163
- <div class="request-help-step"><span>3</span><p>When it stops, open Drawing Filter, review the selected lines, then press Save filter in the top-right corner.</p></div>
1177
+ <div class="request-help-step"><span>3</span><p>When it stops, open Drawing Filter. Check steel, member marks, grids, dimensions, and relevant callouts; ask in AI Chat on the left if you are unsure. Then press Save filter in the top-right corner.</p></div>
1164
1178
  </div>
1165
1179
  <!-- Replaces the three steps above once floless has started the work itself: they describe
1166
1180
  things the user must do, and after "Run it for me" there is nothing left for them to do.
@@ -1472,6 +1486,7 @@
1472
1486
  <script src="aware-update-client.js"></script>
1473
1487
  <script src="aware.js"></script>
1474
1488
  <script src="panels.js"></script>
1489
+ <script src="filter-guidance.js"></script>
1475
1490
  <script src="workspaces.js"></script>
1476
1491
  <script src="left-pane.js"></script>
1477
1492
  <script src="chat.js"></script>
@@ -198,9 +198,13 @@
198
198
  if (focus.group) facts.push(focus.group);
199
199
  if (focus.key) facts.push(focus.key);
200
200
 
201
+ /* "Available now" is a claim about a control, so it is made only when there is one to
202
+ make it about. An entry the registry synthesized for a command with NO control on any
203
+ page (a gesture, an editor that is not open) marks `availabilityKnown: false` and says
204
+ nothing either way (#1545). Entries built from a real control leave it unset. */
201
205
  if (focus.disabled) {
202
206
  facts.push(focus.disabledReason || 'Not available right now');
203
- } else if (facts.length) {
207
+ } else if (facts.length && focus.availabilityKnown !== false) {
204
208
  facts.push('Available now');
205
209
  }
206
210
 
@@ -303,11 +307,9 @@
303
307
  var narratedInstance = target.getAttribute('data-command-instance-label') || cmd.instance;
304
308
  return {
305
309
  label: cmd.meta.label
306
- ? cmd.meta.label.replace(/\{instance\}/g, narratedInstance || 'the one you pick')
310
+ ? fillInstance(cmd.meta.label, narratedInstance, cmd.meta.anyInstance)
307
311
  : accessibleName(target),
308
- acts: narratedInstance && cmd.meta.actsOn
309
- ? cmd.meta.actsOn.replace('{instance}', narratedInstance)
310
- : cmd.meta.actsOn || null,
312
+ acts: cmd.meta.actsOn ? fillInstance(cmd.meta.actsOn, narratedInstance, cmd.meta.anyInstance) : null,
311
313
  group: cmd.meta.group || groupOf(target),
312
314
  key: cmd.meta.key || target.getAttribute('data-key'),
313
315
  tip: tip ? tip.split('\n')[0] : '',
@@ -528,9 +530,9 @@
528
530
  var hasActive = active && active !== document.body;
529
531
  /* A control can disappear while the pointer remains parked at its old coordinates. The revision
530
532
  result does exactly that: Apply is hidden, then focus moves to Close. Treating the hidden Apply
531
- as fresh pointer intent makes `?` narrate an action that is no longer on screen. */
532
- var hoveredIsRendered = lastHovered && lastHovered.isConnected
533
- && lastHovered.getClientRects && lastHovered.getClientRects().length;
533
+ as fresh pointer intent makes `?` narrate an action that is no longer on screen. The same goes for
534
+ one a full-window overlay has since covered (#1445): it keeps its layout but is inert. */
535
+ var hoveredIsRendered = lastHovered && lastHovered.isConnected && isOnScreen(lastHovered);
534
536
  var pointerIsFresh = hoveredIsRendered && (Date.now() - lastHoveredAt) < HOVER_INTENT_MS;
535
537
  var focusedOrder = lastFocused === active ? lastFocusedOrder : 0;
536
538
 
@@ -654,8 +656,7 @@
654
656
  function collect(doc, origin) {
655
657
  if (!doc || !doc.querySelectorAll) return;
656
658
  Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
657
- if ((el.closest && el.closest('#command-sheet'))
658
- || !(el.offsetParent || (el.getClientRects && el.getClientRects().length))) return;
659
+ if ((el.closest && el.closest('#command-sheet')) || !isOnScreen(el)) return;
659
660
  var raw = el.getAttribute('data-command-id') || '';
660
661
  var parts = window.Commands.split ? window.Commands.split(raw) : null;
661
662
  if (!parts || parts.template !== cmd.id || !parts.instance || seen[raw]) return;
@@ -665,7 +666,7 @@
665
666
  commandId: raw,
666
667
  instance: parts.instance,
667
668
  instanceLabel: instanceLabel,
668
- label: cmd.label ? cmd.label.replace(/\{instance\}/g, parts.instance) : instanceLabel,
669
+ label: cmd.label ? fillInstance(cmd.label, parts.instance) : instanceLabel,
669
670
  originSurface: origin,
670
671
  }));
671
672
  });
@@ -678,6 +679,45 @@
678
679
  return found;
679
680
  }
680
681
 
682
+ /* A template's `{instance}` filled for a reader (#1442).
683
+
684
+ With an instance — the live control's label, or the key it carries — the slot takes it
685
+ verbatim. Without one (the `?` sheet lists TEMPLATES, and a control can carry a bare
686
+ template id) the slot needs words of its own, and the braces must never reach a reader.
687
+
688
+ The old fallback substituted "the one you pick" blindly, and templates are written for
689
+ the instance — "Opens or closes the {instance} group" — so it read "the the one you
690
+ pick group". A doubled article is only the loudest form: the placeholder often names a
691
+ KIND ("the {instance} snap", "the {instance} panel"), and "the one you pick" cannot sit
692
+ in front of the noun it modifies. So the fallback is derived from the words around it:
693
+
694
+ the {instance} <noun> → the <noun> you pick "the group you pick in the Model index"
695
+ the {instance} → the one you pick (the template's own article absorbed)
696
+ {instance} → the one you pick "Opens the one you pick on the canvas"
697
+
698
+ A slot that no noun phrase can fill — an adverb ("Zooms {instance}" → in / out), a unit
699
+ ("every so many {instance}") — declares what it reads as instead, as the command's
700
+ `anyInstance`, and that replaces the slot whole. verify: server/instructor-instance-
701
+ fallback.test.ts renders every registered template through THIS function and fails a
702
+ doubled or clashing determiner, or a fallback left in front of a noun. */
703
+ function fillInstance(text, instance, anyInstance) {
704
+ if (!text || text.indexOf('{instance}') === -1) return text;
705
+ if (instance) return text.replace(/\{instance\}/g, instance);
706
+ /* A quoted slot quotes a NAME ("Export IFC"); a stand-in is not a name, so it loses them. */
707
+ text = text.replace(/["“]\{instance\}["”]/g, '{instance}');
708
+ if (anyInstance) return text.replace(/\{instance\}/g, anyInstance);
709
+ /* Words that can follow "the {instance}" without being the noun it modifies. Anything
710
+ else after it is read as that noun. Kept here, beside the one rule that reads it. */
711
+ var NOT_A_NOUN = /^(?:the|a|an|this|that|these|those|its|their|of|on|in|into|onto|to|for|at|as|by|from|with|without|through|against|about|above|below|and|or|but|so|if|then|than|once|while|until|again|right|out|off|is|are|was|were|be|been|has|have|had|can|will)$/;
712
+ return text
713
+ .replace(/\b([Tt])he \{instance\}(?: ([a-z][a-z-]*))?/g, function (m, t, next) {
714
+ if (next && !NOT_A_NOUN.test(next)) return t + 'he ' + next + ' you pick';
715
+ return t + 'he one you pick' + (next ? ' ' + next : '');
716
+ })
717
+ .replace(/(^|[.;:!?]\s+)\{instance\}/g, '$1The one you pick')
718
+ .replace(/\{instance\}/g, 'the one you pick');
719
+ }
720
+
681
721
  /* What a row says BESIDES its label. An entry with nothing to add says
682
722
  nothing — silence beats an echo, and a row that reads "Compile — compiles"
683
723
  would cost the whole surface its credibility. */
@@ -687,7 +727,7 @@
687
727
  serve every generated row. The sheet lists TEMPLATES, so there is no
688
728
  instance to fill it with — and shipping the literal braces to a user is
689
729
  the kind of leak that costs a documentation surface its credibility. */
690
- if (cmd.actsOn) facts.push(cmd.actsOn.replace(/\{instance\}/g, cmd.instanceLabel || cmd.instance || 'the one you pick'));
730
+ if (cmd.actsOn) facts.push(fillInstance(cmd.actsOn, cmd.instanceLabel || cmd.instance, cmd.anyInstance));
691
731
  if (cmd.risk && cmd.risk.indexOf('destructive') !== -1) facts.push('cannot be undone');
692
732
  if (cmd.risk && cmd.risk.indexOf('costs-money') !== -1) facts.push('costs money');
693
733
  if (cmd.persistence === 'external') facts.push('reaches outside FloLess');
@@ -777,32 +817,85 @@
777
817
  function activeSurface() {
778
818
  return (snapshot.child && snapshot.child.surface) || (snapshot.workspace ? 'workspaces' : 'shell');
779
819
  }
820
+ /* Every command template the pages hold a control for, sampled once per render so the
821
+ sort never rescans the DOM. The value says how reachable the best of its controls is:
822
+ true — on screen;
823
+ 'reveal' — hidden inside a container whose opener (`data-reveal-by`) is on screen, so
824
+ activate() can open it and focus the control (#1199), e.g. a ⋯-menu item;
825
+ false — present, but every control is hidden with no visible way to it (#1557).
826
+ A template with no control at all is absent from the map: a gesture or an unrendered
827
+ control proves nothing, so onScreen() leaves it where its surface puts it. */
780
828
  function visibleCarrierTemplates() {
781
829
  var visible = {};
830
+ var RANK = { 'false': 0, reveal: 1, 'true': 2 };
782
831
  function scan(doc) {
783
832
  if (!doc || !doc.querySelectorAll) return;
784
833
  Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
785
834
  if (el.closest && el.closest('#command-sheet')) return;
786
- if (!(el.offsetParent || (el.getClientRects && el.getClientRects().length))) return;
787
835
  var raw = el.getAttribute('data-command-id') || '';
788
836
  var parts = window.Commands.split ? window.Commands.split(raw) : null;
789
- if (parts?.template) visible[parts.template] = true;
837
+ if (!parts?.template) return;
838
+ var state = isOnScreen(el) ? true : revealableCarrier(el, doc) ? 'reveal' : false;
839
+ var had = visible[parts.template];
840
+ if (had === undefined || RANK[String(state)] > RANK[String(had)]) visible[parts.template] = state;
790
841
  });
791
842
  }
792
843
  scan(document);
793
844
  if (activeReporterWindow && snapshot.child) {
794
845
  try { scan(activeReporterWindow.document); } catch (e) { /* torn down */ }
795
846
  }
847
+ // The left Model panel hosts the open child's own controls (the same document anyCarrier() searches).
848
+ scan(panelDoc());
796
849
  return visible;
797
850
  }
851
+
852
+ /* A hidden control activate() could still reach: the OUTERMOST closed container around it
853
+ declares an opener that is on screen and would be clicked (revealCarrier() refuses one that
854
+ cancels a pick). Only that first opener is checked — every inner one sits inside a closed
855
+ container, so it cannot be on screen until the outer one opens. Cheap and side-effect free on
856
+ purpose: the sort runs this for every control, so it does not scroll or hit-test the way
857
+ revealCarrier() does when the user actually picks the row.
858
+ Opening menus only shows their CONTAINERS, so a control hidden by something else on the way
859
+ up — itself or a wrapper that is not a reveal container (the steel ⋯ menu's 3D-only snap
860
+ toggle in 2D is display:none by its own rule) — stays hidden however many menus open, and is
861
+ not reachable. */
862
+ function revealableCarrier(el, doc) {
863
+ var chain = revealChain(el);
864
+ for (var i = 0; i < chain.length; i++) {
865
+ if (isOnScreen(chain[i])) continue;
866
+ for (var n = el; n && n !== chain[i]; n = n.parentElement) {
867
+ if (n.getAttribute && n.getAttribute('data-reveal-by') !== null) continue; // opened on the way in
868
+ if (hiddenByItself(n)) return false;
869
+ }
870
+ var opener = null;
871
+ try { opener = doc.querySelector(chain[i].getAttribute('data-reveal-by')); }
872
+ catch (e) { opener = null; }
873
+ return !!(opener && opener.getAttribute('data-cancels-pick') === null && isOnScreen(opener));
874
+ }
875
+ return false;
876
+ }
877
+ function hiddenByItself(node) {
878
+ if (node.hidden) return true;
879
+ var view = node.ownerDocument && node.ownerDocument.defaultView;
880
+ if (!view || typeof view.getComputedStyle !== 'function') return false;
881
+ try { return view.getComputedStyle(node).display === 'none'; }
882
+ catch (e) { return false; }
883
+ }
798
884
  function onScreen(cmd, visibleTemplates) {
799
885
  /* A command registered before `surface` existed would have none. Treating
800
886
  that as on-screen keeps it visible rather than silently exiling it, and
801
887
  verify-command-registry is what stops one being added. */
802
888
  var surface = cmd.originSurface || cmd.surface;
803
889
  if (!surface) return true;
804
- if (snapshot.workspace && (surface === 'shell' || surface === 'workspaces')) return !!visibleTemplates?.[cmd.id];
805
- if (snapshot.workspace && snapshot.child && surface === snapshot.child.surface) return true;
890
+ var carriers = visibleTemplates?.[cmd.id];
891
+ /* Unchanged for the shell in a workspace: only a control ON screen counts. A closed ≡ menu is
892
+ not "this screen" there, and 'reveal' must not quietly promote its items. */
893
+ if (snapshot.workspace && (surface === 'shell' || surface === 'workspaces')) return carriers === true;
894
+ /* #1557 — the open child's commands are on this screen, EXCEPT one whose every control is
895
+ hidden with no visible opener (the Revit Properties toggle while a project has no model):
896
+ choosing it already reads "Hidden on this screen right now" (#1545), so ranking it above
897
+ the divider was the one place the sheet still claimed otherwise. */
898
+ if (snapshot.child && surface === snapshot.child.surface) return carriers !== false;
806
899
  return surface === activeSurface();
807
900
  }
808
901
 
@@ -870,7 +963,8 @@
870
963
 
871
964
  var label = document.createElement('span');
872
965
  label.className = 'cmd-row-label';
873
- label.textContent = cmd.label;
966
+ // A template row has no instance, and its label must not show a reader the braces.
967
+ label.textContent = fillInstance(cmd.label, cmd.instance, cmd.anyInstance);
874
968
  row.appendChild(label);
875
969
 
876
970
  /* Where this command lives, for screen readers only. Arrow-key navigation
@@ -954,7 +1048,7 @@
954
1048
  var liveOrigin = 'shell';
955
1049
  Array.prototype.forEach.call(document.querySelectorAll('[data-command-id]'), function (el) {
956
1050
  if (live || !matchesCommand(el) || (el.closest && el.closest('#command-sheet'))) return;
957
- if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) live = el;
1051
+ if (isOnScreen(el)) live = el;
958
1052
  });
959
1053
 
960
1054
  /* Then the live child surface, if one is up. Searching only this document used
@@ -976,7 +1070,7 @@
976
1070
  // the one place a data-command-id describes a LIST ENTRY rather than a control,
977
1071
  // and half a rule is how that distinction gets lost.
978
1072
  if (live || !matchesCommand(el) || (el.closest && el.closest('#command-sheet'))) return;
979
- if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) {
1073
+ if (isOnScreen(el)) {
980
1074
  live = el;
981
1075
  liveOrigin = snapshot.child.surface || 'shell';
982
1076
  }
@@ -987,7 +1081,7 @@
987
1081
  if (panel) {
988
1082
  Array.prototype.forEach.call(panel.querySelectorAll('[data-command-id]'), function (el) {
989
1083
  if (live || !matchesCommand(el)) return;
990
- if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) {
1084
+ if (isOnScreen(el)) {
991
1085
  live = el;
992
1086
  liveOrigin = (snapshot.child && snapshot.child.surface) || 'shell';
993
1087
  }
@@ -1046,12 +1140,67 @@
1046
1140
  paint();
1047
1141
  return;
1048
1142
  }
1049
- describeCommand(cmd);
1143
+ describeCommand(cmd, shown || anyCarrier(matchesCommand, cmd.originSurface || cmd.surface));
1050
1144
  }, 0);
1051
1145
  return;
1052
1146
  }
1053
1147
 
1054
- describeCommand(cmd);
1148
+ /* The control that was found live but could not be described, or — when nothing is on
1149
+ screen — any control for this command the page holds hidden, so the entry can say it
1150
+ is hidden (or why) instead of "Available now" (#1545). */
1151
+ describeCommand(cmd, live || anyCarrier(matchesCommand, cmd.originSurface || cmd.surface));
1152
+ }
1153
+
1154
+ /* #1545 — any control for this command, on screen or not, in the same documents and with the
1155
+ same sheet exclusion as activate()'s lookups. The documents are searched surface-first: the
1156
+ live child's own document (and the left Model panel, which hosts its controls) before the
1157
+ shell when the command lives on that child, the shell first otherwise. The FIRST document
1158
+ holding any control for it answers, so a reason written for another surface's copy of the
1159
+ control never speaks for this one. Within that document, a DISABLED control that says why
1160
+ (`data-blocked-reason`) wins, so its own words reach the band — see carrierAvailability for
1161
+ why an enabled one's reason does not count. */
1162
+ function anyCarrier(matches, surface) {
1163
+ var childDoc = null;
1164
+ if (activeReporterWindow && snapshot.child) {
1165
+ try { childDoc = activeReporterWindow.document; } catch (e) { /* torn down mid-lookup */ }
1166
+ }
1167
+ var onChild = !!(childDoc && surface && snapshot.child.surface === surface);
1168
+ var docs = onChild ? [childDoc, panelDoc(), document] : [document, childDoc, panelDoc()];
1169
+ for (var i = 0; i < docs.length; i++) {
1170
+ var doc = docs[i], first = null, reasoned = null;
1171
+ if (!doc || !doc.querySelectorAll) continue;
1172
+ Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
1173
+ if (reasoned || !matches(el) || (el.closest && el.closest('#command-sheet'))) return;
1174
+ if (!first) first = el;
1175
+ if (el.getAttribute('data-blocked-reason') && carrierDisabled(el)) reasoned = el;
1176
+ });
1177
+ if (first) return reasoned || first;
1178
+ }
1179
+ return null;
1180
+ }
1181
+
1182
+ /* What the band may truthfully say about a command's availability, read from its control.
1183
+ No control at all → nothing is known, so nothing is claimed. A control that is not on
1184
+ screen cannot be used, whatever its `disabled` says: its own reason if it is disabled, else
1185
+ that it is hidden. A control on screen → its live disabled state, as focusFor() reads it.
1186
+ A `data-blocked-reason` counts ONLY while its control is disabled, the rule focusFor()
1187
+ already follows: some pages keep one in the markup permanently (#run-btn's "Blocked until
1188
+ the workflow is compiled"), and reading it off an enabled control that is merely hidden in
1189
+ this view would replace one false claim with another. */
1190
+ function carrierAvailability(el) {
1191
+ if (!el) return { known: false, disabled: false, reason: null };
1192
+ var ctl = el.control || el; // a <label> carrier is as disabled as the control it labels
1193
+ var disabled = carrierDisabled(el);
1194
+ var reason = disabled
1195
+ ? el.getAttribute('data-blocked-reason') || (ctl !== el && ctl.getAttribute ? ctl.getAttribute('data-blocked-reason') : null)
1196
+ : null;
1197
+ if (!isOnScreen(el)) return { known: true, disabled: true, reason: reason || 'Hidden on this screen right now' };
1198
+ return { known: true, disabled: disabled, reason: reason };
1199
+ }
1200
+
1201
+ function carrierDisabled(el) {
1202
+ var ctl = el.control || el;
1203
+ return !!(ctl.disabled || (ctl.getAttribute && ctl.getAttribute('aria-disabled') === 'true'));
1055
1204
  }
1056
1205
 
1057
1206
  /* No control we can take the user to: a steel.* command whose surface is not up, one
@@ -1060,24 +1209,51 @@
1060
1209
  (some ≡ items in a workspace), or one registered without a data-command-id in markup.
1061
1210
  Closing and doing nothing would make the footer's "Enter — go to it" a promise the
1062
1211
  sheet breaks. So it puts the command's own entry in the band instead: the user still
1063
- learns what it does and where it lives, which is what they asked for. */
1064
- function describeCommand(cmd) {
1212
+ learns what it does and where it lives, which is what they asked for. What it says about
1213
+ AVAILABILITY comes from `carrier`, the command's control if the page holds one (#1545):
1214
+ this used to hardcode "not disabled", so a command whose only control was hidden read
1215
+ "Available now". */
1216
+ function describeCommand(cmd, carrier) {
1217
+ var availability = carrierAvailability(carrier);
1065
1218
  setFocusEntry({
1066
- label: cmd.label,
1067
- acts: cmd.actsOn ? cmd.actsOn.replace(/\{instance\}/g, cmd.instanceLabel || cmd.instance || 'the one you pick') : null,
1219
+ label: fillInstance(cmd.label, cmd.instance, cmd.anyInstance),
1220
+ acts: cmd.actsOn ? fillInstance(cmd.actsOn, cmd.instanceLabel || cmd.instance, cmd.anyInstance) : null,
1068
1221
  group: cmd.group,
1069
1222
  key: cmd.key,
1070
1223
  tip: cmd.why || '',
1071
- disabled: false,
1072
- disabledReason: null,
1224
+ disabled: availability.disabled,
1225
+ disabledReason: availability.reason,
1226
+ availabilityKnown: availability.known,
1073
1227
  commandId: cmd.id,
1074
1228
  instance: cmd.instance || null,
1075
1229
  }, cmd.surface || 'shell');
1076
1230
  paint();
1077
1231
  }
1078
1232
 
1233
+ /* On screen AND reachable. A control under an `inert` region still has layout — a full-window
1234
+ editor overlay makes the shell under it inert rather than hiding it (#1445) — but it takes no
1235
+ focus and no click, so it is not a control the sheet can take anyone to: activating it would
1236
+ narrate a focus that never happened. The regions this sheet inerts ITSELF while it is open
1237
+ (every body child but the sheet, see setBackgroundInert) do not count — every lookup runs
1238
+ with the sheet still open, so counting them would hide every control on the page. The walk
1239
+ continues out through a child document's frame, so an editor frame inside a covered region
1240
+ is covered too. */
1079
1241
  function isOnScreen(el) {
1080
- return !!(el.offsetParent || (el.getClientRects && el.getClientRects().length));
1242
+ return !!(el.offsetParent || (el.getClientRects && el.getClientRects().length)) && !coveredByInert(el);
1243
+ }
1244
+ function coveredByInert(el) {
1245
+ for (var n = el; n; ) {
1246
+ if (n.inert && !inertedBySheet(n)) return true;
1247
+ if (n.parentElement) { n = n.parentElement; continue; }
1248
+ try {
1249
+ var view = n.ownerDocument && n.ownerDocument.defaultView;
1250
+ n = view && view !== window ? view.frameElement : null;
1251
+ } catch (e) { n = null; }
1252
+ }
1253
+ return false;
1254
+ }
1255
+ function inertedBySheet(n) {
1256
+ return !!inertBefore && inertBefore.some(function (pair) { return pair[0] === n && !pair[1]; });
1081
1257
  }
1082
1258
 
1083
1259
  /* Every ancestor that declares `data-reveal-by`, open or closed, OUTERMOST first. */