expo-router 4.0.6 → 4.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/doctor/index.js +1 -1
- package/build/doctor/index.js.map +1 -1
- package/build/fork/useLinking.d.ts.map +1 -1
- package/build/fork/useLinking.js +23 -1
- package/build/fork/useLinking.js.map +1 -1
- package/build/global-state/router-store.d.ts +1 -0
- package/build/global-state/router-store.d.ts.map +1 -1
- package/build/global-state/router-store.js +1 -0
- package/build/global-state/router-store.js.map +1 -1
- package/build/global-state/routing.d.ts +1 -0
- package/build/global-state/routing.d.ts.map +1 -1
- package/build/global-state/routing.js +5 -1
- package/build/global-state/routing.js.map +1 -1
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +1 -0
- package/build/hooks.js.map +1 -1
- package/build/imperative-api.d.ts +4 -0
- package/build/imperative-api.d.ts.map +1 -1
- package/build/imperative-api.js +1 -0
- package/build/imperative-api.js.map +1 -1
- package/build/link/Link.d.ts.map +1 -1
- package/build/link/Link.js +3 -1
- package/build/link/Link.js.map +1 -1
- package/build/link/useLinkHooks.d.ts +19 -0
- package/build/link/useLinkHooks.d.ts.map +1 -1
- package/build/link/useLinkHooks.js.map +1 -1
- package/build/rsc/router/client.d.ts.map +1 -1
- package/build/rsc/router/client.js +3 -0
- package/build/rsc/router/client.js.map +1 -1
- package/build/typed-routes/generate.js +1 -0
- package/build/typed-routes/generate.js.map +1 -1
- package/package.json +3 -3
package/build/doctor/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const debug = (0, debug_1.default)('expo:router:doctor');
|
|
|
13
13
|
* which in turn will change the structure of the outDir.
|
|
14
14
|
*/
|
|
15
15
|
const routerPkg = require('../../package.json');
|
|
16
|
-
const routerDependencies = Object.entries(Object.assign({}, routerPkg.dependencies, routerPkg.peerDependencies)).filter((entry) => entry[1] !== '*');
|
|
16
|
+
const routerDependencies = Object.entries(Object.assign({}, routerPkg.dependencies, routerPkg.peerDependencies)).filter((entry) => entry[0].startsWith('@react-navigation') && entry[1] !== '*');
|
|
17
17
|
function doctor(pkg, appReactNavigationPath,
|
|
18
18
|
// Reuse the formatting functions from expo-cli
|
|
19
19
|
{ bold, learnMore, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/doctor/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAgC;AAEhC,kEAAqD;AAErD,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,oBAAoB,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,SAAS,GAAsB,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnE,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CACvC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,gBAAgB,CAAC,CACtE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/doctor/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAgC;AAEhC,kEAAqD;AAErD,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,oBAAoB,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,SAAS,GAAsB,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnE,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CACvC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,gBAAgB,CAAC,CACtE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;AASlF,SAAgB,MAAM,CACpB,GAAs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,GAAG,CAAC,YAAY,IAAI,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB;YAC7F,sBAAsB,EAAE,YAAY;YACpC,aAAa,EAAE,UAAU;SAC1B,CAAC,CAAC;KACJ;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AArED,wBAqEC","sourcesContent":["import createDebug from 'debug';\nimport type { PackageJSONConfig } from 'expo/config';\nimport semverRangeSubset from 'semver/ranges/subset';\n\nconst debug = createDebug('expo:router:doctor');\n\n/**\n * Small hack to get the package.json.\n * We do no use import() as this would require changing the rootDir in `tsconfig.json`,\n * which in turn will change the structure of the outDir.\n */\nconst routerPkg: PackageJSONConfig = require('../../package.json');\n\nconst routerDependencies = Object.entries<string>(\n Object.assign({}, routerPkg.dependencies, routerPkg.peerDependencies)\n).filter((entry) => entry[0].startsWith('@react-navigation') && entry[1] !== '*');\n\ntype IncorrectDependency = {\n packageName: string;\n packageType: 'dependencies' | 'devDependencies';\n expectedVersionOrRange: string;\n actualVersion: string;\n};\n\nexport function doctor(\n pkg: PackageJSONConfig,\n appReactNavigationPath: string,\n // Reuse the formatting functions from expo-cli\n {\n bold,\n learnMore,\n }: {\n bold: (text: string) => string;\n learnMore: (url: string, options?: { learnMoreMessage?: string; dim?: boolean }) => string;\n }\n): IncorrectDependency[] {\n const resolvedDependencies = { ...pkg.dependencies, ...pkg.devDependencies };\n const libReactNavigationPath = require.resolve('@react-navigation/native');\n\n const userExcluded = new Set(pkg.expo?.install?.exclude);\n const incorrectDependencies: IncorrectDependency[] = [];\n\n /**\n * If the user has a dependency with a sub-dependency on @react-navigation/native, this may install a different\n * version of @react-navigation/native than the one required by expo-router.\n *\n * To detect this, we require the caller of this function to first resolve their path to @react-navigation/native, as\n * they will get the 'top' level package. When expo-router resolves the path to @react-navigation/native, if it is different\n * when the versions must not have matched and the package manager installed a nested node_module folder with a different\n * version of @react-navigation/native.\n */\n if (\n userExcluded.has('@react-navigation/native') &&\n appReactNavigationPath !== libReactNavigationPath\n ) {\n console.warn(\n `Detected multiple versions of ${bold('@react-navigation/native')} in your ${bold('node_modules')}. This may lead to unexpected navigation behavior and errors. ${learnMore('https://expo.fyi/router-navigation-deps')}.`\n );\n }\n\n for (const [dep, allowedRange] of routerDependencies) {\n if (userExcluded.has(dep)) {\n debug(`Skipping ${dep} because it is excluded in the config`);\n continue;\n }\n\n const usersRange = resolvedDependencies[dep];\n\n /**\n * routerDependencies contains all the dependencies that are required by expo-router,\n * both peerDependencies and dependencies. If the user has not manually installed\n * them, then we should skip them.\n */\n if (!usersRange) {\n continue;\n }\n\n debug(`Checking ${dep} with ${allowedRange} and found ${usersRange}`);\n if (!usersRange || semverRangeSubset(allowedRange, usersRange)) {\n continue;\n }\n\n debug(`Incorrect dependency found for ${dep}`);\n\n incorrectDependencies.push({\n packageName: dep,\n packageType: pkg.dependencies && dep in pkg.dependencies ? 'dependencies' : 'devDependencies',\n expectedVersionOrRange: allowedRange,\n actualVersion: usersRange,\n });\n }\n\n return incorrectDependencies;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinking.d.ts","sourceRoot":"","sources":["../../src/fork/useLinking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAKd,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA+C/B;;GAEG;AACH,eAAO,MAAM,MAAM,OAAQ,MAAM,QAAQ,IAAI,CAAC,eAM7C,CAAC;AAIF,KAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;AAE7C,wBAAgB,UAAU,CACxB,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,OAAc,EACd,MAAM,EACN,gBAA0C,EAC1C,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO,EACV,kBAAkB,EAAE,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useLinking.d.ts","sourceRoot":"","sources":["../../src/fork/useLinking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAKd,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA+C/B;;GAEG;AACH,eAAO,MAAM,MAAM,OAAQ,MAAM,QAAQ,IAAI,CAAC,eAM7C,CAAC;AAIF,KAAK,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;AAE7C,wBAAgB,UAAU,CACxB,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,EAC3D,EACE,OAAc,EACd,MAAM,EACN,gBAA0C,EAC1C,gBAA0C,EAC1C,kBAA8C,GAC/C,EAAE,OAAO,EACV,kBAAkB,EAAE,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;EA0WtE"}
|
package/build/fork/useLinking.js
CHANGED
|
@@ -183,7 +183,29 @@ function useLinking(ref, { enabled = true, config, getStateFromPath = native_1.g
|
|
|
183
183
|
if (validateRoutesNotExistInRootState(state)) {
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
|
-
if (index > previousIndex
|
|
186
|
+
if (index > previousIndex ||
|
|
187
|
+
/* START FORK
|
|
188
|
+
*
|
|
189
|
+
* This is a workaround for React Navigation's handling of hashes (it doesn't handle them)
|
|
190
|
+
* When you click on <a href="#hash">, the browser will first fire a popstate event
|
|
191
|
+
* and this callback will be called.
|
|
192
|
+
*
|
|
193
|
+
* From React Navigation's perspective, it's treating the new hash change like a back/forward
|
|
194
|
+
* button press, so it thinks it should reset the state. When we should
|
|
195
|
+
* be to be pushing the new state
|
|
196
|
+
*
|
|
197
|
+
* Our fix is to check if the index is the same as the previous index
|
|
198
|
+
* and if the incoming path is the same as the old path but with the hash added,
|
|
199
|
+
* then treat it as a push instead of a reset
|
|
200
|
+
*
|
|
201
|
+
* This also works for subsequent hash changes, as internally RN
|
|
202
|
+
* doesn't store the hash in the history state.
|
|
203
|
+
*
|
|
204
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent
|
|
205
|
+
*/
|
|
206
|
+
(index === previousIndex && (!record || `${record?.path}${location.hash}` === path))
|
|
207
|
+
// END FORK
|
|
208
|
+
) {
|
|
187
209
|
const action = getActionFromStateRef.current(state, configRef.current);
|
|
188
210
|
if (action !== undefined) {
|
|
189
211
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinking.js","sourceRoot":"","sources":["../../src/fork/useLinking.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAUkC;AAClC,sEAAsC;AACtC,6CAA+B;AAE/B,+DAA4D;AAC5D,iFAAsE;AAItE;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CACxB,CAAgB,EAChB,CAAgB,EACgB,EAAE;IAClC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE;QACzD,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;KAC/B;IAED,uFAAuF;IACvF,MAAM,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IACtE,MAAM,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IA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;qBAClC;oBAAC,MAAM;wBACN,iCAAiC;qBAClC;iBACF;qBAAM;oBACL,0DAA0D;oBAC1D,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;iBAClC;aACF;iBAAM;gBACL,iEAAiE;gBACjE,6EAA6E;gBAC7E,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;aAClC;QACH,CAAC,CAAC;QAEF,+FAA+F;QAC/F,0DAA0D;QAC1D,qGAAqG;QACrG,OAAO,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,IAAA,cAAM,EAAC,aAAa,CAAC,CAAC,CAAC;IAClE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAE5B,OAAO;QACL,eAAe;KAChB,CAAC;AACJ,CAAC;AA5VD,gCA4VC","sourcesContent":["import {\n LinkingOptions,\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n type NavigationContainerRef,\n type NavigationState,\n type ParamListBase,\n useNavigationIndependentTree,\n} from '@react-navigation/native';\nimport isEqual from 'fast-deep-equal';\nimport * as React from 'react';\n\nimport { createMemoryHistory } from './createMemoryHistory';\nimport { ServerContext } from '../global-state/serverLocationContext';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nexport const series = (cb: () => Promise<void>) => {\n let queue = Promise.resolve();\n const callback = () => {\n queue = queue.then(cb);\n };\n return callback;\n};\n\nconst linkingHandlers: symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase>;\n\nexport function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options,\n onUnhandledLinking: (lastUnhandledLining: string | undefined) => void\n) {\n const independent = useNavigationIndependentTree();\n\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const validateRoutesNotExistInRootState = React.useCallback(\n (state: ResultState) => {\n const navigation = ref.current;\n const rootState = navigation?.getRootState();\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n return state?.routes.some((r) => !rootState?.routeNames.includes(r.name));\n },\n [ref]\n );\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ?? (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const { location } = window;\n\n const path = location.pathname + location.search + location.hash;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n if (validateRoutesNotExistInRootState(state)) {\n return;\n }\n\n if (index > previousIndex) {\n const action = getActionFromStateRef.current(state, configRef.current);\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e ? e.message : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, onUnhandledLinking, ref, validateRoutesNotExistInRootState]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n let path;\n\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(route.path, configRef.current);\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual({ ...focusedRoute.params }, { ...route.params })\n ) {\n path = route.path;\n }\n }\n }\n\n if (path == null) {\n path = getPathFromStateRef.current(state, configRef.current);\n }\n\n // START FORK - ExpoRouter manually handles hashes\n // const previousRoute = previousStateRef.current\n // ? findFocusedRoute(previousStateRef.current)\n // : undefined;\n\n // Preserve the hash if the route didn't change\n // if (\n // previousRoute &&\n // route &&\n // 'key' in previousRoute &&\n // 'key' in route &&\n // previousRoute.key === route.key\n // ) {\n // path = path + location.hash;\n // }\n // END FORK\n\n return path;\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(previousState, state);\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history ? focusedState.history.length : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (\n nextIndex !== -1 &&\n nextIndex < currentIndex &&\n // We should only go back if the entry exists and it's less than current index\n history.get(nextIndex - currentIndex)\n ) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n }, [enabled, history, ref]);\n\n return {\n getInitialState,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useLinking.js","sourceRoot":"","sources":["../../src/fork/useLinking.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAUkC;AAClC,sEAAsC;AACtC,6CAA+B;AAE/B,+DAA4D;AAC5D,iFAAsE;AAItE;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CACxB,CAAgB,EAChB,CAAgB,EACgB,EAAE;IAClC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE;QACzD,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;KAC/B;IAED,uFAAuF;IACvF,MAAM,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IACtE,MAAM,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAA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3F,MAAM,OAAO,CAAC,EAAE,CAAC,SAAS,GAAG,YAAY,CAAC,CAAC;yBAC5C;6BAAM;4BACL,kFAAkF;4BAClF,wEAAwE;4BACxE,gEAAgE;4BAChE,MAAM,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;yBAChC;wBAED,+DAA+D;wBAC/D,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;qBAClC;oBAAC,MAAM;wBACN,iCAAiC;qBAClC;iBACF;qBAAM;oBACL,0DAA0D;oBAC1D,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;iBAClC;aACF;iBAAM;gBACL,iEAAiE;gBACjE,6EAA6E;gBAC7E,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;aAClC;QACH,CAAC,CAAC;QAEF,+FAA+F;QAC/F,0DAA0D;QAC1D,qGAAqG;QACrG,OAAO,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,IAAA,cAAM,EAAC,aAAa,CAAC,CAAC,CAAC;IAClE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAE5B,OAAO;QACL,eAAe;KAChB,CAAC;AACJ,CAAC;AAnXD,gCAmXC","sourcesContent":["import {\n LinkingOptions,\n findFocusedRoute,\n getActionFromState as getActionFromStateDefault,\n getPathFromState as getPathFromStateDefault,\n getStateFromPath as getStateFromPathDefault,\n type NavigationContainerRef,\n type NavigationState,\n type ParamListBase,\n useNavigationIndependentTree,\n} from '@react-navigation/native';\nimport isEqual from 'fast-deep-equal';\nimport * as React from 'react';\n\nimport { createMemoryHistory } from './createMemoryHistory';\nimport { ServerContext } from '../global-state/serverLocationContext';\n\ntype ResultState = ReturnType<typeof getStateFromPathDefault>;\n\n/**\n * Find the matching navigation state that changed between 2 navigation states\n * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state\n */\nconst findMatchingState = <T extends NavigationState>(\n a: T | undefined,\n b: T | undefined\n): [T | undefined, T | undefined] => {\n if (a === undefined || b === undefined || a.key !== b.key) {\n return [undefined, undefined];\n }\n\n // Tab and drawer will have `history` property, but stack will have history in `routes`\n const aHistoryLength = a.history ? a.history.length : a.routes.length;\n const bHistoryLength = b.history ? b.history.length : b.routes.length;\n\n const aRoute = a.routes[a.index];\n const bRoute = b.routes[b.index];\n\n const aChildState = aRoute.state as T | undefined;\n const bChildState = bRoute.state as T | undefined;\n\n // Stop here if this is the state object that changed:\n // - history length is different\n // - focused routes are different\n // - one of them doesn't have child state\n // - child state keys are different\n if (\n aHistoryLength !== bHistoryLength ||\n aRoute.key !== bRoute.key ||\n aChildState === undefined ||\n bChildState === undefined ||\n aChildState.key !== bChildState.key\n ) {\n return [a, b];\n }\n\n return findMatchingState(aChildState, bChildState);\n};\n\n/**\n * Run async function in series as it's called.\n */\nexport const series = (cb: () => Promise<void>) => {\n let queue = Promise.resolve();\n const callback = () => {\n queue = queue.then(cb);\n };\n return callback;\n};\n\nconst linkingHandlers: symbol[] = [];\n\ntype Options = LinkingOptions<ParamListBase>;\n\nexport function useLinking(\n ref: React.RefObject<NavigationContainerRef<ParamListBase>>,\n {\n enabled = true,\n config,\n getStateFromPath = getStateFromPathDefault,\n getPathFromState = getPathFromStateDefault,\n getActionFromState = getActionFromStateDefault,\n }: Options,\n onUnhandledLinking: (lastUnhandledLining: string | undefined) => void\n) {\n const independent = useNavigationIndependentTree();\n\n React.useEffect(() => {\n if (process.env.NODE_ENV === 'production') {\n return undefined;\n }\n\n if (independent) {\n return undefined;\n }\n\n if (enabled !== false && linkingHandlers.length) {\n console.error(\n [\n 'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',\n \"- You don't have multiple NavigationContainers in the app each with 'linking' enabled\",\n '- Only a single instance of the root component is rendered',\n ]\n .join('\\n')\n .trim()\n );\n }\n\n const handler = Symbol();\n\n if (enabled !== false) {\n linkingHandlers.push(handler);\n }\n\n return () => {\n const index = linkingHandlers.indexOf(handler);\n\n if (index > -1) {\n linkingHandlers.splice(index, 1);\n }\n };\n }, [enabled, independent]);\n\n const [history] = React.useState(createMemoryHistory);\n\n // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners\n // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`\n // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect\n const enabledRef = React.useRef(enabled);\n const configRef = React.useRef(config);\n const getStateFromPathRef = React.useRef(getStateFromPath);\n const getPathFromStateRef = React.useRef(getPathFromState);\n const getActionFromStateRef = React.useRef(getActionFromState);\n\n React.useEffect(() => {\n enabledRef.current = enabled;\n configRef.current = config;\n getStateFromPathRef.current = getStateFromPath;\n getPathFromStateRef.current = getPathFromState;\n getActionFromStateRef.current = getActionFromState;\n });\n\n const validateRoutesNotExistInRootState = React.useCallback(\n (state: ResultState) => {\n const navigation = ref.current;\n const rootState = navigation?.getRootState();\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n return state?.routes.some((r) => !rootState?.routeNames.includes(r.name));\n },\n [ref]\n );\n\n const server = React.useContext(ServerContext);\n\n const getInitialState = React.useCallback(() => {\n let value: ResultState | undefined;\n\n if (enabledRef.current) {\n const location =\n server?.location ?? (typeof window !== 'undefined' ? window.location : undefined);\n\n const path = location ? location.pathname + location.search : undefined;\n\n if (path) {\n value = getStateFromPathRef.current(path, configRef.current);\n }\n\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n }\n\n const thenable = {\n then(onfulfilled?: (state: ResultState | undefined) => void) {\n return Promise.resolve(onfulfilled ? onfulfilled(value) : value);\n },\n catch() {\n return thenable;\n },\n };\n\n return thenable as PromiseLike<ResultState | undefined>;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const previousIndexRef = React.useRef<number | undefined>(undefined);\n const previousStateRef = React.useRef<NavigationState | undefined>(undefined);\n const pendingPopStatePathRef = React.useRef<string | undefined>(undefined);\n\n React.useEffect(() => {\n previousIndexRef.current = history.index;\n\n return history.listen(() => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const { location } = window;\n\n const path = location.pathname + location.search + location.hash;\n const index = history.index;\n\n const previousIndex = previousIndexRef.current ?? 0;\n\n previousIndexRef.current = index;\n pendingPopStatePathRef.current = path;\n\n // When browser back/forward is clicked, we first need to check if state object for this index exists\n // If it does we'll reset to that state object\n // Otherwise, we'll handle it like a regular deep link\n const record = history.get(index);\n\n if (record?.path === path && record?.state) {\n navigation.resetRoot(record.state);\n return;\n }\n\n const state = getStateFromPathRef.current(path, configRef.current);\n\n // We should only dispatch an action when going forward\n // Otherwise the action will likely add items to history, which would mess things up\n if (state) {\n // If the link were handled, it gets cleared in NavigationContainer\n onUnhandledLinking(path);\n // Make sure that the routes in the state exist in the root navigator\n // Otherwise there's an error in the linking configuration\n if (validateRoutesNotExistInRootState(state)) {\n return;\n }\n\n if (\n index > previousIndex ||\n /* START FORK\n *\n * This is a workaround for React Navigation's handling of hashes (it doesn't handle them)\n * When you click on <a href=\"#hash\">, the browser will first fire a popstate event\n * and this callback will be called.\n *\n * From React Navigation's perspective, it's treating the new hash change like a back/forward\n * button press, so it thinks it should reset the state. When we should\n * be to be pushing the new state\n *\n * Our fix is to check if the index is the same as the previous index\n * and if the incoming path is the same as the old path but with the hash added,\n * then treat it as a push instead of a reset\n *\n * This also works for subsequent hash changes, as internally RN\n * doesn't store the hash in the history state.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent\n */\n (index === previousIndex && (!record || `${record?.path}${location.hash}` === path))\n // END FORK\n ) {\n const action = getActionFromStateRef.current(state, configRef.current);\n\n if (action !== undefined) {\n try {\n navigation.dispatch(action);\n } catch (e) {\n // Ignore any errors from deep linking.\n // This could happen in case of malformed links, navigation object not being initialized etc.\n console.warn(\n `An error occurred when trying to handle the link '${path}': ${\n typeof e === 'object' && e != null && 'message' in e ? e.message : e\n }`\n );\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n navigation.resetRoot(state);\n }\n } else {\n // if current path didn't return any state, we should revert to initial state\n navigation.resetRoot(state);\n }\n });\n }, [enabled, history, onUnhandledLinking, ref, validateRoutesNotExistInRootState]);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n const getPathForRoute = (\n route: ReturnType<typeof findFocusedRoute>,\n state: NavigationState\n ): string => {\n let path;\n\n // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match\n // This makes sure that we preserve the original URL for wildcard routes\n if (route?.path) {\n const stateForPath = getStateFromPathRef.current(route.path, configRef.current);\n\n if (stateForPath) {\n const focusedRoute = findFocusedRoute(stateForPath);\n\n if (\n focusedRoute &&\n focusedRoute.name === route.name &&\n isEqual({ ...focusedRoute.params }, { ...route.params })\n ) {\n path = route.path;\n }\n }\n }\n\n if (path == null) {\n path = getPathFromStateRef.current(state, configRef.current);\n }\n\n // START FORK - ExpoRouter manually handles hashes\n // const previousRoute = previousStateRef.current\n // ? findFocusedRoute(previousStateRef.current)\n // : undefined;\n\n // Preserve the hash if the route didn't change\n // if (\n // previousRoute &&\n // route &&\n // 'key' in previousRoute &&\n // 'key' in route &&\n // previousRoute.key === route.key\n // ) {\n // path = path + location.hash;\n // }\n // END FORK\n\n return path;\n };\n\n if (ref.current) {\n // We need to record the current metadata on the first render if they aren't set\n // This will allow the initial state to be in the history entry\n const state = ref.current.getRootState();\n\n if (state) {\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n if (previousStateRef.current === undefined) {\n previousStateRef.current = state;\n }\n\n history.replace({ path, state });\n }\n }\n\n const onStateChange = async () => {\n const navigation = ref.current;\n\n if (!navigation || !enabled) {\n return;\n }\n\n const previousState = previousStateRef.current;\n const state = navigation.getRootState();\n\n // root state may not available, for example when root navigators switch inside the container\n if (!state) {\n return;\n }\n\n const pendingPath = pendingPopStatePathRef.current;\n const route = findFocusedRoute(state);\n const path = getPathForRoute(route, state);\n\n previousStateRef.current = state;\n pendingPopStatePathRef.current = undefined;\n\n // To detect the kind of state change, we need to:\n // - Find the common focused navigation state in previous and current state\n // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace\n // - If no common focused navigation state found, it's a replace\n const [previousFocusedState, focusedState] = findMatchingState(previousState, state);\n\n if (\n previousFocusedState &&\n focusedState &&\n // We should only handle push/pop if path changed from what was in last `popstate`\n // Otherwise it's likely a change triggered by `popstate`\n path !== pendingPath\n ) {\n const historyDelta =\n (focusedState.history ? focusedState.history.length : focusedState.routes.length) -\n (previousFocusedState.history\n ? previousFocusedState.history.length\n : previousFocusedState.routes.length);\n\n if (historyDelta > 0) {\n // If history length is increased, we should pushState\n // Note that path might not actually change here, for example, drawer open should pushState\n history.push({ path, state });\n } else if (historyDelta < 0) {\n // If history length is decreased, i.e. entries were removed, we want to go back\n\n const nextIndex = history.backIndex({ path });\n const currentIndex = history.index;\n\n try {\n if (\n nextIndex !== -1 &&\n nextIndex < currentIndex &&\n // We should only go back if the entry exists and it's less than current index\n history.get(nextIndex - currentIndex)\n ) {\n // An existing entry for this path exists and it's less than current index, go back to that\n await history.go(nextIndex - currentIndex);\n } else {\n // We couldn't find an existing entry to go back to, so we'll go back by the delta\n // This won't be correct if multiple routes were pushed in one go before\n // Usually this shouldn't happen and this is a fallback for that\n await history.go(historyDelta);\n }\n\n // Store the updated state as well as fix the path if incorrect\n history.replace({ path, state });\n } catch {\n // The navigation was interrupted\n }\n } else {\n // If history length is unchanged, we want to replaceState\n history.replace({ path, state });\n }\n } else {\n // If no common navigation state was found, assume it's a replace\n // This would happen if the user did a reset/conditionally changed navigators\n history.replace({ path, state });\n }\n };\n\n // We debounce onStateChange coz we don't want multiple state changes to be handled at one time\n // This could happen since `history.go(n)` is asynchronous\n // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up\n return ref.current?.addListener('state', series(onStateChange));\n }, [enabled, history, ref]);\n\n return {\n getInitialState,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EAElC,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAiC,aAAa,EAAY,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EAElC,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAiC,aAAa,EAAY,MAAM,OAAO,CAAC;AAkB/E,OAAO,EAAE,SAAS,EAAyB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAoB,MAAM,qBAAqB,CAAC;AAEjG,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI1C,KAAK,WAAW,GAAG,GAAG,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,WAAW;IACtB,SAAS,EAAG,SAAS,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAG,aAAa,CAAC;IAC9B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,OAAO,CAAC,wBAAwB,CAAkB;IAElD,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAEpC,aAAa,EAAG,iCAAiC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACjF,yBAAyB,EAAG,MAAM,IAAI,CAAC;IAEvC,oBAAoB,YAAiB,IAAI,EAAI;IAC7C,gBAAgB,YAAiB,IAAI,EAAI;IAEzC,MAAM,MAAqB;IAC3B,eAAe,MAA8B;IAC7C,MAAM,MAAqB;IAC3B,SAAS,MAAwB;IACjC,IAAI,MAAmB;IACvB,OAAO,MAAsB;IAC7B,SAAS,MAAwB;IACjC,OAAO,MAAsB;IAC7B,UAAU,MAAyB;IACnC,UAAU,MAAyB;IACnC,SAAS,MAAwB;IACjC,QAAQ,MAAuB;IAC/B,MAAM,MAAqB;IAE3B,UAAU,CACR,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,iCAAiC,CAAC,eAAe,CAAC,aAAa,CAAC,EAC/E,oBAAoB,GAAE,oBAAyB;IAoGjD,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,MAAQ;IAWjD,YAAY,CAAC,KAAK,EAAE,WAAW;IAiB/B,kBAAkB;IAIlB,uEAAuE;IACvE,oBAAoB,eAAgB,MAAM,IAAI,mBAG5C;IACF,gBAAgB,eAAgB,MAAM,IAAI,mBAGxC;IACF,QAAQ,aAEN;IACF,iBAAiB,YAEf;IACF,iBAAiB,kBAEf;IAEF,OAAO;CAKR;AAED,eAAO,MAAM,KAAK,aAAoB,CAAC;AAEvC,wBAAgB,aAAa,gBAE5B;AAYD,wBAAgB,iBAAiB,QAOhC;AAED,wBAAgB,iBAAiB,cAOhC;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,eAK7F"}
|
|
@@ -67,6 +67,7 @@ class RouterStore {
|
|
|
67
67
|
canGoBack = routing_1.canGoBack.bind(this);
|
|
68
68
|
push = routing_1.push.bind(this);
|
|
69
69
|
dismiss = routing_1.dismiss.bind(this);
|
|
70
|
+
dismissTo = routing_1.dismissTo.bind(this);
|
|
70
71
|
replace = routing_1.replace.bind(this);
|
|
71
72
|
dismissAll = routing_1.dismissAll.bind(this);
|
|
72
73
|
canDismiss = routing_1.canDismiss.bind(this);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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,aAAa,CAAC,YAAY,EAA4B,CAAC;QAElF,IAAI,aAAK,CAAC,SAAS,KAAK,YAAY,EAAE;YACpC,aAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SACjC;KACF;AACH,CAAC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,uBAAuB,CAAC,OAAuB,EAAE,OAA6B;IAC5F,MAAM,aAAa,GAAG,IAAA,kCAAyB,GAAE,CAAC;IAClD,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,aAAK,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5E,aAAa,EAAE,CAAC;IAChB,OAAO,aAAK,CAAC;AACf,CAAC;AALD,0DAKC","sourcesContent":["'use client';\n\nimport {\n NavigationContainerRefWithCurrent,\n useNavigationContainerRef,\n} from '@react-navigation/native';\nimport Constants from 'expo-constants';\nimport equal from 'fast-deep-equal';\nimport { useSyncExternalStore, useMemo, ComponentType, Fragment } from 'react';\nimport { Platform } from 'react-native';\n\nimport {\n canGoBack,\n canDismiss,\n goBack,\n linkTo,\n navigate,\n dismiss,\n dismissAll,\n push,\n reload,\n replace,\n setParams,\n} from './routing';\nimport { getSortedRoutes } from './sort-routes';\nimport { UrlObject, getRouteInfoFromState } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { getPathDataFromState, getPathFromState } from '../fork/getPathFromState';\n// import { ResultState } from '../fork/getStateFromPath';\nimport { ExpoLinkingOptions, LinkingConfigOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\nimport * as SplashScreen from '../views/Splash';\n\ntype ResultState = any;\n\n/**\n * This is the global state for the router. It is used to keep track of the current route, and to provide a way to navigate to other routes.\n *\n * There should only be one instance of this class and be initialized via `useInitializeExpoRouter`\n */\nexport class RouterStore {\n routeNode!: RouteNode | null;\n rootComponent!: ComponentType;\n linking?: ExpoLinkingOptions;\n private hasAttemptedToHideSplash: boolean = false;\n\n initialState?: ResultState;\n rootState?: ResultState;\n nextState?: ResultState;\n routeInfo?: UrlObject;\n splashScreenAnimationFrame?: number;\n\n navigationRef!: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;\n navigationRefSubscription!: () => void;\n\n rootStateSubscribers = new Set<() => void>();\n storeSubscribers = new Set<() => void>();\n\n linkTo = linkTo.bind(this);\n getSortedRoutes = getSortedRoutes.bind(this);\n goBack = goBack.bind(this);\n canGoBack = canGoBack.bind(this);\n push = push.bind(this);\n dismiss = dismiss.bind(this);\n replace = replace.bind(this);\n dismissAll = dismissAll.bind(this);\n canDismiss = canDismiss.bind(this);\n setParams = setParams.bind(this);\n navigate = navigate.bind(this);\n reload = reload.bind(this);\n\n initialize(\n context: RequireContext,\n navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>,\n linkingConfigOptions: LinkingConfigOptions = {}\n ) {\n // Clean up any previous state\n this.initialState = undefined;\n this.rootState = undefined;\n this.nextState = undefined;\n this.linking = undefined;\n this.navigationRefSubscription?.();\n this.rootStateSubscribers.clear();\n this.storeSubscribers.clear();\n\n this.routeNode = getRoutes(context, {\n ...Constants.expoConfig?.extra?.router,\n ignoreEntryPoints: true,\n platform: Platform.OS,\n });\n\n // We always needs routeInfo, even if there are no routes. This can happen if:\n // - there are no routes (we are showing the onboarding screen)\n // - getInitialURL() is async\n this.routeInfo = {\n unstable_globalHref: '',\n pathname: '',\n isIndex: false,\n params: {},\n segments: [],\n };\n\n if (this.routeNode) {\n // We have routes, so get the linking config and the root component\n this.linking = getLinkingConfig(this, this.routeNode, context, linkingConfigOptions);\n this.rootComponent = getQualifiedRouteComponent(this.routeNode);\n\n // By default React Navigation is async and does not render anything in the first pass as it waits for `getInitialURL`\n // This will cause static rendering to fail, which once performs a single pass.\n // If the initialURL is a string, we can preload the state and routeInfo, skipping React Navigation's async behavior.\n const initialURL = this.linking?.getInitialURL?.();\n if (typeof initialURL === 'string') {\n this.rootState = this.linking.getStateFromPath?.(initialURL, this.linking.config);\n this.initialState = this.rootState;\n if (this.rootState) {\n this.routeInfo = this.getRouteInfo(this.rootState);\n }\n }\n } else {\n // Only error in production, in development we will show the onboarding screen\n if (process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n // In development, we will show the onboarding screen\n this.rootComponent = Fragment;\n }\n\n /**\n * Counter intuitively - this fires AFTER both React Navigation's state changes and the subsequent paint.\n * This poses a couple of issues for Expo Router,\n * - Ensuring hooks (e.g. useSearchParams()) have data in the initial render\n * - Reacting to state changes after a navigation event\n *\n * This is why the initial render renders a Fragment and we wait until `onReady()` is called\n * Additionally, some hooks compare the state from both the store and the navigationRef. If the store it stale,\n * that hooks will manually update the store.\n *\n */\n this.navigationRef = navigationRef;\n this.navigationRefSubscription = navigationRef.addListener('state', (data) => {\n const state = data.data.state as ResultState;\n\n if (!this.hasAttemptedToHideSplash) {\n this.hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n this.splashScreenAnimationFrame = requestAnimationFrame(() => {\n SplashScreen._internal_maybeHideAsync?.();\n });\n }\n\n let shouldUpdateSubscribers = this.nextState === state;\n this.nextState = undefined;\n\n // This can sometimes be undefined when an error is thrown in the Root Layout Route.\n // Additionally that state may already equal the rootState if it was updated within a hook\n if (state && state !== this.rootState) {\n store.updateState(state, undefined);\n shouldUpdateSubscribers = true;\n }\n\n // If the state has changed, or was changed inside a hook we need to update the subscribers\n if (shouldUpdateSubscribers) {\n for (const subscriber of this.rootStateSubscribers) {\n subscriber();\n }\n }\n });\n\n for (const subscriber of this.storeSubscribers) {\n subscriber();\n }\n }\n\n updateState(state: ResultState, nextState = state) {\n store.rootState = state;\n store.nextState = nextState;\n\n const nextRouteInfo = store.getRouteInfo(state);\n\n if (!equal(this.routeInfo, nextRouteInfo)) {\n store.routeInfo = nextRouteInfo;\n }\n }\n\n getRouteInfo(state: ResultState) {\n return getRouteInfoFromState(\n (state: Parameters<typeof getPathFromState>[0], asPath: boolean) => {\n return getPathDataFromState(state, {\n screens: {},\n ...this.linking?.config,\n preserveDynamicRoutes: asPath,\n preserveGroups: asPath,\n shouldEncodeURISegment: false,\n });\n },\n state\n );\n }\n\n // This is only used in development, to show the onboarding screen\n // In production we should have errored during the initialization\n shouldShowTutorial() {\n return !this.routeNode && process.env.NODE_ENV === 'development';\n }\n\n /** Make sure these are arrow functions so `this` is correctly bound */\n subscribeToRootState = (subscriber: () => void) => {\n this.rootStateSubscribers.add(subscriber);\n return () => this.rootStateSubscribers.delete(subscriber);\n };\n subscribeToStore = (subscriber: () => void) => {\n this.storeSubscribers.add(subscriber);\n return () => this.storeSubscribers.delete(subscriber);\n };\n snapshot = () => {\n return this;\n };\n rootStateSnapshot = () => {\n return this.rootState!;\n };\n routeInfoSnapshot = () => {\n return this.routeInfo!;\n };\n\n cleanup() {\n if (this.splashScreenAnimationFrame) {\n cancelAnimationFrame(this.splashScreenAnimationFrame);\n }\n }\n}\n\nexport const store = new RouterStore();\n\nexport function useExpoRouter() {\n return useSyncExternalStore(store.subscribeToStore, store.snapshot, store.snapshot);\n}\n\nfunction syncStoreRootState() {\n if (store.navigationRef.isReady()) {\n const currentState = store.navigationRef.getRootState() as unknown as ResultState;\n\n if (store.rootState !== currentState) {\n store.updateState(currentState);\n }\n }\n}\n\nexport function useStoreRootState() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.rootStateSnapshot,\n store.rootStateSnapshot\n );\n}\n\nexport function useStoreRouteInfo() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.routeInfoSnapshot,\n store.routeInfoSnapshot\n );\n}\n\nexport function useInitializeExpoRouter(context: RequireContext, options: LinkingConfigOptions) {\n const navigationRef = useNavigationContainerRef();\n useMemo(() => store.initialize(context, navigationRef, options), [context]);\n useExpoRouter();\n return store;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"router-store.js","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,qDAGkC;AAClC,oEAAuC;AACvC,sEAAoC;AACpC,iCAA+E;AAC/E,+CAAwC;AAExC,uCAamB;AACnB,+CAAgD;AAChD,0DAAuE;AAEvE,+DAAkF;AAClF,0DAA0D;AAC1D,0DAAiG;AACjG,4CAAyC;AAEzC,8CAA2D;AAC3D,8DAAgD;AAIhD;;;;GAIG;AACH,MAAa,WAAW;IACtB,SAAS,CAAoB;IAC7B,aAAa,CAAiB;IAC9B,OAAO,CAAsB;IACrB,wBAAwB,GAAY,KAAK,CAAC;IAElD,YAAY,CAAe;IAC3B,SAAS,CAAe;IACxB,SAAS,CAAe;IACxB,SAAS,CAAa;IACtB,0BAA0B,CAAU;IAEpC,aAAa,CAAoE;IACjF,yBAAyB,CAAc;IAEvC,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAC7C,gBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;IAEzC,MAAM,GAAG,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,eAAe,GAAG,6BAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,GAAG,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC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B,OAAO,aAAK,CAAC;AACf,CAAC;AALD,0DAKC","sourcesContent":["'use client';\n\nimport {\n NavigationContainerRefWithCurrent,\n useNavigationContainerRef,\n} from '@react-navigation/native';\nimport Constants from 'expo-constants';\nimport equal from 'fast-deep-equal';\nimport { useSyncExternalStore, useMemo, ComponentType, Fragment } from 'react';\nimport { Platform } from 'react-native';\n\nimport {\n canGoBack,\n canDismiss,\n goBack,\n linkTo,\n navigate,\n dismiss,\n dismissAll,\n push,\n reload,\n replace,\n setParams,\n dismissTo,\n} from './routing';\nimport { getSortedRoutes } from './sort-routes';\nimport { UrlObject, getRouteInfoFromState } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { getPathDataFromState, getPathFromState } from '../fork/getPathFromState';\n// import { ResultState } from '../fork/getStateFromPath';\nimport { ExpoLinkingOptions, LinkingConfigOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\nimport * as SplashScreen from '../views/Splash';\n\ntype ResultState = any;\n\n/**\n * This is the global state for the router. It is used to keep track of the current route, and to provide a way to navigate to other routes.\n *\n * There should only be one instance of this class and be initialized via `useInitializeExpoRouter`\n */\nexport class RouterStore {\n routeNode!: RouteNode | null;\n rootComponent!: ComponentType;\n linking?: ExpoLinkingOptions;\n private hasAttemptedToHideSplash: boolean = false;\n\n initialState?: ResultState;\n rootState?: ResultState;\n nextState?: ResultState;\n routeInfo?: UrlObject;\n splashScreenAnimationFrame?: number;\n\n navigationRef!: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;\n navigationRefSubscription!: () => void;\n\n rootStateSubscribers = new Set<() => void>();\n storeSubscribers = new Set<() => void>();\n\n linkTo = linkTo.bind(this);\n getSortedRoutes = getSortedRoutes.bind(this);\n goBack = goBack.bind(this);\n canGoBack = canGoBack.bind(this);\n push = push.bind(this);\n dismiss = dismiss.bind(this);\n dismissTo = dismissTo.bind(this);\n replace = replace.bind(this);\n dismissAll = dismissAll.bind(this);\n canDismiss = canDismiss.bind(this);\n setParams = setParams.bind(this);\n navigate = navigate.bind(this);\n reload = reload.bind(this);\n\n initialize(\n context: RequireContext,\n navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>,\n linkingConfigOptions: LinkingConfigOptions = {}\n ) {\n // Clean up any previous state\n this.initialState = undefined;\n this.rootState = undefined;\n this.nextState = undefined;\n this.linking = undefined;\n this.navigationRefSubscription?.();\n this.rootStateSubscribers.clear();\n this.storeSubscribers.clear();\n\n this.routeNode = getRoutes(context, {\n ...Constants.expoConfig?.extra?.router,\n ignoreEntryPoints: true,\n platform: Platform.OS,\n });\n\n // We always needs routeInfo, even if there are no routes. This can happen if:\n // - there are no routes (we are showing the onboarding screen)\n // - getInitialURL() is async\n this.routeInfo = {\n unstable_globalHref: '',\n pathname: '',\n isIndex: false,\n params: {},\n segments: [],\n };\n\n if (this.routeNode) {\n // We have routes, so get the linking config and the root component\n this.linking = getLinkingConfig(this, this.routeNode, context, linkingConfigOptions);\n this.rootComponent = getQualifiedRouteComponent(this.routeNode);\n\n // By default React Navigation is async and does not render anything in the first pass as it waits for `getInitialURL`\n // This will cause static rendering to fail, which once performs a single pass.\n // If the initialURL is a string, we can preload the state and routeInfo, skipping React Navigation's async behavior.\n const initialURL = this.linking?.getInitialURL?.();\n if (typeof initialURL === 'string') {\n this.rootState = this.linking.getStateFromPath?.(initialURL, this.linking.config);\n this.initialState = this.rootState;\n if (this.rootState) {\n this.routeInfo = this.getRouteInfo(this.rootState);\n }\n }\n } else {\n // Only error in production, in development we will show the onboarding screen\n if (process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n // In development, we will show the onboarding screen\n this.rootComponent = Fragment;\n }\n\n /**\n * Counter intuitively - this fires AFTER both React Navigation's state changes and the subsequent paint.\n * This poses a couple of issues for Expo Router,\n * - Ensuring hooks (e.g. useSearchParams()) have data in the initial render\n * - Reacting to state changes after a navigation event\n *\n * This is why the initial render renders a Fragment and we wait until `onReady()` is called\n * Additionally, some hooks compare the state from both the store and the navigationRef. If the store it stale,\n * that hooks will manually update the store.\n *\n */\n this.navigationRef = navigationRef;\n this.navigationRefSubscription = navigationRef.addListener('state', (data) => {\n const state = data.data.state as ResultState;\n\n if (!this.hasAttemptedToHideSplash) {\n this.hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n this.splashScreenAnimationFrame = requestAnimationFrame(() => {\n SplashScreen._internal_maybeHideAsync?.();\n });\n }\n\n let shouldUpdateSubscribers = this.nextState === state;\n this.nextState = undefined;\n\n // This can sometimes be undefined when an error is thrown in the Root Layout Route.\n // Additionally that state may already equal the rootState if it was updated within a hook\n if (state && state !== this.rootState) {\n store.updateState(state, undefined);\n shouldUpdateSubscribers = true;\n }\n\n // If the state has changed, or was changed inside a hook we need to update the subscribers\n if (shouldUpdateSubscribers) {\n for (const subscriber of this.rootStateSubscribers) {\n subscriber();\n }\n }\n });\n\n for (const subscriber of this.storeSubscribers) {\n subscriber();\n }\n }\n\n updateState(state: ResultState, nextState = state) {\n store.rootState = state;\n store.nextState = nextState;\n\n const nextRouteInfo = store.getRouteInfo(state);\n\n if (!equal(this.routeInfo, nextRouteInfo)) {\n store.routeInfo = nextRouteInfo;\n }\n }\n\n getRouteInfo(state: ResultState) {\n return getRouteInfoFromState(\n (state: Parameters<typeof getPathFromState>[0], asPath: boolean) => {\n return getPathDataFromState(state, {\n screens: {},\n ...this.linking?.config,\n preserveDynamicRoutes: asPath,\n preserveGroups: asPath,\n shouldEncodeURISegment: false,\n });\n },\n state\n );\n }\n\n // This is only used in development, to show the onboarding screen\n // In production we should have errored during the initialization\n shouldShowTutorial() {\n return !this.routeNode && process.env.NODE_ENV === 'development';\n }\n\n /** Make sure these are arrow functions so `this` is correctly bound */\n subscribeToRootState = (subscriber: () => void) => {\n this.rootStateSubscribers.add(subscriber);\n return () => this.rootStateSubscribers.delete(subscriber);\n };\n subscribeToStore = (subscriber: () => void) => {\n this.storeSubscribers.add(subscriber);\n return () => this.storeSubscribers.delete(subscriber);\n };\n snapshot = () => {\n return this;\n };\n rootStateSnapshot = () => {\n return this.rootState!;\n };\n routeInfoSnapshot = () => {\n return this.routeInfo!;\n };\n\n cleanup() {\n if (this.splashScreenAnimationFrame) {\n cancelAnimationFrame(this.splashScreenAnimationFrame);\n }\n }\n}\n\nexport const store = new RouterStore();\n\nexport function useExpoRouter() {\n return useSyncExternalStore(store.subscribeToStore, store.snapshot, store.snapshot);\n}\n\nfunction syncStoreRootState() {\n if (store.navigationRef.isReady()) {\n const currentState = store.navigationRef.getRootState() as unknown as ResultState;\n\n if (store.rootState !== currentState) {\n store.updateState(currentState);\n }\n }\n}\n\nexport function useStoreRootState() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.rootStateSnapshot,\n store.rootStateSnapshot\n );\n}\n\nexport function useStoreRouteInfo() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.routeInfoSnapshot,\n store.routeInfoSnapshot\n );\n}\n\nexport function useInitializeExpoRouter(context: RequireContext, options: LinkingConfigOptions) {\n const navigationRef = useNavigationContainerRef();\n useMemo(() => store.initialize(context, navigationRef, options), [context]);\n useExpoRouter();\n return store;\n}\n"]}
|
|
@@ -5,6 +5,7 @@ export declare function navigate(this: RouterStore, url: Href, options?: Navigat
|
|
|
5
5
|
export declare function reload(this: RouterStore): void;
|
|
6
6
|
export declare function push(this: RouterStore, url: Href, options?: NavigationOptions): any;
|
|
7
7
|
export declare function dismiss(this: RouterStore, count?: number): void;
|
|
8
|
+
export declare function dismissTo(this: RouterStore, href: Href, options?: NavigationOptions): any;
|
|
8
9
|
export declare function replace(this: RouterStore, url: Href, options?: NavigationOptions): any;
|
|
9
10
|
export declare function dismissAll(this: RouterStore): void;
|
|
10
11
|
export declare function goBack(this: RouterStore): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d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AS,CACvB,IAAI,EAAE,WAAW,EACjB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAM,OAOnE;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,wBAAgB,MAAM,CACpB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,EAAE,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,GAAE,aAAkB,QA6C/D"}
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.linkTo = exports.setParams = exports.canDismiss = exports.canGoBack = exports.goBack = exports.dismissAll = exports.replace = exports.dismiss = exports.push = exports.reload = exports.navigate = void 0;
|
|
26
|
+
exports.linkTo = exports.setParams = exports.canDismiss = exports.canGoBack = exports.goBack = exports.dismissAll = exports.replace = exports.dismissTo = exports.dismiss = exports.push = exports.reload = exports.navigate = void 0;
|
|
27
27
|
const native_1 = require("@react-navigation/native");
|
|
28
28
|
const dom_1 = require("expo/dom");
|
|
29
29
|
const Linking = __importStar(require("expo-linking"));
|
|
@@ -58,6 +58,10 @@ function dismiss(count) {
|
|
|
58
58
|
this.navigationRef?.dispatch(native_1.StackActions.pop(count));
|
|
59
59
|
}
|
|
60
60
|
exports.dismiss = dismiss;
|
|
61
|
+
function dismissTo(href, options) {
|
|
62
|
+
return this.linkTo((0, href_1.resolveHref)(href), { ...options, event: 'POP_TO' });
|
|
63
|
+
}
|
|
64
|
+
exports.dismissTo = dismissTo;
|
|
61
65
|
function replace(url, options) {
|
|
62
66
|
return this.linkTo((0, href_1.resolveHref)(url), { ...options, event: 'REPLACE' });
|
|
63
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA4F;AAC5F,kCAAkC;AAClC,sDAAwC;AACxC,kDAA2C;AAC3C,+CAAwC;AAIxC,uCAA0E;AAC1E,iFAM2C;AAC3C,0CAA+C;AAE/C,sCAAoD;AAEpD,SAAS,aAAa,CAAC,KAAkB;IACvC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;KACH;AACH,CAAC;AAID,SAAgB,QAAQ,CAAoB,GAAS,EAAE,OAA2B;IAChF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAC1E,CAAC;AAFD,4BAEC;AAED,SAAgB,MAAM;IACpB,yCAAyC;IACzC,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;AACzF,CAAC;AAHD,wBAGC;AAED,SAAgB,IAAI,CAAoB,GAAS,EAAE,OAA2B;IAC5E,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AACtE,CAAC;AAFD,oBAEC;AAED,SAAgB,OAAO,CAAoB,KAAc;IACvD,IAAI,IAAA,0CAAc,EAAC,KAAK,CAAC,EAAE;QACzB,OAAO;KACR;IACD,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AACxD,CAAC;AALD,0BAKC;AAED,SAAgB,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,IAAI,eAAe,CAAC,IAAI,KAAK,OAAO,EAAE;YACpC,WAAW,CAAC,MAAM,CAAC,iBAAiB,GAAG,GAAG,WAAW,CAAC,IAAI,IAAI,IAAA,mBAAM,GAAE,EAAE,CAAC,CAAC,yJAAyJ;SACpO;KACF;IAED,IAAI,eAAe,CAAC,IAAI,KAAK,UAAU,EAAE;QACvC,IAAI,GAAG,SAAS,CAAC;KAClB;IAED,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,KAAK,IAAI,eAAe,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE;QAC/F,IAAI,GAAG,SAAS,CAAC;KAClB;IAED,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE;YAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;gBACzC,OAAO,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;aAC1F;SACF;QACD;;;;;;;;WAQG;QACH,WAAW,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,UAAU,CAAC;KAC1C;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,eAAe,CAAC,GAAG;QAC3B,OAAO,EAAE;YACP,wBAAwB;YACxB,IAAI,EAAE,WAAW,CAAC,MAAM;YACxB,MAAM,EAAE,WAAW,CAAC,MAAM;SAC3B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { StackActions, type NavigationState, PartialRoute } from '@react-navigation/native';\nimport { IS_DOM } from 'expo/dom';\nimport * as Linking from 'expo-linking';\nimport { nanoid } from 'nanoid/non-secure';\nimport { Platform } from 'react-native';\n\nimport { type RouterStore } from './router-store';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { resolveHref, resolveHrefStringWithSegments } from '../link/href';\nimport {\n emitDomDismiss,\n emitDomDismissAll,\n emitDomGoBack,\n emitDomLinkEvent,\n emitDomSetParams,\n} from '../link/useDomComponentNavigation';\nimport { matchDynamicName } from '../matchers';\nimport { Href } from '../types';\nimport { shouldLinkExternally } from '../utils/url';\n\nfunction assertIsReady(store: RouterStore) {\n if (!store.navigationRef.isReady()) {\n throw new Error(\n 'Attempted to navigate before mounting the Root Layout component. Ensure the Root Layout component is rendering a Slot, or other navigator on the first render.'\n );\n }\n}\n\nexport type NavigationOptions = Omit<LinkToOptions, 'event'>;\n\nexport function navigate(this: RouterStore, url: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(url), { ...options, event: 'NAVIGATE' });\n}\n\nexport function reload(this: RouterStore) {\n // TODO(EvanBacon): add `reload` support.\n throw new Error('The reload method is not implemented in the client-side router yet.');\n}\n\nexport function push(this: RouterStore, url: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(url), { ...options, event: 'PUSH' });\n}\n\nexport function dismiss(this: RouterStore, count?: number) {\n if (emitDomDismiss(count)) {\n return;\n }\n this.navigationRef?.dispatch(StackActions.pop(count));\n}\n\nexport function replace(this: RouterStore, url: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(url), { ...options, event: 'REPLACE' });\n}\n\nexport function dismissAll(this: RouterStore) {\n if (emitDomDismissAll()) {\n return;\n }\n this.navigationRef?.dispatch(StackActions.popToTop());\n}\n\nexport function goBack(this: RouterStore) {\n if (emitDomGoBack()) {\n return;\n }\n assertIsReady(this);\n this.navigationRef?.current?.goBack();\n}\n\nexport function canGoBack(this: RouterStore): boolean {\n if (IS_DOM) {\n throw new Error(\n 'canGoBack imperative method is not supported. Pass the property to the DOM component instead.'\n );\n }\n // Return a default value here if the navigation hasn't mounted yet.\n // This can happen if the user calls `canGoBack` from the Root Layout route\n // before mounting a navigator. This behavior exists due to React Navigation being dynamically\n // constructed at runtime. We can get rid of this in the future if we use\n // the static configuration internally.\n if (!this.navigationRef.isReady()) {\n return false;\n }\n return this.navigationRef?.current?.canGoBack() ?? false;\n}\n\nexport function canDismiss(this: RouterStore): boolean {\n if (IS_DOM) {\n throw new Error(\n 'canDismiss imperative method is not supported. Pass the property to the DOM component instead.'\n );\n }\n let state = this.rootState;\n\n // Keep traversing down the state tree until we find a stack navigator that we can pop\n while (state) {\n if (state.type === 'stack' && state.routes.length > 1) {\n return true;\n }\n if (state.index === undefined) return false;\n\n state = state.routes?.[state.index]?.state as any;\n }\n\n return false;\n}\n\nexport function setParams(\n this: RouterStore,\n params: Record<string, string | number | (string | number)[]> = {}\n) {\n if (emitDomSetParams(params)) {\n return;\n }\n assertIsReady(this);\n return (this.navigationRef?.current?.setParams as any)(params);\n}\n\nexport type LinkToOptions = {\n event?: string;\n\n /**\n * Relative URL references are either relative to the directory or the document. By default, relative paths are relative to the document.\n * @see: [MDN's documentation on Resolving relative references to a URL](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references).\n */\n relativeToDirectory?: boolean;\n\n /**\n *\n */\n withAnchor?: boolean;\n};\n\nexport function linkTo(\n this: RouterStore,\n href: string,\n { event, relativeToDirectory, withAnchor }: LinkToOptions = {}\n) {\n if (emitDomLinkEvent(href, { event, relativeToDirectory, withAnchor })) {\n return;\n }\n\n if (shouldLinkExternally(href)) {\n if (href.startsWith('//') && Platform.OS !== 'web') {\n href = `https:${href}`;\n }\n\n Linking.openURL(href);\n return;\n }\n\n assertIsReady(this);\n const navigationRef = this.navigationRef.current;\n\n if (navigationRef == null) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n if (!this.linking) {\n throw new Error('Attempted to link to route when no routes are present');\n }\n\n if (href === '..' || href === '../') {\n navigationRef.goBack();\n return;\n }\n\n const rootState = navigationRef.getRootState();\n\n href = resolveHrefStringWithSegments(href, this.routeInfo, relativeToDirectory);\n\n const state = this.linking.getStateFromPath!(href, this.linking.config);\n\n if (!state || state.routes.length === 0) {\n console.error('Could not generate a valid navigation state for the given path: ' + href);\n return;\n }\n\n return navigationRef.dispatch(getNavigateAction(state, rootState, event, withAnchor));\n}\n\nfunction getNavigateAction(\n actionState: ResultState,\n navigationState: NavigationState,\n type = 'NAVIGATE',\n withAnchor?: boolean\n) {\n /**\n * We need to find the deepest navigator where the action and current state diverge, If they do not diverge, the\n * lowest navigator is the target.\n *\n * By default React Navigation will target the current navigator, but this doesn't work for all actions\n * For example:\n * - /deeply/nested/route -> /top-level-route the target needs to be the top-level navigator\n * - /stack/nestedStack/page -> /stack1/nestedStack/other-page needs to target the nestedStack navigator\n *\n * This matching needs to done by comparing the route names and the dynamic path, for example\n * - /1/page -> /2/anotherPage needs to target the /[id] navigator\n *\n * Other parameters such as search params and hash are not evaluated.\n */\n let actionStateRoute: PartialRoute<any> | undefined;\n\n // Traverse the state tree comparing the current state and the action state until we find where they diverge\n while (actionState && navigationState) {\n const stateRoute = navigationState.routes[navigationState.index];\n\n actionStateRoute = actionState.routes[actionState.routes.length - 1];\n\n const childState = actionStateRoute.state;\n const nextNavigationState = stateRoute.state;\n\n const dynamicName = matchDynamicName(actionStateRoute.name);\n\n const didActionAndCurrentStateDiverge =\n actionStateRoute.name !== stateRoute.name ||\n !childState ||\n !nextNavigationState ||\n (dynamicName && actionStateRoute.params?.[dynamicName] !== stateRoute.params?.[dynamicName]);\n\n if (didActionAndCurrentStateDiverge) {\n break;\n }\n\n actionState = childState;\n navigationState = nextNavigationState as NavigationState;\n }\n\n /*\n * We found the target navigator, but the payload is in the incorrect format\n * We need to convert the action state to a payload that can be dispatched\n */\n const rootPayload: Record<string, any> = { params: {} };\n let payload = rootPayload;\n let params = payload.params;\n\n // The root level of payload is a bit weird, its params are in the child object\n while (actionStateRoute) {\n Object.assign(params, { ...payload.params, ...actionStateRoute.params });\n // Assign the screen name to the payload\n payload.screen = actionStateRoute.name;\n // Merge the params, ensuring that we create a new object\n payload.params = { ...params };\n // Params don't include the screen, thats a separate attribute\n delete payload.params['screen'];\n\n // Continue down the payload tree\n // Initially these values are separate, but React Nav merges them after the first layer\n payload = payload.params;\n params = payload;\n\n actionStateRoute = actionStateRoute.state?.routes[actionStateRoute.state?.routes.length - 1];\n }\n\n // Expo Router uses only three actions, but these don't directly translate to all navigator actions\n if (type === 'PUSH') {\n // Only stack navigators have a push action, and even then we want to use NAVIGATE (see below)\n type = 'NAVIGATE';\n\n /*\n * The StackAction.PUSH does not work correctly with Expo Router.\n *\n * Expo Router provides a getId() function for every route, altering how React Navigation handles stack routing.\n * Ordinarily, PUSH always adds a new screen to the stack. However, with getId() present, it navigates to the screen with the matching ID instead (by moving the screen to the top of the stack)\n * When you try and push to a screen with the same ID, no navigation will occur\n * Refer to: https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/routers/src/StackRouter.tsx#L279-L290\n *\n * Expo Router needs to retain the default behavior of PUSH, consistently adding new screens to the stack, even if their IDs are identical.\n *\n * To resolve this issue, we switch to using a NAVIGATE action with a new key. In the navigate action, screens are matched by either key or getId() function.\n * By generating a unique new key, we ensure that the screen is always pushed onto the stack.\n *\n */\n if (navigationState.type === 'stack') {\n rootPayload.params.__EXPO_ROUTER_key = `${rootPayload.name}-${nanoid()}`; // @see https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/routers/src/StackRouter.tsx#L406-L407\n }\n }\n\n if (navigationState.type === 'expo-tab') {\n type = 'JUMP_TO';\n }\n\n if (type === 'REPLACE' && (navigationState.type === 'tab' || navigationState.type === 'drawer')) {\n type = 'JUMP_TO';\n }\n\n if (withAnchor !== undefined) {\n if (rootPayload.params.initial) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`The parameter 'initial' is a reserved parameter name in React Navigation`);\n }\n }\n /*\n * The logic for initial can seen backwards depending on your perspective\n * True: The initialRouteName is not loaded. The incoming screen is the initial screen (default)\n * False: The initialRouteName is loaded. THe incoming screen is placed after the initialRouteName\n *\n * withAnchor flips the perspective.\n * True: You want the initialRouteName to load.\n * False: You do not want the initialRouteName to load.\n */\n rootPayload.params.initial = !withAnchor;\n }\n\n return {\n type,\n target: navigationState.key,\n payload: {\n // key: rootPayload.key,\n name: rootPayload.screen,\n params: rootPayload.params,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA4F;AAC5F,kCAAkC;AAClC,sDAAwC;AACxC,kDAA2C;AAC3C,+CAAwC;AAIxC,uCAA0E;AAC1E,iFAM2C;AAC3C,0CAA+C;AAE/C,sCAAoD;AAEpD,SAAS,aAAa,CAAC,KAAkB;IACvC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;KACH;AACH,CAAC;AAID,SAAgB,QAAQ,CAAoB,GAAS,EAAE,OAA2B;IAChF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAC1E,CAAC;AAFD,4BAEC;AAED,SAAgB,MAAM;IACpB,yCAAyC;IACzC,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;AACzF,CAAC;AAHD,wBAGC;AAED,SAAgB,IAAI,CAAoB,GAAS,EAAE,OAA2B;IAC5E,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AACtE,CAAC;AAFD,oBAEC;AAED,SAAgB,OAAO,CAAoB,KAAc;IACvD,IAAI,IAAA,0CAAc,EAAC,KAAK,CAAC,EAAE;QACzB,OAAO;KACR;IACD,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,qBAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AACxD,CAAC;AALD,0BAKC;AAED,SAAgB,SAAS,CAAoB,IAAU,EAAE,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AAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;KAC9F;IAED,mGAAmG;IACnG,IAAI,IAAI,KAAK,MAAM,EAAE;QACnB,8FAA8F;QAC9F,IAAI,GAAG,UAAU,CAAC;QAElB;;;;;;;;;;;;;WAaG;QACH,IAAI,eAAe,CAAC,IAAI,KAAK,OAAO,EAAE;YACpC,WAAW,CAAC,MAAM,CAAC,iBAAiB,GAAG,GAAG,WAAW,CAAC,IAAI,IAAI,IAAA,mBAAM,GAAE,EAAE,CAAC,CAAC,yJAAyJ;SACpO;KACF;IAED,IAAI,eAAe,CAAC,IAAI,KAAK,UAAU,EAAE;QACvC,IAAI,GAAG,SAAS,CAAC;KAClB;IAED,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,KAAK,IAAI,eAAe,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE;QAC/F,IAAI,GAAG,SAAS,CAAC;KAClB;IAED,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE;YAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;gBACzC,OAAO,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;aAC1F;SACF;QACD;;;;;;;;WAQG;QACH,WAAW,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,UAAU,CAAC;KAC1C;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,eAAe,CAAC,GAAG;QAC3B,OAAO,EAAE;YACP,wBAAwB;YACxB,IAAI,EAAE,WAAW,CAAC,MAAM;YACxB,MAAM,EAAE,WAAW,CAAC,MAAM;SAC3B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { StackActions, type NavigationState, PartialRoute } from '@react-navigation/native';\nimport { IS_DOM } from 'expo/dom';\nimport * as Linking from 'expo-linking';\nimport { nanoid } from 'nanoid/non-secure';\nimport { Platform } from 'react-native';\n\nimport { type RouterStore } from './router-store';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { resolveHref, resolveHrefStringWithSegments } from '../link/href';\nimport {\n emitDomDismiss,\n emitDomDismissAll,\n emitDomGoBack,\n emitDomLinkEvent,\n emitDomSetParams,\n} from '../link/useDomComponentNavigation';\nimport { matchDynamicName } from '../matchers';\nimport { Href } from '../types';\nimport { shouldLinkExternally } from '../utils/url';\n\nfunction assertIsReady(store: RouterStore) {\n if (!store.navigationRef.isReady()) {\n throw new Error(\n 'Attempted to navigate before mounting the Root Layout component. Ensure the Root Layout component is rendering a Slot, or other navigator on the first render.'\n );\n }\n}\n\nexport type NavigationOptions = Omit<LinkToOptions, 'event'>;\n\nexport function navigate(this: RouterStore, url: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(url), { ...options, event: 'NAVIGATE' });\n}\n\nexport function reload(this: RouterStore) {\n // TODO(EvanBacon): add `reload` support.\n throw new Error('The reload method is not implemented in the client-side router yet.');\n}\n\nexport function push(this: RouterStore, url: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(url), { ...options, event: 'PUSH' });\n}\n\nexport function dismiss(this: RouterStore, count?: number) {\n if (emitDomDismiss(count)) {\n return;\n }\n this.navigationRef?.dispatch(StackActions.pop(count));\n}\n\nexport function dismissTo(this: RouterStore, href: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(href), { ...options, event: 'POP_TO' });\n}\n\nexport function replace(this: RouterStore, url: Href, options?: NavigationOptions) {\n return this.linkTo(resolveHref(url), { ...options, event: 'REPLACE' });\n}\n\nexport function dismissAll(this: RouterStore) {\n if (emitDomDismissAll()) {\n return;\n }\n this.navigationRef?.dispatch(StackActions.popToTop());\n}\n\nexport function goBack(this: RouterStore) {\n if (emitDomGoBack()) {\n return;\n }\n assertIsReady(this);\n this.navigationRef?.current?.goBack();\n}\n\nexport function canGoBack(this: RouterStore): boolean {\n if (IS_DOM) {\n throw new Error(\n 'canGoBack imperative method is not supported. Pass the property to the DOM component instead.'\n );\n }\n // Return a default value here if the navigation hasn't mounted yet.\n // This can happen if the user calls `canGoBack` from the Root Layout route\n // before mounting a navigator. This behavior exists due to React Navigation being dynamically\n // constructed at runtime. We can get rid of this in the future if we use\n // the static configuration internally.\n if (!this.navigationRef.isReady()) {\n return false;\n }\n return this.navigationRef?.current?.canGoBack() ?? false;\n}\n\nexport function canDismiss(this: RouterStore): boolean {\n if (IS_DOM) {\n throw new Error(\n 'canDismiss imperative method is not supported. Pass the property to the DOM component instead.'\n );\n }\n let state = this.rootState;\n\n // Keep traversing down the state tree until we find a stack navigator that we can pop\n while (state) {\n if (state.type === 'stack' && state.routes.length > 1) {\n return true;\n }\n if (state.index === undefined) return false;\n\n state = state.routes?.[state.index]?.state as any;\n }\n\n return false;\n}\n\nexport function setParams(\n this: RouterStore,\n params: Record<string, string | number | (string | number)[]> = {}\n) {\n if (emitDomSetParams(params)) {\n return;\n }\n assertIsReady(this);\n return (this.navigationRef?.current?.setParams as any)(params);\n}\n\nexport type LinkToOptions = {\n event?: string;\n\n /**\n * Relative URL references are either relative to the directory or the document. By default, relative paths are relative to the document.\n * @see: [MDN's documentation on Resolving relative references to a URL](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references).\n */\n relativeToDirectory?: boolean;\n\n /**\n *\n */\n withAnchor?: boolean;\n};\n\nexport function linkTo(\n this: RouterStore,\n href: string,\n { event, relativeToDirectory, withAnchor }: LinkToOptions = {}\n) {\n if (emitDomLinkEvent(href, { event, relativeToDirectory, withAnchor })) {\n return;\n }\n\n if (shouldLinkExternally(href)) {\n if (href.startsWith('//') && Platform.OS !== 'web') {\n href = `https:${href}`;\n }\n\n Linking.openURL(href);\n return;\n }\n\n assertIsReady(this);\n const navigationRef = this.navigationRef.current;\n\n if (navigationRef == null) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n if (!this.linking) {\n throw new Error('Attempted to link to route when no routes are present');\n }\n\n if (href === '..' || href === '../') {\n navigationRef.goBack();\n return;\n }\n\n const rootState = navigationRef.getRootState();\n\n href = resolveHrefStringWithSegments(href, this.routeInfo, relativeToDirectory);\n\n const state = this.linking.getStateFromPath!(href, this.linking.config);\n\n if (!state || state.routes.length === 0) {\n console.error('Could not generate a valid navigation state for the given path: ' + href);\n return;\n }\n\n return navigationRef.dispatch(getNavigateAction(state, rootState, event, withAnchor));\n}\n\nfunction getNavigateAction(\n actionState: ResultState,\n navigationState: NavigationState,\n type = 'NAVIGATE',\n withAnchor?: boolean\n) {\n /**\n * We need to find the deepest navigator where the action and current state diverge, If they do not diverge, the\n * lowest navigator is the target.\n *\n * By default React Navigation will target the current navigator, but this doesn't work for all actions\n * For example:\n * - /deeply/nested/route -> /top-level-route the target needs to be the top-level navigator\n * - /stack/nestedStack/page -> /stack1/nestedStack/other-page needs to target the nestedStack navigator\n *\n * This matching needs to done by comparing the route names and the dynamic path, for example\n * - /1/page -> /2/anotherPage needs to target the /[id] navigator\n *\n * Other parameters such as search params and hash are not evaluated.\n */\n let actionStateRoute: PartialRoute<any> | undefined;\n\n // Traverse the state tree comparing the current state and the action state until we find where they diverge\n while (actionState && navigationState) {\n const stateRoute = navigationState.routes[navigationState.index];\n\n actionStateRoute = actionState.routes[actionState.routes.length - 1];\n\n const childState = actionStateRoute.state;\n const nextNavigationState = stateRoute.state;\n\n const dynamicName = matchDynamicName(actionStateRoute.name);\n\n const didActionAndCurrentStateDiverge =\n actionStateRoute.name !== stateRoute.name ||\n !childState ||\n !nextNavigationState ||\n (dynamicName && actionStateRoute.params?.[dynamicName] !== stateRoute.params?.[dynamicName]);\n\n if (didActionAndCurrentStateDiverge) {\n break;\n }\n\n actionState = childState;\n navigationState = nextNavigationState as NavigationState;\n }\n\n /*\n * We found the target navigator, but the payload is in the incorrect format\n * We need to convert the action state to a payload that can be dispatched\n */\n const rootPayload: Record<string, any> = { params: {} };\n let payload = rootPayload;\n let params = payload.params;\n\n // The root level of payload is a bit weird, its params are in the child object\n while (actionStateRoute) {\n Object.assign(params, { ...payload.params, ...actionStateRoute.params });\n // Assign the screen name to the payload\n payload.screen = actionStateRoute.name;\n // Merge the params, ensuring that we create a new object\n payload.params = { ...params };\n // Params don't include the screen, thats a separate attribute\n delete payload.params['screen'];\n\n // Continue down the payload tree\n // Initially these values are separate, but React Nav merges them after the first layer\n payload = payload.params;\n params = payload;\n\n actionStateRoute = actionStateRoute.state?.routes[actionStateRoute.state?.routes.length - 1];\n }\n\n // Expo Router uses only three actions, but these don't directly translate to all navigator actions\n if (type === 'PUSH') {\n // Only stack navigators have a push action, and even then we want to use NAVIGATE (see below)\n type = 'NAVIGATE';\n\n /*\n * The StackAction.PUSH does not work correctly with Expo Router.\n *\n * Expo Router provides a getId() function for every route, altering how React Navigation handles stack routing.\n * Ordinarily, PUSH always adds a new screen to the stack. However, with getId() present, it navigates to the screen with the matching ID instead (by moving the screen to the top of the stack)\n * When you try and push to a screen with the same ID, no navigation will occur\n * Refer to: https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/routers/src/StackRouter.tsx#L279-L290\n *\n * Expo Router needs to retain the default behavior of PUSH, consistently adding new screens to the stack, even if their IDs are identical.\n *\n * To resolve this issue, we switch to using a NAVIGATE action with a new key. In the navigate action, screens are matched by either key or getId() function.\n * By generating a unique new key, we ensure that the screen is always pushed onto the stack.\n *\n */\n if (navigationState.type === 'stack') {\n rootPayload.params.__EXPO_ROUTER_key = `${rootPayload.name}-${nanoid()}`; // @see https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/routers/src/StackRouter.tsx#L406-L407\n }\n }\n\n if (navigationState.type === 'expo-tab') {\n type = 'JUMP_TO';\n }\n\n if (type === 'REPLACE' && (navigationState.type === 'tab' || navigationState.type === 'drawer')) {\n type = 'JUMP_TO';\n }\n\n if (withAnchor !== undefined) {\n if (rootPayload.params.initial) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`The parameter 'initial' is a reserved parameter name in React Navigation`);\n }\n }\n /*\n * The logic for initial can seen backwards depending on your perspective\n * True: The initialRouteName is not loaded. The incoming screen is the initial screen (default)\n * False: The initialRouteName is loaded. THe incoming screen is placed after the initialRouteName\n *\n * withAnchor flips the perspective.\n * True: You want the initialRouteName to load.\n * False: You do not want the initialRouteName to load.\n */\n rootPayload.params.initial = !withAnchor;\n }\n\n return {\n type,\n target: navigationState.key,\n payload: {\n // key: rootPayload.key,\n name: rootPayload.screen,\n params: rootPayload.params,\n },\n };\n}\n"]}
|
package/build/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,QAErC;AAED,wBAAgB,YAAY,2CAE3B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,kGAEhC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,sGAExC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,QAErC;AAED,wBAAgB,YAAY,2CAE3B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,kGAEhC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,sGAExC;AAED;;;;;;;;;;;;;;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store.push,
|
|
71
71
|
dismiss: router_store_1.store.dismiss,
|
|
72
72
|
dismissAll: router_store_1.store.dismissAll,
|
|
73
|
+
dismissTo: router_store_1.store.dismissTo,
|
|
73
74
|
canDismiss: router_store_1.store.canDismiss,
|
|
74
75
|
back: router_store_1.store.goBack,
|
|
75
76
|
replace: router_store_1.store.replace,
|
package/build/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAEb,kDAA0B;AAE1B,mCAAkD;AAClD,8DAA0F;AAI1F;;;;;;;;;;;;;;GAcG;AACH,SAAgB,sBAAsB;IACpC,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,wDAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,oBAAK,CAAC,aAAa,CAAC,OAAO,CAAC;AACrC,CAAC;AAFD,8CAEC;AAED;;;GAGG;AACH,SAAgB,yBAAyB;IACvC,OAAO,oBAAK,CAAC,aAAa,CAAC;AAC7B,CAAC;AAFD,8DAEC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,SAAS;IACvB,OAAO,eAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,IAAI,EAAE,oBAAK,CAAC,IAAI;QAChB,OAAO,EAAE,oBAAK,CAAC,OAAO;QACtB,UAAU,EAAE,oBAAK,CAAC,UAAU;QAC5B,UAAU,EAAE,oBAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,oBAAK,CAAC,MAAM;QAClB,OAAO,EAAE,oBAAK,CAAC,OAAO;QACtB,SAAS,EAAE,oBAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,oBAAK,CAAC,SAAS;QAC1B,QAAQ,EA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CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;CACF","sourcesContent":["'use client';\n\nimport React from 'react';\n\nimport { LocalRouteParamsContext } from './Route';\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { Router } from './imperative-api';\nimport { RouteParams, RouteSegments, UnknownOutputParams, Route } from './types';\n\n/**\n * Returns the [navigation state](https://reactnavigation.org/docs/navigation-state/)\n * of the navigator which contains the current screen.\n *\n * @example\n * ```tsx\n * import { useRootNavigationState } from 'expo-router';\n *\n * export default function Route() {\n * const { routes } = useRootNavigationState();\n *\n * return <Text>{routes[0].name}</Text>;\n * }\n * ```\n */\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/**\n * @deprecated Use [`useNavigationContainerRef`](#usenavigationcontainerref) instead,\n * which returns a React `ref`.\n */\nexport function useRootNavigation() {\n return store.navigationRef.current;\n}\n\n/**\n * @return The root `<NavigationContainer />` ref for the app. The `ref.current` may be `null`\n * if the `<NavigationContainer />` hasn't mounted yet.\n */\nexport function useNavigationContainerRef() {\n return store.navigationRef;\n}\n\n/**\n *\n * Returns the [Router](#router) object for imperative navigation.\n *\n * @example\n *```tsx\n * import { useRouter } from 'expo-router';\n * import { Text } from 'react-native';\n *\n * export default function Route() {\n * const router = useRouter();\n *\n * return (\n * <Text onPress={() => router.push('/home')}>Go Home</Text>\n * );\n *}\n * ```\n */\nexport function useRouter(): Router {\n return React.useMemo(\n () => ({\n push: store.push,\n dismiss: store.dismiss,\n dismissAll: store.dismissAll,\n canDismiss: store.canDismiss,\n back: store.goBack,\n replace: store.replace,\n setParams: store.setParams,\n canGoBack: store.canGoBack,\n navigate: store.navigate,\n reload: store.reload,\n }),\n []\n );\n}\n\n/**\n * @private\n * @returns The current global pathname with query params attached. This may change in the future to include the hostname\n * from a predefined universal link. For example, `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`.\n */\nexport function useUnstableGlobalHref(): string {\n return useStoreRouteInfo().unstable_globalHref;\n}\n\n/**\n * Returns a list of selected file segments for the currently selected route. Segments are not normalized,\n * so they will be the same as the file path. For example, `/[id]?id=normal` becomes `[\"[id]\"]`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n *\n *\n * `useSegments` can be typed using an abstract. Consider the following file structure:\n *\n * ```md\n * - app\n * - [user]\n * - index.tsx\n * - followers.tsx\n * - settings.tsx\n * ```\n *\n *\n * This can be strictly typed using the following abstract with `useSegments` hook:\n *\n * ```tsx\n * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()\n * ```\n */\nexport function useSegments<TSegments extends Route = Route>(): RouteSegments<TSegments>;\nexport function useSegments<TSegments extends RouteSegments<Route>>(): TSegments;\nexport function useSegments() {\n return useStoreRouteInfo().segments;\n}\n\n/**\n * Returns the currently selected route location without search parameters. For example, `/acme?foo=bar` returns `/acme`.\n * Segments will be normalized. For example, `/[id]?id=normal` becomes `/normal`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * Returns URL parameters for globally selected route, including dynamic path segments.\n * This function updates even when the route is not focused. Useful for analytics or\n * other background operations that don't draw to the screen.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * When querying search params in a stack, opt-towards using\n * [`useLocalSearchParams`](#uselocalsearchparams) because it will only update when the route is focused.\n *\n * > **Note:** For usage information, see\n * [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useGlobalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useGlobalSearchParams();\n *\n * return <Text>User: {user}</Text>;\n * }\n * ```\n */\nexport function useGlobalSearchParams<\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): TParams;\nexport function useGlobalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;\nexport function useGlobalSearchParams<\n TRoute extends Route,\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): RouteParams<TRoute> & TParams;\nexport function useGlobalSearchParams() {\n return useStoreRouteInfo().params;\n}\n\n/**\n * Returns the URL parameters for the contextually focused route. Useful for stacks where you may push a new screen\n * that changes the query parameters. For dynamic routes, both the route parameters and the search parameters are returned.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * To observe updates even when the invoking route is not focused, use [`useGlobalSearchParams`](#useglobalsearchparams).\n *\n * > **Note:** For usage information, see\n * [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useLocalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useLocalSearchParams();\n *\n * return <Text>User: {user}</Text>;\n * }\n */\nexport function useLocalSearchParams<\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): TParams;\nexport function useLocalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;\nexport function useLocalSearchParams<\n TRoute extends Route,\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): RouteParams<TRoute> & TParams;\nexport function useLocalSearchParams() {\n const params = React.useContext(LocalRouteParamsContext) ?? {};\n return Object.fromEntries(\n Object.entries(params).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [\n key,\n value.map((v) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n }),\n ];\n } else {\n try {\n return [key, decodeURIComponent(value as string)];\n } catch {\n return [key, value];\n }\n }\n })\n ) as any;\n}\n\nexport function useSearchParams({ global = false } = {}): URLSearchParams {\n const globalRef = React.useRef(global);\n if (process.env.NODE_ENV !== 'production') {\n if (global !== globalRef.current) {\n console.warn(\n `Detected change in 'global' option of useSearchParams. This value cannot change between renders`\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const params = global ? useGlobalSearchParams() : useLocalSearchParams();\n const entries = Object.entries(params).flatMap(([key, value]) => {\n if (global) {\n if (key === 'params') return [];\n if (key === 'screen') return [];\n }\n\n return Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]];\n });\n\n return new ReadOnlyURLSearchParams(entries);\n}\n\nclass ReadOnlyURLSearchParams extends URLSearchParams {\n set() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n append() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n delete() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAEb,kDAA0B;AAE1B,mCAAkD;AAClD,8DAA0F;AAI1F;;;;;;;;;;;;;;GAcG;AACH,SAAgB,sBAAsB;IACpC,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,wDAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,oBAAK,CAAC,aAAa,CAAC,OAAO,CAAC;AACrC,CAAC;AAFD,8CAEC;AAED;;;GAGG;AACH,SAAgB,yBAAyB;IACvC,OAAO,oBAAK,CAAC,aAAa,CAAC;AAC7B,CAAC;AAFD,8DAEC;AAED;;;;;;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C,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAtBD,0CAsBC;AAED,MAAM,uBAAwB,SAAQ,eAAe;IACnD,GAAG;QACD,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;CACF","sourcesContent":["'use client';\n\nimport React from 'react';\n\nimport { LocalRouteParamsContext } from './Route';\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { Router } from './imperative-api';\nimport { RouteParams, RouteSegments, UnknownOutputParams, Route } from './types';\n\n/**\n * Returns the [navigation state](https://reactnavigation.org/docs/navigation-state/)\n * of the navigator which contains the current screen.\n *\n * @example\n * ```tsx\n * import { useRootNavigationState } from 'expo-router';\n *\n * export default function Route() {\n * const { routes } = useRootNavigationState();\n *\n * return <Text>{routes[0].name}</Text>;\n * }\n * ```\n */\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/**\n * @deprecated Use [`useNavigationContainerRef`](#usenavigationcontainerref) instead,\n * which returns a React `ref`.\n */\nexport function useRootNavigation() {\n return store.navigationRef.current;\n}\n\n/**\n * @return The root `<NavigationContainer />` ref for the app. The `ref.current` may be `null`\n * if the `<NavigationContainer />` hasn't mounted yet.\n */\nexport function useNavigationContainerRef() {\n return store.navigationRef;\n}\n\n/**\n *\n * Returns the [Router](#router) object for imperative navigation.\n *\n * @example\n *```tsx\n * import { useRouter } from 'expo-router';\n * import { Text } from 'react-native';\n *\n * export default function Route() {\n * const router = useRouter();\n *\n * return (\n * <Text onPress={() => router.push('/home')}>Go Home</Text>\n * );\n *}\n * ```\n */\nexport function useRouter(): Router {\n return React.useMemo(\n () => ({\n push: store.push,\n dismiss: store.dismiss,\n dismissAll: store.dismissAll,\n dismissTo: store.dismissTo,\n canDismiss: store.canDismiss,\n back: store.goBack,\n replace: store.replace,\n setParams: store.setParams,\n canGoBack: store.canGoBack,\n navigate: store.navigate,\n reload: store.reload,\n }),\n []\n );\n}\n\n/**\n * @private\n * @returns The current global pathname with query params attached. This may change in the future to include the hostname\n * from a predefined universal link. For example, `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`.\n */\nexport function useUnstableGlobalHref(): string {\n return useStoreRouteInfo().unstable_globalHref;\n}\n\n/**\n * Returns a list of selected file segments for the currently selected route. Segments are not normalized,\n * so they will be the same as the file path. For example, `/[id]?id=normal` becomes `[\"[id]\"]`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n *\n *\n * `useSegments` can be typed using an abstract. Consider the following file structure:\n *\n * ```md\n * - app\n * - [user]\n * - index.tsx\n * - followers.tsx\n * - settings.tsx\n * ```\n *\n *\n * This can be strictly typed using the following abstract with `useSegments` hook:\n *\n * ```tsx\n * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()\n * ```\n */\nexport function useSegments<TSegments extends Route = Route>(): RouteSegments<TSegments>;\nexport function useSegments<TSegments extends RouteSegments<Route>>(): TSegments;\nexport function useSegments() {\n return useStoreRouteInfo().segments;\n}\n\n/**\n * Returns the currently selected route location without search parameters. For example, `/acme?foo=bar` returns `/acme`.\n * Segments will be normalized. For example, `/[id]?id=normal` becomes `/normal`.\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useSegments } from 'expo-router';\n *\n * export default function Route() {\n * // segments = [\"profile\", \"[user]\"]\n * const segments = useSegments();\n *\n * return <Text>Hello</Text>;\n * }\n * ```\n */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * Returns URL parameters for globally selected route, including dynamic path segments.\n * This function updates even when the route is not focused. Useful for analytics or\n * other background operations that don't draw to the screen.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * When querying search params in a stack, opt-towards using\n * [`useLocalSearchParams`](#uselocalsearchparams) because it will only update when the route is focused.\n *\n * > **Note:** For usage information, see\n * [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useGlobalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useGlobalSearchParams();\n *\n * return <Text>User: {user}</Text>;\n * }\n * ```\n */\nexport function useGlobalSearchParams<\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): TParams;\nexport function useGlobalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;\nexport function useGlobalSearchParams<\n TRoute extends Route,\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): RouteParams<TRoute> & TParams;\nexport function useGlobalSearchParams() {\n return useStoreRouteInfo().params;\n}\n\n/**\n * Returns the URL parameters for the contextually focused route. Useful for stacks where you may push a new screen\n * that changes the query parameters. For dynamic routes, both the route parameters and the search parameters are returned.\n *\n * Route URL example: `acme://profile/baconbrix?extra=info`.\n *\n * To observe updates even when the invoking route is not focused, use [`useGlobalSearchParams`](#useglobalsearchparams).\n *\n * > **Note:** For usage information, see\n * [Local versus global search parameters](/router/reference/url-parameters/#local-versus-global-url-parameters).\n *\n * @example\n * ```tsx app/profile/[user].tsx\n * import { Text } from 'react-native';\n * import { useLocalSearchParams } from 'expo-router';\n *\n * export default function Route() {\n * // user=baconbrix & extra=info\n * const { user, extra } = useLocalSearchParams();\n *\n * return <Text>User: {user}</Text>;\n * }\n */\nexport function useLocalSearchParams<\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): TParams;\nexport function useLocalSearchParams<TRoute extends Route>(): RouteParams<TRoute>;\nexport function useLocalSearchParams<\n TRoute extends Route,\n TParams extends UnknownOutputParams = UnknownOutputParams,\n>(): RouteParams<TRoute> & TParams;\nexport function useLocalSearchParams() {\n const params = React.useContext(LocalRouteParamsContext) ?? {};\n return Object.fromEntries(\n Object.entries(params).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [\n key,\n value.map((v) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n }),\n ];\n } else {\n try {\n return [key, decodeURIComponent(value as string)];\n } catch {\n return [key, value];\n }\n }\n })\n ) as any;\n}\n\nexport function useSearchParams({ global = false } = {}): URLSearchParams {\n const globalRef = React.useRef(global);\n if (process.env.NODE_ENV !== 'production') {\n if (global !== globalRef.current) {\n console.warn(\n `Detected change in 'global' option of useSearchParams. This value cannot change between renders`\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const params = global ? useGlobalSearchParams() : useLocalSearchParams();\n const entries = Object.entries(params).flatMap(([key, value]) => {\n if (global) {\n if (key === 'params') return [];\n if (key === 'screen') return [];\n }\n\n return Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]];\n });\n\n return new ReadOnlyURLSearchParams(entries);\n}\n\nclass ReadOnlyURLSearchParams extends URLSearchParams {\n set() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n append() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n delete() {\n throw new Error('The URLSearchParams object return from useSearchParams is read-only');\n }\n}\n"]}
|
|
@@ -47,6 +47,10 @@ export type Router = {
|
|
|
47
47
|
* If the current screen is the only route, it will dismiss the entire stack.
|
|
48
48
|
*/
|
|
49
49
|
dismiss: (count?: number) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Dismisses screens until the provided href is reached. If the href is not found, it will instead replace the current screen with the provided href.
|
|
52
|
+
*/
|
|
53
|
+
dismissTo: (href: Href, options?: NavigationOptions) => void;
|
|
50
54
|
/**
|
|
51
55
|
* Returns to the first screen in the closest stack. This is similar to
|
|
52
56
|
* [popToTop](https://reactnavigation.org/docs/stack-actions/#poptotop) stack action.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative-api.d.ts","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;OAEG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB;;OAEG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACxD;;OAEG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC5D;;;;;;SAMK;IACL,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC3D;;;;OAIG;IACH,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;;;OAIG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,CAAC,CAAC,SAAS,KAAK,EAA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O,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3E;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,MAYpB,CAAC"}
|
package/build/imperative-api.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.router = {
|
|
|
10
10
|
push: (href, options) => router_store_1.store.push(href, options),
|
|
11
11
|
dismiss: (count) => router_store_1.store.dismiss(count),
|
|
12
12
|
dismissAll: () => router_store_1.store.dismissAll(),
|
|
13
|
+
dismissTo: (href, options) => router_store_1.store.dismissTo(href, options),
|
|
13
14
|
canDismiss: () => router_store_1.store.canDismiss(),
|
|
14
15
|
replace: (href, options) => router_store_1.store.replace(href, options),
|
|
15
16
|
back: () => router_store_1.store.goBack(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative-api.js","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;
|
|
1
|
+
{"version":3,"file":"imperative-api.js","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;AA6EpD;;GAEG;AACU,QAAA,MAAM,GAAW;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAC1D,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;IAClD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IACxC,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,UAAU,EAAE;IACpC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC;IAC5D,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,UAAU,EAAE;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;IACxD,IAAI,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,MAAM,EAAE;IAC1B,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,SAAS,EAAE;IAClC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAK,CAAC,SAAS,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,MAAM,EAAE;CAC7B,CAAC","sourcesContent":["import { store } from './global-state/router-store';\nimport { NavigationOptions } from './global-state/routing';\nimport { Href, Route, RouteInputParams } from './types';\n\n/**\n * Returns `router` object for imperative navigation API.\n *\n * @example\n *```tsx\n * import { router } from 'expo-router';\n * import { Text } from 'react-native';\n *\n * export default function Route() {\n *\n * return (\n * <Text onPress={() => router.push('/home')}>Go Home</Text>\n * );\n *}\n * ```\n */\nexport type Router = {\n /**\n * Goes back in the navigation history.\n */\n back: () => void;\n /**\n * Navigates to a route in the navigator's history if it supports invoking the `back` function.\n */\n canGoBack: () => boolean;\n /**\n * Navigates to the provided [`href`](#href) using a push operation if possible.\n */\n push: (href: Href, options?: NavigationOptions) => void;\n /**\n * Navigates to the provided [`href`](#href).\n */\n navigate: (href: Href, options?: NavigationOptions) => void;\n /**\n * Navigates to route without appending to the history. Can be used with\n * [`useFocusEffect`](#usefocuseffecteffect-do_not_pass_a_second_prop)\n * to redirect imperatively to a new screen.\n *\n * @see [Using `useRouter()` hook](/router/reference/redirects/) to redirect.\n * */\n replace: (href: Href, options?: NavigationOptions) => void;\n /**\n * Navigates to the a stack lower than the current screen using the provided count if possible, otherwise 1.\n *\n * If the current screen is the only route, it will dismiss the entire stack.\n */\n dismiss: (count?: number) => void;\n /**\n * Dismisses screens until the provided href is reached. If the href is not found, it will instead replace the current screen with the provided href.\n */\n dismissTo: (href: Href, options?: NavigationOptions) => void;\n /**\n * Returns to the first screen in the closest stack. This is similar to\n * [popToTop](https://reactnavigation.org/docs/stack-actions/#poptotop) stack action.\n */\n dismissAll: () => void;\n /**\n * Checks if it is possible to dismiss the current screen. Returns `true` if the\n * router is within the stack with more than one screen in stack's history.\n *\n */\n canDismiss: () => boolean;\n /**\n * Updates the current route's query params.\n */\n setParams: <T extends Route>(params: Partial<RouteInputParams<T>>) => void;\n /**\n * Reloads the currently mounted route in experimental server mode. This can be used to re-fetch data.\n * @hidden\n */\n reload: () => void;\n};\n\n/**\n * @hidden\n */\nexport const router: Router = {\n navigate: (href, options) => store.navigate(href, options),\n push: (href, options) => store.push(href, options),\n dismiss: (count) => store.dismiss(count),\n dismissAll: () => store.dismissAll(),\n dismissTo: (href, options) => store.dismissTo(href, options),\n canDismiss: () => store.canDismiss(),\n replace: (href, options) => store.replace(href, options),\n back: () => store.goBack(),\n canGoBack: () => store.canGoBack(),\n setParams: (params) => store.setParams(params),\n reload: () => store.reload(),\n};\n"]}
|
package/build/link/Link.d.ts.map
CHANGED
|
@@ -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,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,MAAM,MAAM,aAAa,G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AAC;AAyE3E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
|
package/build/link/Link.js
CHANGED
|
@@ -79,7 +79,7 @@ exports.Redirect = Redirect;
|
|
|
79
79
|
*/
|
|
80
80
|
exports.Link = (0, react_1.forwardRef)(ExpoRouterLink);
|
|
81
81
|
exports.Link.resolveHref = href_1.resolveHref;
|
|
82
|
-
function ExpoRouterLink({ href, replace, push,
|
|
82
|
+
function ExpoRouterLink({ href, replace, push, dismissTo,
|
|
83
83
|
// TODO: This does not prevent default on the anchor tag.
|
|
84
84
|
relativeToDirectory, asChild, rel, target, download, withAnchor, ...rest }, ref) {
|
|
85
85
|
// Mutate the style prop to add the className on web.
|
|
@@ -97,6 +97,8 @@ relativeToDirectory, asChild, rel, target, download, withAnchor, ...rest }, ref)
|
|
|
97
97
|
event = 'PUSH';
|
|
98
98
|
if (replace)
|
|
99
99
|
event = 'REPLACE';
|
|
100
|
+
if (dismissTo)
|
|
101
|
+
event = 'POP_TO';
|
|
100
102
|
const props = (0, useLinkToPathProps_1.default)({
|
|
101
103
|
href: resolvedHref,
|
|
102
104
|
event,
|
package/build/link/Link.js.map
CHANGED
|
@@ -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;AA2C9F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,UAAU,EAAiB;IAC/E,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,IAAA,+BAAc,EAAC,GAAG,EAAE;QAClB,IAAI;YACF,MAAM,CAAC,OAAO,CAAC,IAAI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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\nexport type RedirectProps = {\n /**\n * The path of the route to navigate to. It can either be:\n * - **string**: A full path like `/profile/settings` or a relative path like `../settings`.\n * - **object**: An object with a `pathname` and optional `params`. The `pathname` can be\n * a full path like `/profile/settings` or a relative path like `../settings`. The\n * params can be an object of key-value pairs.\n *\n * @example\n * ```tsx Dynamic\n * import { Redirect } from 'expo-router';\n *\n * export default function RedirectToAbout() {\n * return (\n * <Redirect href=\"/about\">About</Link>\n * );\n *}\n * ```\n */\n href: Href;\n\n /**\n * Relative URL references are either relative to the directory or the document.\n * By default, relative paths are relative to the document.\n *\n * @see [Resolving relative references in Mozilla's documentation](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references).\n */\n relativeToDirectory?: boolean;\n\n /**\n * Replaces the initial screen with the current route.\n */\n withAnchor?: boolean;\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, relativeToDirectory, withAnchor }: RedirectProps) {\n const router = useRouter();\n useFocusEffect(() => {\n try {\n router.replace(href, { relativeToDirectory, withAnchor });\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 dismissTo,\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 if (dismissTo) event = 'POP_TO';\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"]}
|
|
@@ -158,6 +158,25 @@ export interface LinkProps extends Omit<TextProps, 'href'>, WebAnchorProps {
|
|
|
158
158
|
* ```
|
|
159
159
|
*/
|
|
160
160
|
push?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* While in a stack, this will dismiss screens until the provided href is reached. If the href is not found,
|
|
163
|
+
* it will instead replace the current screen with the provided href.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
*```tsx
|
|
167
|
+
* import { Link } from 'expo-router';
|
|
168
|
+
* import { View } from 'react-native';
|
|
169
|
+
*
|
|
170
|
+
* export default function Route() {
|
|
171
|
+
* return (
|
|
172
|
+
* <View>
|
|
173
|
+
* <Link dismissTo href="/feed">Close modal</Link>
|
|
174
|
+
* </View>
|
|
175
|
+
* );
|
|
176
|
+
*}
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
dismissTo?: boolean;
|
|
161
180
|
/**
|
|
162
181
|
* On native, this can be used with CSS interop tools like Nativewind.
|
|
163
182
|
* On web, this sets the HTML `class` directly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinkHooks.d.ts","sourceRoot":"","sources":["../../src/link/useLinkHooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAY,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAErE;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,cAAc;IACxE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,IAAI,EAAE,IAAI,CAAC;IAGX;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useLinkHooks.d.ts","sourceRoot":"","sources":["../../src/link/useLinkHooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAY,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhC;;GAEG;AACH,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,GAAG,CAAA;CAAE,GAAG,QAAQ,SAAS,CAoBtE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinkHooks.js","sourceRoot":"","sources":["../../src/link/useLinkHooks.ts"],"names":[],"mappings":";;;AAAA,wFAAwF;AACxF,mCAAmC;AACnC,iCAA4C;AAC5C,+CAA0E;
|
|
1
|
+
{"version":3,"file":"useLinkHooks.js","sourceRoot":"","sources":["../../src/link/useLinkHooks.ts"],"names":[],"mappings":";;;AAAA,wFAAwF;AACxF,mCAAmC;AACnC,iCAA4C;AAC5C,+CAA0E;AAmN1E,qDAAqD;AACrD,SAAgB,mBAAmB,CAAC,KAAyD;IAC3F,IAAI,uBAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QACzB,OAAO,KAAK,CAAC,KAAK,CAAC;KACpB;IAED,sDAAsD;IACtD,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;QAClB,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,EAAE;YAC3B,OAAO,KAAK,CAAC,KAAK,CAAC;SACpB;QACD,MAAM,QAAQ,GAAG;YACf,KAAK,EAAE,IAAI;YACX,qBAAqB,EAAE,KAAK,CAAC,SAAS;SACvC,CAAC;QAEF,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC9B,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;SACnC;QACD,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;AACrC,CAAC;AApBD,kDAoBC;AAEY,QAAA,YAAY,GAAG,uBAAQ,CAAC,MAAM,CAEzC;IACA,GAAG,EAAE,SAAS,YAAY,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAsB;QAC/E,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;YAClB,MAAM,SAAS,GAAG;gBAChB,GAAG;gBACH,MAAM;gBACN,QAAQ;aACT,CAAC;YACF,IAAI,OAAO,EAAE;gBACX,OAAO,SAAS,CAAC;aAClB;YACD,OAAO;gBACL,SAAS;aACV,CAAC;QACJ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,EAAE,SAAS,YAAY;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC","sourcesContent":["// Fork of @react-navigation/native Link.tsx with `href` and `replace` support added and\n// `to` / `action` support removed.\nimport { useMemo, MouseEvent } from 'react';\nimport { TextProps, GestureResponderEvent, Platform } from 'react-native';\n\nimport { Href } from '../types';\n\n// docsMissing\n/**\n * @platform web\n */\nexport type WebAnchorProps = {\n /**\n * Specifies where to open the [`href`](#href).\n *\n * - **_self**: the current tab.\n * - **_blank**: opens in a new tab or window.\n * - **_parent**: opens in the parent browsing context. If no parent, defaults to **_self**.\n * - **_top**: opens in the highest browsing context ancestor. If no ancestors,\n * defaults to **_self**.\n *\n * This property is passed to the underlying anchor (`<a>`) tag.\n *\n * @default '_self'\n *\n * @example\n * ```jsx\n * <Link href=\"https://expo.dev\" target=\"_blank\">Go to Expo in new tab</Link>\n * ```\n */\n target?: '_self' | '_blank' | '_parent' | '_top' | (string & object);\n\n /**\n * Specifies the relationship between the [`href`](#href) and the current route.\n *\n * Common values:\n * - **nofollow**: Indicates to search engines that they should not follow the `href`.\n * This is often used for user-generated content or links that should not influence\n * search engine rankings.\n * - **noopener**: Suggests that the `href` should not have access to the opening\n * window's `window.opener` object, which is a security measure to prevent potentially\n * harmful behavior in cases of links that open new tabs or windows.\n * - **noreferrer**: Requests that the browser does not send the `Referer` HTTP header\n * when navigating to the `href`. This can enhance user privacy.\n *\n * The `rel` property is primarily used for informational and instructive purposes, helping browsers and web\n * crawlers make better decisions about how to handle and interpret the links on a web\n * page. It is important to use appropriate `rel` values to ensure that links behave as intended and adhere\n * to best practices for web development and SEO (Search Engine Optimization).\n *\n * This property is passed to the underlying anchor (`<a>`) tag.\n *\n * @example\n * ```jsx\n * <Link href=\"https://expo.dev\" rel=\"nofollow\">Go to Expo</Link>`\n * ```\n */\n rel?: string;\n\n /**\n * Specifies that the [`href`](#href) should be downloaded when the user clicks on the\n * link, instead of navigating to it. It is typically used for links that point to\n * files that the user should download, such as PDFs, images, documents, and more.\n *\n * The value of the `download` property, which represents the filename for the\n * downloaded file. This property is passed to the underlying anchor (`<a>`) tag.\n *\n * @example\n * ```jsx\n * <Link href=\"/image.jpg\" download=\"my-image.jpg\">Download image</Link>\n * ```\n */\n download?: string;\n};\n\n// @docsMissing\nexport interface LinkProps extends Omit<TextProps, 'href'>, WebAnchorProps {\n /**\n * The path of the route to navigate to. It can either be:\n * - **string**: A full path like `/profile/settings` or a relative path like `../settings`.\n * - **object**: An object with a `pathname` and optional `params`. The `pathname` can be\n * a full path like `/profile/settings` or a relative path like `../settings`. The\n * params can be an object of key-value pairs.\n *\n * @example\n * ```tsx Dynamic\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 * <Link\n * href={{\n * pathname: '/user/[id]',\n * params: { id: 'bacon' }\n * }}>\n * View user\n * </Link>\n * </View>\n * );\n *}\n * ```\n */\n href: Href;\n\n // TODO(EvanBacon): This may need to be extracted for React Native style support.\n /**\n * Used to customize the `Link` component. It will forward all props to the\n * first child of the `Link`. Note that the child component must accept\n * `onPress` or `onClick` props. The `href` and `role` are also\n * passed to the child.\n *\n * @example\n * ```tsx\n * import { Link } from 'expo-router';\n * import { Pressable, Text } from 'react-native';\n *\n * export default function Route() {\n * return (\n * <View>\n * <Link href=\"/home\" asChild>\n * <Pressable>\n * <Text>Home</Text>\n * </Pressable>\n * </Link>\n * </View>\n * );\n *}\n * ```\n */\n asChild?: boolean;\n\n /**\n * Removes the current route from the history and replace it with the\n * specified URL. This is useful for [redirects](/router/reference/redirects/).\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 replace href=\"/feed\">Login</Link>\n * </View>\n * );\n *}\n * ```\n */\n replace?: boolean;\n /**\n * Always pushes a new route, and never pops or replaces to existing route.\n * You can push the current route multiple times or with new parameters.\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 push href=\"/feed\">Login</Link>\n * </View>\n * );\n *}\n * ```\n */\n push?: boolean;\n /**\n * While in a stack, this will dismiss screens until the provided href is reached. If the href is not found,\n * it will instead replace the current screen with the provided href.\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 dismissTo href=\"/feed\">Close modal</Link>\n * </View>\n * );\n *}\n * ```\n */\n dismissTo?: boolean;\n\n /**\n * On native, this can be used with CSS interop tools like Nativewind.\n * On web, this sets the HTML `class` directly.\n */\n className?: string;\n\n onPress?: (e: MouseEvent<HTMLAnchorElement> | GestureResponderEvent) => void;\n\n /**\n * Relative URL references are either relative to the directory or the document.\n * By default, relative paths are relative to the document.\n *\n * @see [Resolving relative references in Mozilla's documentation](https://developer.mozilla.org/en-US/docs/Web/API/URL_API/Resolving_relative_references).\n */\n relativeToDirectory?: boolean;\n\n /**\n * Replaces the initial screen with the current route.\n */\n withAnchor?: boolean;\n}\n\n// Mutate the style prop to add the className on web.\nexport function useInteropClassName(props: { style?: TextProps['style']; className?: string }) {\n if (Platform.OS !== 'web') {\n return props.style;\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMemo(() => {\n if (props.className == null) {\n return props.style;\n }\n const cssStyle = {\n $$css: true,\n __routerLinkClassName: props.className,\n };\n\n if (Array.isArray(props.style)) {\n return [...props.style, cssStyle];\n }\n return [props.style, cssStyle];\n }, [props.style, props.className]);\n}\n\nexport const useHrefAttrs = Platform.select<\n (props: Partial<LinkProps>) => { hrefAttrs?: any } & Partial<LinkProps>\n>({\n web: function useHrefAttrs({ asChild, rel, target, download }: Partial<LinkProps>) {\n return useMemo(() => {\n const hrefAttrs = {\n rel,\n target,\n download,\n };\n if (asChild) {\n return hrefAttrs;\n }\n return {\n hrefAttrs,\n };\n }, [asChild, rel, target, download]);\n },\n default: function useHrefAttrs() {\n return {};\n },\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH,OAAO,KAAK,EAGV,SAAS,EAET,oBAAoB,EAGrB,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,IAAI,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGvF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA+O3C,wBAAgB,kBAAkB,IAAI,qBAAqB,GACzD,UAAU,GAAG;IACX,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CAChC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH,OAAO,KAAK,EAGV,SAAS,EAET,oBAAoB,EAGrB,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,IAAI,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGvF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA+O3C,wBAAgB,kBAAkB,IAAI,qBAAqB,GACzD,UAAU,GAAG;IACX,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CAChC,CA4FF;AAoDD,KAAK,UAAU,GAAG,CAAC,SAAS;IAC1B,MAAM;IACN,SAAS;QACP,OAAO;QACP,MAAM,EAAE;KACT;CACF,CAAC,EAAE,CAAC;AAGL,KAAK,UAAU,GAAG;IAChB,UAAU,CAAC,EAAE,UAAU;IACvB,iBAAiB,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/D,CAAC;AAIF,wBAAgB,MAAM,CAAC,EAAE,UAAgC,EAAE;;CAAA;;;;;;;;;;;;;;;;;;gBAU1D;AAKD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE;;GAgB3F;AAED,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG;IACzC,IAAI,EAAE,MAAM,CAAC;CAMd,GAAG,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,CAAC;AAE1D,eAAO,MAAM,IAAI,eAAyD,CAAC"}
|
|
@@ -253,6 +253,9 @@ function useRouter_UNSTABLE() {
|
|
|
253
253
|
dismiss() {
|
|
254
254
|
throw new Error('router.dismiss() is not supported in React Server Components yet');
|
|
255
255
|
},
|
|
256
|
+
dismissTo() {
|
|
257
|
+
throw new Error('router.dismissTo() is not supported in React Server Components yet');
|
|
258
|
+
},
|
|
256
259
|
dismissAll() {
|
|
257
260
|
throw new Error('router.dismissAll() is not supported in React Server Components yet');
|
|
258
261
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/rsc/router/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,CAAC;;;;AAEb,qDAAyD;AACzD,iCAae;AAUf,+CAAoC;AAEpC,2CAA8E;AAE9E,uCAAgE;AAIhE,0CAA8C;AAC9C,0DAA4E;AAG5E,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC1C,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE;QACzC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;SAC7C;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAc,EAAE;IAC1C,IAAK,UAAkB,CAAC,mBAAmB,EAAE;QAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;KAC9C;IACD,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAC7C,IAAI,YAAY,CAAC,GAAG,CAAC,0BAAc,CAAC,EAAE;QACpC,OAAO,CAAC,IAAI,CAAC,qBAAqB,0BAAc,eAAe,CAAC,CAAC;KAClE;IACD,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QAClC,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE;QAC9B,IAAI;KACL,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,OAAO,GAAG,GA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AChD,2DAA2D;IAC3D,IAAI;IACJ,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n * Copyright © 2024 2023 Daishi Kato\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 * https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/client.ts#L1\n */\n\n'use client';\n\nimport { Slot as ReactSlot } from '@radix-ui/react-slot';\nimport {\n startTransition,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useTransition,\n createElement,\n createContext,\n useState,\n Fragment,\n forwardRef,\n useMemo,\n} from 'react';\nimport type {\n ComponentProps,\n FunctionComponent,\n ReactNode,\n MutableRefObject,\n AnchorHTMLAttributes,\n MouseEvent,\n ForwardedRef,\n} from 'react';\nimport { Text } from 'react-native';\n\nimport { PARAM_KEY_SKIP, getComponentIds, getInputString } from './common.js';\nimport type { RouteProps } from './common.js';\nimport { prefetchRSC, Root, Slot, useRefetch } from './host.js';\nimport type { NavigationOptions } from '../../global-state/routing.js';\nimport type { Router as ClassicExpoRouterType } from '../../imperative-api';\nimport type { LinkProps as ClassicLinkProps, LinkComponent } from '../../link/Link.js';\nimport { resolveHref } from '../../link/href';\nimport { useInteropClassName, useHrefAttrs } from '../../link/useLinkHooks';\nimport type { Href } from '../../types.js';\n\nconst normalizeRoutePath = (path: string) => {\n for (const suffix of ['/', '/index.html']) {\n if (path.endsWith(suffix)) {\n return path.slice(0, -suffix.length) || '/';\n }\n }\n return path;\n};\n\nconst parseRoute = (url: URL): RouteProps => {\n if ((globalThis as any).__EXPO_ROUTER_404__) {\n return { path: '/404', query: '', hash: '' };\n }\n const { pathname, searchParams, hash } = url;\n if (searchParams.has(PARAM_KEY_SKIP)) {\n console.warn(`The search param \"${PARAM_KEY_SKIP}\" is reserved`);\n }\n return {\n path: normalizeRoutePath(pathname),\n query: searchParams.toString(),\n hash,\n };\n};\nconst getHref = () =>\n process.env.EXPO_OS === 'web'\n ? window.location.href\n : // TODO: This is hardcoded on native to simplify the initial PR.\n 'http://localhost:8081/';\n\ntype ChangeRoute = (\n route: RouteProps,\n options?: {\n checkCache?: boolean;\n skipRefetch?: boolean;\n }\n) => void;\n\ntype PrefetchRoute = (route: RouteProps) => void;\n\nconst equalRouteProps = (a: RouteProps, b: RouteProps) => {\n if (a.path !== b.path) {\n return false;\n }\n if (a.query !== b.query) {\n return false;\n }\n return true;\n};\n\nconst RouterContext = createContext<{\n route: RouteProps;\n changeRoute: ChangeRoute;\n prefetchRoute: PrefetchRoute;\n} | null>(null);\n\nconst InnerRouter = ({ routerData }: { routerData: RouterData }) => {\n const refetch = useRefetch();\n\n const initialRouteRef = useRef<RouteProps>();\n if (!initialRouteRef.current) {\n initialRouteRef.current = parseRoute(new URL(getHref()));\n }\n const [route, setRoute] = useState(() => ({\n // This is the first initialization of the route, and it has\n // to ignore the hash, because on server side there is none.\n // Otherwise there will be a hydration error.\n // The client side route, including the hash, will be updated in the effect below.\n ...initialRouteRef.current!,\n hash: '',\n }));\n\n // Update the route post-load to include the current hash.\n useEffect(() => {\n const initialRoute = initialRouteRef.current!;\n setRoute((prev) => {\n if (\n prev.path === initialRoute.path &&\n prev.query === initialRoute.query &&\n prev.hash === initialRoute.hash\n ) {\n return prev;\n }\n return initialRoute;\n });\n }, []);\n\n const componentIds = getComponentIds(route.path);\n\n // const refetchRoute = () => {\n // const loc = parseRoute(new URL(getHref()));\n // const input = getInputString(loc.path);\n // refetch(input, loc.query);\n // refetch(input, JSON.stringify({ query: route.query }));\n // };\n // globalThis.__EXPO_REFETCH_ROUTE_NO_CACHE__ = refetchRoute;\n\n const [cached, setCached] = useState<Record<string, RouteProps>>(() => {\n return Object.fromEntries(componentIds.map((id) => [id, route]));\n });\n const cachedRef = useRef(cached);\n useEffect(() => {\n cachedRef.current = cached;\n }, [cached]);\n\n const changeRoute: ChangeRoute = useCallback(\n (route, options) => {\n const { checkCache, skipRefetch } = options || {};\n startTransition(() => {\n setRoute(route);\n });\n const componentIds = getComponentIds(route.path);\n if (\n checkCache &&\n componentIds.every((id) => {\n const cachedLoc = cachedRef.current[id];\n return cachedLoc && equalRouteProps(cachedLoc, route);\n })\n ) {\n return; // everything is cached\n }\n const shouldSkip = routerData[0];\n const skip = getSkipList(shouldSkip, componentIds, route, cachedRef.current);\n if (componentIds.every((id) => skip.includes(id))) {\n return; // everything is skipped\n }\n const input = getInputString(route.path);\n if (!skipRefetch) {\n refetch(input, JSON.stringify({ query: route.query, skip }));\n }\n startTransition(() => {\n setCached((prev) => ({\n ...prev,\n ...Object.fromEntries(\n componentIds.flatMap((id) => (skip.includes(id) ? [] : [[id, route]]))\n ),\n }));\n });\n },\n [refetch, routerData]\n );\n\n const prefetchRoute: PrefetchRoute = useCallback(\n (route) => {\n const componentIds = getComponentIds(route.path);\n const shouldSkip = routerData[0];\n const skip = getSkipList(shouldSkip, componentIds, route, cachedRef.current);\n if (componentIds.every((id) => skip.includes(id))) {\n return; // everything is cached\n }\n const input = getInputString(route.path);\n prefetchRSC(input, JSON.stringify({ query: route.query, skip }));\n (globalThis as any).__EXPO_ROUTER_PREFETCH__?.(route.path);\n },\n [routerData]\n );\n\n useEffect(() => {\n const callback = () => {\n const route = parseRoute(new URL(getHref()));\n changeRoute(route, { checkCache: true });\n };\n if (window.addEventListener) {\n window.addEventListener('popstate', callback);\n return () => {\n window.removeEventListener('popstate', callback);\n };\n }\n return () => {};\n }, [changeRoute]);\n\n useEffect(() => {\n const callback = (pathname: string, searchParamsString: string) => {\n const url = new URL(getHref());\n url.pathname = pathname;\n url.search = searchParamsString;\n url.hash = '';\n getHistory().pushState(\n {\n ...getHistory().state,\n expo_new_path: url.pathname !== window.location.pathname,\n },\n '',\n url\n );\n changeRoute(parseRoute(url), { skipRefetch: true });\n };\n // eslint-disable-next-line no-multi-assign\n const listeners = (routerData[1] ||= new Set());\n listeners.add(callback);\n return () => {\n listeners.delete(callback);\n };\n }, [changeRoute, routerData]);\n\n useEffect(() => {\n const { hash } = window.location;\n const { state } = getHistory();\n const element = hash && document.getElementById(hash.slice(1));\n if (window.scrollTo) {\n window.scrollTo({\n left: 0,\n top: element ? element.getBoundingClientRect().top + window.scrollY : 0,\n behavior: state?.expo_new_path ? 'instant' : 'auto',\n });\n } else {\n // TODO: Native\n // console.log('window.scrollTo is not available');\n }\n });\n\n const children = componentIds.reduceRight(\n (acc: ReactNode, id) =>\n createElement(RouterSlot, { route, routerData, cachedRef, id, fallback: acc }, acc),\n null\n );\n\n return createElement(\n RouterContext.Provider,\n { value: { route, changeRoute, prefetchRoute } },\n children\n );\n};\n\nfunction getHistory() {\n if (process.env.EXPO_OS === 'web') {\n return window.history;\n }\n // Native shim\n return {\n pushState: () => {},\n replaceState: () => {},\n back: () => {},\n forward: () => {},\n state: {},\n };\n}\n\nexport function useRouter_UNSTABLE(): ClassicExpoRouterType &\n RouteProps & {\n forward: () => void;\n prefetch: (href: Href) => void;\n } {\n const router = useContext(RouterContext);\n if (!router) {\n throw new Error('Missing Router');\n }\n const { route, changeRoute, prefetchRoute } = router;\n const push: ClassicExpoRouterType['push'] = useCallback(\n (href: Href, options?: NavigationOptions) => {\n if (options) {\n // TODO(Bacon): Implement options\n console.warn(\n 'options prop of router.push() is not supported in React Server Components yet'\n );\n }\n\n const url = new URL(resolveHref(href), getHref());\n getHistory().pushState(\n {\n ...getHistory().state,\n expo_new_path: url.pathname !== window.location.pathname,\n },\n '',\n url\n );\n changeRoute(parseRoute(url));\n },\n [changeRoute]\n );\n const replace: ClassicExpoRouterType['replace'] = useCallback(\n (href: Href, options?: NavigationOptions) => {\n if (options) {\n // TODO(Bacon): Implement options\n console.warn(\n 'options prop of router.replace() is not supported in React Server Components yet'\n );\n }\n\n const url = new URL(resolveHref(href), getHref());\n getHistory().replaceState(getHistory().state, '', url);\n changeRoute(parseRoute(url));\n },\n [changeRoute]\n );\n const reload = useCallback(() => {\n const url = new URL(getHref());\n changeRoute(parseRoute(url));\n }, [changeRoute]);\n const back = useCallback(() => {\n // FIXME is this correct?\n getHistory().back();\n }, []);\n const forward = useCallback(() => {\n // FIXME is this correct?\n getHistory().forward();\n }, []);\n const prefetch = useCallback(\n (href: Href) => {\n const url = new URL(resolveHref(href), getHref());\n prefetchRoute(parseRoute(url));\n },\n [prefetchRoute]\n );\n return {\n ...route,\n canDismiss() {\n throw new Error('router.canDismiss() is not supported in React Server Components yet');\n },\n canGoBack() {\n throw new Error('router.canGoBack() is not supported in React Server Components yet');\n },\n dismiss() {\n throw new Error('router.dismiss() is not supported in React Server Components yet');\n },\n dismissAll() {\n throw new Error('router.dismissAll() is not supported in React Server Components yet');\n },\n setParams() {\n throw new Error('router.setParams() is not supported in React Server Components yet');\n },\n\n // TODO: The behavior here is not the same as before.\n navigate: push,\n push,\n replace,\n reload,\n back,\n forward,\n prefetch,\n };\n}\n\nconst RouterSlot = ({\n route,\n routerData,\n cachedRef,\n id,\n fallback,\n children,\n}: {\n route: RouteProps;\n routerData: RouterData;\n cachedRef: MutableRefObject<Record<string, RouteProps>>;\n id: string;\n fallback?: ReactNode;\n children?: ReactNode;\n}) => {\n // const unstable_shouldRenderPrev = (_err: unknown) => {\n // const shouldSkip = routerData[0];\n // const skip = getSkipList(shouldSkip, [id], route, cachedRef.current);\n // return skip.length > 0;\n // };\n return createElement(Slot, { id, fallback }, children);\n};\n\nconst getSkipList = (\n shouldSkip: ShouldSkip | undefined,\n componentIds: readonly string[],\n route: RouteProps,\n cached: Record<string, RouteProps>\n): string[] => {\n const shouldSkipObj = Object.fromEntries(shouldSkip || []);\n return componentIds.filter((id) => {\n const prevProps = cached[id];\n if (!prevProps) {\n return false;\n }\n const shouldCheck = shouldSkipObj[id];\n if (!shouldCheck) {\n return false;\n }\n if (shouldCheck[0] && route.path !== prevProps.path) {\n return false;\n }\n if (shouldCheck[0] && route.query !== prevProps.query) {\n return false;\n }\n return true;\n });\n};\n\n// TODO revisit shouldSkip API\ntype ShouldSkip = (readonly [\n string,\n readonly [\n boolean, // if we compare path\n string[], // searchParams keys to compare\n ],\n])[];\n\n// Note: The router data must be a stable mutable object (array).\ntype RouterData = [\n shouldSkip?: ShouldSkip,\n locationListeners?: Set<(path: string, query: string) => void>,\n];\n\nconst DEFAULT_ROUTER_DATA: RouterData = [];\n\nexport function Router({ routerData = DEFAULT_ROUTER_DATA }) {\n const route = parseRoute(new URL(getHref()));\n const initialInput = getInputString(route.path);\n const initialParams = JSON.stringify({ query: route.query });\n const unstable_onFetchData = () => {};\n return createElement(\n Root as FunctionComponent<Omit<ComponentProps<typeof Root>, 'children'>>,\n { initialInput, initialParams, unstable_onFetchData },\n createElement(InnerRouter, { routerData })\n );\n}\n\nconst notAvailableInServer = (name: string) => () => {\n throw new Error(`${name} is not in the server`);\n};\n/**\n * ServerRouter for SSR\n * This is not a public API.\n */\nexport function ServerRouter({ children, route }: { children: ReactNode; route: RouteProps }) {\n return createElement(\n Fragment,\n null,\n createElement(\n RouterContext.Provider,\n {\n value: {\n route,\n changeRoute: notAvailableInServer('changeRoute'),\n prefetchRoute: notAvailableInServer('prefetchRoute'),\n },\n },\n children\n )\n );\n}\n\nexport type LinkProps = ClassicLinkProps & {\n href: string;\n // pending?: ReactNode;\n // notPending?: ReactNode;\n\n // unstable_prefetchOnEnter?: boolean;\n // unstable_prefetchOnView?: boolean;\n} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>;\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 // pending,\n // notPending,\n // unstable_prefetchOnEnter,\n // unstable_prefetchOnView,\n children,\n ...props\n }: LinkProps,\n ref: ForwardedRef<Text>\n) {\n // Mutate the style prop to add the className on web.\n const style = useInteropClassName(props);\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 const router = useContext(RouterContext);\n const changeRoute = router\n ? router.changeRoute\n : () => {\n throw new Error('Missing Router');\n };\n const prefetchRoute = router\n ? router.prefetchRoute\n : () => {\n throw new Error('Missing Router');\n };\n // TODO: Implement support for pending states in the future.\n const [, startTransition] = useTransition();\n // const elementRef = useRef<HTMLAnchorElement>();\n\n // useEffect(() => {\n // if (unstable_prefetchOnView && process.env.EXPO_OS === 'web' && ref.current) {\n // const observer = new IntersectionObserver(\n // (entries) => {\n // entries.forEach((entry) => {\n // if (entry.isIntersecting) {\n // const url = new URL(resolvedHref, getHref());\n // if (router && url.href !== getHref()) {\n // const route = parseRoute(url);\n // router.prefetchRoute(route);\n // }\n // }\n // });\n // },\n // { threshold: 0.1 }\n // );\n\n // observer.observe(ref.current);\n\n // return () => {\n // observer.disconnect();\n // };\n // }\n // return () => {};\n // }, [unstable_prefetchOnView, router, resolvedHref]);\n\n const onClick = (event: MouseEvent<HTMLAnchorElement>) => {\n event.preventDefault();\n const url = new URL(resolvedHref, getHref());\n // TODO: Use in-memory route for native platforms.\n // if (url.href !== getHref()) {\n const route = parseRoute(url);\n prefetchRoute(route);\n startTransition(() => {\n getHistory().pushState(\n {\n ...getHistory().state,\n expo_new_path: url.pathname !== window.location.pathname,\n },\n '',\n url\n );\n changeRoute(route);\n });\n // }\n props.onClick?.(event);\n };\n // const onMouseEnter = unstable_prefetchOnEnter\n // ? (event: MouseEvent<HTMLAnchorElement>) => {\n // const url = new URL(to, getHref());\n // if (url.href !== getHref()) {\n // const route = parseRoute(url);\n // prefetchRoute(route);\n // }\n // props.onMouseEnter?.(event);\n // }\n // : props.onMouseEnter;\n\n const Element = asChild ? ReactSlot : Text;\n\n const ele = createElement(\n // @ts-expect-error\n Element,\n {\n ...hrefAttrs,\n ...props,\n style,\n href: resolvedHref,\n onPress: onClick,\n // onMouseEnter,\n ref,\n },\n children\n );\n // if (isPending && pending !== undefined) {\n // return createElement(Fragment, null, ele, pending);\n // }\n // if (!isPending && notPending !== undefined) {\n // return createElement(Fragment, null, ele, notPending);\n // }\n return ele;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/rsc/router/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,CAAC;;;;AAEb,qDAAyD;AACzD,iCAae;AAUf,+CAAoC;AAEpC,2CAA8E;AAE9E,uCAAgE;AAIhE,0CAA8C;AAC9C,0DAA4E;AAG5E,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC1C,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE;QACzC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;SAC7C;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAc,EAAE;IAC1C,IAAK,UAAkB,CAAC,mBAAmB,EAAE;QAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;KAC9C;IACD,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAC7C,IAAI,YAAY,CAAC,GAAG,CAAC,0BAAc,CAAC,EAAE;QACpC,OAAO,CAAC,IAAI,CAAC,qBAAqB,0BAAc,eAAe,CAAC,CAAC;KAClE;IACD,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QAClC,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE;QAC9B,IAAI;KACL,CAAC;AACJ,CAA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gBAAgB;QAChB,GAAG;KACJ,EACD,QAAQ,CACT,CAAC;IACF,4CAA4C;IAC5C,wDAAwD;IACxD,IAAI;IACJ,gDAAgD;IAChD,2DAA2D;IAC3D,IAAI;IACJ,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n * Copyright © 2024 2023 Daishi Kato\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 * https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/client.ts#L1\n */\n\n'use client';\n\nimport { Slot as ReactSlot } from '@radix-ui/react-slot';\nimport {\n startTransition,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useTransition,\n createElement,\n createContext,\n useState,\n Fragment,\n forwardRef,\n useMemo,\n} from 'react';\nimport type {\n ComponentProps,\n FunctionComponent,\n ReactNode,\n MutableRefObject,\n AnchorHTMLAttributes,\n MouseEvent,\n ForwardedRef,\n} from 'react';\nimport { Text } from 'react-native';\n\nimport { PARAM_KEY_SKIP, getComponentIds, getInputString } from './common.js';\nimport type { RouteProps } from './common.js';\nimport { prefetchRSC, Root, Slot, useRefetch } from './host.js';\nimport type { NavigationOptions } from '../../global-state/routing.js';\nimport type { Router as ClassicExpoRouterType } from '../../imperative-api';\nimport type { LinkProps as ClassicLinkProps, LinkComponent } from '../../link/Link.js';\nimport { resolveHref } from '../../link/href';\nimport { useInteropClassName, useHrefAttrs } from '../../link/useLinkHooks';\nimport type { Href } from '../../types.js';\n\nconst normalizeRoutePath = (path: string) => {\n for (const suffix of ['/', '/index.html']) {\n if (path.endsWith(suffix)) {\n return path.slice(0, -suffix.length) || '/';\n }\n }\n return path;\n};\n\nconst parseRoute = (url: URL): RouteProps => {\n if ((globalThis as any).__EXPO_ROUTER_404__) {\n return { path: '/404', query: '', hash: '' };\n }\n const { pathname, searchParams, hash } = url;\n if (searchParams.has(PARAM_KEY_SKIP)) {\n console.warn(`The search param \"${PARAM_KEY_SKIP}\" is reserved`);\n }\n return {\n path: normalizeRoutePath(pathname),\n query: searchParams.toString(),\n hash,\n };\n};\nconst getHref = () =>\n process.env.EXPO_OS === 'web'\n ? window.location.href\n : // TODO: This is hardcoded on native to simplify the initial PR.\n 'http://localhost:8081/';\n\ntype ChangeRoute = (\n route: RouteProps,\n options?: {\n checkCache?: boolean;\n skipRefetch?: boolean;\n }\n) => void;\n\ntype PrefetchRoute = (route: RouteProps) => void;\n\nconst equalRouteProps = (a: RouteProps, b: RouteProps) => {\n if (a.path !== b.path) {\n return false;\n }\n if (a.query !== b.query) {\n return false;\n }\n return true;\n};\n\nconst RouterContext = createContext<{\n route: RouteProps;\n changeRoute: ChangeRoute;\n prefetchRoute: PrefetchRoute;\n} | null>(null);\n\nconst InnerRouter = ({ routerData }: { routerData: RouterData }) => {\n const refetch = useRefetch();\n\n const initialRouteRef = useRef<RouteProps>();\n if (!initialRouteRef.current) {\n initialRouteRef.current = parseRoute(new URL(getHref()));\n }\n const [route, setRoute] = useState(() => ({\n // This is the first initialization of the route, and it has\n // to ignore the hash, because on server side there is none.\n // Otherwise there will be a hydration error.\n // The client side route, including the hash, will be updated in the effect below.\n ...initialRouteRef.current!,\n hash: '',\n }));\n\n // Update the route post-load to include the current hash.\n useEffect(() => {\n const initialRoute = initialRouteRef.current!;\n setRoute((prev) => {\n if (\n prev.path === initialRoute.path &&\n prev.query === initialRoute.query &&\n prev.hash === initialRoute.hash\n ) {\n return prev;\n }\n return initialRoute;\n });\n }, []);\n\n const componentIds = getComponentIds(route.path);\n\n // const refetchRoute = () => {\n // const loc = parseRoute(new URL(getHref()));\n // const input = getInputString(loc.path);\n // refetch(input, loc.query);\n // refetch(input, JSON.stringify({ query: route.query }));\n // };\n // globalThis.__EXPO_REFETCH_ROUTE_NO_CACHE__ = refetchRoute;\n\n const [cached, setCached] = useState<Record<string, RouteProps>>(() => {\n return Object.fromEntries(componentIds.map((id) => [id, route]));\n });\n const cachedRef = useRef(cached);\n useEffect(() => {\n cachedRef.current = cached;\n }, [cached]);\n\n const changeRoute: ChangeRoute = useCallback(\n (route, options) => {\n const { checkCache, skipRefetch } = options || {};\n startTransition(() => {\n setRoute(route);\n });\n const componentIds = getComponentIds(route.path);\n if (\n checkCache &&\n componentIds.every((id) => {\n const cachedLoc = cachedRef.current[id];\n return cachedLoc && equalRouteProps(cachedLoc, route);\n })\n ) {\n return; // everything is cached\n }\n const shouldSkip = routerData[0];\n const skip = getSkipList(shouldSkip, componentIds, route, cachedRef.current);\n if (componentIds.every((id) => skip.includes(id))) {\n return; // everything is skipped\n }\n const input = getInputString(route.path);\n if (!skipRefetch) {\n refetch(input, JSON.stringify({ query: route.query, skip }));\n }\n startTransition(() => {\n setCached((prev) => ({\n ...prev,\n ...Object.fromEntries(\n componentIds.flatMap((id) => (skip.includes(id) ? [] : [[id, route]]))\n ),\n }));\n });\n },\n [refetch, routerData]\n );\n\n const prefetchRoute: PrefetchRoute = useCallback(\n (route) => {\n const componentIds = getComponentIds(route.path);\n const shouldSkip = routerData[0];\n const skip = getSkipList(shouldSkip, componentIds, route, cachedRef.current);\n if (componentIds.every((id) => skip.includes(id))) {\n return; // everything is cached\n }\n const input = getInputString(route.path);\n prefetchRSC(input, JSON.stringify({ query: route.query, skip }));\n (globalThis as any).__EXPO_ROUTER_PREFETCH__?.(route.path);\n },\n [routerData]\n );\n\n useEffect(() => {\n const callback = () => {\n const route = parseRoute(new URL(getHref()));\n changeRoute(route, { checkCache: true });\n };\n if (window.addEventListener) {\n window.addEventListener('popstate', callback);\n return () => {\n window.removeEventListener('popstate', callback);\n };\n }\n return () => {};\n }, [changeRoute]);\n\n useEffect(() => {\n const callback = (pathname: string, searchParamsString: string) => {\n const url = new URL(getHref());\n url.pathname = pathname;\n url.search = searchParamsString;\n url.hash = '';\n getHistory().pushState(\n {\n ...getHistory().state,\n expo_new_path: url.pathname !== window.location.pathname,\n },\n '',\n url\n );\n changeRoute(parseRoute(url), { skipRefetch: true });\n };\n // eslint-disable-next-line no-multi-assign\n const listeners = (routerData[1] ||= new Set());\n listeners.add(callback);\n return () => {\n listeners.delete(callback);\n };\n }, [changeRoute, routerData]);\n\n useEffect(() => {\n const { hash } = window.location;\n const { state } = getHistory();\n const element = hash && document.getElementById(hash.slice(1));\n if (window.scrollTo) {\n window.scrollTo({\n left: 0,\n top: element ? element.getBoundingClientRect().top + window.scrollY : 0,\n behavior: state?.expo_new_path ? 'instant' : 'auto',\n });\n } else {\n // TODO: Native\n // console.log('window.scrollTo is not available');\n }\n });\n\n const children = componentIds.reduceRight(\n (acc: ReactNode, id) =>\n createElement(RouterSlot, { route, routerData, cachedRef, id, fallback: acc }, acc),\n null\n );\n\n return createElement(\n RouterContext.Provider,\n { value: { route, changeRoute, prefetchRoute } },\n children\n );\n};\n\nfunction getHistory() {\n if (process.env.EXPO_OS === 'web') {\n return window.history;\n }\n // Native shim\n return {\n pushState: () => {},\n replaceState: () => {},\n back: () => {},\n forward: () => {},\n state: {},\n };\n}\n\nexport function useRouter_UNSTABLE(): ClassicExpoRouterType &\n RouteProps & {\n forward: () => void;\n prefetch: (href: Href) => void;\n } {\n const router = useContext(RouterContext);\n if (!router) {\n throw new Error('Missing Router');\n }\n const { route, changeRoute, prefetchRoute } = router;\n const push: ClassicExpoRouterType['push'] = useCallback(\n (href: Href, options?: NavigationOptions) => {\n if (options) {\n // TODO(Bacon): Implement options\n console.warn(\n 'options prop of router.push() is not supported in React Server Components yet'\n );\n }\n\n const url = new URL(resolveHref(href), getHref());\n getHistory().pushState(\n {\n ...getHistory().state,\n expo_new_path: url.pathname !== window.location.pathname,\n },\n '',\n url\n );\n changeRoute(parseRoute(url));\n },\n [changeRoute]\n );\n const replace: ClassicExpoRouterType['replace'] = useCallback(\n (href: Href, options?: NavigationOptions) => {\n if (options) {\n // TODO(Bacon): Implement options\n console.warn(\n 'options prop of router.replace() is not supported in React Server Components yet'\n );\n }\n\n const url = new URL(resolveHref(href), getHref());\n getHistory().replaceState(getHistory().state, '', url);\n changeRoute(parseRoute(url));\n },\n [changeRoute]\n );\n const reload = useCallback(() => {\n const url = new URL(getHref());\n changeRoute(parseRoute(url));\n }, [changeRoute]);\n const back = useCallback(() => {\n // FIXME is this correct?\n getHistory().back();\n }, []);\n const forward = useCallback(() => {\n // FIXME is this correct?\n getHistory().forward();\n }, []);\n const prefetch = useCallback(\n (href: Href) => {\n const url = new URL(resolveHref(href), getHref());\n prefetchRoute(parseRoute(url));\n },\n [prefetchRoute]\n );\n return {\n ...route,\n canDismiss() {\n throw new Error('router.canDismiss() is not supported in React Server Components yet');\n },\n canGoBack() {\n throw new Error('router.canGoBack() is not supported in React Server Components yet');\n },\n dismiss() {\n throw new Error('router.dismiss() is not supported in React Server Components yet');\n },\n dismissTo() {\n throw new Error('router.dismissTo() is not supported in React Server Components yet');\n },\n dismissAll() {\n throw new Error('router.dismissAll() is not supported in React Server Components yet');\n },\n setParams() {\n throw new Error('router.setParams() is not supported in React Server Components yet');\n },\n\n // TODO: The behavior here is not the same as before.\n navigate: push,\n push,\n replace,\n reload,\n back,\n forward,\n prefetch,\n };\n}\n\nconst RouterSlot = ({\n route,\n routerData,\n cachedRef,\n id,\n fallback,\n children,\n}: {\n route: RouteProps;\n routerData: RouterData;\n cachedRef: MutableRefObject<Record<string, RouteProps>>;\n id: string;\n fallback?: ReactNode;\n children?: ReactNode;\n}) => {\n // const unstable_shouldRenderPrev = (_err: unknown) => {\n // const shouldSkip = routerData[0];\n // const skip = getSkipList(shouldSkip, [id], route, cachedRef.current);\n // return skip.length > 0;\n // };\n return createElement(Slot, { id, fallback }, children);\n};\n\nconst getSkipList = (\n shouldSkip: ShouldSkip | undefined,\n componentIds: readonly string[],\n route: RouteProps,\n cached: Record<string, RouteProps>\n): string[] => {\n const shouldSkipObj = Object.fromEntries(shouldSkip || []);\n return componentIds.filter((id) => {\n const prevProps = cached[id];\n if (!prevProps) {\n return false;\n }\n const shouldCheck = shouldSkipObj[id];\n if (!shouldCheck) {\n return false;\n }\n if (shouldCheck[0] && route.path !== prevProps.path) {\n return false;\n }\n if (shouldCheck[0] && route.query !== prevProps.query) {\n return false;\n }\n return true;\n });\n};\n\n// TODO revisit shouldSkip API\ntype ShouldSkip = (readonly [\n string,\n readonly [\n boolean, // if we compare path\n string[], // searchParams keys to compare\n ],\n])[];\n\n// Note: The router data must be a stable mutable object (array).\ntype RouterData = [\n shouldSkip?: ShouldSkip,\n locationListeners?: Set<(path: string, query: string) => void>,\n];\n\nconst DEFAULT_ROUTER_DATA: RouterData = [];\n\nexport function Router({ routerData = DEFAULT_ROUTER_DATA }) {\n const route = parseRoute(new URL(getHref()));\n const initialInput = getInputString(route.path);\n const initialParams = JSON.stringify({ query: route.query });\n const unstable_onFetchData = () => {};\n return createElement(\n Root as FunctionComponent<Omit<ComponentProps<typeof Root>, 'children'>>,\n { initialInput, initialParams, unstable_onFetchData },\n createElement(InnerRouter, { routerData })\n );\n}\n\nconst notAvailableInServer = (name: string) => () => {\n throw new Error(`${name} is not in the server`);\n};\n/**\n * ServerRouter for SSR\n * This is not a public API.\n */\nexport function ServerRouter({ children, route }: { children: ReactNode; route: RouteProps }) {\n return createElement(\n Fragment,\n null,\n createElement(\n RouterContext.Provider,\n {\n value: {\n route,\n changeRoute: notAvailableInServer('changeRoute'),\n prefetchRoute: notAvailableInServer('prefetchRoute'),\n },\n },\n children\n )\n );\n}\n\nexport type LinkProps = ClassicLinkProps & {\n href: string;\n // pending?: ReactNode;\n // notPending?: ReactNode;\n\n // unstable_prefetchOnEnter?: boolean;\n // unstable_prefetchOnView?: boolean;\n} & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>;\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 // pending,\n // notPending,\n // unstable_prefetchOnEnter,\n // unstable_prefetchOnView,\n children,\n ...props\n }: LinkProps,\n ref: ForwardedRef<Text>\n) {\n // Mutate the style prop to add the className on web.\n const style = useInteropClassName(props);\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 const router = useContext(RouterContext);\n const changeRoute = router\n ? router.changeRoute\n : () => {\n throw new Error('Missing Router');\n };\n const prefetchRoute = router\n ? router.prefetchRoute\n : () => {\n throw new Error('Missing Router');\n };\n // TODO: Implement support for pending states in the future.\n const [, startTransition] = useTransition();\n // const elementRef = useRef<HTMLAnchorElement>();\n\n // useEffect(() => {\n // if (unstable_prefetchOnView && process.env.EXPO_OS === 'web' && ref.current) {\n // const observer = new IntersectionObserver(\n // (entries) => {\n // entries.forEach((entry) => {\n // if (entry.isIntersecting) {\n // const url = new URL(resolvedHref, getHref());\n // if (router && url.href !== getHref()) {\n // const route = parseRoute(url);\n // router.prefetchRoute(route);\n // }\n // }\n // });\n // },\n // { threshold: 0.1 }\n // );\n\n // observer.observe(ref.current);\n\n // return () => {\n // observer.disconnect();\n // };\n // }\n // return () => {};\n // }, [unstable_prefetchOnView, router, resolvedHref]);\n\n const onClick = (event: MouseEvent<HTMLAnchorElement>) => {\n event.preventDefault();\n const url = new URL(resolvedHref, getHref());\n // TODO: Use in-memory route for native platforms.\n // if (url.href !== getHref()) {\n const route = parseRoute(url);\n prefetchRoute(route);\n startTransition(() => {\n getHistory().pushState(\n {\n ...getHistory().state,\n expo_new_path: url.pathname !== window.location.pathname,\n },\n '',\n url\n );\n changeRoute(route);\n });\n // }\n props.onClick?.(event);\n };\n // const onMouseEnter = unstable_prefetchOnEnter\n // ? (event: MouseEvent<HTMLAnchorElement>) => {\n // const url = new URL(to, getHref());\n // if (url.href !== getHref()) {\n // const route = parseRoute(url);\n // prefetchRoute(route);\n // }\n // props.onMouseEnter?.(event);\n // }\n // : props.onMouseEnter;\n\n const Element = asChild ? ReactSlot : Text;\n\n const ele = createElement(\n // @ts-expect-error\n Element,\n {\n ...hrefAttrs,\n ...props,\n style,\n href: resolvedHref,\n onPress: onClick,\n // onMouseEnter,\n ref,\n },\n children\n );\n // if (isPending && pending !== undefined) {\n // return createElement(Fragment, null, ele, pending);\n // }\n // if (!isPending && notPending !== undefined) {\n // return createElement(Fragment, null, ele, notPending);\n // }\n return ele;\n}\n"]}
|
|
@@ -127,6 +127,7 @@ function groupRouteNodes(routeNode, groupedContextKeys = {
|
|
|
127
127
|
// Not all generated files will have the `/` prefix
|
|
128
128
|
routeKey = `/${routeKey}`;
|
|
129
129
|
}
|
|
130
|
+
routeKey = routeKey.replace(/\\/g, '/');
|
|
130
131
|
if (routeNode.dynamic) {
|
|
131
132
|
groupedContextKeys.dynamic.set(routeKey, routeKey
|
|
132
133
|
.split('/')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/typed-routes/generate.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,0CAAwD;AAGxD,oCAAoC;AACpC,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,6BAA6B;AAC7B,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,2DAA2D;AAC3D,MAAM,KAAK,GAAG,kBAAkB,CAAC;AAEjC,MAAM,SAAS,GAAG,qCAAqC,CAAC;AAOxD,SAAgB,6BAA6B,CAC3C,GAAmB,EACnB,EACE,kBAAkB,GAAG,KAAK,EAC1B,kBAAkB,GAAG,KAAK,MACc,EAAE;IAE5C,IAAI,SAAS,GAAqB,IAAI,CAAC;IAEvC,IAAI;QACF,SAAS,GAAG,IAAA,qBAAS,EAAC,GAAG,EAAE;YACzB,MAAM,EAAE,CAAC,mBAAmB,CAAC;YAC7B,cAAc,EAAE,KAAK;YACrB,QAAQ,EAAE,KAAK;YACf,iBAAiB,EAAE,IAA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E;YAC3C,2CAA2C;YAC3C,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;YACvE,4CAA4C;YAC5C,IAAI,kBAAkB,EAAE;gBACtB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACzB;YACD,gCAAgC;YAChC,OAAO,MAAM,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;SAC1C;aAAM;YACL,OAAO,KAAK,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,iBAAiB,GAAG,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;IAEhE;;;;OAIG;IACH,IAAI,iBAAiB,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC3C,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;KAC7C;IAED,OAAO,KAAK,cAAc,UAAU,iBAAiB,IAAI,CAAC;AAC5D,CAAC","sourcesContent":["import { RouteNode } from '../Route';\nimport { getRoutes } from '../getRoutes';\nimport { removeSupportedExtensions } from '../matchers';\nimport { RequireContext } from '../types';\n\n// /[...param1]/ - Match [...param1]\nconst CATCH_ALL = /\\[\\.\\.\\..+?\\]/g;\n// /[param1] - Match [param1]\nconst SLUG = /\\[.+?\\]/g;\n// /(group)/path/(group2)/route - Match [(group), (group2)]\nconst GROUP = /(?:^|\\/)\\(.*?\\)/g;\n\nconst urlParams = \"${`?${string}` | `#${string}` | ''}\";\n\nexport type GetTypedRoutesDeclarationFileOptions = {\n partialTypedGroups?: boolean;\n testIgnoreComments?: boolean;\n};\n\nexport function getTypedRoutesDeclarationFile(\n ctx: RequireContext,\n {\n partialTypedGroups = false,\n testIgnoreComments = false,\n }: GetTypedRoutesDeclarationFileOptions = {}\n) {\n let routeNode: RouteNode | null = null;\n\n try {\n routeNode = getRoutes(ctx, {\n ignore: [/_layout\\.[tj]sx?$/], // Skip layout files\n platformRoutes: false, // We don't need to generate platform specific routes\n notFound: false, // We don't need +not-found routes either\n ignoreEntryPoints: true,\n ignoreRequireErrors: true,\n importMode: 'async', // Don't load the file\n });\n } catch {\n // Ignore errors from `getRoutes`. This is also called inside the app, which has\n // a nicer UX for showing error messages\n }\n\n const groupedNodes = groupRouteNodes(routeNode);\n const staticRoutesStrings: string[] = ['Router.RelativePathString', 'Router.ExternalPathString'];\n const staticRouteInputObjects: string[] = [\n '{ pathname: Router.RelativePathString, params?: Router.UnknownInputParams }',\n '{ pathname: Router.ExternalPathString, params?: Router.UnknownInputParams }',\n ];\n const staticRouteOutputObjects: string[] = [\n '{ pathname: Router.RelativePathString, params?: Router.UnknownOutputParams }',\n '{ pathname: Router.ExternalPathString, params?: Router.UnknownOutputParams }',\n ];\n\n for (const type of groupedNodes.static) {\n staticRoutesStrings.push(contextKeyToType(type + urlParams, partialTypedGroups));\n staticRouteInputObjects.push(\n `{ pathname: ${contextKeyToType(type, partialTypedGroups)}; params?: Router.UnknownInputParams; }`\n );\n staticRouteOutputObjects.push(\n `{ pathname: ${contextKeyToType(type, partialTypedGroups)}; params?: Router.UnknownOutputParams; }`\n );\n }\n\n const dynamicRouteStrings: string[] = [];\n const dynamicRouteInputObjects: string[] = [];\n const dynamicRouteOutputObjects: string[] = [];\n\n for (const [dynamicRouteTemplate, paramsNames] of groupedNodes.dynamic) {\n const inputParams = paramsNames\n .map((param) => {\n const key = param.startsWith('...') ? param.slice(3) : param;\n const value = param.startsWith('...') ? '(string | number)[]' : 'string | number';\n return `${key}: ${value};`;\n })\n .join('');\n\n const outputParams = paramsNames\n .map((param) => {\n const key = param.startsWith('...') ? param.slice(3) : param;\n const value = param.startsWith('...') ? 'string[]' : 'string';\n return `${key}: ${value};`;\n })\n .join('');\n\n dynamicRouteStrings.push(\n contextKeyToType(\n dynamicRouteTemplate\n .replaceAll(CATCH_ALL, '${string}')\n .replaceAll(SLUG, '${Router.SingleRoutePart<T>}'),\n partialTypedGroups\n )\n );\n\n dynamicRouteInputObjects.push(\n `{ pathname: ${contextKeyToType(dynamicRouteTemplate, partialTypedGroups)}, params: Router.UnknownInputParams & { ${inputParams} } }`\n );\n dynamicRouteOutputObjects.push(\n `{ pathname: ${contextKeyToType(dynamicRouteTemplate, partialTypedGroups)}, params: Router.UnknownOutputParams & { ${outputParams} } }`\n );\n }\n\n const href = [\n ...staticRoutesStrings,\n ...staticRouteInputObjects,\n ...dynamicRouteStrings,\n ...dynamicRouteInputObjects,\n ].join(' | ');\n\n const hrefInputParams = [...staticRouteInputObjects, ...dynamicRouteInputObjects].join(' | ');\n const hrefOutputParams = [...staticRouteOutputObjects, ...dynamicRouteOutputObjects].join(' | ');\n\n const tsExpectError = testIgnoreComments\n ? '// @ts-ignore-error -- During tests we need to ignore the \"duplicate\" declaration error, as multiple fixture declare types \\n '\n : '';\n\n return `/* eslint-disable */\nimport * as Router from 'expo-router';\n\nexport * from 'expo-router';\n\ndeclare module 'expo-router' {\n export namespace ExpoRouter {\n export interface __routes<T extends string | object = string> {\n ${tsExpectError}hrefInputParams: ${hrefInputParams};\n ${tsExpectError}hrefOutputParams: ${hrefOutputParams};\n ${tsExpectError}href: ${href};\n }\n }\n}\n`;\n}\n\nfunction groupRouteNodes(\n routeNode: RouteNode | null,\n groupedContextKeys = {\n static: new Set<string>(),\n dynamic: new Map<string, string[]>(),\n }\n) {\n if (!routeNode) {\n return groupedContextKeys;\n }\n\n // Skip non-route files\n if (routeNode.type !== 'route') {\n // Except the root layout\n if (routeNode.route === '') {\n for (const child of routeNode.children) {\n groupRouteNodes(child, groupedContextKeys);\n }\n return groupedContextKeys;\n }\n\n return groupedContextKeys;\n }\n\n let routeKey: string;\n\n if (routeNode.generated) {\n // Some routes like the root _layout, _sitemap, +not-found are generated.\n // We cannot use the contextKey, as their context key does not specify a route\n routeKey = routeNode.route;\n } else {\n routeKey = removeSupportedExtensions(routeNode.contextKey)\n .replace(/\\/index$/, '') // Remove any trailing /index\n .replace(/^\\./, ''); // Remove any leading .\n }\n\n routeKey ||= '/'; // A routeKey may be empty for contextKey '' or './index.js'\n\n if (!routeKey.startsWith('/')) {\n // Not all generated files will have the `/` prefix\n routeKey = `/${routeKey}`;\n }\n\n if (routeNode.dynamic) {\n groupedContextKeys.dynamic.set(\n routeKey,\n routeKey\n .split('/')\n .filter((segment) => {\n return segment.startsWith('[') && segment.endsWith(']');\n })\n .map((segment) => {\n return segment.slice(1, -1);\n })\n );\n } else {\n groupedContextKeys.static.add(routeKey);\n }\n\n for (const child of routeNode.children) {\n groupRouteNodes(child, groupedContextKeys);\n }\n\n return groupedContextKeys;\n}\n\nfunction contextKeyToType(contextKey: string, partialTypedGroups: boolean) {\n if (contextKey.match(GROUP) === null) {\n return `\\`${contextKey}\\``;\n }\n\n // If the route has groups, turn them into template strings\n const typeWithGroups = contextKey.replaceAll(GROUP, (match) => {\n const groups = match.slice(2, -1); // Remove the leading ( and the trailing )\n // When `partialRoutes` is enabled, we always change a group to a template\n if (groups.length > 1 || partialTypedGroups) {\n // Ensure each group has the trailing slash\n const groupsAsType = groups.split(',').map((group) => `'/(${group})'`);\n // `partialRoutes` allow you to skip a group\n if (partialTypedGroups) {\n groupsAsType.push(\"''\");\n }\n // Combine together into a union\n return `\\${${groupsAsType.join(' | ')}}`;\n } else {\n return match;\n }\n });\n\n let typeWithoutGroups = contextKey.replaceAll(GROUP, '') || '/';\n\n /**\n * When getting the static routes, they include a urlParams string at the end.\n * If we have a route like `/(group)/(group2)`, this would normally be collapsed to `/`.\n * But because of the urlParams, it becomes `${urlParams}` and we need to add a `/` to the start.\n */\n if (typeWithoutGroups.startsWith(urlParams)) {\n typeWithoutGroups = `/${typeWithoutGroups}`;\n }\n\n return `\\`${typeWithGroups}\\` | \\`${typeWithoutGroups}\\``;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/typed-routes/generate.ts"],"names":[],"mappings":";;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;KAC7C;IAED,OAAO,KAAK,cAAc,UAAU,iBAAiB,IAAI,CAAC;AAC5D,CAAC","sourcesContent":["import { RouteNode } from '../Route';\nimport { getRoutes } from '../getRoutes';\nimport { removeSupportedExtensions } from '../matchers';\nimport { RequireContext } from '../types';\n\n// /[...param1]/ - Match [...param1]\nconst CATCH_ALL = /\\[\\.\\.\\..+?\\]/g;\n// /[param1] - Match [param1]\nconst SLUG = /\\[.+?\\]/g;\n// /(group)/path/(group2)/route - Match [(group), (group2)]\nconst GROUP = /(?:^|\\/)\\(.*?\\)/g;\n\nconst urlParams = \"${`?${string}` | `#${string}` | ''}\";\n\nexport type GetTypedRoutesDeclarationFileOptions = {\n partialTypedGroups?: boolean;\n testIgnoreComments?: boolean;\n};\n\nexport function getTypedRoutesDeclarationFile(\n ctx: RequireContext,\n {\n partialTypedGroups = false,\n testIgnoreComments = false,\n }: GetTypedRoutesDeclarationFileOptions = {}\n) {\n let routeNode: RouteNode | null = null;\n\n try {\n routeNode = getRoutes(ctx, {\n ignore: [/_layout\\.[tj]sx?$/], // Skip layout files\n platformRoutes: false, // We don't need to generate platform specific routes\n notFound: false, // We don't need +not-found routes either\n ignoreEntryPoints: true,\n ignoreRequireErrors: true,\n importMode: 'async', // Don't load the file\n });\n } catch {\n // Ignore errors from `getRoutes`. This is also called inside the app, which has\n // a nicer UX for showing error messages\n }\n\n const groupedNodes = groupRouteNodes(routeNode);\n const staticRoutesStrings: string[] = ['Router.RelativePathString', 'Router.ExternalPathString'];\n const staticRouteInputObjects: string[] = [\n '{ pathname: Router.RelativePathString, params?: Router.UnknownInputParams }',\n '{ pathname: Router.ExternalPathString, params?: Router.UnknownInputParams }',\n ];\n const staticRouteOutputObjects: string[] = [\n '{ pathname: Router.RelativePathString, params?: Router.UnknownOutputParams }',\n '{ pathname: Router.ExternalPathString, params?: Router.UnknownOutputParams }',\n ];\n\n for (const type of groupedNodes.static) {\n staticRoutesStrings.push(contextKeyToType(type + urlParams, partialTypedGroups));\n staticRouteInputObjects.push(\n `{ pathname: ${contextKeyToType(type, partialTypedGroups)}; params?: Router.UnknownInputParams; }`\n );\n staticRouteOutputObjects.push(\n `{ pathname: ${contextKeyToType(type, partialTypedGroups)}; params?: Router.UnknownOutputParams; }`\n );\n }\n\n const dynamicRouteStrings: string[] = [];\n const dynamicRouteInputObjects: string[] = [];\n const dynamicRouteOutputObjects: string[] = [];\n\n for (const [dynamicRouteTemplate, paramsNames] of groupedNodes.dynamic) {\n const inputParams = paramsNames\n .map((param) => {\n const key = param.startsWith('...') ? param.slice(3) : param;\n const value = param.startsWith('...') ? '(string | number)[]' : 'string | number';\n return `${key}: ${value};`;\n })\n .join('');\n\n const outputParams = paramsNames\n .map((param) => {\n const key = param.startsWith('...') ? param.slice(3) : param;\n const value = param.startsWith('...') ? 'string[]' : 'string';\n return `${key}: ${value};`;\n })\n .join('');\n\n dynamicRouteStrings.push(\n contextKeyToType(\n dynamicRouteTemplate\n .replaceAll(CATCH_ALL, '${string}')\n .replaceAll(SLUG, '${Router.SingleRoutePart<T>}'),\n partialTypedGroups\n )\n );\n\n dynamicRouteInputObjects.push(\n `{ pathname: ${contextKeyToType(dynamicRouteTemplate, partialTypedGroups)}, params: Router.UnknownInputParams & { ${inputParams} } }`\n );\n dynamicRouteOutputObjects.push(\n `{ pathname: ${contextKeyToType(dynamicRouteTemplate, partialTypedGroups)}, params: Router.UnknownOutputParams & { ${outputParams} } }`\n );\n }\n\n const href = [\n ...staticRoutesStrings,\n ...staticRouteInputObjects,\n ...dynamicRouteStrings,\n ...dynamicRouteInputObjects,\n ].join(' | ');\n\n const hrefInputParams = [...staticRouteInputObjects, ...dynamicRouteInputObjects].join(' | ');\n const hrefOutputParams = [...staticRouteOutputObjects, ...dynamicRouteOutputObjects].join(' | ');\n\n const tsExpectError = testIgnoreComments\n ? '// @ts-ignore-error -- During tests we need to ignore the \"duplicate\" declaration error, as multiple fixture declare types \\n '\n : '';\n\n return `/* eslint-disable */\nimport * as Router from 'expo-router';\n\nexport * from 'expo-router';\n\ndeclare module 'expo-router' {\n export namespace ExpoRouter {\n export interface __routes<T extends string | object = string> {\n ${tsExpectError}hrefInputParams: ${hrefInputParams};\n ${tsExpectError}hrefOutputParams: ${hrefOutputParams};\n ${tsExpectError}href: ${href};\n }\n }\n}\n`;\n}\n\nfunction groupRouteNodes(\n routeNode: RouteNode | null,\n groupedContextKeys = {\n static: new Set<string>(),\n dynamic: new Map<string, string[]>(),\n }\n) {\n if (!routeNode) {\n return groupedContextKeys;\n }\n\n // Skip non-route files\n if (routeNode.type !== 'route') {\n // Except the root layout\n if (routeNode.route === '') {\n for (const child of routeNode.children) {\n groupRouteNodes(child, groupedContextKeys);\n }\n return groupedContextKeys;\n }\n\n return groupedContextKeys;\n }\n\n let routeKey: string;\n\n if (routeNode.generated) {\n // Some routes like the root _layout, _sitemap, +not-found are generated.\n // We cannot use the contextKey, as their context key does not specify a route\n routeKey = routeNode.route;\n } else {\n routeKey = removeSupportedExtensions(routeNode.contextKey)\n .replace(/\\/index$/, '') // Remove any trailing /index\n .replace(/^\\./, ''); // Remove any leading .\n }\n\n routeKey ||= '/'; // A routeKey may be empty for contextKey '' or './index.js'\n\n if (!routeKey.startsWith('/')) {\n // Not all generated files will have the `/` prefix\n routeKey = `/${routeKey}`;\n }\n\n routeKey = routeKey.replace(/\\\\/g, '/');\n\n if (routeNode.dynamic) {\n groupedContextKeys.dynamic.set(\n routeKey,\n routeKey\n .split('/')\n .filter((segment) => {\n return segment.startsWith('[') && segment.endsWith(']');\n })\n .map((segment) => {\n return segment.slice(1, -1);\n })\n );\n } else {\n groupedContextKeys.static.add(routeKey);\n }\n\n for (const child of routeNode.children) {\n groupRouteNodes(child, groupedContextKeys);\n }\n\n return groupedContextKeys;\n}\n\nfunction contextKeyToType(contextKey: string, partialTypedGroups: boolean) {\n if (contextKey.match(GROUP) === null) {\n return `\\`${contextKey}\\``;\n }\n\n // If the route has groups, turn them into template strings\n const typeWithGroups = contextKey.replaceAll(GROUP, (match) => {\n const groups = match.slice(2, -1); // Remove the leading ( and the trailing )\n // When `partialRoutes` is enabled, we always change a group to a template\n if (groups.length > 1 || partialTypedGroups) {\n // Ensure each group has the trailing slash\n const groupsAsType = groups.split(',').map((group) => `'/(${group})'`);\n // `partialRoutes` allow you to skip a group\n if (partialTypedGroups) {\n groupsAsType.push(\"''\");\n }\n // Combine together into a union\n return `\\${${groupsAsType.join(' | ')}}`;\n } else {\n return match;\n }\n });\n\n let typeWithoutGroups = contextKey.replaceAll(GROUP, '') || '/';\n\n /**\n * When getting the static routes, they include a urlParams string at the end.\n * If we have a route like `/(group)/(group2)`, this would normally be collapsed to `/`.\n * But because of the urlParams, it becomes `${urlParams}` and we need to add a `/` to the start.\n */\n if (typeWithoutGroups.startsWith(urlParams)) {\n typeWithoutGroups = `/${typeWithoutGroups}`;\n }\n\n return `\\`${typeWithGroups}\\` | \\`${typeWithoutGroups}\\``;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-router",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
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",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"expo-linking": "*",
|
|
81
81
|
"react-native-reanimated": "*",
|
|
82
82
|
"react-native-safe-area-context": "*",
|
|
83
|
-
"react-native-screens": "
|
|
83
|
+
"react-native-screens": "*"
|
|
84
84
|
},
|
|
85
85
|
"peerDependenciesMeta": {
|
|
86
86
|
"react-native-reanimated": {
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"semver": "~7.6.3",
|
|
118
118
|
"server-only": "^0.0.1"
|
|
119
119
|
},
|
|
120
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "eb0d9b5b6ba8dd5b64e016e41166e42ced543a69"
|
|
121
121
|
}
|