decap-cms-widget-file 3.1.4-beta.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.1.4-beta.0",
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",
@@ -34,9 +34,9 @@
34
34
  "decap-cms-ui-default": "^3.0.0",
35
35
  "immutable": "^3.7.6",
36
36
  "prop-types": "^15.7.2",
37
- "react": "17.x || 18.x",
37
+ "react": "^19.1.0",
38
38
  "react-immutable-proptypes": "^2.1.0",
39
39
  "uuid": "^8.3.2"
40
40
  },
41
- "gitHead": "0f91300093c3c074f50c7af8f20a4ad331806e62"
41
+ "gitHead": "ae01ad6f2b139f93472c8f0d049d35277d8583ca"
42
42
  }
@@ -1,10 +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
- import { once } from 'lodash';
7
+ import once from 'lodash/once';
8
8
  import { v4 as uuid } from 'uuid';
9
9
  import { oneLine } from 'common-tags';
10
10
  import {
@@ -61,8 +61,19 @@ const StyledImage = styled.img`
61
61
  object-fit: contain;
62
62
  `;
63
63
 
64
- function Image(props) {
65
- return <StyledImage role="presentation" {...props} />;
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 src={getAsset(itemValue, field) || ''} />
103
+ <Image value={itemValue} field={field} getAsset={getAsset} />
93
104
  </ImageWrapper>
94
105
  <SortableImageButtons
95
106
  item={itemValue}
@@ -257,6 +268,11 @@ export default function withFileControl({ forImage } = {}) {
257
268
  this.controlID = uuid();
258
269
  }
259
270
 
271
+ componentDidMount() {
272
+ // Manually validate PropTypes - React 19 breaking change
273
+ PropTypes.checkPropTypes(FileControl.propTypes, this.props, 'prop', 'FileControl');
274
+ }
275
+
260
276
  shouldComponentUpdate(nextProps) {
261
277
  /**
262
278
  * Always update if the value or getAsset changes.
@@ -412,6 +428,7 @@ export default function withFileControl({ forImage } = {}) {
412
428
  renderImages = () => {
413
429
  const { getAsset, value, field } = this.props;
414
430
  const items = valueListToSortableArray(value);
431
+
415
432
  if (isMultiple(value)) {
416
433
  return (
417
434
  <SortableMultiImageWrapper
@@ -428,10 +445,9 @@ export default function withFileControl({ forImage } = {}) {
428
445
  );
429
446
  }
430
447
 
431
- const src = getAsset(value, field);
432
448
  return (
433
449
  <ImageWrapper>
434
- <Image src={src || ''} />
450
+ <Image value={value} field={field} getAsset={getAsset} />
435
451
  </ImageWrapper>
436
452
  );
437
453
  };