@micromag/media-gallery 0.4.88 → 0.4.90-alpha.1

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 (3) hide show
  1. package/es/index.d.ts +15 -4
  2. package/es/index.js +916 -305
  3. package/package.json +5 -5
package/es/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { Media } from '@micromag/core';
3
+ import { ForwardedRef } from 'react';
4
+ import { DialogModalProps } from '@panneau/modal-dialog';
3
5
 
4
6
  interface MediaGalleryProps {
5
7
  value?: Media | Media[] | null;
6
- types?: string | unknown[] | null;
8
+ types?: string | string[] | null;
7
9
  source?: string;
8
10
  filters?: {
9
11
  id?: string;
@@ -17,11 +19,20 @@ interface MediaGalleryProps {
17
19
  isPicker?: boolean;
18
20
  multiple?: boolean;
19
21
  medias?: Media[] | null;
20
- onChange?: ((...args: unknown[]) => void) | null;
22
+ query?: Record<string, unknown> | null;
23
+ onChange?: ((media: Media | Media[] | null) => void) | null;
21
24
  onMediaFormOpen?: ((...args: unknown[]) => void) | null;
22
25
  onMediaFormClose?: ((...args: unknown[]) => void) | null;
23
26
  className?: string | null;
24
27
  }
25
- declare function MediaGallery({ value, types, source, filters, fields: providedFields, columns, isPicker, multiple, medias: initialMedias, onChange, onMediaFormOpen, onMediaFormClose, className, }: MediaGalleryProps): react_jsx_runtime.JSX.Element;
28
+ declare function MediaGallery({ value, types, source, filters: providedFilters, fields: providedFields, columns, isPicker, multiple, medias: initialMedias, query, onChange, onMediaFormOpen, onMediaFormClose, className, }: MediaGalleryProps): react_jsx_runtime.JSX.Element;
26
29
 
27
- export { MediaGallery as default };
30
+ interface MediaGalleryModalProps extends Omit<DialogModalProps, 'id'>, MediaGalleryProps {
31
+ id?: string | null;
32
+ autoClose?: boolean;
33
+ withoutCloseOnComplete?: boolean;
34
+ formRef?: ForwardedRef<HTMLFormElement> | null;
35
+ }
36
+ declare function MediaGalleryModal({ id, title, size, visible, autoClose, multiple, requestClose: customRequestClose, onClosed, className, value: initialValue, onChange, ...props }: MediaGalleryModalProps): react_jsx_runtime.JSX.Element;
37
+
38
+ export { MediaGallery, MediaGalleryModal, MediaGallery as default };
package/es/index.js CHANGED
@@ -1,13 +1,16 @@
1
+ import _isArray from 'lodash/isArray';
2
+ import { c } from 'react/compiler-runtime';
1
3
  import classNames from 'classnames';
2
- import isArray from 'lodash/isArray';
3
4
  import isObject from 'lodash/isObject';
4
- import { useMemo, useCallback } from 'react';
5
+ import isString from 'lodash/isString';
5
6
  import { MediasPickerContainer, MediasBrowserContainer } from '@panneau/medias';
6
7
  import { useStory } from '@micromag/core/contexts';
7
8
  import { useApi, useMediaCreate } from '@micromag/data';
8
9
  import { FormattedMessage } from 'react-intl';
9
10
  import { jsx } from 'react/jsx-runtime';
10
11
  import { useUrlGenerator } from '@folklore/routes';
12
+ import { useState } from 'react';
13
+ import Dialog from '@panneau/modal-dialog';
11
14
 
12
15
  var defaultColumns = [{
13
16
  id: 'image',
@@ -108,352 +111,697 @@ var defaultColumns = [{
108
111
  // },
109
112
  ];
110
113
 
111
- function fields() {
114
+ function useDefaultFilters() {
115
+ const $ = c(16);
112
116
  const route = useUrlGenerator();
113
- return [{
114
- name: 'name',
115
- label: /*#__PURE__*/jsx(FormattedMessage, {
116
- id: "WX83V9",
117
- defaultMessage: "File name"
118
- }),
119
- type: 'text',
120
- component: 'text'
121
- }, {
122
- id: 'metadata',
123
- component: 'fields',
124
- name: 'metadata',
125
- fields: [{
126
- name: 'description',
117
+ let t0;
118
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
119
+ t0 = {
120
+ id: "search",
121
+ component: "search",
122
+ name: "search",
123
+ width: 152
124
+ };
125
+ $[0] = t0;
126
+ } else {
127
+ t0 = $[0];
128
+ }
129
+ let t1;
130
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
131
+ t1 = {
132
+ id: "types",
133
+ component: "select",
134
+ name: "types",
135
+ placeholder: /*#__PURE__*/jsx(FormattedMessage, {
136
+ id: "9/t5wK",
137
+ defaultMessage: "Type"
138
+ }),
139
+ options: [{
140
+ label: /*#__PURE__*/jsx(FormattedMessage, {
141
+ id: "yHAmDD",
142
+ defaultMessage: "Image"
143
+ }),
144
+ value: "image"
145
+ }, {
146
+ label: /*#__PURE__*/jsx(FormattedMessage, {
147
+ id: "xSERPA",
148
+ defaultMessage: "Video"
149
+ }),
150
+ value: "video"
151
+ }, {
152
+ label: /*#__PURE__*/jsx(FormattedMessage, {
153
+ id: "yQRtgx",
154
+ defaultMessage: "Audio"
155
+ }),
156
+ value: "audio"
157
+ }, {
158
+ label: /*#__PURE__*/jsx(FormattedMessage, {
159
+ id: "fpQzza",
160
+ defaultMessage: "Font"
161
+ }),
162
+ value: "font"
163
+ }],
164
+ multiple: true
165
+ };
166
+ $[1] = t1;
167
+ } else {
168
+ t1 = $[1];
169
+ }
170
+ let t2;
171
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
172
+ t2 = /*#__PURE__*/jsx(FormattedMessage, {
173
+ id: "7oXkoj",
174
+ defaultMessage: "Authors"
175
+ });
176
+ $[2] = t2;
177
+ } else {
178
+ t2 = $[2];
179
+ }
180
+ let t3;
181
+ if ($[3] !== route) {
182
+ t3 = route("medias.authors") || "/medias/authors";
183
+ $[3] = route;
184
+ $[4] = t3;
185
+ } else {
186
+ t3 = $[4];
187
+ }
188
+ let t4;
189
+ if ($[5] !== t3) {
190
+ t4 = {
191
+ id: "authors",
192
+ component: "select",
193
+ name: "authors",
194
+ placeholder: t2,
195
+ requestUrl: t3,
196
+ itemLabelPath: "name",
197
+ itemValuePath: "id",
198
+ multiple: true,
199
+ paginated: false
200
+ };
201
+ $[5] = t3;
202
+ $[6] = t4;
203
+ } else {
204
+ t4 = $[6];
205
+ }
206
+ let t5;
207
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
208
+ t5 = /*#__PURE__*/jsx(FormattedMessage, {
209
+ id: "9mXl24",
210
+ defaultMessage: "Tags"
211
+ });
212
+ $[7] = t5;
213
+ } else {
214
+ t5 = $[7];
215
+ }
216
+ let t6;
217
+ if ($[8] !== route) {
218
+ t6 = route("medias.tags") || "/medias/tags";
219
+ $[8] = route;
220
+ $[9] = t6;
221
+ } else {
222
+ t6 = $[9];
223
+ }
224
+ let t7;
225
+ if ($[10] !== t6) {
226
+ t7 = {
227
+ id: "tags",
228
+ component: "select",
229
+ name: "tags",
230
+ placeholder: t5,
231
+ requestUrl: t6,
232
+ itemLabelPath: "name",
233
+ itemValuePath: "name",
234
+ multiple: true,
235
+ paginated: false
236
+ };
237
+ $[10] = t6;
238
+ $[11] = t7;
239
+ } else {
240
+ t7 = $[11];
241
+ }
242
+ let t8;
243
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
244
+ t8 = {
245
+ id: "source",
246
+ component: "radios",
247
+ name: "source",
248
+ options: [{
249
+ label: /*#__PURE__*/jsx(FormattedMessage, {
250
+ id: "bCtuS/",
251
+ defaultMessage: "In this Micromag"
252
+ }),
253
+ value: "document-"
254
+ }]
255
+ };
256
+ $[12] = t8;
257
+ } else {
258
+ t8 = $[12];
259
+ }
260
+ let t9;
261
+ if ($[13] !== t4 || $[14] !== t7) {
262
+ t9 = [t0, t1, t4, t7, t8];
263
+ $[13] = t4;
264
+ $[14] = t7;
265
+ $[15] = t9;
266
+ } else {
267
+ t9 = $[15];
268
+ }
269
+ return t9;
270
+ }
271
+ function useDefaultFields() {
272
+ const $ = c(20);
273
+ const route = useUrlGenerator();
274
+ let t0;
275
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
276
+ t0 = {
277
+ name: "name",
127
278
  label: /*#__PURE__*/jsx(FormattedMessage, {
128
- id: "ygNvmz",
129
- defaultMessage: "Description"
279
+ id: "WX83V9",
280
+ defaultMessage: "File name"
130
281
  }),
131
- type: 'text',
132
- component: 'text'
133
- }, {
134
- name: 'tags',
282
+ type: "text",
283
+ component: "text"
284
+ };
285
+ $[0] = t0;
286
+ } else {
287
+ t0 = $[0];
288
+ }
289
+ let t1;
290
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
291
+ t1 = {
292
+ name: "description",
135
293
  label: /*#__PURE__*/jsx(FormattedMessage, {
136
- id: "IOVper",
137
- defaultMessage: "Tags"
294
+ id: "ygNvmz",
295
+ defaultMessage: "Description"
138
296
  }),
139
- createPrefix: 'Create',
140
- type: 'array',
141
- component: 'item',
142
- requestUrl: route('medias.tags') || '/medias/tags',
143
- itemLabelPath: 'name',
144
- itemDescriptionPath: null,
145
- itemValuePath: 'id',
146
- // Uses taggable so change the logic here
147
- valueIsOption: true,
148
- multiple: true,
149
- paginated: false,
150
- creatable: true
151
- }]
152
- }, {
153
- id: 'info',
154
- component: 'fields',
155
- label: /*#__PURE__*/jsx(FormattedMessage, {
297
+ type: "text",
298
+ component: "text"
299
+ };
300
+ $[1] = t1;
301
+ } else {
302
+ t1 = $[1];
303
+ }
304
+ let t2;
305
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
306
+ t2 = /*#__PURE__*/jsx(FormattedMessage, {
307
+ id: "IOVper",
308
+ defaultMessage: "Tags"
309
+ });
310
+ $[2] = t2;
311
+ } else {
312
+ t2 = $[2];
313
+ }
314
+ let t3;
315
+ if ($[3] !== route) {
316
+ t3 = route("medias.tags") || "/medias/tags";
317
+ $[3] = route;
318
+ $[4] = t3;
319
+ } else {
320
+ t3 = $[4];
321
+ }
322
+ let t4;
323
+ if ($[5] !== t3) {
324
+ t4 = {
325
+ id: "metadata",
326
+ component: "fields",
327
+ name: "metadata",
328
+ fields: [t1, {
329
+ name: "tags",
330
+ label: t2,
331
+ createPrefix: "Create",
332
+ type: "array",
333
+ component: "item",
334
+ requestUrl: t3,
335
+ itemLabelPath: "name",
336
+ itemDescriptionPath: null,
337
+ itemValuePath: "id",
338
+ valueIsOption: true,
339
+ multiple: true,
340
+ paginated: false,
341
+ creatable: true
342
+ }]
343
+ };
344
+ $[5] = t3;
345
+ $[6] = t4;
346
+ } else {
347
+ t4 = $[6];
348
+ }
349
+ let t5;
350
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
351
+ t5 = /*#__PURE__*/jsx(FormattedMessage, {
156
352
  id: "3RT69u",
157
353
  defaultMessage: "Informations"
158
- }),
159
- isList: true,
160
- hideWithoutValue: true,
161
- fields: [{
162
- id: 'user',
354
+ });
355
+ $[7] = t5;
356
+ } else {
357
+ t5 = $[7];
358
+ }
359
+ let t6;
360
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
361
+ t6 = {
362
+ id: "user",
163
363
  label: /*#__PURE__*/jsx(FormattedMessage, {
164
364
  id: "yByaBh",
165
365
  defaultMessage: "Added by"
166
366
  }),
167
- type: 'display',
168
- display: 'avatar',
169
- name: 'user',
170
- horizontal: true
171
- }, {
172
- id: 'created_at',
173
- label: /*#__PURE__*/jsx(FormattedMessage, {
174
- id: "PN+75e",
175
- defaultMessage: "Created at"
176
- }),
177
- type: 'display',
178
- display: 'date',
179
- name: 'created_at',
180
- format: 'yyyy-MM-dd hh:ss',
367
+ type: "display",
368
+ display: "avatar",
369
+ name: "user",
181
370
  horizontal: true
182
- }]
183
- }, {
184
- id: 'technical',
185
- component: 'fields',
186
- label: /*#__PURE__*/jsx(FormattedMessage, {
371
+ };
372
+ $[8] = t6;
373
+ } else {
374
+ t6 = $[8];
375
+ }
376
+ let t7;
377
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
378
+ t7 = {
379
+ id: "info",
380
+ component: "fields",
381
+ label: t5,
382
+ isList: true,
383
+ hideWithoutValue: true,
384
+ fields: [t6, {
385
+ id: "created_at",
386
+ label: /*#__PURE__*/jsx(FormattedMessage, {
387
+ id: "PN+75e",
388
+ defaultMessage: "Created at"
389
+ }),
390
+ type: "display",
391
+ display: "date",
392
+ name: "created_at",
393
+ format: "yyyy-MM-dd hh:ss",
394
+ horizontal: true
395
+ }]
396
+ };
397
+ $[9] = t7;
398
+ } else {
399
+ t7 = $[9];
400
+ }
401
+ let t8;
402
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
403
+ t8 = /*#__PURE__*/jsx(FormattedMessage, {
187
404
  id: "xKUOLG",
188
405
  defaultMessage: "Technical details"
189
- }),
190
- isList: true,
191
- hideWithoutValue: true,
192
- fields: [{
193
- id: 'format',
406
+ });
407
+ $[10] = t8;
408
+ } else {
409
+ t8 = $[10];
410
+ }
411
+ let t9;
412
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
413
+ t9 = {
414
+ id: "format",
194
415
  label: /*#__PURE__*/jsx(FormattedMessage, {
195
416
  id: "JuxiUN",
196
417
  defaultMessage: "Format"
197
418
  }),
198
- type: 'display',
199
- display: 'unit',
200
- format: 'format',
201
- name: 'format',
419
+ type: "display",
420
+ display: "unit",
421
+ format: "format",
422
+ name: "format",
202
423
  horizontal: true
203
- }, {
204
- id: 'dimensions',
424
+ };
425
+ $[11] = t9;
426
+ } else {
427
+ t9 = $[11];
428
+ }
429
+ let t10;
430
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
431
+ t10 = {
432
+ id: "dimensions",
205
433
  label: /*#__PURE__*/jsx(FormattedMessage, {
206
434
  id: "rmJBin",
207
435
  defaultMessage: "Dimensions"
208
436
  }),
209
- type: 'display',
210
- display: 'unit',
211
- format: 'dimensions',
212
- name: 'metadata',
437
+ type: "display",
438
+ display: "unit",
439
+ format: "dimensions",
440
+ name: "metadata",
213
441
  horizontal: true
214
- }, {
215
- id: 'size',
442
+ };
443
+ $[12] = t10;
444
+ } else {
445
+ t10 = $[12];
446
+ }
447
+ let t11;
448
+ if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
449
+ t11 = {
450
+ id: "size",
216
451
  label: /*#__PURE__*/jsx(FormattedMessage, {
217
452
  id: "g2CRt5",
218
453
  defaultMessage: "Size"
219
454
  }),
220
- type: 'display',
221
- display: 'unit',
222
- format: 'bytes',
223
- name: 'metadata.size',
455
+ type: "display",
456
+ display: "unit",
457
+ format: "bytes",
458
+ name: "metadata.size",
224
459
  horizontal: true
225
- }, {
226
- id: 'duration',
227
- label: /*#__PURE__*/jsx(FormattedMessage, {
228
- id: "wU++NJ",
229
- defaultMessage: "Duration"
230
- }),
231
- type: 'display',
232
- display: 'unit',
233
- format: 'duration',
234
- name: 'metadata.duration',
235
- horizontal: true
236
- }]
237
- }, {
238
- id: 'conversion',
239
- component: 'fields',
240
- label: /*#__PURE__*/jsx(FormattedMessage, {
460
+ };
461
+ $[13] = t11;
462
+ } else {
463
+ t11 = $[13];
464
+ }
465
+ let t12;
466
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
467
+ t12 = {
468
+ id: "technical",
469
+ component: "fields",
470
+ label: t8,
471
+ isList: true,
472
+ hideWithoutValue: true,
473
+ fields: [t9, t10, t11, {
474
+ id: "duration",
475
+ label: /*#__PURE__*/jsx(FormattedMessage, {
476
+ id: "wU++NJ",
477
+ defaultMessage: "Duration"
478
+ }),
479
+ type: "display",
480
+ display: "unit",
481
+ format: "duration",
482
+ name: "metadata.duration",
483
+ horizontal: true
484
+ }]
485
+ };
486
+ $[14] = t12;
487
+ } else {
488
+ t12 = $[14];
489
+ }
490
+ let t13;
491
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
492
+ t13 = /*#__PURE__*/jsx(FormattedMessage, {
241
493
  id: "pBNrdH",
242
494
  defaultMessage: "Conversion"
243
- }),
244
- isList: true,
245
- hideWithoutValue: true,
246
- fields: [{
247
- id: 'h264',
495
+ });
496
+ $[15] = t13;
497
+ } else {
498
+ t13 = $[15];
499
+ }
500
+ let t14;
501
+ if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
502
+ t14 = {
503
+ id: "h264",
248
504
  label: /*#__PURE__*/jsx(FormattedMessage, {
249
505
  id: "4RV6+9",
250
506
  defaultMessage: "H264"
251
507
  }),
252
- type: 'text',
253
- component: 'text',
254
- name: 'files.h264.url',
255
- horizontal: true
256
- }, {
257
- id: 'webm',
258
- label: /*#__PURE__*/jsx(FormattedMessage, {
259
- id: "3I2Xl7",
260
- defaultMessage: "WebM"
261
- }),
262
- type: 'text',
263
- component: 'text',
264
- name: 'files.webm.url',
508
+ type: "text",
509
+ component: "text",
510
+ name: "files.h264.url",
265
511
  horizontal: true
266
- }]
267
- }];
268
- }
269
-
270
- function filters() {
271
- const route = useUrlGenerator();
272
- return [{
273
- id: 'search',
274
- component: 'search',
275
- name: 'search',
276
- width: 152
277
- }, {
278
- id: 'types',
279
- component: 'select',
280
- name: 'types',
281
- placeholder: /*#__PURE__*/jsx(FormattedMessage, {
282
- id: "9/t5wK",
283
- defaultMessage: "Type"
284
- }),
285
- options: [{
286
- label: /*#__PURE__*/jsx(FormattedMessage, {
287
- id: "yHAmDD",
288
- defaultMessage: "Image"
289
- }),
290
- value: 'image'
291
- }, {
292
- label: /*#__PURE__*/jsx(FormattedMessage, {
293
- id: "xSERPA",
294
- defaultMessage: "Video"
295
- }),
296
- value: 'video'
297
- }, {
298
- label: /*#__PURE__*/jsx(FormattedMessage, {
299
- id: "yQRtgx",
300
- defaultMessage: "Audio"
301
- }),
302
- value: 'audio'
303
- }, {
304
- label: /*#__PURE__*/jsx(FormattedMessage, {
305
- id: "fpQzza",
306
- defaultMessage: "Font"
307
- }),
308
- value: 'font'
309
- }],
310
- multiple: true
311
- }, {
312
- id: 'authors',
313
- component: 'select',
314
- name: 'authors',
315
- placeholder: /*#__PURE__*/jsx(FormattedMessage, {
316
- id: "7oXkoj",
317
- defaultMessage: "Authors"
318
- }),
319
- requestUrl: route('medias.authors') || '/medias/authors',
320
- itemLabelPath: 'name',
321
- itemValuePath: 'id',
322
- multiple: true,
323
- paginated: false
324
- }, {
325
- id: 'tags',
326
- component: 'select',
327
- name: 'tags',
328
- placeholder: /*#__PURE__*/jsx(FormattedMessage, {
329
- id: "9mXl24",
330
- defaultMessage: "Tags"
331
- }),
332
- requestUrl: route('medias.tags') || '/medias/tags',
333
- itemLabelPath: 'name',
334
- itemValuePath: 'name',
335
- multiple: true,
336
- paginated: false
337
- }, {
338
- id: 'source',
339
- component: 'radios',
340
- name: 'source',
341
- options: [{
342
- label: /*#__PURE__*/jsx(FormattedMessage, {
343
- id: "bCtuS/",
344
- defaultMessage: "In this Micromag"
345
- }),
346
- value: 'document-'
347
- }]
348
- }];
512
+ };
513
+ $[16] = t14;
514
+ } else {
515
+ t14 = $[16];
516
+ }
517
+ let t15;
518
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
519
+ t15 = {
520
+ id: "conversion",
521
+ component: "fields",
522
+ label: t13,
523
+ isList: true,
524
+ hideWithoutValue: true,
525
+ fields: [t14, {
526
+ id: "webm",
527
+ label: /*#__PURE__*/jsx(FormattedMessage, {
528
+ id: "3I2Xl7",
529
+ defaultMessage: "WebM"
530
+ }),
531
+ type: "text",
532
+ component: "text",
533
+ name: "files.webm.url",
534
+ horizontal: true
535
+ }]
536
+ };
537
+ $[17] = t15;
538
+ } else {
539
+ t15 = $[17];
540
+ }
541
+ let t16;
542
+ if ($[18] !== t4) {
543
+ t16 = [t0, t4, t7, t12, t15];
544
+ $[18] = t4;
545
+ $[19] = t16;
546
+ } else {
547
+ t16 = $[19];
548
+ }
549
+ return t16;
349
550
  }
350
551
 
351
552
  var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
352
553
 
353
- function MediaGallery({
354
- value = null,
355
- types = null,
356
- source = 'all',
357
- filters: filters$1 = null,
358
- fields: providedFields = null,
359
- columns = defaultColumns,
360
- isPicker = false,
361
- multiple = false,
362
- medias: initialMedias = null,
363
- onChange = null,
364
- onMediaFormOpen = null,
365
- onMediaFormClose = null,
366
- className = null
367
- }) {
554
+ function MediaGallery(t0) {
555
+ const $ = c(49);
556
+ const {
557
+ value: t1,
558
+ types: t2,
559
+ source: t3,
560
+ filters: t4,
561
+ fields: t5,
562
+ columns: t6,
563
+ isPicker: t7,
564
+ multiple: t8,
565
+ medias: t9,
566
+ query: t10,
567
+ onChange: t11,
568
+ onMediaFormOpen: t12,
569
+ onMediaFormClose: t13,
570
+ className: t14
571
+ } = t0;
572
+ const value = t1 === undefined ? null : t1;
573
+ const types = t2 === undefined ? null : t2;
574
+ const source = t3 === undefined ? null : t3;
575
+ const providedFilters = t4 === undefined ? null : t4;
576
+ const providedFields = t5 === undefined ? null : t5;
577
+ const columns = t6 === undefined ? defaultColumns : t6;
578
+ const isPicker = t7 === undefined ? false : t7;
579
+ const multiple = t8 === undefined ? false : t8;
580
+ const initialMedias = t9 === undefined ? null : t9;
581
+ const query = t10 === undefined ? null : t10;
582
+ const onChange = t11 === undefined ? null : t11;
583
+ const onMediaFormOpen = t12 === undefined ? null : t12;
584
+ const onMediaFormClose = t13 === undefined ? null : t13;
585
+ const className = t14 === undefined ? null : t14;
368
586
  const api = useApi();
369
587
  const story = useStory();
588
+ let t15;
589
+ if ($[0] !== story) {
590
+ t15 = story || {};
591
+ $[0] = story;
592
+ $[1] = t15;
593
+ } else {
594
+ t15 = $[1];
595
+ }
370
596
  const {
371
- id: storyId = null
372
- } = story || {};
373
- const fields$1 = providedFields === null ? fields() : providedFields;
374
- const mediasApi = useMemo(() => ({
375
- get: (...args) => api.medias.get(...args),
376
- getTrashed: (...args_0) => api.medias.getTrashed(...args_0),
377
- find: (...args_1) => api.medias.find(...args_1),
378
- create: (...args_2) => api.medias.create(...args_2),
379
- update: (...args_3) => api.medias.update(...args_3),
380
- replace: (...args_4) => api.medias.replace(...args_4),
381
- delete: (...args_5) => typeof api.medias.forceDelete !== 'undefined' ? api.medias.forceDelete(...args_5) : api.medias.delete(...args_5),
382
- // TODO: Temporary compat... see how this works
383
- trash: (...args_6) => api.medias.delete(...args_6),
384
- restore: (...args_7) => api.medias.restore(...args_7)
385
- }), [api]);
386
-
387
- // Upload
597
+ id: t16
598
+ } = t15;
599
+ const storyId = t16 === undefined ? null : t16;
600
+ let finalTypes;
601
+ let t17;
602
+ if ($[2] !== types) {
603
+ finalTypes = isString(types) ? [types] : types;
604
+ t17 = [...(finalTypes || []).map(_temp), (finalTypes || []).indexOf("video") !== -1 ? "image/gif" : null].filter(_temp2);
605
+ $[2] = types;
606
+ $[3] = finalTypes;
607
+ $[4] = t17;
608
+ } else {
609
+ finalTypes = $[3];
610
+ t17 = $[4];
611
+ }
612
+ const fileTypes = t17;
613
+ const defaultFields = useDefaultFields();
614
+ const defaultFilters = useDefaultFilters();
615
+ const fields = providedFields ?? defaultFields;
616
+ const t18 = providedFilters ?? defaultFilters;
617
+ let t19;
618
+ if ($[5] !== finalTypes || $[6] !== storyId || $[7] !== t18) {
619
+ let t20;
620
+ if ($[9] !== finalTypes || $[10] !== storyId) {
621
+ t20 = filter => {
622
+ const {
623
+ id: t21,
624
+ options: t22
625
+ } = filter || {};
626
+ const id = t21 === undefined ? null : t21;
627
+ const options = t22 === undefined ? [] : t22;
628
+ if (id === "types" && finalTypes !== null) {
629
+ return false;
630
+ }
631
+ if (id === "source") {
632
+ if (storyId === null) {
633
+ return null;
634
+ }
635
+ return {
636
+ ...filter,
637
+ options: (options || []).map(t23 => {
638
+ const {
639
+ value: t24,
640
+ label: t25
641
+ } = t23 === undefined ? {} : t23;
642
+ const optionValue = t24 === undefined ? null : t24;
643
+ const label = t25 === undefined ? null : t25;
644
+ return optionValue === "document-" ? {
645
+ value: `document-${storyId}`,
646
+ label
647
+ } : {
648
+ value: optionValue,
649
+ label
650
+ };
651
+ })
652
+ };
653
+ }
654
+ return filter;
655
+ };
656
+ $[9] = finalTypes;
657
+ $[10] = storyId;
658
+ $[11] = t20;
659
+ } else {
660
+ t20 = $[11];
661
+ }
662
+ t19 = t18.map(t20).filter(_temp3);
663
+ $[5] = finalTypes;
664
+ $[6] = storyId;
665
+ $[7] = t18;
666
+ $[8] = t19;
667
+ } else {
668
+ t19 = $[8];
669
+ }
670
+ const filters = t19;
671
+ let t20;
672
+ if ($[12] !== api) {
673
+ t20 = {
674
+ get: (...t21) => {
675
+ const args = t21;
676
+ return api.medias.get(...args);
677
+ },
678
+ getTrashed: (...t22) => {
679
+ const args_0 = t22;
680
+ return api.medias.getTrashed(...args_0);
681
+ },
682
+ find: (...t23) => {
683
+ const args_1 = t23;
684
+ return api.medias.find(...args_1);
685
+ },
686
+ create: (...t24) => {
687
+ const args_2 = t24;
688
+ return api.medias.create(...args_2);
689
+ },
690
+ update: (...t25) => {
691
+ const args_3 = t25;
692
+ return api.medias.update(...args_3);
693
+ },
694
+ delete: (...t26) => {
695
+ const args_4 = t26;
696
+ return typeof api.medias.forceDelete !== "undefined" ? api.medias.forceDelete(...args_4) : api.medias.delete(...args_4);
697
+ },
698
+ trash: (...t27) => {
699
+ const args_5 = t27;
700
+ return api.medias.delete(...args_5);
701
+ },
702
+ restore: (...t28) => {
703
+ const args_6 = t28;
704
+ return api.medias.restore(...args_6);
705
+ }
706
+ };
707
+ $[12] = api;
708
+ $[13] = t20;
709
+ } else {
710
+ t20 = $[13];
711
+ }
712
+ const mediasApi = t20;
388
713
  const {
389
714
  create: createMedia
390
715
  } = useMediaCreate();
391
- const onMediaUploaded = useCallback(newMedias => Promise.all(newMedias.map(createMedia)).then(newAddedMedias => newAddedMedias), [createMedia]);
392
- const fileTypes = useMemo(() => {
393
- let finalTypes = [];
394
- if (isArray(types)) {
395
- finalTypes = types.map(t => ['image', 'video', 'audio'].indexOf(t) !== -1 ? `${t}/*` : null).filter(t_0 => t_0 !== null);
396
- }
397
- finalTypes = ['image', 'video', 'audio'].indexOf(types) !== -1 ? [`${types}/*`] : null;
398
- if (finalTypes !== null && isArray(finalTypes) && finalTypes.indexOf('video/*') !== -1) {
399
- finalTypes.push('image/gif');
400
- }
401
- return finalTypes;
402
- }, [types]);
403
- const uppyConfig = useMemo(() => ({
404
- // set sources ? - uppy sources -
405
- allowedFileTypes: fileTypes !== null && fileTypes.length > 0 ? fileTypes : null
406
- }), [fileTypes]);
407
- const finalTypes_0 = useMemo(() => !isArray(types) && types !== null ? [types] : types, [types]);
408
-
409
- // Filters
410
- const partialFilters = filters$1 || filters() || [];
411
- const finalFilters = useMemo(() => partialFilters.map(filter => {
412
- const {
413
- id = null,
414
- options = []
415
- } = filter || {};
416
- if (id === 'types' && finalTypes_0 !== null) {
417
- return false;
418
- }
419
- if (id === 'source') {
420
- if (storyId === null) {
421
- return null;
716
+ let t21;
717
+ if ($[14] !== createMedia) {
718
+ t21 = newMedias => Promise.all(newMedias.map(createMedia)).then(_temp4);
719
+ $[14] = createMedia;
720
+ $[15] = t21;
721
+ } else {
722
+ t21 = $[15];
723
+ }
724
+ const onMediaUploaded = t21;
725
+ const t22 = fileTypes !== null && fileTypes.length > 0 ? fileTypes : null;
726
+ let t23;
727
+ if ($[16] !== t22) {
728
+ t23 = {
729
+ allowedFileTypes: t22
730
+ };
731
+ $[16] = t22;
732
+ $[17] = t23;
733
+ } else {
734
+ t23 = $[17];
735
+ }
736
+ const uppyConfig = t23;
737
+ let t24;
738
+ if ($[18] !== source) {
739
+ t24 = source !== null ? {
740
+ source
741
+ } : null;
742
+ $[18] = source;
743
+ $[19] = t24;
744
+ } else {
745
+ t24 = $[19];
746
+ }
747
+ let t25;
748
+ if ($[20] !== query || $[21] !== t24) {
749
+ t25 = {
750
+ ...query,
751
+ ...t24
752
+ };
753
+ $[20] = query;
754
+ $[21] = t24;
755
+ $[22] = t25;
756
+ } else {
757
+ t25 = $[22];
758
+ }
759
+ const finalQuery = t25;
760
+ let t26;
761
+ if ($[23] !== value) {
762
+ t26 = isObject(value) ? [value] : value;
763
+ $[23] = value;
764
+ $[24] = t26;
765
+ } else {
766
+ t26 = $[24];
767
+ }
768
+ const pickerValue = t26;
769
+ let t27;
770
+ if ($[25] !== multiple || $[26] !== onChange) {
771
+ t27 = newValue => {
772
+ if (onChange !== null) {
773
+ onChange(!multiple && _isArray(newValue) ? newValue?.[0] ?? null : newValue);
422
774
  }
423
- return {
424
- ...filter,
425
- options: (options || []).map(({
426
- value: optionValue = null,
427
- label = null
428
- } = {}) => optionValue === 'document-' ? {
429
- value: `document-${storyId}`,
430
- label
431
- } : {
432
- value: optionValue,
433
- label
434
- })
435
- };
436
- }
437
- return filter;
438
- }).filter(f => f !== null), [partialFilters, storyId]);
439
- const finalQuery = useMemo(() => source !== null ? {
440
- source
441
- } : null, [source]);
442
- return /*#__PURE__*/jsx("div", {
443
- className: classNames([styles.container, className]),
444
- children: isPicker ? /*#__PURE__*/jsx(MediasPickerContainer, {
775
+ };
776
+ $[25] = multiple;
777
+ $[26] = onChange;
778
+ $[27] = t27;
779
+ } else {
780
+ t27 = $[27];
781
+ }
782
+ const onPickerChange = t27;
783
+ let t28;
784
+ if ($[28] !== className) {
785
+ t28 = classNames([styles.container, className]);
786
+ $[28] = className;
787
+ $[29] = t28;
788
+ } else {
789
+ t28 = $[29];
790
+ }
791
+ let t29;
792
+ if ($[30] !== columns || $[31] !== fields || $[32] !== filters || $[33] !== finalQuery || $[34] !== finalTypes || $[35] !== initialMedias || $[36] !== isPicker || $[37] !== mediasApi || $[38] !== multiple || $[39] !== onMediaFormClose || $[40] !== onMediaFormOpen || $[41] !== onMediaUploaded || $[42] !== onPickerChange || $[43] !== pickerValue || $[44] !== uppyConfig) {
793
+ t29 = isPicker ? /*#__PURE__*/jsx(MediasPickerContainer, {
445
794
  className: styles.browser,
446
795
  api: mediasApi,
447
- value: isObject(value) ? [value] : value,
448
- theme: "dark",
449
- types: finalTypes_0,
796
+ value: pickerValue,
797
+ types: finalTypes,
450
798
  query: finalQuery,
451
799
  items: initialMedias,
452
- filters: finalFilters,
453
- fields: fields$1,
800
+ filters: filters,
801
+ fields: fields,
454
802
  columns: columns,
455
803
  multiple: multiple,
456
- onChange: onChange,
804
+ onChange: onPickerChange,
457
805
  uppyConfig: uppyConfig,
458
806
  onMediaUploaded: onMediaUploaded,
459
807
  onMediaFormOpen: onMediaFormOpen,
@@ -463,23 +811,286 @@ function MediaGallery({
463
811
  }) : /*#__PURE__*/jsx(MediasBrowserContainer, {
464
812
  className: styles.browser,
465
813
  api: mediasApi,
466
- value: value,
467
- theme: "dark",
468
- types: finalTypes_0,
814
+ types: finalTypes,
469
815
  query: finalQuery,
470
816
  items: initialMedias,
471
- filters: finalFilters,
472
- fields: fields$1,
817
+ filters: filters,
818
+ fields: fields,
473
819
  columns: columns,
474
820
  uppyConfig: uppyConfig,
475
821
  onMediaUploaded: onMediaUploaded,
476
- multipleSelection: true // allow multi-uploads in MediasBrowser
477
- ,
822
+ multipleSelection: true,
478
823
  withStickySelection: true,
479
824
  withTrash: true,
480
825
  withReplace: true
481
- })
482
- });
826
+ });
827
+ $[30] = columns;
828
+ $[31] = fields;
829
+ $[32] = filters;
830
+ $[33] = finalQuery;
831
+ $[34] = finalTypes;
832
+ $[35] = initialMedias;
833
+ $[36] = isPicker;
834
+ $[37] = mediasApi;
835
+ $[38] = multiple;
836
+ $[39] = onMediaFormClose;
837
+ $[40] = onMediaFormOpen;
838
+ $[41] = onMediaUploaded;
839
+ $[42] = onPickerChange;
840
+ $[43] = pickerValue;
841
+ $[44] = uppyConfig;
842
+ $[45] = t29;
843
+ } else {
844
+ t29 = $[45];
845
+ }
846
+ let t30;
847
+ if ($[46] !== t28 || $[47] !== t29) {
848
+ t30 = /*#__PURE__*/jsx("div", {
849
+ className: t28,
850
+ children: t29
851
+ });
852
+ $[46] = t28;
853
+ $[47] = t29;
854
+ $[48] = t30;
855
+ } else {
856
+ t30 = $[48];
857
+ }
858
+ return t30;
859
+ }
860
+ function _temp4(newAddedMedias) {
861
+ return newAddedMedias;
862
+ }
863
+ function _temp3(f) {
864
+ return f !== null;
865
+ }
866
+ function _temp2(t_0) {
867
+ return t_0 !== null;
868
+ }
869
+ function _temp(t) {
870
+ return ["image", "video", "audio"].indexOf(t) !== -1 ? `${t}/*` : null;
871
+ }
872
+
873
+ function MediaGalleryModal(t0) {
874
+ const $ = c(47);
875
+ let initialValue;
876
+ let props;
877
+ let t1;
878
+ let t10;
879
+ let t2;
880
+ let t3;
881
+ let t4;
882
+ let t5;
883
+ let t6;
884
+ let t7;
885
+ let t8;
886
+ let t9;
887
+ if ($[0] !== t0) {
888
+ ({
889
+ id: t1,
890
+ title: t2,
891
+ size: t3,
892
+ visible: t4,
893
+ autoClose: t5,
894
+ multiple: t6,
895
+ requestClose: t7,
896
+ onClosed: t8,
897
+ className: t9,
898
+ value: initialValue,
899
+ onChange: t10,
900
+ ...props
901
+ } = t0);
902
+ $[0] = t0;
903
+ $[1] = initialValue;
904
+ $[2] = props;
905
+ $[3] = t1;
906
+ $[4] = t10;
907
+ $[5] = t2;
908
+ $[6] = t3;
909
+ $[7] = t4;
910
+ $[8] = t5;
911
+ $[9] = t6;
912
+ $[10] = t7;
913
+ $[11] = t8;
914
+ $[12] = t9;
915
+ } else {
916
+ initialValue = $[1];
917
+ props = $[2];
918
+ t1 = $[3];
919
+ t10 = $[4];
920
+ t2 = $[5];
921
+ t3 = $[6];
922
+ t4 = $[7];
923
+ t5 = $[8];
924
+ t6 = $[9];
925
+ t7 = $[10];
926
+ t8 = $[11];
927
+ t9 = $[12];
928
+ }
929
+ const id = t1 === undefined ? null : t1;
930
+ const title = t2 === undefined ? null : t2;
931
+ const size = t3 === undefined ? "xl" : t3;
932
+ const visible = t4 === undefined ? null : t4;
933
+ const autoClose = t5 === undefined ? true : t5;
934
+ const multiple = t6 === undefined ? false : t6;
935
+ const customRequestClose = t7 === undefined ? null : t7;
936
+ const onClosed = t8 === undefined ? null : t8;
937
+ const className = t9 === undefined ? null : t9;
938
+ const onChange = t10 === undefined ? null : t10;
939
+ const [opened, setOpened] = useState(true);
940
+ const [formOpen, setFormOpen] = useState(false);
941
+ const [value, setValue] = useState(initialValue);
942
+ let t11;
943
+ if ($[13] !== customRequestClose) {
944
+ t11 = customRequestClose ?? (() => {
945
+ setOpened(false);
946
+ });
947
+ $[13] = customRequestClose;
948
+ $[14] = t11;
949
+ } else {
950
+ t11 = $[14];
951
+ }
952
+ const requestClose = t11;
953
+ let t12;
954
+ if ($[15] !== autoClose || $[16] !== multiple || $[17] !== onChange || $[18] !== requestClose) {
955
+ t12 = newValue => {
956
+ if (!autoClose || multiple) {
957
+ setValue(newValue);
958
+ } else {
959
+ if (onChange !== null) {
960
+ onChange(newValue);
961
+ }
962
+ }
963
+ if (autoClose && !multiple) {
964
+ requestClose();
965
+ }
966
+ };
967
+ $[15] = autoClose;
968
+ $[16] = multiple;
969
+ $[17] = onChange;
970
+ $[18] = requestClose;
971
+ $[19] = t12;
972
+ } else {
973
+ t12 = $[19];
974
+ }
975
+ const onGalleryChange = t12;
976
+ let t13;
977
+ if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
978
+ t13 = () => {
979
+ setFormOpen(true);
980
+ };
981
+ $[20] = t13;
982
+ } else {
983
+ t13 = $[20];
984
+ }
985
+ const onFormOpen = t13;
986
+ let t14;
987
+ if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
988
+ t14 = () => {
989
+ setFormOpen(false);
990
+ };
991
+ $[21] = t14;
992
+ } else {
993
+ t14 = $[21];
994
+ }
995
+ const onFormClose = t14;
996
+ let t15;
997
+ if ($[22] !== onChange || $[23] !== value) {
998
+ t15 = () => {
999
+ if (onChange !== null) {
1000
+ onChange(value);
1001
+ }
1002
+ };
1003
+ $[22] = onChange;
1004
+ $[23] = value;
1005
+ $[24] = t15;
1006
+ } else {
1007
+ t15 = $[24];
1008
+ }
1009
+ const onClickSubmit = t15;
1010
+ const t16 = id ?? "media-gallery";
1011
+ let t17;
1012
+ if ($[25] !== title) {
1013
+ t17 = title || /*#__PURE__*/jsx(FormattedMessage, {
1014
+ id: "ZpoE9K",
1015
+ defaultMessage: "Select media"
1016
+ });
1017
+ $[25] = title;
1018
+ $[26] = t17;
1019
+ } else {
1020
+ t17 = $[26];
1021
+ }
1022
+ const t18 = visible ?? opened;
1023
+ const t19 = !formOpen;
1024
+ const t20 = !formOpen;
1025
+ let t21;
1026
+ if ($[27] !== className) {
1027
+ t21 = classNames(["modal-fullscreen-lg-down", className]);
1028
+ $[27] = className;
1029
+ $[28] = t21;
1030
+ } else {
1031
+ t21 = $[28];
1032
+ }
1033
+ let t22;
1034
+ if ($[29] === Symbol.for("react.memo_cache_sentinel")) {
1035
+ t22 = /*#__PURE__*/jsx(FormattedMessage, {
1036
+ id: "rvOVCV",
1037
+ defaultMessage: "Confirm selection"
1038
+ });
1039
+ $[29] = t22;
1040
+ } else {
1041
+ t22 = $[29];
1042
+ }
1043
+ let t23;
1044
+ if ($[30] !== multiple || $[31] !== onGalleryChange || $[32] !== props || $[33] !== value) {
1045
+ t23 = /*#__PURE__*/jsx(MediaGallery, {
1046
+ isPicker: true,
1047
+ multiple: multiple,
1048
+ value: value,
1049
+ onChange: onGalleryChange,
1050
+ onMediaFormOpen: onFormOpen,
1051
+ onMediaFormClose: onFormClose,
1052
+ ...props
1053
+ });
1054
+ $[30] = multiple;
1055
+ $[31] = onGalleryChange;
1056
+ $[32] = props;
1057
+ $[33] = value;
1058
+ $[34] = t23;
1059
+ } else {
1060
+ t23 = $[34];
1061
+ }
1062
+ let t24;
1063
+ if ($[35] !== onClickSubmit || $[36] !== onClosed || $[37] !== requestClose || $[38] !== size || $[39] !== t16 || $[40] !== t17 || $[41] !== t18 || $[42] !== t19 || $[43] !== t20 || $[44] !== t21 || $[45] !== t23) {
1064
+ t24 = /*#__PURE__*/jsx(Dialog, {
1065
+ id: t16,
1066
+ title: t17,
1067
+ size: size,
1068
+ visible: t18,
1069
+ withCancelButton: t19,
1070
+ withSubmitButton: t20,
1071
+ requestClose: requestClose,
1072
+ onClosed: onClosed,
1073
+ onClickSubmit: onClickSubmit,
1074
+ className: t21,
1075
+ submitButtonLabel: t22,
1076
+ children: t23
1077
+ });
1078
+ $[35] = onClickSubmit;
1079
+ $[36] = onClosed;
1080
+ $[37] = requestClose;
1081
+ $[38] = size;
1082
+ $[39] = t16;
1083
+ $[40] = t17;
1084
+ $[41] = t18;
1085
+ $[42] = t19;
1086
+ $[43] = t20;
1087
+ $[44] = t21;
1088
+ $[45] = t23;
1089
+ $[46] = t24;
1090
+ } else {
1091
+ t24 = $[46];
1092
+ }
1093
+ return t24;
483
1094
  }
484
1095
 
485
- export { MediaGallery as default };
1096
+ export { MediaGallery, MediaGalleryModal, MediaGallery as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/media-gallery",
3
- "version": "0.4.88",
3
+ "version": "0.4.90-alpha.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -66,9 +66,9 @@
66
66
  "@fortawesome/fontawesome-svg-core": "^7.2.0",
67
67
  "@fortawesome/free-solid-svg-icons": "^7.2.0",
68
68
  "@fortawesome/react-fontawesome": "^3.2.0",
69
- "@micromag/core": "^0.4.88",
70
- "@micromag/data": "^0.4.88",
71
- "@panneau/medias": "^4.0.42",
69
+ "@micromag/core": "^0.4.90-alpha.1",
70
+ "@micromag/data": "^0.4.90-alpha.1",
71
+ "@panneau/medias": "^4.0.55",
72
72
  "bootstrap": "^5.3.8",
73
73
  "classnames": "^2.2.6",
74
74
  "lodash": "^4.17.23",
@@ -80,6 +80,6 @@
80
80
  "access": "public",
81
81
  "registry": "https://registry.npmjs.org/"
82
82
  },
83
- "gitHead": "cf331286bb6037d61e664cd5c961955c136719c6",
83
+ "gitHead": "a13dd2242ee733dc3b3663354783f0b4395f9926",
84
84
  "types": "es/index.d.ts"
85
85
  }