@micromag/media-gallery 0.4.88 → 0.4.89

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 +4 -3
  2. package/es/index.js +690 -302
  3. package/package.json +2 -2
package/es/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Media } from '@micromag/core';
3
3
 
4
4
  interface MediaGalleryProps {
5
5
  value?: Media | Media[] | null;
6
- types?: string | unknown[] | null;
6
+ types?: string | string[] | null;
7
7
  source?: string;
8
8
  filters?: {
9
9
  id?: string;
@@ -17,11 +17,12 @@ interface MediaGalleryProps {
17
17
  isPicker?: boolean;
18
18
  multiple?: boolean;
19
19
  medias?: Media[] | null;
20
- onChange?: ((...args: unknown[]) => void) | null;
20
+ query?: Record<string, unknown> | null;
21
+ onChange?: ((media: Media | Media[] | null) => void) | null;
21
22
  onMediaFormOpen?: ((...args: unknown[]) => void) | null;
22
23
  onMediaFormClose?: ((...args: unknown[]) => void) | null;
23
24
  className?: string | null;
24
25
  }
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;
26
+ 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
27
 
27
28
  export { MediaGallery as default };
package/es/index.js CHANGED
@@ -1,7 +1,8 @@
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';
@@ -108,352 +109,698 @@ var defaultColumns = [{
108
109
  // },
109
110
  ];
110
111
 
111
- function fields() {
112
+ function useDefaultFilters() {
113
+ const $ = c(16);
112
114
  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',
115
+ let t0;
116
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
117
+ t0 = {
118
+ id: "search",
119
+ component: "search",
120
+ name: "search",
121
+ width: 152
122
+ };
123
+ $[0] = t0;
124
+ } else {
125
+ t0 = $[0];
126
+ }
127
+ let t1;
128
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
129
+ t1 = {
130
+ id: "types",
131
+ component: "select",
132
+ name: "types",
133
+ placeholder: /*#__PURE__*/jsx(FormattedMessage, {
134
+ id: "9/t5wK",
135
+ defaultMessage: "Type"
136
+ }),
137
+ options: [{
138
+ label: /*#__PURE__*/jsx(FormattedMessage, {
139
+ id: "yHAmDD",
140
+ defaultMessage: "Image"
141
+ }),
142
+ value: "image"
143
+ }, {
144
+ label: /*#__PURE__*/jsx(FormattedMessage, {
145
+ id: "xSERPA",
146
+ defaultMessage: "Video"
147
+ }),
148
+ value: "video"
149
+ }, {
150
+ label: /*#__PURE__*/jsx(FormattedMessage, {
151
+ id: "yQRtgx",
152
+ defaultMessage: "Audio"
153
+ }),
154
+ value: "audio"
155
+ }, {
156
+ label: /*#__PURE__*/jsx(FormattedMessage, {
157
+ id: "fpQzza",
158
+ defaultMessage: "Font"
159
+ }),
160
+ value: "font"
161
+ }],
162
+ multiple: true
163
+ };
164
+ $[1] = t1;
165
+ } else {
166
+ t1 = $[1];
167
+ }
168
+ let t2;
169
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
170
+ t2 = /*#__PURE__*/jsx(FormattedMessage, {
171
+ id: "7oXkoj",
172
+ defaultMessage: "Authors"
173
+ });
174
+ $[2] = t2;
175
+ } else {
176
+ t2 = $[2];
177
+ }
178
+ let t3;
179
+ if ($[3] !== route) {
180
+ t3 = route("medias.authors") || "/medias/authors";
181
+ $[3] = route;
182
+ $[4] = t3;
183
+ } else {
184
+ t3 = $[4];
185
+ }
186
+ let t4;
187
+ if ($[5] !== t3) {
188
+ t4 = {
189
+ id: "authors",
190
+ component: "select",
191
+ name: "authors",
192
+ placeholder: t2,
193
+ requestUrl: t3,
194
+ itemLabelPath: "name",
195
+ itemValuePath: "id",
196
+ multiple: true,
197
+ paginated: false
198
+ };
199
+ $[5] = t3;
200
+ $[6] = t4;
201
+ } else {
202
+ t4 = $[6];
203
+ }
204
+ let t5;
205
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
206
+ t5 = /*#__PURE__*/jsx(FormattedMessage, {
207
+ id: "9mXl24",
208
+ defaultMessage: "Tags"
209
+ });
210
+ $[7] = t5;
211
+ } else {
212
+ t5 = $[7];
213
+ }
214
+ let t6;
215
+ if ($[8] !== route) {
216
+ t6 = route("medias.tags") || "/medias/tags";
217
+ $[8] = route;
218
+ $[9] = t6;
219
+ } else {
220
+ t6 = $[9];
221
+ }
222
+ let t7;
223
+ if ($[10] !== t6) {
224
+ t7 = {
225
+ id: "tags",
226
+ component: "select",
227
+ name: "tags",
228
+ placeholder: t5,
229
+ requestUrl: t6,
230
+ itemLabelPath: "name",
231
+ itemValuePath: "name",
232
+ multiple: true,
233
+ paginated: false
234
+ };
235
+ $[10] = t6;
236
+ $[11] = t7;
237
+ } else {
238
+ t7 = $[11];
239
+ }
240
+ let t8;
241
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
242
+ t8 = {
243
+ id: "source",
244
+ component: "radios",
245
+ name: "source",
246
+ options: [{
247
+ label: /*#__PURE__*/jsx(FormattedMessage, {
248
+ id: "bCtuS/",
249
+ defaultMessage: "In this Micromag"
250
+ }),
251
+ value: "document-"
252
+ }]
253
+ };
254
+ $[12] = t8;
255
+ } else {
256
+ t8 = $[12];
257
+ }
258
+ let t9;
259
+ if ($[13] !== t4 || $[14] !== t7) {
260
+ t9 = [t0, t1, t4, t7, t8];
261
+ $[13] = t4;
262
+ $[14] = t7;
263
+ $[15] = t9;
264
+ } else {
265
+ t9 = $[15];
266
+ }
267
+ return t9;
268
+ }
269
+ function useDefaultFields() {
270
+ const $ = c(20);
271
+ const route = useUrlGenerator();
272
+ let t0;
273
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
274
+ t0 = {
275
+ name: "name",
127
276
  label: /*#__PURE__*/jsx(FormattedMessage, {
128
- id: "ygNvmz",
129
- defaultMessage: "Description"
277
+ id: "WX83V9",
278
+ defaultMessage: "File name"
130
279
  }),
131
- type: 'text',
132
- component: 'text'
133
- }, {
134
- name: 'tags',
280
+ type: "text",
281
+ component: "text"
282
+ };
283
+ $[0] = t0;
284
+ } else {
285
+ t0 = $[0];
286
+ }
287
+ let t1;
288
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
289
+ t1 = {
290
+ name: "description",
135
291
  label: /*#__PURE__*/jsx(FormattedMessage, {
136
- id: "IOVper",
137
- defaultMessage: "Tags"
292
+ id: "ygNvmz",
293
+ defaultMessage: "Description"
138
294
  }),
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, {
295
+ type: "text",
296
+ component: "text"
297
+ };
298
+ $[1] = t1;
299
+ } else {
300
+ t1 = $[1];
301
+ }
302
+ let t2;
303
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
304
+ t2 = /*#__PURE__*/jsx(FormattedMessage, {
305
+ id: "IOVper",
306
+ defaultMessage: "Tags"
307
+ });
308
+ $[2] = t2;
309
+ } else {
310
+ t2 = $[2];
311
+ }
312
+ let t3;
313
+ if ($[3] !== route) {
314
+ t3 = route("medias.tags") || "/medias/tags";
315
+ $[3] = route;
316
+ $[4] = t3;
317
+ } else {
318
+ t3 = $[4];
319
+ }
320
+ let t4;
321
+ if ($[5] !== t3) {
322
+ t4 = {
323
+ id: "metadata",
324
+ component: "fields",
325
+ name: "metadata",
326
+ fields: [t1, {
327
+ name: "tags",
328
+ label: t2,
329
+ createPrefix: "Create",
330
+ type: "array",
331
+ component: "item",
332
+ requestUrl: t3,
333
+ itemLabelPath: "name",
334
+ itemDescriptionPath: null,
335
+ itemValuePath: "id",
336
+ valueIsOption: true,
337
+ multiple: true,
338
+ paginated: false,
339
+ creatable: true
340
+ }]
341
+ };
342
+ $[5] = t3;
343
+ $[6] = t4;
344
+ } else {
345
+ t4 = $[6];
346
+ }
347
+ let t5;
348
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
349
+ t5 = /*#__PURE__*/jsx(FormattedMessage, {
156
350
  id: "3RT69u",
157
351
  defaultMessage: "Informations"
158
- }),
159
- isList: true,
160
- hideWithoutValue: true,
161
- fields: [{
162
- id: 'user',
352
+ });
353
+ $[7] = t5;
354
+ } else {
355
+ t5 = $[7];
356
+ }
357
+ let t6;
358
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
359
+ t6 = {
360
+ id: "user",
163
361
  label: /*#__PURE__*/jsx(FormattedMessage, {
164
362
  id: "yByaBh",
165
363
  defaultMessage: "Added by"
166
364
  }),
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',
365
+ type: "display",
366
+ display: "avatar",
367
+ name: "user",
181
368
  horizontal: true
182
- }]
183
- }, {
184
- id: 'technical',
185
- component: 'fields',
186
- label: /*#__PURE__*/jsx(FormattedMessage, {
369
+ };
370
+ $[8] = t6;
371
+ } else {
372
+ t6 = $[8];
373
+ }
374
+ let t7;
375
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
376
+ t7 = {
377
+ id: "info",
378
+ component: "fields",
379
+ label: t5,
380
+ isList: true,
381
+ hideWithoutValue: true,
382
+ fields: [t6, {
383
+ id: "created_at",
384
+ label: /*#__PURE__*/jsx(FormattedMessage, {
385
+ id: "PN+75e",
386
+ defaultMessage: "Created at"
387
+ }),
388
+ type: "display",
389
+ display: "date",
390
+ name: "created_at",
391
+ format: "yyyy-MM-dd hh:ss",
392
+ horizontal: true
393
+ }]
394
+ };
395
+ $[9] = t7;
396
+ } else {
397
+ t7 = $[9];
398
+ }
399
+ let t8;
400
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
401
+ t8 = /*#__PURE__*/jsx(FormattedMessage, {
187
402
  id: "xKUOLG",
188
403
  defaultMessage: "Technical details"
189
- }),
190
- isList: true,
191
- hideWithoutValue: true,
192
- fields: [{
193
- id: 'format',
404
+ });
405
+ $[10] = t8;
406
+ } else {
407
+ t8 = $[10];
408
+ }
409
+ let t9;
410
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
411
+ t9 = {
412
+ id: "format",
194
413
  label: /*#__PURE__*/jsx(FormattedMessage, {
195
414
  id: "JuxiUN",
196
415
  defaultMessage: "Format"
197
416
  }),
198
- type: 'display',
199
- display: 'unit',
200
- format: 'format',
201
- name: 'format',
417
+ type: "display",
418
+ display: "unit",
419
+ format: "format",
420
+ name: "format",
202
421
  horizontal: true
203
- }, {
204
- id: 'dimensions',
422
+ };
423
+ $[11] = t9;
424
+ } else {
425
+ t9 = $[11];
426
+ }
427
+ let t10;
428
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
429
+ t10 = {
430
+ id: "dimensions",
205
431
  label: /*#__PURE__*/jsx(FormattedMessage, {
206
432
  id: "rmJBin",
207
433
  defaultMessage: "Dimensions"
208
434
  }),
209
- type: 'display',
210
- display: 'unit',
211
- format: 'dimensions',
212
- name: 'metadata',
435
+ type: "display",
436
+ display: "unit",
437
+ format: "dimensions",
438
+ name: "metadata",
213
439
  horizontal: true
214
- }, {
215
- id: 'size',
440
+ };
441
+ $[12] = t10;
442
+ } else {
443
+ t10 = $[12];
444
+ }
445
+ let t11;
446
+ if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
447
+ t11 = {
448
+ id: "size",
216
449
  label: /*#__PURE__*/jsx(FormattedMessage, {
217
450
  id: "g2CRt5",
218
451
  defaultMessage: "Size"
219
452
  }),
220
- type: 'display',
221
- display: 'unit',
222
- format: 'bytes',
223
- name: 'metadata.size',
224
- 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',
453
+ type: "display",
454
+ display: "unit",
455
+ format: "bytes",
456
+ name: "metadata.size",
235
457
  horizontal: true
236
- }]
237
- }, {
238
- id: 'conversion',
239
- component: 'fields',
240
- label: /*#__PURE__*/jsx(FormattedMessage, {
458
+ };
459
+ $[13] = t11;
460
+ } else {
461
+ t11 = $[13];
462
+ }
463
+ let t12;
464
+ if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
465
+ t12 = {
466
+ id: "technical",
467
+ component: "fields",
468
+ label: t8,
469
+ isList: true,
470
+ hideWithoutValue: true,
471
+ fields: [t9, t10, t11, {
472
+ id: "duration",
473
+ label: /*#__PURE__*/jsx(FormattedMessage, {
474
+ id: "wU++NJ",
475
+ defaultMessage: "Duration"
476
+ }),
477
+ type: "display",
478
+ display: "unit",
479
+ format: "duration",
480
+ name: "metadata.duration",
481
+ horizontal: true
482
+ }]
483
+ };
484
+ $[14] = t12;
485
+ } else {
486
+ t12 = $[14];
487
+ }
488
+ let t13;
489
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
490
+ t13 = /*#__PURE__*/jsx(FormattedMessage, {
241
491
  id: "pBNrdH",
242
492
  defaultMessage: "Conversion"
243
- }),
244
- isList: true,
245
- hideWithoutValue: true,
246
- fields: [{
247
- id: 'h264',
493
+ });
494
+ $[15] = t13;
495
+ } else {
496
+ t13 = $[15];
497
+ }
498
+ let t14;
499
+ if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
500
+ t14 = {
501
+ id: "h264",
248
502
  label: /*#__PURE__*/jsx(FormattedMessage, {
249
503
  id: "4RV6+9",
250
504
  defaultMessage: "H264"
251
505
  }),
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',
506
+ type: "text",
507
+ component: "text",
508
+ name: "files.h264.url",
265
509
  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
- }];
510
+ };
511
+ $[16] = t14;
512
+ } else {
513
+ t14 = $[16];
514
+ }
515
+ let t15;
516
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
517
+ t15 = {
518
+ id: "conversion",
519
+ component: "fields",
520
+ label: t13,
521
+ isList: true,
522
+ hideWithoutValue: true,
523
+ fields: [t14, {
524
+ id: "webm",
525
+ label: /*#__PURE__*/jsx(FormattedMessage, {
526
+ id: "3I2Xl7",
527
+ defaultMessage: "WebM"
528
+ }),
529
+ type: "text",
530
+ component: "text",
531
+ name: "files.webm.url",
532
+ horizontal: true
533
+ }]
534
+ };
535
+ $[17] = t15;
536
+ } else {
537
+ t15 = $[17];
538
+ }
539
+ let t16;
540
+ if ($[18] !== t4) {
541
+ t16 = [t0, t4, t7, t12, t15];
542
+ $[18] = t4;
543
+ $[19] = t16;
544
+ } else {
545
+ t16 = $[19];
546
+ }
547
+ return t16;
349
548
  }
350
549
 
351
550
  var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
352
551
 
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
- }) {
552
+ function MediaGallery(t0) {
553
+ const $ = c(49);
554
+ const {
555
+ value: t1,
556
+ types: t2,
557
+ source: t3,
558
+ filters: t4,
559
+ fields: t5,
560
+ columns: t6,
561
+ isPicker: t7,
562
+ multiple: t8,
563
+ medias: t9,
564
+ query: t10,
565
+ onChange: t11,
566
+ onMediaFormOpen: t12,
567
+ onMediaFormClose: t13,
568
+ className: t14
569
+ } = t0;
570
+ const value = t1 === undefined ? null : t1;
571
+ const types = t2 === undefined ? null : t2;
572
+ const source = t3 === undefined ? "all" : t3;
573
+ const providedFilters = t4 === undefined ? null : t4;
574
+ const providedFields = t5 === undefined ? null : t5;
575
+ const columns = t6 === undefined ? defaultColumns : t6;
576
+ const isPicker = t7 === undefined ? false : t7;
577
+ const multiple = t8 === undefined ? false : t8;
578
+ const initialMedias = t9 === undefined ? null : t9;
579
+ const query = t10 === undefined ? null : t10;
580
+ const onChange = t11 === undefined ? null : t11;
581
+ const onMediaFormOpen = t12 === undefined ? null : t12;
582
+ const onMediaFormClose = t13 === undefined ? null : t13;
583
+ const className = t14 === undefined ? null : t14;
368
584
  const api = useApi();
369
585
  const story = useStory();
586
+ let t15;
587
+ if ($[0] !== story) {
588
+ t15 = story || {};
589
+ $[0] = story;
590
+ $[1] = t15;
591
+ } else {
592
+ t15 = $[1];
593
+ }
370
594
  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
595
+ id: t16
596
+ } = t15;
597
+ const storyId = t16 === undefined ? null : t16;
598
+ let finalTypes;
599
+ let t17;
600
+ if ($[2] !== types) {
601
+ finalTypes = isString(types) ? [types] : types;
602
+ t17 = [...(finalTypes || []).map(_temp), (finalTypes || []).indexOf("video") !== -1 ? "image/gif" : null].filter(_temp2);
603
+ $[2] = types;
604
+ $[3] = finalTypes;
605
+ $[4] = t17;
606
+ } else {
607
+ finalTypes = $[3];
608
+ t17 = $[4];
609
+ }
610
+ const fileTypes = t17;
611
+ const defaultFields = useDefaultFields();
612
+ const defaultFilters = useDefaultFilters();
613
+ const fields = providedFields ?? defaultFields;
614
+ const t18 = providedFilters ?? defaultFilters;
615
+ let t19;
616
+ if ($[5] !== finalTypes || $[6] !== storyId || $[7] !== t18) {
617
+ let t20;
618
+ if ($[9] !== finalTypes || $[10] !== storyId) {
619
+ t20 = filter => {
620
+ const {
621
+ id: t21,
622
+ options: t22
623
+ } = filter || {};
624
+ const id = t21 === undefined ? null : t21;
625
+ const options = t22 === undefined ? [] : t22;
626
+ if (id === "types" && finalTypes !== null) {
627
+ return false;
628
+ }
629
+ if (id === "source") {
630
+ if (storyId === null) {
631
+ return null;
632
+ }
633
+ return {
634
+ ...filter,
635
+ options: (options || []).map(t23 => {
636
+ const {
637
+ value: t24,
638
+ label: t25
639
+ } = t23 === undefined ? {} : t23;
640
+ const optionValue = t24 === undefined ? null : t24;
641
+ const label = t25 === undefined ? null : t25;
642
+ return optionValue === "document-" ? {
643
+ value: `document-${storyId}`,
644
+ label
645
+ } : {
646
+ value: optionValue,
647
+ label
648
+ };
649
+ })
650
+ };
651
+ }
652
+ return filter;
653
+ };
654
+ $[9] = finalTypes;
655
+ $[10] = storyId;
656
+ $[11] = t20;
657
+ } else {
658
+ t20 = $[11];
659
+ }
660
+ t19 = t18.map(t20).filter(_temp3);
661
+ $[5] = finalTypes;
662
+ $[6] = storyId;
663
+ $[7] = t18;
664
+ $[8] = t19;
665
+ } else {
666
+ t19 = $[8];
667
+ }
668
+ const filters = t19;
669
+ let t20;
670
+ if ($[12] !== api) {
671
+ t20 = {
672
+ get: (...t21) => {
673
+ const args = t21;
674
+ return api.medias.get(...args);
675
+ },
676
+ getTrashed: (...t22) => {
677
+ const args_0 = t22;
678
+ return api.medias.getTrashed(...args_0);
679
+ },
680
+ find: (...t23) => {
681
+ const args_1 = t23;
682
+ return api.medias.find(...args_1);
683
+ },
684
+ create: (...t24) => {
685
+ const args_2 = t24;
686
+ return api.medias.create(...args_2);
687
+ },
688
+ update: (...t25) => {
689
+ const args_3 = t25;
690
+ return api.medias.update(...args_3);
691
+ },
692
+ delete: (...t26) => {
693
+ const args_4 = t26;
694
+ return typeof api.medias.forceDelete !== "undefined" ? api.medias.forceDelete(...args_4) : api.medias.delete(...args_4);
695
+ },
696
+ trash: (...t27) => {
697
+ const args_5 = t27;
698
+ return api.medias.delete(...args_5);
699
+ },
700
+ restore: (...t28) => {
701
+ const args_6 = t28;
702
+ return api.medias.restore(...args_6);
703
+ }
704
+ };
705
+ $[12] = api;
706
+ $[13] = t20;
707
+ } else {
708
+ t20 = $[13];
709
+ }
710
+ const mediasApi = t20;
388
711
  const {
389
712
  create: createMedia
390
713
  } = 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;
714
+ let t21;
715
+ if ($[14] !== createMedia) {
716
+ t21 = newMedias => Promise.all(newMedias.map(createMedia)).then(_temp4);
717
+ $[14] = createMedia;
718
+ $[15] = t21;
719
+ } else {
720
+ t21 = $[15];
721
+ }
722
+ const onMediaUploaded = t21;
723
+ const t22 = fileTypes !== null && fileTypes.length > 0 ? fileTypes : null;
724
+ let t23;
725
+ if ($[16] !== t22) {
726
+ t23 = {
727
+ allowedFileTypes: t22
728
+ };
729
+ $[16] = t22;
730
+ $[17] = t23;
731
+ } else {
732
+ t23 = $[17];
733
+ }
734
+ const uppyConfig = t23;
735
+ let t24;
736
+ if ($[18] !== source) {
737
+ t24 = source !== null ? {
738
+ source
739
+ } : null;
740
+ $[18] = source;
741
+ $[19] = t24;
742
+ } else {
743
+ t24 = $[19];
744
+ }
745
+ let t25;
746
+ if ($[20] !== query || $[21] !== t24) {
747
+ t25 = {
748
+ ...query,
749
+ ...t24
750
+ };
751
+ $[20] = query;
752
+ $[21] = t24;
753
+ $[22] = t25;
754
+ } else {
755
+ t25 = $[22];
756
+ }
757
+ const finalQuery = t25;
758
+ let t26;
759
+ if ($[23] !== value) {
760
+ t26 = isObject(value) ? [value] : value;
761
+ $[23] = value;
762
+ $[24] = t26;
763
+ } else {
764
+ t26 = $[24];
765
+ }
766
+ const pickerValue = t26;
767
+ let t27;
768
+ if ($[25] !== multiple || $[26] !== onChange) {
769
+ t27 = newValue => {
770
+ if (onChange !== null) {
771
+ onChange(!multiple && _isArray(newValue) ? newValue?.[0] ?? null : newValue);
422
772
  }
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, {
773
+ };
774
+ $[25] = multiple;
775
+ $[26] = onChange;
776
+ $[27] = t27;
777
+ } else {
778
+ t27 = $[27];
779
+ }
780
+ const onPickerChange = t27;
781
+ let t28;
782
+ if ($[28] !== className) {
783
+ t28 = classNames([styles.container, className]);
784
+ $[28] = className;
785
+ $[29] = t28;
786
+ } else {
787
+ t28 = $[29];
788
+ }
789
+ let t29;
790
+ 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) {
791
+ t29 = isPicker ? /*#__PURE__*/jsx(MediasPickerContainer, {
445
792
  className: styles.browser,
446
793
  api: mediasApi,
447
- value: isObject(value) ? [value] : value,
794
+ value: pickerValue,
448
795
  theme: "dark",
449
- types: finalTypes_0,
796
+ types: finalTypes,
450
797
  query: finalQuery,
451
798
  items: initialMedias,
452
- filters: finalFilters,
453
- fields: fields$1,
799
+ filters: filters,
800
+ fields: fields,
454
801
  columns: columns,
455
802
  multiple: multiple,
456
- onChange: onChange,
803
+ onChange: onPickerChange,
457
804
  uppyConfig: uppyConfig,
458
805
  onMediaUploaded: onMediaUploaded,
459
806
  onMediaFormOpen: onMediaFormOpen,
@@ -463,23 +810,64 @@ function MediaGallery({
463
810
  }) : /*#__PURE__*/jsx(MediasBrowserContainer, {
464
811
  className: styles.browser,
465
812
  api: mediasApi,
466
- value: value,
467
813
  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;
483
871
  }
484
872
 
485
873
  export { 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.89",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -80,6 +80,6 @@
80
80
  "access": "public",
81
81
  "registry": "https://registry.npmjs.org/"
82
82
  },
83
- "gitHead": "cf331286bb6037d61e664cd5c961955c136719c6",
83
+ "gitHead": "b22ccb83a7c0679970a453b09e2be779ed68f839",
84
84
  "types": "es/index.d.ts"
85
85
  }