@wordpress/compose 5.16.0 → 5.16.1-next.4d3b314fd5.0
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/README.md +36 -3
- package/build/hooks/use-drop-zone/index.js +2 -10
- package/build/hooks/use-drop-zone/index.js.map +1 -1
- package/build/hooks/use-throttle/index.js +12 -8
- package/build/hooks/use-throttle/index.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/index.native.js +14 -0
- package/build/index.native.js.map +1 -1
- package/build/utils/throttle/index.js +98 -0
- package/build/utils/throttle/index.js.map +1 -0
- package/build-module/hooks/use-drop-zone/index.js +2 -10
- package/build-module/hooks/use-drop-zone/index.js.map +1 -1
- package/build-module/hooks/use-throttle/index.js +11 -7
- package/build-module/hooks/use-throttle/index.js.map +1 -1
- package/build-module/index.js +3 -1
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +3 -1
- package/build-module/index.native.js.map +1 -1
- package/build-module/utils/throttle/index.js +88 -0
- package/build-module/utils/throttle/index.js.map +1 -0
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/build-types/hooks/use-throttle/index.d.ts +6 -6
- package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/utils/throttle/index.d.ts +77 -0
- package/build-types/utils/throttle/index.d.ts.map +1 -0
- package/package.json +8 -8
- package/src/hooks/use-drop-zone/index.js +4 -13
- package/src/hooks/use-throttle/index.js +11 -7
- package/src/index.js +2 -0
- package/src/index.native.js +2 -0
- package/src/utils/throttle/index.ts +95 -0
- package/src/utils/throttle/test/index.ts +256 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.js"],"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","useConstrainedTabbing","useCopyOnClick","useCopyToClipboard","__experimentalUseDialog","useDisabled","__experimentalUseDragging","useFocusOnMount","__experimentalUseFocusOutside","useFocusReturn","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","useResizeObserver","useAsyncList","useWarnOnChange","useDebounce","useThrottle","useMergeRefs","useRefEffect","__experimentalUseDropZone","useFocusableIframe","__experimentalUseFixedWindowList"],"mappings":"AAAA;AACA,cAAc,uCAAd,C,CACA;;AACA,cAAc,kBAAd,C,CAEA;;AACA,SAASA,OAAO,IAAIC,OAApB,QAAmC,wBAAnC;AACA,SAASD,OAAO,IAAIE,IAApB,QAAgC,qBAAhC,C,CAEA;;AACA,SAASF,OAAO,IAAIG,WAApB,QAAuC,6BAAvC;AACA,SAASH,OAAO,IAAII,IAApB,QAAgC,qBAAhC;AACA,SAASJ,OAAO,IAAIK,gBAApB,QAA4C,mCAA5C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,iCAA1C;AACA,SAASN,OAAO,IAAIO,eAApB,QAA2C,kCAA3C;AACA,SAASP,OAAO,IAAIQ,SAApB,QAAqC,2BAArC,C,CAEA;;AACA,SAASR,OAAO,IAAIS,qBAApB,QAAiD,iCAAjD;AACA,SAAST,OAAO,IAAIU,cAApB,QAA0C,2BAA1C;AACA,SAASV,OAAO,IAAIW,kBAApB,QAA8C,+BAA9C;AACA,SAASX,OAAO,IAAIY,uBAApB,QAAmD,oBAAnD;AACA,SAASZ,OAAO,IAAIa,WAApB,QAAuC,sBAAvC;AACA,SAASb,OAAO,IAAIc,yBAApB,QAAqD,sBAArD;AACA,SAASd,OAAO,IAAIe,eAApB,QAA2C,4BAA3C;AACA,SAASf,OAAO,IAAIgB,6BAApB,QAAyD,2BAAzD;AACA,SAAShB,OAAO,IAAIiB,cAApB,QAA0C,0BAA1C;AACA,SAASjB,OAAO,IAAIkB,aAApB,QAAyC,yBAAzC;AACA,SAASlB,OAAO,IAAImB,yBAApB,QAAqD,sCAArD;AACA,SAASnB,OAAO,IAAIoB,mBAApB,QAA+C,+BAA/C;AACA,SAASpB,OAAO,IAAIqB,aAApB,QAAyC,yBAAzC;AACA,SAASrB,OAAO,IAAIsB,WAApB,QAAuC,sBAAvC;AACA,SAAStB,OAAO,IAAIuB,gBAApB,QAA4C,4BAA5C;AACA,SAASvB,OAAO,IAAIwB,gBAApB,QAA4C,4BAA5C;AACA,SAASxB,OAAO,IAAIyB,iBAApB,QAA6C,6BAA7C;AACA,SAASzB,OAAO,IAAI0B,YAApB,QAAwC,wBAAxC;AACA,SAAS1B,OAAO,IAAI2B,eAApB,QAA2C,4BAA3C;AACA,SAAS3B,OAAO,IAAI4B,WAApB,QAAuC,sBAAvC;AACA,SAAS5B,OAAO,IAAI6B,WAApB,QAAuC,sBAAvC;AACA,SAAS7B,OAAO,IAAI8B,YAApB,QAAwC,wBAAxC;AACA,SAAS9B,OAAO,IAAI+B,YAApB,QAAwC,wBAAxC;AACA,SAAS/B,OAAO,IAAIgC,yBAApB,QAAqD,uBAArD;AACA,SAAShC,OAAO,IAAIiC,kBAApB,QAA8C,8BAA9C;AACA,SAASjC,OAAO,IAAIkC,gCAApB,QAA4D,+BAA5D","sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/index.js"],"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","useConstrainedTabbing","useCopyOnClick","useCopyToClipboard","__experimentalUseDialog","useDisabled","__experimentalUseDragging","useFocusOnMount","__experimentalUseFocusOutside","useFocusReturn","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","useResizeObserver","useAsyncList","useWarnOnChange","useDebounce","useThrottle","useMergeRefs","useRefEffect","__experimentalUseDropZone","useFocusableIframe","__experimentalUseFixedWindowList"],"mappings":"AAAA;AACA,cAAc,uCAAd,C,CACA;;AACA,cAAc,kBAAd,C,CACA;;AACA,cAAc,kBAAd,C,CAEA;;AACA,SAASA,OAAO,IAAIC,OAApB,QAAmC,wBAAnC;AACA,SAASD,OAAO,IAAIE,IAApB,QAAgC,qBAAhC,C,CAEA;;AACA,SAASF,OAAO,IAAIG,WAApB,QAAuC,6BAAvC;AACA,SAASH,OAAO,IAAII,IAApB,QAAgC,qBAAhC;AACA,SAASJ,OAAO,IAAIK,gBAApB,QAA4C,mCAA5C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,iCAA1C;AACA,SAASN,OAAO,IAAIO,eAApB,QAA2C,kCAA3C;AACA,SAASP,OAAO,IAAIQ,SAApB,QAAqC,2BAArC,C,CAEA;;AACA,SAASR,OAAO,IAAIS,qBAApB,QAAiD,iCAAjD;AACA,SAAST,OAAO,IAAIU,cAApB,QAA0C,2BAA1C;AACA,SAASV,OAAO,IAAIW,kBAApB,QAA8C,+BAA9C;AACA,SAASX,OAAO,IAAIY,uBAApB,QAAmD,oBAAnD;AACA,SAASZ,OAAO,IAAIa,WAApB,QAAuC,sBAAvC;AACA,SAASb,OAAO,IAAIc,yBAApB,QAAqD,sBAArD;AACA,SAASd,OAAO,IAAIe,eAApB,QAA2C,4BAA3C;AACA,SAASf,OAAO,IAAIgB,6BAApB,QAAyD,2BAAzD;AACA,SAAShB,OAAO,IAAIiB,cAApB,QAA0C,0BAA1C;AACA,SAASjB,OAAO,IAAIkB,aAApB,QAAyC,yBAAzC;AACA,SAASlB,OAAO,IAAImB,yBAApB,QAAqD,sCAArD;AACA,SAASnB,OAAO,IAAIoB,mBAApB,QAA+C,+BAA/C;AACA,SAASpB,OAAO,IAAIqB,aAApB,QAAyC,yBAAzC;AACA,SAASrB,OAAO,IAAIsB,WAApB,QAAuC,sBAAvC;AACA,SAAStB,OAAO,IAAIuB,gBAApB,QAA4C,4BAA5C;AACA,SAASvB,OAAO,IAAIwB,gBAApB,QAA4C,4BAA5C;AACA,SAASxB,OAAO,IAAIyB,iBAApB,QAA6C,6BAA7C;AACA,SAASzB,OAAO,IAAI0B,YAApB,QAAwC,wBAAxC;AACA,SAAS1B,OAAO,IAAI2B,eAApB,QAA2C,4BAA3C;AACA,SAAS3B,OAAO,IAAI4B,WAApB,QAAuC,sBAAvC;AACA,SAAS5B,OAAO,IAAI6B,WAApB,QAAuC,sBAAvC;AACA,SAAS7B,OAAO,IAAI8B,YAApB,QAAwC,wBAAxC;AACA,SAAS9B,OAAO,IAAI+B,YAApB,QAAwC,wBAAxC;AACA,SAAS/B,OAAO,IAAIgC,yBAApB,QAAqD,uBAArD;AACA,SAAShC,OAAO,IAAIiC,kBAApB,QAA8C,8BAA9C;AACA,SAASjC,OAAO,IAAIkC,gCAApB,QAA4D,+BAA5D","sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// The `createHigherOrderComponent` helper and helper types.
|
|
2
2
|
export * from './utils/create-higher-order-component'; // The `debounce` helper and its types.
|
|
3
3
|
|
|
4
|
-
export * from './utils/debounce'; // The `
|
|
4
|
+
export * from './utils/debounce'; // The `throttle` helper and its types.
|
|
5
|
+
|
|
6
|
+
export * from './utils/throttle'; // The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).
|
|
5
7
|
|
|
6
8
|
export { default as compose } from './higher-order/compose';
|
|
7
9
|
export { default as pipe } from './higher-order/pipe'; // Higher-order components.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.native.js"],"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","withPreferredColorScheme","useConstrainedTabbing","__experimentalUseDragging","__experimentalUseFocusOutside","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","useAsyncList","usePreferredColorScheme","usePreferredColorSchemeStyle","useResizeObserver","useDebounce","useThrottle","useMergeRefs","useRefEffect"],"mappings":"AAAA;AACA,cAAc,uCAAd,C,CACA;;AACA,cAAc,kBAAd,C,CAEA;;AACA,SAASA,OAAO,IAAIC,OAApB,QAAmC,wBAAnC;AACA,SAASD,OAAO,IAAIE,IAApB,QAAgC,qBAAhC,C,CAEA;;AACA,SAASF,OAAO,IAAIG,WAApB,QAAuC,6BAAvC;AACA,SAASH,OAAO,IAAII,IAApB,QAAgC,qBAAhC;AACA,SAASJ,OAAO,IAAIK,gBAApB,QAA4C,mCAA5C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,iCAA1C;AACA,SAASN,OAAO,IAAIO,eAApB,QAA2C,kCAA3C;AACA,SAASP,OAAO,IAAIQ,SAApB,QAAqC,2BAArC;AACA,SAASR,OAAO,IAAIS,wBAApB,QAAoD,4CAApD,C,CAEA;;AACA,SAAST,OAAO,IAAIU,qBAApB,QAAiD,iCAAjD;AACA,SAASV,OAAO,IAAIW,yBAApB,QAAqD,sBAArD;AACA,SAASX,OAAO,IAAIY,6BAApB,QAAyD,2BAAzD;AACA,SAASZ,OAAO,IAAIa,aAApB,QAAyC,yBAAzC;AACA,SAASb,OAAO,IAAIc,yBAApB,QAAqD,sCAArD;AACA,SAASd,OAAO,IAAIe,mBAApB,QAA+C,+BAA/C;AACA,SAASf,OAAO,IAAIgB,aAApB,QAAyC,yBAAzC;AACA,SAAShB,OAAO,IAAIiB,WAApB,QAAuC,sBAAvC;AACA,SAASjB,OAAO,IAAIkB,gBAApB,QAA4C,4BAA5C;AACA,SAASlB,OAAO,IAAImB,gBAApB,QAA4C,4BAA5C;AACA,SAASnB,OAAO,IAAIoB,YAApB,QAAwC,wBAAxC;AACA,SAASpB,OAAO,IAAIqB,uBAApB,QAAmD,oCAAnD;AACA,SAASrB,OAAO,IAAIsB,4BAApB,QAAwD,0CAAxD;AACA,SAAStB,OAAO,IAAIuB,iBAApB,QAA6C,6BAA7C;AACA,SAASvB,OAAO,IAAIwB,WAApB,QAAuC,sBAAvC;AACA,SAASxB,OAAO,IAAIyB,WAApB,QAAuC,sBAAvC;AACA,SAASzB,OAAO,IAAI0B,YAApB,QAAwC,wBAAxC;AACA,SAAS1B,OAAO,IAAI2B,YAApB,QAAwC,wBAAxC","sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/index.native.js"],"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","withPreferredColorScheme","useConstrainedTabbing","__experimentalUseDragging","__experimentalUseFocusOutside","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","useAsyncList","usePreferredColorScheme","usePreferredColorSchemeStyle","useResizeObserver","useDebounce","useThrottle","useMergeRefs","useRefEffect"],"mappings":"AAAA;AACA,cAAc,uCAAd,C,CACA;;AACA,cAAc,kBAAd,C,CACA;;AACA,cAAc,kBAAd,C,CAEA;;AACA,SAASA,OAAO,IAAIC,OAApB,QAAmC,wBAAnC;AACA,SAASD,OAAO,IAAIE,IAApB,QAAgC,qBAAhC,C,CAEA;;AACA,SAASF,OAAO,IAAIG,WAApB,QAAuC,6BAAvC;AACA,SAASH,OAAO,IAAII,IAApB,QAAgC,qBAAhC;AACA,SAASJ,OAAO,IAAIK,gBAApB,QAA4C,mCAA5C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,iCAA1C;AACA,SAASN,OAAO,IAAIO,eAApB,QAA2C,kCAA3C;AACA,SAASP,OAAO,IAAIQ,SAApB,QAAqC,2BAArC;AACA,SAASR,OAAO,IAAIS,wBAApB,QAAoD,4CAApD,C,CAEA;;AACA,SAAST,OAAO,IAAIU,qBAApB,QAAiD,iCAAjD;AACA,SAASV,OAAO,IAAIW,yBAApB,QAAqD,sBAArD;AACA,SAASX,OAAO,IAAIY,6BAApB,QAAyD,2BAAzD;AACA,SAASZ,OAAO,IAAIa,aAApB,QAAyC,yBAAzC;AACA,SAASb,OAAO,IAAIc,yBAApB,QAAqD,sCAArD;AACA,SAASd,OAAO,IAAIe,mBAApB,QAA+C,+BAA/C;AACA,SAASf,OAAO,IAAIgB,aAApB,QAAyC,yBAAzC;AACA,SAAShB,OAAO,IAAIiB,WAApB,QAAuC,sBAAvC;AACA,SAASjB,OAAO,IAAIkB,gBAApB,QAA4C,4BAA5C;AACA,SAASlB,OAAO,IAAImB,gBAApB,QAA4C,4BAA5C;AACA,SAASnB,OAAO,IAAIoB,YAApB,QAAwC,wBAAxC;AACA,SAASpB,OAAO,IAAIqB,uBAApB,QAAmD,oCAAnD;AACA,SAASrB,OAAO,IAAIsB,4BAApB,QAAwD,0CAAxD;AACA,SAAStB,OAAO,IAAIuB,iBAApB,QAA6C,6BAA7C;AACA,SAASvB,OAAO,IAAIwB,WAApB,QAAuC,sBAAvC;AACA,SAASxB,OAAO,IAAIyB,WAApB,QAAuC,sBAAvC;AACA,SAASzB,OAAO,IAAI0B,YAApB,QAAwC,wBAAxC;AACA,SAAS1B,OAAO,IAAI2B,YAApB,QAAwC,wBAAxC","sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parts of this source were derived and modified from lodash,
|
|
3
|
+
* released under the MIT license.
|
|
4
|
+
*
|
|
5
|
+
* https://github.com/lodash/lodash
|
|
6
|
+
*
|
|
7
|
+
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
8
|
+
*
|
|
9
|
+
* Based on Underscore.js, copyright Jeremy Ashkenas,
|
|
10
|
+
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
|
11
|
+
*
|
|
12
|
+
* This software consists of voluntary contributions made by many
|
|
13
|
+
* individuals. For exact contribution history, see the revision history
|
|
14
|
+
* available at https://github.com/lodash/lodash
|
|
15
|
+
*
|
|
16
|
+
* The following license applies to all parts of this software except as
|
|
17
|
+
* documented below:
|
|
18
|
+
*
|
|
19
|
+
* ====
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
22
|
+
* a copy of this software and associated documentation files (the
|
|
23
|
+
* "Software"), to deal in the Software without restriction, including
|
|
24
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
25
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
26
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
27
|
+
* the following conditions:
|
|
28
|
+
*
|
|
29
|
+
* The above copyright notice and this permission notice shall be
|
|
30
|
+
* included in all copies or substantial portions of the Software.
|
|
31
|
+
*
|
|
32
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
33
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
34
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
35
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
36
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
37
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
38
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Internal dependencies
|
|
43
|
+
*/
|
|
44
|
+
import { debounce } from '../debounce';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A simplified and properly typed version of lodash's `throttle`, that
|
|
48
|
+
* always uses timers instead of sometimes using rAF.
|
|
49
|
+
*
|
|
50
|
+
* Creates a throttled function that only invokes `func` at most once per
|
|
51
|
+
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
52
|
+
* method to cancel delayed `func` invocations and a `flush` method to
|
|
53
|
+
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
54
|
+
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
55
|
+
* timeout. The `func` is invoked with the last arguments provided to the
|
|
56
|
+
* throttled function. Subsequent calls to the throttled function return
|
|
57
|
+
* the result of the last `func` invocation.
|
|
58
|
+
*
|
|
59
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
60
|
+
* invoked on the trailing edge of the timeout only if the throttled function
|
|
61
|
+
* is invoked more than once during the `wait` timeout.
|
|
62
|
+
*
|
|
63
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
64
|
+
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
65
|
+
*
|
|
66
|
+
* @param {Function} func The function to throttle.
|
|
67
|
+
* @param {number} wait The number of milliseconds to throttle invocations to.
|
|
68
|
+
* @param {Partial< ThrottleOptions >} options The options object.
|
|
69
|
+
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
|
|
70
|
+
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
|
|
71
|
+
* @return Returns the new throttled function.
|
|
72
|
+
*/
|
|
73
|
+
export const throttle = (func, wait, options) => {
|
|
74
|
+
let leading = true;
|
|
75
|
+
let trailing = true;
|
|
76
|
+
|
|
77
|
+
if (options) {
|
|
78
|
+
leading = 'leading' in options ? !!options.leading : leading;
|
|
79
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return debounce(func, wait, {
|
|
83
|
+
leading,
|
|
84
|
+
trailing,
|
|
85
|
+
maxWait: wait
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/utils/throttle/index.ts"],"names":["debounce","throttle","func","wait","options","leading","trailing","maxWait"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,aAAzB;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,CACvBC,IADuB,EAEvBC,IAFuB,EAGvBC,OAHuB,KAInB;AACJ,MAAIC,OAAO,GAAG,IAAd;AACA,MAAIC,QAAQ,GAAG,IAAf;;AAEA,MAAKF,OAAL,EAAe;AACdC,IAAAA,OAAO,GAAG,aAAaD,OAAb,GAAuB,CAAC,CAAEA,OAAO,CAACC,OAAlC,GAA4CA,OAAtD;AACAC,IAAAA,QAAQ,GAAG,cAAcF,OAAd,GAAwB,CAAC,CAAEA,OAAO,CAACE,QAAnC,GAA8CA,QAAzD;AACA;;AACD,SAAON,QAAQ,CAAEE,IAAF,EAAQC,IAAR,EAAc;AAC5BE,IAAAA,OAD4B;AAE5BC,IAAAA,QAF4B;AAG5BC,IAAAA,OAAO,EAAEJ;AAHmB,GAAd,CAAf;AAKA,CAjBM","sourcesContent":["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../debounce';\n\nexport interface ThrottleOptions {\n\tleading?: boolean;\n\ttrailing?: boolean;\n}\n\n/**\n * A simplified and properly typed version of lodash's `throttle`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return\n * the result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * @param {Function} func The function to throttle.\n * @param {number} wait The number of milliseconds to throttle invocations to.\n * @param {Partial< ThrottleOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n * @return Returns the new throttled function.\n */\nexport const throttle = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: ThrottleOptions\n) => {\n\tlet leading = true;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = 'leading' in options ? !! options.leading : leading;\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\treturn debounce( func, wait, {\n\t\tleading,\n\t\ttrailing,\n\t\tmaxWait: wait,\n\t} );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CA4LnD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Throttles a function
|
|
2
|
+
* Throttles a function similar to Lodash's `throttle`. A new throttled function will
|
|
3
3
|
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
4
4
|
* including the function to throttle, so please wrap functions created on
|
|
5
5
|
* render in components in `useCallback`.
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @template {(...args: any[]) => void} TFunc
|
|
10
10
|
*
|
|
11
|
-
* @param {TFunc}
|
|
12
|
-
* @param {number}
|
|
13
|
-
* @param {import('
|
|
14
|
-
* @return {import('
|
|
11
|
+
* @param {TFunc} fn The function to throttle.
|
|
12
|
+
* @param {number} [wait] The number of milliseconds to throttle invocations to.
|
|
13
|
+
* @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
|
|
14
|
+
* @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
|
|
15
15
|
*/
|
|
16
|
-
export default function useThrottle<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("
|
|
16
|
+
export default function useThrottle<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("../../utils/throttle").ThrottleOptions | undefined): import("../../utils/debounce").DebouncedFunc<TFunc>;
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,mKAcrC"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./utils/create-higher-order-component";
|
|
2
2
|
export * from "./utils/debounce";
|
|
3
|
+
export * from "./utils/throttle";
|
|
3
4
|
export { default as compose } from "./higher-order/compose";
|
|
4
5
|
export { default as pipe } from "./higher-order/pipe";
|
|
5
6
|
export { default as ifCondition } from "./higher-order/if-condition";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parts of this source were derived and modified from lodash,
|
|
3
|
+
* released under the MIT license.
|
|
4
|
+
*
|
|
5
|
+
* https://github.com/lodash/lodash
|
|
6
|
+
*
|
|
7
|
+
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
8
|
+
*
|
|
9
|
+
* Based on Underscore.js, copyright Jeremy Ashkenas,
|
|
10
|
+
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
|
11
|
+
*
|
|
12
|
+
* This software consists of voluntary contributions made by many
|
|
13
|
+
* individuals. For exact contribution history, see the revision history
|
|
14
|
+
* available at https://github.com/lodash/lodash
|
|
15
|
+
*
|
|
16
|
+
* The following license applies to all parts of this software except as
|
|
17
|
+
* documented below:
|
|
18
|
+
*
|
|
19
|
+
* ====
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
22
|
+
* a copy of this software and associated documentation files (the
|
|
23
|
+
* "Software"), to deal in the Software without restriction, including
|
|
24
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
25
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
26
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
27
|
+
* the following conditions:
|
|
28
|
+
*
|
|
29
|
+
* The above copyright notice and this permission notice shall be
|
|
30
|
+
* included in all copies or substantial portions of the Software.
|
|
31
|
+
*
|
|
32
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
33
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
34
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
35
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
36
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
37
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
38
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
*/
|
|
40
|
+
export interface ThrottleOptions {
|
|
41
|
+
leading?: boolean;
|
|
42
|
+
trailing?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A simplified and properly typed version of lodash's `throttle`, that
|
|
46
|
+
* always uses timers instead of sometimes using rAF.
|
|
47
|
+
*
|
|
48
|
+
* Creates a throttled function that only invokes `func` at most once per
|
|
49
|
+
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
50
|
+
* method to cancel delayed `func` invocations and a `flush` method to
|
|
51
|
+
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
52
|
+
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
53
|
+
* timeout. The `func` is invoked with the last arguments provided to the
|
|
54
|
+
* throttled function. Subsequent calls to the throttled function return
|
|
55
|
+
* the result of the last `func` invocation.
|
|
56
|
+
*
|
|
57
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
58
|
+
* invoked on the trailing edge of the timeout only if the throttled function
|
|
59
|
+
* is invoked more than once during the `wait` timeout.
|
|
60
|
+
*
|
|
61
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
62
|
+
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
63
|
+
*
|
|
64
|
+
* @param {Function} func The function to throttle.
|
|
65
|
+
* @param {number} wait The number of milliseconds to throttle invocations to.
|
|
66
|
+
* @param {Partial< ThrottleOptions >} options The options object.
|
|
67
|
+
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
|
|
68
|
+
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
|
|
69
|
+
* @return Returns the new throttled function.
|
|
70
|
+
*/
|
|
71
|
+
export declare const throttle: <FunctionT extends (...args: unknown[]) => unknown>(func: FunctionT, wait: number, options?: ThrottleOptions | undefined) => {
|
|
72
|
+
(this: unknown, ...args: Parameters<FunctionT>): ReturnType<FunctionT>;
|
|
73
|
+
cancel: () => void;
|
|
74
|
+
flush: () => ReturnType<FunctionT>;
|
|
75
|
+
pending: () => boolean;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/throttle/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAOH,MAAM,WAAW,eAAe;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,QAAQ,+BAAkC,OAAO,EAAE,KAAM,OAAO,yBAEtE,MAAM;;;;;CAeZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "5.16.0",
|
|
3
|
+
"version": "5.16.1-next.4d3b314fd5.0",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
33
|
"@types/lodash": "^4.14.172",
|
|
34
34
|
"@types/mousetrap": "^1.6.8",
|
|
35
|
-
"@wordpress/deprecated": "^3.18.0",
|
|
36
|
-
"@wordpress/dom": "^3.18.0",
|
|
37
|
-
"@wordpress/element": "^4.16.0",
|
|
38
|
-
"@wordpress/is-shallow-equal": "^4.18.0",
|
|
39
|
-
"@wordpress/keycodes": "^3.18.0",
|
|
40
|
-
"@wordpress/priority-queue": "^2.18.0",
|
|
35
|
+
"@wordpress/deprecated": "^3.18.1-next.4d3b314fd5.0",
|
|
36
|
+
"@wordpress/dom": "^3.18.1-next.4d3b314fd5.0",
|
|
37
|
+
"@wordpress/element": "^4.16.1-next.4d3b314fd5.0",
|
|
38
|
+
"@wordpress/is-shallow-equal": "^4.18.1-next.4d3b314fd5.0",
|
|
39
|
+
"@wordpress/keycodes": "^3.18.1-next.4d3b314fd5.0",
|
|
40
|
+
"@wordpress/priority-queue": "^2.18.1-next.4d3b314fd5.0",
|
|
41
41
|
"change-case": "^4.1.2",
|
|
42
42
|
"clipboard": "^2.0.8",
|
|
43
43
|
"lodash": "^4.17.21",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "25054766423cb49d959eb656c2533530073ff5c2"
|
|
54
54
|
}
|
|
@@ -107,11 +107,6 @@ export default function useDropZone( {
|
|
|
107
107
|
|
|
108
108
|
isDragging = true;
|
|
109
109
|
|
|
110
|
-
ownerDocument.removeEventListener(
|
|
111
|
-
'dragenter',
|
|
112
|
-
maybeDragStart
|
|
113
|
-
);
|
|
114
|
-
|
|
115
110
|
// Note that `dragend` doesn't fire consistently for file and
|
|
116
111
|
// HTML drag events where the drag origin is outside the browser
|
|
117
112
|
// window. In Firefox it may also not fire if the originating
|
|
@@ -202,7 +197,6 @@ export default function useDropZone( {
|
|
|
202
197
|
|
|
203
198
|
isDragging = false;
|
|
204
199
|
|
|
205
|
-
ownerDocument.addEventListener( 'dragenter', maybeDragStart );
|
|
206
200
|
ownerDocument.removeEventListener( 'dragend', maybeDragEnd );
|
|
207
201
|
ownerDocument.removeEventListener( 'mousemove', maybeDragEnd );
|
|
208
202
|
|
|
@@ -221,12 +215,6 @@ export default function useDropZone( {
|
|
|
221
215
|
ownerDocument.addEventListener( 'dragenter', maybeDragStart );
|
|
222
216
|
|
|
223
217
|
return () => {
|
|
224
|
-
onDropRef.current = null;
|
|
225
|
-
onDragStartRef.current = null;
|
|
226
|
-
onDragEnterRef.current = null;
|
|
227
|
-
onDragLeaveRef.current = null;
|
|
228
|
-
onDragEndRef.current = null;
|
|
229
|
-
onDragOverRef.current = null;
|
|
230
218
|
delete element.dataset.isDropZone;
|
|
231
219
|
element.removeEventListener( 'drop', onDrop );
|
|
232
220
|
element.removeEventListener( 'dragenter', onDragEnter );
|
|
@@ -234,7 +222,10 @@ export default function useDropZone( {
|
|
|
234
222
|
element.removeEventListener( 'dragleave', onDragLeave );
|
|
235
223
|
ownerDocument.removeEventListener( 'dragend', maybeDragEnd );
|
|
236
224
|
ownerDocument.removeEventListener( 'mousemove', maybeDragEnd );
|
|
237
|
-
ownerDocument.
|
|
225
|
+
ownerDocument.removeEventListener(
|
|
226
|
+
'dragenter',
|
|
227
|
+
maybeDragStart
|
|
228
|
+
);
|
|
238
229
|
};
|
|
239
230
|
},
|
|
240
231
|
[ isDisabled ]
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { throttle } from 'lodash';
|
|
5
4
|
import { useMemoOne } from 'use-memo-one';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -10,7 +9,12 @@ import { useMemoOne } from 'use-memo-one';
|
|
|
10
9
|
import { useEffect } from '@wordpress/element';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { throttle } from '../../utils/throttle';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Throttles a function similar to Lodash's `throttle`. A new throttled function will
|
|
14
18
|
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
15
19
|
* including the function to throttle, so please wrap functions created on
|
|
16
20
|
* render in components in `useCallback`.
|
|
@@ -19,14 +23,14 @@ import { useEffect } from '@wordpress/element';
|
|
|
19
23
|
*
|
|
20
24
|
* @template {(...args: any[]) => void} TFunc
|
|
21
25
|
*
|
|
22
|
-
* @param {TFunc}
|
|
23
|
-
* @param {number}
|
|
24
|
-
* @param {import('
|
|
25
|
-
* @return {import('
|
|
26
|
+
* @param {TFunc} fn The function to throttle.
|
|
27
|
+
* @param {number} [wait] The number of milliseconds to throttle invocations to.
|
|
28
|
+
* @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
|
|
29
|
+
* @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
|
|
26
30
|
*/
|
|
27
31
|
export default function useThrottle( fn, wait, options ) {
|
|
28
32
|
const throttled = useMemoOne(
|
|
29
|
-
() => throttle( fn, wait, options ),
|
|
33
|
+
() => throttle( fn, wait ?? 0, options ),
|
|
30
34
|
[ fn, wait, options ]
|
|
31
35
|
);
|
|
32
36
|
useEffect( () => () => throttled.cancel(), [ throttled ] );
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export * from './utils/create-higher-order-component';
|
|
3
3
|
// The `debounce` helper and its types.
|
|
4
4
|
export * from './utils/debounce';
|
|
5
|
+
// The `throttle` helper and its types.
|
|
6
|
+
export * from './utils/throttle';
|
|
5
7
|
|
|
6
8
|
// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).
|
|
7
9
|
export { default as compose } from './higher-order/compose';
|
package/src/index.native.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export * from './utils/create-higher-order-component';
|
|
3
3
|
// The `debounce` helper and its types.
|
|
4
4
|
export * from './utils/debounce';
|
|
5
|
+
// The `throttle` helper and its types.
|
|
6
|
+
export * from './utils/throttle';
|
|
5
7
|
|
|
6
8
|
// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).
|
|
7
9
|
export { default as compose } from './higher-order/compose';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parts of this source were derived and modified from lodash,
|
|
3
|
+
* released under the MIT license.
|
|
4
|
+
*
|
|
5
|
+
* https://github.com/lodash/lodash
|
|
6
|
+
*
|
|
7
|
+
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
8
|
+
*
|
|
9
|
+
* Based on Underscore.js, copyright Jeremy Ashkenas,
|
|
10
|
+
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
|
11
|
+
*
|
|
12
|
+
* This software consists of voluntary contributions made by many
|
|
13
|
+
* individuals. For exact contribution history, see the revision history
|
|
14
|
+
* available at https://github.com/lodash/lodash
|
|
15
|
+
*
|
|
16
|
+
* The following license applies to all parts of this software except as
|
|
17
|
+
* documented below:
|
|
18
|
+
*
|
|
19
|
+
* ====
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
22
|
+
* a copy of this software and associated documentation files (the
|
|
23
|
+
* "Software"), to deal in the Software without restriction, including
|
|
24
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
25
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
26
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
27
|
+
* the following conditions:
|
|
28
|
+
*
|
|
29
|
+
* The above copyright notice and this permission notice shall be
|
|
30
|
+
* included in all copies or substantial portions of the Software.
|
|
31
|
+
*
|
|
32
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
33
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
34
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
35
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
36
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
37
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
38
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Internal dependencies
|
|
43
|
+
*/
|
|
44
|
+
import { debounce } from '../debounce';
|
|
45
|
+
|
|
46
|
+
export interface ThrottleOptions {
|
|
47
|
+
leading?: boolean;
|
|
48
|
+
trailing?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A simplified and properly typed version of lodash's `throttle`, that
|
|
53
|
+
* always uses timers instead of sometimes using rAF.
|
|
54
|
+
*
|
|
55
|
+
* Creates a throttled function that only invokes `func` at most once per
|
|
56
|
+
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
57
|
+
* method to cancel delayed `func` invocations and a `flush` method to
|
|
58
|
+
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
59
|
+
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
60
|
+
* timeout. The `func` is invoked with the last arguments provided to the
|
|
61
|
+
* throttled function. Subsequent calls to the throttled function return
|
|
62
|
+
* the result of the last `func` invocation.
|
|
63
|
+
*
|
|
64
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
65
|
+
* invoked on the trailing edge of the timeout only if the throttled function
|
|
66
|
+
* is invoked more than once during the `wait` timeout.
|
|
67
|
+
*
|
|
68
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
69
|
+
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
70
|
+
*
|
|
71
|
+
* @param {Function} func The function to throttle.
|
|
72
|
+
* @param {number} wait The number of milliseconds to throttle invocations to.
|
|
73
|
+
* @param {Partial< ThrottleOptions >} options The options object.
|
|
74
|
+
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
|
|
75
|
+
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
|
|
76
|
+
* @return Returns the new throttled function.
|
|
77
|
+
*/
|
|
78
|
+
export const throttle = < FunctionT extends ( ...args: unknown[] ) => unknown >(
|
|
79
|
+
func: FunctionT,
|
|
80
|
+
wait: number,
|
|
81
|
+
options?: ThrottleOptions
|
|
82
|
+
) => {
|
|
83
|
+
let leading = true;
|
|
84
|
+
let trailing = true;
|
|
85
|
+
|
|
86
|
+
if ( options ) {
|
|
87
|
+
leading = 'leading' in options ? !! options.leading : leading;
|
|
88
|
+
trailing = 'trailing' in options ? !! options.trailing : trailing;
|
|
89
|
+
}
|
|
90
|
+
return debounce( func, wait, {
|
|
91
|
+
leading,
|
|
92
|
+
trailing,
|
|
93
|
+
maxWait: wait,
|
|
94
|
+
} );
|
|
95
|
+
};
|