@1agh/maude 2.0.6 → 2.0.8
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.
- package/apps/studio/access/closure.ts +156 -16
- package/apps/studio/access/filters.ts +27 -0
- package/apps/studio/actions/agents.ts +54 -0
- package/apps/studio/actions/ctx.ts +3 -0
- package/apps/studio/actions/defs/sync.ts +13 -0
- package/apps/studio/actions/defs/view.ts +59 -3
- package/apps/studio/actions/keymap.gen.ts +35 -0
- package/apps/studio/actions/menu.ts +2 -0
- package/apps/studio/actions/types.ts +3 -1
- package/apps/studio/actions.manifest.json +136 -1
- package/apps/studio/actions.parity.json +25 -1
- package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
- package/apps/studio/annotations/ui/ride.ts +2 -1
- package/apps/studio/annotations-context-toolbar.tsx +5 -4
- package/apps/studio/annotations-layer.tsx +4 -3
- package/apps/studio/api.ts +383 -128
- package/apps/studio/artboard-activity-overlay.tsx +4 -4
- package/apps/studio/artboard-ai-copies.tsx +4 -4
- package/apps/studio/artboard-freeze.ts +108 -0
- package/apps/studio/artboard-live-gate.tsx +414 -45
- package/apps/studio/artboard-live.ts +526 -31
- package/apps/studio/artboard-placeholder.ts +197 -0
- package/apps/studio/artboard-still-raster.ts +485 -0
- package/apps/studio/artboard-still-warmup.ts +221 -0
- package/apps/studio/artboard-still.ts +1188 -0
- package/apps/studio/artboard-webgl.ts +2 -1
- package/apps/studio/asset-placeholder.tsx +237 -132
- package/apps/studio/asset-upload-bars.tsx +4 -4
- package/apps/studio/bin/_perf-probe-open.mjs +364 -0
- package/apps/studio/bin/_perf-shared.mjs +12 -7
- package/apps/studio/bin/_pw-launch.mjs +26 -1
- package/apps/studio/bin/perf.sh +19 -0
- package/apps/studio/bridge/dgn-protocol.ts +35 -0
- package/apps/studio/canvas-build-sandbox.ts +69 -13
- package/apps/studio/canvas-camera.ts +90 -0
- package/apps/studio/canvas-comment-mount.tsx +9 -9
- package/apps/studio/canvas-lib.tsx +160 -34
- package/apps/studio/canvas-pages-view.tsx +465 -0
- package/apps/studio/canvas-pages.ts +305 -0
- package/apps/studio/canvas-rows.ts +62 -0
- package/apps/studio/canvas-shell.tsx +62 -16
- package/apps/studio/canvas-theme-icons.tsx +41 -0
- package/apps/studio/canvas-theme-pill.tsx +15 -6
- package/apps/studio/canvas-theme.ts +12 -11
- package/apps/studio/client/app.jsx +7 -0
- package/apps/studio/client/canvas-url.js +23 -1
- package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
- package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
- package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
- package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
- package/apps/studio/client/hooks/use-project-data.jsx +11 -2
- package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
- package/apps/studio/client/index-loader.ts +41 -21
- package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
- package/apps/studio/client/shell/viewport.jsx +32 -16
- package/apps/studio/client/tree/tree.jsx +17 -0
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +7 -3
- package/apps/studio/client/v2/code/canvas-imports-words.js +16 -0
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
- package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
- package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
- package/apps/studio/client/v2/code/code-consent.js +67 -0
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
- package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
- package/apps/studio/client/v2/layers/layers-request.js +49 -0
- package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
- package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
- package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
- package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +40 -5
- package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
- package/apps/studio/client/v2/shell/floating-panels.css +37 -1
- package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
- package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
- package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
- package/apps/studio/client/v2/shell/pages-pick.js +49 -0
- package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +3 -1
- package/apps/studio/client/v2/shell/shell-parity.json +8 -0
- package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
- package/apps/studio/comments-overlay.tsx +12 -11
- package/apps/studio/config-reload-wire.ts +4 -1
- package/apps/studio/config.schema.json +6 -0
- package/apps/studio/context.ts +37 -1
- package/apps/studio/dist/client.bundle.js +720 -720
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/board.css +6 -0
- package/apps/studio/ds/board/ds-bar.tsx +21 -3
- package/apps/studio/ds/board/specimen.tsx +6 -3
- package/apps/studio/ds/board/template.ts +39 -19
- package/apps/studio/ds/cli.ts +7 -1
- package/apps/studio/ds/component-list.ts +2 -1
- package/apps/studio/ds/default.ts +6 -1
- package/apps/studio/ds/ds-resolver.ts +58 -8
- package/apps/studio/ds/engine.ts +3 -1
- package/apps/studio/ds/folder-systems.ts +199 -0
- package/apps/studio/ds/pairing-css.ts +2 -1
- package/apps/studio/ds/rename.ts +10 -3
- package/apps/studio/ds/shell-fallbacks.ts +2 -1
- package/apps/studio/ds/upgrade-stage.ts +6 -2
- package/apps/studio/editing/ai-point-ring.tsx +4 -4
- package/apps/studio/editing/ai-scope-outline.tsx +4 -4
- package/apps/studio/editing/align-bar.tsx +4 -4
- package/apps/studio/editing/anchor-report.ts +3 -2
- package/apps/studio/editing/artboard-handles.tsx +4 -4
- package/apps/studio/editing/corner-dots.tsx +4 -4
- package/apps/studio/editing/crop-mode.tsx +4 -4
- package/apps/studio/editing/drop-chip.tsx +4 -4
- package/apps/studio/editing/empty-report.ts +3 -2
- package/apps/studio/editing/focus-model.tsx +4 -4
- package/apps/studio/editing/gap-bands.tsx +3 -3
- package/apps/studio/editing/hold-rings.tsx +4 -4
- package/apps/studio/editing/lock-badge.tsx +3 -3
- package/apps/studio/editing/long-page.ts +23 -1
- package/apps/studio/editing/nudge.tsx +2 -2
- package/apps/studio/editing/page-activity.ts +4 -3
- package/apps/studio/editing/paste-bar.tsx +4 -4
- package/apps/studio/editing/pen/overlay.tsx +4 -3
- package/apps/studio/editing/place-freely.tsx +3 -3
- package/apps/studio/editing/reorder-slot.tsx +3 -3
- package/apps/studio/editing/selection.tsx +4 -4
- package/apps/studio/editing/size-ghost.tsx +4 -4
- package/apps/studio/editing/tab-order.tsx +4 -4
- package/apps/studio/editing/text-in-place.tsx +4 -4
- package/apps/studio/editing/undo-preview.tsx +3 -3
- package/apps/studio/equal-spacing-handles.tsx +3 -3
- package/apps/studio/frame-clock.ts +89 -0
- package/apps/studio/http.ts +66 -32
- package/apps/studio/index/ds-usage.ts +4 -1
- package/apps/studio/index-cache.ts +272 -0
- package/apps/studio/inspect-overlay.tsx +4 -3
- package/apps/studio/inspect.ts +7 -2
- package/apps/studio/link-chip-overlay.tsx +4 -3
- package/apps/studio/measure-overlay.tsx +4 -3
- package/apps/studio/present/pointer-dot.tsx +3 -2
- package/apps/studio/present/present-media.ts +6 -2
- package/apps/studio/present/present-stage.tsx +3 -2
- package/apps/studio/preview/preview-camera.tsx +3 -2
- package/apps/studio/routes/sync.ts +176 -0
- package/apps/studio/safe-zones-overlay.tsx +3 -2
- package/apps/studio/skip-dirs.ts +103 -47
- package/apps/studio/studio-page-host.ts +70 -0
- package/apps/studio/sync/code-module-consent.ts +86 -0
- package/apps/studio/sync/file-ledger.ts +24 -0
- package/apps/studio/sync/file-plane.ts +458 -53
- package/apps/studio/sync/held-deletes.ts +230 -0
- package/apps/studio/sync/hubs-config.ts +59 -2
- package/apps/studio/sync/index.ts +99 -15
- package/apps/studio/sync/seed-progress.ts +92 -2
- package/apps/studio/sync/settings.ts +36 -1
- package/apps/studio/sync/status.ts +15 -1
- package/apps/studio/sync/writer-registry.ts +5 -0
- package/apps/studio/text-caret.ts +5 -3
- package/apps/studio/toolbars/toolbar-rect.ts +3 -2
- package/apps/studio/use-annotation-resize.tsx +4 -3
- package/apps/studio/use-artboard-drag.tsx +3 -2
- package/apps/studio/use-element-resize.tsx +7 -6
- package/apps/studio/use-grid-track-handles.tsx +5 -4
- package/apps/studio/use-selection-set.tsx +64 -4
- package/apps/studio/use-spacing-handles.tsx +7 -6
- package/apps/studio/video-comp.tsx +55 -42
- package/apps/studio/video-play-overlay.tsx +4 -3
- package/apps/studio/whats-new.json +27 -0
- package/cli/commands/design.mjs +5 -2
- package/cli/commands/hub.mjs +10 -1
- package/cli/lib/bash-guard.mjs +14 -0
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-link.mjs +42 -17
- package/cli/lib/hub-purge.mjs +183 -0
- package/package.json +8 -8
- package/plugins/design/templates/_shell.html +164 -1
package/apps/studio/api.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Returns plain objects; http.ts wraps them in Response.json().
|
|
3
3
|
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
|
-
import { type Dirent, existsSync, renameSync } from 'node:fs';
|
|
5
|
+
import { type Dirent, existsSync, lstatSync, readdirSync, renameSync } from 'node:fs';
|
|
6
6
|
import {
|
|
7
7
|
lstat,
|
|
8
8
|
mkdir,
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
type OpResult,
|
|
65
65
|
} from './comments/ops.ts';
|
|
66
66
|
import { trashFolderDsCanvas } from './ds/convert.ts';
|
|
67
|
+
import { folderSystemOf } from './ds/ds-resolver.ts';
|
|
67
68
|
import { DS_CANVAS } from './ds/engine.ts';
|
|
68
69
|
import { readHead } from './ds/head.ts';
|
|
69
70
|
import { dsRenderIndex } from './ds/render-rev.ts';
|
|
@@ -150,6 +151,17 @@ import {
|
|
|
150
151
|
sanitizeReuseText,
|
|
151
152
|
} from './generation/audio-library.ts';
|
|
152
153
|
import { createHistory } from './history.ts';
|
|
154
|
+
import { pidOf, projectDir } from './index/snapshot.ts';
|
|
155
|
+
import {
|
|
156
|
+
CANVAS_INDEX_SEED_DEBOUNCE_MS,
|
|
157
|
+
CANVAS_INDEX_WRITE_EVENTS,
|
|
158
|
+
type CanvasIndexPart,
|
|
159
|
+
createIndexCache,
|
|
160
|
+
isRootRuntimeRel,
|
|
161
|
+
readCanvasIndexSeed,
|
|
162
|
+
writeCanvasIndexSeed,
|
|
163
|
+
yieldToLoop,
|
|
164
|
+
} from './index-cache.ts';
|
|
153
165
|
import { createSingleFlight } from './index-flight.ts';
|
|
154
166
|
import { clearLocatorSlug, readLocator, writeLocator } from './locator.ts';
|
|
155
167
|
import { listMaterializable } from './materialize-client.ts';
|
|
@@ -325,24 +337,26 @@ export async function findFiles(
|
|
|
325
337
|
exts: string[],
|
|
326
338
|
dirsOut?: string[]
|
|
327
339
|
): Promise<string[]> {
|
|
328
|
-
const out: string[] = [];
|
|
329
340
|
let entries: Dirent[];
|
|
330
341
|
try {
|
|
331
342
|
entries = await readdir(absRoot, { withFileTypes: true });
|
|
332
343
|
} catch {
|
|
333
|
-
return
|
|
344
|
+
return [];
|
|
334
345
|
}
|
|
335
346
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
347
|
+
// 2.0.7 (#207) — a folder's files are `lstat`-ed together, not one await after another: on an
|
|
348
|
+
// 11k-file project the serial awaits alone held `/_index-data` seconds whenever the server was
|
|
349
|
+
// busy. Order is unchanged (each entry keeps its slot; folders are walked in the same order).
|
|
350
|
+
const slots: Array<string[] | Promise<string | null>> = [];
|
|
336
351
|
for (const e of entries) {
|
|
337
|
-
|
|
338
|
-
if (
|
|
339
|
-
if (SKIP_DIRS.has(e.name)) continue;
|
|
352
|
+
const kind = findFilesEntry(e, exts);
|
|
353
|
+
if (!kind) continue;
|
|
340
354
|
const full = path.join(absRoot, e.name);
|
|
341
355
|
const rel = path.posix.join(prefix, e.name);
|
|
342
|
-
if (
|
|
356
|
+
if (kind === 'dir') {
|
|
343
357
|
dirsOut?.push(rel);
|
|
344
|
-
|
|
345
|
-
} else
|
|
358
|
+
slots.push(await findFiles(full, rel, exts, dirsOut));
|
|
359
|
+
} else {
|
|
346
360
|
// feature-studio-file-preview security review — `e.isFile()` (not just
|
|
347
361
|
// "not a directory") excludes symlinks: a symlink Dirent is neither
|
|
348
362
|
// isDirectory() nor isFile(), so without this check a symlink dropped
|
|
@@ -359,14 +373,72 @@ export async function findFiles(
|
|
|
359
373
|
// legitimately multiply-linked, so excluding them closes the same
|
|
360
374
|
// one-click-disclosure path for a hardlink planted at, say, a
|
|
361
375
|
// teammate's readable dotfile.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
376
|
+
slots.push(
|
|
377
|
+
lstat(full).then(
|
|
378
|
+
(st) => (singlyLinked(st) ? rel : null),
|
|
379
|
+
() => null
|
|
380
|
+
)
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const out: string[] = [];
|
|
385
|
+
for (const slot of slots) {
|
|
386
|
+
if (Array.isArray(slot)) {
|
|
387
|
+
for (const f of slot) out.push(f);
|
|
388
|
+
continue;
|
|
369
389
|
}
|
|
390
|
+
const rel = await slot;
|
|
391
|
+
if (rel !== null) out.push(rel);
|
|
392
|
+
}
|
|
393
|
+
return out;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** What `findFiles` does with one directory entry: walk it, list it (after the link check), or skip it. */
|
|
397
|
+
function findFilesEntry(e: Dirent, exts: readonly string[]): 'dir' | 'file' | null {
|
|
398
|
+
if (e.name.startsWith('.') && !HIDDEN_OK.has(e.name)) return null;
|
|
399
|
+
if (e.name.startsWith('_')) return null;
|
|
400
|
+
if (SKIP_DIRS.has(e.name)) return null;
|
|
401
|
+
if (e.isDirectory()) return 'dir';
|
|
402
|
+
// `isFile()` excludes symlinks (see findFiles)
|
|
403
|
+
if (e.isFile() && exts.some((x) => e.name.toLowerCase().endsWith(x))) return 'file';
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
/** A hardlinked file (`nlink > 1`) is never listed (see findFiles). */
|
|
407
|
+
const singlyLinked = (st: { nlink: number }) => st.nlink <= 1;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* #207 (list speed) — `findFiles` in one go: the same entries, skips, link check and order, without
|
|
411
|
+
* an await per folder and per file. The tree's first answer walks this way: StudyFi's 109 folders and
|
|
412
|
+
* 1.5k files take ~20 ms, where the awaited walk gave the loop away ~1.7k times and, on a server busy
|
|
413
|
+
* right after boot, took most of a second.
|
|
414
|
+
*/
|
|
415
|
+
export function findFilesSync(
|
|
416
|
+
absRoot: string,
|
|
417
|
+
prefix: string,
|
|
418
|
+
exts: string[],
|
|
419
|
+
dirsOut?: string[]
|
|
420
|
+
): string[] {
|
|
421
|
+
let entries: Dirent[];
|
|
422
|
+
try {
|
|
423
|
+
entries = readdirSync(absRoot, { withFileTypes: true });
|
|
424
|
+
} catch {
|
|
425
|
+
return [];
|
|
426
|
+
}
|
|
427
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
428
|
+
const out: string[] = [];
|
|
429
|
+
for (const e of entries) {
|
|
430
|
+
const kind = findFilesEntry(e, exts);
|
|
431
|
+
if (!kind) continue;
|
|
432
|
+
const full = path.join(absRoot, e.name);
|
|
433
|
+
const rel = path.posix.join(prefix, e.name);
|
|
434
|
+
if (kind === 'dir') {
|
|
435
|
+
dirsOut?.push(rel);
|
|
436
|
+
for (const f of findFilesSync(full, rel, exts, dirsOut)) out.push(f);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
if (singlyLinked(lstatSync(full))) out.push(rel);
|
|
441
|
+
} catch {}
|
|
370
442
|
}
|
|
371
443
|
return out;
|
|
372
444
|
}
|
|
@@ -1040,7 +1112,13 @@ export interface Api {
|
|
|
1040
1112
|
}): Promise<ReorderRevertResult>;
|
|
1041
1113
|
// Aggregate data
|
|
1042
1114
|
/** `viewer.role` — the proxy-vouched role in a cell (`null` on a desktop). */
|
|
1043
|
-
|
|
1115
|
+
/** #207 — `fresh`: wait for a real build instead of a previous run's copy (`indexStale`).
|
|
1116
|
+
* `partial`: with no copy either, the bare listing may answer first (`indexPartial`). */
|
|
1117
|
+
buildIndexData(viewer?: {
|
|
1118
|
+
role?: string | null;
|
|
1119
|
+
fresh?: boolean;
|
|
1120
|
+
partial?: boolean;
|
|
1121
|
+
}): Promise<unknown>;
|
|
1044
1122
|
buildSystemData(dsName?: string | null): Promise<unknown>;
|
|
1045
1123
|
}
|
|
1046
1124
|
|
|
@@ -2341,6 +2419,12 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
2341
2419
|
return v === 'light' || v === 'dark' ? v : null;
|
|
2342
2420
|
}
|
|
2343
2421
|
|
|
2422
|
+
// 2.0.7 B2 — the person's Canvas | Pages pick for this canvas (canvas-pages.ts). Same class as canvasTheme:
|
|
2423
|
+
// per user, per Mac, view.json only (DDR-115); a closed set from the untrusted canvas origin.
|
|
2424
|
+
function normalizeCanvasView(v: unknown): 'canvas' | 'pages' | null {
|
|
2425
|
+
return v === 'canvas' || v === 'pages' ? v : null;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2344
2428
|
// Issue #91 security follow-up — `layout.artboards[]` (DDR-027 position-only
|
|
2345
2429
|
// entries) is reachable from the untrusted canvas origin (DDR-054) via the
|
|
2346
2430
|
// same PATCH lane as overlays/locked above, but previously had no count or
|
|
@@ -2397,6 +2481,7 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
2397
2481
|
overlays?: Record<string, boolean>;
|
|
2398
2482
|
locked?: string[];
|
|
2399
2483
|
canvasTheme?: 'light' | 'dark';
|
|
2484
|
+
canvasView?: 'canvas' | 'pages';
|
|
2400
2485
|
} | null> {
|
|
2401
2486
|
const viewAbs = canvasViewPath(file);
|
|
2402
2487
|
if (!viewAbs) return null;
|
|
@@ -2407,16 +2492,19 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
2407
2492
|
const ov = normalizeOverlays((obj as { overlays?: unknown }).overlays);
|
|
2408
2493
|
const lk = normalizeLocked((obj as { locked?: unknown }).locked);
|
|
2409
2494
|
const ct = normalizeCanvasTheme((obj as { canvasTheme?: unknown }).canvasTheme);
|
|
2495
|
+
const cv = normalizeCanvasView((obj as { canvasView?: unknown }).canvasView);
|
|
2410
2496
|
const result: {
|
|
2411
2497
|
viewport?: { x: number; y: number; zoom: number };
|
|
2412
2498
|
overlays?: Record<string, boolean>;
|
|
2413
2499
|
locked?: string[];
|
|
2414
2500
|
canvasTheme?: 'light' | 'dark';
|
|
2501
|
+
canvasView?: 'canvas' | 'pages';
|
|
2415
2502
|
} = {};
|
|
2416
2503
|
if (vp) result.viewport = vp;
|
|
2417
2504
|
if (ov && Object.keys(ov).length > 0) result.overlays = ov;
|
|
2418
2505
|
if (lk && lk.length > 0) result.locked = lk;
|
|
2419
2506
|
if (ct) result.canvasTheme = ct;
|
|
2507
|
+
if (cv) result.canvasView = cv;
|
|
2420
2508
|
return result;
|
|
2421
2509
|
}
|
|
2422
2510
|
return null;
|
|
@@ -2508,15 +2596,25 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
2508
2596
|
obj.locked = undefined;
|
|
2509
2597
|
// r4 #6 — `canvasTheme` (the Light | Dark pick) is the same class.
|
|
2510
2598
|
obj.canvasTheme = undefined;
|
|
2599
|
+
// 2.0.7 B2 — `canvasView` (Canvas | Pages) is the same class.
|
|
2600
|
+
obj.canvasView = undefined;
|
|
2511
2601
|
const view = await loadCanvasView(file);
|
|
2512
2602
|
if (view?.viewport) obj.viewport = view.viewport;
|
|
2513
2603
|
if (view?.overlays) obj.overlays = view.overlays;
|
|
2514
2604
|
if (view?.locked) obj.locked = view.locked;
|
|
2515
2605
|
if (view?.canvasTheme) obj.canvasTheme = view.canvasTheme;
|
|
2606
|
+
if (view?.canvasView) obj.canvasView = view.canvasView;
|
|
2516
2607
|
// Preserve the historic contract: no meta AND no camera/overlays → null
|
|
2517
2608
|
// (GET → {}, PATCH-on-rejected-path → 404). A view-only canvas still
|
|
2518
2609
|
// returns its camera/overlays.
|
|
2519
|
-
if (
|
|
2610
|
+
if (
|
|
2611
|
+
!hadMeta &&
|
|
2612
|
+
!view?.viewport &&
|
|
2613
|
+
!view?.overlays &&
|
|
2614
|
+
!view?.locked &&
|
|
2615
|
+
!view?.canvasTheme &&
|
|
2616
|
+
!view?.canvasView
|
|
2617
|
+
)
|
|
2520
2618
|
return null;
|
|
2521
2619
|
return obj;
|
|
2522
2620
|
}
|
|
@@ -2645,6 +2743,33 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
2645
2743
|
}
|
|
2646
2744
|
}
|
|
2647
2745
|
|
|
2746
|
+
// --- Per-user Canvas | Pages lane (2.0.7 B2): canvasView → view file, never the versioned meta. Same shape as
|
|
2747
|
+
// the Light | Dark lane above: REPLACE, `null` forgets the pick (back to Canvas), anything else is a no-op.
|
|
2748
|
+
if (patch.canvasView !== undefined) {
|
|
2749
|
+
const viewAbs = canvasViewPath(file);
|
|
2750
|
+
if (viewAbs) {
|
|
2751
|
+
try {
|
|
2752
|
+
const current = await readCanvasViewRaw(file);
|
|
2753
|
+
if (patch.canvasView === null) {
|
|
2754
|
+
const { canvasView: _drop, ...rest } = current;
|
|
2755
|
+
await mkdir(sessionDir(paths.canvasStateDir), { recursive: true });
|
|
2756
|
+
await Bun.write(viewAbs, `${JSON.stringify(rest, null, 2)}\n`);
|
|
2757
|
+
} else {
|
|
2758
|
+
const cv = normalizeCanvasView(patch.canvasView);
|
|
2759
|
+
if (cv !== null) {
|
|
2760
|
+
await mkdir(sessionDir(paths.canvasStateDir), { recursive: true });
|
|
2761
|
+
await Bun.write(
|
|
2762
|
+
viewAbs,
|
|
2763
|
+
`${JSON.stringify({ ...current, canvasView: cv }, null, 2)}\n`
|
|
2764
|
+
);
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
} catch {
|
|
2768
|
+
/* best-effort */
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2648
2773
|
// --- Shared document lane: layout → versioned meta, stamps last_modified. ---
|
|
2649
2774
|
if (patch.layout !== undefined) {
|
|
2650
2775
|
let current: Record<string, unknown> = {};
|
|
@@ -7889,16 +8014,83 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
7889
8014
|
// it, so a build that started before a change is never handed to a later caller.
|
|
7890
8015
|
const indexFlight = createSingleFlight<unknown>();
|
|
7891
8016
|
ctx.bus.on('fs:any', () => indexFlight.bump());
|
|
7892
|
-
|
|
8017
|
+
// #207 — on a desktop the expensive part (the canvas groups and what is derived from each
|
|
8018
|
+
// canvas) is kept between requests (index-cache.ts) and rebuilt only when something it reads
|
|
8019
|
+
// changes; a copy on disk answers the first request after a restart at once. A cell keeps the
|
|
8020
|
+
// per-request build: its listing also follows the hub's journal, which raises no file event.
|
|
8021
|
+
const canvasIndex = createIndexCache<CanvasIndexPart>({
|
|
8022
|
+
build: (early) => buildCanvasIndexPart(early),
|
|
8023
|
+
seed: () => readCanvasIndexSeed(canvasIndexSeedPath(), cfgIndexKey()),
|
|
8024
|
+
persist: (part) => scheduleCanvasIndexSeed(part),
|
|
8025
|
+
onError: (err) => console.warn('[index-data] background build failed:', err),
|
|
8026
|
+
});
|
|
8027
|
+
ctx.bus.on('fs:any', (rel: string) => {
|
|
8028
|
+
if (!isRootRuntimeRel(rel)) canvasIndex.invalidate();
|
|
8029
|
+
});
|
|
8030
|
+
// An API write announces itself before the disk event arrives, and the client reloads the tree
|
|
8031
|
+
// as soon as the write answers: the cache must already know (else it answers "fresh" from before).
|
|
8032
|
+
for (const e of CANVAS_INDEX_WRITE_EVENTS) ctx.bus.on(e, () => canvasIndex.invalidate());
|
|
8033
|
+
let seedTimer: ReturnType<typeof setTimeout> | null = null;
|
|
8034
|
+
let seedPending: CanvasIndexPart | null = null;
|
|
8035
|
+
function scheduleCanvasIndexSeed(part: CanvasIndexPart) {
|
|
8036
|
+
seedPending = part;
|
|
8037
|
+
if (seedTimer) return;
|
|
8038
|
+
seedTimer = setTimeout(() => {
|
|
8039
|
+
seedTimer = null;
|
|
8040
|
+
const p = seedPending;
|
|
8041
|
+
seedPending = null;
|
|
8042
|
+
if (p) writeCanvasIndexSeed(canvasIndexSeedPath(), p, cfgIndexKey());
|
|
8043
|
+
}, CANVAS_INDEX_SEED_DEBOUNCE_MS);
|
|
8044
|
+
(seedTimer as { unref?: () => void }).unref?.();
|
|
8045
|
+
}
|
|
8046
|
+
function canvasIndexSeedPath() {
|
|
8047
|
+
return path.join(projectDir(pidOf(paths.repoRoot)), 'tree.json');
|
|
8048
|
+
}
|
|
8049
|
+
/** What the cached part was built under: a config reload with other groups/systems is a miss. */
|
|
8050
|
+
function cfgIndexKey() {
|
|
8051
|
+
return JSON.stringify([
|
|
8052
|
+
paths.designRel,
|
|
8053
|
+
cfg.canvasGroups,
|
|
8054
|
+
cfg.designSystems ?? [],
|
|
8055
|
+
cfg.defaultDesignSystem ?? null,
|
|
8056
|
+
]);
|
|
8057
|
+
}
|
|
8058
|
+
let cachedCfgKey = '';
|
|
8059
|
+
|
|
8060
|
+
function buildIndexData(viewer?: { role?: string | null; fresh?: boolean; partial?: boolean }) {
|
|
7893
8061
|
// A canvas-only session's answer is filtered by its own grants: never shared.
|
|
7894
8062
|
if (!projectVisibility(ctx).current().full) return buildIndexDataNow(viewer);
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
8063
|
+
if (isWorkspaceMode())
|
|
8064
|
+
return indexFlight.run(`${viewer?.role ?? ''}|${currentSession()}`, () =>
|
|
8065
|
+
buildIndexDataNow(viewer)
|
|
8066
|
+
);
|
|
8067
|
+
const key = cfgIndexKey();
|
|
8068
|
+
if (key !== cachedCfgKey) {
|
|
8069
|
+
cachedCfgKey = key;
|
|
8070
|
+
canvasIndex.invalidate();
|
|
8071
|
+
}
|
|
8072
|
+
// Only the route (which always passes a viewer) may be answered from a previous run's copy; an
|
|
8073
|
+
// internal caller (S11.4 availability: "what is on this Mac") always waits for a real build.
|
|
8074
|
+
// #207 (list speed) — the tree loader asks `partial`: on the first open ever (no copy) it is
|
|
8075
|
+
// answered with the bare listing the build publishes before any content read.
|
|
8076
|
+
return canvasIndex
|
|
8077
|
+
.get({ fresh: viewer === undefined || viewer.fresh === true, partial: viewer?.partial })
|
|
8078
|
+
.then(({ value, stale, partial }) => assembleIndexData(value, viewer, stale, partial));
|
|
7898
8079
|
}
|
|
7899
8080
|
|
|
7900
8081
|
async function buildIndexDataNow(viewer?: { role?: string | null }) {
|
|
7901
|
-
|
|
8082
|
+
return assembleIndexData(await buildCanvasIndexPart(), viewer, false);
|
|
8083
|
+
}
|
|
8084
|
+
|
|
8085
|
+
/**
|
|
8086
|
+
* The canvas groups and everything derived per canvas — the slow, reader-independent part.
|
|
8087
|
+
* `early` gets the bare listing first: the groups as one walk of names (no file is read), with
|
|
8088
|
+
* nothing derived — no design system, kind, revision or import report.
|
|
8089
|
+
*/
|
|
8090
|
+
async function buildCanvasIndexPart(
|
|
8091
|
+
early?: (listing: CanvasIndexPart) => void
|
|
8092
|
+
): Promise<CanvasIndexPart> {
|
|
8093
|
+
const groups: CanvasIndexPart['groups'] = [];
|
|
7902
8094
|
|
|
7903
8095
|
// DDR-093 — per-canvas design-system map (repo-relative canvas path → DS
|
|
7904
8096
|
// name) so the client's canvasUrl() injects each UI canvas's OWN tokens
|
|
@@ -7907,11 +8099,13 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
7907
8099
|
const canvasDesignSystems: Record<string, string> = {};
|
|
7908
8100
|
// S10.4 (V2-1.6 §5.8) — the revision a canvas was left on (`dsRev`), for the converted systems only:
|
|
7909
8101
|
// an unconverted project builds none of this, and its payload is what it always was.
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
.
|
|
7914
|
-
|
|
8102
|
+
// (read after the listing is out: a system's head is a content read)
|
|
8103
|
+
const readConvertedDs = () =>
|
|
8104
|
+
new Set(
|
|
8105
|
+
(cfg.designSystems ?? [])
|
|
8106
|
+
.filter((d) => readHead(path.join(paths.designRoot, d.path)).state === 'ok')
|
|
8107
|
+
.map((d) => d.name)
|
|
8108
|
+
);
|
|
7915
8109
|
const canvasRevs: Record<string, { system: string; dsRev: string; kept?: string }> = {};
|
|
7916
8110
|
// DDR-174 (T15) — surface a canvas's `.meta.json` `kind` in the file tree
|
|
7917
8111
|
// when it's a value the user should notice at a glance (today: only
|
|
@@ -7940,36 +8134,16 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
7940
8134
|
const owner = (cfg.designSystems ?? []).find(
|
|
7941
8135
|
(d) => d.path === `system/${folder}` || d.path.endsWith(`/${folder}`)
|
|
7942
8136
|
);
|
|
7943
|
-
|
|
8137
|
+
// 2.0.7 — a system folder the config does not list owns its own files too (folderSystemOf).
|
|
8138
|
+
return (
|
|
8139
|
+
owner?.name ??
|
|
8140
|
+
folderSystemOf(r, cfg.designSystems ?? [], (f) =>
|
|
8141
|
+
existsSync(path.join(paths.designRoot, ...f.split('/')))
|
|
8142
|
+
)?.name ??
|
|
8143
|
+
null
|
|
8144
|
+
);
|
|
7944
8145
|
};
|
|
7945
8146
|
|
|
7946
|
-
// PROJECT — top-level .design/ files (README.md, INDEX.md, config.json, …).
|
|
7947
|
-
// These are non-HTML so they're listed but not openable in the iframe; the
|
|
7948
|
-
// sidebar can still display them as context (mirrors CV-08 mock).
|
|
7949
|
-
const projectFiles: string[] = [];
|
|
7950
|
-
try {
|
|
7951
|
-
const entries = await readdir(paths.designRoot, { withFileTypes: true });
|
|
7952
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
7953
|
-
for (const e of entries) {
|
|
7954
|
-
if (!e.isFile()) continue;
|
|
7955
|
-
if (e.name.startsWith('_')) continue;
|
|
7956
|
-
if (e.name.startsWith('.')) continue;
|
|
7957
|
-
if (!/\.(md|json|txt|yml|yaml|css)$/i.test(e.name)) continue;
|
|
7958
|
-
projectFiles.push(path.posix.join(paths.designRel, e.name));
|
|
7959
|
-
}
|
|
7960
|
-
} catch {}
|
|
7961
|
-
if (projectFiles.length) {
|
|
7962
|
-
groups.push({
|
|
7963
|
-
label: 'Project',
|
|
7964
|
-
paths: projectFiles,
|
|
7965
|
-
fullPath: paths.designRel,
|
|
7966
|
-
// Strip `.design/` — the section header already names the parent;
|
|
7967
|
-
// the chain `▾ .design → file` was redundant.
|
|
7968
|
-
stripPrefix: `${paths.designRel}/`,
|
|
7969
|
-
kind: 'project' as const,
|
|
7970
|
-
});
|
|
7971
|
-
}
|
|
7972
|
-
|
|
7973
8147
|
// Canvas groups — strip just `.design/` so the immediate subdir
|
|
7974
8148
|
// (`system`, `ui`, …) shows up as a dir wrapper in the tree (mirrors
|
|
7975
8149
|
// CV-08's `▾ ui` / `▾ system/project` headers).
|
|
@@ -7980,6 +8154,9 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
7980
8154
|
// (FileRow non-HTML branch).
|
|
7981
8155
|
// Cell materializer — the media the hub can serve although this checkout
|
|
7982
8156
|
// does not hold it. `null` everywhere else (desktop, self-hosted hub).
|
|
8157
|
+
// #207 (list speed) — an answer already made (a previous run's copy handed out by the request that
|
|
8158
|
+
// started this build) gets out before the walk below takes the loop.
|
|
8159
|
+
await yieldToLoop();
|
|
7983
8160
|
const materializable = await listMaterializable();
|
|
7984
8161
|
for (const g of cfg.canvasGroups) {
|
|
7985
8162
|
const groupAbs = path.join(paths.designRoot, g.path);
|
|
@@ -8000,7 +8177,8 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8000
8177
|
const groupExts = isDs
|
|
8001
8178
|
? ['.tsx', '.html', '.md', '.css', '.json', ...PREVIEW_ASSET_EXTS]
|
|
8002
8179
|
: ['.tsx', '.html', '.css', '.json', ...PREVIEW_ASSET_EXTS];
|
|
8003
|
-
|
|
8180
|
+
// #207 (list speed) — one walk of names that never gives the loop away (findFilesSync).
|
|
8181
|
+
const filePaths = findFilesSync(groupAbs, groupRel, groupExts, dirs);
|
|
8004
8182
|
// A materializing cell lists media its checkout does not hold.
|
|
8005
8183
|
if (materializable) {
|
|
8006
8184
|
mergeMaterializable(filePaths, dirs, materializable, {
|
|
@@ -8009,36 +8187,6 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8009
8187
|
exts: PREVIEW_ASSET_EXTS,
|
|
8010
8188
|
});
|
|
8011
8189
|
}
|
|
8012
|
-
// DDR-093 — record each `.tsx` canvas's design system. canvasUrl() only
|
|
8013
|
-
// injects tokens for `.tsx`, so skip everything else. Path-owned DS wins
|
|
8014
|
-
// (system/<ds>/…); otherwise the sidecar's `meta.designSystem`, defaulting
|
|
8015
|
-
// to the project default when the canvas declares none.
|
|
8016
|
-
for (const fp of filePaths) {
|
|
8017
|
-
if (!fp.endsWith('.tsx')) continue;
|
|
8018
|
-
let dsName = ownerDsName(fp);
|
|
8019
|
-
let meta: Record<string, unknown> | null = null;
|
|
8020
|
-
if (!dsName) {
|
|
8021
|
-
meta = await loadCanvasMeta(fp);
|
|
8022
|
-
const declared = meta?.designSystem;
|
|
8023
|
-
dsName = typeof declared === 'string' && declared.trim() ? declared : defaultDs;
|
|
8024
|
-
const kind = meta?.kind;
|
|
8025
|
-
if (typeof kind === 'string' && NOTABLE_KINDS.has(kind)) canvasKinds[fp] = kind;
|
|
8026
|
-
}
|
|
8027
|
-
canvasDesignSystems[fp] = dsName;
|
|
8028
|
-
if (convertedDs.has(dsName)) {
|
|
8029
|
-
// a canvas inside the system's own folder carries no sidecar read above
|
|
8030
|
-
meta ??= await loadCanvasMeta(fp);
|
|
8031
|
-
const dsRev = meta?.dsRev;
|
|
8032
|
-
// p8-dead-reasons — `dsKept`: the head a person declined with "Keep this version" (the card stays away)
|
|
8033
|
-
const kept = meta?.dsKept;
|
|
8034
|
-
if (typeof dsRev === 'string' && dsRev)
|
|
8035
|
-
canvasRevs[fp] = {
|
|
8036
|
-
system: dsName,
|
|
8037
|
-
dsRev,
|
|
8038
|
-
...(typeof kept === 'string' && kept ? { kept } : {}),
|
|
8039
|
-
};
|
|
8040
|
-
}
|
|
8041
|
-
}
|
|
8042
8190
|
// Strip down to `g.path` so per-DS folders (`project`, `beta`, …) show
|
|
8043
8191
|
// up as the top-level dirs inside the DS section. Single-DS configs get
|
|
8044
8192
|
// a wrapper folder too — slightly more verbose, but consistent with
|
|
@@ -8071,6 +8219,142 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8071
8219
|
});
|
|
8072
8220
|
}
|
|
8073
8221
|
|
|
8222
|
+
// #207 (list speed) — the bare listing goes out now (the tree loader on a first open ever draws it),
|
|
8223
|
+
// and the answer it belongs to gets out before the content reads below take the loop.
|
|
8224
|
+
if (early) {
|
|
8225
|
+
early({ groups: [...groups], canvasDesignSystems: {}, canvasKinds: {} });
|
|
8226
|
+
await yieldToLoop();
|
|
8227
|
+
}
|
|
8228
|
+
// tests only: hold the content reads until a file exists (the listing-first test proves the order)
|
|
8229
|
+
const gate = process.env.MAUDE_TEST_INDEX_DETAILS_GATE;
|
|
8230
|
+
while (gate && !existsSync(gate)) await new Promise((r) => setTimeout(r, 20));
|
|
8231
|
+
|
|
8232
|
+
// DDR-093 — record each `.tsx` canvas's design system. canvasUrl() only
|
|
8233
|
+
// injects tokens for `.tsx`, so skip everything else. Path-owned DS wins
|
|
8234
|
+
// (system/<ds>/…); otherwise the sidecar's `meta.designSystem`, defaulting
|
|
8235
|
+
// to the project default when the canvas declares none.
|
|
8236
|
+
const convertedDs = readConvertedDs();
|
|
8237
|
+
for (const g of groups) {
|
|
8238
|
+
for (const fp of g.paths) {
|
|
8239
|
+
if (!fp.endsWith('.tsx')) continue;
|
|
8240
|
+
let dsName = ownerDsName(fp);
|
|
8241
|
+
let meta: Record<string, unknown> | null = null;
|
|
8242
|
+
if (!dsName) {
|
|
8243
|
+
meta = await loadCanvasMeta(fp);
|
|
8244
|
+
const declared = meta?.designSystem;
|
|
8245
|
+
dsName = typeof declared === 'string' && declared.trim() ? declared : defaultDs;
|
|
8246
|
+
const kind = meta?.kind;
|
|
8247
|
+
if (typeof kind === 'string' && NOTABLE_KINDS.has(kind)) canvasKinds[fp] = kind;
|
|
8248
|
+
}
|
|
8249
|
+
canvasDesignSystems[fp] = dsName;
|
|
8250
|
+
if (convertedDs.has(dsName)) {
|
|
8251
|
+
// a canvas inside the system's own folder carries no sidecar read above
|
|
8252
|
+
meta ??= await loadCanvasMeta(fp);
|
|
8253
|
+
const dsRev = meta?.dsRev;
|
|
8254
|
+
// p8-dead-reasons — `dsKept`: the head a person declined with "Keep this version" (the card stays away)
|
|
8255
|
+
const kept = meta?.dsKept;
|
|
8256
|
+
if (typeof dsRev === 'string' && dsRev)
|
|
8257
|
+
canvasRevs[fp] = {
|
|
8258
|
+
system: dsName,
|
|
8259
|
+
dsRev,
|
|
8260
|
+
...(typeof kept === 'string' && kept ? { kept } : {}),
|
|
8261
|
+
};
|
|
8262
|
+
}
|
|
8263
|
+
}
|
|
8264
|
+
}
|
|
8265
|
+
|
|
8266
|
+
// S10.4 — which revision each canvas renders. Present only once a system is converted: a project that
|
|
8267
|
+
// has none gets the payload it always had.
|
|
8268
|
+
const dsRender =
|
|
8269
|
+
convertedDs.size > 0
|
|
8270
|
+
? dsRenderIndex(paths.designRoot, cfg.designSystems ?? [], canvasRevs)
|
|
8271
|
+
: null;
|
|
8272
|
+
|
|
8273
|
+
// gate-b-c4j — a canvas importing another canvas does not render in its frame (access/closure.ts
|
|
8274
|
+
// `walkImports`: the module is refused); the shell says why on it. The same for every reader;
|
|
8275
|
+
// filterIndexData below holds both sides to what this reader sees.
|
|
8276
|
+
const prefix = `${paths.designRel}/`;
|
|
8277
|
+
const canvasRels = Object.keys(canvasDesignSystems)
|
|
8278
|
+
.filter((fp) => fp.startsWith(prefix))
|
|
8279
|
+
.map((fp) => fp.slice(prefix.length))
|
|
8280
|
+
.sort();
|
|
8281
|
+
const imports = projectVisibility(ctx).canvasImports(canvasRels);
|
|
8282
|
+
const canvasImportsCanvases: Record<string, string[]> = {};
|
|
8283
|
+
for (const [rel, list] of imports) canvasImportsCanvases[`${prefix}${rel}`] = list;
|
|
8284
|
+
// 2.0.7 — an import that resolves to no file blocks the canvas the same way (its frame answers 403
|
|
8285
|
+
// before any build could name the file): the shell names the missing file on the card.
|
|
8286
|
+
const missing = projectVisibility(ctx).canvasMissingImports?.(canvasRels) ?? new Map();
|
|
8287
|
+
const canvasMissingImports: Record<string, string[]> = {};
|
|
8288
|
+
for (const [rel, list] of missing) canvasMissingImports[`${prefix}${rel}`] = list;
|
|
8289
|
+
return {
|
|
8290
|
+
groups,
|
|
8291
|
+
canvasDesignSystems,
|
|
8292
|
+
canvasKinds,
|
|
8293
|
+
...(imports.size ? { canvasImportsCanvases } : {}),
|
|
8294
|
+
...(missing.size ? { canvasMissingImports } : {}),
|
|
8295
|
+
...(dsRender
|
|
8296
|
+
? {
|
|
8297
|
+
canvasDsRevs: Object.fromEntries(
|
|
8298
|
+
Object.entries(canvasRevs).map(([fp, r]) => [fp, r.dsRev])
|
|
8299
|
+
),
|
|
8300
|
+
canvasDsKept: Object.fromEntries(
|
|
8301
|
+
Object.entries(canvasRevs)
|
|
8302
|
+
.filter(([, r]) => r.kept)
|
|
8303
|
+
.map(([fp, r]) => [fp, r.kept as string])
|
|
8304
|
+
),
|
|
8305
|
+
systemHeads: dsRender.systemHeads,
|
|
8306
|
+
dsConverted: dsRender.dsConverted,
|
|
8307
|
+
dsRevGaps: dsRender.dsRevGaps,
|
|
8308
|
+
}
|
|
8309
|
+
: {}),
|
|
8310
|
+
};
|
|
8311
|
+
}
|
|
8312
|
+
|
|
8313
|
+
/**
|
|
8314
|
+
* #207 — the payload for one request: the (cached) canvas part plus what is cheap and per request —
|
|
8315
|
+
* the Project and Runtime rows (one root listing each; the Runtime row depends on the reader), the
|
|
8316
|
+
* refused-inputs report the http layer keeps in memory, and the reader's filter.
|
|
8317
|
+
*/
|
|
8318
|
+
async function assembleIndexData(
|
|
8319
|
+
part: CanvasIndexPart,
|
|
8320
|
+
viewer: { role?: string | null } | undefined,
|
|
8321
|
+
stale: boolean,
|
|
8322
|
+
partial?: boolean
|
|
8323
|
+
) {
|
|
8324
|
+
const head: CanvasIndexPart['groups'] = [];
|
|
8325
|
+
const tail: CanvasIndexPart['groups'] = [];
|
|
8326
|
+
// #207 (list speed) — ONE listing of the design root, read in this tick: an answer from the cache
|
|
8327
|
+
// (a copy, the bare listing) is then made at once, never after a build's next slice of work.
|
|
8328
|
+
let rootEntries: Dirent[] = [];
|
|
8329
|
+
try {
|
|
8330
|
+
rootEntries = readdirSync(paths.designRoot, { withFileTypes: true });
|
|
8331
|
+
rootEntries.sort((a, b) => a.name.localeCompare(b.name));
|
|
8332
|
+
} catch {}
|
|
8333
|
+
// PROJECT — top-level .design/ files (README.md, INDEX.md, config.json, …).
|
|
8334
|
+
// These are non-HTML so they're listed but not openable in the iframe; the
|
|
8335
|
+
// sidebar can still display them as context (mirrors CV-08 mock).
|
|
8336
|
+
const projectFiles: string[] = [];
|
|
8337
|
+
{
|
|
8338
|
+
for (const e of rootEntries) {
|
|
8339
|
+
if (!e.isFile()) continue;
|
|
8340
|
+
if (e.name.startsWith('_')) continue;
|
|
8341
|
+
if (e.name.startsWith('.')) continue;
|
|
8342
|
+
if (!/\.(md|json|txt|yml|yaml|css)$/i.test(e.name)) continue;
|
|
8343
|
+
projectFiles.push(path.posix.join(paths.designRel, e.name));
|
|
8344
|
+
}
|
|
8345
|
+
}
|
|
8346
|
+
if (projectFiles.length) {
|
|
8347
|
+
head.push({
|
|
8348
|
+
label: 'Project',
|
|
8349
|
+
paths: projectFiles,
|
|
8350
|
+
fullPath: paths.designRel,
|
|
8351
|
+
// Strip `.design/` — the section header already names the parent;
|
|
8352
|
+
// the chain `▾ .design → file` was redundant.
|
|
8353
|
+
stripPrefix: `${paths.designRel}/`,
|
|
8354
|
+
kind: 'project' as const,
|
|
8355
|
+
});
|
|
8356
|
+
}
|
|
8357
|
+
|
|
8074
8358
|
// RUNTIME — gitignored state files (_active.json, _server.json) +
|
|
8075
8359
|
// pointers to _history/ and _comments/ dirs. Visible but inert in the
|
|
8076
8360
|
// sidebar; matches the CV-08 mock's bottom section.
|
|
@@ -8084,9 +8368,8 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8084
8368
|
const showRuntime = !workspace || viewer?.role === 'owner';
|
|
8085
8369
|
const mySession = currentSession();
|
|
8086
8370
|
const runtimeFiles: string[] = [];
|
|
8087
|
-
|
|
8088
|
-
const entries = showRuntime ?
|
|
8089
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
8371
|
+
{
|
|
8372
|
+
const entries = showRuntime ? rootEntries : [];
|
|
8090
8373
|
for (const e of entries) {
|
|
8091
8374
|
if (!e.name.startsWith('_')) continue;
|
|
8092
8375
|
if (workspace) {
|
|
@@ -8096,9 +8379,9 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8096
8379
|
}
|
|
8097
8380
|
runtimeFiles.push(path.posix.join(paths.designRel, e.name));
|
|
8098
8381
|
}
|
|
8099
|
-
}
|
|
8382
|
+
}
|
|
8100
8383
|
if (runtimeFiles.length) {
|
|
8101
|
-
|
|
8384
|
+
tail.push({
|
|
8102
8385
|
label: 'Runtime',
|
|
8103
8386
|
paths: runtimeFiles,
|
|
8104
8387
|
fullPath: paths.designRel,
|
|
@@ -8109,30 +8392,14 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8109
8392
|
});
|
|
8110
8393
|
}
|
|
8111
8394
|
|
|
8112
|
-
// S10.4 — which revision each canvas renders. Present only once a system is converted: a project that
|
|
8113
|
-
// has none gets the payload it always had.
|
|
8114
|
-
const dsRender =
|
|
8115
|
-
convertedDs.size > 0
|
|
8116
|
-
? dsRenderIndex(paths.designRoot, cfg.designSystems ?? [], canvasRevs)
|
|
8117
|
-
: null;
|
|
8118
|
-
|
|
8119
|
-
// gate-b-c4j — a canvas importing another canvas does not render in its frame (access/closure.ts
|
|
8120
|
-
// `walkImports`: the module is refused); the shell says why on it. The same for every reader;
|
|
8121
|
-
// filterIndexData below holds both sides to what this reader sees.
|
|
8122
8395
|
const prefix = `${paths.designRel}/`;
|
|
8123
|
-
const canvasRels = Object.keys(canvasDesignSystems)
|
|
8124
|
-
.filter((fp) => fp.startsWith(prefix))
|
|
8125
|
-
.map((fp) => fp.slice(prefix.length))
|
|
8126
|
-
.sort();
|
|
8127
|
-
const imports = projectVisibility(ctx).canvasImports(canvasRels);
|
|
8128
|
-
const canvasImportsCanvases: Record<string, string[]> = {};
|
|
8129
|
-
for (const [rel, list] of imports) canvasImportsCanvases[`${prefix}${rel}`] = list;
|
|
8130
8396
|
// 2.0.5 (#205) — a canvas whose BUILT module the inputs gate refused (it inlined a file another canvas
|
|
8131
8397
|
// owns): the files, kept per canvas by the http layer (access/refused-inputs.ts). Main origin only — the
|
|
8132
8398
|
// canvas origin's 403 stays the bare not-in-scope body.
|
|
8133
8399
|
const refused = refusedInputsFor(ctx).report();
|
|
8134
8400
|
const canvasRefusedInputs: Record<string, string[]> = {};
|
|
8135
8401
|
for (const [rel, list] of refused) canvasRefusedInputs[`${prefix}${rel}`] = list;
|
|
8402
|
+
const { groups, ...derived } = part;
|
|
8136
8403
|
|
|
8137
8404
|
// S9.10 (V2-1.16 L8) — a canvas-only session's tree: what it sees, nothing else.
|
|
8138
8405
|
return filterIndexData(
|
|
@@ -8140,26 +8407,14 @@ export function createApi(ctx: Context, hooks: ApiHooks): Api {
|
|
|
8140
8407
|
project: cfg.name,
|
|
8141
8408
|
projectLabel: ctx.projectLabel,
|
|
8142
8409
|
designRoot: paths.designRel,
|
|
8143
|
-
groups,
|
|
8144
|
-
|
|
8145
|
-
canvasKinds,
|
|
8146
|
-
...(imports.size ? { canvasImportsCanvases } : {}),
|
|
8410
|
+
groups: [...head, ...groups, ...tail],
|
|
8411
|
+
...derived,
|
|
8147
8412
|
...(refused.size ? { canvasRefusedInputs } : {}),
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
canvasDsKept: Object.fromEntries(
|
|
8154
|
-
Object.entries(canvasRevs)
|
|
8155
|
-
.filter(([, r]) => r.kept)
|
|
8156
|
-
.map(([fp, r]) => [fp, r.kept as string])
|
|
8157
|
-
),
|
|
8158
|
-
systemHeads: dsRender.systemHeads,
|
|
8159
|
-
dsConverted: dsRender.dsConverted,
|
|
8160
|
-
dsRevGaps: dsRender.dsRevGaps,
|
|
8161
|
-
}
|
|
8162
|
-
: {}),
|
|
8413
|
+
// #207 — a previous run's copy, answered while the first build runs; the client asks again.
|
|
8414
|
+
...(stale ? { indexStale: true } : {}),
|
|
8415
|
+
// #207 (list speed) — the bare listing: no canvas has its design system, kind or import
|
|
8416
|
+
// report yet (and nothing is granted by it); the client draws the tree and asks again.
|
|
8417
|
+
...(partial ? { indexPartial: true } : {}),
|
|
8163
8418
|
},
|
|
8164
8419
|
projectVisibility(ctx).current(),
|
|
8165
8420
|
paths.designRel,
|