@backmatter/studio 0.0.17 → 0.0.19

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 (48) hide show
  1. package/dist/chunks/{UiKitApp-D7vllRQE.js → UiKitApp-B1ANqCac.js} +528 -481
  2. package/dist/chunks/{WorkspaceRoutes-DH1LD-2Q.js → WorkspaceRoutes-BHNGrf-j.js} +24955 -24119
  3. package/dist/chunks/{dashboard-Dsaeud2x.js → dashboard-b-W6dGm5.js} +586 -565
  4. package/dist/chunks/{index-CGMqw2NH.js → index-HYioDjux.js} +104 -104
  5. package/dist/dashboard.js +2 -2
  6. package/dist/index.js +166 -159
  7. package/dist/site-widget.css +25 -6
  8. package/dist/site-widget.js +6925 -6840
  9. package/dist/studio.css +171 -42
  10. package/package.json +2 -2
  11. package/src/api.ts +44 -1
  12. package/src/chat/ChatMessage.tsx +4 -4
  13. package/src/chat/ChatProvider.tsx +6 -0
  14. package/src/chat/chat-helpers.ts +54 -2
  15. package/src/chrome/CommandPalette.tsx +3 -3
  16. package/src/chrome/ContentExplorerSidebar.tsx +421 -74
  17. package/src/chrome/WorkspaceStatusBar.tsx +24 -24
  18. package/src/chrome/commit-error.ts +48 -60
  19. package/src/chrome/commit-failure.tsx +2 -2
  20. package/src/chrome/content-path-tree.ts +4 -0
  21. package/src/chrome/explorer-row-menu.ts +28 -0
  22. package/src/chrome/folder-create-context.ts +14 -0
  23. package/src/chrome/use-publish-check.ts +75 -0
  24. package/src/{pages/code-session-routes.ts → content-routes.ts} +6 -6
  25. package/src/fields/FieldControl.tsx +198 -64
  26. package/src/fields/LinkFieldInput.tsx +315 -0
  27. package/src/fields/choose-field-input.ts +5 -0
  28. package/src/fields/link-targets.ts +60 -0
  29. package/src/host-path.ts +13 -0
  30. package/src/pages/CodeSessionPage.tsx +6 -241
  31. package/src/pages/DocEditorPage.tsx +121 -178
  32. package/src/pages/EmbedPublishPage.tsx +13 -5
  33. package/src/pages/GithubConnectPage.tsx +1 -1
  34. package/src/pages/LoginPage.tsx +67 -5
  35. package/src/pages/MediaFieldInput.tsx +712 -37
  36. package/src/pages/MediaGalleryPage.tsx +69 -5
  37. package/src/pages/PreviewAddress.tsx +293 -0
  38. package/src/pages/WorkspaceHomePage.tsx +1 -1
  39. package/src/pages/code-session-boot.ts +0 -12
  40. package/src/pages/media-selection.ts +79 -0
  41. package/src/pages/ui-kit/colors.tsx +2 -0
  42. package/src/pages/ui-kit/fields.tsx +60 -0
  43. package/src/styles/themes.ts +2 -0
  44. package/src/styles/tokens.stylex.ts +1 -0
  45. package/src/ui/Button.tsx +14 -0
  46. package/src/ui/Field.tsx +12 -1
  47. package/src/ui/Input.tsx +191 -97
  48. package/src/ui/popup.ts +13 -6
@@ -1,53 +1,395 @@
1
1
  // packages/studio/src/pages/MediaFieldInput.tsx
2
- import { useState } from "react";
2
+ import { useCallback, useEffect, useRef, useState, type DragEvent, type KeyboardEvent } from "react";
3
3
  import { Dialog } from "@base-ui/react/dialog";
4
4
  import { mediaIdFromUrl, mediaVariantUrl } from "@backmatter/core";
5
5
  import * as stylex from "@stylexjs/stylex";
6
- import { colors, radius, space, type } from "../styles/tokens.stylex";
6
+ import { fetchMedia, uploadMedia, type CatalogMedia, type SchemaField } from "../api";
7
+ import { useOutletContext } from "react-router";
8
+ import { colors, radius, space, type, z } from "../styles/tokens.stylex";
7
9
  import { Button } from "../ui/Button";
10
+ import { Text } from "../ui/Text";
8
11
  import { cx, isTransitioning } from "../ui/popup";
12
+ import type { WorkspaceOutletContext } from "../workspace/types";
13
+ import { rejectionReason } from "./media-grid";
14
+ import {
15
+ acceptedDrop,
16
+ appendMediaUrls,
17
+ editorUrls,
18
+ moveMediaUrl,
19
+ notAddedMessage,
20
+ toggleMediaUrl,
21
+ } from "./media-selection";
9
22
  import { MediaGalleryPage } from "./MediaGalleryPage";
10
23
 
11
24
  const CDN_ORIGIN = "https://cdn.backmatter.app";
12
25
 
26
+ type PendingUpload = {
27
+ key: string;
28
+ filename: string;
29
+ previewUrl: string;
30
+ };
31
+
32
+ const hover = "@media (hover: hover)";
33
+ const GALLERY_PER_ROW = 4;
34
+
35
+ function thumbForUrl(url: string): string | null {
36
+ const id = mediaIdFromUrl(url);
37
+ return id ? mediaVariantUrl(CDN_ORIGIN, id, 400) : null;
38
+ }
39
+
13
40
  export function MediaFieldInput({
41
+ field,
14
42
  value,
15
43
  readOnly,
16
44
  onChange,
17
45
  }: {
18
46
  name: string;
47
+ field: SchemaField;
19
48
  value: unknown;
20
49
  readOnly?: boolean;
21
50
  onChange: (value: unknown) => void;
22
51
  }) {
52
+ const { workspace } = useOutletContext<WorkspaceOutletContext>();
53
+ const multiple = field.multiple === true;
54
+ const parsed = editorUrls(value, multiple);
55
+ const savedUrls = parsed.urls;
56
+
23
57
  const [open, setOpen] = useState(false);
24
- const url = typeof value === "string" ? value : "";
25
- const id = url ? mediaIdFromUrl(url) : null;
26
- const thumb = id ? mediaVariantUrl(CDN_ORIGIN, id, 400) : null;
58
+ const [expanded, setExpanded] = useState(false);
59
+ const [checkUrls, setCheckUrls] = useState<string[]>([]);
60
+ const [rejections, setRejections] = useState<string[]>([]);
61
+ const [notAdded, setNotAdded] = useState(0);
62
+ const [pending, setPending] = useState<PendingUpload[]>([]);
63
+ const dragFrom = useRef<number | null>(null);
64
+ const [dropIndex, setDropIndex] = useState<number | null>(null);
65
+ const focusIndex = useRef<number | null>(null);
66
+ const gridRef = useRef<HTMLDivElement>(null);
67
+ const valueRef = useRef(value);
68
+ valueRef.current = value;
69
+ const onChangeRef = useRef(onChange);
70
+ onChangeRef.current = onChange;
71
+ const readOnlyRef = useRef(readOnly);
72
+ readOnlyRef.current = readOnly;
73
+
74
+ const write = useCallback((next: unknown, options?: { keepNotAdded?: boolean }) => {
75
+ if (readOnlyRef.current) return;
76
+ if (!options?.keepNotAdded) {
77
+ setNotAdded(0);
78
+ }
79
+ valueRef.current = next;
80
+ onChangeRef.current(next);
81
+ }, []);
82
+
83
+ const openModal = useCallback(() => {
84
+ setCheckUrls(editorUrls(valueRef.current, multiple).urls);
85
+ setOpen(true);
86
+ }, [multiple]);
87
+
88
+ const closeModal = useCallback(() => {
89
+ setOpen(false);
90
+ }, []);
91
+
92
+ const applyUse = useCallback(() => {
93
+ if (readOnly) return;
94
+ write(checkUrls.length === 0 ? undefined : checkUrls);
95
+ closeModal();
96
+ }, [checkUrls, closeModal, readOnly, write]);
97
+
98
+ const uploadFiles = useCallback(
99
+ (files: File[]) => {
100
+ if (readOnly) return;
101
+ const accepted: File[] = [];
102
+ const rejected: string[] = [];
103
+ for (const file of files) {
104
+ const reason = rejectionReason(file);
105
+ if (reason) rejected.push(reason);
106
+ else accepted.push(file);
107
+ }
108
+ setRejections(rejected);
109
+ if (accepted.length === 0) return;
110
+
111
+ const acceptedIds = accepted.map((file) => file.name);
112
+ const currentSaved = editorUrls(valueRef.current, multiple).urls;
113
+ const drop = acceptedDrop(currentSaved, acceptedIds, multiple);
114
+ setNotAdded(drop.notAdded);
115
+ const toUpload = multiple ? accepted : accepted.slice(0, drop.urls.length);
116
+
117
+ const items = toUpload.map((file) => ({
118
+ key: crypto.randomUUID(),
119
+ filename: file.name,
120
+ previewUrl: URL.createObjectURL(file),
121
+ file,
122
+ }));
123
+ setPending((current) => [
124
+ ...current,
125
+ ...items.map((item) => ({
126
+ key: item.key,
127
+ filename: item.filename,
128
+ previewUrl: item.previewUrl,
129
+ })),
130
+ ]);
131
+
132
+ for (const item of items) {
133
+ void uploadMedia(workspace.id, item.file)
134
+ .then((result) => {
135
+ URL.revokeObjectURL(item.previewUrl);
136
+ setPending((current) => current.filter((slot) => slot.key !== item.key));
137
+ const url = result.media.url;
138
+ const currentSaved = editorUrls(valueRef.current, multiple).urls;
139
+ if (multiple) {
140
+ write(appendMediaUrls(currentSaved, [url]));
141
+ return;
142
+ }
143
+ write(url, { keepNotAdded: true });
144
+ })
145
+ .catch(() => {
146
+ URL.revokeObjectURL(item.previewUrl);
147
+ setPending((current) => current.filter((slot) => slot.key !== item.key));
148
+ setRejections((current) => [...current, `${item.filename} could not be uploaded`]);
149
+ });
150
+ }
151
+ },
152
+ [multiple, readOnly, workspace.id, write],
153
+ );
154
+
155
+ const onFieldDrop = useCallback(
156
+ (event: DragEvent) => {
157
+ event.preventDefault();
158
+ event.stopPropagation();
159
+ uploadFiles(Array.from(event.dataTransfer?.files ?? []));
160
+ },
161
+ [uploadFiles],
162
+ );
163
+
164
+ const removeAt = useCallback(
165
+ (index: number) => {
166
+ const next = savedUrls.filter((_, i) => i !== index);
167
+ write(next.length === 0 ? undefined : next);
168
+ },
169
+ [savedUrls, write],
170
+ );
171
+
172
+ const onThumbDrop = useCallback(
173
+ (toIndex: number, event: DragEvent) => {
174
+ event.preventDefault();
175
+ const from = dragFrom.current;
176
+ dragFrom.current = null;
177
+ setDropIndex(null);
178
+ if (from === null || from === toIndex) return;
179
+ write(moveMediaUrl(savedUrls, from, toIndex));
180
+ },
181
+ [savedUrls, write],
182
+ );
183
+
184
+ const onThumbKeyDown = useCallback(
185
+ (index: number, event: KeyboardEvent) => {
186
+ if (!event.altKey) return;
187
+ const step = event.key === "ArrowLeft" ? -1 : event.key === "ArrowRight" ? 1 : 0;
188
+ const to = index + step;
189
+ if (step === 0 || to < 0 || to >= savedUrls.length) return;
190
+ event.preventDefault();
191
+ if (to >= GALLERY_PER_ROW) setExpanded(true);
192
+ focusIndex.current = to;
193
+ write(moveMediaUrl(savedUrls, index, to));
194
+ },
195
+ [savedUrls, write],
196
+ );
197
+
198
+ useEffect(() => {
199
+ const index = focusIndex.current;
200
+ if (index === null) return;
201
+ focusIndex.current = null;
202
+ gridRef.current?.querySelectorAll<HTMLElement>("[data-media-thumb]")[index]?.focus();
203
+ });
204
+
205
+ const note = notAddedMessage(notAdded);
206
+ const messages = [...rejections, ...(note ? [note] : [])];
207
+
208
+ const wrongShapeOne = !multiple && Array.isArray(parsed.raw);
209
+ const showThumb = !wrongShapeOne && savedUrls.length > 0;
210
+ const selectedUrl = showThumb ? savedUrls[0]! : null;
211
+ const catalogKey = savedUrls.map((url) => mediaIdFromUrl(url) ?? "").join("\n");
212
+ const [catalog, setCatalog] = useState<CatalogMedia[]>([]);
213
+
214
+ useEffect(() => {
215
+ if (!catalogKey) {
216
+ setCatalog([]);
217
+ return;
218
+ }
219
+ let cancelled = false;
220
+ void fetchMedia(workspace.id)
221
+ .then((page) => {
222
+ if (!cancelled) setCatalog(page.media);
223
+ })
224
+ .catch(() => {
225
+ if (!cancelled) setCatalog([]);
226
+ });
227
+ return () => {
228
+ cancelled = true;
229
+ };
230
+ }, [catalogKey, workspace.id]);
231
+
232
+ const detailsFor = (url: string) => {
233
+ const id = mediaIdFromUrl(url);
234
+ return id ? catalog.find((item) => item.id === id) ?? null : null;
235
+ };
236
+ const leadDetails = selectedUrl ? detailsFor(selectedUrl) : null;
237
+ const galleryFilled = multiple && (showThumb || pending.length > 0);
238
+ const hiddenCount = multiple && showThumb ? Math.max(0, savedUrls.length - GALLERY_PER_ROW) : 0;
239
+ const galleryUrls =
240
+ multiple && showThumb && !expanded ? savedUrls.slice(0, GALLERY_PER_ROW) : savedUrls;
27
241
 
28
242
  return (
29
- <div {...stylex.props(styles.row)}>
30
- {thumb ? (
31
- <img src={thumb} alt="" {...stylex.props(styles.thumb)} />
32
- ) : (
33
- <div {...stylex.props(styles.placeholder)}>No image</div>
34
- )}
35
- {readOnly ? null : (
36
- <Button variant="secondary" onClick={() => setOpen(true)}>
37
- Choose
38
- </Button>
39
- )}
40
- {readOnly || !url ? null : (
41
- <Button variant="ghost" onClick={() => onChange("")}>
42
- Clear
43
- </Button>
44
- )}
45
- <Dialog.Root open={open} onOpenChange={setOpen}>
243
+ <div {...stylex.props(styles.stack)}>
244
+ <div
245
+ data-media-drop
246
+ {...stylex.props(styles.row)}
247
+ onDragOver={(event) => event.preventDefault()}
248
+ onDrop={onFieldDrop}
249
+ >
250
+ {multiple && showThumb ? (
251
+ <div {...stylex.props(styles.galleryStack)}>
252
+ <div ref={gridRef} data-media-grid {...stylex.props(styles.galleryGrid)}>
253
+ {galleryUrls.map((url, index) => {
254
+ const thumb = thumbForUrl(url);
255
+ return (
256
+ <div
257
+ key={`${url}-${index}`}
258
+ data-media-thumb
259
+ role="group"
260
+ aria-label={`Image ${index + 1} of ${savedUrls.length}`}
261
+ aria-keyshortcuts={readOnly ? undefined : "Alt+ArrowLeft Alt+ArrowRight"}
262
+ tabIndex={readOnly ? undefined : 0}
263
+ draggable={!readOnly}
264
+ {...stylex.props(
265
+ styles.thumbWrap,
266
+ !readOnly && styles.thumbMovable,
267
+ dropIndex === index && styles.thumbDropTarget,
268
+ )}
269
+ onKeyDown={readOnly ? undefined : (event) => onThumbKeyDown(index, event)}
270
+ onDragStart={() => {
271
+ dragFrom.current = index;
272
+ }}
273
+ onDragEnd={() => {
274
+ dragFrom.current = null;
275
+ setDropIndex(null);
276
+ }}
277
+ onDragOver={(event) => {
278
+ event.preventDefault();
279
+ if (dragFrom.current !== null && dropIndex !== index) setDropIndex(index);
280
+ }}
281
+ onDrop={(event) => onThumbDrop(index, event)}
282
+ >
283
+ {thumb ? (
284
+ <img src={thumb} alt="" draggable={false} {...stylex.props(styles.galleryTile)} />
285
+ ) : (
286
+ <div {...stylex.props(styles.galleryTile, styles.moreEmpty)} />
287
+ )}
288
+ {readOnly || (field.required === true && savedUrls.length === 1) ? null : (
289
+ <button
290
+ type="button"
291
+ aria-label="Remove image"
292
+ {...stylex.props(styles.galleryRemove)}
293
+ onClick={() => removeAt(index)}
294
+ >
295
+ <CloseIcon />
296
+ </button>
297
+ )}
298
+ </div>
299
+ );
300
+ })}
301
+ {pending.map((item) => (
302
+ <div key={item.key} {...stylex.props(styles.thumbWrap)}>
303
+ <img src={item.previewUrl} alt="" {...stylex.props(styles.galleryTile, styles.pending)} />
304
+ </div>
305
+ ))}
306
+ {readOnly ? null : (
307
+ <button
308
+ type="button"
309
+ aria-label="Add images"
310
+ {...stylex.props(styles.galleryTile, styles.addTile)}
311
+ onClick={openModal}
312
+ >
313
+ <PlusIcon />
314
+ </button>
315
+ )}
316
+ </div>
317
+ {hiddenCount > 0 ? (
318
+ <button
319
+ type="button"
320
+ {...stylex.props(styles.showMore)}
321
+ onClick={() => setExpanded((current) => !current)}
322
+ >
323
+ {expanded ? "Show less" : `Show ${hiddenCount} more`}
324
+ </button>
325
+ ) : null}
326
+ </div>
327
+ ) : multiple && pending[0] ? (
328
+ <FileCard
329
+ src={pending[0].previewUrl}
330
+ name={pending[0].filename}
331
+ meta="Uploading"
332
+ readOnly
333
+ required
334
+ onEdit={openModal}
335
+ onRemove={() => undefined}
336
+ />
337
+ ) : multiple ? (
338
+ <div {...stylex.props(styles.thumbRow)} />
339
+ ) : wrongShapeOne ? (
340
+ <Text tone="muted">Choose one image</Text>
341
+ ) : showThumb ? (
342
+ <FileCard
343
+ src={thumbForUrl(selectedUrl!) ?? selectedUrl!}
344
+ name={leadDetails?.filename ?? "Image"}
345
+ meta={leadDetails ? mediaMeta(leadDetails) : null}
346
+ readOnly={readOnly}
347
+ required={field.required === true}
348
+ onEdit={openModal}
349
+ onRemove={() => write(undefined)}
350
+ />
351
+ ) : pending[0] ? (
352
+ <FileCard
353
+ src={pending[0].previewUrl}
354
+ name={pending[0].filename}
355
+ meta="Uploading"
356
+ readOnly
357
+ required
358
+ onEdit={openModal}
359
+ onRemove={() => undefined}
360
+ />
361
+ ) : (
362
+ <div {...stylex.props(styles.placeholder)}>No image</div>
363
+ )}
364
+ {readOnly || galleryFilled || (!multiple && showThumb && !wrongShapeOne) ? null : (
365
+ <Button variant="secondary" onClick={openModal}>
366
+ Choose
367
+ </Button>
368
+ )}
369
+ {readOnly || galleryFilled || !multiple || !showThumb || field.required ? null : (
370
+ <Button variant="ghost" onClick={() => write(undefined)}>
371
+ Clear
372
+ </Button>
373
+ )}
374
+ </div>
375
+ {messages.length > 0 ? (
376
+ <Text tone="danger" size="sm">
377
+ {messages.join(" · ")}
378
+ </Text>
379
+ ) : null}
380
+ <Dialog.Root
381
+ open={open}
382
+ onOpenChange={(next) => {
383
+ if (!next) closeModal();
384
+ }}
385
+ >
46
386
  <Dialog.Portal>
47
387
  <Dialog.Backdrop
388
+ data-media-dialog-backdrop
48
389
  className={(state) =>
49
390
  cx(styles.backdrop, isTransitioning(state.transitionStatus) && styles.backdropHidden)
50
391
  }
392
+ onClick={() => closeModal()}
51
393
  />
52
394
  <Dialog.Popup
53
395
  className={(state) =>
@@ -58,12 +400,31 @@ export function MediaFieldInput({
58
400
  <div {...stylex.props(styles.gallery)}>
59
401
  <MediaGalleryPage
60
402
  pick
61
- onPick={(next) => {
62
- onChange(next);
63
- setOpen(false);
64
- }}
403
+ pickedUrls={multiple ? checkUrls : undefined}
404
+ onToggleUrl={
405
+ multiple
406
+ ? (url) => {
407
+ setCheckUrls((current) => toggleMediaUrl(current, url));
408
+ }
409
+ : undefined
410
+ }
411
+ onPick={
412
+ multiple
413
+ ? undefined
414
+ : (url) => {
415
+ write(url);
416
+ closeModal();
417
+ }
418
+ }
65
419
  />
66
420
  </div>
421
+ {multiple ? (
422
+ <div {...stylex.props(styles.footer)}>
423
+ <Button variant="primary" onClick={applyUse}>
424
+ Use
425
+ </Button>
426
+ </div>
427
+ ) : null}
67
428
  </Dialog.Popup>
68
429
  </Dialog.Portal>
69
430
  </Dialog.Root>
@@ -71,16 +432,222 @@ export function MediaFieldInput({
71
432
  );
72
433
  }
73
434
 
74
- const fade = stylex.keyframes({
75
- from: { opacity: 0 },
76
- to: { opacity: 1 },
77
- });
435
+ function FileCard({
436
+ src,
437
+ name,
438
+ meta,
439
+ readOnly,
440
+ required,
441
+ onEdit,
442
+ onRemove,
443
+ }: {
444
+ src: string;
445
+ name: string;
446
+ meta: string | null;
447
+ readOnly?: boolean;
448
+ required: boolean;
449
+ onEdit: () => void;
450
+ onRemove: () => void;
451
+ }) {
452
+ return (
453
+ <div {...stylex.props(styles.fileCard)} data-media-file>
454
+ <img src={src} alt="" {...stylex.props(styles.fileThumb)} />
455
+ <div {...stylex.props(styles.fileText)}>
456
+ <span {...stylex.props(styles.fileName)}>{name}</span>
457
+ {meta ? <span {...stylex.props(styles.fileMeta)}>{meta}</span> : null}
458
+ </div>
459
+ {readOnly ? null : (
460
+ <div {...stylex.props(styles.fileActions)}>
461
+ <button type="button" aria-label="Edit image" {...stylex.props(styles.iconBtn)} onClick={onEdit}>
462
+ <PencilIcon />
463
+ </button>
464
+ {required ? null : (
465
+ <button
466
+ type="button"
467
+ aria-label="Remove image"
468
+ {...stylex.props(styles.iconBtn)}
469
+ onClick={onRemove}
470
+ >
471
+ <CloseIcon />
472
+ </button>
473
+ )}
474
+ </div>
475
+ )}
476
+ </div>
477
+ );
478
+ }
479
+
480
+ function mediaMeta(item: Pick<CatalogMedia, "byteSize" | "width" | "height" | "contentType">): string {
481
+ const parts = [formatBytes(item.byteSize)];
482
+ if (item.width > 0 && item.height > 0) parts.push(`${item.width}×${item.height}`);
483
+ if (item.contentType) parts.push(item.contentType);
484
+ return parts.join(" - ");
485
+ }
486
+
487
+ function formatBytes(bytes: number): string {
488
+ if (!Number.isFinite(bytes) || bytes < 0) return "0B";
489
+ if (bytes < 1024) return `${Math.round(bytes)}B`;
490
+ if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)}KB`;
491
+ const mb = bytes / (1024 * 1024);
492
+ const rounded = mb >= 10 ? Math.round(mb) : Math.round(mb * 10) / 10;
493
+ return `${rounded}MB`;
494
+ }
495
+
496
+ function PencilIcon() {
497
+ return (
498
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden>
499
+ <path
500
+ d="M9.2 3.4 12.6 6.8 6.1 13.3H2.7V9.9L9.2 3.4Z"
501
+ stroke="currentColor"
502
+ strokeWidth="1.25"
503
+ strokeLinejoin="round"
504
+ />
505
+ <path d="M8.1 4.5 11.5 7.9" stroke="currentColor" strokeWidth="1.25" />
506
+ </svg>
507
+ );
508
+ }
509
+
510
+ function PlusIcon() {
511
+ return (
512
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden>
513
+ <path d="M8 3.5V12.5M3.5 8H12.5" stroke="currentColor" strokeWidth="1.25" strokeLinecap="round" />
514
+ </svg>
515
+ );
516
+ }
517
+
518
+ function CloseIcon() {
519
+ return (
520
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden>
521
+ <path d="M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5" stroke="currentColor" strokeWidth="1.25" strokeLinecap="round" />
522
+ </svg>
523
+ );
524
+ }
78
525
 
79
526
  const styles = stylex.create({
527
+ stack: {
528
+ display: "flex",
529
+ flexDirection: "column",
530
+ gap: space.sm,
531
+ },
80
532
  row: {
81
533
  display: "flex",
82
534
  alignItems: "center",
83
535
  gap: space.md,
536
+ flexWrap: "wrap",
537
+ width: "100%",
538
+ },
539
+ thumbRow: {
540
+ display: "flex",
541
+ flexWrap: "wrap",
542
+ gap: space.sm,
543
+ },
544
+ galleryStack: {
545
+ display: "flex",
546
+ flexDirection: "column",
547
+ gap: space.sm,
548
+ width: "100%",
549
+ },
550
+ galleryGrid: {
551
+ display: "grid",
552
+ gridTemplateColumns: "repeat(auto-fill, 72px)",
553
+ gap: space.sm,
554
+ },
555
+ galleryTile: {
556
+ display: "block",
557
+ width: "72px",
558
+ height: "72px",
559
+ objectFit: "cover",
560
+ borderRadius: radius.md,
561
+ backgroundColor: colors.bgPanel,
562
+ },
563
+ galleryRemove: {
564
+ position: "absolute",
565
+ top: space.xs,
566
+ right: space.xs,
567
+ display: "flex",
568
+ alignItems: "center",
569
+ justifyContent: "center",
570
+ width: "22px",
571
+ height: "22px",
572
+ padding: 0,
573
+ borderWidth: 1,
574
+ borderStyle: "solid",
575
+ borderColor: "rgba(255, 255, 255, 0.6)",
576
+ borderRadius: "999px",
577
+ backgroundColor: "rgba(24, 24, 27, 0.85)",
578
+ color: "#fafafa",
579
+ cursor: "pointer",
580
+ opacity: {
581
+ default: "var(--remove-opacity, 0)",
582
+ ":focus-visible": 1,
583
+ },
584
+ transitionProperty: "opacity",
585
+ transitionDuration: "120ms",
586
+ },
587
+ addTile: {
588
+ display: "flex",
589
+ alignItems: "center",
590
+ justifyContent: "center",
591
+ boxSizing: "border-box",
592
+ padding: 0,
593
+ borderWidth: 1,
594
+ borderStyle: "dashed",
595
+ borderColor: colors.border,
596
+ backgroundColor: "transparent",
597
+ color: colors.textMuted,
598
+ cursor: "pointer",
599
+ [hover]: {
600
+ ":hover": {
601
+ backgroundColor: colors.bgHover,
602
+ color: colors.text,
603
+ },
604
+ },
605
+ },
606
+ showMore: {
607
+ alignSelf: "flex-start",
608
+ padding: 0,
609
+ borderWidth: 0,
610
+ backgroundColor: "transparent",
611
+ color: colors.textMuted,
612
+ cursor: "pointer",
613
+ fontSize: type.sm,
614
+ [hover]: {
615
+ ":hover": {
616
+ color: colors.text,
617
+ },
618
+ },
619
+ },
620
+ moreEmpty: {
621
+ borderWidth: 1,
622
+ borderStyle: "solid",
623
+ borderColor: colors.border,
624
+ },
625
+ thumbWrap: {
626
+ position: "relative",
627
+ borderRadius: radius.md,
628
+ "--remove-opacity": {
629
+ default: 0,
630
+ ":hover": 1,
631
+ ":focus-within": 1,
632
+ "@media (hover: none)": 1,
633
+ },
634
+ outlineOffset: 2,
635
+ ":focus-visible": {
636
+ outlineWidth: 2,
637
+ outlineStyle: "solid",
638
+ outlineColor: colors.focus,
639
+ },
640
+ },
641
+ thumbMovable: {
642
+ cursor: "grab",
643
+ ":active": {
644
+ cursor: "grabbing",
645
+ },
646
+ },
647
+ thumbDropTarget: {
648
+ outlineWidth: 2,
649
+ outlineStyle: "dashed",
650
+ outlineColor: colors.focus,
84
651
  },
85
652
  thumb: {
86
653
  width: "4.5rem",
@@ -89,6 +656,9 @@ const styles = stylex.create({
89
656
  borderRadius: radius.md,
90
657
  backgroundColor: colors.bgPanel,
91
658
  },
659
+ pending: {
660
+ opacity: 0.55,
661
+ },
92
662
  placeholder: {
93
663
  width: "4.5rem",
94
664
  height: "4.5rem",
@@ -100,31 +670,128 @@ const styles = stylex.create({
100
670
  color: colors.textMuted,
101
671
  fontSize: type.xs,
102
672
  },
673
+ fileCard: {
674
+ display: "flex",
675
+ alignItems: "center",
676
+ gap: space.md,
677
+ width: "100%",
678
+ minWidth: 0,
679
+ boxSizing: "border-box",
680
+ padding: space.sm,
681
+ paddingRight: space.md,
682
+ borderWidth: 1,
683
+ borderStyle: "solid",
684
+ borderColor: colors.border,
685
+ borderRadius: radius.md,
686
+ backgroundColor: colors.bgInput,
687
+ },
688
+ fileThumb: {
689
+ width: "40px",
690
+ height: "40px",
691
+ flexShrink: 0,
692
+ objectFit: "cover",
693
+ borderRadius: radius.sm,
694
+ backgroundColor: colors.bgPanel,
695
+ },
696
+ fileText: {
697
+ display: "flex",
698
+ minWidth: 0,
699
+ flex: 1,
700
+ flexDirection: "column",
701
+ gap: "2px",
702
+ },
703
+ fileName: {
704
+ overflow: "hidden",
705
+ textOverflow: "ellipsis",
706
+ whiteSpace: "nowrap",
707
+ color: colors.text,
708
+ fontSize: type.md,
709
+ },
710
+ fileMeta: {
711
+ overflow: "hidden",
712
+ textOverflow: "ellipsis",
713
+ whiteSpace: "nowrap",
714
+ color: colors.textMuted,
715
+ fontSize: type.xs,
716
+ },
717
+ fileActions: {
718
+ display: "flex",
719
+ flexShrink: 0,
720
+ alignItems: "center",
721
+ gap: space.xs,
722
+ },
723
+ iconBtn: {
724
+ display: "flex",
725
+ alignItems: "center",
726
+ justifyContent: "center",
727
+ width: "28px",
728
+ height: "28px",
729
+ padding: 0,
730
+ borderWidth: 0,
731
+ borderRadius: radius.sm,
732
+ backgroundColor: "transparent",
733
+ color: colors.textMuted,
734
+ cursor: "pointer",
735
+ [hover]: {
736
+ ":hover": {
737
+ backgroundColor: colors.bgHover,
738
+ color: colors.text,
739
+ },
740
+ },
741
+ },
742
+ remove: {
743
+ position: "absolute",
744
+ top: 2,
745
+ right: 2,
746
+ width: "1.25rem",
747
+ height: "1.25rem",
748
+ padding: 0,
749
+ borderWidth: 0,
750
+ borderRadius: radius.sm,
751
+ backgroundColor: colors.overlay,
752
+ color: colors.textInverse,
753
+ cursor: "pointer",
754
+ fontSize: type.sm,
755
+ lineHeight: 1,
756
+ },
103
757
  backdrop: {
104
758
  position: "fixed",
105
759
  inset: 0,
760
+ zIndex: z.overlay,
106
761
  backgroundColor: colors.overlay,
107
- animationName: fade,
108
- animationDuration: "120ms",
762
+ backdropFilter: "blur(8px)",
763
+ transitionProperty: "opacity",
764
+ transitionDuration: "160ms",
765
+ transitionTimingFunction: "ease-out",
766
+ "@media (prefers-reduced-motion: reduce)": {
767
+ transitionDuration: "0ms",
768
+ },
109
769
  },
110
770
  backdropHidden: {
111
771
  opacity: 0,
112
772
  },
113
773
  popup: {
114
774
  position: "fixed",
115
- top: "8vh",
116
- left: "50%",
117
- transform: "translateX(-50%)",
118
- width: "min(960px, calc(100vw - 32px))",
119
- height: "min(720px, 80vh)",
775
+ inset: "clamp(12px, 3vw, 32px)",
776
+ zIndex: z.palette,
120
777
  display: "flex",
121
778
  flexDirection: "column",
122
779
  backgroundColor: colors.bgSurface,
123
780
  borderRadius: radius.md,
781
+ boxShadow: "0 24px 64px rgba(0, 0, 0, 0.35)",
124
782
  overflow: "hidden",
783
+ outline: "none",
784
+ transformOrigin: "center",
785
+ transitionProperty: "opacity, transform",
786
+ transitionDuration: "160ms",
787
+ transitionTimingFunction: "cubic-bezier(0.2, 0, 0, 1)",
788
+ "@media (prefers-reduced-motion: reduce)": {
789
+ transitionDuration: "0ms",
790
+ },
125
791
  },
126
792
  popupHidden: {
127
793
  opacity: 0,
794
+ transform: "scale(0.98)",
128
795
  },
129
796
  title: {
130
797
  margin: 0,
@@ -136,4 +803,12 @@ const styles = stylex.create({
136
803
  flex: 1,
137
804
  minHeight: 0,
138
805
  },
806
+ footer: {
807
+ display: "flex",
808
+ justifyContent: "flex-end",
809
+ padding: space.lg,
810
+ borderTopWidth: 1,
811
+ borderTopStyle: "solid",
812
+ borderTopColor: colors.border,
813
+ },
139
814
  });