expo-router 6.1.0-canary-20251015-a6a1272 → 7.0.0-canary-20251023-4c86f95
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/_error.js +36 -3
- package/build/ExpoRoot.js +1 -1
- package/build/ExpoRoot.js.map +1 -1
- package/build/global-state/router-store.d.ts +2 -0
- package/build/global-state/router-store.d.ts.map +1 -1
- package/build/global-state/router-store.js +16 -12
- package/build/global-state/router-store.js.map +1 -1
- package/build/global-state/routing.d.ts +12 -4
- package/build/global-state/routing.d.ts.map +1 -1
- package/build/global-state/routing.js +35 -10
- package/build/global-state/routing.js.map +1 -1
- package/build/global-state/storeContext.d.ts +2 -0
- package/build/global-state/storeContext.d.ts.map +1 -1
- package/build/layouts/BaseStack.d.ts +3 -0
- package/build/layouts/BaseStack.d.ts.map +1 -0
- package/build/layouts/BaseStack.js +8 -0
- package/build/layouts/BaseStack.js.map +1 -0
- package/build/layouts/ExperimentalModalStack.d.ts +9 -0
- package/build/layouts/ExperimentalModalStack.d.ts.map +1 -0
- package/build/layouts/ExperimentalModalStack.js +15 -0
- package/build/layouts/ExperimentalModalStack.js.map +1 -0
- package/build/layouts/Stack.web.d.ts +1 -14
- package/build/layouts/Stack.web.d.ts.map +1 -1
- package/build/layouts/Stack.web.js +10 -13
- package/build/layouts/Stack.web.js.map +1 -1
- package/build/layouts/_web-modal.d.ts +3 -0
- package/build/layouts/_web-modal.d.ts.map +1 -0
- package/build/layouts/_web-modal.js +8 -0
- package/build/layouts/_web-modal.js.map +1 -0
- package/build/modal/web/ModalStack.d.ts.map +1 -1
- package/build/modal/web/ModalStack.js +7 -2
- package/build/modal/web/ModalStack.js.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.d.ts.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.js +4 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.js.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.d.ts.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.js +6 -2
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.js.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.d.ts.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.js +7 -4
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.js.map +1 -1
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.web.js +15 -14
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.web.js.map +1 -1
- package/build/native-tabs/NativeBottomTabs/types.d.ts +8 -2
- package/build/native-tabs/NativeBottomTabs/types.d.ts.map +1 -1
- package/build/native-tabs/NativeBottomTabs/types.js.map +1 -1
- package/build/native-tabs/NativeBottomTabs/utils.d.ts +10 -1
- package/build/native-tabs/NativeBottomTabs/utils.d.ts.map +1 -1
- package/build/native-tabs/NativeBottomTabs/utils.js +24 -0
- package/build/native-tabs/NativeBottomTabs/utils.js.map +1 -1
- package/build/renderRootComponent.d.ts.map +1 -1
- package/build/renderRootComponent.js +4 -7
- package/build/renderRootComponent.js.map +1 -1
- package/build/static/html.d.ts +1 -9
- package/build/static/html.d.ts.map +1 -1
- package/build/static/html.js +0 -26
- package/build/static/html.js.map +1 -1
- package/build/ui/TabRouter.d.ts +3 -4
- package/build/ui/TabRouter.d.ts.map +1 -1
- package/build/ui/TabRouter.js +14 -67
- package/build/ui/TabRouter.js.map +1 -1
- package/build/ui/TabTrigger.d.ts +4 -5
- package/build/ui/TabTrigger.d.ts.map +1 -1
- package/build/ui/TabTrigger.js +9 -8
- package/build/ui/TabTrigger.js.map +1 -1
- package/build/ui/Tabs.d.ts +0 -1
- package/build/ui/Tabs.d.ts.map +1 -1
- package/build/ui/Tabs.js.map +1 -1
- package/html.js +1 -1
- package/package.json +9 -8
- package/build/getServerManifest.d.ts +0 -88
- package/build/getServerManifest.d.ts.map +0 -1
- package/build/getServerManifest.js +0 -238
- package/build/getServerManifest.js.map +0 -1
- package/build/routes-manifest.d.ts +0 -28
- package/build/routes-manifest.d.ts.map +0 -1
- package/build/routes-manifest.js +0 -30
- package/build/routes-manifest.js.map +0 -1
- package/build/static/getRootComponent.d.ts +0 -2
- package/build/static/getRootComponent.d.ts.map +0 -1
- package/build/static/getRootComponent.js +0 -25
- package/build/static/getRootComponent.js.map +0 -1
- package/build/static/getServerManifest.d.ts +0 -22
- package/build/static/getServerManifest.d.ts.map +0 -1
- package/build/static/getServerManifest.js +0 -50
- package/build/static/getServerManifest.js.map +0 -1
- package/build/static/renderStaticContent.d.ts +0 -15
- package/build/static/renderStaticContent.d.ts.map +0 -1
- package/build/static/renderStaticContent.js +0 -130
- package/build/static/renderStaticContent.js.map +0 -1
- package/build/utils/html.d.ts +0 -12
- package/build/utils/html.d.ts.map +0 -1
- package/build/utils/html.js +0 -29
- package/build/utils/html.js.map +0 -1
- package/node/render.js +0 -3
package/build/ui/TabTrigger.js
CHANGED
|
@@ -30,10 +30,10 @@ const TabTriggerSlot = react_slot_1.Slot;
|
|
|
30
30
|
* </Tabs>
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
function TabTrigger({ asChild, name, href,
|
|
33
|
+
function TabTrigger({ asChild, name, href, resetOnFocus, ...props }) {
|
|
34
34
|
const { trigger, triggerProps } = useTabTrigger({
|
|
35
35
|
name,
|
|
36
|
-
|
|
36
|
+
resetOnFocus,
|
|
37
37
|
...props,
|
|
38
38
|
});
|
|
39
39
|
// Pressable doesn't accept the extra props, so only pass them if we are using asChild
|
|
@@ -61,7 +61,7 @@ function isTabTrigger(child) {
|
|
|
61
61
|
*/
|
|
62
62
|
function useTabTrigger(options) {
|
|
63
63
|
const { state, navigation } = (0, Navigator_1.useNavigatorContext)();
|
|
64
|
-
const { name,
|
|
64
|
+
const { name, resetOnFocus, onPress, onLongPress } = options;
|
|
65
65
|
const triggerMap = (0, react_1.use)(TabContext_1.TabTriggerMapContext);
|
|
66
66
|
const getTrigger = (0, react_1.useCallback)((name) => {
|
|
67
67
|
const config = triggerMap[name];
|
|
@@ -84,9 +84,10 @@ function useTabTrigger(options) {
|
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
86
|
return navigation?.dispatch({
|
|
87
|
+
...config.action,
|
|
87
88
|
type: 'JUMP_TO',
|
|
88
89
|
payload: {
|
|
89
|
-
|
|
90
|
+
...config.action.payload,
|
|
90
91
|
...options,
|
|
91
92
|
},
|
|
92
93
|
});
|
|
@@ -114,8 +115,8 @@ function useTabTrigger(options) {
|
|
|
114
115
|
});
|
|
115
116
|
if (!(0, useLinkToPathProps_1.shouldHandleMouseEvent)(event))
|
|
116
117
|
return;
|
|
117
|
-
switchTab(name, {
|
|
118
|
-
}, [onPress, name,
|
|
118
|
+
switchTab(name, { resetOnFocus });
|
|
119
|
+
}, [onPress, name, resetOnFocus, trigger]);
|
|
119
120
|
const handleOnLongPress = (0, react_1.useCallback)((event) => {
|
|
120
121
|
onLongPress?.(event);
|
|
121
122
|
if (!trigger)
|
|
@@ -129,9 +130,9 @@ function useTabTrigger(options) {
|
|
|
129
130
|
if (!(0, useLinkToPathProps_1.shouldHandleMouseEvent)(event))
|
|
130
131
|
return;
|
|
131
132
|
switchTab(name, {
|
|
132
|
-
|
|
133
|
+
resetOnFocus,
|
|
133
134
|
});
|
|
134
|
-
}, [onLongPress, name,
|
|
135
|
+
}, [onLongPress, name, resetOnFocus, trigger]);
|
|
135
136
|
const triggerProps = {
|
|
136
137
|
isFocused: Boolean(trigger?.isFocused),
|
|
137
138
|
onPress: handleOnPress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabTrigger.js","sourceRoot":"","sources":["../../src/ui/TabTrigger.tsx"],"names":[],"mappings":";;AAqEA,gCA4BC;AAKD,oCAIC;AAkCD,sCAwGC;AApPD,qDAA4C;AAE5C,iCAAkF;AAClF,+CAA2E;AAE3E,6CAAoD;AAGpD,+DAAyD;AACzD,sDAA2C;AA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,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI;SACxE,CAAC,CAAC;QAEH,IAAI,CAAC,IAAA,2CAAsB,EAAC,KAAK,CAAC;YAAE,OAAO;QAE3C,SAAS,CAAC,IAAI,EAAE;YACd,KAAK,EAAE,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK;SAClD,CAAC,CAAC;IACL,CAAC,EACD,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CACpC,CAAC;IAEF,MAAM,YAAY,GAAG;QACnB,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;QACtC,OAAO,EAAE,aAAa;QACtB,WAAW,EAAE,iBAAiB;KAC/B,CAAC;IAEF,OAAO;QACL,SAAS;QACT,UAAU;QACV,OAAO;QACP,YAAY;KACb,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IAC/B,UAAU,EAAE;QACV,aAAa,EAAE,KAAK;QACpB,cAAc,EAAE,eAAe;KAChC;CACF,CAAC,CAAC","sourcesContent":["import { Slot } from '@radix-ui/react-slot';\nimport { TabNavigationState } from '@react-navigation/native';\nimport { ReactNode, use, ReactElement, ComponentProps, useCallback } from 'react';\nimport { View, StyleSheet, Pressable, PressableProps } from 'react-native';\n\nimport { TabTriggerMapContext } from './TabContext';\nimport { ExpoTabsResetValue } from './TabRouter';\nimport type { TriggerMap } from './common';\nimport { appendBaseUrl } from '../fork/getPathFromState';\nimport { router } from '../imperative-api';\nimport { shouldHandleMouseEvent } from '../link/useLinkToPathProps';\nimport { stripGroupSegmentsFromPath } from '../matchers';\nimport type { Href } from '../types';\nimport { useNavigatorContext } from '../views/Navigator';\n\ntype PressablePropsWithoutFunctionChildren = Omit<PressableProps, 'children'> & {\n children?: ReactNode | undefined;\n};\n\nexport type TabTriggerProps = PressablePropsWithoutFunctionChildren & {\n /**\n * Name of tab. When used within a `TabList` this sets the name of the tab.\n * Otherwise, this references the name.\n */\n name: string;\n /**\n * Name of tab. Required when used within a `TabList`.\n */\n href?: Href;\n /**\n * Forward props to child component. Useful for custom wrappers.\n */\n asChild?: boolean;\n /**\n * Resets the route when switching to a tab.\n */\n reset?: SwitchToOptions['reset'] | 'onLongPress';\n};\n\nexport type TabTriggerOptions = {\n name: string;\n href: Href;\n};\n\nexport type TabTriggerSlotProps = PressablePropsWithoutFunctionChildren &\n React.RefAttributes<View> & {\n isFocused?: boolean;\n href?: string;\n };\n\nconst TabTriggerSlot = Slot as React.ForwardRefExoticComponent<TabTriggerSlotProps>;\n\n/**\n * Creates a trigger to navigate to a tab. When used as child of `TabList`, its\n * functionality slightly changes since the `href` prop is required,\n * and the trigger also defines what routes are present in the `Tabs`.\n *\n * When used outside of `TabList`, this component no longer requires an `href`.\n *\n * @example\n * ```tsx\n * <Tabs>\n * <TabSlot />\n * <TabList>\n * <TabTrigger name=\"home\" href=\"/\" />\n * </TabList>\n * </Tabs>\n * ```\n */\nexport function TabTrigger({ asChild, name, href, reset = 'onFocus', ...props }: TabTriggerProps) {\n const { trigger, triggerProps } = useTabTrigger({\n name,\n reset,\n ...props,\n });\n\n // Pressable doesn't accept the extra props, so only pass them if we are using asChild\n if (asChild) {\n return (\n <TabTriggerSlot\n style={styles.tabTrigger}\n {...props}\n {...triggerProps}\n href={trigger?.resolvedHref}>\n {props.children}\n </TabTriggerSlot>\n );\n } else {\n // These props are not typed, but are allowed by React Native Web\n const reactNativeWebProps = { href: trigger?.resolvedHref };\n\n return (\n <Pressable style={styles.tabTrigger} {...reactNativeWebProps} {...props} {...triggerProps}>\n {props.children}\n </Pressable>\n );\n }\n}\n\n/**\n * @hidden\n */\nexport function isTabTrigger(\n child: ReactElement<any>\n): child is ReactElement<ComponentProps<typeof TabTrigger>> {\n return child.type === TabTrigger;\n}\n\n/**\n * Options for `switchTab` function.\n */\nexport type SwitchToOptions = {\n /**\n * Navigate and reset the history.\n */\n reset?: ExpoTabsResetValue;\n};\n\nexport type Trigger = TriggerMap[string] & {\n isFocused: boolean;\n resolvedHref: string;\n route: TabNavigationState<any>['routes'][number];\n};\n\nexport type UseTabTriggerResult = {\n switchTab: (name: string, options: SwitchToOptions) => void;\n getTrigger: (name: string) => Trigger | undefined;\n trigger?: Trigger;\n triggerProps: TriggerProps;\n};\n\nexport type TriggerProps = {\n isFocused: boolean;\n onPress: PressableProps['onPress'];\n onLongPress: PressableProps['onLongPress'];\n};\n\n/**\n * Utility hook creating custom `TabTrigger`.\n */\nexport function useTabTrigger(options: TabTriggerProps): UseTabTriggerResult {\n const { state, navigation } = useNavigatorContext();\n const { name, reset, onPress, onLongPress } = options;\n const triggerMap = use(TabTriggerMapContext);\n\n const getTrigger = useCallback(\n (name: string) => {\n const config = triggerMap[name];\n\n if (!config) {\n return;\n }\n\n return {\n isFocused: state.index === config.index,\n route: state.routes[config.index],\n resolvedHref: stripGroupSegmentsFromPath(appendBaseUrl(config.href)),\n ...config,\n };\n },\n [triggerMap]\n );\n\n const trigger = name !== undefined ? getTrigger(name) : undefined;\n\n const switchTab = useCallback(\n (name: string, options?: SwitchToOptions) => {\n const config = triggerMap[name];\n\n if (config) {\n if (config.type === 'external') {\n return router.navigate(config.href);\n } else {\n return navigation?.dispatch({\n type: 'JUMP_TO',\n payload: {\n name,\n ...options,\n },\n });\n }\n } else {\n return navigation?.dispatch({\n type: 'JUMP_TO',\n payload: {\n name,\n },\n });\n }\n },\n [navigation, triggerMap]\n );\n\n const handleOnPress = useCallback<NonNullable<PressableProps['onPress']>>(\n (event) => {\n onPress?.(event);\n if (!trigger) return;\n if (event?.isDefaultPrevented()) return;\n\n navigation?.emit({\n type: 'tabPress',\n target: trigger.type === 'internal' ? trigger.route.key : trigger?.href,\n canPreventDefault: true,\n });\n\n if (!shouldHandleMouseEvent(event)) return;\n\n switchTab(name, { reset: reset !== 'onLongPress' ? reset : undefined });\n },\n [onPress, name, reset, trigger]\n );\n\n const handleOnLongPress = useCallback<NonNullable<PressableProps['onLongPress']>>(\n (event) => {\n onLongPress?.(event);\n if (!trigger) return;\n if (event?.isDefaultPrevented()) return;\n\n navigation?.emit({\n type: 'tabLongPress',\n target: trigger.type === 'internal' ? trigger.route.key : trigger?.href,\n });\n\n if (!shouldHandleMouseEvent(event)) return;\n\n switchTab(name, {\n reset: reset === 'onLongPress' ? 'always' : reset,\n });\n },\n [onLongPress, name, reset, trigger]\n );\n\n const triggerProps = {\n isFocused: Boolean(trigger?.isFocused),\n onPress: handleOnPress,\n onLongPress: handleOnLongPress,\n };\n\n return {\n switchTab,\n getTrigger,\n trigger,\n triggerProps,\n };\n}\n\nconst styles = StyleSheet.create({\n tabTrigger: {\n flexDirection: 'row',\n justifyContent: 'space-between',\n },\n});\n"]}
|
|
1
|
+
{"version":3,"file":"TabTrigger.js","sourceRoot":"","sources":["../../src/ui/TabTrigger.tsx"],"names":[],"mappings":";;AAoEA,gCA4BC;AAKD,oCAIC;AAkCD,sCAyGC;AApPD,qDAA4C;AAE5C,iCAAkF;AAClF,+CAA2E;AAE3E,6CAAoD;AAEpD,+DAAyD;AACzD,sDAA2C;AAC3C,mEAAoE;AACpE,0CAAyD;AAEzD,kDAAyD;AAqCzD,MAAM,cAAc,GAAG,iBAA4D,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,KAAK,EAAmB;IACzF,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC;QAC9C,IAAI;QACJ,YAAY;QACZ,GAAG,KAAK;KACT,CAAC,CAAC;IAEH,sFAAsF;IACtF,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CACL,CAAC,cAAc,CACb,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CACzB,IAAI,KAAK,CAAC,CACV,IAAI,YAAY,CAAC,CACjB,IAAI,CAAC,CAAC,OAAO,EAAE,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Aa,EAAE,KAAK;QACpB,cAAc,EAAE,eAAe;KAChC;CACF,CAAC,CAAC","sourcesContent":["import { Slot } from '@radix-ui/react-slot';\nimport { TabNavigationState } from '@react-navigation/native';\nimport { ReactNode, use, ReactElement, ComponentProps, useCallback } from 'react';\nimport { View, StyleSheet, Pressable, PressableProps } from 'react-native';\n\nimport { TabTriggerMapContext } from './TabContext';\nimport type { TriggerMap } from './common';\nimport { appendBaseUrl } from '../fork/getPathFromState';\nimport { router } from '../imperative-api';\nimport { shouldHandleMouseEvent } from '../link/useLinkToPathProps';\nimport { stripGroupSegmentsFromPath } from '../matchers';\nimport type { Href } from '../types';\nimport { useNavigatorContext } from '../views/Navigator';\n\ntype PressablePropsWithoutFunctionChildren = Omit<PressableProps, 'children'> & {\n children?: ReactNode | undefined;\n};\n\nexport type TabTriggerProps = PressablePropsWithoutFunctionChildren & {\n /**\n * Name of tab. When used within a `TabList` this sets the name of the tab.\n * Otherwise, this references the name.\n */\n name: string;\n /**\n * Name of tab. Required when used within a `TabList`.\n */\n href?: Href;\n /**\n * Forward props to child component. Useful for custom wrappers.\n */\n asChild?: boolean;\n /**\n * Resets the route when switching to a tab.\n */\n resetOnFocus?: boolean;\n};\n\nexport type TabTriggerOptions = {\n name: string;\n href: Href;\n};\n\nexport type TabTriggerSlotProps = PressablePropsWithoutFunctionChildren &\n React.RefAttributes<View> & {\n isFocused?: boolean;\n href?: string;\n };\n\nconst TabTriggerSlot = Slot as React.ForwardRefExoticComponent<TabTriggerSlotProps>;\n\n/**\n * Creates a trigger to navigate to a tab. When used as child of `TabList`, its\n * functionality slightly changes since the `href` prop is required,\n * and the trigger also defines what routes are present in the `Tabs`.\n *\n * When used outside of `TabList`, this component no longer requires an `href`.\n *\n * @example\n * ```tsx\n * <Tabs>\n * <TabSlot />\n * <TabList>\n * <TabTrigger name=\"home\" href=\"/\" />\n * </TabList>\n * </Tabs>\n * ```\n */\nexport function TabTrigger({ asChild, name, href, resetOnFocus, ...props }: TabTriggerProps) {\n const { trigger, triggerProps } = useTabTrigger({\n name,\n resetOnFocus,\n ...props,\n });\n\n // Pressable doesn't accept the extra props, so only pass them if we are using asChild\n if (asChild) {\n return (\n <TabTriggerSlot\n style={styles.tabTrigger}\n {...props}\n {...triggerProps}\n href={trigger?.resolvedHref}>\n {props.children}\n </TabTriggerSlot>\n );\n } else {\n // These props are not typed, but are allowed by React Native Web\n const reactNativeWebProps = { href: trigger?.resolvedHref };\n\n return (\n <Pressable style={styles.tabTrigger} {...reactNativeWebProps} {...props} {...triggerProps}>\n {props.children}\n </Pressable>\n );\n }\n}\n\n/**\n * @hidden\n */\nexport function isTabTrigger(\n child: ReactElement<any>\n): child is ReactElement<ComponentProps<typeof TabTrigger>> {\n return child.type === TabTrigger;\n}\n\n/**\n * Options for `switchTab` function.\n */\nexport type SwitchToOptions = {\n /**\n * Navigate and reset the history on route focus.\n */\n resetOnFocus?: boolean;\n};\n\nexport type Trigger = TriggerMap[string] & {\n isFocused: boolean;\n resolvedHref: string;\n route: TabNavigationState<any>['routes'][number];\n};\n\nexport type UseTabTriggerResult = {\n switchTab: (name: string, options: SwitchToOptions) => void;\n getTrigger: (name: string) => Trigger | undefined;\n trigger?: Trigger;\n triggerProps: TriggerProps;\n};\n\nexport type TriggerProps = {\n isFocused: boolean;\n onPress: PressableProps['onPress'];\n onLongPress: PressableProps['onLongPress'];\n};\n\n/**\n * Utility hook creating custom `TabTrigger`.\n */\nexport function useTabTrigger(options: TabTriggerProps): UseTabTriggerResult {\n const { state, navigation } = useNavigatorContext();\n const { name, resetOnFocus, onPress, onLongPress } = options;\n const triggerMap = use(TabTriggerMapContext);\n\n const getTrigger = useCallback(\n (name: string) => {\n const config = triggerMap[name];\n\n if (!config) {\n return;\n }\n\n return {\n isFocused: state.index === config.index,\n route: state.routes[config.index],\n resolvedHref: stripGroupSegmentsFromPath(appendBaseUrl(config.href)),\n ...config,\n };\n },\n [triggerMap]\n );\n\n const trigger = name !== undefined ? getTrigger(name) : undefined;\n\n const switchTab = useCallback(\n (name: string, options?: SwitchToOptions) => {\n const config = triggerMap[name];\n\n if (config) {\n if (config.type === 'external') {\n return router.navigate(config.href);\n } else {\n return navigation?.dispatch({\n ...config.action,\n type: 'JUMP_TO',\n payload: {\n ...config.action.payload,\n ...options,\n },\n });\n }\n } else {\n return navigation?.dispatch({\n type: 'JUMP_TO',\n payload: {\n name,\n },\n });\n }\n },\n [navigation, triggerMap]\n );\n\n const handleOnPress = useCallback<NonNullable<PressableProps['onPress']>>(\n (event) => {\n onPress?.(event);\n if (!trigger) return;\n if (event?.isDefaultPrevented()) return;\n\n navigation?.emit({\n type: 'tabPress',\n target: trigger.type === 'internal' ? trigger.route.key : trigger?.href,\n canPreventDefault: true,\n });\n\n if (!shouldHandleMouseEvent(event)) return;\n\n switchTab(name, { resetOnFocus });\n },\n [onPress, name, resetOnFocus, trigger]\n );\n\n const handleOnLongPress = useCallback<NonNullable<PressableProps['onLongPress']>>(\n (event) => {\n onLongPress?.(event);\n if (!trigger) return;\n if (event?.isDefaultPrevented()) return;\n\n navigation?.emit({\n type: 'tabLongPress',\n target: trigger.type === 'internal' ? trigger.route.key : trigger?.href,\n });\n\n if (!shouldHandleMouseEvent(event)) return;\n\n switchTab(name, {\n resetOnFocus,\n });\n },\n [onLongPress, name, resetOnFocus, trigger]\n );\n\n const triggerProps = {\n isFocused: Boolean(trigger?.isFocused),\n onPress: handleOnPress,\n onLongPress: handleOnLongPress,\n };\n\n return {\n switchTab,\n getTrigger,\n trigger,\n triggerProps,\n };\n}\n\nconst styles = StyleSheet.create({\n tabTrigger: {\n flexDirection: 'row',\n justifyContent: 'space-between',\n },\n});\n"]}
|
package/build/ui/Tabs.d.ts
CHANGED
package/build/ui/Tabs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../src/ui/Tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,aAAa,EACb,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BAAoB,EAAC,YAAY,CAAC,EAAE,CAAC;YACvC,OAAO,cAAc,CAAC,IAAI,CAAC;gBACzB,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;gBAC3C,OAAO,CAAC,IAAI,CACV,yGAAyG,CAC1G,CAAC;YACJ,CAAC;YACD,OAAO;QACT,CAAC;QAED,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAS,UAAU,CACjB,KAAwB;IAExB,OAAO,KAAK,CAAC,IAAI,KAAK,gBAAQ,CAAC;AACjC,CAAC;AAED,MAAM,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE;QACR,IAAI,EAAE,CAAC;KACR;CACF,CAAC,CAAC","sourcesContent":["import {\n DefaultNavigatorOptions,\n LinkingContext,\n ParamListBase,\n TabActionHelpers,\n TabNavigationState,\n TabRouterOptions,\n useNavigationBuilder,\n} from '@react-navigation/native';\nimport {\n Children,\n ComponentProps,\n Fragment,\n ReactElement,\n ReactNode,\n isValidElement,\n use,\n useMemo,\n PropsWithChildren,\n} from 'react';\nimport { StyleSheet, ViewProps, View } from 'react-native';\n\nimport {\n ExpoTabsScreenOptions,\n TabNavigationEventMap,\n TabTriggerMapContext,\n TabsContextValue,\n} from './TabContext';\nimport { isTabList } from './TabList';\nimport { ExpoTabRouter, ExpoTabRouterOptions } from './TabRouter';\nimport { isTabSlot } from './TabSlot';\nimport { isTabTrigger } from './TabTrigger';\nimport { ViewSlot, ScreenTrigger, triggersToScreens } from './common';\nimport { useComponent } from './useComponent';\nimport { useRouteNode, useContextKey } from '../Route';\nimport { useRouteInfo } from '../hooks';\nimport { resolveHref } from '../link/href';\nimport { shouldLinkExternally } from '../utils/url';\nimport { NavigatorContext, NavigatorContextValue } from '../views/Navigator';\n\nexport * from './TabContext';\nexport * from './TabList';\nexport * from './TabSlot';\nexport * from './TabTrigger';\nexport { ExpoTabsResetValue } from './TabRouter';\n\n/**\n * Options to provide to the Tab Router.\n */\nexport type UseTabsOptions = Omit<\n DefaultNavigatorOptions<\n ParamListBase,\n any,\n TabNavigationState<any>,\n ExpoTabsScreenOptions,\n TabNavigationEventMap,\n any\n >,\n 'children'\n> & {\n backBehavior?: TabRouterOptions['backBehavior'];\n};\n\nexport type TabsProps = ViewProps & {\n /** Forward props to child component and removes the extra `<View>`. Useful for custom wrappers. */\n asChild?: boolean;\n options?: UseTabsOptions;\n};\n\n/**\n * Root component for the headless tabs.\n *\n * @see [`useTabsWithChildren`](#usetabswithchildrenoptions) for a hook version of this component.\n * @example\n * ```tsx\n * <Tabs>\n * <TabSlot />\n * <TabList>\n * <TabTrigger name=\"home\" href=\"/\" />\n * </TabList>\n * </Tabs>\n * ```\n */\nexport function Tabs(props: TabsProps) {\n const { children, asChild, options, ...rest } = props;\n const Comp = asChild ? ViewSlot : View;\n\n const { NavigationContent } = useTabsWithChildren({\n // asChild adds an extra layer, so we need to process the child's children\n children:\n asChild &&\n isValidElement(children) &&\n children.props &&\n typeof children.props === 'object' &&\n 'children' in children.props\n ? (children.props.children as ReactNode)\n : children,\n ...options,\n });\n\n return (\n <Comp style={styles.tabsRoot} {...rest}>\n <NavigationContent>{children}</NavigationContent>\n </Comp>\n );\n}\n\n// @docsMissing\nexport type UseTabsWithChildrenOptions = PropsWithChildren<UseTabsOptions>;\n\n// @docsMissing\nexport type UseTabsWithTriggersOptions = UseTabsOptions & {\n triggers: ScreenTrigger[];\n};\n\n/**\n * Hook version of `Tabs`. The returned NavigationContent component\n * should be rendered. Using the hook requires using the `<TabList />`\n * and `<TabTrigger />` components exported from Expo Router.\n *\n * The `useTabsWithTriggers()` hook can be used for custom components.\n *\n * @see [`Tabs`](#tabs) for the component version of this hook.\n * @example\n * ```tsx\n * export function MyTabs({ children }) {\n * const { NavigationContent } = useTabsWithChildren({ children })\n *\n * return <NavigationContent />\n * }\n * ```\n */\nexport function useTabsWithChildren(options: UseTabsWithChildrenOptions) {\n const { children, ...rest } = options;\n return useTabsWithTriggers({ triggers: parseTriggersFromChildren(children), ...rest });\n}\n\n/**\n * Alternative hook version of `Tabs` that uses explicit triggers\n * instead of `children`.\n *\n * @see [`Tabs`](#tabs) for the component version of this hook.\n * @example\n * ```tsx\n * export function MyTabs({ children }) {\n * const { NavigationContent } = useTabsWithChildren({ triggers: [] })\n *\n * return <NavigationContent />\n * }\n * ```\n */\nexport function useTabsWithTriggers(options: UseTabsWithTriggersOptions): TabsContextValue {\n const { triggers, ...rest } = options;\n // Ensure we extend the parent triggers, so we can trigger them as well\n const parentTriggerMap = use(TabTriggerMapContext);\n const routeNode = useRouteNode();\n const contextKey = useContextKey();\n const linking = use(LinkingContext).options;\n const routeInfo = useRouteInfo();\n\n if (!routeNode || !linking) {\n throw new Error('No RouteNode. This is likely a bug in expo-router.');\n }\n\n const initialRouteName = routeNode.initialRouteName;\n\n const { children, triggerMap } = triggersToScreens(\n triggers,\n routeNode,\n linking,\n initialRouteName,\n parentTriggerMap,\n routeInfo,\n contextKey\n );\n\n const navigatorContext = useNavigationBuilder<\n TabNavigationState<any>,\n ExpoTabRouterOptions,\n TabActionHelpers<ParamListBase>,\n ExpoTabsScreenOptions,\n TabNavigationEventMap\n >(ExpoTabRouter, {\n children,\n ...rest,\n triggerMap,\n id: contextKey,\n initialRouteName,\n });\n\n const {\n state,\n descriptors,\n navigation,\n describe,\n NavigationContent: RNNavigationContent,\n } = navigatorContext;\n\n const navigatorContextValue = useMemo<NavigatorContextValue>(\n () => ({\n ...(navigatorContext as unknown as ReturnType<typeof useNavigationBuilder>),\n contextKey,\n router: ExpoTabRouter,\n }),\n [navigatorContext, contextKey, ExpoTabRouter]\n );\n\n const NavigationContent = useComponent((children: React.ReactNode) => (\n <TabTriggerMapContext.Provider value={triggerMap}>\n <NavigatorContext.Provider value={navigatorContextValue}>\n <RNNavigationContent>{children}</RNNavigationContent>\n </NavigatorContext.Provider>\n </TabTriggerMapContext.Provider>\n )) as TabsContextValue['NavigationContent'];\n\n return { state, descriptors, navigation, NavigationContent, describe };\n}\n\nfunction parseTriggersFromChildren(\n children: ReactNode,\n screenTriggers: ScreenTrigger[] = [],\n isInTabList = false\n) {\n Children.forEach(children, (child) => {\n if (!child || !isValidElement(child) || isTabSlot(child)) {\n return;\n }\n\n if (isFragment(child) && typeof child.props.children !== 'function') {\n return parseTriggersFromChildren(\n child.props.children,\n screenTriggers,\n isInTabList || isTabList(child)\n );\n }\n\n if (isTabList(child) && typeof child.props.children !== 'function') {\n let children = child.props.children;\n\n // <TabList asChild /> adds an extra layer. We need to parse the child's children\n if (\n child.props.asChild &&\n isValidElement(children) &&\n children.props &&\n typeof children.props === 'object' &&\n 'children' in children.props\n ) {\n children = children.props.children as ReactNode;\n }\n\n return parseTriggersFromChildren(children, screenTriggers, isInTabList || isTabList(child));\n }\n\n // We should only process TabTriggers within the TabList. All other components will be ignored\n if (!isInTabList || !isTabTrigger(child)) {\n return;\n }\n\n const { href, name } = child.props;\n\n if (!href) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `<TabTrigger name={${name}}> does not have a 'href' prop. TabTriggers within a <TabList /> are required to have an href.`\n );\n }\n return;\n }\n\n const resolvedHref = resolveHref(href);\n\n if (shouldLinkExternally(resolvedHref)) {\n return screenTriggers.push({\n type: 'external',\n name,\n href: resolvedHref,\n });\n }\n\n if (!name) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `<TabTrigger> does not have a 'name' prop. TabTriggers within a <TabList /> are required to have a name.`\n );\n }\n return;\n }\n\n return screenTriggers.push({ type: 'internal', href: resolvedHref, name });\n });\n\n return screenTriggers;\n}\n\nfunction isFragment(\n child: ReactElement<any>\n): child is ReactElement<ComponentProps<typeof Fragment>> {\n return child.type === Fragment;\n}\n\nconst styles = StyleSheet.create({\n tabsRoot: {\n flex: 1,\n },\n});\n"]}
|
|
1
|
+
{"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../../src/ui/Tabs.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAkFA,oBAsBC;AA2BD,kDAGC;AAgBD,kDAiEC;AAvND,qDAQkC;AAClC,iCAUe;AACf,+CAA2D;AAE3D,6CAKsB;AACtB,uCAAsC;AACtC,2CAAkE;AAClE,uCAAsC;AACtC,6CAA4C;AAC5C,qCAAsE;AACtE,iDAA8C;AAC9C,oCAAuD;AACvD,oCAAwC;AACxC,uCAA2C;AAC3C,sCAAoD;AACpD,kDAA6E;AAE7E,+CAA6B;AAC7B,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAyB7B;;;;;;;;;;;;;GAaG;AACH,SAAgB,IAAI,CAAC,KAAgB;IACnC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACtD,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,iBAAQ,CAAC,CAAC,CAAC,mBAAI,CAAC;IAEvC,MAAM,EAAE,iBAAiB,EAAE,GAAG,mBAAmB,CAAC;QAChD,0EAA0E;QAC1E,QAAQ,EACN,OAAO;YACP,IAAA,sBAAc,EAAC,QAAQ,CAAC;YACxB,QAAQ,CAAC,KAAK;YACd,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ;YAClC,UAAU,IAAI,QAAQ,CAAC,KAAK;YAC1B,CAAC,CAAE,QAAQ,CAAC,KAAK,CAAC,QAAsB;YACxC,CAAC,CAAC,QAAQ;QACd,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,CACL,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAA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AC;QAEvC,IAAI,IAAA,0BAAoB,EAAC,YAAY,CAAC,EAAE,CAAC;YACvC,OAAO,cAAc,CAAC,IAAI,CAAC;gBACzB,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;gBAC3C,OAAO,CAAC,IAAI,CACV,yGAAyG,CAC1G,CAAC;YACJ,CAAC;YACD,OAAO;QACT,CAAC;QAED,OAAO,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAS,UAAU,CACjB,KAAwB;IAExB,OAAO,KAAK,CAAC,IAAI,KAAK,gBAAQ,CAAC;AACjC,CAAC;AAED,MAAM,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE;QACR,IAAI,EAAE,CAAC;KACR;CACF,CAAC,CAAC","sourcesContent":["import {\n DefaultNavigatorOptions,\n LinkingContext,\n ParamListBase,\n TabActionHelpers,\n TabNavigationState,\n TabRouterOptions,\n useNavigationBuilder,\n} from '@react-navigation/native';\nimport {\n Children,\n ComponentProps,\n Fragment,\n ReactElement,\n ReactNode,\n isValidElement,\n use,\n useMemo,\n PropsWithChildren,\n} from 'react';\nimport { StyleSheet, ViewProps, View } from 'react-native';\n\nimport {\n ExpoTabsScreenOptions,\n TabNavigationEventMap,\n TabTriggerMapContext,\n TabsContextValue,\n} from './TabContext';\nimport { isTabList } from './TabList';\nimport { ExpoTabRouter, ExpoTabRouterOptions } from './TabRouter';\nimport { isTabSlot } from './TabSlot';\nimport { isTabTrigger } from './TabTrigger';\nimport { ViewSlot, ScreenTrigger, triggersToScreens } from './common';\nimport { useComponent } from './useComponent';\nimport { useRouteNode, useContextKey } from '../Route';\nimport { useRouteInfo } from '../hooks';\nimport { resolveHref } from '../link/href';\nimport { shouldLinkExternally } from '../utils/url';\nimport { NavigatorContext, NavigatorContextValue } from '../views/Navigator';\n\nexport * from './TabContext';\nexport * from './TabList';\nexport * from './TabSlot';\nexport * from './TabTrigger';\n\n/**\n * Options to provide to the Tab Router.\n */\nexport type UseTabsOptions = Omit<\n DefaultNavigatorOptions<\n ParamListBase,\n any,\n TabNavigationState<any>,\n ExpoTabsScreenOptions,\n TabNavigationEventMap,\n any\n >,\n 'children'\n> & {\n backBehavior?: TabRouterOptions['backBehavior'];\n};\n\nexport type TabsProps = ViewProps & {\n /** Forward props to child component and removes the extra `<View>`. Useful for custom wrappers. */\n asChild?: boolean;\n options?: UseTabsOptions;\n};\n\n/**\n * Root component for the headless tabs.\n *\n * @see [`useTabsWithChildren`](#usetabswithchildrenoptions) for a hook version of this component.\n * @example\n * ```tsx\n * <Tabs>\n * <TabSlot />\n * <TabList>\n * <TabTrigger name=\"home\" href=\"/\" />\n * </TabList>\n * </Tabs>\n * ```\n */\nexport function Tabs(props: TabsProps) {\n const { children, asChild, options, ...rest } = props;\n const Comp = asChild ? ViewSlot : View;\n\n const { NavigationContent } = useTabsWithChildren({\n // asChild adds an extra layer, so we need to process the child's children\n children:\n asChild &&\n isValidElement(children) &&\n children.props &&\n typeof children.props === 'object' &&\n 'children' in children.props\n ? (children.props.children as ReactNode)\n : children,\n ...options,\n });\n\n return (\n <Comp style={styles.tabsRoot} {...rest}>\n <NavigationContent>{children}</NavigationContent>\n </Comp>\n );\n}\n\n// @docsMissing\nexport type UseTabsWithChildrenOptions = PropsWithChildren<UseTabsOptions>;\n\n// @docsMissing\nexport type UseTabsWithTriggersOptions = UseTabsOptions & {\n triggers: ScreenTrigger[];\n};\n\n/**\n * Hook version of `Tabs`. The returned NavigationContent component\n * should be rendered. Using the hook requires using the `<TabList />`\n * and `<TabTrigger />` components exported from Expo Router.\n *\n * The `useTabsWithTriggers()` hook can be used for custom components.\n *\n * @see [`Tabs`](#tabs) for the component version of this hook.\n * @example\n * ```tsx\n * export function MyTabs({ children }) {\n * const { NavigationContent } = useTabsWithChildren({ children })\n *\n * return <NavigationContent />\n * }\n * ```\n */\nexport function useTabsWithChildren(options: UseTabsWithChildrenOptions) {\n const { children, ...rest } = options;\n return useTabsWithTriggers({ triggers: parseTriggersFromChildren(children), ...rest });\n}\n\n/**\n * Alternative hook version of `Tabs` that uses explicit triggers\n * instead of `children`.\n *\n * @see [`Tabs`](#tabs) for the component version of this hook.\n * @example\n * ```tsx\n * export function MyTabs({ children }) {\n * const { NavigationContent } = useTabsWithChildren({ triggers: [] })\n *\n * return <NavigationContent />\n * }\n * ```\n */\nexport function useTabsWithTriggers(options: UseTabsWithTriggersOptions): TabsContextValue {\n const { triggers, ...rest } = options;\n // Ensure we extend the parent triggers, so we can trigger them as well\n const parentTriggerMap = use(TabTriggerMapContext);\n const routeNode = useRouteNode();\n const contextKey = useContextKey();\n const linking = use(LinkingContext).options;\n const routeInfo = useRouteInfo();\n\n if (!routeNode || !linking) {\n throw new Error('No RouteNode. This is likely a bug in expo-router.');\n }\n\n const initialRouteName = routeNode.initialRouteName;\n\n const { children, triggerMap } = triggersToScreens(\n triggers,\n routeNode,\n linking,\n initialRouteName,\n parentTriggerMap,\n routeInfo,\n contextKey\n );\n\n const navigatorContext = useNavigationBuilder<\n TabNavigationState<any>,\n ExpoTabRouterOptions,\n TabActionHelpers<ParamListBase>,\n ExpoTabsScreenOptions,\n TabNavigationEventMap\n >(ExpoTabRouter, {\n children,\n ...rest,\n triggerMap,\n id: contextKey,\n initialRouteName,\n });\n\n const {\n state,\n descriptors,\n navigation,\n describe,\n NavigationContent: RNNavigationContent,\n } = navigatorContext;\n\n const navigatorContextValue = useMemo<NavigatorContextValue>(\n () => ({\n ...(navigatorContext as unknown as ReturnType<typeof useNavigationBuilder>),\n contextKey,\n router: ExpoTabRouter,\n }),\n [navigatorContext, contextKey, ExpoTabRouter]\n );\n\n const NavigationContent = useComponent((children: React.ReactNode) => (\n <TabTriggerMapContext.Provider value={triggerMap}>\n <NavigatorContext.Provider value={navigatorContextValue}>\n <RNNavigationContent>{children}</RNNavigationContent>\n </NavigatorContext.Provider>\n </TabTriggerMapContext.Provider>\n )) as TabsContextValue['NavigationContent'];\n\n return { state, descriptors, navigation, NavigationContent, describe };\n}\n\nfunction parseTriggersFromChildren(\n children: ReactNode,\n screenTriggers: ScreenTrigger[] = [],\n isInTabList = false\n) {\n Children.forEach(children, (child) => {\n if (!child || !isValidElement(child) || isTabSlot(child)) {\n return;\n }\n\n if (isFragment(child) && typeof child.props.children !== 'function') {\n return parseTriggersFromChildren(\n child.props.children,\n screenTriggers,\n isInTabList || isTabList(child)\n );\n }\n\n if (isTabList(child) && typeof child.props.children !== 'function') {\n let children = child.props.children;\n\n // <TabList asChild /> adds an extra layer. We need to parse the child's children\n if (\n child.props.asChild &&\n isValidElement(children) &&\n children.props &&\n typeof children.props === 'object' &&\n 'children' in children.props\n ) {\n children = children.props.children as ReactNode;\n }\n\n return parseTriggersFromChildren(children, screenTriggers, isInTabList || isTabList(child));\n }\n\n // We should only process TabTriggers within the TabList. All other components will be ignored\n if (!isInTabList || !isTabTrigger(child)) {\n return;\n }\n\n const { href, name } = child.props;\n\n if (!href) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `<TabTrigger name={${name}}> does not have a 'href' prop. TabTriggers within a <TabList /> are required to have an href.`\n );\n }\n return;\n }\n\n const resolvedHref = resolveHref(href);\n\n if (shouldLinkExternally(resolvedHref)) {\n return screenTriggers.push({\n type: 'external',\n name,\n href: resolvedHref,\n });\n }\n\n if (!name) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `<TabTrigger> does not have a 'name' prop. TabTriggers within a <TabList /> are required to have a name.`\n );\n }\n return;\n }\n\n return screenTriggers.push({ type: 'internal', href: resolvedHref, name });\n });\n\n return screenTriggers;\n}\n\nfunction isFragment(\n child: ReactElement<any>\n): child is ReactElement<ComponentProps<typeof Fragment>> {\n return child.type === Fragment;\n}\n\nconst styles = StyleSheet.create({\n tabsRoot: {\n flex: 1,\n },\n});\n"]}
|
package/html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ScrollViewStyleReset } from './build/static/html';
|
|
1
|
+
export { ScrollViewStyleReset } from './build/static/html';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-canary-20251023-4c86f95",
|
|
4
4
|
"description": "Expo Router is a file-based router for React Native and web applications.",
|
|
5
5
|
"author": "650 Industries, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,12 +77,13 @@
|
|
|
77
77
|
"expo"
|
|
78
78
|
],
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@expo/metro-runtime": "6.1.3-canary-
|
|
80
|
+
"@expo/metro-runtime": "6.1.3-canary-20251023-4c86f95",
|
|
81
|
+
"@expo/log-box": "0.0.13-canary-20251023-4c86f95",
|
|
81
82
|
"@react-navigation/drawer": "^7.5.0",
|
|
82
83
|
"@testing-library/react-native": ">= 12.0.0",
|
|
83
|
-
"expo": "55.0.0-canary-
|
|
84
|
-
"expo-constants": "18.0.
|
|
85
|
-
"expo-linking": "8.0.9-canary-
|
|
84
|
+
"expo": "55.0.0-canary-20251023-4c86f95",
|
|
85
|
+
"expo-constants": "18.0.11-canary-20251023-4c86f95",
|
|
86
|
+
"expo-linking": "8.0.9-canary-20251023-4c86f95",
|
|
86
87
|
"react": "*",
|
|
87
88
|
"react-dom": "*",
|
|
88
89
|
"react-native": "*",
|
|
@@ -128,8 +129,8 @@
|
|
|
128
129
|
"tsd": "^0.28.1"
|
|
129
130
|
},
|
|
130
131
|
"dependencies": {
|
|
131
|
-
"@expo/metro-runtime": "6.1.3-canary-
|
|
132
|
-
"@expo/schema-utils": "0.1.8-canary-
|
|
132
|
+
"@expo/metro-runtime": "6.1.3-canary-20251023-4c86f95",
|
|
133
|
+
"@expo/schema-utils": "0.1.8-canary-20251023-4c86f95",
|
|
133
134
|
"@radix-ui/react-slot": "1.2.0",
|
|
134
135
|
"@radix-ui/react-tabs": "^1.1.12",
|
|
135
136
|
"@react-navigation/bottom-tabs": "^7.4.0",
|
|
@@ -138,7 +139,7 @@
|
|
|
138
139
|
"client-only": "^0.0.1",
|
|
139
140
|
"debug": "^4.3.4",
|
|
140
141
|
"escape-string-regexp": "^4.0.0",
|
|
141
|
-
"expo-server": "1.1.0-canary-
|
|
142
|
+
"expo-server": "1.1.0-canary-20251023-4c86f95",
|
|
142
143
|
"fast-deep-equal": "^3.1.3",
|
|
143
144
|
"invariant": "^2.2.4",
|
|
144
145
|
"nanoid": "^3.3.8",
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright © 2023 650 Industries.
|
|
3
|
-
* Copyright © 2023 Vercel, Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*
|
|
8
|
-
* Based on https://github.com/vercel/next.js/blob/1df2686bc9964f1a86c444701fa5cbf178669833/packages/next/src/shared/lib/router/utils/route-regex.ts
|
|
9
|
-
*/
|
|
10
|
-
import type { RouteNode } from './Route';
|
|
11
|
-
export type ExpoRouterServerManifestV1Route<TRegex = string> = {
|
|
12
|
-
file: string;
|
|
13
|
-
page: string;
|
|
14
|
-
/**
|
|
15
|
-
* Keys are route param names that have been normalized for a regex named-matcher, values are the original route param names.
|
|
16
|
-
*/
|
|
17
|
-
routeKeys: Record<string, string>;
|
|
18
|
-
/**
|
|
19
|
-
* Regex for matching a path against the route.
|
|
20
|
-
* The regex is normalized for named matchers so keys must be looked up against the `routeKeys` object to collect the original route param names.
|
|
21
|
-
* Regex matching alone cannot accurately route to a file, the order in which routes are matched is equally important to ensure correct priority.
|
|
22
|
-
*/
|
|
23
|
-
namedRegex: TRegex;
|
|
24
|
-
/** Indicates that the route was generated and does not map to any file in the project's routes directory. */
|
|
25
|
-
generated?: boolean;
|
|
26
|
-
/** Indicates that this is a redirect that should use 301 instead of 307 */
|
|
27
|
-
permanent?: boolean;
|
|
28
|
-
/** If a redirect, which methods are allowed. Undefined represents all methods */
|
|
29
|
-
methods?: string[];
|
|
30
|
-
};
|
|
31
|
-
export type ExpoRouterServerManifestV1Middleware = {
|
|
32
|
-
/**
|
|
33
|
-
* Path to the module that contains the middleware function as a default export.
|
|
34
|
-
*
|
|
35
|
-
* @example _expo/functions/+middleware.js
|
|
36
|
-
*/
|
|
37
|
-
file: string;
|
|
38
|
-
};
|
|
39
|
-
export type ExpoRouterServerManifestV1<TRegex = string> = {
|
|
40
|
-
/**
|
|
41
|
-
* Middleware function that runs before any route matching.
|
|
42
|
-
* Only allowed at the root level and requires web.output: "server".
|
|
43
|
-
*/
|
|
44
|
-
middleware?: ExpoRouterServerManifestV1Middleware;
|
|
45
|
-
/**
|
|
46
|
-
* Headers to be applied to all responses from the server.
|
|
47
|
-
*/
|
|
48
|
-
headers?: Record<string, string | string[]>;
|
|
49
|
-
/**
|
|
50
|
-
* Rewrites. After middleware has processed and regular routing resumes, these occur first.
|
|
51
|
-
*/
|
|
52
|
-
rewrites: ExpoRouterServerManifestV1Route<TRegex>[];
|
|
53
|
-
/**
|
|
54
|
-
* List of routes that match second. Returns 301 and redirects to another path.
|
|
55
|
-
*/
|
|
56
|
-
redirects: ExpoRouterServerManifestV1Route<TRegex>[];
|
|
57
|
-
/**
|
|
58
|
-
* Routes that return static HTML files for a given path.
|
|
59
|
-
* These are only matched against requests with method `GET` and `HEAD`.
|
|
60
|
-
*/
|
|
61
|
-
htmlRoutes: ExpoRouterServerManifestV1Route<TRegex>[];
|
|
62
|
-
/**
|
|
63
|
-
* Routes that are matched after HTML routes and invoke WinterCG-compliant functions.
|
|
64
|
-
*/
|
|
65
|
-
apiRoutes: ExpoRouterServerManifestV1Route<TRegex>[];
|
|
66
|
-
/** List of routes that are matched last and return with status code 404. */
|
|
67
|
-
notFoundRoutes: ExpoRouterServerManifestV1Route<TRegex>[];
|
|
68
|
-
};
|
|
69
|
-
export interface Group {
|
|
70
|
-
pos: number;
|
|
71
|
-
repeat: boolean;
|
|
72
|
-
optional: boolean;
|
|
73
|
-
}
|
|
74
|
-
export interface RouteRegex {
|
|
75
|
-
groups: Record<string, Group>;
|
|
76
|
-
re: RegExp;
|
|
77
|
-
}
|
|
78
|
-
type GetServerManifestOptions = {
|
|
79
|
-
headers?: Record<string, string | string[]>;
|
|
80
|
-
};
|
|
81
|
-
export declare function getServerManifest(route: RouteNode, options: GetServerManifestOptions | undefined): ExpoRouterServerManifestV1;
|
|
82
|
-
export declare function parseParameter(param: string): {
|
|
83
|
-
name: string;
|
|
84
|
-
repeat: boolean;
|
|
85
|
-
optional: boolean;
|
|
86
|
-
};
|
|
87
|
-
export {};
|
|
88
|
-
//# sourceMappingURL=getServerManifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getServerManifest.d.ts","sourceRoot":"","sources":["../src/getServerManifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMzC,MAAM,MAAM,+BAA+B,CAAC,MAAM,GAAG,MAAM,IAAI;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,6GAA6G;IAC7G,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,EAAE,CA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@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServerManifest = getServerManifest;
|
|
4
|
-
exports.parseParameter = parseParameter;
|
|
5
|
-
const matchers_1 = require("./matchers");
|
|
6
|
-
const sortRoutes_1 = require("./sortRoutes");
|
|
7
|
-
const url_1 = require("./utils/url");
|
|
8
|
-
function isNotFoundRoute(route) {
|
|
9
|
-
return route.dynamic && route.dynamic[route.dynamic.length - 1].notFound;
|
|
10
|
-
}
|
|
11
|
-
function uniqueBy(arr, key) {
|
|
12
|
-
const seen = new Set();
|
|
13
|
-
return arr.filter((item) => {
|
|
14
|
-
const id = key(item);
|
|
15
|
-
if (seen.has(id)) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
seen.add(id);
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
// Given a nested route tree, return a flattened array of all routes that can be matched.
|
|
23
|
-
function getServerManifest(route, options) {
|
|
24
|
-
function getFlatNodes(route, parentRoute = '') {
|
|
25
|
-
// Use a recreated route instead of contextKey because we duplicate nodes to support array syntax.
|
|
26
|
-
const absoluteRoute = [parentRoute, route.route].filter(Boolean).join('/');
|
|
27
|
-
if (route.children.length) {
|
|
28
|
-
return route.children.map((child) => getFlatNodes(child, absoluteRoute)).flat();
|
|
29
|
-
}
|
|
30
|
-
// API Routes are handled differently to HTML routes because they have no nested behavior.
|
|
31
|
-
// An HTML route can be different based on parent segments due to layout routes, therefore multiple
|
|
32
|
-
// copies should be rendered. However, an API route is always the same regardless of parent segments.
|
|
33
|
-
let key;
|
|
34
|
-
if (route.type.includes('api')) {
|
|
35
|
-
key = getNormalizedContextKey(route.contextKey);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
key = getNormalizedContextKey(absoluteRoute);
|
|
39
|
-
}
|
|
40
|
-
return [[key, '/' + absoluteRoute, route]];
|
|
41
|
-
}
|
|
42
|
-
// Remove duplicates from the runtime manifest which expands array syntax.
|
|
43
|
-
const flat = getFlatNodes(route)
|
|
44
|
-
.sort(([, , a], [, , b]) => (0, sortRoutes_1.sortRoutes)(b, a))
|
|
45
|
-
.reverse();
|
|
46
|
-
const apiRoutes = uniqueBy(flat.filter(([, , route]) => route.type === 'api'), ([path]) => path);
|
|
47
|
-
const otherRoutes = uniqueBy(flat.filter(([, , route]) => route.type === 'route' ||
|
|
48
|
-
(route.type === 'rewrite' && (route.methods === undefined || route.methods.includes('GET')))), ([path]) => path);
|
|
49
|
-
const redirects = uniqueBy(flat.filter(([, , route]) => route.type === 'redirect'), ([path]) => path)
|
|
50
|
-
.map((redirect) => {
|
|
51
|
-
// TODO(@hassankhan): ENG-16577
|
|
52
|
-
// For external redirects, use `destinationContextKey` as the destination URL
|
|
53
|
-
if ((0, url_1.shouldLinkExternally)(redirect[2].destinationContextKey)) {
|
|
54
|
-
redirect[1] = redirect[2].destinationContextKey;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
redirect[1] =
|
|
58
|
-
flat.find(([, , route]) => route.contextKey === redirect[2].destinationContextKey)?.[0] ??
|
|
59
|
-
'/';
|
|
60
|
-
}
|
|
61
|
-
return redirect;
|
|
62
|
-
})
|
|
63
|
-
.reverse();
|
|
64
|
-
const rewrites = uniqueBy(flat.filter(([, , route]) => route.type === 'rewrite'), ([path]) => path)
|
|
65
|
-
.map((rewrite) => {
|
|
66
|
-
rewrite[1] =
|
|
67
|
-
flat.find(([, , route]) => route.contextKey === rewrite[2].destinationContextKey)?.[0] ??
|
|
68
|
-
'/';
|
|
69
|
-
return rewrite;
|
|
70
|
-
})
|
|
71
|
-
.reverse();
|
|
72
|
-
const standardRoutes = otherRoutes.filter(([, , route]) => !isNotFoundRoute(route));
|
|
73
|
-
const notFoundRoutes = otherRoutes.filter(([, , route]) => isNotFoundRoute(route));
|
|
74
|
-
const manifest = {
|
|
75
|
-
apiRoutes: getMatchableManifestForPaths(apiRoutes),
|
|
76
|
-
htmlRoutes: getMatchableManifestForPaths(standardRoutes),
|
|
77
|
-
notFoundRoutes: getMatchableManifestForPaths(notFoundRoutes),
|
|
78
|
-
redirects: getMatchableManifestForPaths(redirects),
|
|
79
|
-
rewrites: getMatchableManifestForPaths(rewrites),
|
|
80
|
-
};
|
|
81
|
-
if (route.middleware) {
|
|
82
|
-
manifest.middleware = {
|
|
83
|
-
file: route.middleware.contextKey,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (options?.headers) {
|
|
87
|
-
manifest.headers = options.headers;
|
|
88
|
-
}
|
|
89
|
-
return manifest;
|
|
90
|
-
}
|
|
91
|
-
function getMatchableManifestForPaths(paths) {
|
|
92
|
-
return paths.map(([normalizedRoutePath, absoluteRoute, node]) => {
|
|
93
|
-
const matcher = getNamedRouteRegex(normalizedRoutePath, absoluteRoute, node.contextKey);
|
|
94
|
-
if (node.generated) {
|
|
95
|
-
matcher.generated = true;
|
|
96
|
-
}
|
|
97
|
-
if (node.permanent) {
|
|
98
|
-
matcher.permanent = true;
|
|
99
|
-
}
|
|
100
|
-
if (node.methods) {
|
|
101
|
-
matcher.methods = node.methods;
|
|
102
|
-
}
|
|
103
|
-
return matcher;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function getNamedRouteRegex(normalizedRoute, page, file) {
|
|
107
|
-
const result = getNamedParametrizedRoute(normalizedRoute);
|
|
108
|
-
return {
|
|
109
|
-
file,
|
|
110
|
-
page,
|
|
111
|
-
namedRegex: `^${result.namedParameterizedRoute}(?:/)?$`,
|
|
112
|
-
routeKeys: result.routeKeys,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Builds a function to generate a minimal routeKey using only a-z and minimal
|
|
117
|
-
* number of characters.
|
|
118
|
-
*/
|
|
119
|
-
function buildGetSafeRouteKey() {
|
|
120
|
-
let currentCharCode = 96; // Starting one before 'a' to make the increment logic simpler
|
|
121
|
-
let currentLength = 1;
|
|
122
|
-
return () => {
|
|
123
|
-
let result = '';
|
|
124
|
-
let incrementNext = true;
|
|
125
|
-
// Iterate from right to left to build the key
|
|
126
|
-
for (let i = 0; i < currentLength; i++) {
|
|
127
|
-
if (incrementNext) {
|
|
128
|
-
currentCharCode++;
|
|
129
|
-
if (currentCharCode > 122) {
|
|
130
|
-
currentCharCode = 97; // Reset to 'a'
|
|
131
|
-
incrementNext = true; // Continue to increment the next character
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
incrementNext = false;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
result = String.fromCharCode(currentCharCode) + result;
|
|
138
|
-
}
|
|
139
|
-
// If all characters are 'z', increase the length of the key
|
|
140
|
-
if (incrementNext) {
|
|
141
|
-
currentLength++;
|
|
142
|
-
currentCharCode = 96; // This will make the next key start with 'a'
|
|
143
|
-
}
|
|
144
|
-
return result;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function removeTrailingSlash(route) {
|
|
148
|
-
return route.replace(/\/$/, '') || '/';
|
|
149
|
-
}
|
|
150
|
-
function getNamedParametrizedRoute(route) {
|
|
151
|
-
const segments = removeTrailingSlash(route).slice(1).split('/');
|
|
152
|
-
const getSafeRouteKey = buildGetSafeRouteKey();
|
|
153
|
-
const routeKeys = {};
|
|
154
|
-
return {
|
|
155
|
-
namedParameterizedRoute: segments
|
|
156
|
-
.map((segment, index) => {
|
|
157
|
-
if (segment === '+not-found' && index === segments.length - 1) {
|
|
158
|
-
segment = '[...not-found]';
|
|
159
|
-
}
|
|
160
|
-
if (/^\[.*\]$/.test(segment)) {
|
|
161
|
-
const { name, optional, repeat } = parseParameter(segment);
|
|
162
|
-
// replace any non-word characters since they can break
|
|
163
|
-
// the named regex
|
|
164
|
-
let cleanedKey = name.replace(/\W/g, '');
|
|
165
|
-
let invalidKey = false;
|
|
166
|
-
// check if the key is still invalid and fallback to using a known
|
|
167
|
-
// safe key
|
|
168
|
-
if (cleanedKey.length === 0 || cleanedKey.length > 30) {
|
|
169
|
-
invalidKey = true;
|
|
170
|
-
}
|
|
171
|
-
if (!isNaN(parseInt(cleanedKey.slice(0, 1), 10))) {
|
|
172
|
-
invalidKey = true;
|
|
173
|
-
}
|
|
174
|
-
// Prevent duplicates after sanitizing the key
|
|
175
|
-
if (cleanedKey in routeKeys) {
|
|
176
|
-
invalidKey = true;
|
|
177
|
-
}
|
|
178
|
-
if (invalidKey) {
|
|
179
|
-
cleanedKey = getSafeRouteKey();
|
|
180
|
-
}
|
|
181
|
-
routeKeys[cleanedKey] = name;
|
|
182
|
-
return repeat
|
|
183
|
-
? optional
|
|
184
|
-
? `(?:/(?<${cleanedKey}>.+?))?`
|
|
185
|
-
: `/(?<${cleanedKey}>.+?)`
|
|
186
|
-
: `/(?<${cleanedKey}>[^/]+?)`;
|
|
187
|
-
}
|
|
188
|
-
else if (/^\(.*\)$/.test(segment)) {
|
|
189
|
-
const groupName = (0, matchers_1.matchGroupName)(segment)
|
|
190
|
-
.split(',')
|
|
191
|
-
.map((group) => group.trim())
|
|
192
|
-
.filter(Boolean);
|
|
193
|
-
if (groupName.length > 1) {
|
|
194
|
-
const optionalSegment = `\\((?:${groupName.map(escapeStringRegexp).join('|')})\\)`;
|
|
195
|
-
// Make section optional
|
|
196
|
-
return `(?:/${optionalSegment})?`;
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
// Use simpler regex for single groups
|
|
200
|
-
return `(?:/${escapeStringRegexp(segment)})?`;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
return `/${escapeStringRegexp(segment)}`;
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
.join(''),
|
|
208
|
-
routeKeys,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
// regexp is based on https://github.com/sindresorhus/escape-string-regexp
|
|
212
|
-
const reHasRegExp = /[|\\{}()[\]^$+*?.-]/;
|
|
213
|
-
const reReplaceRegExp = /[|\\{}()[\]^$+*?.-]/g;
|
|
214
|
-
function escapeStringRegexp(str) {
|
|
215
|
-
// see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23
|
|
216
|
-
if (reHasRegExp.test(str)) {
|
|
217
|
-
return str.replace(reReplaceRegExp, '\\$&');
|
|
218
|
-
}
|
|
219
|
-
return str;
|
|
220
|
-
}
|
|
221
|
-
function parseParameter(param) {
|
|
222
|
-
let repeat = false;
|
|
223
|
-
let optional = false;
|
|
224
|
-
let name = param;
|
|
225
|
-
if (/^\[.*\]$/.test(name)) {
|
|
226
|
-
optional = true;
|
|
227
|
-
name = name.slice(1, -1);
|
|
228
|
-
}
|
|
229
|
-
if (/^\.\.\./.test(name)) {
|
|
230
|
-
repeat = true;
|
|
231
|
-
name = name.slice(3);
|
|
232
|
-
}
|
|
233
|
-
return { name, repeat, optional };
|
|
234
|
-
}
|
|
235
|
-
function getNormalizedContextKey(contextKey) {
|
|
236
|
-
return (0, matchers_1.getContextKey)(contextKey).replace(/\/index$/, '') ?? '/';
|
|
237
|
-
}
|
|
238
|
-
//# sourceMappingURL=getServerManifest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getServerManifest.js","sourceRoot":"","sources":["../src/getServerManifest.ts"],"names":[],"mappings":";;AA+GA,8CAiGC;AA6JD,wCAgBC;AAnXD,yCAA2D;AAC3D,6CAA0C;AAC1C,qCAAmD;AA2EnD,SAAS,eAAe,CAAC,KAAgB;IACvC,OAAO,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3E,CAAC;AAED,SAAS,QAAQ,CAAI,GAAQ,EAAE,GAAwB;IACrD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,EAAE,GAAG,GAA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MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,IAAI,GAAG,KAAK,CAAC;IAEjB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,QAAQ,GAAG,IAAI,CAAC;QAChB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,GAAG,IAAI,CAAC;QACd,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC;AAED,SAAS,uBAAuB,CAAC,UAAkB;IACjD,OAAO,IAAA,wBAAa,EAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAClE,CAAC","sourcesContent":["/**\n * Copyright © 2023 650 Industries.\n * Copyright © 2023 Vercel, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Based on https://github.com/vercel/next.js/blob/1df2686bc9964f1a86c444701fa5cbf178669833/packages/next/src/shared/lib/router/utils/route-regex.ts\n */\nimport type { RouteNode } from './Route';\nimport { getContextKey, matchGroupName } from './matchers';\nimport { sortRoutes } from './sortRoutes';\nimport { shouldLinkExternally } from './utils/url';\n\n// TODO: Share these types across cli, server, router, etc.\nexport type ExpoRouterServerManifestV1Route<TRegex = string> = {\n file: string;\n page: string;\n /**\n * Keys are route param names that have been normalized for a regex named-matcher, values are the original route param names.\n */\n routeKeys: Record<string, string>;\n /**\n * Regex for matching a path against the route.\n * The regex is normalized for named matchers so keys must be looked up against the `routeKeys` object to collect the original route param names.\n * Regex matching alone cannot accurately route to a file, the order in which routes are matched is equally important to ensure correct priority.\n */\n namedRegex: TRegex;\n /** Indicates that the route was generated and does not map to any file in the project's routes directory. */\n generated?: boolean;\n /** Indicates that this is a redirect that should use 301 instead of 307 */\n permanent?: boolean;\n /** If a redirect, which methods are allowed. Undefined represents all methods */\n methods?: string[];\n};\n\nexport type ExpoRouterServerManifestV1Middleware = {\n /**\n * Path to the module that contains the middleware function as a default export.\n *\n * @example _expo/functions/+middleware.js\n */\n file: string;\n};\n\nexport type ExpoRouterServerManifestV1<TRegex = string> = {\n /**\n * Middleware function that runs before any route matching.\n * Only allowed at the root level and requires web.output: \"server\".\n */\n middleware?: ExpoRouterServerManifestV1Middleware;\n /**\n * Headers to be applied to all responses from the server.\n */\n headers?: Record<string, string | string[]>;\n /**\n * Rewrites. After middleware has processed and regular routing resumes, these occur first.\n */\n rewrites: ExpoRouterServerManifestV1Route<TRegex>[];\n /**\n * List of routes that match second. Returns 301 and redirects to another path.\n */\n redirects: ExpoRouterServerManifestV1Route<TRegex>[];\n /**\n * Routes that return static HTML files for a given path.\n * These are only matched against requests with method `GET` and `HEAD`.\n */\n htmlRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n /**\n * Routes that are matched after HTML routes and invoke WinterCG-compliant functions.\n */\n apiRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n /** List of routes that are matched last and return with status code 404. */\n notFoundRoutes: ExpoRouterServerManifestV1Route<TRegex>[];\n};\n\nexport interface Group {\n pos: number;\n repeat: boolean;\n optional: boolean;\n}\n\nexport interface RouteRegex {\n groups: Record<string, Group>;\n re: RegExp;\n}\n\nfunction isNotFoundRoute(route: RouteNode) {\n return route.dynamic && route.dynamic[route.dynamic.length - 1].notFound;\n}\n\nfunction uniqueBy<T>(arr: T[], key: (item: T) => string): T[] {\n const seen = new Set<string>();\n return arr.filter((item) => {\n const id = key(item);\n if (seen.has(id)) {\n return false;\n }\n seen.add(id);\n return true;\n });\n}\n\n// TODO(@hassankhan): ENG-16575\ntype FlatNodeTuple = [contextKey: string, absoluteRoute: string, node: RouteNode];\n\ntype GetServerManifestOptions = {\n headers?: Record<string, string | string[]>;\n};\n\n// Given a nested route tree, return a flattened array of all routes that can be matched.\nexport function getServerManifest(\n route: RouteNode,\n options: GetServerManifestOptions | undefined\n): ExpoRouterServerManifestV1 {\n function getFlatNodes(route: RouteNode, parentRoute: string = ''): FlatNodeTuple[] {\n // Use a recreated route instead of contextKey because we duplicate nodes to support array syntax.\n const absoluteRoute = [parentRoute, route.route].filter(Boolean).join('/');\n\n if (route.children.length) {\n return route.children.map((child) => getFlatNodes(child, absoluteRoute)).flat();\n }\n\n // API Routes are handled differently to HTML routes because they have no nested behavior.\n // An HTML route can be different based on parent segments due to layout routes, therefore multiple\n // copies should be rendered. However, an API route is always the same regardless of parent segments.\n let key: string;\n if (route.type.includes('api')) {\n key = getNormalizedContextKey(route.contextKey);\n } else {\n key = getNormalizedContextKey(absoluteRoute);\n }\n return [[key, '/' + absoluteRoute, route]];\n }\n\n // Remove duplicates from the runtime manifest which expands array syntax.\n const flat = getFlatNodes(route)\n .sort(([, , a], [, , b]) => sortRoutes(b, a))\n .reverse();\n\n const apiRoutes = uniqueBy(\n flat.filter(([, , route]) => route.type === 'api'),\n ([path]) => path\n );\n\n const otherRoutes = uniqueBy(\n flat.filter(\n ([, , route]) =>\n route.type === 'route' ||\n (route.type === 'rewrite' && (route.methods === undefined || route.methods.includes('GET')))\n ),\n ([path]) => path\n );\n\n const redirects = uniqueBy(\n flat.filter(([, , route]) => route.type === 'redirect'),\n ([path]) => path\n )\n .map((redirect) => {\n // TODO(@hassankhan): ENG-16577\n // For external redirects, use `destinationContextKey` as the destination URL\n if (shouldLinkExternally(redirect[2].destinationContextKey!)) {\n redirect[1] = redirect[2].destinationContextKey!;\n } else {\n redirect[1] =\n flat.find(([, , route]) => route.contextKey === redirect[2].destinationContextKey)?.[0] ??\n '/';\n }\n\n return redirect;\n })\n .reverse();\n\n const rewrites = uniqueBy(\n flat.filter(([, , route]) => route.type === 'rewrite'),\n ([path]) => path\n )\n .map((rewrite) => {\n rewrite[1] =\n flat.find(([, , route]) => route.contextKey === rewrite[2].destinationContextKey)?.[0] ??\n '/';\n\n return rewrite;\n })\n .reverse();\n\n const standardRoutes = otherRoutes.filter(([, , route]) => !isNotFoundRoute(route));\n const notFoundRoutes = otherRoutes.filter(([, , route]) => isNotFoundRoute(route));\n\n const manifest: ExpoRouterServerManifestV1 = {\n apiRoutes: getMatchableManifestForPaths(apiRoutes),\n htmlRoutes: getMatchableManifestForPaths(standardRoutes),\n notFoundRoutes: getMatchableManifestForPaths(notFoundRoutes),\n redirects: getMatchableManifestForPaths(redirects),\n rewrites: getMatchableManifestForPaths(rewrites),\n };\n\n if (route.middleware) {\n manifest.middleware = {\n file: route.middleware.contextKey,\n };\n }\n\n if (options?.headers) {\n manifest.headers = options.headers;\n }\n\n return manifest;\n}\n\nfunction getMatchableManifestForPaths(\n paths: [string, string, RouteNode][]\n): ExpoRouterServerManifestV1Route[] {\n return paths.map(([normalizedRoutePath, absoluteRoute, node]) => {\n const matcher: ExpoRouterServerManifestV1Route = getNamedRouteRegex(\n normalizedRoutePath,\n absoluteRoute,\n node.contextKey\n );\n\n if (node.generated) {\n matcher.generated = true;\n }\n\n if (node.permanent) {\n matcher.permanent = true;\n }\n\n if (node.methods) {\n matcher.methods = node.methods;\n }\n\n return matcher;\n });\n}\n\nfunction getNamedRouteRegex(\n normalizedRoute: string,\n page: string,\n file: string\n): ExpoRouterServerManifestV1Route {\n const result = getNamedParametrizedRoute(normalizedRoute);\n return {\n file,\n page,\n namedRegex: `^${result.namedParameterizedRoute}(?:/)?$`,\n routeKeys: result.routeKeys,\n };\n}\n\n/**\n * Builds a function to generate a minimal routeKey using only a-z and minimal\n * number of characters.\n */\nfunction buildGetSafeRouteKey() {\n let currentCharCode = 96; // Starting one before 'a' to make the increment logic simpler\n let currentLength = 1;\n\n return () => {\n let result = '';\n let incrementNext = true;\n\n // Iterate from right to left to build the key\n for (let i = 0; i < currentLength; i++) {\n if (incrementNext) {\n currentCharCode++;\n if (currentCharCode > 122) {\n currentCharCode = 97; // Reset to 'a'\n incrementNext = true; // Continue to increment the next character\n } else {\n incrementNext = false;\n }\n }\n result = String.fromCharCode(currentCharCode) + result;\n }\n\n // If all characters are 'z', increase the length of the key\n if (incrementNext) {\n currentLength++;\n currentCharCode = 96; // This will make the next key start with 'a'\n }\n\n return result;\n };\n}\n\nfunction removeTrailingSlash(route: string): string {\n return route.replace(/\\/$/, '') || '/';\n}\n\nfunction getNamedParametrizedRoute(route: string) {\n const segments = removeTrailingSlash(route).slice(1).split('/');\n const getSafeRouteKey = buildGetSafeRouteKey();\n const routeKeys: Record<string, string> = {};\n return {\n namedParameterizedRoute: segments\n .map((segment, index) => {\n if (segment === '+not-found' && index === segments.length - 1) {\n segment = '[...not-found]';\n }\n if (/^\\[.*\\]$/.test(segment)) {\n const { name, optional, repeat } = parseParameter(segment);\n // replace any non-word characters since they can break\n // the named regex\n let cleanedKey = name.replace(/\\W/g, '');\n let invalidKey = false;\n\n // check if the key is still invalid and fallback to using a known\n // safe key\n if (cleanedKey.length === 0 || cleanedKey.length > 30) {\n invalidKey = true;\n }\n if (!isNaN(parseInt(cleanedKey.slice(0, 1), 10))) {\n invalidKey = true;\n }\n\n // Prevent duplicates after sanitizing the key\n if (cleanedKey in routeKeys) {\n invalidKey = true;\n }\n\n if (invalidKey) {\n cleanedKey = getSafeRouteKey();\n }\n\n routeKeys[cleanedKey] = name;\n return repeat\n ? optional\n ? `(?:/(?<${cleanedKey}>.+?))?`\n : `/(?<${cleanedKey}>.+?)`\n : `/(?<${cleanedKey}>[^/]+?)`;\n } else if (/^\\(.*\\)$/.test(segment)) {\n const groupName = matchGroupName(segment)!\n .split(',')\n .map((group) => group.trim())\n .filter(Boolean);\n if (groupName.length > 1) {\n const optionalSegment = `\\\\((?:${groupName.map(escapeStringRegexp).join('|')})\\\\)`;\n // Make section optional\n return `(?:/${optionalSegment})?`;\n } else {\n // Use simpler regex for single groups\n return `(?:/${escapeStringRegexp(segment)})?`;\n }\n } else {\n return `/${escapeStringRegexp(segment)}`;\n }\n })\n .join(''),\n routeKeys,\n };\n}\n\n// regexp is based on https://github.com/sindresorhus/escape-string-regexp\nconst reHasRegExp = /[|\\\\{}()[\\]^$+*?.-]/;\nconst reReplaceRegExp = /[|\\\\{}()[\\]^$+*?.-]/g;\n\nfunction escapeStringRegexp(str: string) {\n // see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23\n if (reHasRegExp.test(str)) {\n return str.replace(reReplaceRegExp, '\\\\$&');\n }\n return str;\n}\n\nexport function parseParameter(param: string) {\n let repeat = false;\n let optional = false;\n let name = param;\n\n if (/^\\[.*\\]$/.test(name)) {\n optional = true;\n name = name.slice(1, -1);\n }\n\n if (/^\\.\\.\\./.test(name)) {\n repeat = true;\n name = name.slice(3);\n }\n\n return { name, repeat, optional };\n}\n\nfunction getNormalizedContextKey(contextKey: string): string {\n return getContextKey(contextKey).replace(/\\/index$/, '') ?? '/';\n}\n"]}
|