@shopgate/engage 6.20.0-beta.6 → 6.20.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{Fragment,useCallback,useState}from'react';import PropTypes from'prop-types';import{connect}from'react-redux';import{css}from'glamor';import{i18n}from'@shopgate/engage/core';import appConfig,{themeConfig}from'@shopgate/pwa-common/helpers/config';import{Accordion,Card,ContextMenu,SurroundPortals,RippleButton}from'@shopgate/engage/components';import{getFavoritesCount,
|
|
2
|
-
// overflow: 'hidden',
|
|
3
|
-
background:colors.background,flexGrow:1,paddingTop:variables.gap.xsmall,paddingBottom:variables.gap.xxbig,paddingLeft:'16px',paddingRight:'16px'}).toString(),title:css({flex:1}).toString(),divider:css({height:1,width:'calc(100% + 32px)',backgroundColor:'rgb(234, 234, 234)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),spacer:css({height:1,width:'calc(100% + 32px)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),loadMoreButton:css({width:'calc(100% - 32px)',margin:16,backgroundColor:'var(--color-primary)',borderRadius:5}).toString()};/**
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{Fragment,useCallback,useEffect,useState}from'react';import PropTypes from'prop-types';import{connect}from'react-redux';import{css}from'glamor';import{i18n}from'@shopgate/engage/core';import appConfig,{themeConfig}from'@shopgate/pwa-common/helpers/config';import{Accordion,Card,ContextMenu,SurroundPortals,RippleButton}from'@shopgate/engage/components';import{getFavoritesCount,makeGetFavoritesIdsByList}from'@shopgate/pwa-common-commerce/favorites/selectors';import{FAVORITES_LIST_CONTEXT_MENU}from"../../constants/Portals";import Item from"../Item";import{ProductProvider}from"../../../product";import{FAVORITES_SHOW_LIMIT}from"../../constants/constants";var colors=themeConfig.colors,variables=themeConfig.variables;var styles={root:css({margin:'8px 8px 10px'}).toString(),rootNoFavoritesLists:css({background:colors.background,flexGrow:1,paddingTop:variables.gap.xsmall,paddingBottom:variables.gap.xxbig,paddingLeft:'16px',paddingRight:'16px'}).toString(),title:css({flex:1}).toString(),divider:css({height:1,width:'calc(100% + 32px)',backgroundColor:'rgb(234, 234, 234)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),spacer:css({height:1,width:'calc(100% + 32px)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),loadMoreButton:css({width:'calc(100% - 32px)',margin:16,backgroundColor:'var(--color-primary)',borderRadius:5}).toString()};/**
|
|
4
2
|
* Favorite List Label component
|
|
5
3
|
* @return {JSX}
|
|
6
4
|
*/var FavoriteListLabel=function FavoriteListLabel(_ref){var id=_ref.id,title=_ref.title,rename=_ref.rename,remove=_ref.remove,disableRemoveList=_ref.disableRemoveList;return/*#__PURE__*/React.createElement(Fragment,null,/*#__PURE__*/React.createElement("span",{className:styles.title},title),/*#__PURE__*/React.createElement(SurroundPortals,{portalName:FAVORITES_LIST_CONTEXT_MENU,portalProps:{id:id}},/*#__PURE__*/React.createElement(ContextMenu,null,/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:rename},i18n.text('favorites.rename_list')),/*#__PURE__*/React.createElement(ContextMenu.Item,{onClick:remove,disabled:disableRemoveList},i18n.text('favorites.remove_list')))));};/**
|
|
7
5
|
* The content of a favorites list
|
|
8
6
|
* @returns {JSX}
|
|
9
|
-
*/var FavoritesListContent=function FavoritesListContent(_ref2){var id=_ref2.id,productIds=_ref2.productIds,_addToCart=_ref2.addToCart,removeItem=_ref2.removeItem,shouldShowLoadMoreButton=_ref2.shouldShowLoadMoreButton,loadMore=_ref2.loadMore;return/*#__PURE__*/React.createElement(React.Fragment,null,/*#__PURE__*/React.createElement("div",{className:styles.divider}),productIds.length===0?/*#__PURE__*/React.createElement("span",null,i18n.text('favorites.empty')):null,productIds.map(function(_ref3){var productId=_ref3.productId;return/*#__PURE__*/React.createElement(ProductProvider,{productId:productId,key:productId},function(_ref4){var product=_ref4.product;return product?/*#__PURE__*/React.createElement(Item,{key:product.id,product:product,listId:id,productId:product.id,addToCart:function addToCart(e){e.preventDefault();e.stopPropagation();return _addToCart(product);},remove:function remove(e){e.preventDefault();e.stopPropagation();removeItem(product.id);}}):null;});}),shouldShowLoadMoreButton&&/*#__PURE__*/React.createElement(RippleButton,{type:"primary",className:styles.loadMoreButton,onClick:loadMore
|
|
7
|
+
*/var FavoritesListContent=function FavoritesListContent(_ref2){var id=_ref2.id,productIds=_ref2.productIds,_addToCart=_ref2.addToCart,removeItem=_ref2.removeItem,shouldShowLoadMoreButton=_ref2.shouldShowLoadMoreButton,loadMore=_ref2.loadMore;return/*#__PURE__*/React.createElement(React.Fragment,null,/*#__PURE__*/React.createElement("div",{className:styles.divider}),productIds.length===0?/*#__PURE__*/React.createElement("span",null,i18n.text('favorites.empty')):null,productIds.map(function(_ref3){var productId=_ref3.productId;return/*#__PURE__*/React.createElement(ProductProvider,{productId:productId,key:productId},function(_ref4){var product=_ref4.product;return product?/*#__PURE__*/React.createElement(Item,{key:product.id,product:product,listId:id,productId:product.id,addToCart:function addToCart(e){e.preventDefault();e.stopPropagation();return _addToCart(product);},remove:function remove(e){e.preventDefault();e.stopPropagation();removeItem(product.id);}}):null;});}),shouldShowLoadMoreButton&&/*#__PURE__*/React.createElement(RippleButton,{type:"primary",className:styles.loadMoreButton,onClick:loadMore},i18n.text('favorites.load_more_button')),/*#__PURE__*/React.createElement("div",{className:styles.spacer}));};/**
|
|
10
8
|
* @param {Object} _ State
|
|
11
9
|
* @param {Object} props Props
|
|
12
10
|
* @returns {Object}
|
|
13
|
-
*/var makeMapStateToProps=function makeMapStateToProps(_,_ref5){var id=_ref5.id;var getFavoritesIds=makeGetFavoritesIdsByList(function(){return id;});return function(state){return{favoriteIds:getFavoritesIds(state),favoritesCount:getFavoritesCount(state)
|
|
11
|
+
*/var makeMapStateToProps=function makeMapStateToProps(_,_ref5){var id=_ref5.id;var getFavoritesIds=makeGetFavoritesIdsByList(function(){return id;});return function(state){return{favoriteIds:getFavoritesIds(state),favoritesCount:getFavoritesCount(state)};};};/**
|
|
14
12
|
* Favorite List component
|
|
15
13
|
* @return {JSX}
|
|
16
|
-
*/var FavoriteList=function FavoriteList(_ref6){var id=_ref6.id,name=_ref6.name,favoriteIds=_ref6.favoriteIds,_rename=_ref6.rename,remove=_ref6.remove,removeItem=_ref6.removeItem,addToCart=_ref6.addToCart,disableRemoveList=_ref6.disableRemoveList;var _useState=useState(FAVORITES_SHOW_LIMIT),_useState2=_slicedToArray(_useState,2),offset=_useState2[0],setOffset=_useState2[1];var productIds=favoriteIds.slice(0,offset).map(function(productId){return{productId:productId};});var
|
|
14
|
+
*/var FavoriteList=function FavoriteList(_ref6){var id=_ref6.id,name=_ref6.name,favoriteIds=_ref6.favoriteIds,_rename=_ref6.rename,remove=_ref6.remove,removeItem=_ref6.removeItem,addToCart=_ref6.addToCart,disableRemoveList=_ref6.disableRemoveList;var _useState=useState(FAVORITES_SHOW_LIMIT),_useState2=_slicedToArray(_useState,2),offset=_useState2[0],setOffset=_useState2[1];var productIds=favoriteIds.slice(0,offset).map(function(productId){return{productId:productId};});var allFavoritesLoaded=favoriteIds.length-productIds.length>0;var _useState3=useState(allFavoritesLoaded),_useState4=_slicedToArray(_useState3,2),shouldShowLoadMoreButton=_useState4[0],setShouldShowLoadMoreButton=_useState4[1];var loadMore=useCallback(function(){setOffset(offset+FAVORITES_SHOW_LIMIT);},[offset]);useEffect(function(){setShouldShowLoadMoreButton(allFavoritesLoaded);},[offset,allFavoritesLoaded]);return appConfig.favorites.hasMultipleFavoritesLists?/*#__PURE__*/React.createElement(Card,{className:styles.root},/*#__PURE__*/React.createElement(Accordion,{className:"",openWithChevron:true,renderLabel:function renderLabel(){return/*#__PURE__*/React.createElement(FavoriteListLabel,{id:id,title:name,rename:function rename(newName){return _rename(id,newName);},remove:remove,disableRemoveList:disableRemoveList});},chevronPosition:"left",startOpened:true,testId:id},/*#__PURE__*/React.createElement(FavoritesListContent,{addToCart:addToCart,id:id,loadMore:loadMore,productIds:productIds,removeItem:removeItem,shouldShowLoadMoreButton:shouldShowLoadMoreButton}))):/*#__PURE__*/React.createElement("div",{className:styles.rootNoFavoritesLists},/*#__PURE__*/React.createElement(FavoritesListContent,{addToCart:addToCart,id:id,loadMore:loadMore,productIds:productIds,removeItem:removeItem,shouldShowLoadMoreButton:shouldShowLoadMoreButton}));};export default connect(makeMapStateToProps)(FavoriteList);
|
|
@@ -13,4 +13,4 @@ var promiseRef=useRef(null);var handleAddToCart=useCallback(function(listId,prod
|
|
|
13
13
|
var promise=new Promise(function(_resolve,reject){promiseRef.current={resolve:function resolve(){// Remove item from wishlist after adding to cart.
|
|
14
14
|
if(wishlistMode!==WISHLIST_MODE_PERSIST_ON_ADD){_removeItem(listId,product.id);}_resolve();},reject:reject};});// If all options are already configured immediately add it to the cart.
|
|
15
15
|
addToCart([{productId:product.id,quantity:1}]);promiseRef.current.resolve();return promise;},[addToCart,_removeItem,wishlistMode]);// Modal for renaming and adding.
|
|
16
|
-
var _useState=useState(false),_useState2=_slicedToArray(_useState,2),modalOpen=_useState2[0],setModalOpen=_useState2[1];var _useState3=useState(null),_useState4=_slicedToArray(_useState3,2),modalType=_useState4[0],setModalType=_useState4[1];var _useState5=useState(null),_useState6=_slicedToArray(_useState5,2),modalTarget=_useState6[0],setModalTarget=_useState6[1];var openAddModal=useCallback(function(){setModalOpen(true);setModalType('add_list');setModalTarget(null);},[]);var openRenameModal=useCallback(function(code){setModalOpen(true);setModalType('rename_list');setModalTarget(code);},[]);var closeModal=useCallback(function(){setModalOpen(false);setModalType(null);setModalTarget(null);},[]);var confirmModal=useCallback(function(name){if(modalType==='add_list'){addList(name);}else if(modalType==='rename_list'){updateList(modalTarget,name);}closeModal();},[addList,closeModal,modalTarget,modalType,updateList]);if(isInitializing){return null;}return/*#__PURE__*/React.createElement("div",{className:styles.root},lists.map(function(list){return/*#__PURE__*/React.createElement(SurroundPortals,{key:list.id,portalName:FAVORITES_LIST,portalProps:list},/*#__PURE__*/React.createElement(List,{id:list.id,name:list.name,rename:openRenameModal,remove:function remove(){return removeList(list.id);},removeItem:function removeItem(productId){return _removeItem(list.id,productId);},addToCart:function addToCart(product){return handleAddToCart(list.id,product);},disableRemoveList:lists.length<2}));}),modalOpen?/*#__PURE__*/React.createElement(ListsModal,{type:modalType,onDismiss:closeModal,onConfirm:confirmModal}):null,/*#__PURE__*/React.createElement(SurroundPortals,{portalName:FAVORITES_LIST_ADD_BUTTON},appConfig.hasMultipleFavoritesLists?/*#__PURE__*/React.createElement(RippleButton,{type:"primary",className:styles.addButton,onClick:openAddModal,disabled:false},i18n.text('favorites.add_list')):null));};FavoriteLists.defaultProps={lists:[],isInitializing:true};export default connect(mapStateToProps,mapDispatchToProps)(FavoriteLists);
|
|
16
|
+
var _useState=useState(false),_useState2=_slicedToArray(_useState,2),modalOpen=_useState2[0],setModalOpen=_useState2[1];var _useState3=useState(null),_useState4=_slicedToArray(_useState3,2),modalType=_useState4[0],setModalType=_useState4[1];var _useState5=useState(null),_useState6=_slicedToArray(_useState5,2),modalTarget=_useState6[0],setModalTarget=_useState6[1];var openAddModal=useCallback(function(){setModalOpen(true);setModalType('add_list');setModalTarget(null);},[]);var openRenameModal=useCallback(function(code){setModalOpen(true);setModalType('rename_list');setModalTarget(code);},[]);var closeModal=useCallback(function(){setModalOpen(false);setModalType(null);setModalTarget(null);},[]);var confirmModal=useCallback(function(name){if(modalType==='add_list'){addList(name);}else if(modalType==='rename_list'){updateList(modalTarget,name);}closeModal();},[addList,closeModal,modalTarget,modalType,updateList]);if(isInitializing){return null;}return/*#__PURE__*/React.createElement("div",{className:styles.root},lists.map(function(list){return/*#__PURE__*/React.createElement(SurroundPortals,{key:list.id,portalName:FAVORITES_LIST,portalProps:list},/*#__PURE__*/React.createElement(List,{id:list.id,name:list.name,rename:openRenameModal,remove:function remove(){return removeList(list.id);},removeItem:function removeItem(productId){return _removeItem(list.id,productId);},addToCart:function addToCart(product){return handleAddToCart(list.id,product);},disableRemoveList:lists.length<2}));}),modalOpen?/*#__PURE__*/React.createElement(ListsModal,{type:modalType,onDismiss:closeModal,onConfirm:confirmModal}):null,/*#__PURE__*/React.createElement(SurroundPortals,{portalName:FAVORITES_LIST_ADD_BUTTON},appConfig.favorites.hasMultipleFavoritesLists?/*#__PURE__*/React.createElement(RippleButton,{type:"primary",className:styles.addButton,onClick:openAddModal,disabled:false},i18n.text('favorites.add_list')):null));};FavoriteLists.defaultProps={lists:[],isInitializing:true};export default connect(mapStateToProps,mapDispatchToProps)(FavoriteLists);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var FAVORITES_SHOW_LIMIT=10;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "6.20.0-beta.
|
|
3
|
+
"version": "6.20.0-beta.9",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"connect"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@shopgate/pwa-common": "6.20.0-beta.
|
|
19
|
-
"@shopgate/pwa-common-commerce": "6.20.0-beta.
|
|
20
|
-
"@shopgate/pwa-core": "6.20.0-beta.
|
|
21
|
-
"@shopgate/pwa-ui-ios": "6.20.0-beta.
|
|
22
|
-
"@shopgate/pwa-ui-material": "6.20.0-beta.
|
|
23
|
-
"@shopgate/pwa-ui-shared": "6.20.0-beta.
|
|
18
|
+
"@shopgate/pwa-common": "6.20.0-beta.9",
|
|
19
|
+
"@shopgate/pwa-common-commerce": "6.20.0-beta.9",
|
|
20
|
+
"@shopgate/pwa-core": "6.20.0-beta.9",
|
|
21
|
+
"@shopgate/pwa-ui-ios": "6.20.0-beta.9",
|
|
22
|
+
"@shopgate/pwa-ui-material": "6.20.0-beta.9",
|
|
23
|
+
"@shopgate/pwa-ui-shared": "6.20.0-beta.9",
|
|
24
24
|
"@virtuous/conductor": "~2.4.0",
|
|
25
25
|
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
|
|
26
26
|
"babel-plugin-transform-es3-property-literals": "^6.8.0",
|