@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.
Files changed (148) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/README.md +46 -42
  3. package/build/higher-order/pure/index.cjs +15 -0
  4. package/build/higher-order/pure/index.cjs.map +3 -3
  5. package/build/hooks/use-constrained-tabbing/index.cjs +3 -9
  6. package/build/hooks/use-constrained-tabbing/index.cjs.map +3 -3
  7. package/build/hooks/use-debounce/index.cjs +1 -1
  8. package/build/hooks/use-debounce/index.cjs.map +3 -3
  9. package/build/hooks/use-disabled/index.cjs.map +2 -2
  10. package/build/hooks/use-dragging/index.cjs +27 -22
  11. package/build/hooks/use-dragging/index.cjs.map +4 -4
  12. package/build/hooks/use-dragging/types.cjs +19 -0
  13. package/build/hooks/use-dragging/types.cjs.map +7 -0
  14. package/build/hooks/use-drop-zone/index.cjs +2 -5
  15. package/build/hooks/use-drop-zone/index.cjs.map +3 -3
  16. package/build/hooks/use-drop-zone/types.cjs +19 -0
  17. package/build/hooks/use-drop-zone/types.cjs.map +7 -0
  18. package/build/hooks/use-fixed-window-list/index.cjs +10 -8
  19. package/build/hooks/use-fixed-window-list/index.cjs.map +3 -3
  20. package/build/hooks/use-focus-return/index.cjs +12 -9
  21. package/build/hooks/use-focus-return/index.cjs.map +3 -3
  22. package/build/hooks/use-isomorphic-layout-effect/index.cjs +1 -1
  23. package/build/hooks/use-isomorphic-layout-effect/index.cjs.map +1 -1
  24. package/build/hooks/use-keyboard-shortcut/index.cjs +1 -4
  25. package/build/hooks/use-keyboard-shortcut/index.cjs.map +3 -3
  26. package/build/hooks/use-media-query/index.cjs +2 -2
  27. package/build/hooks/use-media-query/index.cjs.map +2 -2
  28. package/build/hooks/use-merge-refs/index.cjs +28 -8
  29. package/build/hooks/use-merge-refs/index.cjs.map +2 -2
  30. package/build/hooks/use-reduced-motion/index.cjs +1 -1
  31. package/build/hooks/use-reduced-motion/index.cjs.map +2 -2
  32. package/build/hooks/use-throttle/index.cjs +1 -1
  33. package/build/hooks/use-throttle/index.cjs.map +3 -3
  34. package/build/hooks/use-viewport-match/index.cjs +3 -6
  35. package/build/hooks/use-viewport-match/index.cjs.map +3 -3
  36. package/build/hooks/use-warn-on-change/index.cjs +3 -10
  37. package/build/hooks/use-warn-on-change/index.cjs.map +3 -3
  38. package/build/utils/subscribe-delegated-listener/index.cjs.map +1 -1
  39. package/build-module/higher-order/pure/index.mjs +5 -0
  40. package/build-module/higher-order/pure/index.mjs.map +2 -2
  41. package/build-module/hooks/use-constrained-tabbing/index.mjs +3 -9
  42. package/build-module/hooks/use-constrained-tabbing/index.mjs.map +3 -3
  43. package/build-module/hooks/use-debounce/index.mjs +1 -1
  44. package/build-module/hooks/use-debounce/index.mjs.map +3 -3
  45. package/build-module/hooks/use-disabled/index.mjs.map +2 -2
  46. package/build-module/hooks/use-dragging/index.mjs +27 -22
  47. package/build-module/hooks/use-dragging/index.mjs.map +4 -4
  48. package/build-module/hooks/use-dragging/types.mjs +1 -0
  49. package/build-module/hooks/use-dragging/types.mjs.map +7 -0
  50. package/build-module/hooks/use-drop-zone/index.mjs +2 -5
  51. package/build-module/hooks/use-drop-zone/index.mjs.map +3 -3
  52. package/build-module/hooks/use-drop-zone/types.mjs +1 -0
  53. package/build-module/hooks/use-drop-zone/types.mjs.map +7 -0
  54. package/build-module/hooks/use-fixed-window-list/index.mjs +10 -8
  55. package/build-module/hooks/use-fixed-window-list/index.mjs.map +3 -3
  56. package/build-module/hooks/use-focus-return/index.mjs +12 -9
  57. package/build-module/hooks/use-focus-return/index.mjs.map +3 -3
  58. package/build-module/hooks/use-isomorphic-layout-effect/index.mjs +1 -1
  59. package/build-module/hooks/use-isomorphic-layout-effect/index.mjs.map +1 -1
  60. package/build-module/hooks/use-keyboard-shortcut/index.mjs +1 -4
  61. package/build-module/hooks/use-keyboard-shortcut/index.mjs.map +3 -3
  62. package/build-module/hooks/use-media-query/index.mjs +2 -2
  63. package/build-module/hooks/use-media-query/index.mjs.map +2 -2
  64. package/build-module/hooks/use-merge-refs/index.mjs +28 -8
  65. package/build-module/hooks/use-merge-refs/index.mjs.map +2 -2
  66. package/build-module/hooks/use-reduced-motion/index.mjs +1 -1
  67. package/build-module/hooks/use-reduced-motion/index.mjs.map +2 -2
  68. package/build-module/hooks/use-throttle/index.mjs +1 -1
  69. package/build-module/hooks/use-throttle/index.mjs.map +3 -3
  70. package/build-module/hooks/use-viewport-match/index.mjs +3 -6
  71. package/build-module/hooks/use-viewport-match/index.mjs.map +3 -3
  72. package/build-module/hooks/use-warn-on-change/index.mjs +3 -10
  73. package/build-module/hooks/use-warn-on-change/index.mjs.map +3 -3
  74. package/build-module/utils/subscribe-delegated-listener/index.mjs.map +1 -1
  75. package/build-types/higher-order/pure/index.d.ts.map +1 -1
  76. package/build-types/hooks/use-constrained-tabbing/index.d.ts +2 -2
  77. package/build-types/hooks/use-constrained-tabbing/index.d.ts.map +1 -1
  78. package/build-types/hooks/use-debounce/index.d.ts +7 -6
  79. package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
  80. package/build-types/hooks/use-disabled/index.d.ts +1 -1
  81. package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
  82. package/build-types/hooks/use-dragging/index.d.ts +9 -13
  83. package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
  84. package/build-types/hooks/use-dragging/types.d.ts +11 -0
  85. package/build-types/hooks/use-dragging/types.d.ts.map +1 -0
  86. package/build-types/hooks/use-drop-zone/index.d.ts +4 -21
  87. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  88. package/build-types/hooks/use-drop-zone/types.d.ts +35 -0
  89. package/build-types/hooks/use-drop-zone/types.d.ts.map +1 -0
  90. package/build-types/hooks/use-fixed-window-list/index.d.ts +22 -26
  91. package/build-types/hooks/use-fixed-window-list/index.d.ts.map +1 -1
  92. package/build-types/hooks/use-focus-return/index.d.ts +3 -3
  93. package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
  94. package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
  95. package/build-types/hooks/use-keyboard-shortcut/index.d.ts +29 -23
  96. package/build-types/hooks/use-keyboard-shortcut/index.d.ts.map +1 -1
  97. package/build-types/hooks/use-media-query/index.d.ts +1 -1
  98. package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
  99. package/build-types/hooks/use-merge-refs/index.d.ts +7 -5
  100. package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
  101. package/build-types/hooks/use-reduced-motion/index.d.ts +1 -1
  102. package/build-types/hooks/use-reduced-motion/index.d.ts.map +1 -1
  103. package/build-types/hooks/use-throttle/index.d.ts +8 -6
  104. package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
  105. package/build-types/hooks/use-viewport-match/index.d.ts +3 -3
  106. package/build-types/hooks/use-viewport-match/index.d.ts.map +1 -1
  107. package/build-types/hooks/use-warn-on-change/index.d.ts +7 -7
  108. package/build-types/hooks/use-warn-on-change/index.d.ts.map +1 -1
  109. package/package.json +21 -12
  110. package/src/higher-order/pure/index.tsx +6 -0
  111. package/src/higher-order/pure/test/index.js +14 -81
  112. package/src/hooks/use-constrained-tabbing/{index.js → index.ts} +7 -11
  113. package/src/hooks/use-debounce/{index.js → index.ts} +11 -6
  114. package/src/hooks/use-disabled/index.ts +3 -1
  115. package/src/hooks/use-dragging/index.ts +78 -0
  116. package/src/hooks/use-dragging/types.ts +11 -0
  117. package/src/hooks/use-drop-zone/README.md +1 -1
  118. package/src/hooks/use-drop-zone/{index.js → index.ts} +17 -31
  119. package/src/hooks/use-drop-zone/types.ts +34 -0
  120. package/src/hooks/use-fixed-window-list/{index.js → index.ts} +46 -37
  121. package/src/hooks/use-focus-return/{index.js → index.ts} +26 -21
  122. package/src/hooks/use-keyboard-shortcut/{index.js → index.ts} +43 -28
  123. package/src/hooks/use-media-query/index.ts +10 -3
  124. package/src/hooks/use-media-query/test/ssr.js +47 -0
  125. package/src/hooks/use-merge-refs/index.ts +49 -18
  126. package/src/hooks/use-merge-refs/test/index.js +288 -0
  127. package/src/hooks/use-reduced-motion/{index.js → index.ts} +2 -2
  128. package/src/hooks/use-throttle/{index.js → index.ts} +12 -6
  129. package/src/hooks/use-viewport-match/{index.js → index.ts} +33 -26
  130. package/src/hooks/use-warn-on-change/index.ts +42 -0
  131. package/src/higher-order/with-network-connectivity/README.md +0 -20
  132. package/src/higher-order/with-network-connectivity/index.native.js +0 -19
  133. package/src/higher-order/with-preferred-color-scheme/index.native.js +0 -40
  134. package/src/hooks/use-constrained-tabbing/index.native.js +0 -14
  135. package/src/hooks/use-dragging/index.js +0 -74
  136. package/src/hooks/use-focus-outside/index.native.js +0 -170
  137. package/src/hooks/use-keyboard-shortcut/index.native.js +0 -2
  138. package/src/hooks/use-network-connectivity/index.native.js +0 -59
  139. package/src/hooks/use-network-connectivity/test/index.native.js +0 -87
  140. package/src/hooks/use-preferred-color-scheme/index.android.js +0 -30
  141. package/src/hooks/use-preferred-color-scheme/index.ios.js +0 -13
  142. package/src/hooks/use-preferred-color-scheme-style/index.native.js +0 -33
  143. package/src/hooks/use-resize-observer/index.native.js +0 -1
  144. package/src/hooks/use-resize-observer/legacy/index.native.js +0 -59
  145. package/src/hooks/use-resize-observer/legacy/test/index.native.js +0 -46
  146. package/src/hooks/use-warn-on-change/index.js +0 -43
  147. package/src/index.native.js +0 -44
  148. /package/src/hooks/use-isomorphic-layout-effect/{index.js → index.ts} +0 -0
@@ -1,38 +1,34 @@
1
- export type WPFixedWindowList = {
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
- export type WPFixedWindowListOptions = {
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
- * @property {number} visibleItems Items visible in the current viewport
17
- * @property {number} start Start index of the window
18
- * @property {number} end End index of the window
19
- * @property {(index:number)=>boolean} itemInView Returns true if item is in the window
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
- * @typedef {Object} WPFixedWindowListOptions
23
- *
24
- * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.
25
- * @property {boolean} [useWindowing] When false avoids calculating the window size
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.js"],"names":[],"mappings":"AAeG,YAAkB,iBAAiB,GAEnC;IAAoC,YAAY,EAArC,MAAM,CACjB;IAAoC,KAAK,EAA9B,MAAM,CACjB;IAAoC,GAAG,EAA5B,MAAM,CACjB;IAAoC,UAAU,EAAnC,CAAC,KAAK,EAAC,MAAM,KAAG,OAAO,CACpC;CAAA,CAAA;AAGE,YAAkB,wBAAwB,GAE1C;IAAqB,cAAc,AAAnC,CACA,EADW,MAAM,CACjB;IAAqB,YAAY,AAAjC,CACA,EADW,OAAO,CAClB;IAAqB,cAAc,AAAnC,CACA,EADW,MAAM,CACjB;IAAqB,aAAa,AAAlC,CACF,EADa,GAAG,CAChB;CAAA,CAAA;AAhBD;;;;;;;GAOG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACzC,UAAU,EAPA,KAAK,CAAC,SAAS,CAAC,WAAW,CAO3B,EACV,UAAU,EAPC,MAOD,EACV,UAAU,EAPC,MAOD,EACV,OAAO,AAPL,CACA,EADS,wBAOJ,GANI,CAAE,iBAAiB,EAAE,kBAAkB,EAAC,CAAC,UAAU,EAAC,iBAAiB,KAAG,IAAI,CAAC,CA0JxF"}
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 {() => void} [onFocusReturn] Overrides the default return behavior.
6
- * @return {React.RefCallback<HTMLElement>} Element Ref.
5
+ * @param onFocusReturn Overrides the default return behavior.
6
+ * @return Element Ref.
7
7
  *
8
8
  * @example
9
- * ```js
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.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,cAAc,CAAE,aAAa,AAlBnC,CACA,EADQ,MAAM,IAkBqB,GAjB1B,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,CAsEzC;eAEc,cAAc"}
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.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAa,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;;;GAIG;AACH,QAAA,MAAM,yBAAyB,wBAC6B,CAAC;eAE9C,yBAAyB"}
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
- export type WPKeyboardShortcutConfig = {
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
- * A block selection object.
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 {string[]|string} shortcuts Keyboard Shortcuts.
28
- * @param {(e: Mousetrap.ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
29
- * @param {WPKeyboardShortcutConfig} options Shortcut options.
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: Mousetrap.ExtendedKeyboardEvent, combo: string) => void, { bindGlobal, eventName, isDisabled, // This is important for performance considerations.
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.js"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,wDAAwD,CAAC;AAW7D,YAAkB,wBAAwB,GAE1C;IAAiD,UAAU,AAA3D,CACA,EADW,OAAO,CAClB;IAAiD,SAAS,AAA1D,CACA,EADW,MAAM,CACjB;IAAiD,UAAU,AAA3D,CACA,EADW,OAAO,CAClB;IAAiD,MAAM,AAAvD,CACF,EADa,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAChD;CAAA,CAAA;AATD;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,iBAAS,mBAAmB,CAC3B,SAAS,EALC,MAAM,EAAE,GAAC,MAKV,EACT,QAAQ,EALE,CAAC,CAAC,EAAE,SAAS,CAAC,qBAAqB,EAAE,KAAK,EAAE,MAAM,KAAK,IAKzD,EACR,EACC,UAAkB,EAClB,SAAqB,EACrB,UAAkB,EAAE,oDAAoD;AACxE,MAAM,EACN,GAVS,wBAUJ,QA2DN;eAEc,mBAAmB"}
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":"AAoEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACpC,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,GAAE,MAAe,GACnB,OAAO,CAQT"}
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
- * To make ref callbacks easier to use, you can also pass the result of
19
- * `useRefEffect`, which makes cleanup easier by allowing you to return a
20
- * cleanup function instead of handling `null`.
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 = useRefEffect( ( node ) => {
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;AAUhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,CAAC,EACtC,IAAI,EAAE,GAAG,CAAE,CAAC,CAAE,EAAE,GACd,WAAW,CAAE,CAAC,CAAE,CA0DlB"}
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 {boolean} Reduced motion preference value.
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.js"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,QAFV,OAGwC,CAAC;eAEtC,gBAAgB"}
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 {(...args: any[]) => void} TFunc
11
+ * @template TFunc
10
12
  *
11
- * @param {TFunc} fn The function to throttle.
12
- * @param {number} [wait] The number of milliseconds to throttle invocations to.
13
- * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
14
- * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
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?: import('../../utils/throttle').ThrottleOptions): import('../../utils/debounce').DebouncedFunc<TFunc>;
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.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAPK,KAAK,SAA/B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAW,EAOR,EAAE,EAL5B,KAK4B,EAAE,IAAI,AAJ1C,CACA,EADQ,MAIkC,EAAE,OAAO,AAHnD,CACA,EADQ,OAAO,sBAAsB,EAAE,eAGY,GAF1C,OAAO,sBAAsB,EAAE,aAAa,CAAC,KAAK,CAAC,CAS9D"}
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
- export type WPBreakpoint = "xhuge" | "huge" | "wide" | "xlarge" | "large" | "medium" | "small" | "mobile";
2
- export type WPViewportOperator = ">=" | "<";
3
- declare function useViewportMatch(breakpoint: WPBreakpoint, operator?: WPViewportOperator, view?: Window): boolean;
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.js"],"names":[],"mappings":"AAWG,YAA0F,YAAY,GAA5F,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAc;AAsBtG,YAAsB,kBAAkB,GAA9B,IAAI,GAAG,GAAG,CAAoB;kCA4ChB,UAAU,EAb1B,YAa0B,EAAE,QAAQ,GAZpC,kBAY2C,EAAE,IAAI,GAXjD,MAW0D,GAFzD,OAAO;;;;eAoBJ,gBAAgB"}
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 preview value of an object
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
- * this is useful in performance related work, to check why a component re-renders.
4
+ * This is useful in performance related work, to check why a component re-renders.
5
5
  *
6
6
  * @example
7
7
  *
8
- * ```jsx
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 {object} object Object which changes to compare.
17
- * @param {string} prefix Just a prefix to show when console logging.
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: object, prefix?: string): void;
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.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAS,eAAe,CAAE,MAAM,EAHrB,MAGqB,EAAE,MAAM,GAF7B,MAEkD,QAc5D;eAEc,eAAe"}
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
- "mock-match-media": "0.4.2"
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": "e7856693aeb4e2522d13608cd32c994e4a97cb9c"
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 { Component } from '@wordpress/element';
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
- it( 'functional component should rerender only when props change', () => {
19
- let i = 0;
20
- const MyComp = pure( () => {
21
- return <p data-testid="counter">{ ++i }</p>;
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( 'class component should rerender if the props or state change', async () => {
43
- const user = userEvent.setup();
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
- // Updating with same props doesn't rerender.
79
- rerender( <MyComp /> );
80
- expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '1' );
26
+ render( <MyComp /> );
81
27
 
82
- // New prop should trigger a rerender.
83
- rerender( <MyComp { ...{ prop: 'a' } } /> );
84
- expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
85
-
86
- // Keeping the same prop value should not rerender.
87
- rerender( <MyComp { ...{ prop: 'a' } } /> );
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 {React.RefCallback<Element>} Element Ref.
15
+ * @return Element Ref.
16
16
  *
17
17
  * @example
18
- * ```js
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( ( /** @type {HTMLElement} */ node ) => {
34
- function onKeyDown( /** @type {KeyboardEvent} */ event ) {
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 {(...args: any[]) => void} TFunc
25
+ * @template TFunc
25
26
  *
26
- * @param {TFunc} fn The function to debounce.
27
- * @param {number} [wait] The number of milliseconds to delay.
28
- * @param {import('../../utils/debounce').DebounceOptions} [options] The options object.
29
- * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.
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( fn, wait, options ) {
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: Function[] = [];
50
+ const updates: ( () => void )[] = [];
49
51
  const disable = () => {
50
52
  node.childNodes.forEach( ( child ) => {
51
53
  if ( ! ( child instanceof defaultView.HTMLElement ) ) {