@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.
- package/dist/floless-server.cjs +3340 -2982
- package/dist/web/app.css +5 -2
- package/dist/web/commands-shell.js +11 -0
- package/dist/web/commands-tekla-parser.js +7 -0
- package/dist/web/instructor.js +1 -1
- package/dist/web/left-pane.js +137 -39
- package/dist/web/model-editor.css +10 -0
- package/dist/web/model-group-navigator.js +331 -0
- package/dist/web/model-panel-bridge.js +63 -5
- package/dist/web/model-pointer-dock.js +55 -5
- package/dist/web/model-selection-tools.js +53 -17
- package/dist/web/model-tekla-selection.js +75 -2
- package/dist/web/model-viewport-revit-adapter.js +14 -9
- package/dist/web/revit-editor.js +350 -51
- package/dist/web/steel-3d-view.js +1 -0
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -38,7 +38,20 @@ export function createModelSelectionOriginGuard() {
|
|
|
38
38
|
|
|
39
39
|
export function serializeModelPanelNodes(host, path = 'root') {
|
|
40
40
|
const nodes = [];
|
|
41
|
+
const occurrencePath = (row) => {
|
|
42
|
+
if (!row?.dataset?.occurrencePath) return null;
|
|
43
|
+
try {
|
|
44
|
+
const value = JSON.parse(row.dataset.occurrencePath);
|
|
45
|
+
return Array.isArray(value) && value.length && value.every((id) => typeof id === 'string') ? value : null;
|
|
46
|
+
} catch { return null; }
|
|
47
|
+
};
|
|
48
|
+
const objectFields = (row) => row?.classList.contains('model-object-row')
|
|
49
|
+
? Object.fromEntries(['name', 'profile', 'id'].map((key) => [key, row.querySelector(`[data-object-field="${key}"]`)?.textContent ?? null]))
|
|
50
|
+
: null;
|
|
41
51
|
for (const [index, child] of [...(host?.children || [])].entries()) {
|
|
52
|
+
if (child.classList.contains('explorer-load-more')) {
|
|
53
|
+
nodes.push({ kind: 'more', label: child.textContent || 'Load more', pageKey: child.dataset.pageKey || null }); continue;
|
|
54
|
+
}
|
|
42
55
|
if (child.classList.contains('revit-explorer-label')) { nodes.push({ kind: 'label', label: child.textContent || '' }); continue; }
|
|
43
56
|
if (child.classList.contains('explorer-empty')) { nodes.push({ kind: 'note', label: child.textContent || '' }); continue; }
|
|
44
57
|
if (child.classList.contains('revit-tree-branch')) {
|
|
@@ -49,6 +62,9 @@ export function serializeModelPanelNodes(host, path = 'root') {
|
|
|
49
62
|
nodes.push({ label: trigger.querySelector('.row-label')?.textContent || trigger.textContent || '',
|
|
50
63
|
count: trigger.querySelector('.explorer-count')?.textContent || null, children,
|
|
51
64
|
tip: trigger.dataset.tip || null,
|
|
65
|
+
...(trigger.dataset.entityId ? { entityId: trigger.dataset.entityId } : {}),
|
|
66
|
+
...(occurrencePath(trigger) ? { occurrencePath: occurrencePath(trigger) } : {}),
|
|
67
|
+
...(objectFields(trigger) ? { objectFields: objectFields(trigger) } : {}),
|
|
52
68
|
...(trigger.dataset.selectable === 'true' ? { selectable: true } : {}),
|
|
53
69
|
lazy: !children.length && Number(trigger.querySelector('.explorer-count')?.textContent || 0) > 0,
|
|
54
70
|
expanded: trigger.getAttribute('aria-expanded') === 'true', groupId: `${path}.${index}` });
|
|
@@ -57,7 +73,8 @@ export function serializeModelPanelNodes(host, path = 'root') {
|
|
|
57
73
|
}
|
|
58
74
|
if (child.classList.contains('explorer-row')) nodes.push({ label: child.querySelector('.row-label')?.textContent ?? child.textContent ?? '',
|
|
59
75
|
count: child.querySelector('.explorer-count')?.textContent || null, entityId: child.dataset.entityId || null,
|
|
60
|
-
...(child
|
|
76
|
+
...(occurrencePath(child) ? { occurrencePath: occurrencePath(child) } : {}),
|
|
77
|
+
...(objectFields(child) ? { objectFields: objectFields(child) } : {}),
|
|
61
78
|
tip: child.dataset.tip || null });
|
|
62
79
|
}
|
|
63
80
|
return nodes;
|
|
@@ -76,7 +93,10 @@ export function expandModelPanelGroup(tabs, byId, groupId) {
|
|
|
76
93
|
const trigger = branch.querySelector(':scope > .explorer-row');
|
|
77
94
|
const children = branch.querySelector(':scope > .revit-tree-children');
|
|
78
95
|
if (!trigger || !children) return false;
|
|
79
|
-
if (!children.children.length)
|
|
96
|
+
if (!children.children.length) {
|
|
97
|
+
if (typeof trigger.__toggleTreeItem === 'function') trigger.__toggleTreeItem(true);
|
|
98
|
+
else trigger.click();
|
|
99
|
+
}
|
|
80
100
|
host = children;
|
|
81
101
|
}
|
|
82
102
|
return true;
|
|
@@ -171,7 +191,8 @@ export function createPanelHost({ win = window, root, bodies, install = (_doc) =
|
|
|
171
191
|
|
|
172
192
|
export function createModelPanelBridge({ win = window, origin = location.origin, snapshot, selectedId, selectedIds = () => {
|
|
173
193
|
const id = selectedId(); return typeof id === 'string' ? [id] : [];
|
|
174
|
-
}, select, expand, selectGroup = (_groupId) => false, search = (_tab, _query) => false,
|
|
194
|
+
}, select, expand, drill = (_entityId, _occurrencePath) => false, ascend = () => false, clearSelection = () => false, selectGroup = (_groupId) => false, search = (_tab, _query) => false,
|
|
195
|
+
loadMore = (_pageKey) => false,
|
|
175
196
|
selectionState = () => ({}), panel = (_tab, _person, _follow) => false,
|
|
176
197
|
gridVisibility = (_action) => false, selectedSubjects = () => null, chatLinksChanged = null, view = /** @type {((command: any, target: any) => any) | null} */ (null) }) {
|
|
177
198
|
let requested = false;
|
|
@@ -189,7 +210,7 @@ gridVisibility = (_action) => false, selectedSubjects = () => null, chatLinksCha
|
|
|
189
210
|
const publishStatus = (message = '') => send({ type: 'status', state: lifecycle, message });
|
|
190
211
|
const publishSnapshot = () => {
|
|
191
212
|
if (lifecycle !== 'ready') return false;
|
|
192
|
-
return send({ type: 'snapshot', snapshot: { ...snapshot(), subjects: selectedSubjects(), datasetKey } });
|
|
213
|
+
return send({ type: 'snapshot', snapshot: { ...snapshot(), subjects: selectedSubjects(), datasetKey, ...selectionState() } });
|
|
193
214
|
};
|
|
194
215
|
// `subjects` is the selection as model objects a chat message may be about (#1653): {source, revision, total,
|
|
195
216
|
// items: [{kind, id, label}]}, or null. Raw selected ids stay beside it for the tree's own rows.
|
|
@@ -219,7 +240,13 @@ gridVisibility = (_action) => false, selectedSubjects = () => null, chatLinksCha
|
|
|
219
240
|
let ok = false;
|
|
220
241
|
// entityId is the row clicked; entityIds what the click selects (a Ctrl/Shift click: more rows, or none left).
|
|
221
242
|
const ids = Array.isArray(data.entityIds) ? data.entityIds.filter((id) => typeof id === 'string') : [data.entityId];
|
|
222
|
-
|
|
243
|
+
const validOccurrence = (value) => value && typeof value.entityId === 'string' && Array.isArray(value.occurrencePath)
|
|
244
|
+
&& value.occurrencePath.length > 0 && value.occurrencePath.every((id) => typeof id === 'string')
|
|
245
|
+
&& value.occurrencePath.at(-1) === value.entityId;
|
|
246
|
+
const occurrences = Array.isArray(data.occurrences) ? data.occurrences.filter(validOccurrence)
|
|
247
|
+
: (validOccurrence(data.occurrence) ? [data.occurrence] : []);
|
|
248
|
+
const operation = ['replace', 'add', 'toggle'].includes(data.operation) ? data.operation : 'replace';
|
|
249
|
+
try { ok = !!select(data.entityId, ids, { operation, occurrences }); if (ok) publishSnapshot(); publishSelection('tree'); }
|
|
223
250
|
catch (error) { try { win.console?.error?.('[model-panel] select action failed', error); } catch { /* reporting must still continue */ } }
|
|
224
251
|
actionResult(data.requestId, ok, ok ? '' : 'That object is no longer in this model revision.');
|
|
225
252
|
return;
|
|
@@ -231,6 +258,37 @@ gridVisibility = (_action) => false, selectedSubjects = () => null, chatLinksCha
|
|
|
231
258
|
actionResult(data.requestId, ok, ok ? '' : 'That model group has changed. Try opening it again.');
|
|
232
259
|
return;
|
|
233
260
|
}
|
|
261
|
+
if (data.action === 'drill' && typeof data.entityId === 'string') {
|
|
262
|
+
let ok = false;
|
|
263
|
+
const occurrencePath = Array.isArray(data.occurrencePath) && data.occurrencePath.length > 0
|
|
264
|
+
&& data.occurrencePath.every((id) => typeof id === 'string') && data.occurrencePath.at(-1) === data.entityId
|
|
265
|
+
? data.occurrencePath : null;
|
|
266
|
+
try { ok = data.datasetKey === datasetKey && !!drill(data.entityId, occurrencePath); if (ok) publishSnapshot(); }
|
|
267
|
+
catch (error) { try { win.console?.error?.('[model-panel] drill action failed', error); } catch { /* reporting must still continue */ } ok = false; }
|
|
268
|
+
actionResult(data.requestId, ok, ok ? '' : 'That model group has changed. Try entering it again.');
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (data.action === 'load-more' && typeof data.pageKey === 'string') {
|
|
272
|
+
let ok = false;
|
|
273
|
+
try { ok = data.datasetKey === datasetKey && !!loadMore(data.pageKey); if (ok) publishSnapshot(); }
|
|
274
|
+
catch (error) { try { win.console?.error?.('[model-panel] load-more action failed', error); } catch { /* reporting must still continue */ } ok = false; }
|
|
275
|
+
actionResult(data.requestId, ok, ok ? '' : 'That part of the model index has changed. Try loading it again.');
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (data.action === 'ascend') {
|
|
279
|
+
let ok = false;
|
|
280
|
+
try { ok = data.datasetKey === datasetKey && !!ascend(); if (ok) publishSnapshot(); }
|
|
281
|
+
catch (error) { try { win.console?.error?.('[model-panel] ascend action failed', error); } catch { /* reporting must still continue */ } ok = false; }
|
|
282
|
+
actionResult(data.requestId, ok, ok ? '' : 'There is no parent group to return to.');
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (data.action === 'clear-selection') {
|
|
286
|
+
let ok = false;
|
|
287
|
+
try { ok = data.datasetKey === datasetKey && !!clearSelection(); if (ok) publishSnapshot(); publishSelection('tree'); }
|
|
288
|
+
catch (error) { try { win.console?.error?.('[model-panel] clear selection action failed', error); } catch { /* reporting must still continue */ } ok = false; }
|
|
289
|
+
actionResult(data.requestId, ok, ok ? '' : 'The selection has already been cleared.');
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
234
292
|
if (data.action === 'select-group' && typeof data.groupId === 'string') {
|
|
235
293
|
let ok = false;
|
|
236
294
|
try { ok = data.datasetKey === datasetKey && !!selectGroup(data.groupId); if (ok) { publishSnapshot(); publishSelection('tree'); } }
|
|
@@ -14,6 +14,8 @@ const REFERENCE_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColo
|
|
|
14
14
|
const CATEGORY_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><rect x="2.5" y="2.5" width="5" height="5" rx="1"/><rect x="10.5" y="2.5" width="5" height="5" rx="1"/><rect x="2.5" y="10.5" width="5" height="5" rx="1"/><rect x="10.5" y="10.5" width="5" height="5" rx="1"/></svg>';
|
|
15
15
|
const TYPE_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M3 4h12M5 9h8M7 14h4"/></svg>';
|
|
16
16
|
const CLASS_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" aria-hidden="true"><path d="M9 2.5l6 3.2v6.6L9 15.5l-6-3.2V5.7L9 2.5Z"/><path d="M3 5.7L9 9l6-3.3M9 9v6.5"/></svg>';
|
|
17
|
+
const GROUP_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><rect x="3" y="3" width="12" height="12" rx="2"/><path d="M6 6h6v6H6z"/></svg>';
|
|
18
|
+
const OBJECTS_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><rect x="2.5" y="2.5" width="5" height="5" rx="1"/><rect x="10.5" y="2.5" width="5" height="5" rx="1"/><rect x="6.5" y="10.5" width="5" height="5" rx="1"/></svg>';
|
|
17
19
|
|
|
18
20
|
const frozen = (value) => Object.freeze(value);
|
|
19
21
|
const selection = (id, command, carrier, label, tip, icon, extra = {}) => frozen({ id, command, carrier, label, tip, icon, ...extra });
|
|
@@ -80,17 +82,42 @@ export function readOnlyModelPointerDockPlan(commandPrefix = 'revit', sourceLabe
|
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
|
|
85
|
+
/** Tekla mirrors the native Component/Object and Assembly/Object selection granularity controls. */
|
|
86
|
+
export function teklaModelPointerDockPlan({ connection = true, assembly = true } = {}) {
|
|
87
|
+
const base = readOnlyModelPointerDockPlan('tekla-parser', 'Tekla');
|
|
88
|
+
const scopeItem = (axis, value, command, carrier, label, shortLabel, tip, icon) => frozen({ axis, value, command,
|
|
89
|
+
carrier, label, shortLabel, tip, icon });
|
|
90
|
+
return frozen({
|
|
91
|
+
...base,
|
|
92
|
+
ascend: frozen({ command: 'tekla-parser.hierarchy-ascend', carrier: 'data-command-id="tekla-parser.hierarchy-ascend"',
|
|
93
|
+
label: 'Leave group', tip: 'Leave the current Connection or Assembly drill-down (Esc)' }),
|
|
94
|
+
selection: frozen(base.selection.filter((item) => item.id === 'type')),
|
|
95
|
+
scopeGroups: frozen([
|
|
96
|
+
frozen({ axis: 'connection', label: 'Connection selection scope', items: frozen([
|
|
97
|
+
scopeItem('connection', 'group', 'tekla-parser.connection-scope-group', 'data-command-id="tekla-parser.connection-scope-group"', 'Select Connections as groups', 'Conn', 'Connection scope — select the Connection as one logical object', GROUP_ICON),
|
|
98
|
+
scopeItem('connection', 'objects', 'tekla-parser.connection-scope-objects', 'data-command-id="tekla-parser.connection-scope-objects"', 'Select objects inside Connections', 'Obj', 'Connection scope — select its descendant objects individually', OBJECTS_ICON),
|
|
99
|
+
]) }),
|
|
100
|
+
frozen({ axis: 'assembly', label: 'Assembly selection scope', items: frozen([
|
|
101
|
+
scopeItem('assembly', 'group', 'tekla-parser.assembly-scope-group', 'data-command-id="tekla-parser.assembly-scope-group"', 'Select Assemblies as groups', 'Asm', 'Assembly scope — select the Assembly as one logical object', GROUP_ICON),
|
|
102
|
+
scopeItem('assembly', 'objects', 'tekla-parser.assembly-scope-objects', 'data-command-id="tekla-parser.assembly-scope-objects"', 'Select objects inside Assemblies', 'Obj', 'Assembly scope — select its descendant objects individually', OBJECTS_ICON),
|
|
103
|
+
]) }),
|
|
104
|
+
].filter((group) => group.axis === 'connection' ? connection : assembly)),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
83
108
|
function escapeAttr(value) {
|
|
84
109
|
return String(value ?? '').replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
85
110
|
}
|
|
86
111
|
|
|
87
112
|
export function pointerDockCarriers(plan) {
|
|
88
|
-
return [...(plan.selection ?? []), ...(plan.snaps ?? []), ...(plan.actions ?? [])].map((item) => item.command).filter(Boolean);
|
|
113
|
+
return [...(plan.scopeGroups ?? []).flatMap((group) => group.items ?? []), ...(plan.ascend ? [plan.ascend] : []), ...(plan.selection ?? []), ...(plan.snaps ?? []), ...(plan.actions ?? [])].map((item) => item.command).filter(Boolean);
|
|
89
114
|
}
|
|
90
115
|
|
|
91
116
|
export function renderSelectionBarMarkup(plan) {
|
|
92
|
-
if (!plan.selection?.length) return '';
|
|
93
|
-
|
|
117
|
+
if (!plan.selection?.length && !plan.scopeGroups?.length) return '';
|
|
118
|
+
const scopes = (plan.scopeGroups ?? []).map((group) => `<span class="model-selection-scope" role="group" aria-label="${escapeAttr(group.label)}">${(group.items ?? []).map((item) => `<button type="button" ${item.carrier} data-selection-scope-axis="${escapeAttr(item.axis)}" data-selection-scope-value="${escapeAttr(item.value)}" aria-label="${escapeAttr(item.label)}" data-tip="${escapeAttr(item.tip)}" aria-pressed="false" tabindex="-1">${item.icon ?? ''}<span class="model-scope-short" aria-hidden="true">${escapeAttr(item.shortLabel)}</span></button>`).join('')}</span>`).join('');
|
|
119
|
+
const status = plan.scopeGroups?.length ? `<span class="model-scope-status" role="status" aria-live="polite"></span>${plan.ascend ? `<button type="button" class="model-scope-ascend" ${plan.ascend.carrier} data-tip="${escapeAttr(plan.ascend.tip)}" hidden>${escapeAttr(plan.ascend.label)}</button>` : ''}` : '';
|
|
120
|
+
return '<span class="lbl">Select</span>' + scopes + status + plan.selection.map((item) => {
|
|
94
121
|
const fly = item.fly ? ` data-fly="${escapeAttr(item.fly)}"` : '';
|
|
95
122
|
const caret = item.caret ? '<span class="car" aria-hidden="true">▾</span>' : '';
|
|
96
123
|
return `<button type="button" ${item.carrier} data-cls="${escapeAttr(item.id)}"${fly} aria-label="${escapeAttr(item.label)}" data-tip="${escapeAttr(item.tip)}">${item.icon ?? ''}${caret}</button>`;
|
|
@@ -119,7 +146,7 @@ function validatePort(port, name) {
|
|
|
119
146
|
/** Render and optionally wire the shared pointer chrome. Provider ports remain the only state owners. */
|
|
120
147
|
export function mountModelPointerDock({ selectionHost = null, snapHost = null, actionsHost = null, plan, ports = {} }) {
|
|
121
148
|
if (!plan || plan.schema !== 'floless.model-pointer-dock/v1') throw new Error('Unsupported model pointer-dock plan.');
|
|
122
|
-
validatePort(ports.selection, 'selection'); validatePort(ports.snap, 'snap'); validatePort(ports.measure, 'measure');
|
|
149
|
+
validatePort(ports.selection, 'selection'); validatePort(ports.scope, 'scope'); validatePort(ports.snap, 'snap'); validatePort(ports.measure, 'measure');
|
|
123
150
|
const cleanup = []; let destroyed = false;
|
|
124
151
|
const listen = (node, type, handler) => { node.addEventListener(type, handler); cleanup.push(() => node.removeEventListener(type, handler)); };
|
|
125
152
|
try {
|
|
@@ -137,6 +164,15 @@ export function mountModelPointerDock({ selectionHost = null, snapHost = null, a
|
|
|
137
164
|
else if (!partial) dot?.remove();
|
|
138
165
|
});
|
|
139
166
|
};
|
|
167
|
+
const reflectScope = (state = ports.scope?.getState?.() ?? {}) => {
|
|
168
|
+
selectionHost?.querySelectorAll('[data-selection-scope-axis]').forEach((button) => {
|
|
169
|
+
const pressed = state[button.dataset.selectionScopeAxis] === button.dataset.selectionScopeValue;
|
|
170
|
+
button.classList.toggle('on', pressed); button.setAttribute('aria-pressed', String(pressed)); button.tabIndex = pressed ? 0 : -1;
|
|
171
|
+
});
|
|
172
|
+
const status = selectionHost?.querySelector('.model-scope-status');
|
|
173
|
+
if (status) { const text = state.drillOverride ? 'Inside group: selecting individual objects' : ''; if (status.textContent !== text) status.textContent = text; }
|
|
174
|
+
const ascend = selectionHost?.querySelector('.model-scope-ascend'); if (ascend) ascend.hidden = state.drillOverride !== true;
|
|
175
|
+
};
|
|
140
176
|
const reflectSnap = (state = ports.snap?.getState?.() ?? {}) => {
|
|
141
177
|
snapHost?.querySelectorAll('[data-snap],[data-snap3d]').forEach((button) => { const key = button.dataset.snap ?? '3d'; const on = state[key] !== false; button.classList.toggle('on', on); button.setAttribute('aria-pressed', String(on)); });
|
|
142
178
|
};
|
|
@@ -171,12 +207,26 @@ export function mountModelPointerDock({ selectionHost = null, snapHost = null, a
|
|
|
171
207
|
});
|
|
172
208
|
listen(button, 'keydown', (event) => { if ((event.key === 'Enter' || event.key === ' ') && !event.repeat) { event.preventDefault(); event.stopPropagation(); ports.selection?.toggle?.(button.dataset.cls, event); } });
|
|
173
209
|
});
|
|
210
|
+
selectionHost?.querySelectorAll('[data-selection-scope-axis]').forEach((button) => {
|
|
211
|
+
const choose = () => ports.scope?.set?.(button.dataset.selectionScopeAxis, button.dataset.selectionScopeValue);
|
|
212
|
+
listen(button, 'click', choose);
|
|
213
|
+
listen(button, 'keydown', (event) => {
|
|
214
|
+
if (event.key === 'Enter' || event.key === ' ') { if (!event.repeat) choose(); event.preventDefault(); event.stopPropagation(); return; }
|
|
215
|
+
if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key)) return;
|
|
216
|
+
const group = button.closest('[data-selection-scope-axis]')?.parentElement;
|
|
217
|
+
const items = [...(group?.querySelectorAll('[data-selection-scope-axis]') ?? [])];
|
|
218
|
+
const delta = event.key === 'ArrowLeft' || event.key === 'ArrowUp' ? -1 : 1;
|
|
219
|
+
const next = items[(items.indexOf(button) + delta + items.length) % items.length];
|
|
220
|
+
ports.scope?.set?.(next.dataset.selectionScopeAxis, next.dataset.selectionScopeValue); next.focus(); event.preventDefault(); event.stopPropagation();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
const ascend = selectionHost?.querySelector('.model-scope-ascend'); if (ascend) listen(ascend, 'click', () => ports.scope?.ascend?.());
|
|
174
224
|
snapHost?.querySelectorAll('[data-snap],[data-snap3d]').forEach((button) => listen(button, 'click', () => ports.snap?.toggle?.(button.dataset.snap ?? '3d')));
|
|
175
225
|
const measure = actionsHost?.querySelector('[data-model-action="measure"]'); if (measure) listen(measure, 'click', () => ports.measure?.toggle?.());
|
|
176
226
|
actionsHost?.querySelectorAll('[data-model-axis]').forEach((button) => listen(button, 'click', () => ports.measure?.setAxisLock?.(button.dataset.modelAxis)));
|
|
177
227
|
const clear = actionsHost?.querySelector('[data-model-action="clear"]'); if (clear) listen(clear, 'click', () => ports.measure?.clear?.());
|
|
178
228
|
|
|
179
|
-
for (const [port, reflect] of [[ports.selection, reflectSelection], [ports.snap, reflectSnap], [ports.measure, reflectMeasure]]) {
|
|
229
|
+
for (const [port, reflect] of [[ports.selection, reflectSelection], [ports.scope, reflectScope], [ports.snap, reflectSnap], [ports.measure, reflectMeasure]]) {
|
|
180
230
|
if (!port) continue; reflect(port.getState()); const unsub = port.subscribe(reflect); if (typeof unsub === 'function') cleanup.push(unsub);
|
|
181
231
|
}
|
|
182
232
|
} catch (error) {
|