@micromag/media-gallery 0.3.537 → 0.3.538

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/media-gallery",
3
- "version": "0.3.537",
3
+ "version": "0.3.538",
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": "d00efc1e19154f3ea19bfdb64ab47a794f74731e"
90
+ "gitHead": "31e20c8dc474ddeace9c77115d6f6b3232588331"
91
91
  }
@@ -1 +0,0 @@
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 DELETED
@@ -1,605 +0,0 @@
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).get.apply(_api$medias2, arguments);
462
- },
463
- // Change this
464
- find: function find() {
465
- var _api$medias3;
466
- return (_api$medias3 = api.medias).find.apply(_api$medias3, arguments);
467
- },
468
- create: function create() {
469
- var _api$medias4;
470
- return (_api$medias4 = api.medias).create.apply(_api$medias4, arguments);
471
- },
472
- update: function update() {
473
- var _api$medias5;
474
- return (_api$medias5 = api.medias).update.apply(_api$medias5, arguments);
475
- },
476
- "delete": function _delete() {
477
- var _api$medias6;
478
- return (_api$medias6 = api.medias)["delete"].apply(_api$medias6, arguments);
479
- },
480
- trash: function trash() {
481
- var _api$medias7;
482
- return (_api$medias7 = api.medias)["delete"].apply(_api$medias7, arguments);
483
- } // Change this
484
- };
485
- }, [api]);
486
-
487
- // Upload
488
- var _useMediaCreate = useMediaCreate(),
489
- createMedia = _useMediaCreate.create;
490
- var onMediaUploaded = useCallback(function (newMedias) {
491
- return Promise.all(newMedias.map(createMedia)).then(function (newAddedMedias) {
492
- return newAddedMedias;
493
- });
494
- }, [createMedia]);
495
- var fileTypes = useMemo(function () {
496
- var finalTypes = [];
497
- if (isArray(types)) {
498
- finalTypes = types.map(function (t) {
499
- return ['image', 'video', 'audio'].indexOf(t) !== -1 ? "".concat(t, "/*") : null;
500
- }).filter(function (t) {
501
- return t !== null;
502
- });
503
- }
504
- finalTypes = ['image', 'video', 'audio'].indexOf(types) !== -1 ? ["".concat(types, "/*")] : null;
505
- if (finalTypes !== null && isArray(finalTypes) && finalTypes.indexOf('video/*') !== -1) {
506
- finalTypes.push('image/gif');
507
- }
508
- return finalTypes;
509
- }, [types]);
510
- var uppyConfig = useMemo(function () {
511
- return {
512
- // set sources ? - uppy sources -
513
- allowedFileTypes: fileTypes !== null && fileTypes.length > 0 ? fileTypes : null
514
- };
515
- }, [fileTypes]);
516
-
517
- // Filters
518
- var partialFilters = filters$1 || filters() || [];
519
- var finalFilters = useMemo(function () {
520
- return partialFilters.map(function (filter) {
521
- var _ref3 = filter || {},
522
- _ref3$id = _ref3.id,
523
- id = _ref3$id === void 0 ? null : _ref3$id,
524
- _ref3$options = _ref3.options,
525
- options = _ref3$options === void 0 ? [] : _ref3$options;
526
- if (id === 'source') {
527
- if (storyId === null) {
528
- return null;
529
- }
530
- return _objectSpread(_objectSpread({}, filter), {}, {
531
- options: (options || []).map(function () {
532
- var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
533
- _ref4$value = _ref4.value,
534
- optionValue = _ref4$value === void 0 ? null : _ref4$value,
535
- _ref4$label = _ref4.label,
536
- label = _ref4$label === void 0 ? null : _ref4$label;
537
- return optionValue === 'document-' ? {
538
- value: "document-".concat(storyId),
539
- label: label
540
- } : {
541
- value: optionValue,
542
- label: label
543
- };
544
- })
545
- });
546
- }
547
- return filter;
548
- }).filter(function (f) {
549
- return f !== null;
550
- });
551
- }, [partialFilters, storyId]);
552
- var _useState = useState(source !== null ? {
553
- source: source
554
- } : null),
555
- _useState2 = _slicedToArray(_useState, 2),
556
- query = _useState2[0],
557
- setQuery = _useState2[1];
558
- var finalQuery = useMemo(function () {
559
- setQuery(_objectSpread(_objectSpread({}, query || null), source !== null ? {
560
- source: source
561
- } : null));
562
- }, [source, setQuery]);
563
- var finalTypes = useMemo(function () {
564
- return !isArray(types) && types !== null ? [types] : types;
565
- }, [types]);
566
- return /*#__PURE__*/React.createElement("div", {
567
- className: classNames([styles.container, _defineProperty({}, className, className)])
568
- }, isPicker ? /*#__PURE__*/React.createElement(MediasPickerContainer, {
569
- className: styles.browser,
570
- api: mediasApi,
571
- value: value,
572
- theme: "dark",
573
- types: finalTypes,
574
- query: finalQuery,
575
- items: initialMedias,
576
- filters: finalFilters,
577
- fields: fields,
578
- columns: columns,
579
- multiple: multiple,
580
- onChange: onChange,
581
- uppyConfig: uppyConfig,
582
- onMediaUploaded: onMediaUploaded,
583
- onMediaFormOpen: onMediaFormOpen,
584
- onMediaFormClose: onMediaFormClose,
585
- withStickySelection: true
586
- }) : /*#__PURE__*/React.createElement(MediasBrowserContainer, {
587
- className: styles.browser,
588
- api: mediasApi,
589
- value: value,
590
- theme: "dark",
591
- types: finalTypes,
592
- query: finalQuery,
593
- items: initialMedias,
594
- filters: finalFilters,
595
- fields: fields,
596
- columns: columns,
597
- uppyConfig: uppyConfig,
598
- onMediaUploaded: onMediaUploaded,
599
- withStickySelection: true
600
- }));
601
- }
602
- MediaGallery.propTypes = propTypes;
603
- MediaGallery.defaultProps = defaultProps;
604
-
605
- export { MediaGallery as default };
package/lib/index.js DELETED
@@ -1,645 +0,0 @@
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).get.apply(_api$medias2, arguments);
502
- },
503
- // Change this
504
- find: function find() {
505
- var _api$medias3;
506
- return (_api$medias3 = api.medias).find.apply(_api$medias3, arguments);
507
- },
508
- create: function create() {
509
- var _api$medias4;
510
- return (_api$medias4 = api.medias).create.apply(_api$medias4, arguments);
511
- },
512
- update: function update() {
513
- var _api$medias5;
514
- return (_api$medias5 = api.medias).update.apply(_api$medias5, arguments);
515
- },
516
- "delete": function _delete() {
517
- var _api$medias6;
518
- return (_api$medias6 = api.medias)["delete"].apply(_api$medias6, arguments);
519
- },
520
- trash: function trash() {
521
- var _api$medias7;
522
- return (_api$medias7 = api.medias)["delete"].apply(_api$medias7, arguments);
523
- } // Change this
524
- };
525
- }, [api]);
526
-
527
- // Upload
528
- var _useMediaCreate = data.useMediaCreate(),
529
- createMedia = _useMediaCreate.create;
530
- var onMediaUploaded = React.useCallback(function (newMedias) {
531
- return Promise.all(newMedias.map(createMedia)).then(function (newAddedMedias) {
532
- return newAddedMedias;
533
- });
534
- }, [createMedia]);
535
- var fileTypes = React.useMemo(function () {
536
- var finalTypes = [];
537
- if (isArray(types)) {
538
- finalTypes = types.map(function (t) {
539
- return ['image', 'video', 'audio'].indexOf(t) !== -1 ? "".concat(t, "/*") : null;
540
- }).filter(function (t) {
541
- return t !== null;
542
- });
543
- }
544
- finalTypes = ['image', 'video', 'audio'].indexOf(types) !== -1 ? ["".concat(types, "/*")] : null;
545
- if (finalTypes !== null && isArray(finalTypes) && finalTypes.indexOf('video/*') !== -1) {
546
- finalTypes.push('image/gif');
547
- }
548
- return finalTypes;
549
- }, [types]);
550
- var uppyConfig = React.useMemo(function () {
551
- return {
552
- // set sources ? - uppy sources -
553
- allowedFileTypes: fileTypes !== null && fileTypes.length > 0 ? fileTypes : null
554
- };
555
- }, [fileTypes]);
556
-
557
- // Filters
558
- var partialFilters = filters$1 || filters() || [];
559
- var finalFilters = React.useMemo(function () {
560
- return partialFilters.map(function (filter) {
561
- var _ref3 = filter || {},
562
- _ref3$id = _ref3.id,
563
- id = _ref3$id === void 0 ? null : _ref3$id,
564
- _ref3$options = _ref3.options,
565
- options = _ref3$options === void 0 ? [] : _ref3$options;
566
- if (id === 'source') {
567
- if (storyId === null) {
568
- return null;
569
- }
570
- return _objectSpread(_objectSpread({}, filter), {}, {
571
- options: (options || []).map(function () {
572
- var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
573
- _ref4$value = _ref4.value,
574
- optionValue = _ref4$value === void 0 ? null : _ref4$value,
575
- _ref4$label = _ref4.label,
576
- label = _ref4$label === void 0 ? null : _ref4$label;
577
- return optionValue === 'document-' ? {
578
- value: "document-".concat(storyId),
579
- label: label
580
- } : {
581
- value: optionValue,
582
- label: label
583
- };
584
- })
585
- });
586
- }
587
- return filter;
588
- }).filter(function (f) {
589
- return f !== null;
590
- });
591
- }, [partialFilters, storyId]);
592
- var _useState = React.useState(source !== null ? {
593
- source: source
594
- } : null),
595
- _useState2 = _slicedToArray(_useState, 2),
596
- query = _useState2[0],
597
- setQuery = _useState2[1];
598
- var finalQuery = React.useMemo(function () {
599
- setQuery(_objectSpread(_objectSpread({}, query || null), source !== null ? {
600
- source: source
601
- } : null));
602
- }, [source, setQuery]);
603
- var finalTypes = React.useMemo(function () {
604
- return !isArray(types) && types !== null ? [types] : types;
605
- }, [types]);
606
- return /*#__PURE__*/React.createElement("div", {
607
- className: classNames([styles.container, _defineProperty({}, className, className)])
608
- }, isPicker ? /*#__PURE__*/React.createElement(medias.MediasPickerContainer, {
609
- className: styles.browser,
610
- api: mediasApi,
611
- value: value,
612
- theme: "dark",
613
- types: finalTypes,
614
- query: finalQuery,
615
- items: initialMedias,
616
- filters: finalFilters,
617
- fields: fields,
618
- columns: columns,
619
- multiple: multiple,
620
- onChange: onChange,
621
- uppyConfig: uppyConfig,
622
- onMediaUploaded: onMediaUploaded,
623
- onMediaFormOpen: onMediaFormOpen,
624
- onMediaFormClose: onMediaFormClose,
625
- withStickySelection: true
626
- }) : /*#__PURE__*/React.createElement(medias.MediasBrowserContainer, {
627
- className: styles.browser,
628
- api: mediasApi,
629
- value: value,
630
- theme: "dark",
631
- types: finalTypes,
632
- query: finalQuery,
633
- items: initialMedias,
634
- filters: finalFilters,
635
- fields: fields,
636
- columns: columns,
637
- uppyConfig: uppyConfig,
638
- onMediaUploaded: onMediaUploaded,
639
- withStickySelection: true
640
- }));
641
- }
642
- MediaGallery.propTypes = propTypes;
643
- MediaGallery.defaultProps = defaultProps;
644
-
645
- module.exports = MediaGallery;