@panneau/media 5.0.0-alpha.4 → 5.0.0-alpha.6

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 (83) hide show
  1. package/README.md +94 -7
  2. package/dist/ImageItem.d.ts +23 -0
  3. package/dist/ImageItem.d.ts.map +1 -0
  4. package/dist/ImageItem.js +292 -0
  5. package/dist/ImageItem.js.map +1 -0
  6. package/dist/MediaField.css +127 -0
  7. package/dist/MediaField.d.ts +67 -15
  8. package/dist/MediaField.d.ts.map +1 -1
  9. package/dist/MediaField.js +354 -148
  10. package/dist/MediaField.js.map +1 -1
  11. package/dist/MediaField.module.js +28 -2
  12. package/dist/MediaField.module.js.map +1 -1
  13. package/dist/editor/ImageEditor.css +369 -0
  14. package/dist/editor/ImageEditor.d.ts +13 -0
  15. package/dist/editor/ImageEditor.d.ts.map +1 -0
  16. package/dist/editor/ImageEditor.js +461 -0
  17. package/dist/editor/ImageEditor.js.map +1 -0
  18. package/dist/editor/ImageEditor.module.js +86 -0
  19. package/dist/editor/ImageEditor.module.js.map +1 -0
  20. package/dist/editor/draw.d.ts +37 -0
  21. package/dist/editor/draw.d.ts.map +1 -0
  22. package/dist/editor/draw.js +93 -0
  23. package/dist/editor/draw.js.map +1 -0
  24. package/dist/editor/geometry.d.ts +54 -0
  25. package/dist/editor/geometry.d.ts.map +1 -0
  26. package/dist/editor/geometry.js +227 -0
  27. package/dist/editor/geometry.js.map +1 -0
  28. package/dist/editor/index.d.ts +5 -0
  29. package/dist/editor/index.d.ts.map +1 -0
  30. package/dist/editor/index.js +3 -0
  31. package/dist/editor/tools.d.ts +11 -0
  32. package/dist/editor/tools.d.ts.map +1 -0
  33. package/dist/editor/tools.js +1199 -0
  34. package/dist/editor/tools.js.map +1 -0
  35. package/dist/editor/types.d.ts +111 -0
  36. package/dist/editor/types.d.ts.map +1 -0
  37. package/dist/index.d.ts +3 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -2
  40. package/dist/picker/MediaDetails.d.ts +22 -0
  41. package/dist/picker/MediaDetails.d.ts.map +1 -0
  42. package/dist/picker/MediaDetails.js +368 -0
  43. package/dist/picker/MediaDetails.js.map +1 -0
  44. package/dist/picker/MediaGrid.d.ts +30 -0
  45. package/dist/picker/MediaGrid.d.ts.map +1 -0
  46. package/dist/picker/MediaGrid.js +260 -0
  47. package/dist/picker/MediaGrid.js.map +1 -0
  48. package/dist/picker/MediaPicker.css +642 -0
  49. package/dist/picker/MediaPicker.d.ts +9 -0
  50. package/dist/picker/MediaPicker.d.ts.map +1 -0
  51. package/dist/picker/MediaPicker.js +601 -0
  52. package/dist/picker/MediaPicker.js.map +1 -0
  53. package/dist/picker/MediaPicker.module.js +132 -0
  54. package/dist/picker/MediaPicker.module.js.map +1 -0
  55. package/dist/picker/PickerToolbar.d.ts +19 -0
  56. package/dist/picker/PickerToolbar.d.ts.map +1 -0
  57. package/dist/picker/PickerToolbar.js +266 -0
  58. package/dist/picker/PickerToolbar.js.map +1 -0
  59. package/dist/picker/UploadPanel.d.ts +22 -0
  60. package/dist/picker/UploadPanel.d.ts.map +1 -0
  61. package/dist/picker/UploadPanel.js +186 -0
  62. package/dist/picker/UploadPanel.js.map +1 -0
  63. package/dist/picker/format.d.ts +18 -0
  64. package/dist/picker/format.d.ts.map +1 -0
  65. package/dist/picker/format.js +64 -0
  66. package/dist/picker/format.js.map +1 -0
  67. package/dist/picker/index.d.ts +3 -0
  68. package/dist/picker/index.d.ts.map +1 -0
  69. package/dist/picker/index.js +1 -0
  70. package/dist/picker/types.d.ts +119 -0
  71. package/dist/picker/types.d.ts.map +1 -0
  72. package/dist/picker/useMediaBrowser.d.ts +50 -0
  73. package/dist/picker/useMediaBrowser.d.ts.map +1 -0
  74. package/dist/picker/useMediaBrowser.js +314 -0
  75. package/dist/picker/useMediaBrowser.js.map +1 -0
  76. package/dist/plugin.d.ts +1 -1
  77. package/dist/plugin.js +5 -2
  78. package/dist/plugin.js.map +1 -1
  79. package/dist/resourceSource.d.ts +21 -0
  80. package/dist/resourceSource.d.ts.map +1 -0
  81. package/dist/resourceSource.js +99 -0
  82. package/dist/resourceSource.js.map +1 -0
  83. package/package.json +18 -7
@@ -0,0 +1,601 @@
1
+ import MediaPicker_module_default from "./MediaPicker.module.js";
2
+ import { describeAccept, isProcessingMedia } from "./format.js";
3
+ import { MediaGrid } from "./MediaGrid.js";
4
+ import { MediaDetails } from "./MediaDetails.js";
5
+ import { PickerToolbar } from "./PickerToolbar.js";
6
+ import { UploadPanel } from "./UploadPanel.js";
7
+ import { useMediaBrowser } from "./useMediaBrowser.js";
8
+ import { c } from "react/compiler-runtime";
9
+ import { Images, Lock, SearchX } from "lucide-react";
10
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
11
+ import { formatSize, useFieldsContext, useRejectionMessage, useUploads } from "@panneau/fields";
12
+ import { mediaMessages } from "@panneau/intl";
13
+ import { Alert, Button, Dialog, Heading, SegmentedControl, Select, Spinner, Tab, TabList, TabPanel, Tabs, Text, usePanneauIntl } from "@panneau/ui";
14
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
+ //#region src/picker/MediaPicker.tsx
16
+ var NO_FILTER = {};
17
+ var keyOf = (source, id) => `${source}\n${id}`;
18
+ /** The smallest of two limits, either of which may be missing. */
19
+ function smallest(a, b) {
20
+ const limits = [a, b].filter((limit) => typeof limit === "number");
21
+ return limits.length > 0 ? Math.min(...limits) : null;
22
+ }
23
+ function isDefaultQuery(query) {
24
+ return query.q === "" && query.type === null && Object.keys(query.filter).length === 0;
25
+ }
26
+ /** The reference a picker returns for a media of a source. */
27
+ function toReference({ source, item }) {
28
+ return {
29
+ id: item.id,
30
+ resource: source,
31
+ label: item.label,
32
+ media: item.media
33
+ };
34
+ }
35
+ function Skeletons() {
36
+ const $ = c(1);
37
+ let t0;
38
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
39
+ t0 = /* @__PURE__ */ jsx("div", {
40
+ className: MediaPicker_module_default.grid,
41
+ "aria-hidden": true,
42
+ children: Array.from({ length: 12 }, _temp)
43
+ });
44
+ $[0] = t0;
45
+ } else t0 = $[0];
46
+ return t0;
47
+ }
48
+ /**
49
+ * The media picker (decision 0027): browse the libraries given as sources, upload to them, and
50
+ * pick one media, or several with `multiple`. It returns references with their library
51
+ * (`resource`). The `media` field opens it, and so can a product's own screens, with their
52
+ * sources, title and button.
53
+ */
54
+ function _temp(_, index) {
55
+ return /* @__PURE__ */ jsxs("div", {
56
+ className: MediaPicker_module_default.skeletonCard,
57
+ children: [
58
+ /* @__PURE__ */ jsx("span", { className: MediaPicker_module_default.skeletonThumbnail }),
59
+ /* @__PURE__ */ jsx("span", { className: MediaPicker_module_default.skeletonLine }),
60
+ /* @__PURE__ */ jsx("span", { className: MediaPicker_module_default.skeletonLineShort })
61
+ ]
62
+ }, index);
63
+ }
64
+ function MediaPicker(props) {
65
+ const $ = c(2);
66
+ if (!props.isOpen) return null;
67
+ let t0;
68
+ if ($[0] !== props) {
69
+ t0 = /* @__PURE__ */ jsx(OpenMediaPicker, { ...props });
70
+ $[0] = props;
71
+ $[1] = t0;
72
+ } else t0 = $[1];
73
+ return t0;
74
+ }
75
+ function OpenMediaPicker({ onOpenChange, sources, source: initialSource, multiple = false, accept = null, maxSize = null, filter: locked = NO_FILTER, filters: openerFilters = [], sorts: openerSorts = [], sort: openerSort, value = [], title, confirmLabel, confirmOnUpload = false, stateKey, uploadSource, refreshInterval = 3e3, onSelect }) {
76
+ const intl = usePanneauIntl();
77
+ const context = useFieldsContext();
78
+ const [sourceId, setSourceId] = useState(initialSource ?? sources[0]?.id ?? "");
79
+ const source = sources.find((candidate) => candidate.id === sourceId) ?? sources[0] ?? null;
80
+ const [tab, setTab] = useState("library");
81
+ const [selection, setSelection] = useState(/* @__PURE__ */ new Map());
82
+ const [focused, setFocused] = useState(null);
83
+ const [pendingFocus, setPendingFocus] = useState(null);
84
+ const [detailsOpen, setDetailsOpen] = useState(false);
85
+ const [draft, setDraft] = useState(null);
86
+ const [saving, setSaving] = useState(false);
87
+ const [saveError, setSaveError] = useState(null);
88
+ const [uploaded, setUploaded] = useState(/* @__PURE__ */ new Map());
89
+ const [problems, setProblems] = useState([]);
90
+ const [creating, setCreating] = useState([]);
91
+ const sortsOf = (candidate_0) => [...candidate_0.sorts ?? [], ...openerSorts.filter((sort) => !(candidate_0.sorts ?? []).some((own) => own.id === sort.id))];
92
+ const browser = useMediaBrowser({
93
+ sources,
94
+ source,
95
+ locked,
96
+ defaultSort: (candidate_1) => openerSort ?? sortsOf(candidate_1)[0]?.id ?? null,
97
+ stateKey
98
+ });
99
+ const { state } = browser;
100
+ const current = new Set(value.map((reference) => keyOf(reference.resource ?? sources[0]?.id ?? "", reference.id)));
101
+ const picked = [...selection.values()];
102
+ const unchanged = !multiple && picked.length === 1 && value.length === 1 && current.has(keyOf(picked[0]?.source ?? "", picked[0]?.item.id ?? ""));
103
+ const pickedSources = new Set(picked.map((entry) => entry.source));
104
+ const known = /* @__PURE__ */ new Map();
105
+ for (const [id, items] of uploaded) items.forEach((item) => known.set(keyOf(id, item.id), {
106
+ source: id,
107
+ item
108
+ }));
109
+ if (source !== null) state.items.forEach((item_0) => known.set(keyOf(source.id, item_0.id), {
110
+ source: source.id,
111
+ item: item_0
112
+ }));
113
+ for (const [key, entry_0] of selection) known.set(key, entry_0);
114
+ const focusedEntry = focused !== null ? known.get(focused) ?? null : null;
115
+ const focusedSource = sources.find((candidate_2) => candidate_2.id === focusedEntry?.source);
116
+ const fields = focusedSource?.update !== void 0 ? focusedSource.fields ?? [] : [];
117
+ const draftValues = draft !== null && draft.key === focused ? draft.values : focusedEntry?.item.values ?? {};
118
+ const dirty = draft !== null && draft.key === focused;
119
+ /** Puts a media everywhere the picker shows it: after a refresh or a save. */
120
+ const replace = (sourceKey, item_1) => {
121
+ const key_0 = keyOf(sourceKey, item_1.id);
122
+ browser.upsert(sourceKey, [item_1]);
123
+ setSelection((currentSelection) => currentSelection.has(key_0) ? new Map(currentSelection).set(key_0, {
124
+ source: sourceKey,
125
+ item: item_1
126
+ }) : currentSelection);
127
+ setUploaded((currentUploaded) => {
128
+ const items_0 = currentUploaded.get(sourceKey);
129
+ return items_0?.some((entry_2) => entry_2.id === item_1.id) === true ? new Map(currentUploaded).set(sourceKey, items_0.map((entry_1) => entry_1.id === item_1.id ? item_1 : entry_1)) : currentUploaded;
130
+ });
131
+ };
132
+ const focus = (key_1) => {
133
+ if (dirty && key_1 !== focused) {
134
+ setPendingFocus(key_1);
135
+ return;
136
+ }
137
+ setFocused(key_1);
138
+ setSaveError(null);
139
+ };
140
+ const save = async () => {
141
+ if (focusedEntry === null || focusedSource?.update === void 0 || draft === null) return true;
142
+ setSaving(true);
143
+ setSaveError(null);
144
+ try {
145
+ const saved = await focusedSource.update(focusedEntry.item.id, draft.values);
146
+ replace(focusedEntry.source, saved);
147
+ setDraft(null);
148
+ return true;
149
+ } catch (error) {
150
+ setSaveError(intl.formatMessage(mediaMessages.pickerSaveFailed, { error: error instanceof Error ? error.message : String(error) }));
151
+ return false;
152
+ } finally {
153
+ setSaving(false);
154
+ }
155
+ };
156
+ const confirm = (entries) => {
157
+ onSelect(entries.map(toReference));
158
+ onOpenChange(false);
159
+ };
160
+ /**
161
+ * A grid reports what it has selected among its media. Two grids show a source (its library and
162
+ * its uploads): each only changes the selection of the media it shows.
163
+ */
164
+ const select = (sourceKey_0, items_1, ids, added) => {
165
+ const shown = new Set(items_1.map((item_2) => item_2.id));
166
+ const isShown = (entry_3) => entry_3.source === sourceKey_0 && shown.has(entry_3.item.id);
167
+ setSelection((currentSelection_0) => {
168
+ if (!multiple) {
169
+ const item_3 = items_1.find((entry_4) => ids.has(entry_4.id));
170
+ if (item_3 !== void 0) return /* @__PURE__ */ new Map([[keyOf(sourceKey_0, item_3.id), {
171
+ source: sourceKey_0,
172
+ item: item_3
173
+ }]]);
174
+ return [...currentSelection_0.values()].some(isShown) ? /* @__PURE__ */ new Map() : currentSelection_0;
175
+ }
176
+ const next = new Map([...currentSelection_0].filter(([, entry_5]) => !isShown(entry_5) || ids.has(entry_5.item.id)));
177
+ for (const item_4 of items_1) if (ids.has(item_4.id)) next.set(keyOf(sourceKey_0, item_4.id), {
178
+ source: sourceKey_0,
179
+ item: item_4
180
+ });
181
+ return next;
182
+ });
183
+ if (added !== null) focus(keyOf(sourceKey_0, added));
184
+ };
185
+ const following = [...known.values()].filter(({ item: item_5 }) => isProcessingMedia(item_5));
186
+ const followKey = following.map(({ source: id_0, item: item_6 }) => `${keyOf(id_0, item_6.id)}:${item_6.media.status ?? ""}`).join(",");
187
+ const latestFollowing = useRef(following);
188
+ const latestReplace = useRef(replace);
189
+ useEffect(() => {
190
+ latestFollowing.current = following;
191
+ latestReplace.current = replace;
192
+ });
193
+ useEffect(() => {
194
+ if (followKey === "") return;
195
+ const controller = new AbortController();
196
+ const timer = setTimeout(() => {
197
+ for (const entry_6 of latestFollowing.current) sources.find((candidate_3) => candidate_3.id === entry_6.source)?.get(entry_6.item.id, { signal: controller.signal }).then((item_7) => latestReplace.current(entry_6.source, item_7)).catch(() => void 0);
198
+ }, refreshInterval);
199
+ return () => {
200
+ clearTimeout(timer);
201
+ controller.abort();
202
+ };
203
+ }, [
204
+ followKey,
205
+ refreshInterval,
206
+ sources
207
+ ]);
208
+ const uploadAccept = accept ?? source?.accept ?? null;
209
+ const uploadMaxSize = smallest(maxSize, source?.maxSize);
210
+ const rejectionMessage = useRejectionMessage(uploadMaxSize);
211
+ const upload = useUploads({
212
+ source: uploadSource === void 0 ? context.uploadSource : uploadSource,
213
+ accept: uploadAccept,
214
+ maxSize: uploadMaxSize,
215
+ onUploaded: (file) => {
216
+ if (source === null) return;
217
+ const target = source;
218
+ const name = file.name;
219
+ setCreating((currentCreating) => [...currentCreating, name]);
220
+ target.create(file).then((item_8) => {
221
+ const entry_7 = {
222
+ source: target.id,
223
+ item: item_8
224
+ };
225
+ setUploaded((currentUploaded_0) => new Map(currentUploaded_0).set(target.id, [item_8, ...currentUploaded_0.get(target.id) ?? []]));
226
+ browser.upsert(target.id, [item_8]);
227
+ if (!multiple && confirmOnUpload) {
228
+ confirm([entry_7]);
229
+ return;
230
+ }
231
+ setSelection((currentSelection_1) => multiple ? new Map(currentSelection_1).set(keyOf(target.id, item_8.id), entry_7) : /* @__PURE__ */ new Map([[keyOf(target.id, item_8.id), entry_7]]));
232
+ focus(keyOf(target.id, item_8.id));
233
+ }).catch((error_0) => setProblems((currentProblems) => [...currentProblems, intl.formatMessage(mediaMessages.pickerCreateFailed, {
234
+ name,
235
+ error: error_0 instanceof Error ? error_0.message : String(error_0)
236
+ })])).finally(() => setCreating((currentCreating_0) => {
237
+ const at = currentCreating_0.indexOf(name);
238
+ return at === -1 ? currentCreating_0 : currentCreating_0.filter((_, index) => index !== at);
239
+ }));
240
+ },
241
+ onRejected: (file_0, reason) => setProblems((currentProblems_0) => [...currentProblems_0, rejectionMessage(file_0, reason)])
242
+ });
243
+ const scroller = useRef(null);
244
+ const sentinel = useRef(null);
245
+ const latestLoadMore = useRef(browser.loadMore);
246
+ useEffect(() => {
247
+ latestLoadMore.current = browser.loadMore;
248
+ });
249
+ const hasMore = state.nextCursor !== null;
250
+ const browsing = state.items.length > 0;
251
+ useEffect(() => {
252
+ const target_0 = sentinel.current;
253
+ if (target_0 === null || !hasMore || typeof IntersectionObserver === "undefined") return;
254
+ const observer = new IntersectionObserver((entries_0) => {
255
+ if (entries_0.some((entry_8) => entry_8.isIntersecting)) latestLoadMore.current();
256
+ }, {
257
+ root: scroller.current,
258
+ rootMargin: "200px"
259
+ });
260
+ observer.observe(target_0);
261
+ return () => observer.disconnect();
262
+ }, [
263
+ hasMore,
264
+ browsing,
265
+ sourceId,
266
+ tab
267
+ ]);
268
+ const restoreScroll = useRef(browser.scrollTop);
269
+ useEffect(() => {
270
+ restoreScroll.current = browser.scrollTop;
271
+ });
272
+ useLayoutEffect(() => {
273
+ if (scroller.current !== null) scroller.current.scrollTop = restoreScroll.current();
274
+ }, [
275
+ sourceId,
276
+ tab,
277
+ browsing
278
+ ]);
279
+ if (source === null) return null;
280
+ const library = source.label;
281
+ const filters = [...source.filters ?? [], ...openerFilters];
282
+ const label = typeof confirmLabel === "function" ? confirmLabel(picked.length) : confirmLabel ?? intl.formatMessage(mediaMessages.pickerSelect);
283
+ const selectedIn = (sourceKey_1) => new Set(picked.filter((entry_9) => entry_9.source === sourceKey_1).map((entry_10) => entry_10.item.id));
284
+ const currentIn = (sourceKey_2) => new Set(value.filter((reference_0) => (reference_0.resource ?? sources[0]?.id) === sourceKey_2).map((reference_1) => reference_1.id));
285
+ const grid = (items_2, gridLabel) => /* @__PURE__ */ jsx(MediaGrid, {
286
+ items: items_2,
287
+ label: gridLabel,
288
+ multiple,
289
+ selected: selectedIn(source.id),
290
+ current: currentIn(source.id),
291
+ onSelectionChange: (ids_0, added_0) => select(source.id, items_2, ids_0, added_0),
292
+ onDetails: (id_1) => {
293
+ focus(keyOf(source.id, id_1));
294
+ setDetailsOpen(true);
295
+ },
296
+ accept,
297
+ maxSize
298
+ });
299
+ let libraryContent;
300
+ if (state.items.length === 0 && (state.status === "idle" || state.status === "loading")) libraryContent = /* @__PURE__ */ jsxs("div", {
301
+ className: MediaPicker_module_default.scroll,
302
+ "aria-busy": "true",
303
+ children: [/* @__PURE__ */ jsx("span", {
304
+ className: MediaPicker_module_default.visuallyHidden,
305
+ role: "status",
306
+ children: intl.formatMessage(mediaMessages.pickerLoading)
307
+ }), /* @__PURE__ */ jsx(Skeletons, {})]
308
+ });
309
+ else if (state.items.length === 0 && state.status === "error") libraryContent = /* @__PURE__ */ jsx("div", {
310
+ className: MediaPicker_module_default.center,
311
+ children: /* @__PURE__ */ jsx(Alert, {
312
+ tone: "danger",
313
+ role: "alert",
314
+ title: intl.formatMessage(mediaMessages.pickerLoadError),
315
+ actions: /* @__PURE__ */ jsx(Button, {
316
+ size: "sm",
317
+ onPress: browser.retry,
318
+ children: intl.formatMessage(mediaMessages.pickerRetry)
319
+ })
320
+ })
321
+ });
322
+ else if (state.items.length === 0 && isDefaultQuery(state.query)) libraryContent = /* @__PURE__ */ jsxs("div", {
323
+ className: MediaPicker_module_default.empty,
324
+ children: [
325
+ /* @__PURE__ */ jsx(Images, {
326
+ "aria-hidden": true,
327
+ size: 48,
328
+ strokeWidth: 1.25,
329
+ className: MediaPicker_module_default.emptyIcon
330
+ }),
331
+ /* @__PURE__ */ jsx(Heading, {
332
+ level: 3,
333
+ size: 4,
334
+ children: intl.formatMessage(mediaMessages.pickerEmpty, { library })
335
+ }),
336
+ source.canCreate ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Text, {
337
+ muted: true,
338
+ size: "sm",
339
+ children: intl.formatMessage(mediaMessages.pickerEmptyUpload, { library })
340
+ }), /* @__PURE__ */ jsx(Button, {
341
+ variant: "primary",
342
+ onPress: () => setTab("upload"),
343
+ children: intl.formatMessage(mediaMessages.pickerUploadFiles)
344
+ })] }) : /* @__PURE__ */ jsx(Text, {
345
+ muted: true,
346
+ size: "sm",
347
+ children: intl.formatMessage(mediaMessages.pickerEmptyReadOnly)
348
+ })
349
+ ]
350
+ });
351
+ else if (state.items.length === 0) libraryContent = /* @__PURE__ */ jsxs("div", {
352
+ className: MediaPicker_module_default.empty,
353
+ children: [
354
+ /* @__PURE__ */ jsx(SearchX, {
355
+ "aria-hidden": true,
356
+ size: 48,
357
+ strokeWidth: 1.25,
358
+ className: MediaPicker_module_default.emptyIcon
359
+ }),
360
+ /* @__PURE__ */ jsx(Heading, {
361
+ level: 3,
362
+ size: 4,
363
+ children: intl.formatMessage(mediaMessages.pickerNoResults)
364
+ }),
365
+ /* @__PURE__ */ jsx(Button, {
366
+ onPress: () => browser.setQuery({
367
+ ...state.query,
368
+ q: "",
369
+ type: null,
370
+ filter: {}
371
+ }),
372
+ children: intl.formatMessage(mediaMessages.pickerClearSearch)
373
+ })
374
+ ]
375
+ });
376
+ else libraryContent = /* @__PURE__ */ jsxs("div", {
377
+ className: MediaPicker_module_default.browse,
378
+ "data-details-open": detailsOpen || void 0,
379
+ children: [/* @__PURE__ */ jsxs("div", {
380
+ ref: scroller,
381
+ className: MediaPicker_module_default.scroll,
382
+ onScroll: (event) => browser.rememberScroll(event.currentTarget.scrollTop),
383
+ children: [grid(state.items, intl.formatMessage(mediaMessages.pickerMedia, { library })), /* @__PURE__ */ jsxs("div", {
384
+ className: MediaPicker_module_default.more,
385
+ children: [
386
+ state.total !== null ? /* @__PURE__ */ jsx(Text, {
387
+ muted: true,
388
+ size: "sm",
389
+ as: "span",
390
+ children: intl.formatMessage(mediaMessages.pickerCount, {
391
+ shown: state.items.length,
392
+ total: state.total
393
+ })
394
+ }) : null,
395
+ state.status === "more" ? /* @__PURE__ */ jsx(Spinner, {
396
+ size: "sm",
397
+ label: intl.formatMessage(mediaMessages.pickerLoadingMore)
398
+ }) : null,
399
+ state.status === "error" ? /* @__PURE__ */ jsx(Button, {
400
+ size: "sm",
401
+ onPress: browser.retry,
402
+ children: intl.formatMessage(mediaMessages.pickerRetry)
403
+ }) : hasMore && state.status === "ready" ? /* @__PURE__ */ jsx(Button, {
404
+ size: "sm",
405
+ variant: "ghost",
406
+ onPress: browser.loadMore,
407
+ children: intl.formatMessage(mediaMessages.pickerLoadMore)
408
+ }) : null,
409
+ /* @__PURE__ */ jsx("div", {
410
+ ref: sentinel,
411
+ className: MediaPicker_module_default.sentinel
412
+ })
413
+ ]
414
+ })]
415
+ }), /* @__PURE__ */ jsx(MediaDetails, {
416
+ item: focusedEntry?.item ?? null,
417
+ fields,
418
+ draft: draftValues,
419
+ onDraftChange: (values) => focused !== null ? setDraft({
420
+ key: focused,
421
+ values
422
+ }) : void 0,
423
+ dirty,
424
+ saving,
425
+ error: saveError,
426
+ onSave: () => void save(),
427
+ onBack: () => setDetailsOpen(false)
428
+ })]
429
+ });
430
+ const uploadedHere = uploaded.get(source.id) ?? [];
431
+ return /* @__PURE__ */ jsxs(Dialog, {
432
+ isOpen: true,
433
+ onOpenChange,
434
+ title: title ?? intl.formatMessage(mediaMessages.pickerTitle),
435
+ size: "xl",
436
+ fullScreenOnPhone: true,
437
+ className: MediaPicker_module_default.dialog,
438
+ bodyClassName: MediaPicker_module_default.body,
439
+ headerContent: sources.length > 3 ? /* @__PURE__ */ jsx(Select, {
440
+ "aria-label": intl.formatMessage(mediaMessages.pickerLibraries),
441
+ isRequired: true,
442
+ options: sources.map((candidate_4) => ({
443
+ value: candidate_4.id,
444
+ label: candidate_4.label
445
+ })),
446
+ value: source.id,
447
+ onChange: (next_0) => setSourceId(String(next_0)),
448
+ className: MediaPicker_module_default.librarySelect
449
+ }) : sources.length > 1 ? /* @__PURE__ */ jsx(SegmentedControl, {
450
+ "aria-label": intl.formatMessage(mediaMessages.pickerLibraries),
451
+ size: "sm",
452
+ options: sources.map((candidate_5) => ({
453
+ value: candidate_5.id,
454
+ label: candidate_5.label
455
+ })),
456
+ value: source.id,
457
+ onChange: setSourceId
458
+ }) : null,
459
+ footer: /* @__PURE__ */ jsxs("div", {
460
+ className: MediaPicker_module_default.footer,
461
+ children: [/* @__PURE__ */ jsx("div", {
462
+ className: MediaPicker_module_default.summary,
463
+ "aria-live": "polite",
464
+ children: picked.length === 0 ? /* @__PURE__ */ jsx(Text, {
465
+ muted: true,
466
+ size: "sm",
467
+ as: "span",
468
+ children: intl.formatMessage(mediaMessages.pickerNothingSelected)
469
+ }) : multiple ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Text, {
470
+ size: "sm",
471
+ weight: "medium",
472
+ as: "span",
473
+ children: pickedSources.size > 1 ? intl.formatMessage(mediaMessages.pickerSelectedIn, {
474
+ count: picked.length,
475
+ libraries: pickedSources.size
476
+ }) : intl.formatMessage(mediaMessages.pickerSelectedCount, { count: picked.length })
477
+ }), /* @__PURE__ */ jsx(Button, {
478
+ size: "sm",
479
+ variant: "ghost",
480
+ onPress: () => setSelection(/* @__PURE__ */ new Map()),
481
+ children: intl.formatMessage(mediaMessages.pickerClear)
482
+ })] }) : /* @__PURE__ */ jsx(Text, {
483
+ size: "sm",
484
+ as: "span",
485
+ truncate: true,
486
+ children: intl.formatMessage(mediaMessages.pickerSelected, { name: picked[0]?.item.label ?? "" })
487
+ })
488
+ }), /* @__PURE__ */ jsxs("div", {
489
+ className: MediaPicker_module_default.actions,
490
+ children: [/* @__PURE__ */ jsx(Button, {
491
+ className: MediaPicker_module_default.cancel,
492
+ onPress: () => onOpenChange(false),
493
+ children: intl.formatMessage(mediaMessages.pickerCancel)
494
+ }), /* @__PURE__ */ jsx(Button, {
495
+ variant: "primary",
496
+ isDisabled: picked.length === 0 || unchanged,
497
+ onPress: () => confirm(picked),
498
+ children: label
499
+ })]
500
+ })]
501
+ }),
502
+ children: [/* @__PURE__ */ jsxs(Tabs, {
503
+ className: MediaPicker_module_default.tabs,
504
+ selectedKey: tab,
505
+ onSelectionChange: (key_2) => setTab(String(key_2)),
506
+ disabledKeys: source.canCreate ? [] : ["upload"],
507
+ children: [
508
+ /* @__PURE__ */ jsxs("div", {
509
+ className: MediaPicker_module_default.bar,
510
+ children: [/* @__PURE__ */ jsxs(TabList, {
511
+ "aria-label": intl.formatMessage(mediaMessages.pickerTabs),
512
+ className: MediaPicker_module_default.tabList,
513
+ children: [/* @__PURE__ */ jsx(Tab, {
514
+ id: "library",
515
+ children: intl.formatMessage(mediaMessages.pickerTabLibrary)
516
+ }), /* @__PURE__ */ jsx(Tab, {
517
+ id: "upload",
518
+ children: intl.formatMessage(mediaMessages.pickerTabUpload)
519
+ })]
520
+ }), !source.canCreate ? /* @__PURE__ */ jsxs("span", {
521
+ className: MediaPicker_module_default.cannotUpload,
522
+ children: [/* @__PURE__ */ jsx(Lock, {
523
+ "aria-hidden": true,
524
+ size: 14
525
+ }), intl.formatMessage(mediaMessages.pickerCannotUpload, { library })]
526
+ }) : null]
527
+ }),
528
+ /* @__PURE__ */ jsxs(TabPanel, {
529
+ id: "library",
530
+ className: MediaPicker_module_default.panel,
531
+ children: [
532
+ state.items.length > 0 || !isDefaultQuery(state.query) ? /* @__PURE__ */ jsx(PickerToolbar, {
533
+ query: state.query,
534
+ onQueryChange: browser.setQuery,
535
+ sorts: sortsOf(source),
536
+ filters,
537
+ locked,
538
+ lockedFilters: filters
539
+ }) : null,
540
+ accept !== null || maxSize !== null ? /* @__PURE__ */ jsx(Text, {
541
+ size: "sm",
542
+ muted: true,
543
+ className: MediaPicker_module_default.constraints,
544
+ children: maxSize !== null ? intl.formatMessage(mediaMessages.pickerAcceptedSize, {
545
+ types: accept !== null && accept.length > 0 ? describeAccept(accept, intl) : intl.formatMessage(mediaMessages.pickerAnyFile),
546
+ size: formatSize(maxSize, intl.locale)
547
+ }) : intl.formatMessage(mediaMessages.pickerAccepted, { types: describeAccept(accept ?? [], intl) })
548
+ }) : null,
549
+ libraryContent
550
+ ]
551
+ }),
552
+ /* @__PURE__ */ jsx(TabPanel, {
553
+ id: "upload",
554
+ className: MediaPicker_module_default.panel,
555
+ children: /* @__PURE__ */ jsx("div", {
556
+ className: MediaPicker_module_default.scroll,
557
+ children: /* @__PURE__ */ jsx(UploadPanel, {
558
+ library,
559
+ multiple,
560
+ confirmOnUpload,
561
+ accept: uploadAccept,
562
+ maxSize: uploadMaxSize,
563
+ upload,
564
+ problems,
565
+ creating,
566
+ uploaded: uploadedHere.length > 0 ? grid(uploadedHere, intl.formatMessage(mediaMessages.pickerAddedTo, { library })) : null
567
+ })
568
+ })
569
+ })
570
+ ]
571
+ }), /* @__PURE__ */ jsx(Dialog, {
572
+ isOpen: pendingFocus !== null,
573
+ onOpenChange: (open) => open ? void 0 : setPendingFocus(null),
574
+ role: "alertdialog",
575
+ isDismissable: false,
576
+ size: "sm",
577
+ title: intl.formatMessage(mediaMessages.pickerUnsaved, { name: focusedEntry?.item.label ?? "" }),
578
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
579
+ onPress: () => {
580
+ setDraft(null);
581
+ setFocused(pendingFocus);
582
+ setPendingFocus(null);
583
+ },
584
+ children: intl.formatMessage(mediaMessages.pickerDiscard)
585
+ }), /* @__PURE__ */ jsx(Button, {
586
+ variant: "primary",
587
+ isDisabled: saving,
588
+ onPress: () => void save().then((saved_0) => {
589
+ if (saved_0) setFocused(pendingFocus);
590
+ setPendingFocus(null);
591
+ }),
592
+ children: intl.formatMessage(mediaMessages.pickerSave)
593
+ })] }),
594
+ children: intl.formatMessage(mediaMessages.pickerUnsavedText)
595
+ })]
596
+ });
597
+ }
598
+ //#endregion
599
+ export { MediaPicker };
600
+
601
+ //# sourceMappingURL=MediaPicker.js.map