@floless/app 0.139.1 → 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.
Files changed (41) hide show
  1. package/dist/floless-server.cjs +32765 -36490
  2. package/dist/skills/floless-app-steel-takeoff/SKILL.md +8 -3
  3. package/dist/skills/floless-app-vectorize/SKILL.md +1 -1
  4. package/dist/skills/floless-app-vectorize/scripts/extract_pdf.py +7 -1
  5. package/dist/skills/floless-app-vectorize/scripts/vision_to_contract.py +7 -1
  6. package/dist/web/app.css +163 -3
  7. package/dist/web/aware.js +657 -66
  8. package/dist/web/chat.css +387 -25
  9. package/dist/web/chat.js +2005 -108
  10. package/dist/web/commands-filter.js +86 -8
  11. package/dist/web/commands-revit.js +2 -1
  12. package/dist/web/commands-shell.js +249 -13
  13. package/dist/web/commands-steel.js +34 -24
  14. package/dist/web/commands.js +19 -0
  15. package/dist/web/filter-ai-context.js +57 -0
  16. package/dist/web/filter-ai-proposal.js +87 -0
  17. package/dist/web/filter-guidance.js +8 -0
  18. package/dist/web/index.html +72 -11
  19. package/dist/web/instructor.js +231 -33
  20. package/dist/web/left-pane.js +185 -18
  21. package/dist/web/local-discovery.js +297 -0
  22. package/dist/web/model-editor-revit-adapter.js +3 -1
  23. package/dist/web/model-editor-steel-adapter.js +3 -1
  24. package/dist/web/model-editor.css +4 -4
  25. package/dist/web/model-revit-module.js +63 -0
  26. package/dist/web/model-viewport-toolbar.js +13 -1
  27. package/dist/web/model-viewport.js +16 -1
  28. package/dist/web/overlay-escape.js +79 -0
  29. package/dist/web/revit-editor.css +7 -0
  30. package/dist/web/revit-editor.html +5 -5
  31. package/dist/web/revit-editor.js +20 -10
  32. package/dist/web/steel-detail-refs.js +0 -69
  33. package/dist/web/steel-editor.html +103 -264
  34. package/dist/web/steel-filter-core.js +298 -12
  35. package/dist/web/steel-filter-hit.js +526 -0
  36. package/dist/web/steel-filter.html +1647 -75
  37. package/dist/web/steel-split-view.js +1 -1
  38. package/dist/web/vector-3d.html +3 -0
  39. package/dist/web/vector-editor.html +9 -1
  40. package/dist/web/workspaces.js +198 -25
  41. package/package.json +5 -2
@@ -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] : '',
@@ -372,6 +374,13 @@
372
374
  $ask.dataset.subject = g.ask;
373
375
  $askQueue.dataset.subject = g.ask;
374
376
  }
377
+ return g;
378
+ }
379
+
380
+ function publishGraftGuidance(guidance) {
381
+ if (guidance && typeof window.flolessGraftInstructorExplain === 'function') {
382
+ window.flolessGraftInstructorExplain({ chip: guidance.chip || '', parts: guidance.parts.slice(), commandId: guidance.commandId || '' });
383
+ }
375
384
  }
376
385
 
377
386
  function setCollapsed(next) {
@@ -521,9 +530,9 @@
521
530
  var hasActive = active && active !== document.body;
522
531
  /* A control can disappear while the pointer remains parked at its old coordinates. The revision
523
532
  result does exactly that: Apply is hidden, then focus moves to Close. Treating the hidden Apply
524
- as fresh pointer intent makes `?` narrate an action that is no longer on screen. */
525
- var hoveredIsRendered = lastHovered && lastHovered.isConnected
526
- && 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);
527
536
  var pointerIsFresh = hoveredIsRendered && (Date.now() - lastHoveredAt) < HOVER_INTENT_MS;
528
537
  var focusedOrder = lastFocused === active ? lastFocusedOrder : 0;
529
538
 
@@ -543,7 +552,20 @@
543
552
  : activeSurface();
544
553
  if (!setFocusEntry(f, origin)) return false;
545
554
  if (collapsed) setCollapsed(false);
546
- paint();
555
+ publishGraftGuidance(paint());
556
+ return true;
557
+ }
558
+
559
+ // A control whose label or enabled state changed must be read directly. The
560
+ // ordinary ?/F1 route also considers recent pointer intent, which may now be
561
+ // over a different control while keyboard focus remains on this one.
562
+ function refreshCarrier(el) {
563
+ if (!enabled || !el || !el.isConnected) return false;
564
+ var origin = el.ownerDocument === document
565
+ ? (snapshot.workspace ? 'workspaces' : 'shell')
566
+ : activeSurface();
567
+ if (!setFocusEntry(focusFor(el), origin)) return false;
568
+ publishGraftGuidance(paint());
547
569
  return true;
548
570
  }
549
571
 
@@ -581,6 +603,7 @@
581
603
  function clearFocusEntry() {
582
604
  if (!snapshot.focus) return;
583
605
  snapshot.focus = null;
606
+ if (typeof window.flolessGraftInstructorClear === 'function') window.flolessGraftInstructorClear();
584
607
  paint();
585
608
  }
586
609
 
@@ -633,8 +656,7 @@
633
656
  function collect(doc, origin) {
634
657
  if (!doc || !doc.querySelectorAll) return;
635
658
  Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
636
- if ((el.closest && el.closest('#command-sheet'))
637
- || !(el.offsetParent || (el.getClientRects && el.getClientRects().length))) return;
659
+ if ((el.closest && el.closest('#command-sheet')) || !isOnScreen(el)) return;
638
660
  var raw = el.getAttribute('data-command-id') || '';
639
661
  var parts = window.Commands.split ? window.Commands.split(raw) : null;
640
662
  if (!parts || parts.template !== cmd.id || !parts.instance || seen[raw]) return;
@@ -644,7 +666,7 @@
644
666
  commandId: raw,
645
667
  instance: parts.instance,
646
668
  instanceLabel: instanceLabel,
647
- label: cmd.label ? cmd.label.replace(/\{instance\}/g, parts.instance) : instanceLabel,
669
+ label: cmd.label ? fillInstance(cmd.label, parts.instance) : instanceLabel,
648
670
  originSurface: origin,
649
671
  }));
650
672
  });
@@ -657,6 +679,45 @@
657
679
  return found;
658
680
  }
659
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
+
660
721
  /* What a row says BESIDES its label. An entry with nothing to add says
661
722
  nothing — silence beats an echo, and a row that reads "Compile — compiles"
662
723
  would cost the whole surface its credibility. */
@@ -666,7 +727,7 @@
666
727
  serve every generated row. The sheet lists TEMPLATES, so there is no
667
728
  instance to fill it with — and shipping the literal braces to a user is
668
729
  the kind of leak that costs a documentation surface its credibility. */
669
- 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));
670
731
  if (cmd.risk && cmd.risk.indexOf('destructive') !== -1) facts.push('cannot be undone');
671
732
  if (cmd.risk && cmd.risk.indexOf('costs-money') !== -1) facts.push('costs money');
672
733
  if (cmd.persistence === 'external') facts.push('reaches outside FloLess');
@@ -717,14 +778,14 @@
717
778
  'In AI Chat', 'In AI Chat history', 'In AI Chat settings', 'In the node Inspect panel', 'In the Instructor strip',
718
779
  'In the ≡ menu', 'In the footer',
719
780
  'In the contract editor', 'In the report viewer', 'In the Knowledge Base viewer', 'In the guide',
720
- 'In the agent library', 'In the requests list', 'In the revision review', 'In the run request dialog', 'In the Integrations dialog', 'In the Routines dialog',
781
+ 'In the agent library', 'In Discover local tools', 'In the requests list', 'In the revision review', 'In the run request dialog', 'In the Integrations dialog', 'In the Routines dialog',
721
782
  'In the Report an issue dialog', 'In the Build an agent dialog', 'In the Bake dialog', 'In the CAD send review',
722
783
  'In the FloLess dialogs',
723
784
  /* the steel editor — read top-left down, then the menus, then the dialogs.
724
785
  The ⋯ menu is six groups rather than one because it is six accordion
725
786
  sections on screen: a single 'In the ⋯ menu' would have been about thirty
726
787
  rows under one heading, which is a scroll rather than a list. */
727
- 'In the steel editor header', 'On the steel canvas', 'On the drawing canvas', 'In the Copy panel', 'In the Copy array panel', 'On the 2D zoom bar',
788
+ 'In the steel editor header', 'On the steel canvas', 'On the drawing canvas', 'In the Copy panel', 'In the Copy array panel', 'In the 2D view toolbar',
728
789
  'In the 3D toolbar', 'In the label menus', 'On the select bar', 'On the snap bar',
729
790
  'In the grid panel', 'In the Inspect panel', 'In the Properties panel',
730
791
  'In the Properties popup', 'In the snap override menu', 'In the dimension value popup', 'In the selection filter',
@@ -737,7 +798,7 @@
737
798
  'In the Connections dialog', 'In the reference-model dialogs', 'In the connection-import dialog',
738
799
  'In the confidence report', 'In the Ask AI panel', 'In the Ask AI dialog', 'In the Favourites dialog',
739
800
  // the read-only Revit model editor
740
- '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', 'On the Inspector',
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',
741
802
  // the drawing filter
742
803
  'In the Drawing Filter header', 'In a Drawing Filter message',
743
804
  'In the Drawing Filter panel', 'On the Drawing Filter canvas',
@@ -756,32 +817,85 @@
756
817
  function activeSurface() {
757
818
  return (snapshot.child && snapshot.child.surface) || (snapshot.workspace ? 'workspaces' : 'shell');
758
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. */
759
828
  function visibleCarrierTemplates() {
760
829
  var visible = {};
830
+ var RANK = { 'false': 0, reveal: 1, 'true': 2 };
761
831
  function scan(doc) {
762
832
  if (!doc || !doc.querySelectorAll) return;
763
833
  Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
764
834
  if (el.closest && el.closest('#command-sheet')) return;
765
- if (!(el.offsetParent || (el.getClientRects && el.getClientRects().length))) return;
766
835
  var raw = el.getAttribute('data-command-id') || '';
767
836
  var parts = window.Commands.split ? window.Commands.split(raw) : null;
768
- 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;
769
841
  });
770
842
  }
771
843
  scan(document);
772
844
  if (activeReporterWindow && snapshot.child) {
773
845
  try { scan(activeReporterWindow.document); } catch (e) { /* torn down */ }
774
846
  }
847
+ // The left Model panel hosts the open child's own controls (the same document anyCarrier() searches).
848
+ scan(panelDoc());
775
849
  return visible;
776
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
+ }
777
884
  function onScreen(cmd, visibleTemplates) {
778
885
  /* A command registered before `surface` existed would have none. Treating
779
886
  that as on-screen keeps it visible rather than silently exiling it, and
780
887
  verify-command-registry is what stops one being added. */
781
888
  var surface = cmd.originSurface || cmd.surface;
782
889
  if (!surface) return true;
783
- if (snapshot.workspace && (surface === 'shell' || surface === 'workspaces')) return !!visibleTemplates?.[cmd.id];
784
- 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;
785
899
  return surface === activeSurface();
786
900
  }
787
901
 
@@ -849,7 +963,8 @@
849
963
 
850
964
  var label = document.createElement('span');
851
965
  label.className = 'cmd-row-label';
852
- 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);
853
968
  row.appendChild(label);
854
969
 
855
970
  /* Where this command lives, for screen readers only. Arrow-key navigation
@@ -933,7 +1048,7 @@
933
1048
  var liveOrigin = 'shell';
934
1049
  Array.prototype.forEach.call(document.querySelectorAll('[data-command-id]'), function (el) {
935
1050
  if (live || !matchesCommand(el) || (el.closest && el.closest('#command-sheet'))) return;
936
- if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) live = el;
1051
+ if (isOnScreen(el)) live = el;
937
1052
  });
938
1053
 
939
1054
  /* Then the live child surface, if one is up. Searching only this document used
@@ -955,7 +1070,7 @@
955
1070
  // the one place a data-command-id describes a LIST ENTRY rather than a control,
956
1071
  // and half a rule is how that distinction gets lost.
957
1072
  if (live || !matchesCommand(el) || (el.closest && el.closest('#command-sheet'))) return;
958
- if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) {
1073
+ if (isOnScreen(el)) {
959
1074
  live = el;
960
1075
  liveOrigin = snapshot.child.surface || 'shell';
961
1076
  }
@@ -966,7 +1081,7 @@
966
1081
  if (panel) {
967
1082
  Array.prototype.forEach.call(panel.querySelectorAll('[data-command-id]'), function (el) {
968
1083
  if (live || !matchesCommand(el)) return;
969
- if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) {
1084
+ if (isOnScreen(el)) {
970
1085
  live = el;
971
1086
  liveOrigin = (snapshot.child && snapshot.child.surface) || 'shell';
972
1087
  }
@@ -1025,12 +1140,67 @@
1025
1140
  paint();
1026
1141
  return;
1027
1142
  }
1028
- describeCommand(cmd);
1143
+ describeCommand(cmd, shown || anyCarrier(matchesCommand, cmd.originSurface || cmd.surface));
1029
1144
  }, 0);
1030
1145
  return;
1031
1146
  }
1032
1147
 
1033
- 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'));
1034
1204
  }
1035
1205
 
1036
1206
  /* No control we can take the user to: a steel.* command whose surface is not up, one
@@ -1039,24 +1209,51 @@
1039
1209
  (some ≡ items in a workspace), or one registered without a data-command-id in markup.
1040
1210
  Closing and doing nothing would make the footer's "Enter — go to it" a promise the
1041
1211
  sheet breaks. So it puts the command's own entry in the band instead: the user still
1042
- learns what it does and where it lives, which is what they asked for. */
1043
- 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);
1044
1218
  setFocusEntry({
1045
- label: cmd.label,
1046
- 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,
1047
1221
  group: cmd.group,
1048
1222
  key: cmd.key,
1049
1223
  tip: cmd.why || '',
1050
- disabled: false,
1051
- disabledReason: null,
1224
+ disabled: availability.disabled,
1225
+ disabledReason: availability.reason,
1226
+ availabilityKnown: availability.known,
1052
1227
  commandId: cmd.id,
1053
1228
  instance: cmd.instance || null,
1054
1229
  }, cmd.surface || 'shell');
1055
1230
  paint();
1056
1231
  }
1057
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. */
1058
1241
  function isOnScreen(el) {
1059
- 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]; });
1060
1257
  }
1061
1258
 
1062
1259
  /* Every ancestor that declares `data-reveal-by`, open or closed, OUTERMOST first. */
@@ -1349,6 +1546,7 @@
1349
1546
  paint();
1350
1547
  },
1351
1548
  explain: explainCurrent,
1549
+ refreshCarrier: refreshCarrier,
1352
1550
  clear: clearFocusEntry,
1353
1551
  childSnapshot: function () { return snapshot.child; },
1354
1552
  isEnabled: function () { return enabled; },