@micromag/media-gallery 0.3.510 → 0.3.514
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/es/index.js +69 -25
- package/lib/index.js +69 -25
- package/package.json +4 -4
package/es/index.js
CHANGED
|
@@ -7,22 +7,16 @@ import isArray from 'lodash/isArray';
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import React, { useMemo, useState, useCallback } from 'react';
|
|
9
9
|
import { createPortal } from 'react-dom';
|
|
10
|
+
import { FormattedMessage } from 'react-intl';
|
|
10
11
|
import { MediasPickerContainer, MediasBrowserContainer } from '@panneau/medias';
|
|
11
12
|
import { PropTypes as PropTypes$1 } from '@micromag/core';
|
|
12
13
|
import { UploadModal } from '@micromag/core/components';
|
|
13
14
|
import { useApi, useMediaCreate } from '@micromag/data';
|
|
14
|
-
import { FormattedMessage } from 'react-intl';
|
|
15
15
|
import { useUrlGenerator } from '@folklore/routes';
|
|
16
16
|
|
|
17
17
|
var defaultColumns = [{
|
|
18
18
|
id: 'image',
|
|
19
|
-
label:
|
|
20
|
-
id: "UbxbKP",
|
|
21
|
-
defaultMessage: [{
|
|
22
|
-
"type": 0,
|
|
23
|
-
"value": "Preview"
|
|
24
|
-
}]
|
|
25
|
-
}),
|
|
19
|
+
label: null,
|
|
26
20
|
component: 'image',
|
|
27
21
|
path: 'thumbnail_url',
|
|
28
22
|
sortable: false
|
|
@@ -171,6 +165,29 @@ var defaultFields = [{
|
|
|
171
165
|
}),
|
|
172
166
|
type: 'text',
|
|
173
167
|
component: 'text'
|
|
168
|
+
}, {
|
|
169
|
+
name: 'tags',
|
|
170
|
+
label: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
171
|
+
id: "IOVper",
|
|
172
|
+
defaultMessage: [{
|
|
173
|
+
"type": 0,
|
|
174
|
+
"value": "Tags"
|
|
175
|
+
}]
|
|
176
|
+
}),
|
|
177
|
+
type: 'array',
|
|
178
|
+
component: 'select'
|
|
179
|
+
// requestUrl: route('medias.tags') || '/api/medias/tags',
|
|
180
|
+
// itemLabelPath: 'name',
|
|
181
|
+
}, {
|
|
182
|
+
id: 'custom_field',
|
|
183
|
+
component: 'custom_field',
|
|
184
|
+
label: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
185
|
+
id: "BjSp56",
|
|
186
|
+
defaultMessage: [{
|
|
187
|
+
"type": 0,
|
|
188
|
+
"value": "Test custom field"
|
|
189
|
+
}]
|
|
190
|
+
})
|
|
174
191
|
}, {
|
|
175
192
|
id: 'info',
|
|
176
193
|
component: 'fields',
|
|
@@ -356,7 +373,7 @@ function filters() {
|
|
|
356
373
|
"value": "This micromag"
|
|
357
374
|
}]
|
|
358
375
|
}),
|
|
359
|
-
value: 'document-
|
|
376
|
+
value: 'document-'
|
|
360
377
|
}]
|
|
361
378
|
}, {
|
|
362
379
|
id: 'authors',
|
|
@@ -394,8 +411,7 @@ function filters() {
|
|
|
394
411
|
|
|
395
412
|
var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
|
|
396
413
|
|
|
397
|
-
|
|
398
|
-
|
|
414
|
+
var videoTypes = ['video', 'image/gif'];
|
|
399
415
|
var propTypes = {
|
|
400
416
|
value: PropTypes.shape({
|
|
401
417
|
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
@@ -441,9 +457,9 @@ function MediaGallery(_ref) {
|
|
|
441
457
|
columns = _ref.columns,
|
|
442
458
|
isPicker = _ref.isPicker,
|
|
443
459
|
multiple = _ref.multiple,
|
|
444
|
-
initialMedias = _ref.medias
|
|
445
|
-
|
|
446
|
-
className = _ref.className,
|
|
460
|
+
initialMedias = _ref.medias;
|
|
461
|
+
_ref.buttons;
|
|
462
|
+
var className = _ref.className,
|
|
447
463
|
onChange = _ref.onChange;
|
|
448
464
|
var api = useApi();
|
|
449
465
|
var mediasApi = useMemo(function () {
|
|
@@ -485,14 +501,14 @@ function MediaGallery(_ref) {
|
|
|
485
501
|
addedMedias = _useState2[0],
|
|
486
502
|
setAddedMedias = _useState2[1];
|
|
487
503
|
var _useState3 = useState(false),
|
|
488
|
-
_useState4 = _slicedToArray(_useState3, 2)
|
|
489
|
-
_useState4[0]
|
|
490
|
-
|
|
504
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
505
|
+
uploading = _useState4[0],
|
|
506
|
+
setUploading = _useState4[1];
|
|
491
507
|
var _useState5 = useState(false),
|
|
492
508
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
493
509
|
uploadModalOpened = _useState6[0],
|
|
494
510
|
setUploadModalOpened = _useState6[1];
|
|
495
|
-
useCallback(function () {
|
|
511
|
+
var onClickAdd = useCallback(function () {
|
|
496
512
|
return setUploadModalOpened(true);
|
|
497
513
|
}, [setUploadModalOpened]);
|
|
498
514
|
var _useMediaCreate = useMediaCreate(),
|
|
@@ -501,6 +517,7 @@ function MediaGallery(_ref) {
|
|
|
501
517
|
console.log('newMedias', newMedias);
|
|
502
518
|
setUploading(true);
|
|
503
519
|
Promise.all(newMedias.map(createMedia)).then(function (newAddedMedias) {
|
|
520
|
+
console.log('not uploading anymore', newAddedMedias);
|
|
504
521
|
setUploading(false);
|
|
505
522
|
return setAddedMedias([].concat(_toConsumableArray(addedMedias), _toConsumableArray(newAddedMedias)));
|
|
506
523
|
});
|
|
@@ -538,10 +555,37 @@ function MediaGallery(_ref) {
|
|
|
538
555
|
if (addedMedias === null || addedMedias.length === 0) {
|
|
539
556
|
return value;
|
|
540
557
|
}
|
|
541
|
-
console.log('
|
|
558
|
+
console.log('addedMedias', addedMedias);
|
|
559
|
+
if (!multiple) {
|
|
560
|
+
var _ref3 = addedMedias || [],
|
|
561
|
+
_ref4 = _slicedToArray(_ref3, 1),
|
|
562
|
+
_ref4$ = _ref4[0],
|
|
563
|
+
firstMedia = _ref4$ === void 0 ? null : _ref4$;
|
|
564
|
+
return firstMedia || null;
|
|
565
|
+
}
|
|
542
566
|
var allMedias = [].concat(_toConsumableArray(addedMedias), _toConsumableArray(isArray(value) ? value || [] : [value]));
|
|
543
567
|
return allMedias.length > 0 ? allMedias : null;
|
|
544
|
-
}, [value, addedMedias]);
|
|
568
|
+
}, [value, addedMedias, multiple]);
|
|
569
|
+
var finalButtons = useMemo(function () {
|
|
570
|
+
return [{
|
|
571
|
+
id: 'upload',
|
|
572
|
+
theme: 'primary',
|
|
573
|
+
label: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
574
|
+
id: "hrS5Pj",
|
|
575
|
+
defaultMessage: [{
|
|
576
|
+
"type": 0,
|
|
577
|
+
"value": "Upload"
|
|
578
|
+
}]
|
|
579
|
+
}),
|
|
580
|
+
onClick: onClickAdd,
|
|
581
|
+
disabled: uploading
|
|
582
|
+
}];
|
|
583
|
+
}, [onClickAdd, uploading]);
|
|
584
|
+
var finalTypes = useMemo(function () {
|
|
585
|
+
var partialTypes = !isArray(types) ? [types] : types;
|
|
586
|
+
return types === 'video' ? videoTypes : partialTypes;
|
|
587
|
+
}, [types]);
|
|
588
|
+
console.log('yesh', uploadModalOpened);
|
|
545
589
|
return /*#__PURE__*/React.createElement("div", {
|
|
546
590
|
className: classNames([styles.container, _defineProperty({}, className, className)])
|
|
547
591
|
}, isPicker ? /*#__PURE__*/React.createElement(MediasPickerContainer, {
|
|
@@ -549,7 +593,7 @@ function MediaGallery(_ref) {
|
|
|
549
593
|
api: mediasApi,
|
|
550
594
|
value: finalValue,
|
|
551
595
|
theme: "dark",
|
|
552
|
-
types:
|
|
596
|
+
types: finalTypes,
|
|
553
597
|
query: finalQuery,
|
|
554
598
|
multiple: multiple,
|
|
555
599
|
items: initialMedias,
|
|
@@ -557,7 +601,7 @@ function MediaGallery(_ref) {
|
|
|
557
601
|
fields: fields,
|
|
558
602
|
columns: columns,
|
|
559
603
|
onChange: onChange,
|
|
560
|
-
buttons:
|
|
604
|
+
buttons: finalButtons,
|
|
561
605
|
buttonsClassName: "ms-xl-auto",
|
|
562
606
|
withStickySelection: true
|
|
563
607
|
}) : /*#__PURE__*/React.createElement(MediasBrowserContainer, {
|
|
@@ -565,18 +609,18 @@ function MediaGallery(_ref) {
|
|
|
565
609
|
api: mediasApi,
|
|
566
610
|
value: finalValue,
|
|
567
611
|
theme: "dark",
|
|
568
|
-
types:
|
|
612
|
+
types: finalTypes,
|
|
569
613
|
query: finalQuery,
|
|
570
614
|
multiple: multiple,
|
|
571
615
|
items: initialMedias,
|
|
572
616
|
filters: finalFilters,
|
|
573
617
|
fields: fields,
|
|
574
618
|
columns: columns,
|
|
575
|
-
buttons:
|
|
619
|
+
buttons: finalButtons,
|
|
576
620
|
buttonsClassName: "ms-xl-auto",
|
|
577
621
|
withStickySelection: true
|
|
578
622
|
}), /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(UploadModal, {
|
|
579
|
-
types:
|
|
623
|
+
types: finalTypes,
|
|
580
624
|
opened: uploadModalOpened,
|
|
581
625
|
onUploaded: onUploadCompleted,
|
|
582
626
|
onRequestClose: onUploadRequestClose
|
package/lib/index.js
CHANGED
|
@@ -9,22 +9,16 @@ var isArray = require('lodash/isArray');
|
|
|
9
9
|
var PropTypes = require('prop-types');
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var reactDom = require('react-dom');
|
|
12
|
+
var reactIntl = require('react-intl');
|
|
12
13
|
var medias = require('@panneau/medias');
|
|
13
14
|
var core = require('@micromag/core');
|
|
14
15
|
var components = require('@micromag/core/components');
|
|
15
16
|
var data = require('@micromag/data');
|
|
16
|
-
var reactIntl = require('react-intl');
|
|
17
17
|
var pathToRegexp = require('path-to-regexp');
|
|
18
18
|
|
|
19
19
|
var defaultColumns = [{
|
|
20
20
|
id: 'image',
|
|
21
|
-
label:
|
|
22
|
-
id: "UbxbKP",
|
|
23
|
-
defaultMessage: [{
|
|
24
|
-
"type": 0,
|
|
25
|
-
"value": "Preview"
|
|
26
|
-
}]
|
|
27
|
-
}),
|
|
21
|
+
label: null,
|
|
28
22
|
component: 'image',
|
|
29
23
|
path: 'thumbnail_url',
|
|
30
24
|
sortable: false
|
|
@@ -173,6 +167,29 @@ var defaultFields = [{
|
|
|
173
167
|
}),
|
|
174
168
|
type: 'text',
|
|
175
169
|
component: 'text'
|
|
170
|
+
}, {
|
|
171
|
+
name: 'tags',
|
|
172
|
+
label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
|
|
173
|
+
id: "IOVper",
|
|
174
|
+
defaultMessage: [{
|
|
175
|
+
"type": 0,
|
|
176
|
+
"value": "Tags"
|
|
177
|
+
}]
|
|
178
|
+
}),
|
|
179
|
+
type: 'array',
|
|
180
|
+
component: 'select'
|
|
181
|
+
// requestUrl: route('medias.tags') || '/api/medias/tags',
|
|
182
|
+
// itemLabelPath: 'name',
|
|
183
|
+
}, {
|
|
184
|
+
id: 'custom_field',
|
|
185
|
+
component: 'custom_field',
|
|
186
|
+
label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
|
|
187
|
+
id: "BjSp56",
|
|
188
|
+
defaultMessage: [{
|
|
189
|
+
"type": 0,
|
|
190
|
+
"value": "Test custom field"
|
|
191
|
+
}]
|
|
192
|
+
})
|
|
176
193
|
}, {
|
|
177
194
|
id: 'info',
|
|
178
195
|
component: 'fields',
|
|
@@ -396,7 +413,7 @@ function filters() {
|
|
|
396
413
|
"value": "This micromag"
|
|
397
414
|
}]
|
|
398
415
|
}),
|
|
399
|
-
value: 'document-
|
|
416
|
+
value: 'document-'
|
|
400
417
|
}]
|
|
401
418
|
}, {
|
|
402
419
|
id: 'authors',
|
|
@@ -434,8 +451,7 @@ function filters() {
|
|
|
434
451
|
|
|
435
452
|
var styles = {"container":"micromag-media-gallery-new-media-gallery-container","browser":"micromag-media-gallery-new-media-gallery-browser"};
|
|
436
453
|
|
|
437
|
-
|
|
438
|
-
|
|
454
|
+
var videoTypes = ['video', 'image/gif'];
|
|
439
455
|
var propTypes = {
|
|
440
456
|
value: PropTypes.shape({
|
|
441
457
|
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
@@ -481,9 +497,9 @@ function MediaGallery(_ref) {
|
|
|
481
497
|
columns = _ref.columns,
|
|
482
498
|
isPicker = _ref.isPicker,
|
|
483
499
|
multiple = _ref.multiple,
|
|
484
|
-
initialMedias = _ref.medias
|
|
485
|
-
|
|
486
|
-
className = _ref.className,
|
|
500
|
+
initialMedias = _ref.medias;
|
|
501
|
+
_ref.buttons;
|
|
502
|
+
var className = _ref.className,
|
|
487
503
|
onChange = _ref.onChange;
|
|
488
504
|
var api = data.useApi();
|
|
489
505
|
var mediasApi = React.useMemo(function () {
|
|
@@ -525,14 +541,14 @@ function MediaGallery(_ref) {
|
|
|
525
541
|
addedMedias = _useState2[0],
|
|
526
542
|
setAddedMedias = _useState2[1];
|
|
527
543
|
var _useState3 = React.useState(false),
|
|
528
|
-
_useState4 = _slicedToArray(_useState3, 2)
|
|
529
|
-
_useState4[0]
|
|
530
|
-
|
|
544
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
545
|
+
uploading = _useState4[0],
|
|
546
|
+
setUploading = _useState4[1];
|
|
531
547
|
var _useState5 = React.useState(false),
|
|
532
548
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
533
549
|
uploadModalOpened = _useState6[0],
|
|
534
550
|
setUploadModalOpened = _useState6[1];
|
|
535
|
-
React.useCallback(function () {
|
|
551
|
+
var onClickAdd = React.useCallback(function () {
|
|
536
552
|
return setUploadModalOpened(true);
|
|
537
553
|
}, [setUploadModalOpened]);
|
|
538
554
|
var _useMediaCreate = data.useMediaCreate(),
|
|
@@ -541,6 +557,7 @@ function MediaGallery(_ref) {
|
|
|
541
557
|
console.log('newMedias', newMedias);
|
|
542
558
|
setUploading(true);
|
|
543
559
|
Promise.all(newMedias.map(createMedia)).then(function (newAddedMedias) {
|
|
560
|
+
console.log('not uploading anymore', newAddedMedias);
|
|
544
561
|
setUploading(false);
|
|
545
562
|
return setAddedMedias([].concat(_toConsumableArray(addedMedias), _toConsumableArray(newAddedMedias)));
|
|
546
563
|
});
|
|
@@ -578,10 +595,37 @@ function MediaGallery(_ref) {
|
|
|
578
595
|
if (addedMedias === null || addedMedias.length === 0) {
|
|
579
596
|
return value;
|
|
580
597
|
}
|
|
581
|
-
console.log('
|
|
598
|
+
console.log('addedMedias', addedMedias);
|
|
599
|
+
if (!multiple) {
|
|
600
|
+
var _ref3 = addedMedias || [],
|
|
601
|
+
_ref4 = _slicedToArray(_ref3, 1),
|
|
602
|
+
_ref4$ = _ref4[0],
|
|
603
|
+
firstMedia = _ref4$ === void 0 ? null : _ref4$;
|
|
604
|
+
return firstMedia || null;
|
|
605
|
+
}
|
|
582
606
|
var allMedias = [].concat(_toConsumableArray(addedMedias), _toConsumableArray(isArray(value) ? value || [] : [value]));
|
|
583
607
|
return allMedias.length > 0 ? allMedias : null;
|
|
584
|
-
}, [value, addedMedias]);
|
|
608
|
+
}, [value, addedMedias, multiple]);
|
|
609
|
+
var finalButtons = React.useMemo(function () {
|
|
610
|
+
return [{
|
|
611
|
+
id: 'upload',
|
|
612
|
+
theme: 'primary',
|
|
613
|
+
label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
|
|
614
|
+
id: "hrS5Pj",
|
|
615
|
+
defaultMessage: [{
|
|
616
|
+
"type": 0,
|
|
617
|
+
"value": "Upload"
|
|
618
|
+
}]
|
|
619
|
+
}),
|
|
620
|
+
onClick: onClickAdd,
|
|
621
|
+
disabled: uploading
|
|
622
|
+
}];
|
|
623
|
+
}, [onClickAdd, uploading]);
|
|
624
|
+
var finalTypes = React.useMemo(function () {
|
|
625
|
+
var partialTypes = !isArray(types) ? [types] : types;
|
|
626
|
+
return types === 'video' ? videoTypes : partialTypes;
|
|
627
|
+
}, [types]);
|
|
628
|
+
console.log('yesh', uploadModalOpened);
|
|
585
629
|
return /*#__PURE__*/React.createElement("div", {
|
|
586
630
|
className: classNames([styles.container, _defineProperty({}, className, className)])
|
|
587
631
|
}, isPicker ? /*#__PURE__*/React.createElement(medias.MediasPickerContainer, {
|
|
@@ -589,7 +633,7 @@ function MediaGallery(_ref) {
|
|
|
589
633
|
api: mediasApi,
|
|
590
634
|
value: finalValue,
|
|
591
635
|
theme: "dark",
|
|
592
|
-
types:
|
|
636
|
+
types: finalTypes,
|
|
593
637
|
query: finalQuery,
|
|
594
638
|
multiple: multiple,
|
|
595
639
|
items: initialMedias,
|
|
@@ -597,7 +641,7 @@ function MediaGallery(_ref) {
|
|
|
597
641
|
fields: fields,
|
|
598
642
|
columns: columns,
|
|
599
643
|
onChange: onChange,
|
|
600
|
-
buttons:
|
|
644
|
+
buttons: finalButtons,
|
|
601
645
|
buttonsClassName: "ms-xl-auto",
|
|
602
646
|
withStickySelection: true
|
|
603
647
|
}) : /*#__PURE__*/React.createElement(medias.MediasBrowserContainer, {
|
|
@@ -605,18 +649,18 @@ function MediaGallery(_ref) {
|
|
|
605
649
|
api: mediasApi,
|
|
606
650
|
value: finalValue,
|
|
607
651
|
theme: "dark",
|
|
608
|
-
types:
|
|
652
|
+
types: finalTypes,
|
|
609
653
|
query: finalQuery,
|
|
610
654
|
multiple: multiple,
|
|
611
655
|
items: initialMedias,
|
|
612
656
|
filters: finalFilters,
|
|
613
657
|
fields: fields,
|
|
614
658
|
columns: columns,
|
|
615
|
-
buttons:
|
|
659
|
+
buttons: finalButtons,
|
|
616
660
|
buttonsClassName: "ms-xl-auto",
|
|
617
661
|
withStickySelection: true
|
|
618
662
|
}), /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/React.createElement(components.UploadModal, {
|
|
619
|
-
types:
|
|
663
|
+
types: finalTypes,
|
|
620
664
|
opened: uploadModalOpened,
|
|
621
665
|
onUploaded: onUploadCompleted,
|
|
622
666
|
onRequestClose: onUploadRequestClose
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/media-gallery",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.514",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
|
73
73
|
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
|
74
74
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
75
|
-
"@micromag/core": "^0.3.
|
|
76
|
-
"@micromag/data": "^0.3.
|
|
75
|
+
"@micromag/core": "^0.3.514",
|
|
76
|
+
"@micromag/data": "^0.3.514",
|
|
77
77
|
"@panneau/medias": "^3.0.163",
|
|
78
78
|
"bootstrap": "^5.3.1",
|
|
79
79
|
"classnames": "^2.2.6",
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"access": "public",
|
|
88
88
|
"registry": "https://registry.npmjs.org/"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "40bbf8d97c0d912ce8be3c8caa2c70e117286fc2"
|
|
91
91
|
}
|