@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.
- package/CHANGELOG.md +2 -0
- package/README.md +9 -9
- package/build/hooks/use-constrained-tabbing/index.cjs.map +1 -1
- package/build/hooks/use-copy-on-click/index.cjs +1 -1
- package/build/hooks/use-copy-on-click/index.cjs.map +2 -2
- package/build/hooks/use-copy-to-clipboard/index.cjs.map +1 -1
- package/build/hooks/use-dialog/index.cjs +1 -1
- package/build/hooks/use-dialog/index.cjs.map +2 -2
- package/build/hooks/use-disabled/index.cjs.map +1 -1
- package/build/hooks/use-dragging/index.cjs.map +1 -1
- package/build/hooks/use-drop-zone/index.cjs.map +1 -1
- package/build/hooks/use-fixed-window-list/index.cjs.map +1 -1
- package/build/hooks/use-focus-on-mount/index.cjs +1 -1
- package/build/hooks/use-focus-on-mount/index.cjs.map +2 -2
- package/build/hooks/use-focus-outside/index.cjs +1 -1
- package/build/hooks/use-focus-outside/index.cjs.map +2 -2
- package/build/hooks/use-focus-return/index.cjs.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.cjs.map +1 -1
- package/build/hooks/use-merge-refs/index.cjs +2 -2
- package/build/hooks/use-merge-refs/index.cjs.map +3 -3
- package/build/hooks/use-previous/index.cjs +1 -1
- package/build/hooks/use-previous/index.cjs.map +2 -2
- package/build/hooks/use-ref-effect/index.cjs +1 -1
- package/build/hooks/use-ref-effect/index.cjs.map +2 -2
- package/build/hooks/use-resize-observer/use-resize-observer.cjs +3 -3
- package/build/hooks/use-resize-observer/use-resize-observer.cjs.map +2 -2
- package/build-module/hooks/use-constrained-tabbing/index.mjs.map +1 -1
- package/build-module/hooks/use-copy-on-click/index.mjs +1 -1
- package/build-module/hooks/use-copy-on-click/index.mjs.map +2 -2
- package/build-module/hooks/use-copy-to-clipboard/index.mjs.map +1 -1
- package/build-module/hooks/use-dialog/index.mjs +1 -1
- package/build-module/hooks/use-dialog/index.mjs.map +2 -2
- package/build-module/hooks/use-disabled/index.mjs.map +1 -1
- package/build-module/hooks/use-dragging/index.mjs.map +1 -1
- package/build-module/hooks/use-drop-zone/index.mjs.map +1 -1
- package/build-module/hooks/use-fixed-window-list/index.mjs.map +1 -1
- package/build-module/hooks/use-focus-on-mount/index.mjs +1 -1
- package/build-module/hooks/use-focus-on-mount/index.mjs.map +2 -2
- package/build-module/hooks/use-focus-outside/index.mjs +1 -1
- package/build-module/hooks/use-focus-outside/index.mjs.map +2 -2
- package/build-module/hooks/use-focus-return/index.mjs.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.mjs.map +1 -1
- package/build-module/hooks/use-merge-refs/index.mjs +2 -2
- package/build-module/hooks/use-merge-refs/index.mjs.map +3 -3
- package/build-module/hooks/use-previous/index.mjs +1 -1
- package/build-module/hooks/use-previous/index.mjs.map +2 -2
- package/build-module/hooks/use-ref-effect/index.mjs +1 -1
- package/build-module/hooks/use-ref-effect/index.mjs.map +2 -2
- package/build-module/hooks/use-resize-observer/use-resize-observer.mjs +3 -3
- package/build-module/hooks/use-resize-observer/use-resize-observer.mjs.map +2 -2
- 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-copy-on-click/index.d.ts +5 -5
- package/build-types/hooks/use-copy-on-click/index.d.ts.map +1 -1
- package/build-types/hooks/use-copy-to-clipboard/index.d.ts +2 -2
- package/build-types/hooks/use-copy-to-clipboard/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +1 -1
- package/build-types/hooks/use-dragging/index.d.ts +6 -6
- package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
- package/build-types/hooks/use-drop-zone/index.d.ts +2 -2
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/build-types/hooks/use-fixed-window-list/index.d.ts +5 -5
- package/build-types/hooks/use-fixed-window-list/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-on-mount/index.d.ts +2 -2
- package/build-types/hooks/use-focus-on-mount/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-return/index.d.ts +2 -2
- package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts +10 -9
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts.map +1 -1
- package/build-types/hooks/use-merge-refs/index.d.ts +4 -6
- package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/hooks/use-constrained-tabbing/index.js +1 -1
- package/src/hooks/use-copy-on-click/index.js +6 -6
- package/src/hooks/use-copy-to-clipboard/index.js +2 -2
- package/src/hooks/use-dialog/index.ts +1 -1
- package/src/hooks/use-disabled/index.ts +1 -1
- package/src/hooks/use-dragging/index.js +5 -5
- package/src/hooks/use-drop-zone/index.js +1 -1
- package/src/hooks/use-fixed-window-list/index.js +4 -4
- package/src/hooks/use-focus-on-mount/index.js +3 -3
- package/src/hooks/use-focus-outside/index.native.js +3 -3
- package/src/hooks/use-focus-outside/index.ts +1 -1
- package/src/hooks/use-focus-return/index.js +3 -3
- package/src/hooks/use-keyboard-shortcut/index.js +7 -7
- package/src/hooks/use-merge-refs/{index.js → index.ts} +11 -22
- package/src/hooks/use-previous/index.ts +1 -1
- package/src/hooks/use-ref-effect/index.ts +1 -1
- 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
|
-
|
|
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
|
-
* @
|
|
64
|
-
* @
|
|
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
|
|
69
|
-
|
|
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
|
-
|
|
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
|
}
|