@floless/app 0.114.0 → 0.115.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.
@@ -206,8 +206,12 @@
206
206
  ],
207
207
  diff: true, // steel semantic diff expander
208
208
  exports: [
209
- { kind: 'bom-csv', ico: '▤', name: 'Bill of materials', fmt: 'CSV', verb: 'Export CSV', file: true, open: true },
210
- { kind: 'bom-xlsx', ico: '▦', name: 'Bill of materials', fmt: 'XLSX', verb: 'Export Excel', file: true, open: true },
209
+ // ONE card, THREE export kinds (bom-csv / bom-xlsx / bom-html). It was a card per file format
210
+ // while there were two; the report made three, and three tiles of the same bill is a grid that
211
+ // says "pick a card" when the real question is "which columns, and in what". `file:false`
212
+ // because a card fronting several kinds cannot state its status through the single-kind
213
+ // exportState path — bomCardState lists one row per file actually produced, like Render.
214
+ { kind: 'bom', ico: '▤', name: 'Bill of materials', fmt: 'CSV · XLSX · Report', verb: 'Export BOM', file: false },
211
215
  { kind: 'ifc', ico: '◈', name: 'Model', fmt: 'IFC4', verb: 'Export IFC', file: true, open: false },
212
216
  // ONE card for every CAD destination, not one per application. It was Tekla-only while
213
217
  // Tekla was the only host that could receive a model; Revit, SketchUp and Rhino now can
@@ -2377,6 +2381,10 @@
2377
2381
  function exportUrl(kind, projectId, appId) {
2378
2382
  const qs = `?project=${encodeURIComponent(projectId)}`;
2379
2383
  const base = `/api/contract/${encodeURIComponent(appId)}`;
2384
+ // The BATCH route: one request, one project lock, every picked format. Three separate requests
2385
+ // would release the lock between formats — long enough for a render to take it and leave this
2386
+ // card waiting minutes — and would let the workbook see a different approved version than the CSV.
2387
+ if (kind === 'bom') return `${base}/export-bom${qs}`;
2380
2388
  if (kind === 'bom-csv') return `${base}/export-bom/csv${qs}`;
2381
2389
  if (kind === 'bom-xlsx') return `${base}/export-bom/xlsx${qs}`;
2382
2390
  if (kind === 'ifc') return `${base}/export-ifc${qs}`;
@@ -2536,6 +2544,193 @@
2536
2544
  return options;
2537
2545
  }
2538
2546
 
2547
+ // ── The Bill of Materials card ────────────────────────────────────────────────────────────────
2548
+ // Formats cheap-first, which is also the order the server writes them in: a report that fails still
2549
+ // leaves the CSV and the workbook on disk. `meta` carries the extension AND the cost, the same shape
2550
+ // the render dialog's own options use.
2551
+ // The extension is IN the label because a checklist row has no neutral slot beside it — its status
2552
+ // slot is coloured (ready / checking / blocked) and none of those tones means "here is a hint".
2553
+ // The cost asymmetry is not repeated here; it belongs in the live footnote, which is the only place
2554
+ // that can state it for the combination actually picked.
2555
+ const BOM_FORMATS = [
2556
+ { value: 'csv', label: 'CSV' },
2557
+ { value: 'xlsx', label: 'Excel workbook (.xlsx)' },
2558
+ { value: 'html', label: 'Report (.html)' },
2559
+ ];
2560
+
2561
+ // One row per format on the card, in this fixed order — deliberately NOT newest-first like the
2562
+ // render card. All three come out of ONE click, so their timestamps are equal to the minute and
2563
+ // sorting by time only makes the order look arbitrary from one repaint to the next.
2564
+ const BOM_ROWS = [
2565
+ { kind: 'bom-csv', format: 'csv', label: 'CSV' },
2566
+ { kind: 'bom-xlsx', format: 'xlsx', label: 'Excel workbook' },
2567
+ { kind: 'bom-html', format: 'html', label: 'Report' },
2568
+ ];
2569
+
2570
+ // Mirrors the server's registry (bom-format.ts). Canonical order, never pick order: a bill is a
2571
+ // standard deliverable, and the same columns arriving in a different sequence week to week is
2572
+ // exactly what breaks an estimator's comparison. `meta` teaches the two that are new.
2573
+ // Each label is EXACTLY the header the file will carry, so the picker is a preview of the bill
2574
+ // rather than a glossary of it. What Grade and Type mean for the ROWS — that picking them
2575
+ // subdivides the bill — is the dialog's `sub`, because that is the part a label cannot say.
2576
+ const BOM_COLUMNS = [
2577
+ { value: 'profile', label: 'Profile' },
2578
+ { value: 'grade', label: 'Grade' },
2579
+ { value: 'type', label: 'Type' },
2580
+ { value: 'qty', label: 'Qty' },
2581
+ { value: 'length', label: 'Length (ft)' },
2582
+ { value: 'lbft', label: 'lb/ft' },
2583
+ { value: 'weight', label: 'Weight (lb)' },
2584
+ ];
2585
+ const BOM_DESCRIPTIVE = ['profile', 'grade', 'type'];
2586
+ const DEFAULT_BOM_FORMATS = ['csv', 'xlsx'];
2587
+ const DEFAULT_BOM_COLUMNS = ['profile', 'qty', 'length', 'lbft', 'weight'];
2588
+
2589
+ // Picks made this session, per project — the same in-memory treatment renderChoices gets, so a
2590
+ // detailer exporting a second project does not inherit the first one's columns.
2591
+ const bomChoices = new Map();
2592
+
2593
+ const splitPicks = (v) => String(v || '').split(',').map((s) => s.trim()).filter(Boolean);
2594
+
2595
+ /**
2596
+ * The refusals, in one place so the live footnote and the OK handler cannot disagree about what is
2597
+ * allowed. Each exists because the alternative is a file that looks like a bill and is not — the
2598
+ * server enforces the same three (bomColumnRefusal), because a browser is not a gate.
2599
+ */
2600
+ function bomRefusal(formats, columns) {
2601
+ if (!formats.length) return 'Pick at least one format to export.';
2602
+ if (!columns.length) return 'Pick at least one column to export.';
2603
+ // Same ORDER as the server's bomColumnRefusal, deliberately: unticking Profile breaks both this
2604
+ // and the descriptive rule, and only this message names the real conflict and both ways out —
2605
+ // and adding Profile satisfies the other rule too, where adding Grade would earn a second refusal.
2606
+ if (columns.includes('lbft') && !columns.includes('profile')) {
2607
+ return 'lb/ft is a property of the profile — pick Profile too, or drop lb/ft.';
2608
+ }
2609
+ if (!columns.some((c) => BOM_DESCRIPTIVE.includes(c))) {
2610
+ return 'Pick at least one of Profile, Grade or Type — a bill has to say what the material is.';
2611
+ }
2612
+ return null;
2613
+ }
2614
+
2615
+ /**
2616
+ * The live footnote: what this click will cost, and the one consequence the dialog cannot otherwise
2617
+ * show. Not a restatement of the picks — the trigger buttons already summarise those, and
2618
+ * renderEstimate's whole justification is saying something no static label could.
2619
+ *
2620
+ * The cost line leads because the formats are not alike: two are instant and the report compiles and
2621
+ * runs an AWARE app. No invented number — "a few seconds" is what has actually been measured until
2622
+ * someone measures it properly, and an under-promise is what makes a working export read as hung.
2623
+ */
2624
+ function bomPreview(values) {
2625
+ const formats = splitPicks(values.formats);
2626
+ const columns = splitPicks(values.columns);
2627
+ const refusal = bomRefusal(formats, columns);
2628
+ if (refusal) return refusal;
2629
+
2630
+ const instant = formats.filter((f) => f !== 'html');
2631
+ const n = formats.length;
2632
+ const files = `${n} file${n === 1 ? '' : 's'}`;
2633
+ let text;
2634
+ if (!formats.includes('html')) text = `${files}, written straight away.`;
2635
+ else if (!instant.length) text = 'One file — the report takes a few seconds to render.';
2636
+ else {
2637
+ const names = instant.map((f) => (f === 'csv' ? 'CSV' : 'Excel workbook'));
2638
+ text = `${files}. The ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} written straight away; the report takes a few seconds.`;
2639
+ }
2640
+ // Said ONLY when it can bite. The bill this button writes is the one you picked; the bill a Run
2641
+ // writes is baked into the approved lock and is always the full one, because what a locked run
2642
+ // produces must not depend on a preference living in a browser. Someone who has not narrowed
2643
+ // anything has no contradiction to be warned about, so they are not.
2644
+ const narrowed = columns.length !== DEFAULT_BOM_COLUMNS.length
2645
+ || DEFAULT_BOM_COLUMNS.some((c) => !columns.includes(c));
2646
+ return narrowed ? `${text} Running the workflow still writes the full bill.` : text;
2647
+ }
2648
+
2649
+ async function askBomOptions(projectId) {
2650
+ if (!bridge.formModal) return { formats: [...DEFAULT_BOM_FORMATS], columns: [...DEFAULT_BOM_COLUMNS] };
2651
+ const last = bomChoices.get(projectId) || {};
2652
+ const chosen = await bridge.formModal({
2653
+ title: 'Export Bill of Materials',
2654
+ // The one mechanic that is not obvious from the controls, and the reason Grade is worth picking:
2655
+ // the columns are the grouping, not just the headings.
2656
+ sub: 'Rows are grouped by the columns you pick — adding Grade or Type can split one line into several.',
2657
+ okLabel: 'Export',
2658
+ onChange: bomPreview,
2659
+ // The card repaints on the way in, which moves focus off the button, so naming it explicitly is
2660
+ // what keeps Cancel from dropping focus behind the dialog — same reasoning as the render dialog.
2661
+ returnFocusTo: $wsExports.querySelector('[data-export="bom"]'),
2662
+ returnFocusFallback: () => (current && current.id === projectId
2663
+ ? $wsExports.querySelector('[data-export="bom"]')
2664
+ : null),
2665
+ fields: [
2666
+ // `checklist compact` — the same control the CAD-destination card and the render dialog's
2667
+ // viewpoints use for a multi-pick, so the two consolidated export cards in this grid ask
2668
+ // their question the same way. Every row is visible and ticked or not, which is what a
2669
+ // column picker wants: a collapsed "5 selected" hides the very thing being chosen.
2670
+ {
2671
+ name: 'formats', label: 'Formats', type: 'checklist', compact: true,
2672
+ // Defaults to the two cards this one replaced. A consolidated card must not quietly give a
2673
+ // plain click FEWER files than before, nor surprise anyone with the slower opt-in format.
2674
+ value: (last.formats || DEFAULT_BOM_FORMATS).join(','),
2675
+ options: BOM_FORMATS,
2676
+ },
2677
+ {
2678
+ name: 'columns', label: 'Columns', type: 'checklist', compact: true,
2679
+ value: (last.columns || DEFAULT_BOM_COLUMNS).join(','),
2680
+ options: BOM_COLUMNS,
2681
+ },
2682
+ ],
2683
+ });
2684
+ if (!chosen) return null;
2685
+ const formats = splitPicks(chosen.formats);
2686
+ const columns = splitPicks(chosen.columns);
2687
+ // Refuse and say which rule — never disable OK (formModal gates only checkbox/files anyway), and
2688
+ // never silently repair the selection. Dropping lb/ft or adding Profile behind someone's back
2689
+ // changes the deliverable's shape without telling them, which is worse than asking again.
2690
+ const refusal = bomRefusal(formats, columns);
2691
+ if (refusal) { showToast(refusal, 'warn'); return null; }
2692
+ const options = { formats, columns };
2693
+ bomChoices.set(projectId, options);
2694
+ return options;
2695
+ }
2696
+
2697
+ /**
2698
+ * The BOM card's state — the same {meta, disabled, tip} shape as renderCardState, and for the same
2699
+ * reason: it fronts several export kinds, so `exportState[c.kind]` cannot describe it.
2700
+ */
2701
+ function bomCardState(approved) {
2702
+ if (!approved) return {
2703
+ meta: '<span class="e-status">Available after approval</span>',
2704
+ disabled: true,
2705
+ tip: 'Approve this version first',
2706
+ };
2707
+ // `exportState == null` means the LISTING failed, not that nothing was exported. Printing "not
2708
+ // exported yet" would be a definite negative the server never confirmed.
2709
+ if (exportState == null) {
2710
+ return { meta: '<span class="e-status">Status unavailable</span>', disabled: false, tip: '' };
2711
+ }
2712
+ const done = BOM_ROWS
2713
+ .filter((row) => exportState[row.kind] && exportState[row.kind].exportedAt)
2714
+ .map((row) => ({ ...row, exportedAt: exportState[row.kind].exportedAt }));
2715
+ if (!done.length) {
2716
+ return { meta: '<span class="e-status">not exported yet</span>', disabled: false, tip: '' };
2717
+ }
2718
+ const rows = done.map((row) =>
2719
+ `<div class="e-render-row">` +
2720
+ `<span class="e-done"><span class="chk">✓</span> ${escapeHtml(row.label)} <span class="t">${escapeHtml(hhmm(row.exportedAt))}</span></span>` +
2721
+ `<span class="e-links">` +
2722
+ `<button type="button" class="e-link" data-openfile="${escapeAttr(row.kind)}" data-tip="Open in its default app">⧉ Open</button>` +
2723
+ `<button type="button" class="e-link" data-reveal="${escapeAttr(row.kind)}" data-tip="Show the file in its folder">▤ Reveal</button>` +
2724
+ `</span>` +
2725
+ `</div>`).join('');
2726
+ // At most three rows, so this never scrolls — but it reuses the render card's themed scroller
2727
+ // verbatim rather than inventing a second way to list produced files.
2728
+ return {
2729
+ meta: `<div class="e-renders" role="group" aria-label="Exported files">${rows}</div>`,
2730
+ disabled: false, tip: '', rendered: true,
2731
+ };
2732
+ }
2733
+
2539
2734
  const receiptKey = (kind) => `${current ? current.id : ''}:${kind}`;
2540
2735
 
2541
2736
  function receiptItemText(prefix, value) {
@@ -3315,7 +3510,8 @@
3315
3510
  // below. `special` keeps the branches from growing a third arm each time a kind is added.
3316
3511
  const special = c.kind === 'send-host' ? sendHostCardState(approved)
3317
3512
  : c.kind === 'share-3d' ? shareCardState(approved)
3318
- : c.kind === 'render' ? renderCardState(approved) : null;
3513
+ : c.kind === 'render' ? renderCardState(approved)
3514
+ : c.kind === 'bom' ? bomCardState(approved) : null;
3319
3515
  if (special) {
3320
3516
  meta = special.meta;
3321
3517
  } else if (!approved) {
@@ -3339,7 +3535,11 @@
3339
3535
  // Re-labelled once a link exists, mirroring the file kinds' "Re-export" convention. Gated on the
3340
3536
  // in-memory record rather than exportState, which only ever tracks file exports.
3341
3537
  const shared = approved && c.kind === 'share-3d' && shareLinks.has(`${current.id}:share-3d`);
3342
- const rendered = approved && c.kind === 'render' && special && special.rendered;
3538
+ // `special.rendered` means "this card has already produced something", whatever card it is. It was
3539
+ // gated on `c.kind === 'render'` as well, which made the flag unreadable for any other multi-kind
3540
+ // card: the BOM card would have gone on saying "Export BOM" forever after a successful export.
3541
+ // Safe for the CAD card, which reports the same idea through its own `sent`.
3542
+ const rendered = approved && special && special.rendered;
3343
3543
  const sentSomewhere = approved && c.kind === 'send-host' && special && special.sent;
3344
3544
  const busyLabel = c.kind === 'send-host' ? sendBusyText() : c.kind === 'share-3d' ? 'Creating…'
3345
3545
  : c.kind === 'render' ? 'Rendering…' : 'Exporting…';
@@ -3356,14 +3556,22 @@
3356
3556
  // and every other project-scoped export serializes on that same key. In-process those queue
3357
3557
  // with no timeout, so a sibling card clicked meanwhile would just sit on "Exporting…" with no
3358
3558
  // explanation. Say what is happening instead of letting it hang.
3359
- const renderHolding = c.kind !== 'render' && exportBusy.has(`${current.id}:render`);
3360
- const disabled = renderHolding || (special ? special.disabled : !approved);
3559
+ //
3560
+ // A LIST rather than one kind, because `render` is no longer the only card shaped like this. The
3561
+ // BOM's Report format installs an agent if missing, then compiles and runs an AWARE app, all
3562
+ // inside the project lock; a CAD send takes that lock once per destination. Both reproduced the
3563
+ // exact hang this line exists to prevent — a sibling card clicked meanwhile sat silent.
3564
+ const HOLDS_PROJECT = ['render', 'bom', 'send-host'];
3565
+ const holder = HOLDS_PROJECT.find((k) => k !== c.kind && exportBusy.has(`${current.id}:${k}`));
3566
+ const disabled = !!holder || (special ? special.disabled : !approved);
3361
3567
  const busyTip = c.kind === 'send-host' ? sendBusyText()
3362
3568
  : c.kind === 'share-3d' ? 'Rendering the model and uploading the link'
3363
3569
  : c.kind === 'render' ? renderBusyText()
3364
3570
  : 'Export in progress';
3365
3571
  const tip = busy ? busyTip
3366
- : renderHolding ? 'Waiting for the render to finish — it holds this project while it runs'
3572
+ : holder === 'render' ? 'Waiting for the render to finish — it holds this project while it runs'
3573
+ : holder === 'bom' ? 'Waiting for the bill of materials to finish — it holds this project while it runs'
3574
+ : holder === 'send-host' ? 'Waiting for the CAD send to finish — it holds this project while it runs'
3367
3575
  : special ? special.tip : (approved ? '' : 'Approve this version first');
3368
3576
  // A button blocked by a DURABLE, card-specific reason is `aria-disabled`, never `disabled`: a
3369
3577
  // natively disabled control leaves the tab order, so a keyboard or screen-reader user can
@@ -3612,6 +3820,15 @@
3612
3820
  // The Render card is the only one that asks anything before it runs, so the options are
3613
3821
  // collected BEFORE the busy state — marking the card "Rendering…" while a dialog is still open
3614
3822
  // would be a lie about what the machine is doing.
3823
+ let bomOptions = null;
3824
+ if (kind === 'bom') {
3825
+ bomOptions = await askBomOptions(projectId);
3826
+ if (!bomOptions) return; // cancelled or refused — nothing started, so nothing to unwind
3827
+ // The dialog is awaited, so the project can move under us; everything below keys off the
3828
+ // captured ids, and bailing here keeps the request from being aimed somewhere else.
3829
+ if (!current || current.id !== projectId) return;
3830
+ }
3831
+
3615
3832
  let renderOptions = null;
3616
3833
  if (kind === 'render') {
3617
3834
  renderOptions = await askRenderOptions(projectId);
@@ -3698,10 +3915,38 @@
3698
3915
  // paint a stale intermediate state over it.
3699
3916
  let refreshing = false;
3700
3917
  try {
3701
- // Render is the only export whose POST carries a body — the options the modal collected.
3702
- const res = await api(exportUrl(kind, projectId, app), renderOptions
3703
- ? { method: 'POST', body: JSON.stringify(renderOptions), headers: { 'content-type': 'application/json' } }
3918
+ // Render and the BOM are the exports whose POST carries a body — the options their modal collected.
3919
+ const body = renderOptions || bomOptions;
3920
+ const res = await api(exportUrl(kind, projectId, app), body
3921
+ ? { method: 'POST', body: JSON.stringify(body), headers: { 'content-type': 'application/json' } }
3704
3922
  : { method: 'POST' });
3923
+ if (kind === 'bom') {
3924
+ // The batch answers per format. A 200 here means SOMETHING landed, not that everything did —
3925
+ // so the toast names what failed rather than letting a green tick stand for a partial run, and
3926
+ // the files that did land are already on the card.
3927
+ const results = Array.isArray(res.results) ? res.results : [];
3928
+ const ok = results.filter((r) => r && r.ok);
3929
+ const failed = results.filter((r) => r && !r.ok);
3930
+ const nameOf = (f) => (BOM_FORMATS.find((x) => x.value === f) || {}).label || f;
3931
+ if (failed.length) {
3932
+ showToast(
3933
+ `${ok.length} of ${results.length} exported — ${failed.map((r) => nameOf(r.format)).join(', ')} failed: `
3934
+ + (failed[0].error || 'no reason given'),
3935
+ 'warn');
3936
+ } else {
3937
+ showToast(`Exported — ${ok.map((r) => nameOf(r.format)).join(', ')}`, 'ok');
3938
+ }
3939
+ // Per FORMAT, so the analytics keep the granularity the two separate cards used to give.
3940
+ for (const r of ok) track('workspace_export', { app, kind: `bom-${r.format}` });
3941
+ // Set BEFORE handing off, exactly as the shared success path does: the `finally` below runs
3942
+ // while this refresh is still in flight and would otherwise paint the pre-refresh state over
3943
+ // it — the card reading "not exported yet" for a second after a successful export.
3944
+ refreshing = true;
3945
+ return renderExports().catch((refreshErr) => {
3946
+ console.warn('exports refresh failed after a BOM export', refreshErr);
3947
+ if (current && current.id === projectId) paintExports(current.approvedAt);
3948
+ });
3949
+ }
3705
3950
  track('workspace_export', { app, kind }); // a successful export/bake (e.g. { app:'vectorize', kind:'svg' })
3706
3951
  if (res.counts) exportReceipts.set(`${projectId}:${kind}`, {
3707
3952
  counts: res.counts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.114.0",
3
+ "version": "0.115.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": {