@shopgate/pwa-common 7.30.0-alpha.7 → 7.30.0-alpha.9
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 +48 -6
- package/action-creators/app/index.js +75 -12
- package/action-creators/app/spec.js +96 -1
- package/action-creators/client/index.js +27 -5
- package/action-creators/client/spec.js +44 -1
- package/action-creators/error/index.js +15 -3
- package/action-creators/index.js +9 -1
- package/action-creators/menu/index.js +23 -4
- package/action-creators/menu/spec.js +37 -1
- package/action-creators/modal/index.js +15 -3
- package/action-creators/modal/spec.js +26 -1
- package/action-creators/page/index.js +24 -4
- package/action-creators/page/spec.js +38 -1
- package/action-creators/router/index.js +48 -7
- package/action-creators/url/index.js +24 -4
- package/action-creators/url/spec.js +45 -1
- package/action-creators/user/index.js +90 -13
- package/action-creators/user/spec.js +186 -2
- package/actions/app/handleDeepLink.js +11 -2
- package/actions/app/handleLink.js +62 -6
- package/actions/app/handlePushNotification.js +32 -4
- package/actions/app/handleUniversalLink.js +11 -2
- package/actions/app/registerLinkEvents.js +24 -3
- package/actions/client/fetchClientInformation.js +26 -2
- package/actions/menu/fetchMenu.js +23 -2
- package/actions/modal/closeModal.js +18 -2
- package/actions/modal/promiseMap.js +3 -1
- package/actions/modal/showModal.js +54 -8
- package/actions/page/fetchPageConfig.js +69 -2
- package/actions/page/getPageConfig.js +6 -2
- package/actions/page/index.js +1 -1
- package/actions/router/historyPop.js +12 -2
- package/actions/router/historyPopToRoute.js +27 -2
- package/actions/router/historyPush.js +12 -2
- package/actions/router/historyRedirect.js +21 -2
- package/actions/router/historyReplace.js +20 -3
- package/actions/router/historyReset.js +11 -2
- package/actions/router/historyResetTo.js +12 -2
- package/actions/router/index.js +17 -1
- package/actions/router/routeDidPop.js +11 -2
- package/actions/router/routeDidPush.js +13 -2
- package/actions/router/routeDidReplace.js +11 -2
- package/actions/router/routeDidReset.js +11 -2
- package/actions/router/routeDidUpdate.js +10 -2
- package/actions/router/routeWillPop.js +11 -2
- package/actions/router/routeWillPush.js +13 -2
- package/actions/router/routeWillReplace.js +11 -2
- package/actions/router/routeWillReset.js +11 -2
- package/actions/router/windowOpenOverride.js +10 -2
- package/actions/user/fetchRegisterUrl.js +36 -2
- package/actions/user/fetchUser.js +29 -3
- package/actions/user/getUser.js +6 -2
- package/actions/user/index.js +1 -1
- package/actions/user/login.js +76 -9
- package/actions/user/logout.js +30 -2
- package/collections/AuthRoutes.js +73 -14
- package/collections/Configuration.js +54 -7
- package/collections/EmbeddedMedia.js +84 -11
- package/collections/PersistedReducers.js +41 -6
- package/collections/Redirects.js +103 -17
- package/collections/index.js +5 -1
- package/collections/media-providers/MediaProvider.js +151 -26
- package/collections/media-providers/Vimeo.js +113 -19
- package/collections/media-providers/YouTube.js +74 -14
- package/collections/media-providers/index.js +3 -1
- package/collections/media-providers/style.js +52 -2
- package/components/Backdrop/index.js +95 -6
- package/components/Backdrop/spec.js +23 -1
- package/components/Backdrop/style.js +11 -2
- package/components/Button/index.js +47 -5
- package/components/Button/spec.js +36 -1
- package/components/Button/style.js +6 -1
- package/components/Checkbox/index.js +126 -32
- package/components/Checkbox/spec.js +94 -3
- package/components/Consume/helpers/buildParams.js +13 -2
- package/components/Consume/index.js +14 -2
- package/components/CountdownTimer/index.js +115 -17
- package/components/CountdownTimer/spec.js +126 -12
- package/components/Drawer/index.js +131 -16
- package/components/Drawer/spec.js +76 -1
- package/components/Drawer/style.js +37 -1
- package/components/Dropdown/index.js +65 -6
- package/components/Dropdown/style.js +4 -1
- package/components/Dropdown/transitions.js +34 -1
- package/components/Ellipsis/index.js +16 -2
- package/components/Ellipsis/spec.js +13 -1
- package/components/EmbeddedMedia/index.js +56 -6
- package/components/EmbeddedMedia/spec.js +52 -3
- package/components/ErrorBoundary/connector.js +9 -2
- package/components/ErrorBoundary/index.js +43 -7
- package/components/Grid/components/Item/index.js +40 -4
- package/components/Grid/components/Item/spec.js +23 -1
- package/components/Grid/components/Item/style.js +17 -3
- package/components/Grid/index.js +36 -4
- package/components/Grid/spec.js +23 -1
- package/components/Grid/style.js +11 -2
- package/components/HtmlSanitizer/connector.js +24 -3
- package/components/HtmlSanitizer/index.js +104 -12
- package/components/HtmlSanitizer/spec.js +214 -7
- package/components/I18n/components/FormatDate/index.js +26 -2
- package/components/I18n/components/FormatDate/spec.js +46 -1
- package/components/I18n/components/FormatNumber/index.js +34 -2
- package/components/I18n/components/FormatNumber/spec.js +41 -2
- package/components/I18n/components/FormatPrice/index.js +32 -2
- package/components/I18n/components/FormatPrice/spec.js +46 -1
- package/components/I18n/components/FormatTime/index.js +26 -2
- package/components/I18n/components/FormatTime/spec.js +43 -2
- package/components/I18n/components/I18nProvider/index.js +52 -9
- package/components/I18n/components/I18nProvider/spec.js +39 -1
- package/components/I18n/components/Placeholder/index.js +8 -2
- package/components/I18n/components/Placeholder/spec.js +30 -1
- package/components/I18n/components/Translate/index.js +68 -7
- package/components/I18n/components/Translate/spec.js +30 -1
- package/components/I18n/index.js +16 -1
- package/components/Icon/index.js +25 -2
- package/components/Icon/style.js +6 -1
- package/components/Image/Image.js +176 -19
- package/components/Image/ImageInner.js +48 -2
- package/components/Image/index.js +1 -1
- package/components/Image/style.js +29 -2
- package/components/InfiniteContainer/index.js +381 -49
- package/components/InfiniteContainer/spec.js +199 -10
- package/components/Input/components/DateInput.js +262 -6
- package/components/Input/components/MultiLineInput.js +98 -12
- package/components/Input/components/SimpleInput.js +207 -31
- package/components/Input/index.js +32 -3
- package/components/Input/spec.js +122 -1
- package/components/KeyboardConsumer/index.js +48 -7
- package/components/Link/connector.js +7 -1
- package/components/Link/index.js +96 -11
- package/components/Link/spec.js +56 -1
- package/components/Link/style.js +10 -1
- package/components/List/components/Item/index.js +35 -3
- package/components/List/components/Item/style.js +16 -1
- package/components/List/index.js +20 -2
- package/components/List/spec.js +31 -1
- package/components/Loading/index.js +6 -2
- package/components/Modal/index.js +38 -3
- package/components/Modal/style.js +36 -1
- package/components/ModalContainer/connector.js +17 -3
- package/components/ModalContainer/index.js +36 -3
- package/components/ModalContainer/spec.js +105 -5
- package/components/Picker/components/Button/index.js +34 -2
- package/components/Picker/components/Button/style.js +19 -1
- package/components/Picker/components/List/index.js +33 -2
- package/components/Picker/components/List/style.js +17 -1
- package/components/Picker/components/Modal/index.js +60 -7
- package/components/Picker/components/Modal/style.js +78 -1
- package/components/Picker/index.js +167 -21
- package/components/Picker/spec.js +83 -2
- package/components/Portal/index.js +130 -19
- package/components/ProductCharacteristics/connector.js +33 -4
- package/components/ProductCharacteristics/context.js +2 -1
- package/components/ProductCharacteristics/helpers/index.js +135 -21
- package/components/ProductCharacteristics/index.js +266 -31
- package/components/RangeSlider/components/Handle/index.js +25 -2
- package/components/RangeSlider/components/Handle/style.js +14 -1
- package/components/RangeSlider/helper.js +43 -8
- package/components/RangeSlider/index.js +228 -38
- package/components/RangeSlider/style.js +14 -1
- package/components/Route/RouteNotFound.js +46 -3
- package/components/Route/index.js +78 -10
- package/components/Router/connector.js +9 -2
- package/components/Router/index.js +237 -31
- package/components/ScannerContainer/connector.js +9 -2
- package/components/ScannerContainer/index.js +42 -6
- package/components/Select/components/Item/index.js +20 -4
- package/components/Select/components/Item/style.js +4 -1
- package/components/Select/index.js +149 -28
- package/components/Select/spec.js +86 -2
- package/components/Select/style.js +17 -1
- package/components/SelectBox/components/Item/index.js +47 -5
- package/components/SelectBox/components/Item/style.js +7 -1
- package/components/SelectBox/index.js +173 -17
- package/components/SelectBox/spec.js +59 -3
- package/components/SelectBox/style.js +18 -1
- package/components/Slider/index.js +6 -2
- package/components/SurroundPortals/index.js +26 -2
- package/components/Swiper/components/SwiperItem/index.js +28 -4
- package/components/Swiper/components/SwiperItem/spec.js +21 -1
- package/components/Swiper/components/SwiperItem/styles.js +5 -1
- package/components/Swiper/index.js +210 -18
- package/components/Swiper/styles.js +75 -7
- package/components/Toaster/index.js +10 -2
- package/components/Transition/index.js +89 -13
- package/components/Widgets/components/Widget/index.js +52 -4
- package/components/Widgets/components/Widget/spec.js +68 -3
- package/components/Widgets/components/Widget/style.js +21 -3
- package/components/Widgets/components/WidgetGrid/index.js +52 -7
- package/components/Widgets/components/WidgetGrid/spec.js +46 -2
- package/components/Widgets/components/WidgetGrid/style.js +8 -1
- package/components/Widgets/helpers/shouldShowWidget.js +44 -7
- package/components/Widgets/index.js +127 -15
- package/components/Widgets/spec.js +228 -6
- package/components/index.js +9 -1
- package/constants/ActionTypes.js +97 -19
- package/constants/Configuration.js +12 -2
- package/constants/Device.js +29 -2
- package/constants/DisplayOptions.js +8 -1
- package/constants/MenuIDs.js +2 -1
- package/constants/ModalTypes.js +1 -1
- package/constants/PageIDs.js +1 -1
- package/constants/Pipelines.js +7 -1
- package/constants/Portals.js +136 -3
- package/constants/Registration.js +3 -1
- package/constants/RoutePaths.js +13 -2
- package/constants/Tracking.js +3 -1
- package/constants/client.js +6 -1
- package/constants/ui.js +2 -1
- package/constants/user.js +6 -2
- package/context/index.js +33 -3
- package/helpers/config/index.js +139 -21
- package/helpers/config/mock.js +200 -8
- package/helpers/config/theme.js +50 -4
- package/helpers/data/index.js +204 -29
- package/helpers/data/spec.js +187 -7
- package/helpers/date/index.js +58 -6
- package/helpers/date/spec.js +92 -1
- package/helpers/dom/index.js +48 -11
- package/helpers/environment/index.js +14 -2
- package/helpers/html/decodeHTML.js +7 -1
- package/helpers/html/handleDOM.js +172 -21
- package/helpers/html/parseHTML.js +67 -12
- package/helpers/i18n/getDateFormatter.js +23 -4
- package/helpers/i18n/getNumberFormatter.js +32 -4
- package/helpers/i18n/getPriceFormatter.js +38 -4
- package/helpers/i18n/getTimeFormatter.js +23 -4
- package/helpers/i18n/getTranslator.js +62 -8
- package/helpers/i18n/index.js +5 -1
- package/helpers/i18n/mergeTranslations.js +36 -9
- package/helpers/i18n/messageCache.js +3 -1
- package/helpers/legacy/index.js +47 -9
- package/helpers/modal/withShowModal.js +13 -2
- package/helpers/portals/portalCollection.js +28 -6
- package/helpers/portals/routePortals.js +12 -1
- package/helpers/redux/compareObjects.js +7 -2
- package/helpers/redux/generateResultHash.js +36 -3
- package/helpers/redux/generateSortedHash.js +7 -2
- package/helpers/redux/hasExpired.js +10 -2
- package/helpers/redux/index.js +7 -1
- package/helpers/redux/mutable.js +143 -24
- package/helpers/redux/shouldFetchData.js +46 -10
- package/helpers/redux/shouldFetchFilters.js +17 -4
- package/helpers/router/index.js +49 -5
- package/helpers/style/index.js +43 -4
- package/helpers/style/spec.js +108 -2
- package/helpers/tracking/index.js +52 -9
- package/helpers/validation/index.js +39 -12
- package/helpers/validation/spec.js +10 -1
- package/package.json +3 -4
- package/providers/index.js +4 -1
- package/providers/loading/context.js +2 -1
- package/providers/loading/index.js +137 -22
- package/providers/toast/context.js +2 -1
- package/providers/toast/index.js +105 -11
- package/reducers/client/connectivity.js +22 -2
- package/reducers/client/index.js +7 -1
- package/reducers/client/info.js +27 -2
- package/reducers/index.js +23 -4
- package/reducers/menu/index.js +5 -1
- package/reducers/menu/menusById.js +41 -2
- package/reducers/modal/index.js +14 -2
- package/reducers/page/index.js +68 -5
- package/reducers/router/index.js +48 -2
- package/reducers/url/index.js +42 -3
- package/reducers/user/data.js +27 -2
- package/reducers/user/index.js +7 -1
- package/reducers/user/login.js +65 -2
- package/selectors/client.js +138 -21
- package/selectors/history.js +49 -11
- package/selectors/menu.js +34 -6
- package/selectors/modal.js +15 -4
- package/selectors/page.js +25 -4
- package/selectors/router.js +154 -30
- package/selectors/url.js +25 -4
- package/selectors/user.js +90 -13
- package/store/index.js +60 -6
- package/store/middelwares/logger.js +7 -1
- package/store/middelwares/streams.js +19 -2
- package/streams/app.js +60 -8
- package/streams/client.js +8 -2
- package/streams/error.js +14 -3
- package/streams/index.js +6 -1
- package/streams/interval.js +6 -2
- package/streams/main.js +27 -2
- package/streams/router.js +45 -8
- package/streams/user.js +89 -15
- package/streams/view.js +97 -25
- package/styles/reset/form.js +57 -5
- package/styles/reset/index.js +6 -1
- package/styles/reset/media.js +22 -1
- package/styles/reset/root.js +33 -1
- package/styles/reset/table.js +10 -1
- package/styles/reset/typography.js +26 -1
- package/subscriptions/app.js +148 -17
- package/subscriptions/error.js +292 -13
- package/subscriptions/helpers/buildRegisterUrl.js +25 -6
- package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
- package/subscriptions/helpers/handleLinks.js +267 -25
- package/subscriptions/helpers/pipeline.js +12 -1
- package/subscriptions/history.js +34 -6
- package/subscriptions/index.js +25 -4
- package/subscriptions/menu.js +22 -5
- package/subscriptions/mock.js +39 -7
- package/subscriptions/router.js +336 -23
- package/subscriptions/user.js +93 -3
|
@@ -3,30 +3,55 @@
|
|
|
3
3
|
* @param {number} relativeValue The relative value between [0...1].
|
|
4
4
|
* @param {number} resolution The resolution, must be a value between [0,1...1].
|
|
5
5
|
* @returns {number} The interpolated value.
|
|
6
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
const easeLinear = (relativeValue, resolution) => {
|
|
8
|
+
const inverseResolution = 1.0 / resolution;
|
|
9
|
+
return relativeValue * inverseResolution / inverseResolution;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
7
13
|
* Generates a linear easing callback.
|
|
8
14
|
* @param {number} resolution The discrete step size.
|
|
9
15
|
* @returns {Function} The generated callback.
|
|
10
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export const generateLinearEasingCallback = (resolution = 0.1) => relativeValue => easeLinear(relativeValue, resolution);
|
|
18
|
+
|
|
19
|
+
/**
|
|
11
20
|
* The exponential easing callback.
|
|
12
21
|
* @param {number} relativeValue The relative value between [0...1].
|
|
13
22
|
* @param {number} factor The exponential scale factor.
|
|
14
23
|
* @returns {number} The interpolated value.
|
|
15
|
-
*/
|
|
24
|
+
*/
|
|
25
|
+
const easeExponential = (relativeValue, factor) => relativeValue ** factor;
|
|
26
|
+
|
|
27
|
+
/**
|
|
16
28
|
* Generates an exponential easing callback.
|
|
17
29
|
* @param {number} factor The exponential scale factor.
|
|
18
30
|
* @returns {Function} The generated callback.
|
|
19
|
-
*/
|
|
31
|
+
*/
|
|
32
|
+
export const generateExponentialEasingCallback = (factor = 2.5) => relativeValue => easeExponential(relativeValue, factor);
|
|
33
|
+
|
|
34
|
+
/**
|
|
20
35
|
* Converts a range of [0...1] into a style object.
|
|
21
36
|
* @param {number} min A value in interval [0...1]
|
|
22
37
|
* @param {number} max A value in interval [0...1]
|
|
23
38
|
* @param {number} transitionDuration The duration of the transition.
|
|
24
39
|
* @returns {Object} The generated style object
|
|
25
|
-
*/
|
|
40
|
+
*/
|
|
41
|
+
export const getRangeStyle = (min, max, transitionDuration) => ({
|
|
42
|
+
left: `${Math.min(1, Math.max(0, min)) * 100}%`,
|
|
43
|
+
right: `${(1 - Math.min(1, Math.max(0, max))) * 100}%`,
|
|
44
|
+
transition: transitionDuration > 0 ? `left ${transitionDuration}ms, right ${transitionDuration}ms` : null
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
26
48
|
* Shortcut for retrieving x position of a touch event.
|
|
27
49
|
* @param {TouchEvent} event The TouchEvent
|
|
28
50
|
* @returns {number} The x position
|
|
29
|
-
*/
|
|
51
|
+
*/
|
|
52
|
+
export const getTouchPositionX = event => event.touches[0].pageX;
|
|
53
|
+
|
|
54
|
+
/**
|
|
30
55
|
* Converts a relative slider value into an absolute value.
|
|
31
56
|
* A relative value is a value between [0...1] indicating the position
|
|
32
57
|
* on the slider given its absolute width.
|
|
@@ -37,7 +62,13 @@
|
|
|
37
62
|
* @param {number} max The maximum.
|
|
38
63
|
* @param {boolean} allowRealValues Whether the value should be rounded to the nearest integer.
|
|
39
64
|
* @returns {number} The converted absolute value.
|
|
40
|
-
*/
|
|
65
|
+
*/
|
|
66
|
+
export const getAbsoluteValue = (value, min, max, allowRealValues = false) => {
|
|
67
|
+
const result = min + (max - min) * value;
|
|
68
|
+
return Math.min(max, Math.max(min, allowRealValues ? result : Math.round(result)));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
41
72
|
* Converts an absolute slider value into a relative value.
|
|
42
73
|
* An absolute value is a value in screen space coordinates. This value must be
|
|
43
74
|
* between [0...offsetWidth] of the price range slider.
|
|
@@ -47,4 +78,8 @@
|
|
|
47
78
|
* @param {number} min The minimum.
|
|
48
79
|
* @param {number} max The maximum.
|
|
49
80
|
* @returns {number} The converted relative value.
|
|
50
|
-
*/
|
|
81
|
+
*/
|
|
82
|
+
export const getRelativeValue = (value, min, max) => {
|
|
83
|
+
const result = (value - min) / (max - min);
|
|
84
|
+
return Math.min(1, Math.max(0, result));
|
|
85
|
+
};
|
|
@@ -1,58 +1,248 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { logger } from '@shopgate/pwa-core/helpers';
|
|
4
|
+
import styles from "./style";
|
|
5
|
+
import RangeSliderHandle from "./components/Handle";
|
|
6
|
+
import { generateLinearEasingCallback, generateExponentialEasingCallback, getRangeStyle, getTouchPositionX, getAbsoluteValue, getRelativeValue } from "./helper";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* The range slider component.
|
|
3
10
|
* @deprecated Will be remove in v7.0.0.
|
|
4
11
|
* Please use `import { RangeSlider } from '@shopgate/engage/components'` instead.
|
|
5
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
class RangeSlider extends Component {
|
|
14
|
+
/**
|
|
6
15
|
* Constructor
|
|
7
16
|
* @param {Object} props The component properties
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
*/
|
|
18
|
+
constructor(props) {
|
|
19
|
+
super(props);
|
|
20
|
+
/**
|
|
21
|
+
* Processes touch start events on handles.
|
|
22
|
+
* @param {Object} event The touch event
|
|
23
|
+
* @param {number} index The index of the touched handle.
|
|
24
|
+
*/
|
|
25
|
+
this.handleTouchStart = (event, index) => {
|
|
26
|
+
this.draggedHandle = index;
|
|
27
|
+
|
|
28
|
+
// Calculate the relative offset to the handles center
|
|
29
|
+
const handleDOMElement = event.target;
|
|
30
|
+
// Get the handles bounding rectangle ...
|
|
31
|
+
const handleRect = handleDOMElement.getBoundingClientRect();
|
|
32
|
+
// ... and calculate its absolute center.
|
|
33
|
+
const handleCenterX = handleRect.left + handleDOMElement.offsetWidth / 2;
|
|
34
|
+
// Store the signed distanced between the current touch offset and the handle center.
|
|
35
|
+
this.touchOffset = getTouchPositionX(event) - handleCenterX;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Processes move events on handles.
|
|
39
|
+
* @param {Object} event The touch event
|
|
40
|
+
*/
|
|
41
|
+
this.handleTouchMove = event => {
|
|
42
|
+
if (this.props.min === this.props.max) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (this.draggedHandle === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const {
|
|
49
|
+
offsetWidth,
|
|
50
|
+
offsetLeft
|
|
51
|
+
} = this.domElement;
|
|
52
|
+
// Calculate the absolute offset where the element was touched...
|
|
53
|
+
let deltaX = getTouchPositionX(event) - offsetLeft - this.touchOffset;
|
|
54
|
+
|
|
55
|
+
// ...and convert it into a relative value between [0...1].
|
|
56
|
+
deltaX = Math.max(0, Math.min(1, deltaX / offsetWidth));
|
|
57
|
+
const stateUpdate = {};
|
|
58
|
+
if (this.draggedHandle === 1) {
|
|
59
|
+
// Right handle dragged
|
|
60
|
+
if (this.state.rangeMin < deltaX) {
|
|
61
|
+
stateUpdate.rangeMax = Math.min(1, deltaX);
|
|
62
|
+
this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMax - this.state.rangeMax);
|
|
63
|
+
} else {
|
|
64
|
+
// Not in valid range, swap handles
|
|
65
|
+
this.draggedHandle = 0;
|
|
66
|
+
stateUpdate.rangeMax = this.state.rangeMin;
|
|
67
|
+
stateUpdate.rangeMin = deltaX;
|
|
68
|
+
this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMin - this.state.rangeMin);
|
|
69
|
+
}
|
|
70
|
+
} else if (this.draggedHandle === 0) {
|
|
71
|
+
// Left handle dragged
|
|
72
|
+
if (this.state.rangeMax > deltaX) {
|
|
73
|
+
stateUpdate.rangeMin = Math.max(0, deltaX);
|
|
74
|
+
this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMin - this.state.rangeMin);
|
|
75
|
+
} else {
|
|
76
|
+
// Not in valid range, swap handles
|
|
77
|
+
this.draggedHandle = 1;
|
|
78
|
+
stateUpdate.rangeMin = this.state.rangeMax;
|
|
79
|
+
stateUpdate.rangeMax = deltaX;
|
|
80
|
+
this.draggedHandlePixelOffset = Math.abs(stateUpdate.rangeMax - this.state.rangeMax);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.draggedHandlePixelOffset *= this.domElement.offsetWidth;
|
|
84
|
+
this.setState(stateUpdate, this.triggerChangeCallback);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Processes global touch end events for handles.
|
|
88
|
+
* @param {Object} e The touch event
|
|
89
|
+
*/
|
|
90
|
+
this.handleTouchEnd = () => {
|
|
91
|
+
this.touchOffset = 0;
|
|
92
|
+
this.draggedHandle = null;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Processes outer range touch end events.
|
|
96
|
+
* @param {Object} event The touch event
|
|
97
|
+
*/
|
|
98
|
+
this.handleRangeTouch = event => {
|
|
99
|
+
const {
|
|
100
|
+
offsetWidth,
|
|
101
|
+
offsetLeft
|
|
102
|
+
} = this.domElement;
|
|
103
|
+
const dx = (getTouchPositionX(event) - offsetLeft) / offsetWidth;
|
|
104
|
+
const d0 = Math.abs(this.state.rangeMin - dx);
|
|
105
|
+
const d1 = Math.abs(this.state.rangeMax - dx);
|
|
106
|
+
if (d0 < d1) {
|
|
107
|
+
this.draggedHandle = 0;
|
|
108
|
+
} else {
|
|
109
|
+
this.draggedHandle = 1;
|
|
110
|
+
}
|
|
111
|
+
this.handleTouchMove(event);
|
|
112
|
+
};
|
|
113
|
+
logger.warn('===== RangeSlider deprecated =====\nThe RangeSlider component and it\'s related components (@shopgate/pwa-common/component/RangeSlider) are deprecated and will be removed in @shopgate/engage v7.0.0.\nPlease use: import { RangeSlider } from \'@shopgate/engage/components\'.\n===================================');
|
|
114
|
+
this.draggedHandle = null; // 0 for left handle, 1 for right handle or null
|
|
115
|
+
this.domElement = null;
|
|
116
|
+
this.touchOffset = 0;
|
|
117
|
+
this.draggedHandlePixelOffset = 0; // The absolute pixel delta of the last handle move event.
|
|
118
|
+
|
|
119
|
+
this.state = this.getRange(props);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
34
123
|
* Sets the global event listeners when component mounts.
|
|
35
|
-
*/
|
|
124
|
+
*/
|
|
125
|
+
componentDidMount() {
|
|
126
|
+
document.addEventListener('touchend', this.handleTouchEnd);
|
|
127
|
+
document.addEventListener('touchmove', this.handleTouchMove);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
36
131
|
* Updates the component properties.
|
|
37
132
|
* @param {Object} newProps The new component properties.
|
|
38
|
-
*/
|
|
133
|
+
*/
|
|
134
|
+
UNSAFE_componentWillReceiveProps(newProps) {
|
|
135
|
+
this.setState(this.getRange(newProps));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
39
139
|
* Removes the global event listeners when component unmounts.
|
|
40
|
-
*/
|
|
140
|
+
*/
|
|
141
|
+
componentWillUnmount() {
|
|
142
|
+
document.removeEventListener('touchend', this.handleTouchEnd);
|
|
143
|
+
document.removeEventListener('touchmove', this.handleTouchMove);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
41
147
|
* Get the easing function.
|
|
42
|
-
*/
|
|
148
|
+
*/
|
|
149
|
+
get ease() {
|
|
150
|
+
return {
|
|
151
|
+
linear: generateLinearEasingCallback(this.props.resolution),
|
|
152
|
+
exponential: generateExponentialEasingCallback(this.props.factor)
|
|
153
|
+
}[this.props.easing];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
43
157
|
* Get the function to invert an eased value to it's original value.
|
|
44
|
-
*/
|
|
158
|
+
*/
|
|
159
|
+
get invertedEase() {
|
|
160
|
+
return {
|
|
161
|
+
linear: generateLinearEasingCallback(this.props.resolution),
|
|
162
|
+
exponential: generateExponentialEasingCallback(1 / this.props.factor)
|
|
163
|
+
}[this.props.easing];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
45
167
|
* Get range min and max from props.
|
|
46
168
|
* @param {Object} props The component props.
|
|
47
169
|
* @returns {Object} The new state
|
|
48
|
-
*/
|
|
170
|
+
*/
|
|
171
|
+
getRange(props) {
|
|
172
|
+
const {
|
|
173
|
+
value,
|
|
174
|
+
min,
|
|
175
|
+
max
|
|
176
|
+
} = props;
|
|
177
|
+
return {
|
|
178
|
+
rangeMin: this.invertedEase(getRelativeValue(value[0], min, max)),
|
|
179
|
+
rangeMax: this.invertedEase(getRelativeValue(value[1], min, max))
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
49
183
|
* Calls the change callback in case of a state update.
|
|
50
|
-
*/
|
|
184
|
+
*/
|
|
185
|
+
triggerChangeCallback() {
|
|
186
|
+
const {
|
|
187
|
+
value,
|
|
188
|
+
onChange,
|
|
189
|
+
min,
|
|
190
|
+
max
|
|
191
|
+
} = this.props;
|
|
192
|
+
if (!onChange) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const newRange = [getAbsoluteValue(this.ease(this.state.rangeMin), min, max, true), getAbsoluteValue(this.ease(this.state.rangeMax), min, max, true)];
|
|
196
|
+
if (newRange !== value) {
|
|
197
|
+
onChange(newRange);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
51
202
|
* Creates a new handle component.
|
|
52
203
|
* @param {number} index The index of the component. Must be either 0 or 1.
|
|
53
204
|
* @returns {JSX}
|
|
54
|
-
*/
|
|
205
|
+
*/
|
|
206
|
+
makeHandle(index) {
|
|
207
|
+
return /*#__PURE__*/React.createElement(RangeSliderHandle, {
|
|
208
|
+
index: index,
|
|
209
|
+
onTouchStart: this.handleTouchStart,
|
|
210
|
+
active: this.draggedHandle === index,
|
|
211
|
+
classNames: this.props.classNames
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
55
216
|
* Renders the component.
|
|
56
217
|
* @returns {JSX}
|
|
57
|
-
*/
|
|
58
|
-
|
|
218
|
+
*/
|
|
219
|
+
render() {
|
|
220
|
+
// Calculate the animation speed.
|
|
221
|
+
const animationSpeed = Math.round(1000 / this.props.animationSpeed * this.draggedHandlePixelOffset);
|
|
222
|
+
const rangeStyle = getRangeStyle(this.state.rangeMin, this.state.rangeMax, animationSpeed > 10 ? animationSpeed : 0);
|
|
223
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
224
|
+
className: `${this.props.classNames.container || ''} common__range-slider`,
|
|
225
|
+
onTouchStart: this.handleRangeTouch
|
|
226
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
227
|
+
className: `${this.props.classNames.outerRange || ''} ${styles.outerRange}`,
|
|
228
|
+
ref: ref => {
|
|
229
|
+
this.domElement = ref;
|
|
230
|
+
}
|
|
231
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
232
|
+
className: `${this.props.classNames.range || ''} ${styles.range}`,
|
|
233
|
+
style: rangeStyle
|
|
234
|
+
}, this.makeHandle(0), this.makeHandle(1))));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
RangeSlider.defaultProps = {
|
|
238
|
+
animationSpeed: 500,
|
|
239
|
+
classNames: {},
|
|
240
|
+
easing: 'linear',
|
|
241
|
+
factor: 2,
|
|
242
|
+
max: 100,
|
|
243
|
+
min: 0,
|
|
244
|
+
resolution: 1,
|
|
245
|
+
value: [0, 100],
|
|
246
|
+
onChange: null
|
|
247
|
+
};
|
|
248
|
+
export default RangeSlider;
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
const outerRange = css({
|
|
3
|
+
minHeight: 1,
|
|
4
|
+
position: 'relative'
|
|
5
|
+
}).toString();
|
|
6
|
+
const range = css({
|
|
7
|
+
left: 0,
|
|
8
|
+
right: 0,
|
|
9
|
+
position: 'absolute'
|
|
10
|
+
}).toString();
|
|
11
|
+
export default {
|
|
12
|
+
outerRange,
|
|
13
|
+
range
|
|
14
|
+
};
|
|
@@ -1,5 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { router } from '@virtuous/conductor';
|
|
4
|
+
import { RouteContext, RouterContext } from '@virtuous/react-conductor';
|
|
5
|
+
import ErrorBoundary from "../ErrorBoundary";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* The RouteNotFound component
|
|
3
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
class RouteNotFound extends React.Component {
|
|
11
|
+
/**
|
|
12
|
+
* @returns {Object}
|
|
13
|
+
*/
|
|
14
|
+
get currentRoute() {
|
|
15
|
+
const {
|
|
16
|
+
[router.routeIndex]: [, route]
|
|
17
|
+
} = this.context.stack;
|
|
18
|
+
return route;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
4
22
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
render() {
|
|
25
|
+
if (router.match(this.currentRoute.pathname)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const {
|
|
29
|
+
component: Component
|
|
30
|
+
} = this.props;
|
|
31
|
+
const {
|
|
32
|
+
setPattern,
|
|
33
|
+
...context
|
|
34
|
+
} = this.currentRoute;
|
|
35
|
+
context.open = true;
|
|
36
|
+
context.visible = true;
|
|
37
|
+
context.pattern = '';
|
|
38
|
+
context.is404 = true;
|
|
39
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
40
|
+
key: "error.404"
|
|
41
|
+
}, /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
42
|
+
key: "404",
|
|
43
|
+
value: context
|
|
44
|
+
}, /*#__PURE__*/React.createElement(Component, null)));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
RouteNotFound.contextType = RouterContext;
|
|
48
|
+
export default RouteNotFound;
|
|
@@ -1,19 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { Suspense } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { router } from '@virtuous/conductor';
|
|
4
|
+
import { RouteContext, RouterContext } from '@virtuous/react-conductor';
|
|
5
|
+
import Loading from "../Loading";
|
|
6
|
+
import ErrorBoundary from "../ErrorBoundary";
|
|
7
|
+
import RouteNotFound from "./RouteNotFound";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* The Route component.
|
|
3
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
class Route extends React.Component {
|
|
13
|
+
/**
|
|
14
|
+
* @param {Object} props The component props.
|
|
15
|
+
*/
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
router.register(props.pattern, props.transform);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
4
22
|
* TODO: Move to router
|
|
5
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
get currentRoute() {
|
|
25
|
+
const {
|
|
26
|
+
[router.routeIndex]: [, route]
|
|
27
|
+
} = this.context.stack;
|
|
28
|
+
return route;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
6
32
|
* @returns {JSX}
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
33
|
+
*/
|
|
34
|
+
render() {
|
|
35
|
+
const {
|
|
36
|
+
cache,
|
|
37
|
+
component: Component,
|
|
38
|
+
pattern
|
|
39
|
+
} = this.props;
|
|
40
|
+
let matches = [];
|
|
41
|
+
|
|
42
|
+
// If the current pattern does not match the whitelist but matches the current route
|
|
43
|
+
// then add the current route as the only match.
|
|
44
|
+
if (!cache && pattern === this.currentRoute.pattern) {
|
|
45
|
+
matches = [[this.currentRoute.id, this.currentRoute]];
|
|
46
|
+
} else if (cache) {
|
|
47
|
+
const subset = this.context.stack.slice(0, router.routeIndex + 1);
|
|
48
|
+
// Find matching patterns.
|
|
49
|
+
matches = subset.filter(([, route]) => route.pattern === pattern);
|
|
50
|
+
}
|
|
51
|
+
if (!matches.length) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return matches.map(([, route]) => {
|
|
55
|
+
const {
|
|
56
|
+
setPattern,
|
|
57
|
+
...context
|
|
58
|
+
} = route;
|
|
59
|
+
context.open = true;
|
|
60
|
+
context.visible = route.id === this.currentRoute.id;
|
|
61
|
+
/**
|
|
11
62
|
* When a route is "replaced" the router doesn't assign a new route id to the old route
|
|
12
63
|
* stack entry. This can cause issues when a route is replaced by itself, since the content
|
|
13
64
|
* will not remount out of the box.
|
|
14
65
|
*
|
|
15
66
|
* The "replaceRouteId" state prop is injected by the "historyReplace" action. It's used
|
|
16
67
|
* to enforce re-remounting routes which where replaced by itself.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
|
|
68
|
+
*/
|
|
69
|
+
const replaceRouteId = context?.state?.replaceRouteId || '';
|
|
70
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
71
|
+
key: `error.${route.id}_${replaceRouteId}`
|
|
72
|
+
}, /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
73
|
+
key: `${route.id}_${replaceRouteId}`,
|
|
74
|
+
value: context
|
|
75
|
+
}, /*#__PURE__*/React.createElement(Suspense, {
|
|
76
|
+
fallback: /*#__PURE__*/React.createElement(Loading, null)
|
|
77
|
+
}, /*#__PURE__*/React.createElement(Component, null))));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
Route.contextType = RouterContext;
|
|
82
|
+
Route.NotFound = RouteNotFound;
|
|
83
|
+
Route.defaultProps = {
|
|
84
|
+
cache: false,
|
|
85
|
+
transform: null
|
|
86
|
+
};
|
|
87
|
+
export default Route;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import{connect}from'react-redux';
|
|
1
|
+
import { connect } from 'react-redux';
|
|
2
|
+
import { isUserLoggedIn } from "../../selectors/user";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* @param {Object} state The current application state.
|
|
3
6
|
* @return {Object} The extended component props.
|
|
4
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const mapStateToProps = state => ({
|
|
9
|
+
isUserLoggedIn: isUserLoggedIn(state)
|
|
10
|
+
});
|
|
11
|
+
export default connect(mapStateToProps);
|