decap-cms-widget-file 3.2.0 → 3.3.0
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-widget-file",
|
|
3
3
|
"description": "Widget for uploading files in Decap CMS.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"homepage": "https://www.decapcms.org/docs/widgets/#file",
|
|
6
6
|
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-file",
|
|
7
7
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"react-immutable-proptypes": "^2.1.0",
|
|
39
39
|
"uuid": "^8.3.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ae01ad6f2b139f93472c8f0d049d35277d8583ca"
|
|
42
42
|
}
|
package/src/withFileControl.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
4
4
|
import styled from '@emotion/styled';
|
|
@@ -61,8 +61,19 @@ const StyledImage = styled.img`
|
|
|
61
61
|
object-fit: contain;
|
|
62
62
|
`;
|
|
63
63
|
|
|
64
|
-
function Image(
|
|
65
|
-
|
|
64
|
+
function Image({ value, field, getAsset }) {
|
|
65
|
+
const [asset, setAsset] = useState(null);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (value) {
|
|
69
|
+
const newAsset = getAsset(value, field);
|
|
70
|
+
setAsset(newAsset);
|
|
71
|
+
} else {
|
|
72
|
+
setAsset(null);
|
|
73
|
+
}
|
|
74
|
+
}, [value, field, getAsset]);
|
|
75
|
+
|
|
76
|
+
return asset ? <StyledImage role="presentation" src={asset} /> : null;
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
function SortableImageButtons({ onRemove, onReplace }) {
|
|
@@ -89,7 +100,7 @@ function SortableImage(props) {
|
|
|
89
100
|
return (
|
|
90
101
|
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
|
|
91
102
|
<ImageWrapper sortable>
|
|
92
|
-
<Image
|
|
103
|
+
<Image value={itemValue} field={field} getAsset={getAsset} />
|
|
93
104
|
</ImageWrapper>
|
|
94
105
|
<SortableImageButtons
|
|
95
106
|
item={itemValue}
|
|
@@ -417,6 +428,7 @@ export default function withFileControl({ forImage } = {}) {
|
|
|
417
428
|
renderImages = () => {
|
|
418
429
|
const { getAsset, value, field } = this.props;
|
|
419
430
|
const items = valueListToSortableArray(value);
|
|
431
|
+
|
|
420
432
|
if (isMultiple(value)) {
|
|
421
433
|
return (
|
|
422
434
|
<SortableMultiImageWrapper
|
|
@@ -433,10 +445,9 @@ export default function withFileControl({ forImage } = {}) {
|
|
|
433
445
|
);
|
|
434
446
|
}
|
|
435
447
|
|
|
436
|
-
const src = getAsset(value, field);
|
|
437
448
|
return (
|
|
438
449
|
<ImageWrapper>
|
|
439
|
-
<Image
|
|
450
|
+
<Image value={value} field={field} getAsset={getAsset} />
|
|
440
451
|
</ImageWrapper>
|
|
441
452
|
);
|
|
442
453
|
};
|