@1agh/maude 2.0.1 → 2.0.3

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 (42) hide show
  1. package/apps/studio/access/filters.ts +24 -2
  2. package/apps/studio/access/frame.ts +38 -0
  3. package/apps/studio/access/request.ts +81 -2
  4. package/apps/studio/asset-placeholder.tsx +157 -62
  5. package/apps/studio/bridge/dgn-protocol.ts +34 -4
  6. package/apps/studio/client/app.jsx +3 -0
  7. package/apps/studio/client/hooks/use-palette-and-panels.jsx +2 -0
  8. package/apps/studio/client/styles/_index.css +2 -0
  9. package/apps/studio/client/v2/assets/asset-state-lane.js +170 -5
  10. package/apps/studio/client/v2/assets/ds-library-view.jsx +263 -0
  11. package/apps/studio/client/v2/assets/ds-library.css +123 -0
  12. package/apps/studio/client/v2/assets/ds-library.js +175 -0
  13. package/apps/studio/client/v2/assets/missing-frame.jsx +8 -4
  14. package/apps/studio/client/v2/export/native-save.js +44 -0
  15. package/apps/studio/client/v2/left-panel/assets-panel.jsx +60 -1
  16. package/apps/studio/dist/client.bundle.js +524 -523
  17. package/apps/studio/dist/comment-mount.js +2 -2
  18. package/apps/studio/dist/styles.css +1 -1
  19. package/apps/studio/ds-assets.ts +407 -0
  20. package/apps/studio/edit-ops/image-fit.ts +19 -2
  21. package/apps/studio/edit-ops/types.ts +5 -0
  22. package/apps/studio/editing/asset-drag.ts +8 -2
  23. package/apps/studio/editing/ds-asset-ref.ts +66 -0
  24. package/apps/studio/http.ts +17 -2
  25. package/apps/studio/materialize-client.ts +11 -0
  26. package/apps/studio/routes/asset-state.ts +12 -0
  27. package/apps/studio/routes/ds-assets.ts +78 -0
  28. package/apps/studio/routes/edit.ts +1 -0
  29. package/apps/studio/routes/index.ts +4 -0
  30. package/apps/studio/sync/accepted-link.ts +28 -6
  31. package/apps/studio/sync/asset-push.ts +8 -1
  32. package/apps/studio/sync/asset-state.ts +27 -2
  33. package/apps/studio/sync/availability.ts +5 -0
  34. package/apps/studio/sync/create-collision.ts +96 -19
  35. package/apps/studio/sync/file-plane.ts +36 -7
  36. package/apps/studio/sync/index.ts +10 -2
  37. package/apps/studio/sync/lfs-pointer.ts +137 -0
  38. package/apps/studio/sync/project-config-push.ts +8 -1
  39. package/apps/studio/sync/transaction-client.ts +54 -11
  40. package/apps/studio/sync/writer-registry.ts +2 -0
  41. package/apps/studio/whats-new.json +9 -0
  42. package/package.json +8 -8
@@ -14,10 +14,22 @@
14
14
  // heard (origin + source gate). The canvas's string is only ever MATCHED against this lane's own
15
15
  // answer for that canvas (S8.19c): a rel the studio did not say is missing is dropped, so a canvas
16
16
  // cannot make the shell open a relink for a path of its choosing. `onRelink` gets the studio's rel.
17
+ //
18
+ // 2.0.3 — a Git LFS placeholder (`lfs-pointer`: the file is here, but it is a pointer, the project was
19
+ // cloned without `git lfs pull`). Where the AI chat exists (`lfsActions`, the desktop app) the frame
20
+ // offers "Fix with AI" (`asset-lfs-fix-request`) and "Copy prompt" (`asset-lfs-copy-request`). Same
21
+ // gate as Relink: the active canvas only, and only a rel this lane's own answer calls `lfs-pointer`.
22
+ // The prompt is built HERE from that answer (`lfsRepairPrompt`), never from canvas text. Fix with AI
23
+ // pre-fills the AI chat (the error card's "Ask AI" path, never sent); Copy prompt writes the clipboard
24
+ // here (the canvas iframe has no clipboard rights) and answers the frame `asset-lfs-copied {rel, ok}`
25
+ // so its button can say "Copied".
17
26
 
18
27
  import { useEffect, useRef, useSyncExternalStore } from 'react';
19
28
  import { acceptFromCanvas } from '../../../bridge/dgn-protocol.ts';
20
29
  import { INDEX_CHANGED_EVENT } from '../canvases/use-canvas-index.js';
30
+ import { nativeSave } from '../export/native-save.js';
31
+ import { dispatchCanvasOp } from '../left-panel/left-panel-bus.js';
32
+ import { ASK_AI_MAX } from '../search/search-env.js';
21
33
 
22
34
  /** canvas file → (rel → item): what the studio last said about each canvas. The relink gate and the
23
35
  * Inspector's absent-picture box read it; nothing else does. */
@@ -78,6 +90,96 @@ export function useAssetAnswers() {
78
90
  return useSyncExternalStore(subscribeAssetAnswers, assetAnswersVersion, assetAnswersVersion);
79
91
  }
80
92
 
93
+ /** The prompt lists at most this many paths, then "and N more". */
94
+ export const LFS_PROMPT_MAX_PATHS = 50;
95
+ const LFS_SPEC = 'version https://git-lfs.github.com/spec/v1';
96
+
97
+ /** `2026-11-04` in local time (the backup folder's name). */
98
+ function dayStamp(d) {
99
+ const pad = (n) => String(n).padStart(2, '0');
100
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
101
+ }
102
+
103
+ /**
104
+ * The repair prompt for a canvas's Git LFS placeholders. Built from the STUDIO's answer only: `items`
105
+ * are this lane's own items for the canvas; anything not `lfs-pointer` is ignored. Pure.
106
+ *
107
+ * It fits `maxChars` (default ASK_AI_MAX): Fix with AI pre-fills the chat through `sendToAskAI`, which
108
+ * keeps only that many chars, so a long path list would push the steps off the end. Paths are listed
109
+ * while they fit (at most LFS_PROMPT_MAX_PATHS); the rest are "…and N more", with how to find them.
110
+ *
111
+ * The restore goes through `git lfs` only (2.0.3 e2e): the design plugin's Bash guard refuses a `cp`
112
+ * into the design root and Write cannot put binary bytes back, so a prompt that said "copy the object
113
+ * over the placeholder" stopped after the backup. `git lfs checkout` restores a local object offline.
114
+ *
115
+ * @param {{ items: Iterable<any>, designRel?: string, date?: Date, maxChars?: number }} o
116
+ */
117
+ export function lfsRepairPrompt({
118
+ items,
119
+ designRel = '.design',
120
+ date = new Date(),
121
+ maxChars = ASK_AI_MAX,
122
+ }) {
123
+ const root = String(designRel || '')
124
+ .replace(/^\/+|\/+$/g, '')
125
+ .replace(/^\.\/?$/, '');
126
+ const inRoot = (rel) => (root ? `${root}/${rel}` : rel);
127
+ const ptrs = [];
128
+ for (const it of items) {
129
+ // a path is shown in backticks: one with a backtick or a line break is not listed
130
+ if (it?.state === 'lfs-pointer' && typeof it.rel === 'string' && !/[`\r\n]/.test(it.rel))
131
+ ptrs.push(it);
132
+ }
133
+ const backup = inRoot(`_trash/lfs-pointers-${dayStamp(date)}`);
134
+ const lineOf = (it) =>
135
+ `- \`${inRoot(it.rel)}\`${it.localObject ? ' (its object is already in .git/lfs/objects)' : ''}`;
136
+ const moreLine = (n) =>
137
+ `- …and ${n} more. Find the rest: every file of at most 1 KB under \`${root || '.'}/\` whose first line is exactly \`${LFS_SPEC}\`.`;
138
+ const head = [
139
+ 'Some pictures and videos in this project are Git LFS placeholders: small text files that stand where the real media should be (the project was cloned without `git lfs pull`). Please put the real files back.',
140
+ '',
141
+ 'The placeholder files, from the project root:',
142
+ ];
143
+ const steps = [
144
+ '',
145
+ 'Do this, step by step:',
146
+ `1. Back up the placeholder files first. Copy each one, keeping its path, into \`${backup}/\` (for example \`${inRoot('assets/a.png')}\` goes to \`${backup}/assets/a.png\`). That folder is ignored by git and never syncs.`,
147
+ '2. Restore them with Git LFS. Check it is installed with `git lfs version`; if it is not, say so (it installs with `brew install git-lfs`, then `git lfs install`) and stop. A file whose object is already in `.git/lfs/objects/<oid[0:2]>/<oid[2:4]>/<oid>` (the `oid sha256:<oid>` line of its pointer) comes back with `git lfs checkout <its path>`, with no network. For the ones left, run `git lfs pull --include "<their paths, comma-separated>"`; if that fails, say why. Do not copy or write the media files any other way.',
148
+ '3. Check each restored file: its sha256 must equal the oid, and its size must equal the `size <n>` line of its pointer. If one does not match, write its placeholder text back from the backup and tell me which file.',
149
+ '4. Do not commit anything, and do not change any other file.',
150
+ '5. Leave the restored files where they are. Maude uploads them by itself; there is nothing else to do.',
151
+ ];
152
+ // +1 per line for the joining '\n'
153
+ const len = (lines) => lines.reduce((n, l) => n + l.length + 1, -1);
154
+ const fixed = len([...head, ...steps]) + 1;
155
+ const lines = [];
156
+ let used = fixed;
157
+ for (const it of ptrs.slice(0, LFS_PROMPT_MAX_PATHS)) {
158
+ const line = lineOf(it);
159
+ const rest = ptrs.length - lines.length - 1;
160
+ // room for this line, and for the "…and N more" line if any are left after it
161
+ const need = line.length + 1 + (rest > 0 ? moreLine(rest).length + 1 : 0);
162
+ if (used + need > maxChars) break;
163
+ lines.push(line);
164
+ used += line.length + 1;
165
+ }
166
+ const more = ptrs.length - lines.length;
167
+ if (more > 0) lines.push(moreLine(more));
168
+ return [...head, ...lines, ...steps].join('\n');
169
+ }
170
+
171
+ /**
172
+ * Copy `text` from the shell; false when it was refused. The click was inside the canvas iframe, so the shell
173
+ * has no user activation: `navigator.clipboard` is tried briefly, then the desktop's `clipboard_write_text`.
174
+ */
175
+ async function shellCopyText(text) {
176
+ try {
177
+ return (await nativeSave().copyText(String(text))).ok === true;
178
+ } catch {
179
+ return false;
180
+ }
181
+ }
182
+
81
183
  const FRAME = 'iframe[data-testid="canvas-frame"]';
82
184
  export const ASSET_STATE_POLL_MS = 60_000;
83
185
  /** While something of this Mac's is still going up, ask again soon: the bar moves and goes away when the last byte lands. */
@@ -94,6 +196,11 @@ const pathOf = (frame) => frame?.getAttribute?.('data-path') || frame?.dataset?.
94
196
  * @param {() => Window | null} [deps.activeWindow] — the active canvas window (relink gate)
95
197
  * @param {() => string} deps.canvasOrigin
96
198
  * @param {(rel: string, canvas: string) => void} [deps.onRelink]
199
+ * @param {() => boolean} [deps.lfsActions] — this shell can repair an LFS placeholder (the AI chat exists)
200
+ * @param {() => string} [deps.designRel] — the design root, project-relative (the prompt's paths)
201
+ * @param {(prompt: string, canvas: string) => void} [deps.onLfsFix] — open the AI chat, pre-filled
202
+ * @param {(text: string) => Promise<boolean>} [deps.copyText]
203
+ * @param {() => Date} [deps.now]
97
204
  * @param {Window} [deps.win]
98
205
  * @param {(fn: () => void, ms: number) => unknown} [deps.setTimer]
99
206
  * @param {(t: unknown) => void} [deps.clearTimer]
@@ -105,6 +212,8 @@ export function createAssetStateLane(deps) {
105
212
  const win = deps.win ?? globalThis.window;
106
213
  const setTimer = deps.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
107
214
  const clearTimer = deps.clearTimer ?? ((t) => clearTimeout(t));
215
+ const lfsActions = () => deps.lfsActions?.() === true;
216
+ const copyText = deps.copyText ?? shellCopyText;
108
217
  /** Window → the JSON last said to it; `waiting` → whether it needs the 60 s poll. */
109
218
  const spoken = new WeakMap();
110
219
  const waiting = new Set();
@@ -143,14 +252,19 @@ export function createAssetStateLane(deps) {
143
252
  if (items.some((it) => it?.state === 'uploading')) uploading.add(canvas);
144
253
  else uploading.delete(canvas);
145
254
  arm();
146
- const json = JSON.stringify(items);
255
+ // The buttons are offered only where the AI chat exists, and only when there is a placeholder.
256
+ const offer = lfsActions() && items.some((it) => it?.state === 'lfs-pointer');
257
+ const json = JSON.stringify(offer ? [items, true] : items);
147
258
  const before = spoken.get(target);
148
259
  if (!force && before === json) return;
149
260
  if (before === undefined && items.length === 0) return;
150
261
  spoken.set(target, json);
151
262
  try {
152
263
  // A literal `{ dgn }` (not postToCanvas) so the bridge inventory sees this send site.
153
- target.postMessage({ dgn: 'asset-state', items }, deps.canvasOrigin() || '*');
264
+ target.postMessage(
265
+ offer ? { dgn: 'asset-state', items, lfsActions: true } : { dgn: 'asset-state', items },
266
+ deps.canvasOrigin() || '*'
267
+ );
154
268
  } catch {
155
269
  /* detached */
156
270
  }
@@ -182,6 +296,10 @@ export function createAssetStateLane(deps) {
182
296
  }
183
297
  return;
184
298
  }
299
+ if (dgn === 'asset-lfs-fix-request' || dgn === 'asset-lfs-copy-request') {
300
+ void onLfsRequest(e);
301
+ return;
302
+ }
185
303
  if (dgn !== 'asset-relink-request') return;
186
304
  const m = acceptFromCanvas(e, {
187
305
  canvasOrigin: deps.canvasOrigin(),
@@ -195,6 +313,39 @@ export function createAssetStateLane(deps) {
195
313
  const item = assetItemsFor(canvas).get(m.rel);
196
314
  if (item?.state === 'missing') deps.onRelink?.(item.rel, canvas);
197
315
  };
316
+ // 2.0.3 — Fix with AI / Copy prompt. The canvas names a rel; everything else is this lane's.
317
+ async function onLfsRequest(e) {
318
+ if (!lfsActions()) return;
319
+ const m = acceptFromCanvas(e, {
320
+ canvasOrigin: deps.canvasOrigin(),
321
+ active: deps.activeWindow?.() ?? null,
322
+ });
323
+ if (!m || (m.dgn !== 'asset-lfs-fix-request' && m.dgn !== 'asset-lfs-copy-request')) return;
324
+ const frame = frames().find((f) => f.contentWindow === e.source);
325
+ const canvas = pathOf(frame);
326
+ const mine = assetItemsFor(canvas);
327
+ const item = mine.get(m.rel);
328
+ if (!canvas || item?.state !== 'lfs-pointer') return;
329
+ const prompt = lfsRepairPrompt({
330
+ items: mine.values(),
331
+ designRel: deps.designRel?.() ?? '.design',
332
+ date: deps.now?.() ?? new Date(),
333
+ });
334
+ if (m.dgn === 'asset-lfs-fix-request') {
335
+ deps.onLfsFix?.(prompt, canvas);
336
+ return;
337
+ }
338
+ const ok = await copyText(prompt);
339
+ try {
340
+ // A literal `{ dgn }` so the bridge inventory sees this send site.
341
+ frame.contentWindow.postMessage(
342
+ { dgn: 'asset-lfs-copied', rel: item.rel, ok: ok === true },
343
+ deps.canvasOrigin() || '*'
344
+ );
345
+ } catch {
346
+ /* detached */
347
+ }
348
+ }
198
349
  win?.addEventListener?.('message', onMessage);
199
350
  // S8.14 — photos just placed from Finder reach the canvas file before their bytes reach the hub: when the index moves (the
200
351
  // placement is one), ask again shortly, so the new pictures hear `uploading` and wear a bar. One quiet read per burst.
@@ -238,7 +389,9 @@ export function assetStateTriggers(prev, next) {
238
389
 
239
390
  /**
240
391
  * Mount once in the shell. `syncStatus` / `wsConnected` are the app's live values; `onRelink` opens
241
- * the relink sheet for (rel, canvas).
392
+ * the relink sheet for (rel, canvas). `askAiAvailable` is the shell's answer the canvas error card
393
+ * uses (the desktop app's AI chat, not read-only): it alone turns on the LFS placeholder's buttons,
394
+ * and "Fix with AI" goes the error card's way — `ask-ai-fix` opens the chat with the prompt, unsent.
242
395
  */
243
396
  export function useAssetStateLane({
244
397
  syncStatus,
@@ -246,18 +399,30 @@ export function useAssetStateLane({
246
399
  canvasOrigin,
247
400
  activeWindow,
248
401
  onRelink,
402
+ askAiAvailable = false,
403
+ designRel = '.design',
249
404
  }) {
250
405
  const lane = useRef(null);
251
- const live = useRef({ canvasOrigin, activeWindow, onRelink });
252
- live.current = { canvasOrigin, activeWindow, onRelink };
406
+ const live = useRef({ canvasOrigin, activeWindow, onRelink, askAiAvailable, designRel });
407
+ live.current = { canvasOrigin, activeWindow, onRelink, askAiAvailable, designRel };
253
408
  useEffect(() => {
254
409
  lane.current = createAssetStateLane({
255
410
  canvasOrigin: () => live.current.canvasOrigin?.() ?? '',
256
411
  activeWindow: () => live.current.activeWindow?.() ?? null,
257
412
  onRelink: (rel, canvas) => live.current.onRelink?.(rel, canvas),
413
+ lfsActions: () => live.current.askAiAvailable === true,
414
+ designRel: () => live.current.designRel || '.design',
415
+ onLfsFix: (prompt, canvas) => dispatchCanvasOp('ask-ai-fix', canvas, prompt),
258
416
  });
259
417
  return () => lane.current?.stop();
260
418
  }, []);
419
+ // The answer can arrive after the first tell (config loads late): say it again with the buttons.
420
+ const askedAi = useRef(askAiAvailable);
421
+ useEffect(() => {
422
+ if (askedAi.current === askAiAvailable) return;
423
+ askedAi.current = askAiAvailable;
424
+ void lane.current?.refresh();
425
+ }, [askAiAvailable]);
261
426
  const prev = useRef(null);
262
427
  useEffect(() => {
263
428
  const next = { syncStatus, wsConnected };
@@ -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
+ }