@floless/app 0.158.0 → 0.159.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/floless-server.cjs +92620 -75445
  2. package/dist/schemas/drawing-check.profile.v1.schema.json +33 -1
  3. package/dist/skills/floless-app-actions/SKILL.md +23 -5
  4. package/dist/skills/floless-app-bridge/SKILL.md +5 -3
  5. package/dist/skills/floless-app-onboarding/SKILL.md +67 -4
  6. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +7 -4
  7. package/dist/skills/floless-app-queue/SKILL.md +3 -1
  8. package/dist/skills/floless-app-steel-model/SKILL.md +11 -5
  9. package/dist/skills/floless-app-steel-takeoff/SKILL.md +28 -8
  10. package/dist/skills/floless-app-workflows/SKILL.md +6 -3
  11. package/dist/web/agents.js +12 -5
  12. package/dist/web/app.css +87 -13
  13. package/dist/web/app.js +6 -0
  14. package/dist/web/aware.js +29 -4
  15. package/dist/web/chat.css +42 -22
  16. package/dist/web/chat.js +181 -30
  17. package/dist/web/commands-shell.js +305 -4
  18. package/dist/web/commands-steel.js +1 -0
  19. package/dist/web/drawing-check-editor.html +10 -0
  20. package/dist/web/drawing-check-editor.js +44 -0
  21. package/dist/web/guide.js +4 -2
  22. package/dist/web/index.html +41 -9
  23. package/dist/web/instructor.js +20 -8
  24. package/dist/web/pages.js +71 -13
  25. package/dist/web/project-access.js +67 -8
  26. package/dist/web/project-modules.js +474 -0
  27. package/dist/web/project-workflows.js +274 -0
  28. package/dist/web/steel-3d-core.js +46 -0
  29. package/dist/web/steel-3d-view.js +8 -38
  30. package/dist/web/steel-editor.html +192 -49
  31. package/dist/web/workspace-root-recovery.js +119 -0
  32. package/dist/web/workspaces.js +358 -114
  33. package/launch-starting-page.mjs +5 -2
  34. package/launch.mjs +136 -78
  35. package/package.json +5 -1
@@ -0,0 +1,474 @@
1
+ /*
2
+ * A General project's Modules step (#2470 R6.7): the module projects linked to it — a Revit model, a steel model from
3
+ * drawings, a Drawing Checker profile… — with Add a module… (the landing's own create cards, each running its own flow,
4
+ * then linked here) and Link an existing project…. A link is a pointer: it opens the other project's own page, with all
5
+ * of that project's own checks, and gives this project nothing.
6
+ *
7
+ * It renders what GET /api/projects/:id/links answers and changes links only through POST/DELETE on the same route.
8
+ * Creating runs the landing's own create flow (window.flolessWorkspaces.activateCreateCard). Spec:
9
+ * docs/superpowers/specs/2026-10-22-2470-r6-7-add-module-PLAN.md.
10
+ */
11
+ (() => {
12
+ const bridge = () => window.flolessBridge || {};
13
+ const ws = () => window.flolessWorkspaces || {};
14
+ const api = (path, init) => {
15
+ if (typeof bridge().api === 'function') return bridge().api(path, init);
16
+ return fetch(path, { headers: { 'Content-Type': 'application/json' }, ...init }).then(async (res) => {
17
+ const body = await res.json().catch(() => ({}));
18
+ if (!res.ok || body.ok === false) { const err = new Error(body.error || `HTTP ${res.status}`); err.status = res.status; err.body = body; throw err; }
19
+ return body;
20
+ });
21
+ };
22
+ const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
23
+ const toast = (msg, kind, options) => (typeof window.showToast === 'function' ? window.showToast(msg, kind, options) : null);
24
+ // A sentence the server wrote for the person is shown as written; anything else gets the fixed line.
25
+ const said = (error, fallback) => (typeof error?.body?.error === 'string' && error.body.error ? error.body.error
26
+ : !error?.status && typeof error?.message === 'string' && /^FloLess /.test(error.message) ? error.message : fallback);
27
+
28
+ /** The module names a person knows, by template id (LINKABLE_APPS on the server). */
29
+ const MODULE_NAMES = {
30
+ 'steel-model': 'Steel model', vectorize: 'Trace', 'revit-model': 'Revit Parser', 'tekla-parser': 'Tekla Parser', 'drawing-check': 'Drawing Checker',
31
+ };
32
+ const moduleName = (templateId) => MODULE_NAMES[templateId] || 'Module project';
33
+ const newOperationId = () => `${String(Date.now()).padStart(13, '0')}-${crypto.randomUUID()}`;
34
+
35
+ // ── the step ───────────────────────────────────────────────────────────────────────────────────────────────────
36
+
37
+ /** The meta line and actions of one link, by its state. Rows that cannot open have no open button. */
38
+ function rowHtml(link) {
39
+ const name = link.target?.name || link.name || 'A project';
40
+ const module = moduleName(link.target?.templateId || link.app);
41
+ const unlink = `<button type="button" class="ghost pm-unlink" data-pm-unlink="${esc(link.projectUuid)}" data-pm-name="${esc(name)}"
42
+ data-command-id="shell.project-module-unlink#${esc(link.projectUuid)}" data-command-instance-label="${esc(name)}"
43
+ aria-label="Remove link to ${esc(name)}" data-tip="Removes this link only. Neither project is changed.">✕</button>`;
44
+ if (link.state === 'live') {
45
+ const reads = link.target.readsApprovedModel ? ' · Workflows here can read its approved model' : '';
46
+ return `<div class="pg-row pm-row" role="listitem">
47
+ <button type="button" class="pm-row-open" data-pm-open="${esc(link.target.id)}" data-command-id="shell.project-module-open#${esc(link.projectUuid)}"
48
+ data-command-instance-label="${esc(name)}" data-tip="Opens this project’s own page">
49
+ <span class="pg-row-line"><span class="pg-row-title">${esc(name)}</span></span>
50
+ <span class="pg-row-meta">${esc(module)}${esc(reads)}</span>
51
+ </button>${unlink}</div>`;
52
+ }
53
+ const states = {
54
+ archived: { chip: 'Archived', meta: 'Archived. Restore it to use it again.',
55
+ action: `<button type="button" class="ghost pm-act" data-pm-restore="${esc(link.projectUuid)}" data-command-id="shell.project-module-restore#${esc(link.projectUuid)}"
56
+ data-command-instance-label="${esc(name)}" data-tip="Shows the archived projects on the Workspaces page, where you can restore it">Restore…</button>` },
57
+ unavailable: { chip: 'Unavailable', meta: link.reason || 'Its folder can’t be read just now.', action: '' },
58
+ missing: { chip: 'Not in this Workspace', meta: `Was ${module} project “${link.name || 'unnamed'}”`, action: 'find' },
59
+ 'needs-reconnect': { chip: 'Needs reconnecting', meta: `From the imported file: ${module} project “${link.name || 'unnamed'}”`, action: 'find' },
60
+ 'not-available': { chip: 'Not available on this account', meta: `A ${module} project. Its module isn’t in this account’s plan.`, action: '' },
61
+ };
62
+ const st = states[link.state] || states.missing;
63
+ const action = st.action === 'find'
64
+ ? `<button type="button" class="ghost pm-act" data-pm-find="${esc(link.projectUuid)}" data-pm-app="${esc(link.app)}" data-pm-name="${esc(name)}"
65
+ data-command-id="shell.project-module-find#${esc(link.projectUuid)}" data-command-instance-label="${esc(name)}"
66
+ data-tip="Choose the project in this Workspace this link should point to">Find it…</button>`
67
+ : st.action;
68
+ return `<div class="pg-row pm-row is-off" role="listitem">
69
+ <div class="pm-row-info"><span class="pg-row-line"><span class="pg-row-title">${esc(name)}</span><span class="pw-chip is-muted">${esc(st.chip)}</span></span>
70
+ <span class="pg-row-meta">${esc(st.meta)}</span></div>${action}${unlink}</div>`;
71
+ }
72
+
73
+ function stripHtml(createdHere) {
74
+ if (!createdHere.length) return '';
75
+ const shown = createdHere.slice(0, 3);
76
+ const rows = shown.map((p) => {
77
+ const first = p.archived
78
+ ? `<button type="button" class="ghost" data-pm-restore-created="${esc(p.id)}" data-command-id="shell.project-module-created-restore#${esc(p.id)}"
79
+ data-command-instance-label="${esc(p.name)}" data-tip="Shows the archived projects on the Workspaces page, where you can restore it">Restore…</button>`
80
+ : `<button type="button" class="ghost" data-pm-link-created="${esc(p.uuid)}" data-command-id="shell.project-module-created-link#${esc(p.id)}"
81
+ data-command-instance-label="${esc(p.name)}" data-tip="Lists it in this project’s modules">Link it</button>`;
82
+ return `<div class="pm-strip-row"><span>“${esc(p.name)}” was created from this project ${p.archived ? 'and is archived.' : 'but isn’t linked to it.'}</span>
83
+ <span class="pm-strip-acts">${first}<button type="button" class="ghost" data-pm-decline="${esc(p.uuid)}" data-pm-name="${esc(p.name)}"
84
+ data-command-id="shell.project-module-created-decline#${esc(p.id)}" data-command-instance-label="${esc(p.name)}"
85
+ data-tip="Keeps the project and stops asking. It is not deleted.">Don’t link</button></span></div>`;
86
+ }).join('');
87
+ const more = createdHere.length > shown.length ? `<p class="pm-strip-more">and ${createdHere.length - shown.length} more</p>` : '';
88
+ return `<div class="pg-empty pm-strip" role="group" aria-label="Created here, not linked">${rows}${more}</div>`;
89
+ }
90
+
91
+ /** The step's markup for one answer. `view`: { status: 'loading'|'ready'|'failed'|'gone'|'unavailable', data, error, busy }. */
92
+ function html(view) {
93
+ const ready = view.status === 'ready';
94
+ const buttons = ready ? `<span class="pm-head-acts">
95
+ <button type="button" class="ghost" data-pm-add="1" aria-haspopup="dialog" data-command-id="shell.project-modules-add"
96
+ data-tip="Create a project of a module beside this one and link it here">Add a module…</button>
97
+ <button type="button" class="ghost" data-pm-link-existing="1" aria-haspopup="dialog" data-command-id="shell.project-modules-link-existing"
98
+ data-tip="List a project you already have in this Workspace here">Link an existing project…</button></span>` : '';
99
+ const head = `<div class="step-head"><span tabindex="-1" data-pm-heading="1">Modules</span>${buttons}</div>
100
+ <p class="pg-sub">Other projects this one works with. Each keeps its own drawings, model and access.</p>`;
101
+ if (view.status === 'loading') return `${head}<p class="pg-loading-line">Loading this project’s modules…</p>`;
102
+ if (view.status === 'gone') {
103
+ return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">FloLess couldn’t find this project any more.</p>
104
+ <p>It may have been archived or removed. Go back to your projects to open it again.</p></div>`;
105
+ }
106
+ if (view.status === 'unavailable') {
107
+ return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">This project’s folder is unavailable.</p><p>${esc(view.error)}</p></div>`;
108
+ }
109
+ if (view.status === 'failed') {
110
+ return `${head}<div class="pg-empty pw-failed"><p class="pg-empty-title">FloLess couldn’t load this project’s modules.</p>
111
+ <p>${esc(view.error)}</p>
112
+ <p><button type="button" class="ghost" data-pm-retry="1" data-command-id="shell.project-modules-retry">Try again</button></p></div>`;
113
+ }
114
+ const data = view.data;
115
+ const list = data.links.length
116
+ ? `<div class="pg-list" role="list" aria-label="Projects linked to this one">${data.links.map(rowHtml).join('')}</div>`
117
+ : `<div class="pg-empty pm-empty"><p class="pg-empty-title">No modules yet</p>
118
+ <p>Add a Revit model, a steel model from drawings or a Drawing Checker profile, or link a project you already have.</p></div>`;
119
+ const dropped = data.dropped > 0
120
+ ? `<p class="pm-note">${data.dropped === 1 ? '1 link' : `${data.dropped} links`} in this project’s file couldn’t be read, so ${data.dropped === 1 ? 'it is' : 'they are'} not listed. ${data.dropped === 1 ? 'It is' : 'They are'} removed the next time this project’s modules change.</p>` : '';
121
+ return head + stripHtml(data.createdHere || []) + list + dropped;
122
+ }
123
+
124
+ // One pane, one project at a time: an answer for a project the person has left is dropped.
125
+ let state = null; // { pane, project, generation, view, inflight, again }
126
+ const ownChild = (pane, cls) => [...pane.children].find((el) => el.classList.contains(cls)) || null;
127
+ const announce = (text) => { const live = state && ownChild(state.pane, 'pm-live'); if (live) live.textContent = text; };
128
+
129
+ function paint(focusAfter) {
130
+ const { pane, view } = state;
131
+ const active = pane.contains(document.activeElement) && document.activeElement !== document.body ? document.activeElement : null;
132
+ const focused = focusAfter || (active?.hasAttribute('data-pm-heading') ? 'heading' : active?.getAttribute('data-command-id') ?? null);
133
+ let body = ownChild(pane, 'pm-body');
134
+ if (!body) {
135
+ pane.innerHTML = '<span class="sr-only pm-live" role="status" aria-live="polite"></span><div class="pm-body"></div>';
136
+ body = ownChild(pane, 'pm-body');
137
+ }
138
+ body.innerHTML = html(view);
139
+ if (!focused) return;
140
+ const again = focused === 'heading' ? null : [...body.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === focused);
141
+ (again || (focused === 'heading' || focused === 'shell.project-modules-retry' || focusAfter ? body.querySelector('[data-pm-heading]') : null))?.focus({ preventScroll: true });
142
+ }
143
+
144
+ async function load() {
145
+ if (!state) return;
146
+ if (state.inflight) { state.again = true; return; }
147
+ const mine = state;
148
+ const generation = mine.generation;
149
+ mine.inflight = true;
150
+ try {
151
+ const data = await api(`/api/projects/${encodeURIComponent(mine.project.id)}/links`);
152
+ if (state !== mine || mine.generation !== generation) return;
153
+ if (data.state === 'unavailable') {
154
+ mine.view = { status: 'unavailable', data: null, error: data.reason };
155
+ } else {
156
+ mine.view = { status: 'ready', data, error: null };
157
+ }
158
+ paint();
159
+ const n = data.links?.length || 0;
160
+ announce(data.state === 'unavailable' ? 'This project’s folder is unavailable.' : n === 0 ? 'No modules yet' : `${n} module${n === 1 ? '' : 's'} linked`);
161
+ } catch (error) {
162
+ if (state !== mine || mine.generation !== generation) return;
163
+ const gone = error?.status === 404;
164
+ mine.view = { status: gone ? 'gone' : 'failed', data: null,
165
+ error: gone ? null : said(error, 'FloLess couldn’t read this project’s modules just now. Check that FloLess is still running, then try again.') };
166
+ paint();
167
+ announce(gone ? 'FloLess couldn’t find this project any more.' : 'FloLess couldn’t load this project’s modules.');
168
+ } finally {
169
+ mine.inflight = false;
170
+ if (state === mine && mine.again) { mine.again = false; void load(); }
171
+ }
172
+ }
173
+
174
+ function render(pane, project) {
175
+ if (!pane || !project) return;
176
+ state = { pane, project, generation: (state?.generation || 0) + 1, view: { status: 'loading', data: null }, inflight: false, again: false };
177
+ paint();
178
+ void load();
179
+ }
180
+
181
+ const shown = (pane) => !pane.hidden && (typeof pane.checkVisibility === 'function' ? pane.checkVisibility() : pane.offsetParent !== null);
182
+ function refresh() { if (state && shown(state.pane)) void load(); }
183
+
184
+ /** Who the writes are for: the Workspace and the incarnation the page showed (the server re-checks both). */
185
+ const target = () => {
186
+ const d = state?.view?.data;
187
+ return d ? { rootId: d.rootId, sourceUuid: d.project.uuid, projectId: d.project.id, name: d.project.name } : null;
188
+ };
189
+
190
+ async function linkTo(projectUuid, { replaces, label } = {}) {
191
+ const t = target();
192
+ if (!t) return false;
193
+ try {
194
+ await api(`/api/projects/${encodeURIComponent(t.projectId)}/links`, { method: 'POST',
195
+ body: JSON.stringify({ rootId: t.rootId, sourceUuid: t.sourceUuid, projectUuid, ...(replaces ? { replaces } : {}) }) });
196
+ toast(`${label ? `“${label}”` : 'The project'} is linked.`, 'ok');
197
+ return true;
198
+ } catch (error) {
199
+ toast(said(error, 'FloLess couldn’t link that project just now. Try again.'), 'warn');
200
+ return false;
201
+ } finally { void load(); }
202
+ }
203
+
204
+ async function unlink(projectUuid, name, { decline = false } = {}) {
205
+ const t = target();
206
+ if (!t) return;
207
+ const q = new URLSearchParams({ rootId: t.rootId, sourceUuid: t.sourceUuid });
208
+ try {
209
+ await api(`/api/projects/${encodeURIComponent(t.projectId)}/links/${encodeURIComponent(projectUuid)}?${q}`, { method: 'DELETE' });
210
+ toast(decline ? `FloLess won’t ask about “${name}” again. The project is still there.` : `“${name}” is no longer listed here. The project itself is unchanged.`, 'ok');
211
+ } catch (error) {
212
+ toast(said(error, 'FloLess couldn’t remove that link just now. Try again.'), 'warn');
213
+ }
214
+ await load();
215
+ // Focus goes to the next row, else the heading.
216
+ state?.pane.querySelector('.pm-body .pm-row-open, .pm-body [data-pm-heading]')?.focus({ preventScroll: true });
217
+ }
218
+
219
+ // ── the sheets ─────────────────────────────────────────────────────────────────────────────────────────────────
220
+
221
+ const $sheet = document.getElementById('project-modules-sheet');
222
+ const $panel = $sheet?.querySelector('.pa-sheet');
223
+ const $title = document.getElementById('pm-title');
224
+ const $sub = document.getElementById('pm-sub');
225
+ const $body = document.getElementById('pm-body');
226
+ let sheet = null; // { mode: 'add'|'link'|'find', returnFocus, find: { uuid, app, name }, query, rows, truncated, timer }
227
+
228
+ const isOpen = () => !!$sheet?.classList.contains('show');
229
+
230
+ function openSheet(mode, returnFocus, find = null) {
231
+ if (!$sheet || !target()) return;
232
+ sheet = { mode, returnFocus: returnFocus || document.activeElement, find, query: '', rows: null, truncated: false };
233
+ $sheet.classList.toggle('pm-wide', mode === 'add');
234
+ paintSheet();
235
+ $sheet.classList.add('show');
236
+ requestAnimationFrame(() => $panel?.focus());
237
+ if (mode !== 'add') void loadLinkable();
238
+ }
239
+
240
+ function closeSheet({ restoreFocus = true } = {}) {
241
+ if (!isOpen()) return;
242
+ $sheet.classList.remove('show');
243
+ const back = sheet?.returnFocus;
244
+ sheet = null;
245
+ if (!restoreFocus) return;
246
+ const id = back?.getAttribute?.('data-command-id');
247
+ const again = back && document.contains(back) ? back
248
+ : id ? [...document.querySelectorAll('[data-command-id]')].find((el) => el.getAttribute('data-command-id') === id) : null;
249
+ again?.focus?.();
250
+ }
251
+
252
+ function paintSheet() {
253
+ const t = target();
254
+ if (!sheet || !t) return;
255
+ if (sheet.mode === 'add') {
256
+ $title.textContent = 'Add a module';
257
+ $sub.textContent = `Pick a module. FloLess creates a new project of that kind and links it to “${t.name}”.`;
258
+ const cards = typeof ws().moduleCreateCardsHtml === 'function' ? ws().moduleCreateCardsHtml() : '';
259
+ $body.innerHTML = cards
260
+ ? `<div class="ws-create-grid pm-cards">${cards}</div>`
261
+ : '<p class="pm-note">No modules can be added on this computer yet. Set them up from the Workspaces page.</p>';
262
+ return;
263
+ }
264
+ const finding = sheet.mode === 'find';
265
+ $title.textContent = finding ? `Find “${sheet.find.name}”` : 'Link an existing project';
266
+ $sub.textContent = finding ? 'Choose the project in this Workspace this link should point to.' : `Choose a project to list in “${t.name}”.`;
267
+ const filter = (sheet.rows && sheet.rows.length > 8) || sheet.query
268
+ ? `<input type="search" class="ws-landing-search pm-filter" data-pm-filter="1" placeholder="Filter by name" aria-label="Filter projects by name" value="${esc(sheet.query)}">` : '';
269
+ if (!sheet.rows) { $body.innerHTML = `${filter}<p class="pg-loading-line">Loading projects…</p>`; return; }
270
+ let rows = sheet.rows;
271
+ if (finding) {
272
+ // The same project as the imported link first (the original is in this Workspace), then the same module.
273
+ rows = [...rows].filter((r) => r.templateId === sheet.find.app || r.uuid === sheet.find.uuid)
274
+ .sort((a, b) => (b.uuid === sheet.find.suggestUuid) - (a.uuid === sheet.find.suggestUuid));
275
+ }
276
+ const list = rows.length
277
+ ? `<div class="pm-pick-list" role="list">${rows.map((r) => `<div role="listitem"><button type="button" class="pm-pick" data-pm-choose="${esc(r.uuid)}"
278
+ data-pm-name="${esc(r.name)}" data-command-id="shell.project-modules-link-choose#${esc(r.id)}" data-command-instance-label="${esc(r.name)}">
279
+ <span class="pg-row-title">${esc(r.name)}</span><span class="pg-row-meta">${esc(moduleName(r.templateId))}${finding && r.uuid === sheet.find.suggestUuid ? ' · Same project as the imported link' : ''}</span></button></div>`).join('')}</div>`
280
+ : `<p class="pm-note">${sheet.query ? 'No project matches that name.' : 'Every project in this Workspace is already linked, or none is a module project yet.'}</p>`;
281
+ const more = sheet.truncated ? '<p class="pm-note">Showing the 200 newest. Use the filter to find an older one.</p>' : '';
282
+ const hadFocus = document.activeElement?.hasAttribute?.('data-pm-filter');
283
+ $body.innerHTML = filter + list + more;
284
+ if (hadFocus) { const input = $body.querySelector('[data-pm-filter]'); input?.focus(); input?.setSelectionRange?.(sheet.query.length, sheet.query.length); }
285
+ }
286
+
287
+ async function loadLinkable() {
288
+ const mine = sheet;
289
+ const t = target();
290
+ if (!mine || !t) return;
291
+ // Typing fast sends several reads; only the newest one's answer, or failure, is shown.
292
+ const generation = (mine.generation = (mine.generation || 0) + 1);
293
+ const current = () => sheet === mine && mine.generation === generation;
294
+ try {
295
+ const q = mine.query ? `?q=${encodeURIComponent(mine.query)}` : '';
296
+ const data = await api(`/api/projects/${encodeURIComponent(t.projectId)}/links${q}`);
297
+ if (!current()) return;
298
+ // A missing link's original is not offered as linkable; a needs-reconnect row's suggestion is.
299
+ const suggestion = mine.find ? data.links.find((l) => l.projectUuid === mine.find.uuid)?.suggestion : null;
300
+ mine.rows = data.linkable.slice();
301
+ if (mine.find) {
302
+ // Find it may also choose a project already linked here: the two entries become one (spec §3.2).
303
+ for (const l of data.links) {
304
+ if (l.state === 'live' && l.target && l.projectUuid !== mine.find.uuid && !mine.rows.some((r) => r.uuid === l.projectUuid)
305
+ && (!mine.query || l.target.name.toLowerCase().includes(mine.query.toLowerCase()))) {
306
+ mine.rows.push({ id: l.target.id, uuid: l.projectUuid, name: l.target.name, app: l.target.app, templateId: l.target.templateId });
307
+ }
308
+ }
309
+ }
310
+ if (suggestion && !mine.rows.some((r) => r.id === suggestion.id)) {
311
+ mine.rows.unshift({ id: suggestion.id, uuid: mine.find.uuid, name: suggestion.name, app: suggestion.app, templateId: mine.find.app });
312
+ }
313
+ if (mine.find) mine.find.suggestUuid = suggestion ? mine.find.uuid : null;
314
+ mine.truncated = !!data.linkableTruncated;
315
+ paintSheet();
316
+ } catch (error) {
317
+ if (!current()) return;
318
+ $body.innerHTML = `<p class="pm-note">${esc(said(error, 'FloLess couldn’t list this Workspace’s projects just now. Close this and try again.'))}</p>`;
319
+ }
320
+ }
321
+
322
+ // ── after a create from Add a module (called by the create flows in workspaces.js) ─────────────────────────────
323
+
324
+ /**
325
+ * One message from the real outcome (spec §6.3): linked; created but not linked (Retry link); the Revit upload failed
326
+ * and the empty project was archived (its link removed too); the Tekla import failed but the project stays linked.
327
+ */
328
+ async function afterCreate({ project, linkFrom, moduleLink, replayed, outcome, error, next }) {
329
+ if (!project || !linkFrom) return;
330
+ const general = linkFrom.name || 'the General project';
331
+ const back = { label: `Back to ${general}`, commandId: 'shell.project-modules-back',
332
+ onClick: () => Promise.resolve(ws().openModulesStep?.(linkFrom.projectId)).catch((e) => toast(e?.message || 'FloLess couldn’t open that project. Open it from Workspaces.', 'warn')) };
333
+ if (outcome === 'archived-empty' || outcome === 'left-empty') {
334
+ let removed = false;
335
+ try {
336
+ const q = new URLSearchParams({ rootId: linkFrom.rootId, sourceUuid: linkFrom.sourceUuid });
337
+ await api(`/api/projects/${encodeURIComponent(linkFrom.projectId)}/links/${encodeURIComponent(project.uuid)}?${q}`, { method: 'DELETE' });
338
+ removed = true;
339
+ } catch (unlinkError) { console.warn('[project-modules] the empty project’s link could not be removed', unlinkError); }
340
+ if (error) console.warn('[project-modules] the Revit model could not be added', error);
341
+ const why = ' Check the .rvt file is not open in Revit, then add the module again.';
342
+ toast(outcome === 'left-empty'
343
+ ? `The Revit model couldn’t be added, and FloLess couldn’t archive the empty project. Archive it from its ⋯ menu.${why}`
344
+ : removed
345
+ ? `The Revit model couldn’t be added, so the empty project was archived and isn’t linked to ${general}.${why}`
346
+ : `The Revit model couldn’t be added. The empty project was archived, but its link is still listed — remove it on ${general}’s Modules step.${why}`, 'warn');
347
+ return;
348
+ }
349
+ if (!moduleLink) {
350
+ // An answer without a link result never reads as linked: the record must not claim what nobody checked.
351
+ toast(`“${project.name}” was created. FloLess couldn’t confirm it was linked to ${general}; check the Modules step there.`, 'warn', { action: back });
352
+ return;
353
+ }
354
+ if (moduleLink.ok === false) {
355
+ if (moduleLink.code === 'link-declined') { toast(`“${project.name}” was created. You chose not to link it, so it stays unlinked.`, 'info'); return; }
356
+ toast(moduleLink.code === 'link-removed'
357
+ ? `“${project.name}” was made by an earlier try. Its link was removed since, so it stays unlinked.`
358
+ : `“${project.name}” was created but couldn’t be linked to ${general}. Nothing was lost; you can link it from the Modules step. ${moduleLink.error || ''}`.trim(),
359
+ 'warn', moduleLink.code === 'link-removed' ? { action: back } : { action: { label: 'Retry link', commandId: 'shell.project-modules-retry-link', onClick: () => retryLink(linkFrom, project) } });
360
+ return;
361
+ }
362
+ if (outcome === 'failed-kept') {
363
+ toast(`“${project.name}” was created and linked to ${general}, but its Tekla model couldn’t be read. Open it to see why, then choose the model again.`, 'warn', { action: back });
364
+ return;
365
+ }
366
+ if (replayed && project.archived) {
367
+ // The earlier try's project was archived since: say so and offer the way back, never a plain "linked".
368
+ toast(`“${project.name}” was already created by an earlier try and has been archived since. Restore it from the archived projects to use it.`,
369
+ 'warn', { action: { label: 'Show archived projects', commandId: 'shell.project-modules-show-archived', onClick: () => ws().showArchivedProjects?.() } });
370
+ return;
371
+ }
372
+ const lead = replayed ? `“${project.name}” was already created by an earlier try and is linked to ${general}.` : `Linked to ${general}.`;
373
+ toast(next ? `${lead} ${next}` : lead, 'ok', { action: back });
374
+ }
375
+
376
+ async function retryLink(linkFrom, project) {
377
+ try {
378
+ await api(`/api/projects/${encodeURIComponent(linkFrom.projectId)}/links`, { method: 'POST',
379
+ body: JSON.stringify({ rootId: linkFrom.rootId, sourceUuid: linkFrom.sourceUuid, projectUuid: project.uuid }) });
380
+ toast(`“${project.name}” is linked to ${linkFrom.name || 'the General project'}.`, 'ok');
381
+ } catch (error) {
382
+ toast(said(error, 'FloLess still couldn’t link it. It is listed under “Created here, not linked” on the General project’s Modules step.'), 'warn');
383
+ }
384
+ }
385
+
386
+ // ── events ─────────────────────────────────────────────────────────────────────────────────────────────────────
387
+
388
+ document.addEventListener('click', (event) => {
389
+ if (!state || !state.pane.contains(event.target)) return;
390
+ const t = event.target;
391
+ const open = t.closest('[data-pm-open]');
392
+ if (open) {
393
+ event.preventDefault();
394
+ Promise.resolve(ws().openLinkedProject?.(open.getAttribute('data-pm-open'))).catch((error) => {
395
+ toast(error?.message || 'FloLess couldn’t open that project. Try again, or open it from Workspaces.', 'warn');
396
+ void load();
397
+ });
398
+ return;
399
+ }
400
+ const unl = t.closest('[data-pm-unlink]');
401
+ if (unl) { event.preventDefault(); void unlink(unl.getAttribute('data-pm-unlink'), unl.getAttribute('data-pm-name')); return; }
402
+ const decline = t.closest('[data-pm-decline]');
403
+ if (decline) { event.preventDefault(); void unlink(decline.getAttribute('data-pm-decline'), decline.getAttribute('data-pm-name'), { decline: true }); return; }
404
+ const linkCreated = t.closest('[data-pm-link-created]');
405
+ if (linkCreated) { event.preventDefault(); void linkTo(linkCreated.getAttribute('data-pm-link-created'), { label: linkCreated.getAttribute('data-command-instance-label') }); return; }
406
+ const restore = t.closest('[data-pm-restore], [data-pm-restore-created]');
407
+ if (restore) { event.preventDefault(); void ws().showArchivedProjects?.(restore); return; }
408
+ const find = t.closest('[data-pm-find]');
409
+ if (find) {
410
+ event.preventDefault();
411
+ openSheet('find', find, { uuid: find.getAttribute('data-pm-find'), app: find.getAttribute('data-pm-app'), name: find.getAttribute('data-pm-name') });
412
+ return;
413
+ }
414
+ if (t.closest('[data-pm-add]')) { event.preventDefault(); openSheet('add', t.closest('[data-pm-add]')); return; }
415
+ if (t.closest('[data-pm-link-existing]')) { event.preventDefault(); openSheet('link', t.closest('[data-pm-link-existing]')); return; }
416
+ if (t.closest('[data-pm-retry]')) { event.preventDefault(); state.view = { status: 'loading', data: null }; paint('heading'); void load(); }
417
+ });
418
+
419
+ $sheet?.addEventListener('click', (event) => {
420
+ if (!sheet) return;
421
+ const t = event.target;
422
+ if (sheet.mode === 'add') {
423
+ const card = t.closest('.ws-seed, [data-seed-app], [data-parser-setup], [data-revit-remedy], [data-module-remedy]');
424
+ if (!card) return;
425
+ const tgt = target();
426
+ // One operation per Add a module: every press of Create in the dialog it opens is the same operation, so a
427
+ // retry after a lost answer can never make a second project (spec §3.4).
428
+ const linkFrom = { projectId: tgt.projectId, sourceUuid: tgt.sourceUuid, rootId: tgt.rootId, operationId: newOperationId(), name: tgt.name };
429
+ const addButton = state?.pane.querySelector('[data-pm-add]');
430
+ // The card's own flow opens its picker or setup dialog, which returns focus to Add a module.
431
+ closeSheet({ restoreFocus: false });
432
+ addButton?.focus({ preventScroll: true });
433
+ const started = ws().activateCreateCard?.(card, linkFrom);
434
+ if (!started) { toast('That module can’t be added from here. Use its card on the Workspaces page.', 'warn'); return; }
435
+ Promise.resolve(started.done).catch((error) => {
436
+ console.warn('[project-modules] a module card could not start', error);
437
+ toast(said(error, 'FloLess couldn’t start adding that module. Try again, or use its card on the Workspaces page.'), 'warn');
438
+ });
439
+ return;
440
+ }
441
+ const choose = t.closest('[data-pm-choose]');
442
+ if (choose) {
443
+ const replaces = sheet.mode === 'find' ? sheet.find.uuid : undefined;
444
+ const label = choose.getAttribute('data-pm-name');
445
+ closeSheet();
446
+ void linkTo(choose.getAttribute('data-pm-choose'), { replaces, label });
447
+ }
448
+ });
449
+ $sheet?.addEventListener('input', (event) => {
450
+ if (!sheet || !event.target.matches?.('[data-pm-filter]')) return;
451
+ sheet.query = event.target.value.slice(0, 200);
452
+ // Any read still on its way answers the previous text: it is out of date from this keystroke on.
453
+ sheet.generation = (sheet.generation || 0) + 1;
454
+ clearTimeout(sheet.timer);
455
+ const mine = sheet;
456
+ // The server filters before its cap, so an older project is found too.
457
+ mine.timer = setTimeout(() => { if (sheet === mine) void loadLinkable(); }, 200);
458
+ });
459
+ document.getElementById('pm-close')?.addEventListener('click', () => closeSheet());
460
+ if (typeof onBackdropDismiss === 'function' && $sheet) onBackdropDismiss($sheet, () => closeSheet());
461
+ document.addEventListener('keydown', (e) => {
462
+ if (e.key !== 'Escape' || !isOpen()) return;
463
+ e.stopPropagation();
464
+ closeSheet();
465
+ });
466
+ window.addEventListener('floless:apps-changed', refresh);
467
+ // A link, a project made from here, an archive or a rename anywhere (another tab, AI Chat) re-reads the open step.
468
+ window.addEventListener('floless:projects-changed', refresh);
469
+
470
+ /** The landing's card set changed (its module list arrived or a lock lifted): an open Add a module sheet repaints. */
471
+ function cardsChanged() { if (sheet?.mode === 'add' && isOpen()) paintSheet(); }
472
+
473
+ window.flolessProjectModules = { render, refresh, html, rowHtml, afterCreate, closeSheet, cardsChanged };
474
+ })();