decap-cms-widget-file 3.2.0 → 3.4.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.2.0",
4
+ "version": "3.4.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",
@@ -25,6 +25,7 @@
25
25
  "@dnd-kit/core": "^6.0.8",
26
26
  "@dnd-kit/modifiers": "^6.0.1",
27
27
  "@dnd-kit/sortable": "^7.0.2",
28
+ "@dnd-kit/utilities": "^3.2.2",
28
29
  "array-move": "4.0.0",
29
30
  "common-tags": "^1.8.0"
30
31
  },
@@ -35,8 +36,7 @@
35
36
  "immutable": "^3.7.6",
36
37
  "prop-types": "^15.7.2",
37
38
  "react": "^19.1.0",
38
- "react-immutable-proptypes": "^2.1.0",
39
- "uuid": "^8.3.2"
39
+ "react-immutable-proptypes": "^2.1.0"
40
40
  },
41
- "gitHead": "ed7e99318007b83f4c57f3237bf92b931676820a"
41
+ "gitHead": "567a80101f4846853701ad7d8abdc29b5e4fab56"
42
42
  }
@@ -1,11 +1,10 @@
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';
5
5
  import { css } from '@emotion/react';
6
6
  import { Map, List } from 'immutable';
7
7
  import once from 'lodash/once';
8
- import { v4 as uuid } from 'uuid';
9
8
  import { oneLine } from 'common-tags';
10
9
  import {
11
10
  lengths,
@@ -61,8 +60,19 @@ const StyledImage = styled.img`
61
60
  object-fit: contain;
62
61
  `;
63
62
 
64
- function Image(props) {
65
- return <StyledImage role="presentation" {...props} />;
63
+ function Image({ value, field, getAsset }) {
64
+ const [asset, setAsset] = useState(null);
65
+
66
+ useEffect(() => {
67
+ if (value) {
68
+ const newAsset = getAsset(value, field);
69
+ setAsset(newAsset);
70
+ } else {
71
+ setAsset(null);
72
+ }
73
+ }, [value, field, getAsset]);
74
+
75
+ return asset ? <StyledImage role="presentation" src={asset} /> : null;
66
76
  }
67
77
 
68
78
  function SortableImageButtons({ onRemove, onReplace }) {
@@ -89,7 +99,7 @@ function SortableImage(props) {
89
99
  return (
90
100
  <div ref={setNodeRef} style={style} {...attributes} {...listeners}>
91
101
  <ImageWrapper sortable>
92
- <Image src={getAsset(itemValue, field) || ''} />
102
+ <Image value={itemValue} field={field} getAsset={getAsset} />
93
103
  </ImageWrapper>
94
104
  <SortableImageButtons
95
105
  item={itemValue}
@@ -211,7 +221,7 @@ function valueListToSortableArray(value) {
211
221
  }
212
222
 
213
223
  const valueArray = valueListToArray(value).map(value => ({
214
- id: uuid(),
224
+ id: crypto.randomUUID(),
215
225
  value,
216
226
  }));
217
227
 
@@ -254,7 +264,7 @@ export default function withFileControl({ forImage } = {}) {
254
264
 
255
265
  constructor(props) {
256
266
  super(props);
257
- this.controlID = uuid();
267
+ this.controlID = crypto.randomUUID();
258
268
  }
259
269
 
260
270
  componentDidMount() {
@@ -417,6 +427,7 @@ export default function withFileControl({ forImage } = {}) {
417
427
  renderImages = () => {
418
428
  const { getAsset, value, field } = this.props;
419
429
  const items = valueListToSortableArray(value);
430
+
420
431
  if (isMultiple(value)) {
421
432
  return (
422
433
  <SortableMultiImageWrapper
@@ -433,10 +444,9 @@ export default function withFileControl({ forImage } = {}) {
433
444
  );
434
445
  }
435
446
 
436
- const src = getAsset(value, field);
437
447
  return (
438
448
  <ImageWrapper>
439
- <Image src={src || ''} />
449
+ <Image value={value} field={field} getAsset={getAsset} />
440
450
  </ImageWrapper>
441
451
  );
442
452
  };