@floless/app 0.104.2 → 0.105.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.
@@ -168,6 +168,9 @@
168
168
  { kind: 'bom-xlsx', ico: '▦', name: 'Bill of materials', fmt: 'XLSX', verb: 'Export Excel', file: true, open: true },
169
169
  { kind: 'ifc', ico: '◈', name: 'Model', fmt: 'IFC4', verb: 'Export IFC', file: true, open: false },
170
170
  { kind: 'tekla', ico: '◧', name: 'Tekla', fmt: 'Native parts', verb: 'Send to Tekla', file: false },
171
+ // Yields a URL, not a file, so none of the exportState/receipt plumbing applies — its status
172
+ // comes from shareCardState and its result is a link with a Copy button (see cardHtml).
173
+ { kind: 'share-3d', ico: '↗', name: 'Model', fmt: 'Shareable web link', verb: 'Create share link', file: false },
171
174
  ],
172
175
  },
173
176
  vectorize: {
@@ -203,11 +206,23 @@
203
206
  let mode = 'workflows';
204
207
  try { if (localStorage.getItem(LS_MODE) === 'workspaces') mode = 'workspaces'; } catch { /* private mode */ }
205
208
  let projects = [];
209
+ let projectsLoadError = null; // last /api/projects failure reason, or null — an empty list means
210
+ // "none yet" ONLY when this is null (see the empty state in renderLanding)
206
211
  let archived = []; // archived projects (the "Trash") — listed under a collapsed section on the landing
207
212
  // Installed workspace apps, in descriptor order. Populated from /api/apps in loadProjects():
208
213
  // the set = apps flagged workspace===true that ALSO have a WORKSPACE_APPS descriptor (an app
209
214
  // flagged workspace with no descriptor is skipped with a console note — never a broken open).
210
215
  // Drives the per-app create cards. Falls back to the descriptor keys if /api/apps can't be read.
216
+ // Starts at the descriptor keys so the create cards are on the FIRST paint, then /api/apps narrows
217
+ // them. Two alternatives were tried and rejected against measurements:
218
+ // - starting EMPTY delayed the cards to 8-14 s (30-43 s loaded), leaving the landing visibly
219
+ // half-built with the empty state pointing at "the cards above" when nothing was above;
220
+ // - rendering them DISABLED until /api/apps confirmed left them dead for 18-60 s, because that
221
+ // call queues behind the (slow, uncached) /api/workflows/updates — a dead control is no better
222
+ // than a missing one.
223
+ // The hazard those were guarding — clicking a card for an app that isn't installed — is closed
224
+ // where it belongs instead: POST /api/projects refuses an app with no readable source, so no
225
+ // client's paint timing can mint an orphan project, and the click surfaces an honest error toast.
211
226
  let wsAppIds = Object.keys(WORKSPACE_APPS);
212
227
  let current = null; // the open project (null = landing)
213
228
 
@@ -287,21 +302,68 @@
287
302
  return h < 48 ? `${h} h ago` : `${Math.round(h / 24)} d ago`;
288
303
  };
289
304
 
290
- async function loadProjects() {
305
+ // Monotonic id per load. applyMode() fires loadProjects() fire-and-forget and re-runs on any mode
306
+ // set (even a no-op one), and several actions trail a refresh, so two loads can overlap. Without
307
+ // this, a slow FAILING load that started first can land after a fast successful one and repaint
308
+ // the error over a list that is actually fine (or the reverse, erasing a real failure). Only the
309
+ // newest load may touch shared state or paint. Same discipline as the editor's saveSeq.
310
+ let projectsLoadSeq = 0;
311
+
312
+ // `quiet` suppresses the failure toast: the retry button's own pending state and the banner it sits
313
+ // in already report the outcome, and a retry against a cached 402 completes in ~35 ms, so the
314
+ // re-entrancy guard never gets to fire and five clicks produced five identical toasts.
315
+ async function loadProjects(opts) {
316
+ const seq = ++projectsLoadSeq;
317
+ const stale = () => seq !== projectsLoadSeq;
291
318
  // Surface a real failure — never present a server/network error as an empty workspace
292
319
  // (the empty-state CTA would be a lie: "no projects yet" when the truth is "load failed").
293
- try { ({ projects } = await api('/api/projects')); }
294
- catch (err) { projects = []; showToast('Couldn’t load projects: ' + (err && err.message || err), 'warn'); }
295
- // Archived ("Trash") list is a secondary concern — never let its failure blank the main workspace,
296
- // but don't swallow it silently either: warn so a broken archive listing is diagnosable (a bare
297
- // catch here would hide a real 500 and leave the "Archived" section invisible with no breadcrumb).
298
- try { ({ projects: archived } = await api('/api/projects/archived')); }
299
- catch (err) { archived = []; console.warn('[workspaces] archived list failed to load: ' + (err && err.message || err)); }
320
+ try {
321
+ const res = await api('/api/projects');
322
+ if (stale()) return;
323
+ projects = res.projects;
324
+ projectsLoadError = null;
325
+ } catch (err) {
326
+ if (stale()) return;
327
+ projects = [];
328
+ // Remember WHY, so renderLanding can say "couldn't load" instead of "none yet" (they look
329
+ // identical from `projects` alone). Cleared on the next success, so a recovered load drops
330
+ // straight back to the normal empty state.
331
+ projectsLoadError = (err && err.message) || String(err);
332
+ if (!(opts && opts.quiet)) showToast('Couldn’t load projects: ' + projectsLoadError, 'warn');
333
+ }
334
+ // Paint the moment the LIST is in hand — before the archived call, not after it. That call is a
335
+ // secondary concern (a collapsed Trash disclosure) but it was measured at 0.31-0.83 s normally
336
+ // and 5.6 s under load, and holding the first paint behind it made it the only remaining source
337
+ // of a blank landing. The repaint below adds the Archived section when it arrives.
338
+ renderLanding();
339
+ // Archived ("Trash") list — never let its failure blank the main workspace, but don't swallow it
340
+ // silently either: warn so a broken archive listing is diagnosable (a bare catch here would hide
341
+ // a real 500 and leave the "Archived" section invisible with no breadcrumb).
342
+ // Signature covers what the rows actually RENDER, not just which rows exist: another client can
343
+ // restore and re-archive the same project (same id, new updatedAt) or rename it, and an
344
+ // id-only comparison would skip the repaint and leave a stale name / "archived N days ago".
345
+ // JSON.stringify, not a delimiter join — names are user-supplied and unrestricted, so a name
346
+ // containing the delimiters could forge another row's signature and suppress a real repaint.
347
+ const archivedSig = (list) => JSON.stringify(list.map((p) => [p.id, p.name, p.app, p.updatedAt]));
348
+ const archivedBefore = archivedSig(archived);
349
+ try {
350
+ const res = await api('/api/projects/archived');
351
+ if (stale()) return;
352
+ archived = res.projects;
353
+ } catch (err) {
354
+ if (stale()) return;
355
+ archived = [];
356
+ console.warn('[workspaces] archived list failed to load: ' + (err && err.message || err));
357
+ }
358
+ if (archivedSig(archived) !== archivedBefore) renderLanding();
300
359
  // Which workspace apps to offer a create card for: those flagged workspace===true on /api/apps
301
360
  // that we ALSO know how to render (have a WORKSPACE_APPS descriptor). Keep descriptor order for a
302
- // stable card order. A load failure leaves wsAppIds at its descriptor-key fallback (still usable).
361
+ // stable card order. A load failure RE-WIDENS wsAppIds to the descriptor keys (the catch assigns
362
+ // them): still usable, and a card for something uninstalled is refused by the server on click.
363
+ const cardsBefore = wsAppIds.join(',');
303
364
  try {
304
365
  const { apps } = await api('/api/apps');
366
+ if (stale()) return;
305
367
  const flagged = new Set((apps || []).filter((a) => a && a.workspace === true).map((a) => a.id));
306
368
  wsAppIds = Object.keys(WORKSPACE_APPS).filter((id) => flagged.has(id));
307
369
  // Hardening: /api/apps loaded but flagged NONE of our known workspace apps (a transient
@@ -315,8 +377,72 @@
315
377
  console.warn(`[workspaces] app "${a.id}" is flagged workspace but has no client descriptor — skipping its create card`);
316
378
  }
317
379
  }
318
- } catch { /* keep the descriptor-key fallback — the create cards still work */ }
319
- renderLanding();
380
+ } catch {
381
+ if (stale()) return;
382
+ // /api/apps failed — fall back to the descriptor keys so the create cards still work.
383
+ wsAppIds = Object.keys(WORKSPACE_APPS);
384
+ }
385
+ // Second paint ONLY if /api/apps actually changed the card set. It usually confirms what the
386
+ // previous answer already showed, and a blind repaint seconds later would blow away whatever the
387
+ // user has since touched in the landing — an open kebab menu, the expanded Archived section.
388
+ if (wsAppIds.join(',') !== cardsBefore) {
389
+ // #ws-proj-menu lives outside $landing, so the rebuild below does NOT close it — it would stay
390
+ // pinned at the coordinates of the kebab that opened it while the grid reflows under it
391
+ // (dropping create cards shifts every project card up), leaving it beside a different project
392
+ // than the one it acts on. It targets by id so nothing acts on the wrong row, but it reads as
393
+ // if it does. Close it first.
394
+ closeProjMenu();
395
+ renderLanding();
396
+ }
397
+ }
398
+
399
+ // Translate the failures we can recognise into the user's language, the way kbPaintError does for
400
+ // the Knowledge viewer. Returns '' for anything unrecognised — better to show only the raw detail
401
+ // than to guess wrong about why. The raw string is shown either way, just demoted.
402
+ function projectsErrorHint(reason) {
403
+ const r = String(reason || '').toLowerCase();
404
+ if (/subscription|session|sign in|402/.test(r)) return 'Your sign-in needs refreshing — sign in again, then retry.';
405
+ if (/failed to fetch|networkerror|load failed|econnrefused|connection/.test(r)) return 'The local server didn’t answer.';
406
+ if (/http 5\d\d/.test(r)) return 'The server hit an error listing them.';
407
+ return '';
408
+ }
409
+
410
+ // Retry from the error banner. renderLanding() replaces the button that was clicked, so focus
411
+ // would collapse to <body>; put it back where the user left it — the same discipline as
412
+ // restoreExportFocus() and wsOpenHistory()'s explicit refocus.
413
+ let retryInFlight = false;
414
+ async function retryProjects() {
415
+ // This panel appears exactly when the server is slow or wedged, so the retry can take many
416
+ // seconds. Without a pending state the UI is byte-identical after the click and the user clicks
417
+ // again (and again), each landing its own failure toast. Same shape as aware.js's bootstrap
418
+ // retry: guard re-entry, disable, and SAY it is trying.
419
+ if (retryInFlight) return;
420
+ const btn = document.getElementById('ws-retry-projects');
421
+ const hadFocus = document.activeElement === btn;
422
+ retryInFlight = true;
423
+ if (btn) { btn.disabled = true; btn.textContent = 'Trying…'; }
424
+ try {
425
+ await loadProjects({ quiet: true }); // the banner + this button already say what happened
426
+ } catch (err) {
427
+ // loadProjects swallows API failures itself, so reaching here means the RENDER threw. The
428
+ // repaint that would have replaced this button never happened, so restore it by hand —
429
+ // otherwise the one recovery control on screen stays disabled reading "Trying…" forever.
430
+ console.error('[workspaces] retry failed to render: ' + ((err && err.message) || err));
431
+ if (btn && btn.isConnected) { btn.disabled = false; btn.textContent = '↻ Try again'; }
432
+ } finally {
433
+ retryInFlight = false;
434
+ // If a concurrent load superseded this one, loadProjects bailed at its first await WITHOUT
435
+ // painting — so the repaint that would have replaced this button never happened and it would
436
+ // sit disabled reading "Trying…", dead, until some other load lands. That other load is
437
+ // against the same slow server this banner is complaining about. Restore it ourselves if it
438
+ // is still the live element.
439
+ const same = document.getElementById('ws-retry-projects');
440
+ if (same && same === btn && same.disabled) { same.disabled = false; same.textContent = '↻ Try again'; }
441
+ }
442
+ if (!hadFocus) return;
443
+ const again = document.getElementById('ws-retry-projects'); // still failing → the new button
444
+ const firstCard = $landing.querySelector('.ws-card[data-open]'); // recovered → the list it just loaded
445
+ (again || firstCard)?.focus({ focusVisible: true });
320
446
  }
321
447
 
322
448
  function renderLanding() {
@@ -367,10 +493,25 @@
367
493
  `</span></div>`;
368
494
  }
369
495
  html += `</div>`;
370
- // Empty state: point at the create cards above and the Import button in the header.
496
+ // Empty state — but ONLY when the list really is empty. A failed load also leaves `projects`
497
+ // empty, and telling someone with 11 projects "No projects yet — start one" is a lie that reads
498
+ // like their work is gone. The toast alone can't carry this: it auto-dismisses, and the false
499
+ // sentence stays on screen. Say what happened and offer the retry instead.
371
500
  if (!projects.length) {
372
- const note = 'No projects yet — start one from the cards above, or Import project to restore an exported .zip.';
373
- html += `<div class="ws-empty-note">${escapeHtml(note)}${archived.length ? ' You have archived projects below.' : ''}</div>`;
501
+ if (projectsLoadError) {
502
+ // role=status/polite, not alert: this can appear on an ordinary repaint (any action that
503
+ // re-runs loadProjects re-renders it), and assertive would interrupt a screen-reader user
504
+ // each time. Matches every other live region in this app.
505
+ const guess = projectsErrorHint(projectsLoadError);
506
+ html += `<div class="ws-empty-note ws-load-error" role="status" aria-live="polite">`
507
+ + `<b>Couldn’t load your projects.</b> `
508
+ + (guess ? `${escapeHtml(guess)} ` : '')
509
+ + `<span class="ws-load-error-detail">${escapeHtml(projectsLoadError)}</span>`
510
+ + ` <button type="button" id="ws-retry-projects">↻ Try again</button></div>`;
511
+ } else {
512
+ const note = 'No projects yet — start one from the cards above, or Import project to restore an exported .zip.';
513
+ html += `<div class="ws-empty-note">${escapeHtml(note)}${archived.length ? ' You have archived projects below.' : ''}</div>`;
514
+ }
374
515
  }
375
516
  // Archived ("Trash") section — a collapsed disclosure below the live grid, only when non-empty.
376
517
  // Demoted rows (muted, no thumb) read as "put away"; each offers Restore + a guarded Delete.
@@ -395,6 +536,7 @@
395
536
  `</details>`;
396
537
  }
397
538
  $landing.innerHTML = html;
539
+ reflashCard(); // a repaint must not swallow an in-flight confirmation glow
398
540
  }
399
541
 
400
542
  $landing.addEventListener('click', async (e) => {
@@ -404,6 +546,7 @@
404
546
  if (restore) { e.stopPropagation(); unarchiveProject(restore.dataset.restore); return; }
405
547
  const del = e.target.closest('[data-delete-archived]');
406
548
  if (del) { e.stopPropagation(); deleteArchivedProject(del.dataset.deleteArchived); return; }
549
+ if (e.target.closest('#ws-retry-projects')) { e.stopPropagation(); retryProjects(); return; }
407
550
  if (e.target.closest('#ws-import-project')) { importProject(); return; }
408
551
  const card = e.target.closest('[data-open]');
409
552
  if (card) { openProject(card.dataset.open); return; }
@@ -687,6 +830,23 @@
687
830
  const w = frames.model && frames.model.contentWindow;
688
831
  if (w && typeof w.clearFind === 'function') { try { w.clearFind(); } catch { /* iframe gone */ } }
689
832
  }
833
+ // The steel editor's ⋯ "Revert to an earlier version…" calls this from inside the Model iframe
834
+ // (same-origin, same bridge as find/clearFind above). Reverting a project belongs to the version
835
+ // ledger — this only navigates to it. No project open = nothing to show, so it's a no-op rather
836
+ // than a switch into an empty History pane.
837
+ function wsOpenHistory() {
838
+ if (!current) return;
839
+ setStep('history');
840
+ // Move focus with the step. The click that gets here comes from a button inside the Model
841
+ // iframe, which setStep() has just hidden — focus would otherwise collapse to <body>, leaving a
842
+ // keyboard user with no visible focus and a screen reader with nothing announced. Landing on the
843
+ // History tab reproduces exactly where a manual click on that tab would have left them.
844
+ // focusVisible: the keypress that got here happened in the IFRAME, so this document's
845
+ // :focus-visible heuristic scores the focus as programmatic and paints no ring. Ask for it
846
+ // explicitly; engines that don't support the option ignore it and behave exactly as before.
847
+ const tab = $stepTabs.querySelector('button[data-step="history"]');
848
+ if (tab) tab.focus({ focusVisible: true });
849
+ }
690
850
  // While focus is inside the editor iframe (the usual case on the Model step), the parent's Ctrl+F
691
851
  // handler never sees the key — so the shell forwards Cmd/Ctrl+F from the same-origin editor up to
692
852
  // the global openFind. Re-wired on every iframe (re)load; each load is a fresh contentWindow, so
@@ -1884,6 +2044,40 @@
1884
2044
  `</div>`;
1885
2045
  }
1886
2046
 
2047
+ // Links created this session, per project: `${projectId}:share-3d` -> { url, approvedAt }. Held in
2048
+ // memory only — the server keeps no record of what a project has shared, and inventing a durable
2049
+ // one here would imply a revoke story that does not exist yet.
2050
+ const shareLinks = new Map();
2051
+
2052
+ // The share card's state, same {meta, disabled, tip} shape as teklaCardState. It is the second
2053
+ // file:false export kind, and the first whose RESULT is a URL rather than a file.
2054
+ function shareCardState(approved) {
2055
+ if (!approved) return {
2056
+ meta: '<span class="e-status">Available after approval</span>',
2057
+ disabled: true,
2058
+ tip: 'Approve this version first',
2059
+ };
2060
+ const made = shareLinks.get(`${current.id}:share-3d`);
2061
+ // A link is a frozen snapshot of the version it was made from. Once the project is re-approved it
2062
+ // no longer shows the current model — and staying silent about that would be worse than for a
2063
+ // file export, because a recipient may already hold the URL and cannot be un-sent it.
2064
+ if (made && made.approvedAt !== current.approvedAt) return {
2065
+ meta: `<span class="e-status">Link is from an earlier version</span>`,
2066
+ disabled: false,
2067
+ tip: 'Create a new link to share the current approved model',
2068
+ };
2069
+ if (made) {
2070
+ const shown = made.url.replace(/^https:\/\//, '');
2071
+ return {
2072
+ meta: `<span class="e-done"><span class="chk">✓</span> <span class="t e-sharelink" data-tip="${escapeAttr(made.url)}">${escapeHtml(shown)}</span></span>` +
2073
+ `<span class="e-links"><button type="button" class="e-link" data-copyshare="1" data-tip="Copy the link to your clipboard">Copy</button></span>`,
2074
+ disabled: false,
2075
+ tip: '',
2076
+ };
2077
+ }
2078
+ return { meta: '<span class="e-status">not created yet</span>', disabled: false, tip: '' };
2079
+ }
2080
+
1887
2081
  function teklaCardState(approved) {
1888
2082
  if (!approved) return {
1889
2083
  meta: '<span class="e-status">Available after approval</span>',
@@ -1919,9 +2113,12 @@
1919
2113
  function cardHtml(c, approved) {
1920
2114
  let meta;
1921
2115
  const busy = exportBusy.has(`${current.id}:${c.kind}`);
1922
- const tekla = c.kind === 'tekla' ? teklaCardState(approved) : null;
1923
- if (tekla) {
1924
- meta = tekla.meta;
2116
+ // The two file:false kinds resolve their own status; everything else uses the file/receipt path
2117
+ // below. `special` keeps the branches from growing a third arm each time a kind is added.
2118
+ const special = c.kind === 'tekla' ? teklaCardState(approved)
2119
+ : c.kind === 'share-3d' ? shareCardState(approved) : null;
2120
+ if (special) {
2121
+ meta = special.meta;
1925
2122
  } else if (!approved) {
1926
2123
  meta = `<span class="e-status">Available after approval</span>`;
1927
2124
  } else if (exportState == null) {
@@ -1940,15 +2137,21 @@
1940
2137
  }
1941
2138
  }
1942
2139
  const exported = approved && c.file && exportState && exportState[c.kind] && exportState[c.kind].exportedAt;
1943
- const label = busy ? (c.kind === 'tekla' ? 'Sending…' : 'Exporting…') : (exported ? 'Re-export' : c.verb);
1944
- const disabled = tekla ? tekla.disabled : !approved;
1945
- const tip = busy ? (c.kind === 'tekla' ? 'Sending the approved model to Tekla' : 'Export in progress')
1946
- : tekla ? tekla.tip : (approved ? '' : 'Approve this version first');
2140
+ // Re-labelled once a link exists, mirroring the file kinds' "Re-export" convention. Gated on the
2141
+ // in-memory record rather than exportState, which only ever tracks file exports.
2142
+ const shared = approved && c.kind === 'share-3d' && shareLinks.has(`${current.id}:share-3d`);
2143
+ const busyLabel = c.kind === 'tekla' ? 'Sending…' : c.kind === 'share-3d' ? 'Creating…' : 'Exporting…';
2144
+ const label = busy ? busyLabel : (exported || shared ? (c.kind === 'share-3d' ? 'Create new link' : 'Re-export') : c.verb);
2145
+ const disabled = special ? special.disabled : !approved;
2146
+ const busyTip = c.kind === 'tekla' ? 'Sending the approved model to Tekla'
2147
+ : c.kind === 'share-3d' ? 'Rendering the model and uploading the link' : 'Export in progress';
2148
+ const tip = busy ? busyTip
2149
+ : special ? special.tip : (approved ? '' : 'Approve this version first');
1947
2150
  const dis = `${disabled && !busy ? ' disabled' : ''}${busy ? ' aria-disabled="true" aria-busy="true"' : ''}${tip ? ` data-tip="${escapeAttr(tip)}"` : ''}`;
1948
2151
  return `<div class="ecard">` +
1949
2152
  `<div class="e-top"><div class="e-ico">${escapeHtml(c.ico)}</div>` +
1950
2153
  `<div><div class="e-name">${escapeHtml(c.name)}</div><div class="e-fmt">${escapeHtml(c.fmt)}</div></div></div>` +
1951
- `<div class="e-meta${tekla ? ' e-meta-tekla' : ''}">${meta}</div>` +
2154
+ `<div class="e-meta${special ? ' e-meta-tekla' : ''}">${meta}</div>` +
1952
2155
  receiptHtml(c.kind, approved) +
1953
2156
  `<div class="e-act"><button type="button" data-export="${escapeAttr(c.kind)}"${dis}>↗ ${escapeHtml(label)}</button></div>` +
1954
2157
  `</div>`;
@@ -1960,6 +2163,7 @@
1960
2163
  'data-reveal',
1961
2164
  'data-export-details',
1962
2165
  'data-tekla-recovery',
2166
+ 'data-copyshare', // the share-link Copy button — omitted here, a repaint mid-render steals its focus
1963
2167
  ];
1964
2168
 
1965
2169
  function exportFocusIdentity(element) {
@@ -2052,7 +2256,7 @@
2052
2256
 
2053
2257
  async function doExport(kind) {
2054
2258
  if (!current) return;
2055
- const app = current.app, projectId = current.id, approvedAt = current.approvedAt; // capture — the user may switch projects during the await
2259
+ const app = current.app, projectId = current.id, approvedAt = current.approvedAt, projectName = current.name; // capture — the user may switch projects, or leave, during the await
2056
2260
  const busyKey = `${projectId}:${kind}`;
2057
2261
  if (exportBusy.has(busyKey)) return;
2058
2262
  exportBusy.add(busyKey);
@@ -2060,6 +2264,60 @@
2060
2264
  // Carry the activated kind through the first replacement explicitly; later repaints infer
2061
2265
  // focus normally, so moving elsewhere during a long export is still respected.
2062
2266
  paintExports(current.approvedAt, kind);
2267
+ // A share link is two existing endpoints composed, not a new one: render the approved model to a
2268
+ // self-contained viewer document, then hand that document to the same upload the HTML report
2269
+ // Share button uses. Nothing about the hosting, the gate or the badge is special-cased here.
2270
+ if (kind === 'share-3d') {
2271
+ try {
2272
+ // `for=share` tells the server this document is about to be PUBLISHED, so it can refuse on an
2273
+ // AWARE too old to render the display modes this card offers. The local 3D view sends no flag.
2274
+ const rendered = await api(`/api/contract/${encodeURIComponent(app)}/export-3d?project=${encodeURIComponent(projectId)}&for=share`, { method: 'POST' });
2275
+ if (!rendered.ok || !rendered.report || !rendered.report.html) {
2276
+ throw new Error(rendered.error || 'the 3D render produced no document');
2277
+ }
2278
+ const html = rendered.report.html;
2279
+ const title = `${projectName || app} · 3D model`;
2280
+ // Measure the SERIALIZED body, not the raw HTML: JSON escaping on quote-heavy viewer markup
2281
+ // inflates the payload, so a document that reads as under the limit can still be over it once
2282
+ // sent — turning a preflight that was supposed to fail fast into a 413 after a long upload.
2283
+ // `kind` is in the measured string because it is in the sent string — the two must not drift.
2284
+ const body = JSON.stringify({ title, html, kind: 'model-3d' });
2285
+ const bytes = new Blob([body]).size;
2286
+ if (bytes > 5 * 1024 * 1024) {
2287
+ throw new Error(`This model is too large to share — ${(bytes / 1048576).toFixed(1)} MB, limit 5 MB.`);
2288
+ }
2289
+ const res = await api('/api/share-report', { method: 'POST', body });
2290
+ shareLinks.set(`${projectId}:share-3d`, { url: res.url, approvedAt });
2291
+ // The copy is tracked separately from the upload, and its failure never reaches the outer
2292
+ // catch: claiming "copied" when the clipboard was denied leaves the user pasting something
2293
+ // stale, and letting a missing navigator.clipboard throw would report a SUCCESSFUL share as
2294
+ // a failure. The link is on the card either way.
2295
+ let copied = false;
2296
+ try { await navigator.clipboard.writeText(res.url); copied = true; } catch { copied = false; }
2297
+ track('workspace_export', { app, kind });
2298
+ showToast(copied ? 'Share link created — copied to clipboard.' : 'Share link created — use Copy on the card.', 'ok');
2299
+ } catch (err) {
2300
+ const code = err && err.body && err.body.error;
2301
+ // The runtime refusal names the floor, not the pill's target: the footer pill installs
2302
+ // whatever the registry currently offers, which may be higher than the floor and would
2303
+ // otherwise read as a contradiction. Only the pill's STABLE label prefix is quoted.
2304
+ const awareVersion = err && err.body && err.body.version;
2305
+ const awareFloor = (err && err.body && err.body.floor) || '0.96.0';
2306
+ showToast(
2307
+ code === 'signed_out' ? 'Your FloLess sign-in has expired — sign in again to share.' :
2308
+ code === 'no_subscription' ? 'A FloLess subscription is required to share a model.' :
2309
+ code === 'rate_limited' ? 'Share limit reached (30 per hour) — try again shortly.' :
2310
+ code === 'aware_too_old' ? (awareVersion
2311
+ ? `AWARE v${awareVersion} is too old to share a faithful model — Realistic and Shadowed need v${awareFloor} or later. Click ↑ Upgrade AWARE in the footer, then share again.`
2312
+ : `Your installed AWARE is too old to share a faithful model — Realistic and Shadowed need v${awareFloor} or later. Click ↑ Upgrade AWARE in the footer, then share again.`) :
2313
+ (err && err.message ? err.message : String(err)),
2314
+ 'warn');
2315
+ } finally {
2316
+ exportBusy.delete(busyKey);
2317
+ if (current && current.id === projectId) paintExports(current.approvedAt);
2318
+ }
2319
+ return;
2320
+ }
2063
2321
  try {
2064
2322
  const res = await api(exportUrl(kind), { method: 'POST' });
2065
2323
  track('workspace_export', { app, kind }); // a successful export/bake (e.g. { app:'vectorize', kind:'svg' })
@@ -2165,6 +2423,26 @@
2165
2423
  if (open) { fileAction('/api/open-file', open.dataset.openfile, 'Couldn’t open the file'); return; }
2166
2424
  const rev = e.target.closest('[data-reveal]');
2167
2425
  if (rev) { fileAction('/api/reveal', rev.dataset.reveal, 'Couldn’t reveal the file'); return; }
2426
+ const cp = e.target.closest('[data-copyshare]');
2427
+ if (cp) {
2428
+ const made = current && shareLinks.get(`${current.id}:share-3d`);
2429
+ if (!made) return;
2430
+ // Toast confirmation, matching how the rest of the app confirms a copy — no inline label swap.
2431
+ // navigator.clipboard can be absent under a restricted browser policy, and dereferencing
2432
+ // .writeText then throws SYNCHRONOUSLY — before any .catch() on the returned promise could
2433
+ // run. That matters most here: the automatic copy guards this case (see the try/catch where
2434
+ // the link is created) and tells the user to press THIS button, so an unguarded throw would
2435
+ // fail exactly the fallback we pointed them at, and silently.
2436
+ void (async () => {
2437
+ try {
2438
+ await navigator.clipboard.writeText(made.url);
2439
+ showToast('Link copied to clipboard', 'ok');
2440
+ } catch {
2441
+ showToast('Couldn’t copy the link', 'warn');
2442
+ }
2443
+ })();
2444
+ return;
2445
+ }
2168
2446
  });
2169
2447
 
2170
2448
  // ── Revisions: attach a revised drawing set → queue a compose-time read (Slice 4b) ──
@@ -2470,6 +2748,15 @@
2470
2748
  try {
2471
2749
  await api(`/api/projects/${encodeURIComponent(proj.id)}/versions/${encodeURIComponent(n)}/rollback`, { method: 'POST' });
2472
2750
  proj.approvedAt = undefined; // rollback re-locks exports (the server cleared the sign-off)
2751
+ // Drop the editor's localStorage draft, or the rollback silently undoes itself. restoreSaved()
2752
+ // re-overlays that draft's members/dims/details on the editor's NEXT boot whenever dataSig()
2753
+ // still matches — and dataSig() is only sheet + segment count, which member edits never change.
2754
+ // The SSE path that normally clears it cannot help here: when History is the visible step the
2755
+ // line below leaves this iframe at about:blank, so there is no editor document listening for
2756
+ // the contract-changed broadcast. After a rollback the server contract is the truth, so a local
2757
+ // draft can only put the user's pre-rollback edits back on top of the version they restored.
2758
+ // Same origin, and the key is the one the editor builds from ?app=.
2759
+ try { localStorage.removeItem('steeltakeoff:edits:v1:' + proj.app); } catch (_) { /* blocked storage */ }
2473
2760
  showToast(`Restored v${n} as a new version — Exports re-locked; Approve to re-enable`, 'ok');
2474
2761
  // Reload the editor iframe so it shows the restored geometry (it fetched the contract on load).
2475
2762
  frames.model.dataset.loaded = '';
@@ -2759,12 +3046,44 @@
2759
3046
  // animationend handler ends the glow ~0.6s later; if a reconcile repaint (or reduced-motion, where
2760
3047
  // there is no animation) gets there first, renderLanding's full innerHTML rebuild drops `is-new`
2761
3048
  // anyway — so nothing sticks either way.
3049
+ // The card to re-glow after a repaint. The landing now paints as soon as the projects list lands
3050
+ // (~200 ms) instead of after /api/apps (~1.2 s), so the reconcile repaint arrives a third of the
3051
+ // way through the 0.6 s pulse and innerHTML rebuilding drops `is-new` mid-animation — killing the
3052
+ // confirmation glow in the very flows it was added for (rename / duplicate / archive / import).
3053
+ // renderLanding() re-applies it for this id, and the animationend handler clears it.
3054
+ let flashId = null;
3055
+ let flashTimer = null;
3056
+ // End the glow. Driven by animationend AND a timer, because under
3057
+ // `prefers-reduced-motion: reduce` app.css sets `animation:none` — animationend then NEVER fires,
3058
+ // and .is-new also carries a static box-shadow, so without the timer the highlight (and the
3059
+ // re-arming below) would stick to that card for the rest of the session. Guarded by id so a
3060
+ // second flash's arrival doesn't let the first one's handler clear it.
3061
+ function endFlash(id, el) {
3062
+ if (flashId !== id) return;
3063
+ flashId = null;
3064
+ if (flashTimer) { clearTimeout(flashTimer); flashTimer = null; }
3065
+ el.classList.remove('is-new');
3066
+ }
3067
+ function armFlash(id, el) {
3068
+ el.classList.add('is-new');
3069
+ el.addEventListener('animationend', () => endFlash(id, el), { once: true });
3070
+ if (flashTimer) clearTimeout(flashTimer);
3071
+ flashTimer = setTimeout(() => endFlash(id, el), 900); // > the 0.6s pulse; the reduced-motion path's only exit
3072
+ }
2762
3073
  function flashCard(id, opts) {
2763
3074
  const el = $landing.querySelector(`.ws-card[data-open="${escapeAttr(id)}"]`);
2764
3075
  if (!el) return;
2765
3076
  if (opts && opts.scroll) el.scrollIntoView({ block: 'nearest' });
2766
- el.classList.add('is-new');
2767
- el.addEventListener('animationend', () => el.classList.remove('is-new'), { once: true });
3077
+ flashId = id;
3078
+ armFlash(id, el);
3079
+ }
3080
+ // Re-arm the glow on the freshly-rendered card after renderLanding() replaced the DOM. A rebuilt
3081
+ // element restarts the animation on its own — it is a new node, not a re-classed one.
3082
+ function reflashCard() {
3083
+ if (!flashId) return;
3084
+ const el = $landing.querySelector(`.ws-card[data-open="${escapeAttr(flashId)}"]`);
3085
+ if (!el) { flashId = null; return; } // card is gone (archived/deleted) — drop the pending flash
3086
+ armFlash(flashId, el);
2768
3087
  }
2769
3088
 
2770
3089
  // rename/duplicate/archive on ONE project — driven by the landing-grid card ⋯ menu (the header
@@ -3024,6 +3343,6 @@
3024
3343
  if ($projPopover && !$projPopover.hidden && $projCombo && !$projCombo.contains(e.target)) closeProjCombo(false);
3025
3344
  });
3026
3345
 
3027
- window.flolessWorkspaces = { setMode, refresh: loadProjects, findActive: wsFindActive, find: wsFind, clearFind: wsClearFind };
3346
+ window.flolessWorkspaces = { setMode, refresh: loadProjects, findActive: wsFindActive, find: wsFind, clearFind: wsClearFind, openHistory: wsOpenHistory };
3028
3347
  applyMode(); // restore persisted mode immediately (matches panels.js applyView timing)
3029
3348
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.104.2",
3
+ "version": "0.105.0",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {
@@ -21,11 +21,16 @@
21
21
  "app": "node launch.mjs open",
22
22
  "app:stop": "node launch.mjs stop",
23
23
  "app:restart": "node launch.mjs restart",
24
+ "test": "node build/run-tests.mjs",
24
25
  "build": "node build/bundle.mjs",
25
26
  "build:exe": "node build/bundle.mjs && node build/make-sea.mjs",
26
27
  "verify:skills": "node build/verify-shipped-skills.mjs",
27
28
  "verify:flo": "node build/verify-flo-descriptions.mjs",
28
29
  "verify:no-title": "node build/verify-no-title.mjs",
30
+ "verify:view-modes": "node build/verify-view-modes.mjs",
31
+ "verify:gateway": "node build/verify-contract-gateway.mjs",
32
+ "verify:flo-versions": "node build/verify-flo-versions.mjs",
33
+ "verify:boundary": "node build/verify-model-boundary.mjs",
29
34
  "typecheck": "tsc --noEmit",
30
35
  "prepack": "npm run build"
31
36
  },