@floless/app 0.155.1 → 0.155.2

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.
@@ -16,7 +16,7 @@ import { mountModelOrientationOverlay } from './model-orientation-overlay.js';
16
16
  import { mountModelMeasureTool } from './model-measure.js';
17
17
  import { createModelCadToolController } from './model-cad-tools.js';
18
18
  import { createModelSelectionTools } from './model-selection-tools.js';
19
- import { mountModelPointerDock, readOnlyModelPointerDockPlan, REVIT_POINTER_DOCK_PLAN } from './model-pointer-dock.js';
19
+ import { mountModelPointerDock, teklaModelPointerDockPlan, REVIT_POINTER_DOCK_PLAN } from './model-pointer-dock.js';
20
20
  import { createModelSpatialTools } from './model-spatial-tools.js';
21
21
  import { mountModelSpatialPanel } from './model-spatial-panel.js';
22
22
  import { createModelClipSession } from './model-clip-session.js';
@@ -30,7 +30,8 @@ import { createModelPanelBridge, createModelSelectionOriginGuard, createPanelHos
30
30
  import { mountModelDisplayUnits } from './model-display-units.js';
31
31
  import { formatModelProperty, teklaObjectFields, teklaObjectLabel, teklaPropertyGroups, teklaTypeGroups } from './model-property-display.js';
32
32
  import { formatLength, parseLengthMm } from './display-units.js';
33
- import { TEKLA_GEOMETRY_SELECTION_CAP, teklaAssemblyMembership, teklaGeometrySelection } from './model-tekla-selection.js';
33
+ import { TEKLA_GEOMETRY_SELECTION_CAP, changeTeklaSelectionScope, readTeklaSelectionScopes, teklaAssemblyMembership, teklaGeometrySelection, teklaHierarchyIndexes } from './model-tekla-selection.js';
34
+ import { createModelGroupNavigator } from './model-group-navigator.js';
34
35
  import { displayNeedsSelection, dominantColour, evaluateModelViewQuery, objectFact, parseModelViewCommand, propertyFact } from './model-view-query.js';
35
36
  import { modelSubjectLabel, renderChatQuestions, subjectLabelText, subjectsKeyOf } from './model-chat-questions.js';
36
37
 
@@ -83,7 +84,12 @@ let propertyDisplayRefresh = new Set();
83
84
  let toolbarChrome = null;
84
85
  let lightingPanel = null;
85
86
  let teklaAssemblyMembers = new Map();
87
+ let teklaHierarchy = teklaHierarchyIndexes([], []);
88
+ let teklaGroupNavigator = null;
89
+ let teklaHierarchyGeneration = 0;
90
+ let teklaSelectionScopes = readTeklaSelectionScopes(localStorage);
86
91
  let geometrySelectionIds = [];
92
+ let lastSelectionHoverHit = null;
87
93
  let terminalDisposed = false;
88
94
  let bfcacheSuspended = false;
89
95
  let revisionLoadToken = 0;
@@ -276,10 +282,13 @@ const TEKLA_AUDIT_COPY = Object.freeze({
276
282
  'weld-recipes-unevaluated': Object.freeze({ group: 'shape-not-evaluated', title: 'Shape detail not evaluated', detail: 'Some weld-shape instructions were preserved as database facts but were not evaluated into display geometry.' }),
277
283
  'grid-mapping-unevaluated': Object.freeze({ group: 'shape-not-evaluated', title: 'Grid not shown in 3D', detail: 'This grid is present in the Tekla database, but its display extents could not be mapped safely.' }),
278
284
  'grid-record-undecoded': Object.freeze({ group: 'not-shown', title: 'Grid not shown in 3D', detail: 'This grid is in the Tekla model, but it could not be drawn: the model has more than one grid, or its grid record could not be read. The rest of the model is unaffected. To see the grid, keep one grid in the Tekla model and read the model again; if it is still not shown, use Report an issue.' }),
285
+ 'uda-value-unreadable': Object.freeze({ group: 'property-not-read', title: 'UDA not read', detail: 'An unreadable user-defined attribute value was omitted. The object’s other readable properties and verified relationships were kept.' }),
279
286
  'unsupported-native-type': Object.freeze({ group: 'shape-not-evaluated', title: 'Shape detail not evaluated', detail: 'This native Tekla object type is recorded but is not yet interpreted by the parser.' }),
280
287
  // #1836: the model was read without a Tekla catalogue file the person chose to continue without.
281
288
  'profile-catalogue-missing': Object.freeze({ group: 'shape-not-evaluated', title: 'Shown as a stand-in bar', detail: 'This part’s profile shape isn’t known because profdb.bin was missing, so it is drawn as a thin stand-in bar where it can be placed. Read the model again with that file for the real shape.' }),
282
289
  'bolt-catalogue-missing': Object.freeze({ group: 'not-shown', title: 'Bolt not drawn', detail: 'This bolt needs a catalogue file that was missing (screwdb.db or assdb.db), so it is not drawn. Read the model again with the file to see it.' }),
290
+ 'component-parent-unverified': Object.freeze({ group: 'hierarchy-not-confirmed', title: 'Connection hierarchy not confirmed', detail: 'This object remains in the imported model, but the parser could not verify its recorded Connection or Component parent from the available database records. The unverified hierarchy link was omitted.' }),
291
+ 'assembly-parent-unverified': Object.freeze({ group: 'hierarchy-not-confirmed', title: 'Assembly hierarchy not confirmed', detail: 'This object remains in the imported model, but the parser could not verify its recorded Assembly parent from the available database records. The unverified hierarchy link was omitted.' }),
283
292
  });
284
293
 
285
294
  // #1836: what a missing catalogue file affects, for the Audit tab's Missing source files group.
@@ -303,6 +312,12 @@ const TEKLA_CATALOGUE_ORIGINS = Object.freeze(['model-local', 'user-supplied-pac
303
312
  // #1836: a part profdb.bin's absence left with no axis is not drawn at all, so it is never called a stand-in bar.
304
313
  const TEKLA_UNPLACED_PROFILE_COPY = Object.freeze({ group: 'not-shown', title: 'Part not drawn', detail: 'This part’s profile shape isn’t known because profdb.bin was missing, and it has no usable start and end point, so it is not drawn. Read the model again with that file to see it.' });
305
314
  function auditCopyFor(finding) {
315
+ if (finding.code === 'uda-value-unreadable') {
316
+ const names = [...new Set((finding.evidence?.udas ?? []).map((row) => row.name).filter((name) => typeof name === 'string' && name.length))];
317
+ const label = names.length ? names.join(', ') : 'unnamed attribute';
318
+ return { ...TEKLA_AUDIT_COPY[finding.code], title: `UDA not read: ${label}`,
319
+ detail: `The parser could not read ${names.length === 1 ? 'the value of the' : 'values of the'} user-defined ${names.length === 1 ? 'attribute' : 'attributes'} “${label}” on this object. Its other readable properties and verified relationships were kept. Check ${names.length === 1 ? 'this attribute' : 'these attributes'} in Tekla, then read the model again; if ${names.length === 1 ? 'it still cannot' : 'they still cannot'} be read, report the problem.` };
320
+ }
306
321
  return finding.code === 'profile-catalogue-missing' && finding.hasGeometry === false ? TEKLA_UNPLACED_PROFILE_COPY : TEKLA_AUDIT_COPY[finding.code];
307
322
  }
308
323
 
@@ -339,6 +354,7 @@ function inspect(id, syncViewport = true, publish = true, origin = 'tree') {
339
354
  }
340
355
  selectionOriginGuard.run(() => viewport.setSelection({ ids: isTeklaParser ? geometrySelectionIds : id ? [id] : [] }));
341
356
  }
357
+ if (syncViewport && isTeklaParser) synchronizeTeklaNavigatorSelection();
342
358
  updateSelectionActions();
343
359
  const modelHostId = modelExplorerTabs.find((tab) => tab.key === 'model')?.bodyId;
344
360
  const nextFollowedId = selectedIds.length === 1 && entities.slice(MODEL_EXPLORER_ENTITY_CAP).some((item) => item.id === selectedIds[0]) ? selectedIds[0] : null;
@@ -373,7 +389,57 @@ function selectRevitEntities(id, ids, fit = false, origin = 'tree') {
373
389
  return result;
374
390
  }
375
391
 
392
+ function decorateSelectionHits(hits) {
393
+ return (Array.isArray(hits) ? hits : []).map((hit) => {
394
+ const sourceId = hit?.entity?.sourceId ?? hit?.sourceId ?? hit?.providerToken;
395
+ const entity = entityById.get(sourceId);
396
+ return { ...hit, entity: { kind: hit?.entity?.kind ?? 'native', sourceId: String(sourceId) }, facets: {
397
+ ...(hit?.facets ?? {}), level: entity?.levelName ?? '', category: entity?.categoryName ?? entity?.category ?? '',
398
+ family: entity?.familyName ?? entity?.family ?? '', type: entity?.typeName ?? '',
399
+ } };
400
+ }).filter((hit) => hit.entity.sourceId && hit.entity.sourceId !== 'undefined');
401
+ }
402
+
403
+ // Type selections and Audit inspection also write the viewer selection. Carry that exact set
404
+ // into the navigator before its next additive operation, retaining known occurrence anchors.
405
+ function synchronizeTeklaNavigatorSelection() {
406
+ if (!teklaGroupNavigator) return false;
407
+ const previous = new Map(teklaGroupNavigator.state().selectedItems.map((item) => [item.entityId, item]));
408
+ const occurrences = selectedIds.map((id) => previous.get(id) ?? { entityId: id, occurrencePath: [id] });
409
+ return teklaGroupNavigator.synchronizeSelection(occurrences, selectedId).ok;
410
+ }
411
+
412
+ function resolveTeklaOccurrences(occurrences, { origin = 'tree', operation = 'replace', altAssembly = false, eligibleHits = null } = {}) {
413
+ if (!teklaGroupNavigator || !Array.isArray(occurrences) || !occurrences.length) return { handled: false, accepted: false };
414
+ for (const occurrence of occurrences) {
415
+ if (!occurrence?.entityId || entityById.get(occurrence.entityId)?.hierarchyContract !== 'tekla-hierarchy/v1') return { handled: false, accepted: false };
416
+ }
417
+ const proposal = teklaGroupNavigator.resolveMany(occurrences, teklaSelectionScopes, { origin, operation: 'replace', altAssembly });
418
+ if (!proposal.ok) {
419
+ if (proposal.reason === 'geometry-cap') toast('Not selected: this hierarchy contains more than 5,000 visible geometry objects. Expand it and select a smaller branch.');
420
+ else if (proposal.reason === 'hierarchy-cap') toast('Not selected: this hierarchy is too large to resolve safely. Expand it and select a smaller branch.');
421
+ return { handled: true, accepted: false, reason: proposal.reason };
422
+ }
423
+ if (operation !== 'replace' && !synchronizeTeklaNavigatorSelection()) return { handled: true, accepted: false };
424
+ const selectedItems = proposal.selectedItems;
425
+ const filter = eligibleHits ?? selectionTools?.eligibleHits;
426
+ const decorated = decorateSelectionHits(selectedItems.map((item) => ({ entity: { kind: 'native', sourceId: item.entityId }, occurrencePath: item.occurrencePath })));
427
+ const eligible = typeof filter === 'function' ? filter(decorated) : decorated;
428
+ if (!eligible.length) {
429
+ toast('Nothing selected: the current selection filters exclude every object in this hierarchy.');
430
+ return { handled: true, accepted: true, reason: 'filtered' };
431
+ }
432
+ const result = teklaGroupNavigator.selectResolved(eligible.map((hit) => ({ entityId: hit.entity.sourceId, occurrencePath: hit.occurrencePath })),
433
+ { origin, operation, exitDrill: altAssembly === true && proposal.exitDrill === true });
434
+ if (!result.ok && result.reason === 'geometry-cap') toast('Not selected: this hierarchy contains more than 5,000 visible geometry objects. Expand it and select a smaller branch.');
435
+ else if (!result.ok && result.reason === 'hierarchy-cap') toast('Not selected: this hierarchy is too large to resolve safely. Expand it and select a smaller branch.');
436
+ return { handled: true, accepted: result.ok, reason: result.reason };
437
+ }
438
+
376
439
  function selectTeklaObjects(id, ids, visibleOnly = false, fit = true, origin = 'tree') {
440
+ if (origin === 'tree' && fit && id && ids.length === 1 && teklaGroupNavigator && entityById.get(id)?.hierarchyContract === 'tekla-hierarchy/v1') {
441
+ return resolveTeklaOccurrences([{ entityId: id, occurrencePath: [id] }], { origin }).accepted;
442
+ }
377
443
  if (!ids.every((each) => entityById.has(each))) return false;
378
444
  const visible = visibleOnly
379
445
  ? new Set((viewport.selectionTools?.allHits() || []).map((hit) => hit.entity.sourceId)) : null;
@@ -388,6 +454,7 @@ function selectTeklaObjects(id, ids, visibleOnly = false, fit = true, origin = '
388
454
  selectionOriginGuard.run(() => viewport.setSelection({ ids: geometryIds }));
389
455
  const selected = ids.includes(id) ? id : (ids.at(-1) ?? null);
390
456
  const result = inspect(selected, false, true, origin);
457
+ synchronizeTeklaNavigatorSelection();
391
458
  if (geometryIds.length) { if (fit) facade.dispatch('model.fit-selection'); }
392
459
  else if (ids.length) toast(visibleOnly ? 'This type has no visible geometry to select.' : 'This object has no verified geometry to frame.');
393
460
  return result;
@@ -519,7 +586,54 @@ function applyModelView(command, target) {
519
586
  };
520
587
  }
521
588
 
522
- function row(label, count, entityId, objectFields = null) {
589
+ function createTeklaNavigator() {
590
+ if (!isTeklaParser) return null;
591
+ return createModelGroupNavigator({
592
+ isGroup: (id) => teklaHierarchy.children.has(id),
593
+ groupKind: (id) => teklaHierarchy.groupKind(id),
594
+ childrenOf: (id) => teklaHierarchy.children.get(id) || [],
595
+ hasGeometry: (id) => !!entityById.get(id)?.geometry?.length || entityById.get(id)?.structuralGrid?.mapping?.kind === 'symmetric',
596
+ groupCandidatesOfPick: (id) => teklaHierarchy.candidates(id),
597
+ generation: () => teklaHierarchyGeneration,
598
+ commitSelection(proposal) {
599
+ geometrySelectionIds = [...proposal.geometryIds]; selectedIds = proposal.selectedItems.map((item) => item.entityId);
600
+ if (selectedIds.length) clipSession?.clearSelection?.();
601
+ selectionOriginGuard.run(() => viewport.setSelection({ ids: geometrySelectionIds }));
602
+ const primary = proposal.primaryEntityId;
603
+ if (selectedIds.length > 1) {
604
+ selectedId = null; selectionOrigin = proposal.origin === 'mesh' ? 'viewport' : 'tree';
605
+ inspector.render({ state: 'ready', heading: `${selectedIds.length.toLocaleString()} objects selected`,
606
+ sections: [propertySection('Selection', [['Objects', selectedIds.length], ['Geometry objects', geometrySelectionIds.length]])], after: [chatQuestionsSection] });
607
+ updateSelectionActions(); modelPanelBridge?.publishSelection(selectionOrigin); window.__instructor?.notifyChanged();
608
+ } else inspect(primary, false, true, proposal.origin === 'mesh' ? 'viewport' : 'tree');
609
+ if (geometrySelectionIds.length && proposal.origin === 'tree') facade?.dispatch('model.fit-selection');
610
+ else if (!geometrySelectionIds.length && primary) toast('This object has no verified geometry to frame.');
611
+ return true;
612
+ },
613
+ });
614
+ }
615
+
616
+ function enterTeklaDrillFromPick(id) {
617
+ if (!teklaGroupNavigator || entityById.get(id)?.hierarchyContract !== 'tekla-hierarchy/v1') return false;
618
+ const ownKind = teklaHierarchy.groupKind(id); const candidates = teklaHierarchy.candidates(id);
619
+ const groupId = ownKind ? id
620
+ : teklaSelectionScopes.connection === 'group' && candidates.connection.length ? candidates.connection[0]
621
+ : teklaSelectionScopes.assembly === 'group' && candidates.assembly.length ? candidates.assembly[0] : null;
622
+ if (!groupId || !teklaGroupNavigator.enter({ entityId: groupId, occurrencePath: [groupId] })) return false;
623
+ if (id !== groupId) teklaGroupNavigator.select({ entityId: id, occurrencePath: [groupId, id] }, teklaSelectionScopes, { origin: 'mesh' });
624
+ return true;
625
+ }
626
+
627
+ function isCurrentTeklaOccurrence(entityId, occurrencePath) {
628
+ if (!Array.isArray(occurrencePath) || !occurrencePath.length || occurrencePath.at(-1) !== entityId) return false;
629
+ if (!occurrencePath.every((id) => entityById.get(id)?.hierarchyContract === 'tekla-hierarchy/v1')) return false;
630
+ for (let index = 1; index < occurrencePath.length; index++) {
631
+ if (!(teklaHierarchy.children.get(occurrencePath[index - 1]) || []).includes(occurrencePath[index])) return false;
632
+ }
633
+ return true;
634
+ }
635
+
636
+ function row(label, count, entityId, objectFields = null, occurrencePath = null) {
523
637
  const button = document.createElement('button'); button.type = 'button'; button.className = 'explorer-row';
524
638
  if (entityId) button.dataset.entityId = entityId;
525
639
  const text = document.createElement('span'); text.className = 'row-label'; text.textContent = label;
@@ -541,7 +655,17 @@ function row(label, count, entityId, objectFields = null) {
541
655
  button.append(summary);
542
656
  } else button.append(text);
543
657
  if (count != null) { const number = document.createElement('span'); number.className = 'explorer-count'; number.textContent = String(count); button.append(number); }
544
- if (entityId) button.addEventListener('click', () => isTeklaParser ? selectTeklaObjects(entityId, [entityId]) : inspect(entityId));
658
+ if (entityId && occurrencePath) button.dataset.occurrencePath = JSON.stringify(occurrencePath);
659
+ if (entityId) button.addEventListener('click', (event) => {
660
+ if (event.detail > 1) return false;
661
+ if ((event.ctrlKey || event.metaKey) && event.shiftKey) { event.preventDefault(); return false; }
662
+ if (!isTeklaParser) return inspect(entityId);
663
+ if (occurrencePath && teklaGroupNavigator && entityById.get(entityId)?.hierarchyContract === 'tekla-hierarchy/v1') {
664
+ const operation = event.ctrlKey || event.metaKey ? 'toggle' : event.shiftKey ? 'add' : 'replace';
665
+ return resolveTeklaOccurrences([{ entityId, occurrencePath }], { origin: 'tree', operation }).accepted;
666
+ }
667
+ return selectTeklaObjects(entityId, [entityId]);
668
+ });
545
669
  return button;
546
670
  }
547
671
 
@@ -590,26 +714,72 @@ function dropStaleFollowedRow(selected) {
590
714
  return true;
591
715
  }
592
716
 
593
- function renderEntityList(host, values, ownProperties = propertyByEntity, memberships = teklaAssemblyMembers, followedId = null) {
717
+ function renderEntityList(host, values, ownProperties = propertyByEntity, memberships = teklaAssemblyMembers, parentPath = [], followedId = null) {
594
718
  host.replaceChildren();
595
719
  if (!values.length) { const empty = document.createElement('div'); empty.className = 'explorer-empty'; empty.textContent = 'No objects in this index.'; host.append(empty); return; }
596
- const fragment = document.createDocumentFragment();
597
720
  const limit = 500;
598
- // An object picked in 3D past the first page still gets its row, after the page, so Follow selection can reveal it.
721
+ let shown = 0;
722
+ const appendNextPage = (focusNew = false) => {
723
+ host.querySelector(':scope > .explorer-load-more')?.remove();
724
+ const fragment = document.createDocumentFragment();
725
+ let firstNewTreeItem = null;
726
+ for (const entity of values.slice(shown, shown + limit)) {
727
+ const extra = [...host.querySelectorAll(':scope > [data-followed-row]')].find((item) => item.dataset.entityId === entity.id);
728
+ if (extra) { extra.remove(); const note = host.querySelector(':scope > [data-plain-note]'); if (note) { note.textContent = note.dataset.plainNote; delete note.dataset.plainNote; } }
729
+ const hierarchyChildren = isTeklaParser ? (teklaHierarchy.children.get(entity.id) || []) : [];
730
+ const memberCount = hierarchyChildren.length || (isTeklaParser && memberships.has(entity.id) ? memberships.get(entity.id).length : null);
731
+ const fields = isTeklaParser ? teklaObjectFields(entity, ownProperties.get(entity.id)) : null;
732
+ const occurrencePath = isTeklaParser ? [...parentPath, entity.id] : null;
733
+ const item = row(isTeklaParser ? (fields.name ?? entity.nativeKind ?? entity.typeName ?? 'Tekla object') : (entity.name || entity.typeName || entity.id), memberCount, entity.id, fields, occurrencePath);
734
+ if (isTeklaParser) { item.setAttribute('role', 'treeitem'); item.tabIndex = -1; }
735
+ if (!firstNewTreeItem && item.getAttribute('role') === 'treeitem') firstNewTreeItem = item;
736
+ if (memberCount != null) item.dataset.tip = `${memberCount} verified descendants; selection follows the active group scope`;
737
+ if (!hierarchyChildren.length) { fragment.append(item); continue; }
738
+ item.dataset.commandId = 'tekla-parser.hierarchy-drill';
739
+ item.dataset.commandInstanceLabel = fields.name ?? entity.nativeKind ?? entity.id;
740
+ const branch = document.createElement('div'); branch.className = 'revit-tree-branch tekla-hierarchy-branch'; branch.setAttribute('role', 'none');
741
+ item.setAttribute('aria-expanded', 'false');
742
+ const disclosure = document.createElement('span'); disclosure.className = 'tekla-hierarchy-disclosure'; disclosure.dataset.tip = 'Show verified objects in this group'; disclosure.setAttribute('aria-hidden', 'true'); disclosure.textContent = '›';
743
+ item.prepend(disclosure);
744
+ const children = document.createElement('div'); children.className = 'revit-tree-children'; children.setAttribute('role', 'group'); children.hidden = true; let populated = false;
745
+ const toggle = (force = null) => {
746
+ const open = force ?? item.getAttribute('aria-expanded') !== 'true';
747
+ if (open && !populated) { renderEntityList(children, hierarchyChildren.map((id) => entityById.get(id)).filter(Boolean), ownProperties, memberships, occurrencePath); populated = true; }
748
+ item.setAttribute('aria-expanded', String(open)); disclosure.textContent = open ? '⌄' : '›'; children.hidden = !open;
749
+ };
750
+ disclosure.addEventListener('click', (event) => { event.preventDefault(); event.stopPropagation(); toggle(); });
751
+ item.addEventListener('dblclick', (event) => { if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) { event.preventDefault(); return; } if (teklaGroupNavigator?.enter({ entityId: entity.id, occurrencePath })) { event.preventDefault(); toggle(true); } });
752
+ item.__toggleTreeItem = toggle;
753
+ branch.append(item, children); fragment.append(branch);
754
+ }
755
+ shown = Math.min(values.length, shown + limit); host.append(fragment);
756
+ if (shown < values.length) {
757
+ const more = document.createElement('button'); more.type = 'button'; more.className = 'explorer-row explorer-load-more';
758
+ more.setAttribute('role', 'treeitem'); more.tabIndex = -1;
759
+ more.dataset.pageKey = `model-page:${JSON.stringify(parentPath)}:${values[0]?.id ?? ''}:${values.at(-1)?.id ?? ''}:${shown}:${values.length}`;
760
+ if (isTeklaParser) {
761
+ more.dataset.commandId = 'tekla-parser.hierarchy-load-more';
762
+ more.dataset.commandInstanceLabel = `${values.length.toLocaleString()} objects`;
763
+ }
764
+ more.textContent = `Load 500 more · ${shown.toLocaleString()} of ${values.length.toLocaleString()} shown`;
765
+ more.addEventListener('click', () => appendNextPage(true), { once: true }); host.append(more);
766
+ }
767
+ if (focusNew && firstNewTreeItem) {
768
+ host.closest('[role="tree"]')?.querySelectorAll('[role="treeitem"]').forEach((item) => { item.tabIndex = item === firstNewTreeItem ? 0 : -1; });
769
+ firstNewTreeItem.focus();
770
+ }
771
+ };
772
+ appendNextPage();
599
773
  const followed = followedId && values.length > limit ? values.slice(limit).find((entity) => entity.id === followedId) : null;
600
- for (const entity of followed ? [...values.slice(0, limit), followed] : values.slice(0, limit)) {
601
- const memberCount = isTeklaParser && memberships.has(entity.id) ? memberships.get(entity.id).length : null;
602
- const fields = isTeklaParser ? teklaObjectFields(entity, ownProperties.get(entity.id)) : null;
603
- const item = row(isTeklaParser ? (fields.name ?? entity.nativeKind ?? entity.typeName ?? 'Tekla object') : (entity.name || entity.typeName || entity.id), memberCount, entity.id, fields);
604
- if (memberCount != null) item.dataset.tip = `${memberCount} assembly members; selects all signed member geometry`;
605
- fragment.append(item);
606
- if (entity === followed) item.dataset.followedRow = 'true';
774
+ if (followed) {
775
+ const fields = isTeklaParser ? teklaObjectFields(followed, ownProperties.get(followed.id)) : null;
776
+ const item = row(isTeklaParser ? (fields.name ?? followed.nativeKind ?? followed.typeName ?? 'Tekla object') : (followed.name || followed.typeName || followed.id), null, followed.id, fields, isTeklaParser ? [...parentPath, followed.id] : null);
777
+ item.dataset.followedRow = 'true'; host.append(item);
607
778
  }
608
- host.append(fragment);
609
- if (values.length > 500) {
779
+ if (values.length > limit) {
610
780
  const note = document.createElement('div'); note.className = 'explorer-empty';
611
781
  const plain = `Showing first 500 of ${values.length.toLocaleString()} objects. Select the Type to select all visible matching geometry.`;
612
- note.textContent = isTeklaParser ? (followed ? plain.replace(' objects.', ' objects, plus the selected object.') : plain) : `Showing 500 of ${values.length.toLocaleString()} objects.`;
782
+ note.textContent = followed ? plain.replace(' objects.', ' objects, plus the selected object.') : plain;
613
783
  if (followed) note.dataset.plainNote = plain;
614
784
  host.append(note);
615
785
  }
@@ -632,22 +802,26 @@ function renderGroupList(host, key, fallback, values = entities, ownProperties =
632
802
  if (ordered.length > MODEL_EXPLORER_GROUP_CAP) { const note = document.createElement('div'); note.className = 'explorer-empty explorer-limit'; note.textContent = `Showing ${MODEL_EXPLORER_GROUP_CAP} of ${ordered.length.toLocaleString()} groups. Refine the model before browsing the remaining groups.`; host.append(note); }
633
803
  }
634
804
 
635
- function renderTeklaTypes(host, values, ownProperties, memberships = teklaAssemblyMembers, { query = '', followedId = null } = {}) {
805
+ function renderTeklaTypes(host, values, ownProperties, memberships = teklaAssemblyMembers, { query = '', followedId = null, hierarchy = teklaHierarchy } = {}) {
636
806
  host.replaceChildren(); host.setAttribute('role', 'tree'); host.setAttribute('aria-label', 'Browse Tekla objects by Type');
637
807
  const valuesById = new Map(values.map((entity) => [entity.id, entity]));
638
808
  const branch = (parent, label, values, populate, { expanded = false, populated = expanded } = {}) => {
639
- const node = document.createElement('div'); node.className = 'revit-tree-branch'; node.setAttribute('role', 'treeitem');
809
+ const node = document.createElement('div'); node.className = 'revit-tree-branch'; node.setAttribute('role', 'none');
640
810
  const trigger = row(label, values.length); trigger.classList.add('revit-tree-trigger'); trigger.setAttribute('aria-expanded', String(expanded));
811
+ trigger.setAttribute('role', 'treeitem'); trigger.tabIndex = -1;
641
812
  trigger.dataset.selectable = 'true';
642
813
  const children = document.createElement('div'); children.className = 'revit-tree-children'; children.setAttribute('role', 'group'); children.hidden = !expanded;
643
814
  let hasChildren = false;
644
815
  const selectGroup = () => selectTeklaObjects(values[0]?.id ?? null, values.map((entity) => entity.id), true);
645
- trigger.addEventListener('model-group-select', selectGroup);
646
- trigger.addEventListener('click', () => {
647
- const open = trigger.getAttribute('aria-expanded') !== 'true';
816
+ const toggle = (force = null) => {
817
+ const open = force ?? trigger.getAttribute('aria-expanded') !== 'true';
648
818
  if (open && !hasChildren) { populate(children); hasChildren = true; }
649
819
  trigger.setAttribute('aria-expanded', String(open)); children.hidden = !open;
650
- selectGroup();
820
+ };
821
+ trigger.__toggleTreeItem = toggle;
822
+ trigger.addEventListener('model-group-select', selectGroup);
823
+ trigger.addEventListener('click', () => {
824
+ toggle(); selectGroup();
651
825
  });
652
826
  if (populated) { populate(children); hasChildren = true; }
653
827
  node.append(trigger, children); parent.append(node);
@@ -655,8 +829,10 @@ function renderTeklaTypes(host, values, ownProperties, memberships = teklaAssemb
655
829
  const allBrowsable = values.filter((entity) => {
656
830
  if (entity.geometry?.length) return true;
657
831
  if (entity.structuralGrid?.mapping?.kind === 'symmetric') return true;
658
- if ((entity.nativeKind || entity.typeName) !== 'Assembly' || entity.assemblyActionable === false) return false;
659
- return memberships.get(entity.id)?.some((memberId) => valuesById.get(memberId)?.geometry?.length) === true;
832
+ const groupKind = hierarchy.groupKind(entity.id);
833
+ if (groupKind) return !(groupKind === 'assembly' && entity.assemblyActionable === false) && hierarchy.children.has(entity.id);
834
+ return (entity.nativeKind || entity.typeName) === 'Assembly' && entity.assemblyActionable !== false
835
+ && memberships.get(entity.id)?.some((memberId) => valuesById.get(memberId)?.geometry?.length) === true;
660
836
  });
661
837
  const normalized = query.trim().toLocaleLowerCase();
662
838
  const browsable = normalized ? allBrowsable.filter((entity) => {
@@ -667,10 +843,10 @@ function renderTeklaTypes(host, values, ownProperties, memberships = teklaAssemb
667
843
  for (const group of teklaTypeGroups(browsable)) {
668
844
  const grouped = [...group.values, ...group.subtypes.flatMap((subtype) => subtype.values)];
669
845
  branch(host, group.label, grouped, (children) => {
670
- if (group.values.length) renderEntityList(children, group.values, ownProperties, memberships, followedId);
846
+ if (group.values.length) renderEntityList(children, group.values, ownProperties, memberships, [], followedId);
671
847
  for (const subtype of group.subtypes) {
672
848
  const containsFollowed = subtype.values.some((entity) => entity.id === followedId);
673
- branch(children, subtype.label, subtype.values, (body) => renderEntityList(body, subtype.values, ownProperties, memberships, followedId),
849
+ branch(children, subtype.label, subtype.values, (body) => renderEntityList(body, subtype.values, ownProperties, memberships, [], followedId),
674
850
  { expanded: !!normalized, populated: !!normalized || containsFollowed });
675
851
  }
676
852
  }, { expanded: !!normalized, populated: !!normalized || grouped.some((entity) => entity.id === followedId) });
@@ -680,6 +856,26 @@ function renderTeklaTypes(host, values, ownProperties, memberships = teklaAssemb
680
856
  // "no match" (the search only ever looks through drawn objects).
681
857
  : values.length ? 'None of this model’s objects could be drawn, so there is nothing to browse here. The Audit tab lists the missing files and the objects they affect.'
682
858
  : 'No verified model objects are available.'; host.append(empty); }
859
+ const treeItems = [...host.querySelectorAll('[role="treeitem"]')]; if (treeItems.length) treeItems[0].tabIndex = 0;
860
+ host.onkeydown = (event) => {
861
+ const current = event.target.closest?.('[role="treeitem"]'); if (!current || !host.contains(current)) return;
862
+ const visible = [...host.querySelectorAll('[role="treeitem"]')].filter((item) => !item.closest('[role="group"][hidden]'));
863
+ const move = (next) => { if (!next) return; visible.forEach((item) => { item.tabIndex = item === next ? 0 : -1; }); next.focus(); event.preventDefault(); };
864
+ const index = visible.indexOf(current);
865
+ if (event.key === 'ArrowDown') return move(visible[index + 1]);
866
+ if (event.key === 'ArrowUp') return move(visible[index - 1]);
867
+ if (event.key === 'Home') return move(visible[0]);
868
+ if (event.key === 'End') return move(visible.at(-1));
869
+ if (event.key === 'ArrowRight' && current.hasAttribute('aria-expanded')) {
870
+ if (current.getAttribute('aria-expanded') !== 'true') { if (current.__toggleTreeItem) current.__toggleTreeItem(true); else current.click(); }
871
+ else move(current.parentElement?.querySelector('[role="group"] [role="treeitem"]'));
872
+ event.preventDefault(); return;
873
+ }
874
+ if (event.key === 'ArrowLeft') {
875
+ if (current.getAttribute('aria-expanded') === 'true') { if (current.__toggleTreeItem) current.__toggleTreeItem(false); else current.click(); event.preventDefault(); return; }
876
+ const parent = current.parentElement?.parentElement?.querySelector(':scope > [role="treeitem"]'); if (parent) move(parent);
877
+ }
878
+ };
683
879
  return { shown: browsable.length, total: allBrowsable.length };
684
880
  }
685
881
 
@@ -767,7 +963,7 @@ function validateTeklaAuditDocument(value, manifest, auditReceipt, snapshotEntit
767
963
  || typeof finding.code !== 'string' || !Object.hasOwn(TEKLA_AUDIT_COPY, finding.code)
768
964
  || typeof finding.hasGeometry !== 'boolean' || auditCopyFor(finding).group !== finding.group
769
965
  || !finding.evidence || typeof finding.evidence !== 'object' || Array.isArray(finding.evidence)
770
- || JSON.stringify(finding.evidence).length > 4096) failAudit();
966
+ || JSON.stringify(finding.evidence).length > (finding.code === 'uda-value-unreadable' ? 512 * 1024 : 4096)) failAudit();
771
967
  ids.add(finding.issueId); affected.add(finding.entityId);
772
968
  }
773
969
  if (affected.size !== value.summary.affectedObjects) failAudit();
@@ -783,6 +979,7 @@ function selectAuditFinding(finding) {
783
979
  selectedIds = []; geometrySelectionIds = [];
784
980
  selectionOriginGuard.run(() => viewport.setSelection({ ids: [] }));
785
981
  inspect(finding.entityId, false, true, 'audit');
982
+ synchronizeTeklaNavigatorSelection();
786
983
  }
787
984
  renderTeklaAudit();
788
985
  }
@@ -837,7 +1034,7 @@ function renderTeklaAudit() {
837
1034
  }
838
1035
  const filters = document.createElement('div'); filters.className = 'tekla-audit-filters'; filters.setAttribute('role', 'group'); filters.setAttribute('aria-label', 'Filter import findings');
839
1036
  const filterSpecs = [
840
- ['all', 'All'], ['not-shown', 'Not shown'], ['fit-not-confirmed', 'Fit not confirmed'], ['shape-not-evaluated', 'Shape detail not evaluated'],
1037
+ ['all', 'All'], ['not-shown', 'Not shown'], ['fit-not-confirmed', 'Fit not confirmed'], ['shape-not-evaluated', 'Shape detail not evaluated'], ['hierarchy-not-confirmed', 'Hierarchy not confirmed'], ['property-not-read', 'Property not read'],
841
1038
  ];
842
1039
  let active = host.dataset.filter || 'all';
843
1040
  const list = document.createElement('div'); list.className = 'tekla-audit-list'; list.setAttribute('role', 'listbox'); list.setAttribute('aria-label', 'Import findings');
@@ -873,13 +1070,13 @@ function renderTeklaAudit() {
873
1070
  }
874
1071
 
875
1072
  function updateSelectionActions() {
876
- const blocked = !selectedId || (isTeklaParser ? geometrySelectionIds : selectedIds).length === 0;
1073
+ const blocked = isTeklaParser ? geometrySelectionIds.length === 0 : !selectedId || selectedIds.length === 0;
877
1074
  for (const command of [`${commandPrefix}.fit-selection`]) {
878
1075
  const control = [...document.querySelectorAll('[data-command-id]')].find((item) => item.dataset.commandId === command);
879
1076
  if (!control) continue;
880
1077
  if (command === `${commandPrefix}.fit-selection`) {
881
1078
  control.disabled = blocked;
882
- if (blocked) control.dataset.blockedReason = selectedId ? 'This audit object has no 3D location to frame.' : 'Select a model object first.'; else delete control.dataset.blockedReason;
1079
+ if (blocked) control.dataset.blockedReason = selectedId ? 'This audit object has no 3D location to frame.' : selectedIds.length ? 'This selection has no verified 3D location to frame.' : 'Select a model object first.'; else delete control.dataset.blockedReason;
883
1080
  }
884
1081
  }
885
1082
  }
@@ -959,11 +1156,67 @@ function mountRevitSelectionFilters(tools) {
959
1156
  });
960
1157
  }
961
1158
 
1159
+ function mountTeklaSelectionScopes() {
1160
+ const subscribers = new Set(); let destroyed = false;
1161
+ const state = () => teklaGroupNavigator?.state().drillStack.length ? { connection: 'objects', assembly: 'objects', drillOverride: true } : { ...teklaSelectionScopes, drillOverride: false };
1162
+ const publish = () => {
1163
+ for (const subscriber of subscribers) subscriber(state());
1164
+ modelPanelBridge?.publishSelection(selectionOrigin);
1165
+ if (lastSelectionHoverHit) reflectSelectionHover(lastSelectionHoverHit);
1166
+ window.__instructor?.notifyChanged();
1167
+ };
1168
+ const unsubscribeNavigator = teklaGroupNavigator?.subscribe?.(publish) ?? null;
1169
+ return Object.freeze({
1170
+ port: Object.freeze({
1171
+ getState: state,
1172
+ subscribe(listener) { subscribers.add(listener); listener(state()); return () => subscribers.delete(listener); },
1173
+ set(axis, value) {
1174
+ const result = changeTeklaSelectionScope({ storage: localStorage, navigator: teklaGroupNavigator, current: teklaSelectionScopes, axis, value });
1175
+ if (!result.changed) return false;
1176
+ teklaSelectionScopes = result.scopes; publish(); return true;
1177
+ },
1178
+ ascend() { return teklaGroupNavigator?.ascend() ?? false; },
1179
+ }),
1180
+ destroy() { if (destroyed) return; destroyed = true; unsubscribeNavigator?.(); subscribers.clear(); },
1181
+ });
1182
+ }
1183
+
962
1184
  function reflectSelectionHover(hit) {
963
- const id = hit?.entity?.sourceId ?? null; viewport?.setHover?.(id);
1185
+ lastSelectionHoverHit = hit ?? null;
1186
+ const id = hit?.entity?.sourceId ?? null;
964
1187
  const summary = $('modelHoverSummary');
965
- if (!id) { summary.hidden = true; summary.textContent = ''; return; }
966
- const entity = entityById.get(id); summary.textContent = isTeklaParser && entity ? teklaObjectLabel(entity, propertyByEntity.get(id)) : (entity?.name || entity?.typeName || id); summary.hidden = false;
1188
+ if (!id) { viewport?.setHover?.([]); summary.hidden = true; summary.textContent = ''; return; }
1189
+ let previewIds = [id]; let previewId = id; let previewCount = 1;
1190
+ if (isTeklaParser && teklaGroupNavigator && entityById.get(id)?.hierarchyContract === 'tekla-hierarchy/v1') {
1191
+ const proposal = teklaGroupNavigator.resolveMany([{ entityId: id, occurrencePath: hit?.occurrencePath ?? [id] }],
1192
+ teklaSelectionScopes, { origin: 'mesh', operation: 'replace' });
1193
+ if (proposal.ok) {
1194
+ const decorated = decorateSelectionHits(proposal.selectedItems.map((item) => ({ entity: { kind: 'native', sourceId: item.entityId }, occurrencePath: item.occurrencePath })));
1195
+ const eligible = selectionTools?.eligibleHits?.(decorated) ?? decorated;
1196
+ if (!eligible.length) { viewport?.setHover?.([]); summary.hidden = true; summary.textContent = ''; return; }
1197
+ const preview = teklaGroupNavigator.resolveResolved(eligible.map((item) => ({
1198
+ entityId: item.entity.sourceId, occurrencePath: item.occurrencePath,
1199
+ })));
1200
+ if (!preview.ok) {
1201
+ viewport?.setHover?.([]); summary.hidden = true; summary.textContent = '';
1202
+ if (preview.reason === 'geometry-cap' || preview.reason === 'hierarchy-cap') {
1203
+ summary.textContent = 'Too large to preview — select a smaller branch.'; summary.hidden = false;
1204
+ }
1205
+ return;
1206
+ }
1207
+ previewIds = [...preview.geometryIds]; previewId = proposal.primaryEntityId ?? preview.primaryEntityId ?? id; previewCount = previewIds.length;
1208
+ } else {
1209
+ viewport?.setHover?.([]); summary.hidden = true; summary.textContent = '';
1210
+ if (proposal.reason === 'geometry-cap' || proposal.reason === 'hierarchy-cap') {
1211
+ summary.textContent = 'Too large to preview — select a smaller branch.'; summary.hidden = false;
1212
+ }
1213
+ return;
1214
+ }
1215
+ }
1216
+ viewport?.setHover?.(previewIds);
1217
+ const entity = entityById.get(previewId);
1218
+ const label = isTeklaParser && entity ? teklaObjectLabel(entity, propertyByEntity.get(previewId)) : (entity?.name || entity?.typeName || previewId);
1219
+ summary.textContent = previewId !== id ? `${label} · ${previewCount.toLocaleString()} objects` : label; summary.hidden = false;
967
1220
  }
968
1221
 
969
1222
  function reflectSelectionMarquee(rect) {
@@ -1378,7 +1631,7 @@ async function loadRevision(state, authority, spatialCandidate) {
1378
1631
  renderGroupList(staged.levels, 'levelName', 'No level', nextEntities);
1379
1632
  renderGroupList(staged.categories, (entity) => entity.categoryName ?? entity.category, 'No category', nextEntities);
1380
1633
  }
1381
- if (isTeklaParser) renderTeklaTypes(staged.types, nextEntities, nextPropertyByEntity, teklaAssemblyMembership(nextRelationships));
1634
+ if (isTeklaParser) renderTeklaTypes(staged.types, nextEntities, nextPropertyByEntity, teklaAssemblyMembership(nextRelationships), { hierarchy: teklaHierarchyIndexes(nextEntities, nextRelationships) });
1382
1635
  else renderGroupList(staged.types, 'typeName', 'No type', nextEntities, nextPropertyByEntity);
1383
1636
  if (token !== revisionLoadToken) return false;
1384
1637
  const nextStructuralGrid = isTeklaParser ? findTeklaStructuralGrid(nextEntities) : null;
@@ -1392,6 +1645,9 @@ async function loadRevision(state, authority, spatialCandidate) {
1392
1645
  loadedRevisionId = handle.revisionId; loadedSourceDigest = handle.sourceSha256;
1393
1646
  entities = nextEntities; properties = nextProperties; relationships = nextRelationships; entityById = nextEntityById; propertyByEntity = nextPropertyByEntity; teklaAudit = nextAudit;
1394
1647
  teklaAssemblyMembers = isTeklaParser ? teklaAssemblyMembership(nextRelationships) : new Map();
1648
+ teklaHierarchy = isTeklaParser ? teklaHierarchyIndexes(nextEntities, nextRelationships) : teklaHierarchyIndexes([], []);
1649
+ teklaHierarchyGeneration++;
1650
+ teklaGroupNavigator = isTeklaParser ? createTeklaNavigator() : null;
1395
1651
  selectionTools?.generationChanged();
1396
1652
  selectionFilterChrome?.refresh();
1397
1653
  $('revitExplorerClassification').replaceChildren(...staged.model.childNodes);
@@ -1401,7 +1657,9 @@ async function loadRevision(state, authority, spatialCandidate) {
1401
1657
  $('revitExplorerCategories').replaceChildren(...staged.categories.childNodes);
1402
1658
  }
1403
1659
  $('revitExplorerTypes').replaceChildren(...staged.types.childNodes);
1660
+ if (isTeklaParser) renderTeklaTypes($('revitExplorerTypes'), entities, propertyByEntity, teklaAssemblyMembers);
1404
1661
  inspect(null, true, false, 'tree');
1662
+ refreshTeklaModelToolsForRevision();
1405
1663
  renderTeklaAudit();
1406
1664
  viewerLoading = false;
1407
1665
  modelPanelBridge?.ready(handle.revisionId);
@@ -1425,7 +1683,7 @@ async function loadRevision(state, authority, spatialCandidate) {
1425
1683
  // The main window's left Model section shows the clip list as a PANEL tab (web/model-panel-bridge.js).
1426
1684
  const REVIT_PANEL_TABS = Object.freeze([
1427
1685
  Object.freeze({ key: 'clips', label: 'Clips', tip: 'Clips — the planes and boxes cutting the model: select, rename, switch on or off, remove' }),
1428
- ...(isTeklaParser ? [Object.freeze({ key: 'audit', label: 'Audit', tip: 'Audit — database objects whose displayed shape or placement could not be fully verified' })] : []),
1686
+ ...(isTeklaParser ? [Object.freeze({ key: 'audit', label: 'Audit', tip: 'Audit — model properties, hierarchy, shape or placement that could not be fully verified' })] : []),
1429
1687
  ]);
1430
1688
  // Held, not looked up: once shown, the Clips tab lives in the main window's frame, where $() cannot find it.
1431
1689
  const revitClipListHost = $('revitClipListHost');
@@ -1438,15 +1696,38 @@ function mountPanels() {
1438
1696
  mountSidePanel({ panel: $('inspectorPanel'), resizer: $('inspectorResizer'), toggle: $('inspectorToggle'), root: $('editorRoot'), doc: document, win: window, widthKey: `${storagePrefix}:inspector-width`, collapsedKey: `${storagePrefix}:inspector-collapsed`, label: (collapsed) => (collapsed ? 'Expand Properties' : 'Collapse Properties') });
1439
1697
  modelPanelBridge = createModelPanelBridge({
1440
1698
  win: window, origin: location.origin, snapshot: modelPanelSnapshot, selectedId: () => selectedId, selectedIds: () => [...selectedIds],
1441
- selectionState: () => isTeklaParser ? { focusEntityId: selectedId, geometrySelectionIds: [...geometrySelectionIds] } : {},
1699
+ selectionState: () => isTeklaParser ? { focusEntityId: selectedId, geometrySelectionIds: [...geometrySelectionIds],
1700
+ drillDepth: teklaGroupNavigator?.state().drillStack.length ?? 0 } : {},
1442
1701
  // ids: what a list click selects (Ctrl/Shift can make it several, or none). The Properties panel shows the row clicked
1443
1702
  // when it stays selected, else the last one; the viewport shows them all.
1444
- select: (id, ids = [id]) => (isTeklaParser ? selectTeklaObjects(id, ids) : selectRevitEntities(id, ids)),
1703
+ select: (id, ids = [id], context = {}) => {
1704
+ if (isTeklaParser) {
1705
+ if (!ids.every((each) => entityById.has(each))) return false;
1706
+ // Older authenticated snapshots have assembly membership but no occurrence hierarchy.
1707
+ // Keep their existing list selection; a full hierarchy still requires every signed path.
1708
+ if (!entities.some((entity) => entity.hierarchyContract === 'tekla-hierarchy/v1')) return selectTeklaObjects(id, ids);
1709
+ const occurrences = Array.isArray(context.occurrences) ? context.occurrences : [];
1710
+ if (!teklaGroupNavigator || !occurrences.length || !occurrences.every((item) => isCurrentTeklaOccurrence(item.entityId, item.occurrencePath))) return false;
1711
+ return resolveTeklaOccurrences(occurrences, { origin: 'tree', operation: context.operation }).accepted;
1712
+ }
1713
+ return selectRevitEntities(id, ids);
1714
+ },
1445
1715
  // #2255: an AI view command this window claimed, applied in this viewer.
1446
1716
  view: (command, target) => applyModelView(command, target),
1447
1717
  expand: (groupId) => expandModelPanelGroup(modelExplorerTabs, $, groupId),
1718
+ drill: (entityId, occurrencePath) => {
1719
+ if (!isTeklaParser || !teklaGroupNavigator || !teklaHierarchy.groupKind(entityId) || !isCurrentTeklaOccurrence(entityId, occurrencePath)) return false;
1720
+ return teklaGroupNavigator.enter({ entityId, occurrencePath });
1721
+ },
1722
+ ascend: () => isTeklaParser && (teklaGroupNavigator?.ascend() ?? false),
1723
+ clearSelection: () => isTeklaParser && (teklaGroupNavigator?.clear() ?? false),
1448
1724
  selectGroup: (groupId) => isTeklaParser && selectModelPanelGroup(modelExplorerTabs, $, groupId),
1449
1725
  search: (tab, query) => renderExplorerSearch(tab, query, selectedIds.length === 1 ? selectedIds[0] : null),
1726
+ loadMore: (pageKey) => {
1727
+ const button = [...document.querySelectorAll('.explorer-load-more')].find((item) => item.dataset.pageKey === pageKey);
1728
+ if (!button) return false;
1729
+ button.click(); return true;
1730
+ },
1450
1731
  gridVisibility: ({ levelKey, visible }) => {
1451
1732
  const levels = viewport?.gridLevels?.() || [];
1452
1733
  if (!levels.length || (levelKey !== null && !levels.some((level) => String(level.key) === levelKey))) return false;
@@ -1464,6 +1745,14 @@ function mountPanels() {
1464
1745
  });
1465
1746
  }
1466
1747
 
1748
+ // Scope controls and their navigator subscription belong to the displayed revision.
1749
+ function refreshTeklaModelToolsForRevision() {
1750
+ if (!isTeklaParser || !sharedTools) return false;
1751
+ sharedTools.destroy(); sharedTools = null;
1752
+ mountSharedModelTools();
1753
+ return true;
1754
+ }
1755
+
1467
1756
  function mountSharedModelTools() {
1468
1757
  const measureListeners = new Set(); const snapListeners = new Set();
1469
1758
  const cleanup = []; let destroyed = false;
@@ -1504,23 +1793,25 @@ function mountSharedModelTools() {
1504
1793
  let nextSelectionTools = null;
1505
1794
  if (selectionPort && ['coordinator', 'hitsAt', 'allHits', 'marqueeHits', 'generationToken', 'registerInterceptor']
1506
1795
  .every((name) => name === 'coordinator' ? selectionPort.coordinator : typeof selectionPort[name] === 'function')) {
1507
- const decorate = (hits) => (Array.isArray(hits) ? hits : []).map((hit) => {
1508
- const sourceId = hit?.entity?.sourceId ?? hit?.sourceId ?? hit?.providerToken;
1509
- const entity = entityById.get(sourceId);
1510
- return { ...hit, entity: { kind: hit?.entity?.kind ?? 'native', sourceId: String(sourceId) }, facets: {
1511
- ...(hit?.facets ?? {}), level: entity?.levelName ?? '', category: entity?.categoryName ?? entity?.category ?? '',
1512
- family: entity?.familyName ?? entity?.family ?? '', type: entity?.typeName ?? '',
1513
- } };
1514
- }).filter((hit) => hit.entity.sourceId && hit.entity.sourceId !== 'undefined');
1515
1796
  nextSelectionTools = createModelSelectionTools({
1516
1797
  coordinator: selectionPort.coordinator,
1517
- hitsAt: (pointer, event) => decorate(selectionPort.hitsAt(pointer, event)),
1518
- allHits: () => decorate(selectionPort.allHits()),
1519
- marqueeHits: (rect) => decorate(selectionPort.marqueeHits(rect)),
1798
+ hitsAt: (pointer, event) => decorateSelectionHits(selectionPort.hitsAt(pointer, event)),
1799
+ allHits: () => decorateSelectionHits(selectionPort.allHits()),
1800
+ marqueeHits: (rect) => decorateSelectionHits(selectionPort.marqueeHits(rect)),
1520
1801
  generationToken: () => selectionPort.generationToken(),
1521
1802
  fitSelection: () => facade.dispatch('model.fit-selection'),
1803
+ cancelActiveTool: () => isTeklaParser ? (teklaGroupNavigator?.ascend() ?? false) : false,
1522
1804
  onHover: reflectSelectionHover,
1523
1805
  onMarquee: reflectSelectionMarquee,
1806
+ onHierarchyDoubleClick: isTeklaParser ? (hit) => enterTeklaDrillFromPick(hit?.entity?.sourceId) : null,
1807
+ clearSelection: isTeklaParser ? () => teklaGroupNavigator?.clear() ?? selectionPort.coordinator.clear('mesh') : null,
1808
+ resolveSelection: isTeklaParser ? (hits, context) => {
1809
+ if (!hits.length || !teklaGroupNavigator) return false;
1810
+ const occurrences = hits.map((hit) => ({ entityId: hit?.entity?.sourceId, occurrencePath: hit?.occurrencePath ?? [hit?.entity?.sourceId] }));
1811
+ const outcome = resolveTeklaOccurrences(occurrences, { origin: context.origin, operation: context.operation,
1812
+ altAssembly: context.event?.altKey === true, eligibleHits: context.eligibleHits });
1813
+ return outcome.handled;
1814
+ } : null,
1524
1815
  });
1525
1816
  own(() => nextSelectionTools.destroy());
1526
1817
  const releaseInput = selectionPort.registerInterceptor(nextSelectionTools.interceptor); if (releaseInput) own(releaseInput);
@@ -1528,12 +1819,18 @@ function mountSharedModelTools() {
1528
1819
  }
1529
1820
  const nextSelectionFilterChrome = nextSelectionTools ? mountRevitSelectionFilters(nextSelectionTools) : null;
1530
1821
  if (nextSelectionFilterChrome) own(() => nextSelectionFilterChrome.destroy());
1822
+ const nextTeklaScopeChrome = isTeklaParser ? mountTeklaSelectionScopes() : null;
1823
+ if (nextTeklaScopeChrome) own(() => nextTeklaScopeChrome.destroy());
1531
1824
  const subscribe = (set) => (listener) => { set.add(listener); let live = true; return () => { if (live) { live = false; set.delete(listener); } }; };
1532
1825
  const dock = mountModelPointerDock({
1533
1826
  selectionHost: $('modelSelectBar'), snapHost: $('modelSnapBar'), actionsHost: $('modelModuleActions'),
1534
- plan: isTeklaParser ? readOnlyModelPointerDockPlan(commandPrefix, 'Tekla') : REVIT_POINTER_DOCK_PLAN,
1827
+ plan: isTeklaParser ? teklaModelPointerDockPlan({
1828
+ connection: entities.some((entity) => entity.nativeKind === 'Component' || entity.nativeKind === 'Connection'),
1829
+ assembly: entities.some((entity) => entity.nativeKind === 'Assembly'),
1830
+ }) : REVIT_POINTER_DOCK_PLAN,
1535
1831
  ports: {
1536
1832
  selection: nextSelectionFilterChrome?.port,
1833
+ scope: nextTeklaScopeChrome?.port,
1537
1834
  snap: {
1538
1835
  getState: () => nextCadTools.snapState(), subscribe: subscribe(snapListeners),
1539
1836
  toggle: (kind) => { const state = nextCadTools.snapState(); nextCadTools.setSnapMode(kind, state[kind] === false); },
@@ -1664,6 +1961,7 @@ async function boot() {
1664
1961
  modelPanelBridge?.publishSnapshot();
1665
1962
  }
1666
1963
  inspect(ids.at(-1) || null, false, true, 'viewport');
1964
+ if (isTeklaParser) synchronizeTeklaNavigatorSelection();
1667
1965
  } });
1668
1966
  facade = createReadOnlyModelEditorAdapter({ viewport, host: { openSavedViews } }); toolbarChrome = wireToolbar();
1669
1967
  window.__revitEditorTest = { dispatchLog: () => facade.dispatchLog(), selected: () => selectedId, entityCount: () => entities.length,
@@ -1672,7 +1970,8 @@ async function boot() {
1672
1970
  semantic: row.semantic ?? null, valueEncoding: row.valueEncoding ?? null })),
1673
1971
  drawnIds: () => entities.filter((entity) => (entity.geometry || []).length).map((entity) => entity.id),
1674
1972
  selectedIds: () => [...selectedIds],
1675
- selectionState: () => ({ focusEntityId: selectedId, geometrySelectionIds: [...geometrySelectionIds] }),
1973
+ selectionState: () => ({ focusEntityId: selectedId, selectedIds: [...selectedIds], geometrySelectionIds: [...geometrySelectionIds],
1974
+ drillStack: teklaGroupNavigator?.state().drillStack.map((item) => ({ entityId: item.entityId, occurrencePath: [...item.occurrencePath] })) ?? [] }),
1676
1975
  selectionCapabilities: () => selectionTools?.capabilities() ?? null, spatialState: () => spatialTools?.state() ?? null,
1677
1976
  editorState: () => facade.getState(), presentation: () => viewport.presentationProbe(),
1678
1977
  lighting: () => facade.lightingState(), gridLevels: () => viewport.gridLevels(),