@1agh/maude 2.0.0 → 2.0.2
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/filters.ts +24 -2
- package/apps/studio/access/frame.ts +38 -0
- package/apps/studio/access/request.ts +81 -2
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +2 -0
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/v2/assets/ds-library-view.jsx +263 -0
- package/apps/studio/client/v2/assets/ds-library.css +123 -0
- package/apps/studio/client/v2/assets/ds-library.js +175 -0
- package/apps/studio/client/v2/left-panel/assets-panel.jsx +60 -1
- package/apps/studio/dist/client.bundle.js +844 -844
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds-assets.ts +317 -0
- package/apps/studio/edit-ops/image-fit.ts +19 -2
- package/apps/studio/edit-ops/types.ts +5 -0
- package/apps/studio/editing/asset-drag.ts +8 -2
- package/apps/studio/editing/ds-asset-ref.ts +66 -0
- package/apps/studio/http.ts +17 -2
- package/apps/studio/materialize-client.ts +11 -0
- package/apps/studio/routes/ds-assets.ts +70 -0
- package/apps/studio/routes/edit.ts +1 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/sync/accepted-link.ts +28 -6
- package/apps/studio/sync/availability.ts +5 -0
- package/apps/studio/sync/create-collision.ts +96 -19
- package/apps/studio/sync/index.ts +10 -2
- package/apps/studio/sync/project-config-push.ts +8 -1
- package/apps/studio/sync/transaction-client.ts +54 -11
- package/apps/studio/sync/writer-registry.ts +2 -0
- package/package.json +8 -8
|
@@ -52,6 +52,7 @@ import type { ServerWebSocket } from 'bun';
|
|
|
52
52
|
import { canvasSlugFromRel } from '../canvas-slug.ts';
|
|
53
53
|
import type { Context } from '../context.ts';
|
|
54
54
|
import type { ProjectIndexSnapshot, SearchResult } from '../index/types.ts';
|
|
55
|
+
import { lastMaterializable, listMaterializable } from '../materialize-client.ts';
|
|
55
56
|
import {
|
|
56
57
|
type Closure,
|
|
57
58
|
type ClosureCache,
|
|
@@ -61,7 +62,7 @@ import {
|
|
|
61
62
|
projectClosureConfig,
|
|
62
63
|
} from './closure.ts';
|
|
63
64
|
import { closureConfigFor, knownCanvasesFor } from './known-canvases.ts';
|
|
64
|
-
import { currentAccess, diskProjectReader, toDesignRel } from './request.ts';
|
|
65
|
+
import { currentAccess, diskProjectReader, toDesignRel, withJournalMedia } from './request.ts';
|
|
65
66
|
import { type Access, sees } from './scope.ts';
|
|
66
67
|
|
|
67
68
|
// ===========================================================================
|
|
@@ -580,6 +581,12 @@ export interface ProjectVisibility {
|
|
|
580
581
|
* the names to what its reader sees (`filterIndexData`). Memoized per tree generation.
|
|
581
582
|
*/
|
|
582
583
|
canvasImports(canvases: readonly string[]): ReadonlyMap<string, string[]>;
|
|
584
|
+
/**
|
|
585
|
+
* 2.0.2 — resolves once the closure's listing holds a materializing cell's journal media (the
|
|
586
|
+
* first `listMaterializable` answer; later ones refresh in the background). Immediate off a
|
|
587
|
+
* cell. The access gate awaits it before judging a session with grants.
|
|
588
|
+
*/
|
|
589
|
+
ready?(): Promise<void>;
|
|
583
590
|
}
|
|
584
591
|
|
|
585
592
|
const sources = new WeakMap<object, ProjectVisibility>();
|
|
@@ -602,7 +609,21 @@ export function projectVisibility(
|
|
|
602
609
|
generation++;
|
|
603
610
|
});
|
|
604
611
|
const cache: ClosureCache = createClosureCache();
|
|
605
|
-
|
|
612
|
+
// 2.0.2 — on a materializing cell the checkout holds no media (DDR-243): the journal's inert
|
|
613
|
+
// media joins the listing, so a design system's logos and photos are in its canvases' closure.
|
|
614
|
+
const reader = withJournalMedia(
|
|
615
|
+
diskProjectReader(ctx.paths.designRoot, () => String(generation)),
|
|
616
|
+
lastMaterializable
|
|
617
|
+
);
|
|
618
|
+
const ready = async (): Promise<void> => {
|
|
619
|
+
// Stale-while-revalidate: only the FIRST listing is waited for, so a hub that hangs costs one
|
|
620
|
+
// request its hop timeout, not every request every TTL.
|
|
621
|
+
if (lastMaterializable() !== null) {
|
|
622
|
+
void listMaterializable();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
await listMaterializable();
|
|
626
|
+
};
|
|
606
627
|
// p8-c4b — plus the canvases the authority knows of (a stored grant), re-read per call.
|
|
607
628
|
const config = () =>
|
|
608
629
|
closureConfigFor(ctx) ?? projectClosureConfig(reader, knownCanvasesFor(undefined));
|
|
@@ -625,6 +646,7 @@ export function projectVisibility(
|
|
|
625
646
|
visibilityFor,
|
|
626
647
|
current: () => visibilityFor(currentAccess()),
|
|
627
648
|
canvasImports,
|
|
649
|
+
ready,
|
|
628
650
|
});
|
|
629
651
|
sources.set(ctx, src);
|
|
630
652
|
return src;
|
|
@@ -217,6 +217,44 @@ export function narrowToFrame(base: Access, canvases: readonly string[] | null):
|
|
|
217
217
|
return Object.freeze({ ...narrowed, unnarrowed: base.unnarrowed ?? base });
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Project media a frame may read: pictures, video, audio and fonts — inert bytes the canvas CSP
|
|
222
|
+
* never runs. The same set as the file plane's inert media (sync/file-membership.ts), by extension
|
|
223
|
+
* only: the shape there refuses names like `Team photo (2).jpg` that a design root does hold.
|
|
224
|
+
*/
|
|
225
|
+
const PROJECT_MEDIA_EXT_RE =
|
|
226
|
+
/\.(png|jpe?g|webp|gif|avif|svg|ico|mp4|webm|mov|m4v|mp3|wav|m4a|aac|ogg|woff2?|ttf|otf)$/i;
|
|
227
|
+
|
|
228
|
+
/** A designRoot-relative path that names project media: no runtime state, no dot or empty segment. */
|
|
229
|
+
export function isProjectMediaRel(rel: string): boolean {
|
|
230
|
+
if (!rel || rel.startsWith('/') || rel.includes('\\')) return false;
|
|
231
|
+
const segs = rel.split('/');
|
|
232
|
+
if (segs.some((s) => s === '' || s.startsWith('.'))) return false;
|
|
233
|
+
// Runtime state is first-segment `_*` (DDR-115) — never project media.
|
|
234
|
+
if ((segs[0] as string).startsWith('_')) return false;
|
|
235
|
+
return PROJECT_MEDIA_EXT_RE.test(rel);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Decision `maude/v2-202-project-role-frames-read-project-media` (Michal, 2026-11-03): a frame
|
|
240
|
+
* whose OPENER holds a project read role (`unnarrowed`, the access before `narrowToFrame`) may GET
|
|
241
|
+
* any project media, anywhere in the design root — so a canvas that builds a picture path in code
|
|
242
|
+
* (G3 leaves it out of the closure) or places another system's picture still draws it for the
|
|
243
|
+
* people who can read that picture on the main origin anyway. Reads only, media only: source, CSS,
|
|
244
|
+
* JSON, sidecars and other canvases stay behind the closure. A canvas-only opener (a share of one
|
|
245
|
+
* canvas) gets nothing here — its frame keeps the strict closure.
|
|
246
|
+
*
|
|
247
|
+
* Residual risk, accepted: code planted in a canvas by an editor of a single-canvas share can load
|
|
248
|
+
* other canvases' pictures when an owner or member opens that canvas.
|
|
249
|
+
*/
|
|
250
|
+
export function frameReadsProjectMedia(access: Access, rel: string, method: string): boolean {
|
|
251
|
+
if (method !== 'GET' && method !== 'HEAD') return false;
|
|
252
|
+
const opener = access.unnarrowed;
|
|
253
|
+
if (!access.canvasOnly || !opener || opener.role === null) return false;
|
|
254
|
+
if (!opener.can('read', null)) return false;
|
|
255
|
+
return isProjectMediaRel(rel);
|
|
256
|
+
}
|
|
257
|
+
|
|
220
258
|
// ---------------------------------------------------------------------------
|
|
221
259
|
// The request's frame (set by the canvas / capture listener, read by `accessOf`).
|
|
222
260
|
|
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
25
25
|
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
26
26
|
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
27
|
+
import { classifyProjectFile } from '../sync/file-membership.ts';
|
|
27
28
|
import type { Closure, ProjectReader } from './closure.ts';
|
|
28
29
|
// S9.12 — the revert-guard seam (a call-time read, so the import cycle with filters.ts is inert).
|
|
29
30
|
import { aclCheckOn } from './filters.ts';
|
|
31
|
+
import { frameReadsProjectMedia } from './frame.ts';
|
|
30
32
|
import type { Capability, ProjectRole } from './roles.ts';
|
|
31
33
|
import { FLOOR_ROLE, can as roleCan } from './roles.ts';
|
|
32
34
|
import {
|
|
@@ -438,8 +440,30 @@ export async function canvasScopeRefusal(req: Request, g: GateInput): Promise<Re
|
|
|
438
440
|
if (!g.access.canvasOnly || !aclCheckOn('canvasScopeRefusal')) return null;
|
|
439
441
|
const target = await gateTarget(req, g);
|
|
440
442
|
if (target === undefined) return null;
|
|
441
|
-
if (target === null
|
|
442
|
-
return null;
|
|
443
|
+
if (target === null) return notInScopeResponse();
|
|
444
|
+
if (seesTarget(g, target, req.method)) return null;
|
|
445
|
+
// 2.0.2 (decision maude/v2-202-project-role-frames-read-project-media) — the static lane's own
|
|
446
|
+
// path (never a `?file=` naming it for an API) may be project media a project-role opener's frame
|
|
447
|
+
// reads; `frameReadsProjectMedia` holds it to GET/HEAD and media, and never a canvas-only opener.
|
|
448
|
+
if (
|
|
449
|
+
staticPathTarget(req, g.designRel) === target &&
|
|
450
|
+
frameReadsProjectMedia(g.access, target, req.method)
|
|
451
|
+
)
|
|
452
|
+
return null;
|
|
453
|
+
return notInScopeResponse();
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The designRoot file a request's PATH names when no target key in its query names another. */
|
|
457
|
+
function staticPathTarget(req: Request, designRel: string): string | null {
|
|
458
|
+
let url: URL;
|
|
459
|
+
try {
|
|
460
|
+
url = new URL(req.url);
|
|
461
|
+
} catch {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
if (TARGET_KEYS.some((k) => url.searchParams.has(k))) return null;
|
|
465
|
+
const base = `/${designRel.replace(/^\/+|\/+$/g, '')}/`;
|
|
466
|
+
return url.pathname.startsWith(base) ? toDesignRel(url.pathname, designRel) : null;
|
|
443
467
|
}
|
|
444
468
|
|
|
445
469
|
export type LocalGate =
|
|
@@ -635,3 +659,58 @@ export function diskProjectReader(
|
|
|
635
659
|
},
|
|
636
660
|
};
|
|
637
661
|
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* 2.0.2 — `disk` plus a materializing cell's journal media (`media()`, materialize-client.ts
|
|
665
|
+
* `lastMaterializable`). On a cell the disk is a cache (DDR-243): inert media lives in the bucket
|
|
666
|
+
* and is served from a hub-owned cache OUTSIDE the design root, so it never appears at its checkout
|
|
667
|
+
* path. A closure over the disk alone therefore never held a design system's logos or photos, and
|
|
668
|
+
* the path-first gate refused a canvas frame its own system's media (alligators, 2.0.1).
|
|
669
|
+
*
|
|
670
|
+
* The hub is semi-trusted (DDR-054), so its listing only ADDS names the closure's own rules then
|
|
671
|
+
* judge — and only inert-media names (`classifyProjectFile(rel, {})`, the check the static lane's
|
|
672
|
+
* fill makes): never a module, a stylesheet, config or runtime state, never a dot name. `text()` of
|
|
673
|
+
* one is the disk's (null when absent); serving one still goes through `materializeMissing`.
|
|
674
|
+
* `head()` carries a version that moves when the listing does, so cached closures are recomputed.
|
|
675
|
+
*/
|
|
676
|
+
export function withJournalMedia(
|
|
677
|
+
disk: ProjectReader,
|
|
678
|
+
media: () => readonly string[] | null
|
|
679
|
+
): ProjectReader {
|
|
680
|
+
let seen: readonly string[] | null = null;
|
|
681
|
+
let version = 0;
|
|
682
|
+
let extra: ReadonlySet<string> = new Set();
|
|
683
|
+
const sync = () => {
|
|
684
|
+
const rels = media();
|
|
685
|
+
if (rels === seen) return;
|
|
686
|
+
seen = rels;
|
|
687
|
+
const next = new Set<string>();
|
|
688
|
+
for (const rel of rels ?? []) {
|
|
689
|
+
if (rel.split('/').some((s) => s.startsWith('.'))) continue;
|
|
690
|
+
if (classifyProjectFile(rel, {}) !== 'inert-media') continue;
|
|
691
|
+
next.add(rel);
|
|
692
|
+
}
|
|
693
|
+
if (next.size === extra.size && [...next].every((r) => extra.has(r))) return;
|
|
694
|
+
extra = next;
|
|
695
|
+
version++;
|
|
696
|
+
};
|
|
697
|
+
return {
|
|
698
|
+
head: () => {
|
|
699
|
+
sync();
|
|
700
|
+
return `${disk.head()}+m${version}`;
|
|
701
|
+
},
|
|
702
|
+
text: (rel) => disk.text(rel),
|
|
703
|
+
listTruncated: disk.listTruncated ? () => disk.listTruncated?.() === true : undefined,
|
|
704
|
+
present: disk.present ? (rel) => disk.present?.(rel) === true || extra.has(rel) : undefined,
|
|
705
|
+
unlisted: disk.unlisted ? () => disk.unlisted?.() ?? [] : undefined,
|
|
706
|
+
*list() {
|
|
707
|
+
sync();
|
|
708
|
+
const listed = new Set<string>();
|
|
709
|
+
for (const f of disk.list()) {
|
|
710
|
+
listed.add(f);
|
|
711
|
+
yield f;
|
|
712
|
+
}
|
|
713
|
+
for (const f of extra) if (!listed.has(f)) yield f;
|
|
714
|
+
},
|
|
715
|
+
};
|
|
716
|
+
}
|
|
@@ -679,6 +679,8 @@ export function usePaletteAndPanels({
|
|
|
679
679
|
isOffline={() => importsWaitHereFrom({ cfg, cloudLinkedHub, syncStatus, project })}
|
|
680
680
|
// S8.21 — "Used in" in an asset's details opens that artboard
|
|
681
681
|
onOpenCanvas={openCanvasAt}
|
|
682
|
+
// 2.0.2 — each design system's own library is a source of the tab
|
|
683
|
+
designSystems={cfg?.designSystems}
|
|
682
684
|
/>
|
|
683
685
|
);
|
|
684
686
|
// S1.14 — Version history (⌥⌘H): the dock id `changes` stays (testids, the dock strip, `history.open`).
|
|
@@ -172,6 +172,8 @@
|
|
|
172
172
|
@import url("../v2/assets/takes.css");
|
|
173
173
|
/* S8.20 — search in pictures: the offer, the sheet, "Seen in the picture" and its marks (client/v2/assets/). */
|
|
174
174
|
@import url("../v2/assets/describe.css");
|
|
175
|
+
/* 2.0.2 - the Assets tab Library switch and a design system own library (client/v2/assets/ds-library-view.jsx). */
|
|
176
|
+
@import url("../v2/assets/ds-library.css");
|
|
175
177
|
/* Phase 4 gate — the a11y contrast floor (WCAG 1.4.3), utilities layer: wins over shell + components. */
|
|
176
178
|
@import url("../v2/shell/contrast.css");
|
|
177
179
|
/* V2-3.3 — the Home page, scoped under `.maude-v2.home-root` (maude-v2 tokens only). */
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// client/v2/assets/ds-library-view.jsx — the Assets tab with a design system as its source (2.0.2; ds-library.js).
|
|
2
|
+
//
|
|
3
|
+
// The library's own folders first (a row per folder with its count), then its pictures in the same tiles as the
|
|
4
|
+
// project's: hover names them, a picture or a clip drags onto a frame, ↵ places the picked one on the selected artboard
|
|
5
|
+
// (`assets.place` → `placeAsset`, one edit-op, one undo step). What lands on the canvas is the picture's LITERAL
|
|
6
|
+
// reference (`/<designRel>/system/<ds>/assets/…`), never a copy. A breadcrumb walks back up; the search reads names
|
|
7
|
+
// below the current folder; the next page comes when the end of the list scrolls into view (or on "Show more").
|
|
8
|
+
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
import { StIcon } from '../../shell/icons.jsx';
|
|
11
|
+
import { crumbsOf, filesWords, useDsLibrary } from './ds-library.js';
|
|
12
|
+
import { placeAsset, SELECT_ARTBOARD_LINE } from './place-asset.js';
|
|
13
|
+
import { AssetTile } from './tile.jsx';
|
|
14
|
+
|
|
15
|
+
/** "Placed the photo in Fotky ze zápasu." — the design system keeps the picture; nothing is copied. */
|
|
16
|
+
export function dsPlacedWords(label) {
|
|
17
|
+
return label ? `Placed the photo in ${label}.` : 'Placed the photo.';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const NOT_PLACEABLE =
|
|
21
|
+
'This file’s name can’t be used on a canvas. Rename it in the design system first.';
|
|
22
|
+
|
|
23
|
+
export function DsLibraryView({
|
|
24
|
+
ds,
|
|
25
|
+
designRel = '.design',
|
|
26
|
+
readOnly = false,
|
|
27
|
+
placeTarget = null,
|
|
28
|
+
placeLabel = null,
|
|
29
|
+
onRecord = undefined,
|
|
30
|
+
toast = undefined,
|
|
31
|
+
// the panel's ↵ reaches the picked tile through this (assets-bus `place` / `tileSelected`)
|
|
32
|
+
apiRef = undefined,
|
|
33
|
+
fetchImpl = undefined,
|
|
34
|
+
}) {
|
|
35
|
+
const [dir, setDir] = useState('');
|
|
36
|
+
const [typed, setTyped] = useState('');
|
|
37
|
+
const [query, setQuery] = useState('');
|
|
38
|
+
const [picked, setPicked] = useState(null);
|
|
39
|
+
const [err, setErr] = useState('');
|
|
40
|
+
const rootRef = useRef(null);
|
|
41
|
+
const sentinel = useRef(null);
|
|
42
|
+
const alive = useRef(true);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
alive.current = true;
|
|
45
|
+
return () => {
|
|
46
|
+
alive.current = false;
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
// another system is a fresh view: the panel keys this by `ds`, so it starts at the library's top
|
|
50
|
+
// a burst of keys is one search
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const t = setTimeout(() => setQuery(typed), 180);
|
|
53
|
+
return () => clearTimeout(t);
|
|
54
|
+
}, [typed]);
|
|
55
|
+
|
|
56
|
+
const { state, error, loading, loadMore } = useDsLibrary({
|
|
57
|
+
ds,
|
|
58
|
+
dir,
|
|
59
|
+
q: query,
|
|
60
|
+
designRel,
|
|
61
|
+
fetchImpl,
|
|
62
|
+
});
|
|
63
|
+
const rows = state?.rows ?? [];
|
|
64
|
+
const byPath = new Map(rows.map((r) => [r.path, r]));
|
|
65
|
+
|
|
66
|
+
const place = useCallback(
|
|
67
|
+
async (path) => {
|
|
68
|
+
if (readOnly) return;
|
|
69
|
+
const asset = rows.find((r) => r.path === path);
|
|
70
|
+
if (!asset || (asset.kind !== 'image' && asset.kind !== 'video')) return;
|
|
71
|
+
if (!asset.placeable) {
|
|
72
|
+
setErr(NOT_PLACEABLE);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!placeTarget) {
|
|
76
|
+
setErr(SELECT_ARTBOARD_LINE);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
setErr('');
|
|
80
|
+
const tile = Array.from(rootRef.current?.querySelectorAll?.('[data-asset]') ?? []).find(
|
|
81
|
+
(el) => el.dataset.asset === path
|
|
82
|
+
);
|
|
83
|
+
const img = tile?.querySelector?.('img');
|
|
84
|
+
const natural =
|
|
85
|
+
img?.naturalWidth > 0 && img?.naturalHeight > 0
|
|
86
|
+
? { w: img.naturalWidth, h: img.naturalHeight }
|
|
87
|
+
: undefined;
|
|
88
|
+
const r = await placeAsset(
|
|
89
|
+
{ asset: path, target: placeTarget, natural },
|
|
90
|
+
{ record: onRecord }
|
|
91
|
+
);
|
|
92
|
+
if (!alive.current) return;
|
|
93
|
+
if (!r.ok) setErr(r.message);
|
|
94
|
+
else toast?.(dsPlacedWords(placeLabel));
|
|
95
|
+
},
|
|
96
|
+
[readOnly, rows, placeTarget, placeLabel, onRecord, toast]
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (apiRef)
|
|
100
|
+
apiRef.current = {
|
|
101
|
+
place: () => (picked ? place(picked) : undefined),
|
|
102
|
+
tileSelected: () => !!picked && !!rootRef.current?.contains(document.activeElement),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// the next page when the end of the list comes into view
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const el = sentinel.current;
|
|
108
|
+
if (!el || !state?.next || typeof IntersectionObserver !== 'function') return;
|
|
109
|
+
const io = new IntersectionObserver((entries) => {
|
|
110
|
+
if (entries.some((e) => e.isIntersecting)) void loadMore();
|
|
111
|
+
});
|
|
112
|
+
io.observe(el);
|
|
113
|
+
return () => io.disconnect();
|
|
114
|
+
}, [state?.next, loadMore]);
|
|
115
|
+
|
|
116
|
+
const open = (d) => {
|
|
117
|
+
setDir(d);
|
|
118
|
+
setTyped('');
|
|
119
|
+
setQuery('');
|
|
120
|
+
setPicked(null);
|
|
121
|
+
setErr('');
|
|
122
|
+
};
|
|
123
|
+
const crumbs = crumbsOf(ds, dir);
|
|
124
|
+
const searching = !!query.trim();
|
|
125
|
+
const dirs = searching ? [] : (state?.dirs ?? []);
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div className="lp-ds-lib" data-testid="assets-ds" data-ds={ds} data-dir={dir} ref={rootRef}>
|
|
129
|
+
<div className="lp-head-row">
|
|
130
|
+
<label className="lp-find">
|
|
131
|
+
<StIcon name="search" size={14} />
|
|
132
|
+
<input
|
|
133
|
+
type="search"
|
|
134
|
+
data-testid="assets-ds-search"
|
|
135
|
+
placeholder={`Search ${ds}`}
|
|
136
|
+
aria-label={`Search ${ds}`}
|
|
137
|
+
value={typed}
|
|
138
|
+
onChange={(e) => setTyped(e.target.value)}
|
|
139
|
+
/>
|
|
140
|
+
</label>
|
|
141
|
+
</div>
|
|
142
|
+
<nav
|
|
143
|
+
className="lp-ds-crumbs"
|
|
144
|
+
aria-label="Where in the library"
|
|
145
|
+
data-testid="assets-ds-crumbs"
|
|
146
|
+
>
|
|
147
|
+
{crumbs.map((c, i) => (
|
|
148
|
+
<span key={c.dir || '/'} className="lp-ds-crumb-w">
|
|
149
|
+
{i > 0 ? (
|
|
150
|
+
<span className="lp-ds-sep" aria-hidden="true">
|
|
151
|
+
›
|
|
152
|
+
</span>
|
|
153
|
+
) : null}
|
|
154
|
+
<button
|
|
155
|
+
type="button"
|
|
156
|
+
className="lp-ds-crumb"
|
|
157
|
+
data-testid="assets-ds-crumb"
|
|
158
|
+
data-dir={c.dir}
|
|
159
|
+
aria-current={i === crumbs.length - 1 ? 'location' : undefined}
|
|
160
|
+
onClick={() => open(c.dir)}
|
|
161
|
+
>
|
|
162
|
+
{c.label}
|
|
163
|
+
</button>
|
|
164
|
+
</span>
|
|
165
|
+
))}
|
|
166
|
+
</nav>
|
|
167
|
+
<div className="lp-assets-list">
|
|
168
|
+
{state === null ? <p className="lp-empty-b">Loading…</p> : null}
|
|
169
|
+
{error ? (
|
|
170
|
+
<p className="lp-note lp-note--err" role="alert" data-testid="assets-ds-error">
|
|
171
|
+
{error}
|
|
172
|
+
</p>
|
|
173
|
+
) : null}
|
|
174
|
+
{dirs.length ? (
|
|
175
|
+
<ul className="lp-ds-dirs" data-testid="assets-ds-dirs">
|
|
176
|
+
{dirs.map((d) => (
|
|
177
|
+
<li key={d.dir}>
|
|
178
|
+
<button
|
|
179
|
+
type="button"
|
|
180
|
+
className="lp-ds-dir"
|
|
181
|
+
data-testid="assets-ds-folder"
|
|
182
|
+
data-dir={d.dir}
|
|
183
|
+
onClick={() => open(d.dir)}
|
|
184
|
+
>
|
|
185
|
+
<StIcon name="folder" size={14} />
|
|
186
|
+
<span className="lp-ds-dir-n">{d.name}</span>
|
|
187
|
+
<span className="lp-count">{d.count}</span>
|
|
188
|
+
</button>
|
|
189
|
+
</li>
|
|
190
|
+
))}
|
|
191
|
+
</ul>
|
|
192
|
+
) : null}
|
|
193
|
+
{state && rows.length ? (
|
|
194
|
+
<>
|
|
195
|
+
<p className="lp-group">
|
|
196
|
+
<span className="lp-group-s">
|
|
197
|
+
{searching ? `Matching “${query.trim()}”` : 'Files'}
|
|
198
|
+
<span className="lp-count" data-testid="assets-ds-total">
|
|
199
|
+
{state.total}
|
|
200
|
+
</span>
|
|
201
|
+
</span>
|
|
202
|
+
</p>
|
|
203
|
+
<div className="lp-grid" data-testid="assets-ds-grid">
|
|
204
|
+
{rows.map((a) => (
|
|
205
|
+
<AssetTile
|
|
206
|
+
key={a.path}
|
|
207
|
+
asset={a}
|
|
208
|
+
url={a.path}
|
|
209
|
+
picked={picked === a.path}
|
|
210
|
+
canDrag={!readOnly && a.placeable}
|
|
211
|
+
onPick={(p) => {
|
|
212
|
+
setPicked(p);
|
|
213
|
+
setErr('');
|
|
214
|
+
}}
|
|
215
|
+
onMenu={() => {}}
|
|
216
|
+
/>
|
|
217
|
+
))}
|
|
218
|
+
</div>
|
|
219
|
+
</>
|
|
220
|
+
) : null}
|
|
221
|
+
{state && !rows.length && !dirs.length && !error ? (
|
|
222
|
+
<div
|
|
223
|
+
className="lp-empty"
|
|
224
|
+
data-testid={searching ? 'assets-ds-nohits' : 'assets-ds-empty'}
|
|
225
|
+
>
|
|
226
|
+
<p className="lp-empty-t">
|
|
227
|
+
{searching ? `Nothing called “${query.trim()}”.` : 'Nothing in here yet.'}
|
|
228
|
+
</p>
|
|
229
|
+
<p className="lp-empty-b">
|
|
230
|
+
{searching
|
|
231
|
+
? 'Try another word — search reads names.'
|
|
232
|
+
: `Pictures added to ${ds} show here.`}
|
|
233
|
+
</p>
|
|
234
|
+
</div>
|
|
235
|
+
) : null}
|
|
236
|
+
{state?.next ? (
|
|
237
|
+
<button
|
|
238
|
+
type="button"
|
|
239
|
+
ref={sentinel}
|
|
240
|
+
className="lp-mac"
|
|
241
|
+
data-testid="assets-ds-more"
|
|
242
|
+
disabled={loading}
|
|
243
|
+
onClick={() => void loadMore()}
|
|
244
|
+
>
|
|
245
|
+
{loading
|
|
246
|
+
? 'Loading…'
|
|
247
|
+
: `Show more · ${filesWords(Math.max(0, state.total - rows.length))} left`}
|
|
248
|
+
</button>
|
|
249
|
+
) : null}
|
|
250
|
+
{err ? (
|
|
251
|
+
<p className="lp-note lp-note--err" role="alert" data-testid="assets-ds-note">
|
|
252
|
+
{err}
|
|
253
|
+
</p>
|
|
254
|
+
) : null}
|
|
255
|
+
</div>
|
|
256
|
+
{picked && byPath.get(picked) ? (
|
|
257
|
+
<p className="lp-foot" data-testid="assets-ds-foot">
|
|
258
|
+
{byPath.get(picked)?.name}
|
|
259
|
+
</p>
|
|
260
|
+
) : null}
|
|
261
|
+
</div>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/* client/v2/assets/ds-library.css — 2.0.2: the Assets tab's Library switch and a design system's own library
|
|
2
|
+
* (ds-library-view.jsx): the breadcrumb, a row per folder, then the same tiles as the project's. Tokens only. */
|
|
3
|
+
|
|
4
|
+
@layer shell {
|
|
5
|
+
.lp-source-row {
|
|
6
|
+
flex: none;
|
|
7
|
+
padding: var(--space-1) var(--space-2) 0;
|
|
8
|
+
}
|
|
9
|
+
.lp-source {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
gap: var(--space-2);
|
|
13
|
+
font-size: var(--type-xs);
|
|
14
|
+
color: var(--fg-1);
|
|
15
|
+
}
|
|
16
|
+
.lp-source-l {
|
|
17
|
+
flex: none;
|
|
18
|
+
font-weight: var(--w-medium);
|
|
19
|
+
}
|
|
20
|
+
.lp-source select {
|
|
21
|
+
flex: 1;
|
|
22
|
+
min-width: 0;
|
|
23
|
+
height: 26px;
|
|
24
|
+
padding: 0 var(--space-1);
|
|
25
|
+
border: 0;
|
|
26
|
+
border-radius: var(--radius-sm);
|
|
27
|
+
background: var(--bg-3);
|
|
28
|
+
color: var(--fg-0);
|
|
29
|
+
font: inherit;
|
|
30
|
+
font-size: var(--type-sm);
|
|
31
|
+
}
|
|
32
|
+
.lp-source select:focus-visible {
|
|
33
|
+
outline: 2px solid var(--accent);
|
|
34
|
+
outline-offset: 1px;
|
|
35
|
+
}
|
|
36
|
+
.lp-ds-lib {
|
|
37
|
+
flex: 1 1 auto;
|
|
38
|
+
min-height: 0;
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
}
|
|
42
|
+
.lp-ds-crumbs {
|
|
43
|
+
flex: none;
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-wrap: wrap;
|
|
46
|
+
align-items: center;
|
|
47
|
+
gap: 2px;
|
|
48
|
+
padding: 0 var(--space-2) var(--space-1);
|
|
49
|
+
font-size: var(--type-xs);
|
|
50
|
+
}
|
|
51
|
+
.lp-ds-crumb-w {
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
gap: 2px;
|
|
55
|
+
min-width: 0;
|
|
56
|
+
}
|
|
57
|
+
.lp-ds-sep {
|
|
58
|
+
color: var(--fg-2);
|
|
59
|
+
}
|
|
60
|
+
.lp-ds-crumb {
|
|
61
|
+
max-width: 160px;
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
text-overflow: ellipsis;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
padding: 2px var(--space-1);
|
|
66
|
+
border: 0;
|
|
67
|
+
border-radius: var(--radius-sm);
|
|
68
|
+
background: transparent;
|
|
69
|
+
color: var(--fg-1);
|
|
70
|
+
font: inherit;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
.lp-ds-crumb[aria-current="location"] {
|
|
74
|
+
color: var(--fg-0);
|
|
75
|
+
font-weight: var(--w-semibold);
|
|
76
|
+
cursor: default;
|
|
77
|
+
}
|
|
78
|
+
.lp-ds-crumb:hover:not([aria-current]) {
|
|
79
|
+
background: var(--bg-3);
|
|
80
|
+
color: var(--fg-0);
|
|
81
|
+
}
|
|
82
|
+
.lp-ds-dirs {
|
|
83
|
+
margin: 0 0 var(--space-2);
|
|
84
|
+
padding: 0;
|
|
85
|
+
list-style: none;
|
|
86
|
+
}
|
|
87
|
+
.lp-ds-dir {
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
gap: var(--space-2);
|
|
91
|
+
width: 100%;
|
|
92
|
+
height: 30px;
|
|
93
|
+
padding: 0 var(--space-2);
|
|
94
|
+
border: 0;
|
|
95
|
+
border-radius: var(--radius-sm);
|
|
96
|
+
background: transparent;
|
|
97
|
+
color: var(--fg-1);
|
|
98
|
+
font: inherit;
|
|
99
|
+
font-size: var(--type-sm);
|
|
100
|
+
text-align: left;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
}
|
|
103
|
+
.lp-ds-dir:hover {
|
|
104
|
+
background: var(--bg-3);
|
|
105
|
+
color: var(--fg-0);
|
|
106
|
+
}
|
|
107
|
+
.lp-ds-dir-n {
|
|
108
|
+
flex: 1;
|
|
109
|
+
min-width: 0;
|
|
110
|
+
overflow: hidden;
|
|
111
|
+
text-overflow: ellipsis;
|
|
112
|
+
white-space: nowrap;
|
|
113
|
+
}
|
|
114
|
+
.lp-ds-dir .lp-count {
|
|
115
|
+
color: var(--fg-2);
|
|
116
|
+
font-size: var(--type-xs);
|
|
117
|
+
}
|
|
118
|
+
.lp-ds-crumb:focus-visible,
|
|
119
|
+
.lp-ds-dir:focus-visible {
|
|
120
|
+
outline: 2px solid var(--accent);
|
|
121
|
+
outline-offset: 1px;
|
|
122
|
+
}
|
|
123
|
+
}
|