@uncinc/uncinc-react-kitchen-sink 2.11.5-adaptive-image-debounce → 2.11.5
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/dist/components/Form/Select/Input/index.js +9 -4
- package/dist/components/Image/AdaptivePicture/index.d.ts +0 -1
- package/dist/components/Image/AdaptivePicture/index.js +24 -39
- package/dist/components/Image/index.d.ts +1 -3
- package/dist/components/Image/index.js +3 -5
- package/package.json +1 -1
|
@@ -46,7 +46,12 @@ var SelectInput = function SelectInput(props) {
|
|
|
46
46
|
setFieldValue = _useExtendedFormikCon.setFieldValue;
|
|
47
47
|
var _useTranslation = useTranslation(),
|
|
48
48
|
t = _useTranslation.t;
|
|
49
|
-
|
|
49
|
+
|
|
50
|
+
// Because Object.keys doesn't respect integers:
|
|
51
|
+
// When using integers as keys for your select options (for example, when using Taxonomy IDs)
|
|
52
|
+
// below logic would fail to find your initialValue, and your Select would not be pre-filled.
|
|
53
|
+
var value = values[fieldName] && values[fieldName].toString();
|
|
54
|
+
var defaultValueString = defaultValue && defaultValue.toString();
|
|
50
55
|
|
|
51
56
|
// Check if options is [{value, label}] or {value: label}.
|
|
52
57
|
var optionsTransformed = options;
|
|
@@ -63,12 +68,12 @@ var SelectInput = function SelectInput(props) {
|
|
|
63
68
|
// If the selected option is not set, find the currently selected option by value.
|
|
64
69
|
if (!selectedOption) {
|
|
65
70
|
if (multiple) {
|
|
66
|
-
var _value = value !== undefined ? value :
|
|
71
|
+
var _value = value !== undefined ? value : defaultValueString || [];
|
|
67
72
|
selectedOption = optionsTransformed.filter(function (option) {
|
|
68
73
|
return _value.includes(option.value);
|
|
69
74
|
});
|
|
70
75
|
} else {
|
|
71
|
-
var _value2 = value !== undefined ? value :
|
|
76
|
+
var _value2 = value !== undefined ? value : defaultValueString || '';
|
|
72
77
|
selectedOption = optionsTransformed.filter(function (option) {
|
|
73
78
|
return option.value === _value2;
|
|
74
79
|
});
|
|
@@ -94,7 +99,7 @@ var SelectInput = function SelectInput(props) {
|
|
|
94
99
|
className: c('Select__select', className),
|
|
95
100
|
classNamePrefix: c('Select__inner', wrapperClassName),
|
|
96
101
|
value: selectedOption,
|
|
97
|
-
defaultValue:
|
|
102
|
+
defaultValue: defaultValueString,
|
|
98
103
|
disabled: disabled,
|
|
99
104
|
onChange: function onChange(e) {
|
|
100
105
|
var value = '';
|
|
@@ -5,7 +5,6 @@ interface Props extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src'> {
|
|
|
5
5
|
onLoad: (e: any) => void;
|
|
6
6
|
objectFit?: 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
|
|
7
7
|
aspectRatio?: number | string;
|
|
8
|
-
resizeDelay?: number;
|
|
9
8
|
}
|
|
10
9
|
declare const AdaptivePicture: React.FC<Props>;
|
|
11
10
|
export default AdaptivePicture;
|
|
@@ -18,9 +18,7 @@ var AdaptivePicture = function AdaptivePicture(_ref) {
|
|
|
18
18
|
alt = _ref.alt,
|
|
19
19
|
objectFit = _ref.objectFit,
|
|
20
20
|
_ref$aspectRatio = _ref.aspectRatio,
|
|
21
|
-
aspectRatio = _ref$aspectRatio === void 0 ? 1 : _ref$aspectRatio
|
|
22
|
-
_ref$resizeDelay = _ref.resizeDelay,
|
|
23
|
-
resizeDelay = _ref$resizeDelay === void 0 ? 100 : _ref$resizeDelay;
|
|
21
|
+
aspectRatio = _ref$aspectRatio === void 0 ? 1 : _ref$aspectRatio;
|
|
24
22
|
var sourcesAsArray = Array.isArray(src) ? src : [src];
|
|
25
23
|
var validatedSources = sourcesAsArray.filter(isValidImage);
|
|
26
24
|
var fallbackImage = validatedSources[0];
|
|
@@ -37,8 +35,6 @@ var AdaptivePicture = function AdaptivePicture(_ref) {
|
|
|
37
35
|
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
38
36
|
targetSrc = _React$useState4[0],
|
|
39
37
|
setTargetSrc = _React$useState4[1];
|
|
40
|
-
var resizingDelay = React.useRef(0);
|
|
41
|
-
var resizingDelayTimer = React.useRef();
|
|
42
38
|
React.useEffect(function () {
|
|
43
39
|
// @ts-ignore
|
|
44
40
|
if (global.ssr) return;
|
|
@@ -48,43 +44,32 @@ var AdaptivePicture = function AdaptivePicture(_ref) {
|
|
|
48
44
|
var container = image.parentElement;
|
|
49
45
|
if (!container) return;
|
|
50
46
|
var resizeObserver = new ResizeObserver(function (entries) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var newTargetSrc = calculateTargetSrc(image.width, validatedSources, fallbackImage);
|
|
59
|
-
if (targetSrc !== newTargetSrc) {
|
|
60
|
-
setTargetSrc(newTargetSrc);
|
|
61
|
-
newSrcRequired = true;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
var _newTargetSrc = calculateTargetSrc(widthAfterResize, validatedSources, fallbackImage);
|
|
65
|
-
if (targetSrc !== _newTargetSrc) {
|
|
66
|
-
setTargetSrc(_newTargetSrc);
|
|
67
|
-
newSrcRequired = true;
|
|
68
|
-
}
|
|
47
|
+
var widthAfterResize = entries[0].contentRect.width;
|
|
48
|
+
var newSrcRequired = false;
|
|
49
|
+
if (image.width < widthAfterResize) {
|
|
50
|
+
var newTargetSrc = calculateTargetSrc(image.width, validatedSources, fallbackImage);
|
|
51
|
+
if (targetSrc !== newTargetSrc) {
|
|
52
|
+
setTargetSrc(newTargetSrc);
|
|
53
|
+
newSrcRequired = true;
|
|
69
54
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// With caching turned on, the onLoad function on the img would only trigger once
|
|
76
|
-
// and thus never unblur the smallest
|
|
77
|
-
if (!newSrcRequired) {
|
|
78
|
-
setStatus('INITIAL_LOADED');
|
|
79
|
-
}
|
|
55
|
+
} else {
|
|
56
|
+
var _newTargetSrc = calculateTargetSrc(widthAfterResize, validatedSources, fallbackImage);
|
|
57
|
+
if (targetSrc !== _newTargetSrc) {
|
|
58
|
+
setTargetSrc(_newTargetSrc);
|
|
59
|
+
newSrcRequired = true;
|
|
80
60
|
}
|
|
61
|
+
}
|
|
62
|
+
if (status === 'PENDING') {
|
|
63
|
+
setStatus('INITIAL_BREAKPOINT_CALCULATED');
|
|
81
64
|
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
// We always load the smallest source. If that's also the source we need
|
|
66
|
+
// set INITIAL_LOADED directly.
|
|
67
|
+
// With caching turned on, the onLoad function on the img would only trigger once
|
|
68
|
+
// and thus never unblur the smallest
|
|
69
|
+
if (!newSrcRequired) {
|
|
70
|
+
setStatus('INITIAL_LOADED');
|
|
86
71
|
}
|
|
87
|
-
}
|
|
72
|
+
}
|
|
88
73
|
});
|
|
89
74
|
resizeObserver.observe(container);
|
|
90
75
|
|
|
@@ -92,7 +77,7 @@ var AdaptivePicture = function AdaptivePicture(_ref) {
|
|
|
92
77
|
return function () {
|
|
93
78
|
resizeObserver.unobserve(container);
|
|
94
79
|
};
|
|
95
|
-
}, [fallbackImage, status, targetSrc, validatedSources
|
|
80
|
+
}, [fallbackImage, status, targetSrc, validatedSources]);
|
|
96
81
|
var loadedUrl = useImageLoader(fallbackImage, targetSrc, imageRef);
|
|
97
82
|
function onErrorFallback(e) {
|
|
98
83
|
// Make sure that both URLs are absolute URLs, so we can compare them.
|
|
@@ -8,13 +8,11 @@ declare namespace Image {
|
|
|
8
8
|
lazyload: PropTypes.Requireable<boolean>;
|
|
9
9
|
aspectRatio: PropTypes.Requireable<number>;
|
|
10
10
|
objectFit: PropTypes.Requireable<string>;
|
|
11
|
-
resizeDelay: PropTypes.Requireable<number>;
|
|
12
11
|
};
|
|
13
12
|
namespace defaultProps {
|
|
14
13
|
let lazyload: boolean;
|
|
15
|
-
let aspectRatio:
|
|
14
|
+
let aspectRatio: null;
|
|
16
15
|
let objectFit: null;
|
|
17
|
-
let resizeDelay: number;
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
import React from 'react';
|
|
@@ -24,13 +24,11 @@ Image.propTypes = _objectSpread({
|
|
|
24
24
|
src: PropTypes.oneOfType([PropTypes.string, ImmutablePropTypes.map, PropTypes.arrayOf(PropTypes.string)]).isRequired,
|
|
25
25
|
lazyload: PropTypes.bool,
|
|
26
26
|
aspectRatio: PropTypes.number,
|
|
27
|
-
objectFit: PropTypes.oneOf(['fill', 'contain', 'cover', 'none', 'scale-down'])
|
|
28
|
-
resizeDelay: PropTypes.number
|
|
27
|
+
objectFit: PropTypes.oneOf(['fill', 'contain', 'cover', 'none', 'scale-down'])
|
|
29
28
|
}, Picture.propTypes);
|
|
30
29
|
Image.defaultProps = {
|
|
31
30
|
lazyload: true,
|
|
32
|
-
aspectRatio:
|
|
33
|
-
objectFit: null
|
|
34
|
-
resizeDelay: 100
|
|
31
|
+
aspectRatio: null,
|
|
32
|
+
objectFit: null
|
|
35
33
|
};
|
|
36
34
|
export default Image;
|