expo-router 4.0.0-preview.9 → 4.0.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.
Files changed (194) hide show
  1. package/assets/error.png +0 -0
  2. package/assets/file.png +0 -0
  3. package/assets/forward.png +0 -0
  4. package/assets/logotype.png +0 -0
  5. package/assets/pkg.png +0 -0
  6. package/assets/sitemap.png +0 -0
  7. package/build/ExpoRoot.js +2 -2
  8. package/build/ExpoRoot.js.map +1 -1
  9. package/build/doctor/index.d.ts +16 -0
  10. package/build/doctor/index.d.ts.map +1 -0
  11. package/build/doctor/index.js +66 -0
  12. package/build/doctor/index.js.map +1 -0
  13. package/build/exports.d.ts +1 -1
  14. package/build/exports.d.ts.map +1 -1
  15. package/build/exports.js +24 -2
  16. package/build/exports.js.map +1 -1
  17. package/build/fast-refresh.d.ts.map +1 -1
  18. package/build/fast-refresh.js.map +1 -1
  19. package/build/getRoutesCore.d.ts +1 -0
  20. package/build/getRoutesCore.d.ts.map +1 -1
  21. package/build/getRoutesCore.js +3 -1
  22. package/build/getRoutesCore.js.map +1 -1
  23. package/build/global-state/router-store.d.ts.map +1 -1
  24. package/build/global-state/router-store.js +1 -2
  25. package/build/global-state/router-store.js.map +1 -1
  26. package/build/global-state/routing.d.ts.map +1 -1
  27. package/build/global-state/routing.js +4 -0
  28. package/build/global-state/routing.js.map +1 -1
  29. package/build/head/url.d.ts +1 -0
  30. package/build/head/url.d.ts.map +1 -1
  31. package/build/head/url.js +21 -4
  32. package/build/head/url.js.map +1 -1
  33. package/build/hooks.d.ts +90 -38
  34. package/build/hooks.d.ts.map +1 -1
  35. package/build/hooks.js +46 -39
  36. package/build/hooks.js.map +1 -1
  37. package/build/imperative-api.d.ts +58 -15
  38. package/build/imperative-api.d.ts.map +1 -1
  39. package/build/imperative-api.js.map +1 -1
  40. package/build/layouts/Drawer.d.ts +2 -142
  41. package/build/layouts/Drawer.d.ts.map +1 -1
  42. package/build/layouts/Drawer.js +8 -5
  43. package/build/layouts/Drawer.js.map +1 -1
  44. package/build/layouts/DrawerClient.d.ts +144 -0
  45. package/build/layouts/DrawerClient.d.ts.map +1 -0
  46. package/build/layouts/DrawerClient.js +10 -0
  47. package/build/layouts/DrawerClient.js.map +1 -0
  48. package/build/layouts/Stack.d.ts +2 -126
  49. package/build/layouts/Stack.d.ts.map +1 -1
  50. package/build/layouts/Stack.js +8 -6
  51. package/build/layouts/Stack.js.map +1 -1
  52. package/build/layouts/StackClient.d.ts +128 -0
  53. package/build/layouts/StackClient.d.ts.map +1 -0
  54. package/build/layouts/StackClient.js +10 -0
  55. package/build/layouts/StackClient.js.map +1 -0
  56. package/build/layouts/Tabs.d.ts +2 -134
  57. package/build/layouts/Tabs.d.ts.map +1 -1
  58. package/build/layouts/Tabs.js +5 -37
  59. package/build/layouts/Tabs.js.map +1 -1
  60. package/build/layouts/TabsClient.d.ts +136 -0
  61. package/build/layouts/TabsClient.d.ts.map +1 -0
  62. package/build/layouts/TabsClient.js +44 -0
  63. package/build/layouts/TabsClient.js.map +1 -0
  64. package/build/layouts/withLayoutContext.d.ts +4 -1
  65. package/build/layouts/withLayoutContext.d.ts.map +1 -1
  66. package/build/layouts/withLayoutContext.js +4 -1
  67. package/build/layouts/withLayoutContext.js.map +1 -1
  68. package/build/link/Link.d.ts +48 -4
  69. package/build/link/Link.d.ts.map +1 -1
  70. package/build/link/Link.js +47 -3
  71. package/build/link/Link.js.map +1 -1
  72. package/build/link/href.d.ts +1 -1
  73. package/build/link/href.d.ts.map +1 -1
  74. package/build/link/href.js.map +1 -1
  75. package/build/link/useLinkHooks.d.ts +122 -29
  76. package/build/link/useLinkHooks.d.ts.map +1 -1
  77. package/build/link/useLinkHooks.js.map +1 -1
  78. package/build/onboard/Tutorial.d.ts.map +1 -1
  79. package/build/onboard/Tutorial.js +140 -86
  80. package/build/onboard/Tutorial.js.map +1 -1
  81. package/build/renderRootComponent.d.ts.map +1 -1
  82. package/build/renderRootComponent.js +1 -2
  83. package/build/renderRootComponent.js.map +1 -1
  84. package/build/rsc/exports.d.ts +3 -1
  85. package/build/rsc/exports.d.ts.map +1 -1
  86. package/build/rsc/exports.js +3 -1
  87. package/build/rsc/exports.js.map +1 -1
  88. package/build/rsc/middleware.d.ts +1 -1
  89. package/build/rsc/middleware.d.ts.map +1 -1
  90. package/build/rsc/middleware.js +2 -1
  91. package/build/rsc/middleware.js.map +1 -1
  92. package/build/rsc/router/client.d.ts +2 -2
  93. package/build/rsc/router/client.d.ts.map +1 -1
  94. package/build/rsc/router/client.js.map +1 -1
  95. package/build/rsc/router/host.d.ts.map +1 -1
  96. package/build/rsc/router/host.js +20 -15
  97. package/build/rsc/router/host.js.map +1 -1
  98. package/build/rsc/rsc-renderer.d.ts +1 -1
  99. package/build/rsc/rsc-renderer.d.ts.map +1 -1
  100. package/build/rsc/rsc-renderer.js +1 -1
  101. package/build/rsc/rsc-renderer.js.map +1 -1
  102. package/build/rsc/server.d.ts +3 -0
  103. package/build/rsc/server.d.ts.map +1 -1
  104. package/build/rsc/server.js +19 -1
  105. package/build/rsc/server.js.map +1 -1
  106. package/build/testing-library/context-stubs.d.ts.map +1 -1
  107. package/build/testing-library/context-stubs.js +3 -1
  108. package/build/testing-library/context-stubs.js.map +1 -1
  109. package/build/testing-library/mocks.js +14 -13
  110. package/build/testing-library/mocks.js.map +1 -1
  111. package/build/typed-routes/generate.d.ts +5 -1
  112. package/build/typed-routes/generate.d.ts.map +1 -1
  113. package/build/typed-routes/generate.js +129 -64
  114. package/build/typed-routes/generate.js.map +1 -1
  115. package/build/typed-routes/index.d.ts +5 -0
  116. package/build/typed-routes/index.d.ts.map +1 -1
  117. package/build/typed-routes/index.js +8 -3
  118. package/build/typed-routes/index.js.map +1 -1
  119. package/build/typed-routes/testSetup.d.ts +1 -1
  120. package/build/typed-routes/testSetup.d.ts.map +1 -1
  121. package/build/typed-routes/testSetup.js +29 -17
  122. package/build/typed-routes/testSetup.js.map +1 -1
  123. package/build/typed-routes/types.d.ts +43 -145
  124. package/build/typed-routes/types.d.ts.map +1 -1
  125. package/build/typed-routes/types.js.map +1 -1
  126. package/build/types.d.ts +33 -0
  127. package/build/types.d.ts.map +1 -1
  128. package/build/types.js.map +1 -1
  129. package/build/ui/TabContext.d.ts +158 -1
  130. package/build/ui/TabContext.d.ts.map +1 -1
  131. package/build/ui/TabContext.js +25 -1
  132. package/build/ui/TabContext.js.map +1 -1
  133. package/build/ui/TabList.d.ts +17 -1
  134. package/build/ui/TabList.d.ts.map +1 -1
  135. package/build/ui/TabList.js +16 -0
  136. package/build/ui/TabList.js.map +1 -1
  137. package/build/ui/TabSlot.d.ts +55 -5
  138. package/build/ui/TabSlot.d.ts.map +1 -1
  139. package/build/ui/TabSlot.js +38 -14
  140. package/build/ui/TabSlot.js.map +1 -1
  141. package/build/ui/TabTrigger.d.ts +65 -70
  142. package/build/ui/TabTrigger.d.ts.map +1 -1
  143. package/build/ui/TabTrigger.js +25 -1
  144. package/build/ui/TabTrigger.js.map +1 -1
  145. package/build/ui/Tabs.d.ts +89 -132
  146. package/build/ui/Tabs.d.ts.map +1 -1
  147. package/build/ui/Tabs.js +53 -8
  148. package/build/ui/Tabs.js.map +1 -1
  149. package/build/ui/common.d.ts +3 -3
  150. package/build/ui/common.d.ts.map +1 -1
  151. package/build/ui/common.js.map +1 -1
  152. package/build/useFocusEffect.d.ts +15 -6
  153. package/build/useFocusEffect.d.ts.map +1 -1
  154. package/build/useFocusEffect.js +15 -6
  155. package/build/useFocusEffect.js.map +1 -1
  156. package/build/useNavigation.d.ts +11 -5
  157. package/build/useNavigation.d.ts.map +1 -1
  158. package/build/useNavigation.js +11 -5
  159. package/build/useNavigation.js.map +1 -1
  160. package/build/utils/splash.d.ts +6 -0
  161. package/build/utils/splash.d.ts.map +1 -0
  162. package/build/utils/splash.js +51 -0
  163. package/build/utils/splash.js.map +1 -0
  164. package/build/utils/url.js +2 -2
  165. package/build/utils/url.js.map +1 -1
  166. package/build/views/Navigator.d.ts +6 -5
  167. package/build/views/Navigator.d.ts.map +1 -1
  168. package/build/views/Navigator.js +6 -5
  169. package/build/views/Navigator.js.map +1 -1
  170. package/build/views/Sitemap.d.ts.map +1 -1
  171. package/build/views/Sitemap.js +93 -46
  172. package/build/views/Sitemap.js.map +1 -1
  173. package/build/views/Splash.d.ts +1 -1
  174. package/build/views/Splash.d.ts.map +1 -1
  175. package/build/views/Splash.js +3 -13
  176. package/build/views/Splash.js.map +1 -1
  177. package/build/views/Try.d.ts +1 -1
  178. package/build/views/Try.d.ts.map +1 -1
  179. package/build/views/Try.js +1 -1
  180. package/build/views/Try.js.map +1 -1
  181. package/doctor.js +1 -0
  182. package/entry-classic.js +0 -6
  183. package/package.json +23 -24
  184. package/plugin/build/index.d.ts +2 -0
  185. package/plugin/options.json +74 -73
  186. package/plugin/src/index.ts +64 -0
  187. package/rsc/entry.js +0 -6
  188. package/rsc/headers.d.ts +3 -0
  189. package/rsc/headers.js +5 -0
  190. package/build/rsc/runtime.d.ts +0 -9
  191. package/build/rsc/runtime.d.ts.map +0 -1
  192. package/build/rsc/runtime.js +0 -36
  193. package/build/rsc/runtime.js.map +0 -1
  194. package/virtual-client-boundaries.js +0 -1
@@ -0,0 +1,136 @@
1
+ import { BottomTabNavigationEventMap, BottomTabNavigationOptions } from '@react-navigation/bottom-tabs';
2
+ import { ParamListBase, TabNavigationState } from '@react-navigation/native';
3
+ import React from 'react';
4
+ import { Href } from '../types';
5
+ type TabsProps = BottomTabNavigationOptions & {
6
+ href?: Href | null;
7
+ };
8
+ export declare const Tabs: React.ForwardRefExoticComponent<Omit<Omit<import("@react-navigation/native").DefaultNavigatorOptions<ParamListBase, string | undefined, TabNavigationState<ParamListBase>, BottomTabNavigationOptions, BottomTabNavigationEventMap, import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase>> & import("@react-navigation/native").DefaultRouterOptions & {
9
+ backBehavior?: import("@react-navigation/routers/lib/typescript/commonjs/src/TabRouter").BackBehavior | undefined;
10
+ } & import("@react-navigation/bottom-tabs/lib/typescript/commonjs/src/types").BottomTabNavigationConfig, "children" | "initialRouteName" | "id" | "screenOptions" | "layout" | "screenListeners" | "screenLayout" | "UNSTABLE_getStateForRouteNamesChange"> & import("@react-navigation/native").DefaultRouterOptions<string> & {
11
+ children: React.ReactNode;
12
+ layout?: ((props: {
13
+ state: TabNavigationState<ParamListBase>;
14
+ navigation: import("@react-navigation/native").NavigationHelpers<ParamListBase, {}>;
15
+ descriptors: Record<string, import("@react-navigation/native").Descriptor<BottomTabNavigationOptions, import("@react-navigation/native").NavigationProp<ParamListBase, string, string | undefined, TabNavigationState<ParamListBase>, BottomTabNavigationOptions, BottomTabNavigationEventMap>, import("@react-navigation/native").RouteProp<ParamListBase, string>>>;
16
+ children: React.ReactNode;
17
+ }) => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
18
+ screenListeners?: Partial<{
19
+ tabPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabPress", true>;
20
+ tabLongPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabLongPress", unknown>;
21
+ transitionStart: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionStart", unknown>;
22
+ transitionEnd: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionEnd", unknown>;
23
+ focus: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "focus", unknown>;
24
+ blur: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "blur", unknown>;
25
+ state: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "state", unknown>;
26
+ beforeRemove: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "beforeRemove", true>;
27
+ }> | ((props: {
28
+ route: import("@react-navigation/native").RouteProp<ParamListBase, string>;
29
+ navigation: import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase, string, undefined>;
30
+ }) => Partial<{
31
+ tabPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabPress", true>;
32
+ tabLongPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabLongPress", unknown>;
33
+ transitionStart: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionStart", unknown>;
34
+ transitionEnd: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionEnd", unknown>;
35
+ focus: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "focus", unknown>;
36
+ blur: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "blur", unknown>;
37
+ state: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "state", unknown>;
38
+ beforeRemove: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "beforeRemove", true>;
39
+ }>) | undefined;
40
+ screenOptions?: BottomTabNavigationOptions | ((props: {
41
+ route: import("@react-navigation/native").RouteProp<ParamListBase, string>;
42
+ navigation: import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase, string, undefined>;
43
+ theme: ReactNavigation.Theme;
44
+ }) => BottomTabNavigationOptions) | undefined;
45
+ screenLayout?: ((props: {
46
+ route: import("@react-navigation/native").RouteProp<ParamListBase, string>;
47
+ navigation: import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase, string, undefined>;
48
+ theme: ReactNavigation.Theme;
49
+ children: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
50
+ }) => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
51
+ UNSTABLE_getStateForRouteNamesChange?: ((state: Readonly<{
52
+ key: string;
53
+ index: number;
54
+ routeNames: string[];
55
+ history?: unknown[] | undefined;
56
+ routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
57
+ type: string;
58
+ stale: false;
59
+ }>) => import("@react-navigation/native").PartialState<Readonly<{
60
+ key: string;
61
+ index: number;
62
+ routeNames: string[];
63
+ history?: unknown[] | undefined;
64
+ routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
65
+ type: string;
66
+ stale: false;
67
+ }>> | undefined) | undefined;
68
+ } & {
69
+ id?: undefined;
70
+ }, "children"> & Partial<Pick<Omit<import("@react-navigation/native").DefaultNavigatorOptions<ParamListBase, string | undefined, TabNavigationState<ParamListBase>, BottomTabNavigationOptions, BottomTabNavigationEventMap, import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase>> & import("@react-navigation/native").DefaultRouterOptions & {
71
+ backBehavior?: import("@react-navigation/routers/lib/typescript/commonjs/src/TabRouter").BackBehavior | undefined;
72
+ } & import("@react-navigation/bottom-tabs/lib/typescript/commonjs/src/types").BottomTabNavigationConfig, "children" | "initialRouteName" | "id" | "screenOptions" | "layout" | "screenListeners" | "screenLayout" | "UNSTABLE_getStateForRouteNamesChange"> & import("@react-navigation/native").DefaultRouterOptions<string> & {
73
+ children: React.ReactNode;
74
+ layout?: ((props: {
75
+ state: TabNavigationState<ParamListBase>;
76
+ navigation: import("@react-navigation/native").NavigationHelpers<ParamListBase, {}>;
77
+ descriptors: Record<string, import("@react-navigation/native").Descriptor<BottomTabNavigationOptions, import("@react-navigation/native").NavigationProp<ParamListBase, string, string | undefined, TabNavigationState<ParamListBase>, BottomTabNavigationOptions, BottomTabNavigationEventMap>, import("@react-navigation/native").RouteProp<ParamListBase, string>>>;
78
+ children: React.ReactNode;
79
+ }) => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
80
+ screenListeners?: Partial<{
81
+ tabPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabPress", true>;
82
+ tabLongPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabLongPress", unknown>;
83
+ transitionStart: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionStart", unknown>;
84
+ transitionEnd: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionEnd", unknown>;
85
+ focus: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "focus", unknown>;
86
+ blur: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "blur", unknown>;
87
+ state: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "state", unknown>;
88
+ beforeRemove: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "beforeRemove", true>;
89
+ }> | ((props: {
90
+ route: import("@react-navigation/native").RouteProp<ParamListBase, string>;
91
+ navigation: import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase, string, undefined>;
92
+ }) => Partial<{
93
+ tabPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabPress", true>;
94
+ tabLongPress: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "tabLongPress", unknown>;
95
+ transitionStart: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionStart", unknown>;
96
+ transitionEnd: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "transitionEnd", unknown>;
97
+ focus: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "focus", unknown>;
98
+ blur: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "blur", unknown>;
99
+ state: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "state", unknown>;
100
+ beforeRemove: import("@react-navigation/native").EventListenerCallback<BottomTabNavigationEventMap & import("@react-navigation/native").EventMapCore<TabNavigationState<ParamListBase>>, "beforeRemove", true>;
101
+ }>) | undefined;
102
+ screenOptions?: BottomTabNavigationOptions | ((props: {
103
+ route: import("@react-navigation/native").RouteProp<ParamListBase, string>;
104
+ navigation: import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase, string, undefined>;
105
+ theme: ReactNavigation.Theme;
106
+ }) => BottomTabNavigationOptions) | undefined;
107
+ screenLayout?: ((props: {
108
+ route: import("@react-navigation/native").RouteProp<ParamListBase, string>;
109
+ navigation: import("@react-navigation/bottom-tabs").BottomTabNavigationProp<ParamListBase, string, undefined>;
110
+ theme: ReactNavigation.Theme;
111
+ children: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
112
+ }) => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
113
+ UNSTABLE_getStateForRouteNamesChange?: ((state: Readonly<{
114
+ key: string;
115
+ index: number;
116
+ routeNames: string[];
117
+ history?: unknown[] | undefined;
118
+ routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
119
+ type: string;
120
+ stale: false;
121
+ }>) => import("@react-navigation/native").PartialState<Readonly<{
122
+ key: string;
123
+ index: number;
124
+ routeNames: string[];
125
+ history?: unknown[] | undefined;
126
+ routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
127
+ type: string;
128
+ stale: false;
129
+ }>> | undefined) | undefined;
130
+ } & {
131
+ id?: undefined;
132
+ }, "children">> & React.RefAttributes<unknown>> & {
133
+ Screen: (props: import("..").ScreenProps<TabsProps, TabNavigationState<ParamListBase>, BottomTabNavigationEventMap>) => null;
134
+ };
135
+ export default Tabs;
136
+ //# sourceMappingURL=TabsClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TabsClient.d.ts","sourceRoot":"","sources":["../../src/layouts/TabsClient.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAE3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhC,KAAK,SAAS,GAAG,0BAA0B,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,CAAC;AAErE,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCf,CAAC;AAEH,eAAe,IAAI,CAAC"}
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Tabs = void 0;
8
+ const bottom_tabs_1 = require("@react-navigation/bottom-tabs");
9
+ const react_1 = __importDefault(require("react"));
10
+ const react_native_1 = require("react-native");
11
+ const withLayoutContext_1 = require("./withLayoutContext");
12
+ const Link_1 = require("../link/Link");
13
+ // This is the only way to access the navigator.
14
+ const BottomTabNavigator = (0, bottom_tabs_1.createBottomTabNavigator)().Navigator;
15
+ exports.Tabs = (0, withLayoutContext_1.withLayoutContext)(BottomTabNavigator, (screens) => {
16
+ // Support the `href` shortcut prop.
17
+ return screens.map((screen) => {
18
+ if (typeof screen.options !== 'function' && screen.options?.href !== undefined) {
19
+ const { href, ...options } = screen.options;
20
+ if (options.tabBarButton) {
21
+ throw new Error('Cannot use `href` and `tabBarButton` together.');
22
+ }
23
+ return {
24
+ ...screen,
25
+ options: {
26
+ ...options,
27
+ tabBarItemStyle: href == null ? { display: 'none' } : options.tabBarItemStyle,
28
+ tabBarButton: (props) => {
29
+ if (href == null) {
30
+ return null;
31
+ }
32
+ const children = react_native_1.Platform.OS === 'web' ? props.children : <react_native_1.Pressable>{props.children}</react_native_1.Pressable>;
33
+ // TODO: React Navigation types these props as Animated.WithAnimatedValue<StyleProp<ViewStyle>>
34
+ // While Link expects a TextStyle. We need to reconcile these types.
35
+ return (<Link_1.Link {...props} style={[{ display: 'flex' }, props.style]} href={href} asChild={react_native_1.Platform.OS !== 'web'} children={children}/>);
36
+ },
37
+ },
38
+ };
39
+ }
40
+ return screen;
41
+ });
42
+ });
43
+ exports.default = exports.Tabs;
44
+ //# sourceMappingURL=TabsClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TabsClient.js","sourceRoot":"","sources":["../../src/layouts/TabsClient.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAEb,+DAIuC;AAEvC,kDAA0B;AAC1B,+CAAmD;AAEnD,2DAAwD;AACxD,uCAAoC;AAGpC,gDAAgD;AAChD,MAAM,kBAAkB,GAAG,IAAA,sCAAwB,GAAE,CAAC,SAAS,CAAC;AAInD,QAAA,IAAI,GAAG,IAAA,qCAAiB,EAKnC,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;IAChC,oCAAoC;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,IAAI,MAAM,CAAC,OAAO,EAAE,IAAI,KAAK,SAAS,EAAE;YAC9E,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;YAC5C,IAAI,OAAO,CAAC,YAAY,EAAE;gBACxB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;aACnE;YACD,OAAO;gBACL,GAAG,MAAM;gBACT,OAAO,EAAE;oBACP,GAAG,OAAO;oBACV,eAAe,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe;oBAC7E,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;wBACtB,IAAI,IAAI,IAAI,IAAI,EAAE;4BAChB,OAAO,IAAI,CAAC;yBACb;wBACD,MAAM,QAAQ,GACZ,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,wBAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,wBAAS,CAAC,CAAC;wBACnF,+FAA+F;wBAC/F,0EAA0E;wBAC1E,OAAO,CACL,CAAC,WAAI,CACH,IAAK,KAAa,CAAC,CACnB,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,KAAY,CAAC,CAAC,CACjD,IAAI,CAAC,CAAC,IAAI,CAAC,CACX,OAAO,CAAC,CAAC,uBAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAC/B,QAAQ,CAAC,CAAC,QAAQ,CAAC,EACnB,CACH,CAAC;oBACJ,CAAC;iBACF;aACF,CAAC;SACH;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,kBAAe,YAAI,CAAC","sourcesContent":["'use client';\n\nimport {\n BottomTabNavigationEventMap,\n BottomTabNavigationOptions,\n createBottomTabNavigator,\n} from '@react-navigation/bottom-tabs';\nimport { ParamListBase, TabNavigationState } from '@react-navigation/native';\nimport React from 'react';\nimport { Pressable, Platform } from 'react-native';\n\nimport { withLayoutContext } from './withLayoutContext';\nimport { Link } from '../link/Link';\nimport { Href } from '../types';\n\n// This is the only way to access the navigator.\nconst BottomTabNavigator = createBottomTabNavigator().Navigator;\n\ntype TabsProps = BottomTabNavigationOptions & { href?: Href | null };\n\nexport const Tabs = withLayoutContext<\n TabsProps,\n typeof BottomTabNavigator,\n TabNavigationState<ParamListBase>,\n BottomTabNavigationEventMap\n>(BottomTabNavigator, (screens) => {\n // Support the `href` shortcut prop.\n return screens.map((screen) => {\n if (typeof screen.options !== 'function' && screen.options?.href !== undefined) {\n const { href, ...options } = screen.options;\n if (options.tabBarButton) {\n throw new Error('Cannot use `href` and `tabBarButton` together.');\n }\n return {\n ...screen,\n options: {\n ...options,\n tabBarItemStyle: href == null ? { display: 'none' } : options.tabBarItemStyle,\n tabBarButton: (props) => {\n if (href == null) {\n return null;\n }\n const children =\n Platform.OS === 'web' ? props.children : <Pressable>{props.children}</Pressable>;\n // TODO: React Navigation types these props as Animated.WithAnimatedValue<StyleProp<ViewStyle>>\n // While Link expects a TextStyle. We need to reconcile these types.\n return (\n <Link\n {...(props as any)}\n style={[{ display: 'flex' }, props.style as any]}\n href={href}\n asChild={Platform.OS !== 'web'}\n children={children}\n />\n );\n },\n },\n };\n }\n return screen;\n });\n});\n\nexport default Tabs;\n"]}
@@ -10,7 +10,10 @@ export declare function useFilterScreenChildren(children: ReactNode, { isCustomN
10
10
  screens: any[] | null | undefined;
11
11
  children: any[];
12
12
  };
13
- /** Return a navigator that automatically injects matched routes and renders nothing when there are no children. Return type with children prop optional */
13
+ /**
14
+ * Returns a navigator that automatically injects matched routes and renders nothing when there are no children.
15
+ * Return type with `children` prop optional.
16
+ */
14
17
  export declare function withLayoutContext<TOptions extends object, T extends ComponentType<any>, TState extends NavigationState, TEventMap extends EventMapBase>(Nav: T, processor?: (options: ScreenProps<TOptions, TState, TEventMap>[]) => ScreenProps<TOptions, TState, TEventMap>[]): React.ForwardRefExoticComponent<React.PropsWithoutRef<PickPartial<React.ComponentProps<T>, "children">> & React.RefAttributes<unknown>> & {
15
18
  Screen: (props: ScreenProps<TOptions, TState, TEventMap>) => null;
16
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"withLayoutContext.d.ts","sourceRoot":"","sources":["../../src/layouts/withLayoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,EAIZ,aAAa,EAGb,SAAS,EAIV,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAoB,WAAW,EAAE,MAAM,eAAe,CAAC;AAG9D,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,SAAS,EACnB,EACE,iBAAiB,EACjB,UAAU,GACX,GAAE;IACD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IA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EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAChD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE;oBA2B7B,YAAY,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,KAAK,IAAI;EAEpE"}
@@ -67,7 +67,10 @@ function useFilterScreenChildren(children, { isCustomNavigator, contextKey, } =
67
67
  }, [children]);
68
68
  }
69
69
  exports.useFilterScreenChildren = useFilterScreenChildren;
70
- /** Return a navigator that automatically injects matched routes and renders nothing when there are no children. Return type with children prop optional */
70
+ /**
71
+ * Returns a navigator that automatically injects matched routes and renders nothing when there are no children.
72
+ * Return type with `children` prop optional.
73
+ */
71
74
  function withLayoutContext(Nav, processor) {
72
75
  return Object.assign((0, react_1.forwardRef)(({ children: userDefinedChildren, ...props }, ref) => {
73
76
  const contextKey = (0, Route_1.useContextKey)();
@@ -1 +1 @@
1
- {"version":3,"file":"withLayoutContext.js","sourceRoot":"","sources":["../../src/layouts/withLayoutContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAWe;AAEf,oCAAyC;AAEzC,8CAA8D;AAC9D,4CAAyC;AAEzC,SAAgB,uBAAuB,CACrC,QAAmB,EACnB,EACE,iBAAiB,EACjB,UAAU,MAKR,EAAE;IAEN,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;QAClB,MAAM,cAAc,GAAU,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAC/C,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,eAAM,EAAE;gBAC3D,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE;oBACrB,MAAM,IAAI,KAAK,CACb,sDAAsD,UAAU,8EAA8E,CAC/I,CAAC;iBACH;gBACD,IAAI,OAAO,CAAC,GAAG,CAA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AE,CAAC;QAEnC,MAAM,EAAE,OAAO,EAAE,GAAG,uBAAuB,CAAC,mBAAmB,EAAE;YAC/D,UAAU;SACX,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAEjE,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,SAAS,IAAI,EAAE,CAAC,CAAC;QAEjD,uDAAuD;QACvD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QAED,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAG,CAAC;IACxE,CAAC,CAAC,EACF;QACE,MAAM,EAAN,eAAM;KACP,CAKF,CAAC;AACJ,CAAC;AAtCD,8CAsCC","sourcesContent":["import { EventMapBase, NavigationState } from '@react-navigation/native';\nimport React, {\n Children,\n forwardRef,\n ComponentProps,\n ComponentType,\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ReactNode,\n RefAttributes,\n isValidElement,\n useMemo,\n} from 'react';\n\nimport { useContextKey } from '../Route';\nimport { PickPartial } from '../types';\nimport { useSortedScreens, ScreenProps } from '../useScreens';\nimport { Screen } from '../views/Screen';\n\nexport function useFilterScreenChildren(\n children: ReactNode,\n {\n isCustomNavigator,\n contextKey,\n }: {\n isCustomNavigator?: boolean;\n /** Used for sending developer hints */\n contextKey?: string;\n } = {}\n) {\n return useMemo(() => {\n const customChildren: any[] = [];\n const screens = Children.map(children, (child) => {\n if (isValidElement(child) && child && child.type === Screen) {\n if (!child.props.name) {\n throw new Error(\n `<Screen /> component in \\`default export\\` at \\`app${contextKey}/_layout\\` must have a \\`name\\` prop when used as a child of a Layout Route.`\n );\n }\n if (process.env.NODE_ENV !== 'production') {\n if (['children', 'component', 'getComponent'].some((key) => key in child.props)) {\n throw new Error(\n `<Screen /> component in \\`default export\\` at \\`app${contextKey}/_layout\\` must not have a \\`children\\`, \\`component\\`, or \\`getComponent\\` prop when used as a child of a Layout Route`\n );\n }\n }\n return child.props;\n } else {\n if (isCustomNavigator) {\n customChildren.push(child);\n } else {\n console.warn(\n `Layout children must be of type Screen, all other children are ignored. To use custom children, create a custom <Layout />. Update Layout Route at: \"app${contextKey}/_layout\"`\n );\n }\n }\n });\n\n // Add an assertion for development\n if (process.env.NODE_ENV !== 'production') {\n // Assert if names are not unique\n const names = screens?.map((screen) => screen.name);\n if (names && new Set(names).size !== names.length) {\n throw new Error('Screen names must be unique: ' + names);\n }\n }\n\n return {\n screens,\n children: customChildren,\n };\n }, [children]);\n}\n\n/** Return a navigator that automatically injects matched routes and renders nothing when there are no children. Return type with children prop optional */\nexport function withLayoutContext<\n TOptions extends object,\n T extends ComponentType<any>,\n TState extends NavigationState,\n TEventMap extends EventMapBase,\n>(\n Nav: T,\n processor?: (\n options: ScreenProps<TOptions, TState, TEventMap>[]\n ) => ScreenProps<TOptions, TState, TEventMap>[]\n) {\n return Object.assign(\n forwardRef(({ children: userDefinedChildren, ...props }: any, ref) => {\n const contextKey = useContextKey();\n\n const { screens } = useFilterScreenChildren(userDefinedChildren, {\n contextKey,\n });\n\n const processed = processor ? processor(screens ?? []) : screens;\n\n const sorted = useSortedScreens(processed ?? []);\n\n // Prevent throwing an error when there are no screens.\n if (!sorted.length) {\n return null;\n }\n\n return <Nav {...props} id={contextKey} ref={ref} children={sorted} />;\n }),\n {\n Screen,\n }\n ) as ForwardRefExoticComponent<\n PropsWithoutRef<PickPartial<ComponentProps<T>, 'children'>> & RefAttributes<unknown>\n > & {\n Screen: (props: ScreenProps<TOptions, TState, TEventMap>) => null;\n };\n}\n"]}
1
+ {"version":3,"file":"withLayoutContext.js","sourceRoot":"","sources":["../../src/layouts/withLayoutContext.tsx"],"names":[],"mappings":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C","sourcesContent":["import { EventMapBase, NavigationState } from '@react-navigation/native';\nimport React, {\n Children,\n forwardRef,\n ComponentProps,\n ComponentType,\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ReactNode,\n RefAttributes,\n isValidElement,\n useMemo,\n} from 'react';\n\nimport { useContextKey } from '../Route';\nimport { PickPartial } from '../types';\nimport { useSortedScreens, ScreenProps } from '../useScreens';\nimport { Screen } from '../views/Screen';\n\nexport function useFilterScreenChildren(\n children: ReactNode,\n {\n isCustomNavigator,\n contextKey,\n }: {\n isCustomNavigator?: boolean;\n /** Used for sending developer hints */\n contextKey?: string;\n } = {}\n) {\n return useMemo(() => {\n const customChildren: any[] = [];\n const screens = Children.map(children, (child) => {\n if (isValidElement(child) && child && child.type === Screen) {\n if (!child.props.name) {\n throw new Error(\n `<Screen /> component in \\`default export\\` at \\`app${contextKey}/_layout\\` must have a \\`name\\` prop when used as a child of a Layout Route.`\n );\n }\n if (process.env.NODE_ENV !== 'production') {\n if (['children', 'component', 'getComponent'].some((key) => key in child.props)) {\n throw new Error(\n `<Screen /> component in \\`default export\\` at \\`app${contextKey}/_layout\\` must not have a \\`children\\`, \\`component\\`, or \\`getComponent\\` prop when used as a child of a Layout Route`\n );\n }\n }\n return child.props;\n } else {\n if (isCustomNavigator) {\n customChildren.push(child);\n } else {\n console.warn(\n `Layout children must be of type Screen, all other children are ignored. To use custom children, create a custom <Layout />. Update Layout Route at: \"app${contextKey}/_layout\"`\n );\n }\n }\n });\n\n // Add an assertion for development\n if (process.env.NODE_ENV !== 'production') {\n // Assert if names are not unique\n const names = screens?.map((screen) => screen.name);\n if (names && new Set(names).size !== names.length) {\n throw new Error('Screen names must be unique: ' + names);\n }\n }\n\n return {\n screens,\n children: customChildren,\n };\n }, [children]);\n}\n\n/**\n * Returns a navigator that automatically injects matched routes and renders nothing when there are no children.\n * Return type with `children` prop optional.\n */\nexport function withLayoutContext<\n TOptions extends object,\n T extends ComponentType<any>,\n TState extends NavigationState,\n TEventMap extends EventMapBase,\n>(\n Nav: T,\n processor?: (\n options: ScreenProps<TOptions, TState, TEventMap>[]\n ) => ScreenProps<TOptions, TState, TEventMap>[]\n) {\n return Object.assign(\n forwardRef(({ children: userDefinedChildren, ...props }: any, ref) => {\n const contextKey = useContextKey();\n\n const { screens } = useFilterScreenChildren(userDefinedChildren, {\n contextKey,\n });\n\n const processed = processor ? processor(screens ?? []) : screens;\n\n const sorted = useSortedScreens(processed ?? []);\n\n // Prevent throwing an error when there are no screens.\n if (!sorted.length) {\n return null;\n }\n\n return <Nav {...props} id={contextKey} ref={ref} children={sorted} />;\n }),\n {\n Screen,\n }\n ) as ForwardRefExoticComponent<\n PropsWithoutRef<PickPartial<ComponentProps<T>, 'children'>> & RefAttributes<unknown>\n > & {\n Screen: (props: ScreenProps<TOptions, TState, TEventMap>) => null;\n };\n}\n"]}
@@ -2,17 +2,61 @@ import { PropsWithChildren } from 'react';
2
2
  import { Href } from '../types';
3
3
  import { LinkProps, WebAnchorProps } from './useLinkHooks';
4
4
  export interface LinkComponent {
5
- <T extends string | object>(props: PropsWithChildren<LinkProps<T>>): JSX.Element;
5
+ (props: PropsWithChildren<LinkProps>): JSX.Element;
6
6
  /** Helper method to resolve a Href object into a string. */
7
7
  resolveHref: (href: Href) => string;
8
8
  }
9
- /** Redirects to the href as soon as the component is mounted. */
9
+ /**
10
+ * Redirects to the `href` as soon as the component is mounted.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { View, Text } from 'react-native';
15
+ * import { Redirect } from 'expo-router';
16
+ *
17
+ * export default function Page() {
18
+ * const { user } = useAuth();
19
+ *
20
+ * if (!user) {
21
+ * return <Redirect href="/login" />;
22
+ * }
23
+ *
24
+ * return (
25
+ * <View>
26
+ * <Text>Welcome Back!</Text>
27
+ * </View>
28
+ * );
29
+ * }
30
+ * ```
31
+ */
10
32
  export declare function Redirect({ href }: {
11
33
  href: Href;
12
34
  }): null;
13
35
  /**
14
- * Component to render link to another route using a path.
15
- * Uses an anchor tag on the web.
36
+ * Component that renders a link using [`href`](#href) to another route.
37
+ * By default, it accepts children and wraps them in a `<Text>` component.
38
+ *
39
+ * Uses an anchor tag (`<a>`) on web and performs a client-side navigation to preserve
40
+ * the state of the website and navigate faster. The web-only attributes such as `target`,
41
+ * `rel`, and `download` are supported and passed to the anchor tag on web. See
42
+ * [`WebAnchorProps`](#webanchorprops) for more details.
43
+ *
44
+ * > **Note**: Client-side navigation works with both single-page apps,
45
+ * and [static-rendering](/router/reference/static-rendering/).
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * import { Link } from 'expo-router';
50
+ * import { View } from 'react-native';
51
+ *
52
+ * export default function Route() {
53
+ * return (
54
+ * <View>
55
+ * <Link href="/about">About</Link>
56
+ * </View>
57
+ * );
58
+ *}
59
+ * ```
16
60
  */
17
61
  export declare const Link: LinkComponent;
18
62
  export { LinkProps, WebAnchorProps };
@@ -1 +1 @@
1
- {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAiD,MAAM,OAAO,CAAC;AAOzF,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAqC,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE9F,MAAM,WAAW,aAAa;IAC5B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;IACjF,4DAA4D;IAC5D,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;CACrC;AAED,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,QAUhD;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,eAAyD,CAAC;AAuE3E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAiD,MAAM,OAAO,CAAC;AAOzF,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAqC,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE9F,MAAM,WAAW,aAAa;IAC5B,CAAC,KAAK,EAAE,iBAAiB,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;IACnD,4DAA4D;IAC5D,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,QAUhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,eAAyD,CAAC;AAuE3E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
@@ -15,7 +15,29 @@ const useLinkToPathProps_1 = __importDefault(require("./useLinkToPathProps"));
15
15
  const hooks_1 = require("../hooks");
16
16
  const useFocusEffect_1 = require("../useFocusEffect");
17
17
  const useLinkHooks_1 = require("./useLinkHooks");
18
- /** Redirects to the href as soon as the component is mounted. */
18
+ /**
19
+ * Redirects to the `href` as soon as the component is mounted.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * import { View, Text } from 'react-native';
24
+ * import { Redirect } from 'expo-router';
25
+ *
26
+ * export default function Page() {
27
+ * const { user } = useAuth();
28
+ *
29
+ * if (!user) {
30
+ * return <Redirect href="/login" />;
31
+ * }
32
+ *
33
+ * return (
34
+ * <View>
35
+ * <Text>Welcome Back!</Text>
36
+ * </View>
37
+ * );
38
+ * }
39
+ * ```
40
+ */
19
41
  function Redirect({ href }) {
20
42
  const router = (0, hooks_1.useRouter)();
21
43
  (0, useFocusEffect_1.useFocusEffect)(() => {
@@ -30,8 +52,30 @@ function Redirect({ href }) {
30
52
  }
31
53
  exports.Redirect = Redirect;
32
54
  /**
33
- * Component to render link to another route using a path.
34
- * Uses an anchor tag on the web.
55
+ * Component that renders a link using [`href`](#href) to another route.
56
+ * By default, it accepts children and wraps them in a `<Text>` component.
57
+ *
58
+ * Uses an anchor tag (`<a>`) on web and performs a client-side navigation to preserve
59
+ * the state of the website and navigate faster. The web-only attributes such as `target`,
60
+ * `rel`, and `download` are supported and passed to the anchor tag on web. See
61
+ * [`WebAnchorProps`](#webanchorprops) for more details.
62
+ *
63
+ * > **Note**: Client-side navigation works with both single-page apps,
64
+ * and [static-rendering](/router/reference/static-rendering/).
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * import { Link } from 'expo-router';
69
+ * import { View } from 'react-native';
70
+ *
71
+ * export default function Route() {
72
+ * return (
73
+ * <View>
74
+ * <Link href="/about">About</Link>
75
+ * </View>
76
+ * );
77
+ *}
78
+ * ```
35
79
  */
36
80
  exports.Link = (0, react_1.forwardRef)(ExpoRouterLink);
37
81
  exports.Link.resolveHref = href_1.resolveHref;
@@ -1 +1 @@
1
- {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AACb,wFAAwF;AACxF,mCAAmC;AACnC,iCAAyF;AACzF,+CAAqE;AAErE,yCAAkC;AAClC,iCAAqC;AACrC,8EAAsD;AACtD,oCAAqC;AAErC,sDAAmD;AACnD,iDAA8F;AAQ9F,iEAAiE;AACjE,SAAgB,QAAQ,CAAC,EAAE,IAAI,EAAkB;IAC/C,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,IAAA,+BAAc,EAAC,GAAG,EAAE;QAClB,IAAI;YACF,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SACtB;QAAC,OAAO,KAAK,EAA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AAE,CAAC,CAAC,CAAC,CAAC;SACnB;QACD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,eAAI,CAAC,CAAC,CAAC,mBAAI,CAAC;IAEtC,6HAA6H;IAC7H,OAAO,CACL,CAAC,OAAO,CACN,GAAG,CAAC,CAAC,GAAG,CAAC,CACT,IAAI,KAAK,CAAC,CACV,IAAI,SAAS,CAAC,CACd,IAAI,IAAI,CAAC,CACT,KAAK,CAAC,CAAC,KAAK,CAAC,CACb,IAAI,uBAAQ,CAAC,MAAM,CAAC;QAClB,GAAG,EAAE;YACH,OAAO,EAAE,OAAO;SACV;QACR,OAAO,EAAE,EAAE,OAAO,EAAE;KACrB,CAAC,CAAC,EACH,CACH,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n// Fork of @react-navigation/native Link.tsx with `href` and `replace` support added and\n// `to` / `action` support removed.\nimport { PropsWithChildren, forwardRef, useMemo, MouseEvent, ForwardedRef } from 'react';\nimport { Text, GestureResponderEvent, Platform } from 'react-native';\n\nimport { Slot } from './LinkSlot';\nimport { resolveHref } from './href';\nimport useLinkToPathProps from './useLinkToPathProps';\nimport { useRouter } from '../hooks';\nimport { Href } from '../types';\nimport { useFocusEffect } from '../useFocusEffect';\nimport { useInteropClassName, useHrefAttrs, LinkProps, WebAnchorProps } from './useLinkHooks';\n\nexport interface LinkComponent {\n <T extends string | object>(props: PropsWithChildren<LinkProps<T>>): JSX.Element;\n /** Helper method to resolve a Href object into a string. */\n resolveHref: (href: Href) => string;\n}\n\n/** Redirects to the href as soon as the component is mounted. */\nexport function Redirect({ href }: { href: Href }) {\n const router = useRouter();\n useFocusEffect(() => {\n try {\n router.replace(href);\n } catch (error) {\n console.error(error);\n }\n });\n return null;\n}\n\n/**\n * Component to render link to another route using a path.\n * Uses an anchor tag on the web.\n */\nexport const Link = forwardRef(ExpoRouterLink) as unknown as LinkComponent;\n\nLink.resolveHref = resolveHref;\n\nfunction ExpoRouterLink(\n {\n href,\n replace,\n push,\n // TODO: This does not prevent default on the anchor tag.\n relativeToDirectory,\n asChild,\n rel,\n target,\n download,\n withAnchor,\n ...rest\n }: LinkProps<any>,\n ref: ForwardedRef<Text>\n) {\n // Mutate the style prop to add the className on web.\n const style = useInteropClassName(rest);\n\n // If not passing asChild, we need to forward the props to the anchor tag using React Native Web's `hrefAttrs`.\n const hrefAttrs = useHrefAttrs({ asChild, rel, target, download });\n\n const resolvedHref = useMemo(() => {\n if (href == null) {\n throw new Error('Link: href is required');\n }\n return resolveHref(href);\n }, [href]);\n\n let event;\n if (push) event = 'PUSH';\n if (replace) event = 'REPLACE';\n\n const props = useLinkToPathProps({\n href: resolvedHref,\n event,\n relativeToDirectory,\n withAnchor,\n });\n\n const onPress = (e: MouseEvent<HTMLAnchorElement> | GestureResponderEvent) => {\n if ('onPress' in rest) {\n rest.onPress?.(e);\n }\n props.onPress(e);\n };\n\n const Element = asChild ? Slot : Text;\n\n // Avoid using createElement directly, favoring JSX, to allow tools like NativeWind to perform custom JSX handling on native.\n return (\n <Element\n ref={ref}\n {...props}\n {...hrefAttrs}\n {...rest}\n style={style}\n {...Platform.select({\n web: {\n onClick: onPress,\n } as any,\n default: { onPress },\n })}\n />\n );\n}\n\nexport { LinkProps, WebAnchorProps };\n"]}
1
+ {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/link/Link.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AACb,wFAAwF;AACxF,mCAAmC;AACnC,iCAAyF;AACzF,+CAAqE;AAErE,yCAAkC;AAClC,iCAAqC;AACrC,8EAAsD;AACtD,oCAAqC;AAErC,sDAAmD;AACnD,iDAA8F;AAQ9F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,QAAQ,CAAC,EAAE,IAAI,EAAkB;IAC/C,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,IAAA,+BA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UAAU;KACX,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,CAAC,CAAwD,EAAE,EAAE;QAC3E,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;SACnB;QACD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,eAAI,CAAC,CAAC,CAAC,mBAAI,CAAC;IAEtC,6HAA6H;IAC7H,OAAO,CACL,CAAC,OAAO,CACN,GAAG,CAAC,CAAC,GAAG,CAAC,CACT,IAAI,KAAK,CAAC,CACV,IAAI,SAAS,CAAC,CACd,IAAI,IAAI,CAAC,CACT,KAAK,CAAC,CAAC,KAAK,CAAC,CACb,IAAI,uBAAQ,CAAC,MAAM,CAAC;QAClB,GAAG,EAAE;YACH,OAAO,EAAE,OAAO;SACV;QACR,OAAO,EAAE,EAAE,OAAO,EAAE;KACrB,CAAC,CAAC,EACH,CACH,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n// Fork of @react-navigation/native Link.tsx with `href` and `replace` support added and\n// `to` / `action` support removed.\nimport { PropsWithChildren, forwardRef, useMemo, MouseEvent, ForwardedRef } from 'react';\nimport { Text, GestureResponderEvent, Platform } from 'react-native';\n\nimport { Slot } from './LinkSlot';\nimport { resolveHref } from './href';\nimport useLinkToPathProps from './useLinkToPathProps';\nimport { useRouter } from '../hooks';\nimport { Href } from '../types';\nimport { useFocusEffect } from '../useFocusEffect';\nimport { useInteropClassName, useHrefAttrs, LinkProps, WebAnchorProps } from './useLinkHooks';\n\nexport interface LinkComponent {\n (props: PropsWithChildren<LinkProps>): JSX.Element;\n /** Helper method to resolve a Href object into a string. */\n resolveHref: (href: Href) => string;\n}\n\n/**\n * Redirects to the `href` as soon as the component is mounted.\n *\n * @example\n * ```tsx\n * import { View, Text } from 'react-native';\n * import { Redirect } from 'expo-router';\n *\n * export default function Page() {\n * const { user } = useAuth();\n *\n * if (!user) {\n * return <Redirect href=\"/login\" />;\n * }\n *\n * return (\n * <View>\n * <Text>Welcome Back!</Text>\n * </View>\n * );\n * }\n * ```\n */\nexport function Redirect({ href }: { href: Href }) {\n const router = useRouter();\n useFocusEffect(() => {\n try {\n router.replace(href);\n } catch (error) {\n console.error(error);\n }\n });\n return null;\n}\n\n/**\n * Component that renders a link using [`href`](#href) to another route.\n * By default, it accepts children and wraps them in a `<Text>` component.\n *\n * Uses an anchor tag (`<a>`) on web and performs a client-side navigation to preserve\n * the state of the website and navigate faster. The web-only attributes such as `target`,\n * `rel`, and `download` are supported and passed to the anchor tag on web. See\n * [`WebAnchorProps`](#webanchorprops) for more details.\n *\n * > **Note**: Client-side navigation works with both single-page apps,\n * and [static-rendering](/router/reference/static-rendering/).\n *\n * @example\n * ```tsx\n * import { Link } from 'expo-router';\n * import { View } from 'react-native';\n *\n * export default function Route() {\n * return (\n * <View>\n * <Link href=\"/about\">About</Link>\n * </View>\n * );\n *}\n * ```\n */\nexport const Link = forwardRef(ExpoRouterLink) as unknown as LinkComponent;\n\nLink.resolveHref = resolveHref;\n\nfunction ExpoRouterLink(\n {\n href,\n replace,\n push,\n // TODO: This does not prevent default on the anchor tag.\n relativeToDirectory,\n asChild,\n rel,\n target,\n download,\n withAnchor,\n ...rest\n }: LinkProps,\n ref: ForwardedRef<Text>\n) {\n // Mutate the style prop to add the className on web.\n const style = useInteropClassName(rest);\n\n // If not passing asChild, we need to forward the props to the anchor tag using React Native Web's `hrefAttrs`.\n const hrefAttrs = useHrefAttrs({ asChild, rel, target, download });\n\n const resolvedHref = useMemo(() => {\n if (href == null) {\n throw new Error('Link: href is required');\n }\n return resolveHref(href);\n }, [href]);\n\n let event;\n if (push) event = 'PUSH';\n if (replace) event = 'REPLACE';\n\n const props = useLinkToPathProps({\n href: resolvedHref,\n event,\n relativeToDirectory,\n withAnchor,\n });\n\n const onPress = (e: MouseEvent<HTMLAnchorElement> | GestureResponderEvent) => {\n if ('onPress' in rest) {\n rest.onPress?.(e);\n }\n props.onPress(e);\n };\n\n const Element = asChild ? Slot : Text;\n\n // Avoid using createElement directly, favoring JSX, to allow tools like NativeWind to perform custom JSX handling on native.\n return (\n <Element\n ref={ref}\n {...props}\n {...hrefAttrs}\n {...rest}\n style={style}\n {...Platform.select({\n web: {\n onClick: onPress,\n } as any,\n default: { onPress },\n })}\n />\n );\n}\n\nexport { LinkProps, WebAnchorProps };\n"]}
@@ -1,6 +1,6 @@
1
1
  import { UrlObject } from '../LocationProvider';
2
2
  import { Href } from '../types';
3
3
  /** Resolve an href object into a fully qualified, relative href. */
4
- export declare const resolveHref: (href: Href<any>) => string;
4
+ export declare const resolveHref: (href: Href) => string;
5
5
  export declare function resolveHrefStringWithSegments(href: string, { segments, params }?: Partial<UrlObject>, relativeToDirectory?: boolean): string;
6
6
  //# sourceMappingURL=href.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"href.d.ts","sourceRoot":"","sources":["../../src/link/href.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAmB,MAAM,UAAU,CAAC;AAEjD,oEAAoE;AACpE,eAAO,MAAM,WAAW,SAAU,KAAK,GAAG,CAAC,KAAG,MAa7C,CAAC;AAEF,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,EACZ,EAAE,QAAa,EAAE,MAAW,EAAE,GAAE,OAAO,CAAC,SAAS,CAAM,EACvD,mBAAmB,GAAE,OAAe,UAiCrC"}
1
+ {"version":3,"file":"href.d.ts","sourceRoot":"","sources":["../../src/link/href.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,oEAAoE;AACpE,eAAO,MAAM,WAAW,SAAU,IAAI,KAAG,MAaxC,CAAC;AAEF,wBAAgB,6B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WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;SAC7D;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;YAC5C,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;SACjE;aAAM;YACL,SAAS;SACV;QAED,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,WAAW,CAAC,KAAU;IAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACnD;IAED,OAAO,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,iBAAiB,CAAC,MAA2B;IACpD,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,uBAAuB;SACtB,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;SACpC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;SACvE,IAAI,CAAC,GAAG,CAAC,CACb,CAAC;AACJ,CAAC","sourcesContent":["import { UrlObject } from '../LocationProvider';\nimport { Href, RouteParamInput } from '../types';\n\n/** Resolve an href object into a fully qualified, relative href. */\nexport const resolveHref = (href: Href<any>): string => {\n if (typeof href === 'string') {\n return resolveHref({ pathname: href });\n }\n const path = href.pathname ?? '';\n if (!href?.params) {\n return path;\n }\n const { pathname, params } = createQualifiedPathname(path, {\n ...href.params,\n });\n const paramsString = createQueryParams(params);\n return pathname + (paramsString ? `?${paramsString}` : '');\n};\n\nexport function resolveHrefStringWithSegments(\n href: string,\n { segments = [], params = {} }: Partial<UrlObject> = {},\n relativeToDirectory: boolean = false\n) {\n if (href.startsWith('.')) {\n // Resolve base path by merging the current segments with the params\n let base =\n segments\n ?.map((segment) => {\n if (!segment.startsWith('[')) return segment;\n\n if (segment.startsWith('[...')) {\n segment = segment.slice(4, -1);\n const param = params[segment];\n if (Array.isArray(param)) {\n return param.join('/');\n } else {\n return param?.split(',')?.join('/') ?? '';\n }\n } else {\n segment = segment.slice(1, -1);\n return params[segment];\n }\n })\n .filter(Boolean)\n .join('/') ?? '/';\n\n if (relativeToDirectory) {\n base = `${base}/`;\n }\n\n href = new URL(href, `http://hostname/${base}`).pathname;\n }\n\n return href;\n}\n\nfunction createQualifiedPathname(\n pathname: string,\n params: Record<string, any>\n): { pathname: string; params: RouteParamInput<string> } {\n for (const [key, value = ''] of Object.entries(params)) {\n const dynamicKey = `[${key}]`;\n const deepDynamicKey = `[...${key}]`;\n if (pathname.includes(dynamicKey)) {\n pathname = pathname.replace(dynamicKey, encodeParam(value));\n } else if (pathname.includes(deepDynamicKey)) {\n pathname = pathname.replace(deepDynamicKey, encodeParam(value));\n } else {\n continue;\n }\n\n delete params[key];\n }\n return { pathname, params };\n}\n\nfunction encodeParam(param: any): string {\n if (Array.isArray(param)) {\n return param.map((p) => encodeParam(p)).join('/');\n }\n\n return encodeURIComponent(param.toString());\n}\n\nfunction createQueryParams(params: Record<string, any>): string {\n return (\n Object.entries(params)\n // Allow nullish params\n .filter(([, value]) => value != null)\n .map(([key, value]) => `${key}=${encodeURIComponent(value.toString())}`)\n .join('&')\n );\n}\n"]}
1
+ {"version":3,"file":"href.js","sourceRoot":"","sources":["../../src/link/href.ts"],"names":[],"mappings":";;;AAGA,oEAAoE;AAC7D,MAAM,WAAW,GAAG,CAAC,IAAU,EAAU,EAAE;IAChD,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QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,WAAW,CAAC,KAAU;IAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACnD;IAED,OAAO,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,iBAAiB,CAAC,MAA2B;IACpD,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,uBAAuB;SACtB,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;SACpC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;SACvE,IAAI,CAAC,GAAG,CAAC,CACb,CAAC;AACJ,CAAC","sourcesContent":["import { UrlObject } from '../LocationProvider';\nimport { Href } from '../types';\n\n/** Resolve an href object into a fully qualified, relative href. */\nexport const resolveHref = (href: Href): string => {\n if (typeof href === 'string') {\n return resolveHref({ pathname: href });\n }\n const path = href.pathname ?? '';\n if (!href?.params) {\n return path;\n }\n const { pathname, params } = createQualifiedPathname(path, {\n ...href.params,\n });\n const paramsString = createQueryParams(params);\n return pathname + (paramsString ? `?${paramsString}` : '');\n};\n\nexport function resolveHrefStringWithSegments(\n href: string,\n { segments = [], params = {} }: Partial<UrlObject> = {},\n relativeToDirectory: boolean = false\n) {\n if (href.startsWith('.')) {\n // Resolve base path by merging the current segments with the params\n let base =\n segments\n ?.map((segment) => {\n if (!segment.startsWith('[')) return segment;\n\n if (segment.startsWith('[...')) {\n segment = segment.slice(4, -1);\n const param = params[segment];\n if (Array.isArray(param)) {\n return param.join('/');\n } else {\n return param?.split(',')?.join('/') ?? '';\n }\n } else {\n segment = segment.slice(1, -1);\n return params[segment];\n }\n })\n .filter(Boolean)\n .join('/') ?? '/';\n\n if (relativeToDirectory) {\n base = `${base}/`;\n }\n\n href = new URL(href, `http://hostname/${base}`).pathname;\n }\n\n return href;\n}\n\nfunction createQualifiedPathname(\n pathname: string,\n params: Record<string, any>\n): { pathname: string; params: any } {\n for (const [key, value = ''] of Object.entries(params)) {\n const dynamicKey = `[${key}]`;\n const deepDynamicKey = `[...${key}]`;\n if (pathname.includes(dynamicKey)) {\n pathname = pathname.replace(dynamicKey, encodeParam(value));\n } else if (pathname.includes(deepDynamicKey)) {\n pathname = pathname.replace(deepDynamicKey, encodeParam(value));\n } else {\n continue;\n }\n\n delete params[key];\n }\n return { pathname, params };\n}\n\nfunction encodeParam(param: any): string {\n if (Array.isArray(param)) {\n return param.map((p) => encodeParam(p)).join('/');\n }\n\n return encodeURIComponent(param.toString());\n}\n\nfunction createQueryParams(params: Record<string, any>): string {\n return (\n Object.entries(params)\n // Allow nullish params\n .filter(([, value]) => value != null)\n .map(([key, value]) => `${key}=${encodeURIComponent(value.toString())}`)\n .join('&')\n );\n}\n"]}