@shopgate/pwa-common 7.30.0-alpha.9 → 7.30.0-beta.2
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/App.js +28 -13
- package/actions/app/handleUniversalLink.js +0 -2
- package/collections/AuthRoutes.js +15 -13
- package/collections/Configuration.js +11 -10
- package/collections/EmbeddedMedia.js +21 -19
- package/collections/PersistedReducers.js +11 -9
- package/collections/Redirects.js +15 -13
- package/collections/media-providers/MediaProvider.js +23 -21
- package/collections/media-providers/Vimeo.js +28 -22
- package/collections/media-providers/YouTube.js +17 -10
- package/components/Backdrop/index.js +15 -13
- package/components/Backdrop/spec.js +3 -2
- package/components/Button/index.js +41 -29
- package/components/Button/spec.js +16 -10
- package/components/Checkbox/index.js +36 -28
- package/components/Checkbox/spec.js +40 -27
- package/components/Consume/index.js +4 -1
- package/components/CountdownTimer/index.js +27 -20
- package/components/CountdownTimer/spec.js +2 -1
- package/components/Drawer/index.js +31 -23
- package/components/Drawer/spec.js +7 -6
- package/components/Dropdown/index.js +27 -18
- package/components/Ellipsis/index.js +5 -3
- package/components/Ellipsis/spec.js +5 -3
- package/components/EmbeddedMedia/index.js +9 -6
- package/components/EmbeddedMedia/spec.js +11 -2
- package/components/ErrorBoundary/index.js +26 -16
- package/components/Grid/components/Item/index.js +13 -6
- package/components/Grid/components/Item/spec.js +4 -3
- package/components/Grid/index.js +13 -6
- package/components/Grid/spec.js +4 -3
- package/components/HtmlSanitizer/index.js +42 -45
- package/components/HtmlSanitizer/spec.js +16 -12
- package/components/I18n/components/FormatDate/index.js +11 -4
- package/components/I18n/components/FormatDate/spec.js +22 -14
- package/components/I18n/components/FormatNumber/index.js +8 -6
- package/components/I18n/components/FormatNumber/spec.js +10 -5
- package/components/I18n/components/FormatPrice/index.js +5 -3
- package/components/I18n/components/FormatPrice/spec.js +22 -14
- package/components/I18n/components/FormatTime/index.js +11 -4
- package/components/I18n/components/FormatTime/spec.js +22 -14
- package/components/I18n/components/I18nProvider/index.js +18 -11
- package/components/I18n/components/I18nProvider/spec.js +2 -1
- package/components/I18n/components/Placeholder/index.js +10 -3
- package/components/I18n/components/Placeholder/spec.js +12 -5
- package/components/I18n/components/Translate/index.js +12 -8
- package/components/I18n/components/Translate/spec.js +9 -6
- package/components/Icon/index.js +2 -1
- package/components/Image/Image.js +23 -21
- package/components/Image/ImageInner.js +2 -1
- package/components/InfiniteContainer/index.js +59 -53
- package/components/InfiniteContainer/spec.js +10 -5
- package/components/Input/components/MultiLineInput.js +33 -26
- package/components/Input/components/SimpleInput.js +70 -54
- package/components/Input/index.js +7 -17
- package/components/Input/spec.js +12 -11
- package/components/KeyboardConsumer/index.js +19 -13
- package/components/Link/index.js +28 -20
- package/components/Link/spec.js +13 -9
- package/components/List/components/Item/index.js +5 -3
- package/components/List/index.js +5 -3
- package/components/List/spec.js +6 -9
- package/components/Loading/index.js +1 -3
- package/components/Modal/index.js +13 -10
- package/components/ModalContainer/spec.js +24 -20
- package/components/Picker/components/Button/index.js +18 -12
- package/components/Picker/components/List/index.js +19 -16
- package/components/Picker/components/Modal/index.js +34 -25
- package/components/Picker/index.js +44 -33
- package/components/Picker/spec.js +4 -1
- package/components/Portal/index.js +26 -17
- package/components/ProductCharacteristics/index.js +65 -57
- package/components/RangeSlider/components/Handle/index.js +7 -5
- package/components/RangeSlider/index.js +98 -84
- package/components/Route/RouteNotFound.js +30 -19
- package/components/Route/index.js +31 -21
- package/components/Router/index.js +51 -34
- package/components/ScannerContainer/index.js +17 -10
- package/components/Select/components/Item/index.js +5 -3
- package/components/Select/index.js +59 -47
- package/components/Select/spec.js +7 -6
- package/components/SelectBox/components/Item/index.js +23 -13
- package/components/SelectBox/index.js +83 -80
- package/components/SelectBox/spec.js +8 -5
- package/components/SurroundPortals/index.js +15 -11
- package/components/Swiper/components/SwiperItem/index.js +6 -5
- package/components/Swiper/components/SwiperItem/spec.js +8 -4
- package/components/Swiper/index.js +23 -20
- package/components/Toaster/index.js +4 -1
- package/components/Transition/index.js +19 -12
- package/components/Widgets/components/Widget/index.js +27 -16
- package/components/Widgets/components/Widget/spec.js +5 -4
- package/components/Widgets/components/WidgetGrid/index.js +27 -19
- package/components/Widgets/components/WidgetGrid/spec.js +4 -3
- package/components/Widgets/index.js +33 -26
- package/components/Widgets/spec.js +12 -13
- package/helpers/data/index.js +1 -1
- package/helpers/portals/portalCollection.js +13 -10
- package/helpers/redux/mutable.js +2 -2
- package/package.json +5 -5
- package/providers/loading/index.js +71 -57
- package/providers/toast/index.js +39 -28
- package/reducers/modal/index.js +1 -1
- package/store/index.js +1 -1
- package/subscriptions/helpers/buildRegisterUrl.js +1 -0
- package/components/Input/components/DateInput.js +0 -273
|
@@ -7,7 +7,8 @@ import SelectBox from "./index";
|
|
|
7
7
|
* Mock Icon component.
|
|
8
8
|
* @returns {JSX}
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const MockIconComponent = () => /*#__PURE__*/_jsx("span", {
|
|
11
12
|
id: "icon"
|
|
12
13
|
});
|
|
13
14
|
|
|
@@ -19,7 +20,9 @@ const MockIconComponent = () => /*#__PURE__*/React.createElement("span", {
|
|
|
19
20
|
*/
|
|
20
21
|
const MockItemComponent = ({
|
|
21
22
|
children
|
|
22
|
-
}) => /*#__PURE__*/
|
|
23
|
+
}) => /*#__PURE__*/_jsx("div", {
|
|
24
|
+
children: children
|
|
25
|
+
});
|
|
23
26
|
describe('<SelectBox>', () => {
|
|
24
27
|
const dummyItems = [{
|
|
25
28
|
label: 'My item #1',
|
|
@@ -32,7 +35,7 @@ describe('<SelectBox>', () => {
|
|
|
32
35
|
value: 'item_3'
|
|
33
36
|
}];
|
|
34
37
|
it('should render the selectbox with given mock components', () => {
|
|
35
|
-
const wrapper = mount(/*#__PURE__*/
|
|
38
|
+
const wrapper = mount(/*#__PURE__*/_jsx(SelectBox, {
|
|
36
39
|
icon: MockIconComponent,
|
|
37
40
|
item: MockItemComponent,
|
|
38
41
|
items: dummyItems
|
|
@@ -42,7 +45,7 @@ describe('<SelectBox>', () => {
|
|
|
42
45
|
expect(wrapper.find(MockItemComponent).length).toEqual(3);
|
|
43
46
|
});
|
|
44
47
|
it('should render with a default text', () => {
|
|
45
|
-
const wrapper = mount(/*#__PURE__*/
|
|
48
|
+
const wrapper = mount(/*#__PURE__*/_jsx(SelectBox, {
|
|
46
49
|
icon: MockIconComponent,
|
|
47
50
|
item: MockItemComponent,
|
|
48
51
|
items: dummyItems,
|
|
@@ -52,7 +55,7 @@ describe('<SelectBox>', () => {
|
|
|
52
55
|
expect(wrapper.find('span').at(0).text()).toEqual('Foo');
|
|
53
56
|
});
|
|
54
57
|
it('should render with a preselected selection', () => {
|
|
55
|
-
const wrapper = mount(/*#__PURE__*/
|
|
58
|
+
const wrapper = mount(/*#__PURE__*/_jsx(SelectBox, {
|
|
56
59
|
icon: MockIconComponent,
|
|
57
60
|
item: MockItemComponent,
|
|
58
61
|
items: dummyItems,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import Portal from "../Portal";
|
|
4
4
|
import { AFTER, BEFORE } from "../../constants/Portals";
|
|
@@ -15,20 +15,24 @@ import { AFTER, BEFORE } from "../../constants/Portals";
|
|
|
15
15
|
* @param {React.ReactNode} props.children Component children
|
|
16
16
|
* @returns {JSX.Element}
|
|
17
17
|
*/
|
|
18
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
const SurroundPortals = ({
|
|
19
20
|
portalName,
|
|
20
21
|
portalProps,
|
|
21
22
|
children
|
|
22
|
-
}) => /*#__PURE__*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
23
|
+
}) => /*#__PURE__*/_jsxs(_Fragment, {
|
|
24
|
+
children: [/*#__PURE__*/_jsx(Portal, {
|
|
25
|
+
name: `${portalName}.${BEFORE}`,
|
|
26
|
+
props: portalProps
|
|
27
|
+
}), /*#__PURE__*/_jsx(Portal, {
|
|
28
|
+
name: portalName,
|
|
29
|
+
props: portalProps,
|
|
30
|
+
children: children
|
|
31
|
+
}), /*#__PURE__*/_jsx(Portal, {
|
|
32
|
+
name: `${portalName}.${AFTER}`,
|
|
33
|
+
props: portalProps
|
|
34
|
+
})]
|
|
35
|
+
});
|
|
32
36
|
SurroundPortals.defaultProps = {
|
|
33
37
|
children: null,
|
|
34
38
|
portalProps: null
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
3
|
import classNames from 'classnames';
|
|
5
|
-
// eslint-disable-next-line import/no-unresolved
|
|
6
4
|
import { SwiperSlide } from 'swiper/react';
|
|
7
5
|
import { item } from "./styles";
|
|
8
6
|
|
|
@@ -15,15 +13,18 @@ import { item } from "./styles";
|
|
|
15
13
|
* @param {SwiperSlideProps} props The component props.
|
|
16
14
|
* @returns {React.Node}
|
|
17
15
|
*/
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
17
|
function SwiperItem({
|
|
19
18
|
children,
|
|
20
19
|
className,
|
|
21
20
|
...slideProps
|
|
22
21
|
}) {
|
|
23
|
-
return /*#__PURE__*/
|
|
22
|
+
return /*#__PURE__*/_jsx(SwiperSlide, {
|
|
23
|
+
...slideProps,
|
|
24
24
|
className: classNames(item, className),
|
|
25
|
-
"data-test-id": "Slider"
|
|
26
|
-
|
|
25
|
+
"data-test-id": "Slider",
|
|
26
|
+
children: children
|
|
27
|
+
});
|
|
27
28
|
}
|
|
28
29
|
SwiperItem.displayName = 'SwiperSlide';
|
|
29
30
|
SwiperItem.defaultProps = {
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { shallow } from 'enzyme';
|
|
3
3
|
import SwiperItem from '.';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
jest.mock('react', () => ({
|
|
5
6
|
...jest.requireActual('react'),
|
|
6
7
|
useLayoutEffect: jest.requireActual('react').useEffect
|
|
7
8
|
}));
|
|
8
9
|
describe('<SwiperItem />', () => {
|
|
9
10
|
it('should not render without children', () => {
|
|
10
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
11
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(SwiperItem, {
|
|
12
|
+
children: /*#__PURE__*/_jsx("div", {})
|
|
13
|
+
}));
|
|
11
14
|
expect(wrapper).toMatchSnapshot();
|
|
12
15
|
expect(wrapper.html()).toEqual('<div class="swiper-slide css-10a4qrv" data-test-id="Slider"><div></div></div>');
|
|
13
16
|
});
|
|
14
17
|
it('should add custom className', () => {
|
|
15
|
-
const wrapper = shallow(/*#__PURE__*/
|
|
16
|
-
className: "test"
|
|
17
|
-
|
|
18
|
+
const wrapper = shallow(/*#__PURE__*/_jsx(SwiperItem, {
|
|
19
|
+
className: "test",
|
|
20
|
+
children: /*#__PURE__*/_jsx("div", {})
|
|
21
|
+
}));
|
|
18
22
|
expect(wrapper).toMatchSnapshot();
|
|
19
23
|
expect(wrapper.html()).toEqual('<div class="swiper-slide css-10a4qrv test" data-test-id="Slider"><div></div></div>');
|
|
20
24
|
});
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React, { useMemo, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
3
|
import cls from 'classnames';
|
|
5
4
|
import { A11y, Autoplay, FreeMode, Navigation, Pagination, Zoom } from 'swiper/modules';
|
|
6
|
-
/* eslint-disable import/no-unresolved */
|
|
7
5
|
import { Swiper as OriginalSwiper } from 'swiper/react';
|
|
8
6
|
import 'swiper/css';
|
|
9
7
|
import 'swiper/css/a11y';
|
|
10
8
|
import 'swiper/css/pagination';
|
|
11
9
|
import 'swiper/css/navigation';
|
|
12
10
|
import 'swiper/css/zoom';
|
|
13
|
-
/* eslint-enable import/no-unresolved */
|
|
14
11
|
import { useReduceMotion } from '@shopgate/engage/a11y/hooks';
|
|
15
12
|
import SwiperItem from "./components/SwiperItem";
|
|
16
13
|
import { container, innerContainer, zoomFix, buttonNext, buttonPrev } from "./styles";
|
|
@@ -28,6 +25,7 @@ import { container, innerContainer, zoomFix, buttonNext, buttonPrev } from "./st
|
|
|
28
25
|
* @param {SwiperClass} swiper Swiper instance
|
|
29
26
|
* @param {boolean} loop Whether the loop mode should be enabled or not.
|
|
30
27
|
*/
|
|
28
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
31
29
|
const handleLoopPropUpdate = (swiper, loop) => {
|
|
32
30
|
const realIndex = swiper?.realIndex || 0;
|
|
33
31
|
|
|
@@ -102,7 +100,7 @@ const Swiper = ({
|
|
|
102
100
|
* @type {SwiperCmpProps}
|
|
103
101
|
*/
|
|
104
102
|
const internalProps = useMemo(() => ({
|
|
105
|
-
modules: [A11y, Autoplay, FreeMode, Navigation, Pagination, Zoom
|
|
103
|
+
modules: [A11y, Autoplay, FreeMode, Navigation, Pagination, Zoom].concat(Array.isArray(additionalModules) ? additionalModules : []),
|
|
106
104
|
className: cls(innerContainer, classNames.container, {
|
|
107
105
|
[zoomFix]: swiperProps?.zoom
|
|
108
106
|
}),
|
|
@@ -188,23 +186,28 @@ const Swiper = ({
|
|
|
188
186
|
onBreakpoint(swiper, breakpoint);
|
|
189
187
|
}
|
|
190
188
|
}, [delay, loopProp, onBreakpoint]);
|
|
191
|
-
return /*#__PURE__*/
|
|
189
|
+
return /*#__PURE__*/_jsx("div", {
|
|
192
190
|
className: cls(container, className, 'common__swiper'),
|
|
193
|
-
"aria-hidden": ariaHidden
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
191
|
+
"aria-hidden": ariaHidden,
|
|
192
|
+
children: /*#__PURE__*/_jsxs(OriginalSwiper, {
|
|
193
|
+
"aria-live": "off",
|
|
194
|
+
a11y: {
|
|
195
|
+
enabled: false
|
|
196
|
+
},
|
|
197
|
+
...internalProps,
|
|
198
|
+
...swiperProps,
|
|
199
|
+
loop: shouldLoop,
|
|
200
|
+
onBreakpoint: handleOnBreakpoint,
|
|
201
|
+
ref: swiperRef,
|
|
202
|
+
children: [children, hasControls && /*#__PURE__*/_jsxs(_Fragment, {
|
|
203
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
204
|
+
className: `swiper-button-next ${buttonNext}`
|
|
205
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
206
|
+
className: `swiper-button-prev ${buttonPrev}`
|
|
207
|
+
})]
|
|
208
|
+
})]
|
|
209
|
+
})
|
|
210
|
+
});
|
|
208
211
|
};
|
|
209
212
|
Swiper.Item = SwiperItem;
|
|
210
213
|
Swiper.defaultProps = {
|
|
@@ -6,7 +6,10 @@ import ToastContext from "../../providers/toast/context";
|
|
|
6
6
|
* The Toaster component.
|
|
7
7
|
* @returns {JSX}
|
|
8
8
|
*/
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
const Toaster = ({
|
|
10
11
|
render
|
|
11
|
-
}) => /*#__PURE__*/
|
|
12
|
+
}) => /*#__PURE__*/_jsx(ToastContext.Consumer, {
|
|
13
|
+
children: context => render(context)
|
|
14
|
+
});
|
|
12
15
|
export default Toaster;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import isEqual from 'lodash/isEqual';
|
|
2
3
|
import React, { Component } from 'react';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
@@ -8,19 +9,24 @@ import gsap from 'gsap';
|
|
|
8
9
|
* Handles a transition of an object.
|
|
9
10
|
* This component only can have one child element at a time!
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
let Transition = /*#__PURE__*/function (_Component) {
|
|
13
|
+
function Transition() {
|
|
14
|
+
return _Component.apply(this, arguments) || this;
|
|
15
|
+
}
|
|
16
|
+
_inheritsLoose(Transition, _Component);
|
|
17
|
+
var _proto = Transition.prototype;
|
|
12
18
|
/**
|
|
13
19
|
* Runs the transition animation initially.
|
|
14
20
|
*/
|
|
15
|
-
componentDidMount() {
|
|
21
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
16
22
|
this.animate();
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* Checks if transition related props (from/to) have updated and runs the animation.
|
|
21
27
|
* @param {Object} nextProps - The received props.
|
|
22
|
-
|
|
23
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
28
|
+
*/;
|
|
29
|
+
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
24
30
|
if (!isEqual(this.props.from, nextProps.from) || !isEqual(this.props.to, nextProps.to)) {
|
|
25
31
|
this.animate(nextProps);
|
|
26
32
|
}
|
|
@@ -29,8 +35,8 @@ class Transition extends Component {
|
|
|
29
35
|
/**
|
|
30
36
|
* Returns the first child of children.
|
|
31
37
|
* @returns {React.Element}
|
|
32
|
-
|
|
33
|
-
getFirstChild() {
|
|
38
|
+
*/;
|
|
39
|
+
_proto.getFirstChild = function getFirstChild() {
|
|
34
40
|
return React.Children.map(this.props.children, (element, idx) => (/*#__PURE__*/React.cloneElement(element, {
|
|
35
41
|
ref: idx
|
|
36
42
|
})))[0];
|
|
@@ -39,8 +45,8 @@ class Transition extends Component {
|
|
|
39
45
|
/**
|
|
40
46
|
* Sets the transition state and runs the transition animation.
|
|
41
47
|
* @param {Object} props - The props object the animation should be based upon.
|
|
42
|
-
|
|
43
|
-
animate(props = this.props) {
|
|
48
|
+
*/;
|
|
49
|
+
_proto.animate = function animate(props = this.props) {
|
|
44
50
|
// eslint-disable-next-line react/no-find-dom-node, react/no-string-refs
|
|
45
51
|
const element = findDOMNode(this.refs[0]);
|
|
46
52
|
const duration = props.duration / 1000;
|
|
@@ -83,11 +89,12 @@ class Transition extends Component {
|
|
|
83
89
|
/**
|
|
84
90
|
* Renders the component.
|
|
85
91
|
* @returns {JSX}
|
|
86
|
-
|
|
87
|
-
render() {
|
|
92
|
+
*/;
|
|
93
|
+
_proto.render = function render() {
|
|
88
94
|
return React.Children.only(this.getFirstChild());
|
|
89
|
-
}
|
|
90
|
-
|
|
95
|
+
};
|
|
96
|
+
return Transition;
|
|
97
|
+
}(Component);
|
|
91
98
|
Transition.defaultProps = {
|
|
92
99
|
easing: 'Power1.easeOut',
|
|
93
100
|
origin: '0 0 0',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component, Suspense } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import isEqual from 'lodash/isEqual';
|
|
@@ -7,12 +8,18 @@ import styles from "./style";
|
|
|
7
8
|
/**
|
|
8
9
|
* The widget component.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
let Widget = /*#__PURE__*/function (_Component) {
|
|
13
|
+
function Widget() {
|
|
14
|
+
return _Component.apply(this, arguments) || this;
|
|
15
|
+
}
|
|
16
|
+
_inheritsLoose(Widget, _Component);
|
|
17
|
+
var _proto = Widget.prototype;
|
|
11
18
|
/**
|
|
12
19
|
* @param {Object} nextProps The next component props.
|
|
13
20
|
* @return {boolean}
|
|
14
21
|
*/
|
|
15
|
-
shouldComponentUpdate(nextProps) {
|
|
22
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
|
16
23
|
if (this.props.component !== nextProps.component) return true;
|
|
17
24
|
if (!isEqual(this.props.config, nextProps.config)) return true;
|
|
18
25
|
return false;
|
|
@@ -20,8 +27,8 @@ class Widget extends Component {
|
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* @return {JSX}
|
|
23
|
-
|
|
24
|
-
render() {
|
|
30
|
+
*/;
|
|
31
|
+
_proto.render = function render() {
|
|
25
32
|
const {
|
|
26
33
|
col,
|
|
27
34
|
row,
|
|
@@ -32,24 +39,28 @@ class Widget extends Component {
|
|
|
32
39
|
if (!this.props.component) {
|
|
33
40
|
return null;
|
|
34
41
|
}
|
|
35
|
-
return /*#__PURE__*/
|
|
42
|
+
return /*#__PURE__*/_jsx(Grid.Item, {
|
|
36
43
|
className: `common__widgets__widget ${styles.widgetCell({
|
|
37
44
|
col,
|
|
38
45
|
row,
|
|
39
46
|
height,
|
|
40
47
|
width
|
|
41
48
|
})}`,
|
|
42
|
-
component: "div"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
49
|
+
component: "div",
|
|
50
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
51
|
+
className: styles.content,
|
|
52
|
+
children: /*#__PURE__*/_jsx(Suspense, {
|
|
53
|
+
fallback: /*#__PURE__*/_jsx(Loading, {}),
|
|
54
|
+
children: /*#__PURE__*/React.createElement(this.props.component, {
|
|
55
|
+
settings,
|
|
56
|
+
ratio: [width, height]
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return Widget;
|
|
63
|
+
}(Component);
|
|
53
64
|
Widget.defaultProps = {
|
|
54
65
|
component: null
|
|
55
66
|
};
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { mount } from 'enzyme';
|
|
3
3
|
import Grid from "../../../Grid";
|
|
4
4
|
import Widget from "./index";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
jest.mock('react', () => ({
|
|
6
7
|
...jest.requireActual('react'),
|
|
7
8
|
Suspense: function Suspense({
|
|
@@ -15,7 +16,7 @@ jest.mock('react', () => ({
|
|
|
15
16
|
* A dummy component.
|
|
16
17
|
* @returns {JSX}
|
|
17
18
|
*/
|
|
18
|
-
const MyComponent = () => /*#__PURE__*/
|
|
19
|
+
const MyComponent = () => /*#__PURE__*/_jsx("div", {});
|
|
19
20
|
const widgets = {
|
|
20
21
|
'@shopgate/commerce-widgets/image': MyComponent
|
|
21
22
|
};
|
|
@@ -28,7 +29,7 @@ describe('<Widget />', () => {
|
|
|
28
29
|
width: 12,
|
|
29
30
|
height: 6
|
|
30
31
|
};
|
|
31
|
-
const wrapper = mount(/*#__PURE__*/
|
|
32
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Widget, {
|
|
32
33
|
config: config,
|
|
33
34
|
component: widgets[config.type]
|
|
34
35
|
}));
|
|
@@ -43,7 +44,7 @@ describe('<Widget />', () => {
|
|
|
43
44
|
width: 6,
|
|
44
45
|
height: 6
|
|
45
46
|
};
|
|
46
|
-
const wrapper = mount(/*#__PURE__*/
|
|
47
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Widget, {
|
|
47
48
|
config: config,
|
|
48
49
|
component: widgets[config.type],
|
|
49
50
|
cellSize: 100
|
|
@@ -60,7 +61,7 @@ describe('<Widget />', () => {
|
|
|
60
61
|
width: 12,
|
|
61
62
|
height: 6
|
|
62
63
|
};
|
|
63
|
-
const wrapper = mount(/*#__PURE__*/
|
|
64
|
+
const wrapper = mount(/*#__PURE__*/_jsx(Widget, {
|
|
64
65
|
config: config,
|
|
65
66
|
component: widgets[config.type]
|
|
66
67
|
}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import isEqual from 'lodash/isEqual';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
@@ -9,12 +10,18 @@ import shouldShowWidget from "../../helpers/shouldShowWidget";
|
|
|
9
10
|
/**
|
|
10
11
|
* The WidgetGrid component.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
let WidgetGrid = /*#__PURE__*/function (_Component) {
|
|
15
|
+
function WidgetGrid() {
|
|
16
|
+
return _Component.apply(this, arguments) || this;
|
|
17
|
+
}
|
|
18
|
+
_inheritsLoose(WidgetGrid, _Component);
|
|
19
|
+
var _proto = WidgetGrid.prototype;
|
|
13
20
|
/**
|
|
14
21
|
* @param {Object} nextProps The next component props.
|
|
15
22
|
* @return {boolean}
|
|
16
23
|
*/
|
|
17
|
-
shouldComponentUpdate(nextProps) {
|
|
24
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
|
18
25
|
if (!isEqual(this.props.components, nextProps.components)) return true;
|
|
19
26
|
if (!isEqual(this.props.config, nextProps.config)) return true;
|
|
20
27
|
return false;
|
|
@@ -23,8 +30,8 @@ class WidgetGrid extends Component {
|
|
|
23
30
|
/**
|
|
24
31
|
* Render the component.
|
|
25
32
|
* @return {JSX}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
33
|
+
*/;
|
|
34
|
+
_proto.render = function render() {
|
|
28
35
|
const {
|
|
29
36
|
components,
|
|
30
37
|
config
|
|
@@ -36,21 +43,22 @@ class WidgetGrid extends Component {
|
|
|
36
43
|
// TODO: This should not happen within every render call.
|
|
37
44
|
// Sort the widgets by row. This has to happen to take care of the z-index flow.
|
|
38
45
|
const widgets = sortBy(config, ['row']).filter(w => shouldShowWidget(w.settings));
|
|
39
|
-
return /*#__PURE__*/
|
|
40
|
-
className: `${styles} common__widgets__widget-grid
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
46
|
+
return /*#__PURE__*/_jsx("div", {
|
|
47
|
+
className: `${styles} common__widgets__widget-grid`,
|
|
48
|
+
children: Object.keys(widgets).map(key => {
|
|
49
|
+
const widget = widgets[key];
|
|
50
|
+
const widgetKey = `w${key}`;
|
|
51
|
+
// Map to the correct widget component using the `type` key inside the widget.
|
|
52
|
+
const WidgetComponent = components[widget.type];
|
|
53
|
+
return /*#__PURE__*/_jsx(Widget, {
|
|
54
|
+
config: widget,
|
|
55
|
+
component: WidgetComponent
|
|
56
|
+
}, widgetKey);
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
return WidgetGrid;
|
|
61
|
+
}(Component);
|
|
54
62
|
WidgetGrid.defaultProps = {
|
|
55
63
|
config: []
|
|
56
64
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { mount } from 'enzyme';
|
|
3
3
|
import WidgetGrid from "./index";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
jest.mock('react', () => ({
|
|
5
6
|
...jest.requireActual('react'),
|
|
6
7
|
Suspense: function Suspense({
|
|
@@ -14,7 +15,7 @@ jest.mock('react', () => ({
|
|
|
14
15
|
* A mock Image component.
|
|
15
16
|
* @returns {JSX}
|
|
16
17
|
*/
|
|
17
|
-
const Image = () => /*#__PURE__*/
|
|
18
|
+
const Image = () => /*#__PURE__*/_jsx("div", {});
|
|
18
19
|
const components = {
|
|
19
20
|
'@shopgate/commerce-widgets/image': Image
|
|
20
21
|
};
|
|
@@ -31,7 +32,7 @@ describe('<WidgetGrid />', () => {
|
|
|
31
32
|
},
|
|
32
33
|
type: '@shopgate/commerce-widgets/image'
|
|
33
34
|
}];
|
|
34
|
-
const wrapper = mount(/*#__PURE__*/
|
|
35
|
+
const wrapper = mount(/*#__PURE__*/_jsx(WidgetGrid, {
|
|
35
36
|
config: config,
|
|
36
37
|
components: components
|
|
37
38
|
}));
|
|
@@ -39,7 +40,7 @@ describe('<WidgetGrid />', () => {
|
|
|
39
40
|
expect(wrapper.find(Image).length).toEqual(1);
|
|
40
41
|
});
|
|
41
42
|
it('should not render without a `config` prop', () => {
|
|
42
|
-
const wrapper = mount(/*#__PURE__*/
|
|
43
|
+
const wrapper = mount(/*#__PURE__*/_jsx(WidgetGrid, {
|
|
43
44
|
components: components
|
|
44
45
|
}));
|
|
45
46
|
expect(wrapper).toMatchSnapshot();
|