@shopgate/engage 7.27.2-beta.1 → 7.27.2-beta.3
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/components/ScrollHeader/index.js +18 -5
- package/core/contexts/ThemeResourcesContext.d.ts +60 -0
- package/core/contexts/ThemeResourcesContext.js +2 -20
- package/core/hooks/events/useLongPress.d.ts +68 -0
- package/core/hooks/events/useLongPress.js +6 -18
- package/core/hooks/events/useScrollDirectionChange.d.ts +60 -0
- package/core/hooks/events/useScrollDirectionChange.js +4 -21
- package/core/hooks/layout/useElementSize.d.ts +46 -0
- package/core/hooks/layout/useElementSize.js +2 -10
- package/core/hooks/useThemeResources.js +15 -10
- package/core/index.js +3 -1
- package/package.json +7 -7
|
@@ -1,5 +1,18 @@
|
|
|
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 _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,{useState}from'react';import PropTypes from'prop-types';import classNames from'classnames';import{useScrollDirectionChange}from'@shopgate/engage/core/hooks';import{root,scrolledIn,scrolledOut,transition}from"./style"
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
|
|
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 _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,{useState,forwardRef,useEffect}from'react';import PropTypes from'prop-types';import classNames from'classnames';import{useScrollDirectionChange}from'@shopgate/engage/core/hooks';import{root,scrolledIn,scrolledOut,transition}from"./style";/* eslint-disable react/prop-types */ /**
|
|
2
|
+
* A container component that hides its content on scroll down and shows it on scroll up.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} props The component props.
|
|
5
|
+
* @param {boolean} [props.hideOnScroll] Toggle hide-on-scroll (default: true).
|
|
6
|
+
* @param {number} [props.scrollOffset] Pixels to scroll before toggling (default: 100).
|
|
7
|
+
* @param {Function} [props.onChange] Callback function that is called when the header changes
|
|
8
|
+
* @param {string} [props.className] Extra CSS classes on the root element.
|
|
9
|
+
* @param {Object} [props.classes] Override internal class names.
|
|
10
|
+
* @param {string} [props.classes.scrolledIn] Override class for the scrolled-in state
|
|
11
|
+
* (content is hidden).
|
|
12
|
+
* @param {string} [props.classes.scrolledOut] Override class for the scrolled-out state
|
|
13
|
+
* (content is visible).
|
|
14
|
+
* visibility. Contains a boolean indicating whether the header is visible.
|
|
15
|
+
* @param {React.ReactNode} props.children Content of the header.
|
|
16
|
+
* @param {React.Ref<HTMLDivElement>} ref Forwarded ref to the header `<div>`.
|
|
17
|
+
* @returns {JSX.Element}
|
|
18
|
+
*/function ScrollHeaderBase(_ref,ref){var className=_ref.className,children=_ref.children,_ref$hideOnScroll=_ref.hideOnScroll,hideOnScroll=_ref$hideOnScroll===void 0?true:_ref$hideOnScroll,_ref$scrollOffset=_ref.scrollOffset,scrollOffset=_ref$scrollOffset===void 0?100:_ref$scrollOffset,onChange=_ref.onChange,classes=_ref.classes;var _useState=useState(false),_useState2=_slicedToArray(_useState,2),shouldHideHeader=_useState2[0],setShouldHideHeader=_useState2[1];useScrollDirectionChange({enabled:hideOnScroll,offset:scrollOffset,onScrollDown:function onScrollDown(){setShouldHideHeader(true);},onScrollUp:function onScrollUp(){setShouldHideHeader(false);}});useEffect(function(){if(typeof onChange!=='function'){return;}onChange(!shouldHideHeader);},[onChange,shouldHideHeader]);return React.createElement("div",{ref:ref,className:classNames(root,transition,className,_defineProperty(_defineProperty({},classNames(scrolledIn,classes===null||classes===void 0?void 0:classes.scrolledIn),!shouldHideHeader),classNames(scrolledOut,classes===null||classes===void 0?void 0:classes.scrolledOut),shouldHideHeader))},children);}/* eslint-enable react/prop-types */var ScrollHeader=forwardRef(ScrollHeaderBase);ScrollHeader.displayName='ScrollHeader';ScrollHeader.propTypes={children:PropTypes.node.isRequired,classes:PropTypes.shape({scrolledIn:PropTypes.string,scrolledOut:PropTypes.string}),className:PropTypes.string,hideOnScroll:PropTypes.bool,onChange:PropTypes.func,scrollOffset:PropTypes.number};ScrollHeader.defaultProps={className:null,hideOnScroll:true,scrollOffset:100,classes:{},onChange:null};export default ScrollHeader;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ComponentType, Context } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A mapping object that contains multiple components provided by the theme.
|
|
5
|
+
* Key is the component name, value is the component.
|
|
6
|
+
*/
|
|
7
|
+
export interface ThemeComponentMap {
|
|
8
|
+
/**
|
|
9
|
+
* Used to display the app bar at the top of the screen.
|
|
10
|
+
*/
|
|
11
|
+
AppBar: ComponentType;
|
|
12
|
+
/**
|
|
13
|
+
* Acts as a wrapper around displayed products and is usually used in components like product sliders.
|
|
14
|
+
*/
|
|
15
|
+
ProductCard: ComponentType;
|
|
16
|
+
/**
|
|
17
|
+
* Used to display products in a grid layout.
|
|
18
|
+
*/
|
|
19
|
+
ProductGrid: ComponentType;
|
|
20
|
+
/**
|
|
21
|
+
* Used to display the header section of a product page. Contains rating, name, and product information.
|
|
22
|
+
* Depending on the theme it may also include CTA buttons.
|
|
23
|
+
*/
|
|
24
|
+
ProductHeader: ComponentType;
|
|
25
|
+
/**
|
|
26
|
+
* Tab bar component provided by the theme. Only available inside the ios11 theme.
|
|
27
|
+
*/
|
|
28
|
+
TabBar?: ComponentType;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A mapping of widget code to widget React components.
|
|
33
|
+
*/
|
|
34
|
+
export interface ThemeWidgetMap {
|
|
35
|
+
[key: string]: ComponentType;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Context type for theme resources.
|
|
40
|
+
*/
|
|
41
|
+
export interface ThemeResourcesContextType {
|
|
42
|
+
/**
|
|
43
|
+
* Mapping object that contains all available widgets.
|
|
44
|
+
* Key is the widget code, value is the widget component.
|
|
45
|
+
*/
|
|
46
|
+
widgets: ThemeWidgetMap;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Mapping object that contains multiple components provided by the theme.
|
|
50
|
+
* Key is the component name, value is the component.
|
|
51
|
+
*/
|
|
52
|
+
components: ThemeComponentMap;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* React context for theme resources.
|
|
57
|
+
*/
|
|
58
|
+
declare const ThemeResourcesContext: Context<ThemeResourcesContextType>;
|
|
59
|
+
|
|
60
|
+
export default ThemeResourcesContext;
|
|
@@ -1,21 +1,3 @@
|
|
|
1
1
|
import{createContext}from'react';/**
|
|
2
|
-
* @typedef
|
|
3
|
-
|
|
4
|
-
* @property {React.ComponentType} ProductCard Acts as a wrapper around
|
|
5
|
-
* displayed products and is usually used in components like product sliders.
|
|
6
|
-
* @property {React.ComponentType} ProductGrid Used to display products in a grid layout.
|
|
7
|
-
* @property {React.ComponentType} ProductHeader Used to display the header section of a product
|
|
8
|
-
* page. Contains rating, name, and product information. Depending on the theme it may also include
|
|
9
|
-
* CTA buttons.
|
|
10
|
-
* @property {React.ComponentType} [TabBar] Tab bar component provided by the theme. Only available
|
|
11
|
-
* inside the ios11 theme.
|
|
12
|
-
*/ /**
|
|
13
|
-
* @typedef {Object.<string, React.ComponentType>} ThemeWidgetMap
|
|
14
|
-
* A mapping of widget code to widget React components.
|
|
15
|
-
*/ /**
|
|
16
|
-
* @typedef {Object} ThemeResourcesContext
|
|
17
|
-
* @property {ThemeWidgetMap} widgets Mapping object that contains all available widgets.
|
|
18
|
-
* Key is the widget code, value is the widget component.
|
|
19
|
-
* @property {ThemeComponentMap} components Mapping object that contains multiple components
|
|
20
|
-
* provided by the theme. Key is the component name, value is the component
|
|
21
|
-
*/ /** @type {import('react').Context<ThemeResourcesContext>} */export default createContext({widgets:{},components:{}});
|
|
2
|
+
* @typedef {import('./ThemeResourcesContext').ThemeResourcesContextType ThemeResourcesContextType}
|
|
3
|
+
*/ /** @type {import('react').Context<ThemeResourcesContextType>} */export default createContext({widgets:{},components:{}});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface LongPressHandlers {
|
|
4
|
+
/**
|
|
5
|
+
* Attach to `onMouseDown` event.
|
|
6
|
+
*/
|
|
7
|
+
onMouseDown: (e: ReactMouseEvent | TouchEvent) => void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Attach to `onTouchStart` event.
|
|
11
|
+
*/
|
|
12
|
+
onTouchStart: (e: ReactTouchEvent | TouchEvent) => void;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Attach to `onMouseUp` event.
|
|
16
|
+
*/
|
|
17
|
+
onMouseUp: (e: ReactMouseEvent | TouchEvent) => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Attach to `onMouseLeave` event.
|
|
21
|
+
*/
|
|
22
|
+
onMouseLeave: (e: ReactMouseEvent | TouchEvent) => void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Attach to `onTouchEnd` event.
|
|
26
|
+
*/
|
|
27
|
+
onTouchEnd: (e: ReactTouchEvent | TouchEvent) => void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Attach to `onContextMenu` event to prevent the native context menu.
|
|
31
|
+
*/
|
|
32
|
+
onContextMenu: (e: MouseEvent) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface UseLongPressOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Duration in milliseconds to trigger long press.
|
|
38
|
+
* @default 1000
|
|
39
|
+
*/
|
|
40
|
+
threshold?: number;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Called when the press starts.
|
|
44
|
+
*/
|
|
45
|
+
onStart?: (e: ReactMouseEvent | ReactTouchEvent) => void;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Called when the long press completes.
|
|
49
|
+
*/
|
|
50
|
+
onFinish?: (e: ReactMouseEvent | ReactTouchEvent) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Called when the press is cancelled before the threshold.
|
|
54
|
+
*/
|
|
55
|
+
onCancel?: (e: ReactMouseEvent | ReactTouchEvent) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Custom hook to handle long press interactions.
|
|
60
|
+
*
|
|
61
|
+
* @param callback Function to call on long press.
|
|
62
|
+
* @param options Configuration and lifecycle callbacks.
|
|
63
|
+
* @returns An object containing event handlers for mouse and touch events.
|
|
64
|
+
*/
|
|
65
|
+
export default function useLongPress(
|
|
66
|
+
callback: (e: ReactMouseEvent | ReactTouchEvent) => void,
|
|
67
|
+
options?: UseLongPressOptions
|
|
68
|
+
): LongPressHandlers;
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @property {Function} onMouseDown - Attach to `onMouseDown` event.
|
|
4
|
-
* @property {Function} onTouchStart - Attach to `onTouchStart` event.
|
|
5
|
-
* @property {Function} onMouseUp - Attach to `onMouseUp` event.
|
|
6
|
-
* @property {Function} onMouseLeave - Attach to `onMouseLeave` event.
|
|
7
|
-
* @property {Function} onTouchEnd - Attach to `onTouchEnd` event.
|
|
8
|
-
* @property {Function} onContextMenu - Attach to `onContextMenu` event to prevent the native
|
|
9
|
-
* context menu.
|
|
10
|
-
*/ /**
|
|
1
|
+
// @ts-check
|
|
2
|
+
import{useRef,useCallback}from'react';/** @typedef {import('./useLongPress').LongPressHandlers} LongPressHandlers */ /** @typedef {import('./useLongPress').UseLongPressOptions} UseLongPressOptions */ /**
|
|
11
3
|
* Prevents the default context menu from appearing on long press.
|
|
12
4
|
* @param {MouseEvent} e The event object.
|
|
13
|
-
*/var preventContextMenu=function preventContextMenu(e){e.preventDefault();}
|
|
5
|
+
*/var preventContextMenu=function preventContextMenu(e){e.preventDefault();};// eslint-disable-next-line valid-jsdoc
|
|
6
|
+
/**
|
|
14
7
|
* Custom hook to handle long press interactions.
|
|
15
8
|
*
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {number} [options.threshold=1000] - Duration in milliseconds to trigger long press.
|
|
19
|
-
* @param {Function} [options.onStart] - Called when the press starts.
|
|
20
|
-
* @param {Function} [options.onFinish] - Called when the long press completes.
|
|
21
|
-
* @param {Function} [options.onCancel] - Called when the press is cancelled before the threshold.
|
|
22
|
-
*
|
|
9
|
+
* @param {(e: Event) => void} callback - Function to call on long press.
|
|
10
|
+
* @param {UseLongPressOptions} [options={}] - Configuration and lifecycle callbacks.
|
|
23
11
|
* @returns {LongPressHandlers} An object containing event handlers for mouse and touch events.
|
|
24
12
|
*/export default function useLongPress(callback){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_ref$threshold=_ref.threshold,threshold=_ref$threshold===void 0?1000:_ref$threshold,onStart=_ref.onStart,onFinish=_ref.onFinish,onCancel=_ref.onCancel;var timerRef=useRef(null);var triggeredRef=useRef(false);var start=useCallback(function(e){if(onStart)onStart(e);triggeredRef.current=false;timerRef.current=setTimeout(function(){callback(e);triggeredRef.current=true;if(onFinish)onFinish(e);},threshold);},[onStart,threshold,callback,onFinish]);var cancel=useCallback(function(e){clearTimeout(timerRef.current);if(!triggeredRef.current&&onCancel){onCancel(e);}},[onCancel]);return{onMouseDown:start,onTouchStart:start,onMouseUp:cancel,onMouseLeave:cancel,onTouchEnd:cancel,// prevents right-click or long-press menu
|
|
25
13
|
onContextMenu:preventContextMenu};}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface ViewScrollEvent {
|
|
2
|
+
/** The original scroll event object */
|
|
3
|
+
event: UIEvent;
|
|
4
|
+
|
|
5
|
+
/** Current vertical scroll position */
|
|
6
|
+
scrollTop: number;
|
|
7
|
+
|
|
8
|
+
/** Previous scrollTop value */
|
|
9
|
+
previousScrollTop: number;
|
|
10
|
+
|
|
11
|
+
/** True if scrolling down */
|
|
12
|
+
scrollDown: boolean;
|
|
13
|
+
|
|
14
|
+
/** True if scrolling up */
|
|
15
|
+
scrollUp: boolean;
|
|
16
|
+
|
|
17
|
+
/** Scroll direction: 'up', 'down', or null */
|
|
18
|
+
direction: 'up' | 'down' | null;
|
|
19
|
+
|
|
20
|
+
/** Optional internal/legacy props (not passed to callbacks) */
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param event Scroll event
|
|
26
|
+
*/
|
|
27
|
+
export type ScrollCallback = (event: ViewScrollEvent) => void;
|
|
28
|
+
|
|
29
|
+
export interface UseScrollDirectionChangeParams {
|
|
30
|
+
/** Whether the hook is active */
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* ScrollTop threshold for down scroll triggers. When set,
|
|
35
|
+
* `onScrollDown` fires only when the scroll position is greater than this.
|
|
36
|
+
* @default 100
|
|
37
|
+
*/
|
|
38
|
+
offset?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If true, callbacks fire only once per direction change
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
onlyFireOnDirectionChange?: boolean;
|
|
45
|
+
|
|
46
|
+
/** Callback triggered on scroll up */
|
|
47
|
+
onScrollUp?: ScrollCallback;
|
|
48
|
+
|
|
49
|
+
/** Callback triggered on scroll down past offset */
|
|
50
|
+
onScrollDown?: ScrollCallback;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A scroll hook that detects scroll direction changes (up/down) and
|
|
55
|
+
* triggers the appropriate callbacks. Commonly used to show/hide
|
|
56
|
+
* UI elements based on scroll behavior.
|
|
57
|
+
*
|
|
58
|
+
* @param {UseScrollDirectionChangeParams} params The hook parameters
|
|
59
|
+
*/
|
|
60
|
+
export default function useScrollDirectionChange(params: UseScrollDirectionChangeParams): void;
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
var _excluded=["scrollIn","scrollOut","scrolled"],_excluded2=["scrollIn","scrollOut","scrolled"];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;}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @property {number} scrollTop Current vertical scroll position
|
|
5
|
-
* @property {number} previousScrollTop Previous scrollTop value
|
|
6
|
-
* @property {boolean} scrollDown True if scrolling down
|
|
7
|
-
* @property {boolean} scrollUp True if scrolling up
|
|
8
|
-
* @property {'up' | 'down' | null} direction Scroll direction
|
|
9
|
-
*/ /**
|
|
10
|
-
* @callback ScrollCallback
|
|
11
|
-
* @param {ViewScrollEvent} event
|
|
12
|
-
* @returns {void}
|
|
13
|
-
*/ /**
|
|
1
|
+
var _excluded=["scrollIn","scrollOut","scrolled"],_excluded2=["scrollIn","scrollOut","scrolled"];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;}// @ts-check
|
|
2
|
+
import{useEffect,useRef,useCallback}from'react';import{viewScroll$}from'@shopgate/engage/core/streams';/** @typedef {import('./useScrollDirectionChange').ViewScrollEvent} ViewScrollEvent */ /** @typedef {import('./useScrollDirectionChange').ScrollCallback} ScrollCallback */ // eslint-disable-next-line max-len
|
|
3
|
+
/** @typedef {import('./useScrollDirectionChange').UseScrollDirectionChangeParams} UseScrollDirectionChangeParams */ /**
|
|
14
4
|
* A scroll hook that detects scroll direction changes (up/down) and
|
|
15
5
|
* triggers the appropriate callbacks. Commonly used to show/hide
|
|
16
6
|
* UI elements based on scroll behavior.
|
|
17
7
|
*
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {boolean} params.enabled Whether the hook is active
|
|
20
|
-
* @param {number} [params.offset=100] ScrollTop threshold for down scroll triggers. When set,
|
|
21
|
-
* onScrollDown will first be triggered when the scroll position is greater than this value.
|
|
22
|
-
* @param {boolean} [params.onlyFireOnDirectionChange=true]
|
|
23
|
-
* If true, callbacks fire only once per direction change
|
|
24
|
-
* @param {ScrollCallback} [params.onScrollUp] Triggered on scroll up
|
|
25
|
-
* @param {ScrollCallback} [params.onScrollDown] Triggered on scroll down past offset
|
|
8
|
+
* @param {UseScrollDirectionChangeParams} params The hook parameters
|
|
26
9
|
*/export default function useScrollDirectionChange(_ref){var enabled=_ref.enabled,_ref$offset=_ref.offset,offset=_ref$offset===void 0?100:_ref$offset,_ref$onlyFireOnDirect=_ref.onlyFireOnDirectionChange,onlyFireOnDirectionChange=_ref$onlyFireOnDirect===void 0?true:_ref$onlyFireOnDirect,onScrollUp=_ref.onScrollUp,onScrollDown=_ref.onScrollDown;var lastDirectionRef=useRef(null);var downTriggeredRef=useRef(false);var upTriggeredRef=useRef(false);/**
|
|
27
10
|
* Scroll event handler.
|
|
28
11
|
* Uses `event.direction` and triggers callbacks accordingly.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the dimensions of a DOM element.
|
|
5
|
+
*/
|
|
6
|
+
export interface ElementSize {
|
|
7
|
+
/**
|
|
8
|
+
* The element's height in pixels.
|
|
9
|
+
*/
|
|
10
|
+
height: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The element's width in pixels (optional).
|
|
14
|
+
*/
|
|
15
|
+
width?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for configuring the useElementSize hook.
|
|
20
|
+
*/
|
|
21
|
+
export interface UseElementSizeOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Throttle delay in milliseconds.
|
|
24
|
+
* @default 100
|
|
25
|
+
*/
|
|
26
|
+
throttleMs?: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether to measure the element's width.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
includeWidth?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Tracks the height (and optionally width) of a DOM element using ResizeObserver.
|
|
37
|
+
* Falls back to window resize and MutationObserver in older browsers.
|
|
38
|
+
*
|
|
39
|
+
* @param ref A ref to the element being measured.
|
|
40
|
+
* @param options Optional settings.
|
|
41
|
+
* @returns The current height (and optionally width) of the element.
|
|
42
|
+
*/
|
|
43
|
+
export default function useElementSize(
|
|
44
|
+
ref: RefObject<HTMLElement>,
|
|
45
|
+
options?: UseElementSizeOptions
|
|
46
|
+
): ElementSize;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{useState,useEffect,useRef}from'react';import throttle from'lodash/throttle';/**
|
|
2
|
-
* @typedef {Object} ElementSize
|
|
3
|
-
* @property {number} height - The element's height in pixels.
|
|
4
|
-
* @property {number} [width] - The element's width in pixels (optional).
|
|
5
|
-
*/ /**
|
|
6
|
-
* @typedef {Object} UseElementSizeOptions
|
|
7
|
-
* @property {number} [throttleMs=100] - Throttle delay in milliseconds.
|
|
8
|
-
* @property {boolean} [includeWidth=false] - Whether to measure the element's width.
|
|
9
|
-
*/ /**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{useState,useEffect,useRef}from'react';import throttle from'lodash/throttle';/** @typedef {import('./useElementSize').ElementSize} ElementSize */ /** @typedef {import('./useElementSize').UseElementSizeOptions} UseElementSizeOptions */ /** @typedef {import('react').RefObject<HTMLElement>} HTMLElementRef */ /**
|
|
10
2
|
* Tracks the height (and optionally width) of a DOM element using ResizeObserver,
|
|
11
3
|
* with a fallback to window resize and MutationObserver in older browsers.
|
|
12
4
|
*
|
|
13
|
-
* @param {
|
|
5
|
+
* @param {HTMLElementRef} ref - A ref to the element being measured.
|
|
14
6
|
* @param {UseElementSizeOptions} [options={}] - Optional settings.
|
|
15
7
|
* @returns {ElementSize} The current height (and optionally width) of the element.
|
|
16
8
|
*/export default function useElementSize(ref){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var _options$throttleMs=options.throttleMs,throttleMs=_options$throttleMs===void 0?100:_options$throttleMs,_options$includeWidth=options.includeWidth,includeWidth=_options$includeWidth===void 0?false:_options$includeWidth;/**
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import{useContext}from'react';import ThemeResourcesContext from"../contexts/ThemeResourcesContext"
|
|
2
|
-
|
|
1
|
+
import{useContext}from'react';import ThemeResourcesContext from"../contexts/ThemeResourcesContext";/**
|
|
2
|
+
* @typedef {import('../contexts/ThemeResourcesContext').ThemeResourcesContextType
|
|
3
|
+
* ThemeResourcesContextType}
|
|
4
|
+
*/ /**
|
|
5
|
+
* @typedef {ThemeResourcesContextType['components']} ThemeComponentsType
|
|
6
|
+
*/ /**
|
|
7
|
+
* @typedef {ThemeResourcesContextType['widgets']} ThemeWidgetsType
|
|
8
|
+
*/ /**
|
|
3
9
|
* Hook to access to the ThemeResourceContext. The context provides access to different groups
|
|
4
10
|
* of React components provided by the active theme.
|
|
5
|
-
* @returns Value of the ThemeResourceContext
|
|
6
|
-
*/export function useThemeResources(){return useContext(ThemeResourcesContext);}
|
|
7
|
-
/**
|
|
11
|
+
* @returns {ThemeResourcesContextType} Value of the ThemeResourceContext
|
|
12
|
+
*/export function useThemeResources(){return useContext(ThemeResourcesContext);}/**
|
|
8
13
|
* Hook to access the components provided by the ThemeResourceContext
|
|
9
|
-
* @returns Mapping object that contains multiple components provided by the
|
|
14
|
+
* @returns {ThemeComponentsType} Mapping object that contains multiple components provided by the
|
|
15
|
+
* theme.
|
|
10
16
|
* Key is the component name, value is the component
|
|
11
|
-
*/export function useThemeComponents(){var _useThemeResources=useThemeResources(),components=_useThemeResources.components;return components;}
|
|
12
|
-
/**
|
|
17
|
+
*/export function useThemeComponents(){var _useThemeResources=useThemeResources(),components=_useThemeResources.components;return components;}/**
|
|
13
18
|
* Hook to access the widgets provided by the ThemeResourceContext
|
|
14
|
-
* @returns Mapping object that contains all available widgets.
|
|
15
|
-
* the widget component.
|
|
19
|
+
* @returns {ThemeWidgetsType} Mapping object that contains all available widgets.
|
|
20
|
+
* Key is the widget code, value is the widget component.
|
|
16
21
|
*/export function useThemeWidgets(){var _useThemeResources2=useThemeResources(),widgets=_useThemeResources2.widgets;return widgets;}
|
package/core/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
/** @module core */ // --------------- STORE --------------- //
|
|
2
2
|
export*from'@shopgate/pwa-common/store';// --------------- CONFIG --------------- //
|
|
3
|
-
export{ThemeConfigResolver}from"./config/ThemeConfigResolver";export{getThemeConfig}from"./config/getThemeConfig";export{getThemeSettings}from"./config/getThemeSettings";export{getThemeColors}from"./config/getThemeColors";export{getThemeAssets}from"./config/getThemeAssets";export{getPageConfig}from"./config/getPageConfig";export{getPageSettings}from"./config/getPageSettings";export{getWidgetConfig}from"./config/getWidgetConfig";export{getWidgetSettings}from"./config/getWidgetSettings";export*from"./actions";export*from"./action-creators";export*from"./classes";export*from"./collections";export*from"./commands";export*from"./constants";export*from"./contexts";export*from"./events";export*from"./helpers"
|
|
3
|
+
export{ThemeConfigResolver}from"./config/ThemeConfigResolver";export{getThemeConfig}from"./config/getThemeConfig";export{getThemeSettings}from"./config/getThemeSettings";export{getThemeColors}from"./config/getThemeColors";export{getThemeAssets}from"./config/getThemeAssets";export{getPageConfig}from"./config/getPageConfig";export{getPageSettings}from"./config/getPageSettings";export{getWidgetConfig}from"./config/getWidgetConfig";export{getWidgetSettings}from"./config/getWidgetSettings";export*from"./actions";export*from"./action-creators";export*from"./classes";export*from"./collections";export*from"./commands";export*from"./constants";export*from"./contexts";export*from"./events";export*from"./helpers";// Only export HOCs that existed before the hoc folder existed
|
|
4
|
+
export{withShowModal,withTheme,withRoute,withCurrentProduct,withForwardedRef,withNavigation,withWidgetSettings,withWidgetStyles,withApp}from"./hocs";// Only export hooks that existed before the hooks folder existed
|
|
5
|
+
export{useAsyncMemo,useRoute,useTheme,useApp,useCurrentProduct,useNavigation,usePageConfig,usePageSettings,useWidgetConfig,useWidgetSettings,useWidgetStyles,useLoadImage,usePrevious,useResponsiveValue}from"./hooks";export*from"./initialization";export*from"./providers";export*from"./selectors";export*from"./streams";export*from"./validation";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "7.27.2-beta.
|
|
3
|
+
"version": "7.27.2-beta.3",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@shopgate/native-modules": "1.0.0-beta.25",
|
|
19
|
-
"@shopgate/pwa-common": "7.27.2-beta.
|
|
20
|
-
"@shopgate/pwa-common-commerce": "7.27.2-beta.
|
|
21
|
-
"@shopgate/pwa-core": "7.27.2-beta.
|
|
22
|
-
"@shopgate/pwa-ui-ios": "7.27.2-beta.
|
|
23
|
-
"@shopgate/pwa-ui-material": "7.27.2-beta.
|
|
24
|
-
"@shopgate/pwa-ui-shared": "7.27.2-beta.
|
|
19
|
+
"@shopgate/pwa-common": "7.27.2-beta.3",
|
|
20
|
+
"@shopgate/pwa-common-commerce": "7.27.2-beta.3",
|
|
21
|
+
"@shopgate/pwa-core": "7.27.2-beta.3",
|
|
22
|
+
"@shopgate/pwa-ui-ios": "7.27.2-beta.3",
|
|
23
|
+
"@shopgate/pwa-ui-material": "7.27.2-beta.3",
|
|
24
|
+
"@shopgate/pwa-ui-shared": "7.27.2-beta.3",
|
|
25
25
|
"@stripe/react-stripe-js": "^1.16.5",
|
|
26
26
|
"@stripe/stripe-js": "^1.3.1",
|
|
27
27
|
"@virtuous/conductor": "~2.5.0",
|