@wordpress/components 27.1.0 → 27.3.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 +53 -3
- package/README.md +13 -0
- package/build/button/index.js +3 -4
- package/build/button/index.js.map +1 -1
- package/build/button/types.js.map +1 -1
- package/build/color-picker/component.js +2 -12
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/picker.js +18 -77
- package/build/color-picker/picker.js.map +1 -1
- package/build/color-picker/types.js.map +1 -1
- package/build/custom-select-control-v2/default-component/index.js +4 -2
- package/build/custom-select-control-v2/default-component/index.js.map +1 -1
- package/build/custom-select-control-v2/index.js +1 -8
- package/build/custom-select-control-v2/index.js.map +1 -1
- package/build/custom-select-control-v2/{custom-select-item.js → item.js} +2 -1
- package/build/custom-select-control-v2/{custom-select-item.js.map → item.js.map} +1 -1
- package/build/custom-select-control-v2/legacy-component/index.js +5 -5
- package/build/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build/date-time/date/styles.js +7 -7
- package/build/date-time/date/styles.js.map +1 -1
- package/build/form-token-field/index.js +1 -1
- package/build/form-token-field/index.js.map +1 -1
- package/build/input-control/index.js +1 -1
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/input-field.js +2 -1
- package/build/input-control/input-field.js.map +1 -1
- package/build/mobile/color-settings/palette.screen.native.js +1 -0
- package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build/navigable-container/container.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +162 -120
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +2 -2
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/palette-edit/index.js +18 -12
- package/build/palette-edit/index.js.map +1 -1
- package/build/popover/index.js +7 -34
- package/build/popover/index.js.map +1 -1
- package/build/range-control/styles/range-control-styles.js +29 -29
- package/build/range-control/styles/range-control-styles.js.map +1 -1
- package/build/text-control/types.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/component.js +5 -2
- package/build/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build/tools-panel/tools-panel-header/component.js +1 -1
- package/build/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build/utils/config-values.js +1 -1
- package/build/utils/config-values.js.map +1 -1
- package/build/utils/input/base.js +2 -2
- package/build/utils/input/base.js.map +1 -1
- package/build-module/button/index.js +3 -4
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/types.js.map +1 -1
- package/build-module/color-picker/component.js +3 -13
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/picker.js +19 -78
- package/build-module/color-picker/picker.js.map +1 -1
- package/build-module/color-picker/types.js.map +1 -1
- package/build-module/custom-select-control-v2/default-component/index.js +4 -2
- package/build-module/custom-select-control-v2/default-component/index.js.map +1 -1
- package/build-module/custom-select-control-v2/index.js +1 -2
- package/build-module/custom-select-control-v2/index.js.map +1 -1
- package/build-module/custom-select-control-v2/{custom-select-item.js → item.js} +2 -1
- package/build-module/custom-select-control-v2/{custom-select-item.js.map → item.js.map} +1 -1
- package/build-module/custom-select-control-v2/legacy-component/index.js +4 -4
- package/build-module/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build-module/date-time/date/styles.js +7 -7
- package/build-module/date-time/date/styles.js.map +1 -1
- package/build-module/form-token-field/index.js +1 -1
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/input-control/index.js +1 -1
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/input-field.js +2 -1
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/mobile/color-settings/palette.screen.native.js +1 -0
- package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
- package/build-module/navigable-container/container.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +163 -121
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +2 -2
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/palette-edit/index.js +17 -11
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/popover/index.js +9 -36
- package/build-module/popover/index.js.map +1 -1
- package/build-module/range-control/styles/range-control-styles.js +29 -29
- package/build-module/range-control/styles/range-control-styles.js.map +1 -1
- package/build-module/text-control/types.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js +6 -3
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel-header/component.js +1 -1
- package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build-module/utils/config-values.js +1 -1
- package/build-module/utils/config-values.js.map +1 -1
- package/build-module/utils/input/base.js +2 -2
- package/build-module/utils/input/base.js.map +1 -1
- package/build-style/style-rtl.css +26 -29
- package/build-style/style.css +26 -29
- package/build-types/box-control/styles/box-control-styles.d.ts +1 -1
- package/build-types/button/deprecated.d.ts +4 -10
- package/build-types/button/deprecated.d.ts.map +1 -1
- package/build-types/button/index.d.ts +3 -3
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/button/stories/e2e/index.story.d.ts +1 -1
- package/build-types/button/stories/e2e/index.story.d.ts.map +1 -1
- package/build-types/button/stories/index.story.d.ts +7 -7
- package/build-types/button/stories/index.story.d.ts.map +1 -1
- package/build-types/button/types.d.ts +37 -8
- package/build-types/button/types.d.ts.map +1 -1
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +1 -1
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +1 -1
- package/build-types/color-picker/types.d.ts +0 -3
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/custom-select-control/stories/index.story.d.ts +35 -0
- package/build-types/custom-select-control/stories/index.story.d.ts.map +1 -0
- package/build-types/custom-select-control-v2/default-component/index.d.ts +5 -2
- package/build-types/custom-select-control-v2/default-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/index.d.ts +1 -2
- package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/{custom-select-item.d.ts → item.d.ts} +4 -1
- package/build-types/custom-select-control-v2/item.d.ts.map +1 -0
- package/build-types/custom-select-control-v2/legacy-component/index.d.ts +2 -2
- package/build-types/custom-select-control-v2/legacy-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/stories/default.story.d.ts +2 -2
- package/build-types/custom-select-control-v2/stories/default.story.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/stories/legacy.story.d.ts +4 -2
- package/build-types/custom-select-control-v2/stories/legacy.story.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +1 -1
- package/build-types/dropdown/stories/index.story.d.ts +1 -0
- package/build-types/dropdown/stories/index.story.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts +1 -1
- package/build-types/form-token-field/index.d.ts +1 -1
- package/build-types/input-control/index.d.ts +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/stories/index.story.d.ts.map +1 -1
- package/build-types/navigation/styles/navigation-styles.d.ts +1 -1
- package/build-types/navigator/navigator-back-button/component.d.ts +0 -1
- package/build-types/navigator/navigator-back-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +1 -2
- package/build-types/navigator/navigator-back-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/component.d.ts +0 -1
- package/build-types/navigator/navigator-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +1 -2
- package/build-types/navigator/navigator-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-to-parent-button/component.d.ts +0 -1
- package/build-types/navigator/navigator-to-parent-button/component.d.ts.map +1 -1
- package/build-types/number-control/styles/number-control-styles.d.ts +1 -1
- package/build-types/palette-edit/index.d.ts +6 -3
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/palette-edit/styles.d.ts +2 -2
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/text-control/index.d.ts +1 -1
- package/build-types/text-control/types.d.ts +1 -1
- package/build-types/text-control/types.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +4 -10
- package/build-types/toolbar/toolbar-button/index.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/button/index.tsx +3 -4
- package/src/button/test/index.tsx +6 -6
- package/src/button/types.ts +37 -9
- package/src/color-picker/component.tsx +3 -25
- package/src/color-picker/picker.tsx +12 -96
- package/src/color-picker/types.ts +0 -3
- package/src/confirm-dialog/README.md +7 -0
- package/src/custom-select-control/stories/{index.story.js → index.story.tsx} +8 -3
- package/src/custom-select-control/test/index.js +24 -0
- package/src/custom-select-control-v2/README.md +27 -27
- package/src/custom-select-control-v2/default-component/index.tsx +5 -2
- package/src/custom-select-control-v2/index.tsx +1 -2
- package/src/custom-select-control-v2/{custom-select-item.tsx → item.tsx} +2 -0
- package/src/custom-select-control-v2/legacy-component/index.tsx +4 -6
- package/src/custom-select-control-v2/legacy-component/test/index.tsx +13 -10
- package/src/custom-select-control-v2/stories/default.story.tsx +16 -17
- package/src/custom-select-control-v2/stories/legacy.story.tsx +20 -35
- package/src/custom-select-control-v2/test/index.tsx +26 -16
- package/src/date-time/date/styles.ts +2 -2
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +4 -4
- package/src/dropdown/stories/index.story.tsx +19 -0
- package/src/dropdown/style.scss +26 -0
- package/src/dropdown-menu/style.scss +0 -25
- package/src/flex/flex/README.md +2 -2
- package/src/form-token-field/README.md +1 -1
- package/src/form-token-field/index.tsx +1 -1
- package/src/grid/README.md +11 -11
- package/src/h-stack/README.md +6 -6
- package/src/heading/README.md +1 -1
- package/src/heading/test/__snapshots__/index.tsx.snap +3 -3
- package/src/input-control/README.md +1 -1
- package/src/input-control/index.tsx +1 -1
- package/src/input-control/input-field.tsx +2 -1
- package/src/input-control/stories/index.story.tsx +1 -0
- package/src/item-group/test/__snapshots__/index.js.snap +11 -11
- package/src/mobile/bottom-sheet-select-control/README.md +1 -1
- package/src/mobile/color-settings/palette.screen.native.js +5 -1
- package/src/navigable-container/container.tsx +1 -1
- package/src/navigator/navigator-provider/component.tsx +187 -188
- package/src/navigator/navigator-screen/component.tsx +2 -4
- package/src/palette-edit/index.tsx +21 -21
- package/src/palette-edit/test/index.tsx +21 -17
- package/src/placeholder/style.scss +5 -1
- package/src/popover/index.tsx +59 -99
- package/src/popover/style.scss +0 -9
- package/src/progress-bar/README.md +1 -1
- package/src/radio-control/README.md +3 -3
- package/src/range-control/styles/range-control-styles.ts +1 -1
- package/src/resizable-box/resize-tooltip/README.md +2 -2
- package/src/text/test/__snapshots__/index.tsx.snap +3 -3
- package/src/text-control/style.scss +2 -0
- package/src/text-control/types.ts +12 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +14 -10
- package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +14 -12
- package/src/toolbar/toolbar/style.scss +1 -1
- package/src/tools-panel/tools-panel-header/component.tsx +1 -1
- package/src/truncate/README.md +5 -5
- package/src/utils/config-values.js +1 -1
- package/src/utils/input/base.js +1 -1
- package/src/v-stack/README.md +6 -6
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/custom-select-control-v2/custom-select-item.d.ts.map +0 -1
|
@@ -6,7 +6,7 @@ import { createElement } from "react";
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { useMemo,
|
|
9
|
+
import { useMemo, useReducer } from '@wordpress/element';
|
|
10
10
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -20,14 +20,127 @@ import { View } from '../../view';
|
|
|
20
20
|
import { NavigatorContext } from '../context';
|
|
21
21
|
import * as styles from '../styles';
|
|
22
22
|
const MAX_HISTORY_LENGTH = 50;
|
|
23
|
-
function
|
|
23
|
+
function addScreen({
|
|
24
|
+
screens
|
|
25
|
+
}, screen) {
|
|
26
|
+
return [...screens, screen];
|
|
27
|
+
}
|
|
28
|
+
function removeScreen({
|
|
29
|
+
screens
|
|
30
|
+
}, screen) {
|
|
31
|
+
return screens.filter(s => s.id !== screen.id);
|
|
32
|
+
}
|
|
33
|
+
function goBack({
|
|
34
|
+
locationHistory
|
|
35
|
+
}) {
|
|
36
|
+
if (locationHistory.length <= 1) {
|
|
37
|
+
return locationHistory;
|
|
38
|
+
}
|
|
39
|
+
return [...locationHistory.slice(0, -2), {
|
|
40
|
+
...locationHistory[locationHistory.length - 2],
|
|
41
|
+
isBack: true,
|
|
42
|
+
hasRestoredFocus: false
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
function goTo(state, path, options = {}) {
|
|
46
|
+
const {
|
|
47
|
+
locationHistory
|
|
48
|
+
} = state;
|
|
49
|
+
const {
|
|
50
|
+
focusTargetSelector,
|
|
51
|
+
isBack = false,
|
|
52
|
+
skipFocus = false,
|
|
53
|
+
replace = false,
|
|
54
|
+
...restOptions
|
|
55
|
+
} = options;
|
|
56
|
+
const isNavigatingToPreviousPath = isBack && locationHistory.length > 1 && locationHistory[locationHistory.length - 2].path === path;
|
|
57
|
+
if (isNavigatingToPreviousPath) {
|
|
58
|
+
return goBack(state);
|
|
59
|
+
}
|
|
60
|
+
const newLocation = {
|
|
61
|
+
...restOptions,
|
|
62
|
+
path,
|
|
63
|
+
isBack,
|
|
64
|
+
hasRestoredFocus: false,
|
|
65
|
+
skipFocus
|
|
66
|
+
};
|
|
67
|
+
if (locationHistory.length === 0) {
|
|
68
|
+
return replace ? [] : [newLocation];
|
|
69
|
+
}
|
|
70
|
+
const newLocationHistory = locationHistory.slice(locationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
|
|
71
|
+
if (!replace) {
|
|
72
|
+
newLocationHistory.push(
|
|
73
|
+
// Assign `focusTargetSelector` to the previous location in history
|
|
74
|
+
// (the one we just navigated from).
|
|
75
|
+
{
|
|
76
|
+
...locationHistory[locationHistory.length - 1],
|
|
77
|
+
focusTargetSelector
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
newLocationHistory.push(newLocation);
|
|
81
|
+
return newLocationHistory;
|
|
82
|
+
}
|
|
83
|
+
function goToParent(state, options = {}) {
|
|
84
|
+
const {
|
|
85
|
+
locationHistory,
|
|
86
|
+
screens
|
|
87
|
+
} = state;
|
|
88
|
+
const currentPath = locationHistory[locationHistory.length - 1].path;
|
|
89
|
+
if (currentPath === undefined) {
|
|
90
|
+
return locationHistory;
|
|
91
|
+
}
|
|
92
|
+
const parentPath = findParent(currentPath, screens);
|
|
93
|
+
if (parentPath === undefined) {
|
|
94
|
+
return locationHistory;
|
|
95
|
+
}
|
|
96
|
+
return goTo(state, parentPath, {
|
|
97
|
+
...options,
|
|
98
|
+
isBack: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function routerReducer(state, action) {
|
|
102
|
+
let {
|
|
103
|
+
screens,
|
|
104
|
+
locationHistory,
|
|
105
|
+
matchedPath
|
|
106
|
+
} = state;
|
|
24
107
|
switch (action.type) {
|
|
25
108
|
case 'add':
|
|
26
|
-
|
|
109
|
+
screens = addScreen(state, action.screen);
|
|
110
|
+
break;
|
|
27
111
|
case 'remove':
|
|
28
|
-
|
|
112
|
+
screens = removeScreen(state, action.screen);
|
|
113
|
+
break;
|
|
114
|
+
case 'goback':
|
|
115
|
+
locationHistory = goBack(state);
|
|
116
|
+
break;
|
|
117
|
+
case 'goto':
|
|
118
|
+
locationHistory = goTo(state, action.path, action.options);
|
|
119
|
+
break;
|
|
120
|
+
case 'gotoparent':
|
|
121
|
+
locationHistory = goToParent(state, action.options);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Return early in case there is no change
|
|
126
|
+
if (screens === state.screens && locationHistory === state.locationHistory) {
|
|
127
|
+
return state;
|
|
29
128
|
}
|
|
30
|
-
|
|
129
|
+
|
|
130
|
+
// Compute the matchedPath
|
|
131
|
+
const currentPath = locationHistory.length > 0 ? locationHistory[locationHistory.length - 1].path : undefined;
|
|
132
|
+
matchedPath = currentPath !== undefined ? patternMatch(currentPath, screens) : undefined;
|
|
133
|
+
|
|
134
|
+
// If the new match is the same as the previous match,
|
|
135
|
+
// return the previous one to keep immutability.
|
|
136
|
+
if (matchedPath && state.matchedPath && matchedPath.id === state.matchedPath.id && isShallowEqual(matchedPath.params, state.matchedPath.params)) {
|
|
137
|
+
matchedPath = state.matchedPath;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
screens,
|
|
141
|
+
locationHistory,
|
|
142
|
+
matchedPath
|
|
143
|
+
};
|
|
31
144
|
}
|
|
32
145
|
function UnconnectedNavigatorProvider(props, forwardedRef) {
|
|
33
146
|
const {
|
|
@@ -36,124 +149,53 @@ function UnconnectedNavigatorProvider(props, forwardedRef) {
|
|
|
36
149
|
className,
|
|
37
150
|
...otherProps
|
|
38
151
|
} = useContextSystem(props, 'NavigatorProvider');
|
|
39
|
-
const [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
currentScreens.current = screens;
|
|
47
|
-
}, [screens]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
currentLocationHistory.current = locationHistory;
|
|
50
|
-
}, [locationHistory]);
|
|
51
|
-
const currentMatch = useRef();
|
|
52
|
-
const matchedPath = useMemo(() => {
|
|
53
|
-
let currentPath;
|
|
54
|
-
if (locationHistory.length === 0 || (currentPath = locationHistory[locationHistory.length - 1].path) === undefined) {
|
|
55
|
-
currentMatch.current = undefined;
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
const resolvePath = path => {
|
|
59
|
-
const newMatch = patternMatch(path, screens);
|
|
152
|
+
const [routerState, dispatch] = useReducer(routerReducer, initialPath, path => ({
|
|
153
|
+
screens: [],
|
|
154
|
+
locationHistory: [{
|
|
155
|
+
path
|
|
156
|
+
}],
|
|
157
|
+
matchedPath: undefined
|
|
158
|
+
}));
|
|
60
159
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
160
|
+
// The methods are constant forever, create stable references to them.
|
|
161
|
+
const methods = useMemo(() => ({
|
|
162
|
+
goBack: () => dispatch({
|
|
163
|
+
type: 'goback'
|
|
164
|
+
}),
|
|
165
|
+
goTo: (path, options) => dispatch({
|
|
166
|
+
type: 'goto',
|
|
167
|
+
path,
|
|
168
|
+
options
|
|
169
|
+
}),
|
|
170
|
+
goToParent: options => dispatch({
|
|
171
|
+
type: 'gotoparent',
|
|
172
|
+
options
|
|
173
|
+
}),
|
|
174
|
+
addScreen: screen => dispatch({
|
|
175
|
+
type: 'add',
|
|
176
|
+
screen
|
|
177
|
+
}),
|
|
178
|
+
removeScreen: screen => dispatch({
|
|
179
|
+
type: 'remove',
|
|
180
|
+
screen
|
|
181
|
+
})
|
|
75
182
|
}), []);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}, []);
|
|
92
|
-
const goTo = useCallback((path, options = {}) => {
|
|
93
|
-
const {
|
|
94
|
-
focusTargetSelector,
|
|
95
|
-
isBack = false,
|
|
96
|
-
skipFocus = false,
|
|
97
|
-
replace = false,
|
|
98
|
-
...restOptions
|
|
99
|
-
} = options;
|
|
100
|
-
const isNavigatingToPreviousPath = isBack && currentLocationHistory.current.length > 1 && currentLocationHistory.current[currentLocationHistory.current.length - 2].path === path;
|
|
101
|
-
if (isNavigatingToPreviousPath) {
|
|
102
|
-
goBack();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
setLocationHistory(prevLocationHistory => {
|
|
106
|
-
const newLocation = {
|
|
107
|
-
...restOptions,
|
|
108
|
-
path,
|
|
109
|
-
isBack,
|
|
110
|
-
hasRestoredFocus: false,
|
|
111
|
-
skipFocus
|
|
112
|
-
};
|
|
113
|
-
if (prevLocationHistory.length === 0) {
|
|
114
|
-
return replace ? [] : [newLocation];
|
|
115
|
-
}
|
|
116
|
-
const newLocationHistory = prevLocationHistory.slice(prevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
|
|
117
|
-
if (!replace) {
|
|
118
|
-
newLocationHistory.push(
|
|
119
|
-
// Assign `focusTargetSelector` to the previous location in history
|
|
120
|
-
// (the one we just navigated from).
|
|
121
|
-
{
|
|
122
|
-
...prevLocationHistory[prevLocationHistory.length - 1],
|
|
123
|
-
focusTargetSelector
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
newLocationHistory.push(newLocation);
|
|
127
|
-
return newLocationHistory;
|
|
128
|
-
});
|
|
129
|
-
}, [goBack]);
|
|
130
|
-
const goToParent = useCallback((options = {}) => {
|
|
131
|
-
const currentPath = currentLocationHistory.current[currentLocationHistory.current.length - 1].path;
|
|
132
|
-
if (currentPath === undefined) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const parentPath = findParent(currentPath, currentScreens.current);
|
|
136
|
-
if (parentPath === undefined) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
goTo(parentPath, {
|
|
140
|
-
...options,
|
|
141
|
-
isBack: true
|
|
142
|
-
});
|
|
143
|
-
}, [goTo]);
|
|
144
|
-
const navigatorContextValue = useMemo(() => ({
|
|
145
|
-
location: {
|
|
146
|
-
...locationHistory[locationHistory.length - 1],
|
|
147
|
-
isInitial: locationHistory.length === 1
|
|
148
|
-
},
|
|
149
|
-
params: matchedPath ? matchedPath.params : {},
|
|
150
|
-
match: matchedPath ? matchedPath.id : undefined,
|
|
151
|
-
goTo,
|
|
152
|
-
goBack,
|
|
153
|
-
goToParent,
|
|
154
|
-
addScreen,
|
|
155
|
-
removeScreen
|
|
156
|
-
}), [locationHistory, matchedPath, goTo, goBack, goToParent, addScreen, removeScreen]);
|
|
183
|
+
const {
|
|
184
|
+
locationHistory,
|
|
185
|
+
matchedPath
|
|
186
|
+
} = routerState;
|
|
187
|
+
const navigatorContextValue = useMemo(() => {
|
|
188
|
+
var _matchedPath$params;
|
|
189
|
+
return {
|
|
190
|
+
location: {
|
|
191
|
+
...locationHistory[locationHistory.length - 1],
|
|
192
|
+
isInitial: locationHistory.length === 1
|
|
193
|
+
},
|
|
194
|
+
params: (_matchedPath$params = matchedPath?.params) !== null && _matchedPath$params !== void 0 ? _matchedPath$params : {},
|
|
195
|
+
match: matchedPath?.id,
|
|
196
|
+
...methods
|
|
197
|
+
};
|
|
198
|
+
}, [locationHistory, matchedPath, methods]);
|
|
157
199
|
const cx = useCx();
|
|
158
200
|
const classes = useMemo(() => cx(styles.navigatorProviderWrapper, className), [className, cx]);
|
|
159
201
|
return createElement(View, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useState","useCallback","useReducer","useRef","useEffect","isShallowEqual","contextConnect","useContextSystem","useCx","patternMatch","findParent","View","NavigatorContext","styles","MAX_HISTORY_LENGTH","screensReducer","state","action","type","screen","filter","s","id","UnconnectedNavigatorProvider","props","forwardedRef","initialPath","children","className","otherProps","locationHistory","setLocationHistory","path","currentLocationHistory","screens","dispatch","currentScreens","current","currentMatch","matchedPath","currentPath","length","undefined","resolvePath","newMatch","params","addScreen","removeScreen","goBack","prevLocationHistory","slice","isBack","hasRestoredFocus","goTo","options","focusTargetSelector","skipFocus","replace","restOptions","isNavigatingToPreviousPath","newLocation","newLocationHistory","push","goToParent","parentPath","navigatorContextValue","location","isInitial","match","cx","classes","navigatorProviderWrapper","createElement","ref","Provider","value","NavigatorProvider"],"sources":["@wordpress/components/src/navigator/navigator-provider/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseState,\n\tuseCallback,\n\tuseReducer,\n\tuseRef,\n\tuseEffect,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { patternMatch, findParent } from '../utils/router';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type {\n\tNavigatorProviderProps,\n\tNavigatorLocation,\n\tNavigatorContext as NavigatorContextType,\n\tScreen,\n} from '../types';\n\ntype MatchedPath = ReturnType< typeof patternMatch >;\ntype ScreenAction = { type: string; screen: Screen };\n\nconst MAX_HISTORY_LENGTH = 50;\n\nfunction screensReducer(\n\tstate: Screen[] = [],\n\taction: ScreenAction\n): Screen[] {\n\tswitch ( action.type ) {\n\t\tcase 'add':\n\t\t\treturn [ ...state, action.screen ];\n\t\tcase 'remove':\n\t\t\treturn state.filter( ( s: Screen ) => s.id !== action.screen.id );\n\t}\n\n\treturn state;\n}\n\nfunction UnconnectedNavigatorProvider(\n\tprops: WordPressComponentProps< NavigatorProviderProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst { initialPath, children, className, ...otherProps } =\n\t\tuseContextSystem( props, 'NavigatorProvider' );\n\n\tconst [ locationHistory, setLocationHistory ] = useState<\n\t\tNavigatorLocation[]\n\t>( [\n\t\t{\n\t\t\tpath: initialPath,\n\t\t},\n\t] );\n\tconst currentLocationHistory = useRef< NavigatorLocation[] >( [] );\n\tconst [ screens, dispatch ] = useReducer( screensReducer, [] );\n\tconst currentScreens = useRef< Screen[] >( [] );\n\tuseEffect( () => {\n\t\tcurrentScreens.current = screens;\n\t}, [ screens ] );\n\tuseEffect( () => {\n\t\tcurrentLocationHistory.current = locationHistory;\n\t}, [ locationHistory ] );\n\tconst currentMatch = useRef< MatchedPath >();\n\tconst matchedPath = useMemo( () => {\n\t\tlet currentPath: string | undefined;\n\t\tif (\n\t\t\tlocationHistory.length === 0 ||\n\t\t\t( currentPath =\n\t\t\t\tlocationHistory[ locationHistory.length - 1 ].path ) ===\n\t\t\t\tundefined\n\t\t) {\n\t\t\tcurrentMatch.current = undefined;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst resolvePath = ( path: string ) => {\n\t\t\tconst newMatch = patternMatch( path, screens );\n\n\t\t\t// If the new match is the same as the current match,\n\t\t\t// return the previous one for performance reasons.\n\t\t\tif (\n\t\t\t\tcurrentMatch.current &&\n\t\t\t\tnewMatch &&\n\t\t\t\tisShallowEqual(\n\t\t\t\t\tnewMatch.params,\n\t\t\t\t\tcurrentMatch.current.params\n\t\t\t\t) &&\n\t\t\t\tnewMatch.id === currentMatch.current.id\n\t\t\t) {\n\t\t\t\treturn currentMatch.current;\n\t\t\t}\n\n\t\t\treturn newMatch;\n\t\t};\n\n\t\tconst newMatch = resolvePath( currentPath );\n\t\tcurrentMatch.current = newMatch;\n\t\treturn newMatch;\n\t}, [ screens, locationHistory ] );\n\n\tconst addScreen = useCallback(\n\t\t( screen: Screen ) => dispatch( { type: 'add', screen } ),\n\t\t[]\n\t);\n\n\tconst removeScreen = useCallback(\n\t\t( screen: Screen ) => dispatch( { type: 'remove', screen } ),\n\t\t[]\n\t);\n\n\tconst goBack: NavigatorContextType[ 'goBack' ] = useCallback( () => {\n\t\tsetLocationHistory( ( prevLocationHistory ) => {\n\t\t\tif ( prevLocationHistory.length <= 1 ) {\n\t\t\t\treturn prevLocationHistory;\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t...prevLocationHistory.slice( 0, -2 ),\n\t\t\t\t{\n\t\t\t\t\t...prevLocationHistory[ prevLocationHistory.length - 2 ],\n\t\t\t\t\tisBack: true,\n\t\t\t\t\thasRestoredFocus: false,\n\t\t\t\t},\n\t\t\t];\n\t\t} );\n\t}, [] );\n\n\tconst goTo: NavigatorContextType[ 'goTo' ] = useCallback(\n\t\t( path, options = {} ) => {\n\t\t\tconst {\n\t\t\t\tfocusTargetSelector,\n\t\t\t\tisBack = false,\n\t\t\t\tskipFocus = false,\n\t\t\t\treplace = false,\n\t\t\t\t...restOptions\n\t\t\t} = options;\n\n\t\t\tconst isNavigatingToPreviousPath =\n\t\t\t\tisBack &&\n\t\t\t\tcurrentLocationHistory.current.length > 1 &&\n\t\t\t\tcurrentLocationHistory.current[\n\t\t\t\t\tcurrentLocationHistory.current.length - 2\n\t\t\t\t].path === path;\n\n\t\t\tif ( isNavigatingToPreviousPath ) {\n\t\t\t\tgoBack();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetLocationHistory( ( prevLocationHistory ) => {\n\t\t\t\tconst newLocation = {\n\t\t\t\t\t...restOptions,\n\t\t\t\t\tpath,\n\t\t\t\t\tisBack,\n\t\t\t\t\thasRestoredFocus: false,\n\t\t\t\t\tskipFocus,\n\t\t\t\t};\n\n\t\t\t\tif ( prevLocationHistory.length === 0 ) {\n\t\t\t\t\treturn replace ? [] : [ newLocation ];\n\t\t\t\t}\n\n\t\t\t\tconst newLocationHistory = prevLocationHistory.slice(\n\t\t\t\t\tprevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0,\n\t\t\t\t\t-1\n\t\t\t\t);\n\n\t\t\t\tif ( ! replace ) {\n\t\t\t\t\tnewLocationHistory.push(\n\t\t\t\t\t\t// Assign `focusTargetSelector` to the previous location in history\n\t\t\t\t\t\t// (the one we just navigated from).\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...prevLocationHistory[\n\t\t\t\t\t\t\t\tprevLocationHistory.length - 1\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfocusTargetSelector,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tnewLocationHistory.push( newLocation );\n\n\t\t\t\treturn newLocationHistory;\n\t\t\t} );\n\t\t},\n\t\t[ goBack ]\n\t);\n\n\tconst goToParent: NavigatorContextType[ 'goToParent' ] = useCallback(\n\t\t( options = {} ) => {\n\t\t\tconst currentPath =\n\t\t\t\tcurrentLocationHistory.current[\n\t\t\t\t\tcurrentLocationHistory.current.length - 1\n\t\t\t\t].path;\n\t\t\tif ( currentPath === undefined ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst parentPath = findParent(\n\t\t\t\tcurrentPath,\n\t\t\t\tcurrentScreens.current\n\t\t\t);\n\t\t\tif ( parentPath === undefined ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tgoTo( parentPath, { ...options, isBack: true } );\n\t\t},\n\t\t[ goTo ]\n\t);\n\n\tconst navigatorContextValue: NavigatorContextType = useMemo(\n\t\t() => ( {\n\t\t\tlocation: {\n\t\t\t\t...locationHistory[ locationHistory.length - 1 ],\n\t\t\t\tisInitial: locationHistory.length === 1,\n\t\t\t},\n\t\t\tparams: matchedPath ? matchedPath.params : {},\n\t\t\tmatch: matchedPath ? matchedPath.id : undefined,\n\t\t\tgoTo,\n\t\t\tgoBack,\n\t\t\tgoToParent,\n\t\t\taddScreen,\n\t\t\tremoveScreen,\n\t\t} ),\n\t\t[\n\t\t\tlocationHistory,\n\t\t\tmatchedPath,\n\t\t\tgoTo,\n\t\t\tgoBack,\n\t\t\tgoToParent,\n\t\t\taddScreen,\n\t\t\tremoveScreen,\n\t\t]\n\t);\n\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() => cx( styles.navigatorProviderWrapper, className ),\n\t\t[ className, cx ]\n\t);\n\n\treturn (\n\t\t<View ref={ forwardedRef } className={ classes } { ...otherProps }>\n\t\t\t<NavigatorContext.Provider value={ navigatorContextValue }>\n\t\t\t\t{ children }\n\t\t\t</NavigatorContext.Provider>\n\t\t</View>\n\t);\n}\n\n/**\n * The `NavigatorProvider` component allows rendering nested views/panels/menus\n * (via the `NavigatorScreen` component and navigate between these different\n * view (via the `NavigatorButton` and `NavigatorBackButton` components or the\n * `useNavigator` hook).\n *\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorProvider = contextConnect(\n\tUnconnectedNavigatorProvider,\n\t'NavigatorProvider'\n);\n\nexport default NavigatorProvider;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SACCA,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,UAAU,EACVC,MAAM,EACNC,SAAS,QACH,oBAAoB;AAC3B,OAAOC,cAAc,MAAM,6BAA6B;;AAExD;AACA;AACA;;AAEA,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,eAAe;AAChE,SAASC,KAAK,QAAQ,0BAA0B;AAChD,SAASC,YAAY,EAAEC,UAAU,QAAQ,iBAAiB;AAC1D,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,OAAO,KAAKC,MAAM,MAAM,WAAW;AAWnC,MAAMC,kBAAkB,GAAG,EAAE;AAE7B,SAASC,cAAcA,CACtBC,KAAe,GAAG,EAAE,EACpBC,MAAoB,EACT;EACX,QAASA,MAA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AAExD,MAAM,CAAC0D,wBAAwB,EAAE3C,SAAU,CAAC,EACtD,CAAEA,SAAS,EAAEyC,EAAE,CAChB,CAAC;EAED,OACCG,aAAA,CAAC7D,IAAI;IAAC8D,GAAG,EAAGhD,YAAc;IAACG,SAAS,EAAG0C,OAAS;IAAA,GAAMzC;EAAU,GAC/D2C,aAAA,CAAC5D,gBAAgB,CAAC8D,QAAQ;IAACC,KAAK,EAAGV;EAAuB,GACvDtC,QACwB,CACtB,CAAC;AAET;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMiD,iBAAiB,GAAGtE,cAAc,CAC9CiB,4BAA4B,EAC5B,mBACD,CAAC;AAED,eAAeqD,iBAAiB"}
|
|
1
|
+
{"version":3,"names":["useMemo","useReducer","isShallowEqual","contextConnect","useContextSystem","useCx","patternMatch","findParent","View","NavigatorContext","styles","MAX_HISTORY_LENGTH","addScreen","screens","screen","removeScreen","filter","s","id","goBack","locationHistory","length","slice","isBack","hasRestoredFocus","goTo","state","path","options","focusTargetSelector","skipFocus","replace","restOptions","isNavigatingToPreviousPath","newLocation","newLocationHistory","push","goToParent","currentPath","undefined","parentPath","routerReducer","action","matchedPath","type","params","UnconnectedNavigatorProvider","props","forwardedRef","initialPath","children","className","otherProps","routerState","dispatch","methods","navigatorContextValue","_matchedPath$params","location","isInitial","match","cx","classes","navigatorProviderWrapper","createElement","ref","Provider","value","NavigatorProvider"],"sources":["@wordpress/components/src/navigator/navigator-provider/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { patternMatch, findParent } from '../utils/router';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type {\n\tNavigatorProviderProps,\n\tNavigatorLocation,\n\tNavigatorContext as NavigatorContextType,\n\tNavigateOptions,\n\tScreen,\n\tNavigateToParentOptions,\n} from '../types';\n\ntype MatchedPath = ReturnType< typeof patternMatch >;\n\ntype RouterAction =\n\t| { type: 'add' | 'remove'; screen: Screen }\n\t| { type: 'goback' }\n\t| { type: 'goto'; path: string; options?: NavigateOptions }\n\t| { type: 'gotoparent'; options?: NavigateToParentOptions };\n\ntype RouterState = {\n\tscreens: Screen[];\n\tlocationHistory: NavigatorLocation[];\n\tmatchedPath: MatchedPath;\n};\n\nconst MAX_HISTORY_LENGTH = 50;\n\nfunction addScreen( { screens }: RouterState, screen: Screen ) {\n\treturn [ ...screens, screen ];\n}\n\nfunction removeScreen( { screens }: RouterState, screen: Screen ) {\n\treturn screens.filter( ( s ) => s.id !== screen.id );\n}\n\nfunction goBack( { locationHistory }: RouterState ) {\n\tif ( locationHistory.length <= 1 ) {\n\t\treturn locationHistory;\n\t}\n\treturn [\n\t\t...locationHistory.slice( 0, -2 ),\n\t\t{\n\t\t\t...locationHistory[ locationHistory.length - 2 ],\n\t\t\tisBack: true,\n\t\t\thasRestoredFocus: false,\n\t\t},\n\t];\n}\n\nfunction goTo(\n\tstate: RouterState,\n\tpath: string,\n\toptions: NavigateOptions = {}\n) {\n\tconst { locationHistory } = state;\n\tconst {\n\t\tfocusTargetSelector,\n\t\tisBack = false,\n\t\tskipFocus = false,\n\t\treplace = false,\n\t\t...restOptions\n\t} = options;\n\n\tconst isNavigatingToPreviousPath =\n\t\tisBack &&\n\t\tlocationHistory.length > 1 &&\n\t\tlocationHistory[ locationHistory.length - 2 ].path === path;\n\n\tif ( isNavigatingToPreviousPath ) {\n\t\treturn goBack( state );\n\t}\n\n\tconst newLocation = {\n\t\t...restOptions,\n\t\tpath,\n\t\tisBack,\n\t\thasRestoredFocus: false,\n\t\tskipFocus,\n\t};\n\n\tif ( locationHistory.length === 0 ) {\n\t\treturn replace ? [] : [ newLocation ];\n\t}\n\n\tconst newLocationHistory = locationHistory.slice(\n\t\tlocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0,\n\t\t-1\n\t);\n\n\tif ( ! replace ) {\n\t\tnewLocationHistory.push(\n\t\t\t// Assign `focusTargetSelector` to the previous location in history\n\t\t\t// (the one we just navigated from).\n\t\t\t{\n\t\t\t\t...locationHistory[ locationHistory.length - 1 ],\n\t\t\t\tfocusTargetSelector,\n\t\t\t}\n\t\t);\n\t}\n\n\tnewLocationHistory.push( newLocation );\n\n\treturn newLocationHistory;\n}\n\nfunction goToParent(\n\tstate: RouterState,\n\toptions: NavigateToParentOptions = {}\n) {\n\tconst { locationHistory, screens } = state;\n\tconst currentPath = locationHistory[ locationHistory.length - 1 ].path;\n\tif ( currentPath === undefined ) {\n\t\treturn locationHistory;\n\t}\n\tconst parentPath = findParent( currentPath, screens );\n\tif ( parentPath === undefined ) {\n\t\treturn locationHistory;\n\t}\n\treturn goTo( state, parentPath, {\n\t\t...options,\n\t\tisBack: true,\n\t} );\n}\n\nfunction routerReducer(\n\tstate: RouterState,\n\taction: RouterAction\n): RouterState {\n\tlet { screens, locationHistory, matchedPath } = state;\n\n\tswitch ( action.type ) {\n\t\tcase 'add':\n\t\t\tscreens = addScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'remove':\n\t\t\tscreens = removeScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'goback':\n\t\t\tlocationHistory = goBack( state );\n\t\t\tbreak;\n\t\tcase 'goto':\n\t\t\tlocationHistory = goTo( state, action.path, action.options );\n\t\t\tbreak;\n\t\tcase 'gotoparent':\n\t\t\tlocationHistory = goToParent( state, action.options );\n\t\t\tbreak;\n\t}\n\n\t// Return early in case there is no change\n\tif (\n\t\tscreens === state.screens &&\n\t\tlocationHistory === state.locationHistory\n\t) {\n\t\treturn state;\n\t}\n\n\t// Compute the matchedPath\n\tconst currentPath =\n\t\tlocationHistory.length > 0\n\t\t\t? locationHistory[ locationHistory.length - 1 ].path\n\t\t\t: undefined;\n\tmatchedPath =\n\t\tcurrentPath !== undefined\n\t\t\t? patternMatch( currentPath, screens )\n\t\t\t: undefined;\n\n\t// If the new match is the same as the previous match,\n\t// return the previous one to keep immutability.\n\tif (\n\t\tmatchedPath &&\n\t\tstate.matchedPath &&\n\t\tmatchedPath.id === state.matchedPath.id &&\n\t\tisShallowEqual( matchedPath.params, state.matchedPath.params )\n\t) {\n\t\tmatchedPath = state.matchedPath;\n\t}\n\n\treturn { screens, locationHistory, matchedPath };\n}\n\nfunction UnconnectedNavigatorProvider(\n\tprops: WordPressComponentProps< NavigatorProviderProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst { initialPath, children, className, ...otherProps } =\n\t\tuseContextSystem( props, 'NavigatorProvider' );\n\n\tconst [ routerState, dispatch ] = useReducer(\n\t\trouterReducer,\n\t\tinitialPath,\n\t\t( path ) => ( {\n\t\t\tscreens: [],\n\t\t\tlocationHistory: [ { path } ],\n\t\t\tmatchedPath: undefined,\n\t\t} )\n\t);\n\n\t// The methods are constant forever, create stable references to them.\n\tconst methods = useMemo(\n\t\t() => ( {\n\t\t\tgoBack: () => dispatch( { type: 'goback' } ),\n\t\t\tgoTo: ( path: string, options?: NavigateOptions ) =>\n\t\t\t\tdispatch( { type: 'goto', path, options } ),\n\t\t\tgoToParent: ( options: NavigateToParentOptions | undefined ) =>\n\t\t\t\tdispatch( { type: 'gotoparent', options } ),\n\t\t\taddScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'add', screen } ),\n\t\t\tremoveScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'remove', screen } ),\n\t\t} ),\n\t\t[]\n\t);\n\n\tconst { locationHistory, matchedPath } = routerState;\n\n\tconst navigatorContextValue: NavigatorContextType = useMemo(\n\t\t() => ( {\n\t\t\tlocation: {\n\t\t\t\t...locationHistory[ locationHistory.length - 1 ],\n\t\t\t\tisInitial: locationHistory.length === 1,\n\t\t\t},\n\t\t\tparams: matchedPath?.params ?? {},\n\t\t\tmatch: matchedPath?.id,\n\t\t\t...methods,\n\t\t} ),\n\t\t[ locationHistory, matchedPath, methods ]\n\t);\n\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() => cx( styles.navigatorProviderWrapper, className ),\n\t\t[ className, cx ]\n\t);\n\n\treturn (\n\t\t<View ref={ forwardedRef } className={ classes } { ...otherProps }>\n\t\t\t<NavigatorContext.Provider value={ navigatorContextValue }>\n\t\t\t\t{ children }\n\t\t\t</NavigatorContext.Provider>\n\t\t</View>\n\t);\n}\n\n/**\n * The `NavigatorProvider` component allows rendering nested views/panels/menus\n * (via the `NavigatorScreen` component and navigate between these different\n * view (via the `NavigatorButton` and `NavigatorBackButton` components or the\n * `useNavigator` hook).\n *\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorProvider = contextConnect(\n\tUnconnectedNavigatorProvider,\n\t'NavigatorProvider'\n);\n\nexport default NavigatorProvider;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,OAAO,E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AAED,eAAesB,iBAAiB"}
|
|
@@ -84,14 +84,14 @@ function UnconnectedNavigatorScreen(props, forwardedRef) {
|
|
|
84
84
|
|
|
85
85
|
// When navigating back, if a selector is provided, use it to look for the
|
|
86
86
|
// target element (assumed to be a node inside the current NavigatorScreen)
|
|
87
|
-
if (location.isBack && location
|
|
87
|
+
if (location.isBack && location.focusTargetSelector) {
|
|
88
88
|
elementToFocus = wrapperRef.current.querySelector(location.focusTargetSelector);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// If the previous query didn't run or find any element to focus, fallback
|
|
92
92
|
// to the first tabbable element in the screen (or the screen itself).
|
|
93
93
|
if (!elementToFocus) {
|
|
94
|
-
const firstTabbable = focus.tabbable.find(wrapperRef.current)
|
|
94
|
+
const [firstTabbable] = focus.tabbable.find(wrapperRef.current);
|
|
95
95
|
elementToFocus = firstTabbable !== null && firstTabbable !== void 0 ? firstTabbable : wrapperRef.current;
|
|
96
96
|
}
|
|
97
97
|
locationRef.current.hasRestoredFocus = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["focus","useContext","useEffect","useMemo","useRef","useId","useMergeRefs","isRTL","isRTLFn","escapeAttribute","contextConnect","useContextSystem","useCx","View","NavigatorContext","styles","UnconnectedNavigatorScreen","props","forwardedRef","screenId","children","className","path","otherProps","location","match","addScreen","removeScreen","isMatch","wrapperRef","screen","id","isInitial","isBack","cx","classes","navigatorScreen","locationRef","current","isInitialLocation","hasRestoredFocus","skipFocus","activeElement","ownerDocument","contains","elementToFocus","focusTargetSelector","querySelector","firstTabbable","tabbable","find","mergedWrapperRef","createElement","ref","NavigatorScreen"],"sources":["@wordpress/components/src/navigator/navigator-screen/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseId,\n} from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport { isRTL as isRTLFn } from '@wordpress/i18n';\nimport { escapeAttribute } from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type { NavigatorScreenProps } from '../types';\n\nfunction UnconnectedNavigatorScreen(\n\tprops: WordPressComponentProps< NavigatorScreenProps, 'div', false >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst screenId = useId();\n\tconst { children, className, path, ...otherProps } = useContextSystem(\n\t\tprops,\n\t\t'NavigatorScreen'\n\t);\n\n\tconst { location, match, addScreen, removeScreen } =\n\t\tuseContext( NavigatorContext );\n\tconst isMatch = match === screenId;\n\tconst wrapperRef = useRef< HTMLDivElement >( null );\n\n\tuseEffect( () => {\n\t\tconst screen = {\n\t\t\tid: screenId,\n\t\t\tpath: escapeAttribute( path ),\n\t\t};\n\t\taddScreen( screen );\n\t\treturn () => removeScreen( screen );\n\t}, [ screenId, path, addScreen, removeScreen ] );\n\n\tconst isRTL = isRTLFn();\n\tconst { isInitial, isBack } = location;\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() =>\n\t\t\tcx(\n\t\t\t\tstyles.navigatorScreen( {\n\t\t\t\t\tisInitial,\n\t\t\t\t\tisBack,\n\t\t\t\t\tisRTL,\n\t\t\t\t} ),\n\t\t\t\tclassName\n\t\t\t),\n\t\t[ className, cx, isInitial, isBack, isRTL ]\n\t);\n\n\tconst locationRef = useRef( location );\n\n\tuseEffect( () => {\n\t\tlocationRef.current = location;\n\t}, [ location ] );\n\n\t// Focus restoration\n\tconst isInitialLocation = location.isInitial && ! location.isBack;\n\tuseEffect( () => {\n\t\t// Only attempt to restore focus:\n\t\t// - if the current location is not the initial one (to avoid moving focus on page load)\n\t\t// - when the screen becomes visible\n\t\t// - if the wrapper ref has been assigned\n\t\t// - if focus hasn't already been restored for the current location\n\t\t// - if the `skipFocus` option is not set to `true`. This is useful when we trigger the navigation outside of NavigatorScreen.\n\t\tif (\n\t\t\tisInitialLocation ||\n\t\t\t! isMatch ||\n\t\t\t! wrapperRef.current ||\n\t\t\tlocationRef.current.hasRestoredFocus ||\n\t\t\tlocation.skipFocus\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst activeElement = wrapperRef.current.ownerDocument.activeElement;\n\n\t\t// If an element is already focused within the wrapper do not focus the\n\t\t// element. This prevents inputs or buttons from losing focus unnecessarily.\n\t\tif ( wrapperRef.current.contains( activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet elementToFocus: HTMLElement | null = null;\n\n\t\t// When navigating back, if a selector is provided, use it to look for the\n\t\t// target element (assumed to be a node inside the current NavigatorScreen)\n\t\tif ( location.isBack && location
|
|
1
|
+
{"version":3,"names":["focus","useContext","useEffect","useMemo","useRef","useId","useMergeRefs","isRTL","isRTLFn","escapeAttribute","contextConnect","useContextSystem","useCx","View","NavigatorContext","styles","UnconnectedNavigatorScreen","props","forwardedRef","screenId","children","className","path","otherProps","location","match","addScreen","removeScreen","isMatch","wrapperRef","screen","id","isInitial","isBack","cx","classes","navigatorScreen","locationRef","current","isInitialLocation","hasRestoredFocus","skipFocus","activeElement","ownerDocument","contains","elementToFocus","focusTargetSelector","querySelector","firstTabbable","tabbable","find","mergedWrapperRef","createElement","ref","NavigatorScreen"],"sources":["@wordpress/components/src/navigator/navigator-screen/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseId,\n} from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport { isRTL as isRTLFn } from '@wordpress/i18n';\nimport { escapeAttribute } from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type { NavigatorScreenProps } from '../types';\n\nfunction UnconnectedNavigatorScreen(\n\tprops: WordPressComponentProps< NavigatorScreenProps, 'div', false >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst screenId = useId();\n\tconst { children, className, path, ...otherProps } = useContextSystem(\n\t\tprops,\n\t\t'NavigatorScreen'\n\t);\n\n\tconst { location, match, addScreen, removeScreen } =\n\t\tuseContext( NavigatorContext );\n\tconst isMatch = match === screenId;\n\tconst wrapperRef = useRef< HTMLDivElement >( null );\n\n\tuseEffect( () => {\n\t\tconst screen = {\n\t\t\tid: screenId,\n\t\t\tpath: escapeAttribute( path ),\n\t\t};\n\t\taddScreen( screen );\n\t\treturn () => removeScreen( screen );\n\t}, [ screenId, path, addScreen, removeScreen ] );\n\n\tconst isRTL = isRTLFn();\n\tconst { isInitial, isBack } = location;\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() =>\n\t\t\tcx(\n\t\t\t\tstyles.navigatorScreen( {\n\t\t\t\t\tisInitial,\n\t\t\t\t\tisBack,\n\t\t\t\t\tisRTL,\n\t\t\t\t} ),\n\t\t\t\tclassName\n\t\t\t),\n\t\t[ className, cx, isInitial, isBack, isRTL ]\n\t);\n\n\tconst locationRef = useRef( location );\n\n\tuseEffect( () => {\n\t\tlocationRef.current = location;\n\t}, [ location ] );\n\n\t// Focus restoration\n\tconst isInitialLocation = location.isInitial && ! location.isBack;\n\tuseEffect( () => {\n\t\t// Only attempt to restore focus:\n\t\t// - if the current location is not the initial one (to avoid moving focus on page load)\n\t\t// - when the screen becomes visible\n\t\t// - if the wrapper ref has been assigned\n\t\t// - if focus hasn't already been restored for the current location\n\t\t// - if the `skipFocus` option is not set to `true`. This is useful when we trigger the navigation outside of NavigatorScreen.\n\t\tif (\n\t\t\tisInitialLocation ||\n\t\t\t! isMatch ||\n\t\t\t! wrapperRef.current ||\n\t\t\tlocationRef.current.hasRestoredFocus ||\n\t\t\tlocation.skipFocus\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst activeElement = wrapperRef.current.ownerDocument.activeElement;\n\n\t\t// If an element is already focused within the wrapper do not focus the\n\t\t// element. This prevents inputs or buttons from losing focus unnecessarily.\n\t\tif ( wrapperRef.current.contains( activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet elementToFocus: HTMLElement | null = null;\n\n\t\t// When navigating back, if a selector is provided, use it to look for the\n\t\t// target element (assumed to be a node inside the current NavigatorScreen)\n\t\tif ( location.isBack && location.focusTargetSelector ) {\n\t\t\telementToFocus = wrapperRef.current.querySelector(\n\t\t\t\tlocation.focusTargetSelector\n\t\t\t);\n\t\t}\n\n\t\t// If the previous query didn't run or find any element to focus, fallback\n\t\t// to the first tabbable element in the screen (or the screen itself).\n\t\tif ( ! elementToFocus ) {\n\t\t\tconst [ firstTabbable ] = focus.tabbable.find( wrapperRef.current );\n\t\t\telementToFocus = firstTabbable ?? wrapperRef.current;\n\t\t}\n\n\t\tlocationRef.current.hasRestoredFocus = true;\n\t\telementToFocus.focus();\n\t}, [\n\t\tisInitialLocation,\n\t\tisMatch,\n\t\tlocation.isBack,\n\t\tlocation.focusTargetSelector,\n\t\tlocation.skipFocus,\n\t] );\n\n\tconst mergedWrapperRef = useMergeRefs( [ forwardedRef, wrapperRef ] );\n\n\treturn isMatch ? (\n\t\t<View ref={ mergedWrapperRef } className={ classes } { ...otherProps }>\n\t\t\t{ children }\n\t\t</View>\n\t) : null;\n}\n\n/**\n * The `NavigatorScreen` component represents a single view/screen/panel and\n * should be used in combination with the `NavigatorProvider`, the\n * `NavigatorButton` and the `NavigatorBackButton` components (or the `useNavigator`\n * hook).\n *\n * @example\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorScreen = contextConnect(\n\tUnconnectedNavigatorScreen,\n\t'NavigatorScreen'\n);\n\nexport default NavigatorScreen;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,gBAAgB;AACtC,SACCC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,KAAK,QACC,oBAAoB;AAC3B,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,KAAK,IAAIC,OAAO,QAAQ,iBAAiB;AAClD,SAASC,eAAe,QAAQ,wBAAwB;;AAExD;AACA;AACA;;AAEA,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,eAAe;AAChE,SAASC,KAAK,QAAQ,0BAA0B;AAChD,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,OAAO,KAAKC,MAAM,MAAM,WAAW;AAGnC,SAASC,0BAA0BA,CAClCC,KAAoE,EACpEC,YAAiC,EAChC;EACD,MAAMC,QAAQ,GAAGd,KAAK,CAAC,CAAC;EACxB,MAAM;IAAEe,QAAQ;IAAEC,SAAS;IAAEC,IAAI;IAAE,GAAGC;EAAW,CAAC,GAAGZ,gBAAgB,CACpEM,KAAK,EACL,iBACD,CAAC;EAED,MAAM;IAAEO,QAAQ;IAAEC,KAAK;IAAE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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMkC,eAAe,GAAG5C,cAAc,CAC5CM,0BAA0B,EAC1B,iBACD,CAAC;AAED,eAAesC,eAAe"}
|
|
@@ -45,7 +45,7 @@ function NameInput({
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Returns a name for a palette item
|
|
48
|
+
* Returns a name and slug for a palette item. The name takes the format "Color + id".
|
|
49
49
|
* To ensure there are no duplicate ids, this function checks all slugs.
|
|
50
50
|
* It expects slugs to be in the format: slugPrefix + color- + number.
|
|
51
51
|
* It then sets the id component of the new name based on the incremented id of the highest existing slug id.
|
|
@@ -53,9 +53,9 @@ function NameInput({
|
|
|
53
53
|
* @param elements An array of color palette items.
|
|
54
54
|
* @param slugPrefix The slug prefix used to match the element slug.
|
|
55
55
|
*
|
|
56
|
-
* @return A
|
|
56
|
+
* @return A name and slug for the new palette item.
|
|
57
57
|
*/
|
|
58
|
-
export function
|
|
58
|
+
export function getNameAndSlugForPosition(elements, slugPrefix) {
|
|
59
59
|
const nameRegex = new RegExp(`^${slugPrefix}color-([\\d]+)$`);
|
|
60
60
|
const position = elements.reduce((previousValue, currentValue) => {
|
|
61
61
|
if (typeof currentValue?.slug === 'string') {
|
|
@@ -69,8 +69,11 @@ export function getNameForPosition(elements, slugPrefix) {
|
|
|
69
69
|
}
|
|
70
70
|
return previousValue;
|
|
71
71
|
}, 1);
|
|
72
|
-
return
|
|
73
|
-
|
|
72
|
+
return {
|
|
73
|
+
name: sprintf( /* translators: %s: is an id for a custom color */
|
|
74
|
+
__('Color %s'), position),
|
|
75
|
+
slug: `${slugPrefix}color-${position}`
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
function ColorPickerPopover({
|
|
76
79
|
isGradient,
|
|
@@ -298,18 +301,21 @@ export function PaletteEdit({
|
|
|
298
301
|
icon: plus,
|
|
299
302
|
label: isGradient ? __('Add gradient') : __('Add color'),
|
|
300
303
|
onClick: () => {
|
|
301
|
-
const
|
|
304
|
+
const {
|
|
305
|
+
name,
|
|
306
|
+
slug
|
|
307
|
+
} = getNameAndSlugForPosition(elements, slugPrefix);
|
|
302
308
|
if (!!gradients) {
|
|
303
309
|
onChange([...gradients, {
|
|
304
310
|
gradient: DEFAULT_GRADIENT,
|
|
305
|
-
name
|
|
306
|
-
slug
|
|
311
|
+
name,
|
|
312
|
+
slug
|
|
307
313
|
}]);
|
|
308
314
|
} else {
|
|
309
315
|
onChange([...colors, {
|
|
310
316
|
color: DEFAULT_COLOR,
|
|
311
|
-
name
|
|
312
|
-
slug
|
|
317
|
+
name,
|
|
318
|
+
slug
|
|
313
319
|
}]);
|
|
314
320
|
}
|
|
315
321
|
setIsEditing(true);
|
|
@@ -319,7 +325,7 @@ export function PaletteEdit({
|
|
|
319
325
|
icon: moreVertical,
|
|
320
326
|
label: isGradient ? __('Gradient options') : __('Color options'),
|
|
321
327
|
toggleProps: {
|
|
322
|
-
|
|
328
|
+
size: 'small'
|
|
323
329
|
}
|
|
324
330
|
}, ({
|
|
325
331
|
onClose
|