@shopgate/pwa-common 7.30.0-alpha.6 → 7.30.0-alpha.8
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 +207 -6
- 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 +17 -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 +213 -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 -3
- 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
package/helpers/redux/mutable.js
CHANGED
|
@@ -1,58 +1,177 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
import "core-js/modules/es.string.replace.js";
|
|
3
|
+
import noop from 'lodash/noop';
|
|
4
|
+
import { isObject } from "../validation";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* @typedef {Object} MutableFunction
|
|
3
8
|
* @property {Function} replace Replaces the original functionality with a custom function.
|
|
4
9
|
* @property {Function} restore Restores the original function.
|
|
5
10
|
* @property {Function} reset Restores the original function and removes all pre-processes steps.
|
|
6
11
|
* @property {Function} useBefore Adds a pre-processing step func.
|
|
7
12
|
* @property {Function} original Original function
|
|
8
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const BEFORE_ACTION_NEXT = 'next';
|
|
16
|
+
const BEFORE_ACTION_SKIP_REST = 'skipRest';
|
|
17
|
+
const BEFORE_ACTION_STOP = 'stop';
|
|
18
|
+
|
|
19
|
+
/**
|
|
9
20
|
* Defines parameters to be used by the next step or mutable function.
|
|
10
21
|
* @param {*} args Transforms an argument list to be consumed by the next step or
|
|
11
22
|
* @returns {Object}
|
|
12
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
export function next(...args) {
|
|
25
|
+
return {
|
|
26
|
+
action: BEFORE_ACTION_NEXT,
|
|
27
|
+
args
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
13
32
|
* Causes the stack to skip forward to processing the mutable using the given arguments.
|
|
14
33
|
* @param {*} [args] A number of arguments to be passed to the mutable. This is optional.
|
|
15
34
|
* @returns {Object}
|
|
16
|
-
*/
|
|
35
|
+
*/
|
|
36
|
+
export function skipRest(...args) {
|
|
37
|
+
return {
|
|
38
|
+
action: BEFORE_ACTION_SKIP_REST,
|
|
39
|
+
args
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
17
44
|
* Causes the stack to stop processing any further actions. On stop only one return value possible.
|
|
18
45
|
* @param {*} [arg] Optional final result value.
|
|
19
46
|
* @returns {Object}
|
|
20
|
-
*/
|
|
47
|
+
*/
|
|
48
|
+
export function stop(arg) {
|
|
49
|
+
return {
|
|
50
|
+
action: BEFORE_ACTION_STOP,
|
|
51
|
+
args: arg
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
21
56
|
* Public api export
|
|
22
57
|
* @type {{next: Function, stop: Function, skipRest: Function}}
|
|
23
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
export const mutableActions = {
|
|
60
|
+
next,
|
|
61
|
+
skipRest,
|
|
62
|
+
stop
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
24
66
|
* Takes a function and makes it mutable.
|
|
25
67
|
* @template {Function} T
|
|
26
68
|
* @param {T} func Original function to convert to a mutable
|
|
27
69
|
* @returns {T}
|
|
28
|
-
*/
|
|
70
|
+
*/
|
|
71
|
+
export const mutable = func => {
|
|
72
|
+
const original = func;
|
|
73
|
+
let current = func;
|
|
74
|
+
const steps = [];
|
|
75
|
+
|
|
76
|
+
/**
|
|
29
77
|
* Takes the pre-processing steps and calls all step functions, as well as the mutable function
|
|
30
78
|
* afterwards. Each step can transform the arguments, that are passed in to the next step in the
|
|
31
79
|
* stack and ultimately to the mutable function.
|
|
32
80
|
* @param {*} args Arguments passed down to the mutable and its pre-processor actions.
|
|
33
81
|
* @returns {Function} A function to be consumed by redux
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
82
|
+
*/
|
|
83
|
+
function mutableFunc(...args) {
|
|
84
|
+
let mutatedArgs = args;
|
|
85
|
+
let runAction = true;
|
|
86
|
+
|
|
87
|
+
// Execute pre-processing steps, if any available.
|
|
88
|
+
if (steps.length > 0) {
|
|
89
|
+
mutatedArgs = steps.reduce((acc, step, i, arr) => {
|
|
90
|
+
// Call next step func in the pipeline with mutated args
|
|
91
|
+
let res = step(...acc);
|
|
92
|
+
|
|
93
|
+
// Keep params unchanged if the step did not perform any change action at all
|
|
94
|
+
if (!isObject(res)) {
|
|
95
|
+
return acc;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Unpack arguments from the "useBefore" pre-processor with "next" action.
|
|
99
|
+
if (res.action === BEFORE_ACTION_NEXT) {
|
|
100
|
+
if (res.args && res.args.length > 0) {
|
|
101
|
+
res = res.args;
|
|
102
|
+
} else {
|
|
103
|
+
res = args;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Unpack arguments from the "useBefore" pre-processor with "skipRest" action.
|
|
108
|
+
if (res.action === BEFORE_ACTION_SKIP_REST) {
|
|
109
|
+
arr.splice(-(arr.length - i));
|
|
110
|
+
if (res.args && res.args.length > 0) {
|
|
111
|
+
res = res.args;
|
|
112
|
+
} else {
|
|
113
|
+
res = args;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Check if the step requested to stop any further processing including the action itself
|
|
118
|
+
if (res.action === BEFORE_ACTION_STOP) {
|
|
119
|
+
// Cut off all following step functions including the mutable func
|
|
120
|
+
arr.splice(-(arr.length - i));
|
|
121
|
+
runAction = false;
|
|
122
|
+
res = res.args;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Replace arguments for the next step to get.
|
|
126
|
+
return res;
|
|
127
|
+
}, args);
|
|
128
|
+
}
|
|
129
|
+
if (!runAction) {
|
|
130
|
+
// the return value here gets passed to the dispatch() so it must be a function or action obj
|
|
131
|
+
return noop;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Call the actual mutable
|
|
135
|
+
return current(...mutatedArgs);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
45
139
|
* Replaces the original functionality with a custom function.
|
|
46
140
|
* @param {Function} customFunc The function to execute instead of the original one.
|
|
47
|
-
*/
|
|
48
|
-
mutableFunc.
|
|
141
|
+
*/
|
|
142
|
+
mutableFunc.replace = customFunc => {
|
|
143
|
+
current = customFunc;
|
|
144
|
+
|
|
145
|
+
// Allow access to the current mutation.
|
|
146
|
+
mutableFunc.current = current;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
49
150
|
* Restores the original func, while keeping additional functions to be called beforehand.
|
|
50
|
-
*/
|
|
151
|
+
*/
|
|
152
|
+
mutableFunc.restore = () => {
|
|
153
|
+
current = original;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
51
157
|
* Resets the whole mutable to its initial state, restoring the original functionality and
|
|
52
158
|
* dropping all injected functions.
|
|
53
|
-
*/
|
|
159
|
+
*/
|
|
160
|
+
mutableFunc.reset = () => {
|
|
161
|
+
current = original;
|
|
162
|
+
steps.length = 0;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
54
166
|
* Adds a pre-processing step func to a list to be called before the actual functionality
|
|
55
167
|
* executes. Each step can modify the arguments, passed down to the next step or the mutable.
|
|
56
168
|
* @param {Function} stepFunc The function to be executed before
|
|
57
|
-
*/
|
|
58
|
-
mutableFunc.
|
|
169
|
+
*/
|
|
170
|
+
mutableFunc.useBefore = stepFunc => {
|
|
171
|
+
steps.push(stepFunc);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// Allow access to the original function.
|
|
175
|
+
mutableFunc.original = original;
|
|
176
|
+
return mutableFunc;
|
|
177
|
+
};
|
|
@@ -1,16 +1,52 @@
|
|
|
1
|
-
import{isObject}from"../validation"
|
|
1
|
+
import { isObject } from "../validation";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Checks if an item can be fetched or (only when the itemKey parameter is set) if there is a
|
|
3
5
|
* certain key inside the item that is filled with data.
|
|
4
6
|
* @param {Object} item The item to check.
|
|
5
7
|
* @param {string} [itemKey=null] A key of a property to check additionally.
|
|
6
8
|
* @param {string} [requiredCount=null] The number of required products that should be in the store.
|
|
7
9
|
* @return {boolean} Whether it can be fetched.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if(!item
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if
|
|
16
|
-
if(
|
|
10
|
+
*/
|
|
11
|
+
export function shouldFetchData(item, itemKey = null, requiredCount = null) {
|
|
12
|
+
// Get data if we have none.
|
|
13
|
+
if (!item) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Fetch data if we have an empty object in the store.
|
|
18
|
+
if (isObject(item) && Object.keys(item).length === 0) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check that the item is not fetching currently.
|
|
23
|
+
if (!item.isFetching) {
|
|
24
|
+
// Fetch data if the expiry date has expired or is set to 0 (initially set).
|
|
25
|
+
if (item.expires === 0 || item.expires && item.expires > 0 && item.expires < Date.now()) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check for a specific key inside items and fetch it if it's not found.
|
|
30
|
+
if (itemKey && Array.isArray(item[itemKey])) {
|
|
31
|
+
const {
|
|
32
|
+
totalResultCount = item[itemKey].length // fallback to original items length
|
|
33
|
+
} = item;
|
|
34
|
+
|
|
35
|
+
// 1. Fetch by requiredCount.
|
|
36
|
+
if (requiredCount) {
|
|
37
|
+
const assertCount = Math.min(requiredCount, totalResultCount);
|
|
38
|
+
|
|
39
|
+
// Fetch is needed to assert N of items in store.
|
|
40
|
+
if (item[itemKey].length !== assertCount) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 2. Sync items when totalResultCount is less
|
|
46
|
+
if (!requiredCount && item[itemKey].length > totalResultCount) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import{isObject}from"../validation";
|
|
1
|
+
import { isObject } from "../validation";
|
|
2
|
+
import { hasExpired } from "./hasExpired";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Determine if there should be a request to fetch the filter data.
|
|
3
6
|
* @param {Object} item The filter object.
|
|
4
7
|
* @returns {boolean}
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
if
|
|
8
|
+
*/
|
|
9
|
+
export function shouldFetchFilters(item) {
|
|
10
|
+
// Get data if we no item.
|
|
11
|
+
if (!item) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Fetch data if we have an empty object in the store.
|
|
16
|
+
if (isObject(item) && Object.keys(item).length === 0) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return hasExpired(item);
|
|
20
|
+
}
|
package/helpers/router/index.js
CHANGED
|
@@ -1,15 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
import { createBrowserHistory } from 'history';
|
|
3
|
+
import URLSearchParams from 'url-search-params';
|
|
4
|
+
import { router } from '@virtuous/conductor';
|
|
5
|
+
const match = /^(.*)index.html/.exec(window.location.pathname);
|
|
6
|
+
const {
|
|
7
|
+
getCurrentRoute
|
|
8
|
+
} = router;
|
|
9
|
+
/**
|
|
2
10
|
* @deprecated
|
|
3
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
export { getCurrentRoute, router };
|
|
13
|
+
|
|
14
|
+
/**
|
|
4
15
|
* Creates the router history.
|
|
5
16
|
* @returns {Object}
|
|
6
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
export const history = () => createBrowserHistory({
|
|
19
|
+
basename: match ? match[0] : ''
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
7
23
|
* Transforms a given URL query string to an object.
|
|
8
24
|
* @param {string} queryString An URL query string.
|
|
9
25
|
* @returns {Object}
|
|
10
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
export const parseQueryStringToObject = (queryString = null) => {
|
|
28
|
+
if (!queryString) {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
const urlParams = new URLSearchParams(queryString);
|
|
32
|
+
const keys = Array.from(urlParams.keys());
|
|
33
|
+
return keys.reduce((obj, key) => ({
|
|
34
|
+
...obj,
|
|
35
|
+
[key]: urlParams.get(key)
|
|
36
|
+
}), {});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
11
40
|
* Transforms a given object to an URL query string.
|
|
12
41
|
* @param {Object} obj An object with keys/values.
|
|
13
42
|
* @param {boolean} [includePrefix=true] If true a `?` is prefixed.
|
|
14
43
|
* @returns {string}
|
|
15
|
-
*/
|
|
44
|
+
*/
|
|
45
|
+
export const parseObjectToQueryString = (obj, includePrefix = true) => {
|
|
46
|
+
if (!obj) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
const urlParams = new URLSearchParams();
|
|
50
|
+
const keys = Object.keys(obj);
|
|
51
|
+
if (keys.length === 0) {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
keys.forEach(key => urlParams.set(key, obj[key]));
|
|
55
|
+
if (includePrefix) {
|
|
56
|
+
return `?${urlParams.toString()}`;
|
|
57
|
+
}
|
|
58
|
+
return urlParams.toString();
|
|
59
|
+
};
|
package/helpers/style/index.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { logger } from '@shopgate/pwa-core/helpers';
|
|
2
|
+
import { isNumber } from "../validation";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Calculates a rem value for a passed pixel value. The calculation is based on the root
|
|
3
6
|
* font size that is defined inside the template's font styles.
|
|
4
7
|
* @param {number} pixels The source value
|
|
5
8
|
* @returns {string} The result value
|
|
6
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
export const rem = pixels => {
|
|
11
|
+
let result = '';
|
|
12
|
+
if (isNumber(pixels) && pixels >= 0) {
|
|
13
|
+
result = `${1 / 16 * pixels}rem`;
|
|
14
|
+
} else {
|
|
15
|
+
result = '1rem';
|
|
16
|
+
logger.error(`rem(): Invalid value (${pixels})`);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
7
22
|
* Returns an object ready to use with glamor with one pixel size property.
|
|
8
23
|
* For example physicalPixelSize('height', 1) would result in:
|
|
9
24
|
* - height: 1px for screen density 1,
|
|
@@ -12,5 +27,29 @@ function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj
|
|
|
12
27
|
* @param {string} property Css property name.
|
|
13
28
|
* @param {number} [size=1] Requested physical pixel size.
|
|
14
29
|
* @returns {Object}
|
|
15
|
-
*/
|
|
16
|
-
|
|
30
|
+
*/
|
|
31
|
+
export const physicalPixelSize = (property, size = 1) => {
|
|
32
|
+
// Android doesn't accept decimals.
|
|
33
|
+
if (navigator && navigator.userAgent && navigator.userAgent.includes('Android')) {
|
|
34
|
+
return {
|
|
35
|
+
[property]: size
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const double = Math.round(size / 2 * 100) / 100;
|
|
39
|
+
const triple = Math.round(size / 3 * 100) / 100;
|
|
40
|
+
return {
|
|
41
|
+
[property]: size,
|
|
42
|
+
'@media (min-device-pixel-ratio: 2)': {
|
|
43
|
+
[property]: double
|
|
44
|
+
},
|
|
45
|
+
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
46
|
+
[property]: double
|
|
47
|
+
},
|
|
48
|
+
'@media (min-device-pixel-ratio: 3)': {
|
|
49
|
+
[property]: triple
|
|
50
|
+
},
|
|
51
|
+
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
52
|
+
[property]: triple
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
package/helpers/style/spec.js
CHANGED
|
@@ -1,2 +1,108 @@
|
|
|
1
|
-
import{rem,physicalPixelSize}from"./index";
|
|
2
|
-
|
|
1
|
+
import { rem, physicalPixelSize } from "./index";
|
|
2
|
+
describe('style helper', () => {
|
|
3
|
+
describe('rem helper with 16px rootSize', () => {
|
|
4
|
+
it('should output 0.875rem for 16px input', () => {
|
|
5
|
+
expect(rem(16)).toBe('1rem');
|
|
6
|
+
});
|
|
7
|
+
it('should output 0.875rem for 14px input', () => {
|
|
8
|
+
expect(rem(14)).toBe('0.875rem');
|
|
9
|
+
});
|
|
10
|
+
it('should output 0.75rem for 12px input', () => {
|
|
11
|
+
expect(rem(12)).toBe('0.75rem');
|
|
12
|
+
});
|
|
13
|
+
it('should output 0rem for 0px input', () => {
|
|
14
|
+
expect(rem(0)).toBe('0rem');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('rem helper error handling', () => {
|
|
18
|
+
let consoleSpy;
|
|
19
|
+
beforeAll(() => {
|
|
20
|
+
// Deactivate the console for the next tests to avoid logs within the test report.
|
|
21
|
+
consoleSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
22
|
+
});
|
|
23
|
+
afterAll(() => {
|
|
24
|
+
consoleSpy.mockRestore();
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
consoleSpy.mockReset();
|
|
28
|
+
});
|
|
29
|
+
it('should output 1rem as fallback for wrong parameters', () => {
|
|
30
|
+
expect(rem('rem')).toBe('1rem');
|
|
31
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('physicalPixelSize', () => {
|
|
35
|
+
describe('non-Android devices', () => {
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
Object.defineProperty(window.navigator, 'userAgent', {
|
|
38
|
+
value: 'Not And... user agent',
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it('should output declarations for 1px size', () => {
|
|
43
|
+
expect(physicalPixelSize('foo', 1)).toEqual({
|
|
44
|
+
foo: 1,
|
|
45
|
+
'@media (min-device-pixel-ratio: 2)': {
|
|
46
|
+
foo: 0.5
|
|
47
|
+
},
|
|
48
|
+
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
49
|
+
foo: 0.5
|
|
50
|
+
},
|
|
51
|
+
'@media (min-device-pixel-ratio: 3)': {
|
|
52
|
+
foo: 0.33
|
|
53
|
+
},
|
|
54
|
+
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
55
|
+
foo: 0.33
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it('should output declarations for 2px size', () => {
|
|
60
|
+
expect(physicalPixelSize('foo', 2)).toEqual({
|
|
61
|
+
foo: 2,
|
|
62
|
+
'@media (min-device-pixel-ratio: 2)': {
|
|
63
|
+
foo: 1
|
|
64
|
+
},
|
|
65
|
+
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
66
|
+
foo: 1
|
|
67
|
+
},
|
|
68
|
+
'@media (min-device-pixel-ratio: 3)': {
|
|
69
|
+
foo: 0.67
|
|
70
|
+
},
|
|
71
|
+
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
72
|
+
foo: 0.67
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
it('should output declarations for 3px size', () => {
|
|
77
|
+
expect(physicalPixelSize('foo', 3)).toEqual({
|
|
78
|
+
foo: 3,
|
|
79
|
+
'@media (min-device-pixel-ratio: 2)': {
|
|
80
|
+
foo: 1.5
|
|
81
|
+
},
|
|
82
|
+
'@media (-webkit-min-device-pixel-ratio: 2)': {
|
|
83
|
+
foo: 1.5
|
|
84
|
+
},
|
|
85
|
+
'@media (min-device-pixel-ratio: 3)': {
|
|
86
|
+
foo: 1
|
|
87
|
+
},
|
|
88
|
+
'@media (-webkit-min-device-pixel-ratio: 3)': {
|
|
89
|
+
foo: 1
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('android devices', () => {
|
|
95
|
+
beforeAll(() => {
|
|
96
|
+
Object.defineProperty(window.navigator, 'userAgent', {
|
|
97
|
+
value: 'Foo Android',
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it('should return natural number rules only', () => {
|
|
102
|
+
expect(physicalPixelSize('foo', 3)).toEqual({
|
|
103
|
+
foo: 3
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -1,25 +1,68 @@
|
|
|
1
|
-
import get from'lodash/get';
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import { OS_ALL, TYPE_PHONE } from "../../constants/Device";
|
|
3
|
+
import { TRACKING_TARGET_ALL, TRACKING_TARGET_APPS, TRACKING_TARGET_APPS_SMARTPHONE } from "../../constants/Tracking";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Extracts the action from the pathname.
|
|
3
7
|
* @param {string} pathName The ULR pathname.
|
|
4
8
|
* @returns {string} The action.
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
export const getPathAction = pathName => pathName.split('/')[1];
|
|
11
|
+
|
|
12
|
+
/**
|
|
6
13
|
* Selector that extracts the pathname from the current path.
|
|
7
14
|
* @param {Object} state The current state.
|
|
8
15
|
* @returns {string} The action.
|
|
9
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export const pathActionSelector = state => getPathAction(state.history.pathname);
|
|
18
|
+
|
|
19
|
+
/**
|
|
10
20
|
* Checks if a given target is supported by the type
|
|
11
21
|
* @param {string} target Tracking target
|
|
12
22
|
* @param {Object} clientInformation Information about the current client
|
|
13
23
|
* @returns {boolean}
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
*/
|
|
25
|
+
export function isTargetSupported(target, clientInformation) {
|
|
26
|
+
const {
|
|
27
|
+
type
|
|
28
|
+
} = clientInformation;
|
|
29
|
+
|
|
30
|
+
// Always use 'all' and 'apps'
|
|
31
|
+
const validTargets = [TRACKING_TARGET_ALL, TRACKING_TARGET_APPS];
|
|
32
|
+
|
|
33
|
+
// Add more valid targets depending on the platform/device
|
|
34
|
+
if (type === TYPE_PHONE) {
|
|
35
|
+
validTargets.push(TRACKING_TARGET_APPS_SMARTPHONE);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check if the given target matches any valid target
|
|
39
|
+
return validTargets.indexOf(target) !== -1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
18
43
|
* Collects tracking configurations from the sgxs configuration, which match to the current client.
|
|
19
44
|
* @param {Object} sgxsConfig The SGXS configuration
|
|
20
45
|
* @param {Object} clientInformation Information about the current client
|
|
21
46
|
* @return {Array}
|
|
22
|
-
*/
|
|
47
|
+
*/
|
|
48
|
+
export const getRelevantConfigs = (sgxsConfig = {}, clientInformation = {}) => {
|
|
49
|
+
const {
|
|
50
|
+
stage: sgxsStage = '',
|
|
51
|
+
trackers = []
|
|
52
|
+
} = sgxsConfig;
|
|
53
|
+
return trackers.filter(({
|
|
54
|
+
stage,
|
|
55
|
+
shopgateAccount,
|
|
56
|
+
os,
|
|
57
|
+
target
|
|
58
|
+
}) => {
|
|
59
|
+
/**
|
|
23
60
|
* Only Shopgate tracking configurations contain a stage property. In case of the merchant
|
|
24
61
|
* configurations we only get entries which match the stage, on which the client is running.
|
|
25
|
-
*/
|
|
62
|
+
*/
|
|
63
|
+
const validStage = !shopgateAccount || stage === sgxsStage;
|
|
64
|
+
const validOs = !os || os === get(clientInformation, 'os') || os === OS_ALL;
|
|
65
|
+
const validTarget = isTargetSupported(target, clientInformation);
|
|
66
|
+
return validStage && validOs && validTarget;
|
|
67
|
+
});
|
|
68
|
+
};
|