@panneau/media 5.0.0-alpha.5 → 5.0.0-alpha.7

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.
@@ -147,12 +147,40 @@ function _temp(entry) {
147
147
  };
148
148
  }
149
149
  function MediaField(props) {
150
+ const $ = c(141);
150
151
  const intl = usePanneauIntl();
151
152
  const contextAdapter = useOptionalDataAdapter();
152
153
  const context = useFieldsContext();
153
- const { adapter = contextAdapter, uploadSource = context.uploadSource, accept = null, maxSize = null, refreshInterval = 3e3, resource, itemTitle = "name", sources = [], stateKey, label, description, errors = [], disabled, readOnly, required, className, labelClassName, descriptionClassName, errorsClassName } = props;
154
+ const { adapter: t0, accept: t1, maxSize: t2, refreshInterval: t3, resource, itemTitle: t4, sources: t5, stateKey, label, description, errors: t6, disabled, readOnly, required, className, labelClassName, descriptionClassName, errorsClassName } = props;
155
+ const adapter = t0 === void 0 ? contextAdapter : t0;
156
+ const accept = t1 === void 0 ? null : t1;
157
+ const maxSize = t2 === void 0 ? null : t2;
158
+ const refreshInterval = t3 === void 0 ? 3e3 : t3;
159
+ const itemTitle = t4 === void 0 ? "name" : t4;
160
+ let t7;
161
+ if ($[0] !== t5) {
162
+ t7 = t5 === void 0 ? [] : t5;
163
+ $[0] = t5;
164
+ $[1] = t7;
165
+ } else t7 = $[1];
166
+ const sources = t7;
167
+ let t8;
168
+ if ($[2] !== t6) {
169
+ t8 = t6 === void 0 ? [] : t6;
170
+ $[2] = t6;
171
+ $[3] = t8;
172
+ } else t8 = $[3];
173
+ const errors = t8;
174
+ const uploadSource = props.uploadSource === void 0 ? context.uploadSource : props.uploadSource;
154
175
  const multiple = props.multiple === true;
155
- const media = toMediaReferences(props.value, itemTitle);
176
+ let t9;
177
+ if ($[4] !== itemTitle || $[5] !== props.value) {
178
+ t9 = toMediaReferences(props.value, itemTitle);
179
+ $[4] = itemTitle;
180
+ $[5] = props.value;
181
+ $[6] = t9;
182
+ } else t9 = $[6];
183
+ const media = t9;
156
184
  const enabled = disabled !== true && readOnly !== true;
157
185
  const canUpload = adapter !== null && enabled;
158
186
  const canPick = sources.length > 0 && enabled;
@@ -160,37 +188,72 @@ function MediaField(props) {
160
188
  const imageOptions = props.image ?? null;
161
189
  const [editing, setEditing] = useState(null);
162
190
  const editorTools = useImageEditorTools();
163
- const [problems, setProblems] = useState([]);
164
- const [creating, setCreating] = useState([]);
191
+ let t10;
192
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
193
+ t10 = [];
194
+ $[7] = t10;
195
+ } else t10 = $[7];
196
+ const [problems, setProblems] = useState(t10);
197
+ let t11;
198
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
199
+ t11 = [];
200
+ $[8] = t11;
201
+ } else t11 = $[8];
202
+ const [creating, setCreating] = useState(t11);
165
203
  const rejectionMessage = useRejectionMessage(maxSize);
166
204
  const latest = useRef(media);
167
- useEffect(() => {
168
- latest.current = media;
169
- });
170
- const set = (next) => {
171
- latest.current = next;
172
- if (props.multiple === true) props.onChange?.(next.length > 0 ? next : null);
173
- else props.onChange?.(next[0] ?? null);
174
- };
175
- /** Adds picked media: a single pick replaces the media, several are added to the list, once. */
176
- const add = (picked) => {
177
- const known = new Set(latest.current.map((entry) => keyOf(entry, resource)));
178
- set(multiple ? [...latest.current, ...picked.filter((entry_0) => !known.has(keyOf(entry_0, resource)))] : picked.slice(0, 1));
179
- };
180
- useMediaRefresh(media, resource, adapter, refreshInterval, (refreshed) => set(latest.current.map((reference) => {
181
- const item = refreshed.find((candidate) => candidate.item.id === reference.id && candidate.resource === (reference.resource ?? resource))?.item;
182
- const fresh = item !== void 0 ? toMediaReference(item, itemTitle) : null;
183
- return fresh !== null ? {
184
- ...reference,
185
- ...fresh,
186
- transform: reference.transform
187
- } : reference;
188
- })));
189
- const upload = useUploads({
190
- source: uploadSource,
191
- accept,
192
- maxSize,
193
- onUploaded: (file) => {
205
+ let t12;
206
+ if ($[9] !== media) {
207
+ t12 = () => {
208
+ latest.current = media;
209
+ };
210
+ $[9] = media;
211
+ $[10] = t12;
212
+ } else t12 = $[10];
213
+ useEffect(t12);
214
+ let t13;
215
+ if ($[11] !== props) {
216
+ t13 = (next) => {
217
+ latest.current = next;
218
+ if (props.multiple === true) props.onChange?.(next.length > 0 ? next : null);
219
+ else props.onChange?.(next[0] ?? null);
220
+ };
221
+ $[11] = props;
222
+ $[12] = t13;
223
+ } else t13 = $[12];
224
+ const set = t13;
225
+ let t14;
226
+ if ($[13] !== multiple || $[14] !== resource || $[15] !== set) {
227
+ t14 = (picked) => {
228
+ const known = new Set(latest.current.map((entry) => keyOf(entry, resource)));
229
+ set(multiple ? [...latest.current, ...picked.filter((entry_0) => !known.has(keyOf(entry_0, resource)))] : picked.slice(0, 1));
230
+ };
231
+ $[13] = multiple;
232
+ $[14] = resource;
233
+ $[15] = set;
234
+ $[16] = t14;
235
+ } else t14 = $[16];
236
+ const add = t14;
237
+ let t15;
238
+ if ($[17] !== itemTitle || $[18] !== resource || $[19] !== set) {
239
+ t15 = (refreshed) => set(latest.current.map((reference) => {
240
+ const item = refreshed.find((candidate) => candidate.item.id === reference.id && candidate.resource === (reference.resource ?? resource))?.item;
241
+ const fresh = item !== void 0 ? toMediaReference(item, itemTitle) : null;
242
+ return fresh !== null ? {
243
+ ...reference,
244
+ ...fresh,
245
+ transform: reference.transform
246
+ } : reference;
247
+ }));
248
+ $[17] = itemTitle;
249
+ $[18] = resource;
250
+ $[19] = set;
251
+ $[20] = t15;
252
+ } else t15 = $[20];
253
+ useMediaRefresh(media, resource, adapter, refreshInterval, t15);
254
+ let t16;
255
+ if ($[21] !== adapter || $[22] !== intl || $[23] !== itemTitle || $[24] !== multiple || $[25] !== resource || $[26] !== set) {
256
+ t16 = (file) => {
194
257
  if (adapter === null) return;
195
258
  const name = file.name;
196
259
  setCreating((current) => [...current, name]);
@@ -204,202 +267,423 @@ function MediaField(props) {
204
267
  const at = current_1.indexOf(name);
205
268
  return at === -1 ? current_1 : current_1.filter((_, index) => index !== at);
206
269
  }));
207
- },
208
- onRejected: (file_0, reason) => setProblems((current_2) => [...current_2, rejectionMessage(file_0, reason)])
209
- });
210
- const statusBadge = (item_1) => {
211
- if (item_1.media?.status === "failed") return /* @__PURE__ */ jsx(Badge, {
212
- tone: "danger",
213
- children: intl.formatMessage(mediaMessages.statusFailed)
214
- });
215
- if (isProcessing(item_1)) return /* @__PURE__ */ jsx(Badge, {
216
- tone: "warning",
217
- children: intl.formatMessage(item_1.media?.status === "pending" ? mediaMessages.statusPending : mediaMessages.statusProcessing)
218
- });
219
- return null;
220
- };
221
- const imageRatios = imageOptions?.ratios ?? [];
222
- const constraints = imageOptions === null ? [] : [...imageRatios.length > 0 ? [intl.formatMessage(imageOptions.enforceRatios === true ? mediaMessages.imageRatios : mediaMessages.imageSuggestedRatios, { ratios: intl.formatList(imageRatios, { type: "disjunction" }) })] : [], ...imageOptions.cropRequired === true ? [intl.formatMessage(mediaMessages.imageCropRequired)] : []];
223
- const edited = editing === null ? null : "key" in editing ? media.find((entry_1) => keyOf(entry_1, resource) === editing.key) ?? null : editing.picked;
224
- const editedImage = edited !== null ? editedImageOf(edited) : null;
225
- const tools = [
226
- editorTools.crop,
227
- ...imageOptions?.rotate === false ? [] : [editorTools.rotate],
228
- ...imageOptions?.focalPoint === false ? [] : [editorTools.focalPoint]
229
- ];
270
+ };
271
+ $[21] = adapter;
272
+ $[22] = intl;
273
+ $[23] = itemTitle;
274
+ $[24] = multiple;
275
+ $[25] = resource;
276
+ $[26] = set;
277
+ $[27] = t16;
278
+ } else t16 = $[27];
279
+ let t17;
280
+ if ($[28] !== rejectionMessage) {
281
+ t17 = (file_0, reason) => setProblems((current_2) => [...current_2, rejectionMessage(file_0, reason)]);
282
+ $[28] = rejectionMessage;
283
+ $[29] = t17;
284
+ } else t17 = $[29];
285
+ let t18;
286
+ if ($[30] !== accept || $[31] !== maxSize || $[32] !== t16 || $[33] !== t17 || $[34] !== uploadSource) {
287
+ t18 = {
288
+ source: uploadSource,
289
+ accept,
290
+ maxSize,
291
+ onUploaded: t16,
292
+ onRejected: t17
293
+ };
294
+ $[30] = accept;
295
+ $[31] = maxSize;
296
+ $[32] = t16;
297
+ $[33] = t17;
298
+ $[34] = uploadSource;
299
+ $[35] = t18;
300
+ } else t18 = $[35];
301
+ const upload = useUploads(t18);
302
+ let t19;
303
+ if ($[36] !== intl) {
304
+ t19 = (item_1) => {
305
+ if (item_1.media?.status === "failed") {
306
+ const reason_0 = item_1.media.error?.message;
307
+ return /* @__PURE__ */ jsxs("span", {
308
+ className: MediaField_module_default.failed,
309
+ children: [/* @__PURE__ */ jsx(Badge, {
310
+ tone: "danger",
311
+ children: intl.formatMessage(mediaMessages.statusFailed)
312
+ }), typeof reason_0 === "string" && reason_0 !== "" ? /* @__PURE__ */ jsx("span", {
313
+ className: MediaField_module_default.failure,
314
+ title: reason_0,
315
+ children: reason_0
316
+ }) : null]
317
+ });
318
+ }
319
+ if (isProcessing(item_1)) return /* @__PURE__ */ jsx(Badge, {
320
+ tone: "warning",
321
+ children: intl.formatMessage(item_1.media?.status === "pending" ? mediaMessages.statusPending : mediaMessages.statusProcessing)
322
+ });
323
+ return null;
324
+ };
325
+ $[36] = intl;
326
+ $[37] = t19;
327
+ } else t19 = $[37];
328
+ const statusBadge = t19;
329
+ let imageRatios;
330
+ let t20;
331
+ if ($[38] !== imageOptions || $[39] !== intl) {
332
+ imageRatios = imageOptions?.ratios ?? [];
333
+ t20 = imageOptions === null ? [] : [...imageRatios.length > 0 ? [intl.formatMessage(imageOptions.enforceRatios === true ? mediaMessages.imageRatios : mediaMessages.imageSuggestedRatios, { ratios: intl.formatList(imageRatios, { type: "disjunction" }) })] : [], ...imageOptions.cropRequired === true ? [intl.formatMessage(mediaMessages.imageCropRequired)] : []];
334
+ $[38] = imageOptions;
335
+ $[39] = intl;
336
+ $[40] = imageRatios;
337
+ $[41] = t20;
338
+ } else {
339
+ imageRatios = $[40];
340
+ t20 = $[41];
341
+ }
342
+ const constraints = t20;
343
+ let t21;
344
+ if ($[42] !== editing || $[43] !== media || $[44] !== resource) {
345
+ t21 = editing === null ? null : "key" in editing ? media.find((entry_1) => keyOf(entry_1, resource) === editing.key) ?? null : editing.picked;
346
+ $[42] = editing;
347
+ $[43] = media;
348
+ $[44] = resource;
349
+ $[45] = t21;
350
+ } else t21 = $[45];
351
+ const edited = t21;
352
+ let t22;
353
+ if ($[46] !== edited) {
354
+ t22 = edited !== null ? editedImageOf(edited) : null;
355
+ $[46] = edited;
356
+ $[47] = t22;
357
+ } else t22 = $[47];
358
+ const editedImage = t22;
359
+ let t23;
360
+ if ($[48] !== editorTools.rotate || $[49] !== imageOptions?.rotate) {
361
+ t23 = imageOptions?.rotate === false ? [] : [editorTools.rotate];
362
+ $[48] = editorTools.rotate;
363
+ $[49] = imageOptions?.rotate;
364
+ $[50] = t23;
365
+ } else t23 = $[50];
366
+ let t24;
367
+ if ($[51] !== editorTools.focalPoint || $[52] !== imageOptions?.focalPoint) {
368
+ t24 = imageOptions?.focalPoint === false ? [] : [editorTools.focalPoint];
369
+ $[51] = editorTools.focalPoint;
370
+ $[52] = imageOptions?.focalPoint;
371
+ $[53] = t24;
372
+ } else t24 = $[53];
373
+ let t25;
374
+ if ($[54] !== editorTools.crop || $[55] !== t23 || $[56] !== t24) {
375
+ t25 = [
376
+ editorTools.crop,
377
+ ...t23,
378
+ ...t24
379
+ ];
380
+ $[54] = editorTools.crop;
381
+ $[55] = t23;
382
+ $[56] = t24;
383
+ $[57] = t25;
384
+ } else t25 = $[57];
385
+ const tools = t25;
230
386
  const unavailable = adapter === null && disabled !== true && readOnly !== true;
231
387
  const chooseLabel = imageOptions !== null ? multiple ? mediaMessages.addImages : mediaMessages.chooseImage : multiple ? mediaMessages.addMedia : mediaMessages.chooseMedia;
232
388
  const cropStep = imageOptions?.cropRequired === true && !multiple;
233
- const withTransform = (reference_0, transform) => {
234
- const { transform: _previous, ...rest } = reference_0;
235
- return transform === null || transform === void 0 ? rest : {
236
- ...rest,
237
- transform
238
- };
239
- };
240
- return /* @__PURE__ */ jsxs(Fieldset, {
241
- legend: label,
242
- description: description !== void 0 || unavailable || constraints.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
389
+ const withTransform = _temp3;
390
+ let t26;
391
+ if ($[58] !== constraints || $[59] !== description || $[60] !== intl || $[61] !== unavailable) {
392
+ t26 = description !== void 0 || unavailable || constraints.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
243
393
  description,
244
394
  unavailable ? `${description !== void 0 ? " " : ""}${intl.formatMessage(mediaMessages.unavailable)}` : null,
245
395
  constraints.length > 0 ? /* @__PURE__ */ jsx("span", {
246
396
  className: MediaField_module_default.constraints,
247
- children: constraints.map((constraint) => /* @__PURE__ */ jsx(Badge, { children: constraint }, constraint))
397
+ children: constraints.map(_temp4)
248
398
  }) : null
249
- ] }) : void 0,
250
- errors: [...errors, ...problems],
251
- isRequired: required,
252
- isDisabled: disabled,
253
- className,
254
- legendClassName: labelClassName,
255
- descriptionClassName,
256
- errorsClassName,
257
- children: [
258
- /* @__PURE__ */ jsxs("div", {
259
- className: MediaField_module_default.field,
260
- children: [
261
- media.length > 0 && imageOptions !== null ? /* @__PURE__ */ jsx("ul", {
262
- className: multiple ? MediaField_module_default.gallery : MediaField_module_default.media,
263
- children: media.map((item_2) => /* @__PURE__ */ jsx(ImageItem, {
264
- reference: item_2,
265
- tile: multiple,
266
- cropRequired: imageOptions.cropRequired === true,
267
- status: statusBadge(item_2),
268
- onEdit: enabled ? () => setEditing({ key: keyOf(item_2, resource) }) : null,
269
- onRemove: canUpload || canPick ? () => set(latest.current.filter((entry_2) => keyOf(entry_2, resource) !== keyOf(item_2, resource))) : null
270
- }, keyOf(item_2, resource)))
271
- }) : media.length > 0 ? /* @__PURE__ */ jsx("ul", {
272
- className: MediaField_module_default.media,
273
- children: media.map((item_3) => {
274
- const name_0 = item_3.label ?? item_3.id;
275
- const size = item_3.media?.size;
276
- return /* @__PURE__ */ jsxs("li", {
277
- className: MediaField_module_default.item,
399
+ ] }) : void 0;
400
+ $[58] = constraints;
401
+ $[59] = description;
402
+ $[60] = intl;
403
+ $[61] = unavailable;
404
+ $[62] = t26;
405
+ } else t26 = $[62];
406
+ let t27;
407
+ if ($[63] !== errors || $[64] !== problems) {
408
+ t27 = [...errors, ...problems];
409
+ $[63] = errors;
410
+ $[64] = problems;
411
+ $[65] = t27;
412
+ } else t27 = $[65];
413
+ let t28;
414
+ if ($[66] !== canPick || $[67] !== canUpload || $[68] !== creating.length || $[69] !== enabled || $[70] !== imageOptions || $[71] !== intl || $[72] !== media || $[73] !== multiple || $[74] !== resource || $[75] !== set || $[76] !== statusBadge || $[77] !== upload.items) {
415
+ t28 = media.length > 0 && imageOptions !== null ? /* @__PURE__ */ jsx("ul", {
416
+ className: multiple ? MediaField_module_default.gallery : MediaField_module_default.media,
417
+ children: media.map((item_2) => /* @__PURE__ */ jsx(ImageItem, {
418
+ reference: item_2,
419
+ tile: multiple,
420
+ cropRequired: imageOptions.cropRequired === true,
421
+ status: statusBadge(item_2),
422
+ onEdit: enabled ? () => setEditing({ key: keyOf(item_2, resource) }) : null,
423
+ onRemove: canUpload || canPick ? () => set(latest.current.filter((entry_2) => keyOf(entry_2, resource) !== keyOf(item_2, resource))) : null
424
+ }, keyOf(item_2, resource)))
425
+ }) : media.length > 0 ? /* @__PURE__ */ jsx("ul", {
426
+ className: MediaField_module_default.media,
427
+ children: media.map((item_3) => {
428
+ const name_0 = item_3.label ?? item_3.id;
429
+ const size = item_3.media?.size;
430
+ return /* @__PURE__ */ jsxs("li", {
431
+ className: MediaField_module_default.item,
432
+ children: [
433
+ /* @__PURE__ */ jsx("span", {
434
+ className: MediaField_module_default.thumbnail,
435
+ children: typeof item_3.media?.thumbnailUrl === "string" ? /* @__PURE__ */ jsx("img", {
436
+ src: item_3.media.thumbnailUrl,
437
+ alt: ""
438
+ }) : /* @__PURE__ */ jsx(FileImage, { "aria-hidden": true })
439
+ }),
440
+ /* @__PURE__ */ jsxs("span", {
441
+ className: MediaField_module_default.details,
442
+ children: [/* @__PURE__ */ jsx("span", {
443
+ className: MediaField_module_default.name,
444
+ children: name_0
445
+ }), /* @__PURE__ */ jsxs("span", {
446
+ className: MediaField_module_default.meta,
278
447
  children: [
279
- /* @__PURE__ */ jsx("span", {
280
- className: MediaField_module_default.thumbnail,
281
- children: typeof item_3.media?.thumbnailUrl === "string" ? /* @__PURE__ */ jsx("img", {
282
- src: item_3.media.thumbnailUrl,
283
- alt: ""
284
- }) : /* @__PURE__ */ jsx(FileImage, { "aria-hidden": true })
285
- }),
286
- /* @__PURE__ */ jsxs("span", {
287
- className: MediaField_module_default.details,
288
- children: [/* @__PURE__ */ jsx("span", {
289
- className: MediaField_module_default.name,
290
- children: name_0
291
- }), /* @__PURE__ */ jsxs("span", {
292
- className: MediaField_module_default.meta,
293
- children: [
294
- item_3.media !== void 0 ? /* @__PURE__ */ jsx("span", { children: item_3.media.type }) : null,
295
- typeof size === "number" ? /* @__PURE__ */ jsx("span", { children: formatSize(size, intl.locale) }) : null,
296
- statusBadge(item_3)
297
- ]
298
- })]
299
- }),
300
- canUpload || canPick ? /* @__PURE__ */ jsx(IconButton, {
301
- icon: X,
302
- size: "sm",
303
- label: intl.formatMessage(fieldsMessages.removeFile, { name: name_0 }),
304
- onPress: () => set(latest.current.filter((entry_3) => keyOf(entry_3, resource) !== keyOf(item_3, resource)))
305
- }) : null
448
+ item_3.media !== void 0 ? /* @__PURE__ */ jsx("span", { children: item_3.media.type }) : null,
449
+ typeof size === "number" ? /* @__PURE__ */ jsx("span", { children: formatSize(size, intl.locale) }) : null,
450
+ statusBadge(item_3)
306
451
  ]
307
- }, keyOf(item_3, resource));
308
- })
309
- }) : creating.length === 0 && upload.items.length === 0 ? /* @__PURE__ */ jsx("span", {
310
- className: MediaField_module_default.none,
311
- children: intl.formatMessage(imageOptions !== null ? mediaMessages.noImage : mediaMessages.noMedia)
312
- }) : null,
313
- /* @__PURE__ */ jsx(UploadList, {
314
- items: upload.items,
315
- onPause: upload.pause,
316
- onResume: upload.resume,
317
- onCancel: upload.cancel,
318
- onRetry: upload.retry
319
- }),
320
- creating.length > 0 ? /* @__PURE__ */ jsxs("span", {
321
- className: MediaField_module_default.meta,
322
- role: "status",
323
- children: [
324
- /* @__PURE__ */ jsx(Spinner, { size: "sm" }),
325
- intl.formatMessage(fieldsMessages.uploadCompleting),
326
- " ",
327
- creating.join(", ")
328
- ]
329
- }) : null,
330
- canPick || canUpload ? /* @__PURE__ */ jsxs("div", {
331
- className: MediaField_module_default.actions,
332
- children: [canPick ? /* @__PURE__ */ jsx(Button, {
452
+ })]
453
+ }),
454
+ canUpload || canPick ? /* @__PURE__ */ jsx(IconButton, {
455
+ icon: X,
333
456
  size: "sm",
334
- appearance: "outline",
335
- icon: Images,
336
- onPress: () => setPicking(true),
337
- children: intl.formatMessage(chooseLabel)
338
- }) : null, canUpload ? /* @__PURE__ */ jsx(FilePicker, {
339
- accept,
340
- multiple,
341
- className: MediaField_module_default.upload,
342
- ...canPick ? { label: intl.formatMessage(imageOptions !== null ? multiple ? mediaMessages.uploadImages : mediaMessages.uploadImage : multiple ? mediaMessages.uploadFiles : mediaMessages.uploadFile) } : {},
343
- onSelect: (selected) => {
344
- setProblems([]);
345
- upload.add(selected);
346
- }
347
- }) : null]
348
- }) : null
349
- ]
350
- }),
351
- canPick ? /* @__PURE__ */ jsx(MediaPicker, {
352
- isOpen: picking,
353
- onOpenChange: setPicking,
354
- sources,
355
- multiple,
457
+ label: intl.formatMessage(fieldsMessages.removeFile, { name: name_0 }),
458
+ onPress: () => set(latest.current.filter((entry_3) => keyOf(entry_3, resource) !== keyOf(item_3, resource)))
459
+ }) : null
460
+ ]
461
+ }, keyOf(item_3, resource));
462
+ })
463
+ }) : creating.length === 0 && upload.items.length === 0 ? /* @__PURE__ */ jsx("span", {
464
+ className: MediaField_module_default.none,
465
+ children: intl.formatMessage(imageOptions !== null ? mediaMessages.noImage : mediaMessages.noMedia)
466
+ }) : null;
467
+ $[66] = canPick;
468
+ $[67] = canUpload;
469
+ $[68] = creating.length;
470
+ $[69] = enabled;
471
+ $[70] = imageOptions;
472
+ $[71] = intl;
473
+ $[72] = media;
474
+ $[73] = multiple;
475
+ $[74] = resource;
476
+ $[75] = set;
477
+ $[76] = statusBadge;
478
+ $[77] = upload.items;
479
+ $[78] = t28;
480
+ } else t28 = $[78];
481
+ let t29;
482
+ if ($[79] !== upload.cancel || $[80] !== upload.items || $[81] !== upload.pause || $[82] !== upload.resume || $[83] !== upload.retry) {
483
+ t29 = /* @__PURE__ */ jsx(UploadList, {
484
+ items: upload.items,
485
+ onPause: upload.pause,
486
+ onResume: upload.resume,
487
+ onCancel: upload.cancel,
488
+ onRetry: upload.retry
489
+ });
490
+ $[79] = upload.cancel;
491
+ $[80] = upload.items;
492
+ $[81] = upload.pause;
493
+ $[82] = upload.resume;
494
+ $[83] = upload.retry;
495
+ $[84] = t29;
496
+ } else t29 = $[84];
497
+ let t30;
498
+ if ($[85] !== creating || $[86] !== intl) {
499
+ t30 = creating.length > 0 ? /* @__PURE__ */ jsxs("span", {
500
+ className: MediaField_module_default.meta,
501
+ role: "status",
502
+ children: [
503
+ /* @__PURE__ */ jsx(Spinner, { size: "sm" }),
504
+ intl.formatMessage(fieldsMessages.uploadCompleting),
505
+ " ",
506
+ creating.join(", ")
507
+ ]
508
+ }) : null;
509
+ $[85] = creating;
510
+ $[86] = intl;
511
+ $[87] = t30;
512
+ } else t30 = $[87];
513
+ let t31;
514
+ if ($[88] !== accept || $[89] !== canPick || $[90] !== canUpload || $[91] !== chooseLabel || $[92] !== imageOptions || $[93] !== intl || $[94] !== multiple || $[95] !== upload) {
515
+ t31 = canPick || canUpload ? /* @__PURE__ */ jsxs("div", {
516
+ className: MediaField_module_default.actions,
517
+ children: [canPick ? /* @__PURE__ */ jsx(Button, {
518
+ size: "sm",
519
+ appearance: "outline",
520
+ icon: Images,
521
+ onPress: () => setPicking(true),
522
+ children: intl.formatMessage(chooseLabel)
523
+ }) : null, canUpload ? /* @__PURE__ */ jsx(FilePicker, {
356
524
  accept,
357
- maxSize,
358
- value: media,
359
- title: intl.formatMessage(chooseLabel),
360
- ...cropStep ? { confirmLabel: intl.formatMessage(mediaMessages.imageNextCrop) } : {},
361
- uploadSource,
362
- refreshInterval,
363
- ...stateKey !== void 0 ? { stateKey } : {},
364
- onSelect: (picked_0) => {
525
+ multiple,
526
+ className: MediaField_module_default.upload,
527
+ ...canPick ? { label: intl.formatMessage(imageOptions !== null ? multiple ? mediaMessages.uploadImages : mediaMessages.uploadImage : multiple ? mediaMessages.uploadFiles : mediaMessages.uploadFile) } : {},
528
+ onSelect: (selected) => {
365
529
  setProblems([]);
366
- const [first] = picked_0;
367
- if (cropStep && picked_0.length === 1 && first !== void 0 && editedImageOf(first) !== null) {
368
- setEditing({ picked: first });
369
- return;
370
- }
371
- add(picked_0);
530
+ upload.add(selected);
372
531
  }
373
- }) : null,
374
- imageOptions !== null && edited !== null && editedImage !== null && editing !== null ? /* @__PURE__ */ jsx(ImageEditorDialog, {
375
- isOpen: true,
376
- onOpenChange: (isOpen) => {
377
- if (!isOpen) setEditing(null);
378
- },
379
- image: editedImage,
380
- value: "key" in editing ? edited.transform ?? null : null,
381
- base: imageOptions.transformBase === "original" ? "original" : "media",
382
- canChooseBase: imageOptions.transformBase === "choose",
383
- tools,
384
- ratios: imageRatios,
385
- enforceRatios: imageOptions.enforceRatios === true,
386
- cropRequired: imageOptions.cropRequired === true,
387
- ..."picked" in editing ? {
388
- title: intl.formatMessage(mediaMessages.imageCropForUse),
389
- applyLabel: intl.formatMessage(mediaMessages.imageUseCrop),
390
- onBack: () => {
391
- setEditing(null);
392
- setPicking(true);
393
- }
394
- } : {},
395
- onApply: (transform_0) => {
396
- const next_0 = withTransform(edited, transform_0);
397
- if ("picked" in editing) add([next_0]);
398
- else set(latest.current.map((entry_4) => keyOf(entry_4, resource) === editing.key ? next_0 : entry_4));
532
+ }) : null]
533
+ }) : null;
534
+ $[88] = accept;
535
+ $[89] = canPick;
536
+ $[90] = canUpload;
537
+ $[91] = chooseLabel;
538
+ $[92] = imageOptions;
539
+ $[93] = intl;
540
+ $[94] = multiple;
541
+ $[95] = upload;
542
+ $[96] = t31;
543
+ } else t31 = $[96];
544
+ let t32;
545
+ if ($[97] !== t28 || $[98] !== t29 || $[99] !== t30 || $[100] !== t31) {
546
+ t32 = /* @__PURE__ */ jsxs("div", {
547
+ className: MediaField_module_default.field,
548
+ children: [
549
+ t28,
550
+ t29,
551
+ t30,
552
+ t31
553
+ ]
554
+ });
555
+ $[97] = t28;
556
+ $[98] = t29;
557
+ $[99] = t30;
558
+ $[100] = t31;
559
+ $[101] = t32;
560
+ } else t32 = $[101];
561
+ let t33;
562
+ if ($[102] !== accept || $[103] !== add || $[104] !== canPick || $[105] !== chooseLabel || $[106] !== cropStep || $[107] !== intl || $[108] !== maxSize || $[109] !== media || $[110] !== multiple || $[111] !== picking || $[112] !== refreshInterval || $[113] !== sources || $[114] !== stateKey || $[115] !== uploadSource) {
563
+ t33 = canPick ? /* @__PURE__ */ jsx(MediaPicker, {
564
+ isOpen: picking,
565
+ onOpenChange: setPicking,
566
+ sources,
567
+ multiple,
568
+ accept,
569
+ maxSize,
570
+ value: media,
571
+ title: intl.formatMessage(chooseLabel),
572
+ ...cropStep ? { confirmLabel: intl.formatMessage(mediaMessages.imageNextCrop) } : {},
573
+ uploadSource,
574
+ refreshInterval,
575
+ ...stateKey !== void 0 ? { stateKey } : {},
576
+ onSelect: (picked_0) => {
577
+ setProblems([]);
578
+ const [first] = picked_0;
579
+ if (cropStep && picked_0.length === 1 && first !== void 0 && editedImageOf(first) !== null) {
580
+ setEditing({ picked: first });
581
+ return;
399
582
  }
400
- }) : null
401
- ]
402
- });
583
+ add(picked_0);
584
+ }
585
+ }) : null;
586
+ $[102] = accept;
587
+ $[103] = add;
588
+ $[104] = canPick;
589
+ $[105] = chooseLabel;
590
+ $[106] = cropStep;
591
+ $[107] = intl;
592
+ $[108] = maxSize;
593
+ $[109] = media;
594
+ $[110] = multiple;
595
+ $[111] = picking;
596
+ $[112] = refreshInterval;
597
+ $[113] = sources;
598
+ $[114] = stateKey;
599
+ $[115] = uploadSource;
600
+ $[116] = t33;
601
+ } else t33 = $[116];
602
+ let t34;
603
+ if ($[117] !== add || $[118] !== edited || $[119] !== editedImage || $[120] !== editing || $[121] !== imageOptions || $[122] !== imageRatios || $[123] !== intl || $[124] !== resource || $[125] !== set || $[126] !== tools) {
604
+ t34 = imageOptions !== null && edited !== null && editedImage !== null && editing !== null ? /* @__PURE__ */ jsx(ImageEditorDialog, {
605
+ isOpen: true,
606
+ onOpenChange: (isOpen) => {
607
+ if (!isOpen) setEditing(null);
608
+ },
609
+ image: editedImage,
610
+ value: "key" in editing ? edited.transform ?? null : null,
611
+ base: imageOptions.transformBase === "original" ? "original" : "media",
612
+ canChooseBase: imageOptions.transformBase === "choose",
613
+ tools,
614
+ ratios: imageRatios,
615
+ enforceRatios: imageOptions.enforceRatios === true,
616
+ cropRequired: imageOptions.cropRequired === true,
617
+ ..."picked" in editing ? {
618
+ title: intl.formatMessage(mediaMessages.imageCropForUse),
619
+ applyLabel: intl.formatMessage(mediaMessages.imageUseCrop),
620
+ onBack: () => {
621
+ setEditing(null);
622
+ setPicking(true);
623
+ }
624
+ } : {},
625
+ onApply: (transform_0) => {
626
+ const next_0 = withTransform(edited, transform_0);
627
+ if ("picked" in editing) add([next_0]);
628
+ else set(latest.current.map((entry_4) => keyOf(entry_4, resource) === editing.key ? next_0 : entry_4));
629
+ }
630
+ }) : null;
631
+ $[117] = add;
632
+ $[118] = edited;
633
+ $[119] = editedImage;
634
+ $[120] = editing;
635
+ $[121] = imageOptions;
636
+ $[122] = imageRatios;
637
+ $[123] = intl;
638
+ $[124] = resource;
639
+ $[125] = set;
640
+ $[126] = tools;
641
+ $[127] = t34;
642
+ } else t34 = $[127];
643
+ let t35;
644
+ if ($[128] !== className || $[129] !== descriptionClassName || $[130] !== disabled || $[131] !== errorsClassName || $[132] !== label || $[133] !== labelClassName || $[134] !== required || $[135] !== t26 || $[136] !== t27 || $[137] !== t32 || $[138] !== t33 || $[139] !== t34) {
645
+ t35 = /* @__PURE__ */ jsxs(Fieldset, {
646
+ legend: label,
647
+ description: t26,
648
+ errors: t27,
649
+ isRequired: required,
650
+ isDisabled: disabled,
651
+ className,
652
+ legendClassName: labelClassName,
653
+ descriptionClassName,
654
+ errorsClassName,
655
+ children: [
656
+ t32,
657
+ t33,
658
+ t34
659
+ ]
660
+ });
661
+ $[128] = className;
662
+ $[129] = descriptionClassName;
663
+ $[130] = disabled;
664
+ $[131] = errorsClassName;
665
+ $[132] = label;
666
+ $[133] = labelClassName;
667
+ $[134] = required;
668
+ $[135] = t26;
669
+ $[136] = t27;
670
+ $[137] = t32;
671
+ $[138] = t33;
672
+ $[139] = t34;
673
+ $[140] = t35;
674
+ } else t35 = $[140];
675
+ return t35;
676
+ }
677
+ /** The props of `ImageField`: those of `MediaField`, with the options of an `image` field. */
678
+ function _temp4(constraint) {
679
+ return /* @__PURE__ */ jsx(Badge, { children: constraint }, constraint);
680
+ }
681
+ function _temp3(reference_0, transform) {
682
+ const { transform: _previous, ...rest } = reference_0;
683
+ return transform === null || transform === void 0 ? rest : {
684
+ ...rest,
685
+ transform
686
+ };
403
687
  }
404
688
  /**
405
689
  * An `image` field (decision 0031): a `media` field for images, with the image editor. It accepts
@@ -408,20 +692,112 @@ function MediaField(props) {
408
692
  * pick of one image.
409
693
  */
410
694
  function ImageField(props) {
411
- const { ratios, enforceRatios, cropRequired, rotate, focalPoint, transformBase, accept = ["image/*"], ...rest } = props;
412
- const image = {
413
- ...ratios !== void 0 ? { ratios } : {},
414
- ...enforceRatios !== void 0 ? { enforceRatios } : {},
415
- ...cropRequired !== void 0 ? { cropRequired } : {},
416
- ...rotate !== void 0 ? { rotate } : {},
417
- ...focalPoint !== void 0 ? { focalPoint } : {},
418
- ...transformBase !== void 0 ? { transformBase } : {}
419
- };
420
- return /* @__PURE__ */ jsx(MediaField, {
421
- ...rest,
422
- accept,
423
- image
424
- });
695
+ const $ = c(34);
696
+ let cropRequired;
697
+ let enforceRatios;
698
+ let focalPoint;
699
+ let ratios;
700
+ let rest;
701
+ let rotate;
702
+ let t0;
703
+ let transformBase;
704
+ if ($[0] !== props) {
705
+ ({ratios, enforceRatios, cropRequired, rotate, focalPoint, transformBase, accept: t0, ...rest} = props);
706
+ $[0] = props;
707
+ $[1] = cropRequired;
708
+ $[2] = enforceRatios;
709
+ $[3] = focalPoint;
710
+ $[4] = ratios;
711
+ $[5] = rest;
712
+ $[6] = rotate;
713
+ $[7] = t0;
714
+ $[8] = transformBase;
715
+ } else {
716
+ cropRequired = $[1];
717
+ enforceRatios = $[2];
718
+ focalPoint = $[3];
719
+ ratios = $[4];
720
+ rest = $[5];
721
+ rotate = $[6];
722
+ t0 = $[7];
723
+ transformBase = $[8];
724
+ }
725
+ let t1;
726
+ if ($[9] !== t0) {
727
+ t1 = t0 === void 0 ? ["image/*"] : t0;
728
+ $[9] = t0;
729
+ $[10] = t1;
730
+ } else t1 = $[10];
731
+ const accept = t1;
732
+ let t2;
733
+ if ($[11] !== ratios) {
734
+ t2 = ratios !== void 0 ? { ratios } : {};
735
+ $[11] = ratios;
736
+ $[12] = t2;
737
+ } else t2 = $[12];
738
+ let t3;
739
+ if ($[13] !== enforceRatios) {
740
+ t3 = enforceRatios !== void 0 ? { enforceRatios } : {};
741
+ $[13] = enforceRatios;
742
+ $[14] = t3;
743
+ } else t3 = $[14];
744
+ let t4;
745
+ if ($[15] !== cropRequired) {
746
+ t4 = cropRequired !== void 0 ? { cropRequired } : {};
747
+ $[15] = cropRequired;
748
+ $[16] = t4;
749
+ } else t4 = $[16];
750
+ let t5;
751
+ if ($[17] !== rotate) {
752
+ t5 = rotate !== void 0 ? { rotate } : {};
753
+ $[17] = rotate;
754
+ $[18] = t5;
755
+ } else t5 = $[18];
756
+ let t6;
757
+ if ($[19] !== focalPoint) {
758
+ t6 = focalPoint !== void 0 ? { focalPoint } : {};
759
+ $[19] = focalPoint;
760
+ $[20] = t6;
761
+ } else t6 = $[20];
762
+ let t7;
763
+ if ($[21] !== transformBase) {
764
+ t7 = transformBase !== void 0 ? { transformBase } : {};
765
+ $[21] = transformBase;
766
+ $[22] = t7;
767
+ } else t7 = $[22];
768
+ let t8;
769
+ if ($[23] !== t2 || $[24] !== t3 || $[25] !== t4 || $[26] !== t5 || $[27] !== t6 || $[28] !== t7) {
770
+ t8 = {
771
+ ...t2,
772
+ ...t3,
773
+ ...t4,
774
+ ...t5,
775
+ ...t6,
776
+ ...t7
777
+ };
778
+ $[23] = t2;
779
+ $[24] = t3;
780
+ $[25] = t4;
781
+ $[26] = t5;
782
+ $[27] = t6;
783
+ $[28] = t7;
784
+ $[29] = t8;
785
+ } else t8 = $[29];
786
+ const image = t8;
787
+ const t9 = rest;
788
+ let t10;
789
+ if ($[30] !== accept || $[31] !== image || $[32] !== t9) {
790
+ t10 = /* @__PURE__ */ jsx(MediaField, {
791
+ ...t9,
792
+ accept,
793
+ image
794
+ });
795
+ $[30] = accept;
796
+ $[31] = image;
797
+ $[32] = t9;
798
+ $[33] = t10;
799
+ } else t10 = $[33];
800
+ return t10;
425
801
  }
426
802
  /**
427
803
  * The options of an `image` field of a definition: its `crop` rule (enforced ratios, a required
@@ -475,7 +851,7 @@ function MediaFieldEntry(props) {
475
851
  maxSize: getMaxSize(field),
476
852
  sources,
477
853
  image,
478
- stateKey: `panneau.media.${libraries.map(_temp3).join(",")}`,
854
+ stateKey: `panneau.media.${libraries.map(_temp5).join(",")}`,
479
855
  ...library === null ? { adapter: null } : {}
480
856
  };
481
857
  t0 = toMediaReferences(value, itemTitle);
@@ -511,7 +887,7 @@ function MediaFieldEntry(props) {
511
887
  } else t1 = $[13];
512
888
  return t1;
513
889
  }
514
- function _temp3(candidate_1) {
890
+ function _temp5(candidate_1) {
515
891
  return candidate_1.id;
516
892
  }
517
893
  //#endregion