@micromag/media-gallery 0.3.536 → 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.536",
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": "92977b9414f2996d660d36931b4e6d0b36221f5f"
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,604 +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
- }]
189
- }, {
190
- id: 'info',
191
- component: 'fields',
192
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
193
- id: "3RT69u",
194
- defaultMessage: [{
195
- "type": 0,
196
- "value": "Informations"
197
- }]
198
- }),
199
- isList: true,
200
- hideWithoutValue: true,
201
- fields: [{
202
- id: 'user',
203
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
204
- id: "yByaBh",
205
- defaultMessage: [{
206
- "type": 0,
207
- "value": "Added by"
208
- }]
209
- }),
210
- type: 'display',
211
- display: 'avatar',
212
- name: 'user',
213
- horizontal: true
214
- }, {
215
- id: 'created_at',
216
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
217
- id: "PN+75e",
218
- defaultMessage: [{
219
- "type": 0,
220
- "value": "Created at"
221
- }]
222
- }),
223
- type: 'display',
224
- display: 'date',
225
- name: 'created_at',
226
- format: 'yyyy-MM-dd hh:ss',
227
- horizontal: true
228
- }]
229
- }, {
230
- id: 'technical',
231
- component: 'fields',
232
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
233
- id: "xKUOLG",
234
- defaultMessage: [{
235
- "type": 0,
236
- "value": "Technical details"
237
- }]
238
- }),
239
- isList: true,
240
- hideWithoutValue: true,
241
- fields: [{
242
- id: 'format',
243
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
244
- id: "JuxiUN",
245
- defaultMessage: [{
246
- "type": 0,
247
- "value": "Format"
248
- }]
249
- }),
250
- type: 'display',
251
- display: 'unit',
252
- format: 'format',
253
- name: 'format',
254
- horizontal: true
255
- }, {
256
- id: 'dimensions',
257
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
258
- id: "rmJBin",
259
- defaultMessage: [{
260
- "type": 0,
261
- "value": "Dimensions"
262
- }]
263
- }),
264
- type: 'display',
265
- display: 'unit',
266
- format: 'dimensions',
267
- name: 'metadata',
268
- horizontal: true
269
- }, {
270
- id: 'size',
271
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
272
- id: "g2CRt5",
273
- defaultMessage: [{
274
- "type": 0,
275
- "value": "Size"
276
- }]
277
- }),
278
- type: 'display',
279
- display: 'unit',
280
- format: 'bytes',
281
- name: 'metadata.size',
282
- horizontal: true
283
- }, {
284
- id: 'duration',
285
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
286
- id: "wU++NJ",
287
- defaultMessage: [{
288
- "type": 0,
289
- "value": "Duration"
290
- }]
291
- }),
292
- type: 'display',
293
- display: 'unit',
294
- format: 'duration',
295
- name: 'metadata.duration',
296
- horizontal: true
297
- }]
298
- }];
299
-
300
- function filters() {
301
- var route = useUrlGenerator();
302
- return [{
303
- id: 'search',
304
- component: 'search',
305
- name: 'search',
306
- width: 152
307
- }, {
308
- id: 'types',
309
- component: 'select',
310
- name: 'types',
311
- placeholder: /*#__PURE__*/React.createElement(FormattedMessage, {
312
- id: "9/t5wK",
313
- defaultMessage: [{
314
- "type": 0,
315
- "value": "Type"
316
- }]
317
- }),
318
- options: [{
319
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
320
- id: "yHAmDD",
321
- defaultMessage: [{
322
- "type": 0,
323
- "value": "Image"
324
- }]
325
- }),
326
- value: 'image'
327
- }, {
328
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
329
- id: "xSERPA",
330
- defaultMessage: [{
331
- "type": 0,
332
- "value": "Video"
333
- }]
334
- }),
335
- value: 'video'
336
- }, {
337
- label: /*#__PURE__*/React.createElement(FormattedMessage, {
338
- id: "yQRtgx",
339
- defaultMessage: [{
340
- "type": 0,
341
- "value": "Audio"
342
- }]
343
- }),
344
- value: 'audio'
345
- }],
346
- multiple: true
347
- }, {
348
- id: 'authors',
349
- component: 'select',
350
- name: 'authors',
351
- placeholder: /*#__PURE__*/React.createElement(FormattedMessage, {
352
- id: "7oXkoj",
353
- defaultMessage: [{
354
- "type": 0,
355
- "value": "Authors"
356
- }]
357
- }),
358
- requestUrl: route('medias.authors') || '/medias/authors',
359
- itemLabelPath: 'name',
360
- itemValuePath: 'id',
361
- multiple: true,
362
- paginated: false
363
- }, {
364
- id: 'tags',
365
- component: 'select',
366
- name: 'tags',
367
- placeholder: /*#__PURE__*/React.createElement(FormattedMessage, {
368
- id: "9mXl24",
369
- defaultMessage: [{
370
- "type": 0,
371
- "value": "Tags"
372
- }]
373
- }),
374
- requestUrl: route('medias.tags') || '/medias/tags',
375
- itemLabelPath: 'name',
376
- itemValuePath: 'id',
377
- multiple: true,
378
- paginated: false
379
- }, {
380
- id: 'source',
381
- component: 'radios',
382
- name: 'source',
383
- options: [{
384
- label: 'Tous les micromags',
385
- value: 'all'
386
- }, {
387
- label: 'Ce micromag',
388
- value: 'document-'
389
- }]
390
- }];
391
- }
392
-
393
- var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
394
-
395
- var propTypes = {
396
- value: PropTypes.shape({
397
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
398
- }),
399
- types: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
400
- source: PropTypes.string,
401
- filters: PropTypes.arrayOf(PropTypes.shape({
402
- id: PropTypes.string
403
- })),
404
- fields: PropTypes.arrayOf(PropTypes.shape({
405
- id: PropTypes.string
406
- })),
407
- columns: PropTypes.arrayOf(PropTypes.shape({
408
- id: PropTypes.string
409
- })),
410
- isPicker: PropTypes.bool,
411
- multiple: PropTypes.bool,
412
- medias: PropTypes$1.medias,
413
- onChange: PropTypes.func,
414
- onMediaFormOpen: PropTypes.func,
415
- onMediaFormClose: PropTypes.func,
416
- className: PropTypes.string
417
- };
418
- var defaultProps = {
419
- value: null,
420
- types: null,
421
- source: 'all',
422
- filters: null,
423
- fields: defaultFields,
424
- columns: defaultColumns,
425
- isPicker: false,
426
- multiple: false,
427
- medias: null,
428
- onChange: null,
429
- onMediaFormOpen: null,
430
- onMediaFormClose: null,
431
- className: null
432
- };
433
- function MediaGallery(_ref) {
434
- var value = _ref.value,
435
- types = _ref.types,
436
- source = _ref.source,
437
- filters$1 = _ref.filters,
438
- fields = _ref.fields,
439
- columns = _ref.columns,
440
- isPicker = _ref.isPicker,
441
- multiple = _ref.multiple,
442
- initialMedias = _ref.medias,
443
- onChange = _ref.onChange,
444
- onMediaFormOpen = _ref.onMediaFormOpen,
445
- onMediaFormClose = _ref.onMediaFormClose,
446
- className = _ref.className;
447
- var api = useApi();
448
- var story = useStory();
449
- var _ref2 = story || {},
450
- _ref2$id = _ref2.id,
451
- storyId = _ref2$id === void 0 ? null : _ref2$id;
452
- var mediasApi = useMemo(function () {
453
- return {
454
- get: function get() {
455
- var _api$medias;
456
- return (_api$medias = api.medias).get.apply(_api$medias, arguments);
457
- },
458
- getTrashed: function getTrashed() {
459
- var _api$medias2;
460
- return (_api$medias2 = api.medias).get.apply(_api$medias2, arguments);
461
- },
462
- // Change this
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)["delete"].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
- } // Change this
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
- }));
600
- }
601
- MediaGallery.propTypes = propTypes;
602
- MediaGallery.defaultProps = defaultProps;
603
-
604
- export { MediaGallery as default };
package/lib/index.js DELETED
@@ -1,644 +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
- }]
191
- }, {
192
- id: 'info',
193
- component: 'fields',
194
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
195
- id: "3RT69u",
196
- defaultMessage: [{
197
- "type": 0,
198
- "value": "Informations"
199
- }]
200
- }),
201
- isList: true,
202
- hideWithoutValue: true,
203
- fields: [{
204
- id: 'user',
205
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
206
- id: "yByaBh",
207
- defaultMessage: [{
208
- "type": 0,
209
- "value": "Added by"
210
- }]
211
- }),
212
- type: 'display',
213
- display: 'avatar',
214
- name: 'user',
215
- horizontal: true
216
- }, {
217
- id: 'created_at',
218
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
219
- id: "PN+75e",
220
- defaultMessage: [{
221
- "type": 0,
222
- "value": "Created at"
223
- }]
224
- }),
225
- type: 'display',
226
- display: 'date',
227
- name: 'created_at',
228
- format: 'yyyy-MM-dd hh:ss',
229
- horizontal: true
230
- }]
231
- }, {
232
- id: 'technical',
233
- component: 'fields',
234
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
235
- id: "xKUOLG",
236
- defaultMessage: [{
237
- "type": 0,
238
- "value": "Technical details"
239
- }]
240
- }),
241
- isList: true,
242
- hideWithoutValue: true,
243
- fields: [{
244
- id: 'format',
245
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
246
- id: "JuxiUN",
247
- defaultMessage: [{
248
- "type": 0,
249
- "value": "Format"
250
- }]
251
- }),
252
- type: 'display',
253
- display: 'unit',
254
- format: 'format',
255
- name: 'format',
256
- horizontal: true
257
- }, {
258
- id: 'dimensions',
259
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
260
- id: "rmJBin",
261
- defaultMessage: [{
262
- "type": 0,
263
- "value": "Dimensions"
264
- }]
265
- }),
266
- type: 'display',
267
- display: 'unit',
268
- format: 'dimensions',
269
- name: 'metadata',
270
- horizontal: true
271
- }, {
272
- id: 'size',
273
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
274
- id: "g2CRt5",
275
- defaultMessage: [{
276
- "type": 0,
277
- "value": "Size"
278
- }]
279
- }),
280
- type: 'display',
281
- display: 'unit',
282
- format: 'bytes',
283
- name: 'metadata.size',
284
- horizontal: true
285
- }, {
286
- id: 'duration',
287
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
288
- id: "wU++NJ",
289
- defaultMessage: [{
290
- "type": 0,
291
- "value": "Duration"
292
- }]
293
- }),
294
- type: 'display',
295
- display: 'unit',
296
- format: 'duration',
297
- name: 'metadata.duration',
298
- horizontal: true
299
- }]
300
- }];
301
-
302
- /* eslint-disable react/jsx-props-no-spreading */
303
- var RoutesContext = /*#__PURE__*/React.createContext(null);
304
- var useRoutesContext = function useRoutesContext() {
305
- return React.useContext(RoutesContext);
306
- };
307
- ({
308
- children: PropTypes.node.isRequired,
309
- routes: PropTypes.objectOf(PropTypes.string).isRequired,
310
- basePath: PropTypes.string
311
- });
312
- var compilers = {};
313
- function generatePath(fullPath, data) {
314
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
315
- var fullUrlMatches = fullPath.match(/^(https?:\/\/)/);
316
- if (typeof compilers[fullPath] === 'undefined') {
317
- compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/)/, ''), opts);
318
- }
319
- var compiler = compilers[fullPath];
320
- return fullUrlMatches !== null ? "".concat(fullUrlMatches[1]).concat(compiler(data)) : compiler(data);
321
- }
322
- var useUrlGeneratorPathToRepexp = function useUrlGeneratorPathToRepexp() {
323
- var _ref2 = useRoutesContext() || {},
324
- _ref2$routes = _ref2.routes,
325
- routes = _ref2$routes === void 0 ? null : _ref2$routes,
326
- _ref2$basePath = _ref2.basePath,
327
- basePath = _ref2$basePath === void 0 ? null : _ref2$basePath;
328
- var urlGenerator = React.useCallback(function (key, data, opts) {
329
- var path = routes !== null ? routes[key] || null : null;
330
- if (path === null) {
331
- return null;
332
- }
333
- var url = generatePath(path, data, opts);
334
- return basePath !== null ? "".concat(basePath.replace(/\/$/, ''), "/").concat(url.replace(/^\//, '')) : url;
335
- }, [routes, basePath]);
336
- return urlGenerator;
337
- };
338
- var useUrlGeneratorPathToRegexp = useUrlGeneratorPathToRepexp;
339
-
340
- function filters() {
341
- var route = useUrlGeneratorPathToRegexp();
342
- return [{
343
- id: 'search',
344
- component: 'search',
345
- name: 'search',
346
- width: 152
347
- }, {
348
- id: 'types',
349
- component: 'select',
350
- name: 'types',
351
- placeholder: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
352
- id: "9/t5wK",
353
- defaultMessage: [{
354
- "type": 0,
355
- "value": "Type"
356
- }]
357
- }),
358
- options: [{
359
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
360
- id: "yHAmDD",
361
- defaultMessage: [{
362
- "type": 0,
363
- "value": "Image"
364
- }]
365
- }),
366
- value: 'image'
367
- }, {
368
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
369
- id: "xSERPA",
370
- defaultMessage: [{
371
- "type": 0,
372
- "value": "Video"
373
- }]
374
- }),
375
- value: 'video'
376
- }, {
377
- label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
378
- id: "yQRtgx",
379
- defaultMessage: [{
380
- "type": 0,
381
- "value": "Audio"
382
- }]
383
- }),
384
- value: 'audio'
385
- }],
386
- multiple: true
387
- }, {
388
- id: 'authors',
389
- component: 'select',
390
- name: 'authors',
391
- placeholder: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
392
- id: "7oXkoj",
393
- defaultMessage: [{
394
- "type": 0,
395
- "value": "Authors"
396
- }]
397
- }),
398
- requestUrl: route('medias.authors') || '/medias/authors',
399
- itemLabelPath: 'name',
400
- itemValuePath: 'id',
401
- multiple: true,
402
- paginated: false
403
- }, {
404
- id: 'tags',
405
- component: 'select',
406
- name: 'tags',
407
- placeholder: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
408
- id: "9mXl24",
409
- defaultMessage: [{
410
- "type": 0,
411
- "value": "Tags"
412
- }]
413
- }),
414
- requestUrl: route('medias.tags') || '/medias/tags',
415
- itemLabelPath: 'name',
416
- itemValuePath: 'id',
417
- multiple: true,
418
- paginated: false
419
- }, {
420
- id: 'source',
421
- component: 'radios',
422
- name: 'source',
423
- options: [{
424
- label: 'Tous les micromags',
425
- value: 'all'
426
- }, {
427
- label: 'Ce micromag',
428
- value: 'document-'
429
- }]
430
- }];
431
- }
432
-
433
- var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
434
-
435
- var propTypes = {
436
- value: PropTypes.shape({
437
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
438
- }),
439
- types: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
440
- source: PropTypes.string,
441
- filters: PropTypes.arrayOf(PropTypes.shape({
442
- id: PropTypes.string
443
- })),
444
- fields: PropTypes.arrayOf(PropTypes.shape({
445
- id: PropTypes.string
446
- })),
447
- columns: PropTypes.arrayOf(PropTypes.shape({
448
- id: PropTypes.string
449
- })),
450
- isPicker: PropTypes.bool,
451
- multiple: PropTypes.bool,
452
- medias: core.PropTypes.medias,
453
- onChange: PropTypes.func,
454
- onMediaFormOpen: PropTypes.func,
455
- onMediaFormClose: PropTypes.func,
456
- className: PropTypes.string
457
- };
458
- var defaultProps = {
459
- value: null,
460
- types: null,
461
- source: 'all',
462
- filters: null,
463
- fields: defaultFields,
464
- columns: defaultColumns,
465
- isPicker: false,
466
- multiple: false,
467
- medias: null,
468
- onChange: null,
469
- onMediaFormOpen: null,
470
- onMediaFormClose: null,
471
- className: null
472
- };
473
- function MediaGallery(_ref) {
474
- var value = _ref.value,
475
- types = _ref.types,
476
- source = _ref.source,
477
- filters$1 = _ref.filters,
478
- fields = _ref.fields,
479
- columns = _ref.columns,
480
- isPicker = _ref.isPicker,
481
- multiple = _ref.multiple,
482
- initialMedias = _ref.medias,
483
- onChange = _ref.onChange,
484
- onMediaFormOpen = _ref.onMediaFormOpen,
485
- onMediaFormClose = _ref.onMediaFormClose,
486
- className = _ref.className;
487
- var api = data.useApi();
488
- var story = contexts.useStory();
489
- var _ref2 = story || {},
490
- _ref2$id = _ref2.id,
491
- storyId = _ref2$id === void 0 ? null : _ref2$id;
492
- var mediasApi = React.useMemo(function () {
493
- return {
494
- get: function get() {
495
- var _api$medias;
496
- return (_api$medias = api.medias).get.apply(_api$medias, arguments);
497
- },
498
- getTrashed: function getTrashed() {
499
- var _api$medias2;
500
- return (_api$medias2 = api.medias).get.apply(_api$medias2, arguments);
501
- },
502
- // Change this
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)["delete"].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
- } // Change this
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
- }));
640
- }
641
- MediaGallery.propTypes = propTypes;
642
- MediaGallery.defaultProps = defaultProps;
643
-
644
- module.exports = MediaGallery;