@wordpress/compose 7.39.1-next.v.202602111440.0 → 7.40.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 (89) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +9 -9
  3. package/build/hooks/use-constrained-tabbing/index.cjs.map +1 -1
  4. package/build/hooks/use-copy-on-click/index.cjs +1 -1
  5. package/build/hooks/use-copy-on-click/index.cjs.map +2 -2
  6. package/build/hooks/use-copy-to-clipboard/index.cjs.map +1 -1
  7. package/build/hooks/use-dialog/index.cjs +1 -1
  8. package/build/hooks/use-dialog/index.cjs.map +2 -2
  9. package/build/hooks/use-disabled/index.cjs.map +1 -1
  10. package/build/hooks/use-dragging/index.cjs.map +1 -1
  11. package/build/hooks/use-drop-zone/index.cjs.map +1 -1
  12. package/build/hooks/use-fixed-window-list/index.cjs.map +1 -1
  13. package/build/hooks/use-focus-on-mount/index.cjs +1 -1
  14. package/build/hooks/use-focus-on-mount/index.cjs.map +2 -2
  15. package/build/hooks/use-focus-outside/index.cjs +1 -1
  16. package/build/hooks/use-focus-outside/index.cjs.map +2 -2
  17. package/build/hooks/use-focus-return/index.cjs.map +1 -1
  18. package/build/hooks/use-keyboard-shortcut/index.cjs.map +1 -1
  19. package/build/hooks/use-merge-refs/index.cjs +2 -2
  20. package/build/hooks/use-merge-refs/index.cjs.map +3 -3
  21. package/build/hooks/use-previous/index.cjs +1 -1
  22. package/build/hooks/use-previous/index.cjs.map +2 -2
  23. package/build/hooks/use-ref-effect/index.cjs +1 -1
  24. package/build/hooks/use-ref-effect/index.cjs.map +2 -2
  25. package/build/hooks/use-resize-observer/use-resize-observer.cjs +3 -3
  26. package/build/hooks/use-resize-observer/use-resize-observer.cjs.map +2 -2
  27. package/build-module/hooks/use-constrained-tabbing/index.mjs.map +1 -1
  28. package/build-module/hooks/use-copy-on-click/index.mjs +1 -1
  29. package/build-module/hooks/use-copy-on-click/index.mjs.map +2 -2
  30. package/build-module/hooks/use-copy-to-clipboard/index.mjs.map +1 -1
  31. package/build-module/hooks/use-dialog/index.mjs +1 -1
  32. package/build-module/hooks/use-dialog/index.mjs.map +2 -2
  33. package/build-module/hooks/use-disabled/index.mjs.map +1 -1
  34. package/build-module/hooks/use-dragging/index.mjs.map +1 -1
  35. package/build-module/hooks/use-drop-zone/index.mjs.map +1 -1
  36. package/build-module/hooks/use-fixed-window-list/index.mjs.map +1 -1
  37. package/build-module/hooks/use-focus-on-mount/index.mjs +1 -1
  38. package/build-module/hooks/use-focus-on-mount/index.mjs.map +2 -2
  39. package/build-module/hooks/use-focus-outside/index.mjs +1 -1
  40. package/build-module/hooks/use-focus-outside/index.mjs.map +2 -2
  41. package/build-module/hooks/use-focus-return/index.mjs.map +1 -1
  42. package/build-module/hooks/use-keyboard-shortcut/index.mjs.map +1 -1
  43. package/build-module/hooks/use-merge-refs/index.mjs +2 -2
  44. package/build-module/hooks/use-merge-refs/index.mjs.map +3 -3
  45. package/build-module/hooks/use-previous/index.mjs +1 -1
  46. package/build-module/hooks/use-previous/index.mjs.map +2 -2
  47. package/build-module/hooks/use-ref-effect/index.mjs +1 -1
  48. package/build-module/hooks/use-ref-effect/index.mjs.map +2 -2
  49. package/build-module/hooks/use-resize-observer/use-resize-observer.mjs +3 -3
  50. package/build-module/hooks/use-resize-observer/use-resize-observer.mjs.map +2 -2
  51. package/build-types/hooks/use-constrained-tabbing/index.d.ts +2 -2
  52. package/build-types/hooks/use-constrained-tabbing/index.d.ts.map +1 -1
  53. package/build-types/hooks/use-copy-on-click/index.d.ts +5 -5
  54. package/build-types/hooks/use-copy-on-click/index.d.ts.map +1 -1
  55. package/build-types/hooks/use-copy-to-clipboard/index.d.ts +2 -2
  56. package/build-types/hooks/use-copy-to-clipboard/index.d.ts.map +1 -1
  57. package/build-types/hooks/use-disabled/index.d.ts +1 -1
  58. package/build-types/hooks/use-dragging/index.d.ts +6 -6
  59. package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
  60. package/build-types/hooks/use-drop-zone/index.d.ts +2 -2
  61. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  62. package/build-types/hooks/use-fixed-window-list/index.d.ts +5 -5
  63. package/build-types/hooks/use-fixed-window-list/index.d.ts.map +1 -1
  64. package/build-types/hooks/use-focus-on-mount/index.d.ts +2 -2
  65. package/build-types/hooks/use-focus-on-mount/index.d.ts.map +1 -1
  66. package/build-types/hooks/use-focus-return/index.d.ts +2 -2
  67. package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
  68. package/build-types/hooks/use-keyboard-shortcut/index.d.ts +10 -9
  69. package/build-types/hooks/use-keyboard-shortcut/index.d.ts.map +1 -1
  70. package/build-types/hooks/use-merge-refs/index.d.ts +4 -6
  71. package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
  72. package/package.json +9 -9
  73. package/src/hooks/use-constrained-tabbing/index.js +1 -1
  74. package/src/hooks/use-copy-on-click/index.js +6 -6
  75. package/src/hooks/use-copy-to-clipboard/index.js +2 -2
  76. package/src/hooks/use-dialog/index.ts +1 -1
  77. package/src/hooks/use-disabled/index.ts +1 -1
  78. package/src/hooks/use-dragging/index.js +5 -5
  79. package/src/hooks/use-drop-zone/index.js +1 -1
  80. package/src/hooks/use-fixed-window-list/index.js +4 -4
  81. package/src/hooks/use-focus-on-mount/index.js +3 -3
  82. package/src/hooks/use-focus-outside/index.native.js +3 -3
  83. package/src/hooks/use-focus-outside/index.ts +1 -1
  84. package/src/hooks/use-focus-return/index.js +3 -3
  85. package/src/hooks/use-keyboard-shortcut/index.js +7 -7
  86. package/src/hooks/use-merge-refs/{index.js → index.ts} +11 -22
  87. package/src/hooks/use-previous/index.ts +1 -1
  88. package/src/hooks/use-ref-effect/index.ts +1 -1
  89. package/src/hooks/use-resize-observer/use-resize-observer.ts +3 -3
@@ -2,23 +2,13 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useRef, useCallback, useLayoutEffect } from '@wordpress/element';
5
+ import type { MutableRefObject, Ref, RefCallback } from 'react';
5
6
 
6
- /**
7
- * @template T
8
- * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef
9
- */
10
-
11
- /**
12
- * @template T
13
- * @param {import('react').Ref<T>} ref
14
- * @param {T} value
15
- */
16
- function assignRef( ref, value ) {
7
+ function assignRef< T >( ref: Ref< T >, value: T ) {
17
8
  if ( typeof ref === 'function' ) {
18
9
  ref( value );
19
10
  } else if ( ref && ref.hasOwnProperty( 'current' ) ) {
20
- /** @type {import('react').MutableRefObject<T>} */ ( ref ).current =
21
- value;
11
+ ( ref as MutableRefObject< T > ).current = value;
22
12
  }
23
13
  }
24
14
 
@@ -60,17 +50,16 @@ function assignRef( ref, value ) {
60
50
  * return <div ref={ mergedRefs } />;
61
51
  * ```
62
52
  *
63
- * @template {import('react').Ref<any>} TRef
64
- * @param {Array<TRef>} refs The refs to be merged.
65
- *
66
- * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.
53
+ * @param refs The refs to be merged.
54
+ * @return The merged ref callback.
67
55
  */
68
- export default function useMergeRefs( refs ) {
69
- const element = useRef();
56
+ export default function useMergeRefs< T >(
57
+ refs: Ref< T >[]
58
+ ): RefCallback< T > {
59
+ const element = useRef( null );
70
60
  const isAttachedRef = useRef( false );
71
61
  const didElementChangeRef = useRef( false );
72
- /** @type {import('react').MutableRefObject<TRef[]>} */
73
- const previousRefsRef = useRef( [] );
62
+ const previousRefsRef = useRef< Ref< T >[] >( [] );
74
63
  const currentRefsRef = useRef( refs );
75
64
 
76
65
  // Update on render before the ref callback is called, so the ref callback
@@ -105,7 +94,7 @@ export default function useMergeRefs( refs ) {
105
94
 
106
95
  // There should be no dependencies so that `callback` is only called when
107
96
  // the node changes.
108
- return useCallback( ( value ) => {
97
+ return useCallback( ( value: T | null ) => {
109
98
  // Update the element so it can be used when calling ref callbacks on a
110
99
  // dependency change.
111
100
  assignRef( element, value );
@@ -12,7 +12,7 @@ import { useEffect, useRef } from '@wordpress/element';
12
12
  * @return The value from the previous render.
13
13
  */
14
14
  export default function usePrevious< T >( value: T ): T | undefined {
15
- const ref = useRef< T >();
15
+ const ref = useRef< T >( undefined );
16
16
 
17
17
  // Store current value in ref.
18
18
  useEffect( () => {
@@ -31,7 +31,7 @@ export default function useRefEffect< TElement = Node >(
31
31
  callback: ( node: TElement ) => ( () => void ) | void,
32
32
  dependencies: DependencyList
33
33
  ): RefCallback< TElement | null > {
34
- const cleanupRef = useRef< ( () => void ) | void >();
34
+ const cleanupRef = useRef< ( () => void ) | void >( undefined );
35
35
  return useCallback( ( node: TElement | null ) => {
36
36
  if ( node ) {
37
37
  cleanupRef.current = callback( node );
@@ -18,8 +18,8 @@ export function useResizeObserver< T extends HTMLElement >(
18
18
  ): ( element?: T | null ) => void {
19
19
  const callbackEvent = useEvent( callback );
20
20
 
21
- const observedElementRef = useRef< T | null >();
22
- const resizeObserverRef = useRef< ResizeObserver >();
21
+ const observedElementRef = useRef< T | null >( null );
22
+ const resizeObserverRef = useRef< ResizeObserver >( undefined );
23
23
  return useEvent( ( element?: T | null ) => {
24
24
  if ( element === observedElementRef.current ) {
25
25
  return;
@@ -35,7 +35,7 @@ export function useResizeObserver< T extends HTMLElement >(
35
35
  }
36
36
 
37
37
  // Observe new element.
38
- observedElementRef.current = element;
38
+ observedElementRef.current = element ?? null;
39
39
  if ( element ) {
40
40
  resizeObserver.observe( element, resizeObserverOptions );
41
41
  }