@shopgate/engage 7.29.1-beta.1 → 7.29.1-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "7.29.1-beta.1",
3
+ "version": "7.29.1-beta.2",
4
4
  "description": "Shopgate's ENGAGE library.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -17,12 +17,12 @@
17
17
  "dependencies": {
18
18
  "@emotion/react": "^11.14.0",
19
19
  "@shopgate/native-modules": "1.0.0-beta.25",
20
- "@shopgate/pwa-common": "7.29.1-beta.1",
21
- "@shopgate/pwa-common-commerce": "7.29.1-beta.1",
22
- "@shopgate/pwa-core": "7.29.1-beta.1",
23
- "@shopgate/pwa-ui-ios": "7.29.1-beta.1",
24
- "@shopgate/pwa-ui-material": "7.29.1-beta.1",
25
- "@shopgate/pwa-ui-shared": "7.29.1-beta.1",
20
+ "@shopgate/pwa-common": "7.29.1-beta.2",
21
+ "@shopgate/pwa-common-commerce": "7.29.1-beta.2",
22
+ "@shopgate/pwa-core": "7.29.1-beta.2",
23
+ "@shopgate/pwa-ui-ios": "7.29.1-beta.2",
24
+ "@shopgate/pwa-ui-material": "7.29.1-beta.2",
25
+ "@shopgate/pwa-ui-shared": "7.29.1-beta.2",
26
26
  "@stripe/react-stripe-js": "^1.16.5",
27
27
  "@stripe/stripe-js": "^1.3.1",
28
28
  "@virtuous/conductor": "~2.5.0",
@@ -68,3 +68,17 @@ type BorderRadiusParams = {
68
68
  export declare function resolveBorderRadiusFromWidgetConfig(
69
69
  params: BorderRadiusParams
70
70
  )
71
+
72
+ /**
73
+ * Validator factory for regular expressions.
74
+ * @param regex The regular expression to match.
75
+ * @returns A function that validates if a value matches the regex.
76
+ */
77
+ export declare function matchesRegex(regex: RegExp): (val: string) => boolean;
78
+
79
+ /**
80
+ * Validates if a given string is a valid HTTPS URL.
81
+ * @param val The string to validate.
82
+ * @returns True if the string is a valid HTTPS URL, false otherwise.
83
+ */
84
+ export declare const isHttpsUrl: (val: string) => boolean;
@@ -21,4 +21,12 @@ var _ref2=mapping.find(function(_ref4){var _ref5=_slicedToArray(_ref4,2),value=_
21
21
  * @param {"default"|"none"|"rounded"|"custom"} params.borderRadius The border radius option.
22
22
  * @param {number} params.borderRadiusCustom The custom border radius value.
23
23
  * @returns {number} The resolved border radius.
24
- */export var resolveBorderRadiusFromWidgetConfig=function resolveBorderRadiusFromWidgetConfig(_ref6){var borderRadius=_ref6.borderRadius,borderRadiusCustom=_ref6.borderRadiusCustom;if(borderRadius==='none')return 0;if(borderRadius==='rounded')return 16;if(borderRadius==='custom'&&typeof borderRadiusCustom==='number')return borderRadiusCustom;return 0;};
24
+ */export var resolveBorderRadiusFromWidgetConfig=function resolveBorderRadiusFromWidgetConfig(_ref6){var borderRadius=_ref6.borderRadius,borderRadiusCustom=_ref6.borderRadiusCustom;if(borderRadius==='none')return 0;if(borderRadius==='rounded')return 16;if(borderRadius==='custom'&&typeof borderRadiusCustom==='number')return borderRadiusCustom;return 0;};/**
25
+ * Validator factory for regular expressions
26
+ * @param {RegExp} regex the regex
27
+ * @return {Function}
28
+ */export var matchesRegex=function matchesRegex(regex){return function(val){return!val||regex.test(val);};};/**
29
+ * Returns a function that validates if input is a valid url with the https protocol
30
+ * @param {string} val the string to be validated
31
+ * @return {boolean}
32
+ */export var isHttpsUrl=matchesRegex(new RegExp('^\\s*https://[^\\s/$.?#].[^\\s]*\\s*$','i'));
@@ -0,0 +1,4 @@
1
+ function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useEffect,useMemo,useState}from'react';import{makeStyles}from'@shopgate/engage/styles';import{useReduceMotion}from'@shopgate/engage/a11y/hooks';import{usePrevious}from'@shopgate/engage/core';import{useVideoWidget}from"./hooks";import{isHttpsUrl}from"../../helpers";var useStyles=makeStyles()(function(theme,_ref){var borderRadius=_ref.borderRadius;return{video:{width:'100%',borderRadius:borderRadius}};});/**
2
+ * The VideoWidget is used to display a video.
3
+ * @returns {JSX.Element}
4
+ */var Video=function Video(){var _useVideoWidget=useVideoWidget(),url=_useVideoWidget.url,muted=_useVideoWidget.muted,loop=_useVideoWidget.loop,controls=_useVideoWidget.controls,autoplay=_useVideoWidget.autoplay,borderRadius=_useVideoWidget.borderRadius;var _useStyles=useStyles({borderRadius:borderRadius}),classes=_useStyles.classes;var reduceMotion=useReduceMotion();var _useState=useState(false),_useState2=_slicedToArray(_useState,2),hasError=_useState2[0],setHasError=_useState2[1];var videoRef=React.useRef(null);var prevAutoPlay=usePrevious(autoplay);var prevUrl=usePrevious(url);var isValidUrl=useMemo(function(){return url?isHttpsUrl(url):false;},[url]);useEffect(function(){if(videoRef.current&&prevAutoPlay&&!autoplay){videoRef.current.pause();videoRef.current.currentTime=0;}if(videoRef.current&&!prevAutoPlay&&autoplay){videoRef.current.play();}if(!url||url!==prevUrl||!hasError){setHasError(false);}},[autoplay,hasError,prevAutoPlay,prevUrl,url]);if(!url||hasError||!isValidUrl)return null;return React.createElement("video",{ref:videoRef,src:url,muted:muted,controls:!autoplay||reduceMotion?true:controls,autoPlay:reduceMotion?false:autoplay,className:classes.video,preload:"auto",playsInline:true,loop:loop,"aria-hidden":true,onError:function onError(){return setHasError(true);}},React.createElement("track",{kind:"captions",src:"",srcLang:"de",label:"Deutsch"}));};export default Video;
@@ -0,0 +1,14 @@
1
+ import{useWidget}from'@shopgate/engage/page/hooks';import{resolveBorderRadiusFromWidgetConfig}from"../../helpers";/**
2
+ * @typedef {Object} VideoWidgetConfig
3
+ * @property {string} url The video URL.
4
+ * @property {boolean} [muted] Whether the video should be muted.
5
+ * @property {boolean} [loop] Whether the video should loop.
6
+ * @property {boolean} [controls] Whether the video should display controls.
7
+ * @property {boolean} [autoplay] Whether the video should autoplay.
8
+ */ /**
9
+ * @typedef {ReturnType< typeof import('@shopgate/engage/page/hooks')
10
+ * .useWidget<VideoWidgetConfig> >} UseWidgetReturnType
11
+ */ // eslint-disable-next-line valid-jsdoc
12
+ /**
13
+ * Hook to access the Video widget configuration and data.
14
+ */export var useVideoWidget=function useVideoWidget(){/** @type {UseWidgetReturnType} */var _useWidget=useWidget(),config=_useWidget.config;var _ref=config||{},url=_ref.url,muted=_ref.muted,loop=_ref.loop,controls=_ref.controls,autoplay=_ref.autoplay,borderRadius=_ref.borderRadius,borderRadiusCustom=_ref.borderRadiusCustom;var borderRadiusResolved=resolveBorderRadiusFromWidgetConfig({borderRadius:borderRadius,borderRadiusCustom:borderRadiusCustom});return{url:url,muted:muted,loop:loop,controls:controls,autoplay:autoplay,borderRadius:borderRadiusResolved};};
@@ -0,0 +1 @@
1
+ export{default}from"./Video";
@@ -1 +1 @@
1
- export{default as PlaceholderWidget}from"./Placeholder";export{default as ProductListWidget}from"./ProductList";export{default as CategoryListWidget}from"./CategoryList";export{default as HtmlWidget}from"./HTML";export{default as ProductSliderWidget}from"./ProductSlider";export{default as HeadlineWidget}from"./Headline";export{default as ImageWidget}from"./Image";export{default as ImageRowWidget}from"./ImageRow";export{default as ImageSliderWidget}from"./ImageSlider";export{default as RichTextWidget}from"./RichText";export{default as HeroBannerWidget}from"./HeroBanner";export{default as ButtonWidget}from"./Button";
1
+ export{default as PlaceholderWidget}from"./Placeholder";export{default as ProductListWidget}from"./ProductList";export{default as CategoryListWidget}from"./CategoryList";export{default as HtmlWidget}from"./HTML";export{default as VideoWidget}from"./Video";export{default as ProductSliderWidget}from"./ProductSlider";export{default as HeadlineWidget}from"./Headline";export{default as ImageWidget}from"./Image";export{default as ImageRowWidget}from"./ImageRow";export{default as ImageSliderWidget}from"./ImageSlider";export{default as RichTextWidget}from"./RichText";export{default as HeroBannerWidget}from"./HeroBanner";export{default as ButtonWidget}from"./Button";
@@ -11,6 +11,9 @@
11
11
  "@shopgate/widgets/htmlWidget": {
12
12
  "path": "@shopgate/engage/page/widgets/HTML"
13
13
  },
14
+ "@shopgate/widgets/videoWidget": {
15
+ "path": "@shopgate/engage/page/widgets/Video"
16
+ },
14
17
  "@shopgate/widgets/headlineWidget": {
15
18
  "path": "@shopgate/engage/page/widgets/Headline"
16
19
  },