@floless/app 0.138.2 → 0.139.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autostart.mjs +6 -2
- package/desktop-access-production-manifest.mjs +7 -0
- package/dist/floless-server.cjs +157207 -70887
- package/dist/schemas/model.continuation.v1.schema.json +19 -0
- package/dist/schemas/model.continuation.v2.schema.json +19 -0
- package/dist/schemas/model.query-response.v1.schema.json +95 -0
- package/dist/schemas/model.query-response.v2.schema.json +80 -0
- package/dist/schemas/model.query.v1.schema.json +87 -0
- package/dist/schemas/model.query.v2.schema.json +87 -0
- package/dist/schemas/model.snap-candidate.v1.schema.json +48 -0
- package/dist/schemas/model.snap-constraint.v1.schema.json +18 -0
- package/dist/schemas/model.snap-query.v1.schema.json +24 -0
- package/dist/schemas/model.snap-result.v1.schema.json +33 -0
- package/dist/schemas/model.snapshot.v1.schema.json +136 -0
- package/dist/schemas/revit.model.v1.schema.json +24 -0
- package/dist/schemas/steel.model.v2.schema.json +45 -6
- package/dist/skills/floless-app-approval/SKILL.md +19 -5
- package/dist/skills/floless-app-bridge/SKILL.md +19 -6
- package/dist/skills/floless-app-knowledge/SKILL.md +22 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +31 -27
- package/dist/skills/floless-app-new-workflow/references/build-and-verify.md +13 -12
- package/dist/skills/floless-app-onboarding/SKILL.md +3 -3
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +16 -9
- package/dist/skills/floless-app-steel-model/SKILL.md +11 -2
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +95 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +142 -21
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +19 -0
- package/dist/skills/floless-app-tweak-contract/SKILL.md +42 -8
- package/dist/skills/floless-app-vectorize/SKILL.md +19 -6
- package/dist/skills/floless-app-workflows/SKILL.md +30 -3
- package/dist/skills/floless-app-workflows/references/workspace-data.md +77 -4
- package/dist/templates/floless-workspace-model-report.flo +77 -0
- package/dist/templates/revit-model.flo +111 -0
- package/dist/web/app.css +415 -177
- package/dist/web/app.js +302 -51
- package/dist/web/aware.js +1357 -1032
- package/dist/web/chat.css +692 -0
- package/dist/web/chat.js +2651 -0
- package/dist/web/commands-revit.js +42 -0
- package/dist/web/commands-shell.js +531 -70
- package/dist/web/commands-steel.js +344 -146
- package/dist/web/commands.js +1 -1
- package/dist/web/index.html +283 -77
- package/dist/web/instructor.js +217 -36
- package/dist/web/left-pane.js +636 -0
- package/dist/web/model-artifact-loader.js +75 -0
- package/dist/web/model-authoring-gestures.js +141 -0
- package/dist/web/model-cad-tools.js +20 -0
- package/dist/web/model-clip-gesture.js +148 -0
- package/dist/web/model-clip-list.js +156 -0
- package/dist/web/model-clip-session.js +274 -0
- package/dist/web/model-clip-three-overlay.js +295 -0
- package/dist/web/model-clip-three-preview.js +59 -0
- package/dist/web/model-editor-contract.js +519 -0
- package/dist/web/model-editor-revit-adapter.js +139 -0
- package/dist/web/model-editor-shell.js +271 -0
- package/dist/web/model-editor-state-recovery.js +44 -0
- package/dist/web/model-editor-steel-adapter.js +415 -0
- package/dist/web/model-editor.css +268 -0
- package/dist/web/model-frame.js +192 -0
- package/dist/web/model-inspector.js +128 -0
- package/dist/web/model-measure.js +390 -0
- package/dist/web/model-navigation-controls.js +246 -0
- package/dist/web/model-orientation-overlay.js +217 -0
- package/dist/web/model-panel-bridge.js +230 -0
- package/dist/web/model-pointer-dock.js +164 -0
- package/dist/web/model-revit-module.js +83 -0
- package/dist/web/model-selection-coordinator.js +151 -0
- package/dist/web/model-selection-tools.js +290 -0
- package/dist/web/model-snap-contract.js +267 -0
- package/dist/web/model-snapping.js +497 -0
- package/dist/web/model-spatial-panel.js +294 -0
- package/dist/web/model-spatial-tools.js +249 -0
- package/dist/web/model-tree.js +47 -0
- package/dist/web/model-viewport-lighting.js +166 -0
- package/dist/web/model-viewport-revit-adapter.js +1224 -0
- package/dist/web/model-viewport-state.js +505 -0
- package/dist/web/model-viewport-steel-adapter.js +150 -0
- package/dist/web/model-viewport-toolbar.js +516 -0
- package/dist/web/model-viewport.js +717 -0
- package/dist/web/panels.js +8 -15
- package/dist/web/renderers.js +3 -0
- package/dist/web/revit-editor.css +35 -0
- package/dist/web/revit-editor.html +74 -0
- package/dist/web/revit-editor.js +845 -0
- package/dist/web/steel-3d-core.js +16 -44
- package/dist/web/steel-3d-view.js +1384 -633
- package/dist/web/steel-canvas-guidance.js +3 -1
- package/dist/web/steel-editor.html +2145 -1255
- package/dist/web/steel-filter.html +5 -1
- package/dist/web/steel-model-v2-commands.js +80 -3
- package/dist/web/steel-split-view.js +5 -39
- package/dist/web/steel-view-generation.js +107 -17
- package/dist/web/vector-3d.html +12 -0
- package/dist/web/workspaces.js +2154 -283
- package/distribution-profile-active.mjs +2 -0
- package/distribution-profile-production.mjs +47 -0
- package/distribution-profile-shared.mjs +8 -0
- package/distribution-profile.mjs +18 -0
- package/distribution-resource-inventory.mjs +81 -0
- package/launch.mjs +18 -10
- package/log.mjs +2 -1
- package/managed-runtime-policy.mjs +104 -0
- package/model-reader-policy-active.mjs +7 -0
- package/network-policy-active.mjs +6 -0
- package/package.json +17 -2
- package/post-update-marker.mjs +3 -1
- package/rvt-production-uat-authority.mjs +60 -0
- package/teardown.mjs +4 -3
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CHANNEL = 'floless:model-panel';
|
|
5
|
+
const VERSION = 1;
|
|
6
|
+
const STORAGE_KEY = 'floless:left-pane-v1';
|
|
7
|
+
const frame = document.getElementById('ws-frame-model');
|
|
8
|
+
let overlayFrame = null; // an editor opened full-window over the main window (Workflows → Edit contract) — see useOverlayModelFrame
|
|
9
|
+
const modelFrame = () => overlayFrame || frame;
|
|
10
|
+
const modelVisible = () => !!overlayFrame || state.workspaceModelVisible;
|
|
11
|
+
const pane = document.getElementById('chat-panel');
|
|
12
|
+
const stack = document.getElementById('left-pane-stack');
|
|
13
|
+
const split = document.getElementById('left-pane-split');
|
|
14
|
+
const status = document.getElementById('left-pane-status');
|
|
15
|
+
const modelTabs = document.getElementById('left-model-tabs');
|
|
16
|
+
const modelIndexLabel = document.getElementById('left-model-index-label');
|
|
17
|
+
const followSelection = document.getElementById('left-model-follow-selection');
|
|
18
|
+
const modelContent = document.getElementById('left-model-content');
|
|
19
|
+
const collapsedHost = document.getElementById('left-collapsed-sections');
|
|
20
|
+
const empty = document.getElementById('left-pane-empty');
|
|
21
|
+
const modelContext = document.getElementById('left-model-context');
|
|
22
|
+
const modelIndexHeader = document.getElementById('left-model-index-header');
|
|
23
|
+
// A PANEL tab's slot (web/model-panel-bridge.js has the contract): the editor moves its own controls into
|
|
24
|
+
// this frame. It is replaced by a fresh, empty one whenever the generation changes, so a departing editor's
|
|
25
|
+
// controls leave with it. No src: the frame's first about:blank document is this origin and stays put.
|
|
26
|
+
const panelSlot = document.getElementById('left-model-panel-slot');
|
|
27
|
+
let panelFrame = document.getElementById('left-model-panel');
|
|
28
|
+
if (!frame || !pane || !stack || !split || !status || !modelTabs || !modelIndexLabel || !followSelection || !modelContent || !collapsedHost || !empty || !modelContext
|
|
29
|
+
|| !modelIndexHeader || !panelSlot || !panelFrame) return;
|
|
30
|
+
|
|
31
|
+
const sections = {
|
|
32
|
+
narrative: stack.querySelector('[data-left-section="narrative"]'),
|
|
33
|
+
model: stack.querySelector('[data-left-section="model"]'),
|
|
34
|
+
};
|
|
35
|
+
const switches = {
|
|
36
|
+
narrative: pane.querySelector('[data-left-section-switch="narrative"]'),
|
|
37
|
+
model: pane.querySelector('[data-left-section-switch="model"]'),
|
|
38
|
+
};
|
|
39
|
+
const defaults = { order: ['narrative', 'model'], visible: { narrative: true, model: true }, ratio: 58, tab: 'model', followSelection: true };
|
|
40
|
+
let stored = {};
|
|
41
|
+
try { stored = JSON.parse(localStorage.getItem(STORAGE_KEY) || '{}'); } catch { /* a locked-down profile still gets the pane */ }
|
|
42
|
+
const validOrder = Array.isArray(stored.order) && stored.order.length === 2
|
|
43
|
+
&& stored.order.includes('narrative') && stored.order.includes('model');
|
|
44
|
+
const state = {
|
|
45
|
+
order: validOrder ? stored.order.slice() : defaults.order.slice(),
|
|
46
|
+
visible: {
|
|
47
|
+
narrative: stored.visible?.narrative !== false,
|
|
48
|
+
model: stored.visible?.model !== false,
|
|
49
|
+
},
|
|
50
|
+
ratio: Number.isFinite(stored.ratio) ? Math.max(25, Math.min(75, stored.ratio)) : defaults.ratio,
|
|
51
|
+
tab: typeof stored.tab === 'string' ? stored.tab : defaults.tab,
|
|
52
|
+
followSelection: typeof stored.followSelection === 'boolean' ? stored.followSelection : defaults.followSelection,
|
|
53
|
+
modelAvailable: false,
|
|
54
|
+
workspaceModelVisible: false,
|
|
55
|
+
snapshot: null,
|
|
56
|
+
datasetKey: null,
|
|
57
|
+
revision: -1,
|
|
58
|
+
generation: 0,
|
|
59
|
+
};
|
|
60
|
+
const sessionVisible = { narrative: false, model: false };
|
|
61
|
+
const groupDisclosure = new Map();
|
|
62
|
+
let dragKey = null;
|
|
63
|
+
let splitSession = null;
|
|
64
|
+
let nextActionId = 0;
|
|
65
|
+
let revealSequence = 0;
|
|
66
|
+
let pendingRevealId = null;
|
|
67
|
+
let selectAnchor = null; // the list row last clicked without Shift: where a Shift-click's range starts
|
|
68
|
+
let pendingSelectIds = null; // what the last click asked for, until the editor answers: a quick second Ctrl-click builds on it
|
|
69
|
+
const pendingActions = new Map();
|
|
70
|
+
let panelShown = null; // the panel tab the editor was last told it is showing (null: none)
|
|
71
|
+
let chosenByPerson = false; // true only while a click on a tab renders: the editor is told a person chose it
|
|
72
|
+
let displacedTab = null; // a chosen tab the snapshot stopped offering (a 3D-only tab while in 2D); it comes back with it
|
|
73
|
+
|
|
74
|
+
const panelTabsOf = (snapshot) => (Array.isArray(snapshot?.panelTabs) ? snapshot.panelTabs : [])
|
|
75
|
+
.filter((tab) => typeof tab?.key === 'string' && typeof tab?.label === 'string');
|
|
76
|
+
const isPanelTab = (key) => panelTabsOf(state.snapshot).some((tab) => tab.key === key);
|
|
77
|
+
// A panel tab can follow the selection itself (steel's Objects): it gets the Follow selection switch, and the editor its state.
|
|
78
|
+
const followTip = followSelection.closest('[data-tip]');
|
|
79
|
+
const LIST_FOLLOW_TIP = followTip?.dataset.tip || '';
|
|
80
|
+
const followsTab = (key) => panelTabsOf(state.snapshot).some((tab) => tab.key === key && tab.follows === true);
|
|
81
|
+
function resetPanelFrame() {
|
|
82
|
+
panelShown = null;
|
|
83
|
+
const fresh = panelFrame.cloneNode(false); panelFrame.replaceWith(fresh); panelFrame = fresh;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function save() {
|
|
87
|
+
try { localStorage.setItem(STORAGE_KEY, JSON.stringify({ order: state.order, visible: state.visible, ratio: state.ratio, tab: state.tab, followSelection: state.followSelection })); }
|
|
88
|
+
catch (error) { console.warn('[left-pane] Could not save panel layout.', error); }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
followSelection.checked = state.followSelection;
|
|
92
|
+
followSelection.setAttribute('aria-checked', String(state.followSelection));
|
|
93
|
+
followSelection.addEventListener('change', () => {
|
|
94
|
+
state.followSelection = followSelection.checked;
|
|
95
|
+
followSelection.setAttribute('aria-checked', String(state.followSelection));
|
|
96
|
+
save();
|
|
97
|
+
status.textContent = `Follow selection ${state.followSelection ? 'on' : 'off'}.`;
|
|
98
|
+
if (state.followSelection) revealSelectedEntity();
|
|
99
|
+
if (followsTab(state.tab)) { panelShown = null; renderModel(); } // the editor draws the following, so it is told again
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
function available(key) { return key === 'narrative' || state.modelAvailable; }
|
|
103
|
+
function shown(key) { return available(key) && (state.visible[key] || sessionVisible[key]); }
|
|
104
|
+
function commandInstance(value) { return encodeURIComponent(String(value)); }
|
|
105
|
+
|
|
106
|
+
function applyChatIndicator(button) {
|
|
107
|
+
const chat = document.getElementById('ai-chat-shell');
|
|
108
|
+
const unread = Math.max(0, Number(chat?.dataset.unreadCount || 0));
|
|
109
|
+
const approval = chat?.dataset.approvalPending === 'true';
|
|
110
|
+
button.querySelector('.left-collapsed-badge')?.remove();
|
|
111
|
+
button.setAttribute('aria-label', 'Expand AI Chat');
|
|
112
|
+
if (!unread && !approval) return;
|
|
113
|
+
const badge = document.createElement('span');
|
|
114
|
+
badge.className = `left-collapsed-badge${approval ? ' approval' : ''}`;
|
|
115
|
+
badge.textContent = approval ? '!' : (unread > 99 ? '99+' : String(unread));
|
|
116
|
+
badge.setAttribute('aria-hidden', 'true');
|
|
117
|
+
button.append(badge);
|
|
118
|
+
const states = [unread ? `${unread} unread chat event${unread === 1 ? '' : 's'}` : '', approval ? 'approval needed' : '']
|
|
119
|
+
.filter(Boolean).join(', ');
|
|
120
|
+
button.setAttribute('aria-label', `Expand AI Chat, ${states}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function syncChatIndicator() {
|
|
124
|
+
const button = collapsedHost.querySelector('[data-left-collapsed-section="narrative"]');
|
|
125
|
+
if (button) applyChatIndicator(button);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function collapsedButton(key) {
|
|
129
|
+
const label = key === 'model' ? 'Model' : 'AI Chat';
|
|
130
|
+
const button = document.createElement('button');
|
|
131
|
+
button.type = 'button';
|
|
132
|
+
button.className = 'left-collapsed-section';
|
|
133
|
+
button.dataset.commandId = `shell.left-section#${label}`;
|
|
134
|
+
button.dataset.commandInstanceLabel = label;
|
|
135
|
+
button.dataset.leftCollapsedSection = key;
|
|
136
|
+
button.setAttribute('aria-pressed', String(shown(key)));
|
|
137
|
+
button.setAttribute('aria-label', `Expand ${label}`);
|
|
138
|
+
button.dataset.tip = `Expand ${label}`;
|
|
139
|
+
button.textContent = label;
|
|
140
|
+
if (key === 'narrative') applyChatIndicator(button);
|
|
141
|
+
return button;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function arrange() {
|
|
145
|
+
const first = state.order[0];
|
|
146
|
+
const second = state.order[1];
|
|
147
|
+
stack.append(sections[first], split, sections[second], empty);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function reflect() {
|
|
151
|
+
const both = shown('narrative') && shown('model');
|
|
152
|
+
const first = state.order[0];
|
|
153
|
+
split.hidden = !both;
|
|
154
|
+
empty.hidden = shown('narrative') || shown('model');
|
|
155
|
+
pane.setAttribute('aria-label', state.modelAvailable ? 'AI Chat and Model panels' : 'AI Chat panel');
|
|
156
|
+
for (const key of Object.keys(sections)) {
|
|
157
|
+
const isShown = shown(key);
|
|
158
|
+
sections[key].hidden = !isShown;
|
|
159
|
+
switches[key].hidden = !available(key);
|
|
160
|
+
switches[key].setAttribute('aria-pressed', String(isShown));
|
|
161
|
+
sections[key].style.flex = both
|
|
162
|
+
? `0 0 calc(${key === first ? state.ratio : 100 - state.ratio}% - 5.5px)`
|
|
163
|
+
: (isShown ? '1 1 auto' : '0 0 auto');
|
|
164
|
+
}
|
|
165
|
+
if (both) {
|
|
166
|
+
const topPercent = Math.round(state.ratio);
|
|
167
|
+
split.setAttribute('aria-valuemin', '25');
|
|
168
|
+
split.setAttribute('aria-valuemax', '75');
|
|
169
|
+
split.setAttribute('aria-valuenow', String(topPercent));
|
|
170
|
+
split.setAttribute('aria-valuetext', `${topPercent}% for ${first === 'model' ? 'Model' : 'AI Chat'}`);
|
|
171
|
+
}
|
|
172
|
+
collapsedHost.replaceChildren(...state.order.filter(available).map(collapsedButton));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function setVisible(key, value, announce = true) {
|
|
176
|
+
if (!available(key)) return;
|
|
177
|
+
sessionVisible[key] = false;
|
|
178
|
+
state.visible[key] = !!value;
|
|
179
|
+
save(); reflect();
|
|
180
|
+
if (announce) status.textContent = `${key === 'model' ? 'Model' : 'AI Chat'} panel ${value ? 'shown' : 'hidden'}.`;
|
|
181
|
+
if (key === 'model' && value && pendingRevealId) revealSelectedEntity();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function move(key, delta, announce = true) {
|
|
185
|
+
// A panel move also rewrites the ratio so each section keeps its physical
|
|
186
|
+
// height. Do not let it sample the temporary ratio from an unfinished
|
|
187
|
+
// splitter gesture; Escape must still be able to restore one coherent state.
|
|
188
|
+
if (splitSession) return;
|
|
189
|
+
const from = state.order.indexOf(key);
|
|
190
|
+
const to = Math.max(0, Math.min(state.order.length - 1, from + delta));
|
|
191
|
+
if (from < 0 || from === to) return;
|
|
192
|
+
state.order.splice(from, 1); state.order.splice(to, 0, key);
|
|
193
|
+
state.ratio = 100 - state.ratio;
|
|
194
|
+
save(); arrange(); reflect();
|
|
195
|
+
if (panelShown !== null) { panelShown = null; renderModel(); } // the move re-created the panel frame's document
|
|
196
|
+
if (announce) status.textContent = `${key === 'model' ? 'Model' : 'AI Chat'} panel moved ${to === 0 ? 'above' : 'below'} ${state.order[1 - to] === 'model' ? 'Model' : 'AI Chat'}.`;
|
|
197
|
+
pane.querySelector(`[data-left-reorder="${key}"]`)?.focus();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
pane.addEventListener('click', (event) => {
|
|
201
|
+
const switcher = event.target.closest('[data-left-section-switch]');
|
|
202
|
+
if (switcher) { const key = switcher.dataset.leftSectionSwitch; setVisible(key, !shown(key)); return; }
|
|
203
|
+
const close = event.target.closest('[data-left-section-close]');
|
|
204
|
+
if (close) {
|
|
205
|
+
const key = close.dataset.leftSectionClose;
|
|
206
|
+
switches[key]?.focus({ preventScroll: true });
|
|
207
|
+
setVisible(key, false);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const collapsed = event.target.closest('[data-left-collapsed-section]');
|
|
211
|
+
if (collapsed) {
|
|
212
|
+
setVisible(collapsed.dataset.leftCollapsedSection, true, false);
|
|
213
|
+
document.querySelector('.pane-rail-left .panel-toggle[data-side="left"]')?.click();
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
pane.addEventListener('keydown', (event) => {
|
|
218
|
+
const grip = event.target.closest('[data-left-reorder]');
|
|
219
|
+
if (grip && event.altKey && ['ArrowUp', 'ArrowDown'].includes(event.key)) {
|
|
220
|
+
event.preventDefault(); move(grip.dataset.leftReorder, event.key === 'ArrowUp' ? -1 : 1); return;
|
|
221
|
+
}
|
|
222
|
+
const sectionSwitch = event.target.closest('[data-left-section-switch]');
|
|
223
|
+
if (!sectionSwitch || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
224
|
+
const live = [...pane.querySelectorAll('[data-left-section-switch]:not([hidden])')];
|
|
225
|
+
const index = live.indexOf(sectionSwitch);
|
|
226
|
+
const next = event.key === 'Home' ? 0 : event.key === 'End' ? live.length - 1
|
|
227
|
+
: (index + (event.key === 'ArrowRight' ? 1 : -1) + live.length) % live.length;
|
|
228
|
+
event.preventDefault(); live[next]?.focus();
|
|
229
|
+
});
|
|
230
|
+
document.addEventListener('floless:chat-indicator', syncChatIndicator);
|
|
231
|
+
pane.querySelectorAll('[data-left-reorder]').forEach((grip) => {
|
|
232
|
+
grip.addEventListener('dragstart', (event) => {
|
|
233
|
+
if (splitSession) { event.preventDefault(); return; }
|
|
234
|
+
dragKey = grip.dataset.leftReorder; event.dataTransfer.effectAllowed = 'move'; event.dataTransfer.setData('text/plain', dragKey);
|
|
235
|
+
});
|
|
236
|
+
grip.addEventListener('dragend', () => { dragKey = null; pane.querySelectorAll('.drag-over').forEach((el) => el.classList.remove('drag-over')); });
|
|
237
|
+
});
|
|
238
|
+
pane.querySelectorAll('[data-left-section]').forEach((section) => {
|
|
239
|
+
section.addEventListener('dragover', (event) => { if (!dragKey || dragKey === section.dataset.leftSection) return; event.preventDefault(); section.classList.add('drag-over'); });
|
|
240
|
+
section.addEventListener('dragleave', () => section.classList.remove('drag-over'));
|
|
241
|
+
section.addEventListener('drop', (event) => {
|
|
242
|
+
event.preventDefault(); section.classList.remove('drag-over');
|
|
243
|
+
const target = section.dataset.leftSection;
|
|
244
|
+
if (dragKey && dragKey !== target) move(dragKey, state.order.indexOf(target) - state.order.indexOf(dragKey));
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
function setRatio(value) { state.ratio = Math.max(25, Math.min(75, value)); reflect(); }
|
|
249
|
+
function finishSplit(commit) {
|
|
250
|
+
if (!splitSession) return;
|
|
251
|
+
const session = splitSession;
|
|
252
|
+
splitSession = null;
|
|
253
|
+
split.classList.remove('dragging'); document.body.classList.remove('left-pane-height-resizing');
|
|
254
|
+
if (!commit) state.ratio = session.startRatio;
|
|
255
|
+
try { if (!split.hasPointerCapture || split.hasPointerCapture(session.pointerId)) split.releasePointerCapture(session.pointerId); } catch { /* capture may already be gone */ }
|
|
256
|
+
reflect();
|
|
257
|
+
if (commit) save();
|
|
258
|
+
}
|
|
259
|
+
split.addEventListener('pointerdown', (event) => {
|
|
260
|
+
if (event.button !== 0 || event.isPrimary === false) return;
|
|
261
|
+
if (splitSession) finishSplit(false);
|
|
262
|
+
event.preventDefault(); split.focus();
|
|
263
|
+
const rect = stack.getBoundingClientRect();
|
|
264
|
+
if (!(rect.height > 0)) return;
|
|
265
|
+
splitSession = { pointerId: event.pointerId, top: rect.top, height: rect.height, startRatio: state.ratio };
|
|
266
|
+
try { split.setPointerCapture(event.pointerId); } catch { /* window listeners still own the gesture */ }
|
|
267
|
+
split.classList.add('dragging'); document.body.classList.add('left-pane-height-resizing');
|
|
268
|
+
});
|
|
269
|
+
window.addEventListener('pointermove', (event) => {
|
|
270
|
+
if (!splitSession || event.pointerId !== splitSession.pointerId) return;
|
|
271
|
+
if (event.pointerType === 'mouse' && event.buttons === 0) { finishSplit(true); return; }
|
|
272
|
+
setRatio(((event.clientY - splitSession.top) / splitSession.height) * 100);
|
|
273
|
+
});
|
|
274
|
+
window.addEventListener('pointerup', (event) => { if (splitSession?.pointerId === event.pointerId) finishSplit(true); });
|
|
275
|
+
window.addEventListener('pointercancel', (event) => { if (splitSession?.pointerId === event.pointerId) finishSplit(false); });
|
|
276
|
+
split.addEventListener('lostpointercapture', (event) => { if (splitSession?.pointerId === event.pointerId) finishSplit(false); });
|
|
277
|
+
window.addEventListener('blur', () => finishSplit(false));
|
|
278
|
+
document.addEventListener('visibilitychange', () => { if (document.hidden) finishSplit(false); });
|
|
279
|
+
split.addEventListener('dblclick', (event) => {
|
|
280
|
+
if (splitSession) { event.preventDefault(); return; }
|
|
281
|
+
state.ratio = defaults.ratio; save(); reflect();
|
|
282
|
+
});
|
|
283
|
+
window.addEventListener('keydown', (event) => {
|
|
284
|
+
if (event.key === 'Escape' && splitSession) { event.preventDefault(); finishSplit(false); return; }
|
|
285
|
+
if (event.target !== split) return;
|
|
286
|
+
if (splitSession) {
|
|
287
|
+
if (['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) event.preventDefault();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (event.key === 'Enter') { event.preventDefault(); state.ratio = defaults.ratio; save(); reflect(); return; }
|
|
291
|
+
if (!['ArrowUp', 'ArrowDown'].includes(event.key)) return;
|
|
292
|
+
event.preventDefault(); setRatio(state.ratio + (event.key === 'ArrowUp' ? -1 : 1) * (event.shiftKey ? 10 : 2)); save();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
function renderNodes(nodes, host) {
|
|
296
|
+
const scrollTop = host.scrollTop;
|
|
297
|
+
host.replaceChildren();
|
|
298
|
+
if (!Array.isArray(nodes) || !nodes.length) { const empty = document.createElement('div'); empty.className = 'left-model-empty'; empty.textContent = 'No objects in this index.'; host.append(empty); return; }
|
|
299
|
+
const append = (items, parent) => {
|
|
300
|
+
for (const node of items) {
|
|
301
|
+
if (!node || typeof node.label !== 'string') continue;
|
|
302
|
+
if (node.kind === 'label' || node.kind === 'note') {
|
|
303
|
+
const copy = document.createElement('div'); copy.className = node.kind === 'label' ? 'revit-explorer-label' : 'left-model-empty'; copy.setAttribute('role', 'presentation'); copy.textContent = node.label; parent.append(copy); continue;
|
|
304
|
+
}
|
|
305
|
+
const row = document.createElement('button'); row.type = 'button'; row.className = 'left-model-row';
|
|
306
|
+
const instance = node.entityId || node.groupId || node.label;
|
|
307
|
+
row.dataset.commandId = node.entityId
|
|
308
|
+
? `shell.model-item#${commandInstance(instance)}`
|
|
309
|
+
: `shell.model-group#${commandInstance(instance)}`;
|
|
310
|
+
row.dataset.commandInstanceLabel = node.label;
|
|
311
|
+
const accessibleLabel = node.count == null ? node.label : `${node.label}, ${node.count}`;
|
|
312
|
+
row.setAttribute('aria-label', accessibleLabel);
|
|
313
|
+
if (typeof node.tip === 'string' && node.tip) row.dataset.tip = node.tip;
|
|
314
|
+
const label = document.createElement('span'); label.className = 'row-label'; label.textContent = node.label; row.append(label);
|
|
315
|
+
if (node.count != null) { const count = document.createElement('span'); count.className = 'explorer-count'; count.textContent = String(node.count); row.append(count); }
|
|
316
|
+
if (node.entityId) {
|
|
317
|
+
row.dataset.entityId = node.entityId;
|
|
318
|
+
row.classList.toggle('selected', selectedIdsOf(state.snapshot).includes(node.entityId));
|
|
319
|
+
if (node.entityId === state.snapshot?.selectedId) row.setAttribute('aria-current', 'true');
|
|
320
|
+
row.addEventListener('click', (event) => selectRow(node.entityId, event));
|
|
321
|
+
const item = document.createElement('div'); item.setAttribute('role', 'listitem'); item.append(row);
|
|
322
|
+
parent.append(item); continue;
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(node.children)) {
|
|
325
|
+
const branch = document.createElement('div'); branch.className = 'left-model-branch'; branch.setAttribute('role', 'listitem');
|
|
326
|
+
const disclosureKey = `${state.datasetKey}:${state.tab}:${node.groupId || node.label}`;
|
|
327
|
+
const expanded = groupDisclosure.has(disclosureKey) ? groupDisclosure.get(disclosureKey) : !!node.expanded;
|
|
328
|
+
row.setAttribute('aria-expanded', String(expanded));
|
|
329
|
+
const children = document.createElement('div'); children.className = 'left-model-children'; children.setAttribute('role', 'list'); children.hidden = !expanded; append(node.children, children);
|
|
330
|
+
const requestLazyChildren = () => {
|
|
331
|
+
if (row.getAttribute('aria-busy') === 'true') return;
|
|
332
|
+
const outstanding = [...pendingActions.values()].some((pending) => pending.kind === 'expand' && pending.disclosureKey === disclosureKey);
|
|
333
|
+
if (outstanding) { row.setAttribute('aria-busy', 'true'); return; }
|
|
334
|
+
row.setAttribute('aria-busy', 'true');
|
|
335
|
+
const requestId = sendAction({ action: 'expand', groupId: node.groupId, datasetKey: state.datasetKey });
|
|
336
|
+
if (requestId) pendingActions.set(requestId, { kind: 'expand', row, disclosureKey, commandId: row.dataset.commandId });
|
|
337
|
+
else row.removeAttribute('aria-busy');
|
|
338
|
+
};
|
|
339
|
+
row.addEventListener('click', () => {
|
|
340
|
+
if (node.lazy && !node.children.length) { requestLazyChildren(); return; }
|
|
341
|
+
const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); children.hidden = !open;
|
|
342
|
+
groupDisclosure.set(disclosureKey, open);
|
|
343
|
+
});
|
|
344
|
+
branch.append(row, children); parent.append(branch);
|
|
345
|
+
if (expanded && node.lazy && !node.children.length) requestLazyChildren();
|
|
346
|
+
} else {
|
|
347
|
+
const item = document.createElement('div'); item.setAttribute('role', 'listitem'); item.append(row); parent.append(item);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const tree = document.createElement('div'); tree.className = 'left-model-tree'; tree.setAttribute('role', 'list');
|
|
352
|
+
const count = nodes.reduce((sum, node) => sum + (Number(node?.count) || (node?.entityId ? 1 : 0)), 0);
|
|
353
|
+
tree.setAttribute('aria-label', count ? `Model index, ${count} items` : 'Model index');
|
|
354
|
+
append(nodes, tree); host.append(tree); host.scrollTop = scrollTop;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function revealSelectedEntity() {
|
|
358
|
+
const selectedIds = selectedIdsOf(state.snapshot);
|
|
359
|
+
// A panel tab is the editor's own tool, chosen on purpose: a canvas pick does not pull the user off it.
|
|
360
|
+
if (!state.followSelection || selectedIds.length !== 1 || state.snapshot?.selectionOrigin !== 'viewport' || isPanelTab(state.tab)) {
|
|
361
|
+
revealSequence++; pendingRevealId = null; return false;
|
|
362
|
+
}
|
|
363
|
+
const selectedId = selectedIds[0];
|
|
364
|
+
pendingRevealId = selectedId;
|
|
365
|
+
if (state.tab !== 'model') { state.tab = 'model'; renderModel(); }
|
|
366
|
+
const row = [...modelContent.querySelectorAll('[data-entity-id]')]
|
|
367
|
+
.find((candidate) => candidate.dataset.entityId === selectedId);
|
|
368
|
+
if (!row) return false;
|
|
369
|
+
let children = row.closest('.left-model-children');
|
|
370
|
+
while (children) {
|
|
371
|
+
children.hidden = false;
|
|
372
|
+
const branch = children.closest('.left-model-branch');
|
|
373
|
+
const trigger = branch?.querySelector(':scope > .left-model-row');
|
|
374
|
+
if (trigger) {
|
|
375
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
376
|
+
const groupId = trigger.dataset.commandId?.replace(/^shell\.model-group#/, '');
|
|
377
|
+
if (groupId) groupDisclosure.set(`${state.datasetKey}:${state.tab}:${groupId}`, true);
|
|
378
|
+
}
|
|
379
|
+
children = branch?.parentElement?.closest('.left-model-children') || null;
|
|
380
|
+
}
|
|
381
|
+
const sequence = ++revealSequence;
|
|
382
|
+
const generation = state.generation;
|
|
383
|
+
const revision = state.revision;
|
|
384
|
+
const schedule = window.requestAnimationFrame || ((callback) => callback());
|
|
385
|
+
const center = (attempt = 0) => schedule(() => {
|
|
386
|
+
const liveIds = Array.isArray(state.snapshot?.selectedIds) ? state.snapshot.selectedIds : [];
|
|
387
|
+
if (sequence !== revealSequence || generation !== state.generation || revision !== state.revision
|
|
388
|
+
|| !state.followSelection || state.snapshot?.selectionOrigin !== 'viewport'
|
|
389
|
+
|| liveIds.length !== 1 || liveIds[0] !== selectedId) return;
|
|
390
|
+
if (!shown('model') || sections.model.hidden) { pendingRevealId = selectedId; return; }
|
|
391
|
+
const liveRow = [...modelContent.querySelectorAll('[data-entity-id]')]
|
|
392
|
+
.find((candidate) => candidate.dataset.entityId === selectedId);
|
|
393
|
+
if (!liveRow) { pendingRevealId = selectedId; return; }
|
|
394
|
+
const hostRect = modelContent.getBoundingClientRect();
|
|
395
|
+
const rowRect = liveRow.getBoundingClientRect();
|
|
396
|
+
const viewportHeight = modelContent.clientHeight || hostRect.height || 0;
|
|
397
|
+
if (!(viewportHeight > 0)) {
|
|
398
|
+
if (attempt === 0) center(1); else pendingRevealId = selectedId;
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const currentTop = Number(modelContent.scrollTop) || 0;
|
|
402
|
+
const maxTop = Math.max(0, (Number(modelContent.scrollHeight) || viewportHeight) - viewportHeight);
|
|
403
|
+
const target = currentTop + (rowRect.top + rowRect.height / 2) - (hostRect.top + viewportHeight / 2);
|
|
404
|
+
const top = Math.max(0, Math.min(maxTop, target));
|
|
405
|
+
const reducedMotion = typeof window.matchMedia === 'function'
|
|
406
|
+
&& window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
407
|
+
modelContent.scrollTo?.({ top, left: Number(modelContent.scrollLeft) || 0, behavior: reducedMotion ? 'auto' : 'smooth' });
|
|
408
|
+
pendingRevealId = null;
|
|
409
|
+
status.textContent = `${liveRow.querySelector('.row-label')?.textContent || 'Selected object'} centred in Model tree.`;
|
|
410
|
+
});
|
|
411
|
+
center();
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function renderModel() {
|
|
416
|
+
const snapshot = state.snapshot;
|
|
417
|
+
if (!snapshot) return;
|
|
418
|
+
const tabs = [...(Array.isArray(snapshot.tabs) ? snapshot.tabs : []), ...panelTabsOf(snapshot)];
|
|
419
|
+
if (displacedTab && tabs.some((tab) => tab.key === displacedTab)) { state.tab = displacedTab; displacedTab = null; }
|
|
420
|
+
if (!tabs.some((tab) => tab.key === state.tab)) { if (state.tab) displacedTab = state.tab; state.tab = tabs[0]?.key || ''; }
|
|
421
|
+
const focusedKey = document.activeElement?.closest?.('#left-model-tabs button')?.dataset.modelTabKey || null;
|
|
422
|
+
const existing = new Map([...modelTabs.querySelectorAll('button')].map((button) => [button.dataset.modelTabKey, button]));
|
|
423
|
+
// Panel tabs start their own row, so the lists and the editor's tools read as two groups.
|
|
424
|
+
const firstPanel = Array.isArray(snapshot.tabs) && snapshot.tabs.length ? panelTabsOf(snapshot)[0]?.key : null;
|
|
425
|
+
const buttons = tabs.map((tab) => {
|
|
426
|
+
const button = existing.get(tab.key) || document.createElement('button'); button.type = 'button'; button.textContent = tab.label;
|
|
427
|
+
button.dataset.tip = typeof tab.tip === 'string' && tab.tip ? tab.tip : tab.label; // also the full name when a narrow pane cuts the label short
|
|
428
|
+
button.classList.toggle('left-model-tab-group-start', tab.key === firstPanel);
|
|
429
|
+
button.id = `left-model-tab-${tab.key}`;
|
|
430
|
+
button.dataset.modelTabKey = tab.key;
|
|
431
|
+
button.dataset.commandId = `shell.model-tab#${tab.key}`; button.dataset.commandInstanceLabel = tab.label;
|
|
432
|
+
button.setAttribute('role', 'tab'); button.setAttribute('aria-controls', isPanelTab(tab.key) ? 'left-model-panel-slot' : 'left-model-content');
|
|
433
|
+
button.setAttribute('aria-selected', String(tab.key === state.tab)); button.tabIndex = tab.key === state.tab ? 0 : -1;
|
|
434
|
+
if (!button.dataset.leftPaneBound) {
|
|
435
|
+
button.dataset.leftPaneBound = 'true';
|
|
436
|
+
button.addEventListener('click', () => {
|
|
437
|
+
state.tab = button.dataset.modelTabKey; displacedTab = null; save();
|
|
438
|
+
chosenByPerson = true; try { renderModel(); } finally { chosenByPerson = false; }
|
|
439
|
+
button.focus();
|
|
440
|
+
});
|
|
441
|
+
button.addEventListener('keydown', (event) => {
|
|
442
|
+
const liveTabs = [...modelTabs.querySelectorAll('button')];
|
|
443
|
+
const index = liveTabs.indexOf(button);
|
|
444
|
+
if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); button.click(); return; }
|
|
445
|
+
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
446
|
+
event.preventDefault();
|
|
447
|
+
const next = event.key === 'Home' ? 0 : event.key === 'End' ? liveTabs.length - 1 : (index + (event.key === 'ArrowRight' ? 1 : -1) + liveTabs.length) % liveTabs.length;
|
|
448
|
+
liveTabs[next]?.focus();
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return button;
|
|
452
|
+
});
|
|
453
|
+
modelTabs.replaceChildren(...buttons);
|
|
454
|
+
if (focusedKey) buttons.find((button) => button.dataset.modelTabKey === focusedKey)?.focus({ preventScroll: true });
|
|
455
|
+
// A PANEL tab: the editor draws it in the frame; this side only shows the slot and says which tab.
|
|
456
|
+
const panel = isPanelTab(state.tab) ? state.tab : null;
|
|
457
|
+
modelIndexHeader.hidden = !!panel && !followsTab(panel); modelContent.hidden = !!panel; panelSlot.hidden = !panel;
|
|
458
|
+
if (panel) {
|
|
459
|
+
if (followsTab(panel)) modelIndexLabel.textContent = tabs.find((tab) => tab.key === panel).label;
|
|
460
|
+
panelSlot.setAttribute('aria-labelledby', `left-model-tab-${panel}`);
|
|
461
|
+
panelFrame.setAttribute('title', `${tabs.find((tab) => tab.key === panel).label} panel`); // verify-no-title: allow — an iframe's accessible name, the one title= this app allows
|
|
462
|
+
}
|
|
463
|
+
if (followTip) followTip.dataset.tip = panel ? 'Mark the rows that hold what is selected, and scroll to them' : LIST_FOLLOW_TIP;
|
|
464
|
+
if (panel !== panelShown) {
|
|
465
|
+
const requestId = sendAction({ action: 'panel', tab: panel, person: chosenByPerson, follow: !!panel && followsTab(panel) && state.followSelection });
|
|
466
|
+
if (requestId) { panelShown = panel; pendingActions.set(requestId, { kind: 'panel', key: panel }); }
|
|
467
|
+
}
|
|
468
|
+
if (panel) return;
|
|
469
|
+
modelContent.setAttribute('aria-labelledby', `left-model-tab-${state.tab}`);
|
|
470
|
+
const focusedCommand = modelContent.contains(document.activeElement)
|
|
471
|
+
? document.activeElement?.closest?.('[data-command-id]')?.getAttribute('data-command-id') : null;
|
|
472
|
+
const body = Array.isArray(snapshot.bodies?.[state.tab]) ? snapshot.bodies[state.tab] : [];
|
|
473
|
+
const headingIndex = body.findIndex((node) => node?.kind === 'label');
|
|
474
|
+
modelIndexLabel.textContent = headingIndex >= 0 ? body[headingIndex].label : `Browse by ${tabs.find((tab) => tab.key === state.tab)?.label?.toLowerCase() || 'model'}`;
|
|
475
|
+
renderNodes(headingIndex >= 0 ? body.filter((_node, index) => index !== headingIndex) : body, modelContent);
|
|
476
|
+
if (focusedCommand) [...modelContent.querySelectorAll('[data-command-id]')]
|
|
477
|
+
.find((item) => item.getAttribute('data-command-id') === focusedCommand)?.focus({ preventScroll: true });
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function send(message) {
|
|
481
|
+
if (!modelFrame().contentWindow || !modelVisible()) return false;
|
|
482
|
+
modelFrame().contentWindow.postMessage({ channel: CHANNEL, version: VERSION, generation: state.generation, ...message }, location.origin);
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
function selectedIdsOf(source) {
|
|
486
|
+
return Array.isArray(source?.selectedIds) ? source.selectedIds.filter((id) => typeof id === 'string')
|
|
487
|
+
: (typeof source?.selectedId === 'string' ? [source.selectedId] : []);
|
|
488
|
+
}
|
|
489
|
+
// A list row click, as in a file explorer: Ctrl (⌘) adds or removes the row, Shift takes every row from the last one
|
|
490
|
+
// clicked to this one in the order shown (rows in closed groups are skipped), and Ctrl+Shift adds that range. The
|
|
491
|
+
// main window works out the ids because it draws the rows; the editor selects them.
|
|
492
|
+
function selectRow(id, event) {
|
|
493
|
+
const current = pendingSelectIds ?? selectedIdsOf(state.snapshot), add = event.ctrlKey || event.metaKey;
|
|
494
|
+
let ids;
|
|
495
|
+
if (event.shiftKey && selectAnchor) {
|
|
496
|
+
const order = [...new Set([...modelContent.querySelectorAll('[data-entity-id]')]
|
|
497
|
+
.filter((row) => !row.closest('[hidden]')).map((row) => row.dataset.entityId))];
|
|
498
|
+
const from = order.indexOf(selectAnchor), to = order.indexOf(id);
|
|
499
|
+
if (from < 0) selectAnchor = id; // the anchor is no longer shown (closed, or another tab): this row starts the next range
|
|
500
|
+
const range = from < 0 || to < 0 ? [id] : order.slice(Math.min(from, to), Math.max(from, to) + 1);
|
|
501
|
+
ids = add ? [...new Set([...current, ...range])] : range;
|
|
502
|
+
} else {
|
|
503
|
+
ids = !add ? [id] : current.includes(id) ? current.filter((other) => other !== id) : [...current, id];
|
|
504
|
+
selectAnchor = id;
|
|
505
|
+
}
|
|
506
|
+
if (sendAction({ action: 'select', entityId: id, entityIds: ids })) pendingSelectIds = ids;
|
|
507
|
+
}
|
|
508
|
+
function sendAction(action) {
|
|
509
|
+
const requestId = `${state.generation}:${++nextActionId}`;
|
|
510
|
+
return send({ type: 'action', requestId, ...action }) ? requestId : null;
|
|
511
|
+
}
|
|
512
|
+
function hello() { if (modelVisible()) send({ type: 'hello' }); }
|
|
513
|
+
window.addEventListener('message', (event) => {
|
|
514
|
+
const data = event.data;
|
|
515
|
+
if (event.source !== modelFrame().contentWindow || event.origin !== location.origin || data?.channel !== CHANNEL || data.version !== VERSION) return;
|
|
516
|
+
if (data.type === 'available') { hello(); return; }
|
|
517
|
+
if (!modelVisible() || data.generation !== state.generation) return;
|
|
518
|
+
if (!Number.isInteger(data.revision) || data.revision <= state.revision) return;
|
|
519
|
+
if (data.type === 'status') {
|
|
520
|
+
state.revision = data.revision;
|
|
521
|
+
if (data.state === 'failed') {
|
|
522
|
+
state.modelAvailable = false; state.snapshot = null; state.datasetKey = null;
|
|
523
|
+
pendingActions.clear(); resetPanelFrame(); reflect();
|
|
524
|
+
}
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (data.type === 'action-result') {
|
|
528
|
+
state.revision = data.revision;
|
|
529
|
+
const pending = pendingActions.get(data.requestId); pendingActions.delete(data.requestId);
|
|
530
|
+
if (pending?.row?.isConnected) pending.row.removeAttribute('aria-busy');
|
|
531
|
+
if (pending?.kind === 'expand') {
|
|
532
|
+
const currentRow = [...modelContent.querySelectorAll('[data-command-id]')]
|
|
533
|
+
.find((row) => row.dataset.commandId === pending.commandId);
|
|
534
|
+
currentRow?.removeAttribute('aria-busy');
|
|
535
|
+
if (data.ok) {
|
|
536
|
+
groupDisclosure.set(pending.disclosureKey, true);
|
|
537
|
+
currentRow?.setAttribute('aria-expanded', 'true');
|
|
538
|
+
const currentChildren = currentRow?.closest('.left-model-branch')?.querySelector(':scope > .left-model-children');
|
|
539
|
+
if (currentChildren) currentChildren.hidden = false;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (!data.ok) status.textContent = data.message || 'That model action is no longer available.';
|
|
543
|
+
// The frame stays empty, so say so where the tab would be — for the tab still shown, not an earlier one.
|
|
544
|
+
if (pending?.kind === 'panel' && !data.ok && pending.key === panelShown) {
|
|
545
|
+
panelShown = null;
|
|
546
|
+
if (isPanelTab(state.tab)) {
|
|
547
|
+
const note = document.createElement('div'); note.className = 'left-model-empty'; note.textContent = status.textContent;
|
|
548
|
+
panelSlot.hidden = true; modelContent.hidden = false; modelContent.replaceChildren(note);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
// The editor asks for one of its tabs to be shown — what a toolbar button that opens a tab does.
|
|
554
|
+
if (data.type === 'reveal') {
|
|
555
|
+
state.revision = data.revision;
|
|
556
|
+
const tabs = [...(Array.isArray(state.snapshot?.tabs) ? state.snapshot.tabs : []), ...panelTabsOf(state.snapshot)];
|
|
557
|
+
if (!tabs.some((tab) => tab.key === data.tab)) return;
|
|
558
|
+
state.tab = data.tab; displacedTab = null; save();
|
|
559
|
+
if (!shown('model')) sessionVisible.model = true;
|
|
560
|
+
reflect(); renderModel();
|
|
561
|
+
if (document.getElementById('app')?.classList.contains('left-collapsed')) document.querySelector('.pane-rail-left .panel-toggle[data-side="left"]')?.click();
|
|
562
|
+
status.textContent = `${tabs.find((tab) => tab.key === data.tab).label} shown in the Model panel.`;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (data.type === 'selection') {
|
|
566
|
+
state.revision = data.revision;
|
|
567
|
+
if (state.snapshot) {
|
|
568
|
+
state.snapshot.selectedId = typeof data.selectedId === 'string' ? data.selectedId : null;
|
|
569
|
+
state.snapshot.selectedIds = Array.isArray(data.selectedIds) ? data.selectedIds.filter((id) => typeof id === 'string') : (state.snapshot.selectedId ? [state.snapshot.selectedId] : []);
|
|
570
|
+
state.snapshot.selectionOrigin = data.selectionOrigin || 'tree';
|
|
571
|
+
}
|
|
572
|
+
pendingSelectIds = null;
|
|
573
|
+
const picked = selectedIdsOf(data);
|
|
574
|
+
modelContent.querySelectorAll('[data-entity-id]').forEach((row) => {
|
|
575
|
+
row.classList.toggle('selected', picked.includes(row.dataset.entityId));
|
|
576
|
+
if (row.dataset.entityId === data.selectedId) row.setAttribute('aria-current', 'true'); else row.removeAttribute('aria-current');
|
|
577
|
+
});
|
|
578
|
+
if (state.followSelection && state.snapshot?.selectedIds?.length === 1) { renderModel(); revealSelectedEntity(); }
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (data.type !== 'snapshot') return;
|
|
582
|
+
state.revision = data.revision; state.snapshot = data.snapshot; state.modelAvailable = true;
|
|
583
|
+
if (state.datasetKey !== data.snapshot.datasetKey) state.datasetKey = data.snapshot.datasetKey || null;
|
|
584
|
+
modelContext.textContent = data.snapshot.context || 'Project model';
|
|
585
|
+
reflect(); renderModel(); revealSelectedEntity();
|
|
586
|
+
});
|
|
587
|
+
// Everything the departing editor told us goes, and its controls leave with the panel frame.
|
|
588
|
+
function forgetModel() {
|
|
589
|
+
state.generation++; state.revision = -1; state.snapshot = null; state.datasetKey = null; state.modelAvailable = false;
|
|
590
|
+
revealSequence++; pendingRevealId = null; pendingActions.clear(); resetPanelFrame(); reflect();
|
|
591
|
+
}
|
|
592
|
+
// A model frame loaded another document. Forgotten at once when the old one unloads — an editor reloads itself
|
|
593
|
+
// whenever the AI edits the model, and its moved controls would otherwise sit dead until the new page loads.
|
|
594
|
+
// A document that loads behind Edit contract registers too: Close hands the section back to it.
|
|
595
|
+
function onModelFrameLoad(event) {
|
|
596
|
+
const loaded = event.currentTarget;
|
|
597
|
+
try { loaded.contentWindow.addEventListener('pagehide', () => { if (loaded === modelFrame()) forgetModel(); }, { once: true }); }
|
|
598
|
+
catch { /* not this origin (about:blank while closing): the next load forgets it */ }
|
|
599
|
+
if (loaded !== modelFrame()) return;
|
|
600
|
+
forgetModel(); hello();
|
|
601
|
+
}
|
|
602
|
+
frame.addEventListener('load', onModelFrameLoad);
|
|
603
|
+
|
|
604
|
+
window.flolessLeftPane = Object.freeze({
|
|
605
|
+
showSection(key) {
|
|
606
|
+
if (!available(key)) return false;
|
|
607
|
+
const changed = !shown(key); sessionVisible[key] = true; reflect(); return changed;
|
|
608
|
+
},
|
|
609
|
+
setWorkspaceModelVisible(visible) {
|
|
610
|
+
if (overlayFrame) { state.workspaceModelVisible = !!visible; return; } // the overlay's editor has the section until it closes
|
|
611
|
+
if (!visible && state.workspaceModelVisible) send({ type: 'release' });
|
|
612
|
+
if (!!visible !== state.workspaceModelVisible) state.generation++;
|
|
613
|
+
state.workspaceModelVisible = !!visible;
|
|
614
|
+
if (visible) hello();
|
|
615
|
+
else { sessionVisible.model = false; state.modelAvailable = false; state.snapshot = null; state.datasetKey = null; state.revision = -1; revealSequence++; pendingRevealId = null; pendingActions.clear(); resetPanelFrame(); reflect(); }
|
|
616
|
+
},
|
|
617
|
+
// The model frame is being replaced (another project, or a reload from server truth). A new
|
|
618
|
+
// generation disowns everything the departing editor sends; the next document's load says hello.
|
|
619
|
+
resetWorkspaceModel() {
|
|
620
|
+
if (state.workspaceModelVisible && !overlayFrame) send({ type: 'release' });
|
|
621
|
+
if (!overlayFrame) forgetModel();
|
|
622
|
+
},
|
|
623
|
+
// A model editor opened full-window over the main window (Workflows → Edit contract) gets the Model section
|
|
624
|
+
// while it is open — the same tabs by the same code as in Workspaces; null gives it back to the workspace.
|
|
625
|
+
useOverlayModelFrame(next) {
|
|
626
|
+
next = next || null;
|
|
627
|
+
if (next === overlayFrame) return;
|
|
628
|
+
if (modelVisible()) send({ type: 'release' });
|
|
629
|
+
if (next && !next.dataset.leftPaneBound) { next.dataset.leftPaneBound = 'true'; next.addEventListener('load', onModelFrameLoad); }
|
|
630
|
+
overlayFrame = next;
|
|
631
|
+
if (!next) sessionVisible.model = false;
|
|
632
|
+
forgetModel(); hello();
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
arrange(); reflect();
|
|
636
|
+
})();
|