@wordpress/compose 8.1.0 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -1
- package/README.md +5 -5
- package/build/higher-order/pure/index.cjs +15 -0
- package/build/higher-order/pure/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-viewport-match/index.cjs +1 -1
- package/build/hooks/use-viewport-match/index.cjs.map +2 -2
- 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-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-viewport-match/index.mjs +1 -1
- package/build-module/hooks/use-viewport-match/index.mjs.map +2 -2
- package/build-types/higher-order/pure/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-viewport-match/index.d.ts +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts.map +1 -1
- package/package.json +16 -12
- package/src/higher-order/pure/index.tsx +6 -0
- package/src/higher-order/pure/test/index.js +14 -81
- package/src/hooks/use-drop-zone/README.md +1 -1
- 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-viewport-match/index.js +8 -2
- 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-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/index.native.js +0 -44
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { act, renderHook } from 'test/helpers';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import {
|
|
10
|
-
requestConnectionStatus,
|
|
11
|
-
subscribeConnectionStatus,
|
|
12
|
-
} from '@wordpress/react-native-bridge';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import useNetworkConnectivity from '../index';
|
|
18
|
-
|
|
19
|
-
describe( 'useNetworkConnectivity', () => {
|
|
20
|
-
it( 'should optimisitically presume network connectivity', () => {
|
|
21
|
-
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
22
|
-
|
|
23
|
-
expect( result.current.isConnected ).toBe( true );
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
describe( 'when network connectivity is available', () => {
|
|
27
|
-
beforeAll( () => {
|
|
28
|
-
requestConnectionStatus.mockImplementation( ( callback ) => {
|
|
29
|
-
callback( true );
|
|
30
|
-
return { remove: jest.fn() };
|
|
31
|
-
} );
|
|
32
|
-
} );
|
|
33
|
-
|
|
34
|
-
it( 'should return true', () => {
|
|
35
|
-
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
36
|
-
|
|
37
|
-
expect( result.current.isConnected ).toBe( true );
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
it( 'should update the status when network connectivity changes', () => {
|
|
41
|
-
let subscriptionCallback;
|
|
42
|
-
subscribeConnectionStatus.mockImplementation( ( callback ) => {
|
|
43
|
-
subscriptionCallback = callback;
|
|
44
|
-
return { remove: jest.fn() };
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
|
-
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
48
|
-
|
|
49
|
-
expect( result.current.isConnected ).toBe( true );
|
|
50
|
-
|
|
51
|
-
act( () => subscriptionCallback( { isConnected: false } ) );
|
|
52
|
-
|
|
53
|
-
expect( result.current.isConnected ).toBe( false );
|
|
54
|
-
} );
|
|
55
|
-
} );
|
|
56
|
-
|
|
57
|
-
describe( 'when network connectivity is unavailable', () => {
|
|
58
|
-
beforeAll( () => {
|
|
59
|
-
requestConnectionStatus.mockImplementation( ( callback ) => {
|
|
60
|
-
callback( false );
|
|
61
|
-
return { remove: jest.fn() };
|
|
62
|
-
} );
|
|
63
|
-
} );
|
|
64
|
-
|
|
65
|
-
it( 'should return false', () => {
|
|
66
|
-
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
67
|
-
|
|
68
|
-
expect( result.current.isConnected ).toBe( false );
|
|
69
|
-
} );
|
|
70
|
-
|
|
71
|
-
it( 'should update the status when network connectivity changes', () => {
|
|
72
|
-
let subscriptionCallback;
|
|
73
|
-
subscribeConnectionStatus.mockImplementation( ( callback ) => {
|
|
74
|
-
subscriptionCallback = callback;
|
|
75
|
-
return { remove: jest.fn() };
|
|
76
|
-
} );
|
|
77
|
-
|
|
78
|
-
const { result } = renderHook( () => useNetworkConnectivity() );
|
|
79
|
-
|
|
80
|
-
expect( result.current.isConnected ).toBe( false );
|
|
81
|
-
|
|
82
|
-
act( () => subscriptionCallback( { isConnected: true } ) );
|
|
83
|
-
|
|
84
|
-
expect( result.current.isConnected ).toBe( true );
|
|
85
|
-
} );
|
|
86
|
-
} );
|
|
87
|
-
} );
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useState, useEffect } from '@wordpress/element';
|
|
5
|
-
import {
|
|
6
|
-
subscribePreferredColorScheme,
|
|
7
|
-
isInitialColorSchemeDark,
|
|
8
|
-
} from '@wordpress/react-native-bridge';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]
|
|
12
|
-
*
|
|
13
|
-
* @return {string} return current color scheme.
|
|
14
|
-
*/
|
|
15
|
-
function usePreferredColorScheme() {
|
|
16
|
-
const [ currentColorScheme, setCurrentColorScheme ] = useState(
|
|
17
|
-
isInitialColorSchemeDark ? 'dark' : 'light'
|
|
18
|
-
);
|
|
19
|
-
useEffect( () => {
|
|
20
|
-
subscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {
|
|
21
|
-
const colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';
|
|
22
|
-
if ( colorScheme !== currentColorScheme ) {
|
|
23
|
-
setCurrentColorScheme( colorScheme );
|
|
24
|
-
}
|
|
25
|
-
} );
|
|
26
|
-
} );
|
|
27
|
-
return currentColorScheme;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default usePreferredColorScheme;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useColorScheme } from 'react-native';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]
|
|
8
|
-
*
|
|
9
|
-
* @return {string} return current color scheme.
|
|
10
|
-
*/
|
|
11
|
-
const usePreferredColorScheme = useColorScheme;
|
|
12
|
-
|
|
13
|
-
export default usePreferredColorScheme;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import usePreferredColorScheme from '../use-preferred-color-scheme';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Selects which of the passed style objects should be applied depending on the
|
|
8
|
-
* user's preferred color scheme.
|
|
9
|
-
*
|
|
10
|
-
* The "light" color schemed is assumed to be the default, and its styles are
|
|
11
|
-
* always applied. The "dark" styles will always extend those defined for the
|
|
12
|
-
* light case.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const light = { padding: 10, backgroundColor: 'white' };
|
|
16
|
-
* const dark = { backgroundColor: 'black' };
|
|
17
|
-
* usePreferredColorSchemeStyle( light, dark);
|
|
18
|
-
* // On light mode:
|
|
19
|
-
* // => { padding: 10, backgroundColor: 'white' }
|
|
20
|
-
* // On dark mode:
|
|
21
|
-
* // => { padding: 10, backgroundColor: 'black' }
|
|
22
|
-
* @param {Object} lightStyle
|
|
23
|
-
* @param {Object} darkStyle
|
|
24
|
-
* @return {Object} the combined styles depending on the current color scheme
|
|
25
|
-
*/
|
|
26
|
-
const usePreferredColorSchemeStyle = ( lightStyle, darkStyle ) => {
|
|
27
|
-
const colorScheme = usePreferredColorScheme();
|
|
28
|
-
const isDarkMode = colorScheme === 'dark';
|
|
29
|
-
|
|
30
|
-
return isDarkMode ? { ...lightStyle, ...darkStyle } : lightStyle;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default usePreferredColorSchemeStyle;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './legacy/index.native';
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { View, StyleSheet } from 'react-native';
|
|
5
|
-
/**
|
|
6
|
-
* WordPress dependencies
|
|
7
|
-
*/
|
|
8
|
-
import { useState, useCallback } from '@wordpress/element';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Hook which allows to listen the resize event of any target element when it changes sizes.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```js
|
|
16
|
-
* const App = () => {
|
|
17
|
-
* const [ resizeListener, sizes ] = useResizeObserver();
|
|
18
|
-
*
|
|
19
|
-
* return (
|
|
20
|
-
* <View>
|
|
21
|
-
* { resizeListener }
|
|
22
|
-
* Your content here
|
|
23
|
-
* </View>
|
|
24
|
-
* );
|
|
25
|
-
* };
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
const useResizeObserver = () => {
|
|
29
|
-
const [ measurements, setMeasurements ] = useState( null );
|
|
30
|
-
|
|
31
|
-
const onLayout = useCallback( ( { nativeEvent } ) => {
|
|
32
|
-
const { width, height } = nativeEvent.layout;
|
|
33
|
-
setMeasurements( ( prevState ) => {
|
|
34
|
-
if (
|
|
35
|
-
! prevState ||
|
|
36
|
-
prevState.width !== width ||
|
|
37
|
-
prevState.height !== height
|
|
38
|
-
) {
|
|
39
|
-
return {
|
|
40
|
-
width: Math.floor( width ),
|
|
41
|
-
height: Math.floor( height ),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return prevState;
|
|
45
|
-
} );
|
|
46
|
-
}, [] );
|
|
47
|
-
|
|
48
|
-
const observer = (
|
|
49
|
-
<View
|
|
50
|
-
testID="resize-observer"
|
|
51
|
-
style={ StyleSheet.absoluteFill }
|
|
52
|
-
onLayout={ onLayout }
|
|
53
|
-
/>
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
return [ observer, measurements ];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default useResizeObserver;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { render, fireEvent } from 'test/helpers';
|
|
5
|
-
import { View } from 'react-native';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import useResizeObserver from '..';
|
|
11
|
-
|
|
12
|
-
const TestComponent = ( { onLayout } ) => {
|
|
13
|
-
const [ resizeObserver, sizes ] = useResizeObserver();
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<View testID="test-component" sizes={ sizes } onLayout={ onLayout }>
|
|
17
|
-
{ resizeObserver }
|
|
18
|
-
</View>
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe( 'useResizeObserver()', () => {
|
|
23
|
-
it( 'should return "{ width: 300, height: 500 }"', () => {
|
|
24
|
-
const mockNativeEvent = {
|
|
25
|
-
nativeEvent: {
|
|
26
|
-
layout: {
|
|
27
|
-
width: 300,
|
|
28
|
-
height: 500,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const { getByTestId } = render(
|
|
34
|
-
<TestComponent onLayout={ mockNativeEvent } />
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const resizeObserver = getByTestId( 'resize-observer' );
|
|
38
|
-
fireEvent( resizeObserver, 'layout', mockNativeEvent );
|
|
39
|
-
|
|
40
|
-
const testComponent = getByTestId( 'test-component' );
|
|
41
|
-
expect( testComponent.props.sizes ).toMatchObject( {
|
|
42
|
-
width: 300,
|
|
43
|
-
height: 500,
|
|
44
|
-
} );
|
|
45
|
-
} );
|
|
46
|
-
} );
|
package/src/index.native.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// The `createHigherOrderComponent` helper and helper types.
|
|
2
|
-
export * from './utils/create-higher-order-component';
|
|
3
|
-
// The `debounce` helper and its types.
|
|
4
|
-
export * from './utils/debounce';
|
|
5
|
-
// The `throttle` helper and its types.
|
|
6
|
-
export * from './utils/throttle';
|
|
7
|
-
// The `ObservableMap` data structure
|
|
8
|
-
export * from './utils/observable-map';
|
|
9
|
-
|
|
10
|
-
// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).
|
|
11
|
-
export { default as compose } from './higher-order/compose';
|
|
12
|
-
export { default as pipe } from './higher-order/pipe';
|
|
13
|
-
|
|
14
|
-
// Higher-order components.
|
|
15
|
-
export { default as ifCondition } from './higher-order/if-condition';
|
|
16
|
-
export { default as pure } from './higher-order/pure';
|
|
17
|
-
export { default as withGlobalEvents } from './higher-order/with-global-events';
|
|
18
|
-
export { default as withInstanceId } from './higher-order/with-instance-id';
|
|
19
|
-
export { default as withSafeTimeout } from './higher-order/with-safe-timeout';
|
|
20
|
-
export { default as withState } from './higher-order/with-state';
|
|
21
|
-
export { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';
|
|
22
|
-
export { default as withNetworkConnectivity } from './higher-order/with-network-connectivity';
|
|
23
|
-
|
|
24
|
-
// Hooks.
|
|
25
|
-
export { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';
|
|
26
|
-
export { default as __experimentalUseDragging } from './hooks/use-dragging';
|
|
27
|
-
export { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';
|
|
28
|
-
export { default as useInstanceId } from './hooks/use-instance-id';
|
|
29
|
-
export { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';
|
|
30
|
-
export { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';
|
|
31
|
-
export { default as useMediaQuery } from './hooks/use-media-query';
|
|
32
|
-
export { default as usePrevious } from './hooks/use-previous';
|
|
33
|
-
export { default as useReducedMotion } from './hooks/use-reduced-motion';
|
|
34
|
-
export { default as useViewportMatch } from './hooks/use-viewport-match';
|
|
35
|
-
export { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';
|
|
36
|
-
export { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';
|
|
37
|
-
export { default as useResizeObserver } from './hooks/use-resize-observer';
|
|
38
|
-
export { default as useDebounce } from './hooks/use-debounce';
|
|
39
|
-
export { default as useDebouncedInput } from './hooks/use-debounced-input';
|
|
40
|
-
export { default as useThrottle } from './hooks/use-throttle';
|
|
41
|
-
export { default as useMergeRefs } from './hooks/use-merge-refs';
|
|
42
|
-
export { default as useRefEffect } from './hooks/use-ref-effect';
|
|
43
|
-
export { default as useNetworkConnectivity } from './hooks/use-network-connectivity';
|
|
44
|
-
export { default as useObservableValue } from './hooks/use-observable-value';
|