@wordpress/components 21.0.2 → 21.1.2-next.4d3b314fd5.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 +31 -4
- package/build/autocomplete/get-default-use-items.js +3 -3
- package/build/autocomplete/get-default-use-items.js.map +1 -1
- package/build/box-control/unit-control.js +0 -1
- package/build/box-control/unit-control.js.map +1 -1
- package/build/button/index.js +5 -1
- package/build/button/index.js.map +1 -1
- package/build/draggable/index.js +3 -6
- package/build/draggable/index.js.map +1 -1
- package/build/drop-zone/index.js +7 -1
- package/build/drop-zone/index.js.map +1 -1
- package/build/higher-order/with-filters/index.js +1 -1
- package/build/higher-order/with-filters/index.js.map +1 -1
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/build/menu-item/index.js +4 -3
- package/build/menu-item/index.js.map +1 -1
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +10 -3
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js.map +1 -1
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +15 -6
- package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js.map +1 -1
- package/build/mobile/bottom-sheet/sub-sheet/index.native.js +4 -1
- package/build/mobile/bottom-sheet/sub-sheet/index.native.js.map +1 -1
- package/build/mobile/color-settings/index.native.js +3 -1
- package/build/mobile/color-settings/index.native.js.map +1 -1
- package/build/mobile/color-settings/picker-screen.native.js +3 -1
- package/build/mobile/color-settings/picker-screen.native.js.map +1 -1
- package/build/mobile/image/index.native.js +3 -1
- package/build/mobile/image/index.native.js.map +1 -1
- package/build/mobile/keyboard-avoiding-view/index.ios.js +3 -1
- package/build/mobile/keyboard-avoiding-view/index.ios.js.map +1 -1
- package/build/mobile/link-picker/index.native.js +3 -1
- package/build/mobile/link-picker/index.native.js.map +1 -1
- package/build/mobile/link-picker/link-picker-results.native.js +6 -4
- package/build/mobile/link-picker/link-picker-results.native.js.map +1 -1
- package/build/mobile/link-picker/link-picker-screen.native.js +3 -1
- package/build/mobile/link-picker/link-picker-screen.native.js.map +1 -1
- package/build/mobile/link-settings/index.native.js +24 -6
- package/build/mobile/link-settings/index.native.js.map +1 -1
- package/build/mobile/link-settings/link-settings-screen.native.js +3 -1
- package/build/mobile/link-settings/link-settings-screen.native.js.map +1 -1
- package/build/mobile/segmented-control/index.native.js +6 -2
- package/build/mobile/segmented-control/index.native.js.map +1 -1
- package/build/mobile/utils/use-unit-converter-to-mobile.native.js +6 -2
- package/build/mobile/utils/use-unit-converter-to-mobile.native.js.map +1 -1
- package/build/notice/index.native.js +15 -19
- package/build/notice/index.native.js.map +1 -1
- package/build/notice/list.native.js +2 -3
- package/build/notice/list.native.js.map +1 -1
- package/build/palette-edit/index.js +1 -1
- package/build/palette-edit/index.js.map +1 -1
- package/build/popover/index.js +29 -32
- package/build/popover/index.js.map +1 -1
- package/build/popover/limit-shift.js +145 -0
- package/build/popover/limit-shift.js.map +1 -0
- package/build/popover/utils.js +55 -15
- package/build/popover/utils.js.map +1 -1
- package/build/range-control/input-range.js +1 -15
- package/build/range-control/input-range.js.map +1 -1
- package/build/range-control/tooltip.js +1 -1
- package/build/range-control/tooltip.js.map +1 -1
- package/build/range-control/utils.js +2 -58
- package/build/range-control/utils.js.map +1 -1
- package/build/tools-panel/styles.js +27 -12
- package/build/tools-panel/styles.js.map +1 -1
- package/build/tools-panel/tools-panel-header/component.js +19 -6
- package/build/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build/tools-panel/tools-panel-header/hook.js +4 -0
- package/build/tools-panel/tools-panel-header/hook.js.map +1 -1
- package/build/tree-grid/index.js +13 -8
- package/build/tree-grid/index.js.map +1 -1
- package/build/unit-control/index.js +2 -2
- package/build/unit-control/index.js.map +1 -1
- package/build/unit-control/index.native.js +10 -2
- package/build/unit-control/index.native.js.map +1 -1
- package/build/unit-control/styles/unit-control-styles.js +21 -32
- package/build/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build/utils/hooks/use-controlled-state.js +2 -3
- package/build/utils/hooks/use-controlled-state.js.map +1 -1
- package/build-module/autocomplete/get-default-use-items.js +1 -1
- package/build-module/autocomplete/get-default-use-items.js.map +1 -1
- package/build-module/box-control/unit-control.js +0 -1
- package/build-module/box-control/unit-control.js.map +1 -1
- package/build-module/button/index.js +5 -1
- package/build-module/button/index.js.map +1 -1
- package/build-module/draggable/index.js +2 -5
- package/build-module/draggable/index.js.map +1 -1
- package/build-module/drop-zone/index.js +7 -1
- package/build-module/drop-zone/index.js.map +1 -1
- package/build-module/higher-order/with-filters/index.js +2 -2
- package/build-module/higher-order/with-filters/index.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/menu-item/index.js +4 -3
- package/build-module/menu-item/index.js.map +1 -1
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +10 -3
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js.map +1 -1
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +13 -4
- package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js.map +1 -1
- package/build-module/mobile/bottom-sheet/sub-sheet/index.native.js +4 -1
- package/build-module/mobile/bottom-sheet/sub-sheet/index.native.js.map +1 -1
- package/build-module/mobile/color-settings/index.native.js +3 -1
- package/build-module/mobile/color-settings/index.native.js.map +1 -1
- package/build-module/mobile/color-settings/picker-screen.native.js +3 -1
- package/build-module/mobile/color-settings/picker-screen.native.js.map +1 -1
- package/build-module/mobile/image/index.native.js +3 -1
- package/build-module/mobile/image/index.native.js.map +1 -1
- package/build-module/mobile/keyboard-avoiding-view/index.ios.js +3 -1
- package/build-module/mobile/keyboard-avoiding-view/index.ios.js.map +1 -1
- package/build-module/mobile/link-picker/index.native.js +3 -1
- package/build-module/mobile/link-picker/index.native.js.map +1 -1
- package/build-module/mobile/link-picker/link-picker-results.native.js +4 -2
- package/build-module/mobile/link-picker/link-picker-results.native.js.map +1 -1
- package/build-module/mobile/link-picker/link-picker-screen.native.js +3 -1
- package/build-module/mobile/link-picker/link-picker-screen.native.js.map +1 -1
- package/build-module/mobile/link-settings/index.native.js +24 -6
- package/build-module/mobile/link-settings/index.native.js.map +1 -1
- package/build-module/mobile/link-settings/link-settings-screen.native.js +3 -1
- package/build-module/mobile/link-settings/link-settings-screen.native.js.map +1 -1
- package/build-module/mobile/segmented-control/index.native.js +6 -2
- package/build-module/mobile/segmented-control/index.native.js.map +1 -1
- package/build-module/mobile/utils/use-unit-converter-to-mobile.native.js +6 -2
- package/build-module/mobile/utils/use-unit-converter-to-mobile.native.js.map +1 -1
- package/build-module/notice/index.native.js +16 -21
- package/build-module/notice/index.native.js.map +1 -1
- package/build-module/notice/list.native.js +3 -3
- package/build-module/notice/list.native.js.map +1 -1
- package/build-module/palette-edit/index.js +1 -1
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/popover/index.js +31 -35
- package/build-module/popover/index.js.map +1 -1
- package/build-module/popover/limit-shift.js +136 -0
- package/build-module/popover/limit-shift.js.map +1 -0
- package/build-module/popover/utils.js +55 -15
- package/build-module/popover/utils.js.map +1 -1
- package/build-module/range-control/input-range.js +1 -14
- package/build-module/range-control/input-range.js.map +1 -1
- package/build-module/range-control/tooltip.js +1 -1
- package/build-module/range-control/tooltip.js.map +1 -1
- package/build-module/range-control/utils.js +2 -57
- package/build-module/range-control/utils.js.map +1 -1
- package/build-module/tools-panel/styles.js +23 -12
- package/build-module/tools-panel/styles.js.map +1 -1
- package/build-module/tools-panel/tools-panel-header/component.js +19 -7
- package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel-header/hook.js +4 -0
- package/build-module/tools-panel/tools-panel-header/hook.js.map +1 -1
- package/build-module/tree-grid/index.js +13 -8
- package/build-module/tree-grid/index.js.map +1 -1
- package/build-module/unit-control/index.js +2 -2
- package/build-module/unit-control/index.js.map +1 -1
- package/build-module/unit-control/index.native.js +10 -2
- package/build-module/unit-control/index.native.js.map +1 -1
- package/build-module/unit-control/styles/unit-control-styles.js +20 -31
- package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build-module/utils/hooks/use-controlled-state.js +3 -4
- package/build-module/utils/hooks/use-controlled-state.js.map +1 -1
- package/build-style/style-rtl.css +13 -2
- package/build-style/style.css +13 -2
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/draggable/index.d.ts.map +1 -1
- package/build-types/drop-zone/index.d.ts.map +1 -1
- package/build-types/external-link/styles/external-link-styles.d.ts +1 -1
- package/build-types/focal-point-picker/styles/focal-point-style.d.ts +3 -3
- package/build-types/menu-item/index.d.ts.map +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/popover/limit-shift.d.ts +87 -0
- package/build-types/popover/limit-shift.d.ts.map +1 -0
- package/build-types/popover/stories/e2e/index.d.ts +8 -0
- package/build-types/popover/stories/e2e/index.d.ts.map +1 -0
- package/build-types/popover/test/index.d.ts +2 -0
- package/build-types/popover/test/index.d.ts.map +1 -0
- package/build-types/popover/types.d.ts +1 -1
- package/build-types/popover/types.d.ts.map +1 -1
- package/build-types/popover/utils.d.ts.map +1 -1
- package/build-types/range-control/input-range.d.ts.map +1 -1
- package/build-types/range-control/stories/index.d.ts.map +1 -1
- package/build-types/range-control/types.d.ts +0 -34
- package/build-types/range-control/types.d.ts.map +1 -1
- package/build-types/range-control/utils.d.ts +1 -12
- package/build-types/range-control/utils.d.ts.map +1 -1
- package/build-types/spinner/index.d.ts +1 -1
- package/build-types/tools-panel/styles.d.ts +6 -0
- package/build-types/tools-panel/styles.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/hook.d.ts +1 -0
- package/build-types/tools-panel/tools-panel-header/hook.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +1 -0
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -4
- package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
- package/build-types/utils/hooks/use-controlled-state.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/autocomplete/get-default-use-items.js +1 -1
- package/src/box-control/unit-control.js +0 -1
- package/src/button/index.js +7 -1
- package/src/button/test/index.js +36 -0
- package/src/color-palette/test/__snapshots__/index.js.snap +169 -1106
- package/src/color-palette/test/index.js +107 -61
- package/src/draggable/index.js +2 -5
- package/src/drop-zone/index.tsx +4 -1
- package/src/font-size-picker/stories/e2e/index.js +47 -0
- package/src/higher-order/with-filters/index.js +2 -2
- package/src/index.js +1 -1
- package/src/menu-item/README.md +7 -0
- package/src/menu-item/index.js +11 -5
- package/src/menu-item/style.scss +1 -0
- package/src/menu-item/test/index.js +36 -0
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +9 -0
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +12 -2
- package/src/mobile/bottom-sheet/sub-sheet/index.native.js +3 -0
- package/src/mobile/color-settings/index.native.js +3 -0
- package/src/mobile/color-settings/picker-screen.native.js +3 -0
- package/src/mobile/image/index.native.js +3 -0
- package/src/mobile/keyboard-avoiding-view/index.ios.js +3 -0
- package/src/mobile/link-picker/index.native.js +3 -0
- package/src/mobile/link-picker/link-picker-results.native.js +4 -1
- package/src/mobile/link-picker/link-picker-screen.native.js +3 -0
- package/src/mobile/link-settings/index.native.js +18 -0
- package/src/mobile/link-settings/link-settings-screen.native.js +3 -0
- package/src/mobile/segmented-control/index.native.js +6 -0
- package/src/mobile/utils/use-unit-converter-to-mobile.native.js +6 -0
- package/src/notice/index.native.js +17 -20
- package/src/notice/list.native.js +7 -3
- package/src/palette-edit/index.js +1 -1
- package/src/placeholder/style.scss +1 -1
- package/src/popover/index.tsx +26 -42
- package/src/popover/limit-shift.ts +205 -0
- package/src/popover/stories/e2e/index.tsx +25 -0
- package/src/popover/test/index.tsx +230 -0
- package/src/popover/types.ts +1 -0
- package/src/popover/utils.ts +58 -16
- package/src/range-control/README.md +6 -7
- package/src/range-control/input-range.tsx +1 -21
- package/src/range-control/stories/index.tsx +2 -1
- package/src/range-control/tooltip.tsx +1 -1
- package/src/range-control/types.ts +0 -35
- package/src/range-control/utils.ts +3 -75
- package/src/tools-panel/stories/index.js +27 -0
- package/src/tools-panel/styles.ts +28 -1
- package/src/tools-panel/tools-panel-header/component.tsx +12 -5
- package/src/tools-panel/tools-panel-header/hook.ts +5 -0
- package/src/tools-panel/types.ts +1 -0
- package/src/tree-grid/index.js +23 -14
- package/src/tree-grid/test/__snapshots__/cell.js.snap +21 -17
- package/src/tree-grid/test/__snapshots__/index.js.snap +1 -1
- package/src/unit-control/index.native.js +8 -0
- package/src/unit-control/index.tsx +2 -2
- package/src/unit-control/styles/unit-control-styles.ts +0 -20
- package/src/unit-control/test/index.tsx +6 -3
- package/src/utils/hooks/use-controlled-state.js +9 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/src/popover/test/__snapshots__/index.js.snap +0 -34
- package/src/popover/test/index.js +0 -164
- package/src/unit-control/test/__snapshots__/index.tsx.snap +0 -31
|
@@ -37,6 +37,9 @@ const LinkSettingsScreen = ( props ) => {
|
|
|
37
37
|
urlValue={ inputValue }
|
|
38
38
|
/>
|
|
39
39
|
);
|
|
40
|
+
// Disable reason: deferring this refactor to the native team.
|
|
41
|
+
// see https://github.com/WordPress/gutenberg/pull/41166
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
43
|
}, [ props, inputValue, navigation, route ] );
|
|
41
44
|
};
|
|
42
45
|
|
|
@@ -74,12 +74,18 @@ const SegmentedControls = ( {
|
|
|
74
74
|
useEffect( () => {
|
|
75
75
|
setActiveSegmentIndex( selectedSegmentIndex );
|
|
76
76
|
segmentHandler( segments[ selectedSegmentIndex ] );
|
|
77
|
+
// Disable reason: deferring this refactor to the native team.
|
|
78
|
+
// see https://github.com/WordPress/gutenberg/pull/41166
|
|
79
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
80
|
}, [] );
|
|
78
81
|
|
|
79
82
|
useEffect( () => {
|
|
80
83
|
positionAnimationValue.setValue(
|
|
81
84
|
calculateEndValue( activeSegmentIndex )
|
|
82
85
|
);
|
|
86
|
+
// Disable reason: deferring this refactor to the native team.
|
|
87
|
+
// see https://github.com/WordPress/gutenberg/pull/41166
|
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
89
|
}, [ segmentsDimensions ] );
|
|
84
90
|
|
|
85
91
|
const containerStyle = usePreferredColorSchemeStyle(
|
|
@@ -78,6 +78,9 @@ const useConvertUnitToMobile = ( value, unit ) => {
|
|
|
78
78
|
return () => {
|
|
79
79
|
dimensionsChangeSubscription.remove();
|
|
80
80
|
};
|
|
81
|
+
// Disable reason: deferring this refactor to the native team.
|
|
82
|
+
// see https://github.com/WordPress/gutenberg/pull/41166
|
|
83
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
81
84
|
}, [] );
|
|
82
85
|
|
|
83
86
|
const onDimensionsChange = useCallback( ( { window } ) => {
|
|
@@ -94,6 +97,9 @@ const useConvertUnitToMobile = ( value, unit ) => {
|
|
|
94
97
|
valueToConvert,
|
|
95
98
|
valueUnit
|
|
96
99
|
);
|
|
100
|
+
// Disable reason: deferring this refactor to the native team.
|
|
101
|
+
// see https://github.com/WordPress/gutenberg/pull/41166
|
|
102
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
103
|
}, [ windowSizes, value, unit ] );
|
|
98
104
|
};
|
|
99
105
|
|
|
@@ -14,7 +14,7 @@ import { BlurView } from '@react-native-community/blur';
|
|
|
14
14
|
/**
|
|
15
15
|
* WordPress dependencies
|
|
16
16
|
*/
|
|
17
|
-
import { useEffect, useRef, Platform } from '@wordpress/element';
|
|
17
|
+
import { useEffect, useRef, useCallback, Platform } from '@wordpress/element';
|
|
18
18
|
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -30,40 +30,37 @@ const Notice = ( { onNoticeHidden, content, id, status } ) => {
|
|
|
30
30
|
const timer = useRef( null );
|
|
31
31
|
|
|
32
32
|
useEffect( () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return () => {
|
|
36
|
-
clearTimeout( timer?.current );
|
|
37
|
-
};
|
|
38
|
-
}, [] );
|
|
39
|
-
|
|
40
|
-
function onHide() {
|
|
33
|
+
// start animation
|
|
41
34
|
Animated.timing( animationValue, {
|
|
42
|
-
toValue:
|
|
43
|
-
duration:
|
|
35
|
+
toValue: 1,
|
|
36
|
+
duration: 300,
|
|
44
37
|
useNativeDriver: true,
|
|
45
38
|
easing: Easing.out( Easing.quad ),
|
|
46
39
|
} ).start( ( { finished } ) => {
|
|
47
40
|
if ( finished && onNoticeHidden ) {
|
|
48
|
-
|
|
41
|
+
timer.current = setTimeout( () => {
|
|
42
|
+
onHide();
|
|
43
|
+
}, HIDE_TIMER );
|
|
49
44
|
}
|
|
50
45
|
} );
|
|
51
|
-
}
|
|
52
46
|
|
|
53
|
-
|
|
47
|
+
return () => {
|
|
48
|
+
clearTimeout( timer?.current );
|
|
49
|
+
};
|
|
50
|
+
}, [ animationValue, onHide, onNoticeHidden ] );
|
|
51
|
+
|
|
52
|
+
const onHide = useCallback( () => {
|
|
54
53
|
Animated.timing( animationValue, {
|
|
55
|
-
toValue:
|
|
56
|
-
duration:
|
|
54
|
+
toValue: 0,
|
|
55
|
+
duration: 150,
|
|
57
56
|
useNativeDriver: true,
|
|
58
57
|
easing: Easing.out( Easing.quad ),
|
|
59
58
|
} ).start( ( { finished } ) => {
|
|
60
59
|
if ( finished && onNoticeHidden ) {
|
|
61
|
-
|
|
62
|
-
onHide();
|
|
63
|
-
}, HIDE_TIMER );
|
|
60
|
+
onNoticeHidden( id );
|
|
64
61
|
}
|
|
65
62
|
} );
|
|
66
|
-
}
|
|
63
|
+
}, [ animationValue, onNoticeHidden, id ] );
|
|
67
64
|
|
|
68
65
|
const noticeSolidStyles = usePreferredColorSchemeStyle(
|
|
69
66
|
styles.noticeSolid,
|
|
@@ -14,6 +14,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
14
14
|
*/
|
|
15
15
|
import Notice from './';
|
|
16
16
|
import styles from './style.scss';
|
|
17
|
+
import { useCallback } from '@wordpress/element';
|
|
17
18
|
|
|
18
19
|
function NoticeList() {
|
|
19
20
|
const { notices } = useSelect( ( select ) => {
|
|
@@ -25,9 +26,12 @@ function NoticeList() {
|
|
|
25
26
|
|
|
26
27
|
const { removeNotice } = useDispatch( noticesStore );
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const onRemoveNotice = useCallback(
|
|
30
|
+
( id ) => {
|
|
31
|
+
removeNotice( id );
|
|
32
|
+
},
|
|
33
|
+
[ removeNotice ]
|
|
34
|
+
);
|
|
31
35
|
|
|
32
36
|
if ( ! notices.length ) {
|
|
33
37
|
return null;
|
|
@@ -316,7 +316,7 @@ export default function PaletteEdit( {
|
|
|
316
316
|
<PaletteHStackHeader>
|
|
317
317
|
<PaletteHeading>{ paletteLabel }</PaletteHeading>
|
|
318
318
|
<PaletteActionsContainer>
|
|
319
|
-
{ isEditing && (
|
|
319
|
+
{ hasElements && isEditing && (
|
|
320
320
|
<DoneButton
|
|
321
321
|
isSmall
|
|
322
322
|
onClick={ () => {
|
package/src/popover/index.tsx
CHANGED
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
autoUpdate,
|
|
11
11
|
arrow,
|
|
12
12
|
offset as offsetMiddleware,
|
|
13
|
-
limitShift,
|
|
14
13
|
size,
|
|
15
14
|
Middleware,
|
|
15
|
+
MiddlewareArguments,
|
|
16
16
|
} from '@floating-ui/react-dom';
|
|
17
17
|
// eslint-disable-next-line no-restricted-imports
|
|
18
18
|
import {
|
|
@@ -34,7 +34,6 @@ import {
|
|
|
34
34
|
useMemo,
|
|
35
35
|
useState,
|
|
36
36
|
useCallback,
|
|
37
|
-
useEffect,
|
|
38
37
|
} from '@wordpress/element';
|
|
39
38
|
import {
|
|
40
39
|
useViewportMatch,
|
|
@@ -65,6 +64,7 @@ import type {
|
|
|
65
64
|
PopoverAnchorRefReference,
|
|
66
65
|
PopoverAnchorRefTopBottom,
|
|
67
66
|
} from './types';
|
|
67
|
+
import { limitShift as customLimitShift } from './limit-shift';
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Name of slot in which popover should fill.
|
|
@@ -281,42 +281,31 @@ const UnforwardedPopover = (
|
|
|
281
281
|
* https://floating-ui.com/docs/react-dom#variables-inside-middleware-functions.
|
|
282
282
|
*/
|
|
283
283
|
const frameOffsetRef = useRef( getFrameOffset( referenceOwnerDocument ) );
|
|
284
|
-
/**
|
|
285
|
-
* Store the offset prop in a ref, due to constraints with floating-ui:
|
|
286
|
-
* https://floating-ui.com/docs/react-dom#variables-inside-middleware-functions.
|
|
287
|
-
*/
|
|
288
|
-
const offsetRef = useRef( offsetProp );
|
|
289
284
|
|
|
290
285
|
const middleware = [
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
mainAxis:
|
|
315
|
-
offsetRef.current +
|
|
316
|
-
frameOffsetRef.current[ mainAxis ] * mainAxisModifier,
|
|
317
|
-
crossAxis: frameOffsetRef.current[ crossAxis ],
|
|
318
|
-
};
|
|
319
|
-
} ),
|
|
286
|
+
// Custom middleware which adjusts the popover's position by taking into
|
|
287
|
+
// account the offset of the anchor's iframe (if any) compared to the page.
|
|
288
|
+
{
|
|
289
|
+
name: 'frameOffset',
|
|
290
|
+
fn( { x, y }: MiddlewareArguments ) {
|
|
291
|
+
if ( ! frameOffsetRef.current ) {
|
|
292
|
+
return {
|
|
293
|
+
x,
|
|
294
|
+
y,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
x: x + frameOffsetRef.current.x,
|
|
300
|
+
y: y + frameOffsetRef.current.y,
|
|
301
|
+
data: {
|
|
302
|
+
// This will be used in the customLimitShift() function.
|
|
303
|
+
amount: frameOffsetRef.current,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
offsetMiddleware( offsetProp ),
|
|
320
309
|
computedFlipProp ? flipMiddleware() : undefined,
|
|
321
310
|
computedResizeProp
|
|
322
311
|
? size( {
|
|
@@ -339,7 +328,7 @@ const UnforwardedPopover = (
|
|
|
339
328
|
shouldShift
|
|
340
329
|
? shiftMiddleware( {
|
|
341
330
|
crossAxis: true,
|
|
342
|
-
limiter:
|
|
331
|
+
limiter: customLimitShift(),
|
|
343
332
|
padding: 1, // Necessary to avoid flickering at the edge of the viewport.
|
|
344
333
|
} )
|
|
345
334
|
: undefined,
|
|
@@ -395,11 +384,6 @@ const UnforwardedPopover = (
|
|
|
395
384
|
} ),
|
|
396
385
|
} );
|
|
397
386
|
|
|
398
|
-
useEffect( () => {
|
|
399
|
-
offsetRef.current = offsetProp;
|
|
400
|
-
update();
|
|
401
|
-
}, [ offsetProp, update ] );
|
|
402
|
-
|
|
403
387
|
const arrowCallbackRef = useCallback(
|
|
404
388
|
( node ) => {
|
|
405
389
|
arrowRef.current = node;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type {
|
|
5
|
+
Axis,
|
|
6
|
+
Coords,
|
|
7
|
+
Placement,
|
|
8
|
+
Side,
|
|
9
|
+
MiddlewareArguments,
|
|
10
|
+
} from '@floating-ui/react-dom';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parts of this source were derived and modified from `floating-ui`,
|
|
14
|
+
* released under the MIT license.
|
|
15
|
+
*
|
|
16
|
+
* https://github.com/floating-ui/floating-ui
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2021 Floating UI contributors
|
|
19
|
+
*
|
|
20
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
22
|
+
* in the Software without restriction, including without limitation the rights
|
|
23
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
25
|
+
* furnished to do so, subject to the following conditions:
|
|
26
|
+
*
|
|
27
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
28
|
+
* copies or substantial portions of the Software.
|
|
29
|
+
*
|
|
30
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
33
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
35
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
36
|
+
* SOFTWARE.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Custom limiter function for the `shift` middleware.
|
|
41
|
+
* This function is mostly identical default `limitShift` from ``@floating-ui`;
|
|
42
|
+
* the only difference is that, when computing the min/max shift limits, it
|
|
43
|
+
* also takes into account the iframe offset that is added by the
|
|
44
|
+
* custom "frameOffset" middleware.
|
|
45
|
+
*
|
|
46
|
+
* All unexported types and functions are also from the `@floating-ui` library,
|
|
47
|
+
* and have been copied to this file for convenience.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
type LimitShiftOffset =
|
|
51
|
+
| ( ( args: MiddlewareArguments ) =>
|
|
52
|
+
| number
|
|
53
|
+
| {
|
|
54
|
+
/**
|
|
55
|
+
* Offset the limiting of the axis that runs along the alignment of the
|
|
56
|
+
* floating element.
|
|
57
|
+
*/
|
|
58
|
+
mainAxis?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Offset the limiting of the axis that runs along the side of the
|
|
61
|
+
* floating element.
|
|
62
|
+
*/
|
|
63
|
+
crossAxis?: number;
|
|
64
|
+
} )
|
|
65
|
+
| number
|
|
66
|
+
| {
|
|
67
|
+
/**
|
|
68
|
+
* Offset the limiting of the axis that runs along the alignment of the
|
|
69
|
+
* floating element.
|
|
70
|
+
*/
|
|
71
|
+
mainAxis?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Offset the limiting of the axis that runs along the side of the
|
|
74
|
+
* floating element.
|
|
75
|
+
*/
|
|
76
|
+
crossAxis?: number;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type LimitShiftOptions = {
|
|
80
|
+
/**
|
|
81
|
+
* Offset when limiting starts. `0` will limit when the opposite edges of the
|
|
82
|
+
* reference and floating elements are aligned.
|
|
83
|
+
* - positive = start limiting earlier
|
|
84
|
+
* - negative = start limiting later
|
|
85
|
+
*/
|
|
86
|
+
offset: LimitShiftOffset;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to limit the axis that runs along the alignment of the floating
|
|
89
|
+
* element.
|
|
90
|
+
*/
|
|
91
|
+
mainAxis: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to limit the axis that runs along the side of the floating element.
|
|
94
|
+
*/
|
|
95
|
+
crossAxis: boolean;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function getSide( placement: Placement ): Side {
|
|
99
|
+
return placement.split( '-' )[ 0 ] as Side;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getMainAxisFromPlacement( placement: Placement ): Axis {
|
|
103
|
+
return [ 'top', 'bottom' ].includes( getSide( placement ) ) ? 'x' : 'y';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getCrossAxis( axis: Axis ): Axis {
|
|
107
|
+
return axis === 'x' ? 'y' : 'x';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const limitShift = (
|
|
111
|
+
options: Partial< LimitShiftOptions > = {}
|
|
112
|
+
): {
|
|
113
|
+
options: Partial< LimitShiftOffset >;
|
|
114
|
+
fn: ( middlewareArguments: MiddlewareArguments ) => Coords;
|
|
115
|
+
} => ( {
|
|
116
|
+
options,
|
|
117
|
+
fn( middlewareArguments ) {
|
|
118
|
+
const { x, y, placement, rects, middlewareData } = middlewareArguments;
|
|
119
|
+
const {
|
|
120
|
+
offset = 0,
|
|
121
|
+
mainAxis: checkMainAxis = true,
|
|
122
|
+
crossAxis: checkCrossAxis = true,
|
|
123
|
+
} = options;
|
|
124
|
+
|
|
125
|
+
const coords = { x, y };
|
|
126
|
+
const mainAxis = getMainAxisFromPlacement( placement );
|
|
127
|
+
const crossAxis = getCrossAxis( mainAxis );
|
|
128
|
+
|
|
129
|
+
let mainAxisCoord = coords[ mainAxis ];
|
|
130
|
+
let crossAxisCoord = coords[ crossAxis ];
|
|
131
|
+
|
|
132
|
+
const rawOffset =
|
|
133
|
+
typeof offset === 'function'
|
|
134
|
+
? offset( middlewareArguments )
|
|
135
|
+
: offset;
|
|
136
|
+
const computedOffset =
|
|
137
|
+
typeof rawOffset === 'number'
|
|
138
|
+
? { mainAxis: rawOffset, crossAxis: 0 }
|
|
139
|
+
: { mainAxis: 0, crossAxis: 0, ...rawOffset };
|
|
140
|
+
|
|
141
|
+
// At the moment of writing, this is the only difference
|
|
142
|
+
// with the `limitShift` function from `@floating-ui`.
|
|
143
|
+
// This offset needs to be added to all min/max limits
|
|
144
|
+
// in order to make the shift-limiting work as expected.
|
|
145
|
+
const additionalFrameOffset = {
|
|
146
|
+
x: 0,
|
|
147
|
+
y: 0,
|
|
148
|
+
...middlewareData.frameOffset?.amount,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if ( checkMainAxis ) {
|
|
152
|
+
const len = mainAxis === 'y' ? 'height' : 'width';
|
|
153
|
+
const limitMin =
|
|
154
|
+
rects.reference[ mainAxis ] -
|
|
155
|
+
rects.floating[ len ] +
|
|
156
|
+
computedOffset.mainAxis +
|
|
157
|
+
additionalFrameOffset[ mainAxis ];
|
|
158
|
+
const limitMax =
|
|
159
|
+
rects.reference[ mainAxis ] +
|
|
160
|
+
rects.reference[ len ] -
|
|
161
|
+
computedOffset.mainAxis +
|
|
162
|
+
additionalFrameOffset[ mainAxis ];
|
|
163
|
+
|
|
164
|
+
if ( mainAxisCoord < limitMin ) {
|
|
165
|
+
mainAxisCoord = limitMin;
|
|
166
|
+
} else if ( mainAxisCoord > limitMax ) {
|
|
167
|
+
mainAxisCoord = limitMax;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if ( checkCrossAxis ) {
|
|
172
|
+
const len = mainAxis === 'y' ? 'width' : 'height';
|
|
173
|
+
const isOriginSide = [ 'top', 'left' ].includes(
|
|
174
|
+
getSide( placement )
|
|
175
|
+
);
|
|
176
|
+
const limitMin =
|
|
177
|
+
rects.reference[ crossAxis ] -
|
|
178
|
+
rects.floating[ len ] +
|
|
179
|
+
( isOriginSide
|
|
180
|
+
? middlewareData.offset?.[ crossAxis ] ?? 0
|
|
181
|
+
: 0 ) +
|
|
182
|
+
( isOriginSide ? 0 : computedOffset.crossAxis ) +
|
|
183
|
+
additionalFrameOffset[ crossAxis ];
|
|
184
|
+
const limitMax =
|
|
185
|
+
rects.reference[ crossAxis ] +
|
|
186
|
+
rects.reference[ len ] +
|
|
187
|
+
( isOriginSide
|
|
188
|
+
? 0
|
|
189
|
+
: middlewareData.offset?.[ crossAxis ] ?? 0 ) -
|
|
190
|
+
( isOriginSide ? computedOffset.crossAxis : 0 ) +
|
|
191
|
+
additionalFrameOffset[ crossAxis ];
|
|
192
|
+
|
|
193
|
+
if ( crossAxisCoord < limitMin ) {
|
|
194
|
+
crossAxisCoord = limitMin;
|
|
195
|
+
} else if ( crossAxisCoord > limitMax ) {
|
|
196
|
+
crossAxisCoord = limitMax;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
[ mainAxis ]: mainAxisCoord,
|
|
202
|
+
[ crossAxis ]: crossAxisCoord,
|
|
203
|
+
} as Coords;
|
|
204
|
+
},
|
|
205
|
+
} );
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import Popover from '../..';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Components/Popover',
|
|
13
|
+
component: Popover,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Default = () => {
|
|
17
|
+
const [ isVisible, setIsVisible ] = useState( false );
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<button onClick={ () => setIsVisible( ( state ) => ! state ) }>
|
|
21
|
+
Toggle Popover!
|
|
22
|
+
{ isVisible && <Popover>Popover is toggled!</Popover> }
|
|
23
|
+
</button>
|
|
24
|
+
);
|
|
25
|
+
};
|