@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.
Files changed (306) hide show
  1. package/App.js +48 -6
  2. package/action-creators/app/index.js +75 -12
  3. package/action-creators/app/spec.js +96 -1
  4. package/action-creators/client/index.js +27 -5
  5. package/action-creators/client/spec.js +44 -1
  6. package/action-creators/error/index.js +15 -3
  7. package/action-creators/index.js +9 -1
  8. package/action-creators/menu/index.js +23 -4
  9. package/action-creators/menu/spec.js +37 -1
  10. package/action-creators/modal/index.js +15 -3
  11. package/action-creators/modal/spec.js +26 -1
  12. package/action-creators/page/index.js +24 -4
  13. package/action-creators/page/spec.js +38 -1
  14. package/action-creators/router/index.js +48 -7
  15. package/action-creators/url/index.js +24 -4
  16. package/action-creators/url/spec.js +45 -1
  17. package/action-creators/user/index.js +90 -13
  18. package/action-creators/user/spec.js +186 -2
  19. package/actions/app/handleDeepLink.js +11 -2
  20. package/actions/app/handleLink.js +62 -6
  21. package/actions/app/handlePushNotification.js +32 -4
  22. package/actions/app/handleUniversalLink.js +11 -2
  23. package/actions/app/registerLinkEvents.js +24 -3
  24. package/actions/client/fetchClientInformation.js +26 -2
  25. package/actions/menu/fetchMenu.js +23 -2
  26. package/actions/modal/closeModal.js +18 -2
  27. package/actions/modal/promiseMap.js +3 -1
  28. package/actions/modal/showModal.js +54 -8
  29. package/actions/page/fetchPageConfig.js +69 -2
  30. package/actions/page/getPageConfig.js +6 -2
  31. package/actions/page/index.js +1 -1
  32. package/actions/router/historyPop.js +12 -2
  33. package/actions/router/historyPopToRoute.js +27 -2
  34. package/actions/router/historyPush.js +12 -2
  35. package/actions/router/historyRedirect.js +21 -2
  36. package/actions/router/historyReplace.js +20 -3
  37. package/actions/router/historyReset.js +11 -2
  38. package/actions/router/historyResetTo.js +12 -2
  39. package/actions/router/index.js +17 -1
  40. package/actions/router/routeDidPop.js +11 -2
  41. package/actions/router/routeDidPush.js +13 -2
  42. package/actions/router/routeDidReplace.js +11 -2
  43. package/actions/router/routeDidReset.js +11 -2
  44. package/actions/router/routeDidUpdate.js +10 -2
  45. package/actions/router/routeWillPop.js +11 -2
  46. package/actions/router/routeWillPush.js +13 -2
  47. package/actions/router/routeWillReplace.js +11 -2
  48. package/actions/router/routeWillReset.js +11 -2
  49. package/actions/router/windowOpenOverride.js +10 -2
  50. package/actions/user/fetchRegisterUrl.js +36 -2
  51. package/actions/user/fetchUser.js +29 -3
  52. package/actions/user/getUser.js +6 -2
  53. package/actions/user/index.js +1 -1
  54. package/actions/user/login.js +76 -9
  55. package/actions/user/logout.js +30 -2
  56. package/collections/AuthRoutes.js +73 -14
  57. package/collections/Configuration.js +54 -7
  58. package/collections/EmbeddedMedia.js +84 -11
  59. package/collections/PersistedReducers.js +41 -6
  60. package/collections/Redirects.js +103 -17
  61. package/collections/index.js +5 -1
  62. package/collections/media-providers/MediaProvider.js +151 -26
  63. package/collections/media-providers/Vimeo.js +113 -19
  64. package/collections/media-providers/YouTube.js +74 -14
  65. package/collections/media-providers/index.js +3 -1
  66. package/collections/media-providers/style.js +52 -2
  67. package/components/Backdrop/index.js +95 -6
  68. package/components/Backdrop/spec.js +23 -1
  69. package/components/Backdrop/style.js +11 -2
  70. package/components/Button/index.js +47 -5
  71. package/components/Button/spec.js +36 -1
  72. package/components/Button/style.js +6 -1
  73. package/components/Checkbox/index.js +126 -32
  74. package/components/Checkbox/spec.js +94 -3
  75. package/components/Consume/helpers/buildParams.js +13 -2
  76. package/components/Consume/index.js +14 -2
  77. package/components/CountdownTimer/index.js +115 -17
  78. package/components/CountdownTimer/spec.js +126 -12
  79. package/components/Drawer/index.js +131 -16
  80. package/components/Drawer/spec.js +76 -1
  81. package/components/Drawer/style.js +37 -1
  82. package/components/Dropdown/index.js +65 -6
  83. package/components/Dropdown/style.js +4 -1
  84. package/components/Dropdown/transitions.js +34 -1
  85. package/components/Ellipsis/index.js +16 -2
  86. package/components/Ellipsis/spec.js +13 -1
  87. package/components/EmbeddedMedia/index.js +56 -6
  88. package/components/EmbeddedMedia/spec.js +52 -3
  89. package/components/ErrorBoundary/connector.js +9 -2
  90. package/components/ErrorBoundary/index.js +43 -7
  91. package/components/Grid/components/Item/index.js +40 -4
  92. package/components/Grid/components/Item/spec.js +23 -1
  93. package/components/Grid/components/Item/style.js +17 -3
  94. package/components/Grid/index.js +36 -4
  95. package/components/Grid/spec.js +23 -1
  96. package/components/Grid/style.js +11 -2
  97. package/components/HtmlSanitizer/connector.js +24 -3
  98. package/components/HtmlSanitizer/index.js +104 -12
  99. package/components/HtmlSanitizer/spec.js +207 -6
  100. package/components/I18n/components/FormatDate/index.js +26 -2
  101. package/components/I18n/components/FormatDate/spec.js +46 -1
  102. package/components/I18n/components/FormatNumber/index.js +34 -2
  103. package/components/I18n/components/FormatNumber/spec.js +41 -2
  104. package/components/I18n/components/FormatPrice/index.js +32 -2
  105. package/components/I18n/components/FormatPrice/spec.js +46 -1
  106. package/components/I18n/components/FormatTime/index.js +26 -2
  107. package/components/I18n/components/FormatTime/spec.js +43 -2
  108. package/components/I18n/components/I18nProvider/index.js +52 -9
  109. package/components/I18n/components/I18nProvider/spec.js +39 -1
  110. package/components/I18n/components/Placeholder/index.js +8 -2
  111. package/components/I18n/components/Placeholder/spec.js +30 -1
  112. package/components/I18n/components/Translate/index.js +68 -7
  113. package/components/I18n/components/Translate/spec.js +30 -1
  114. package/components/I18n/index.js +16 -1
  115. package/components/Icon/index.js +25 -2
  116. package/components/Icon/style.js +6 -1
  117. package/components/Image/Image.js +176 -19
  118. package/components/Image/ImageInner.js +48 -2
  119. package/components/Image/index.js +1 -1
  120. package/components/Image/style.js +29 -2
  121. package/components/InfiniteContainer/index.js +381 -49
  122. package/components/InfiniteContainer/spec.js +199 -10
  123. package/components/Input/components/DateInput.js +262 -6
  124. package/components/Input/components/MultiLineInput.js +98 -12
  125. package/components/Input/components/SimpleInput.js +207 -31
  126. package/components/Input/index.js +32 -3
  127. package/components/Input/spec.js +122 -1
  128. package/components/KeyboardConsumer/index.js +48 -7
  129. package/components/Link/connector.js +7 -1
  130. package/components/Link/index.js +96 -11
  131. package/components/Link/spec.js +56 -1
  132. package/components/Link/style.js +10 -1
  133. package/components/List/components/Item/index.js +35 -3
  134. package/components/List/components/Item/style.js +16 -1
  135. package/components/List/index.js +20 -2
  136. package/components/List/spec.js +31 -1
  137. package/components/Loading/index.js +6 -2
  138. package/components/Modal/index.js +38 -3
  139. package/components/Modal/style.js +36 -1
  140. package/components/ModalContainer/connector.js +17 -3
  141. package/components/ModalContainer/index.js +36 -3
  142. package/components/ModalContainer/spec.js +105 -5
  143. package/components/Picker/components/Button/index.js +34 -2
  144. package/components/Picker/components/Button/style.js +19 -1
  145. package/components/Picker/components/List/index.js +33 -2
  146. package/components/Picker/components/List/style.js +17 -1
  147. package/components/Picker/components/Modal/index.js +60 -7
  148. package/components/Picker/components/Modal/style.js +78 -1
  149. package/components/Picker/index.js +167 -21
  150. package/components/Picker/spec.js +83 -2
  151. package/components/Portal/index.js +130 -19
  152. package/components/ProductCharacteristics/connector.js +33 -4
  153. package/components/ProductCharacteristics/context.js +2 -1
  154. package/components/ProductCharacteristics/helpers/index.js +135 -21
  155. package/components/ProductCharacteristics/index.js +266 -31
  156. package/components/RangeSlider/components/Handle/index.js +25 -2
  157. package/components/RangeSlider/components/Handle/style.js +14 -1
  158. package/components/RangeSlider/helper.js +43 -8
  159. package/components/RangeSlider/index.js +228 -38
  160. package/components/RangeSlider/style.js +14 -1
  161. package/components/Route/RouteNotFound.js +46 -3
  162. package/components/Route/index.js +78 -10
  163. package/components/Router/connector.js +9 -2
  164. package/components/Router/index.js +237 -31
  165. package/components/ScannerContainer/connector.js +9 -2
  166. package/components/ScannerContainer/index.js +42 -6
  167. package/components/Select/components/Item/index.js +20 -4
  168. package/components/Select/components/Item/style.js +4 -1
  169. package/components/Select/index.js +149 -28
  170. package/components/Select/spec.js +86 -2
  171. package/components/Select/style.js +17 -1
  172. package/components/SelectBox/components/Item/index.js +47 -5
  173. package/components/SelectBox/components/Item/style.js +7 -1
  174. package/components/SelectBox/index.js +173 -17
  175. package/components/SelectBox/spec.js +59 -3
  176. package/components/SelectBox/style.js +18 -1
  177. package/components/Slider/index.js +6 -2
  178. package/components/SurroundPortals/index.js +26 -2
  179. package/components/Swiper/components/SwiperItem/index.js +28 -4
  180. package/components/Swiper/components/SwiperItem/spec.js +17 -1
  181. package/components/Swiper/components/SwiperItem/styles.js +5 -1
  182. package/components/Swiper/index.js +210 -18
  183. package/components/Swiper/styles.js +75 -7
  184. package/components/Toaster/index.js +10 -2
  185. package/components/Transition/index.js +89 -13
  186. package/components/Widgets/components/Widget/index.js +52 -4
  187. package/components/Widgets/components/Widget/spec.js +68 -3
  188. package/components/Widgets/components/Widget/style.js +21 -3
  189. package/components/Widgets/components/WidgetGrid/index.js +52 -7
  190. package/components/Widgets/components/WidgetGrid/spec.js +46 -2
  191. package/components/Widgets/components/WidgetGrid/style.js +8 -1
  192. package/components/Widgets/helpers/shouldShowWidget.js +44 -7
  193. package/components/Widgets/index.js +127 -15
  194. package/components/Widgets/spec.js +213 -6
  195. package/components/index.js +9 -1
  196. package/constants/ActionTypes.js +97 -19
  197. package/constants/Configuration.js +12 -2
  198. package/constants/Device.js +29 -2
  199. package/constants/DisplayOptions.js +8 -1
  200. package/constants/MenuIDs.js +2 -1
  201. package/constants/ModalTypes.js +1 -1
  202. package/constants/PageIDs.js +1 -1
  203. package/constants/Pipelines.js +7 -1
  204. package/constants/Portals.js +136 -3
  205. package/constants/Registration.js +3 -1
  206. package/constants/RoutePaths.js +13 -2
  207. package/constants/Tracking.js +3 -1
  208. package/constants/client.js +6 -1
  209. package/constants/ui.js +2 -1
  210. package/constants/user.js +6 -2
  211. package/context/index.js +33 -3
  212. package/helpers/config/index.js +139 -21
  213. package/helpers/config/mock.js +200 -8
  214. package/helpers/config/theme.js +50 -4
  215. package/helpers/data/index.js +204 -29
  216. package/helpers/data/spec.js +187 -7
  217. package/helpers/date/index.js +58 -6
  218. package/helpers/date/spec.js +92 -1
  219. package/helpers/dom/index.js +48 -11
  220. package/helpers/environment/index.js +14 -2
  221. package/helpers/html/decodeHTML.js +7 -1
  222. package/helpers/html/handleDOM.js +172 -21
  223. package/helpers/html/parseHTML.js +67 -12
  224. package/helpers/i18n/getDateFormatter.js +23 -4
  225. package/helpers/i18n/getNumberFormatter.js +32 -4
  226. package/helpers/i18n/getPriceFormatter.js +38 -4
  227. package/helpers/i18n/getTimeFormatter.js +23 -4
  228. package/helpers/i18n/getTranslator.js +62 -8
  229. package/helpers/i18n/index.js +5 -1
  230. package/helpers/i18n/mergeTranslations.js +36 -9
  231. package/helpers/i18n/messageCache.js +3 -1
  232. package/helpers/legacy/index.js +47 -9
  233. package/helpers/modal/withShowModal.js +13 -2
  234. package/helpers/portals/portalCollection.js +28 -6
  235. package/helpers/portals/routePortals.js +12 -1
  236. package/helpers/redux/compareObjects.js +7 -2
  237. package/helpers/redux/generateResultHash.js +36 -3
  238. package/helpers/redux/generateSortedHash.js +7 -2
  239. package/helpers/redux/hasExpired.js +10 -2
  240. package/helpers/redux/index.js +7 -1
  241. package/helpers/redux/mutable.js +143 -24
  242. package/helpers/redux/shouldFetchData.js +46 -10
  243. package/helpers/redux/shouldFetchFilters.js +17 -4
  244. package/helpers/router/index.js +49 -5
  245. package/helpers/style/index.js +43 -4
  246. package/helpers/style/spec.js +108 -2
  247. package/helpers/tracking/index.js +52 -9
  248. package/helpers/validation/index.js +39 -12
  249. package/helpers/validation/spec.js +10 -1
  250. package/package.json +3 -3
  251. package/providers/index.js +4 -1
  252. package/providers/loading/context.js +2 -1
  253. package/providers/loading/index.js +137 -22
  254. package/providers/toast/context.js +2 -1
  255. package/providers/toast/index.js +105 -11
  256. package/reducers/client/connectivity.js +22 -2
  257. package/reducers/client/index.js +7 -1
  258. package/reducers/client/info.js +27 -2
  259. package/reducers/index.js +23 -4
  260. package/reducers/menu/index.js +5 -1
  261. package/reducers/menu/menusById.js +41 -2
  262. package/reducers/modal/index.js +14 -2
  263. package/reducers/page/index.js +68 -5
  264. package/reducers/router/index.js +48 -2
  265. package/reducers/url/index.js +42 -3
  266. package/reducers/user/data.js +27 -2
  267. package/reducers/user/index.js +7 -1
  268. package/reducers/user/login.js +65 -2
  269. package/selectors/client.js +138 -21
  270. package/selectors/history.js +49 -11
  271. package/selectors/menu.js +34 -6
  272. package/selectors/modal.js +15 -4
  273. package/selectors/page.js +25 -4
  274. package/selectors/router.js +154 -30
  275. package/selectors/url.js +25 -4
  276. package/selectors/user.js +90 -13
  277. package/store/index.js +60 -6
  278. package/store/middelwares/logger.js +7 -1
  279. package/store/middelwares/streams.js +19 -2
  280. package/streams/app.js +60 -8
  281. package/streams/client.js +8 -2
  282. package/streams/error.js +14 -3
  283. package/streams/index.js +6 -1
  284. package/streams/interval.js +6 -2
  285. package/streams/main.js +27 -2
  286. package/streams/router.js +45 -8
  287. package/streams/user.js +89 -15
  288. package/streams/view.js +97 -25
  289. package/styles/reset/form.js +57 -5
  290. package/styles/reset/index.js +6 -1
  291. package/styles/reset/media.js +22 -1
  292. package/styles/reset/root.js +33 -1
  293. package/styles/reset/table.js +10 -1
  294. package/styles/reset/typography.js +26 -1
  295. package/subscriptions/app.js +148 -17
  296. package/subscriptions/error.js +292 -13
  297. package/subscriptions/helpers/buildRegisterUrl.js +25 -6
  298. package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
  299. package/subscriptions/helpers/handleLinks.js +267 -25
  300. package/subscriptions/helpers/pipeline.js +12 -1
  301. package/subscriptions/history.js +34 -6
  302. package/subscriptions/index.js +25 -4
  303. package/subscriptions/menu.js +22 -5
  304. package/subscriptions/mock.js +39 -7
  305. package/subscriptions/router.js +336 -23
  306. package/subscriptions/user.js +93 -3
@@ -1,4 +1,16 @@
1
- function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useMemo,useState,useEffect,useRef,useCallback,memo}from'react';import PropTypes from'prop-types';import classNames from'classnames';import noop from'lodash/noop';import{themeConfig}from'@shopgate/engage';import{getFullImageSource}from'@shopgate/engage/core/helpers';import styles from"./style";import ImageInner from"./ImageInner";var themeColors=themeConfig.colors;/**
1
+ import React, { useMemo, useState, useEffect, useRef, useCallback, memo } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import noop from 'lodash/noop';
5
+ import { themeConfig } from '@shopgate/engage';
6
+ import { getFullImageSource } from '@shopgate/engage/core/helpers';
7
+ import styles from "./style";
8
+ import ImageInner from "./ImageInner";
9
+ const {
10
+ colors: themeColors
11
+ } = themeConfig;
12
+
13
+ /**
2
14
  * Calculates the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm.
3
15
  *
4
16
  * @param {number} a - The first number (must be a positive integer).
@@ -9,32 +21,177 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
9
21
  * gcd(1920, 1080); // Returns 120
10
22
  * gcd(10, 15); // Returns 5
11
23
  * gcd(100, 25); // Returns 25
12
- */var gcd=function gcd(a,b){return b===0?a:gcd(b,a%b);};/**
24
+ */
25
+ const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
26
+
27
+ /**
13
28
  * The image component.
14
29
  * @param {Object} props The components props.
15
30
  * @returns {JSX.Element}
16
- */var Image=function Image(_ref){var alt=_ref.alt,backgroundColor=_ref.backgroundColor,className=_ref.className,classNameImg=_ref.classNameImg,parentRendersPlaceholder=_ref.forcePlaceholder,highestResolutionLoaded=_ref.highestResolutionLoaded,onError=_ref.onError,onLoad=_ref.onLoad,ratio=_ref.ratio,resolutions=_ref.resolutions,src=_ref.src,lazy=_ref.lazy,unwrapped=_ref.unwrapped;// Prepare two image sources - a small preview image and a large main image. The idea is to
17
- // display an image as soon as possible. Small images might be also available in the cache from
18
- // the previous page.
19
- var sources=useMemo(function(){// Create a preview source when resolutions array has more than one element
20
- var preview=resolutions.length>1?getFullImageSource(src,resolutions[resolutions.length-2]):null;// Create a main source when resolutions array has at least one element (highest resolution)
21
- var main=resolutions.length>0?getFullImageSource(src,resolutions[resolutions.length-1]):null;return{// Only assign preview source if it is different from the main source. Image swap logic
22
- // will not run when no preview source is available.
23
- preview:preview!==main?preview:null,main:main};},[resolutions,src]);var imgRef=useRef(null);var _useState=useState(!lazy),_useState2=_slicedToArray(_useState,2),isInView=_useState2[0],setIsInView=_useState2[1];// Effect to create an Intersection Observer to enable lazy loading of preview images
24
- useEffect(function(){if(!lazy||!sources.preview)return undefined;// Intersection Observer to check if the image is in (or near) the viewport
25
- var observer=new IntersectionObserver(function(_ref2){var _ref3=_slicedToArray(_ref2,1),entry=_ref3[0];if(entry.isIntersecting){setIsInView(true);// stop observing once visible
26
- observer.unobserve(entry.target);}},// load a bit earlier
27
- {rootMargin:'100px'});if(imgRef.current){// start observing the image element
28
- observer.observe(imgRef.current);}return function(){// disconnect the observer when the component is unmounted
29
- observer.disconnect();};},[lazy,sources.preview]);/**
31
+ */
32
+ const Image = ({
33
+ alt,
34
+ backgroundColor,
35
+ className,
36
+ classNameImg,
37
+ forcePlaceholder: parentRendersPlaceholder,
38
+ highestResolutionLoaded,
39
+ onError,
40
+ onLoad,
41
+ ratio,
42
+ resolutions,
43
+ src,
44
+ lazy,
45
+ unwrapped
46
+ }) => {
47
+ // Prepare two image sources - a small preview image and a large main image. The idea is to
48
+ // display an image as soon as possible. Small images might be also available in the cache from
49
+ // the previous page.
50
+ const sources = useMemo(() => {
51
+ // Create a preview source when resolutions array has more than one element
52
+ const preview = resolutions.length > 1 ? getFullImageSource(src, resolutions[resolutions.length - 2]) : null;
53
+
54
+ // Create a main source when resolutions array has at least one element (highest resolution)
55
+ const main = resolutions.length > 0 ? getFullImageSource(src, resolutions[resolutions.length - 1]) : null;
56
+ return {
57
+ // Only assign preview source if it is different from the main source. Image swap logic
58
+ // will not run when no preview source is available.
59
+ preview: preview !== main ? preview : null,
60
+ main
61
+ };
62
+ }, [resolutions, src]);
63
+ const imgRef = useRef(null);
64
+ const [isInView, setIsInView] = useState(!lazy);
65
+
66
+ // Effect to create an Intersection Observer to enable lazy loading of preview images
67
+ useEffect(() => {
68
+ if (!lazy || !sources.preview) return undefined;
69
+
70
+ // Intersection Observer to check if the image is in (or near) the viewport
71
+ const observer = new IntersectionObserver(([entry]) => {
72
+ if (entry.isIntersecting) {
73
+ setIsInView(true);
74
+ // stop observing once visible
75
+ observer.unobserve(entry.target);
76
+ }
77
+ },
78
+ // load a bit earlier
79
+ {
80
+ rootMargin: '100px'
81
+ });
82
+ if (imgRef.current) {
83
+ // start observing the image element
84
+ observer.observe(imgRef.current);
85
+ }
86
+ return () => {
87
+ // disconnect the observer when the component is unmounted
88
+ observer.disconnect();
89
+ };
90
+ }, [lazy, sources.preview]);
91
+
92
+ /**
30
93
  * Handles the onLoad event of the image.
31
- */var handleOnLoad=useCallback(function(e){highestResolutionLoaded();onLoad(e);},[highestResolutionLoaded,onLoad]);/**
94
+ */
95
+ const handleOnLoad = useCallback(e => {
96
+ highestResolutionLoaded();
97
+ onLoad(e);
98
+ }, [highestResolutionLoaded, onLoad]);
99
+
100
+ /**
32
101
  * Handles the onError event of the image.
33
- */var handleOnError=useCallback(function(e){onError(e);},[onError]);/**
102
+ */
103
+ const handleOnError = useCallback(e => {
104
+ onError(e);
105
+ }, [onError]);
106
+
107
+ /**
34
108
  * Memoized calculation of aspect ratio and CSS padding-hack ratio for responsive elements.
35
109
  *
36
110
  * Returns n object containing:
37
111
  * - `aspectRatio` {string} - The aspect ratio in the format `width / height` (e.g., `16 / 9`).
38
112
  * - `paddingHackRatio` {string} - The CSS padding-hack ratio as a percentage for older browsers
39
113
  * (e.g., `56.250%` for a 16:9 ratio).
40
- */var _useMemo=useMemo(function(){var width;var height;if(ratio){var _ratio=_slicedToArray(ratio,2);width=_ratio[0];height=_ratio[1];}else{var _resolutions=resolutions[resolutions.length-1];width=_resolutions.width;height=_resolutions.height;}var divisor=gcd(width,height);return{aspectRatio:"".concat(width/divisor," / ").concat(height/divisor),paddingHackRatio:"".concat((height/width*100).toFixed(3),"%")};},[ratio,resolutions]),aspectRatio=_useMemo.aspectRatio,paddingHackRatio=_useMemo.paddingHackRatio;if(unwrapped){if(!(src&&!parentRendersPlaceholder))return null;return React.createElement(ImageInner,{ref:imgRef,src:sources.main,className:classNames(classNameImg),style:_extends({aspectRatio:aspectRatio},isInView&&sources.preview&&{backgroundImage:"url(".concat(sources.preview,")"),backgroundSize:'contain',backgroundRepeat:'no-repeat',backgroundPosition:'center'}),alt:alt,lazy:lazy,onLoad:handleOnLoad,onError:handleOnError});}var containerStyle=styles.container(backgroundColor,paddingHackRatio);return React.createElement("div",{className:classNames(containerStyle,className,'common__image__container')},src&&!parentRendersPlaceholder&&React.createElement(ImageInner,{ref:imgRef,src:sources.main,className:classNames(classNameImg),style:_extends({aspectRatio:aspectRatio},isInView&&sources.preview&&{backgroundImage:"url(".concat(sources.preview,")"),backgroundSize:'contain',backgroundRepeat:'no-repeat',backgroundPosition:'center'}),alt:alt,lazy:lazy,onLoad:handleOnLoad,onError:handleOnError}));};var defaultResolutions=[{width:440,height:440}];Image.defaultProps={alt:null,backgroundColor:themeColors.placeholder,className:'',classNameImg:'',forcePlaceholder:false,highestResolutionLoaded:noop,onError:noop,onLoad:noop,ratio:null,resolutions:defaultResolutions,src:null,unwrapped:false,lazy:true};export default memo(Image);
114
+ */
115
+ const {
116
+ aspectRatio,
117
+ paddingHackRatio
118
+ } = useMemo(() => {
119
+ let width;
120
+ let height;
121
+ if (ratio) {
122
+ [width, height] = ratio;
123
+ } else {
124
+ ({
125
+ width,
126
+ height
127
+ } = resolutions[resolutions.length - 1]);
128
+ }
129
+ const divisor = gcd(width, height);
130
+ return {
131
+ aspectRatio: `${width / divisor} / ${height / divisor}`,
132
+ paddingHackRatio: `${(height / width * 100).toFixed(3)}%`
133
+ };
134
+ }, [ratio, resolutions]);
135
+ if (unwrapped) {
136
+ if (!(src && !parentRendersPlaceholder)) return null;
137
+ return /*#__PURE__*/React.createElement(ImageInner, {
138
+ ref: imgRef,
139
+ src: sources.main,
140
+ className: classNames(classNameImg),
141
+ style: {
142
+ aspectRatio,
143
+ ...(isInView && sources.preview && {
144
+ backgroundImage: `url(${sources.preview})`,
145
+ backgroundSize: 'contain',
146
+ backgroundRepeat: 'no-repeat',
147
+ backgroundPosition: 'center'
148
+ })
149
+ },
150
+ alt: alt,
151
+ lazy: lazy,
152
+ onLoad: handleOnLoad,
153
+ onError: handleOnError
154
+ });
155
+ }
156
+ const containerStyle = styles.container(backgroundColor, paddingHackRatio);
157
+ return /*#__PURE__*/React.createElement("div", {
158
+ className: classNames(containerStyle, className, 'common__image__container')
159
+ }, src && !parentRendersPlaceholder && /*#__PURE__*/React.createElement(ImageInner, {
160
+ ref: imgRef,
161
+ src: sources.main,
162
+ className: classNames(classNameImg),
163
+ style: {
164
+ aspectRatio,
165
+ ...(isInView && sources.preview && {
166
+ backgroundImage: `url(${sources.preview})`,
167
+ backgroundSize: 'contain',
168
+ backgroundRepeat: 'no-repeat',
169
+ backgroundPosition: 'center'
170
+ })
171
+ },
172
+ alt: alt,
173
+ lazy: lazy,
174
+ onLoad: handleOnLoad,
175
+ onError: handleOnError
176
+ }));
177
+ };
178
+ const defaultResolutions = [{
179
+ width: 440,
180
+ height: 440
181
+ }];
182
+ Image.defaultProps = {
183
+ alt: null,
184
+ backgroundColor: themeColors.placeholder,
185
+ className: '',
186
+ classNameImg: '',
187
+ forcePlaceholder: false,
188
+ highestResolutionLoaded: noop,
189
+ onError: noop,
190
+ onLoad: noop,
191
+ ratio: null,
192
+ resolutions: defaultResolutions,
193
+ src: null,
194
+ unwrapped: false,
195
+ lazy: true
196
+ };
197
+ export default /*#__PURE__*/memo(Image);
@@ -1,6 +1,52 @@
1
- import React,{forwardRef}from'react';import PropTypes from'prop-types';import classNames from'classnames';import noop from'lodash/noop';import styles from"./style";/**
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import noop from 'lodash/noop';
5
+ import styles from "./style";
6
+
7
+ /**
2
8
  * The ImageInner component renders tha actual image of the Image component.
3
9
  * @param {Object} props The component props
4
10
  * @param {Function} ref The component reference
5
11
  * @returns {JSX.Element}
6
- */var ImageInner=forwardRef(function(_ref,ref){var src=_ref.src,className=_ref.className,alt=_ref.alt,lazy=_ref.lazy,onLoad=_ref.onLoad,onError=_ref.onError,style=_ref.style;return React.createElement("img",{ref:ref,loading:lazy?'lazy':'eager',src:src,className:classNames(className,styles.image,'common__image'),alt:alt,"aria-label":alt,"aria-hidden":!alt,"data-test-id":"image",onLoad:onLoad,onError:onError,style:style});});ImageInner.propTypes={alt:PropTypes.string,className:PropTypes.string,lazy:PropTypes.bool,onError:PropTypes.func,onLoad:PropTypes.func,src:PropTypes.string,style:PropTypes.shape()};ImageInner.defaultProps={src:null,alt:null,className:null,lazy:false,style:null,onError:noop,onLoad:noop};export default ImageInner;
12
+ */
13
+ const ImageInner = /*#__PURE__*/forwardRef(({
14
+ src,
15
+ className,
16
+ alt,
17
+ lazy,
18
+ onLoad,
19
+ onError,
20
+ style
21
+ }, ref) => /*#__PURE__*/React.createElement("img", {
22
+ ref: ref,
23
+ loading: lazy ? 'lazy' : 'eager',
24
+ src: src,
25
+ className: classNames(className, styles.image, 'common__image'),
26
+ alt: alt,
27
+ "aria-label": alt,
28
+ "aria-hidden": !alt,
29
+ "data-test-id": "image",
30
+ onLoad: onLoad,
31
+ onError: onError,
32
+ style: style
33
+ }));
34
+ ImageInner.propTypes = {
35
+ alt: PropTypes.string,
36
+ className: PropTypes.string,
37
+ lazy: PropTypes.bool,
38
+ onError: PropTypes.func,
39
+ onLoad: PropTypes.func,
40
+ src: PropTypes.string,
41
+ style: PropTypes.shape()
42
+ };
43
+ ImageInner.defaultProps = {
44
+ src: null,
45
+ alt: null,
46
+ className: null,
47
+ lazy: false,
48
+ style: null,
49
+ onError: noop,
50
+ onLoad: noop
51
+ };
52
+ export default ImageInner;
@@ -1 +1 @@
1
- export{default}from"./Image";
1
+ export { default } from "./Image";
@@ -1,5 +1,32 @@
1
- import{css}from'glamor';import{themeColors}from'@shopgate/pwa-common/helpers/config';/**
1
+ import { css } from 'glamor';
2
+ import { themeColors } from '@shopgate/pwa-common/helpers/config';
3
+
4
+ /**
2
5
  * @param {string} [background=themeColors.placeholder] The background color.
3
6
  * @param {string} [paddingTop='100%'] The padding top value.
4
7
  * @returns {string} The compiled class names.
5
- */var container=function container(){var background=arguments.length>0&&arguments[0]!==undefined?arguments[0]:themeColors.placeholder;var paddingTop=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'100%';return css({background:background,position:'relative',zIndex:0,':before':{display:'block',content:'""',width:'100%',paddingTop:paddingTop}}).toString();};var image=css({position:'absolute',top:0,left:0,width:'100%',maxHeight:'100%',WebkitTouchCallout:'none',fontSize:0}).toString();export default{container:container,image:image};
8
+ */
9
+ const container = (background = themeColors.placeholder, paddingTop = '100%') => css({
10
+ background,
11
+ position: 'relative',
12
+ zIndex: 0,
13
+ ':before': {
14
+ display: 'block',
15
+ content: '""',
16
+ width: '100%',
17
+ paddingTop
18
+ }
19
+ }).toString();
20
+ const image = css({
21
+ position: 'absolute',
22
+ top: 0,
23
+ left: 0,
24
+ width: '100%',
25
+ maxHeight: '100%',
26
+ WebkitTouchCallout: 'none',
27
+ fontSize: 0
28
+ }).toString();
29
+ export default {
30
+ container,
31
+ image
32
+ };