@floless/app 0.150.0 → 0.152.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,197 @@
1
+ /* Saved-directory declarations change registration, never the folder's contents. */
2
+ (() => {
3
+ const modal = document.getElementById('workspace-root-modal');
4
+ if (!modal) return;
5
+ const instructorNote = document.getElementById('workspace-root-instructor-note');
6
+ window.flolessWorkspaceRootInstructorExplain = (guidance) => {
7
+ if (!instructorNote || !modal.classList.contains('show') || !Array.isArray(guidance?.parts)) return;
8
+ const chip = document.createElement('span'); chip.className = 'ix-chip'; chip.textContent = guidance.chip || '';
9
+ const parts = document.createElement('div'); parts.className = 'workspace-root-instructor-parts';
10
+ guidance.parts.forEach((part, index) => {
11
+ if (index) parts.append(document.createTextNode(' · '));
12
+ const segment = document.createElement('span'); segment.textContent = part; parts.append(segment);
13
+ });
14
+ instructorNote.replaceChildren(chip, parts); instructorNote.dataset.commandId = guidance.commandId || ''; instructorNote.hidden = false;
15
+ };
16
+ window.flolessWorkspaceRootInstructorClear = () => {
17
+ if (!instructorNote) return;
18
+ instructorNote.hidden = true; instructorNote.replaceChildren(); delete instructorNote.dataset.commandId;
19
+ };
20
+ const mount = document.createElement('section');
21
+ mount.className = 'workspace-root-management'; mount.tabIndex = -1;
22
+ modal.querySelector('#workspace-root-status').after(mount);
23
+ const heading = document.createElement('h3'); heading.textContent = 'Saved directories';
24
+ const status = document.createElement('div'); status.className = 'workspace-root-management-message'; status.setAttribute('role', 'status'); status.setAttribute('aria-live', 'polite');
25
+ const alert = document.createElement('div'); alert.className = 'workspace-root-error'; alert.setAttribute('role', 'alert');
26
+ const content = document.createElement('div'); mount.append(heading, status, alert, content);
27
+ const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
28
+ let data = null, step = null, busy = false, message = '', problem = '', request = 0, reviewRequest = 0;
29
+ let sessionReady = null;
30
+ const existing = ['workspace-root-cancel', 'workspace-root-change', 'workspace-root-use'].map((id) => document.getElementById(id));
31
+ const disabledBefore = new Map();
32
+ const carriers = {
33
+ 'shell.workspace-root-stop-using': (row) => `data-command-id="shell.workspace-root-stop-using#${esc(row.rootId)}" data-command-instance-label="${esc(row.path)}"`,
34
+ 'shell.workspace-root-destination': (row) => `data-command-id="shell.workspace-root-destination#${esc(row.rootId)}" data-command-instance-label="${esc(row.path)}"`,
35
+ 'shell.workspace-root-choose-destination': 'data-command-id="shell.workspace-root-choose-destination"',
36
+ 'shell.workspace-root-confirm-retirement': (row) => `data-command-id="shell.workspace-root-confirm-retirement#${esc(row.rootId)}" data-command-instance-label="${esc(row.path)}"`,
37
+ 'shell.workspace-root-restore-registration': (row) => `data-command-id="shell.workspace-root-restore-registration#${esc(row.rootId)}" data-command-instance-label="${esc(row.path)}"`,
38
+ 'shell.workspace-root-confirm-restoration': (row) => `data-command-id="shell.workspace-root-confirm-restoration#${esc(row.rootId)}" data-command-instance-label="${esc(row.path)}"`,
39
+ 'shell.dialog-cancel#the directory registration': 'data-command-id="shell.dialog-cancel#the directory registration"',
40
+ };
41
+ async function api(path, body) {
42
+ if (!sessionReady) sessionReady = (async () => {
43
+ // Bootstrap once for this dialog. Renewing a cookie between review and recording
44
+ // would change the local decision's session identity.
45
+ const response = await fetch('/api/editor/session', { method: 'POST', credentials: 'same-origin' });
46
+ const result = await response.json().catch(() => null);
47
+ if (!response.ok && !(response.status === 403 && result?.error === 'editor_session_unavailable')) {
48
+ throw new Error('The local browser session could not be opened. Close this dialog and open it again.');
49
+ }
50
+ })();
51
+ await sessionReady;
52
+ const response = await fetch(path, { credentials: 'same-origin', headers: { 'content-type': 'application/json' },
53
+ ...(body === undefined ? {} : { method: 'POST', body: JSON.stringify(body) }) });
54
+ const result = await response.json();
55
+ if (!response.ok || result.ok === false) throw new Error(result.error || 'FloLess could not review this directory. Try again.');
56
+ return result;
57
+ }
58
+ function button(action, text, command, attrs = '', row = null) {
59
+ return `<button type="button" data-registration-action="${esc(action)}" ${typeof carriers[command] === 'function' ? carriers[command](row) : carriers[command]} ${attrs}${busy ? ' disabled data-blocked-reason="The directory choice is being recorded."' : ''}>${text}</button>`;
60
+ }
61
+ function render() {
62
+ const focused = document.activeElement?.closest('[data-registration-action]');
63
+ const focusKey = focused && content.contains(focused) ? { action: focused.dataset.registrationAction, rootId: focused.dataset.rootId } : null;
64
+ modal.classList.toggle('workspace-root-management-reviewing', !!step);
65
+ status.textContent = message; status.hidden = !message;
66
+ alert.textContent = problem; alert.hidden = !problem;
67
+ let html = '';
68
+ if (!data) html += '<p class="workspace-root-management-note">Checking saved directories…</p>';
69
+ else if (!step) {
70
+ html += '<div class="workspace-root-management-list">';
71
+ for (const row of data.roots) {
72
+ const different = !row.observation.available && row.observation.filesystemId && row.observation.markerId;
73
+ const state = row.retirement ? `Stopped · ${new Date(row.retirement.at).toLocaleDateString()}`
74
+ : row.rootId === data.activeRootId ? `In use${row.observation.available ? '' : ' · Unavailable'}`
75
+ : row.observation.available ? 'Available' : different ? 'Different folder at this path' : 'Unavailable';
76
+ html += `<div class="workspace-root-management-row"><div><code data-tip="${esc(row.path)}">${esc(row.path)}</code>` +
77
+ `<span class="workspace-root-management-state${!row.observation.available ? ' is-unavailable' : ''}">${esc(state)}</span></div>`;
78
+ if (row.retirement && row.observation.available) html += button('restore', 'Restore…', 'shell.workspace-root-restore-registration', `data-root-id="${esc(row.rootId)}" `, row);
79
+ else if (!row.retirement && !row.observation.available) html += button('retire', 'Stop using…', 'shell.workspace-root-stop-using', `data-root-id="${esc(row.rootId)}" `, row);
80
+ html += '</div>';
81
+ }
82
+ html += '</div><p class="workspace-root-management-note">Stopped directories keep their place reserved. FloLess does not look inside them for projects until you restore their registration.</p>';
83
+ } else {
84
+ html += `<h4>${step.action === 'restore' ? 'Restore this directory and switch?' : 'Stop using this directory?'}</h4>` +
85
+ `<code class="workspace-root-management-target" data-tip="${esc(step.row.path)}">${esc(step.row.path)}</code>` +
86
+ `<p class="workspace-root-management-note">${step.action === 'restore'
87
+ ? 'FloLess will verify the original folder, resume looking inside it for projects, and switch to it. Your files stay where they are, and the current directory stays registered.'
88
+ : 'Your files stay where they are. While stopped, FloLess will not look inside this directory for projects. Its place stays reserved. If the original folder comes back, you can restore its registration. If the Revit or Tekla Parser uses an approved model from a project in this directory, its next setup can leave that model out. Choose Cancel to keep this directory as it is.'}</p>`;
89
+ if (step.action === 'retire' && step.row.rootId === data.activeRootId) {
90
+ html += '<p class="workspace-root-management-note">Switch to:</p><div class="workspace-root-management-destinations">';
91
+ for (const row of data.roots.filter((row) => row.rootId !== step.row.rootId && !row.retirement && row.observation.available)) {
92
+ html += button('destination', `<code>${esc(row.path)}</code>`, 'shell.workspace-root-destination',
93
+ `class="workspace-root-management-choice" data-root-id="${esc(row.rootId)}" aria-pressed="${step.destinationRootId === row.rootId}" data-tip="${esc(row.path)}" `, row);
94
+ }
95
+ html += button('choose', 'Choose another folder…', 'shell.workspace-root-choose-destination') + '</div>';
96
+ if (step.destinationPath) html += `<p class="workspace-root-management-note">Selected: <code>${esc(step.destinationPath)}</code></p>`;
97
+ }
98
+ const label = step.action === 'restore' ? 'Restore and switch' : step.row.rootId === data.activeRootId ? 'Stop using it and switch' : 'Stop using this directory';
99
+ html += '<div class="workspace-root-management-actions modal-actions">' + button('back', 'Cancel', 'shell.dialog-cancel#the directory registration') +
100
+ (step.failed && (step.action === 'restore' || step.row.rootId !== data.activeRootId)
101
+ ? button(step.action, 'Review again', step.action === 'restore' ? 'shell.workspace-root-restore-registration' : 'shell.workspace-root-stop-using', `data-root-id="${esc(step.row.rootId)}" data-review-again `, step.row) : '') +
102
+ button('confirm', label, step.action === 'restore' ? 'shell.workspace-root-confirm-restoration' : 'shell.workspace-root-confirm-retirement',
103
+ `${step.action === 'restore' ? 'class="primary" ' : 'class="danger" '}${!step.previewId && !busy ? `disabled data-blocked-reason="${step.checking ? 'FloLess is checking this directory.' : step.failed && (step.action === 'restore' || step.row.rootId !== data.activeRootId) ? 'Choose Review again first.' : 'Choose where to switch first.'}" ` : ''}`, step.row) + '</div>';
104
+ }
105
+ content.innerHTML = html;
106
+ if (focusKey) [...content.querySelectorAll('[data-registration-action]')].find((control) => control.dataset.registrationAction === focusKey.action && control.dataset.rootId === focusKey.rootId)?.focus();
107
+ const carrier = document.activeElement?.closest('[data-command-id]');
108
+ if (carrier && modal.contains(carrier)) window.Instructor?.refreshCarrier(carrier);
109
+ }
110
+ async function refresh() {
111
+ const generation = ++request;
112
+ try { const result = await api('/api/workspace-root/registrations'); if (generation !== request) return; data = result; render(); }
113
+ catch (error) { if (generation !== request) return; problem = error.message; render(); }
114
+ }
115
+ function setBusy(value) {
116
+ busy = value;
117
+ if (value) {
118
+ mount.focus(); mount.setAttribute('aria-busy', 'true');
119
+ for (const control of existing) { disabledBefore.set(control, control.disabled); control.disabled = true; control.setAttribute('data-blocked-reason', 'The directory choice is being recorded.'); }
120
+ } else {
121
+ for (const control of existing) { control.disabled = disabledBefore.get(control) ?? control.disabled; control.removeAttribute('data-blocked-reason'); }
122
+ disabledBefore.clear(); mount.removeAttribute('aria-busy');
123
+ }
124
+ render();
125
+ }
126
+ function back() {
127
+ if (busy) return;
128
+ const rootId = step?.row.rootId;
129
+ step = null; message = ''; problem = ''; render(); mount.querySelector(`[data-root-id="${rootId}"]`)?.focus();
130
+ }
131
+ async function review(extra = {}) {
132
+ const current = step, generation = ++reviewRequest;
133
+ current.previewId = null; current.destinationRootId = undefined; current.destinationPath = undefined; current.checking = true; current.failed = false; render();
134
+ let result;
135
+ try { result = await api('/api/workspace-root/retirement-preview', { rootId: current.row.rootId, action: current.action, ...extra }); }
136
+ catch (error) { if (step !== current || generation !== reviewRequest) return; current.checking = false; throw error; }
137
+ if (step !== current || generation !== reviewRequest) return;
138
+ step.checking = false; step.previewId = result.previewId; step.destinationPath = result.preview?.destinationPath; step.destinationRootId = extra.destinationRootId;
139
+ render(); mount.querySelector('[data-registration-action="back"]')?.focus();
140
+ }
141
+ mount.addEventListener('click', async (event) => {
142
+ const control = event.target.closest('[data-registration-action]');
143
+ if (!control || busy) return;
144
+ const action = control.dataset.registrationAction; message = ''; problem = '';
145
+ try {
146
+ if (action === 'back') return back();
147
+ if (action === 'retire' || action === 'restore') {
148
+ step = { action, row: data.roots.find((row) => row.rootId === control.dataset.rootId) };
149
+ render(); mount.querySelector('[data-registration-action="back"]')?.focus();
150
+ if (action === 'restore' || step.row.rootId !== data.activeRootId) await review();
151
+ } else if (action === 'destination') await review({ destinationRootId: control.dataset.rootId });
152
+ else if (action === 'choose') {
153
+ const current = step, generation = ++reviewRequest;
154
+ current.previewId = null; current.destinationRootId = undefined; current.destinationPath = undefined; render();
155
+ const native = await api('/api/workspace-root/choose', {});
156
+ if (step !== current || generation !== reviewRequest || native.cancelled) return;
157
+ if (!native.selectionId) throw new Error('Choose a different working directory to switch to.');
158
+ await review({ selectionId: native.selectionId });
159
+ } else if (action === 'confirm' && step?.previewId) {
160
+ setBusy(true);
161
+ const result = await api('/api/workspace-root/retirement-confirm', { previewId: step.previewId });
162
+ step = null;
163
+ message = `Your choice was recorded from this FloLess window at ${new Date(result.recordedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}.`;
164
+ await window.flolessWorkspaceRoot?.refresh(); await refresh();
165
+ }
166
+ } catch (error) { problem = error.message; if (step) { step.previewId = null; step.failed = true; step.checking = false; } }
167
+ finally {
168
+ if (busy) setBusy(false); else render();
169
+ if (problem && step) {
170
+ (['destination', 'choose'].includes(action) ? mount.querySelector('[data-registration-action="choose"]') : mount.querySelector('[data-review-again]') || mount.querySelector('[data-registration-action="back"]'))?.focus();
171
+ } else if (action === 'confirm' && !step) existing[0]?.focus();
172
+ const carrier = document.activeElement?.closest('[data-command-id]');
173
+ if (carrier && modal.contains(carrier)) window.Instructor?.refreshCarrier(carrier);
174
+ }
175
+ });
176
+ modal.addEventListener('click', (event) => {
177
+ if (busy && (event.target === modal || existing.some((control) => control.contains(event.target)))) { event.preventDefault(); event.stopImmediatePropagation(); }
178
+ else if (step && (event.target === modal || event.target === existing[0])) { event.preventDefault(); event.stopImmediatePropagation(); back(); }
179
+ }, true);
180
+ document.addEventListener('keydown', (event) => {
181
+ if (!modal.classList.contains('show') || event.key !== 'Escape' || (!step && !busy)) return;
182
+ event.preventDefault(); event.stopImmediatePropagation(); if (!busy) back();
183
+ }, true);
184
+ let shown = modal.classList.contains('show');
185
+ new MutationObserver(() => {
186
+ const open = modal.classList.contains('show');
187
+ if (open && !shown) { sessionReady = null; step = null; message = ''; problem = ''; void refresh(); }
188
+ if (!open && shown) {
189
+ if (instructorNote && !instructorNote.hidden) window.Instructor?.clear();
190
+ window.flolessWorkspaceRootInstructorClear();
191
+ }
192
+ shown = open;
193
+ })
194
+ .observe(modal, { attributes: true, attributeFilter: ['class'] });
195
+ window.addEventListener('floless:workspace-root-state', () => { if (shown && !busy) void refresh(); });
196
+ render();
197
+ })();