@floless/app 0.155.1 → 0.156.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 (46) hide show
  1. package/cli-actions.mjs +376 -0
  2. package/dist/floless-server.cjs +101615 -87681
  3. package/dist/skills/floless-app-actions/SKILL.md +137 -0
  4. package/dist/skills/floless-app-approval/SKILL.md +8 -5
  5. package/dist/skills/floless-app-bridge/SKILL.md +12 -9
  6. package/dist/skills/floless-app-knowledge/SKILL.md +30 -13
  7. package/dist/skills/floless-app-new-workflow/SKILL.md +4 -4
  8. package/dist/skills/floless-app-onboarding/SKILL.md +1 -1
  9. package/dist/skills/floless-app-onboarding/references/aware-runtime.md +4 -4
  10. package/dist/skills/floless-app-queue/SKILL.md +10 -6
  11. package/dist/skills/floless-app-report-issue/SKILL.md +13 -10
  12. package/dist/skills/floless-app-rfi/SKILL.md +59 -68
  13. package/dist/skills/floless-app-routines/SKILL.md +19 -14
  14. package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
  15. package/dist/skills/floless-app-workflows/SKILL.md +5 -4
  16. package/dist/web/agent-steps.js +933 -0
  17. package/dist/web/agents.js +5 -0
  18. package/dist/web/app.css +210 -5
  19. package/dist/web/app.js +1 -0
  20. package/dist/web/aware.js +584 -44
  21. package/dist/web/chat.css +9 -0
  22. package/dist/web/chat.js +195 -13
  23. package/dist/web/commands-shell.js +299 -1
  24. package/dist/web/commands-tekla-parser.js +7 -0
  25. package/dist/web/index.html +52 -1
  26. package/dist/web/instructor.js +5 -3
  27. package/dist/web/leave-guard.js +4 -2
  28. package/dist/web/left-pane.js +145 -42
  29. package/dist/web/model-editor.css +10 -0
  30. package/dist/web/model-group-navigator.js +331 -0
  31. package/dist/web/model-panel-bridge.js +63 -5
  32. package/dist/web/model-pointer-dock.js +55 -5
  33. package/dist/web/model-revit-module.js +15 -0
  34. package/dist/web/model-selection-tools.js +53 -17
  35. package/dist/web/model-tekla-selection.js +75 -2
  36. package/dist/web/model-viewport-revit-adapter.js +17 -10
  37. package/dist/web/pages.js +27 -3
  38. package/dist/web/panels.js +3 -3
  39. package/dist/web/project-reconciliation.js +357 -0
  40. package/dist/web/revit-editor.js +464 -76
  41. package/dist/web/steel-3d-view.js +1 -0
  42. package/dist/web/terminal-requests.js +541 -0
  43. package/dist/web/tool-updates.js +147 -13
  44. package/dist/web/workspaces.js +213 -12
  45. package/launch.mjs +80 -2
  46. package/package.json +1 -1
@@ -744,12 +744,27 @@
744
744
  if (node.kind === 'label' || node.kind === 'note') {
745
745
  const copy = document.createElement('div'); copy.className = node.kind === 'label' ? 'revit-explorer-label' : 'left-model-empty'; copy.setAttribute('role', 'presentation'); copy.textContent = node.label; parent.append(copy); continue;
746
746
  }
747
+ if (node.kind === 'more' && typeof node.pageKey === 'string') {
748
+ const more = document.createElement('button'); more.type = 'button'; more.className = 'left-model-row left-model-load-more';
749
+ more.setAttribute('role', 'treeitem');
750
+ more.textContent = node.label; more.dataset.commandId = `shell.model-load-more#${commandInstance(node.pageKey)}`;
751
+ more.dataset.commandInstanceLabel = node.label;
752
+ more.addEventListener('click', () => {
753
+ const seenPaths = new Set([...modelContent.querySelectorAll('[data-occurrence-path]')].map((row) => row.dataset.occurrencePath));
754
+ const requestId = sendAction({ action: 'load-more', pageKey: node.pageKey, datasetKey: state.datasetKey });
755
+ if (requestId) pendingActions.set(requestId, { kind: 'load-more', seenPaths });
756
+ });
757
+ parent.append(more); continue;
758
+ }
747
759
  const row = document.createElement('button'); row.type = 'button'; row.className = 'left-model-row';
748
760
  const instance = node.entityId || node.groupId || node.label;
749
761
  row.dataset.commandId = node.entityId
750
- ? `shell.model-item#${commandInstance(instance)}`
762
+ ? `${Array.isArray(node.children) ? 'shell.model-hierarchy-drill' : 'shell.model-item'}#${commandInstance(instance)}`
751
763
  : `shell.model-group#${commandInstance(instance)}`;
752
764
  row.dataset.commandInstanceLabel = node.label;
765
+ if (Array.isArray(node.occurrencePath) && node.occurrencePath.length && node.occurrencePath.every((id) => typeof id === 'string')) {
766
+ row.dataset.occurrencePath = JSON.stringify(node.occurrencePath);
767
+ }
753
768
  if (typeof node.tip === 'string' && node.tip) row.dataset.tip = node.tip;
754
769
  const label = document.createElement('span'); label.className = 'row-label'; label.textContent = node.label;
755
770
  if (node.entityId && node.objectFields && ['name', 'profile', 'id'].every((key) => node.objectFields[key] == null || typeof node.objectFields[key] === 'string')) {
@@ -774,9 +789,78 @@
774
789
  row.append(label);
775
790
  }
776
791
  if (node.count != null) { const count = document.createElement('span'); count.className = 'explorer-count'; count.textContent = String(node.count); row.append(count); }
792
+ if (Array.isArray(node.children)) {
793
+ const branch = document.createElement('div'); branch.className = 'left-model-branch'; branch.setAttribute('role', 'none');
794
+ const disclosureKey = `${state.datasetKey}:${state.tab}:${node.groupId || node.entityId || node.label}`;
795
+ const expanded = groupDisclosure.has(disclosureKey) ? groupDisclosure.get(disclosureKey) : !!node.expanded;
796
+ row.setAttribute('role', 'treeitem'); row.setAttribute('aria-expanded', String(expanded));
797
+ if (node.entityId) {
798
+ row.dataset.entityId = node.entityId;
799
+ row.classList.toggle('selected', selectedIdsOf(state.snapshot).includes(node.entityId));
800
+ row.setAttribute('aria-selected', String(selectedIdsOf(state.snapshot).includes(node.entityId)));
801
+ if (node.entityId === state.snapshot?.selectedId) row.setAttribute('aria-current', 'true');
802
+ }
803
+ const disclosure = document.createElement('span'); disclosure.className = 'left-model-disclosure'; disclosure.setAttribute('aria-hidden', 'true');
804
+ disclosure.dataset.tip = `${expanded ? 'Collapse' : 'Expand'} ${node.label}`;
805
+ row.prepend(disclosure);
806
+ const children = document.createElement('div'); children.className = 'left-model-children'; children.setAttribute('role', 'group'); children.hidden = !expanded; append(node.children, children);
807
+ const requestLazyChildren = () => {
808
+ if (row.getAttribute('aria-busy') === 'true') return;
809
+ const outstanding = [...pendingActions.values()].some((pending) => pending.kind === 'expand' && pending.disclosureKey === disclosureKey);
810
+ if (outstanding) { row.setAttribute('aria-busy', 'true'); return; }
811
+ row.setAttribute('aria-busy', 'true');
812
+ const requestId = sendAction({ action: 'expand', groupId: node.groupId, datasetKey: state.datasetKey });
813
+ if (requestId) pendingActions.set(requestId, { kind: 'expand', row, disclosureKey, commandId: row.dataset.commandId });
814
+ else row.removeAttribute('aria-busy');
815
+ };
816
+ const toggle = (force = null) => {
817
+ if (node.lazy && !node.children.length) { requestLazyChildren(); return; }
818
+ const open = force ?? row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); children.hidden = !open;
819
+ disclosure.dataset.tip = `${open ? 'Collapse' : 'Expand'} ${node.label}`; groupDisclosure.set(disclosureKey, open);
820
+ };
821
+ disclosure.addEventListener('click', (event) => { event.preventDefault(); event.stopPropagation(); if (event.detail > 1) return; toggle(); });
822
+ disclosure.addEventListener('dblclick', (event) => { event.preventDefault(); event.stopPropagation(); });
823
+ row.addEventListener('click', (event) => {
824
+ if (event.detail > 1) return;
825
+ if (node.entityId) selectRow(node, event);
826
+ else {
827
+ toggle();
828
+ if (node.selectable === true) sendAction({ action: 'select-group', groupId: node.groupId, datasetKey: state.datasetKey });
829
+ }
830
+ });
831
+ if (node.entityId) row.addEventListener('dblclick', (event) => {
832
+ if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) { event.preventDefault(); return; }
833
+ event.preventDefault(); toggle(true);
834
+ sendAction({ action: 'drill', entityId: node.entityId, occurrencePath: node.occurrencePath, datasetKey: state.datasetKey });
835
+ });
836
+ row.addEventListener('keydown', (event) => {
837
+ if (event.key === 'ArrowRight') {
838
+ event.preventDefault();
839
+ if (row.getAttribute('aria-expanded') !== 'true') toggle(true);
840
+ else if (node.entityId) sendAction({ action: 'drill', entityId: node.entityId, occurrencePath: node.occurrencePath, datasetKey: state.datasetKey });
841
+ return;
842
+ }
843
+ if (event.key === 'ArrowLeft') {
844
+ if (row.getAttribute('aria-expanded') === 'true') { event.preventDefault(); event.stopPropagation(); toggle(false); }
845
+ else if (node.entityId && Number(state.snapshot?.drillDepth) > 0) {
846
+ event.preventDefault(); event.stopPropagation(); sendAction({ action: 'ascend', datasetKey: state.datasetKey });
847
+ }
848
+ return;
849
+ }
850
+ if (event.key === 'Escape' && node.entityId) {
851
+ event.preventDefault(); event.stopPropagation();
852
+ sendAction({ action: Number(state.snapshot?.drillDepth) > 0 ? 'ascend' : 'clear-selection', datasetKey: state.datasetKey });
853
+ }
854
+ });
855
+ row.__toggleTreeItem = toggle;
856
+ branch.append(row, children); parent.append(branch);
857
+ if (expanded && node.lazy && !node.children.length) requestLazyChildren();
858
+ continue;
859
+ }
777
860
  if (node.entityId) {
778
861
  row.dataset.entityId = node.entityId;
779
862
  row.classList.toggle('selected', selectedIdsOf(state.snapshot).includes(node.entityId));
863
+ row.setAttribute('aria-selected', String(selectedIdsOf(state.snapshot).includes(node.entityId)));
780
864
  if (node.entityId === state.snapshot?.selectedId) row.setAttribute('aria-current', 'true');
781
865
  const gridControl = state.snapshot?.gridVisibility?.entityId === node.entityId ? renderGridVisibility(state.snapshot.gridVisibility) : null;
782
866
  const item = document.createElement('div'); item.setAttribute('role', 'listitem');
@@ -788,41 +872,30 @@
788
872
  row.setAttribute('aria-expanded', String(expanded)); gridControl.hidden = !expanded;
789
873
  row.addEventListener('click', (event) => {
790
874
  const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); gridControl.hidden = !open;
791
- groupDisclosure.set(disclosureKey, open); selectRow(node.entityId, event);
875
+ groupDisclosure.set(disclosureKey, open); selectRow(node, event);
792
876
  });
793
877
  item.append(row, gridControl);
794
- } else { row.addEventListener('click', (event) => selectRow(node.entityId, event)); item.append(row); }
878
+ } else {
879
+ row.setAttribute('role', 'treeitem');
880
+ row.addEventListener('click', (event) => selectRow(node, event));
881
+ row.addEventListener('keydown', (event) => {
882
+ if (event.key !== 'Escape' && event.key !== 'ArrowLeft') return;
883
+ if (Number(state.snapshot?.drillDepth) > 0) {
884
+ event.preventDefault(); event.stopPropagation(); sendAction({ action: 'ascend', datasetKey: state.datasetKey });
885
+ } else if (event.key === 'Escape') {
886
+ event.preventDefault(); event.stopPropagation(); sendAction({ action: 'clear-selection', datasetKey: state.datasetKey });
887
+ }
888
+ });
889
+ item.append(row);
890
+ }
795
891
  parent.append(item); continue;
796
892
  }
797
- if (Array.isArray(node.children)) {
798
- const branch = document.createElement('div'); branch.className = 'left-model-branch'; branch.setAttribute('role', 'listitem');
799
- const disclosureKey = `${state.datasetKey}:${state.tab}:${node.groupId || node.label}`;
800
- const expanded = groupDisclosure.has(disclosureKey) ? groupDisclosure.get(disclosureKey) : !!node.expanded;
801
- row.setAttribute('aria-expanded', String(expanded));
802
- const children = document.createElement('div'); children.className = 'left-model-children'; children.setAttribute('role', 'list'); children.hidden = !expanded; append(node.children, children);
803
- const requestLazyChildren = () => {
804
- if (row.getAttribute('aria-busy') === 'true') return;
805
- const outstanding = [...pendingActions.values()].some((pending) => pending.kind === 'expand' && pending.disclosureKey === disclosureKey);
806
- if (outstanding) { row.setAttribute('aria-busy', 'true'); return; }
807
- row.setAttribute('aria-busy', 'true');
808
- const requestId = sendAction({ action: 'expand', groupId: node.groupId, datasetKey: state.datasetKey });
809
- if (requestId) pendingActions.set(requestId, { kind: 'expand', row, disclosureKey, commandId: row.dataset.commandId });
810
- else row.removeAttribute('aria-busy');
811
- };
812
- row.addEventListener('click', () => {
813
- if (node.lazy && !node.children.length) { requestLazyChildren(); return; }
814
- const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); children.hidden = !open;
815
- groupDisclosure.set(disclosureKey, open);
816
- if (node.selectable === true) sendAction({ action: 'select-group', groupId: node.groupId, datasetKey: state.datasetKey });
817
- });
818
- branch.append(row, children); parent.append(branch);
819
- if (expanded && node.lazy && !node.children.length) requestLazyChildren();
820
- } else {
893
+ else {
821
894
  const item = document.createElement('div'); item.setAttribute('role', 'listitem'); item.append(row); parent.append(item);
822
895
  }
823
896
  }
824
897
  };
825
- const tree = document.createElement('div'); tree.className = 'left-model-tree'; tree.setAttribute('role', 'list');
898
+ const tree = document.createElement('div'); tree.className = 'left-model-tree'; tree.setAttribute('role', 'tree');
826
899
  const count = nodes.reduce((sum, node) => sum + (Number(node?.count) || (node?.entityId ? 1 : 0)), 0);
827
900
  tree.setAttribute('aria-label', count ? `Model index, ${count} items` : 'Model index');
828
901
  append(nodes, tree); host.append(tree); host.scrollTop = scrollTop;
@@ -860,11 +933,13 @@
860
933
  if (gridControl) { row.setAttribute('aria-expanded', 'true'); gridControl.hidden = false; }
861
934
  const sequence = ++revealSequence;
862
935
  const generation = state.generation;
863
- const revision = state.revision;
864
936
  const schedule = window.requestAnimationFrame || ((callback) => callback());
865
937
  const center = (attempt = 0) => schedule(() => {
866
938
  const liveIds = Array.isArray(state.snapshot?.selectedIds) ? state.snapshot.selectedIds : [];
867
- if (sequence !== revealSequence || generation !== state.generation || revision !== state.revision
939
+ // Not the message revision: any later message bumps it, an action's answer included, and that dropped the scroll
940
+ // while the line below still said the row was centred. The row is looked up again here, so what matters is that
941
+ // the selection is still this one.
942
+ if (sequence !== revealSequence || generation !== state.generation
868
943
  || !state.followSelection || state.snapshot?.selectionOrigin !== 'viewport'
869
944
  || liveIds.length !== 1 || liveIds[0] !== selectedId) return;
870
945
  if (!shown('model') || sections.model.hidden) { pendingRevealId = selectedId; return; }
@@ -884,7 +959,10 @@
884
959
  const top = Math.max(0, Math.min(maxTop, target));
885
960
  const reducedMotion = typeof window.matchMedia === 'function'
886
961
  && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
887
- modelContent.scrollTo?.({ top, left: Number(modelContent.scrollLeft) || 0, behavior: reducedMotion ? 'auto' : 'smooth' });
962
+ // A row more than two screens away is jumped to. Gliding past hundreds of rows shows nothing useful, and a long
963
+ // glide is still running when the tree repaints after the pick, which stops it short of the row (Take 5: 19,000 px).
964
+ const far = Math.abs(top - currentTop) > viewportHeight * 2;
965
+ modelContent.scrollTo?.({ top, left: Number(modelContent.scrollLeft) || 0, behavior: reducedMotion || far ? 'auto' : 'smooth' });
888
966
  pendingRevealId = null;
889
967
  status.textContent = `${liveRow.querySelector('.row-label')?.textContent || 'Selected object'} centred in Model tree.`;
890
968
  });
@@ -985,21 +1063,38 @@
985
1063
  // A list row click, as in a file explorer: Ctrl (⌘) adds or removes the row, Shift takes every row from the last one
986
1064
  // clicked to this one in the order shown (rows in closed groups are skipped), and Ctrl+Shift adds that range. The
987
1065
  // main window works out the ids because it draws the rows; the editor selects them.
988
- function selectRow(id, event) {
1066
+ function selectRow(node, event) {
1067
+ if ((event.ctrlKey || event.metaKey) && event.shiftKey) { event.preventDefault(); return false; }
1068
+ const id = node.entityId;
989
1069
  const current = pendingSelectIds ?? selectedIdsOf(state.snapshot), add = event.ctrlKey || event.metaKey;
990
- let ids;
991
- if (event.shiftKey && selectAnchor) {
992
- const order = [...new Set([...modelContent.querySelectorAll('[data-entity-id]')]
993
- .filter((row) => !row.closest('[hidden]')).map((row) => row.dataset.entityId))];
994
- const from = order.indexOf(selectAnchor), to = order.indexOf(id);
995
- if (from < 0) selectAnchor = id; // the anchor is no longer shown (closed, or another tab): this row starts the next range
996
- const range = from < 0 || to < 0 ? [id] : order.slice(Math.min(from, to), Math.max(from, to) + 1);
1070
+ const pathOf = (row) => {
1071
+ try {
1072
+ const path = JSON.parse(row.dataset.occurrencePath || 'null');
1073
+ return Array.isArray(path) && path.length && path.every((part) => typeof part === 'string') ? path : [row.dataset.entityId];
1074
+ } catch { return [row.dataset.entityId]; }
1075
+ };
1076
+ const clickedOccurrence = { entityId: id, occurrencePath: Array.isArray(node.occurrencePath) ? [...node.occurrencePath] : [id] };
1077
+ let ids; let occurrences;
1078
+ const hierarchyOccurrence = Number.isInteger(state.snapshot?.drillDepth) && Array.isArray(node.occurrencePath) && node.occurrencePath.length > 0;
1079
+ if (event.shiftKey && hierarchyOccurrence) {
1080
+ occurrences = [clickedOccurrence]; ids = [...new Set([...current, id])];
1081
+ selectAnchor = JSON.stringify(clickedOccurrence.occurrencePath);
1082
+ } else if (event.shiftKey && selectAnchor) {
1083
+ const order = [...modelContent.querySelectorAll('[data-entity-id]')].filter((row) => !row.closest('[hidden]'))
1084
+ .map((row) => ({ entityId: row.dataset.entityId, occurrencePath: pathOf(row) }));
1085
+ const keys = order.map((item) => JSON.stringify(item.occurrencePath)); const clickedKey = JSON.stringify(clickedOccurrence.occurrencePath);
1086
+ const from = keys.indexOf(selectAnchor), to = keys.indexOf(clickedKey);
1087
+ if (from < 0) selectAnchor = clickedKey;
1088
+ occurrences = from < 0 || to < 0 ? [clickedOccurrence] : order.slice(Math.min(from, to), Math.max(from, to) + 1);
1089
+ const range = occurrences.map((item) => item.entityId);
997
1090
  ids = add ? [...new Set([...current, ...range])] : range;
998
1091
  } else {
999
1092
  ids = !add ? [id] : current.includes(id) ? current.filter((other) => other !== id) : [...current, id];
1000
- selectAnchor = id;
1093
+ occurrences = [clickedOccurrence]; selectAnchor = JSON.stringify(clickedOccurrence.occurrencePath);
1001
1094
  }
1002
- if (sendAction({ action: 'select', entityId: id, entityIds: ids })) pendingSelectIds = ids;
1095
+ const operation = event.ctrlKey || event.metaKey ? 'toggle' : event.shiftKey ? 'add' : 'replace';
1096
+ if (sendAction({ action: 'select', entityId: id, entityIds: ids, occurrence: clickedOccurrence, occurrences, operation })) pendingSelectIds = ids;
1097
+ return true;
1003
1098
  }
1004
1099
  function sendAction(action) {
1005
1100
  const requestId = `${state.generation}:${++nextActionId}`;
@@ -1047,6 +1142,11 @@
1047
1142
  else window.Instructor?.clear?.();
1048
1143
  }
1049
1144
  }
1145
+ if (pending?.kind === 'load-more' && data.ok) {
1146
+ const firstNew = [...modelContent.querySelectorAll('[role="treeitem"][data-occurrence-path]')]
1147
+ .find((row) => !pending.seenPaths.has(row.dataset.occurrencePath));
1148
+ firstNew?.focus();
1149
+ }
1050
1150
  if (!data.ok) status.textContent = data.message || 'That model action is no longer available.';
1051
1151
  // The frame stays empty, so say so where the tab would be — for the tab still shown, not an earlier one.
1052
1152
  if (pending?.kind === 'panel' && !data.ok && pending.key === panelShown) {
@@ -1080,13 +1180,16 @@
1080
1180
  state.snapshot.focusEntityId = typeof data.focusEntityId === 'string' ? data.focusEntityId : null;
1081
1181
  state.snapshot.geometrySelectionIds = data.geometrySelectionIds.filter((id) => typeof id === 'string');
1082
1182
  }
1183
+ if (Number.isInteger(data.drillDepth) && data.drillDepth >= 0) state.snapshot.drillDepth = data.drillDepth;
1083
1184
  state.snapshot.subjects = data.subjects && typeof data.subjects === 'object' ? data.subjects : null;
1084
1185
  }
1085
1186
  announceSelection();
1086
1187
  pendingSelectIds = null;
1087
1188
  const picked = selectedIdsOf(data);
1088
1189
  modelContent.querySelectorAll('[data-entity-id]').forEach((row) => {
1089
- row.classList.toggle('selected', picked.includes(row.dataset.entityId));
1190
+ const isSelected = picked.includes(row.dataset.entityId);
1191
+ row.classList.toggle('selected', isSelected);
1192
+ if (row.getAttribute('role') === 'treeitem') row.setAttribute('aria-selected', String(isSelected));
1090
1193
  if (row.dataset.entityId === data.selectedId) row.setAttribute('aria-current', 'true'); else row.removeAttribute('aria-current');
1091
1194
  });
1092
1195
  if (state.followSelection && state.snapshot?.selectedIds?.length === 1) { renderModel(); revealSelectedEntity(); }
@@ -157,6 +157,16 @@ body:has(.model-inspector-resizer.drag) .model-inspector-panel,body:has(.model-i
157
157
  .model-select-bar button:focus-visible,.model-snap-bar button:focus-visible,.model-module-actions button:focus-visible{outline:2px solid var(--brand,var(--accent,#60a5fa));outline-offset:1px}
158
158
  .model-select-bar button .car{position:absolute;right:1px;bottom:0;font-size:8px;opacity:.7;pointer-events:none}
159
159
  .model-select-bar button .seldot{position:absolute;top:2px;right:2px;width:6px;height:6px;border-radius:50%;background:var(--brand,var(--accent,#60a5fa));box-shadow:0 0 0 1.5px var(--panel)}
160
+ .model-selection-scope{display:flex;align-items:center;gap:1px;padding-right:3px;margin-right:2px;border-right:1px solid var(--line)}
161
+ .model-selection-scope button{width:auto;min-width:42px;grid-template-columns:16px auto;gap:3px;padding:0 5px;font-size:10px;font-weight:650;letter-spacing:.02em}
162
+ .model-selection-scope button svg{width:15px;height:15px}
163
+ .model-scope-short{line-height:1;white-space:nowrap}
164
+ .model-select-bar .model-scope-ascend{width:auto;height:28px;padding:0 8px;font-size:10px;font-weight:700}
165
+ .model-scope-status{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
166
+ .tekla-hierarchy-disclosure{display:grid;place-items:center;width:22px;min-width:22px;align-self:stretch;border-radius:4px;color:var(--mut,var(--muted));cursor:pointer;padding:0;font-size:14px}
167
+ .tekla-hierarchy-disclosure:hover{background:rgba(148,163,184,.12);color:var(--text)}
168
+ .tekla-hierarchy-disclosure:focus-visible{outline:2px solid var(--brand,var(--accent,#60a5fa));outline-offset:-2px}
169
+ .tekla-hierarchy-branch>.revit-tree-children{margin-left:11px;border-left:1px solid var(--line)}
160
170
  .model-snap-bar button{color:var(--model-snap-ink,#22d3ee)}
161
171
  .model-snap-bar [data-snap3d]{font-size:11px;font-weight:700;letter-spacing:.02em;margin-left:4px;border-left:1px solid var(--line);border-radius:0 5px 5px 0;padding-left:4px;box-sizing:border-box;width:32px}
162
172
  .model-module-actions{gap:5px}
@@ -0,0 +1,331 @@
1
+ /*
2
+ * Provider-neutral semantic selection for nested model groups.
3
+ *
4
+ * Providers authenticate the graph and expose it through the ports below. This module owns only
5
+ * selection meaning: group-vs-objects scope, exact occurrence anchors, drill overrides, budgets,
6
+ * and one atomic commit boundary. It deliberately knows neither Tekla nor Steel schemas.
7
+ */
8
+
9
+ export const MODEL_GROUP_NAVIGATOR_SCHEMA = 'floless.model-group-navigator/v1';
10
+ export const MODEL_GROUP_GEOMETRY_CAP = 5000;
11
+ export const MODEL_GROUP_NODE_CAP = 50000;
12
+ export const MODEL_GROUP_DEPTH_CAP = 256;
13
+
14
+ const frozen = (value) => Object.freeze(value);
15
+ const freezeOccurrence = (value) => frozen({ entityId: String(value.entityId), occurrencePath: frozen([...(value.occurrencePath || [value.entityId])].map(String)) });
16
+ const emptyState = () => frozen({ generation: null, selectedItems: frozen([]), primaryEntityId: null, geometryIds: frozen([]), drillStack: frozen([]) });
17
+
18
+ function scopesOf(value) {
19
+ const scope = value || {};
20
+ if (!['group', 'objects'].includes(scope.connection) || !['group', 'objects'].includes(scope.assembly)) {
21
+ throw new TypeError('Group selection scopes must be group or objects.');
22
+ }
23
+ return scope;
24
+ }
25
+
26
+ /**
27
+ * @param {{
28
+ * isGroup:(id:string)=>boolean,
29
+ * groupKind?:(id:string)=>('connection'|'assembly'|null),
30
+ * childrenOf:(id:string)=>string[],
31
+ * hasGeometry:(id:string)=>boolean,
32
+ * groupCandidatesOfPick:(id:string)=>{connection?:string[],assembly?:string[]},
33
+ * commitSelection:(proposal:any)=>boolean|void,
34
+ * generation?:()=>any,
35
+ * }} ports
36
+ */
37
+ export function createModelGroupNavigator(ports) {
38
+ for (const name of ['isGroup', 'childrenOf', 'hasGeometry', 'groupCandidatesOfPick', 'commitSelection']) {
39
+ if (typeof ports?.[name] !== 'function') throw new TypeError(`Model group navigator needs ${name}().`);
40
+ }
41
+ let state = emptyState();
42
+ const listeners = new Set();
43
+ const publish = () => { for (const listener of listeners) listener(state); };
44
+
45
+ const walkTerminals = (root, rootPath) => {
46
+ const items = []; const itemSeen = new Set(); const geometryIds = []; const geometrySeen = new Set(); const visited = new Set();
47
+ const stack = [{ id: root, path: rootPath, depth: 0 }]; let visitedCount = 0;
48
+ while (stack.length) {
49
+ const current = stack.pop();
50
+ if (++visitedCount > MODEL_GROUP_NODE_CAP || current.depth > MODEL_GROUP_DEPTH_CAP) return { ok: false, reason: 'hierarchy-cap' };
51
+ const occurrenceToken = JSON.stringify(current.path);
52
+ if (visited.has(occurrenceToken)) return { ok: false, reason: 'hierarchy-integrity' };
53
+ visited.add(occurrenceToken);
54
+ const children = ports.isGroup(current.id) ? [...(ports.childrenOf(current.id) || [])] : [];
55
+ if (!children.length) {
56
+ if (!itemSeen.has(current.id)) { itemSeen.add(current.id); items.push(freezeOccurrence({ entityId: current.id, occurrencePath: current.path })); }
57
+ if (ports.hasGeometry(current.id) && !geometrySeen.has(current.id)) {
58
+ geometrySeen.add(current.id); geometryIds.push(current.id);
59
+ if (geometryIds.length > MODEL_GROUP_GEOMETRY_CAP) return { ok: false, reason: 'geometry-cap' };
60
+ }
61
+ continue;
62
+ }
63
+ for (let index = children.length - 1; index >= 0; index--) {
64
+ const child = String(children[index]);
65
+ if (current.path.includes(child)) return { ok: false, reason: 'hierarchy-integrity' };
66
+ stack.push({ id: child, path: [...current.path, child], depth: current.depth + 1 });
67
+ }
68
+ }
69
+ return { ok: true, items, geometryIds, visitedCount };
70
+ };
71
+
72
+ const pathUnder = (rootOccurrence, targetId) => {
73
+ const stack = [{ id: rootOccurrence.entityId, path: [...rootOccurrence.occurrencePath], depth: 0 }]; let visited = 0;
74
+ while (stack.length) {
75
+ const current = stack.pop();
76
+ if (++visited > MODEL_GROUP_NODE_CAP || current.depth > MODEL_GROUP_DEPTH_CAP) return null;
77
+ if (current.id === targetId) return current.path;
78
+ const children = ports.isGroup(current.id) ? [...(ports.childrenOf(current.id) || [])] : [];
79
+ for (let index = children.length - 1; index >= 0; index--) {
80
+ const child = String(children[index]);
81
+ if (!current.path.includes(child)) stack.push({ id: child, path: [...current.path, child], depth: current.depth + 1 });
82
+ }
83
+ }
84
+ return null;
85
+ };
86
+
87
+ const targetFor = (occurrence, scopeValue, options = {}) => {
88
+ const scopes = scopesOf(scopeValue); let picked = freezeOccurrence(occurrence);
89
+ let resolvedId = picked.entityId; let resolvedPath = picked.occurrencePath;
90
+ const activeDrill = state.drillStack.at(-1);
91
+ if (activeDrill && picked.occurrencePath.length === 1) {
92
+ const anchored = pathUnder(activeDrill, picked.entityId);
93
+ if (anchored) picked = freezeOccurrence({ entityId: picked.entityId, occurrencePath: anchored });
94
+ resolvedPath = picked.occurrencePath;
95
+ }
96
+ const drilled = !!activeDrill && activeDrill.occurrencePath.every((id, index) => picked.occurrencePath[index] === id);
97
+ const exitDrill = state.drillStack.length > 0 && (!drilled || options.altAssembly === true);
98
+ const candidates = ports.groupCandidatesOfPick(picked.entityId) || {};
99
+ if (options.altAssembly === true) {
100
+ const assembly = candidates.assembly?.[0];
101
+ if (!assembly) return frozen({ ok: false, reason: 'no-assembly' });
102
+ resolvedId = String(assembly); resolvedPath = frozen([resolvedId]);
103
+ } else if (!drilled && !ports.isGroup(picked.entityId)) {
104
+ const connection = scopes.connection === 'group' ? candidates.connection?.[0] : null;
105
+ const assembly = scopes.assembly === 'group' ? candidates.assembly?.[0] : null;
106
+ if (connection) { resolvedId = String(connection); resolvedPath = frozen([resolvedId]); }
107
+ else if (assembly) { resolvedId = String(assembly); resolvedPath = frozen([resolvedId]); }
108
+ }
109
+ const kind = ports.groupKind?.(resolvedId) ?? (candidates.connection?.includes(resolvedId) ? 'connection' : candidates.assembly?.includes(resolvedId) ? 'assembly' : null);
110
+ return frozen({ ok: true, occurrence: freezeOccurrence({ entityId: resolvedId, occurrencePath: resolvedPath }), kind, exitDrill });
111
+ };
112
+
113
+ const proposalFor = (occurrence, scopeValue, options = {}) => {
114
+ const scopes = scopesOf(scopeValue);
115
+ const target = options._target ?? targetFor(occurrence, scopes, options);
116
+ if (!target.ok) return target;
117
+ const generation = ports.generation?.() ?? null;
118
+ const resolvedId = target.occurrence.entityId; const resolvedPath = target.occurrence.occurrencePath;
119
+ const exitDrill = target.exitDrill;
120
+ const activeDrill = state.drillStack.at(-1);
121
+ const drilled = !!activeDrill && activeDrill.occurrencePath.every((id, index) => resolvedPath[index] === id);
122
+ const kind = target.kind;
123
+ const expands = ports.isGroup(resolvedId) && options.altAssembly !== true
124
+ && ((kind === 'connection' && scopes.connection === 'objects') || (kind === 'assembly' && scopes.assembly === 'objects') || !kind);
125
+ const drillExpands = ports.isGroup(resolvedId) && drilled && options.altAssembly !== true;
126
+ let selectedItems; let geometryIds; let traversalCount = 1;
127
+ if (expands || drillExpands) {
128
+ const walked = walkTerminals(resolvedId, [...resolvedPath]);
129
+ if (!walked.ok) return frozen(walked);
130
+ selectedItems = walked.items; geometryIds = walked.geometryIds; traversalCount = walked.visitedCount;
131
+ } else if (ports.isGroup(resolvedId)) {
132
+ const walked = walkTerminals(resolvedId, [...resolvedPath]);
133
+ if (!walked.ok) return frozen(walked);
134
+ selectedItems = [freezeOccurrence({ entityId: resolvedId, occurrencePath: resolvedPath })]; geometryIds = walked.geometryIds; traversalCount = walked.visitedCount;
135
+ } else {
136
+ selectedItems = [freezeOccurrence({ entityId: resolvedId, occurrencePath: resolvedPath })];
137
+ geometryIds = ports.hasGeometry(resolvedId) ? [resolvedId] : [];
138
+ }
139
+ const operation = options.operation ?? 'replace';
140
+ if (operation === 'add' || operation === 'toggle') {
141
+ const incoming = new Map(selectedItems.map((item) => [item.entityId, item]));
142
+ const combined = [...state.selectedItems]; const existing = new Map(combined.map((item, index) => [item.entityId, index]));
143
+ const removeIncoming = operation === 'toggle' && selectedItems.length > 0 && selectedItems.every((item) => existing.has(item.entityId));
144
+ for (const item of selectedItems) {
145
+ if (removeIncoming && existing.has(item.entityId)) {
146
+ combined[existing.get(item.entityId)] = null;
147
+ } else if (!existing.has(item.entityId)) combined.push(item);
148
+ }
149
+ selectedItems = combined.filter(Boolean);
150
+ const nextGeometry = []; const seenGeometry = new Set(); let visited = 0;
151
+ for (const item of selectedItems) {
152
+ const resolved = ports.isGroup(item.entityId) ? walkTerminals(item.entityId, [...item.occurrencePath])
153
+ : { ok: true, geometryIds: ports.hasGeometry(item.entityId) ? [item.entityId] : [], visitedCount: 1 };
154
+ if (!resolved.ok) return frozen(resolved);
155
+ visited += resolved.visitedCount ?? 1;
156
+ if (visited > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
157
+ for (const geometryId of resolved.geometryIds) if (!seenGeometry.has(geometryId)) {
158
+ seenGeometry.add(geometryId); nextGeometry.push(geometryId);
159
+ if (nextGeometry.length > MODEL_GROUP_GEOMETRY_CAP) return frozen({ ok: false, reason: 'geometry-cap' });
160
+ }
161
+ }
162
+ geometryIds = nextGeometry;
163
+ traversalCount = visited;
164
+ const added = selectedItems.filter((item) => incoming.has(item.entityId));
165
+ options = { ...options, primaryEntityId: added.at(-1)?.entityId ?? selectedItems.at(-1)?.entityId ?? null };
166
+ }
167
+ return frozen({ ok: true, generation, selectedItems: frozen(selectedItems), primaryEntityId: options.primaryEntityId ?? selectedItems[0]?.entityId ?? null,
168
+ geometryIds: frozen(geometryIds), origin: options.origin ?? 'model', operation, exitDrill, traversalCount });
169
+ };
170
+
171
+ const mergeSelection = (incomingItems, operation) => {
172
+ if (operation !== 'add' && operation !== 'toggle') return [...incomingItems];
173
+ const combined = [...state.selectedItems];
174
+ const positions = new Map(combined.map((item, index) => [item.entityId, index]));
175
+ const removeIncoming = operation === 'toggle' && incomingItems.length > 0 && incomingItems.every((item) => positions.has(item.entityId));
176
+ for (const item of incomingItems) {
177
+ const key = item.entityId;
178
+ if (removeIncoming && positions.has(key)) combined[positions.get(key)] = null;
179
+ else if (!positions.has(key)) combined.push(item);
180
+ }
181
+ return combined.filter(Boolean);
182
+ };
183
+
184
+ const geometryForItems = (items) => {
185
+ const geometryIds = []; const seenGeometry = new Set(); let visited = 0;
186
+ for (const item of items) {
187
+ const resolved = ports.isGroup(item.entityId) ? walkTerminals(item.entityId, [...item.occurrencePath])
188
+ : { ok: true, geometryIds: ports.hasGeometry(item.entityId) ? [item.entityId] : [], visitedCount: 1 };
189
+ if (!resolved.ok) return resolved;
190
+ visited += resolved.visitedCount ?? 1;
191
+ if (visited > MODEL_GROUP_NODE_CAP) return { ok: false, reason: 'hierarchy-cap' };
192
+ for (const geometryId of resolved.geometryIds) if (!seenGeometry.has(geometryId)) {
193
+ seenGeometry.add(geometryId); geometryIds.push(geometryId);
194
+ if (geometryIds.length > MODEL_GROUP_GEOMETRY_CAP) return { ok: false, reason: 'geometry-cap' };
195
+ }
196
+ }
197
+ return { ok: true, geometryIds, visitedCount: visited };
198
+ };
199
+
200
+ const commit = (proposal, { exitDrill = false } = {}) => {
201
+ if (!proposal.ok) return proposal;
202
+ if ((ports.generation?.() ?? null) !== proposal.generation) return frozen({ ok: false, reason: 'stale-generation' });
203
+ if (ports.commitSelection(proposal) === false) return frozen({ ok: false, reason: 'commit-refused' });
204
+ state = frozen({ generation: proposal.generation, selectedItems: proposal.selectedItems, primaryEntityId: proposal.primaryEntityId,
205
+ geometryIds: proposal.geometryIds, drillStack: exitDrill ? frozen([]) : state.drillStack });
206
+ publish();
207
+ return proposal;
208
+ };
209
+
210
+ const proposalMany = (occurrences, scopes, options = {}) => {
211
+ const targets = []; const seenTargets = new Set(); let exitDrill = false;
212
+ for (const occurrence of occurrences || []) {
213
+ const target = targetFor(occurrence, scopes, options);
214
+ if (!target.ok) return target;
215
+ exitDrill ||= target.exitDrill === true;
216
+ const key = `${target.occurrence.entityId}\u0000${target.occurrence.occurrencePath.join('\u0000')}`;
217
+ if (!seenTargets.has(key)) { seenTargets.add(key); targets.push(target); }
218
+ }
219
+ const selectedItems = []; const geometryIds = []; const seenItems = new Set(); const seenGeometry = new Set(); let traversed = 0;
220
+ for (const target of targets) {
221
+ const proposal = proposalFor(target.occurrence, scopes, { ...options, operation: 'replace', _target: target });
222
+ if (!proposal.ok) return proposal;
223
+ traversed += proposal.traversalCount ?? 1;
224
+ if (traversed > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
225
+ for (const item of proposal.selectedItems) if (!seenItems.has(item.entityId)) {
226
+ seenItems.add(item.entityId); selectedItems.push(item);
227
+ if (selectedItems.length > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
228
+ }
229
+ for (const id of proposal.geometryIds) if (!seenGeometry.has(id)) {
230
+ seenGeometry.add(id); geometryIds.push(id);
231
+ if (geometryIds.length > MODEL_GROUP_GEOMETRY_CAP) return frozen({ ok: false, reason: 'geometry-cap' });
232
+ }
233
+ }
234
+ const operation = options.operation ?? 'replace';
235
+ const mergedItems = mergeSelection(selectedItems, operation);
236
+ if (mergedItems.length > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
237
+ const mergedGeometry = operation === 'replace' ? { ok: true, geometryIds } : geometryForItems(mergedItems);
238
+ if (!mergedGeometry.ok) return frozen(mergedGeometry);
239
+ const incomingIds = new Set(selectedItems.map((item) => item.entityId));
240
+ const primaryEntityId = operation === 'replace' ? mergedItems[0]?.entityId ?? null
241
+ : mergedItems.filter((item) => incomingIds.has(item.entityId)).at(-1)?.entityId ?? mergedItems.at(-1)?.entityId ?? null;
242
+ return frozen({ ok: true, generation: ports.generation?.() ?? null, selectedItems: frozen(mergedItems),
243
+ primaryEntityId, geometryIds: frozen(mergedGeometry.geometryIds), origin: options.origin ?? 'model', operation, exitDrill });
244
+ };
245
+
246
+ return frozen({
247
+ schema: MODEL_GROUP_NAVIGATOR_SCHEMA,
248
+ state: () => state,
249
+ subscribe(listener) { if (typeof listener !== 'function') throw new TypeError('Navigator subscriber must be a function.'); listeners.add(listener); listener(state); return () => listeners.delete(listener); },
250
+ resolve: proposalFor,
251
+ resolveMany: proposalMany,
252
+ resolveResolved(occurrences) {
253
+ const selectedItems = []; const seen = new Set();
254
+ for (const value of occurrences || []) {
255
+ const item = freezeOccurrence(value);
256
+ if (!item.occurrencePath.length || item.occurrencePath.at(-1) !== item.entityId) return frozen({ ok: false, reason: 'hierarchy-integrity' });
257
+ if (seen.has(item.entityId)) continue;
258
+ seen.add(item.entityId); selectedItems.push(item);
259
+ if (selectedItems.length > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
260
+ }
261
+ const geometry = geometryForItems(selectedItems);
262
+ if (!geometry.ok) return frozen(geometry);
263
+ return frozen({ ok: true, selectedItems: frozen(selectedItems), primaryEntityId: selectedItems[0]?.entityId ?? null,
264
+ geometryIds: frozen(geometry.geometryIds) });
265
+ },
266
+ synchronizeSelection(occurrences, primaryEntityId = null) {
267
+ const proposal = this.resolveResolved(occurrences);
268
+ if (!proposal.ok) return proposal;
269
+ state = frozen({ ...state, generation: ports.generation?.() ?? null, selectedItems: proposal.selectedItems,
270
+ primaryEntityId: proposal.selectedItems.some((item) => item.entityId === primaryEntityId) ? primaryEntityId : proposal.primaryEntityId,
271
+ geometryIds: proposal.geometryIds });
272
+ publish(); return proposal;
273
+ },
274
+ select(occurrence, scopes, options = {}) {
275
+ const proposal = proposalFor(occurrence, scopes, options);
276
+ return commit(proposal, { exitDrill: proposal.ok && (options.altAssembly === true || proposal.exitDrill === true) });
277
+ },
278
+ selectMany(occurrences, scopes, options = {}) {
279
+ const proposal = proposalMany(occurrences, scopes, options);
280
+ return commit(proposal, { exitDrill: proposal.ok && proposal.exitDrill === true });
281
+ },
282
+ selectResolved(occurrences, options = {}) {
283
+ const incoming = []; const seen = new Set();
284
+ for (const value of occurrences || []) {
285
+ const item = freezeOccurrence(value);
286
+ if (!item.occurrencePath.length || item.occurrencePath.at(-1) !== item.entityId) return frozen({ ok: false, reason: 'hierarchy-integrity' });
287
+ const key = item.entityId;
288
+ if (seen.has(key)) continue;
289
+ seen.add(key); incoming.push(item);
290
+ if (incoming.length > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
291
+ }
292
+ const operation = options.operation ?? 'replace';
293
+ if (!['replace', 'add', 'toggle'].includes(operation)) return frozen({ ok: false, reason: 'invalid-operation' });
294
+ const selectedItems = mergeSelection(incoming, operation);
295
+ if (selectedItems.length > MODEL_GROUP_NODE_CAP) return frozen({ ok: false, reason: 'hierarchy-cap' });
296
+ const geometry = geometryForItems(selectedItems);
297
+ if (!geometry.ok) return frozen(geometry);
298
+ const incomingKeys = new Set(incoming.map((item) => item.entityId));
299
+ const primaryEntityId = operation === 'replace' ? selectedItems[0]?.entityId ?? null
300
+ : selectedItems.filter((item) => incomingKeys.has(item.entityId)).at(-1)?.entityId ?? selectedItems.at(-1)?.entityId ?? null;
301
+ const activeDrill = state.drillStack.at(-1);
302
+ const inDrill = !activeDrill || incoming.every((item) => activeDrill.occurrencePath.every((id, index) => item.occurrencePath[index] === id));
303
+ return commit(frozen({ ok: true, generation: ports.generation?.() ?? null, selectedItems: frozen(selectedItems),
304
+ primaryEntityId, geometryIds: frozen(geometry.geometryIds), origin: options.origin ?? 'model', operation }),
305
+ { exitDrill: options.exitDrill === true || !inDrill });
306
+ },
307
+ enter(groupOccurrence) {
308
+ const occurrence = freezeOccurrence(groupOccurrence);
309
+ if (!ports.isGroup(occurrence.entityId) || occurrence.occurrencePath.at(-1) !== occurrence.entityId) return false;
310
+ for (let index = 1; index < occurrence.occurrencePath.length; index++) {
311
+ if (!(ports.childrenOf(occurrence.occurrencePath[index - 1]) || []).map(String).includes(occurrence.occurrencePath[index])) return false;
312
+ }
313
+ const active = state.drillStack.at(-1);
314
+ if (active && active.occurrencePath.length === occurrence.occurrencePath.length
315
+ && active.occurrencePath.every((id, index) => occurrence.occurrencePath[index] === id)) return false;
316
+ const nested = active && active.occurrencePath.length < occurrence.occurrencePath.length
317
+ && active.occurrencePath.every((id, index) => occurrence.occurrencePath[index] === id);
318
+ state = frozen({ ...state, drillStack: frozen(nested ? [...state.drillStack, occurrence] : [occurrence]) }); publish(); return true;
319
+ },
320
+ ascend() {
321
+ if (!state.drillStack.length) return false;
322
+ state = frozen({ ...state, drillStack: frozen(state.drillStack.slice(0, -1)) }); publish(); return true;
323
+ },
324
+ clear() {
325
+ const generation = ports.generation?.() ?? null;
326
+ const proposal = frozen({ ok: true, generation, selectedItems: frozen([]), primaryEntityId: null, geometryIds: frozen([]), origin: 'model', operation: 'clear' });
327
+ if (ports.commitSelection(proposal) === false) return false;
328
+ state = frozen({ ...emptyState(), generation }); publish(); return true;
329
+ },
330
+ });
331
+ }