@wordpress/compose 8.1.0 → 8.1.2-next.v.202606191442.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/CHANGELOG.md +20 -1
- package/README.md +46 -42
- package/build/higher-order/pure/index.cjs +15 -0
- package/build/higher-order/pure/index.cjs.map +3 -3
- package/build/hooks/use-constrained-tabbing/index.cjs +3 -9
- package/build/hooks/use-constrained-tabbing/index.cjs.map +3 -3
- package/build/hooks/use-debounce/index.cjs +1 -1
- package/build/hooks/use-debounce/index.cjs.map +3 -3
- package/build/hooks/use-disabled/index.cjs.map +2 -2
- package/build/hooks/use-dragging/index.cjs +27 -22
- package/build/hooks/use-dragging/index.cjs.map +4 -4
- package/build/hooks/use-dragging/types.cjs +19 -0
- package/build/hooks/use-dragging/types.cjs.map +7 -0
- package/build/hooks/use-drop-zone/index.cjs +2 -5
- package/build/hooks/use-drop-zone/index.cjs.map +3 -3
- package/build/hooks/use-drop-zone/types.cjs +19 -0
- package/build/hooks/use-drop-zone/types.cjs.map +7 -0
- package/build/hooks/use-fixed-window-list/index.cjs +10 -8
- package/build/hooks/use-fixed-window-list/index.cjs.map +3 -3
- package/build/hooks/use-focus-return/index.cjs +12 -9
- package/build/hooks/use-focus-return/index.cjs.map +3 -3
- package/build/hooks/use-isomorphic-layout-effect/index.cjs +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.cjs.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.cjs +1 -4
- package/build/hooks/use-keyboard-shortcut/index.cjs.map +3 -3
- package/build/hooks/use-media-query/index.cjs +2 -2
- package/build/hooks/use-media-query/index.cjs.map +2 -2
- package/build/hooks/use-merge-refs/index.cjs +28 -8
- package/build/hooks/use-merge-refs/index.cjs.map +2 -2
- package/build/hooks/use-reduced-motion/index.cjs +1 -1
- package/build/hooks/use-reduced-motion/index.cjs.map +2 -2
- package/build/hooks/use-throttle/index.cjs +1 -1
- package/build/hooks/use-throttle/index.cjs.map +3 -3
- package/build/hooks/use-viewport-match/index.cjs +3 -6
- package/build/hooks/use-viewport-match/index.cjs.map +3 -3
- package/build/hooks/use-warn-on-change/index.cjs +3 -10
- package/build/hooks/use-warn-on-change/index.cjs.map +3 -3
- package/build/utils/subscribe-delegated-listener/index.cjs.map +1 -1
- package/build-module/higher-order/pure/index.mjs +5 -0
- package/build-module/higher-order/pure/index.mjs.map +2 -2
- package/build-module/hooks/use-constrained-tabbing/index.mjs +3 -9
- package/build-module/hooks/use-constrained-tabbing/index.mjs.map +3 -3
- package/build-module/hooks/use-debounce/index.mjs +1 -1
- package/build-module/hooks/use-debounce/index.mjs.map +3 -3
- package/build-module/hooks/use-disabled/index.mjs.map +2 -2
- package/build-module/hooks/use-dragging/index.mjs +27 -22
- package/build-module/hooks/use-dragging/index.mjs.map +4 -4
- package/build-module/hooks/use-dragging/types.mjs +1 -0
- package/build-module/hooks/use-dragging/types.mjs.map +7 -0
- package/build-module/hooks/use-drop-zone/index.mjs +2 -5
- package/build-module/hooks/use-drop-zone/index.mjs.map +3 -3
- package/build-module/hooks/use-drop-zone/types.mjs +1 -0
- package/build-module/hooks/use-drop-zone/types.mjs.map +7 -0
- package/build-module/hooks/use-fixed-window-list/index.mjs +10 -8
- package/build-module/hooks/use-fixed-window-list/index.mjs.map +3 -3
- package/build-module/hooks/use-focus-return/index.mjs +12 -9
- package/build-module/hooks/use-focus-return/index.mjs.map +3 -3
- package/build-module/hooks/use-isomorphic-layout-effect/index.mjs +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.mjs.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.mjs +1 -4
- package/build-module/hooks/use-keyboard-shortcut/index.mjs.map +3 -3
- package/build-module/hooks/use-media-query/index.mjs +2 -2
- package/build-module/hooks/use-media-query/index.mjs.map +2 -2
- package/build-module/hooks/use-merge-refs/index.mjs +28 -8
- package/build-module/hooks/use-merge-refs/index.mjs.map +2 -2
- package/build-module/hooks/use-reduced-motion/index.mjs +1 -1
- package/build-module/hooks/use-reduced-motion/index.mjs.map +2 -2
- package/build-module/hooks/use-throttle/index.mjs +1 -1
- package/build-module/hooks/use-throttle/index.mjs.map +3 -3
- package/build-module/hooks/use-viewport-match/index.mjs +3 -6
- package/build-module/hooks/use-viewport-match/index.mjs.map +3 -3
- package/build-module/hooks/use-warn-on-change/index.mjs +3 -10
- package/build-module/hooks/use-warn-on-change/index.mjs.map +3 -3
- package/build-module/utils/subscribe-delegated-listener/index.mjs.map +1 -1
- package/build-types/higher-order/pure/index.d.ts.map +1 -1
- package/build-types/hooks/use-constrained-tabbing/index.d.ts +2 -2
- package/build-types/hooks/use-constrained-tabbing/index.d.ts.map +1 -1
- package/build-types/hooks/use-debounce/index.d.ts +7 -6
- package/build-types/hooks/use-debounce/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-dragging/index.d.ts +9 -13
- package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
- package/build-types/hooks/use-dragging/types.d.ts +11 -0
- package/build-types/hooks/use-dragging/types.d.ts.map +1 -0
- package/build-types/hooks/use-drop-zone/index.d.ts +4 -21
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/build-types/hooks/use-drop-zone/types.d.ts +35 -0
- package/build-types/hooks/use-drop-zone/types.d.ts.map +1 -0
- package/build-types/hooks/use-fixed-window-list/index.d.ts +22 -26
- package/build-types/hooks/use-fixed-window-list/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-return/index.d.ts +3 -3
- package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts +29 -23
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts.map +1 -1
- package/build-types/hooks/use-media-query/index.d.ts +1 -1
- package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
- package/build-types/hooks/use-merge-refs/index.d.ts +7 -5
- package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
- package/build-types/hooks/use-reduced-motion/index.d.ts +1 -1
- package/build-types/hooks/use-reduced-motion/index.d.ts.map +1 -1
- package/build-types/hooks/use-throttle/index.d.ts +8 -6
- package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts +3 -3
- package/build-types/hooks/use-viewport-match/index.d.ts.map +1 -1
- package/build-types/hooks/use-warn-on-change/index.d.ts +7 -7
- package/build-types/hooks/use-warn-on-change/index.d.ts.map +1 -1
- package/package.json +21 -12
- package/src/higher-order/pure/index.tsx +6 -0
- package/src/higher-order/pure/test/index.js +14 -81
- package/src/hooks/use-constrained-tabbing/{index.js → index.ts} +7 -11
- package/src/hooks/use-debounce/{index.js → index.ts} +11 -6
- package/src/hooks/use-disabled/index.ts +3 -1
- package/src/hooks/use-dragging/index.ts +78 -0
- package/src/hooks/use-dragging/types.ts +11 -0
- package/src/hooks/use-drop-zone/README.md +1 -1
- package/src/hooks/use-drop-zone/{index.js → index.ts} +17 -31
- package/src/hooks/use-drop-zone/types.ts +34 -0
- package/src/hooks/use-fixed-window-list/{index.js → index.ts} +46 -37
- package/src/hooks/use-focus-return/{index.js → index.ts} +26 -21
- package/src/hooks/use-keyboard-shortcut/{index.js → index.ts} +43 -28
- package/src/hooks/use-media-query/index.ts +10 -3
- package/src/hooks/use-media-query/test/ssr.js +47 -0
- package/src/hooks/use-merge-refs/index.ts +49 -18
- package/src/hooks/use-merge-refs/test/index.js +288 -0
- package/src/hooks/use-reduced-motion/{index.js → index.ts} +2 -2
- package/src/hooks/use-throttle/{index.js → index.ts} +12 -6
- package/src/hooks/use-viewport-match/{index.js → index.ts} +33 -26
- package/src/hooks/use-warn-on-change/index.ts +42 -0
- package/src/higher-order/with-network-connectivity/README.md +0 -20
- package/src/higher-order/with-network-connectivity/index.native.js +0 -19
- package/src/higher-order/with-preferred-color-scheme/index.native.js +0 -40
- package/src/hooks/use-constrained-tabbing/index.native.js +0 -14
- package/src/hooks/use-dragging/index.js +0 -74
- package/src/hooks/use-focus-outside/index.native.js +0 -170
- package/src/hooks/use-keyboard-shortcut/index.native.js +0 -2
- package/src/hooks/use-network-connectivity/index.native.js +0 -59
- package/src/hooks/use-network-connectivity/test/index.native.js +0 -87
- package/src/hooks/use-preferred-color-scheme/index.android.js +0 -30
- package/src/hooks/use-preferred-color-scheme/index.ios.js +0 -13
- package/src/hooks/use-preferred-color-scheme-style/index.native.js +0 -33
- package/src/hooks/use-resize-observer/index.native.js +0 -1
- package/src/hooks/use-resize-observer/legacy/index.native.js +0 -59
- package/src/hooks/use-resize-observer/legacy/test/index.native.js +0 -46
- package/src/hooks/use-warn-on-change/index.js +0 -43
- package/src/index.native.js +0 -44
- /package/src/hooks/use-isomorphic-layout-effect/{index.js → index.ts} +0 -0
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
interface FixedWindowList {
|
|
2
|
+
/** Items visible in the current viewport */
|
|
2
3
|
visibleItems: number;
|
|
4
|
+
/** Start index of the window */
|
|
3
5
|
start: number;
|
|
6
|
+
/** End index of the window */
|
|
4
7
|
end: number;
|
|
8
|
+
/** Returns true if item is in the window */
|
|
5
9
|
itemInView: (index: number) => boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
10
|
+
}
|
|
11
|
+
interface FixedWindowListOptions {
|
|
12
|
+
/** Renders windowOverscan number of items before and after the calculated visible window. */
|
|
8
13
|
windowOverscan?: number;
|
|
14
|
+
/** When false avoids calculating the window size */
|
|
9
15
|
useWindowing?: boolean;
|
|
16
|
+
/** Initial window size to use on first render before we can calculate the window size. */
|
|
10
17
|
initWindowSize?: number;
|
|
18
|
+
/** Used to recalculate the window size when the expanded state of a list changes. */
|
|
11
19
|
expandedState?: any;
|
|
12
|
-
}
|
|
20
|
+
}
|
|
13
21
|
/**
|
|
14
|
-
* @typedef {Object} WPFixedWindowList
|
|
15
22
|
*
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
23
|
+
* @param elementRef Used to find the closest scroll container that contains element.
|
|
24
|
+
* @param itemHeight Fixed item height in pixels
|
|
25
|
+
* @param totalItems Total items in list
|
|
26
|
+
* @param [options] Options object
|
|
27
|
+
* @return Array with the fixed window list and setter
|
|
20
28
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.
|
|
27
|
-
* @property {any} [expandedState] Used to recalculate the window size when the expanded state of a list changes.
|
|
28
|
-
*/
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {React.RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.
|
|
32
|
-
* @param { number } itemHeight Fixed item height in pixels
|
|
33
|
-
* @param { number } totalItems Total items in list
|
|
34
|
-
* @param { WPFixedWindowListOptions } [options] Options object
|
|
35
|
-
* @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter
|
|
36
|
-
*/
|
|
37
|
-
export default function useFixedWindowList(elementRef: React.RefObject<HTMLElement>, itemHeight: number, totalItems: number, options?: WPFixedWindowListOptions): [WPFixedWindowList, setFixedListWindow: (nextWindow: WPFixedWindowList) => void];
|
|
29
|
+
export default function useFixedWindowList(elementRef: React.RefObject<HTMLElement>, itemHeight: number, totalItems: number, options?: FixedWindowListOptions): [
|
|
30
|
+
FixedWindowList,
|
|
31
|
+
React.Dispatch<React.SetStateAction<FixedWindowList>>
|
|
32
|
+
];
|
|
33
|
+
export {};
|
|
38
34
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-fixed-window-list/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-fixed-window-list/index.ts"],"names":[],"mappings":"AAcA,UAAU,eAAe;IACxB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,UAAU,EAAE,CAAE,KAAK,EAAE,MAAM,KAAM,OAAO,CAAC;CACzC;AAED,UAAU,sBAAsB;IAC/B,6FAA6F;IAC7F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,aAAa,CAAC,EAAE,GAAG,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACzC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAE,WAAW,CAAE,EAC1C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,sBAAsB,GAC9B;IACF,eAAe;IACf,KAAK,CAAC,QAAQ,CAAE,KAAK,CAAC,cAAc,CAAE,eAAe,CAAE,CAAE;CACzD,CAqJA"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Adds the unmount behavior of returning focus to the element which had it
|
|
3
3
|
* previously as is expected for roles like menus or dialogs.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @return
|
|
5
|
+
* @param onFocusReturn Overrides the default return behavior.
|
|
6
|
+
* @return Element Ref.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* ```
|
|
9
|
+
* ```ts
|
|
10
10
|
* import { useFocusReturn } from '@wordpress/compose';
|
|
11
11
|
*
|
|
12
12
|
* const WithFocusReturn = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-return/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-return/index.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,cAAc,CACtB,aAAa,CAAC,EAAE,MAAM,IAAI,GACxB,KAAK,CAAC,WAAW,CAAE,WAAW,CAAE,CAyDlC;eAEc,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-isomorphic-layout-effect/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-isomorphic-layout-effect/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAa,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;GAIG;AACH,QAAA,MAAM,yBAAyB,wBAC6B,CAAC;eAE9C,yBAAyB"}
|
|
@@ -1,34 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import Mousetrap from 'mousetrap';
|
|
5
1
|
import 'mousetrap/plugins/global-bind/mousetrap-global-bind.js';
|
|
6
|
-
|
|
7
|
-
bindGlobal?: boolean;
|
|
8
|
-
eventName?: string;
|
|
9
|
-
isDisabled?: boolean;
|
|
10
|
-
target?: React.RefObject<HTMLElement | null>;
|
|
11
|
-
};
|
|
2
|
+
import type { ExtendedKeyboardEvent } from 'mousetrap';
|
|
12
3
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @typedef {Object} WPKeyboardShortcutConfig
|
|
16
|
-
*
|
|
17
|
-
* @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
|
|
18
|
-
* @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
|
|
19
|
-
* @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
|
|
20
|
-
* @property {React.RefObject<HTMLElement | null>} [target] React reference to the DOM element used to catch the keyboard event.
|
|
4
|
+
* WordPress dependencies
|
|
21
5
|
*/
|
|
6
|
+
import type { RefObject } from '@wordpress/element';
|
|
7
|
+
type KeyboardShortcutConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* Handle keyboard events anywhere including inside textarea/input fields.
|
|
10
|
+
*/
|
|
11
|
+
bindGlobal: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Event name used to trigger the handler, defaults to keydown.
|
|
14
|
+
*/
|
|
15
|
+
eventName: string;
|
|
16
|
+
/**
|
|
17
|
+
* Disables the keyboard handler if the value is true.
|
|
18
|
+
*/
|
|
19
|
+
isDisabled: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* React reference to the DOM element used to catch the keyboard event.
|
|
22
|
+
*/
|
|
23
|
+
target: RefObject<HTMLElement>;
|
|
24
|
+
};
|
|
22
25
|
/**
|
|
23
26
|
* Attach a keyboard shortcut handler.
|
|
24
27
|
*
|
|
25
28
|
* @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
|
|
26
29
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
+
* @param shortcuts Keyboard Shortcuts.
|
|
31
|
+
* @param callback Shortcut callback.
|
|
32
|
+
* @param options Shortcut options.
|
|
33
|
+
* @param options.bindGlobal
|
|
34
|
+
* @param options.eventName
|
|
35
|
+
* @param options.isDisabled
|
|
36
|
+
* @param options.target
|
|
30
37
|
*/
|
|
31
|
-
declare function useKeyboardShortcut(shortcuts: string[] | string, callback: (e:
|
|
32
|
-
target }?: WPKeyboardShortcutConfig): void;
|
|
38
|
+
declare function useKeyboardShortcut(shortcuts: string[] | string, callback: (e: ExtendedKeyboardEvent, combo: string) => void, { bindGlobal, eventName, isDisabled, target }?: Partial<KeyboardShortcutConfig>): void;
|
|
33
39
|
export default useKeyboardShortcut;
|
|
34
40
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-keyboard-shortcut/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-keyboard-shortcut/index.ts"],"names":[],"mappings":"AAIA,OAAO,wDAAwD,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD,KAAK,sBAAsB,GAAG;IAC7B;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,SAAS,CAAE,WAAW,CAAE,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,iBAAS,mBAAmB,CAC3B,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAC5B,QAAQ,EAAE,CAAE,CAAC,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,KAAM,IAAI,EAC7D,EACC,UAAkB,EAClB,SAAqB,EACrB,UAAkB,EAClB,MAAM,EACN,GAAE,OAAO,CAAE,sBAAsB,CAAO,QA4DzC;eAEc,mBAAmB"}
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* @param [view] Window instance, else default to global window
|
|
6
6
|
* @return return value of the media query.
|
|
7
7
|
*/
|
|
8
|
-
export default function useMediaQuery(query?: string, view?: Window): boolean;
|
|
8
|
+
export default function useMediaQuery(query?: string, view?: Window | undefined): boolean;
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-media-query/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-media-query/index.ts"],"names":[],"mappings":"AAuEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACpC,KAAK,CAAC,EAAE,MAAM,EAGd,IAAI,GAAE,MAAM,GAAG,SAEH,GACV,OAAO,CAQT"}
|
|
@@ -15,22 +15,24 @@ import type { Ref, RefCallback } from 'react';
|
|
|
15
15
|
* old ref callback will be called with `null` and the new ref callback will be
|
|
16
16
|
* called with the same value.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Inner ref callbacks may return a cleanup function (React 19's ref callback
|
|
19
|
+
* cleanup pattern). When a ref callback returns a function, that function is
|
|
20
|
+
* invoked at teardown (node change, dependency change, or unmount) **instead
|
|
21
|
+
* of** the callback being called with `null`. Callbacks that do not return a
|
|
22
|
+
* cleanup continue to receive `null` on teardown as before.
|
|
21
23
|
*
|
|
22
24
|
* It's also possible to _disable_ a ref (and its behaviour) by simply not
|
|
23
25
|
* passing the ref.
|
|
24
26
|
*
|
|
25
27
|
* ```jsx
|
|
26
|
-
* const ref =
|
|
28
|
+
* const ref = useCallback( ( node ) => {
|
|
27
29
|
* node.addEventListener( ... );
|
|
28
30
|
* return () => {
|
|
29
31
|
* node.removeEventListener( ... );
|
|
30
32
|
* };
|
|
31
33
|
* }, [ ...dependencies ] );
|
|
32
34
|
* const otherRef = useRef();
|
|
33
|
-
* const mergedRefs useMergeRefs( [
|
|
35
|
+
* const mergedRefs = useMergeRefs( [
|
|
34
36
|
* enabled && ref,
|
|
35
37
|
* otherRef,
|
|
36
38
|
* ] );
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-merge-refs/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,GAAG,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-merge-refs/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,GAAG,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AA+BhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,CAAC,EACtC,IAAI,EAAE,GAAG,CAAE,CAAC,CAAE,EAAE,GACd,WAAW,CAAE,CAAC,CAAE,CAkElB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook returning whether the user has a preference for reduced motion.
|
|
3
3
|
*
|
|
4
|
-
* @return
|
|
4
|
+
* @return Reduced motion preference value.
|
|
5
5
|
*/
|
|
6
6
|
declare const useReducedMotion: () => boolean;
|
|
7
7
|
export default useReducedMotion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-reduced-motion/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-reduced-motion/index.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,QAAO,OACuB,CAAC;eAEtC,gBAAgB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ThrottleOptions } from '../../utils/throttle';
|
|
2
|
+
import type { DebouncedFunc } from '../../utils/debounce';
|
|
1
3
|
/**
|
|
2
4
|
* Throttles a function similar to Lodash's `throttle`. A new throttled function will
|
|
3
5
|
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
@@ -6,12 +8,12 @@
|
|
|
6
8
|
*
|
|
7
9
|
* @see https://lodash.com/docs/4#throttle
|
|
8
10
|
*
|
|
9
|
-
* @template
|
|
11
|
+
* @template TFunc
|
|
10
12
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @return
|
|
13
|
+
* @param fn The function to throttle.
|
|
14
|
+
* @param wait The number of milliseconds to throttle invocations to.
|
|
15
|
+
* @param options The options object.
|
|
16
|
+
* @return Throttled function.
|
|
15
17
|
*/
|
|
16
|
-
export default function useThrottle<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number, options?:
|
|
18
|
+
export default function useThrottle<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number, options?: ThrottleOptions): DebouncedFunc<TFunc>;
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAE,KAAK,SAAS,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAM,IAAI,EAC5E,EAAE,EAAE,KAAK,EACT,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GACvB,aAAa,CAAE,KAAK,CAAE,CAOxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare function useViewportMatch(breakpoint:
|
|
1
|
+
type Breakpoint = 'xhuge' | 'huge' | 'wide' | 'xlarge' | 'large' | 'medium' | 'small' | 'mobile';
|
|
2
|
+
type ViewportOperator = '>=' | '<';
|
|
3
|
+
declare function useViewportMatch(breakpoint: Breakpoint, operator?: ViewportOperator, view?: Window | undefined): boolean;
|
|
4
4
|
declare namespace useViewportMatch {
|
|
5
5
|
var __experimentalWidthProvider: import("react").Provider<number | null>;
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-viewport-match/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-viewport-match/index.ts"],"names":[],"mappings":"AAUA,KAAK,UAAU,GACZ,OAAO,GACP,MAAM,GACN,MAAM,GACN,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,OAAO,GACP,QAAQ,CAAC;AACZ,KAAK,gBAAgB,GAAG,IAAI,GAAG,GAAG,CAAC;kCAyDlC,UAAU,EAAE,UAAU,EACtB,QAAQ,GAAE,gBAAuB,EAGjC,IAAI,GAAE,MAAM,GAAG,SAEH,GACV,OAAO;;;;eAmBK,gBAAgB"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hook that performs a shallow comparison between the
|
|
2
|
+
* Hook that performs a shallow comparison between the previous value of an object
|
|
3
3
|
* and the new one, if there's a difference, it prints it to the console.
|
|
4
|
-
*
|
|
4
|
+
* This is useful in performance related work, to check why a component re-renders.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
|
-
* ```
|
|
9
|
-
* function MyComponent(props) {
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function MyComponent(props: Record<string, any>) {
|
|
10
10
|
* useWarnOnChange(props);
|
|
11
11
|
*
|
|
12
12
|
* return "Something";
|
|
13
13
|
* }
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
16
|
+
* @param object Object which changes to compare.
|
|
17
|
+
* @param prefix Just a prefix to show when console logging.
|
|
18
18
|
*/
|
|
19
|
-
declare function useWarnOnChange(object:
|
|
19
|
+
declare function useWarnOnChange(object: Record<string, any> | any[], prefix?: string): void;
|
|
20
20
|
export default useWarnOnChange;
|
|
21
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-warn-on-change/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-warn-on-change/index.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,eAAe,CACvB,MAAM,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,GAAG,GAAG,EAAE,EACrC,MAAM,GAAE,MAA2B,GACjC,IAAI,CAaN;eAEc,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "8.1.0",
|
|
3
|
+
"version": "8.1.2-next.v.202606191442.0+17fe7db8a",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -41,32 +41,41 @@
|
|
|
41
41
|
},
|
|
42
42
|
"./package.json": "./package.json"
|
|
43
43
|
},
|
|
44
|
-
"react-native": "src/index",
|
|
45
44
|
"wpScript": true,
|
|
46
45
|
"types": "build-types",
|
|
47
46
|
"sideEffects": false,
|
|
48
47
|
"dependencies": {
|
|
49
48
|
"@types/mousetrap": "^1.6.8",
|
|
50
|
-
"@wordpress/deprecated": "^4.48.0",
|
|
51
|
-
"@wordpress/dom": "^4.48.0",
|
|
52
|
-
"@wordpress/element": "^8.0.0",
|
|
53
|
-
"@wordpress/is-shallow-equal": "^5.48.0",
|
|
54
|
-
"@wordpress/keycodes": "^4.48.0",
|
|
55
|
-
"@wordpress/priority-queue": "^3.48.0",
|
|
56
|
-
"@wordpress/private-apis": "^1.48.0",
|
|
57
|
-
"@wordpress/undo-manager": "^1.48.0",
|
|
49
|
+
"@wordpress/deprecated": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
50
|
+
"@wordpress/dom": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
51
|
+
"@wordpress/element": "^8.0.2-next.v.202606191442.0+17fe7db8a",
|
|
52
|
+
"@wordpress/is-shallow-equal": "^5.48.2-next.v.202606191442.0+17fe7db8a",
|
|
53
|
+
"@wordpress/keycodes": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
54
|
+
"@wordpress/priority-queue": "^3.48.2-next.v.202606191442.0+17fe7db8a",
|
|
55
|
+
"@wordpress/private-apis": "^1.48.2-next.v.202606191442.0+17fe7db8a",
|
|
56
|
+
"@wordpress/undo-manager": "^1.48.2-next.v.202606191442.0+17fe7db8a",
|
|
58
57
|
"change-case": "^4.1.2",
|
|
59
58
|
"mousetrap": "^1.6.5",
|
|
60
59
|
"use-memo-one": "^1.1.1"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
|
-
"
|
|
62
|
+
"@testing-library/dom": "^10.4.1",
|
|
63
|
+
"@testing-library/react": "^16.3.2",
|
|
64
|
+
"@testing-library/user-event": "^14.6.1",
|
|
65
|
+
"mock-match-media": "^0.4.2",
|
|
66
|
+
"react-dom": "^18.3.1"
|
|
64
67
|
},
|
|
65
68
|
"peerDependencies": {
|
|
69
|
+
"@types/react": "^18.3.27",
|
|
66
70
|
"react": "^18.0.0"
|
|
67
71
|
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"@types/react": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
68
77
|
"publishConfig": {
|
|
69
78
|
"access": "public"
|
|
70
79
|
},
|
|
71
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "1b6a19222df5a88f161880b5789efb3171d8f425"
|
|
72
81
|
}
|
|
@@ -8,6 +8,7 @@ import type { ComponentType, ComponentClass } from 'react';
|
|
|
8
8
|
*/
|
|
9
9
|
import { isShallowEqual } from '@wordpress/is-shallow-equal';
|
|
10
10
|
import { Component } from '@wordpress/element';
|
|
11
|
+
import deprecated from '@wordpress/deprecated';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
@@ -23,6 +24,11 @@ import { createHigherOrderComponent } from '../../utils/create-higher-order-comp
|
|
|
23
24
|
const pure = createHigherOrderComponent( function < Props extends {} >(
|
|
24
25
|
WrappedComponent: ComponentType< Props >
|
|
25
26
|
): ComponentType< Props > {
|
|
27
|
+
deprecated( 'wp.compose.pure', {
|
|
28
|
+
since: '7.1',
|
|
29
|
+
alternative: 'Use `memo` or `PureComponent` instead',
|
|
30
|
+
} );
|
|
31
|
+
|
|
26
32
|
if ( WrappedComponent.prototype instanceof Component ) {
|
|
27
33
|
return class extends ( WrappedComponent as ComponentClass< Props > ) {
|
|
28
34
|
shouldComponentUpdate( nextProps: Props, nextState: any ) {
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { render, screen } from '@testing-library/react';
|
|
5
|
-
import userEvent from '@testing-library/user-event';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* WordPress dependencies
|
|
9
8
|
*/
|
|
10
|
-
import {
|
|
9
|
+
import { logged } from '@wordpress/deprecated';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Internal dependencies
|
|
@@ -15,88 +14,22 @@ import { Component } from '@wordpress/element';
|
|
|
15
14
|
import pure from '../';
|
|
16
15
|
|
|
17
16
|
describe( 'pure', () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} );
|
|
23
|
-
const { rerender } = render( <MyComp /> );
|
|
24
|
-
|
|
25
|
-
// Updating with same props doesn't rerender.
|
|
26
|
-
rerender( <MyComp /> );
|
|
27
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '1' );
|
|
28
|
-
|
|
29
|
-
// New prop should trigger a rerender.
|
|
30
|
-
rerender( <MyComp { ...{ prop: 'a' } } /> );
|
|
31
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
|
|
32
|
-
|
|
33
|
-
// Keeping the same prop value should not rerender.
|
|
34
|
-
rerender( <MyComp { ...{ prop: 'a' } } /> );
|
|
35
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
|
|
36
|
-
|
|
37
|
-
// Changing the prop value should rerender.
|
|
38
|
-
rerender( <MyComp { ...{ prop: 'b' } } /> );
|
|
39
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '3' );
|
|
17
|
+
afterEach( () => {
|
|
18
|
+
for ( const key in logged ) {
|
|
19
|
+
delete logged[ key ];
|
|
20
|
+
}
|
|
40
21
|
} );
|
|
41
22
|
|
|
42
|
-
it( '
|
|
43
|
-
const
|
|
44
|
-
let i = 0;
|
|
45
|
-
const MyComp = pure(
|
|
46
|
-
class extends Component {
|
|
47
|
-
constructor() {
|
|
48
|
-
super( ...arguments );
|
|
49
|
-
this.state = {
|
|
50
|
-
val: '',
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
render() {
|
|
54
|
-
return (
|
|
55
|
-
<>
|
|
56
|
-
<p data-testid="counter">{ ++i }</p>
|
|
57
|
-
<input
|
|
58
|
-
type="text"
|
|
59
|
-
value={ this.state.val }
|
|
60
|
-
onChange={ ( e ) =>
|
|
61
|
-
this.setState( { val: e.target.value } )
|
|
62
|
-
}
|
|
63
|
-
/>
|
|
64
|
-
<input
|
|
65
|
-
type="button"
|
|
66
|
-
onClick={ () =>
|
|
67
|
-
this.setState( { val: this.state.val } )
|
|
68
|
-
}
|
|
69
|
-
/>
|
|
70
|
-
</>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const { rerender } = render( <MyComp /> );
|
|
23
|
+
it( 'wraps a component and logs a deprecation warning', () => {
|
|
24
|
+
const MyComp = pure( () => <p data-testid="content">content</p> );
|
|
77
25
|
|
|
78
|
-
|
|
79
|
-
rerender( <MyComp /> );
|
|
80
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '1' );
|
|
26
|
+
render( <MyComp /> );
|
|
81
27
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
|
|
89
|
-
|
|
90
|
-
// Changing the prop value should rerender.
|
|
91
|
-
rerender( <MyComp { ...{ prop: 'b' } } /> );
|
|
92
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '3' );
|
|
93
|
-
|
|
94
|
-
// New state value should trigger a rerender.
|
|
95
|
-
await user.type( screen.getByRole( 'textbox' ), 'a' );
|
|
96
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '4' );
|
|
97
|
-
|
|
98
|
-
// Keeping the same state value should not trigger a rerender.
|
|
99
|
-
await user.click( screen.getByRole( 'button' ) );
|
|
100
|
-
expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '4' );
|
|
28
|
+
expect( console ).toHaveWarnedWith(
|
|
29
|
+
'wp.compose.pure is deprecated since version 7.1. Please use Use `memo` or `PureComponent` instead instead.'
|
|
30
|
+
);
|
|
31
|
+
expect( screen.getByTestId( 'content' ) ).toHaveTextContent(
|
|
32
|
+
'content'
|
|
33
|
+
);
|
|
101
34
|
} );
|
|
102
35
|
} );
|
|
@@ -12,10 +12,10 @@ import useRefEffect from '../use-ref-effect';
|
|
|
12
12
|
* In Dialogs/modals, the tabbing must be constrained to the content of
|
|
13
13
|
* the wrapper element. This hook adds the behavior to the returned ref.
|
|
14
14
|
*
|
|
15
|
-
* @return
|
|
15
|
+
* @return Element Ref.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
-
* ```
|
|
18
|
+
* ```ts
|
|
19
19
|
* import { useConstrainedTabbing } from '@wordpress/compose';
|
|
20
20
|
*
|
|
21
21
|
* const ConstrainedTabbingExample = () => {
|
|
@@ -29,9 +29,9 @@ import useRefEffect from '../use-ref-effect';
|
|
|
29
29
|
* }
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
function useConstrainedTabbing() {
|
|
33
|
-
return useRefEffect( (
|
|
34
|
-
function onKeyDown(
|
|
32
|
+
function useConstrainedTabbing(): React.RefCallback< Element > {
|
|
33
|
+
return useRefEffect( ( node: HTMLElement ) => {
|
|
34
|
+
function onKeyDown( event: KeyboardEvent ): void {
|
|
35
35
|
const { key, shiftKey, target } = event;
|
|
36
36
|
|
|
37
37
|
if ( key !== 'Tab' ) {
|
|
@@ -40,9 +40,7 @@ function useConstrainedTabbing() {
|
|
|
40
40
|
|
|
41
41
|
const action = shiftKey ? 'findPrevious' : 'findNext';
|
|
42
42
|
const nextElement =
|
|
43
|
-
focus.tabbable[ action ](
|
|
44
|
-
/** @type {HTMLElement} */ ( target )
|
|
45
|
-
) || null;
|
|
43
|
+
focus.tabbable[ action ]( target as HTMLElement ) || null;
|
|
46
44
|
|
|
47
45
|
// When the target element contains the element that is about to
|
|
48
46
|
// receive focus, for example when the target is a tabbable
|
|
@@ -50,9 +48,7 @@ function useConstrainedTabbing() {
|
|
|
50
48
|
// In this case we can't rely on native browsers behavior. We need
|
|
51
49
|
// to manage focus instead.
|
|
52
50
|
// See https://github.com/WordPress/gutenberg/issues/46041.
|
|
53
|
-
if (
|
|
54
|
-
/** @type {HTMLElement} */ ( target ).contains( nextElement )
|
|
55
|
-
) {
|
|
51
|
+
if ( ( target as HTMLElement ).contains( nextElement ) ) {
|
|
56
52
|
event.preventDefault();
|
|
57
53
|
nextElement?.focus();
|
|
58
54
|
return;
|
|
@@ -12,6 +12,7 @@ import { useEffect } from '@wordpress/element';
|
|
|
12
12
|
* Internal dependencies
|
|
13
13
|
*/
|
|
14
14
|
import { debounce } from '../../utils/debounce';
|
|
15
|
+
import type { DebounceOptions, DebouncedFunc } from '../../utils/debounce';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Debounces a function similar to Lodash's `debounce`. A new debounced function will
|
|
@@ -21,14 +22,18 @@ import { debounce } from '../../utils/debounce';
|
|
|
21
22
|
*
|
|
22
23
|
* @see https://lodash.com/docs/4#debounce
|
|
23
24
|
*
|
|
24
|
-
* @template
|
|
25
|
+
* @template TFunc
|
|
25
26
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @return
|
|
27
|
+
* @param fn The function to debounce.
|
|
28
|
+
* @param wait The number of milliseconds to delay.
|
|
29
|
+
* @param options The options object.
|
|
30
|
+
* @return Debounced function.
|
|
30
31
|
*/
|
|
31
|
-
export default function useDebounce(
|
|
32
|
+
export default function useDebounce< TFunc extends ( ...args: any[] ) => void >(
|
|
33
|
+
fn: TFunc,
|
|
34
|
+
wait?: number,
|
|
35
|
+
options?: DebounceOptions
|
|
36
|
+
): DebouncedFunc< TFunc > {
|
|
32
37
|
const debounced = useMemoOne(
|
|
33
38
|
() => debounce( fn, wait ?? 0, options ),
|
|
34
39
|
[ fn, wait, options?.leading, options?.trailing, options?.maxWait ]
|
|
@@ -32,6 +32,8 @@ import useRefEffect from '../use-ref-effect';
|
|
|
32
32
|
*/
|
|
33
33
|
export default function useDisabled( {
|
|
34
34
|
isDisabled: isDisabledProp = false,
|
|
35
|
+
}: {
|
|
36
|
+
isDisabled?: boolean;
|
|
35
37
|
} = {} ) {
|
|
36
38
|
return useRefEffect(
|
|
37
39
|
( node ) => {
|
|
@@ -45,7 +47,7 @@ export default function useDisabled( {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** A variable keeping track of the previous updates in order to restore them. */
|
|
48
|
-
const updates:
|
|
50
|
+
const updates: ( () => void )[] = [];
|
|
49
51
|
const disable = () => {
|
|
50
52
|
node.childNodes.forEach( ( child ) => {
|
|
51
53
|
if ( ! ( child instanceof defaultView.HTMLElement ) ) {
|