@shopgate/pwa-common 7.12.7-beta.1 → 7.20.0-beta.10
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/router/historyReplace.js +11 -1
- package/actions/user/getUser.js +1 -0
- package/actions/user/login.js +2 -2
- package/collections/AuthRoutes.js +3 -3
- package/collections/Configuration.js +3 -3
- package/collections/EmbeddedMedia.js +13 -3
- package/collections/PersistedReducers.js +2 -2
- package/collections/Redirects.js +3 -3
- package/collections/media-providers/MediaProvider.js +32 -4
- package/collections/media-providers/Vimeo.js +26 -7
- package/collections/media-providers/YouTube.js +10 -5
- package/collections/media-providers/style.js +2 -1
- 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/EmbeddedMedia/index.js +5 -5
- 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 +9 -0
- package/components/HtmlSanitizer/index.js +11 -11
- package/components/HtmlSanitizer/spec.js +4 -4
- 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/connector.js +1 -1
- 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/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 +12 -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 +6 -6
- 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/dom/index.js +2 -1
- package/helpers/html/parseHTML.js +10 -3
- package/helpers/i18n/getNumberFormatter.js +1 -1
- package/helpers/i18n/getTranslator.js +10 -4
- package/helpers/i18n/index.js +1 -1
- package/helpers/i18n/mergeTranslations.js +1 -1
- package/helpers/portals/portalCollection.js +3 -3
- package/helpers/redux/shouldFetchData.js +1 -1
- package/helpers/style/index.js +2 -2
- package/package.json +5 -5
- 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,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;
|
|
@@ -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 _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 _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,{useCallback,useState,useEffect,useRef}from'react';import PropTypes from'prop-types';import DayPicker from'react-day-picker';import MomentLocaleUtils from'react-day-picker/moment';import'react-day-picker/lib/style.css';import{css}from'glamor';import classNames from'classnames';import moment from'moment';import CalendarIcon from'@shopgate/pwa-ui-shared/icons/CalendarIcon';import appConfig,{themeConfig}from'@shopgate/pwa-common/helpers/config';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import{i18n}from'@shopgate/engage/core';import SimpleInput from"./SimpleInput";var variables=themeConfig.variables;var locale=appConfig.language.substring(0,2);/**
|
|
1
|
+
var _excluded=["onFocusChange","onChange","type","value"];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 _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 _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,{useCallback,useState,useEffect,useRef}from'react';import PropTypes from'prop-types';import DayPicker from'react-day-picker';import MomentLocaleUtils from'react-day-picker/moment';import'react-day-picker/lib/style.css';import{css}from'glamor';import classNames from'classnames';import moment from'moment';import CalendarIcon from'@shopgate/pwa-ui-shared/icons/CalendarIcon';import appConfig,{themeConfig}from'@shopgate/pwa-common/helpers/config';import Backdrop from'@shopgate/pwa-common/components/Backdrop';import{i18n}from'@shopgate/engage/core';import SimpleInput from"./SimpleInput";var variables=themeConfig.variables;var locale=appConfig.language.substring(0,2);/**
|
|
2
2
|
* @param {Object|string} date The input date
|
|
3
3
|
* @returns {string}
|
|
4
4
|
*/var getDateFromISO=function getDateFromISO(date){var result=moment(date);if(!result.isValid()){return null;}return result.toDate();};/**
|
|
@@ -14,4 +14,4 @@ function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj
|
|
|
14
14
|
*/var Caption=function Caption(_ref){var date=_ref.date,localeUtils=_ref.localeUtils,onChange=_ref.onChange;var months=localeUtils.getMonths(locale);var years=[];for(var i=fromMonth.getFullYear();i<=toMonth.getFullYear();i+=1){years.push(i);}var handleChange=function handleChange(e){var _e$target$form=e.target.form,year=_e$target$form.year,month=_e$target$form.month;onChange(new Date(year.value,month.value));};return React.createElement("div",{className:"DayPicker-Caption"},React.createElement("select",{name:"month",onChange:handleChange,value:date.getMonth(),className:styles.selectBox},months.map(function(month,i){return React.createElement("option",{key:month,value:i},month);})),React.createElement("select",{name:"year",onChange:handleChange,value:date.getFullYear(),className:styles.selectBox},years.map(function(year){return React.createElement("option",{key:year,value:year},year);})));};/**
|
|
15
15
|
* @param {Object} props The components props
|
|
16
16
|
* @returns {JSX}
|
|
17
|
-
*/var DateInput=function DateInput(_ref2){var onFocusChange=_ref2.onFocusChange,onChange=_ref2.onChange,type=_ref2.type,value=_ref2.value,rest=_objectWithoutProperties(_ref2,
|
|
17
|
+
*/var DateInput=function DateInput(_ref2){var onFocusChange=_ref2.onFocusChange,onChange=_ref2.onChange,type=_ref2.type,value=_ref2.value,rest=_objectWithoutProperties(_ref2,_excluded);var wrapperRef=useRef(null);var _useState=useState(getLocaleFormattedDate(value)),_useState2=_slicedToArray(_useState,2),inputValue=_useState2[0],setInputValue=_useState2[1];var _useState3=useState(getDateFromISO(value)),_useState4=_slicedToArray(_useState3,2),pickerValue=_useState4[0],setPickerValue=_useState4[1];var _useState5=useState(false),_useState6=_slicedToArray(_useState5,2),isFocused=_useState6[0],setIsFocused=_useState6[1];var _useState7=useState(false),_useState8=_slicedToArray(_useState7,2),pickerVisible=_useState8[0],setPickerVisible=_useState8[1];useEffect(function(){var updated=getLocaleFormattedDate(value);if(updated){setInputValue(updated);setPickerValue(getDateFromISO(value));}},[value]);var needsPositionTop=useCallback(function(){var element=wrapperRef.current;if(!element){return false;}var _element$getBoundingC=element.getBoundingClientRect(),top=_element$getBoundingC.top,height=_element$getBoundingC.height;var distToBottom=document.body.offsetHeight-(top+height);return distToBottom<=300;},[wrapperRef]);var handleInputValueChange=useCallback(function(val){setInputValue(val);},[]);var handleFocusChange=useCallback(function(focused,e){if(!focused){setPickerValue(getDateFromISO(getISOFormattedDate(inputValue)));onChange(inputValue.length!==0?getISOFormattedDate(inputValue,false):null);}setIsFocused(focused);onFocusChange(focused,e);},[inputValue,onChange,onFocusChange]);var handlePickerChange=useCallback(function(date){setPickerVisible(false);setPickerValue(date);setInputValue(getLocaleFormattedDate(date));onChange(getISOFormattedDate(date));},[onChange]);var handleMonthChange=useCallback(function(date){setPickerValue(date);},[]);var handleIconClick=useCallback(function(){setPickerVisible(!pickerVisible);},[pickerVisible]);var handleBackdropClick=useCallback(function(){setPickerVisible(false);},[]);return React.createElement(React.Fragment,null,React.createElement("div",{ref:wrapperRef},React.createElement(SimpleInput,_extends({},rest,{attributes:{placeholder:isFocused?i18n.text('formats.date.pattern'):null},value:inputValue,type:"text",onFocusChange:handleFocusChange,onChange:handleInputValueChange})),React.createElement("div",{className:styles.iconWrapper,onClick:handleIconClick,role:"button",tabIndex:"0",onKeyDown:handleIconClick},React.createElement(CalendarIcon,null))),React.createElement("div",{className:classNames(styles.pickerWrapper,_defineProperty({},styles.hidden,!pickerVisible))},React.createElement(DayPicker,{className:classNames('DayPickerInput-Overlay',styles.picker,_defineProperty({},styles.pickerTop,needsPositionTop())),onDayClick:handlePickerChange,selectedDays:pickerValue,localeUtils:MomentLocaleUtils,locale:locale,todayButton:i18n.text('locations.your_current_timeslot.today'),onTodayButtonClick:handlePickerChange,month:pickerValue,showOutsideDays:true,captionElement:function captionElement(_ref3){var date=_ref3.date,localeUtils=_ref3.localeUtils;return React.createElement(Caption,{date:date,localeUtils:localeUtils,onChange:handleMonthChange});}})),pickerVisible&&React.createElement(Backdrop,{isVisible:true,level:11,opacity:0,onClick:handleBackdropClick}));};DateInput.defaultProps={onFocusChange:function onFocusChange(){},onChange:function onChange(){},type:null,value:null};export default DateInput;
|
|
@@ -1,26 +1,26 @@
|
|
|
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 _get(target,property,receiver){if(typeof Reflect!=="undefined"&&Reflect.get){_get=Reflect.get;}else{_get=function _get(target,property,receiver){var base=_superPropBase(target,property);if(!base)return;var desc=Object.getOwnPropertyDescriptor(base,property);if(desc.get){return desc.get.call(receiver);}return desc.value;};}return _get(target,property,receiver||target);}function _superPropBase(object,property){while(!Object.prototype.hasOwnProperty.call(object,property)){object=_getPrototypeOf(object);if(object===null)break;}return object;}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 from'react';import classNames from'classnames';import{logger}from'@shopgate/pwa-core';import SimpleInput from"./SimpleInput";/**
|
|
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 _get(target,property,receiver){if(typeof Reflect!=="undefined"&&Reflect.get){_get=Reflect.get;}else{_get=function _get(target,property,receiver){var base=_superPropBase(target,property);if(!base)return;var desc=Object.getOwnPropertyDescriptor(base,property);if(desc.get){return desc.get.call(receiver);}return desc.value;};}return _get(target,property,receiver||target);}function _superPropBase(object,property){while(!Object.prototype.hasOwnProperty.call(object,property)){object=_getPrototypeOf(object);if(object===null)break;}return object;}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 from'react';import classNames from'classnames';import{logger}from'@shopgate/pwa-core';import SimpleInput from"./SimpleInput";/**
|
|
2
2
|
* A component that takes care of rendering and validation of input fields.
|
|
3
3
|
* This component has no styling and should not be used directly.
|
|
4
4
|
* You may want to use an appropriate form field component from the template instead.
|
|
5
|
-
*/var MultiLineInput=/*#__PURE__*/function(_SimpleInput){
|
|
5
|
+
*/var MultiLineInput=/*#__PURE__*/function(_SimpleInput){/**
|
|
6
6
|
* Creates a new input component.
|
|
7
7
|
* @param {Object} props The component properties.
|
|
8
|
-
*/function MultiLineInput(props){var
|
|
9
|
-
|
|
8
|
+
*/function MultiLineInput(props){var _this2;_classCallCheck(this,MultiLineInput);_this2=_callSuper(this,MultiLineInput,[props]);/**
|
|
9
|
+
* Sets an initial height of the multiline HTMLElement.
|
|
10
|
+
*/_defineProperty(_this2,"setBaseHeight",function(){if(_this2.baseHeight!==null){return;}_this2.baseHeight=_this2.ref.clientHeight;});_this2.baseHeight=null;// First render must be empty.
|
|
11
|
+
var sanitizedValue=_this2.props.onSanitize('');_this2.state={value:sanitizedValue,isValid:_this2.props.onValidate(sanitizedValue,true),isFocused:false};return _this2;}/**
|
|
10
12
|
* Additional function to make avoid .setState use in componentDidMount
|
|
11
13
|
* usage violation.
|
|
12
|
-
*/_createClass(MultiLineInput,[{key:"doComponentDidMount",value:function doComponentDidMount(){var sanitizedValue=this.props.onSanitize(this.props.value||'');this.props.onChange(sanitizedValue);this.setState({value:sanitizedValue,isValid:this.props.onValidate(sanitizedValue,true),isFocused:false});}/**
|
|
14
|
+
*/_inherits(MultiLineInput,_SimpleInput);return _createClass(MultiLineInput,[{key:"doComponentDidMount",value:function doComponentDidMount(){var sanitizedValue=this.props.onSanitize(this.props.value||'');this.props.onChange(sanitizedValue);this.setState({value:sanitizedValue,isValid:this.props.onValidate(sanitizedValue,true),isFocused:false});}/**
|
|
13
15
|
* Set real value and trigger second render.
|
|
14
16
|
* Initially trigger onChange() to set the initial value.
|
|
15
17
|
*/},{key:"componentDidMount",value:function componentDidMount(){// No super, would have to sanitize anyway.
|
|
16
18
|
this.doComponentDidMount();}/**
|
|
17
19
|
* Adjusts the element height.
|
|
18
|
-
*/},{key:"componentDidUpdate",value:function componentDidUpdate(){if(!(this.ref instanceof HTMLElement)){logger.error('Ref is not an HTMLElement');return;}this.ref.style.height="".concat(this.baseHeight,"px");this.ref.style.height="".concat(this.ref.scrollHeight,"px");}
|
|
19
|
-
* Sets an initial height of the multiline HTMLElement.
|
|
20
|
-
*/},{key:"handleRef",/**
|
|
20
|
+
*/},{key:"componentDidUpdate",value:function componentDidUpdate(){if(!(this.ref instanceof HTMLElement)){logger.error('Ref is not an HTMLElement');return;}this.ref.style.height="".concat(this.baseHeight,"px");this.ref.style.height="".concat(this.ref.scrollHeight,"px");}},{key:"handleRef",value:/**
|
|
21
21
|
* Handles reference passing to callback and assignation.
|
|
22
22
|
* @param {HTMLElement} ref The element
|
|
23
|
-
*/
|
|
23
|
+
*/function handleRef(ref){_get(_getPrototypeOf(MultiLineInput.prototype),"handleRef",this).call(this,ref);this.setBaseHeight();}/**
|
|
24
24
|
* Renders the component.
|
|
25
25
|
* @returns {JSX}
|
|
26
|
-
*/},{key:"render",value:function render(){var
|
|
26
|
+
*/},{key:"render",value:function render(){var _this3=this;var _this$props=this.props,className=_this$props.className,password=_this$props.password,attributes=_this$props.attributes;var type=password?'password':this.props.type;var value=this.state.value;return React.createElement("textarea",_extends({id:this.props.id,name:this.props.name,ref:function ref(_ref){return _this3.handleRef(_ref);},className:classNames(className,'multiLineInput','common__multi-line-input'),type:type,value:value,onChange:this.handleChange,onFocus:this.handleFocus,onBlur:this.handleBlur,disabled:this.props.disabled},attributes));}}]);}(SimpleInput);export default MultiLineInput;
|
|
@@ -1,19 +1,28 @@
|
|
|
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
|
|
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 classNames from'classnames';/**
|
|
2
2
|
* A component that takes care of rendering and validation of input fields.
|
|
3
3
|
* This component has no styling and should not be used directly.
|
|
4
4
|
* You may want to use an appropriate form field component from the template instead.
|
|
5
|
-
*/var SimpleInput=/*#__PURE__*/function(_Component){
|
|
5
|
+
*/var SimpleInput=/*#__PURE__*/function(_Component){/**
|
|
6
6
|
* Creates a new input component.
|
|
7
7
|
* @param {Object} props The component properties.
|
|
8
|
-
*/function SimpleInput(props){var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
8
|
+
*/function SimpleInput(props){var _this2;_classCallCheck(this,SimpleInput);_this2=_callSuper(this,SimpleInput,[props]);/**
|
|
9
|
+
* Internal focus event handler.
|
|
10
|
+
* @param {Object} e The event object.
|
|
11
|
+
*/_defineProperty(_this2,"handleFocus",function(e){_this2.setState({isFocused:true});_this2.props.onFocusChange(true,e);});/**
|
|
12
|
+
* Internal blur event handler.
|
|
13
|
+
* @param {Object} e The event object.
|
|
14
|
+
*/_defineProperty(_this2,"handleBlur",function(e){var newState={isFocused:false};if(_this2.props.validateOnBlur){// Validate the value.
|
|
15
|
+
newState.isValid=_this2.props.onValidate(_this2.value,false);}_this2.setState(newState);_this2.props.onFocusChange(false,e);});/**
|
|
16
|
+
* Internal change event handler.
|
|
17
|
+
* @param {Object} event The event object.
|
|
18
|
+
*/_defineProperty(_this2,"handleChange",function(event){var _event$target,_event$target$validit;var value=_this2.state.value;var type=_this2.props.type;// Special handling to prevent invalid characters within number inputs on Firefox / Safari
|
|
19
|
+
if(type==='number'&&(event===null||event===void 0?void 0:(_event$target=event.target)===null||_event$target===void 0?void 0:(_event$target$validit=_event$target.validity)===null||_event$target$validit===void 0?void 0:_event$target$validit.badInput)){event.preventDefault();event.stopPropagation();_this2.ref.value=value;return;}// Sanitize the input value.
|
|
20
|
+
var sanitizedValue=_this2.props.onSanitize(event.target.value||'');// Update the state.
|
|
21
|
+
_this2.updateValue(sanitizedValue,!_this2.props.isControlled);// Emit an event.
|
|
22
|
+
_this2.props.onChange(sanitizedValue,event);});_this2.ref=null;// Initially sanitize the value.
|
|
23
|
+
var _sanitizedValue=_this2.props.onSanitize(_this2.props.value||'');_this2.state={value:_sanitizedValue,isValid:_this2.props.onValidate(_sanitizedValue,true),isFocused:false};return _this2;}/**
|
|
15
24
|
* Initially trigger onChange() to set the initial value.
|
|
16
|
-
*/_createClass(SimpleInput,[{key:"componentDidMount",value:function componentDidMount(){var sanitizedValue=this.props.onSanitize(this.props.value||'');this.props.onChange(sanitizedValue);}/**
|
|
25
|
+
*/_inherits(SimpleInput,_Component);return _createClass(SimpleInput,[{key:"componentDidMount",value:function componentDidMount(){var sanitizedValue=this.props.onSanitize(this.props.value||'');this.props.onChange(sanitizedValue);}/**
|
|
17
26
|
* Updates the value of the input field if the props has been modified.
|
|
18
27
|
* @param {Object} nextProps The new properties.
|
|
19
28
|
*/},{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){/**
|
|
@@ -21,10 +30,14 @@ var _sanitizedValue=_this.props.onSanitize(_this.props.value||'');_this.state={v
|
|
|
21
30
|
* otherwise use the current input state.
|
|
22
31
|
*/var sanitizedValue=this.props.onSanitize(nextProps.value||'');if(sanitizedValue!==this.state.value){this.updateValue(sanitizedValue,true);}}/**
|
|
23
32
|
* @returns {boolean} Whether the current value of the input field is valid.
|
|
24
|
-
*/},{key:"
|
|
33
|
+
*/},{key:"isValid",get:function get(){return this.state.isValid;}/**
|
|
34
|
+
* @return {boolean} Whether the input field is focused.
|
|
35
|
+
*/},{key:"isFocused",get:function get(){return this.state.isFocused;}/**
|
|
36
|
+
* @returns {string} The current value of the input field.
|
|
37
|
+
*/},{key:"value",get:function get(){return this.state.value;}},{key:"handleRef",value:/**
|
|
25
38
|
* Handles reference passing to callback and assignation.
|
|
26
39
|
* @param {HTMLElement} ref The element
|
|
27
|
-
*/
|
|
40
|
+
*/function handleRef(ref){this.ref=ref;this.props.setRef(ref);}/**
|
|
28
41
|
* Updates and validates the internal state value of the input field.
|
|
29
42
|
* @param {string} newValue The new value.
|
|
30
43
|
* @param {boolean} setOwnState Specifies whether or not to update the internal state.
|
|
@@ -33,13 +46,6 @@ newState.isValid=this.props.onValidate(newValue,false);}// Uncontrolled when set
|
|
|
33
46
|
if(setOwnState){this.setState(newState);}}/**
|
|
34
47
|
* Renders the component.
|
|
35
48
|
* @returns {JSX}
|
|
36
|
-
*/},{key:"render",value:function render(){var
|
|
49
|
+
*/},{key:"render",value:function render(){var _this3=this;var _this$props=this.props,attributes=_this$props.attributes,className=_this$props.className,password=_this$props.password,onKeyPress=_this$props.onKeyPress,maxLength=_this$props.maxLength;var type=password?'password':this.props.type;var value=this.state.value;var autoComplete=this.props.autoComplete?'on':'off';var autoCorrect=this.props.autoCorrect?'on':'off';var InputComponent=this.props.inputComponent;return React.createElement(InputComponent,_extends({id:this.props.id,name:this.props.name,ref:function ref(_ref){return _this3.handleRef(_ref);},className:classNames(className,'simpleInput','common__simple-input'),type:type,inputMode:type==='number'?'decimal':null,pattern:type==='number'?'[0-9]*':null,min:type==='number'?0:null,step:type==='number'?'any':null,value:value,onKeyPress:onKeyPress// Use onInput for number fields to enable handling for invalid values
|
|
37
50
|
// (onChange might to be triggered when the input is invalid)
|
|
38
|
-
,onInput:type==='number'?this.handleChange:null,onChange:type!=='number'?this.handleChange:function(){},onFocus:this.handleFocus,onBlur:this.handleBlur,disabled:this.props.disabled,autoCorrect:autoCorrect,autoComplete:autoComplete},attributes));}},
|
|
39
|
-
* @return {boolean} Whether the input field is focused.
|
|
40
|
-
*/},{key:"isFocused",get:function get(){return this.state.isFocused;}/**
|
|
41
|
-
* @returns {string} The current value of the input field.
|
|
42
|
-
*/},{key:"value",get:function get(){return this.state.value;}/**
|
|
43
|
-
* Internal focus event handler.
|
|
44
|
-
* @param {Object} e The event object.
|
|
45
|
-
*/}]);return SimpleInput;}(Component);_defineProperty(SimpleInput,"defaultProps",{attributes:null,autoComplete:false,autoCorrect:false,className:'',disabled:false,id:null,isControlled:false,name:null,onChange:function onChange(){},onFocusChange:function onFocusChange(){},onKeyPress:function onKeyPress(){},onSanitize:function onSanitize(value){return value;},onValidate:function onValidate(){return true;},password:false,setRef:function setRef(){},type:'text',validateOnBlur:true,value:'',inputComponent:'input'});export default SimpleInput;
|
|
51
|
+
,onInput:type==='number'?this.handleChange:null,onChange:type!=='number'?this.handleChange:function(){},onFocus:this.handleFocus,onBlur:this.handleBlur,disabled:this.props.disabled,autoCorrect:autoCorrect,autoComplete:autoComplete,maxLength:maxLength},attributes));}}]);}(Component);_defineProperty(SimpleInput,"defaultProps",{attributes:null,autoComplete:false,autoCorrect:false,className:'',disabled:false,id:null,isControlled:false,maxLength:'',name:null,onChange:function onChange(){},onFocusChange:function onFocusChange(){},onKeyPress:function onKeyPress(){},onSanitize:function onSanitize(value){return value;},onValidate:function onValidate(){return true;},password:false,setRef:function setRef(){},type:'text',validateOnBlur:true,value:'',inputComponent:'input'});export default SimpleInput;
|
|
@@ -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 Event from'@shopgate/pwa-core/classes/Event';import{EVENT_KEYBOARD_WILL_CHANGE}from'@shopgate/pwa-core/constants/AppEvents';/**
|
|
2
2
|
* Keyboard state consumer.
|
|
3
|
-
*/var KeyboardConsumer=/*#__PURE__*/function(_PureComponent){
|
|
3
|
+
*/var KeyboardConsumer=/*#__PURE__*/function(_PureComponent){function KeyboardConsumer(){var _this2;_classCallCheck(this,KeyboardConsumer);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this2=_callSuper(this,KeyboardConsumer,[].concat(args));_defineProperty(_this2,"state",{open:false,overlap:0,duration:0});/**
|
|
4
|
+
* Stores current keyboard state.
|
|
5
|
+
*/_defineProperty(_this2,"handleKeyboardChange",function(_ref){var open=_ref.open,overlap=_ref.overlap,duration=_ref.duration;_this2.setState({open:open,overlap:overlap,duration:duration});});return _this2;}_inherits(KeyboardConsumer,_PureComponent);return _createClass(KeyboardConsumer,[{key:"componentDidMount",value:/**
|
|
4
6
|
* Listen to keyboard changes as soon as the component mounts.
|
|
5
|
-
*/
|
|
7
|
+
*/function componentDidMount(){Event.addCallback(EVENT_KEYBOARD_WILL_CHANGE,this.handleKeyboardChange);}/**
|
|
6
8
|
* Remove listener when component will unmount.
|
|
7
|
-
*/},{key:"componentWillUnmount",value:function componentWillUnmount(){Event.removeCallback(EVENT_KEYBOARD_WILL_CHANGE,this.handleKeyboardChange);}
|
|
8
|
-
* Stores current keyboard state.
|
|
9
|
-
*/},{key:"render",/**
|
|
9
|
+
*/},{key:"componentWillUnmount",value:function componentWillUnmount(){Event.removeCallback(EVENT_KEYBOARD_WILL_CHANGE,this.handleKeyboardChange);}},{key:"render",value:/**
|
|
10
10
|
* @returns {JSX}
|
|
11
|
-
*/
|
|
11
|
+
*/function render(){return this.props.children(this.state);}}]);}(PureComponent);export default KeyboardConsumer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{connect}from'react-redux';import{historyPush
|
|
1
|
+
import{connect}from'react-redux';import{historyPush,historyReplace}from"../../actions/router";var mapDispatchToProps={historyPush:historyPush,historyReplace:historyReplace};export default connect(null,mapDispatchToProps);
|
package/components/Link/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
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
|
|
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{hasWebBridge}from'@shopgate/engage/core';import connect from"./connector";import styles from"./style";/**
|
|
2
2
|
* Link component.
|
|
3
3
|
* @param {Object} props Props for the component.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var Link=/*#__PURE__*/function(_Component){
|
|
6
|
-
|
|
5
|
+
*/var Link=/*#__PURE__*/function(_Component){function Link(){var _this2;_classCallCheck(this,Link);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this2=_callSuper(this,Link,[].concat(args));/**
|
|
6
|
+
* Opens the link.
|
|
7
|
+
* @param {Event} e An event object.
|
|
8
|
+
*/_defineProperty(_this2,"handleOpenLink",function(e){e.preventDefault();if(_this2.props.disabled){return;}var params={pathname:_this2.props.href,state:_extends({},_this2.props.state||{},{},_this2.props.target?{target:_this2.props.target}:{})};// setTimeout prevents double click while VoiceOver is active
|
|
9
|
+
setTimeout(function(){if(_this2.props.replace){_this2.props.historyReplace(params);}else{_this2.props.historyPush(params);}},0);});return _this2;}_inherits(Link,_Component);return _createClass(Link,[{key:"render",value:/**
|
|
7
10
|
* Renders the component.
|
|
8
11
|
* @returns {JSX}
|
|
9
|
-
*/
|
|
12
|
+
*/function render(){var _this$props=this.props,tag=_this$props.tag,className=_this$props.className,href=_this$props.href,children=_this$props.children,role=_this$props.role,ariaLabel=_this$props['aria-label'],ariaHidden=_this$props['aria-hidden'],tabIndex=_this$props.tabIndex;var Tag=tag;if(!hasWebBridge()&&tag==='a'){/**
|
|
10
13
|
* Don't use link tags on apps. Sometimes links are really opened since the preventDefault
|
|
11
14
|
* doesn't work as expected which results in white pages.
|
|
12
|
-
*/Tag='span';}return React.createElement(Tag,{className:"".concat(styles," ").concat(className),onClick:this.handleOpenLink,role:role,"data-test-id":"link: ".concat(href),"aria-label":ariaLabel,tabIndex:tabIndex,"aria-hidden":ariaHidden,href:href&&Tag==='a'?href:null},children);}}]);
|
|
15
|
+
*/Tag='span';}return React.createElement(Tag,{className:"".concat(styles," ").concat(className," common__link"),onClick:this.handleOpenLink,role:role,"data-test-id":"link: ".concat(href),"aria-label":ariaLabel,tabIndex:tabIndex,"aria-hidden":ariaHidden,href:href&&Tag==='a'?href:null},children);}}]);}(Component);_defineProperty(Link,"defaultProps",{'aria-hidden':null,'aria-label':null,className:'',disabled:false,replace:false,role:'link',tag:'div',tabIndex:null,target:null,state:{}});export var Disconnected=Link;export default connect(Link);
|
|
@@ -2,4 +2,4 @@ import React from'react';import PropTypes from'prop-types';import styles from"./
|
|
|
2
2
|
* The ListItem component.
|
|
3
3
|
* @returns {JSX}
|
|
4
4
|
*/var ListItem=function ListItem(_ref){var children=_ref.children,className=_ref.className,isSelected=_ref.isSelected,role=_ref.role;if(!React.Children.count(children)){return null;}var classes=styles.item;if(className){classes+=" ".concat(className);}// Add selected or unselected styling.
|
|
5
|
-
classes+=" ".concat(isSelected?styles.selected:styles.unselected);return React.createElement("li",{className:classes,"data-test-id":"listItem",role:role},children);};ListItem.defaultProps={className:null,children:null,isSelected:false,role:null};export default ListItem;
|
|
5
|
+
classes+=" common__list__list-item ".concat(isSelected?styles.selected:styles.unselected);return React.createElement("li",{className:classes,"data-test-id":"listItem",role:role},children);};ListItem.defaultProps={className:null,children:null,isSelected:false,role:null};export default ListItem;
|
package/components/List/index.js
CHANGED
|
@@ -2,4 +2,4 @@ import React from'react';import PropTypes from'prop-types';import ListItem from"
|
|
|
2
2
|
* The List component.
|
|
3
3
|
* @param {Object} props The component props.
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/var List=function List(_ref){var children=_ref.children,className=_ref.className,role=_ref.role;return React.createElement("ul",{className:className,role:role},children);};List.Item=ListItem;List.defaultProps={className:'',role:null};export default List;
|
|
5
|
+
*/var List=function List(_ref){var children=_ref.children,className=_ref.className,role=_ref.role;return React.createElement("ul",{className:"".concat(className," common_list"),role:role},children);};List.Item=ListItem;List.defaultProps={className:'',role:null};export default List;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{css}from'glamor';var container=css({position:'fixed',top:0,bottom:0,left:0,right:0,overflow:'hidden',zIndex:2000}).toString();var layout=css({display:'flex',flexDirection:'column',alignItems:'center',justifyContent:'center',height:'100%'}).toString();var content=css({position:'relative',maxWidth:'100vw',maxHeight:'100vh',paddingTop:'var(--safe-area-inset-top)',paddingBottom:'var(--safe-area-inset-bottom)',overflowY:'scroll'}).toString();export default{container:container,layout:layout,content:content};
|
|
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;}import{css}from'glamor';import{responsiveMediaQuery}from'@shopgate/engage/styles';var container=css({position:'fixed',top:0,bottom:0,left:0,right:0,overflow:'hidden',zIndex:2000}).toString();var layout=css({display:'flex',flexDirection:'column',alignItems:'center',justifyContent:'center',height:'100%'}).toString();var content=css(_defineProperty({position:'relative',maxWidth:'100vw',maxHeight:'100vh',paddingTop:'var(--safe-area-inset-top)',paddingBottom:'var(--safe-area-inset-bottom)',overflowY:'scroll'},responsiveMediaQuery('>xs',{webOnly:true}),{overflowY:'initial'})).toString();export default{container:container,layout:layout,content:content};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
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;}import React from'react';import PropTypes from'prop-types';import classNames from'classnames';import styles from"./style";/**
|
|
2
2
|
* The default button for the Picker component.
|
|
3
3
|
* @returns {JSX} The button component.
|
|
4
|
-
*/var PickerList=function PickerList(_ref){var items=_ref.items,onClose=_ref.onClose,onSelect=_ref.onSelect,selectedIndex=_ref.selectedIndex;return React.createElement("ul",
|
|
4
|
+
*/var PickerList=function PickerList(_ref){var items=_ref.items,onClose=_ref.onClose,onSelect=_ref.onSelect,selectedIndex=_ref.selectedIndex;return React.createElement("ul",{className:"common__picker__list"},items.map(function(item,currentIndex){return React.createElement("li",{key:item.value,className:classNames(_defineProperty({},styles.active,currentIndex===selectedIndex))},React.createElement("button",{className:styles.button,disabled:item.disabled,onClick:function onClick(){onSelect(item.value);onClose();},type:"button"},item.label));}));};PickerList.defaultProps={onClose:function onClose(){},selectedIndex:null};export default PickerList;
|
|
@@ -1,14 +1,14 @@
|
|
|
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 styles from"./style";/**
|
|
2
2
|
* The picker modal.
|
|
3
|
-
*/var PickerModal=/*#__PURE__*/function(_Component){
|
|
3
|
+
*/var PickerModal=/*#__PURE__*/function(_Component){/**
|
|
4
4
|
* The constructor.
|
|
5
5
|
* @param {Object} props The props.
|
|
6
|
-
*/function PickerModal(props){var
|
|
6
|
+
*/function PickerModal(props){var _this2;_classCallCheck(this,PickerModal);_this2=_callSuper(this,PickerModal,[props]);/**
|
|
7
|
+
* Closes the modal after the closing animations have finished.
|
|
8
|
+
*/_defineProperty(_this2,"closeModal",function(){_this2.setState({active:false});clearTimeout(_this2.timeout);_this2.timeout=setTimeout(_this2.props.onClose,styles.duration);});_this2.timeout=null;_this2.state={active:true};return _this2;}/**
|
|
7
9
|
* Update state when isOpen changes.
|
|
8
10
|
* @param {Object} nextProps The next component props.
|
|
9
|
-
*/_createClass(PickerModal,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isOpen!==nextProps.isOpen){this.setState({active:nextProps.isOpen});}}
|
|
10
|
-
* Closes the modal after the closing animations have finished.
|
|
11
|
-
*/},{key:"render",/**
|
|
11
|
+
*/_inherits(PickerModal,_Component);return _createClass(PickerModal,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isOpen!==nextProps.isOpen){this.setState({active:nextProps.isOpen});}}},{key:"render",value:/**
|
|
12
12
|
* Render all the things!
|
|
13
13
|
* @returns {JSX} The picker modal with the picker list inside.
|
|
14
|
-
*/
|
|
14
|
+
*/function render(){var backgroundClassName=classNames(styles.background.base,_defineProperty({},styles.background.inactive,!this.state.active));var containerClassName=classNames(styles.container.base,_defineProperty({},styles.container.inactive,!this.state.active));return this.props.isOpen?React.createElement("div",{className:"".concat(styles.wrapper," common__picker__modal")},React.createElement("div",{"aria-hidden":true,className:backgroundClassName,onClick:this.closeModal}),React.createElement("div",{className:containerClassName},React.cloneElement(this.props.children,{onClose:this.closeModal}))):null;}}]);}(Component);export default PickerModal;
|