expo-router 0.0.19 → 0.0.20
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/build/ContextNavigationContainer.d.ts +3 -3
- package/build/ContextNavigationContainer.d.ts.map +1 -1
- package/build/ContextNavigationContainer.js +33 -12
- package/build/ContextNavigationContainer.js.map +1 -1
- package/build/ContextNavigator.d.ts +1 -1
- package/build/ContextNavigator.d.ts.map +1 -1
- package/build/ContextNavigator.js +8 -6
- package/build/ContextNavigator.js.map +1 -1
- package/build/Route.d.ts +1 -1
- package/build/Route.d.ts.map +1 -1
- package/build/Route.js +3 -3
- package/build/Route.js.map +1 -1
- package/build/aasa.js +1 -1
- package/build/aasa.js.map +1 -1
- package/build/fork/getPathFromState.d.ts +3 -3
- package/build/fork/getPathFromState.d.ts.map +1 -1
- package/build/fork/getPathFromState.js +9 -11
- package/build/fork/getPathFromState.js.map +1 -1
- package/build/fork/getStateFromPath.d.ts +3 -3
- package/build/fork/getStateFromPath.d.ts.map +1 -1
- package/build/fork/getStateFromPath.js +3 -4
- package/build/fork/getStateFromPath.js.map +1 -1
- package/build/fork/useLinkToPath.d.ts +2 -0
- package/build/fork/useLinkToPath.d.ts.map +1 -0
- package/build/fork/useLinkToPath.js +45 -0
- package/build/fork/useLinkToPath.js.map +1 -0
- package/build/getLinkingConfig.d.ts +3 -3
- package/build/getLinkingConfig.d.ts.map +1 -1
- package/build/getLinkingConfig.js +3 -3
- package/build/getLinkingConfig.js.map +1 -1
- package/build/getRoutes.d.ts.map +1 -1
- package/build/getRoutes.js.map +1 -1
- package/build/layouts/Drawer.d.ts +1 -1
- package/build/layouts/Drawer.d.ts.map +1 -1
- package/build/layouts/Drawer.js +2 -2
- package/build/layouts/Drawer.js.map +1 -1
- package/build/layouts/NativeStack.d.ts +1 -1
- package/build/layouts/NativeStack.d.ts.map +1 -1
- package/build/layouts/NativeStack.js +2 -2
- package/build/layouts/NativeStack.js.map +1 -1
- package/build/layouts/Stack.d.ts +1 -1
- package/build/layouts/Stack.d.ts.map +1 -1
- package/build/layouts/Stack.js +2 -2
- package/build/layouts/Stack.js.map +1 -1
- package/build/layouts/Tabs.d.ts +1 -1
- package/build/layouts/Tabs.d.ts.map +1 -1
- package/build/layouts/Tabs.js +2 -2
- package/build/layouts/Tabs.js.map +1 -1
- package/build/layouts/withLayoutContext.d.ts +2 -2
- package/build/layouts/withLayoutContext.d.ts.map +1 -1
- package/build/layouts/withLayoutContext.js +10 -10
- package/build/layouts/withLayoutContext.js.map +1 -1
- package/build/matchers.d.ts.map +1 -1
- package/build/matchers.js +2 -1
- package/build/matchers.js.map +1 -1
- package/build/onboard/Tutorial.d.ts.map +1 -1
- package/build/onboard/Tutorial.js +1 -1
- package/build/onboard/Tutorial.js.map +1 -1
- package/build/primitives.d.ts.map +1 -1
- package/build/primitives.js +1 -1
- package/build/primitives.js.map +1 -1
- package/build/useLink.d.ts +1 -0
- package/build/useLink.d.ts.map +1 -1
- package/build/useLink.js +8 -3
- package/build/useLink.js.map +1 -1
- package/build/useScreens.js +1 -1
- package/build/useScreens.js.map +1 -1
- package/build/views/Directory.d.ts.map +1 -1
- package/build/views/Directory.js +3 -3
- package/build/views/Directory.js.map +1 -1
- package/build/views/ErrorBoundary.d.ts +1 -1
- package/build/views/ErrorBoundary.d.ts.map +1 -1
- package/build/views/ErrorBoundary.js +56 -19
- package/build/views/ErrorBoundary.js.map +1 -1
- package/build/views/Layout.d.ts +1 -1
- package/build/views/Layout.d.ts.map +1 -1
- package/build/views/Layout.js +1 -1
- package/build/views/Layout.js.map +1 -1
- package/build/views/Link.d.ts +3 -3
- package/build/views/Link.d.ts.map +1 -1
- package/build/views/Link.js.map +1 -1
- package/build/views/Root.d.ts +1 -1
- package/build/views/Root.d.ts.map +1 -1
- package/build/views/Root.js +4 -3
- package/build/views/Root.js.map +1 -1
- package/build/views/Screen.d.ts +1 -1
- package/build/views/Screen.d.ts.map +1 -1
- package/build/views/Screen.js +2 -1
- package/build/views/Screen.js.map +1 -1
- package/build/views/Try.d.ts.map +1 -1
- package/build/views/Try.js.map +1 -1
- package/build/views/Unmatched.d.ts.map +1 -1
- package/build/views/Unmatched.js +2 -3
- package/build/views/Unmatched.js.map +1 -1
- package/package.json +2 -3
- package/metro-config.js +0 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NavigationContainer, NavigationContainerRef } from
|
|
2
|
-
import React from
|
|
1
|
+
import { NavigationContainer, NavigationContainerRef } from "@react-navigation/native";
|
|
2
|
+
import React from "react";
|
|
3
3
|
declare type NavigationContainerProps = React.ComponentProps<typeof NavigationContainer>;
|
|
4
4
|
export declare function useNavigationContainerContext(): [Partial<import("@react-navigation/native").NavigationContainerProps & {
|
|
5
5
|
theme?: import("@react-navigation/native").Theme | undefined;
|
|
@@ -28,6 +28,6 @@ export declare const ContextNavigationContainer: React.ForwardRefExoticComponent
|
|
|
28
28
|
} & {
|
|
29
29
|
ref?: React.Ref<NavigationContainerRef<{}>> | undefined;
|
|
30
30
|
}, keyof import("@react-navigation/native").NavigationContainerProps | "theme" | "linking" | "fallback" | "documentTitle" | "onReady"> & React.RefAttributes<NavigationContainerRef<{}>>>;
|
|
31
|
-
export declare function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme }: Omit<NavigationContainerProps,
|
|
31
|
+
export declare function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme, }: Omit<NavigationContainerProps, "independent" | "ref" | "children" | "linking">): null;
|
|
32
32
|
export {};
|
|
33
33
|
//# sourceMappingURL=ContextNavigationContainer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextNavigationContainer.d.ts","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ContextNavigationContainer.d.ts","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,sBAAsB,EAEvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAsB,MAAM,OAAO,CAAC;AAM3C,aAAK,wBAAwB,GAAG,KAAK,CAAC,cAAc,CAClD,OAAO,mBAAmB,CAC3B,CAAC;AASF,wBAAgB,6BAA6B;;;;;;;;;;;;;;;;aAQ5C;AAED,8GAA8G;AAC9G,eAAO,MAAM,0BAA0B;;;;;;;;yLAwBtC,CAAC;AA6DF,wBAAgB,aAAa,CAAC,EAC5B,aAAa,EACb,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,KAAK,GACN,EAAE,IAAI,CACL,wBAAwB,EACxB,aAAa,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAC/C,QAwBA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { findFocusedRoute, NavigationContainer } from
|
|
2
|
-
import React, { useCallback } from
|
|
3
|
-
import { useLinkingConfig } from
|
|
4
|
-
import SplashModule from
|
|
5
|
-
import { VirtualRouteContext } from
|
|
1
|
+
import { findFocusedRoute, NavigationContainer, } from "@react-navigation/native";
|
|
2
|
+
import React, { useCallback } from "react";
|
|
3
|
+
import { useLinkingConfig } from "./getLinkingConfig";
|
|
4
|
+
import SplashModule from "./splash";
|
|
5
|
+
import { VirtualRouteContext } from "./useCurrentRoute";
|
|
6
6
|
const NavigationContainerContext = React.createContext([{}, function () { }]);
|
|
7
7
|
export function useNavigationContainerContext() {
|
|
8
8
|
const context = React.useContext(NavigationContainerContext);
|
|
@@ -15,7 +15,7 @@ export function useNavigationContainerContext() {
|
|
|
15
15
|
export const ContextNavigationContainer = React.forwardRef((props, ref) => {
|
|
16
16
|
const [state, setState] = React.useState({});
|
|
17
17
|
const linking = useLinkingConfig();
|
|
18
|
-
console.log(
|
|
18
|
+
console.log("linking", linking);
|
|
19
19
|
return (React.createElement(NavigationContainerContext.Provider, { value: [
|
|
20
20
|
{
|
|
21
21
|
...props,
|
|
@@ -27,7 +27,7 @@ export const ContextNavigationContainer = React.forwardRef((props, ref) => {
|
|
|
27
27
|
React.createElement(InternalContextNavigationContainer, { ref: ref })));
|
|
28
28
|
});
|
|
29
29
|
function trimQuery(pathname) {
|
|
30
|
-
const queryIndex = pathname.indexOf(
|
|
30
|
+
const queryIndex = pathname.indexOf("?");
|
|
31
31
|
if (queryIndex !== -1) {
|
|
32
32
|
return pathname.substring(0, queryIndex);
|
|
33
33
|
}
|
|
@@ -39,11 +39,16 @@ const InternalContextNavigationContainer = React.forwardRef((props, ref) => {
|
|
|
39
39
|
const onStateChange = useCallback((state) => {
|
|
40
40
|
if (state) {
|
|
41
41
|
const currentRoute = findFocusedRoute(state);
|
|
42
|
-
setState({
|
|
42
|
+
setState({
|
|
43
|
+
pathname: trimQuery(currentRoute?.path ?? "/"),
|
|
44
|
+
query: currentRoute?.params ?? {},
|
|
45
|
+
});
|
|
43
46
|
}
|
|
44
47
|
}, [setState]);
|
|
45
48
|
const navigationRef = React.useRef(null);
|
|
46
|
-
React.useImperativeHandle(ref, () => navigationRef.current, [
|
|
49
|
+
React.useImperativeHandle(ref, () => navigationRef.current, [
|
|
50
|
+
navigationRef,
|
|
51
|
+
]);
|
|
47
52
|
return (React.createElement(VirtualRouteContext.Provider, { value: state },
|
|
48
53
|
React.createElement(NavigationContainer, { ...props, ...contextProps, ref: navigationRef, onReady: () => {
|
|
49
54
|
contextProps.onReady?.();
|
|
@@ -55,11 +60,27 @@ const InternalContextNavigationContainer = React.forwardRef((props, ref) => {
|
|
|
55
60
|
onStateChange(state);
|
|
56
61
|
} })));
|
|
57
62
|
});
|
|
58
|
-
export function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme }) {
|
|
63
|
+
export function RootContainer({ documentTitle, fallback, onReady, initialState, onStateChange, onUnhandledAction, theme, }) {
|
|
59
64
|
const [, setProps] = useNavigationContainerContext();
|
|
60
65
|
React.useEffect(() => {
|
|
61
|
-
setProps({
|
|
62
|
-
|
|
66
|
+
setProps({
|
|
67
|
+
documentTitle,
|
|
68
|
+
fallback,
|
|
69
|
+
onReady,
|
|
70
|
+
initialState,
|
|
71
|
+
onStateChange,
|
|
72
|
+
onUnhandledAction,
|
|
73
|
+
theme,
|
|
74
|
+
});
|
|
75
|
+
}, [
|
|
76
|
+
documentTitle,
|
|
77
|
+
fallback,
|
|
78
|
+
onReady,
|
|
79
|
+
initialState,
|
|
80
|
+
onStateChange,
|
|
81
|
+
onUnhandledAction,
|
|
82
|
+
theme,
|
|
83
|
+
]);
|
|
63
84
|
return null;
|
|
64
85
|
}
|
|
65
86
|
//# sourceMappingURL=ContextNavigationContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextNavigationContainer.js","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ContextNavigationContainer.js","sourceRoot":"","sources":["../src/ContextNavigationContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,GAGpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,YAAY,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxD,MAAM,0BAA0B,GAAG,KAAK,CAAC,aAAa,CAKpD,CAAC,EAAE,EAAE,cAAa,CAAC,CAAC,CAAC,CAAC;AAExB,MAAM,UAAU,6BAA6B;IAC3C,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8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aAAa;YACb,iBAAiB;YACjB,KAAK;SACN,CAAC,CAAC;IACL,CAAC,EAAE;QACD,aAAa;QACb,QAAQ;QACR,OAAO;QACP,YAAY;QACZ,aAAa;QACb,iBAAiB;QACjB,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {\n findFocusedRoute,\n NavigationContainer,\n NavigationContainerRef,\n ParamListBase,\n} from \"@react-navigation/native\";\nimport React, { useCallback } from \"react\";\n\nimport { useLinkingConfig } from \"./getLinkingConfig\";\nimport SplashModule from \"./splash\";\nimport { VirtualRouteContext } from \"./useCurrentRoute\";\n\ntype NavigationContainerProps = React.ComponentProps<\n typeof NavigationContainer\n>;\n\nconst NavigationContainerContext = React.createContext<\n [\n Partial<NavigationContainerProps>,\n (props: Partial<NavigationContainerProps>) => void\n ]\n>([{}, function () {}]);\n\nexport function useNavigationContainerContext() {\n const context = React.useContext(NavigationContainerContext);\n if (!context) {\n throw new Error(\n \"useNavigationContainerContext must be used within a NavigationContainerContext\"\n );\n }\n return context;\n}\n\n/** react-navigation `NavigationContainer` with automatic `linking` prop generated from the routes context. */\nexport const ContextNavigationContainer = React.forwardRef(\n (props: NavigationContainerProps, ref: NavigationContainerProps[\"ref\"]) => {\n const [state, setState] = React.useState<Partial<NavigationContainerProps>>(\n {}\n );\n\n const linking = useLinkingConfig();\n console.log(\"linking\", linking);\n\n return (\n <NavigationContainerContext.Provider\n value={[\n {\n ...props,\n linking,\n ...state,\n },\n setState,\n ]}\n >\n <InternalContextNavigationContainer ref={ref} />\n </NavigationContainerContext.Provider>\n );\n }\n);\n\nfunction trimQuery(pathname: string): string {\n const queryIndex = pathname.indexOf(\"?\");\n if (queryIndex !== -1) {\n return pathname.substring(0, queryIndex);\n }\n return pathname;\n}\n\nconst InternalContextNavigationContainer = React.forwardRef(\n (props: object, ref: NavigationContainerProps[\"ref\"]) => {\n const [contextProps] = useNavigationContainerContext();\n const [state, setState] = React.useState<{\n pathname: string | null;\n query: Record<string, any>;\n }>({ pathname: null, query: {} });\n\n const onStateChange = useCallback(\n (state) => {\n if (state) {\n const currentRoute = findFocusedRoute(state);\n setState({\n pathname: trimQuery(currentRoute?.path ?? \"/\"),\n query: currentRoute?.params ?? {},\n });\n }\n },\n [setState]\n );\n\n const navigationRef =\n React.useRef<NavigationContainerRef<ParamListBase>>(null);\n\n React.useImperativeHandle(ref, () => navigationRef.current!, [\n navigationRef,\n ]);\n\n return (\n <VirtualRouteContext.Provider value={state}>\n {/* @ts-expect-error: children are required */}\n <NavigationContainer\n {...props}\n {...contextProps}\n ref={navigationRef}\n onReady={() => {\n contextProps.onReady?.();\n SplashModule?.hideAsync();\n const initialState = navigationRef.current?.getRootState();\n onStateChange(initialState);\n }}\n onStateChange={(state) => {\n contextProps.onStateChange?.(state);\n onStateChange(state);\n }}\n />\n </VirtualRouteContext.Provider>\n );\n }\n);\n\nexport function RootContainer({\n documentTitle,\n fallback,\n onReady,\n initialState,\n onStateChange,\n onUnhandledAction,\n theme,\n}: Omit<\n NavigationContainerProps,\n \"independent\" | \"ref\" | \"children\" | \"linking\"\n>) {\n const [, setProps] = useNavigationContainerContext();\n\n React.useEffect(() => {\n setProps({\n documentTitle,\n fallback,\n onReady,\n initialState,\n onStateChange,\n onUnhandledAction,\n theme,\n });\n }, [\n documentTitle,\n fallback,\n onReady,\n initialState,\n onStateChange,\n onUnhandledAction,\n theme,\n ]);\n\n return null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextNavigator.d.ts","sourceRoot":"","sources":["../src/ContextNavigator.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"ContextNavigator.d.ts","sourceRoot":"","sources":["../src/ContextNavigator.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA2DzC,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,eAkBxE"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { useMemo } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import { ContextNavigationContainer } from "./ContextNavigationContainer";
|
|
3
|
+
import { Route } from "./Route";
|
|
4
|
+
import { RoutesContext } from "./context";
|
|
5
|
+
import { getRoutes } from "./getRoutes";
|
|
6
|
+
import { NativeStack } from "./layouts/NativeStack";
|
|
7
7
|
function useContextModuleAsRoutes(context) {
|
|
8
8
|
// TODO: Is this an optimal hook dependency?
|
|
9
9
|
const keys = useMemo(() => context.keys(), [context]);
|
|
@@ -24,7 +24,9 @@ function useTutorial(context) {
|
|
|
24
24
|
if (process.env.NODE_ENV === "production") {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
27
28
|
const keys = useMemo(() => context.keys(), [context]);
|
|
29
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
28
30
|
const hasAnyValidComponent = useMemo(() => {
|
|
29
31
|
for (const key of keys) {
|
|
30
32
|
// NOTE(EvanBacon): This should only ever occur in development as it breaks lazily loading.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextNavigator.js","sourceRoot":"","sources":["../src/ContextNavigator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ContextNavigator.js","sourceRoot":"","sources":["../src/ContextNavigator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAA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AM,oBAAoB,GAAG,OAAO,CAAC,GAAG,EAAE;QACxC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,2FAA2F;YAC3F,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;YACxC,IAAI,0BAA0B,CAAC,SAAS,CAAC,EAAE;gBACzC,OAAO,IAAI,CAAC;aACb;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,IAAI,oBAAoB,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,OAAO,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAE,OAAO,EAA+B;IACvE,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,QAAQ,EAAE;QACZ,OAAO,oBAAC,QAAQ,OAAG,CAAC;KACrB;IAED,OAAO,CACL,oBAAC,qBAAqB,IAAC,OAAO,EAAE,OAAO;QACrC,oBAAC,KAAK,IAAC,QAAQ,EAAC,IAAI;YAClB,oBAAC,0BAA0B;gBAEzB,oBAAC,WAAW,IACV,aAAa,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GACxD,CACyB,CACvB,CACc,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import React, { useMemo } from \"react\";\n\nimport { ContextNavigationContainer } from \"./ContextNavigationContainer\";\nimport { Route } from \"./Route\";\nimport { RoutesContext } from \"./context\";\nimport { getRoutes } from \"./getRoutes\";\nimport { NativeStack } from \"./layouts/NativeStack\";\nimport { RequireContext } from \"./types\";\n\nfunction useContextModuleAsRoutes(context: RequireContext) {\n // TODO: Is this an optimal hook dependency?\n const keys = useMemo(() => context.keys(), [context]);\n return useMemo(() => getRoutes(context), [keys]);\n}\n\nfunction RoutesContextProvider({\n context,\n children,\n}: {\n context: RequireContext;\n children: React.ReactNode;\n}) {\n const routes = useContextModuleAsRoutes(context);\n return (\n <RoutesContext.Provider value={routes}>{children}</RoutesContext.Provider>\n );\n}\n\nfunction isFunctionOrReactComponent(\n Component: any\n): Component is React.ComponentType {\n return (\n !!Component &&\n (typeof Component === \"function\" ||\n Component?.prototype?.isReactComponent ||\n Component.$$typeof === Symbol.for(\"react.forward_ref\"))\n );\n}\n\n/** Returns the Tutorial component if there are no React components exported as default from any files in the provided context module. */\nfunction useTutorial(context: RequireContext) {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const keys = useMemo(() => context.keys(), [context]);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const hasAnyValidComponent = useMemo(() => {\n for (const key of keys) {\n // NOTE(EvanBacon): This should only ever occur in development as it breaks lazily loading.\n const component = context(key)?.default;\n if (isFunctionOrReactComponent(component)) {\n return true;\n }\n }\n return false;\n }, [keys]);\n\n if (hasAnyValidComponent) {\n return null;\n }\n\n return require(\"./onboard/Tutorial\").Tutorial;\n}\n\nexport function ContextNavigator({ context }: { context: RequireContext }) {\n const Tutorial = useTutorial(context);\n if (Tutorial) {\n return <Tutorial />;\n }\n\n return (\n <RoutesContextProvider context={context}>\n <Route filename=\"./\">\n <ContextNavigationContainer>\n {/* Using a switch navigator at the root to host all pages. */}\n <NativeStack\n screenOptions={{ animation: \"none\", headerShown: false }}\n />\n </ContextNavigationContainer>\n </Route>\n </RoutesContextProvider>\n );\n}\n"]}
|
package/build/Route.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { ReactNode } from
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
2
|
/** The list of input keys will become optional, everything else will remain the same. */
|
|
3
3
|
export declare type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
4
4
|
export declare type RouteNode = {
|
package/build/Route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAKrD,yFAAyF;AACzF,oBAAY,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AAKrD,yFAAyF;AACzF,oBAAY,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACxD,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEtB,oBAAY,SAAS,GAAG;IACtB,oBAAoB;IACpB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,qCAAqC;IACrC,YAAY,EAAE,MAAM,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,kCAAkC;IAClC,OAAO,EAAE,IAAI,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;IAChD,wCAAwC;IACxC,SAAS,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAWF,sDAAsD;AACtD,wBAAgB,SAAS,IAAI,SAAS,EAAE,CAEvC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED,iEAAiE;AACjE,wBAAgB,KAAK,CAAC,EACpB,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;CACrB,eAUA;AAkCD,wBAAgB,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CA4B7D"}
|
package/build/Route.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { useContext } from
|
|
2
|
-
import { RoutesContext } from
|
|
3
|
-
import { getNameFromFilePath, matchFragmentName } from
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import { RoutesContext } from "./context";
|
|
3
|
+
import { getNameFromFilePath, matchFragmentName } from "./matchers";
|
|
4
4
|
const CurrentRoutePathContext = React.createContext(null);
|
|
5
5
|
const CurrentRouteContext = React.createContext([]);
|
|
6
6
|
if (process.env.NODE_ENV !== "production") {
|
package/build/Route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA0BpE,MAAM,uBAAuB,GAAG,KAAK,CAAC,aAAa,CAAgB,IAAI,CAAC,CAAC;AAEzE,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAAc,EAAE,CAAC,CAAC;AAEjE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,a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C,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE;YACrC,OAAO,CAAC,CAAC,CAAC;SACX;QACD,OAAO,CAAC,CAAC;KACV;IAED,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACzE,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAEzE,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE;QACrB,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE;QACrB,OAAO,CAAC,CAAC;KACV;IAED,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;AACzC,CAAC","sourcesContent":["import React, { ReactNode, useContext } from \"react\";\n\nimport { RoutesContext } from \"./context\";\nimport { getNameFromFilePath, matchFragmentName } from \"./matchers\";\n\n/** The list of input keys will become optional, everything else will remain the same. */\nexport type PickPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>;\n\nexport type RouteNode = {\n /** nested routes */\n children: RouteNode[];\n /** Lazily get the React component */\n getComponent: () => React.ComponentType<any>;\n /** Is the route a dynamic path */\n dynamic: null | { name: string; deep: boolean };\n /** All static exports from the file. */\n getExtras: () => Record<string, any>;\n /** `index`, `error-boundary`, etc. */\n route: string;\n /** require.context key, used for matching children. */\n contextKey: string;\n /** Added in-memory */\n generated?: boolean;\n\n /** Internal screens like the directory or the auto 404 should be marked as internal. */\n internal?: boolean;\n};\n\nconst CurrentRoutePathContext = React.createContext<string | null>(null);\n\nconst CurrentRouteContext = React.createContext<RouteNode[]>([]);\n\nif (process.env.NODE_ENV !== \"production\") {\n CurrentRoutePathContext.displayName = \"RoutePath\";\n CurrentRouteContext.displayName = \"Route\";\n}\n\n/** Return all the routes for the current boundary. */\nexport function useRoutes(): RouteNode[] {\n return useContext(CurrentRouteContext);\n}\n\nexport function useContextKey(): string {\n const filename = useContext(CurrentRoutePathContext);\n if (!filename) {\n throw new Error(\"No filename found. This is likely a bug in expo-router.\");\n }\n return filename;\n}\n\n/** Provides the matching routes and filename to the children. */\nexport function Route({\n filename,\n children,\n}: {\n filename: string;\n children: ReactNode;\n}) {\n const routes = useRoutesAtPath(filename);\n\n return (\n <CurrentRoutePathContext.Provider value={filename}>\n <CurrentRouteContext.Provider value={routes}>\n {children}\n </CurrentRouteContext.Provider>\n </CurrentRoutePathContext.Provider>\n );\n}\n\nfunction useRoutesAtPath(filename: string): RouteNode[] {\n const normalName = React.useMemo(\n () => getNameFromFilePath(filename),\n [filename]\n );\n const routes = useContext(RoutesContext);\n const keys = React.useMemo(() => routes.keys(), [routes]);\n\n const family = React.useMemo(() => {\n let children: RouteNode[] = routes;\n\n // Skip root directory\n if (normalName) {\n // split and search\n const parts = normalName.split(\"/\");\n for (const part of parts) {\n const next = children.find(({ route }) => route === part);\n\n if (!next?.children) {\n return [];\n }\n\n children = next?.children;\n }\n }\n\n return children.sort(sortRoutes);\n }, [normalName, keys]);\n\n return family;\n}\n\nexport function sortRoutes(a: RouteNode, b: RouteNode): number {\n if (a.dynamic && !b.dynamic) {\n return 1;\n }\n if (!a.dynamic && b.dynamic) {\n return -1;\n }\n if (a.dynamic && b.dynamic) {\n if (a.dynamic.deep && !b.dynamic.deep) {\n return 1;\n }\n if (!a.dynamic.deep && b.dynamic.deep) {\n return -1;\n }\n return 0;\n }\n\n const aIndex = a.route === \"index\" || matchFragmentName(a.route) != null;\n const bIndex = b.route === \"index\" || matchFragmentName(b.route) != null;\n\n if (aIndex && !bIndex) {\n return -1;\n }\n if (!aIndex && bIndex) {\n return 1;\n }\n\n return a.route.length - b.route.length;\n}\n"]}
|
package/build/aasa.js
CHANGED
|
@@ -8,7 +8,7 @@ function getWebUrlsFromManifest() {
|
|
|
8
8
|
const applinks = domains
|
|
9
9
|
.filter((domain) => domain.startsWith("applinks:"))
|
|
10
10
|
.map((domain) => {
|
|
11
|
-
|
|
11
|
+
const clean = domain.replace(/^applinks:/, "");
|
|
12
12
|
return clean.endsWith("/") ? clean.slice(0, -1) : clean;
|
|
13
13
|
});
|
|
14
14
|
return applinks;
|
package/build/aasa.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aasa.js","sourceRoot":"","sources":["../src/aasa.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,SAAS,sBAAsB;IAC7B,8DAA8D;IAC9D,oFAAoF;IACpF,sDAAsD;IACtD,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,EAAE,iBAAiB,IAAI,EAAE,CAAC;IACnE,mEAAmE;IACnE,MAAM,QAAQ,GAAG,OAAO;SACrB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;SAClD,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACd,
|
|
1
|
+
{"version":3,"file":"aasa.js","sourceRoot":"","sources":["../src/aasa.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,SAAS,sBAAsB;IAC7B,8DAA8D;IAC9D,oFAAoF;IACpF,sDAAsD;IACtD,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,EAAE,iBAAiB,IAAI,EAAE,CAAC;IACnE,mEAAmE;IACnE,MAAM,QAAQ,GAAG,OAAO;SACrB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;SAClD,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEL,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,SAAS,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAC7B,UAAU,GAAG,CAAC,GAAG,CAAC;IAElB,MAAM,IAAI,GAAG,sBAAsB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5C,OAAO,IAAI;SACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACX,SAAS;SACN,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAChB,WAAW,CAAC,GAAG,CACb,CAAC,SAAS,EAAE,EAAE,CACZ,GAAG,QAAQ,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CACjE,CACF;SACA,IAAI,EAAE,CACV;SACA,IAAI,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import Constants from \"expo-constants\";\n\nfunction getWebUrlsFromManifest() {\n // TODO: Replace this with the source of truth native manifest\n // Then do a check to warn the user if the config doesn't match the native manifest.\n // TODO: Warn if the applinks have `https://` in them.\n const domains = Constants.expoConfig?.ios?.associatedDomains || [];\n // [applinks:explore-api.netlify.app/] -> [explore-api.netlify.app]\n const applinks = domains\n .filter((domain) => domain.startsWith(\"applinks:\"))\n .map((domain) => {\n const clean = domain.replace(/^applinks:/, \"\");\n return clean.endsWith(\"/\") ? clean.slice(0, -1) : clean;\n });\n\n return applinks;\n}\n\nexport function getAllWebRedirects(\n protocols = [\"https\", \"http\"],\n subdomains = [\"*\"]\n) {\n const urls = getWebUrlsFromManifest();\n const _subdomains = [\"\"].concat(subdomains);\n return urls\n .map((url) =>\n protocols\n .map((protocol) =>\n _subdomains.map(\n (subdomain) =>\n `${protocol}://${[subdomain, url].filter(Boolean).join(\".\")}/`\n )\n )\n .flat()\n )\n .flat();\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { NavigationState, PartialState } from "@react-navigation/routers";
|
|
2
1
|
import { PathConfigMap } from "@react-navigation/core";
|
|
3
|
-
|
|
2
|
+
import type { NavigationState, PartialState } from "@react-navigation/routers";
|
|
3
|
+
declare type Options<ParamList extends object> = {
|
|
4
4
|
initialRouteName?: string;
|
|
5
5
|
screens: PathConfigMap<ParamList>;
|
|
6
6
|
};
|
|
@@ -34,6 +34,6 @@ declare type State = NavigationState | Omit<PartialState<NavigationState>, "stal
|
|
|
34
34
|
* @param options Extra options to fine-tune how to serialize the path.
|
|
35
35
|
* @returns Path representing the state, e.g. /foo/bar?count=42.
|
|
36
36
|
*/
|
|
37
|
-
export default function getPathFromState<ParamList extends
|
|
37
|
+
export default function getPathFromState<ParamList extends object>(state: State, options?: Options<ParamList>): string;
|
|
38
38
|
export {};
|
|
39
39
|
//# sourceMappingURL=getPathFromState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPathFromState.d.ts","sourceRoot":"","sources":["../../src/fork/getPathFromState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAEb,MAAM,2BAA2B,CAAC;AAGnC,
|
|
1
|
+
{"version":3,"file":"getPathFromState.d.ts","sourceRoot":"","sources":["../../src/fork/getPathFromState.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAEb,MAAM,2BAA2B,CAAC;AAGnC,aAAK,OAAO,CAAC,SAAS,SAAS,MAAM,IAAI;IACvC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACnC,CAAC;AAEF,aAAK,KAAK,GAAG,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,CAAC;AAuB5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,SAAS,SAAS,MAAM,EAC/D,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAC3B,MAAM,CAuKR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as queryString from "query-string";
|
|
2
1
|
import { validatePathConfig, } from "@react-navigation/core";
|
|
2
|
+
import * as queryString from "query-string";
|
|
3
3
|
const getActiveRoute = (state) => {
|
|
4
4
|
const route = typeof state.index === "number"
|
|
5
5
|
? state.routes[state.index]
|
|
@@ -57,10 +57,10 @@ export default function getPathFromState(state, options) {
|
|
|
57
57
|
let route = current.routes[index];
|
|
58
58
|
let pattern;
|
|
59
59
|
let focusedParams;
|
|
60
|
-
|
|
60
|
+
const focusedRoute = getActiveRoute(state);
|
|
61
61
|
let currentOptions = configs;
|
|
62
62
|
// Keep all the route names that appeared during going deeper in config in case the pattern is resolved to undefined
|
|
63
|
-
|
|
63
|
+
const nestedRouteNames = [];
|
|
64
64
|
let hasNext = true;
|
|
65
65
|
while (route.name in currentOptions && hasNext) {
|
|
66
66
|
pattern = currentOptions[route.name].pattern;
|
|
@@ -153,7 +153,7 @@ export default function getPathFromState(state, options) {
|
|
|
153
153
|
path += "/";
|
|
154
154
|
}
|
|
155
155
|
else if (focusedParams) {
|
|
156
|
-
for (
|
|
156
|
+
for (const param in focusedParams) {
|
|
157
157
|
if (focusedParams[param] === "undefined") {
|
|
158
158
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
159
159
|
delete focusedParams[param];
|
|
@@ -182,16 +182,14 @@ const createConfigItem = (config, parentPattern) => {
|
|
|
182
182
|
const pattern = parentPattern ? joinPaths(parentPattern, config) : config;
|
|
183
183
|
return { pattern };
|
|
184
184
|
}
|
|
185
|
-
// If an object is specified as the value (e.g. Foo: { ... }),
|
|
186
|
-
// It can have `path` property and `screens` prop which has nested configs
|
|
187
|
-
let pattern;
|
|
188
185
|
if (config.exact && config.path === undefined) {
|
|
189
186
|
throw new Error("A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`.");
|
|
190
187
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
// If an object is specified as the value (e.g. Foo: { ... }),
|
|
189
|
+
// It can have `path` property and `screens` prop which has nested configs
|
|
190
|
+
const pattern = config.exact !== true
|
|
191
|
+
? joinPaths(parentPattern || "", config.path || "")
|
|
192
|
+
: config.path || "";
|
|
195
193
|
const screens = config.screens
|
|
196
194
|
? createNormalizedConfigs(config.screens, pattern)
|
|
197
195
|
: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPathFromState.js","sourceRoot":"","sources":["../../src/fork/getPathFromState.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAE5C,OAAO,EACL,kBAAkB,GAGnB,MAAM,wBAAwB,CAAC;AAiBhC,MAAM,cAAc,GAAG,CAAC,KAAY,EAAqC,EAAE;IACzE,MAAM,KAAK,GACT,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC7B,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE5C,IAAI,KAAK,CAAC,KAAK,EAAE;QACf,OAAO,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACpC;IAED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AAC,SAAS;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAC9B,OAA8B,EAC9B,OAAgB,EACY,EAAE,CAC9B,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;IACxC,MAAM,MAAM,GAAG,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAE5C,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACxB,CAAC,CAAC,CACH,CAAC","sourcesContent":["import type {\n NavigationState,\n PartialState,\n Route,\n} from \"@react-navigation/routers\";\nimport * as queryString from \"query-string\";\n\nimport {\n validatePathConfig,\n PathConfig,\n PathConfigMap,\n} from \"@react-navigation/core\";\n\ntype Options<ParamList extends {}> = {\n initialRouteName?: string;\n screens: PathConfigMap<ParamList>;\n};\n\ntype State = NavigationState | Omit<PartialState<NavigationState>, \"stale\">;\n\ntype StringifyConfig = Record<string, (value: any) => string>;\n\ntype ConfigItem = {\n pattern?: string;\n stringify?: StringifyConfig;\n screens?: Record<string, ConfigItem>;\n};\n\nconst getActiveRoute = (state: State): { name: string; params?: object } => {\n const route =\n typeof state.index === \"number\"\n ? state.routes[state.index]\n : state.routes[state.routes.length - 1];\n\n if (route.state) {\n return getActiveRoute(route.state);\n }\n\n return route;\n};\n\n/**\n * Utility to serialize a navigation state object to a path string.\n *\n * @example\n * ```js\n * getPathFromState(\n * {\n * routes: [\n * {\n * name: 'Chat',\n * params: { author: 'Jane', id: 42 },\n * },\n * ],\n * },\n * {\n * screens: {\n * Chat: {\n * path: 'chat/:author/:id',\n * stringify: { author: author => author.toLowerCase() }\n * }\n * }\n * }\n * )\n * ```\n *\n * @param state Navigation state to serialize.\n * @param options Extra options to fine-tune how to serialize the path.\n * @returns Path representing the state, e.g. /foo/bar?count=42.\n */\nexport default function getPathFromState<ParamList extends {}>(\n state: State,\n options?: Options<ParamList>\n): string {\n if (state == null) {\n throw Error(\n \"Got 'undefined' for the navigation state. You must pass a valid state object.\"\n );\n }\n\n if (options) {\n validatePathConfig(options);\n }\n\n // Create a normalized configs object which will be easier to use\n const configs: Record<string, ConfigItem> = options?.screens\n ? createNormalizedConfigs(options?.screens)\n : {};\n\n let path = \"/\";\n let current: State | undefined = state;\n\n const allParams: Record<string, any> = {};\n\n while (current) {\n let index = typeof current.index === \"number\" ? current.index : 0;\n let route = current.routes[index] as Route<string> & {\n state?: State;\n };\n\n let pattern: string | undefined;\n\n let focusedParams: Record<string, any> | undefined;\n let focusedRoute = getActiveRoute(state);\n let currentOptions = configs;\n\n // Keep all the route names that appeared during going deeper in config in case the pattern is resolved to undefined\n let nestedRouteNames = [];\n\n let hasNext = true;\n\n while (route.name in currentOptions && hasNext) {\n pattern = currentOptions[route.name].pattern;\n\n // @ts-expect-error\n nestedRouteNames.push(route.name);\n\n if (route.params) {\n const stringify = currentOptions[route.name]?.stringify;\n\n const currentParams = Object.fromEntries(\n Object.entries(route.params).map(([key, value]) => [\n key,\n stringify?.[key] ? stringify[key](value) : String(value),\n ])\n );\n\n if (pattern) {\n Object.assign(allParams, currentParams);\n }\n\n if (focusedRoute === route) {\n // If this is the focused route, keep the params for later use\n // We save it here since it's been stringified already\n focusedParams = { ...currentParams };\n\n pattern\n ?.split(\"/\")\n .filter((p) => p.startsWith(\":\") || p === \"*\")\n // eslint-disable-next-line no-loop-func\n .forEach((p) => {\n const name = getParamName(p);\n\n // Remove the params present in the pattern since we'll only use the rest for query string\n if (focusedParams) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete focusedParams[name];\n }\n });\n }\n }\n\n // If there is no `screens` property or no nested state, we return pattern\n if (!currentOptions[route.name].screens || route.state === undefined) {\n hasNext = false;\n } else {\n index =\n typeof route.state.index === \"number\"\n ? route.state.index\n : route.state.routes.length - 1;\n\n const nextRoute = route.state.routes[index];\n const nestedConfig = currentOptions[route.name].screens;\n\n // if there is config for next route name, we go deeper\n if (nestedConfig && nextRoute.name in nestedConfig) {\n route = nextRoute as Route<string> & { state?: State };\n currentOptions = nestedConfig;\n } else {\n // If not, there is no sense in going deeper in config\n hasNext = false;\n }\n }\n }\n\n if (pattern === undefined) {\n pattern = nestedRouteNames.join(\"/\");\n }\n\n if (currentOptions[route.name] !== undefined) {\n path += pattern\n .split(\"/\")\n .map((p) => {\n const name = getParamName(p);\n\n // We don't know what to show for wildcard patterns\n // Showing the route name seems ok, though whatever we show here will be incorrect\n // Since the page doesn't actually exist\n if (p === \"*\") {\n // This can occur when a wildcard matches all routes and the given path was `/`.\n return route.path ?? \"\";\n }\n\n // If the path has a pattern for a param, put the param in the path\n if (p.startsWith(\":\")) {\n const value = allParams[name];\n\n if (value == null) {\n // Optional params without value assigned in route.params should be ignored\n return \"\";\n }\n return value;\n }\n\n return encodeURIComponent(p);\n })\n .join(\"/\");\n } else {\n path += encodeURIComponent(route.name);\n }\n\n if (!focusedParams) {\n focusedParams = focusedRoute.params;\n }\n\n if (route.state) {\n path += \"/\";\n } else if (focusedParams) {\n for (let param in focusedParams) {\n if (focusedParams[param] === \"undefined\") {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete focusedParams[param];\n }\n }\n\n const query = queryString.stringify(focusedParams, { sort: false });\n\n if (query) {\n path += `?${query}`;\n }\n }\n\n current = route.state;\n }\n\n // Remove multiple as well as trailing slashes\n path = path.replace(/\\/+/g, \"/\");\n path = path.length > 1 ? path.replace(/\\/$/, \"\") : path;\n\n return path;\n}\n\nconst getParamName = (pattern: string) =>\n pattern.replace(/^:/, \"\").replace(/\\?$/, \"\");\n\nconst joinPaths = (...paths: string[]): string =>\n ([] as string[])\n .concat(...paths.map((p) => p.split(\"/\")))\n .filter(Boolean)\n .join(\"/\");\n\nconst createConfigItem = (\n config: PathConfig<object> | string,\n parentPattern?: string\n): ConfigItem => {\n if (typeof config === \"string\") {\n // If a string is specified as the value of the key(e.g. Foo: '/path'), use it as the pattern\n const pattern = parentPattern ? joinPaths(parentPattern, config) : config;\n\n return { pattern };\n }\n\n // If an object is specified as the value (e.g. Foo: { ... }),\n // It can have `path` property and `screens` prop which has nested configs\n let pattern: string | undefined;\n\n if (config.exact && config.path === undefined) {\n throw new Error(\n \"A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`.\"\n );\n }\n\n pattern =\n config.exact !== true\n ? joinPaths(parentPattern || \"\", config.path || \"\")\n : config.path || \"\";\n\n const screens = config.screens\n ? createNormalizedConfigs(config.screens, pattern)\n : undefined;\n\n return {\n // Normalize pattern to remove any leading, trailing slashes, duplicate slashes etc.\n pattern: pattern?.split(\"/\").filter(Boolean).join(\"/\"),\n stringify: config.stringify,\n screens,\n };\n};\n\nconst createNormalizedConfigs = (\n options: PathConfigMap<object>,\n pattern?: string\n): Record<string, ConfigItem> =>\n Object.fromEntries(\n Object.entries(options).map(([name, c]) => {\n const result = createConfigItem(c, pattern);\n\n return [name, result];\n })\n );\n"]}
|
|
1
|
+
{"version":3,"file":"getPathFromState.js","sourceRoot":"","sources":["../../src/fork/getPathFromState.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAGnB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAiB5C,MAAM,cAAc,GAAG,CAAC,KAAY,EAAqC,EAAE;IACzE,MAAM,KAAK,GACT,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC7B,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE5C,IAAI,KAAK,CAAC,KAAK,EAAE;QACf,OAAO,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACpC;IAED,OAAO,KAAK,CA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ACJ,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAC9B,OAA8B,EAC9B,OAAgB,EACY,EAAE,CAC9B,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;IACxC,MAAM,MAAM,GAAG,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAE5C,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACxB,CAAC,CAAC,CACH,CAAC","sourcesContent":["import {\n validatePathConfig,\n PathConfig,\n PathConfigMap,\n} from \"@react-navigation/core\";\nimport type {\n NavigationState,\n PartialState,\n Route,\n} from \"@react-navigation/routers\";\nimport * as queryString from \"query-string\";\n\ntype Options<ParamList extends object> = {\n initialRouteName?: string;\n screens: PathConfigMap<ParamList>;\n};\n\ntype State = NavigationState | Omit<PartialState<NavigationState>, \"stale\">;\n\ntype StringifyConfig = Record<string, (value: any) => string>;\n\ntype ConfigItem = {\n pattern?: string;\n stringify?: StringifyConfig;\n screens?: Record<string, ConfigItem>;\n};\n\nconst getActiveRoute = (state: State): { name: string; params?: object } => {\n const route =\n typeof state.index === \"number\"\n ? state.routes[state.index]\n : state.routes[state.routes.length - 1];\n\n if (route.state) {\n return getActiveRoute(route.state);\n }\n\n return route;\n};\n\n/**\n * Utility to serialize a navigation state object to a path string.\n *\n * @example\n * ```js\n * getPathFromState(\n * {\n * routes: [\n * {\n * name: 'Chat',\n * params: { author: 'Jane', id: 42 },\n * },\n * ],\n * },\n * {\n * screens: {\n * Chat: {\n * path: 'chat/:author/:id',\n * stringify: { author: author => author.toLowerCase() }\n * }\n * }\n * }\n * )\n * ```\n *\n * @param state Navigation state to serialize.\n * @param options Extra options to fine-tune how to serialize the path.\n * @returns Path representing the state, e.g. /foo/bar?count=42.\n */\nexport default function getPathFromState<ParamList extends object>(\n state: State,\n options?: Options<ParamList>\n): string {\n if (state == null) {\n throw Error(\n \"Got 'undefined' for the navigation state. You must pass a valid state object.\"\n );\n }\n\n if (options) {\n validatePathConfig(options);\n }\n\n // Create a normalized configs object which will be easier to use\n const configs: Record<string, ConfigItem> = options?.screens\n ? createNormalizedConfigs(options?.screens)\n : {};\n\n let path = \"/\";\n let current: State | undefined = state;\n\n const allParams: Record<string, any> = {};\n\n while (current) {\n let index = typeof current.index === \"number\" ? current.index : 0;\n let route = current.routes[index] as Route<string> & {\n state?: State;\n };\n\n let pattern: string | undefined;\n\n let focusedParams: Record<string, any> | undefined;\n const focusedRoute = getActiveRoute(state);\n let currentOptions = configs;\n\n // Keep all the route names that appeared during going deeper in config in case the pattern is resolved to undefined\n const nestedRouteNames = [];\n\n let hasNext = true;\n\n while (route.name in currentOptions && hasNext) {\n pattern = currentOptions[route.name].pattern;\n\n // @ts-expect-error\n nestedRouteNames.push(route.name);\n\n if (route.params) {\n const stringify = currentOptions[route.name]?.stringify;\n\n const currentParams = Object.fromEntries(\n Object.entries(route.params).map(([key, value]) => [\n key,\n stringify?.[key] ? stringify[key](value) : String(value),\n ])\n );\n\n if (pattern) {\n Object.assign(allParams, currentParams);\n }\n\n if (focusedRoute === route) {\n // If this is the focused route, keep the params for later use\n // We save it here since it's been stringified already\n focusedParams = { ...currentParams };\n\n pattern\n ?.split(\"/\")\n .filter((p) => p.startsWith(\":\") || p === \"*\")\n // eslint-disable-next-line no-loop-func\n .forEach((p) => {\n const name = getParamName(p);\n\n // Remove the params present in the pattern since we'll only use the rest for query string\n if (focusedParams) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete focusedParams[name];\n }\n });\n }\n }\n\n // If there is no `screens` property or no nested state, we return pattern\n if (!currentOptions[route.name].screens || route.state === undefined) {\n hasNext = false;\n } else {\n index =\n typeof route.state.index === \"number\"\n ? route.state.index\n : route.state.routes.length - 1;\n\n const nextRoute = route.state.routes[index];\n const nestedConfig = currentOptions[route.name].screens;\n\n // if there is config for next route name, we go deeper\n if (nestedConfig && nextRoute.name in nestedConfig) {\n route = nextRoute as Route<string> & { state?: State };\n currentOptions = nestedConfig;\n } else {\n // If not, there is no sense in going deeper in config\n hasNext = false;\n }\n }\n }\n\n if (pattern === undefined) {\n pattern = nestedRouteNames.join(\"/\");\n }\n\n if (currentOptions[route.name] !== undefined) {\n path += pattern\n .split(\"/\")\n .map((p) => {\n const name = getParamName(p);\n\n // We don't know what to show for wildcard patterns\n // Showing the route name seems ok, though whatever we show here will be incorrect\n // Since the page doesn't actually exist\n if (p === \"*\") {\n // This can occur when a wildcard matches all routes and the given path was `/`.\n return route.path ?? \"\";\n }\n\n // If the path has a pattern for a param, put the param in the path\n if (p.startsWith(\":\")) {\n const value = allParams[name];\n\n if (value == null) {\n // Optional params without value assigned in route.params should be ignored\n return \"\";\n }\n return value;\n }\n\n return encodeURIComponent(p);\n })\n .join(\"/\");\n } else {\n path += encodeURIComponent(route.name);\n }\n\n if (!focusedParams) {\n focusedParams = focusedRoute.params;\n }\n\n if (route.state) {\n path += \"/\";\n } else if (focusedParams) {\n for (const param in focusedParams) {\n if (focusedParams[param] === \"undefined\") {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete focusedParams[param];\n }\n }\n\n const query = queryString.stringify(focusedParams, { sort: false });\n\n if (query) {\n path += `?${query}`;\n }\n }\n\n current = route.state;\n }\n\n // Remove multiple as well as trailing slashes\n path = path.replace(/\\/+/g, \"/\");\n path = path.length > 1 ? path.replace(/\\/$/, \"\") : path;\n\n return path;\n}\n\nconst getParamName = (pattern: string) =>\n pattern.replace(/^:/, \"\").replace(/\\?$/, \"\");\n\nconst joinPaths = (...paths: string[]): string =>\n ([] as string[])\n .concat(...paths.map((p) => p.split(\"/\")))\n .filter(Boolean)\n .join(\"/\");\n\nconst createConfigItem = (\n config: PathConfig<object> | string,\n parentPattern?: string\n): ConfigItem => {\n if (typeof config === \"string\") {\n // If a string is specified as the value of the key(e.g. Foo: '/path'), use it as the pattern\n const pattern = parentPattern ? joinPaths(parentPattern, config) : config;\n\n return { pattern };\n }\n\n if (config.exact && config.path === undefined) {\n throw new Error(\n \"A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`.\"\n );\n }\n\n // If an object is specified as the value (e.g. Foo: { ... }),\n // It can have `path` property and `screens` prop which has nested configs\n const pattern =\n config.exact !== true\n ? joinPaths(parentPattern || \"\", config.path || \"\")\n : config.path || \"\";\n\n const screens = config.screens\n ? createNormalizedConfigs(config.screens, pattern)\n : undefined;\n\n return {\n // Normalize pattern to remove any leading, trailing slashes, duplicate slashes etc.\n pattern: pattern?.split(\"/\").filter(Boolean).join(\"/\"),\n stringify: config.stringify,\n screens,\n };\n};\n\nconst createNormalizedConfigs = (\n options: PathConfigMap<object>,\n pattern?: string\n): Record<string, ConfigItem> =>\n Object.fromEntries(\n Object.entries(options).map(([name, c]) => {\n const result = createConfigItem(c, pattern);\n\n return [name, result];\n })\n );\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { NavigationState, PartialState } from "@react-navigation/routers";
|
|
2
1
|
import { PathConfigMap } from "@react-navigation/core";
|
|
3
|
-
|
|
2
|
+
import type { NavigationState, PartialState } from "@react-navigation/routers";
|
|
3
|
+
declare type Options<ParamList extends object> = {
|
|
4
4
|
initialRouteName?: string;
|
|
5
5
|
screens: PathConfigMap<ParamList>;
|
|
6
6
|
};
|
|
@@ -28,6 +28,6 @@ declare type ResultState = PartialState<NavigationState> & {
|
|
|
28
28
|
* @param path Path string to parse and convert, e.g. /foo/bar?count=42.
|
|
29
29
|
* @param options Extra options to fine-tune how to parse the path.
|
|
30
30
|
*/
|
|
31
|
-
export default function getStateFromPath<ParamList extends
|
|
31
|
+
export default function getStateFromPath<ParamList extends object>(path: string, options?: Options<ParamList>): ResultState | undefined;
|
|
32
32
|
export {};
|
|
33
33
|
//# sourceMappingURL=getStateFromPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStateFromPath.d.ts","sourceRoot":"","sources":["../../src/fork/getStateFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"getStateFromPath.d.ts","sourceRoot":"","sources":["../../src/fork/getStateFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAGd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAEV,eAAe,EACf,YAAY,EACb,MAAM,2BAA2B,CAAC;AAQnC,aAAK,OAAO,CAAC,SAAS,SAAS,MAAM,IAAI;IACvC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACnC,CAAC;AAoBF,aAAK,WAAW,GAAG,YAAY,CAAC,eAAe,CAAC,GAAG;IACjD,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,SAAS,SAAS,MAAM,EAC/D,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAC3B,WAAW,GAAG,SAAS,CA+OzB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { findFocusedRoute, validatePathConfig, } from "@react-navigation/core";
|
|
1
2
|
import escape from "escape-string-regexp";
|
|
2
3
|
import * as queryString from "query-string";
|
|
3
|
-
import { findFocusedRoute, validatePathConfig, } from "@react-navigation/core";
|
|
4
4
|
/**
|
|
5
5
|
* Utility to parse a path string to initial state object accepted by the container.
|
|
6
6
|
* This is useful for deep linking when we need to handle the incoming URL.
|
|
@@ -26,7 +26,7 @@ export default function getStateFromPath(path, options) {
|
|
|
26
26
|
if (options) {
|
|
27
27
|
validatePathConfig(options);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
const initialRoutes = [];
|
|
30
30
|
if (options?.initialRouteName) {
|
|
31
31
|
initialRoutes.push({
|
|
32
32
|
initialRouteName: options.initialRouteName,
|
|
@@ -379,12 +379,11 @@ const createStateObject = (initialRoute, route, isEmpty) => {
|
|
|
379
379
|
}
|
|
380
380
|
};
|
|
381
381
|
const createNestedStateObject = (path, routes, initialRoutes, flatConfig) => {
|
|
382
|
-
let state;
|
|
383
382
|
let route = routes.shift();
|
|
384
383
|
const parentScreens = [];
|
|
385
384
|
let initialRoute = findInitialRoute(route.name, parentScreens, initialRoutes);
|
|
386
385
|
parentScreens.push(route.name);
|
|
387
|
-
state = createStateObject(initialRoute, route, routes.length === 0);
|
|
386
|
+
const state = createStateObject(initialRoute, route, routes.length === 0);
|
|
388
387
|
if (routes.length > 0) {
|
|
389
388
|
let nestedState = state;
|
|
390
389
|
while ((route = routes.shift())) {
|