@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.
@@ -378,17 +378,37 @@
378
378
  // image/*"> can't carry a custom label — Chromium shows it as generic "Custom Files").
379
379
  // Falls back to the hidden <input type=file> on engines without the API. Returns []
380
380
  // on cancel; never throws (AbortError from a user cancel is swallowed).
381
+ // Chrome refuses a file chooser while another one is already open — as a NotAllowedError, or as an AbortError
382
+ // that looks like a cancel — and a chooser left open behind another window is easy to miss, so the next click
383
+ // seemed to do nothing. NotAllowedError is never a choice. A person cannot cancel a dialog in under half a
384
+ // second, so an instant AbortError, or one asked for while the page had no focus, is the browser refusing too.
385
+ // A real cancel stays silent; a refusal says what to do. Returns true when the error was one of these.
386
+ const pageHasFocus = () => typeof document.hasFocus !== 'function' || document.hasFocus();
387
+ const CHOOSER_HUMAN_CANCEL_MS = 500;
388
+ let dismissChooserHint = null;
389
+ function chooserEndedWithoutChoice(err, wasFocused, startedAt) {
390
+ if (!err) return false;
391
+ const refused = err.name === 'NotAllowedError'
392
+ || (err.name === 'AbortError' && (!wasFocused || Date.now() - startedAt < CHOOSER_HUMAN_CANCEL_MS));
393
+ if (refused) {
394
+ // The cause is a window the person cannot see, so the hint stays until dismissed, and a repeat replaces it.
395
+ if (typeof dismissChooserHint === 'function') dismissChooserHint(true);
396
+ dismissChooserHint = showToast('The file chooser did not open. One may already be open behind another window. Close it, then click again.', 'warn', { persistent: true });
397
+ }
398
+ return refused || err.name === 'AbortError';
399
+ }
381
400
  const DRAWING_FILE_TYPES = [{
382
401
  description: 'PDF or image',
383
402
  accept: { 'application/pdf': ['.pdf'], 'image/*': ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp'] },
384
403
  }];
385
404
  async function pickDrawingFiles(fallbackInput) {
386
405
  if (window.showOpenFilePicker) {
406
+ const wasFocused = pageHasFocus(), startedAt = Date.now();
387
407
  try {
388
408
  const handles = await window.showOpenFilePicker({ multiple: true, types: DRAWING_FILE_TYPES });
389
409
  return Promise.all(handles.map((h) => h.getFile()));
390
410
  } catch (err) {
391
- if (err && err.name === 'AbortError') return []; // user cancelled — not an error
411
+ if (chooserEndedWithoutChoice(err, wasFocused, startedAt)) return []; // a cancel is silent; a refusal said so
392
412
  throw err;
393
413
  }
394
414
  }
@@ -415,11 +435,12 @@
415
435
  const ZIP_FILE_TYPES = [{ description: 'Project archive (.zip)', accept: { 'application/zip': ['.zip'] } }];
416
436
  async function pickZipFile(fallbackInput) {
417
437
  if (window.showOpenFilePicker) {
438
+ const wasFocused = pageHasFocus(), startedAt = Date.now();
418
439
  try {
419
440
  const [handle] = await window.showOpenFilePicker({ multiple: false, types: ZIP_FILE_TYPES });
420
441
  return handle ? handle.getFile() : null;
421
442
  } catch (err) {
422
- if (err && err.name === 'AbortError') return null; // user cancelled — not an error
443
+ if (chooserEndedWithoutChoice(err, wasFocused, startedAt)) return null; // a cancel is silent; a refusal said so
423
444
  throw err;
424
445
  }
425
446
  }
@@ -439,11 +460,12 @@
439
460
  const RVT_FILE_TYPES = [{ description: 'Revit model (.rvt)', accept: { 'application/x-rvt': ['.rvt'] } }];
440
461
  async function pickRvtFile(fallbackInput) {
441
462
  if (window.showOpenFilePicker) {
463
+ const wasFocused = pageHasFocus(), startedAt = Date.now();
442
464
  try {
443
465
  const [handle] = await window.showOpenFilePicker({ multiple: false, types: RVT_FILE_TYPES });
444
466
  return handle ? handle.getFile() : null;
445
467
  } catch (err) {
446
- if (err && err.name === 'AbortError') return null;
468
+ if (chooserEndedWithoutChoice(err, wasFocused, startedAt)) return null;
447
469
  throw err;
448
470
  }
449
471
  }
@@ -500,8 +522,9 @@
500
522
 
501
523
  async function pickTeklaFolder(fallbackInput) {
502
524
  if (window.showDirectoryPicker) {
525
+ const wasFocused = pageHasFocus(), startedAt = Date.now();
503
526
  try { return await filesFromDirectoryHandle(await window.showDirectoryPicker({ mode: 'read' })); }
504
- catch (error) { if (error?.name === 'AbortError') return null; throw error; }
527
+ catch (error) { if (chooserEndedWithoutChoice(error, wasFocused, startedAt)) return null; throw error; }
505
528
  }
506
529
  return new Promise((resolve, reject) => {
507
530
  const cleanup = () => { fallbackInput.removeEventListener('change', onChange); fallbackInput.removeEventListener('cancel', onCancel); };
@@ -520,15 +543,18 @@
520
543
  });
521
544
  }
522
545
 
523
- async function pickTeklaZip(fallbackInput) {
524
- const file = await pickZipFile(fallbackInput);
525
- if (!file) return null;
546
+ // One ZIP of a Tekla model as a source — shared by the ZIP picker and a ZIP dropped on the card.
547
+ function teklaZipSource(file) {
526
548
  if (!/\.zip$/i.test(file.name) || file.size > 1024 * 1024 * 1024) throw new Error('Choose one Tekla model ZIP up to 1 GB.');
527
549
  return { label: file.name, kind: 'zip', entries: [{ path: file.name, file }] };
528
550
  }
551
+ async function pickTeklaZip(fallbackInput) {
552
+ const file = await pickZipFile(fallbackInput);
553
+ return file ? teklaZipSource(file) : null;
554
+ }
529
555
 
530
556
  // Single-image picker for Add/Replace thumbnail — same File System Access preference + hidden-input
531
- // fallback as the two above. Returns null on cancel; never throws.
557
+ // fallback as pickDrawingFiles and pickZipFile. Returns null on cancel; rethrows anything but a cancel.
532
558
  const THUMB_FILE_TYPES = [{
533
559
  description: 'Image',
534
560
  accept: { 'image/*': ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp'] },
@@ -671,8 +697,8 @@
671
697
 
672
698
  const LS_MODE = 'floless:mode';
673
699
  // Per-app Workspaces presentation. The flag (floless.workspace, surfaced on /api/apps) says WHICH
674
- // apps are workspaces; this map says HOW to render each (presentation is ours — spec §3.2). Two
675
- // first-party apps today; promote to a .flo-declared descriptor when a user-authored one appears.
700
+ // apps are workspaces; this map says HOW to render each (presentation is ours — spec §3.2). All
701
+ // first-party today; promote to a .flo-declared descriptor when a user-authored one appears.
676
702
  // NB: both apps keep the SAME data-step keys (drawings/model/exports/history) so setStep() and the
677
703
  // frame slots are unchanged — only the first two LABELS and which HTML each frame loads differ.
678
704
  //
@@ -680,8 +706,17 @@
680
706
  // "✓ exported HH:MM" line + ⧉ Open / ▤ Reveal); `open:false` (IFC) = reveal-only (no OS default app
681
707
  // for a .ifc). Tekla is an ACTION (host mutation, no file). `kind` matches the server's export route
682
708
  // + listing (projectExportFiles). renderExports()/exportUrl() read wsApp().exports — never a global.
709
+ //
710
+ // `cardIcon`: the create card's mark — the INNER markup of a 24×24 outline drawing, which
711
+ // workspaceCreateCardHtml wraps in an <svg> and inserts unescaped (authored here, never user data).
712
+ // Each one says what the card makes, never whose product it reads: no vendor logo for Revit/Tekla.
713
+ // On a create action, `dropHint` is the line telling the person the card also takes a dropped file
714
+ // (shown only for a kind workspaceCreateCardHtml treats as a dropzone); `dropWarn` is what a READY
715
+ // card that takes no file says when one is dropped on it. Locked and setting-up cards answer with
716
+ // their own sentence instead (cardDropWarning).
683
717
  const WORKSPACE_APPS = {
684
718
  'steel-model': {
719
+ cardIcon: '<path d="M3 8.5h10v3H9.5v6H13v3H3v-3h3.5v-6H3z"/><path d="M3 8.5 11 3.5h10l-8 5"/><path d="M21 3.5v3l-8 5"/><path d="M17.5 8.7v3.8"/><path d="M9.5 17.5l8-5H21l-8 5"/><path d="M21 12.5v3l-8 5"/>', // a 3D I-beam
685
720
  displayName: 'Steel model',
686
721
  projectCapability: 'review, detail, export',
687
722
  createActions: [
@@ -691,6 +726,7 @@
691
726
  capability: 'PDF or image → 3D steel model',
692
727
  sub: 'Turn steel drawings into a 3D model you can review and export.',
693
728
  label: 'Pick drawings',
729
+ dropHint: 'Click or drop drawings',
694
730
  },
695
731
  ],
696
732
  editor: '/steel-editor.html',
@@ -729,6 +765,7 @@
729
765
  ],
730
766
  },
731
767
  vectorize: {
768
+ cardIcon: '<path d="M5 16C8 6 16 6 19 16"/><rect x="3.25" y="16" width="3.5" height="3.5" rx=".5"/><rect x="17.25" y="16" width="3.5" height="3.5" rx=".5"/><rect x="10.5" y="7" width="3" height="3" rx=".5"/><path d="M6.5 8.5h4M13.5 8.5h4"/><circle cx="5" cy="8.5" r="1.5"/><circle cx="19" cy="8.5" r="1.5"/>', // a curve with anchors and handles
732
769
  displayName: 'Trace',
733
770
  projectCapability: 'editable 2D drawing',
734
771
  docGuide: true,
@@ -739,6 +776,7 @@
739
776
  capability: 'Drawing → editable shapes',
740
777
  sub: 'Turn one drawing into editable lines and shapes.',
741
778
  label: 'Pick drawing',
779
+ dropHint: 'Click or drop a drawing',
742
780
  },
743
781
  ],
744
782
  editor: '/vector-editor.html',
@@ -760,7 +798,7 @@
760
798
  // participates in first-paint fallback: /api/apps must positively report the canonical
761
799
  // installer-owned workflow plus its coarse access state before this card appears.
762
800
  serverAuthorizedOnly: true,
763
- cardIcon: 'R',
801
+ cardIcon: '<path d="M12 3 20 7 12 11 4 7z"/><path d="M4 7v10l8 4 8-4V7"/><path d="M12 11v10"/><path d="M4 10.3l8 4 8-4M4 13.7l8 4 8-4"/>', // a building model, floor by floor
764
802
  displayName: 'Revit Parser',
765
803
  projectCapability: 'read-only 3D model',
766
804
  readOnlyLabel: 'Read-only',
@@ -770,6 +808,7 @@
770
808
  capability: 'Read-only 3D model',
771
809
  sub: 'Open an RVT without Revit. Inspect its hierarchy and properties—the source RVT is never changed.',
772
810
  label: 'Choose RVT for Revit Parser',
811
+ dropHint: 'Click or drop an .rvt',
773
812
  }],
774
813
  editor: '/revit-editor.html',
775
814
  filter: null,
@@ -786,7 +825,7 @@
786
825
  // Tekla is a family entitlement; this descriptor names only the read-only parser module so
787
826
  // future Tekla modules can have their own workflows and product language.
788
827
  serverAuthorizedOnly: true,
789
- cardIcon: 'T',
828
+ cardIcon: '<path d="M5 20V4M19 20V4M5 4h14M5 12h14"/><path d="M5 12l14 8M19 12 5 20"/><path d="M3 20h4M17 20h4"/>', // a braced steel frame
790
829
  displayName: 'Tekla Parser',
791
830
  projectCapability: 'read-only 3D model',
792
831
  readOnlyLabel: 'Read-only',
@@ -794,8 +833,9 @@
794
833
  kind: 'tekla-source',
795
834
  headline: 'Tekla Parser',
796
835
  capability: 'Read-only 3D model',
797
- sub: 'Open a Tekla model folder or ZIP as a reviewable 3D model. Inspect its hierarchy and properties—the source model is never changed.',
836
+ sub: 'Open a Tekla model as a reviewable 3D model. Inspect its hierarchy and properties—the source model is never changed.',
798
837
  label: 'Choose Tekla model…',
838
+ dropHint: 'Click or drop a folder or .zip',
799
839
  }],
800
840
  editor: '/tekla-editor.html',
801
841
  filter: null,
@@ -849,7 +889,7 @@
849
889
  // it opens straight into its own editor frame, never the read-only source chrome. Every branch
850
890
  // that means "Revit or Tekla" therefore says so (isModelSourceProject), not serverAuthorizedOnly.
851
891
  serverAuthorizedOnly: true,
852
- cardIcon: 'D', // R = Revit, T = Tekla, D = Drawing Checker
892
+ cardIcon: '<rect x="2.5" y="4.5" width="19" height="15" rx="1.5"/><path d="M15 19.5v-4h6.5"/><path d="m6.5 11 2.5 2.5 5-5"/>', // a drawing sheet, checked
853
893
  displayName: 'Drawing Checker',
854
894
  projectCapability: 'checks shop drawings',
855
895
  createActions: [{
@@ -858,6 +898,8 @@
858
898
  capability: 'Checks shop drawings',
859
899
  sub: 'Make a profile for one client from drawings you already trust.',
860
900
  label: 'New client profile…',
901
+ // Takes no file, but a file dropped on it still gets an answer rather than nothing.
902
+ dropWarn: 'Drawing Checker starts from a client profile, not a file, so nothing was uploaded. Click the card to make the profile, then add reference drawings on its page.',
861
903
  }],
862
904
  editor: '/drawing-check-editor.html',
863
905
  filter: null,
@@ -974,6 +1016,7 @@
974
1016
  byRoot.get(root).push(a.id);
975
1017
  }
976
1018
  const capabilityByRoot = new Map();
1019
+ const setupChoiceByRoot = new Set();
977
1020
  // The server decides when a "Needs setup" card has a remedy the person can act on (#1965 review);
978
1021
  // the card only renders that sentence, and only on the state it was written for.
979
1022
  const remedyByRoot = new Map();
@@ -983,6 +1026,7 @@
983
1026
  || WORKSPACE_APPS[capability.templateId]?.serverAuthorizedOnly !== true) continue;
984
1027
  const known = ['ready', 'access-required', 'account-selection-required', 'setup-provisioning', 'setup-unavailable', 'setup-integrity-failure', 'setup-repair-required', 'check-unavailable'];
985
1028
  capabilityByRoot.set(capability.templateId, known.includes(capability.status) ? capability.status : 'check-unavailable');
1029
+ if (capability.setupChoice === true && ['tekla-parser', 'revit-model'].includes(capability.templateId)) setupChoiceByRoot.add(capability.templateId);
986
1030
  if (capability.status === 'setup-unavailable' && typeof capability.setupRemedy === 'string' && capability.setupRemedy.trim()) {
987
1031
  remedyByRoot.set(capability.templateId, capability.setupRemedy.trim());
988
1032
  }
@@ -1014,6 +1058,7 @@
1014
1058
  templateId: root,
1015
1059
  ambiguous: WORKSPACE_APPS[root]?.serverAuthorizedOnly === true ? false : ids.length > 1,
1016
1060
  ...(capabilityStatus ? { capabilityStatus } : {}),
1061
+ ...(setupChoiceByRoot.has(root) ? { setupChoice: true } : {}),
1017
1062
  ...(setupRemedy ? { setupRemedy } : {}),
1018
1063
  ...(missingCoreRoots.has(root) ? { missing: true } : {}),
1019
1064
  };
@@ -1827,6 +1872,7 @@
1827
1872
  // app.js owns the app-wide root selector; repaint only the neutral landing when its remembered
1828
1873
  // availability/path changes. An open project is reconciled through projects-changed instead.
1829
1874
  window.addEventListener('floless:workspace-root-state', () => {
1875
+ syncProjectGroupSearchRoot();
1830
1876
  if (mode === 'workspaces' && !current) renderLanding();
1831
1877
  });
1832
1878
 
@@ -2109,8 +2155,8 @@
2109
2155
  function workspaceCreateEntries(entries) {
2110
2156
  // Create affordances stay docked at the top, separate from existing projects. Cards come out in
2111
2157
  // descriptor order, per workflow. (A sort used to push the kind:'current' card last because it
2112
- // started from a different mode; that card is gone — #625 — and every remaining action starts
2113
- // from a drawing, so declaration order IS the intended order.)
2158
+ // started from a different mode; that card is gone — #625 — so declaration order IS the intended
2159
+ // order.)
2114
2160
  return entries.flatMap((entry) => {
2115
2161
  const d = WORKSPACE_APPS[entry.templateId];
2116
2162
  const actions = d && Array.isArray(d.createActions) ? d.createActions : [];
@@ -2120,6 +2166,9 @@
2120
2166
 
2121
2167
  function workspaceCreateCardHtml(entry, action) {
2122
2168
  const descriptor = WORKSPACE_APPS[entry.templateId];
2169
+ // The descriptor's own drawing when it has one (see `cardIcon` on WORKSPACE_APPS), else `fallback`.
2170
+ const seedIcon = (fallback) => `<span class="ws-seed-icon" aria-hidden="true">${descriptor?.cardIcon
2171
+ ? `<svg viewBox="0 0 24 24" focusable="false">${descriptor.cardIcon}</svg>` : fallback}</span>`;
2123
2172
  if (entry.missing === true) {
2124
2173
  const descriptionId = `ws-${entry.templateId}-missing`;
2125
2174
  const buttonStart = entry.templateId === 'vectorize'
@@ -2127,7 +2176,8 @@
2127
2176
  : `<button type="button" class="ws-seed ws-seed-remedy" data-command-id="shell.project-steel-missing-workflow" `;
2128
2177
  return buttonStart +
2129
2178
  `aria-label="${escapeAttr(`${action.headline} needs setup — why unavailable`)}" aria-describedby="${escapeAttr(descriptionId)}" ` +
2130
- `data-seed-app="${escapeAttr(entry.appId)}" data-seed-template="${escapeAttr(entry.templateId)}" data-seed-action="${escapeAttr(action.kind)}">` +
2179
+ `data-seed-app="${escapeAttr(entry.appId)}" data-seed-template="${escapeAttr(entry.templateId)}" data-seed-action="${escapeAttr(action.kind)}" ` +
2180
+ `data-drop-warn="${escapeAttr(`Nothing was opened. ${missingWorkspaceWorkflowMessage(entry.templateId)}`)}">` +
2131
2181
  `<span class="ws-seed-icon" aria-hidden="true">!</span>` +
2132
2182
  `<span class="ws-seed-headline">${escapeHtml(action.headline)}</span>` +
2133
2183
  `<span class="ws-seed-capability ws-seed-state">Needs setup</span>` +
@@ -2163,10 +2213,15 @@
2163
2213
  },
2164
2214
  };
2165
2215
  const states = descriptor.accessCopy || revitStates;
2166
- const state = states[entry.capabilityStatus] || states['check-unavailable'];
2216
+ const state = { ...(states[entry.capabilityStatus] || states['check-unavailable']) };
2217
+ if (entry.setupChoice === true) {
2218
+ state.body = `FloLess couldn’t verify the current ${descriptor.displayName}. Review the choices for keeping its files and setting up a fresh copy.`;
2219
+ state.action = 'Review setup choices';
2220
+ state.aria = `${descriptor.displayName} needs a setup choice — review choices`;
2221
+ }
2167
2222
  // A remedy the server wrote for this "Needs setup" replaces "setup didn’t finish"; the button
2168
2223
  // still re-runs setup, so the person can check again once they have fixed it.
2169
- const body = entry.capabilityStatus === 'setup-unavailable' && entry.setupRemedy ? entry.setupRemedy : state.body;
2224
+ const body = entry.setupChoice !== true && entry.capabilityStatus === 'setup-unavailable' && entry.setupRemedy ? entry.setupRemedy : state.body;
2170
2225
  const descriptionId = `ws-${entry.templateId}-${entry.capabilityStatus || 'check-unavailable'}`;
2171
2226
  const actionable = !!state.action;
2172
2227
  const provisioning = entry.capabilityStatus === 'setup-provisioning';
@@ -2190,12 +2245,14 @@
2190
2245
  return `<${actionable ? 'button type="button"' : 'div'} class="ws-seed ws-seed-remedy" ` +
2191
2246
  `aria-label="${escapeAttr(state.aria)}" aria-describedby="${escapeAttr(descriptionId)}" ` +
2192
2247
  (provisioning ? 'aria-busy="true" ' : '') +
2193
- (actionable ? entry.templateId === 'revit-model'
2248
+ (actionable ? entry.setupChoice === true
2249
+ ? `data-command-id="shell.parser-review-setup#${escapeAttr(entry.templateId)}" data-command-instance-label="${escapeAttr(descriptor.displayName)}" data-parser-setup="${escapeAttr(entry.templateId)}"`
2250
+ : entry.templateId === 'revit-model'
2194
2251
  ? `${revitCommand} data-revit-remedy="${remedyState}"`
2195
2252
  : entry.templateId === 'drawing-check'
2196
2253
  ? `${drawingCheckCommand} data-module-remedy="drawing-check" data-module-remedy-state="${remedyState}"`
2197
2254
  : `${teklaCommand} data-module-remedy="tekla-parser" data-module-remedy-state="${remedyState}"` : '') + `>` +
2198
- `<span class="ws-seed-icon" aria-hidden="true">${escapeHtml(descriptor.cardIcon || '!')}</span>` +
2255
+ seedIcon('!') +
2199
2256
  `<span class="ws-seed-headline">${escapeHtml(descriptor.displayName)}</span>` +
2200
2257
  (descriptor.readOnlyLabel ? `<span class="ws-seed-readonly">${escapeHtml(descriptor.readOnlyLabel)}</span>` : '') +
2201
2258
  `<span class="ws-seed-capability ws-seed-state">${escapeHtml(state.status)}</span>` +
@@ -2203,8 +2260,9 @@
2203
2260
  (state.action ? `<span class="ws-seed-action">${escapeHtml(state.action)} →</span>` : '') +
2204
2261
  `</${actionable ? 'button' : 'div'}>`;
2205
2262
  }
2206
- const acceptsDrop = action.kind === 'drawing' || action.kind === 'rvt';
2263
+ const acceptsDrop = action.kind === 'drawing' || action.kind === 'rvt' || action.kind === 'tekla-source';
2207
2264
  const createCommand = action.kind === 'tekla-source' ? 'data-command-id="shell.project-create-tekla-read" '
2265
+ : action.kind === 'rvt' ? 'data-command-id="shell.project-create-revit-read" '
2208
2266
  : action.kind === 'drawing-check-profile' ? 'data-command-id="shell.project-create-drawing-check-profile" '
2209
2267
  : action.kind !== 'drawing' ? ''
2210
2268
  : entry.templateId === 'steel-model' ? 'data-command-id="shell.project-create-steel-from-drawings" '
@@ -2220,13 +2278,17 @@
2220
2278
  createCommand +
2221
2279
  (action.tip ? `data-tip="${escapeAttr(action.tip)}" ` : '') +
2222
2280
  `data-seed-app="${escapeAttr(entry.appId)}" data-seed-template="${escapeAttr(entry.templateId)}" data-seed-action="${escapeAttr(action.kind)}"` +
2223
- (acceptsDrop ? ` data-seed-drop="${escapeAttr(entry.appId)}" data-seed-drop-kind="${escapeAttr(action.kind)}"` : '') +
2281
+ (acceptsDrop ? ` data-seed-drop="${escapeAttr(entry.appId)}" data-seed-drop-kind="${escapeAttr(action.kind)}"`
2282
+ : ` data-drop-warn="${escapeAttr(action.dropWarn || `Nothing was opened. ${action.headline} doesn’t take a dropped file; click the card to start.`)}"`) +
2224
2283
  `>` +
2225
- `<span class="ws-seed-icon" aria-hidden="true">${escapeHtml(descriptor?.cardIcon || '+')}</span>` +
2284
+ seedIcon('+') +
2226
2285
  `<span class="ws-seed-headline">${escapeHtml(action.headline)}</span>` +
2227
2286
  (descriptor?.readOnlyLabel ? `<span class="ws-seed-readonly">${escapeHtml(descriptor.readOnlyLabel)}</span>` : '') +
2228
2287
  (action.capability ? `<span class="ws-seed-capability">${escapeHtml(action.capability)}</span>` : '') +
2229
2288
  `<span class="ws-seed-sub">${escapeHtml(action.sub)}</span>` +
2289
+ // Kept out of the accessible name (aria-hidden for good measure): the aria-label names the
2290
+ // click route, which everyone has; "or drop" names a pointer-only one.
2291
+ (acceptsDrop && action.dropHint ? `<span class="ws-seed-hint" aria-hidden="true">${escapeHtml(action.dropHint)}</span>` : '') +
2230
2292
  (target
2231
2293
  ? `<span class="ws-seed-target" data-tip="You have more than one of these workflows installed.\nThis card creates on:\n${escapeAttr(target)}">On ${escapeHtml(target)}</span>`
2232
2294
  : '') +
@@ -2295,7 +2357,81 @@
2295
2357
  if (hadFocus && card) card.focus({ focusVisible: true, preventScroll: true });
2296
2358
  }
2297
2359
 
2360
+ /** Keep a renamed workflow with its original module; preserve the server's order within each
2361
+ * module. Built-in modules follow the descriptor order, with custom workflows after them. */
2362
+ function workspaceProjectGroups(list) {
2363
+ const groups = new Map();
2364
+ for (const project of list) {
2365
+ const key = project.templateId || project.app || '';
2366
+ if (!groups.has(key)) groups.set(key, {
2367
+ key, label: projectAppName(project) || 'Other projects', projects: [],
2368
+ });
2369
+ groups.get(key).projects.push(project);
2370
+ }
2371
+ const ordered = [];
2372
+ for (const key of Object.keys(WORKSPACE_APPS)) {
2373
+ if (groups.has(key)) { ordered.push(groups.get(key)); groups.delete(key); }
2374
+ }
2375
+ return ordered.concat([...groups.values()]);
2376
+ }
2377
+
2378
+ // Browser display preferences are scoped to the actual registered directory identity.
2379
+ const PROJECT_GROUP_PREF = 'floless:project-groups:v1:';
2380
+ const projectGroupSearchOverrides = new Map();
2381
+ const projectGroupMemory = new Map();
2382
+ let projectGroupSearchRootId = null;
2383
+ function projectGroupRootId() { return window.flolessWorkspaceRoot?.current()?.root?.rootId || ''; }
2384
+ function syncProjectGroupSearchRoot() {
2385
+ const rootId = projectGroupRootId();
2386
+ if (rootId !== projectGroupSearchRootId) {
2387
+ projectGroupSearchOverrides.clear();
2388
+ projectGroupSearchRootId = rootId;
2389
+ }
2390
+ }
2391
+ function projectGroupExpanded(key) {
2392
+ const rootId = projectGroupRootId();
2393
+ const memory = projectGroupMemory.get(rootId);
2394
+ if (memory?.has(key)) return memory.get(key);
2395
+ if (!rootId) return true;
2396
+ try {
2397
+ const saved = JSON.parse(localStorage.getItem(PROJECT_GROUP_PREF + encodeURIComponent(rootId)) || '{}');
2398
+ return !(saved && Object.prototype.hasOwnProperty.call(saved, key) && saved[key] === false);
2399
+ } catch { return true; }
2400
+ }
2401
+ function saveProjectGroupExpanded(key, expanded) {
2402
+ const rootId = projectGroupRootId();
2403
+ if (!projectGroupMemory.has(rootId)) projectGroupMemory.set(rootId, new Map());
2404
+ projectGroupMemory.get(rootId).set(key, expanded);
2405
+ if (!rootId) return;
2406
+ try {
2407
+ let parsed;
2408
+ try { parsed = JSON.parse(localStorage.getItem(PROJECT_GROUP_PREF + encodeURIComponent(rootId)) || '{}'); } catch { parsed = null; }
2409
+ const saved = Object.assign(Object.create(null), parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {});
2410
+ saved[key] = expanded;
2411
+ localStorage.setItem(PROJECT_GROUP_PREF + encodeURIComponent(rootId), JSON.stringify(saved));
2412
+ } catch { /* keep the choice on this page when browser storage is blocked */ }
2413
+ }
2414
+ function showProjectGroup(section, expanded) {
2415
+ const button = section.querySelector('[data-project-group-toggle]');
2416
+ section.querySelector('.ws-grid').hidden = !expanded;
2417
+ button.setAttribute('aria-expanded', String(expanded));
2418
+ button.setAttribute('data-tip', (expanded ? 'Collapse ' : 'Expand ') + button.dataset.commandInstanceLabel);
2419
+ if (document.activeElement === button) window.Instructor?.refreshCarrier(button);
2420
+ }
2421
+
2422
+ // An explicit success must reveal its project; search-only choices remain temporary.
2423
+ function revealProjectGroup(card) {
2424
+ const section = card.closest('.ws-project-section');
2425
+ if (!section?.querySelector('.ws-grid')?.hidden) return;
2426
+ const key = section.dataset.module;
2427
+ if (landingQuery.trim()) projectGroupSearchOverrides.set(key, true);
2428
+ else saveProjectGroupExpanded(key, true);
2429
+ showProjectGroup(section, true);
2430
+ tipTruncatedNames();
2431
+ }
2432
+
2298
2433
  function renderLanding() {
2434
+ syncProjectGroupSearchRoot();
2299
2435
  const rootState = window.flolessWorkspaceRoot && window.flolessWorkspaceRoot.current();
2300
2436
  const rootPath = rootState && rootState.root && rootState.root.path;
2301
2437
  const rootUnavailable = !!rootState && rootState.available === false;
@@ -2323,8 +2459,15 @@
2323
2459
  }
2324
2460
  html += `</div>`;
2325
2461
  }
2326
- html += `<div class="ws-grid">`;
2327
- for (const p of projects) {
2462
+ const projectGroups = projects.length ? workspaceProjectGroups(projects) : [];
2463
+ for (const [groupIndex, group] of projectGroups.entries()) {
2464
+ const groupGridId = `ws-project-group-grid-${groupIndex}`;
2465
+ const expanded = landingQuery.trim() ? (projectGroupSearchOverrides.get(group.key) ?? true) : projectGroupExpanded(group.key);
2466
+ html += `<section class="ws-project-section" data-module="${escapeAttr(group.key)}">` +
2467
+ `<h3 class="ws-project-heading"><button type="button" class="ws-project-group-toggle" data-project-group-toggle="${escapeAttr(group.key)}" data-command-id="shell.project-group-toggle#${escapeAttr(group.key)}" data-command-instance-label="${escapeAttr(group.label)}" aria-controls="${groupGridId}" aria-expanded="${expanded}" data-tip="${escapeAttr((expanded ? 'Collapse ' : 'Expand ') + group.label)}"><span class="ws-project-chevron" aria-hidden="true">›</span><span class="ws-project-group-label">${escapeHtml(group.label)}</span> ` +
2468
+ `<span class="ws-project-count">${group.projects.length} ${group.projects.length === 1 ? 'project' : 'projects'}</span></button></h3>` +
2469
+ `<div class="ws-grid" id="${groupGridId}"${expanded ? '' : ' hidden'}>`;
2470
+ for (const p of group.projects) {
2328
2471
  const d = wsDescOf(p);
2329
2472
  const displayApp = projectAppName(p);
2330
2473
  const projectCapability = d && d.projectCapability ? d.projectCapability : '';
@@ -2351,7 +2494,8 @@
2351
2494
  `<button type="button" class="ws-kebab" data-kebab="${escapeAttr(p.id)}" aria-label="Project actions" data-tip="${p.importedMidSave ? 'Rename · Thumbnail · Mark as checked · Duplicate · Export · Archive' : 'Rename · Thumbnail · Duplicate · Export · Archive'}">⋯</button>` +
2352
2495
  `</span></div>`;
2353
2496
  }
2354
- html += `</div>`;
2497
+ html += `</div></section>`;
2498
+ }
2355
2499
  // The search's no-match message. Always rendered (empty) beside a search box, and filled in by
2356
2500
  // applyLandingSearch(): a live region inserted with its text already inside is announced unreliably.
2357
2501
  if (projects.length) html += `<div class="ws-empty-note ws-search-empty" id="ws-search-empty" role="status" aria-live="polite"></div>`;
@@ -2370,29 +2514,16 @@
2370
2514
  + (guess ? `${escapeHtml(guess)} ` : 'FloLess could not read the Workspace directory. ')
2371
2515
  + ` <button type="button" id="ws-retry-projects">↻ Try again</button></div>`;
2372
2516
  } else {
2373
- // First-run onboarding (#598). Workflows mode greets a newcomer with a real card and a route
2374
- // into the guided tour; landing HERE first (a direct link, or Workflows already has apps
2375
- // installed so its card never shows) used to be one dim line and no route at all.
2376
- //
2377
- // Deliberately NOT the Workflows card's shape. The create cards are already on screen right
2378
- // above this, and they are the actual first action — a second bordered, accent-filled "start
2379
- // here" panel under them would put two accent affordances in a staring contest and invert the
2380
- // hierarchy. So: the same plain note, one added sentence, and the tour as a QUIET text link
2381
- // (the .onb-build-btn tier, never the filled .onb-tour-btn one).
2382
- //
2383
- // The added sentence says what a project IS, because that is the one thing a newcomer here
2384
- // cannot infer — not "no Run here", which .ws-sub already states unconditionally two lines up.
2517
+ // First-run onboarding (#598, #2046). The create cards above are the actual first action, so the way to the
2518
+ // Guide is a QUIET text link (the .onb-build-btn tier, never the filled .onb-tour-btn one), and the added
2519
+ // sentence says what a project IS — the one thing a newcomer here cannot infer.
2385
2520
  const note = 'No projects yet — start one from the cards above, or Import project to restore an exported .zip.';
2386
2521
  const what = 'A project is an approved, running copy of a workflow app — you open it like a document and keep working. Building or changing the app itself happens in Workflows mode.';
2387
2522
  html += `<div class="ws-empty-note">${escapeHtml(note)} ${escapeHtml(what)}${archived.length ? ' You have archived projects below.' : ''}`
2388
- // Same prompt, same aria wording as the Workflows card — a screen-reader user who meets both
2389
- // entry points should hear one action, not two. The id is what carries focus across a
2390
- // repaint (landingFocusKey keys on it).
2523
+ // The same Guide as the Workflows card. The id is what carries focus across a repaint (landingFocusKey keys on it).
2391
2524
  + `<div class="ws-empty-tour">New here? `
2392
- + `<button type="button" id="ws-onb-tour" class="ws-empty-tour-btn" `
2393
- + `aria-label="Start the guided tour — copies the onboarding prompt to your clipboard" `
2394
- + `data-tip="Copies a prompt — paste it into Claude Code or Codex">Start the guided tour →</button>`
2395
- + `<span class="sr-only ws-empty-tour-live" aria-live="polite"></span>`
2525
+ + `<button type="button" id="ws-onb-tour" class="ws-empty-tour-btn" data-command-id="shell.ask-guide#the Workspaces page" `
2526
+ + `data-tip="Ask the Guide in AI Chat to look at your setup and suggest what to do first.">Ask the Guide →</button>`
2396
2527
  + `</div></div>`;
2397
2528
  }
2398
2529
  }
@@ -2449,7 +2580,7 @@
2449
2580
  tipTruncatedNames();
2450
2581
  // The first-run tour link, when the empty state rendered one. app.js owns the copy behaviour so
2451
2582
  // both entry points to the tour stay identical; a no-op when the button isn't on screen.
2452
- wireTourCopy($landing.querySelector('#ws-onb-tour'));
2583
+ wireAskGuide($landing.querySelector('#ws-onb-tour'));
2453
2584
  reflashCard(); // a repaint must not swallow an in-flight confirmation glow
2454
2585
  }
2455
2586
 
@@ -2458,6 +2589,7 @@
2458
2589
  * cards and the Archived list are not results, so they are left alone. `caret` restores the
2459
2590
  * selection a rebuild dropped. */
2460
2591
  function applyLandingSearch(caret) {
2592
+ syncProjectGroupSearchRoot();
2461
2593
  const input = $landing.querySelector('#ws-landing-search');
2462
2594
  if (!input) return;
2463
2595
  const terms = landingQuery.trim().toLowerCase().split(/\s+/).filter(Boolean);
@@ -2467,6 +2599,15 @@
2467
2599
  card.hidden = !terms.every((t) => hay.includes(t));
2468
2600
  if (!card.hidden) shown++;
2469
2601
  }
2602
+ // Search counts describe the visible results, and a module with no matches leaves no empty
2603
+ // heading behind. Clearing the query restores the same sections without rebuilding the cards.
2604
+ for (const section of $landing.querySelectorAll('.ws-project-section')) {
2605
+ const count = Array.from(section.querySelectorAll('.ws-card[data-open]')).filter((card) => !card.hidden).length;
2606
+ section.hidden = count === 0;
2607
+ const key = section.dataset.module;
2608
+ showProjectGroup(section, terms.length ? (projectGroupSearchOverrides.get(key) ?? true) : projectGroupExpanded(key));
2609
+ section.querySelector('.ws-project-count').textContent = `${count} ${count === 1 ? 'project' : 'projects'}`;
2610
+ }
2470
2611
  const note = $landing.querySelector('#ws-search-empty');
2471
2612
  if (note) {
2472
2613
  note.textContent = shown ? '' : `No projects match “${landingQuery.trim()}”.${archived.length ? ' Archived projects aren’t searched.' : ''} `;
@@ -2476,6 +2617,7 @@
2476
2617
  if (caret) input.setSelectionRange(caret[0], caret[1]);
2477
2618
  }
2478
2619
  function setLandingQuery(q) {
2620
+ if (q !== landingQuery) projectGroupSearchOverrides.clear();
2479
2621
  landingQuery = q;
2480
2622
  const input = $landing.querySelector('#ws-landing-search');
2481
2623
  if (input) input.value = q;
@@ -2526,7 +2668,7 @@
2526
2668
  // element is ACTED on by, never by DOM position: a rebuild reorders the grid (a rename re-fronts its
2527
2669
  // card), so an index would hand focus to a different project — worse than losing it. Returns null
2528
2670
  // for anything unrecognised or outside the landing, which simply means "don't restore".
2529
- const FOCUS_KEY_ATTRS = ['data-open', 'data-kebab', 'data-thumb', 'data-restore', 'data-delete-archived', 'data-revit-remedy', 'data-module-remedy'];
2671
+ const FOCUS_KEY_ATTRS = ['data-project-group-toggle', 'data-open', 'data-kebab', 'data-thumb', 'data-restore', 'data-delete-archived', 'data-parser-setup', 'data-revit-remedy', 'data-module-remedy'];
2530
2672
  function landingFocusKey(el) {
2531
2673
  if (!el || !$landing.contains(el)) return null;
2532
2674
  if (el.id) return `#${el.id}`; // #ws-import-project / #ws-retry-projects
@@ -2578,6 +2720,17 @@
2578
2720
  }
2579
2721
 
2580
2722
  $landing.addEventListener('click', async (e) => {
2723
+ const groupToggle = e.target.closest('[data-project-group-toggle]');
2724
+ if (groupToggle) {
2725
+ const expanded = groupToggle.getAttribute('aria-expanded') !== 'true';
2726
+ const key = groupToggle.dataset.projectGroupToggle;
2727
+ if (landingQuery.trim()) projectGroupSearchOverrides.set(key, expanded);
2728
+ else saveProjectGroupExpanded(key, expanded);
2729
+ showProjectGroup(groupToggle.closest('.ws-project-section'), expanded);
2730
+ if (expanded) tipTruncatedNames();
2731
+ e.stopPropagation();
2732
+ return;
2733
+ }
2581
2734
  const kebab = e.target.closest('[data-kebab]');
2582
2735
  if (kebab) { e.stopPropagation(); openProjMenu(kebab.dataset.kebab, kebab); return; }
2583
2736
  // Before the card's own [data-open] branch below, exactly like the kebab: the thumbnail is the one
@@ -2597,6 +2750,11 @@
2597
2750
  return;
2598
2751
  }
2599
2752
  if (e.target.closest('#ws-import-project')) { importProject(); return; }
2753
+ const parserSetup = e.target.closest('[data-parser-setup]');
2754
+ if (parserSetup) {
2755
+ window.flolessParserSetupRecovery?.open(parserSetup.dataset.parserSetup, parserSetup);
2756
+ return;
2757
+ }
2600
2758
  const revitRemedy = e.target.closest('[data-revit-remedy]');
2601
2759
  if (revitRemedy) {
2602
2760
  if (revitRemedy.dataset.revitRemedy === 'report-issue') {
@@ -2789,9 +2947,8 @@
2789
2947
  const appId = seed.dataset.seedApp;
2790
2948
  const templateId = seed.dataset.seedTemplate || appId;
2791
2949
  if (!WORKSPACE_APPS[templateId]) return;
2792
- // Every create action is drawing-first since #625 removed the copy-from-Workflows card. The
2793
- // check stays a check rather than an assumption: a future kind must declare its own branch,
2794
- // not silently inherit the file picker.
2950
+ // Each create kind has its own branch below. The 'drawing' check stays a check rather than an
2951
+ // assumption: a future kind must declare its own branch, not silently inherit the file picker.
2795
2952
  if (seed.dataset.seedAction === 'drawing') {
2796
2953
  if (workspaceWorkflowKnownMissing(appId)) {
2797
2954
  showToast(missingWorkspaceWorkflowMessage(templateId), 'warn');
@@ -2826,6 +2983,7 @@
2826
2983
  });
2827
2984
  $landing.addEventListener('input', (e) => {
2828
2985
  if (e.target.id !== 'ws-landing-search') return;
2986
+ projectGroupSearchOverrides.clear();
2829
2987
  landingQuery = e.target.value;
2830
2988
  applyLandingSearch();
2831
2989
  });
@@ -2849,11 +3007,10 @@
2849
3007
  openProject(e.target.dataset.open);
2850
3008
  });
2851
3009
 
2852
- // Drop-a-drawing dropzone. A single hidden picker (outside $landing so an innerHTML re-render can't
2853
- // wipe it) backs the click-to-pick; dragover/drop are delegated on $landing so they survive the
2854
- // re-render too. The dashed card lights up (.drag-over) while a file hovers it.
2855
- // Fallback-only hidden input (outside $landing so an innerHTML re-render can't wipe it) —
2856
- // driven by pickDrawingFiles() above when the File System Access API isn't available.
3010
+ // Hidden fallback pickers for the create cards' click path: drawings, one .rvt, a Tekla folder, a
3011
+ // Tekla .zip. They live outside $landing so an innerHTML re-render can't wipe them, and the pick*()
3012
+ // helpers above use them only when the File System Access API is missing. Files DROPPED on a card
3013
+ // are handled by dropOnLanding below.
2857
3014
  const $seedFile = document.createElement('input');
2858
3015
  $seedFile.type = 'file'; $seedFile.accept = '.pdf,image/*'; $seedFile.multiple = true; $seedFile.hidden = true;
2859
3016
  document.body.appendChild($seedFile);
@@ -3046,33 +3203,173 @@
3046
3203
  const $thumbFile = document.createElement('input');
3047
3204
  $thumbFile.type = 'file'; $thumbFile.accept = 'image/*'; $thumbFile.hidden = true;
3048
3205
  document.body.appendChild($thumbFile);
3049
- $landing.addEventListener('dragover', (e) => {
3050
- const zone = e.target.closest('[data-seed-drop]');
3051
- if (!zone) return;
3206
+ // Files dropped on the landing. Every create card takes part: a card that reads a file starts a
3207
+ // project from it, and every other one (locked, needing setup, or Drawing Checker, which starts from
3208
+ // a profile) still accepts the drop so it can say why nothing opened (cardDropWarning). Anywhere else
3209
+ // the drop is refused with a no-drop cursor (the guard below), so the browser never leaves the app to
3210
+ // display the dropped file, which is what an unhandled drop does.
3211
+ const DRAWING_EXTENSIONS = Object.values(DRAWING_FILE_TYPES[0].accept).flat();
3212
+ const isDrawingFile = (file) => DRAWING_EXTENSIONS.some((ext) => file.name.toLowerCase().endsWith(ext));
3213
+ const DRAWING_FORMATS = 'PDF and image files (PNG, JPG, GIF, WebP or BMP)';
3214
+ const draggingFiles = (e) => Array.from(e.dataTransfer?.types || []).includes('Files');
3215
+ // While files are dragged over the window, `data-file-drag` on $landing (so a re-render keeps it)
3216
+ // shows every card that takes a file. Set on every dragenter and dragover, which keep firing while a
3217
+ // drag hovers, so nothing can leave it wrongly cleared for more than a moment. Cleared when the drag
3218
+ // leaves the window (a dragleave whose relatedTarget is null: moving between elements names the new
3219
+ // one), on a drop, and on the first pointer move after the drag — a drag fires no pointer events, and
3220
+ // no event reliably ends one that started outside the page. (A count of enters and leaves was tried
3221
+ // first: one unpaired leave, such as a leftover from the previous drag, cleared it mid-drag.)
3222
+ function endFileDrag() {
3223
+ if (!('fileDrag' in $landing.dataset)) return;
3224
+ delete $landing.dataset.fileDrag;
3225
+ $landing.querySelectorAll('.drag-over').forEach((zone) => zone.classList.remove('drag-over'));
3226
+ }
3227
+ function fileDragEnter(e) {
3228
+ if (draggingFiles(e) && !('fileDrag' in $landing.dataset)) $landing.dataset.fileDrag = '';
3229
+ }
3230
+ function fileDragLeave(e) { if (draggingFiles(e) && !e.relatedTarget) endFileDrag(); }
3231
+ window.addEventListener('dragenter', fileDragEnter);
3232
+ window.addEventListener('dragover', fileDragEnter);
3233
+ window.addEventListener('dragleave', fileDragLeave);
3234
+ window.addEventListener('drop', endFileDrag, true);
3235
+ window.addEventListener('pointermove', endFileDrag, { passive: true });
3236
+ // Anywhere in the app that nothing takes a file — an open dialog, the header — a dropped one is
3237
+ // refused instead of opened in place of FloLess. Bubble phase, and only when nothing below handled
3238
+ // it, so the real drop zones (the cards, chat, Knowledge) answer first; never on a file input,
3239
+ // whose own default is to take the file.
3240
+ const unhandledFileDrag = (e) => draggingFiles(e) && !e.defaultPrevented
3241
+ && !(e.target instanceof HTMLInputElement && e.target.type === 'file');
3242
+ window.addEventListener('dragover', (e) => { if (unhandledFileDrag(e)) { e.preventDefault(); e.dataTransfer.dropEffect = 'none'; } });
3243
+ window.addEventListener('drop', (e) => { if (unhandledFileDrag(e)) e.preventDefault(); });
3244
+
3245
+ // A file dropped on the wrong card: what this card opens, and where the file goes instead. Only a
3246
+ // card that is on screen and ready is ever named, and a folder or .zip is only SUGGESTED for Tekla
3247
+ // Parser, since a folder of drawings or a project archive is neither a Tekla model.
3248
+ function misdropMessage(zone, opens, files, folderCount) {
3249
+ const cardFor = (kind) => $landing.querySelector(`[data-seed-drop-kind="${kind}"] .ws-seed-headline`)?.textContent;
3250
+ const name = zone.querySelector('.ws-seed-headline')?.textContent || 'This card';
3251
+ const other = (card) => (card && card !== name ? card : null);
3252
+ const revit = files.some((file) => /\.rvt$/i.test(file.name)) && other(cardFor('rvt'));
3253
+ const drawing = files.some(isDrawingFile) && other(cardFor('drawing'));
3254
+ const tekla = (folderCount || files.some((file) => /\.zip$/i.test(file.name))) && other(cardFor('tekla-source'));
3255
+ const next = revit ? `Drop it on ${revit} instead.`
3256
+ : drawing ? `Drop it on ${drawing} instead.`
3257
+ : folderCount && zone.dataset.seedDropKind === 'drawing'
3258
+ ? `Folders aren’t opened: drop the drawings inside it instead${tekla ? `, or drop a Tekla model folder on ${tekla}` : ''}.`
3259
+ : tekla ? `If it is a Tekla model, drop it on ${tekla} instead.`
3260
+ : 'Drop one of those, or click the card to choose it.';
3261
+ return `${name} opens ${opens}, so nothing was opened. ${next}`;
3262
+ }
3263
+
3264
+ // What a card that takes no file says when one is dropped on it. A locked or setting-up card answers
3265
+ // with what it shows NOW (retrying setup rewrites the card in place) plus its next step; that text can
3266
+ // carry the server's own remedy naming the person's folders, so it goes out as authored copy.
3267
+ function cardDropWarning(zone) {
3268
+ if (zone.dataset.dropWarn) return zone.dataset.dropWarn;
3269
+ const said = zone.querySelector('.ws-seed-sub')?.textContent?.trim() || '';
3270
+ const action = zone.querySelector('.ws-seed-action')?.textContent?.replace(/\s*→\s*$/, '').trim();
3271
+ // A busy card (setting up, or retrying: its action then reads "Trying…") has nothing to press yet.
3272
+ return authoredToastCopy(`Nothing was opened. ${said}`
3273
+ + (zone.getAttribute('aria-busy') === 'true' ? ' Drop the file again once it finishes.'
3274
+ : action ? ` Use “${action}” on the card, then drop the file again.` : ''));
3275
+ }
3276
+
3277
+ // A Tekla model dropped on its card: the whole model folder, or one .zip of it, read as the folder
3278
+ // and ZIP pickers read them (filesFromDirectoryHandle, teklaZipSource). The folder's handle must be
3279
+ // requested INSIDE the drop event (the browser empties dataTransfer once the handler returns), so
3280
+ // only its answer is awaited. A browser without getAsFileSystemHandle is pointed to the click route.
3281
+ let teklaDropReading = false;
3282
+ function dropTeklaSource(zone, items, files, folderCount) {
3283
+ const appId = zone.dataset.seedDrop;
3284
+ const templateId = zone.dataset.seedTemplate || appId;
3285
+ if (items.length !== 1 || !(folderCount || /\.zip$/i.test(files[0]?.name || ''))) {
3286
+ showToast(misdropMessage(zone, 'a Tekla model folder or one .zip of it', files, folderCount), 'warn');
3287
+ return;
3288
+ }
3289
+ if (teklaDropReading) {
3290
+ showToast('FloLess is still reading the Tekla model you dropped a moment ago, so nothing new was opened. Wait for its project setup to open, then drop again if you need to.', 'warn');
3291
+ return;
3292
+ }
3293
+ const label = items[0].getAsFile?.()?.name || 'the Tekla model';
3294
+ const folder = folderCount ? items[0].getAsFileSystemHandle?.() : null;
3295
+ // A big model folder takes a while to read, and nothing else on screen moves meanwhile.
3296
+ const reading = folderCount ? showToast(`Reading ${label}…`, 'progress') : null;
3297
+ teklaDropReading = true;
3298
+ void (async () => {
3299
+ try {
3300
+ let source;
3301
+ if (!folderCount) source = teklaZipSource(files[0]);
3302
+ else {
3303
+ const handle = await folder;
3304
+ if (handle?.kind !== 'directory') throw new Error('FloLess couldn’t read the dropped folder, so nothing was opened. Click the card to choose the Tekla model folder instead.');
3305
+ source = await filesFromDirectoryHandle(handle);
3306
+ }
3307
+ // The read may have outlasted the moment: never open setup over another window or a project.
3308
+ if (projectSetupState || teklaSourceChoice || $landing.hidden) {
3309
+ throw new Error(`FloLess finished reading ${label}, but something else is open now, so nothing was opened. Drop the model on Tekla Parser again when you are ready.`);
3310
+ }
3311
+ await createFromTeklaSource(appId, templateId, source, zone.isConnected ? zone : null);
3312
+ } catch (error) {
3313
+ // Our own checks throw a plain Error that already says what to do. Anything else is the browser
3314
+ // failing to read a file (moved, locked, unreadable), whose message is not written for people.
3315
+ if (error?.name !== 'Error') console.warn('[workspaces] could not read a dropped Tekla model', error);
3316
+ showToast(error?.name === 'Error' && error.message ? error.message
3317
+ : 'FloLess couldn’t read every file of that Tekla model, so nothing was opened. Check it is still there and not open in another program, then drop it again or click the card to choose it.', 'warn');
3318
+ } finally {
3319
+ teklaDropReading = false;
3320
+ reading?.(true);
3321
+ }
3322
+ })();
3323
+ }
3324
+
3325
+ // Every create card accepts the drag (so a card that takes no file can still answer the drop); off
3326
+ // the cards the no-drop cursor says it lands nowhere.
3327
+ $landing.addEventListener('dragover', dragOverLanding);
3328
+ function dragOverLanding(e) {
3329
+ if (!draggingFiles(e)) return;
3052
3330
  e.preventDefault();
3053
- zone.classList.add('drag-over');
3054
- });
3331
+ const zone = e.target.closest('.ws-seed');
3332
+ if (!zone) { e.dataTransfer.dropEffect = 'none'; return; }
3333
+ if (zone.dataset.seedDrop) zone.classList.add('drag-over');
3334
+ }
3055
3335
  $landing.addEventListener('dragleave', (e) => {
3056
3336
  const zone = e.target.closest('[data-seed-drop]');
3057
3337
  if (zone && !zone.contains(e.relatedTarget)) zone.classList.remove('drag-over');
3058
3338
  });
3059
- $landing.addEventListener('drop', (e) => {
3060
- const zone = e.target.closest('[data-seed-drop]');
3061
- if (!zone) return;
3339
+ $landing.addEventListener('drop', dropOnLanding);
3340
+ function dropOnLanding(e) {
3341
+ if (!draggingFiles(e)) return;
3062
3342
  e.preventDefault();
3063
- zone.classList.remove('drag-over');
3064
- const files = Array.from((e.dataTransfer && e.dataTransfer.files) || []);
3343
+ const zone = e.target.closest('.ws-seed');
3344
+ if (!zone) return;
3345
+ if (!zone.dataset.seedDrop) { showToast(cardDropWarning(zone), 'warn'); return; }
3346
+ const items = Array.from(e.dataTransfer.items || []).filter((item) => item.kind === 'file');
3347
+ const isFolder = items.map((item) => !!item.webkitGetAsEntry?.()?.isDirectory);
3348
+ const folderCount = isFolder.filter(Boolean).length;
3349
+ // A dropped folder also comes through as an empty file named like the folder ("plans.pdf"
3350
+ // included), so the files are taken from the non-folder items only.
3351
+ const files = items.filter((_, i) => !isFolder[i]).map((item) => item.getAsFile()).filter(Boolean);
3065
3352
  // Same two ids as the click path — the dropzone IS the seed button, so it carries both.
3066
- if (zone.dataset.seedDropKind === 'rvt') {
3067
- if (files.length === 1 && /\.rvt$/i.test(files[0].name)) createFromRvt(zone.dataset.seedDrop, zone.dataset.seedTemplate || zone.dataset.seedDrop, files[0]);
3068
- else showToast('Choose one Revit .rvt file.', 'warn');
3069
- } else if (files.length) {
3070
- const appId = zone.dataset.seedDrop;
3071
- const templateId = zone.dataset.seedTemplate || appId;
3072
- if (workspaceWorkflowKnownMissing(appId)) showToast(missingWorkspaceWorkflowMessage(templateId), 'warn');
3073
- else createFromDrawing(appId, templateId, files);
3353
+ const appId = zone.dataset.seedDrop;
3354
+ const templateId = zone.dataset.seedTemplate || appId;
3355
+ const kind = zone.dataset.seedDropKind;
3356
+ if (kind === 'tekla-source') { dropTeklaSource(zone, items, files, folderCount); return; }
3357
+ if (kind === 'rvt') {
3358
+ if (files.length === 1 && !folderCount && /\.rvt$/i.test(files[0].name)) createFromRvt(appId, templateId, files[0]);
3359
+ else showToast(misdropMessage(zone, 'one Revit .rvt file', files, folderCount), 'warn');
3360
+ return;
3074
3361
  }
3075
- });
3362
+ const drawings = files.filter(isDrawingFile);
3363
+ if (!drawings.length) { showToast(misdropMessage(zone, DRAWING_FORMATS, files, folderCount), 'warn'); return; }
3364
+ if (workspaceWorkflowKnownMissing(appId)) { showToast(missingWorkspaceWorkflowMessage(templateId), 'warn'); return; }
3365
+ const skippedFiles = files.length - drawings.length;
3366
+ const skipped = [
3367
+ skippedFiles && `Skipped ${skippedFiles} ${skippedFiles === 1 ? 'file that isn’t a PDF or image' : 'files that aren’t PDFs or images'}.`,
3368
+ folderCount && `Skipped ${folderCount === 1 ? '1 folder' : `${folderCount} folders`}: folders aren’t opened, so drop the drawings inside instead.`,
3369
+ ].filter(Boolean);
3370
+ if (skipped.length) showToast(skipped.join(' '), 'warn');
3371
+ createFromDrawing(appId, templateId, drawings);
3372
+ }
3076
3373
 
3077
3374
  async function promptName(title, label, value) {
3078
3375
  if (!bridge.formModal) return null;
@@ -3171,6 +3468,17 @@
3171
3468
  if (userMessage) return userMessage;
3172
3469
  const raw = String(error && error.body?.error || error && error.message || error || '');
3173
3470
  const code = String(error && (error.code || error.body?.code) || '');
3471
+ // Account access can expire while this dialog is open, before the folder chooser
3472
+ // or project creation runs. Name that cause without blaming the selected folder.
3473
+ if (error?.status === 402 || error?.body?.error === 'subscription required') {
3474
+ const access = error?.body || error;
3475
+ if (access?.reason === 'session-expired') return 'Your FloLess sign-in has expired. Sign in again, then try again.';
3476
+ if (access?.reason === 'signed-out') return 'You are signed out of FloLess. Sign in again, then try again.';
3477
+ if (access?.reason === 'seat-taken') return 'Your FloLess session has ended. Sign in again, then try again.';
3478
+ if (access?.state === 'expired') return 'Your FloLess subscription has expired. Renew your subscription, then try again.';
3479
+ if (access?.reason === 'no-subscription') return 'This account does not have a FloLess subscription. Sign in with a subscribed account or subscribe, then try again.';
3480
+ return 'Sign in to FloLess to check your account access, then try again.';
3481
+ }
3174
3482
  // A setup refusal with no sentence for the person (#1965 review, round 3). The code covers several
3175
3483
  // causes — the parser's setup has not finished, or a check refused this project while its card shows
3176
3484
  // the ready state — so the sentence names none of them, only the card that shows what is left to do.
@@ -5953,6 +6261,37 @@
5953
6261
  }
5954
6262
  }
5955
6263
 
6264
+ // These replies are made before this attempt writes durable approval state. Asking for its
6265
+ // receipt would only find nothing and turn the rejected request into an identical retry.
6266
+ const APPROVAL_PREWRITE_REFUSAL_CODES = ['approval-forward-invalid', 'approval-partition-conflict', 'approval-head-stale', 'nothing-to-approve'];
6267
+ function showApprovalPrewriteRefusal(error, project) {
6268
+ const st = approvalDialogState;
6269
+ const code = error && error.body && error.body.code;
6270
+ if (!st || !APPROVAL_PREWRITE_REFUSAL_CODES.includes(code)) return false;
6271
+ rememberApprovalOperation(project, null);
6272
+ st.operationId = null;
6273
+ st.operationToken = null;
6274
+ st.decisions = {};
6275
+ st.conflicts = {};
6276
+ st.retryAction = null;
6277
+ st.stale = true;
6278
+ const nothingSelected = code === 'nothing-to-approve';
6279
+ const explanation = error.body.error || (nothingSelected
6280
+ ? 'Choose at least one change to approve.'
6281
+ : 'FloLess could not apply these selected changes together.');
6282
+ const next = nothingSelected
6283
+ ? 'Close this review, then reopen it to choose the changes you want to approve.'
6284
+ : code === 'approval-partition-conflict'
6285
+ ? 'Reload current review, then approve related changes together or leave them pending. Your earlier decisions will be cleared.'
6286
+ : 'Reload current review, then choose which changes to approve. Your earlier decisions will be cleared.';
6287
+ $approvalImpact.textContent = explanation;
6288
+ $approvalCounts.textContent = '';
6289
+ $approvalBody.innerHTML = `<div class="approval-notice approval-notice-error"><b>Nothing was approved.</b> ${escapeHtml(next)}</div>`;
6290
+ setApprovalPhase(nothingSelected ? 'recovery-close' : 'stale', `Nothing was approved. ${next}`);
6291
+ (nothingSelected ? $approvalClose : $approvalReload).focus();
6292
+ return true;
6293
+ }
6294
+
5956
6295
  async function confirmApprovalReview() {
5957
6296
  const st = approvalDialogState;
5958
6297
  if (!st || $approvalConfirm.disabled || !current || current.id !== st.projectId) return;
@@ -5977,6 +6316,7 @@
5977
6316
  });
5978
6317
  await finishApprovalSuccess(res, project);
5979
6318
  } catch (error) {
6319
+ if (showApprovalPrewriteRefusal(error, project)) return;
5980
6320
  if (approvalDialogState && error && error.body && IMPORT_FINDINGS_REFUSAL_CODES.includes(error.body.code)) {
5981
6321
  // Refused BEFORE anything durable was written for this operation (no claim, no recovery), so it
5982
6322
  // is never a retry. Forget the operation pair, clear the decision, re-bind the warning to the
@@ -6004,8 +6344,8 @@
6004
6344
  st.operationId = null;
6005
6345
  st.operationToken = null;
6006
6346
  approvalDialogState.stale = true;
6007
- $approvalImpact.textContent = 'The working copy changed. Your decisions were not applied. Reload the current review; earlier decisions will be cleared.';
6008
6347
  renderApprovalReview();
6348
+ $approvalImpact.textContent = 'The working copy changed. Your decisions were not applied. Reload the current review; earlier decisions will be cleared.';
6009
6349
  setApprovalPhase('stale', 'The review changed. Reload current review.');
6010
6350
  $approvalReload.focus();
6011
6351
  } else if (approvalDialogState) {
@@ -6397,7 +6737,8 @@
6397
6737
  function kbPending(st) {
6398
6738
  if (st.organize) return { started: true, since: Date.parse(st.organize.startedAt) };
6399
6739
  const q = st.queued[0];
6400
- if (q) return { started: false, since: Date.parse(q.createdAt), id: q.id }; // id: which queued request Cancel deletes
6740
+ // id: which queued request Cancel deletes; wait (#2131): its start met work already changing the project.
6741
+ if (q) return { started: false, since: Date.parse(q.createdAt), id: q.id, wait: q.organizeWait || null };
6401
6742
  return null;
6402
6743
  }
6403
6744
  const kbAgo = (ms) => {
@@ -6483,6 +6824,21 @@
6483
6824
  `</div>`;
6484
6825
  }
6485
6826
 
6827
+ /**
6828
+ * #2131: a queued organize whose start met work already changing the project. Only what was recorded is said — when
6829
+ * the AI last tried and who held the project — never that it starts by itself: nothing here can tell whether that AI
6830
+ * is still trying. Past FloLess's 30 minutes the server's own sentence says what happened and what to do.
6831
+ */
6832
+ function kbWaitLead(wait) {
6833
+ if (wait.endedAt) return escapeHtml(String(wait.message || 'Organizing waited too long for other work in this project and didn’t start. Ask your AI to organize again.'));
6834
+ const full = String(wait.holder?.title || 'other work');
6835
+ const title = full.length > 48 ? `${full.slice(0, 45).trimEnd()}…` : full;
6836
+ const who = wait.holder?.kind === 'chat' ? `“${title}”` : title;
6837
+ const ago = kbAgo(Date.now() - Date.parse(wait.lastTriedAt));
6838
+ return escapeHtml(`Your AI tried to start organizing${ago ? ` ${ago}` : ''}, but ${who} was changing this project. Organizing hasn’t started. `
6839
+ + 'If your AI is no longer waiting, ask it to organize again once that work is done.');
6840
+ }
6841
+
6486
6842
  function kbFoot(st) {
6487
6843
  const enabled = st.sources.filter((s) => s.useAsKb).length;
6488
6844
  const pending = kbPending(st);
@@ -6495,11 +6851,12 @@
6495
6851
  const age = kbAgo(Date.now() - pending.since);
6496
6852
  const stale = pending.started && Date.now() - pending.since > KB_LOCK_STALE_MS;
6497
6853
  const cls = stale ? 'kb-pending stale' : pending.started ? 'kb-pending' : 'kb-pending queued';
6498
- const ico = stale ? '<span class="kb-ico" aria-hidden="true">⚠</span>'
6854
+ const ico = stale || pending.wait?.endedAt ? '<span class="kb-ico" aria-hidden="true">⚠</span>'
6499
6855
  : pending.started ? '<span class="kb-spin" aria-hidden="true"></span>'
6500
6856
  : '<span class="kb-ico" aria-hidden="true">◷</span>';
6501
6857
  const lead = pending.started
6502
6858
  ? `Organizing…${age ? ` started ${escapeHtml(age)}` : ''}`
6859
+ : pending.wait ? kbWaitLead(pending.wait)
6503
6860
  : `Queued for your terminal AI — waiting to start…${age ? ` (${escapeHtml(age)})` : ''}`;
6504
6861
  // A queued organize (not yet started) can be cancelled — at that point there is no organize lock
6505
6862
  // to strand, so this is the immediate, user-initiated escape from a button wedged by an organize
@@ -7641,6 +7998,8 @@
7641
7998
  // already-started: the terminal AI won a fair race — not a failure; the repaint shows "Organizing…".
7642
7999
  // not-found: already gone (drained/cancelled elsewhere) — silent; the repaint shows it's cleared.
7643
8000
  if (code === 'already-started') showToast('Knowledge organization has already started, so it will finish in your AI app.', 'warn');
8001
+ // #2132: the AI is starting it right now (it may still fail to start), or FloLess could not check — say which.
8002
+ else if ((code === 'organize-starting' || code === 'organize-state-unknown') && typeof err.body.error === 'string') showToast(err.body.error, 'warn');
7644
8003
  else if (code !== 'not-found') showToast('Couldn’t cancel Knowledge organization. Try again.', 'warn');
7645
8004
  } finally {
7646
8005
  kbCancelBusy = false;
@@ -13852,6 +14211,7 @@
13852
14211
  const el = $landing.querySelector(`.ws-card[data-open="${escapeAttr(id)}"]`);
13853
14212
  if (!el) return;
13854
14213
  if (el.hidden) setLandingQuery(''); // never confirm on a card the search is hiding (an import, a rename)
14214
+ revealProjectGroup(el);
13855
14215
  if (opts && opts.scroll) el.scrollIntoView({ block: 'nearest' });
13856
14216
  flashId = id;
13857
14217
  armFlash(id, el);
@@ -13862,6 +14222,8 @@
13862
14222
  if (!flashId) return;
13863
14223
  const el = $landing.querySelector(`.ws-card[data-open="${escapeAttr(flashId)}"]`);
13864
14224
  if (!el) { flashId = null; return; } // card is gone (archived/deleted) — drop the pending flash
14225
+ // A later manual collapse or search choice wins over this background confirmation repaint.
14226
+ if (el.hidden || el.closest('.ws-grid')?.hidden) { endFlash(flashId, el); return; }
13865
14227
  armFlash(flashId, el);
13866
14228
  }
13867
14229
 
@@ -14413,6 +14775,17 @@
14413
14775
  renderKnowledge();
14414
14776
  }
14415
14777
 
14778
+ /**
14779
+ * #2106: open a project on its Knowledge step — where a person sees FloLess organizing its knowledge, the work a busy
14780
+ * card's "Open it" leads to. Throws a plain sentence when the project can't be opened, so the caller can say so.
14781
+ */
14782
+ async function openKnowledgeStep(projectId) {
14783
+ if (typeof projectId !== 'string' || !projectId) throw new Error('That project could not be opened. Open it from Workspaces.');
14784
+ await setMode('workspaces');
14785
+ await openProject(projectId, 'knowledge');
14786
+ if (current?.id !== projectId) throw new Error('That project could not be opened. Open it from Workspaces.');
14787
+ }
14788
+
14416
14789
  // A cross-project object pin still belongs to its original conversation, wherever its model is shown.
14417
14790
  async function openChatOwner(owner) {
14418
14791
  const validId = (id) => typeof id === 'string' && !!id && id.length <= 200;
@@ -14433,7 +14806,7 @@
14433
14806
 
14434
14807
  window.flolessWorkspaces = {
14435
14808
  setMode, refresh: loadProjects, findActive: wsFindActive, find: wsFind, clearFind: wsClearFind,
14436
- openHistory: wsOpenHistory, openKnowledgePage, drawingFilterCheckpointSaved,
14809
+ openHistory: wsOpenHistory, openKnowledgePage, openKnowledgeStep, drawingFilterCheckpointSaved,
14437
14810
  syncWorkspaceReporter, openChatOwner,
14438
14811
  };
14439
14812
  applyMode(); // restore persisted mode immediately (matches panels.js applyView timing)