@wordpress/compose 6.16.0 → 6.17.1
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/CHANGELOG.md +2 -0
- package/build/higher-order/compose.js +0 -2
- package/build/higher-order/compose.js.map +1 -1
- package/build/higher-order/if-condition/index.js +2 -6
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pipe.js +1 -5
- package/build/higher-order/pipe.js.map +1 -1
- package/build/higher-order/pure/index.js +2 -10
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +13 -32
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-global-events/listener.js +5 -28
- package/build/higher-order/with-global-events/listener.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +4 -8
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +3 -6
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js +4 -14
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/higher-order/with-state/index.js +3 -11
- package/build/higher-order/with-state/index.js.map +1 -1
- package/build/hooks/use-async-list/index.js +1 -14
- package/build/hooks/use-async-list/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.js +14 -30
- package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.native.js +4 -4
- package/build/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build/hooks/use-copy-on-click/index.js +6 -15
- package/build/hooks/use-copy-on-click/index.js.map +1 -1
- package/build/hooks/use-copy-to-clipboard/index.js +3 -11
- package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build/hooks/use-debounce/index.js +0 -4
- package/build/hooks/use-debounce/index.js.map +1 -1
- package/build/hooks/use-dialog/index.js +2 -12
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +5 -15
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-dragging/index.js +4 -11
- package/build/hooks/use-dragging/index.js.map +1 -1
- package/build/hooks/use-drop-zone/index.js +27 -66
- package/build/hooks/use-drop-zone/index.js.map +1 -1
- package/build/hooks/use-fixed-window-list/index.js +8 -34
- package/build/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build/hooks/use-focus-on-mount/index.js +3 -14
- package/build/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.js +13 -19
- package/build/hooks/use-focus-outside/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.native.js +13 -21
- package/build/hooks/use-focus-outside/index.native.js.map +1 -1
- package/build/hooks/use-focus-return/index.js +7 -15
- package/build/hooks/use-focus-return/index.js.map +1 -1
- package/build/hooks/use-focusable-iframe/index.js +1 -5
- package/build/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build/hooks/use-instance-id/index.js +3 -5
- package/build/hooks/use-instance-id/index.js.map +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.js +0 -2
- package/build/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.js +12 -28
- package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.native.js +0 -2
- package/build/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build/hooks/use-media-query/index.js +1 -9
- package/build/hooks/use-media-query/index.js.map +1 -1
- package/build/hooks/use-merge-refs/index.js +18 -24
- package/build/hooks/use-merge-refs/index.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +0 -5
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.ios.js +0 -2
- package/build/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme-style/index.native.js +2 -5
- package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build/hooks/use-previous/index.js +3 -4
- package/build/hooks/use-previous/index.js.map +1 -1
- package/build/hooks/use-reduced-motion/index.js +0 -4
- package/build/hooks/use-reduced-motion/index.js.map +1 -1
- package/build/hooks/use-ref-effect/index.js +0 -2
- package/build/hooks/use-ref-effect/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.js +23 -30
- package/build/hooks/use-resize-observer/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +0 -6
- package/build/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build/hooks/use-throttle/index.js +0 -4
- package/build/hooks/use-throttle/index.js.map +1 -1
- package/build/hooks/use-viewport-match/index.js +4 -13
- package/build/hooks/use-viewport-match/index.js.map +1 -1
- package/build/hooks/use-warn-on-change/index.js +4 -14
- package/build/hooks/use-warn-on-change/index.js.map +1 -1
- package/build/index.js +0 -41
- package/build/index.js.map +1 -1
- package/build/index.native.js +0 -33
- package/build/index.native.js.map +1 -1
- package/build/utils/create-higher-order-component/index.js +1 -4
- package/build/utils/create-higher-order-component/index.js.map +1 -1
- package/build/utils/debounce/index.js +12 -37
- package/build/utils/debounce/index.js.map +1 -1
- package/build/utils/throttle/index.js +0 -5
- package/build/utils/throttle/index.js.map +1 -1
- package/build-module/higher-order/compose.js +1 -1
- package/build-module/higher-order/compose.js.map +1 -1
- package/build-module/higher-order/if-condition/index.js +3 -5
- package/build-module/higher-order/if-condition/index.js.map +1 -1
- package/build-module/higher-order/pipe.js +1 -4
- package/build-module/higher-order/pipe.js.map +1 -1
- package/build-module/higher-order/pure/index.js +4 -8
- package/build-module/higher-order/pure/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/index.js +15 -29
- package/build-module/higher-order/with-global-events/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/listener.js +5 -27
- package/build-module/higher-order/with-global-events/listener.js.map +1 -1
- package/build-module/higher-order/with-instance-id/index.js +5 -5
- package/build-module/higher-order/with-instance-id/index.js.map +1 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +3 -3
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build-module/higher-order/with-safe-timeout/index.js +6 -8
- package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build-module/higher-order/with-state/index.js +5 -9
- package/build-module/higher-order/with-state/index.js.map +1 -1
- package/build-module/hooks/use-async-list/index.js +1 -12
- package/build-module/hooks/use-async-list/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +16 -27
- package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.native.js +3 -3
- package/build-module/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build-module/hooks/use-copy-on-click/index.js +8 -12
- package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +6 -9
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build-module/hooks/use-debounce/index.js +3 -3
- package/build-module/hooks/use-debounce/index.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js +3 -5
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +6 -12
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-dragging/index.js +6 -9
- package/build-module/hooks/use-dragging/index.js.map +1 -1
- package/build-module/hooks/use-drop-zone/index.js +29 -64
- package/build-module/hooks/use-drop-zone/index.js.map +1 -1
- package/build-module/hooks/use-fixed-window-list/index.js +8 -30
- package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build-module/hooks/use-focus-on-mount/index.js +4 -12
- package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.js +14 -18
- package/build-module/hooks/use-focus-outside/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.native.js +14 -20
- package/build-module/hooks/use-focus-outside/index.native.js.map +1 -1
- package/build-module/hooks/use-focus-return/index.js +8 -14
- package/build-module/hooks/use-focus-return/index.js.map +1 -1
- package/build-module/hooks/use-focusable-iframe/index.js +2 -3
- package/build-module/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build-module/hooks/use-instance-id/index.js +2 -3
- package/build-module/hooks/use-instance-id/index.js.map +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js +14 -24
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build-module/hooks/use-media-query/index.js +2 -8
- package/build-module/hooks/use-media-query/index.js.map +1 -1
- package/build-module/hooks/use-merge-refs/index.js +19 -23
- package/build-module/hooks/use-merge-refs/index.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.android.js +1 -3
- package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +3 -3
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build-module/hooks/use-previous/index.js +4 -3
- package/build-module/hooks/use-previous/index.js.map +1 -1
- package/build-module/hooks/use-reduced-motion/index.js +1 -2
- package/build-module/hooks/use-reduced-motion/index.js.map +1 -1
- package/build-module/hooks/use-ref-effect/index.js +1 -1
- package/build-module/hooks/use-ref-effect/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.js +22 -30
- package/build-module/hooks/use-resize-observer/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.native.js +1 -6
- package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-module/hooks/use-throttle/index.js +3 -3
- package/build-module/hooks/use-throttle/index.js.map +1 -1
- package/build-module/hooks/use-viewport-match/index.js +6 -11
- package/build-module/hooks/use-viewport-match/index.js.map +1 -1
- package/build-module/hooks/use-warn-on-change/index.js +6 -12
- package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
- package/build-module/index.js +10 -7
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +10 -7
- package/build-module/index.native.js.map +1 -1
- package/build-module/utils/create-higher-order-component/index.js +1 -2
- package/build-module/utils/create-higher-order-component/index.js.map +1 -1
- package/build-module/utils/debounce/index.js +12 -35
- package/build-module/utils/debounce/index.js.map +1 -1
- package/build-module/utils/throttle/index.js +0 -3
- package/build-module/utils/throttle/index.js.map +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +1 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts +1 -1
- package/package.json +8 -8
- package/src/higher-order/with-instance-id/index.tsx +2 -2
- package/src/higher-order/with-safe-timeout/index.tsx +2 -2
- package/src/hooks/use-resize-observer/index.native.js +0 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","withPreferredColorScheme","useConstrainedTabbing","__experimentalUseDragging","__experimentalUseFocusOutside","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","usePreferredColorScheme","usePreferredColorSchemeStyle","useResizeObserver","useDebounce","useThrottle","useMergeRefs","useRefEffect"],"sources":["@wordpress/compose/src/index.native.js"],"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 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"],"mappings":"AAAA;AACA,cAAc,uCAAuC;AACrD;AAC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AW,QAAQ,sBAAsB;AAC7D,SAASxB,OAAO,IAAIyB,YAAY,QAAQ,wBAAwB;AAChE,SAASzB,OAAO,IAAI0B,YAAY,QAAQ,wBAAwB"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { pascalCase } from 'change-case';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Given a function mapping a component to an enhanced component and modifier
|
|
8
7
|
* name, returns the enhanced component augmented with a generated displayName.
|
|
@@ -19,6 +18,7 @@ export function createHigherOrderComponent(mapComponent, modifierName) {
|
|
|
19
18
|
return Outer;
|
|
20
19
|
};
|
|
21
20
|
}
|
|
21
|
+
|
|
22
22
|
/**
|
|
23
23
|
* Returns a displayName for a higher-order component, given a wrapper name.
|
|
24
24
|
*
|
|
@@ -30,7 +30,6 @@ export function createHigherOrderComponent(mapComponent, modifierName) {
|
|
|
30
30
|
* @param Inner Wrapped component inside higher-order component.
|
|
31
31
|
* @return Wrapped name of higher-order component.
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
33
|
const hocName = (name, Inner) => {
|
|
35
34
|
const inner = Inner.displayName || Inner.name || 'Component';
|
|
36
35
|
const outer = pascalCase(name !== null && name !== void 0 ? name : '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["pascalCase","createHigherOrderComponent","mapComponent","modifierName","Inner","Outer","displayName","hocName","name","inner","outer"],"sources":["@wordpress/compose/src/utils/create-higher-order-component/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { pascalCase } from 'change-case';\nimport type { ComponentType } from 'react';\n\ntype GetProps< C > = C extends ComponentType< infer P > ? P : never;\n\nexport type WithoutInjectedProps< C, I > = Omit< GetProps< C >, keyof I >;\n\nexport type WithInjectedProps< C, I > = ComponentType<\n\tWithoutInjectedProps< C, I > & I\n>;\n\n/**\n * Given a function mapping a component to an enhanced component and modifier\n * name, returns the enhanced component augmented with a generated displayName.\n *\n * @param mapComponent Function mapping component to enhanced component.\n * @param modifierName Seed name from which to generated display name.\n *\n * @return Component class with generated display name assigned.\n */\nexport function createHigherOrderComponent<\n\tTInner extends ComponentType< any >,\n\tTOuter extends ComponentType< any >\n>( mapComponent: ( Inner: TInner ) => TOuter, modifierName: string ) {\n\treturn ( Inner: TInner ) => {\n\t\tconst Outer = mapComponent( Inner );\n\t\tOuter.displayName = hocName( modifierName, Inner );\n\t\treturn Outer;\n\t};\n}\n\n/**\n * Returns a displayName for a higher-order component, given a wrapper name.\n *\n * @example\n * hocName( 'MyMemo', Widget ) === 'MyMemo(Widget)';\n * hocName( 'MyMemo', <div /> ) === 'MyMemo(Component)';\n *\n * @param name Name assigned to higher-order component's wrapper component.\n * @param Inner Wrapped component inside higher-order component.\n * @return Wrapped name of higher-order component.\n */\nconst hocName = ( name: string, Inner: ComponentType< any > ) => {\n\tconst inner = Inner.displayName || Inner.name || 'Component';\n\tconst outer = pascalCase( name ?? '' );\n\n\treturn `${ outer }(${ inner })`;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,aAAa;AAWxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CAGvCC,YAAyC,EAAEC,YAAoB,EAAG;EACpE,OAASC,KAAa,IAAM;IAC3B,MAAMC,KAAK,GAAGH,YAAY,CAAEE,KAAM,CAAC;IACnCC,KAAK,CAACC,WAAW,GAAGC,OAAO,CAAEJ,YAAY,EAAEC,KAAM,CAAC;IAClD,OAAOC,KAAK;EACb,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,OAAO,GAAGA,CAAEC,IAAY,EAAEJ,KAA2B,KAAM;EAChE,MAAMK,KAAK,GAAGL,KAAK,CAACE,WAAW,IAAIF,KAAK,CAACI,IAAI,IAAI,WAAW;EAC5D,MAAME,KAAK,GAAGV,UAAU,CAAEQ,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,EAAG,CAAC;EAEtC,OAAQ,GAAGE,KAAO,IAAID,KAAO,GAAE;AAChC,CAAC"}
|
|
@@ -78,18 +78,14 @@ export const debounce = (func, wait, options) => {
|
|
|
78
78
|
let leading = false;
|
|
79
79
|
let maxing = false;
|
|
80
80
|
let trailing = true;
|
|
81
|
-
|
|
82
81
|
if (options) {
|
|
83
82
|
leading = !!options.leading;
|
|
84
83
|
maxing = 'maxWait' in options;
|
|
85
|
-
|
|
86
84
|
if (options.maxWait !== undefined) {
|
|
87
85
|
maxWait = Math.max(options.maxWait, wait);
|
|
88
86
|
}
|
|
89
|
-
|
|
90
87
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
91
88
|
}
|
|
92
|
-
|
|
93
89
|
function invokeFunc(time) {
|
|
94
90
|
const args = lastArgs;
|
|
95
91
|
const thisArg = lastThis;
|
|
@@ -99,115 +95,96 @@ export const debounce = (func, wait, options) => {
|
|
|
99
95
|
result = func.apply(thisArg, args);
|
|
100
96
|
return result;
|
|
101
97
|
}
|
|
102
|
-
|
|
103
98
|
function startTimer(pendingFunc, waitTime) {
|
|
104
99
|
timerId = setTimeout(pendingFunc, waitTime);
|
|
105
100
|
}
|
|
106
|
-
|
|
107
101
|
function cancelTimer() {
|
|
108
102
|
if (timerId !== undefined) {
|
|
109
103
|
clearTimeout(timerId);
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
|
-
|
|
113
106
|
function leadingEdge(time) {
|
|
114
107
|
// Reset any `maxWait` timer.
|
|
115
|
-
lastInvokeTime = time;
|
|
116
|
-
|
|
117
|
-
startTimer(timerExpired, wait);
|
|
118
|
-
|
|
108
|
+
lastInvokeTime = time;
|
|
109
|
+
// Start the timer for the trailing edge.
|
|
110
|
+
startTimer(timerExpired, wait);
|
|
111
|
+
// Invoke the leading edge.
|
|
119
112
|
return leading ? invokeFunc(time) : result;
|
|
120
113
|
}
|
|
121
|
-
|
|
122
114
|
function getTimeSinceLastCall(time) {
|
|
123
115
|
return time - (lastCallTime || 0);
|
|
124
116
|
}
|
|
125
|
-
|
|
126
117
|
function remainingWait(time) {
|
|
127
118
|
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
128
119
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
129
120
|
const timeWaiting = wait - timeSinceLastCall;
|
|
130
121
|
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
131
122
|
}
|
|
132
|
-
|
|
133
123
|
function shouldInvoke(time) {
|
|
134
124
|
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
135
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
125
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
126
|
+
|
|
127
|
+
// Either this is the first call, activity has stopped and we're at the
|
|
136
128
|
// trailing edge, the system time has gone backwards and we're treating
|
|
137
129
|
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
138
|
-
|
|
139
130
|
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
140
131
|
}
|
|
141
|
-
|
|
142
132
|
function timerExpired() {
|
|
143
133
|
const time = Date.now();
|
|
144
|
-
|
|
145
134
|
if (shouldInvoke(time)) {
|
|
146
135
|
return trailingEdge(time);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
136
|
+
}
|
|
137
|
+
// Restart the timer.
|
|
150
138
|
startTimer(timerExpired, remainingWait(time));
|
|
151
139
|
return undefined;
|
|
152
140
|
}
|
|
153
|
-
|
|
154
141
|
function clearTimer() {
|
|
155
142
|
timerId = undefined;
|
|
156
143
|
}
|
|
157
|
-
|
|
158
144
|
function trailingEdge(time) {
|
|
159
|
-
clearTimer();
|
|
160
|
-
// debounced at least once.
|
|
145
|
+
clearTimer();
|
|
161
146
|
|
|
147
|
+
// Only invoke if we have `lastArgs` which means `func` has been
|
|
148
|
+
// debounced at least once.
|
|
162
149
|
if (trailing && lastArgs) {
|
|
163
150
|
return invokeFunc(time);
|
|
164
151
|
}
|
|
165
|
-
|
|
166
152
|
lastArgs = lastThis = undefined;
|
|
167
153
|
return result;
|
|
168
154
|
}
|
|
169
|
-
|
|
170
155
|
function cancel() {
|
|
171
156
|
cancelTimer();
|
|
172
157
|
lastInvokeTime = 0;
|
|
173
158
|
clearTimer();
|
|
174
159
|
lastArgs = lastCallTime = lastThis = undefined;
|
|
175
160
|
}
|
|
176
|
-
|
|
177
161
|
function flush() {
|
|
178
162
|
return pending() ? trailingEdge(Date.now()) : result;
|
|
179
163
|
}
|
|
180
|
-
|
|
181
164
|
function pending() {
|
|
182
165
|
return timerId !== undefined;
|
|
183
166
|
}
|
|
184
|
-
|
|
185
167
|
function debounced(...args) {
|
|
186
168
|
const time = Date.now();
|
|
187
169
|
const isInvoking = shouldInvoke(time);
|
|
188
170
|
lastArgs = args;
|
|
189
171
|
lastThis = this;
|
|
190
172
|
lastCallTime = time;
|
|
191
|
-
|
|
192
173
|
if (isInvoking) {
|
|
193
174
|
if (!pending()) {
|
|
194
175
|
return leadingEdge(lastCallTime);
|
|
195
176
|
}
|
|
196
|
-
|
|
197
177
|
if (maxing) {
|
|
198
178
|
// Handle invocations in a tight loop.
|
|
199
179
|
startTimer(timerExpired, wait);
|
|
200
180
|
return invokeFunc(lastCallTime);
|
|
201
181
|
}
|
|
202
182
|
}
|
|
203
|
-
|
|
204
183
|
if (!pending()) {
|
|
205
184
|
startTimer(timerExpired, wait);
|
|
206
185
|
}
|
|
207
|
-
|
|
208
186
|
return result;
|
|
209
187
|
}
|
|
210
|
-
|
|
211
188
|
debounced.cancel = cancel;
|
|
212
189
|
debounced.flush = flush;
|
|
213
190
|
debounced.pending = pending;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/utils/debounce/index.ts"],"names":["debounce","func","wait","options","lastArgs","lastThis","maxWait","result","timerId","lastCallTime","lastInvokeTime","leading","maxing","trailing","undefined","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","waitTime","setTimeout","cancelTimer","clearTimeout","leadingEdge","timerExpired","getTimeSinceLastCall","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","clearTimer","cancel","flush","pending","debounced","isInvoking"],"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;;AAmCA;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,OAAO,MAAMA,QAAQ,GAAG,CACvBC,IADuB,EAEvBC,IAFuB,EAGvBC,OAHuB,KAInB;AACJ,MAAIC,QAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,OAAO,GAAG,CAAd;AACA,MAAIC,MAAJ;AACA,MAAIC,OAAJ;AACA,MAAIC,YAAJ;AAEA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,OAAO,GAAG,KAAd;AACA,MAAIC,MAAM,GAAG,KAAb;AACA,MAAIC,QAAQ,GAAG,IAAf;;AAEA,MAAKV,OAAL,EAAe;AACdQ,IAAAA,OAAO,GAAG,CAAC,CAAER,OAAO,CAACQ,OAArB;AACAC,IAAAA,MAAM,GAAG,aAAaT,OAAtB;;AACA,QAAKA,OAAO,CAACG,OAAR,KAAoBQ,SAAzB,EAAqC;AACpCR,MAAAA,OAAO,GAAGS,IAAI,CAACC,GAAL,CAAUb,OAAO,CAACG,OAAlB,EAA2BJ,IAA3B,CAAV;AACA;;AACDW,IAAAA,QAAQ,GAAG,cAAcV,OAAd,GAAwB,CAAC,CAAEA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;;AAED,WAASoC,OAAT,GAAmB;AAClB,WAAOnC,OAAO,KAAKM,SAAnB;AACA;;AAED,WAAS8B,SAAT,CAAmC,GAAGzB,IAAtC,EAAsE;AACrE,UAAMD,IAAI,GAAGmB,IAAI,CAACC,GAAL,EAAb;AACA,UAAMO,UAAU,GAAGT,YAAY,CAAElB,IAAF,CAA/B;AAEAd,IAAAA,QAAQ,GAAGe,IAAX;AACAd,IAAAA,QAAQ,GAAG,IAAX;AACAI,IAAAA,YAAY,GAAGS,IAAf;;AAEA,QAAK2B,UAAL,EAAkB;AACjB,UAAK,CAAEF,OAAO,EAAd,EAAmB;AAClB,eAAOf,WAAW,CAAEnB,YAAF,CAAlB;AACA;;AACD,UAAKG,MAAL,EAAc;AACb;AACAU,QAAAA,UAAU,CAAEO,YAAF,EAAgB3B,IAAhB,CAAV;AACA,eAAOe,UAAU,CAAER,YAAF,CAAjB;AACA;AACD;;AACD,QAAK,CAAEkC,OAAO,EAAd,EAAmB;AAClBrB,MAAAA,UAAU,CAAEO,YAAF,EAAgB3B,IAAhB,CAAV;AACA;;AACD,WAAOK,MAAP;AACA;;AACDqC,EAAAA,SAAS,CAACH,MAAV,GAAmBA,MAAnB;AACAG,EAAAA,SAAS,CAACF,KAAV,GAAkBA,KAAlB;AACAE,EAAAA,SAAS,CAACD,OAAV,GAAoBA,OAApB;AACA,SAAOC,SAAP;AACA,CA7JM","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\nexport interface DebounceOptions {\n\tleading: boolean;\n\tmaxWait: number;\n\ttrailing: boolean;\n}\n\nexport interface DebouncedFunc< T extends ( ...args: any[] ) => any > {\n\t/**\n\t * Call the original function, but applying the debounce rules.\n\t *\n\t * If the debounced function can be run immediately, this calls it and returns its return\n\t * value.\n\t *\n\t * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n\t * function was not invoked yet.\n\t */\n\t( ...args: Parameters< T > ): ReturnType< T > | undefined;\n\n\t/**\n\t * Throw away any pending invocation of the debounced function.\n\t */\n\tcancel(): void;\n\n\t/**\n\t * If there is a pending invocation of the debounced function, invoke it immediately and return\n\t * its return value.\n\t *\n\t * Otherwise, return the value from the last invocation, or undefined if the debounced function\n\t * was never invoked.\n\t */\n\tflush(): ReturnType< T > | undefined;\n}\n\n/**\n * A simplified and properly typed version of lodash's `debounce`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel delayed\n * `func` invocations and a `flush` method to immediately invoke them. Provide\n * `options` to indicate whether `func` should be invoked on the leading and/or\n * trailing edge of the `wait` timeout. The `func` is invoked with the last\n * arguments provided to the debounced function. Subsequent calls to the debounced\n * function return 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 debounced 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 debounce.\n * @param {number} wait The number of milliseconds to delay.\n * @param {Partial< DebounceOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n *\n * @return Returns the new debounced function.\n */\nexport const debounce = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: Partial< DebounceOptions >\n) => {\n\tlet lastArgs: Parameters< FunctionT > | undefined;\n\tlet lastThis: unknown | undefined;\n\tlet maxWait = 0;\n\tlet result: ReturnType< FunctionT >;\n\tlet timerId: ReturnType< typeof setTimeout > | undefined;\n\tlet lastCallTime: number | undefined;\n\n\tlet lastInvokeTime = 0;\n\tlet leading = false;\n\tlet maxing = false;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = !! options.leading;\n\t\tmaxing = 'maxWait' in options;\n\t\tif ( options.maxWait !== undefined ) {\n\t\t\tmaxWait = Math.max( options.maxWait, wait );\n\t\t}\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\n\tfunction invokeFunc( time: number ) {\n\t\tconst args = lastArgs;\n\t\tconst thisArg = lastThis;\n\n\t\tlastArgs = undefined;\n\t\tlastThis = undefined;\n\t\tlastInvokeTime = time;\n\n\t\tresult = func.apply( thisArg, args! ) as ReturnType< FunctionT >;\n\t\treturn result;\n\t}\n\n\tfunction startTimer(\n\t\tpendingFunc: () => void,\n\t\twaitTime: number | undefined\n\t) {\n\t\ttimerId = setTimeout( pendingFunc, waitTime );\n\t}\n\n\tfunction cancelTimer() {\n\t\tif ( timerId !== undefined ) {\n\t\t\tclearTimeout( timerId );\n\t\t}\n\t}\n\n\tfunction leadingEdge( time: number ) {\n\t\t// Reset any `maxWait` timer.\n\t\tlastInvokeTime = time;\n\t\t// Start the timer for the trailing edge.\n\t\tstartTimer( timerExpired, wait );\n\t\t// Invoke the leading edge.\n\t\treturn leading ? invokeFunc( time ) : result;\n\t}\n\n\tfunction getTimeSinceLastCall( time: number ) {\n\t\treturn time - ( lastCallTime || 0 );\n\t}\n\n\tfunction remainingWait( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\t\tconst timeWaiting = wait - timeSinceLastCall;\n\n\t\treturn maxing\n\t\t\t? Math.min( timeWaiting, maxWait - timeSinceLastInvoke )\n\t\t\t: timeWaiting;\n\t}\n\n\tfunction shouldInvoke( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\n\t\t// Either this is the first call, activity has stopped and we're at the\n\t\t// trailing edge, the system time has gone backwards and we're treating\n\t\t// it as the trailing edge, or we've hit the `maxWait` limit.\n\t\treturn (\n\t\t\tlastCallTime === undefined ||\n\t\t\ttimeSinceLastCall >= wait ||\n\t\t\ttimeSinceLastCall < 0 ||\n\t\t\t( maxing && timeSinceLastInvoke >= maxWait )\n\t\t);\n\t}\n\n\tfunction timerExpired() {\n\t\tconst time = Date.now();\n\t\tif ( shouldInvoke( time ) ) {\n\t\t\treturn trailingEdge( time );\n\t\t}\n\t\t// Restart the timer.\n\t\tstartTimer( timerExpired, remainingWait( time ) );\n\t\treturn undefined;\n\t}\n\n\tfunction clearTimer() {\n\t\ttimerId = undefined;\n\t}\n\n\tfunction trailingEdge( time: number ) {\n\t\tclearTimer();\n\n\t\t// Only invoke if we have `lastArgs` which means `func` has been\n\t\t// debounced at least once.\n\t\tif ( trailing && lastArgs ) {\n\t\t\treturn invokeFunc( time );\n\t\t}\n\t\tlastArgs = lastThis = undefined;\n\t\treturn result;\n\t}\n\n\tfunction cancel() {\n\t\tcancelTimer();\n\t\tlastInvokeTime = 0;\n\t\tclearTimer();\n\t\tlastArgs = lastCallTime = lastThis = undefined;\n\t}\n\n\tfunction flush() {\n\t\treturn pending() ? trailingEdge( Date.now() ) : result;\n\t}\n\n\tfunction pending() {\n\t\treturn timerId !== undefined;\n\t}\n\n\tfunction debounced( this: unknown, ...args: Parameters< FunctionT > ) {\n\t\tconst time = Date.now();\n\t\tconst isInvoking = shouldInvoke( time );\n\n\t\tlastArgs = args;\n\t\tlastThis = this;\n\t\tlastCallTime = time;\n\n\t\tif ( isInvoking ) {\n\t\t\tif ( ! pending() ) {\n\t\t\t\treturn leadingEdge( lastCallTime );\n\t\t\t}\n\t\t\tif ( maxing ) {\n\t\t\t\t// Handle invocations in a tight loop.\n\t\t\t\tstartTimer( timerExpired, wait );\n\t\t\t\treturn invokeFunc( lastCallTime );\n\t\t\t}\n\t\t}\n\t\tif ( ! pending() ) {\n\t\t\tstartTimer( timerExpired, wait );\n\t\t}\n\t\treturn result;\n\t}\n\tdebounced.cancel = cancel;\n\tdebounced.flush = flush;\n\tdebounced.pending = pending;\n\treturn debounced;\n};\n"]}
|
|
1
|
+
{"version":3,"names":["debounce","func","wait","options","lastArgs","lastThis","maxWait","result","timerId","lastCallTime","lastInvokeTime","leading","maxing","trailing","undefined","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","waitTime","setTimeout","cancelTimer","clearTimeout","leadingEdge","timerExpired","getTimeSinceLastCall","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","clearTimer","cancel","flush","pending","debounced","isInvoking"],"sources":["@wordpress/compose/src/utils/debounce/index.ts"],"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\nexport interface DebounceOptions {\n\tleading: boolean;\n\tmaxWait: number;\n\ttrailing: boolean;\n}\n\nexport interface DebouncedFunc< T extends ( ...args: any[] ) => any > {\n\t/**\n\t * Call the original function, but applying the debounce rules.\n\t *\n\t * If the debounced function can be run immediately, this calls it and returns its return\n\t * value.\n\t *\n\t * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n\t * function was not invoked yet.\n\t */\n\t( ...args: Parameters< T > ): ReturnType< T > | undefined;\n\n\t/**\n\t * Throw away any pending invocation of the debounced function.\n\t */\n\tcancel(): void;\n\n\t/**\n\t * If there is a pending invocation of the debounced function, invoke it immediately and return\n\t * its return value.\n\t *\n\t * Otherwise, return the value from the last invocation, or undefined if the debounced function\n\t * was never invoked.\n\t */\n\tflush(): ReturnType< T > | undefined;\n}\n\n/**\n * A simplified and properly typed version of lodash's `debounce`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel delayed\n * `func` invocations and a `flush` method to immediately invoke them. Provide\n * `options` to indicate whether `func` should be invoked on the leading and/or\n * trailing edge of the `wait` timeout. The `func` is invoked with the last\n * arguments provided to the debounced function. Subsequent calls to the debounced\n * function return 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 debounced 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 debounce.\n * @param {number} wait The number of milliseconds to delay.\n * @param {Partial< DebounceOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n *\n * @return Returns the new debounced function.\n */\nexport const debounce = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: Partial< DebounceOptions >\n) => {\n\tlet lastArgs: Parameters< FunctionT > | undefined;\n\tlet lastThis: unknown | undefined;\n\tlet maxWait = 0;\n\tlet result: ReturnType< FunctionT >;\n\tlet timerId: ReturnType< typeof setTimeout > | undefined;\n\tlet lastCallTime: number | undefined;\n\n\tlet lastInvokeTime = 0;\n\tlet leading = false;\n\tlet maxing = false;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = !! options.leading;\n\t\tmaxing = 'maxWait' in options;\n\t\tif ( options.maxWait !== undefined ) {\n\t\t\tmaxWait = Math.max( options.maxWait, wait );\n\t\t}\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\n\tfunction invokeFunc( time: number ) {\n\t\tconst args = lastArgs;\n\t\tconst thisArg = lastThis;\n\n\t\tlastArgs = undefined;\n\t\tlastThis = undefined;\n\t\tlastInvokeTime = time;\n\n\t\tresult = func.apply( thisArg, args! ) as ReturnType< FunctionT >;\n\t\treturn result;\n\t}\n\n\tfunction startTimer(\n\t\tpendingFunc: () => void,\n\t\twaitTime: number | undefined\n\t) {\n\t\ttimerId = setTimeout( pendingFunc, waitTime );\n\t}\n\n\tfunction cancelTimer() {\n\t\tif ( timerId !== undefined ) {\n\t\t\tclearTimeout( timerId );\n\t\t}\n\t}\n\n\tfunction leadingEdge( time: number ) {\n\t\t// Reset any `maxWait` timer.\n\t\tlastInvokeTime = time;\n\t\t// Start the timer for the trailing edge.\n\t\tstartTimer( timerExpired, wait );\n\t\t// Invoke the leading edge.\n\t\treturn leading ? invokeFunc( time ) : result;\n\t}\n\n\tfunction getTimeSinceLastCall( time: number ) {\n\t\treturn time - ( lastCallTime || 0 );\n\t}\n\n\tfunction remainingWait( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\t\tconst timeWaiting = wait - timeSinceLastCall;\n\n\t\treturn maxing\n\t\t\t? Math.min( timeWaiting, maxWait - timeSinceLastInvoke )\n\t\t\t: timeWaiting;\n\t}\n\n\tfunction shouldInvoke( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\n\t\t// Either this is the first call, activity has stopped and we're at the\n\t\t// trailing edge, the system time has gone backwards and we're treating\n\t\t// it as the trailing edge, or we've hit the `maxWait` limit.\n\t\treturn (\n\t\t\tlastCallTime === undefined ||\n\t\t\ttimeSinceLastCall >= wait ||\n\t\t\ttimeSinceLastCall < 0 ||\n\t\t\t( maxing && timeSinceLastInvoke >= maxWait )\n\t\t);\n\t}\n\n\tfunction timerExpired() {\n\t\tconst time = Date.now();\n\t\tif ( shouldInvoke( time ) ) {\n\t\t\treturn trailingEdge( time );\n\t\t}\n\t\t// Restart the timer.\n\t\tstartTimer( timerExpired, remainingWait( time ) );\n\t\treturn undefined;\n\t}\n\n\tfunction clearTimer() {\n\t\ttimerId = undefined;\n\t}\n\n\tfunction trailingEdge( time: number ) {\n\t\tclearTimer();\n\n\t\t// Only invoke if we have `lastArgs` which means `func` has been\n\t\t// debounced at least once.\n\t\tif ( trailing && lastArgs ) {\n\t\t\treturn invokeFunc( time );\n\t\t}\n\t\tlastArgs = lastThis = undefined;\n\t\treturn result;\n\t}\n\n\tfunction cancel() {\n\t\tcancelTimer();\n\t\tlastInvokeTime = 0;\n\t\tclearTimer();\n\t\tlastArgs = lastCallTime = lastThis = undefined;\n\t}\n\n\tfunction flush() {\n\t\treturn pending() ? trailingEdge( Date.now() ) : result;\n\t}\n\n\tfunction pending() {\n\t\treturn timerId !== undefined;\n\t}\n\n\tfunction debounced( this: unknown, ...args: Parameters< FunctionT > ) {\n\t\tconst time = Date.now();\n\t\tconst isInvoking = shouldInvoke( time );\n\n\t\tlastArgs = args;\n\t\tlastThis = this;\n\t\tlastCallTime = time;\n\n\t\tif ( isInvoking ) {\n\t\t\tif ( ! pending() ) {\n\t\t\t\treturn leadingEdge( lastCallTime );\n\t\t\t}\n\t\t\tif ( maxing ) {\n\t\t\t\t// Handle invocations in a tight loop.\n\t\t\t\tstartTimer( timerExpired, wait );\n\t\t\t\treturn invokeFunc( lastCallTime );\n\t\t\t}\n\t\t}\n\t\tif ( ! pending() ) {\n\t\t\tstartTimer( timerExpired, wait );\n\t\t}\n\t\treturn result;\n\t}\n\tdebounced.cancel = cancel;\n\tdebounced.flush = flush;\n\tdebounced.pending = pending;\n\treturn debounced;\n};\n"],"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;;AAmCA;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,OAAO,MAAMA,QAAQ,GAAGA,CACvBC,IAAe,EACfC,IAAY,EACZC,OAAoC,KAChC;EACJ,IAAIC,QAA6C;EACjD,IAAIC,QAA6B;EACjC,IAAIC,OAAO,GAAG,CAAC;EACf,IAAIC,MAA+B;EACnC,IAAIC,OAAoD;EACxD,IAAIC,YAAgC;EAEpC,IAAIC,cAAc,GAAG,CAAC;EACtB,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAIC,MAAM,GAAG,KAAK;EAClB,IAAIC,QAAQ,GAAG,IAAI;EAEnB,IAAKV,OAAO,EAAG;IACdQ,OAAO,GAAG,CAAC,CAAER,OAAO,CAACQ,OAAO;IAC5BC,MAAM,GAAG,SAAS,IAAIT,OAAO;IAC7B,IAAKA,OAAO,CAACG,OAAO,KAAKQ,SAAS,EAAG;MACpCR,OAAO,GAAGS,IAAI,CAACC,GAAG,CAAEb,OAAO,CAACG,OAAO,EAAEJ,IAAK,CAAC;IAC5C;IACAW,QAAQ,GAAG,UAAU,IAAIV,OAAO,GAAG,CAAC,CAAEA,OAAO,CAACU,QAAQ,GAAGA,QAAQ;EAClE;EAEA,SAASI,UAAUA,CAAEC,IAAY,EAAG;IACnC,MAAMC,IAAI,GAAGf,QAAQ;IACrB,MAAMgB,OAAO,GAAGf,QAAQ;IAExBD,QAAQ,GAAG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,GAAGe,IAAI;IACfd,QAAQ,GAAG,IAAI;IACfI,YAAY,GAAGS,IAAI;IAEnB,IAAK2B,UAAU,EAAG;MACjB,IAAK,CAAEF,OAAO,CAAC,CAAC,EAAG;QAClB,OAAOf,WAAW,CAAEnB,YAAa,CAAC;MACnC;MACA,IAAKG,MAAM,EAAG;QACb;QACAU,UAAU,CAAEO,YAAY,EAAE3B,IAAK,CAAC;QAChC,OAAOe,UAAU,CAAER,YAAa,CAAC;MAClC;IACD;IACA,IAAK,CAAEkC,OAAO,CAAC,CAAC,EAAG;MAClBrB,UAAU,CAAEO,YAAY,EAAE3B,IAAK,CAAC;IACjC;IACA,OAAOK,MAAM;EACd;EACAqC,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAC3B,OAAOC,SAAS;AACjB,CAAC"}
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
* Internal dependencies
|
|
43
43
|
*/
|
|
44
44
|
import { debounce } from '../debounce';
|
|
45
|
-
|
|
46
45
|
/**
|
|
47
46
|
* A simplified and properly typed version of lodash's `throttle`, that
|
|
48
47
|
* always uses timers instead of sometimes using rAF.
|
|
@@ -73,12 +72,10 @@ import { debounce } from '../debounce';
|
|
|
73
72
|
export const throttle = (func, wait, options) => {
|
|
74
73
|
let leading = true;
|
|
75
74
|
let trailing = true;
|
|
76
|
-
|
|
77
75
|
if (options) {
|
|
78
76
|
leading = 'leading' in options ? !!options.leading : leading;
|
|
79
77
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
80
78
|
}
|
|
81
|
-
|
|
82
79
|
return debounce(func, wait, {
|
|
83
80
|
leading,
|
|
84
81
|
trailing,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["debounce","throttle","func","wait","options","leading","trailing","maxWait"],"sources":["@wordpress/compose/src/utils/throttle/index.ts"],"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"],"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,QAAQ,QAAQ,aAAa;AAOtC;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,GAAGA,CACvBC,IAAe,EACfC,IAAY,EACZC,OAAyB,KACrB;EACJ,IAAIC,OAAO,GAAG,IAAI;EAClB,IAAIC,QAAQ,GAAG,IAAI;EAEnB,IAAKF,OAAO,EAAG;IACdC,OAAO,GAAG,SAAS,IAAID,OAAO,GAAG,CAAC,CAAEA,OAAO,CAACC,OAAO,GAAGA,OAAO;IAC7DC,QAAQ,GAAG,UAAU,IAAIF,OAAO,GAAG,CAAC,CAAEA,OAAO,CAACE,QAAQ,GAAGA,QAAQ;EAClE;EACA,OAAON,QAAQ,CAAEE,IAAI,EAAEC,IAAI,EAAE;IAC5BE,OAAO;IACPC,QAAQ;IACRC,OAAO,EAAEJ;EACV,CAAE,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { WithInjectedProps, WithoutInjectedProps } from '../../utils/create-higher-order-component';
|
|
4
|
+
import type { WithInjectedProps, WithoutInjectedProps } from '../../utils/create-higher-order-component';
|
|
5
5
|
type InstanceIdProps = {
|
|
6
6
|
instanceId: string | number;
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-instance-id/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-instance-id/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,2CAA2C,CAAC;AAInD,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEvD;;;GAGG;AACH,QAAA,MAAM,cAAc,iIAWnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { WithInjectedProps, WithoutInjectedProps } from '../../utils/create-higher-order-component';
|
|
4
|
+
import type { WithInjectedProps, WithoutInjectedProps } from '../../utils/create-higher-order-component';
|
|
5
5
|
/**
|
|
6
6
|
* We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
|
|
7
7
|
* types here because those functions include functionality that is not handled
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-safe-timeout/index.tsx"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-safe-timeout/index.tsx"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;GAOG;AACH,UAAU,YAAY;IACrB,UAAU,EAAE,CAAE,EAAE,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,KAAM,MAAM,CAAC;IACxD,YAAY,EAAE,CAAE,EAAE,EAAE,MAAM,KAAM,IAAI,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe;;kBAMR,MAAM,EAAE;;uBAaF,MAAM,IAAI,SAAS,MAAM;yBASvB,MAAM;;;;;;;;;;;;;;;;;;;;;;;CAoB1B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAE,EACpC,UAAU,EAAE,cAAsB,GAClC;;CAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAE,EACpC,UAAU,EAAE,cAAsB,GAClC;;CAAK,4CAmDL"}
|
|
@@ -5,5 +5,5 @@ export default useIsomorphicLayoutEffect;
|
|
|
5
5
|
* throws a warning when using useLayoutEffect in that environment.
|
|
6
6
|
*/
|
|
7
7
|
declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
8
|
-
import { useEffect } from
|
|
8
|
+
import { useEffect } from '@wordpress/element';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-isomorphic-layout-effect/index.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH,0DAC6D"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-isomorphic-layout-effect/index.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH,0DAC6D;0BARlB,oBAAoB"}
|
|
@@ -18,6 +18,6 @@ export type WPViewportOperator = ">=" | "<";
|
|
|
18
18
|
*/
|
|
19
19
|
declare function useViewportMatch(breakpoint: WPBreakpoint, operator?: WPViewportOperator | undefined): boolean;
|
|
20
20
|
declare namespace useViewportMatch {
|
|
21
|
-
|
|
21
|
+
let __experimentalWidthProvider: import("react").Provider<number | null>;
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.17.1",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
33
|
"@types/mousetrap": "^1.6.8",
|
|
34
|
-
"@wordpress/deprecated": "^3.
|
|
35
|
-
"@wordpress/dom": "^3.
|
|
36
|
-
"@wordpress/element": "^5.
|
|
37
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
38
|
-
"@wordpress/keycodes": "^3.
|
|
39
|
-
"@wordpress/priority-queue": "^2.
|
|
34
|
+
"@wordpress/deprecated": "^3.40.1",
|
|
35
|
+
"@wordpress/dom": "^3.40.1",
|
|
36
|
+
"@wordpress/element": "^5.17.1",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^4.40.1",
|
|
38
|
+
"@wordpress/keycodes": "^3.40.1",
|
|
39
|
+
"@wordpress/priority-queue": "^2.40.1",
|
|
40
40
|
"change-case": "^4.1.2",
|
|
41
41
|
"clipboard": "^2.0.8",
|
|
42
42
|
"mousetrap": "^1.6.5",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "bb1fbf87bb0f451744530fc6a85de2dff1263bed"
|
|
52
52
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
createHigherOrderComponent,
|
|
4
|
+
import type {
|
|
6
5
|
WithInjectedProps,
|
|
7
6
|
WithoutInjectedProps,
|
|
8
7
|
} from '../../utils/create-higher-order-component';
|
|
8
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
9
9
|
import useInstanceId from '../../hooks/use-instance-id';
|
|
10
10
|
|
|
11
11
|
type InstanceIdProps = { instanceId: string | number };
|
|
@@ -6,11 +6,11 @@ import { Component } from '@wordpress/element';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
createHigherOrderComponent,
|
|
9
|
+
import type {
|
|
11
10
|
WithInjectedProps,
|
|
12
11
|
WithoutInjectedProps,
|
|
13
12
|
} from '../../utils/create-higher-order-component';
|
|
13
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
|