@micromag/media-gallery 0.3.538 → 0.3.540

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.
@@ -0,0 +1 @@
1
+ .micromag-media-gallery-new-media-gallery-container .micromag-media-gallery-new-media-gallery-browser{--bs-input-color:hsla(0,0%,100%,.07)!important}
package/es/index.js ADDED
@@ -0,0 +1,605 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
4
+ import classNames from 'classnames';
5
+ import isArray from 'lodash/isArray';
6
+ import PropTypes from 'prop-types';
7
+ import React, { useMemo, useCallback, useState } from 'react';
8
+ import { MediasPickerContainer, MediasBrowserContainer } from '@panneau/medias';
9
+ import { PropTypes as PropTypes$1 } from '@micromag/core';
10
+ import { useStory } from '@micromag/core/contexts';
11
+ import { useApi, useMediaCreate } from '@micromag/data';
12
+ import { FormattedMessage } from 'react-intl';
13
+ import { useUrlGenerator } from '@folklore/routes';
14
+
15
+ var defaultColumns = [{
16
+ id: 'image',
17
+ label: null,
18
+ component: 'image',
19
+ path: 'thumbnail_url',
20
+ sortable: false
21
+ }, {
22
+ id: 'name',
23
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
24
+ id: "WX83V9",
25
+ defaultMessage: [{
26
+ "type": 0,
27
+ "value": "File name"
28
+ }]
29
+ }),
30
+ component: 'text-description',
31
+ path: 'name',
32
+ descriptionPath: 'type',
33
+ descriptionValues: {
34
+ image: /*#__PURE__*/React.createElement(FormattedMessage, {
35
+ id: "AwDQvD",
36
+ defaultMessage: [{
37
+ "type": 0,
38
+ "value": "Image"
39
+ }]
40
+ }),
41
+ video: /*#__PURE__*/React.createElement(FormattedMessage, {
42
+ id: "mQiyAm",
43
+ defaultMessage: [{
44
+ "type": 0,
45
+ "value": "Video"
46
+ }]
47
+ }),
48
+ audio: /*#__PURE__*/React.createElement(FormattedMessage, {
49
+ id: "XnyI69",
50
+ defaultMessage: [{
51
+ "type": 0,
52
+ "value": "Audio"
53
+ }]
54
+ }),
55
+ document: /*#__PURE__*/React.createElement(FormattedMessage, {
56
+ id: "1dqmFw",
57
+ defaultMessage: [{
58
+ "type": 0,
59
+ "value": "Document"
60
+ }]
61
+ })
62
+ },
63
+ sortable: true
64
+ }, {
65
+ id: 'dimensions',
66
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
67
+ id: "eCe9ZY",
68
+ defaultMessage: [{
69
+ "type": 0,
70
+ "value": "Dimensions"
71
+ }]
72
+ }),
73
+ component: 'unit',
74
+ format: 'dimensions',
75
+ path: 'metadata'
76
+ }, {
77
+ id: 'size',
78
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
79
+ id: "c3hu9o",
80
+ defaultMessage: [{
81
+ "type": 0,
82
+ "value": "Size"
83
+ }]
84
+ }),
85
+ component: 'unit',
86
+ format: 'bytes',
87
+ path: 'metadata.size'
88
+ }, {
89
+ id: 'duration',
90
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
91
+ id: "002oWQ",
92
+ defaultMessage: [{
93
+ "type": 0,
94
+ "value": "Duration"
95
+ }]
96
+ }),
97
+ component: 'unit',
98
+ format: 'duration',
99
+ path: 'metadata.duration'
100
+ },
101
+ // {
102
+ // id: 'author',
103
+ // label: <FormattedMessage defaultMessage="Added by" description="Field name" />,
104
+ // component: 'avatar',
105
+ // path: 'metadata.author',
106
+ // namePath: 'name',
107
+ // withoutName: true,
108
+ // },
109
+ {
110
+ id: 'created_at',
111
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
112
+ id: "OzYWZz",
113
+ defaultMessage: [{
114
+ "type": 0,
115
+ "value": "Created at"
116
+ }]
117
+ }),
118
+ component: 'date',
119
+ path: 'created_at',
120
+ format: 'yyyy-MM-dd hh:ss',
121
+ sortable: true
122
+ }, {
123
+ id: 'actions',
124
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
125
+ id: "rtwfuZ",
126
+ defaultMessage: [{
127
+ "type": 0,
128
+ "value": "Actions"
129
+ }]
130
+ }),
131
+ actions: ['edit', 'delete']
132
+ // component: ItemActions,
133
+ // label: 'Edit',
134
+ // url: '/edit/1',
135
+ }
136
+ // {
137
+ // id: 'status',
138
+ // label: <FormattedMessage defaultMessage="Status" description="Field name" />,
139
+ // component: 'text',
140
+ // path: 'metadata.status',
141
+ // },
142
+ ];
143
+
144
+ var defaultFields = [{
145
+ name: 'name',
146
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
147
+ id: "WX83V9",
148
+ defaultMessage: [{
149
+ "type": 0,
150
+ "value": "File name"
151
+ }]
152
+ }),
153
+ type: 'text',
154
+ component: 'text'
155
+ }, {
156
+ id: 'metadata',
157
+ component: 'fields',
158
+ name: 'metadata',
159
+ fields: [{
160
+ name: 'description',
161
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
162
+ id: "ygNvmz",
163
+ defaultMessage: [{
164
+ "type": 0,
165
+ "value": "Description"
166
+ }]
167
+ }),
168
+ type: 'text',
169
+ component: 'text'
170
+ }, {
171
+ name: 'tags',
172
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
173
+ id: "IOVper",
174
+ defaultMessage: [{
175
+ "type": 0,
176
+ "value": "Tags"
177
+ }]
178
+ }),
179
+ type: 'array',
180
+ component: 'select',
181
+ requestUrl: '/api/medias/tags',
182
+ optionLabelPath: 'name',
183
+ optionValuePath: 'id',
184
+ // Uses taggable so change the logic here
185
+ valueIsOption: true,
186
+ multiple: true,
187
+ paginated: false
188
+ // creatable: true, // TODO
189
+ }]
190
+ }, {
191
+ id: 'info',
192
+ component: 'fields',
193
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
194
+ id: "3RT69u",
195
+ defaultMessage: [{
196
+ "type": 0,
197
+ "value": "Informations"
198
+ }]
199
+ }),
200
+ isList: true,
201
+ hideWithoutValue: true,
202
+ fields: [{
203
+ id: 'user',
204
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
205
+ id: "yByaBh",
206
+ defaultMessage: [{
207
+ "type": 0,
208
+ "value": "Added by"
209
+ }]
210
+ }),
211
+ type: 'display',
212
+ display: 'avatar',
213
+ name: 'user',
214
+ horizontal: true
215
+ }, {
216
+ id: 'created_at',
217
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
218
+ id: "PN+75e",
219
+ defaultMessage: [{
220
+ "type": 0,
221
+ "value": "Created at"
222
+ }]
223
+ }),
224
+ type: 'display',
225
+ display: 'date',
226
+ name: 'created_at',
227
+ format: 'yyyy-MM-dd hh:ss',
228
+ horizontal: true
229
+ }]
230
+ }, {
231
+ id: 'technical',
232
+ component: 'fields',
233
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
234
+ id: "xKUOLG",
235
+ defaultMessage: [{
236
+ "type": 0,
237
+ "value": "Technical details"
238
+ }]
239
+ }),
240
+ isList: true,
241
+ hideWithoutValue: true,
242
+ fields: [{
243
+ id: 'format',
244
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
245
+ id: "JuxiUN",
246
+ defaultMessage: [{
247
+ "type": 0,
248
+ "value": "Format"
249
+ }]
250
+ }),
251
+ type: 'display',
252
+ display: 'unit',
253
+ format: 'format',
254
+ name: 'format',
255
+ horizontal: true
256
+ }, {
257
+ id: 'dimensions',
258
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
259
+ id: "rmJBin",
260
+ defaultMessage: [{
261
+ "type": 0,
262
+ "value": "Dimensions"
263
+ }]
264
+ }),
265
+ type: 'display',
266
+ display: 'unit',
267
+ format: 'dimensions',
268
+ name: 'metadata',
269
+ horizontal: true
270
+ }, {
271
+ id: 'size',
272
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
273
+ id: "g2CRt5",
274
+ defaultMessage: [{
275
+ "type": 0,
276
+ "value": "Size"
277
+ }]
278
+ }),
279
+ type: 'display',
280
+ display: 'unit',
281
+ format: 'bytes',
282
+ name: 'metadata.size',
283
+ horizontal: true
284
+ }, {
285
+ id: 'duration',
286
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
287
+ id: "wU++NJ",
288
+ defaultMessage: [{
289
+ "type": 0,
290
+ "value": "Duration"
291
+ }]
292
+ }),
293
+ type: 'display',
294
+ display: 'unit',
295
+ format: 'duration',
296
+ name: 'metadata.duration',
297
+ horizontal: true
298
+ }]
299
+ }];
300
+
301
+ function filters() {
302
+ var route = useUrlGenerator();
303
+ return [{
304
+ id: 'search',
305
+ component: 'search',
306
+ name: 'search',
307
+ width: 152
308
+ }, {
309
+ id: 'types',
310
+ component: 'select',
311
+ name: 'types',
312
+ placeholder: /*#__PURE__*/React.createElement(FormattedMessage, {
313
+ id: "9/t5wK",
314
+ defaultMessage: [{
315
+ "type": 0,
316
+ "value": "Type"
317
+ }]
318
+ }),
319
+ options: [{
320
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
321
+ id: "yHAmDD",
322
+ defaultMessage: [{
323
+ "type": 0,
324
+ "value": "Image"
325
+ }]
326
+ }),
327
+ value: 'image'
328
+ }, {
329
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
330
+ id: "xSERPA",
331
+ defaultMessage: [{
332
+ "type": 0,
333
+ "value": "Video"
334
+ }]
335
+ }),
336
+ value: 'video'
337
+ }, {
338
+ label: /*#__PURE__*/React.createElement(FormattedMessage, {
339
+ id: "yQRtgx",
340
+ defaultMessage: [{
341
+ "type": 0,
342
+ "value": "Audio"
343
+ }]
344
+ }),
345
+ value: 'audio'
346
+ }],
347
+ multiple: true
348
+ }, {
349
+ id: 'authors',
350
+ component: 'select',
351
+ name: 'authors',
352
+ placeholder: /*#__PURE__*/React.createElement(FormattedMessage, {
353
+ id: "7oXkoj",
354
+ defaultMessage: [{
355
+ "type": 0,
356
+ "value": "Authors"
357
+ }]
358
+ }),
359
+ requestUrl: route('medias.authors') || '/medias/authors',
360
+ itemLabelPath: 'name',
361
+ itemValuePath: 'id',
362
+ multiple: true,
363
+ paginated: false
364
+ }, {
365
+ id: 'tags',
366
+ component: 'select',
367
+ name: 'tags',
368
+ placeholder: /*#__PURE__*/React.createElement(FormattedMessage, {
369
+ id: "9mXl24",
370
+ defaultMessage: [{
371
+ "type": 0,
372
+ "value": "Tags"
373
+ }]
374
+ }),
375
+ requestUrl: route('medias.tags') || '/medias/tags',
376
+ itemLabelPath: 'name',
377
+ itemValuePath: 'id',
378
+ multiple: true,
379
+ paginated: false
380
+ }, {
381
+ id: 'source',
382
+ component: 'radios',
383
+ name: 'source',
384
+ options: [{
385
+ label: 'Tous les micromags',
386
+ value: 'all'
387
+ }, {
388
+ label: 'Ce micromag',
389
+ value: 'document-'
390
+ }]
391
+ }];
392
+ }
393
+
394
+ var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
395
+
396
+ var propTypes = {
397
+ value: PropTypes.shape({
398
+ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
399
+ }),
400
+ types: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
401
+ source: PropTypes.string,
402
+ filters: PropTypes.arrayOf(PropTypes.shape({
403
+ id: PropTypes.string
404
+ })),
405
+ fields: PropTypes.arrayOf(PropTypes.shape({
406
+ id: PropTypes.string
407
+ })),
408
+ columns: PropTypes.arrayOf(PropTypes.shape({
409
+ id: PropTypes.string
410
+ })),
411
+ isPicker: PropTypes.bool,
412
+ multiple: PropTypes.bool,
413
+ medias: PropTypes$1.medias,
414
+ onChange: PropTypes.func,
415
+ onMediaFormOpen: PropTypes.func,
416
+ onMediaFormClose: PropTypes.func,
417
+ className: PropTypes.string
418
+ };
419
+ var defaultProps = {
420
+ value: null,
421
+ types: null,
422
+ source: 'all',
423
+ filters: null,
424
+ fields: defaultFields,
425
+ columns: defaultColumns,
426
+ isPicker: false,
427
+ multiple: false,
428
+ medias: null,
429
+ onChange: null,
430
+ onMediaFormOpen: null,
431
+ onMediaFormClose: null,
432
+ className: null
433
+ };
434
+ function MediaGallery(_ref) {
435
+ var value = _ref.value,
436
+ types = _ref.types,
437
+ source = _ref.source,
438
+ filters$1 = _ref.filters,
439
+ fields = _ref.fields,
440
+ columns = _ref.columns,
441
+ isPicker = _ref.isPicker,
442
+ multiple = _ref.multiple,
443
+ initialMedias = _ref.medias,
444
+ onChange = _ref.onChange,
445
+ onMediaFormOpen = _ref.onMediaFormOpen,
446
+ onMediaFormClose = _ref.onMediaFormClose,
447
+ className = _ref.className;
448
+ var api = useApi();
449
+ var story = useStory();
450
+ var _ref2 = story || {},
451
+ _ref2$id = _ref2.id,
452
+ storyId = _ref2$id === void 0 ? null : _ref2$id;
453
+ var mediasApi = useMemo(function () {
454
+ return {
455
+ get: function get() {
456
+ var _api$medias;
457
+ return (_api$medias = api.medias).get.apply(_api$medias, arguments);
458
+ },
459
+ getTrashed: function getTrashed() {
460
+ var _api$medias2;
461
+ return (_api$medias2 = api.medias).getTrashed.apply(_api$medias2, arguments);
462
+ },
463
+ find: function find() {
464
+ var _api$medias3;
465
+ return (_api$medias3 = api.medias).find.apply(_api$medias3, arguments);
466
+ },
467
+ create: function create() {
468
+ var _api$medias4;
469
+ return (_api$medias4 = api.medias).create.apply(_api$medias4, arguments);
470
+ },
471
+ update: function update() {
472
+ var _api$medias5;
473
+ return (_api$medias5 = api.medias).update.apply(_api$medias5, arguments);
474
+ },
475
+ "delete": function _delete() {
476
+ var _api$medias6;
477
+ return (_api$medias6 = api.medias).forceDelete.apply(_api$medias6, arguments);
478
+ },
479
+ trash: function trash() {
480
+ var _api$medias7;
481
+ return (_api$medias7 = api.medias)["delete"].apply(_api$medias7, arguments);
482
+ }
483
+ };
484
+ }, [api]);
485
+
486
+ // Upload
487
+ var _useMediaCreate = useMediaCreate(),
488
+ createMedia = _useMediaCreate.create;
489
+ var onMediaUploaded = useCallback(function (newMedias) {
490
+ return Promise.all(newMedias.map(createMedia)).then(function (newAddedMedias) {
491
+ return newAddedMedias;
492
+ });
493
+ }, [createMedia]);
494
+ var fileTypes = useMemo(function () {
495
+ var finalTypes = [];
496
+ if (isArray(types)) {
497
+ finalTypes = types.map(function (t) {
498
+ return ['image', 'video', 'audio'].indexOf(t) !== -1 ? "".concat(t, "/*") : null;
499
+ }).filter(function (t) {
500
+ return t !== null;
501
+ });
502
+ }
503
+ finalTypes = ['image', 'video', 'audio'].indexOf(types) !== -1 ? ["".concat(types, "/*")] : null;
504
+ if (finalTypes !== null && isArray(finalTypes) && finalTypes.indexOf('video/*') !== -1) {
505
+ finalTypes.push('image/gif');
506
+ }
507
+ return finalTypes;
508
+ }, [types]);
509
+ var uppyConfig = useMemo(function () {
510
+ return {
511
+ // set sources ? - uppy sources -
512
+ allowedFileTypes: fileTypes !== null && fileTypes.length > 0 ? fileTypes : null
513
+ };
514
+ }, [fileTypes]);
515
+
516
+ // Filters
517
+ var partialFilters = filters$1 || filters() || [];
518
+ var finalFilters = useMemo(function () {
519
+ return partialFilters.map(function (filter) {
520
+ var _ref3 = filter || {},
521
+ _ref3$id = _ref3.id,
522
+ id = _ref3$id === void 0 ? null : _ref3$id,
523
+ _ref3$options = _ref3.options,
524
+ options = _ref3$options === void 0 ? [] : _ref3$options;
525
+ if (id === 'source') {
526
+ if (storyId === null) {
527
+ return null;
528
+ }
529
+ return _objectSpread(_objectSpread({}, filter), {}, {
530
+ options: (options || []).map(function () {
531
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
532
+ _ref4$value = _ref4.value,
533
+ optionValue = _ref4$value === void 0 ? null : _ref4$value,
534
+ _ref4$label = _ref4.label,
535
+ label = _ref4$label === void 0 ? null : _ref4$label;
536
+ return optionValue === 'document-' ? {
537
+ value: "document-".concat(storyId),
538
+ label: label
539
+ } : {
540
+ value: optionValue,
541
+ label: label
542
+ };
543
+ })
544
+ });
545
+ }
546
+ return filter;
547
+ }).filter(function (f) {
548
+ return f !== null;
549
+ });
550
+ }, [partialFilters, storyId]);
551
+ var _useState = useState(source !== null ? {
552
+ source: source
553
+ } : null),
554
+ _useState2 = _slicedToArray(_useState, 2),
555
+ query = _useState2[0],
556
+ setQuery = _useState2[1];
557
+ var finalQuery = useMemo(function () {
558
+ setQuery(_objectSpread(_objectSpread({}, query || null), source !== null ? {
559
+ source: source
560
+ } : null));
561
+ }, [source, setQuery]);
562
+ var finalTypes = useMemo(function () {
563
+ return !isArray(types) && types !== null ? [types] : types;
564
+ }, [types]);
565
+ return /*#__PURE__*/React.createElement("div", {
566
+ className: classNames([styles.container, _defineProperty({}, className, className)])
567
+ }, isPicker ? /*#__PURE__*/React.createElement(MediasPickerContainer, {
568
+ className: styles.browser,
569
+ api: mediasApi,
570
+ value: value,
571
+ theme: "dark",
572
+ types: finalTypes,
573
+ query: finalQuery,
574
+ items: initialMedias,
575
+ filters: finalFilters,
576
+ fields: fields,
577
+ columns: columns,
578
+ multiple: multiple,
579
+ onChange: onChange,
580
+ uppyConfig: uppyConfig,
581
+ onMediaUploaded: onMediaUploaded,
582
+ onMediaFormOpen: onMediaFormOpen,
583
+ onMediaFormClose: onMediaFormClose,
584
+ withStickySelection: true
585
+ }) : /*#__PURE__*/React.createElement(MediasBrowserContainer, {
586
+ className: styles.browser,
587
+ api: mediasApi,
588
+ value: value,
589
+ theme: "dark",
590
+ types: finalTypes,
591
+ query: finalQuery,
592
+ items: initialMedias,
593
+ filters: finalFilters,
594
+ fields: fields,
595
+ columns: columns,
596
+ uppyConfig: uppyConfig,
597
+ onMediaUploaded: onMediaUploaded,
598
+ withStickySelection: true,
599
+ withTrash: true
600
+ }));
601
+ }
602
+ MediaGallery.propTypes = propTypes;
603
+ MediaGallery.defaultProps = defaultProps;
604
+
605
+ export { MediaGallery as default };
package/lib/index.js ADDED
@@ -0,0 +1,645 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
+ var classNames = require('classnames');
7
+ var isArray = require('lodash/isArray');
8
+ var PropTypes = require('prop-types');
9
+ var React = require('react');
10
+ var medias = require('@panneau/medias');
11
+ var core = require('@micromag/core');
12
+ var contexts = require('@micromag/core/contexts');
13
+ var data = require('@micromag/data');
14
+ var reactIntl = require('react-intl');
15
+ var pathToRegexp = require('path-to-regexp');
16
+
17
+ var defaultColumns = [{
18
+ id: 'image',
19
+ label: null,
20
+ component: 'image',
21
+ path: 'thumbnail_url',
22
+ sortable: false
23
+ }, {
24
+ id: 'name',
25
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
26
+ id: "WX83V9",
27
+ defaultMessage: [{
28
+ "type": 0,
29
+ "value": "File name"
30
+ }]
31
+ }),
32
+ component: 'text-description',
33
+ path: 'name',
34
+ descriptionPath: 'type',
35
+ descriptionValues: {
36
+ image: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
37
+ id: "AwDQvD",
38
+ defaultMessage: [{
39
+ "type": 0,
40
+ "value": "Image"
41
+ }]
42
+ }),
43
+ video: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
44
+ id: "mQiyAm",
45
+ defaultMessage: [{
46
+ "type": 0,
47
+ "value": "Video"
48
+ }]
49
+ }),
50
+ audio: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
51
+ id: "XnyI69",
52
+ defaultMessage: [{
53
+ "type": 0,
54
+ "value": "Audio"
55
+ }]
56
+ }),
57
+ document: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
58
+ id: "1dqmFw",
59
+ defaultMessage: [{
60
+ "type": 0,
61
+ "value": "Document"
62
+ }]
63
+ })
64
+ },
65
+ sortable: true
66
+ }, {
67
+ id: 'dimensions',
68
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
69
+ id: "eCe9ZY",
70
+ defaultMessage: [{
71
+ "type": 0,
72
+ "value": "Dimensions"
73
+ }]
74
+ }),
75
+ component: 'unit',
76
+ format: 'dimensions',
77
+ path: 'metadata'
78
+ }, {
79
+ id: 'size',
80
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
81
+ id: "c3hu9o",
82
+ defaultMessage: [{
83
+ "type": 0,
84
+ "value": "Size"
85
+ }]
86
+ }),
87
+ component: 'unit',
88
+ format: 'bytes',
89
+ path: 'metadata.size'
90
+ }, {
91
+ id: 'duration',
92
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
93
+ id: "002oWQ",
94
+ defaultMessage: [{
95
+ "type": 0,
96
+ "value": "Duration"
97
+ }]
98
+ }),
99
+ component: 'unit',
100
+ format: 'duration',
101
+ path: 'metadata.duration'
102
+ },
103
+ // {
104
+ // id: 'author',
105
+ // label: <FormattedMessage defaultMessage="Added by" description="Field name" />,
106
+ // component: 'avatar',
107
+ // path: 'metadata.author',
108
+ // namePath: 'name',
109
+ // withoutName: true,
110
+ // },
111
+ {
112
+ id: 'created_at',
113
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
114
+ id: "OzYWZz",
115
+ defaultMessage: [{
116
+ "type": 0,
117
+ "value": "Created at"
118
+ }]
119
+ }),
120
+ component: 'date',
121
+ path: 'created_at',
122
+ format: 'yyyy-MM-dd hh:ss',
123
+ sortable: true
124
+ }, {
125
+ id: 'actions',
126
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
127
+ id: "rtwfuZ",
128
+ defaultMessage: [{
129
+ "type": 0,
130
+ "value": "Actions"
131
+ }]
132
+ }),
133
+ actions: ['edit', 'delete']
134
+ // component: ItemActions,
135
+ // label: 'Edit',
136
+ // url: '/edit/1',
137
+ }
138
+ // {
139
+ // id: 'status',
140
+ // label: <FormattedMessage defaultMessage="Status" description="Field name" />,
141
+ // component: 'text',
142
+ // path: 'metadata.status',
143
+ // },
144
+ ];
145
+
146
+ var defaultFields = [{
147
+ name: 'name',
148
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
149
+ id: "WX83V9",
150
+ defaultMessage: [{
151
+ "type": 0,
152
+ "value": "File name"
153
+ }]
154
+ }),
155
+ type: 'text',
156
+ component: 'text'
157
+ }, {
158
+ id: 'metadata',
159
+ component: 'fields',
160
+ name: 'metadata',
161
+ fields: [{
162
+ name: 'description',
163
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
164
+ id: "ygNvmz",
165
+ defaultMessage: [{
166
+ "type": 0,
167
+ "value": "Description"
168
+ }]
169
+ }),
170
+ type: 'text',
171
+ component: 'text'
172
+ }, {
173
+ name: 'tags',
174
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
175
+ id: "IOVper",
176
+ defaultMessage: [{
177
+ "type": 0,
178
+ "value": "Tags"
179
+ }]
180
+ }),
181
+ type: 'array',
182
+ component: 'select',
183
+ requestUrl: '/api/medias/tags',
184
+ optionLabelPath: 'name',
185
+ optionValuePath: 'id',
186
+ // Uses taggable so change the logic here
187
+ valueIsOption: true,
188
+ multiple: true,
189
+ paginated: false
190
+ // creatable: true, // TODO
191
+ }]
192
+ }, {
193
+ id: 'info',
194
+ component: 'fields',
195
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
196
+ id: "3RT69u",
197
+ defaultMessage: [{
198
+ "type": 0,
199
+ "value": "Informations"
200
+ }]
201
+ }),
202
+ isList: true,
203
+ hideWithoutValue: true,
204
+ fields: [{
205
+ id: 'user',
206
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
207
+ id: "yByaBh",
208
+ defaultMessage: [{
209
+ "type": 0,
210
+ "value": "Added by"
211
+ }]
212
+ }),
213
+ type: 'display',
214
+ display: 'avatar',
215
+ name: 'user',
216
+ horizontal: true
217
+ }, {
218
+ id: 'created_at',
219
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
220
+ id: "PN+75e",
221
+ defaultMessage: [{
222
+ "type": 0,
223
+ "value": "Created at"
224
+ }]
225
+ }),
226
+ type: 'display',
227
+ display: 'date',
228
+ name: 'created_at',
229
+ format: 'yyyy-MM-dd hh:ss',
230
+ horizontal: true
231
+ }]
232
+ }, {
233
+ id: 'technical',
234
+ component: 'fields',
235
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
236
+ id: "xKUOLG",
237
+ defaultMessage: [{
238
+ "type": 0,
239
+ "value": "Technical details"
240
+ }]
241
+ }),
242
+ isList: true,
243
+ hideWithoutValue: true,
244
+ fields: [{
245
+ id: 'format',
246
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
247
+ id: "JuxiUN",
248
+ defaultMessage: [{
249
+ "type": 0,
250
+ "value": "Format"
251
+ }]
252
+ }),
253
+ type: 'display',
254
+ display: 'unit',
255
+ format: 'format',
256
+ name: 'format',
257
+ horizontal: true
258
+ }, {
259
+ id: 'dimensions',
260
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
261
+ id: "rmJBin",
262
+ defaultMessage: [{
263
+ "type": 0,
264
+ "value": "Dimensions"
265
+ }]
266
+ }),
267
+ type: 'display',
268
+ display: 'unit',
269
+ format: 'dimensions',
270
+ name: 'metadata',
271
+ horizontal: true
272
+ }, {
273
+ id: 'size',
274
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
275
+ id: "g2CRt5",
276
+ defaultMessage: [{
277
+ "type": 0,
278
+ "value": "Size"
279
+ }]
280
+ }),
281
+ type: 'display',
282
+ display: 'unit',
283
+ format: 'bytes',
284
+ name: 'metadata.size',
285
+ horizontal: true
286
+ }, {
287
+ id: 'duration',
288
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
289
+ id: "wU++NJ",
290
+ defaultMessage: [{
291
+ "type": 0,
292
+ "value": "Duration"
293
+ }]
294
+ }),
295
+ type: 'display',
296
+ display: 'unit',
297
+ format: 'duration',
298
+ name: 'metadata.duration',
299
+ horizontal: true
300
+ }]
301
+ }];
302
+
303
+ /* eslint-disable react/jsx-props-no-spreading */
304
+ var RoutesContext = /*#__PURE__*/React.createContext(null);
305
+ var useRoutesContext = function useRoutesContext() {
306
+ return React.useContext(RoutesContext);
307
+ };
308
+ ({
309
+ children: PropTypes.node.isRequired,
310
+ routes: PropTypes.objectOf(PropTypes.string).isRequired,
311
+ basePath: PropTypes.string
312
+ });
313
+ var compilers = {};
314
+ function generatePath(fullPath, data) {
315
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
316
+ var fullUrlMatches = fullPath.match(/^(https?:\/\/)/);
317
+ if (typeof compilers[fullPath] === 'undefined') {
318
+ compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/)/, ''), opts);
319
+ }
320
+ var compiler = compilers[fullPath];
321
+ return fullUrlMatches !== null ? "".concat(fullUrlMatches[1]).concat(compiler(data)) : compiler(data);
322
+ }
323
+ var useUrlGeneratorPathToRepexp = function useUrlGeneratorPathToRepexp() {
324
+ var _ref2 = useRoutesContext() || {},
325
+ _ref2$routes = _ref2.routes,
326
+ routes = _ref2$routes === void 0 ? null : _ref2$routes,
327
+ _ref2$basePath = _ref2.basePath,
328
+ basePath = _ref2$basePath === void 0 ? null : _ref2$basePath;
329
+ var urlGenerator = React.useCallback(function (key, data, opts) {
330
+ var path = routes !== null ? routes[key] || null : null;
331
+ if (path === null) {
332
+ return null;
333
+ }
334
+ var url = generatePath(path, data, opts);
335
+ return basePath !== null ? "".concat(basePath.replace(/\/$/, ''), "/").concat(url.replace(/^\//, '')) : url;
336
+ }, [routes, basePath]);
337
+ return urlGenerator;
338
+ };
339
+ var useUrlGeneratorPathToRegexp = useUrlGeneratorPathToRepexp;
340
+
341
+ function filters() {
342
+ var route = useUrlGeneratorPathToRegexp();
343
+ return [{
344
+ id: 'search',
345
+ component: 'search',
346
+ name: 'search',
347
+ width: 152
348
+ }, {
349
+ id: 'types',
350
+ component: 'select',
351
+ name: 'types',
352
+ placeholder: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
353
+ id: "9/t5wK",
354
+ defaultMessage: [{
355
+ "type": 0,
356
+ "value": "Type"
357
+ }]
358
+ }),
359
+ options: [{
360
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
361
+ id: "yHAmDD",
362
+ defaultMessage: [{
363
+ "type": 0,
364
+ "value": "Image"
365
+ }]
366
+ }),
367
+ value: 'image'
368
+ }, {
369
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
370
+ id: "xSERPA",
371
+ defaultMessage: [{
372
+ "type": 0,
373
+ "value": "Video"
374
+ }]
375
+ }),
376
+ value: 'video'
377
+ }, {
378
+ label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
379
+ id: "yQRtgx",
380
+ defaultMessage: [{
381
+ "type": 0,
382
+ "value": "Audio"
383
+ }]
384
+ }),
385
+ value: 'audio'
386
+ }],
387
+ multiple: true
388
+ }, {
389
+ id: 'authors',
390
+ component: 'select',
391
+ name: 'authors',
392
+ placeholder: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
393
+ id: "7oXkoj",
394
+ defaultMessage: [{
395
+ "type": 0,
396
+ "value": "Authors"
397
+ }]
398
+ }),
399
+ requestUrl: route('medias.authors') || '/medias/authors',
400
+ itemLabelPath: 'name',
401
+ itemValuePath: 'id',
402
+ multiple: true,
403
+ paginated: false
404
+ }, {
405
+ id: 'tags',
406
+ component: 'select',
407
+ name: 'tags',
408
+ placeholder: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
409
+ id: "9mXl24",
410
+ defaultMessage: [{
411
+ "type": 0,
412
+ "value": "Tags"
413
+ }]
414
+ }),
415
+ requestUrl: route('medias.tags') || '/medias/tags',
416
+ itemLabelPath: 'name',
417
+ itemValuePath: 'id',
418
+ multiple: true,
419
+ paginated: false
420
+ }, {
421
+ id: 'source',
422
+ component: 'radios',
423
+ name: 'source',
424
+ options: [{
425
+ label: 'Tous les micromags',
426
+ value: 'all'
427
+ }, {
428
+ label: 'Ce micromag',
429
+ value: 'document-'
430
+ }]
431
+ }];
432
+ }
433
+
434
+ var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
435
+
436
+ var propTypes = {
437
+ value: PropTypes.shape({
438
+ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
439
+ }),
440
+ types: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
441
+ source: PropTypes.string,
442
+ filters: PropTypes.arrayOf(PropTypes.shape({
443
+ id: PropTypes.string
444
+ })),
445
+ fields: PropTypes.arrayOf(PropTypes.shape({
446
+ id: PropTypes.string
447
+ })),
448
+ columns: PropTypes.arrayOf(PropTypes.shape({
449
+ id: PropTypes.string
450
+ })),
451
+ isPicker: PropTypes.bool,
452
+ multiple: PropTypes.bool,
453
+ medias: core.PropTypes.medias,
454
+ onChange: PropTypes.func,
455
+ onMediaFormOpen: PropTypes.func,
456
+ onMediaFormClose: PropTypes.func,
457
+ className: PropTypes.string
458
+ };
459
+ var defaultProps = {
460
+ value: null,
461
+ types: null,
462
+ source: 'all',
463
+ filters: null,
464
+ fields: defaultFields,
465
+ columns: defaultColumns,
466
+ isPicker: false,
467
+ multiple: false,
468
+ medias: null,
469
+ onChange: null,
470
+ onMediaFormOpen: null,
471
+ onMediaFormClose: null,
472
+ className: null
473
+ };
474
+ function MediaGallery(_ref) {
475
+ var value = _ref.value,
476
+ types = _ref.types,
477
+ source = _ref.source,
478
+ filters$1 = _ref.filters,
479
+ fields = _ref.fields,
480
+ columns = _ref.columns,
481
+ isPicker = _ref.isPicker,
482
+ multiple = _ref.multiple,
483
+ initialMedias = _ref.medias,
484
+ onChange = _ref.onChange,
485
+ onMediaFormOpen = _ref.onMediaFormOpen,
486
+ onMediaFormClose = _ref.onMediaFormClose,
487
+ className = _ref.className;
488
+ var api = data.useApi();
489
+ var story = contexts.useStory();
490
+ var _ref2 = story || {},
491
+ _ref2$id = _ref2.id,
492
+ storyId = _ref2$id === void 0 ? null : _ref2$id;
493
+ var mediasApi = React.useMemo(function () {
494
+ return {
495
+ get: function get() {
496
+ var _api$medias;
497
+ return (_api$medias = api.medias).get.apply(_api$medias, arguments);
498
+ },
499
+ getTrashed: function getTrashed() {
500
+ var _api$medias2;
501
+ return (_api$medias2 = api.medias).getTrashed.apply(_api$medias2, arguments);
502
+ },
503
+ find: function find() {
504
+ var _api$medias3;
505
+ return (_api$medias3 = api.medias).find.apply(_api$medias3, arguments);
506
+ },
507
+ create: function create() {
508
+ var _api$medias4;
509
+ return (_api$medias4 = api.medias).create.apply(_api$medias4, arguments);
510
+ },
511
+ update: function update() {
512
+ var _api$medias5;
513
+ return (_api$medias5 = api.medias).update.apply(_api$medias5, arguments);
514
+ },
515
+ "delete": function _delete() {
516
+ var _api$medias6;
517
+ return (_api$medias6 = api.medias).forceDelete.apply(_api$medias6, arguments);
518
+ },
519
+ trash: function trash() {
520
+ var _api$medias7;
521
+ return (_api$medias7 = api.medias)["delete"].apply(_api$medias7, arguments);
522
+ }
523
+ };
524
+ }, [api]);
525
+
526
+ // Upload
527
+ var _useMediaCreate = data.useMediaCreate(),
528
+ createMedia = _useMediaCreate.create;
529
+ var onMediaUploaded = React.useCallback(function (newMedias) {
530
+ return Promise.all(newMedias.map(createMedia)).then(function (newAddedMedias) {
531
+ return newAddedMedias;
532
+ });
533
+ }, [createMedia]);
534
+ var fileTypes = React.useMemo(function () {
535
+ var finalTypes = [];
536
+ if (isArray(types)) {
537
+ finalTypes = types.map(function (t) {
538
+ return ['image', 'video', 'audio'].indexOf(t) !== -1 ? "".concat(t, "/*") : null;
539
+ }).filter(function (t) {
540
+ return t !== null;
541
+ });
542
+ }
543
+ finalTypes = ['image', 'video', 'audio'].indexOf(types) !== -1 ? ["".concat(types, "/*")] : null;
544
+ if (finalTypes !== null && isArray(finalTypes) && finalTypes.indexOf('video/*') !== -1) {
545
+ finalTypes.push('image/gif');
546
+ }
547
+ return finalTypes;
548
+ }, [types]);
549
+ var uppyConfig = React.useMemo(function () {
550
+ return {
551
+ // set sources ? - uppy sources -
552
+ allowedFileTypes: fileTypes !== null && fileTypes.length > 0 ? fileTypes : null
553
+ };
554
+ }, [fileTypes]);
555
+
556
+ // Filters
557
+ var partialFilters = filters$1 || filters() || [];
558
+ var finalFilters = React.useMemo(function () {
559
+ return partialFilters.map(function (filter) {
560
+ var _ref3 = filter || {},
561
+ _ref3$id = _ref3.id,
562
+ id = _ref3$id === void 0 ? null : _ref3$id,
563
+ _ref3$options = _ref3.options,
564
+ options = _ref3$options === void 0 ? [] : _ref3$options;
565
+ if (id === 'source') {
566
+ if (storyId === null) {
567
+ return null;
568
+ }
569
+ return _objectSpread(_objectSpread({}, filter), {}, {
570
+ options: (options || []).map(function () {
571
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
572
+ _ref4$value = _ref4.value,
573
+ optionValue = _ref4$value === void 0 ? null : _ref4$value,
574
+ _ref4$label = _ref4.label,
575
+ label = _ref4$label === void 0 ? null : _ref4$label;
576
+ return optionValue === 'document-' ? {
577
+ value: "document-".concat(storyId),
578
+ label: label
579
+ } : {
580
+ value: optionValue,
581
+ label: label
582
+ };
583
+ })
584
+ });
585
+ }
586
+ return filter;
587
+ }).filter(function (f) {
588
+ return f !== null;
589
+ });
590
+ }, [partialFilters, storyId]);
591
+ var _useState = React.useState(source !== null ? {
592
+ source: source
593
+ } : null),
594
+ _useState2 = _slicedToArray(_useState, 2),
595
+ query = _useState2[0],
596
+ setQuery = _useState2[1];
597
+ var finalQuery = React.useMemo(function () {
598
+ setQuery(_objectSpread(_objectSpread({}, query || null), source !== null ? {
599
+ source: source
600
+ } : null));
601
+ }, [source, setQuery]);
602
+ var finalTypes = React.useMemo(function () {
603
+ return !isArray(types) && types !== null ? [types] : types;
604
+ }, [types]);
605
+ return /*#__PURE__*/React.createElement("div", {
606
+ className: classNames([styles.container, _defineProperty({}, className, className)])
607
+ }, isPicker ? /*#__PURE__*/React.createElement(medias.MediasPickerContainer, {
608
+ className: styles.browser,
609
+ api: mediasApi,
610
+ value: value,
611
+ theme: "dark",
612
+ types: finalTypes,
613
+ query: finalQuery,
614
+ items: initialMedias,
615
+ filters: finalFilters,
616
+ fields: fields,
617
+ columns: columns,
618
+ multiple: multiple,
619
+ onChange: onChange,
620
+ uppyConfig: uppyConfig,
621
+ onMediaUploaded: onMediaUploaded,
622
+ onMediaFormOpen: onMediaFormOpen,
623
+ onMediaFormClose: onMediaFormClose,
624
+ withStickySelection: true
625
+ }) : /*#__PURE__*/React.createElement(medias.MediasBrowserContainer, {
626
+ className: styles.browser,
627
+ api: mediasApi,
628
+ value: value,
629
+ theme: "dark",
630
+ types: finalTypes,
631
+ query: finalQuery,
632
+ items: initialMedias,
633
+ filters: finalFilters,
634
+ fields: fields,
635
+ columns: columns,
636
+ uppyConfig: uppyConfig,
637
+ onMediaUploaded: onMediaUploaded,
638
+ withStickySelection: true,
639
+ withTrash: true
640
+ }));
641
+ }
642
+ MediaGallery.propTypes = propTypes;
643
+ MediaGallery.defaultProps = defaultProps;
644
+
645
+ module.exports = MediaGallery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/media-gallery",
3
- "version": "0.3.538",
3
+ "version": "0.3.540",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -87,5 +87,5 @@
87
87
  "access": "public",
88
88
  "registry": "https://registry.npmjs.org/"
89
89
  },
90
- "gitHead": "31e20c8dc474ddeace9c77115d6f6b3232588331"
90
+ "gitHead": "e29e691314fedb1f950c6d82f407954e225d813b"
91
91
  }