@shopgate/pwa-common 7.12.3-beta.1 → 7.20.0-beta.1
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 +6 -6
- package/actions/app/handleLink.js +7 -5
- package/actions/client/fetchClientInformation.js +1 -1
- package/actions/page/fetchPageConfig.js +2 -2
- package/actions/user/login.js +2 -2
- package/collections/AuthRoutes.js +3 -3
- package/collections/Configuration.js +3 -3
- package/collections/EmbeddedMedia.js +2 -2
- package/collections/PersistedReducers.js +2 -2
- package/collections/Redirects.js +3 -3
- package/collections/media-providers/MediaProvider.js +2 -2
- package/collections/media-providers/Vimeo.js +7 -7
- package/collections/media-providers/YouTube.js +5 -5
- package/components/Backdrop/index.js +11 -11
- package/components/Button/index.js +7 -7
- package/components/Checkbox/index.js +27 -14
- package/components/CountdownTimer/index.js +7 -7
- package/components/Drawer/index.js +13 -13
- package/components/Dropdown/index.js +5 -5
- package/components/Ellipsis/index.js +1 -1
- package/components/ErrorBoundary/index.js +5 -5
- package/components/Grid/components/Item/index.js +4 -4
- package/components/Grid/index.js +4 -4
- package/components/HtmlSanitizer/connector.js +5 -0
- package/components/HtmlSanitizer/index.js +10 -10
- package/components/HtmlSanitizer/spec.js +3 -3
- package/components/I18n/components/FormatPrice/index.js +2 -2
- package/components/I18n/components/I18nProvider/index.js +9 -9
- package/components/I18n/components/Translate/index.js +11 -7
- package/components/Icon/index.js +1 -1
- package/components/Image/index.js +9 -9
- package/components/Image/spec.js +2 -2
- package/components/InfiniteContainer/index.js +21 -21
- package/components/Input/components/DateInput.js +2 -2
- package/components/Input/components/MultiLineInput.js +10 -10
- package/components/Input/components/SimpleInput.js +27 -21
- package/components/KeyboardConsumer/index.js +7 -7
- package/components/Link/index.js +8 -5
- package/components/List/components/Item/index.js +1 -1
- package/components/List/index.js +1 -1
- package/components/Modal/index.js +1 -1
- package/components/Modal/style.js +1 -1
- package/components/Picker/components/List/index.js +1 -1
- package/components/Picker/components/Modal/index.js +7 -7
- package/components/Picker/index.js +19 -9
- package/components/Portal/index.js +15 -11
- package/components/ProductCharacteristics/helpers/index.js +1 -1
- package/components/ProductCharacteristics/index.js +27 -12
- package/components/RangeSlider/index.js +33 -24
- package/components/Route/RouteNotFound.js +3 -3
- package/components/Route/index.js +5 -5
- package/components/Router/index.js +18 -10
- package/components/ScannerContainer/index.js +3 -3
- package/components/Select/index.js +25 -15
- package/components/SelectBox/components/Item/index.js +5 -3
- package/components/SelectBox/index.js +17 -8
- package/components/Swiper/components/SwiperItem/spec.js +1 -1
- package/components/Swiper/index.js +3 -3
- package/components/Swiper/styles.js +4 -1
- package/components/Transition/index.js +4 -4
- package/components/Widgets/components/Widget/index.js +4 -4
- package/components/Widgets/components/WidgetGrid/index.js +5 -5
- package/components/Widgets/index.js +7 -7
- package/components/index.js +1 -2
- package/constants/Configuration.js +1 -1
- package/constants/Device.js +2 -2
- package/constants/Portals.js +2 -2
- package/helpers/config/mock.js +2 -2
- package/helpers/config/theme.js +2 -2
- package/helpers/i18n/getTranslator.js +10 -4
- package/helpers/portals/portalCollection.js +3 -3
- package/helpers/redux/mutable.js +3 -2
- package/helpers/redux/shouldFetchData.js +1 -1
- package/helpers/style/index.js +2 -2
- package/package.json +4 -4
- package/providers/loading/index.js +24 -14
- package/providers/toast/index.js +10 -8
- package/reducers/page/index.js +1 -1
- package/reducers/router/index.js +1 -1
- package/selectors/client.js +9 -7
- package/streams/app.js +8 -2
- package/streams/main.js +1 -1
- package/streams/view.js +12 -0
- package/subscriptions/error.js +4 -4
- package/subscriptions/helpers/handleLinks.js +2 -2
- package/subscriptions/menu.js +4 -2
- package/subscriptions/router.js +6 -6
- package/subscriptions/user.js +1 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import Transition from"../Transition";import styles from"./style";import transitions from"./transitions";/**
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import Transition from"../Transition";import styles from"./style";import transitions from"./transitions";/**
|
|
2
2
|
* This component slides it's child content up or down based on it's isOpen property.
|
|
3
3
|
* @returns {JSX}
|
|
4
|
-
*/var Dropdown=/*#__PURE__*/function(_Component){
|
|
4
|
+
*/var Dropdown=/*#__PURE__*/function(_Component){/**
|
|
5
5
|
* Constructor
|
|
6
6
|
* @param {Object} props Props of the Component
|
|
7
|
-
*/function Dropdown(props){var
|
|
7
|
+
*/function Dropdown(props){var _this2;_classCallCheck(this,Dropdown);_this2=_callSuper(this,Dropdown,[props]);_this2.state={initialRender:true};return _this2;}/**
|
|
8
8
|
* Update the initialRender state if the isOpen state changes from false to true
|
|
9
9
|
* @param {Object} nextProps The new props
|
|
10
|
-
*/_createClass(Dropdown,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isOpen===false&&nextProps.isOpen===true){this.setState({initialRender:false});}}/**
|
|
10
|
+
*/_inherits(Dropdown,_Component);return _createClass(Dropdown,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isOpen===false&&nextProps.isOpen===true){this.setState({initialRender:false});}}/**
|
|
11
11
|
* Only update the component if isOpen changed
|
|
12
12
|
* @param {Object} nextProps The new props
|
|
13
13
|
* @returns {boolean}
|
|
14
14
|
*/},{key:"shouldComponentUpdate",value:function shouldComponentUpdate(nextProps){return this.props.isOpen!==nextProps.isOpen;}/**
|
|
15
15
|
* Renders the component.
|
|
16
16
|
* @returns {JSX}
|
|
17
|
-
*/},{key:"render",value:function render(){var transitionProps;if(this.props.isOpen){transitionProps=this.state.initialRender?transitions.initialOpen:transitions.open;}else{transitionProps=this.state.initialRender?transitions.initialClose:transitions.close;}return React.createElement(Transition,_extends({},transitionProps,{onComplete:this.props.onComplete,onStart:this.props.onStart,duration:this.props.duration,easing:this.props.easing}),React.createElement("div",{className:"".concat(styles," ").concat(this.props.className),"aria-hidden":!this.props.isOpen},this.props.children));}}]);
|
|
17
|
+
*/},{key:"render",value:function render(){var transitionProps;if(this.props.isOpen){transitionProps=this.state.initialRender?transitions.initialOpen:transitions.open;}else{transitionProps=this.state.initialRender?transitions.initialClose:transitions.close;}return React.createElement(Transition,_extends({},transitionProps,{onComplete:this.props.onComplete,onStart:this.props.onStart,duration:this.props.duration,easing:this.props.easing}),React.createElement("div",{className:"".concat(styles," ").concat(this.props.className," common__dropdown"),"aria-hidden":!this.props.isOpen},this.props.children));}}]);}(Component);_defineProperty(Dropdown,"defaultProps",{className:'',children:null,duration:150,easing:null,isOpen:false,onComplete:function onComplete(){},onStart:function onStart(){}});export default Dropdown;
|
|
@@ -2,4 +2,4 @@ import React from'react';import PropTypes from'prop-types';import Dotdotdot from
|
|
|
2
2
|
* The ellipsis text component.
|
|
3
3
|
* @param {Object} props The component props.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var Ellipsis=function Ellipsis(props){return React.createElement(Dotdotdot,{clamp:props.rows,ellipsis:props.ellipsis,className:props.className,useNativeClamp:true},props.children);};Ellipsis.defaultProps={className:'',ellipsis:'...',rows:3};export default Ellipsis;
|
|
5
|
+
*/var Ellipsis=function Ellipsis(props){return React.createElement(Dotdotdot,{clamp:props.rows,ellipsis:props.ellipsis,className:"".concat(props.className," common__ellipsis"),useNativeClamp:true},props.children);};Ellipsis.defaultProps={className:'',ellipsis:'...',rows:3};export default Ellipsis;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{PureComponent}from'react';import PropTypes from'prop-types';import connector from"./connector";/**
|
|
2
2
|
* The App error boundary component.
|
|
3
|
-
*/var ErrorBoundary=/*#__PURE__*/function(_PureComponent){
|
|
3
|
+
*/var ErrorBoundary=/*#__PURE__*/function(_PureComponent){function ErrorBoundary(){var _this2;_classCallCheck(this,ErrorBoundary);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this2=_callSuper(this,ErrorBoundary,[].concat(args));_defineProperty(_this2,"state",{hasError:false});return _this2;}_inherits(ErrorBoundary,_PureComponent);return _createClass(ErrorBoundary,[{key:"componentDidCatch",value:/**
|
|
4
4
|
* @param {Object} error The error object.
|
|
5
5
|
* @param {Object} errorInfo The error information.
|
|
6
|
-
*/
|
|
6
|
+
*/function componentDidCatch(error,errorInfo){// eslint-disable-next-line no-param-reassign
|
|
7
7
|
error.stack=errorInfo.componentStack;this.props.appError(error);}/**
|
|
8
8
|
* @returns {JSX}
|
|
9
|
-
*/},{key:"render",value:function render(){if(this.state.hasError){return this.props.fallbackUi;}return this.props.children;}}],[{key:"getDerivedStateFromError"
|
|
9
|
+
*/},{key:"render",value:function render(){if(this.state.hasError){return this.props.fallbackUi;}return this.props.children;}}],[{key:"getDerivedStateFromError",value:/**
|
|
10
10
|
* @returns {{hasError: boolean}}
|
|
11
|
-
*/
|
|
11
|
+
*/function getDerivedStateFromError(){return{hasError:true};}}]);}(PureComponent);_defineProperty(ErrorBoundary,"defaultProps",{fallbackUi:null});export default connector(ErrorBoundary);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{objectWithoutProps}from"../../../../helpers/data";import styles from"./style";/**
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{objectWithoutProps}from"../../../../helpers/data";import styles from"./style";/**
|
|
2
2
|
* The grid item component.
|
|
3
|
-
*/var GridItem=/*#__PURE__*/function(_Component){
|
|
3
|
+
*/var GridItem=/*#__PURE__*/function(_Component){function GridItem(){_classCallCheck(this,GridItem);return _callSuper(this,GridItem,arguments);}_inherits(GridItem,_Component);return _createClass(GridItem,[{key:"getProps",value:/**
|
|
4
4
|
* Composes the props.
|
|
5
5
|
* @returns {Object} The composed props.
|
|
6
|
-
*/
|
|
6
|
+
*/function getProps(){var className=this.props.className;if(this.props.grow!==0){className+=" ".concat(styles.grow(this.props.grow));}if(this.props.shrink!==1){className+=" ".concat(styles.shrink(this.props.shrink));}var props=_extends({},this.props,{className:className});return objectWithoutProps(props,['component','grow','shrink']);}/**
|
|
7
7
|
* Renders the component.
|
|
8
8
|
* @returns {JSX}
|
|
9
|
-
*/},{key:"render",value:function render(){return React.createElement(this.props.component,this.getProps());}}]);
|
|
9
|
+
*/},{key:"render",value:function render(){return React.createElement(this.props.component,this.getProps());}}]);}(Component);_defineProperty(GridItem,"defaultProps",{className:'',component:'li',grow:0,shrink:1});export default GridItem;
|
package/components/Grid/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{objectWithoutProps}from"../../helpers/data";import GridItem from"./components/Item";import styles,{wrap}from"./style";/**
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{objectWithoutProps}from"../../helpers/data";import GridItem from"./components/Item";import styles,{wrap}from"./style";/**
|
|
2
2
|
* The grid component.
|
|
3
|
-
*/var Grid=/*#__PURE__*/function(_Component){
|
|
3
|
+
*/var Grid=/*#__PURE__*/function(_Component){function Grid(){_classCallCheck(this,Grid);return _callSuper(this,Grid,arguments);}_inherits(Grid,_Component);return _createClass(Grid,[{key:"getProps",value:/**
|
|
4
4
|
* Composes the props.
|
|
5
5
|
* @returns {Object} The composed props.
|
|
6
|
-
*/
|
|
6
|
+
*/function getProps(){var className="".concat(this.props.className," ").concat(styles," common__grid");if(this.props.wrap){className+=" ".concat(wrap(this.props.wrap));}var props=_extends({},this.props,{className:className});return objectWithoutProps(props,['wrap','component']);}/**
|
|
7
7
|
* Renders the component.
|
|
8
8
|
* @returns {JSX}
|
|
9
|
-
*/},{key:"render",value:function render(){return React.createElement(this.props.component,this.getProps());}}]);
|
|
9
|
+
*/},{key:"render",value:function render(){return React.createElement(this.props.component,this.getProps());}}]);}(Component);_defineProperty(Grid,"Item",GridItem);_defineProperty(Grid,"defaultProps",{className:'',component:'ul',wrap:false});export default Grid;
|
|
@@ -0,0 +1,5 @@
|
|
|
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);}import{connect}from'react-redux';import{historyPush}from"../../actions/router";/**
|
|
2
|
+
* Connects the dispatch function to a callable function in the props.
|
|
3
|
+
* @param {Function} dispatch The redux dispatch function.
|
|
4
|
+
* @return {Object} The extended component props.
|
|
5
|
+
*/var mapDispatchToProps=function mapDispatchToProps(dispatch){return{navigate:function navigate(pathname,target){return dispatch(historyPush(_extends({pathname:pathname},target&&{state:{target:target}})));}};};export default connect(null,mapDispatchToProps);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import classNames from'classnames';import{embeddedMedia}from'@shopgate/pwa-common/collections';import EmbeddedMedia from"../EmbeddedMedia";import parseHTML from"../../helpers/html/parseHTML";import connect from"./connector";/**
|
|
2
2
|
* HtmlSanitizer component.
|
|
3
|
-
*/var HtmlSanitizer=/*#__PURE__*/function(_Component){
|
|
3
|
+
*/var HtmlSanitizer=/*#__PURE__*/function(_Component){/**
|
|
4
4
|
* @param {Object} props The component props.
|
|
5
|
-
*/function HtmlSanitizer(props){var
|
|
5
|
+
*/function HtmlSanitizer(props){var _this2;_classCallCheck(this,HtmlSanitizer);_this2=_callSuper(this,HtmlSanitizer,[props]);/**
|
|
6
|
+
* If the user tapped a link element, prevent the default behavior.
|
|
7
|
+
* @param {Object} event The touchstart event.
|
|
8
|
+
*/_defineProperty(_this2,"handleTap",function(event){var linkTag=event.target.closest('a');if(linkTag){var _linkTag$attributes3=linkTag.attributes,_linkTag$attributes4=_linkTag$attributes3===void 0?{}:_linkTag$attributes3,_linkTag$attributes2$7=_linkTag$attributes4.href,_linkTag$attributes2$8=_linkTag$attributes2$7===void 0?{}:_linkTag$attributes2$7,_linkTag$attributes2$9=_linkTag$attributes2$8.value,href=_linkTag$attributes2$9===void 0?'':_linkTag$attributes2$9,_linkTag$attributes2$10=_linkTag$attributes4.target,_linkTag$attributes2$11=_linkTag$attributes2$10===void 0?{}:_linkTag$attributes2$10,_linkTag$attributes2$12=_linkTag$attributes2$11.value,target=_linkTag$attributes2$12===void 0?'':_linkTag$attributes2$12;if(href){event.preventDefault();if(_this2.props.settings.handleClick){_this2.props.settings.handleClick(href,target);}else{_this2.props.navigate(href,target);}}}});_this2.htmlContainer=React.createRef();return _this2;}/**
|
|
6
9
|
* Registers the event handler for when the user taps inside the html content.
|
|
7
|
-
*/_createClass(HtmlSanitizer,[{key:"componentDidMount",value:function componentDidMount(){this.htmlContainer.current.addEventListener('click',this.handleTap,true);embeddedMedia.add(this.htmlContainer.current);}/**
|
|
10
|
+
*/_inherits(HtmlSanitizer,_Component);return _createClass(HtmlSanitizer,[{key:"componentDidMount",value:function componentDidMount(){this.htmlContainer.current.addEventListener('click',this.handleTap,true);embeddedMedia.add(this.htmlContainer.current);}/**
|
|
8
11
|
* Only update if the HTML changed.
|
|
9
12
|
* @param {Object} nextProps The next props for the component.
|
|
10
13
|
* @return {boolean}
|
|
@@ -12,11 +15,8 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
12
15
|
* Updates embedded media within the html container.
|
|
13
16
|
*/},{key:"componentDidUpdate",value:function componentDidUpdate(){embeddedMedia.add(this.htmlContainer.current);}/**
|
|
14
17
|
* Removes the event handler.
|
|
15
|
-
*/},{key:"componentWillUnmount",value:function componentWillUnmount(){this.htmlContainer.current.removeEventListener('click',this.handleTap,true);embeddedMedia.remove(this.htmlContainer.current);}
|
|
16
|
-
* If the user tapped a link element, prevent the default behavior.
|
|
17
|
-
* @param {Object} event The touchstart event.
|
|
18
|
-
*/},{key:"render",/**
|
|
18
|
+
*/},{key:"componentWillUnmount",value:function componentWillUnmount(){this.htmlContainer.current.removeEventListener('click',this.handleTap,true);embeddedMedia.remove(this.htmlContainer.current);}},{key:"render",value:/**
|
|
19
19
|
* Renders the component.
|
|
20
20
|
* @returns {JSX}
|
|
21
|
-
*/
|
|
22
|
-
dangerouslySetInnerHTML:innerHTML,ref:this.htmlContainer,className:this.props.className}));}}]);
|
|
21
|
+
*/function render(){var innerHTML={__html:parseHTML(this.props.children,this.props.decode,this.props.settings,this.props.processStyles)};var Wrapper=this.props.wrapper;return React.createElement(Wrapper,null,React.createElement("div",{// eslint-disable-next-line react/no-danger
|
|
22
|
+
dangerouslySetInnerHTML:innerHTML,ref:this.htmlContainer,className:classNames(this.props.className,'common__html-sanitizer')}));}}]);}(Component);_defineProperty(HtmlSanitizer,"defaultProps",{children:'',className:'',decode:false,processStyles:false,settings:{},wrapper:EmbeddedMedia});export default connect(HtmlSanitizer);
|
|
@@ -1,4 +1,4 @@
|
|
|
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);}import React from'react';import{mount}from'enzyme';import{JSDOM}from'jsdom';import{embeddedMedia}from'@shopgate/pwa-common/collections';import HtmlSanitizer from"./index";jest.mock('@shopgate/pwa-common/collections/EmbeddedMedia',function(){return{add:jest.fn(),remove:jest.fn()};});jest.mock("../EmbeddedMedia",function(){return function(_ref){var children=_ref.children;return children;};});/**
|
|
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);}import React from'react';import{mount}from'enzyme';import{JSDOM}from'jsdom';import{embeddedMedia}from'@shopgate/pwa-common/collections';import HtmlSanitizer from"./index";jest.mock('@shopgate/pwa-common/collections/EmbeddedMedia',function(){return{add:jest.fn(),remove:jest.fn()};});jest.mock("../EmbeddedMedia",function(){return function(_ref){var children=_ref.children;return children;};});jest.mock("./connector",function(){return function(Cmp){return Cmp;};});/**
|
|
2
2
|
* @param {string} html HTML markup.
|
|
3
3
|
* @param {Object} props Component props.
|
|
4
4
|
* @returns {JSX}
|
|
@@ -7,7 +7,7 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
7
7
|
* <h1>Hello World!</h1>
|
|
8
8
|
* @type {string}
|
|
9
9
|
*/var html='<h1>Hello World!</h1>';var wrapper=createWrapper(html,{decode:true});// Test result of dangerouslySetInnerHTML.
|
|
10
|
-
expect(wrapper.html()).toEqual('<div><h1>Hello World!</h1></div>');expect(wrapper.render()).toMatchSnapshot();});it('should add and remove handlers for embedded media',function(){var wrapper=createWrapper('<div></div>',{decode:true});var ref=wrapper.instance().htmlContainer.current;expect(embeddedMedia.add).toHaveBeenCalledTimes(1);expect(embeddedMedia.add).toHaveBeenCalledWith(ref);expect(embeddedMedia.remove).toHaveBeenCalledTimes(0);wrapper.setProps({children:'<span></span>'});expect(embeddedMedia.add).toHaveBeenCalledTimes(2);expect(embeddedMedia.add).toHaveBeenCalledWith(ref);expect(embeddedMedia.remove).toHaveBeenCalledTimes(0);wrapper.unmount();expect(embeddedMedia.add).toHaveBeenCalledTimes(2);expect(embeddedMedia.remove).toHaveBeenCalledTimes(1);expect(embeddedMedia.remove).toHaveBeenCalledWith(ref);});it('strips out images with relative paths',function(){var html="\n <div>\n <style>a { color: red }</style>\n <a href=\"foo\">\n <img src=\"bar.jpg\" />\n </a>\n </div>\n ";var wrapper=createWrapper(html);expect(wrapper.html()).not.toContain('<img');expect(wrapper.html()).toContain('<style>');expect(wrapper.render()).toMatchSnapshot();});it('should move style blocks out of the content',function(){var html="\n <div>\n <style>a { color: red }</style>\n <a href=\"foo\">\n <img src=\"bar.jpg\" />\n </a>\n </div>\n ";var wrapper=createWrapper(html,{processStyles:true});expect(wrapper.html()).not.toContain('<style>');});it('does not strip out images with absolute paths',function(){var html="\n <div>\n <a href=\"foo\">\n <img src=\"http://google.de/bar.jpg\" />\n </a>\n </div>\n ";var wrapper=createWrapper(html);expect(wrapper.html()).toContain('<img');expect(wrapper.render()).toMatchSnapshot();});it('strips out the script tags',function(){/**
|
|
10
|
+
expect(wrapper.html()).toEqual('<div class="common__html-sanitizer"><h1>Hello World!</h1></div>');expect(wrapper.render()).toMatchSnapshot();});it('should add and remove handlers for embedded media',function(){var wrapper=createWrapper('<div></div>',{decode:true});var ref=wrapper.instance().htmlContainer.current;expect(embeddedMedia.add).toHaveBeenCalledTimes(1);expect(embeddedMedia.add).toHaveBeenCalledWith(ref);expect(embeddedMedia.remove).toHaveBeenCalledTimes(0);wrapper.setProps({children:'<span></span>'});expect(embeddedMedia.add).toHaveBeenCalledTimes(2);expect(embeddedMedia.add).toHaveBeenCalledWith(ref);expect(embeddedMedia.remove).toHaveBeenCalledTimes(0);wrapper.unmount();expect(embeddedMedia.add).toHaveBeenCalledTimes(2);expect(embeddedMedia.remove).toHaveBeenCalledTimes(1);expect(embeddedMedia.remove).toHaveBeenCalledWith(ref);});it('strips out images with relative paths',function(){var html="\n <div>\n <style>a { color: red }</style>\n <a href=\"foo\">\n <img src=\"bar.jpg\" />\n </a>\n </div>\n ";var wrapper=createWrapper(html);expect(wrapper.html()).not.toContain('<img');expect(wrapper.html()).toContain('<style>');expect(wrapper.render()).toMatchSnapshot();});it('should move style blocks out of the content',function(){var html="\n <div>\n <style>a { color: red }</style>\n <a href=\"foo\">\n <img src=\"bar.jpg\" />\n </a>\n </div>\n ";var wrapper=createWrapper(html,{processStyles:true});expect(wrapper.html()).not.toContain('<style>');});it('does not strip out images with absolute paths',function(){var html="\n <div>\n <a href=\"foo\">\n <img src=\"http://google.de/bar.jpg\" />\n </a>\n </div>\n ";var wrapper=createWrapper(html);expect(wrapper.html()).toContain('<img');expect(wrapper.render()).toMatchSnapshot();});it('strips out the script tags',function(){/**
|
|
11
11
|
* The value for html is the HTML-escaped equivalent of the following:
|
|
12
12
|
* <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
|
|
13
13
|
* <script type="text/javascript">var x = 42;</script>
|
|
@@ -15,4 +15,4 @@ expect(wrapper.html()).toEqual('<div><h1>Hello World!</h1></div>');expect(wrappe
|
|
|
15
15
|
* <script>var y = 23;</script>
|
|
16
16
|
* @type {string}
|
|
17
17
|
*/var html='<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> <script type="text/javascript">var x = 42;</script> <p>Foo Bar</p> <script>var y = 23;</script>';var wrapper=createWrapper(html,{decode:true});// Test result of dangerouslySetInnerHTML.
|
|
18
|
-
expect(wrapper.html()).toEqual('<div> <p>Foo Bar</p> </div>');expect(wrapper).toMatchSnapshot();});describe('Link handling',function(){var mockedHandleClick=jest.fn();beforeEach(function(){mockedHandleClick.mockClear();});it('follows a link from a plain <a>',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='<a id="link" href="#follow-me-and-everything-is-alright">Plain Link</a>';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick},navigate:function navigate(){}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];aTag.closest=function(){return aTag;};var event={target:aTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#follow-me-and-everything-is-alright','');});it('follows a link from a <a> with other HTML inside',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='<a id="link" target="_blank" href="#I-ll-be-the-one-to-tuck-you-in-at-night"><span>Span Link</span></a>';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick},navigate:function navigate(){}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];var spanTag=doc.getElementsByTagName('span')[0];spanTag.closest=function(){return aTag;};var event={target:spanTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#I-ll-be-the-one-to-tuck-you-in-at-night','_blank');});});});
|
|
18
|
+
expect(wrapper.html()).toEqual('<div class="common__html-sanitizer"> <p>Foo Bar</p> </div>');expect(wrapper).toMatchSnapshot();});describe('Link handling',function(){var mockedHandleClick=jest.fn();beforeEach(function(){mockedHandleClick.mockClear();});it('follows a link from a plain <a>',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='<a id="link" href="#follow-me-and-everything-is-alright">Plain Link</a>';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick},navigate:function navigate(){}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];aTag.closest=function(){return aTag;};var event={target:aTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#follow-me-and-everything-is-alright','');});it('follows a link from a <a> with other HTML inside',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='<a id="link" target="_blank" href="#I-ll-be-the-one-to-tuck-you-in-at-night"><span>Span Link</span></a>';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick},navigate:function navigate(){}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];var spanTag=doc.getElementsByTagName('span')[0];spanTag.closest=function(){return aTag;};var event={target:spanTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#I-ll-be-the-one-to-tuck-you-in-at-night','_blank');});});});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import React,{memo}from'react';import PropTypes from'prop-types';import{i18n}from'@shopgate/engage/core/helpers/i18n';/**
|
|
1
|
+
var _excluded=["className"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import React,{memo}from'react';import PropTypes from'prop-types';import{i18n}from'@shopgate/engage/core/helpers/i18n';/**
|
|
2
2
|
* Formats a price.
|
|
3
3
|
* @param {Object} props The component props.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var FormatPrice=function FormatPrice(props){var className=props.className,formatProps=_objectWithoutProperties(props,
|
|
5
|
+
*/var FormatPrice=function FormatPrice(props){var className=props.className,formatProps=_objectWithoutProperties(props,_excluded);if(!className){return FormatPrice.format(formatProps);}return React.createElement("span",{className:className},FormatPrice.format(formatProps));};FormatPrice.format=function(_ref){var price=_ref.price,currency=_ref.currency,fractions=_ref.fractions;if(!i18n.ready){return price;}return i18n.price(price,currency,fractions);};FormatPrice.defaultProps={className:null,fractions:true};export default memo(FormatPrice);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{i18n}from'@shopgate/engage/core/helpers/i18n';import{logger}from'@shopgate/pwa-core/helpers';/**
|
|
2
2
|
* A React component that provides child components with i18n features.
|
|
3
3
|
* @returns {React.Component}
|
|
4
|
-
*/var I18nProvider=/*#__PURE__*/function(_Component){
|
|
4
|
+
*/var I18nProvider=/*#__PURE__*/function(_Component){/**
|
|
5
5
|
* @inheritDoc
|
|
6
|
-
*/function I18nProvider(props){var
|
|
7
|
-
|
|
8
|
-
* Provides context for child components.
|
|
9
|
-
* @returns {Object}
|
|
10
|
-
*/_createClass(I18nProvider,[{key:"getChildContext",value:function getChildContext(){return{i18n:this.getI18nInstance};}/**
|
|
6
|
+
*/function I18nProvider(props){var _this2;_classCallCheck(this,I18nProvider);_this2=_callSuper(this,I18nProvider,[props]);// eslint-disable-next-line react/prop-types
|
|
7
|
+
/**
|
|
11
8
|
* Gets a shortcut to i18n functionality with preset language.
|
|
12
9
|
* @returns {Object}
|
|
13
|
-
*/
|
|
10
|
+
*/_defineProperty(_this2,"getI18nInstance",function(){return{__:i18n.text,_p:i18n.price,_d:i18n.date,_t:i18n.time,_n:i18n.number};});if(_this2.props.lang||_this2.props.locales){logger.warn("===== I18nProvider deprecated =====\nI18nProvider and it's related components (@shopgate/pwa-common/component/I18n) or context types are deprecated and will be removed in @shopgate/engage v7.0.0.\nPlease use { i18n } from @shopgate/engage/core.\n===================================\n ");}return _this2;}/**
|
|
11
|
+
* Provides context for child components.
|
|
12
|
+
* @returns {Object}
|
|
13
|
+
*/_inherits(I18nProvider,_Component);return _createClass(I18nProvider,[{key:"getChildContext",value:function getChildContext(){return{i18n:this.getI18nInstance};}},{key:"render",value:/**
|
|
14
14
|
* Renders the component.
|
|
15
15
|
* @returns {JSX}
|
|
16
|
-
*/
|
|
16
|
+
*/function render(){var children=this.props.children;return children?React.cloneElement(children):null;}}]);}(Component);_defineProperty(I18nProvider,"childContextTypes",{i18n:PropTypes.func.isRequired});_defineProperty(I18nProvider,"defaultProps",{children:null});export{I18nProvider as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import React from'react';import PropTypes from'prop-types';import{renderToString}from'react-dom/server';import{logger}from'@shopgate/pwa-core';import{i18n}from'@shopgate/engage/core/helpers/i18n';/**
|
|
1
|
+
var _excluded=["string","children","params","className","role","transform","acceptPlainTextWithPlaceholders"];function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import React from'react';import PropTypes from'prop-types';import{renderToString}from'react-dom/server';import{logger}from'@shopgate/pwa-core';import{i18n}from'@shopgate/engage/core/helpers/i18n';/**
|
|
2
2
|
* Returns a translation and replaces placeholder with children output.
|
|
3
3
|
* It is possible to either pass JSX components or plain strings as replacement for
|
|
4
4
|
* the translation keys.
|
|
@@ -6,14 +6,18 @@ function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj
|
|
|
6
6
|
* and pass the JSX nodes as children.
|
|
7
7
|
* @param {Object} props The component props.
|
|
8
8
|
* @param {Object} props.string The string to translate.
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {Object} [props.params] Object with translation placeholder replacements
|
|
10
|
+
* @param {Array} [props.children] Children to use as placeholders. Must be one of the components
|
|
10
11
|
* provided by I18n.
|
|
11
|
-
* @param {string} props.className Additional classes to append to the translated wrapper element.
|
|
12
|
+
* @param {string} [props.className] Additional classes to append to the translated wrapper element.
|
|
13
|
+
* @param {string} [props.role] Optional aria role
|
|
12
14
|
* @param {Function} [props.transform] Input a function to modify the resulting string.
|
|
13
|
-
* @
|
|
14
|
-
|
|
15
|
+
* @param {boolean} [acceptPlainTextWithPlaceholders=false] When set to TRUE, the component can
|
|
16
|
+
* also handle human readable texts that contain text replacement placeholders.
|
|
17
|
+
* @returns {JSX.Element} The translated string as JSX component.
|
|
18
|
+
*/var Translate=function Translate(_ref){var string=_ref.string,children=_ref.children,params=_ref.params,className=_ref.className,role=_ref.role,transform=_ref.transform,acceptPlainTextWithPlaceholders=_ref.acceptPlainTextWithPlaceholders,rest=_objectWithoutProperties(_ref,_excluded);if(typeof string!=='string'||string.length===0){return string;}if(!i18n.ready){return React.createElement("span",_extends({className:className,role:role},rest),string);}// When the input string is malformed, return the original string rather than raising an error.
|
|
15
19
|
var formatted=string;try{// First replace every occurrence of a translation key with a separator.
|
|
16
20
|
var separator='__%S%__';var childrenArray=React.Children.toArray(children);var values=childrenArray.reduce(function(obj,child){return child.props&&child.props.forKey?_extends({},obj,_defineProperty({},child.props.forKey,separator)):obj;},_extends({},params));// Split the tokenized string at the separators.
|
|
17
|
-
var stringParts=i18n.text(string,values).split(separator);// Create a new array containing the separated chunks of the text and merge the substitutions.
|
|
21
|
+
var stringParts=i18n.text(string,values,{acceptPlainTextWithPlaceholders:acceptPlainTextWithPlaceholders}).split(separator);// Create a new array containing the separated chunks of the text and merge the substitutions.
|
|
18
22
|
// The result can be an array with multiple strings and will be joined together.
|
|
19
|
-
formatted=stringParts.reduce(function(result,text,index){return[].concat(result,[text,childrenArray[index]]);},[]);}catch(e){logger.error('i18n error for string %s',string,e);}return React.createElement("span",_extends({className:className,role:role},rest),!transform?formatted:transform(renderToString(formatted)));};Translate.defaultProps={children:null,className:null,params:{},role:null,transform:null};export default Translate;
|
|
23
|
+
formatted=stringParts.reduce(function(result,text,index){return[].concat(result,[text,childrenArray[index]]);},[]);}catch(e){logger.error('i18n error for string %s',string,e);}return React.createElement("span",_extends({className:className,role:role},rest),!transform?formatted:transform(renderToString(formatted)));};Translate.defaultProps={children:null,className:null,params:{},role:null,transform:null,acceptPlainTextWithPlaceholders:false};export default Translate;
|
package/components/Icon/index.js
CHANGED
|
@@ -6,4 +6,4 @@ import React from'react';import PropTypes from'prop-types';import styles from"./
|
|
|
6
6
|
* @param {string} [props.viewBox] The viewBox attribute passed to the SVG
|
|
7
7
|
* @param {number} [props.size=24] The icon size
|
|
8
8
|
* @returns {JSX}
|
|
9
|
-
*/var Icon=function Icon(props){return React.createElement("svg",{className:"".concat(styles," ").concat(props.className),viewBox:props.viewBox,xmlns:"http://www.w3.org/2000/svg",dangerouslySetInnerHTML:{__html:props.content},style:{fontSize:props.size,fill:props.color}});};Icon.defaultProps={className:'',color:null,viewBox:'0 0 24 24',size:'inherit'};export default Icon;
|
|
9
|
+
*/var Icon=function Icon(props){return React.createElement("svg",{className:"".concat(styles," ").concat(props.className," common__icon"),viewBox:props.viewBox,xmlns:"http://www.w3.org/2000/svg",dangerouslySetInnerHTML:{__html:props.content},style:{fontSize:props.size,fill:props.color}});};Icon.defaultProps={className:'',color:null,viewBox:'0 0 24 24',size:'inherit'};export default Icon;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{themeColors}from'@shopgate/pwa-common/helpers/config';import{getFullImageSource,logger}from'@shopgate/engage/core';import Transition from"../Transition";import styles from"./style";/**
|
|
1
|
+
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import{themeColors}from'@shopgate/pwa-common/helpers/config';import{getFullImageSource,logger}from'@shopgate/engage/core';import Transition from"../Transition";import styles from"./style";/**
|
|
2
2
|
* The image component. It supports lazy and progressive loading of images.
|
|
3
|
-
*/var Image=/*#__PURE__*/function(_Component){
|
|
3
|
+
*/var Image=/*#__PURE__*/function(_Component){/**
|
|
4
4
|
* Sets the initial state, to not render image slider component yet.
|
|
5
5
|
* @param {Object} props The components props.
|
|
6
|
-
*/function Image(props){var
|
|
6
|
+
*/function Image(props){var _this2;_classCallCheck(this,Image);_this2=_callSuper(this,Image,[props]);logger.assert(!props.srcmap,'Use of srcmap prop is deprecated. Use resolutions instead');/**
|
|
7
7
|
* The initial component state.
|
|
8
8
|
* Pre-loads all resolutions if already cached will
|
|
9
9
|
* set the state for the resolution to true.
|
|
10
10
|
* @type {Object}
|
|
11
|
-
*/if(props.srcmap){
|
|
11
|
+
*/if(props.srcmap){_this2.state={loaded:props.srcmap.map(function(image,index){return _this2.loadImage(image,index);})};}else{_this2.state={loaded:props.resolutions.map(function(resolution,index){return _this2.loadImage(_this2.props.src,index);})};}_this2.mounted=false;return _this2;}/**
|
|
12
12
|
* When component is added to the DOM.
|
|
13
|
-
*/_createClass(Image,[{key:"componentDidMount",value:function componentDidMount(){this.mounted=true;}/**
|
|
13
|
+
*/_inherits(Image,_Component);return _createClass(Image,[{key:"componentDidMount",value:function componentDidMount(){this.mounted=true;}/**
|
|
14
14
|
* When component was removed from DOM.
|
|
15
15
|
*/},{key:"componentWillUnmount",value:function componentWillUnmount(){this.mounted=false;}/**
|
|
16
16
|
* Sets the image ratio based on width and height.
|
|
17
17
|
* @return {number} The image ratio.
|
|
18
|
-
*/},{key:"
|
|
18
|
+
*/},{key:"imageRatio",get:function get(){if(this.props.ratio){var _this$props$ratio2=_slicedToArray(this.props.ratio,2),x=_this$props$ratio2[0],y=_this$props$ratio2[1];return(y/x*100).toFixed(3);}var _this$props$resolutio=this.props.resolutions[this.props.resolutions.length-1],width=_this$props$resolutio.width,height=_this$props$resolutio.height;return(height/width*100).toFixed(3);}/**
|
|
19
19
|
* Image loaded event listener
|
|
20
20
|
* @param {number} resolutionIndex The index of the loaded resolution
|
|
21
|
-
*/value:function imageLoaded(resolutionIndex){if(!this.mounted){return;}this.setState(function(_ref){var loaded=_ref.loaded;return{loaded:loaded.map(function(entry,index){if(resolutionIndex===index){return true;}return entry;})};});if(!this.props.srcmap&&resolutionIndex===this.props.resolutions.length-1){this.props.highestResolutionLoaded();}if(this.props.srcmap&&resolutionIndex===this.props.srcmap.length-1){this.props.highestResolutionLoaded();}}/**
|
|
21
|
+
*/},{key:"imageLoaded",value:function imageLoaded(resolutionIndex){if(!this.mounted){return;}this.setState(function(_ref){var loaded=_ref.loaded;return{loaded:loaded.map(function(entry,index){if(resolutionIndex===index){return true;}return entry;})};});if(!this.props.srcmap&&resolutionIndex===this.props.resolutions.length-1){this.props.highestResolutionLoaded();}if(this.props.srcmap&&resolutionIndex===this.props.srcmap.length-1){this.props.highestResolutionLoaded();}}/**
|
|
22
22
|
* Pre-loads the given image in given resolution
|
|
23
23
|
* @param {string} src Source to the image.
|
|
24
24
|
* @param {number} resolutionIndex The index of the loaded resolution.
|
|
25
25
|
* @returns {number} true if image is already in cache.
|
|
26
|
-
*/},{key:"loadImage",value:function loadImage(src,resolutionIndex){var
|
|
26
|
+
*/},{key:"loadImage",value:function loadImage(src,resolutionIndex){var _this3=this;var image=new window.Image();image.onload=function(){_this3.imageLoaded(resolutionIndex);if(_this3.props.onLoad){_this3.props.onLoad();}};image.onerror=function(){if(_this3.props.onError){_this3.props.onError();}};if(!this.props.srcmap){image.src=getFullImageSource(src,this.props.resolutions[resolutionIndex]);}else{image.src=src;}return image.complete;}/**
|
|
27
27
|
* Renders the smooth image component.
|
|
28
28
|
* @returns {JSX}
|
|
29
29
|
*/},{key:"render",value:function render(){var index=this.state.loaded.lastIndexOf(true);var src=null;if(index>-1){src=!this.props.srcmap?getFullImageSource(this.props.src,this.props.resolutions[index]):this.props.srcmap[index];}var innerImage=null;if(src&&!this.props.forcePlaceholder){// Applies a blur effect to every resolution that has the blur flag set to true.
|
|
30
30
|
var inlineStyles={width:'100%'};if(!this.props.srcmap&&this.props.resolutions[index].blur){inlineStyles.filter="blur(".concat(this.props.resolutions[index].blur,"px)");}// Renders the actual image.
|
|
31
|
-
innerImage=React.createElement("img",{className:this.props.classNameImg||styles.image,src:src,style:inlineStyles,alt:this.props.alt,"aria-label":this.props.alt,role:"presentation","data-test-id":"image"});}if(this.props.unwrapped){return innerImage;}var containerStyle=styles.container(this.props.backgroundColor,"".concat(this.imageRatio,"%"));if(!this.props.animating||!this.props.transition){return React.createElement("div",{className:"".concat(containerStyle," ").concat(this.props.className)},innerImage);}return React.createElement(Transition,{childrenStyles:this.props.transition,className:"".concat(containerStyle," ").concat(this.props.className)},innerImage);}}
|
|
31
|
+
innerImage=React.createElement("img",{className:"".concat(this.props.classNameImg||styles.image," common__image"),src:src,style:inlineStyles,alt:this.props.alt,"aria-label":this.props.alt,role:"presentation","data-test-id":"image"});}if(this.props.unwrapped){return innerImage;}var containerStyle=styles.container(this.props.backgroundColor,"".concat(this.imageRatio,"%"));if(!this.props.animating||!this.props.transition){return React.createElement("div",{className:"".concat(containerStyle," ").concat(this.props.className)},innerImage);}return React.createElement(Transition,{childrenStyles:this.props.transition,className:"".concat(containerStyle," ").concat(this.props.className)},innerImage);}}]);}(Component);_defineProperty(Image,"defaultProps",{alt:null,animating:true,backgroundColor:themeColors.placeholder,className:'',classNameImg:'',forcePlaceholder:false,highestResolutionLoaded:function highestResolutionLoaded(){},onError:null,onLoad:null,ratio:null,resolutions:[{width:440,height:440}],src:null,srcmap:null,transition:null,unwrapped:false});export default Image;
|
package/components/Image/spec.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}import React from'react';import{mount}from'enzyme';import Image from"./index";window.requestAnimationFrame=function(){};jest.unmock('@shopgate/pwa-core');describe('<Image />',function(){var loadedImages=[];global.Image=/*#__PURE__*/function(){/**
|
|
1
|
+
function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}import React from'react';import{mount}from'enzyme';import Image from"./index";window.requestAnimationFrame=function(){};jest.unmock('@shopgate/pwa-core');describe('<Image />',function(){var loadedImages=[];global.Image=/*#__PURE__*/function(){/**
|
|
2
2
|
* Saves all images on init
|
|
3
|
-
*/function _class(){_classCallCheck(this,_class);this.complete=true;loadedImages.push(this);}return _class;}();it('should render placeholders if forced to',function(){var wrapper=mount(React.createElement(Image,{src:"foo/bar",forcePlaceholder:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('img').length).toEqual(0);});it('should render placeholders if src is null',function(){var wrapper=mount(React.createElement(Image,{src:"foo/bar"}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('img').length).toEqual(1);});});
|
|
3
|
+
*/function _class(){_classCallCheck(this,_class);this.complete=true;loadedImages.push(this);}return _createClass(_class);}();it('should render placeholders if forced to',function(){var wrapper=mount(React.createElement(Image,{src:"foo/bar",forcePlaceholder:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('img').length).toEqual(0);});it('should render placeholders if src is null',function(){var wrapper=mount(React.createElement(Image,{src:"foo/bar"}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('img').length).toEqual(1);});});
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}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;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import throttle from'lodash/throttle';import isEqual from'lodash/isEqual';import{router}from'@virtuous/conductor';import{RouteContext}from"../../context";import{ITEMS_PER_LOAD}from"../../constants/DisplayOptions";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}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 asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}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;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{Component}from'react';import PropTypes from'prop-types';import throttle from'lodash/throttle';import isEqual from'lodash/isEqual';import{router}from'@virtuous/conductor';import{RouteContext}from"../../context";import{ITEMS_PER_LOAD}from"../../constants/DisplayOptions";/**
|
|
2
2
|
* This component receives a data source and will then load
|
|
3
3
|
* more items from it when the user reaches the end of the
|
|
4
4
|
* (parent) scroll container.
|
|
5
|
-
*/var InfiniteContainer=/*#__PURE__*/function(_Component){
|
|
5
|
+
*/var InfiniteContainer=/*#__PURE__*/function(_Component){/**
|
|
6
6
|
* The component constructor.
|
|
7
7
|
* @param {Object} props The component props.
|
|
8
8
|
* @param {Object} context The component context.
|
|
9
|
-
*/function InfiniteContainer(props,context){var
|
|
9
|
+
*/function InfiniteContainer(props,context){var _this2;_classCallCheck(this,InfiniteContainer);_this2=_callSuper(this,InfiniteContainer,[props,context]);_this2.domElement=null;_this2.domScrollContainer=null;/**
|
|
10
10
|
* 10ms was chosen because, on the one hand, it prevents the scroll event from flooding but,
|
|
11
11
|
* on the other hand, it does not hinder users that scroll quickly from reloading next chunk.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
var items=props.items,limit=props.limit,initialLimit=props.initialLimit;var currentOffset=items.length?initialLimit:limit;var _ref=context||{},_ref$state=_ref.state
|
|
12
|
+
*/_this2.handleLoadingProxy=throttle(function(){if(props.enablePromiseBasedLoading){_this2.handleLoadingPromise();}else{_this2.handleLoading();}},10);// A flag to prevent concurrent loading requests.
|
|
13
|
+
_this2.isLoading=false;// Determine the initial offset of items.
|
|
14
|
+
var items=props.items,limit=props.limit,initialLimit=props.initialLimit;var currentOffset=items.length?initialLimit:limit;var _ref=context||{},_ref$state=_ref.state,_ref$state2=_ref$state===void 0?{}:_ref$state,_ref$state2$offset=_ref$state2.offset,offset=_ref$state2$offset===void 0?0:_ref$state2$offset;_this2.state={itemCount:items.length,offset:[offset,currentOffset],// A state flag that will be true as long as we await more items.
|
|
15
15
|
// The loading indicator will be shown accordingly.
|
|
16
|
-
awaitingItems:true};return
|
|
16
|
+
awaitingItems:true};return _this2;}/**
|
|
17
17
|
* When the component is mounted, it tries to find a proper
|
|
18
18
|
* parent scroll container if available.
|
|
19
19
|
* After that it calls for the initial data to load.
|
|
20
|
-
*/_createClass(InfiniteContainer,[{key:"componentDidMount",value:function componentDidMount(){var current=this.props.containerRef.current;if(current){this.domScrollContainer=current;this.bindEvents();}// Initially request items if none received.
|
|
21
|
-
if(!this.props.items.length){var _this$state$
|
|
20
|
+
*/_inherits(InfiniteContainer,_Component);return _createClass(InfiniteContainer,[{key:"componentDidMount",value:function componentDidMount(){var current=this.props.containerRef.current;if(current){this.domScrollContainer=current;this.bindEvents();}// Initially request items if none received.
|
|
21
|
+
if(!this.props.items.length){var _this$state$offset2=_slicedToArray(this.state.offset,1),start=_this$state$offset2[0];this.props.loader(start);}this.verifyAllDone();}/**
|
|
22
22
|
* Checks if the component received new items or already received all items.
|
|
23
23
|
* @param {Object} nextProps The next props.
|
|
24
|
-
*/},{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){var
|
|
24
|
+
*/},{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){var _this3=this;/**
|
|
25
25
|
* Downstream logic to process the props. It's wrapped into a separate function, since it might
|
|
26
26
|
* be executed after the state was updated to avoid race conditions.
|
|
27
|
-
*/var finalize=function finalize(){var current=nextProps.containerRef.current;if(!
|
|
28
|
-
if(nextProps.enablePromiseBasedLoading){
|
|
27
|
+
*/var finalize=function finalize(){var current=nextProps.containerRef.current;if(!_this3.domScrollContainer&¤t){_this3.domScrollContainer=current;_this3.bindEvents();}if(_this3.receivedTotalItems(nextProps)){// Trigger loading if totalItems are available
|
|
28
|
+
if(nextProps.enablePromiseBasedLoading){_this3.handleLoadingPromise(true,nextProps);}else{_this3.handleLoading(true,nextProps);}}_this3.verifyAllDone(nextProps);};if(nextProps.requestHash!==this.props.requestHash){this.resetComponent(function(){finalize();});return;}if(nextProps.items.length>=this.state.itemCount){this.setState({itemCount:nextProps.items.length},finalize());}else{this.resetComponent(function(){finalize();});}}/**
|
|
29
29
|
* Let the component only update when props.items or state changes.
|
|
30
30
|
* @param {Object} nextProps The next component props.
|
|
31
31
|
* @param {Object} nextState The next component state.
|
|
@@ -54,13 +54,13 @@ if(!this.props.enablePromiseBasedLoading){this.isLoading=false;}}/**
|
|
|
54
54
|
* Tests if all items have been received and are visible based on current offset.
|
|
55
55
|
* @param {Object} [props] The current or next component props.
|
|
56
56
|
* @returns {boolean}
|
|
57
|
-
*/},{key:"allItemsAreRendered",value:function allItemsAreRendered(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:this.props;var totalItems=props.totalItems,items=props.items;var _this$state$
|
|
57
|
+
*/},{key:"allItemsAreRendered",value:function allItemsAreRendered(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:this.props;var totalItems=props.totalItems,items=props.items;var _this$state$offset3=_slicedToArray(this.state.offset,2),offset=_this$state$offset3[0],limit=_this$state$offset3[1];if(props.enablePromiseBasedLoading){// At promise based loading the offset is increased after the response came in.
|
|
58
58
|
// This method is invoked to evaluate if a new request needs to be dispatched, so we check
|
|
59
59
|
// against the current offset state.
|
|
60
60
|
return totalItems!==null&&(offset>=totalItems||offset===0&&Array.isArray(items)&&items.length===totalItems);}return!this.needsToReceiveItems(props)&&offset+limit>=totalItems;}/**
|
|
61
61
|
* Increases the current offset by limit (from props).
|
|
62
62
|
* @returns {Object}
|
|
63
|
-
*/},{key:"increaseOffset",value:function increaseOffset(){var _this$state$
|
|
63
|
+
*/},{key:"increaseOffset",value:function increaseOffset(){var _this$state$offset4=_slicedToArray(this.state.offset,2),start=_this$state$offset4[0],length=_this$state$offset4[1];var newOffset=start+length;/**
|
|
64
64
|
* When items are cached, the initial limit can be "6".
|
|
65
65
|
* Then, new offset should be limited to the "normal" limit (30).
|
|
66
66
|
* Otherwise, with cached items, this component would skip the initial number of items
|
|
@@ -70,7 +70,7 @@ newOffset=this.props.limit;}this.setState({offset:[newOffset,this.props.limit]})
|
|
|
70
70
|
* Resets the state.
|
|
71
71
|
* @param {Function} callback A callback which is invoked after the state was updated.
|
|
72
72
|
* This is necessary to avoid race conditions with downstream code.
|
|
73
|
-
*/},{key:"resetComponent",value:function resetComponent(callback){var
|
|
73
|
+
*/},{key:"resetComponent",value:function resetComponent(callback){var _this4=this;this.setState({offset:[0,this.props.limit],awaitingItems:true,itemCount:0},function(){_this4.unbindEvents();_this4.bindEvents();callback();});}/**
|
|
74
74
|
* Stops the lazy loading processes
|
|
75
75
|
*/},{key:"stopLazyLoading",value:function stopLazyLoading(){this.setState({awaitingItems:false});this.unbindEvents();}/**
|
|
76
76
|
* Verifies if all items are loaded and shown, then set final state and unbind events.
|
|
@@ -85,7 +85,7 @@ newOffset=this.props.limit;}this.setState({offset:[newOffset,this.props.limit]})
|
|
|
85
85
|
* @param {boolean} [force] If set to true, proceed independently of scroll validation.
|
|
86
86
|
* @param {Object} [props] The current or next component props.
|
|
87
87
|
*/},{key:"handleLoading",value:function handleLoading(){var force=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:this.props;// Do not load if there is an update in progress.
|
|
88
|
-
if(this.isLoading){return;}if(this.verifyAllDone()){return;}var _this$state$
|
|
88
|
+
if(this.isLoading){return;}if(this.verifyAllDone()){return;}var _this$state$offset5=_slicedToArray(this.state.offset,2),start=_this$state$offset5[0],length=_this$state$offset5[1];var items=props.items,totalItems=props.totalItems,loader=props.loader;var renderLength=start+length;if(force||this.validateScrollPosition()){// Check if we need to render items that we already received.
|
|
89
89
|
if(renderLength<=items.length){// Render already received items by increasing the offset.
|
|
90
90
|
this.isLoading=true;this.increaseOffset();}else if(items.length<totalItems){// We already rendered all received items but there are more available.
|
|
91
91
|
// Therefore request new items.
|
|
@@ -98,13 +98,13 @@ if(renderLength<items.length+length){this.increaseOffset();}}}}/**
|
|
|
98
98
|
* for offset handling.
|
|
99
99
|
* @param {boolean} [force] If set to true, proceed independently of scroll validation.
|
|
100
100
|
* @param {Object} [props] The current or next component props.
|
|
101
|
-
*/},{key:"handleLoadingPromise",value:function(){var _handleLoadingPromise=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var force,props,loader,_this$state$
|
|
102
|
-
this.isLoading=true;loader=props.loader;_context.prev=9;_this$state$
|
|
101
|
+
*/},{key:"handleLoadingPromise",value:function(){var _handleLoadingPromise=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var force,props,loader,_this$state$offset7,offset,_args=arguments;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:force=_args.length>0&&_args[0]!==undefined?_args[0]:false;props=_args.length>1&&_args[1]!==undefined?_args[1]:this.props;if(!this.isLoading){_context.next=4;break;}return _context.abrupt("return");case 4:if(!this.verifyAllDone()){_context.next=6;break;}return _context.abrupt("return");case 6:if(!(force||this.validateScrollPosition())){_context.next=20;break;}// Add isLoading state to prevent requests while the current one is running
|
|
102
|
+
this.isLoading=true;loader=props.loader;_context.prev=9;_this$state$offset7=_slicedToArray(this.state.offset,1),offset=_this$state$offset7[0];// Dispatch the request
|
|
103
103
|
_context.next=13;return loader(offset);case 13:// Increase the offset for the next request
|
|
104
104
|
this.increaseOffset();_context.next=19;break;case 16:_context.prev=16;_context.t0=_context["catch"](9);// Stop lazy loading processes on request error
|
|
105
105
|
this.stopLazyLoading();case 19:// Remove the loading state to enable next request
|
|
106
|
-
this.isLoading=false;case 20:case"end":return _context.stop();}}
|
|
106
|
+
this.isLoading=false;case 20:case"end":return _context.stop();}},_callee,this,[[9,16]]);}));function handleLoadingPromise(){return _handleLoadingPromise.apply(this,arguments);}return handleLoadingPromise;}()/**
|
|
107
107
|
* Renders the component.
|
|
108
108
|
* @returns {JSX}
|
|
109
|
-
*/},{key:"render",value:function render(){var
|
|
110
|
-
var children=items.slice(0,start+length).map(function(item){return iterator(_extends({},item,{columns:columns}));});var content=typeof wrapper==='function'?wrapper({children:children}):React.createElement(wrapper,{},children);return React.createElement("div",{ref:function ref(elementRef){
|
|
109
|
+
*/},{key:"render",value:function render(){var _this5=this;var _this$props=this.props,wrapper=_this$props.wrapper,items=_this$props.items,iterator=_this$props.iterator,loadingIndicator=_this$props.loadingIndicator,columns=_this$props.columns;var awaitingItems=this.state.awaitingItems;var _this$state$offset8=_slicedToArray(this.state.offset,2),start=_this$state$offset8[0],length=_this$state$offset8[1];// Only show items in offset range. uses iterator component as item factory
|
|
110
|
+
var children=items.slice(0,start+length).map(function(item){return iterator(_extends({},item,{columns:columns}));});var content=typeof wrapper==='function'?wrapper({children:children}):React.createElement(wrapper,{},children);return React.createElement("div",{ref:function ref(elementRef){_this5.domElement=elementRef;},className:"common__infinite-container"},React.createElement("div",null,content),awaitingItems&&loadingIndicator);}}]);}(Component);_defineProperty(InfiniteContainer,"contextType",RouteContext);_defineProperty(InfiniteContainer,"defaultProps",{columns:2,containerRef:{current:null},initialLimit:10,limit:ITEMS_PER_LOAD,loadingIndicator:null,preloadMultiplier:2,requestHash:null,totalItems:null,wrapper:'div',enablePromiseBasedLoading:false});export default InfiniteContainer;
|