@floless/app 0.140.0 → 0.141.1

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.
@@ -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');
@@ -736,11 +776,11 @@
736
776
  'In the Informed by row', 'In Set inputs',
737
777
  'At the left edge of the workspace', 'At the edge of the left or Inspect panel', 'In the left panel', 'Between AI Chat and Model', 'In the Model section of the left panel',
738
778
  'In AI Chat', 'In AI Chat history', 'In AI Chat settings', 'In the node Inspect panel', 'In the Instructor strip',
739
- 'In the ≡ menu', 'In the footer',
779
+ 'In the ≡ menu', 'In the account menu', 'In the footer',
740
780
  'In the contract editor', 'In the report viewer', 'In the Knowledge Base viewer', 'In the guide',
741
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',
742
782
  'In the Report an issue dialog', 'In the Build an agent dialog', 'In the Bake dialog', 'In the CAD send review',
743
- 'In the FloLess dialogs',
783
+ 'In the FloLess dialogs', 'On the FloLess has stopped screen',
744
784
  /* the steel editor — read top-left down, then the menus, then the dialogs.
745
785
  The ⋯ menu is six groups rather than one because it is six accordion
746
786
  sections on screen: a single 'In the ⋯ menu' would have been about thirty
@@ -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. */