@react-navigation/core 8.0.0-alpha.3 → 8.0.0-alpha.30
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/lib/module/BaseNavigationContainer.js +34 -17
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/ConsumedParamsContext.js +5 -0
- package/lib/module/ConsumedParamsContext.js.map +1 -0
- package/lib/module/DataLoading.js +127 -0
- package/lib/module/DataLoading.js.map +1 -0
- package/lib/module/NavigationBuilderContext.js +1 -0
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +17 -8
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +22 -11
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +37 -27
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +7 -40
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +179 -50
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/StaticTreeContext.js +5 -0
- package/lib/module/StaticTreeContext.js.map +1 -0
- package/lib/module/checkSerializable.js +18 -13
- package/lib/module/checkSerializable.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js +6 -8
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +27 -5
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/findFocusedRoute.js +7 -4
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +45 -20
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +171 -90
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +20 -4
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +485 -214
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/getStateFromRouteParams.js +24 -0
- package/lib/module/getStateFromRouteParams.js.map +1 -0
- package/lib/module/index.js +5 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js +35 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +19 -11
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +48 -33
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEvents.js +12 -4
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +2 -2
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js +7 -12
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js +4 -2
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useLazyValue.js.map +1 -1
- package/lib/module/useNavigation.js +2 -15
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +201 -131
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +22 -17
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +28 -10
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useNavigationState.js +70 -35
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +37 -7
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +6 -3
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +39 -30
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +10 -5
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +10 -3
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +1 -1
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js +2 -2
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useRoute.js +2 -0
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useRouteCache.js +17 -11
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +9 -9
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/module/useStateForPath.js +1 -1
- package/lib/module/useStateForPath.js.map +1 -1
- package/lib/module/useSyncState.js +7 -3
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/validatePathConfig.js +50 -36
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/ConsumedParamsContext.d.ts +3 -0
- package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
- package/lib/typescript/src/DataLoading.d.ts +21 -0
- package/lib/typescript/src/DataLoading.d.ts.map +1 -0
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
- package/lib/typescript/src/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +9 -8
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/NavigationProvider.d.ts +12 -13
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
- package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
- package/lib/typescript/src/PreventRemoveContext.d.ts +1 -0
- package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
- package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
- package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
- package/lib/typescript/src/SceneView.d.ts +3 -2
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/StaticContainer.d.ts +1 -1
- package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +189 -109
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/StaticTreeContext.d.ts +4 -0
- package/lib/typescript/src/StaticTreeContext.d.ts.map +1 -0
- package/lib/typescript/src/checkSerializable.d.ts +8 -4
- package/lib/typescript/src/checkSerializable.d.ts.map +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +23 -5
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +3 -3
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getActionFromState.d.ts +4 -4
- package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +3 -3
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPatternParts.d.ts +1 -0
- package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +5 -5
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
- package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +36 -33
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +260 -159
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useChildListeners.d.ts +3 -3
- package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useComponent.d.ts +1 -1
- package/lib/typescript/src/useComponent.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +8 -8
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts +2 -2
- package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEvents.d.ts +2 -2
- package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
- package/lib/typescript/src/useIsFocused.d.ts +3 -0
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useKeyedChildListeners.d.ts +3 -3
- package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useLazyValue.d.ts.map +1 -1
- package/lib/typescript/src/useNavigation.d.ts +4 -2
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +23 -30
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +3 -3
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +19 -27
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +13 -3
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts +9 -9
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetState.d.ts +1 -1
- package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts +5 -9
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts +2 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
- package/lib/typescript/src/useRoute.d.ts +7 -3
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +5 -5
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts +5 -4
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
- package/lib/typescript/src/useStateForPath.d.ts +1 -1
- package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/lib/typescript/src/utilities.d.ts +74 -37
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +23 -22
- package/src/BaseNavigationContainer.tsx +351 -333
- package/src/ConsumedParamsContext.tsx +5 -0
- package/src/DataLoading.tsx +203 -0
- package/src/NavigationBuilderContext.tsx +14 -9
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +18 -12
- package/src/NavigationProvider.tsx +26 -15
- package/src/NavigationStateContext.tsx +5 -6
- package/src/PreventRemoveContext.tsx +1 -0
- package/src/PreventRemoveProvider.tsx +51 -46
- package/src/SceneView.tsx +7 -39
- package/src/StaticNavigation.tsx +659 -307
- package/src/StaticTreeContext.tsx +7 -0
- package/src/checkSerializable.tsx +35 -19
- package/src/createNavigationContainerRef.tsx +12 -9
- package/src/createNavigatorFactory.tsx +92 -8
- package/src/findFocusedRoute.tsx +13 -8
- package/src/getActionFromState.tsx +86 -51
- package/src/getPathFromState.tsx +254 -128
- package/src/getPatternParts.tsx +25 -4
- package/src/getStateFromPath.tsx +811 -309
- package/src/getStateFromRouteParams.tsx +60 -0
- package/src/index.tsx +55 -5
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +798 -373
- package/src/useDescriptors.tsx +28 -14
- package/src/useEventEmitter.tsx +52 -38
- package/src/useFocusEvents.tsx +15 -7
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useIsFocused.tsx +14 -21
- package/src/useKeyedChildListeners.tsx +4 -2
- package/src/useLazyValue.tsx +2 -2
- package/src/useNavigation.tsx +7 -24
- package/src/useNavigationBuilder.tsx +311 -186
- package/src/useNavigationCache.tsx +32 -25
- package/src/useNavigationHelpers.tsx +27 -10
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useNavigationState.tsx +93 -59
- package/src/useOnAction.tsx +61 -13
- package/src/useOnGetState.tsx +5 -3
- package/src/useOnPreventRemove.tsx +75 -42
- package/src/useOnRouteFocus.tsx +10 -12
- package/src/useOptionsGetters.tsx +11 -5
- package/src/usePreventRemove.tsx +12 -3
- package/src/usePreventRemoveContext.tsx +1 -1
- package/src/useRegisterNavigator.tsx +2 -2
- package/src/useRoute.tsx +20 -6
- package/src/useRouteCache.tsx +22 -16
- package/src/useScheduleUpdate.tsx +9 -10
- package/src/useStateForPath.tsx +1 -1
- package/src/useSyncState.tsx +8 -3
- package/src/utilities.tsx +144 -31
- package/src/validatePathConfig.tsx +86 -57
- package/lib/module/CurrentRenderContext.js +0 -10
- package/lib/module/CurrentRenderContext.js.map +0 -1
- package/lib/module/useCurrentRender.js +0 -19
- package/lib/module/useCurrentRender.js.map +0 -1
- package/lib/typescript/src/CurrentRenderContext.d.ts +0 -9
- package/lib/typescript/src/CurrentRenderContext.d.ts.map +0 -1
- package/lib/typescript/src/useCurrentRender.d.ts +0 -14
- package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
- package/src/CurrentRenderContext.tsx +0 -9
- package/src/useCurrentRender.tsx +0 -31
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import queryString from 'query-string';
|
|
4
4
|
import { getPatternParts } from "./getPatternParts.js";
|
|
5
|
+
import { getStateFromRouteParams } from "./getStateFromRouteParams.js";
|
|
5
6
|
import { validatePathConfig } from "./validatePathConfig.js";
|
|
6
|
-
const
|
|
7
|
+
const serializeParamValue = value => value === null ? null : Array.isArray(value) ? value.map(String) : String(value);
|
|
8
|
+
const encodePathParam = value => {
|
|
9
|
+
let result = '';
|
|
10
|
+
for (const char of value) {
|
|
11
|
+
const charCode = char.charCodeAt(0);
|
|
12
|
+
const safe = charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || charCode >= 48 && charCode <= 57 || "-._~!$&'()*+,;=:@".includes(char);
|
|
13
|
+
result += safe ? char : encodeURIComponent(char);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const getActiveRoute = (state, configs, getRouteState) => {
|
|
7
18
|
const route = typeof state.index === 'number' ? state.routes[state.index] : state.routes[state.routes.length - 1];
|
|
8
|
-
if (route
|
|
9
|
-
|
|
19
|
+
if (route == null) {
|
|
20
|
+
throw new Error(`Couldn't find the active route.`);
|
|
21
|
+
}
|
|
22
|
+
const config = configs?.[route.name];
|
|
23
|
+
const routeState = getRouteState(route, config);
|
|
24
|
+
if (routeState) {
|
|
25
|
+
return getActiveRoute(routeState, config?.screens, getRouteState);
|
|
10
26
|
}
|
|
11
27
|
return route;
|
|
12
28
|
};
|
|
13
29
|
const cachedNormalizedConfigs = new WeakMap();
|
|
14
30
|
const getNormalizedConfigs = options => {
|
|
15
|
-
if (!options
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
if (!options) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
const cached = cachedNormalizedConfigs.get(options);
|
|
35
|
+
if (cached) {
|
|
36
|
+
return cached;
|
|
37
|
+
}
|
|
38
|
+
validatePathConfig(options);
|
|
18
39
|
const normalizedConfigs = createNormalizedConfigs(options.screens);
|
|
19
|
-
cachedNormalizedConfigs.set(options
|
|
40
|
+
cachedNormalizedConfigs.set(options, normalizedConfigs);
|
|
20
41
|
return normalizedConfigs;
|
|
21
42
|
};
|
|
22
43
|
|
|
@@ -53,78 +74,115 @@ export function getPathFromState(state, options) {
|
|
|
53
74
|
if (state == null) {
|
|
54
75
|
throw Error(`Got '${String(state)}' for the navigation state. You must pass a valid state object.`);
|
|
55
76
|
}
|
|
56
|
-
if (options) {
|
|
57
|
-
validatePathConfig(options);
|
|
58
|
-
}
|
|
59
77
|
const configs = getNormalizedConfigs(options);
|
|
78
|
+
const cachedRouteStates = new Map();
|
|
79
|
+
const getRouteState = (route, config) => {
|
|
80
|
+
if (route.state) {
|
|
81
|
+
return route.state;
|
|
82
|
+
}
|
|
83
|
+
const hasScreenParams = route.params && 'screen' in route.params && typeof route.params.screen === 'string' && config?.screens?.[route.params.screen];
|
|
84
|
+
const hasStateParams = route.params && 'state' in route.params && config?.screens;
|
|
85
|
+
if (!route.params || !config?.screens || !hasScreenParams && !hasStateParams) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
if (!cachedRouteStates.has(route)) {
|
|
89
|
+
cachedRouteStates.set(route, getStateFromRouteParams(route.params));
|
|
90
|
+
}
|
|
91
|
+
return cachedRouteStates.get(route);
|
|
92
|
+
};
|
|
93
|
+
const focusedRoute = getActiveRoute(state, configs, getRouteState);
|
|
60
94
|
let path = '/';
|
|
61
95
|
let current = state;
|
|
62
|
-
const allParams = {};
|
|
63
96
|
while (current) {
|
|
64
97
|
let index = typeof current.index === 'number' ? current.index : 0;
|
|
65
|
-
|
|
98
|
+
const initialRoute = current.routes[index];
|
|
99
|
+
if (initialRoute == null) {
|
|
100
|
+
throw new Error(`Couldn't find a route at index ${index}.`);
|
|
101
|
+
}
|
|
102
|
+
let route = initialRoute;
|
|
66
103
|
let parts;
|
|
104
|
+
|
|
105
|
+
// Values for each pattern part object, so the same param name
|
|
106
|
+
// at different nesting levels gets the value from its own level
|
|
107
|
+
const partValues = new Map();
|
|
67
108
|
let focusedParams;
|
|
68
109
|
let currentOptions = configs;
|
|
69
|
-
const focusedRoute = getActiveRoute(state);
|
|
70
110
|
|
|
71
111
|
// Keep all the route names that appeared during going deeper in config in case the pattern is resolved to undefined
|
|
72
112
|
const nestedRouteNames = [];
|
|
73
113
|
let hasNext = true;
|
|
74
|
-
while (
|
|
75
|
-
|
|
114
|
+
while (hasNext) {
|
|
115
|
+
const config = currentOptions[route.name];
|
|
116
|
+
if (config == null) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
parts = config.parts;
|
|
120
|
+
const ownParts = config.ownParts;
|
|
76
121
|
nestedRouteNames.push(route.name);
|
|
77
122
|
if (route.params) {
|
|
78
|
-
const options =
|
|
79
|
-
const
|
|
123
|
+
const options = config;
|
|
124
|
+
const params = route.params;
|
|
125
|
+
const currentParams = {};
|
|
126
|
+
for (const key in params) {
|
|
127
|
+
const value = params[key];
|
|
80
128
|
if (value === undefined) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
129
|
+
let optional = false;
|
|
130
|
+
for (const part of ownParts) {
|
|
131
|
+
if (part.param === key) {
|
|
132
|
+
optional = part.optional === true;
|
|
133
|
+
break;
|
|
85
134
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
135
|
+
}
|
|
136
|
+
if (optional) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const stringify = options.stringify?.[key];
|
|
141
|
+
currentParams[key] = stringify ? stringify(value) : serializeParamValue(value);
|
|
142
|
+
}
|
|
143
|
+
const claimedParams = new Set();
|
|
144
|
+
for (const part of ownParts) {
|
|
145
|
+
if (part.param && part.param in currentParams) {
|
|
146
|
+
const value = currentParams[part.param];
|
|
147
|
+
if (value !== undefined) {
|
|
148
|
+
partValues.set(part, value);
|
|
149
|
+
claimedParams.add(part.param);
|
|
88
150
|
}
|
|
89
151
|
}
|
|
90
|
-
const stringify = options?.stringify?.[key] ?? String;
|
|
91
|
-
return [key, stringify(value)];
|
|
92
|
-
}).filter(entry => entry != null));
|
|
93
|
-
if (parts?.length) {
|
|
94
|
-
Object.assign(allParams, currentParams);
|
|
95
152
|
}
|
|
96
153
|
if (focusedRoute === route) {
|
|
97
154
|
// If this is the focused route, keep the params for later use
|
|
98
155
|
// We save it here since it's been stringified already
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
param
|
|
106
|
-
}) => {
|
|
107
|
-
if (param) {
|
|
108
|
-
// Remove the params present in the pattern since we'll only use the rest for query string
|
|
109
|
-
if (focusedParams) {
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
111
|
-
delete focusedParams[param];
|
|
112
|
-
}
|
|
156
|
+
// Params claimed by the pattern shouldn't be repeated in the query string
|
|
157
|
+
focusedParams = {};
|
|
158
|
+
for (const key in currentParams) {
|
|
159
|
+
const value = currentParams[key];
|
|
160
|
+
if (!claimedParams.has(key) && value !== undefined && value !== 'undefined') {
|
|
161
|
+
focusedParams[key] = value;
|
|
113
162
|
}
|
|
114
|
-
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const part of ownParts) {
|
|
167
|
+
if (part.param && !partValues.has(part)) {
|
|
168
|
+
partValues.set(part, undefined);
|
|
115
169
|
}
|
|
116
170
|
}
|
|
117
171
|
|
|
118
172
|
// If there is no `screens` property or no nested state, we return pattern
|
|
119
|
-
|
|
173
|
+
const routeState = getRouteState(route, config);
|
|
174
|
+
if (!config.screens || routeState == null) {
|
|
120
175
|
hasNext = false;
|
|
121
176
|
} else {
|
|
122
|
-
index = typeof
|
|
123
|
-
const nextRoute =
|
|
124
|
-
|
|
177
|
+
index = typeof routeState.index === 'number' ? routeState.index : routeState.routes.length - 1;
|
|
178
|
+
const nextRoute = routeState.routes[index];
|
|
179
|
+
if (nextRoute == null) {
|
|
180
|
+
throw new Error(`Couldn't find a route at index ${index}.`);
|
|
181
|
+
}
|
|
182
|
+
const nestedConfig = config.screens;
|
|
125
183
|
|
|
126
184
|
// if there is config for next route name, we go deeper
|
|
127
|
-
if (
|
|
185
|
+
if (nextRoute.name in nestedConfig) {
|
|
128
186
|
route = nextRoute;
|
|
129
187
|
currentOptions = nestedConfig;
|
|
130
188
|
} else {
|
|
@@ -133,48 +191,61 @@ export function getPathFromState(state, options) {
|
|
|
133
191
|
}
|
|
134
192
|
}
|
|
135
193
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
194
|
+
const routeState = getRouteState(route, currentOptions[route.name]);
|
|
195
|
+
if (currentOptions[route.name] != null) {
|
|
196
|
+
if (parts) {
|
|
197
|
+
let index = 0;
|
|
198
|
+
for (const part of parts) {
|
|
199
|
+
const {
|
|
200
|
+
segment,
|
|
201
|
+
param,
|
|
202
|
+
optional
|
|
203
|
+
} = part;
|
|
204
|
+
if (index > 0) {
|
|
205
|
+
path += '/';
|
|
206
|
+
}
|
|
207
|
+
index++;
|
|
148
208
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
209
|
+
// We don't know what to show for wildcard patterns
|
|
210
|
+
// Showing the route name seems ok, though whatever we show here will be incorrect
|
|
211
|
+
// Since the page doesn't actually exist
|
|
212
|
+
if (segment === '*') {
|
|
213
|
+
path += route.name;
|
|
214
|
+
continue;
|
|
155
215
|
}
|
|
156
216
|
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
217
|
+
// If the path has a pattern for a param, put the param in the path
|
|
218
|
+
if (param) {
|
|
219
|
+
const value = partValues.get(part);
|
|
220
|
+
if (value === undefined && optional) {
|
|
221
|
+
// Optional params without value assigned in route.params should be ignored
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Valid characters according to
|
|
226
|
+
// https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 (see pchar definition)
|
|
227
|
+
path += encodePathParam(String(value));
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
path += encodeURIComponent(segment);
|
|
160
231
|
}
|
|
161
|
-
|
|
162
|
-
}).join('/');
|
|
232
|
+
}
|
|
163
233
|
} else {
|
|
164
234
|
path += encodeURIComponent(route.name);
|
|
165
235
|
}
|
|
166
236
|
if (!focusedParams && focusedRoute.params) {
|
|
167
|
-
focusedParams =
|
|
237
|
+
focusedParams = {};
|
|
238
|
+
const params = focusedRoute.params;
|
|
239
|
+
for (const key in params) {
|
|
240
|
+
const value = serializeParamValue(params[key]);
|
|
241
|
+
if (value !== 'undefined') {
|
|
242
|
+
focusedParams[key] = value;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
168
245
|
}
|
|
169
|
-
if (
|
|
246
|
+
if (routeState) {
|
|
170
247
|
path += '/';
|
|
171
248
|
} else if (focusedParams) {
|
|
172
|
-
for (const param in focusedParams) {
|
|
173
|
-
if (focusedParams[param] === 'undefined') {
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
175
|
-
delete focusedParams[param];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
249
|
const query = queryString.stringify(focusedParams, {
|
|
179
250
|
sort: false
|
|
180
251
|
});
|
|
@@ -182,7 +253,7 @@ export function getPathFromState(state, options) {
|
|
|
182
253
|
path += `?${query}`;
|
|
183
254
|
}
|
|
184
255
|
}
|
|
185
|
-
current =
|
|
256
|
+
current = routeState;
|
|
186
257
|
}
|
|
187
258
|
|
|
188
259
|
// Include the root path if specified
|
|
@@ -203,15 +274,16 @@ export function getPathFromState(state, options) {
|
|
|
203
274
|
}
|
|
204
275
|
const createConfigItem = (config, parentParts) => {
|
|
205
276
|
if (typeof config === 'string') {
|
|
206
|
-
|
|
207
|
-
const parts = getPatternParts(config);
|
|
277
|
+
const ownParts = getPatternParts(config);
|
|
208
278
|
if (parentParts) {
|
|
209
279
|
return {
|
|
210
|
-
parts: [...parentParts, ...
|
|
280
|
+
parts: [...parentParts, ...ownParts],
|
|
281
|
+
ownParts
|
|
211
282
|
};
|
|
212
283
|
}
|
|
213
284
|
return {
|
|
214
|
-
parts
|
|
285
|
+
parts: ownParts,
|
|
286
|
+
ownParts
|
|
215
287
|
};
|
|
216
288
|
}
|
|
217
289
|
if (config.exact && config.path === undefined) {
|
|
@@ -220,16 +292,25 @@ const createConfigItem = (config, parentParts) => {
|
|
|
220
292
|
|
|
221
293
|
// If an object is specified as the value (e.g. Foo: { ... }),
|
|
222
294
|
// It can have `path` property and `screens` prop which has nested configs
|
|
223
|
-
const
|
|
295
|
+
const ownParts = config.path ? getPatternParts(config.path) : [];
|
|
296
|
+
const parts = config.exact !== true ? [...(parentParts || []), ...ownParts] : ownParts.length ? ownParts : undefined;
|
|
224
297
|
const screens = 'screens' in config && config.screens ? createNormalizedConfigs(config.screens, parts) : undefined;
|
|
225
298
|
return {
|
|
226
299
|
parts,
|
|
300
|
+
ownParts,
|
|
227
301
|
stringify: config.stringify,
|
|
228
302
|
screens
|
|
229
303
|
};
|
|
230
304
|
};
|
|
231
|
-
const createNormalizedConfigs = (options, parts) =>
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
305
|
+
const createNormalizedConfigs = (options, parts) => {
|
|
306
|
+
const configs = {};
|
|
307
|
+
const screens = options;
|
|
308
|
+
for (const name in screens) {
|
|
309
|
+
const config = screens[name];
|
|
310
|
+
if (config !== undefined) {
|
|
311
|
+
configs[name] = createConfigItem(config, parts);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return configs;
|
|
315
|
+
};
|
|
235
316
|
//# sourceMappingURL=getPathFromState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["queryString","getPatternParts","validatePathConfig","
|
|
1
|
+
{"version":3,"names":["queryString","getPatternParts","getStateFromRouteParams","validatePathConfig","serializeParamValue","value","Array","isArray","map","String","encodePathParam","result","char","charCode","charCodeAt","safe","includes","encodeURIComponent","getActiveRoute","state","configs","getRouteState","route","index","routes","length","Error","config","name","routeState","screens","cachedNormalizedConfigs","WeakMap","getNormalizedConfigs","options","cached","get","normalizedConfigs","createNormalizedConfigs","set","getPathFromState","cachedRouteStates","Map","hasScreenParams","params","screen","hasStateParams","undefined","has","focusedRoute","path","current","initialRoute","parts","partValues","focusedParams","currentOptions","nestedRouteNames","hasNext","ownParts","push","currentParams","key","optional","part","param","stringify","claimedParams","Set","add","nextRoute","nestedConfig","segment","query","sort","replace","startsWith","createConfigItem","parentParts","exact"],"sourceRoot":"../../src","sources":["getPathFromState.tsx"],"mappings":";;AACA,OAAOA,WAAW,MAAM,cAAc;AAEtC,SAASC,eAAe,QAA0B,sBAAmB;AACrE,SAASC,uBAAuB,QAAQ,8BAA2B;AAEnE,SAASC,kBAAkB,QAAQ,yBAAsB;AAqBzD,MAAMC,mBAAmB,GAAIC,KAAc,IACzCA,KAAK,KAAK,IAAI,GACV,IAAI,GACJC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,GAClBA,KAAK,CAACG,GAAG,CAACC,MAAM,CAAC,GACjBA,MAAM,CAACJ,KAAK,CAAC;AAErB,MAAMK,eAAe,GAAIL,KAAa,IAAK;EACzC,IAAIM,MAAM,GAAG,EAAE;EAEf,KAAK,MAAMC,IAAI,IAAIP,KAAK,EAAE;IACxB,MAAMQ,QAAQ,GAAGD,IAAI,CAACE,UAAU,CAAC,CAAC,CAAC;IACnC,MAAMC,IAAI,GACPF,QAAQ,IAAI,EAAE,IAAIA,QAAQ,IAAI,EAAE,IAChCA,QAAQ,IAAI,EAAE,IAAIA,QAAQ,IAAI,GAAI,IAClCA,QAAQ,IAAI,EAAE,IAAIA,QAAQ,IAAI,EAAG,IAClC,mBAAmB,CAACG,QAAQ,CAACJ,IAAI,CAAC;IAEpCD,MAAM,IAAII,IAAI,GAAGH,IAAI,GAAGK,kBAAkB,CAACL,IAAI,CAAC;EAClD;EAEA,OAAOD,MAAM;AACf,CAAC;AAED,MAAMO,cAAc,GAAGA,CACrBC,KAAY,EACZC,OAA+C,EAC/CC,aAGsB,KAC4B;EAClD,MAAMC,KAAK,GACT,OAAOH,KAAK,CAACI,KAAK,KAAK,QAAQ,GAC3BJ,KAAK,CAACK,MAAM,CAACL,KAAK,CAACI,KAAK,CAAC,GACzBJ,KAAK,CAACK,MAAM,CAACL,KAAK,CAACK,MAAM,CAACC,MAAM,GAAG,CAAC,CAAC;EAE3C,IAAIH,KAAK,IAAI,IAAI,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;AAED,MAAMQ,uBAAuB,GAAGA,CAC9BJ,OAA8B,EAC9BmB,KAAqB,KACU;EAC/B,MAAMjC,OAAmC,GAAG,CAAC,CAAC;EAC9C,MAAMU,OAAO,GAAGI,OAAkD;EAElE,KAAK,MAAMN,IAAI,IAAIE,OAAO,EAAE;IAC1B,MAAMH,MAAM,GAAGG,OAAO,CAACF,IAAI,CAAC;IAE5B,IAAID,MAAM,KAAKoB,SAAS,EAAE;MACxB3B,OAAO,CAACQ,IAAI,CAAC,GAAGiD,gBAAgB,CAAClD,MAAM,EAAE0B,KAAK,CAAC;IACjD;EACF;EAEA,OAAOjC,OAAO;AAChB,CAAC","ignoreList":[]}
|
|
@@ -10,6 +10,8 @@ export function getPatternParts(path) {
|
|
|
10
10
|
};
|
|
11
11
|
let isRegex = false;
|
|
12
12
|
let isParam = false;
|
|
13
|
+
let isEscaped = false;
|
|
14
|
+
let isInCharClass = false;
|
|
13
15
|
let regexInnerParens = 0;
|
|
14
16
|
|
|
15
17
|
// One extra iteration to add the last character
|
|
@@ -25,7 +27,7 @@ export function getPatternParts(path) {
|
|
|
25
27
|
} else if (!isRegex) {
|
|
26
28
|
throw new Error(`Encountered ':' in the middle of a segment in path: ${path}`);
|
|
27
29
|
}
|
|
28
|
-
} else if (char === '(') {
|
|
30
|
+
} else if (char === '(' && !isEscaped && !isInCharClass) {
|
|
29
31
|
if (isParam) {
|
|
30
32
|
if (isRegex) {
|
|
31
33
|
// The '(' is part of the regex if we're already inside one
|
|
@@ -36,20 +38,20 @@ export function getPatternParts(path) {
|
|
|
36
38
|
} else {
|
|
37
39
|
throw new Error(`Encountered '(' without preceding ':' in path: ${path}`);
|
|
38
40
|
}
|
|
39
|
-
} else if (char === ')') {
|
|
41
|
+
} else if (char === ')' && !isEscaped && !isInCharClass) {
|
|
40
42
|
if (isParam && isRegex) {
|
|
41
43
|
if (regexInnerParens) {
|
|
42
44
|
// The ')' is part of the regex if we're already inside one
|
|
43
45
|
regexInnerParens--;
|
|
44
|
-
current.regex += char;
|
|
45
46
|
} else {
|
|
47
|
+
current.regex += char;
|
|
46
48
|
isRegex = false;
|
|
47
49
|
isParam = false;
|
|
48
50
|
}
|
|
49
51
|
} else {
|
|
50
52
|
throw new Error(`Encountered ')' without preceding '(' in path: ${path}`);
|
|
51
53
|
}
|
|
52
|
-
} else if (char === '?') {
|
|
54
|
+
} else if (char === '?' && !isRegex) {
|
|
53
55
|
if (current.param) {
|
|
54
56
|
isParam = false;
|
|
55
57
|
current.optional = true;
|
|
@@ -81,6 +83,17 @@ export function getPatternParts(path) {
|
|
|
81
83
|
if (isRegex) {
|
|
82
84
|
current.regex = current.regex || '';
|
|
83
85
|
current.regex += char;
|
|
86
|
+
|
|
87
|
+
// Track escapes and character classes so parens inside them are not special
|
|
88
|
+
if (isEscaped) {
|
|
89
|
+
isEscaped = false;
|
|
90
|
+
} else if (char === '\\') {
|
|
91
|
+
isEscaped = true;
|
|
92
|
+
} else if (char === '[') {
|
|
93
|
+
isInCharClass = true;
|
|
94
|
+
} else if (char === ']') {
|
|
95
|
+
isInCharClass = false;
|
|
96
|
+
}
|
|
84
97
|
}
|
|
85
98
|
if (isParam && !isRegex) {
|
|
86
99
|
current.param = current.param || '';
|
|
@@ -98,4 +111,7 @@ export function getPatternParts(path) {
|
|
|
98
111
|
}
|
|
99
112
|
return parts;
|
|
100
113
|
}
|
|
114
|
+
export function combinePatternParts(parentParts, parts, exact = false) {
|
|
115
|
+
return exact ? parts : [...parentParts, ...parts];
|
|
116
|
+
}
|
|
101
117
|
//# sourceMappingURL=getPatternParts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getPatternParts","path","parts","current","segment","isRegex","isParam","regexInnerParens","i","length","char","Error","regex","param","optional","replace","push","params","map","part","filter","Boolean","index","entries","indexOf"],"sourceRoot":"../../src","sources":["getPatternParts.tsx"],"mappings":";;AAOA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAACC,IAAY,EAAiB;EAC3D,MAAMC,KAAoB,GAAG,EAAE;EAE/B,IAAIC,OAAoB,GAAG;IAAEC,OAAO,EAAE;EAAG,CAAC;EAE1C,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAIC,gBAAgB,GAAG,CAAC;;EAExB;EACA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,
|
|
1
|
+
{"version":3,"names":["getPatternParts","path","parts","current","segment","isRegex","isParam","isEscaped","isInCharClass","regexInnerParens","i","length","char","Error","regex","param","optional","replace","push","params","map","part","filter","Boolean","index","entries","indexOf","combinePatternParts","parentParts","exact"],"sourceRoot":"../../src","sources":["getPatternParts.tsx"],"mappings":";;AAOA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAACC,IAAY,EAAiB;EAC3D,MAAMC,KAAoB,GAAG,EAAE;EAE/B,IAAIC,OAAoB,GAAG;IAAEC,OAAO,EAAE;EAAG,CAAC;EAE1C,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAIC,SAAS,GAAG,KAAK;EACrB,IAAIC,aAAa,GAAG,KAAK;EACzB,IAAIC,gBAAgB,GAAG,CAAC;;EAExB;EACA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIT,IAAI,CAACU,MAAM,EAAED,CAAC,EAAE,EAAE;IACrC,MAAME,IAAI,GAAGX,IAAI,CAACS,CAAC,CAAC;IAEpB,IAAIE,IAAI,IAAI,IAAI,EAAE;MAChBT,OAAO,CAACC,OAAO,IAAIQ,IAAI;IACzB;IAEA,IAAIA,IAAI,KAAK,GAAG,EAAE;MAChB;MACA,IAAIT,OAAO,CAACC,OAAO,KAAK,GAAG,EAAE;QAC3BE,OAAO,GAAG,IAAI;MAChB,CAAC,MAAM,IAAI,CAACD,OAAO,EAAE;QACnB,MAAM,IAAIQ,KAAK,CACb,uDAAuDZ,IAAI,EAC7D,CAAC;MACH;IACF,CAAC,MAAM,I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