@1agh/maude 1.8.1 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/apps/studio/acp/bridge.ts +14 -2
  2. package/apps/studio/acp/probe.ts +51 -1
  3. package/apps/studio/api.ts +19 -4
  4. package/apps/studio/bin/_curl-local.mjs +7 -0
  5. package/apps/studio/bin/annotate.mjs +16 -7
  6. package/apps/studio/bin/read-annotations.mjs +62 -4
  7. package/apps/studio/client/app.jsx +428 -15977
  8. package/apps/studio/client/dialogs/asset-picker.jsx +331 -0
  9. package/apps/studio/client/dialogs/command-palette.jsx +112 -0
  10. package/apps/studio/client/dialogs/export-dialog.jsx +782 -0
  11. package/apps/studio/client/dialogs/help-modal.jsx +324 -0
  12. package/apps/studio/client/dialogs/shortcuts-overlay.jsx +144 -0
  13. package/apps/studio/client/hooks/use-canvas-bridge.jsx +2150 -0
  14. package/apps/studio/client/hooks/use-git-actions.jsx +236 -0
  15. package/apps/studio/client/hooks/use-keyboard-shortcuts.jsx +297 -0
  16. package/apps/studio/client/hooks/use-palette-and-panels.jsx +474 -0
  17. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +901 -0
  18. package/apps/studio/client/hooks/use-project-data.jsx +90 -0
  19. package/apps/studio/client/hooks/use-shell-core.jsx +1212 -0
  20. package/apps/studio/client/hooks/use-tabs.jsx +723 -0
  21. package/apps/studio/client/hooks/use-web-socket.jsx +13 -0
  22. package/apps/studio/client/inspector/artboard-knobs.jsx +456 -0
  23. package/apps/studio/client/inspector/color-picker.jsx +196 -0
  24. package/apps/studio/client/inspector/color.js +92 -0
  25. package/apps/studio/client/inspector/css-knobs.jsx +1720 -0
  26. package/apps/studio/client/inspector/css-vocab.jsx +131 -0
  27. package/apps/studio/client/inspector/ds-tokens.js +90 -0
  28. package/apps/studio/client/inspector/grid-tracks-editor.jsx +97 -0
  29. package/apps/studio/client/inspector/inspect-computed.jsx +68 -0
  30. package/apps/studio/client/inspector/inspector-panel.jsx +769 -0
  31. package/apps/studio/client/inspector/layers.jsx +322 -0
  32. package/apps/studio/client/inspector/selection.js +65 -0
  33. package/apps/studio/client/inspector/token-popover.jsx +301 -0
  34. package/apps/studio/client/menus/menubar.jsx +856 -0
  35. package/apps/studio/client/selection-scope.js +40 -0
  36. package/apps/studio/client/shell/banners.jsx +272 -0
  37. package/apps/studio/client/shell/collapsed-rail.jsx +23 -0
  38. package/apps/studio/client/shell/comments-panel.jsx +177 -0
  39. package/apps/studio/client/shell/constants.js +60 -0
  40. package/apps/studio/client/shell/dock.jsx +131 -0
  41. package/apps/studio/client/shell/icons.jsx +370 -0
  42. package/apps/studio/client/shell/status-bar.jsx +215 -0
  43. package/apps/studio/client/shell/util.js +332 -0
  44. package/apps/studio/client/shell/viewport.jsx +254 -0
  45. package/apps/studio/client/system/system-view.jsx +255 -0
  46. package/apps/studio/client/tree/tree.jsx +1243 -0
  47. package/apps/studio/comments-overlay.tsx +6 -4
  48. package/apps/studio/config.schema.json +5 -0
  49. package/apps/studio/context.ts +13 -0
  50. package/apps/studio/dist/client.bundle.js +1337 -1337
  51. package/apps/studio/dist/comment-mount.js +2 -2
  52. package/apps/studio/exporters/_browser-bundles.ts +21 -2
  53. package/apps/studio/exporters/jobs.ts +75 -15
  54. package/apps/studio/exporters/scope.ts +15 -12
  55. package/apps/studio/format.ts +296 -0
  56. package/apps/studio/http.ts +217 -23
  57. package/apps/studio/server.ts +141 -30
  58. package/apps/studio/sync/accepted-link.ts +6 -0
  59. package/apps/studio/sync/agent.ts +9 -1
  60. package/apps/studio/sync/cold-start-apply.ts +29 -4
  61. package/apps/studio/sync/cold-start.ts +78 -0
  62. package/apps/studio/sync/file-plane.ts +61 -1
  63. package/apps/studio/sync/format-sync.ts +160 -0
  64. package/apps/studio/sync/index.ts +134 -10
  65. package/apps/studio/sync/journal-client.ts +25 -5
  66. package/apps/studio/sync/migrate-seed.ts +8 -1
  67. package/apps/studio/sync/status.ts +2 -0
  68. package/apps/studio/sync/transaction-client.ts +130 -13
  69. package/apps/studio/ui-prefs.ts +95 -10
  70. package/apps/studio/whats-new.json +9 -0
  71. package/apps/studio/ws.ts +19 -4
  72. package/cli/bin/claude-design-server.mjs +0 -0
  73. package/package.json +10 -8
@@ -0,0 +1,1243 @@
1
+ // tree/tree.jsx — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
2
+
3
+ import { displayName, filterTree, groupBySidecar, openCount, pathTestIdSlug, previewKind, sectionDefaultOpen } from '../shell/util.js';
4
+ import { Icon, Kbd, StIcon } from '../shell/icons.jsx';
5
+ import { FileTree, FileTreeItem } from '../file-tree.jsx';
6
+ import { CANVAS_EXT_RE, SYSTEM_TAB } from '../shell/constants.js';
7
+ import { prefetchPreviewImage } from '../panels/file-preview.jsx';
8
+ import { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
9
+ import { useTreeDrag } from '../use-tree-drag.js';
10
+ import { TreeRowMenu, useRowMenu } from '../tree-row-menu.jsx';
11
+ import RepoBranchSwitcher from '../panels/RepoBranchSwitcher.jsx';
12
+ import CloudBar from '../panels/CloudBar.jsx';
13
+ import IdentityBar from '../panels/IdentityBar.jsx';
14
+
15
+ // ───── Tree (CV-08 spec) ─────
16
+ // File rows use `.tp-row` with optional .dir / .sel / .star / .modified
17
+ // modifiers + a leading `.glyph` (▾ open dir, ▸ closed dir / selected file,
18
+ // · file). Section headers use `.tp-section-hd` with a `.pill` counter.
19
+ // The flat-row model (vs the old nested <details>) mirrors the mock and
20
+ // keeps padding-left under explicit control per depth level.
21
+
22
+ export const TREE_INDENT_BASE = 12;
23
+
24
+ export const TREE_INDENT_STEP = 16;
25
+
26
+ // Issue #124 — disclosure is CONTROLLED: `expansion` is App's tree state (see
27
+ // tree-expansion.js), so a collapse outlives this row's unmount (dock-tab
28
+ // switch, section toggle, reload). `forceOpen` = an active search; it shows
29
+ // the hits without recording anything.
30
+ export function DirRow({ name, depth, children, dirPath, drag, menu, expansion, forceOpen }) {
31
+ const open = !!forceOpen || !!expansion?.isOpen(dirPath);
32
+ const setOpen = (v) => {
33
+ if (forceOpen) return; // search is showing hits — don't record a choice
34
+ const next = typeof v === 'function' ? v(open) : v;
35
+ if (next !== open) expansion?.setOpen(dirPath, next);
36
+ };
37
+ // feature-file-tree-drag-drop-folders (Task 8) — a folder row IS the drop
38
+ // target. `drag` is undefined for groups that can't accept a move (the
39
+ // design-system group) — no handlers attach there, so the browser's default
40
+ // "no drop" cursor applies with zero extra code. Spring-load reopens a
41
+ // closed folder after a sustained hover; `setOpen` is this row's OWN local
42
+ // state, which is why the callback lives here rather than in the hook.
43
+ const dropHandlers = drag ? drag.dropProps(dirPath, true, () => setOpen(true)) : {};
44
+ const isOver = drag?.overDir === dirPath;
45
+ // feature-file-tree-drag-drop-folders (Task 11) — a folder is ALSO a drag
46
+ // SOURCE (drag folder onto folder). No client-side branching needed beyond
47
+ // this: the payload is just `dirPath` (no `.tsx` suffix), and the server's
48
+ // moveCanvas auto-detects a non-.tsx source as a folder move.
49
+ const dragHandlers = drag ? drag.dragProps(dirPath, true) : {};
50
+ const isDragging = drag?.draggedPath === dirPath;
51
+ const isBusy = drag?.busyPath === dirPath;
52
+ const row = (
53
+ <button
54
+ type="button"
55
+ role="treeitem"
56
+ data-testid={`tree-folder-${pathTestIdSlug(dirPath)}`}
57
+ aria-expanded={open}
58
+ aria-dropeffect={drag ? 'move' : undefined}
59
+ aria-busy={isBusy || undefined}
60
+ tabIndex={-1}
61
+ className={
62
+ 'st-row' +
63
+ (isOver ? ' is-drop-target' : '') +
64
+ (isDragging ? ' is-dragging' : '') +
65
+ (isBusy ? ' is-busy' : '')
66
+ }
67
+ style={{ paddingLeft: TREE_INDENT_BASE + depth * TREE_INDENT_STEP + 'px' }}
68
+ onClick={() => setOpen((v) => !v)}
69
+ onContextMenu={menu ? (e) => menu.openAt(e, { kind: 'dir', dirPath }) : undefined}
70
+ {...dragHandlers}
71
+ {...dropHandlers}
72
+ >
73
+ <span className="st-row-glyph">
74
+ <StIcon name="chevron-right" className={'st-chev' + (open ? ' is-open' : '')} size={13} />
75
+ </span>
76
+ <span className="st-row-name">{name}</span>
77
+ </button>
78
+ );
79
+ return (
80
+ <FileTreeItem label={name} row={row} expanded={open} busy={isBusy}
81
+ onToggle={() => setOpen(v => !v)} actions={menu ? (
82
+ <button
83
+ type="button"
84
+ className="st-row-menu-btn"
85
+ data-testid={`tree-row-menu-${pathTestIdSlug(dirPath)}`}
86
+ title={`Folder actions — ${name}`}
87
+ aria-label={`Folder actions for ${name}`}
88
+ aria-haspopup="menu"
89
+ onClick={(e) => menu.openAt(e, { kind: 'dir', dirPath })}
90
+ >
91
+ <Icon d="M12 6a1 1 0 100-2 1 1 0 000 2zM12 13a1 1 0 100-2 1 1 0 000 2zM12 20a1 1 0 100-2 1 1 0 000 2z" size={12} />
92
+ </button>
93
+ ) : null}>
94
+ {open && children}
95
+ </FileTreeItem>
96
+ );
97
+ }
98
+
99
+ // DsFolderRow — a per-DS folder inside the DESIGN SYSTEM section.
100
+ // Split target: chevron toggles disclosure of the folder's contents; clicking
101
+ // the folder name opens the SystemView focused on that DS (single SystemView
102
+ // for now; the dsName is plumbed through so a future per-DS view can use it).
103
+ export function DsFolderRow({ name, dsName, dirPath, depth, active, onOpenSystem, children, expansion, forceOpen }) {
104
+ const open = !!forceOpen || !!expansion?.isOpen(dirPath);
105
+ const setOpen = (v) => {
106
+ if (forceOpen) return; // search is showing hits — don't record a choice
107
+ const next = typeof v === 'function' ? v(open) : v;
108
+ if (next !== open) expansion?.setOpen(dirPath, next);
109
+ };
110
+ return (
111
+ <FileTreeItem label={name} expanded={open} selected={active}
112
+ onToggle={() => setOpen(v => !v)} row={
113
+ <div
114
+ className={'st-row st-ds-folder' + (active ? ' is-sel' : '')}
115
+ style={{ paddingLeft: TREE_INDENT_BASE + depth * TREE_INDENT_STEP + 'px' }}
116
+ >
117
+ <button
118
+ type="button"
119
+ className="st-ds-chev"
120
+ onClick={() => setOpen((v) => !v)}
121
+ aria-label={open ? 'Collapse design system' : 'Expand design system'}
122
+ title={open ? 'Collapse' : 'Expand'}
123
+ >
124
+ <StIcon name="chevron-right" className={'st-chev' + (open ? ' is-open' : '')} size={13} />
125
+ </button>
126
+ <button
127
+ type="button"
128
+ className="st-ds-open"
129
+ data-tree-primary=""
130
+ tabIndex={-1}
131
+ onClick={() => onOpenSystem(dsName)}
132
+ aria-label={`Open ${dsName} design system view`}
133
+ title="Open the design system view"
134
+ >
135
+ <span className="st-row-glyph">
136
+ <StIcon name="folder" size={13} />
137
+ </span>
138
+ <span className="st-row-name">{name}</span>
139
+ </button>
140
+ </div>}>
141
+ {open && children}
142
+ </FileTreeItem>
143
+ );
144
+ }
145
+
146
+ export function FileRow({
147
+ file,
148
+ activePath,
149
+ previewPath,
150
+ onOpen,
151
+ onPreview,
152
+ onDelete,
153
+ openCount: oc,
154
+ depth,
155
+ kind,
156
+ sidecar,
157
+ dirty,
158
+ experimentalKind,
159
+ drag,
160
+ menu,
161
+ }) {
162
+ // feature-studio-file-preview (a11y fix) — a previewed row must expose
163
+ // aria-selected too, or a screen-reader user gets no confirmation their
164
+ // click did anything (a11y-auditor finding: state never changed).
165
+ const isSel = file.path === activePath || file.path === previewPath;
166
+ const isCanvas = CANVAS_EXT_RE.test(file.name);
167
+ // feature-studio-file-preview — RUNTIME rows (_active.json, _server.json, …)
168
+ // stay inert no matter their extension: they're gitignored process state,
169
+ // never user-facing content, and must not become previewable just because
170
+ // `.json` also matches the `text` preview kind (DDR-115 exclusion).
171
+ const pKind = !isCanvas && kind !== 'runtime' ? previewKind(file.name) : null;
172
+ // Non-canvas, non-previewable rows (RUNTIME files, unrecognized extensions)
173
+ // are display-only — clicking them doesn't open anything; we leave the
174
+ // click as no-op + cursor hint via `aria-disabled`.
175
+ const inert = !isCanvas && !pKind;
176
+ const label = isCanvas ? displayName(file.name) : file.name;
177
+ // Delete only real canvases in a deletable group (onDelete is undefined for the
178
+ // DS group + runtime files); the server enforces the rest.
179
+ const canDelete = isCanvas && typeof onDelete === 'function' && kind !== 'runtime';
180
+ // feature-file-tree-drag-drop-folders (Task 8) — only real canvas primaries
181
+ // (never sidecars, never runtime rows) are draggable; `drag` is undefined
182
+ // for groups that can't be a move source (the design-system group).
183
+ const draggableRow = isCanvas && !sidecar && kind !== 'runtime' && typeof drag !== 'undefined';
184
+ const dragHandlers = draggableRow ? drag.dragProps(file.path, true) : {};
185
+ const isDragging = drag?.draggedPath === file.path;
186
+ const isBusy = drag?.busyPath === file.path;
187
+ // feature-file-tree-drag-drop-folders (Task 9) — the KEYBOARD path for
188
+ // "Move to…" (drag-only fails WCAG 2.1.1). Same eligibility as dragging.
189
+ const canMove = draggableRow && typeof menu !== 'undefined';
190
+ // Plan T17/L03 — a supporting file (notes, styles, images, media) in a
191
+ // canvas folder gets the same ⋯ menu: rename, move, delete.
192
+ const supporting = !isCanvas && !!pKind && !sidecar && typeof menu !== 'undefined';
193
+ const canShare = typeof menu !== 'undefined' && kind !== 'runtime';
194
+ const fileDir = file.path.split('/').slice(0, -1).join('/');
195
+ // Stable hook for the desktop E2E harness (data-testid convention — see the
196
+ // `desktop-e2e` skill): canvas rows only, slug derived from the relative path
197
+ // (e.g. `ui/Smoke.tsx` → `canvas-row-ui-smoke`).
198
+ const testId = isCanvas
199
+ ? 'canvas-row-' +
200
+ file.path
201
+ .replace(/^\.[^/]+\//, '') // strip the leading designRoot dot-folder (.design/)
202
+ .replace(CANVAS_EXT_RE, '')
203
+ .replace(/[^a-z0-9]+/gi, '-')
204
+ .toLowerCase()
205
+ .replace(/^-+|-+$/g, '')
206
+ : undefined;
207
+ const row = (
208
+ <button
209
+ type="button"
210
+ role="treeitem"
211
+ data-testid={testId ?? (supporting ? `file-row-${pathTestIdSlug(file.path)}` : undefined)}
212
+ aria-selected={isSel}
213
+ aria-disabled={inert ? 'true' : undefined}
214
+ aria-busy={isBusy || undefined}
215
+ tabIndex={isSel ? 0 : -1}
216
+ className={
217
+ 'st-row' +
218
+ (isSel ? ' is-sel' : '') +
219
+ (kind === 'runtime' ? ' is-muted' : '') +
220
+ (isDragging ? ' is-dragging' : '') +
221
+ (isBusy ? ' is-busy' : '')
222
+ }
223
+ style={{ paddingLeft: TREE_INDENT_BASE + depth * TREE_INDENT_STEP + 'px' }}
224
+ title={file.path + (oc ? ` — ${oc} open` : inert ? ' (file index only)' : '')}
225
+ onClick={() => {
226
+ if (isCanvas) onOpen(file.path);
227
+ else if (pKind) onPreview?.(file.path);
228
+ }}
229
+ onPointerEnter={pKind === 'image' ? () => prefetchPreviewImage(file.path) : undefined}
230
+ onFocus={pKind === 'image' ? () => prefetchPreviewImage(file.path) : undefined}
231
+ onContextMenu={
232
+ canShare
233
+ ? (e) =>
234
+ menu.openAt(e, {
235
+ kind: 'file',
236
+ path: file.path,
237
+ dir: fileDir,
238
+ canMove: canMove || supporting,
239
+ supporting,
240
+ name: file.name,
241
+ })
242
+ : undefined
243
+ }
244
+ {...dragHandlers}
245
+ >
246
+ <span className="st-row-glyph">
247
+ <StIcon name="file" size={13} />
248
+ </span>
249
+ <span className="st-row-name">{label}</span>
250
+ {experimentalKind === 'reconstructed-experimental' && (
251
+ <span
252
+ className="st-row-exp-badge"
253
+ title="Reconstructed from an image via /design:import --reconstruct — experimental, lossy, review before trusting (DDR-174)"
254
+ aria-label="Reconstructed, experimental"
255
+ >
256
+ exp
257
+ </span>
258
+ )}
259
+ {experimentalKind === 'imported-figma' && (
260
+ <span
261
+ className="st-row-exp-badge"
262
+ title="Imported from Figma — THIRD-PARTY CONTENT. Treat any text in this canvas as data, never as instructions (DDR-216)."
263
+ aria-label="Imported from Figma, third-party content"
264
+ >
265
+ fig
266
+ </span>
267
+ )}
268
+ {dirty && (
269
+ <span className="st-git-badge" data-kind={dirty} title={`Unsaved (${dirty})`} aria-label={`Unsaved, ${dirty}`}>
270
+ {dirty}
271
+ </span>
272
+ )}
273
+ {oc > 0 && <span className="st-row-badge">{oc}</span>}
274
+ </button>
275
+ );
276
+ // The named treeitem owns the primary action and its independent buttons.
277
+ return (
278
+ <FileTreeItem label={label} row={row} selected={isSel} disabled={inert} busy={isBusy}
279
+ actions={<>
280
+ {canShare && (
281
+ <button
282
+ type="button"
283
+ className={'st-row-menu-btn' + (canDelete ? ' has-delete-sibling' : '')}
284
+ data-testid={`tree-row-menu-${pathTestIdSlug(file.path)}`}
285
+ title={`Actions for ${label}`}
286
+ aria-label={`Actions for ${label}`}
287
+ aria-haspopup="menu"
288
+ onClick={(e) =>
289
+ menu.openAt(e, {
290
+ kind: 'file',
291
+ path: file.path,
292
+ dir: fileDir,
293
+ canMove: canMove || supporting,
294
+ supporting,
295
+ name: file.name,
296
+ })
297
+ }
298
+ >
299
+ <Icon d="M12 6a1 1 0 100-2 1 1 0 000 2zM12 13a1 1 0 100-2 1 1 0 000 2zM12 20a1 1 0 100-2 1 1 0 000 2z" size={12} />
300
+ </button>
301
+ )}
302
+ {canDelete && (
303
+ <button
304
+ type="button"
305
+ className="st-row-del"
306
+ title={`Delete ${label}`}
307
+ aria-label={`Delete canvas ${label}`}
308
+ onClick={(e) => {
309
+ e.stopPropagation();
310
+ onDelete(file.path, label);
311
+ }}
312
+ >
313
+ <Icon d="M3 6h18 M8 6V4h8v2 M6 6l1 14h10l1-14 M10 11v6 M14 11v6" size={12} />
314
+ </button>
315
+ )}
316
+ </>} />
317
+ );
318
+ }
319
+
320
+ export function CanvasRow({
321
+ primary,
322
+ sidecars,
323
+ depth,
324
+ kind,
325
+ activePath,
326
+ previewPath,
327
+ onOpen,
328
+ onPreview,
329
+ onDelete,
330
+ openCount: oc,
331
+ showHidden,
332
+ forceOpen,
333
+ dirtyByPath,
334
+ experimentalKind,
335
+ drag,
336
+ menu,
337
+ }) {
338
+ const dirty = dirtyByPath?.get(primary.path);
339
+ const hasSidecars = sidecars.length > 0;
340
+ const [openState, setOpenState] = useState(false);
341
+ // Sidecars are only revealed when the user opts in via `showHidden` — the
342
+ // chevron itself only appears in that mode. When `forceOpen` is true (search
343
+ // match in a sidecar), override local state so the user sees the hit.
344
+ const open = forceOpen || openState;
345
+ const isSel = primary.path === activePath;
346
+ const showChevron = hasSidecars && showHidden;
347
+ if (!showChevron) {
348
+ return (
349
+ <FileRow
350
+ file={primary}
351
+ activePath={activePath}
352
+ previewPath={previewPath}
353
+ onOpen={onOpen}
354
+ onPreview={onPreview}
355
+ onDelete={onDelete}
356
+ openCount={oc}
357
+ depth={depth}
358
+ kind={kind}
359
+ dirty={dirty}
360
+ experimentalKind={experimentalKind}
361
+ drag={drag}
362
+ menu={menu}
363
+ />
364
+ );
365
+ }
366
+ const draggableRow = typeof drag !== 'undefined';
367
+ const dragHandlers = draggableRow ? drag.dragProps(primary.path, true) : {};
368
+ const isDragging = drag?.draggedPath === primary.path;
369
+ const isBusy = drag?.busyPath === primary.path;
370
+ const canMove = draggableRow && typeof menu !== 'undefined';
371
+ const canShare = typeof menu !== 'undefined' && kind !== 'runtime';
372
+ const primaryDir = primary.path.split('/').slice(0, -1).join('/');
373
+ const row = (
374
+ <button
375
+ type="button"
376
+ role="treeitem"
377
+ aria-selected={isSel}
378
+ aria-expanded={open}
379
+ aria-busy={isBusy || undefined}
380
+ tabIndex={isSel ? 0 : -1}
381
+ className={
382
+ 'st-row st-canvas-row' +
383
+ (isSel ? ' is-sel' : '') +
384
+ (isDragging ? ' is-dragging' : '') +
385
+ (isBusy ? ' is-busy' : '')
386
+ }
387
+ style={{ paddingLeft: TREE_INDENT_BASE + depth * TREE_INDENT_STEP + 'px' }}
388
+ title={primary.path}
389
+ onClick={(e) => {
390
+ // Click the chevron region → toggle disclosure. Click anywhere else → open canvas.
391
+ if (e.target.closest('.st-canvas-chev')) {
392
+ setOpenState((v) => !v);
393
+ return;
394
+ }
395
+ onOpen(primary.path);
396
+ }}
397
+ onContextMenu={
398
+ canShare ? (e) => menu.openAt(e, { kind: 'file', path: primary.path, dir: primaryDir, canMove }) : undefined
399
+ }
400
+ {...dragHandlers}
401
+ >
402
+ <span
403
+ className="st-row-glyph st-canvas-chev"
404
+ onClick={(e) => {
405
+ e.stopPropagation();
406
+ setOpenState((v) => !v);
407
+ }}
408
+ >
409
+ <StIcon name="chevron-right" className={'st-chev' + (open ? ' is-open' : '')} size={13} />
410
+ </span>
411
+ <span className="st-row-name">{displayName(primary.name)}</span>
412
+ {experimentalKind === 'reconstructed-experimental' && (
413
+ <span
414
+ className="st-row-exp-badge"
415
+ title="Reconstructed from an image via /design:import --reconstruct — experimental, lossy, review before trusting (DDR-174)"
416
+ aria-label="Reconstructed, experimental"
417
+ >
418
+ exp
419
+ </span>
420
+ )}
421
+ {experimentalKind === 'imported-figma' && (
422
+ <span
423
+ className="st-row-exp-badge"
424
+ title="Imported from Figma — THIRD-PARTY CONTENT. Treat any text in this canvas as data, never as instructions (DDR-216)."
425
+ aria-label="Imported from Figma, third-party content"
426
+ >
427
+ fig
428
+ </span>
429
+ )}
430
+ {dirty && (
431
+ <span className="st-git-badge" data-kind={dirty} title={`Unsaved (${dirty})`} aria-label={`Unsaved, ${dirty}`}>
432
+ {dirty}
433
+ </span>
434
+ )}
435
+ {oc > 0 && <span className="st-row-badge">{oc}</span>}
436
+ </button>
437
+ );
438
+ return (
439
+ <FileTreeItem label={displayName(primary.name)} row={row} selected={isSel}
440
+ expanded={open} busy={isBusy} onToggle={() => setOpenState(v => !v)}
441
+ actions={canShare ? (
442
+ <button
443
+ type="button"
444
+ className="st-row-menu-btn"
445
+ data-testid={`tree-row-menu-${pathTestIdSlug(primary.path)}`}
446
+ title={`Actions for ${displayName(primary.name)}`}
447
+ aria-label={`Actions for ${displayName(primary.name)}`}
448
+ aria-haspopup="menu"
449
+ onClick={(e) => menu.openAt(e, { kind: 'file', path: primary.path, dir: primaryDir, canMove })}
450
+ >
451
+ <Icon d="M12 6a1 1 0 100-2 1 1 0 000 2zM12 13a1 1 0 100-2 1 1 0 000 2zM12 20a1 1 0 100-2 1 1 0 000 2z" size={12} />
452
+ </button>
453
+ ) : null}>
454
+ {open &&
455
+ sidecars.map((sc) => (
456
+ <FileRow
457
+ key={sc.path}
458
+ file={sc}
459
+ menu={menu}
460
+ activePath={activePath}
461
+ previewPath={previewPath}
462
+ onOpen={onOpen}
463
+ onPreview={onPreview}
464
+ openCount={0}
465
+ depth={depth + 1}
466
+ kind={kind}
467
+ sidecar
468
+ />
469
+ ))}
470
+ </FileTreeItem>
471
+ );
472
+ }
473
+
474
+ export function Tree({
475
+ node,
476
+ activePath,
477
+ previewPath,
478
+ onOpen,
479
+ onPreview,
480
+ commentsByFile,
481
+ depth = 1,
482
+ kind,
483
+ showHidden,
484
+ search,
485
+ dsFolders,
486
+ activeDsName,
487
+ onOpenSystem,
488
+ onDelete,
489
+ dirtyByPath,
490
+ canvasKinds,
491
+ // feature-file-tree-drag-drop-folders (Task 8) — `dirPath` accumulates this
492
+ // node's full path (starts at the group's `fullPath`) so a DirRow knows
493
+ // where to fs-move a drop TO; `drag` is the shared drag-bookkeeping bundle
494
+ // from useTreeDrag, undefined for groups that can't participate (DS).
495
+ dirPath = '',
496
+ drag,
497
+ // feature-file-tree-drag-drop-folders (Task 9) — the shared row-menu
498
+ // instance (useRowMenu()), undefined for groups that can't participate.
499
+ menu,
500
+ // Issue #124 — App-level folder disclosure `{ isOpen, setOpen }`.
501
+ expansion,
502
+ }) {
503
+ const dirs = Object.keys(node)
504
+ .filter((k) => k !== '_files')
505
+ .sort();
506
+ const files = node._files || [];
507
+ // VS Code-style sidecar grouping. Canvas (`.tsx`/`.html`) becomes the primary
508
+ // row; same-basename non-canvas files (`.meta.json`, `.css`, …) collapse
509
+ // under it. Meta/doc orphans (README.md, tokens.css, …) surface only when
510
+ // `showHidden` is on; media/asset orphans (images, fonts, video, audio —
511
+ // feature-studio-file-preview) are content the user asked to see by
512
+ // default, not sidecar noise, so they always render.
513
+ const { canvases, orphans } = useMemo(() => groupBySidecar(files), [files]);
514
+ const { mediaOrphans, metaOrphans } = useMemo(() => {
515
+ const media = [];
516
+ const meta = [];
517
+ for (const entry of orphans) {
518
+ const k = previewKind(entry.primary.name);
519
+ (k === 'image' || k === 'video' || k === 'audio' || k === 'font' ? media : meta).push(entry);
520
+ }
521
+ return { mediaOrphans: media, metaOrphans: meta };
522
+ }, [orphans]);
523
+ const hasSearch = !!(search && search.trim());
524
+ // DS-folder lookup: only meaningful at the top level of a DS group. The
525
+ // server emits `dsFolders: [{name, folder}, ...]` so the client knows which
526
+ // dir at depth=1 corresponds to a DS root (click → open SystemView).
527
+ const dsFolderByName = useMemo(() => {
528
+ if (!dsFolders || depth !== 1) return null;
529
+ const m = new Map();
530
+ for (const f of dsFolders) m.set(f.folder, f);
531
+ return m;
532
+ }, [dsFolders, depth]);
533
+ return (
534
+ <Fragment>
535
+ {canvases.map((entry) => {
536
+ const forceOpen =
537
+ hasSearch &&
538
+ entry.sidecars.some((sc) => {
539
+ const q = search.toLowerCase();
540
+ return sc.name.toLowerCase().includes(q) || sc.path.toLowerCase().includes(q);
541
+ });
542
+ return (
543
+ <CanvasRow
544
+ key={entry.primary.path}
545
+ primary={entry.primary}
546
+ sidecars={entry.sidecars}
547
+ activePath={activePath}
548
+ previewPath={previewPath}
549
+ onOpen={onOpen}
550
+ onPreview={onPreview}
551
+ onDelete={onDelete}
552
+ openCount={openCount(commentsByFile[entry.primary.path])}
553
+ depth={depth}
554
+ kind={kind}
555
+ showHidden={showHidden}
556
+ forceOpen={forceOpen}
557
+ dirtyByPath={dirtyByPath}
558
+ experimentalKind={canvasKinds?.[entry.primary.path]}
559
+ drag={drag}
560
+ menu={menu}
561
+ />
562
+ );
563
+ })}
564
+ {mediaOrphans.map((entry) => (
565
+ <FileRow
566
+ key={entry.primary.path}
567
+ file={entry.primary}
568
+ menu={menu}
569
+ activePath={activePath}
570
+ previewPath={previewPath}
571
+ onOpen={onOpen}
572
+ onPreview={onPreview}
573
+ openCount={openCount(commentsByFile[entry.primary.path])}
574
+ depth={depth}
575
+ kind={kind}
576
+ />
577
+ ))}
578
+ {showHidden &&
579
+ metaOrphans.map((entry) => (
580
+ <FileRow
581
+ key={entry.primary.path}
582
+ file={entry.primary}
583
+ menu={menu}
584
+ activePath={activePath}
585
+ previewPath={previewPath}
586
+ onOpen={onOpen}
587
+ onPreview={onPreview}
588
+ openCount={openCount(commentsByFile[entry.primary.path])}
589
+ depth={depth}
590
+ kind={kind}
591
+ />
592
+ ))}
593
+ {/* orphans are sidecars/loose files — no canvas to delete, so no onDelete/drag */}
594
+ {dirs.map((d) => {
595
+ const dsMatch = dsFolderByName?.get(d);
596
+ const childPath = dirPath ? `${dirPath}/${d}` : d;
597
+ const childTree = (
598
+ <Tree
599
+ node={node[d]}
600
+ activePath={activePath}
601
+ previewPath={previewPath}
602
+ onOpen={onOpen}
603
+ onPreview={onPreview}
604
+ commentsByFile={commentsByFile}
605
+ depth={depth + 1}
606
+ kind={kind}
607
+ showHidden={showHidden}
608
+ search={search}
609
+ activeDsName={activeDsName}
610
+ onOpenSystem={onOpenSystem}
611
+ onDelete={onDelete}
612
+ dirtyByPath={dirtyByPath}
613
+ canvasKinds={canvasKinds}
614
+ dirPath={childPath}
615
+ drag={drag}
616
+ menu={menu}
617
+ expansion={expansion}
618
+ />
619
+ );
620
+ if (dsMatch && onOpenSystem) {
621
+ return (
622
+ <DsFolderRow
623
+ key={d}
624
+ name={d}
625
+ dsName={dsMatch.name}
626
+ dirPath={childPath}
627
+ depth={depth}
628
+ expansion={expansion}
629
+ forceOpen={hasSearch}
630
+ active={activePath === SYSTEM_TAB && dsMatch.name === activeDsName}
631
+ onOpenSystem={onOpenSystem}
632
+ >
633
+ {childTree}
634
+ </DsFolderRow>
635
+ );
636
+ }
637
+ return (
638
+ <DirRow
639
+ key={d}
640
+ name={d}
641
+ depth={depth}
642
+ dirPath={childPath}
643
+ expansion={expansion}
644
+ forceOpen={hasSearch}
645
+ drag={drag}
646
+ menu={drag ? menu : undefined}
647
+ >
648
+ {childTree}
649
+ </DirRow>
650
+ );
651
+ })}
652
+ </Fragment>
653
+ );
654
+ }
655
+
656
+ // CV-08 section labels — title + optional SKU pill. The pill carries
657
+ // project / DS identity; the mock keeps these tight (1 line). Labels are
658
+ // keyed by the server-provided `kind` (PROJECT / DS / UI / RUNTIME).
659
+ export const SECTION_META = {
660
+ project: { title: 'PROJECT', pillFromCount: false },
661
+ // Design-system group: pill shows the number of DSes (one row per DS folder
662
+ // inside). Computed in Sidebar from `g.dsFolders.length`.
663
+ ds: { title: 'DESIGN SYSTEM', pillFromDsCount: true },
664
+ canvas: { title: 'UI CANVASES', pillFromCount: true },
665
+ runtime: { title: 'RUNTIME · GITIGNORED', pillFromCount: true },
666
+ };
667
+
668
+ export function sectionMetaFor(g) {
669
+ if (g.kind === 'project') return SECTION_META.project;
670
+ if (g.kind === 'runtime') return SECTION_META.runtime;
671
+ // canvas-kind groups: "Design system" → ds, anything else → canvas label
672
+ if (g.label === 'Design system') return SECTION_META.ds;
673
+ if (g.label === 'UI kit') return SECTION_META.canvas;
674
+ return { title: g.label.toUpperCase(), pillFromCount: true };
675
+ }
676
+
677
+ // The file tree before its first index arrives. A large project — above all a
678
+ // cloud one on a cold workspace — can take several seconds to list, and a blank
679
+ // panel reading "0 / 0" looks like an empty or broken project. Skeleton rows
680
+ // say "coming"; after a few seconds a line says why, and a failed attempt says
681
+ // it is being retried (the index loader retries on its own).
682
+ export function TreeLoading({ failures, cloud }) {
683
+ const [slow, setSlow] = useState(false);
684
+ useEffect(() => {
685
+ const t = setTimeout(() => setSlow(true), 3000);
686
+ return () => clearTimeout(t);
687
+ }, []);
688
+ const hint =
689
+ failures > 0
690
+ ? 'The project is taking a while to answer — trying again…'
691
+ : cloud
692
+ ? 'Still loading — a large cloud project can take a few seconds to list.'
693
+ : 'Still loading — a large project can take a few seconds to list.';
694
+ return (
695
+ <div className="st-tree-loading" role="status" aria-live="polite" data-testid="tree-loading">
696
+ <div className="st-tree-loading-head">
697
+ <span className="st-canvas-loading-spinner" aria-hidden="true" />
698
+ <span>Loading files…</span>
699
+ </div>
700
+ {[64, 48, 72, 40, 56, 68, 44].map((w, i) => (
701
+ <span
702
+ key={i}
703
+ className="skel st-tree-loading-row"
704
+ style={{ width: `${w}%`, marginLeft: i % 3 ? 22 : 8 }}
705
+ aria-hidden="true"
706
+ />
707
+ ))}
708
+ {(slow || failures > 0) && <div className="st-tree-loading-hint">{hint}</div>}
709
+ </div>
710
+ );
711
+ }
712
+
713
+ export function Sidebar({
714
+ // Cloud Phase 25 C2 — viewer role: create / delete / move / rename
715
+ // affordances are absent (buttons, composer, row menus, drag & drop).
716
+ readOnly = false,
717
+ /** `{ dashboardUrl?, projectName }` when this is a cloud tab, else null. */
718
+ // Tri-state (see the note where this value is created): `undefined` until
719
+ // the server config answers, `null` for the desktop, an object for a cloud
720
+ // tab. Defaulting it to `null` here is what re-broke the boot 404 after the
721
+ // call sites were fixed — a default fires on `undefined`, so "not known yet"
722
+ // became "not cloud" one layer further in, invisibly.
723
+ cloud,
724
+ groups,
725
+ activePath,
726
+ previewPath,
727
+ activeDsName,
728
+ onOpen,
729
+ onPreview,
730
+ onOpenSystem,
731
+ wsConnected,
732
+ search,
733
+ setSearch,
734
+ commentsByFile,
735
+ showHidden,
736
+ sectionsExpanded,
737
+ onToggleSection,
738
+ // Issue #124 — App-level folder disclosure `{ isOpen, setOpen }`.
739
+ treeExpansion,
740
+ onNewBoard,
741
+ onDeleteBoard,
742
+ onRefresh,
743
+ refreshing,
744
+ collapsed,
745
+ onCollapse,
746
+ width,
747
+ resizing,
748
+ dirtyByPath,
749
+ project,
750
+ gitBranch,
751
+ remoteSync,
752
+ onGetLatest,
753
+ canvasKinds,
754
+ onMoveCanvas,
755
+ onNewFolder,
756
+ onDeleteFolder,
757
+ onRenameFolder,
758
+ onRenameCanvas,
759
+ onDuplicateCanvas,
760
+ onDeleteFile,
761
+ // Passed through to CloudBar only — the live `sync:status` payload that makes
762
+ // the connect note follow the link instead of freezing at attach time.
763
+ syncStatus,
764
+ // Passed through to CloudBar only — lifts linkedHub changes to the app shell
765
+ // so the GitPanel's cloud-managed posture (DDR-218) reacts live.
766
+ onLinkedHub,
767
+ onLocalProject,
768
+ onOpenLinkedFile,
769
+ filesReady,
770
+ treeLoadFailures = 0,
771
+ onShare,
772
+ // feature-cloud-managed-git-posture — the widened DDR-218 gate, resolved once
773
+ // in App and handed down. Withdraws the drafts switcher: a local branch
774
+ // switch moves a HEAD the cell knows nothing about.
775
+ savingIsManaged = false,
776
+ }) {
777
+ const filteredGroups = useMemo(() => {
778
+ if (!search) return groups;
779
+ return groups.map((g) => ({ ...g, tree: filterTree(g.tree, search), filtered: !!search }));
780
+ }, [groups, search]);
781
+
782
+ // feature-file-tree-drag-drop-folders (Task 8) — one drag-bookkeeping
783
+ // instance shared by every group's Tree; `onMoveCanvas` does the actual
784
+ // fetch + tree refresh (App-level, alongside createBoard/deleteBoard).
785
+ const treeDrag = useTreeDrag(onMoveCanvas);
786
+
787
+ // feature-file-tree-drag-drop-folders (Task 9) — the keyboard path. One
788
+ // shared row-menu instance (only one row's menu is ever open); every
789
+ // non-DS canvas group folder (incl. each group's own root) is a valid
790
+ // "Move to…" destination.
791
+ const rowMenu = useRowMenu();
792
+ const destinations = useMemo(() => {
793
+ const out = [];
794
+ for (const g of groups) {
795
+ if (g.label === 'Design system' || g.kind !== 'canvas') continue;
796
+ const rootLabel = g.fullPath.replace(/^\.[^/]+\//, '') || g.fullPath;
797
+ out.push({ path: g.fullPath, label: rootLabel });
798
+ for (const d of g.dirs || []) {
799
+ out.push({ path: d, label: d.replace(/^\.[^/]+\//, '') });
800
+ }
801
+ }
802
+ return out;
803
+ }, [groups]);
804
+ const menuExtra = rowMenu.state?.extra;
805
+ const rowMenuRootItems =
806
+ menuExtra?.kind === 'file'
807
+ ? [
808
+ { id: 'share', label: 'Share…', onSelect: () => { rowMenu.close(); onShare(menuExtra.path); } },
809
+ ...(onRenameCanvas && /\.tsx$/i.test(menuExtra.path)
810
+ ? [
811
+ {
812
+ id: 'rename-canvas',
813
+ label: 'Rename…',
814
+ onSelect: () => {
815
+ rowMenu.close();
816
+ const current = displayName(menuExtra.path.split('/').pop());
817
+ const name = window.prompt('Rename canvas to:', current);
818
+ if (name?.trim() && name.trim() !== current) onRenameCanvas(menuExtra.path, name.trim());
819
+ },
820
+ },
821
+ ]
822
+ : []),
823
+ ...(onDuplicateCanvas && /\.tsx$/i.test(menuExtra.path)
824
+ ? [
825
+ {
826
+ id: 'duplicate-canvas',
827
+ label: 'Duplicate',
828
+ onSelect: () => {
829
+ rowMenu.close();
830
+ onDuplicateCanvas(menuExtra.path);
831
+ },
832
+ },
833
+ ]
834
+ : []),
835
+ // Plan T17/L03 — a supporting file renames as itself (the extension
836
+ // stays: a rename is not a conversion).
837
+ ...(menuExtra.supporting && onRenameCanvas
838
+ ? [
839
+ {
840
+ id: 'rename-file',
841
+ label: 'Rename…',
842
+ onSelect: () => {
843
+ rowMenu.close();
844
+ const n = menuExtra.name ?? menuExtra.path.split('/').pop();
845
+ const ext = n.includes('.') ? n.slice(n.lastIndexOf('.')) : '';
846
+ const current = ext ? n.slice(0, -ext.length) : n;
847
+ const name = window.prompt(`Rename ${n} to:`, current);
848
+ if (name?.trim() && name.trim() !== current) onRenameCanvas(menuExtra.path, name.trim());
849
+ },
850
+ },
851
+ ]
852
+ : []),
853
+ ...(menuExtra.canMove ? [{ id: 'move-to', label: 'Move to…', onSelect: () => rowMenu.showMoveTo() }] : []),
854
+ ...(menuExtra.supporting && onDeleteFile
855
+ ? [
856
+ {
857
+ id: 'delete-file',
858
+ label: 'Delete',
859
+ destructive: true,
860
+ onSelect: () => {
861
+ rowMenu.close();
862
+ onDeleteFile(menuExtra.path, menuExtra.name ?? menuExtra.path.split('/').pop());
863
+ },
864
+ },
865
+ ]
866
+ : []),
867
+ ]
868
+ : menuExtra?.kind === 'dir'
869
+ ? [
870
+ {
871
+ id: 'new-folder-here',
872
+ label: 'New folder here',
873
+ onSelect: () => {
874
+ rowMenu.close();
875
+ const name = window.prompt('New folder name:');
876
+ if (name?.trim()) onNewFolder(menuExtra.dirPath, name.trim());
877
+ },
878
+ },
879
+ {
880
+ id: 'rename-folder',
881
+ label: 'Rename folder',
882
+ onSelect: () => {
883
+ rowMenu.close();
884
+ const current = menuExtra.dirPath.split('/').pop();
885
+ const name = window.prompt('Rename folder to:', current);
886
+ if (name?.trim() && name.trim() !== current) onRenameFolder(menuExtra.dirPath, name.trim());
887
+ },
888
+ },
889
+ {
890
+ id: 'delete-folder',
891
+ label: 'Delete folder',
892
+ destructive: true,
893
+ onSelect: () => {
894
+ rowMenu.close();
895
+ onDeleteFolder(menuExtra.dirPath, menuExtra.dirPath.split('/').pop());
896
+ },
897
+ },
898
+ ]
899
+ : [];
900
+ const rowMenuDestinations =
901
+ menuExtra?.kind === 'file' || menuExtra?.kind === 'supporting'
902
+ ? destinations.filter((d) => d.path !== menuExtra.dir)
903
+ : [];
904
+
905
+ // Phase 22 — inline "new brief board" composer in the tree header. Click +,
906
+ // type a name, Enter to create (Esc cancels). The board opens active so it's
907
+ // ready to annotate; generation (ingest) still goes through /design:new.
908
+ // feature-file-tree-drag-drop-folders (Task 12) — the SAME composer, in
909
+ // 'folder' mode, backs the header "New folder" button — the plan's
910
+ // InlineComposer intent (one composer, two submit paths) without a full
911
+ // component extraction: `composerMode` picks the placeholder + handler.
912
+ const [creating, setCreating] = useState(false);
913
+ const [composerMode, setComposerMode] = useState('board');
914
+ const [newName, setNewName] = useState('');
915
+ const [newErr, setNewErr] = useState('');
916
+ const [newBusy, setNewBusy] = useState(false);
917
+
918
+ // Default folder-creation target: the first non-DS canvas group's root
919
+ // (mirrors the server's own `newCanvasDir` default for board creation).
920
+ const defaultFolderParent = useMemo(
921
+ () => groups.find((g) => g.kind === 'canvas' && g.label !== 'Design system')?.fullPath,
922
+ [groups]
923
+ );
924
+
925
+ const submitComposer = useCallback(async () => {
926
+ const name = newName.trim();
927
+ if (!name || newBusy) return;
928
+ setNewBusy(true);
929
+ setNewErr('');
930
+ if (composerMode === 'folder') {
931
+ if (!defaultFolderParent) {
932
+ setNewBusy(false);
933
+ setNewErr('no canvas group to create a folder in');
934
+ return;
935
+ }
936
+ const res = await onNewFolder(defaultFolderParent, name);
937
+ setNewBusy(false);
938
+ if (res?.ok) {
939
+ setCreating(false);
940
+ setNewName('');
941
+ } else {
942
+ setNewErr(res?.error || 'could not create folder');
943
+ }
944
+ return;
945
+ }
946
+ const res = await onNewBoard(name);
947
+ setNewBusy(false);
948
+ if (res?.ok) {
949
+ setCreating(false);
950
+ setNewName('');
951
+ } else {
952
+ setNewErr(res?.error || 'could not create board');
953
+ }
954
+ }, [newName, newBusy, onNewBoard, onNewFolder, composerMode, defaultFolderParent]);
955
+
956
+ // Mock uses `42 / 42` — total openable canvases, not every listed file.
957
+ // We count canvas files (TSX Phase 3.6+ default, HTML legacy) so the counter
958
+ // matches "canvases you can mount".
959
+ const htmlCount = useMemo(() => {
960
+ let total = 0;
961
+ for (const g of groups) for (const p of g.paths || []) if (CANVAS_EXT_RE.test(p)) total++;
962
+ return total;
963
+ }, [groups]);
964
+ const htmlShown = useMemo(() => {
965
+ let total = 0;
966
+ for (const g of filteredGroups)
967
+ for (const p of g.paths || []) if (CANVAS_EXT_RE.test(p)) total++;
968
+ return total;
969
+ }, [filteredGroups]);
970
+
971
+ return (
972
+ <nav
973
+ className={'st-sidebar' + (collapsed ? ' is-collapsed' : '') + (resizing ? ' is-resizing' : '')}
974
+ style={collapsed || !width ? undefined : { width, flexBasis: width }}
975
+ aria-label="Files"
976
+ data-tour="sidebar"
977
+ >
978
+ <div className="st-sb-hd">
979
+ <span className="st-sb-title">Files</span>
980
+ <div className="st-sb-hd-actions">
981
+ {!readOnly && (
982
+ <button
983
+ type="button"
984
+ className="st-iconbtn"
985
+ data-tip="New blank brief board"
986
+ aria-label="New blank brief board"
987
+ aria-expanded={creating && composerMode === 'board'}
988
+ onClick={() => {
989
+ setNewErr('');
990
+ setComposerMode('board');
991
+ setCreating((v) => (composerMode === 'board' ? !v : true));
992
+ }}
993
+ >
994
+ <StIcon name="plus" size={15} />
995
+ </button>
996
+ )}
997
+ {!readOnly && defaultFolderParent && (
998
+ <button
999
+ type="button"
1000
+ className="st-iconbtn"
1001
+ data-tip="New folder"
1002
+ aria-label="New folder"
1003
+ data-testid="tree-new-folder"
1004
+ aria-expanded={creating && composerMode === 'folder'}
1005
+ onClick={() => {
1006
+ setNewErr('');
1007
+ setComposerMode('folder');
1008
+ setCreating((v) => (composerMode === 'folder' ? !v : true));
1009
+ }}
1010
+ >
1011
+ <StIcon name="folder-plus" size={15} />
1012
+ </button>
1013
+ )}
1014
+ {onRefresh && (
1015
+ <button
1016
+ type="button"
1017
+ className={'st-iconbtn st-refresh' + (refreshing ? ' is-spinning' : '')}
1018
+ data-tip="Refresh files · ⇧⌘R"
1019
+ aria-label="Refresh files"
1020
+ aria-busy={refreshing || undefined}
1021
+ disabled={refreshing}
1022
+ onClick={() => onRefresh()}
1023
+ >
1024
+ <StIcon name="reload" size={15} />
1025
+ </button>
1026
+ )}
1027
+ <span
1028
+ className="st-live"
1029
+ data-tip={wsConnected ? 'live · file index synced' : 'reconnecting…'}
1030
+ >
1031
+ <span className={'st-live-dot' + (wsConnected ? ' is-connected' : '')} aria-hidden="true" />
1032
+ {htmlShown} / {htmlCount}
1033
+ </span>
1034
+ {onCollapse && (
1035
+ <button
1036
+ type="button"
1037
+ className="st-iconbtn"
1038
+ aria-label="Collapse sidebar"
1039
+ data-tip="Collapse sidebar · T"
1040
+ onClick={onCollapse}
1041
+ >
1042
+ <StIcon name="panel-left" size={15} />
1043
+ </button>
1044
+ )}
1045
+ </div>
1046
+ </div>
1047
+
1048
+ {creating ? (
1049
+ <div className="st-newboard">
1050
+ <input
1051
+ type="text"
1052
+ // biome-ignore lint/a11y/noAutofocus: deliberate — the composer opens on an explicit click.
1053
+ autoFocus
1054
+ placeholder={composerMode === 'folder' ? 'folder name…' : 'brief board name…'}
1055
+ value={newName}
1056
+ maxLength={60}
1057
+ disabled={newBusy}
1058
+ aria-label={composerMode === 'folder' ? 'New folder name' : 'New brief board name'}
1059
+ onChange={(e) => setNewName(e.target.value)}
1060
+ onKeyDown={(e) => {
1061
+ if (e.key === 'Enter') {
1062
+ e.preventDefault();
1063
+ submitComposer();
1064
+ } else if (e.key === 'Escape') {
1065
+ e.preventDefault();
1066
+ setCreating(false);
1067
+ setNewName('');
1068
+ setNewErr('');
1069
+ }
1070
+ }}
1071
+ />
1072
+ <button
1073
+ type="button"
1074
+ className="st-newboard-go"
1075
+ disabled={newBusy || !newName.trim()}
1076
+ data-tip="Create · Enter"
1077
+ aria-label={composerMode === 'folder' ? 'Create folder' : 'Create brief board'}
1078
+ onClick={submitComposer}
1079
+ >
1080
+ {newBusy ? '…' : '↵'}
1081
+ </button>
1082
+ </div>
1083
+ ) : null}
1084
+ {newErr ? (
1085
+ <div className="st-newboard-err" role="alert">
1086
+ {newErr}
1087
+ </div>
1088
+ ) : null}
1089
+
1090
+ <div className="st-search">
1091
+ <div className="st-search-box">
1092
+ <StIcon name="search" size={13} />
1093
+ <input
1094
+ type="search"
1095
+ data-testid="canvas-search"
1096
+ placeholder="Search canvases…"
1097
+ value={search}
1098
+ onChange={(e) => setSearch(e.target.value)}
1099
+ onKeyDown={(e) => {
1100
+ // Esc — clear the filter first; a second Esc leaves the field.
1101
+ if (e.key === 'Escape') {
1102
+ e.preventDefault();
1103
+ if (search) setSearch('');
1104
+ else e.currentTarget.blur();
1105
+ }
1106
+ }}
1107
+ aria-label="Filter files"
1108
+ />
1109
+ {search ? (
1110
+ <button
1111
+ className="st-search-clear"
1112
+ onClick={() => setSearch('')}
1113
+ data-tip="Clear · Esc"
1114
+ aria-label="Clear search"
1115
+ >
1116
+ ×
1117
+ </button>
1118
+ ) : (
1119
+ <Kbd>/</Kbd>
1120
+ )}
1121
+ </div>
1122
+ </div>
1123
+
1124
+ {!filesReady && <TreeLoading failures={treeLoadFailures} cloud={cloud} />}
1125
+ <FileTree aria-label="Project file tree" data-testid="canvas-list">
1126
+ {filteredGroups.map((g) => {
1127
+ // Hide gitignored runtime / orphan-only project sections by default.
1128
+ // Active search overrides — if the user typed a query, they want hits
1129
+ // wherever they live.
1130
+ if (!showHidden && !search && g.kind === 'runtime') return null;
1131
+ const meta = sectionMetaFor(g);
1132
+ // Counter pill counts canvases only — sidecars + orphans inflate the
1133
+ // raw `paths.length` and the FILES header already filters this way.
1134
+ const canvasCount = (g.paths || []).filter((p) => CANVAS_EXT_RE.test(p)).length;
1135
+ const pill =
1136
+ meta.pill ||
1137
+ (meta.pillFromDsCount ? String(g.dsFolders?.length || 0) : null) ||
1138
+ (meta.pillFromCount ? String(canvasCount || g.paths?.length || 0) : null);
1139
+ const hasItems = g.tree && Object.keys(g.tree).length > 0;
1140
+ const isDs = g.label === 'Design system';
1141
+ const isProject = g.kind === 'project';
1142
+ // Project section: when showHidden is off, every row inside is an
1143
+ // orphan (.md / .json / .css) → empty body. Skip the header in that
1144
+ // case so the sidebar doesn't show "PROJECT" with nothing under it.
1145
+ if (!showHidden && !search && isProject && canvasCount === 0) return null;
1146
+ const defaultOpen = sectionDefaultOpen(g);
1147
+ const explicit = sectionsExpanded[g.label];
1148
+ // Active search forces every section open so hits aren't hidden.
1149
+ const sectionOpen = !!search || (explicit === undefined ? defaultOpen : explicit);
1150
+ // feature-file-tree-drag-drop-folders (dogfood follow-up) — the
1151
+ // section header IS the drop target for "move back to this group's
1152
+ // root". Without this a canvas inside a folder could never return
1153
+ // to the top level via drag & drop — DirRow only covers actual
1154
+ // subfolders, never the group root itself.
1155
+ const canDropOnRoot = !isDs && g.kind === 'canvas' && !readOnly;
1156
+ const rootDropHandlers = canDropOnRoot ? treeDrag.dropProps(g.fullPath, true) : {};
1157
+ const isRootOver = treeDrag.overDir === g.fullPath;
1158
+ return (
1159
+ <FileTreeItem className="st-tree-section" key={g.label} label={meta.title}
1160
+ expanded={sectionOpen} onToggle={() => onToggleSection(g.label, defaultOpen)} row={
1161
+ <button
1162
+ type="button"
1163
+ className={'st-tree-sec-hd' + (isRootOver ? ' is-drop-target' : '')}
1164
+ data-testid={`tree-section-${g.label.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`}
1165
+ onClick={() => onToggleSection(g.label, defaultOpen)}
1166
+ aria-expanded={sectionOpen}
1167
+ aria-dropeffect={canDropOnRoot ? 'move' : undefined}
1168
+ title={sectionOpen ? 'Collapse section' : 'Expand section'}
1169
+ {...rootDropHandlers}
1170
+ >
1171
+ <StIcon name="chevron-right" className={'st-chev' + (sectionOpen ? ' is-open' : '')} size={13} />
1172
+ <span className="st-sec-name">{meta.title}</span>
1173
+ {pill && <span className="st-pill">{pill}</span>}
1174
+ </button>}>
1175
+ {sectionOpen &&
1176
+ (hasItems ? (
1177
+ <Tree
1178
+ node={g.tree}
1179
+ activePath={activePath}
1180
+ previewPath={previewPath}
1181
+ onOpen={onOpen}
1182
+ onPreview={onPreview}
1183
+ commentsByFile={commentsByFile}
1184
+ depth={1}
1185
+ kind={g.kind}
1186
+ showHidden={showHidden}
1187
+ search={search}
1188
+ dsFolders={g.dsFolders}
1189
+ activeDsName={activeDsName}
1190
+ onOpenSystem={isDs ? onOpenSystem : undefined}
1191
+ onDelete={isDs || readOnly ? undefined : onDeleteBoard}
1192
+ dirtyByPath={dirtyByPath}
1193
+ canvasKinds={canvasKinds}
1194
+ dirPath={g.fullPath}
1195
+ drag={!isDs && g.kind === 'canvas' && !readOnly ? treeDrag : undefined}
1196
+ menu={rowMenu}
1197
+ expansion={treeExpansion}
1198
+ />
1199
+ ) : (
1200
+ <div className="st-tree-empty">{search ? 'No matches.' : 'Empty.'}</div>
1201
+ ))}
1202
+ </FileTreeItem>
1203
+ );
1204
+ })}
1205
+ </FileTree>
1206
+ <TreeRowMenu
1207
+ state={rowMenu.state}
1208
+ onClose={rowMenu.close}
1209
+ rootItems={rowMenuRootItems}
1210
+ destinations={rowMenuDestinations}
1211
+ onPickDestination={(dest) => onMoveCanvas(menuExtra.path, dest)}
1212
+ />
1213
+ {/* Phase 29 (E4) — the project + draft switcher: a compact one-line dock that
1214
+ opens UPWARD, sitting directly above the GitHub identity avatar so the two
1215
+ form one bottom dock. Renders nothing until the project is a git repo.
1216
+
1217
+ WITHDRAWN while somebody else is committing (feature-cloud-managed-git-
1218
+ posture). A draft is a local branch, and switching one moves a HEAD the
1219
+ cell knows nothing about — it would rewrite the working tree under a
1220
+ project whose history is being written elsewhere. Same
1221
+ presentation-not-a-control rule as the rest of DDR-218: `/_api/git/branch`
1222
+ and `/_api/git/checkout` keep exactly their old gates, and a terminal
1223
+ `git checkout` still works (and still flushes into Yjs via DDR-051's
1224
+ watcher). Absent, not disabled — there is nothing to explain here. */}
1225
+ {/* Plan T22 — withdrawn means the BRANCH half. A managed project still
1226
+ needs the way to another project, so the dock stays, project-only. */}
1227
+ <RepoBranchSwitcher project={project} liveBranch={gitBranch} remoteSync={remoteSync} onGetLatest={onGetLatest} projectOnly={savingIsManaged} />
1228
+ {/* Cloud Phase 23 C3 — Maude Cloud sign-in + remote-project attach, docked
1229
+ above the GitHub identity. Dev-server-backed, so it works in the desktop
1230
+ shell AND a plain browser. */}
1231
+ {/* Cloud Phase 27 — "Sign in to Maude Cloud" is an offer to do the thing
1232
+ you have already done: you reached this tab THROUGH a Maude account.
1233
+ Absent rather than disabled, because unlike the agent chat there is
1234
+ nothing here to explain — the capability is not missing, it is
1235
+ already satisfied. */}
1236
+ {cloud === null ? <CloudBar syncStatus={syncStatus} onLinkedHub={onLinkedHub} onLocalProject={onLocalProject} onOpenFile={onOpenLinkedFile} filesReady={filesReady} /> : null}
1237
+ {/* Phase 28 (E3) — GitHub identity as a compact avatar docked at the BOTTOM:
1238
+ sign in, connected account + New/Pull/Share, sign out. Self-contained
1239
+ (owns its device-code + CreateProject dialogs). Renders nothing in browser. */}
1240
+ <IdentityBar />
1241
+ </nav>
1242
+ );
1243
+ }