first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import type { NavigationState, PartialState } from '@react-navigation/native';
import type { FocusedRouteState } from './router-store';
export type UrlObject = {
unstable_globalHref: string;
pathname: string;
readonly params: Record<string, string | string[]>;
searchParams: URLSearchParams;
segments: string[];
pathnameWithParams: string;
isIndex: boolean;
};
export declare const defaultRouteInfo: UrlObject;
/**
* A better typed version of `FocusedRouteState` that is easier to parse
*/
type StrictState = (FocusedRouteState | NavigationState | PartialState<NavigationState>) & {
routes: {
key?: string;
name: string;
params?: StrictFocusedRouteParams;
path?: string;
state?: StrictState;
}[];
};
type StrictFocusedRouteParams = Record<string, string | string[]> | {
screen?: string;
params?: StrictFocusedRouteParams;
};
export declare function getRouteInfoFromState(state?: StrictState): UrlObject;
export {};
//# sourceMappingURL=routeInfo.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"routeInfo.d.ts","sourceRoot":"","sources":["../../src/global-state/routeInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,MAAM,MAAM,SAAS,GAAG;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACnD,YAAY,EAAE,eAAe,CAAC;IAC9B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,SAS9B,CAAC;AAEF;;GAEG;AACH,KAAK,WAAW,GAAG,CAAC,iBAAiB,GAAG,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC,GAAG;IACzF,MAAM,EAAE;QACN,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,wBAAwB,CAAC;QAClC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,EAAE,CAAC;CACL,CAAC;AAEF,KAAK,wBAAwB,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,GACjC;IACE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,wBAAwB,CAAC;CACnC,CAAC;AAEN,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,CAuKpE"}

View File

@@ -0,0 +1,172 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultRouteInfo = void 0;
exports.getRouteInfoFromState = getRouteInfoFromState;
const constants_1 = require("../constants");
const getPathFromState_forks_1 = require("../fork/getPathFromState-forks");
exports.defaultRouteInfo = {
unstable_globalHref: '',
searchParams: new URLSearchParams(),
pathname: '/',
params: {},
segments: [],
pathnameWithParams: '/',
// TODO: Remove this, it is not used anywhere
isIndex: false,
};
function getRouteInfoFromState(state) {
if (!state)
return exports.defaultRouteInfo;
const index = 'index' in state ? (state.index ?? 0) : 0;
let route = state.routes[index];
if (route.name === constants_1.NOT_FOUND_ROUTE_NAME || route.name === constants_1.SITEMAP_ROUTE_NAME) {
const path = route.path || (route.name === constants_1.NOT_FOUND_ROUTE_NAME ? '/' : `/${route.name}`);
return {
...exports.defaultRouteInfo,
unstable_globalHref: (0, getPathFromState_forks_1.appendBaseUrl)(path),
pathname: path,
pathnameWithParams: path,
segments: [route.name],
};
}
if (route.name !== constants_1.INTERNAL_SLOT_NAME) {
throw new Error(`Expected the first route to be ${constants_1.INTERNAL_SLOT_NAME}, but got ${route.name}`);
}
state = route.state;
const segments = [];
let params = Object.create(null);
while (state) {
route = state.routes['index' in state && state.index ? state.index : 0];
Object.assign(params, route.params);
let routeName = route.name;
if (routeName.startsWith('/')) {
routeName = routeName.slice(1);
}
segments.push(...routeName.split('/'));
state = route.state;
}
params = Object.fromEntries(Object.entries(params).map(([key, value]) => {
if (typeof value === 'string') {
return [key, safeDecodeURIComponent(value)];
}
else if (Array.isArray(value)) {
return [key, value.map((v) => safeDecodeURIComponent(v))];
}
else {
return [key, value];
}
}));
/**
* If React Navigation didn't render the entire tree (e.g it was interrupted in a layout)
* then the state maybe incomplete. The reset of the path is in the params, instead of being a route
*/
let routeParams = route.params;
while (routeParams && 'screen' in routeParams) {
if (typeof routeParams.screen === 'string') {
const screen = routeParams.screen.startsWith('/')
? routeParams.screen.slice(1)
: routeParams.screen;
segments.push(...screen.split('/'));
}
if (typeof routeParams.params === 'object' && !Array.isArray(routeParams.params)) {
routeParams = routeParams.params;
}
else {
routeParams = undefined;
}
}
if (route.params && 'screen' in route.params && route.params.screen === 'string') {
const screen = route.params.screen.startsWith('/')
? route.params.screen.slice(1)
: route.params.screen;
segments.push(...screen.split('/'));
}
if (segments[segments.length - 1] === 'index') {
segments.pop();
}
delete params['screen'];
delete params['params'];
const pathParams = new Set();
const pathname = '/' +
segments
.filter((segment) => {
return !(segment.startsWith('(') && segment.endsWith(')'));
})
.flatMap((segment) => {
if (segment === '+not-found') {
const notFoundPath = params['not-found'];
pathParams.add('not-found');
if (typeof notFoundPath === 'undefined') {
// Not founds are optional, do nothing if its not present
return [];
}
else if (Array.isArray(notFoundPath)) {
return notFoundPath;
}
else {
return [notFoundPath];
}
}
else if (segment.startsWith('[...') && segment.endsWith(']')) {
let paramName = segment.slice(4, -1);
// Legacy for React Navigation optional params
if (paramName.endsWith('?')) {
paramName = paramName.slice(0, -1);
}
const values = params[paramName];
pathParams.add(paramName);
// Catchall params are optional
return values || [];
}
else if (segment.startsWith('[') && segment.endsWith(']')) {
const paramName = segment.slice(1, -1);
const value = params[paramName];
pathParams.add(paramName);
// Optional params are optional
return value ? [value] : [];
}
else {
return [segment];
}
})
.join('/');
const searchParams = new URLSearchParams(Object.entries(params).flatMap(([key, value]) => {
// Search params should not include path params
if (pathParams.has(key)) {
return [];
}
else if (Array.isArray(value)) {
return value.map((v) => [key, v]);
}
return [[key, value]];
}));
let hash;
if (searchParams.has('#')) {
hash = searchParams.get('#') || undefined;
searchParams.delete('#');
}
// We cannot use searchParams.size because it is not included in the React Native polyfill
const searchParamString = searchParams.toString();
let pathnameWithParams = searchParamString ? pathname + '?' + searchParamString : pathname;
pathnameWithParams = hash ? pathnameWithParams + '#' + hash : pathnameWithParams;
return {
segments,
pathname,
params,
unstable_globalHref: (0, getPathFromState_forks_1.appendBaseUrl)(pathnameWithParams),
searchParams,
pathnameWithParams,
// TODO: Remove this, it is not used anywhere
isIndex: false,
};
}
function safeDecodeURIComponent(value) {
try {
return typeof value === 'string' ? decodeURIComponent(value) : value;
}
catch {
// If the value is not a valid URI component, return it as is
return value;
}
}
//# sourceMappingURL=routeInfo.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,92 @@
import { NavigationContainerRefWithCurrent, NavigationState, PartialState, useStateForPath } from '@react-navigation/native';
import { ComponentType } from 'react';
import { RouteNode } from '../Route';
import { ExpoLinkingOptions, LinkingConfigOptions } from '../getLinkingConfig';
import { RedirectConfig } from '../getRoutesCore';
import { UrlObject } from './routeInfo';
import { RequireContext, type Href } from '../types';
import { type LinkToOptions } from './routing';
export type StoreRedirects = readonly [RegExp, RedirectConfig, boolean];
export type ReactNavigationState = NavigationState | PartialState<NavigationState>;
export type FocusedRouteState = NonNullable<ReturnType<typeof useStateForPath>>;
export type RouterStore = typeof store;
export declare const store: {
shouldShowTutorial(): boolean;
readonly state: ReactNavigationState | undefined;
readonly navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
readonly routeNode: RouteNode | null;
getRouteInfo(): UrlObject;
readonly redirects: StoreRedirects[];
readonly rootComponent: ComponentType<any>;
getStateForHref(href: Href, options?: LinkToOptions): (Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/native").NavigationRoute<import("@react-navigation/native").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/native").PartialRoute<import("@react-navigation/native").Route<string, object | undefined>>[];
}> & {
state?: Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/native").NavigationRoute<import("@react-navigation/native").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/native").PartialRoute<import("@react-navigation/native").Route<string, object | undefined>>[];
}> & /*elided*/ any;
}) | undefined;
readonly linking: ExpoLinkingOptions | undefined;
setFocusedState(state: FocusedRouteState): void;
onReady(): void;
onStateChange(newState: ReactNavigationState | undefined): void;
assertIsReady(): void;
};
export declare function useStore(context: RequireContext, linkingConfigOptions: LinkingConfigOptions, serverUrl?: string): {
shouldShowTutorial(): boolean;
readonly state: ReactNavigationState | undefined;
readonly navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
readonly routeNode: RouteNode | null;
getRouteInfo(): UrlObject;
readonly redirects: StoreRedirects[];
readonly rootComponent: ComponentType<any>;
getStateForHref(href: Href, options?: LinkToOptions): (Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/native").NavigationRoute<import("@react-navigation/native").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/native").PartialRoute<import("@react-navigation/native").Route<string, object | undefined>>[];
}> & {
state?: Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/native").NavigationRoute<import("@react-navigation/native").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/native").PartialRoute<import("@react-navigation/native").Route<string, object | undefined>>[];
}> & /*elided*/ any;
}) | undefined;
readonly linking: ExpoLinkingOptions | undefined;
setFocusedState(state: FocusedRouteState): void;
onReady(): void;
onStateChange(newState: ReactNavigationState | undefined): void;
assertIsReady(): void;
};
export declare function useRouteInfo(): UrlObject;
//# sourceMappingURL=router-store.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EACjC,eAAe,EACf,YAAY,EAEZ,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,aAAa,EAA6C,MAAM,OAAO,CAAC;AAGjF,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAoB,MAAM,qBAAqB,CAAC;AAGjG,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAA2C,SAAS,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAK/C,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;AACxE,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;AACnF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG,OAAO,KAAK,CAAC;AAwBvC,eAAO,MAAM,KAAK;;;;;oBAaA,SAAS;;;0BASH,IAAI,YAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;2BAS5B,iBAAiB;;4BAahB,oBAAoB,GAAG,SAAS;;CAwCzD,CAAC;AAEF,wBAAgB,QAAQ,CACtB,OAAO,EAAE,cAAc,EACvB,oBAAoB,EAAE,oBAAoB,EAC1C,SAAS,CAAC,EAAE,MAAM;;;;;oBA5EF,SAAS;;;0BASH,IAAI,YAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;2BAS5B,iBAAiB;;4BAahB,oBAAoB,GAAG,SAAS;;EA6IzD;AAUD,wBAAgB,YAAY,IAAI,SAAS,CAmBxC"}

View File

@@ -0,0 +1,263 @@
"use strict";
'use client';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.store = void 0;
exports.useStore = useStore;
exports.useRouteInfo = useRouteInfo;
const native_1 = require("@react-navigation/native");
const expo_constants_1 = __importDefault(require("expo-constants"));
const react_1 = require("react");
const react_native_1 = require("react-native");
const extractPathFromURL_1 = require("../fork/extractPathFromURL");
const getStateFromPath_forks_1 = require("../fork/getStateFromPath-forks");
const getLinkingConfig_1 = require("../getLinkingConfig");
const getReactNavigationConfig_1 = require("../getReactNavigationConfig");
const getRoutes_1 = require("../getRoutes");
const routeInfo_1 = require("./routeInfo");
const href_1 = require("../link/href");
const useScreens_1 = require("../useScreens");
const PreviewRouteContext_1 = require("../link/preview/PreviewRouteContext");
const url_1 = require("../utils/url");
const SplashScreen = __importStar(require("../views/Splash"));
const storeRef = {
current: {},
};
const routeInfoCache = new WeakMap();
const routeInfoValuesCache = new Map();
let splashScreenAnimationFrame;
let hasAttemptedToHideSplash = false;
exports.store = {
shouldShowTutorial() {
return !storeRef.current.routeNode && process.env.NODE_ENV === 'development';
},
get state() {
return storeRef.current.state;
},
get navigationRef() {
return storeRef.current.navigationRef;
},
get routeNode() {
return storeRef.current.routeNode;
},
getRouteInfo() {
return storeRef.current.routeInfo || routeInfo_1.defaultRouteInfo;
},
get redirects() {
return storeRef.current.redirects || [];
},
get rootComponent() {
return storeRef.current.rootComponent;
},
getStateForHref(href, options) {
href = (0, href_1.resolveHref)(href);
href = (0, href_1.resolveHrefStringWithSegments)(href, exports.store.getRouteInfo(), options);
return this.linking?.getStateFromPath(href, this.linking.config);
},
get linking() {
return storeRef.current.linking;
},
setFocusedState(state) {
const routeInfo = getCachedRouteInfo(state);
storeRef.current.routeInfo = routeInfo;
},
onReady() {
if (!hasAttemptedToHideSplash) {
hasAttemptedToHideSplash = true;
// NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.
splashScreenAnimationFrame = requestAnimationFrame(() => {
SplashScreen._internal_maybeHideAsync?.();
});
}
},
onStateChange(newState) {
if (!newState) {
return;
}
if (process.env.NODE_ENV === 'development') {
let isStale = false;
let state = newState;
while (!isStale && state) {
isStale = state.stale;
state =
state.routes?.['index' in state && typeof state.index === 'number'
? state.index
: state.routes.length - 1]?.state;
}
if (isStale) {
// This should never happen, as onStateChange should provide a full state. However, adding this check to catch any undocumented behavior.
console.error('Detected stale state in onStateChange. This is likely a bug in Expo Router.');
}
}
storeRef.current.state = newState;
storeRef.current.routeInfo = getCachedRouteInfo(newState);
for (const callback of routeInfoSubscribers) {
callback();
}
},
assertIsReady() {
if (!storeRef.current.navigationRef.isReady()) {
throw new Error('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.');
}
},
};
function useStore(context, linkingConfigOptions, serverUrl) {
const navigationRef = (0, native_1.useNavigationContainerRef)();
const config = expo_constants_1.default.expoConfig?.extra?.router;
let linking;
let rootComponent = react_1.Fragment;
let initialState;
const routeNode = (0, getRoutes_1.getRoutes)(context, {
...config,
skipGenerated: true,
ignoreEntryPoints: true,
platform: react_native_1.Platform.OS,
preserveRedirectAndRewrites: true,
});
const redirects = [config?.redirects, config?.rewrites]
.filter(Boolean)
.flat()
.map((route) => {
return [
(0, getStateFromPath_forks_1.routePatternToRegex)((0, getReactNavigationConfig_1.parseRouteSegments)(route.source)),
route,
(0, url_1.shouldLinkExternally)(route.destination),
];
});
if (routeNode) {
// We have routes, so get the linking config and the root component
linking = (0, getLinkingConfig_1.getLinkingConfig)(routeNode, context, () => exports.store.getRouteInfo(), {
metaOnly: linkingConfigOptions.metaOnly,
serverUrl,
redirects,
skipGenerated: config?.skipGenerated ?? false,
sitemap: config?.sitemap ?? true,
notFound: config?.notFound ?? true,
});
rootComponent = (0, useScreens_1.getQualifiedRouteComponent)(routeNode);
// By default React Navigation is async and does not render anything in the first pass as it waits for `getInitialURL`
// This will cause static rendering to fail, which once performs a single pass.
// If the initialURL is a string, we can prefetch the state and routeInfo, skipping React Navigation's async behavior.
const initialURL = linking?.getInitialURL?.();
if (typeof initialURL === 'string') {
let initialPath = (0, extractPathFromURL_1.extractExpoPathFromURL)(linking.prefixes, initialURL);
// It does not matter if the path starts with a `/` or not, but this keeps the behavior consistent
if (!initialPath.startsWith('/'))
initialPath = '/' + initialPath;
initialState = linking.getStateFromPath(initialPath, linking.config);
const initialRouteInfo = (0, routeInfo_1.getRouteInfoFromState)(initialState);
routeInfoCache.set(initialState, initialRouteInfo);
routeInfoValuesCache.set(JSON.stringify(initialRouteInfo), initialRouteInfo);
}
}
else {
// Only error in production, in development we will show the onboarding screen
if (process.env.NODE_ENV === 'production') {
throw new Error('No routes found');
}
// In development, we will show the onboarding screen
rootComponent = react_1.Fragment;
}
if (react_native_1.Platform.OS === 'android' && storeRef.current.state && storeRef.current.context === context) {
initialState = storeRef.current.state;
}
storeRef.current = {
navigationRef,
routeNode,
config,
rootComponent,
linking,
redirects,
state: initialState,
context,
};
if (initialState) {
storeRef.current.routeInfo = getCachedRouteInfo(initialState);
}
(0, react_1.useEffect)(() => {
return () => {
// listener();
if (splashScreenAnimationFrame) {
cancelAnimationFrame(splashScreenAnimationFrame);
splashScreenAnimationFrame = undefined;
}
};
});
return exports.store;
}
const routeInfoSubscribers = new Set();
const routeInfoSubscribe = (callback) => {
routeInfoSubscribers.add(callback);
return () => {
routeInfoSubscribers.delete(callback);
};
};
function useRouteInfo() {
const routeInfo = (0, react_1.useSyncExternalStore)(routeInfoSubscribe, exports.store.getRouteInfo, exports.store.getRouteInfo);
const { isPreview, segments, params, pathname } = (0, PreviewRouteContext_1.usePreviewInfo)();
if (isPreview) {
return {
pathname: pathname ?? '',
segments: segments ?? [],
unstable_globalHref: '',
params: params ?? {},
searchParams: new URLSearchParams(),
pathnameWithParams: pathname ?? '',
isIndex: false,
};
}
return routeInfo;
}
function getCachedRouteInfo(state) {
let routeInfo = routeInfoCache.get(state);
if (!routeInfo) {
routeInfo = (0, routeInfo_1.getRouteInfoFromState)(state);
const routeInfoString = JSON.stringify(routeInfo);
// Using cached values to avoid re-renders, to increase the chance that the object reference is the same
const cachedRouteInfo = routeInfoValuesCache.get(routeInfoString);
if (cachedRouteInfo) {
routeInfo = cachedRouteInfo;
}
else {
routeInfoValuesCache.set(routeInfoString, routeInfo);
}
routeInfoCache.set(state, routeInfo);
}
return routeInfo;
}
//# sourceMappingURL=router-store.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,87 @@
import { NavigationAction, type NavigationState, PartialRoute, type PartialState, type NavigationContainerRef, ParamListBase } from '@react-navigation/native';
import { type RefObject } from 'react';
import { ResultState } from '../fork/getStateFromPath';
import { Href } from '../types';
import { SingularOptions } from '../useScreens';
interface LinkAction {
type: 'ROUTER_LINK';
payload: {
options: LinkToOptions;
href: string;
};
}
export declare const routingQueue: {
queue: (NavigationAction | LinkAction)[];
subscribers: Set<() => void>;
subscribe(callback: () => void): () => void;
snapshot(): (Readonly<{
type: string;
payload?: object;
source?: string;
target?: string;
}> | LinkAction)[];
add(action: NavigationAction | LinkAction): void;
run(ref: RefObject<NavigationContainerRef<ParamListBase> | null>): void;
};
export type NavigationOptions = Omit<LinkToOptions, 'event'>;
export declare function navigate(url: Href, options?: NavigationOptions): void;
export declare function reload(): void;
export declare function prefetch(href: Href, options?: NavigationOptions): void;
export declare function push(url: Href, options?: NavigationOptions): void;
export declare function dismiss(count?: number): void;
export declare function dismissTo(href: Href, options?: NavigationOptions): void;
export declare function replace(url: Href, options?: NavigationOptions): void;
export declare function dismissAll(): void;
export declare function goBack(): void;
export declare function canGoBack(): boolean;
export declare function canDismiss(): boolean;
export declare function setParams(params?: Record<string, undefined | string | number | (string | number)[]>): any;
export type LinkToOptions = {
event?: string;
/**
* Relative URL references are either relative to the directory or the document. By default, relative paths are relative to the document.
* @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).
*/
relativeToDirectory?: boolean;
/**
* Include the anchor when navigating to a new navigator
*/
withAnchor?: boolean;
/**
* When navigating in a Stack, remove all screen from the history that match the singular condition
*
* If used with `push`, the history will be filtered even if no navigation occurs.
*/
dangerouslySingular?: SingularOptions;
__internal__PreviewKey?: string;
};
export declare function linkTo(originalHref: Href, options?: LinkToOptions): void;
/**
* React Navigation uses params to store information about the screens, rather then create new state for each level.
* This function traverses the action state that will not be part of state and returns a payload that can be used in action.
*/
export declare function getPayloadFromStateRoute(_actionStateRoute: PartialRoute<any>): Record<string, any>;
export declare function findDivergentState(_actionState: ResultState, _navigationState: NavigationState, lookThroughAllTabs?: boolean): {
actionState: PartialState<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
type: string;
stale: false;
}>>;
navigationState: Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
type: string;
stale: false;
}>;
actionStateRoute: PartialRoute<any> | undefined;
navigationRoutes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
};
export {};
//# sourceMappingURL=routing.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,eAAe,EACpB,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,aAAa,EACd,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAWvC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAWhD,UAAU,UAAU;IAClB,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE;QACP,OAAO,EAAE,aAAa,CAAC;QACvB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,eAAO,MAAM,YAAY;WACV,CAAC,gBAAgB,GAAG,UAAU,CAAC,EAAE;2BACnB,IAAI;wBACX,MAAM,IAAI;;;;;;;gBASlB,gBAAgB,GAAG,UAAU;aAMhC,SAAS,CAAC,sBAAsB,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;CA6BjE,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAE7D,wBAAgB,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,QAE9D;AAED,wBAAgB,MAAM,SAGrB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,QAE/D;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,QAE1D;AAED,wBAAgB,OAAO,CAAC,KAAK,GAAE,MAAU,QAMxC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,QAEhE;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,iBAAiB,QAE7D;AAED,wBAAgB,UAAU,SAKzB;AAED,wBAAgB,MAAM,SAMrB;AAED,wBAAgB,SAAS,IAAI,OAAO,CAenC;AAED,wBAAgB,UAAU,IAAI,OAAO,CAmBpC;AAED,wBAAgB,SAAS,CACvB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAM,OAO/E;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;IAErB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,eAAe,CAAC;IAEtC,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,wBAAgB,MAAM,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,GAAE,aAAkB,QA4CrE;AAoHD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,iBAAiB,EAAE,YAAY,CAAC,GAAG,CAAC,uBAwB5E;AAKD,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,WAAW,EACzB,gBAAgB,EAAE,eAAe,EAEjC,kBAAkB,GAAE,OAAe;;;;;;;;;;;;;;;;;;;;;EAoDpC"}

378
node_modules/expo-router/build/global-state/routing.js generated vendored Normal file
View File

@@ -0,0 +1,378 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.routingQueue = void 0;
exports.navigate = navigate;
exports.reload = reload;
exports.prefetch = prefetch;
exports.push = push;
exports.dismiss = dismiss;
exports.dismissTo = dismissTo;
exports.replace = replace;
exports.dismissAll = dismissAll;
exports.goBack = goBack;
exports.canGoBack = canGoBack;
exports.canDismiss = canDismiss;
exports.setParams = setParams;
exports.linkTo = linkTo;
exports.getPayloadFromStateRoute = getPayloadFromStateRoute;
exports.findDivergentState = findDivergentState;
const dom_1 = require("expo/dom");
const Linking = __importStar(require("expo-linking"));
const react_native_1 = require("react-native");
const router_store_1 = require("./router-store");
const emitDomEvent_1 = require("../domComponents/emitDomEvent");
const getRoutesRedirects_1 = require("../getRoutesRedirects");
const href_1 = require("../link/href");
const matchers_1 = require("../matchers");
const navigationParams_1 = require("../navigationParams");
const url_1 = require("../utils/url");
function assertIsReady() {
if (!router_store_1.store.navigationRef.isReady()) {
throw new Error('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.');
}
}
exports.routingQueue = {
queue: [],
subscribers: new Set(),
subscribe(callback) {
exports.routingQueue.subscribers.add(callback);
return () => {
exports.routingQueue.subscribers.delete(callback);
};
},
snapshot() {
return exports.routingQueue.queue;
},
add(action) {
exports.routingQueue.queue.push(action);
for (const callback of exports.routingQueue.subscribers) {
callback();
}
},
run(ref) {
// Reset the identity of the queue.
const events = exports.routingQueue.queue;
exports.routingQueue.queue = [];
let action;
while ((action = events.shift())) {
if (ref.current) {
if (action.type === 'ROUTER_LINK') {
const { payload: { href, options }, } = action;
action = getNavigateAction(href, options, options.event, options.withAnchor, options.dangerouslySingular, !!options.__internal__PreviewKey);
if (action) {
ref.current.dispatch(action);
}
}
else {
ref.current.dispatch(action);
}
}
}
},
};
function navigate(url, options) {
return linkTo((0, href_1.resolveHref)(url), { ...options, event: 'NAVIGATE' });
}
function reload() {
// TODO(EvanBacon): add `reload` support.
throw new Error('The reload method is not implemented in the client-side router yet.');
}
function prefetch(href, options) {
return linkTo((0, href_1.resolveHref)(href), { ...options, event: 'PRELOAD' });
}
function push(url, options) {
return linkTo((0, href_1.resolveHref)(url), { ...options, event: 'PUSH' });
}
function dismiss(count = 1) {
if ((0, emitDomEvent_1.emitDomDismiss)(count)) {
return;
}
exports.routingQueue.add({ type: 'POP', payload: { count } });
}
function dismissTo(href, options) {
return linkTo((0, href_1.resolveHref)(href), { ...options, event: 'POP_TO' });
}
function replace(url, options) {
return linkTo((0, href_1.resolveHref)(url), { ...options, event: 'REPLACE' });
}
function dismissAll() {
if ((0, emitDomEvent_1.emitDomDismissAll)()) {
return;
}
exports.routingQueue.add({ type: 'POP_TO_TOP' });
}
function goBack() {
if ((0, emitDomEvent_1.emitDomGoBack)()) {
return;
}
assertIsReady();
exports.routingQueue.add({ type: 'GO_BACK' });
}
function canGoBack() {
if (dom_1.IS_DOM) {
throw new Error('canGoBack imperative method is not supported. Pass the property to the DOM component instead.');
}
// Return a default value here if the navigation hasn't mounted yet.
// This can happen if the user calls `canGoBack` from the Root Layout route
// before mounting a navigator. This behavior exists due to React Navigation being dynamically
// constructed at runtime. We can get rid of this in the future if we use
// the static configuration internally.
if (!router_store_1.store.navigationRef.isReady()) {
return false;
}
return router_store_1.store.navigationRef?.current?.canGoBack() ?? false;
}
function canDismiss() {
if (dom_1.IS_DOM) {
throw new Error('canDismiss imperative method is not supported. Pass the property to the DOM component instead.');
}
let state = router_store_1.store.state;
// Keep traversing down the state tree until we find a stack navigator that we can pop
while (state) {
if (state.type === 'stack' && state.routes.length > 1) {
return true;
}
if (state.index === undefined)
return false;
state = state.routes?.[state.index]?.state;
}
return false;
}
function setParams(params = {}) {
if ((0, emitDomEvent_1.emitDomSetParams)(params)) {
return;
}
assertIsReady();
return (router_store_1.store.navigationRef?.current?.setParams)(params);
}
function linkTo(originalHref, options = {}) {
originalHref = typeof originalHref == 'string' ? originalHref : (0, href_1.resolveHref)(originalHref);
let href = originalHref;
if ((0, emitDomEvent_1.emitDomLinkEvent)(href, options)) {
return;
}
if ((0, url_1.shouldLinkExternally)(href)) {
if (href.startsWith('//') && react_native_1.Platform.OS !== 'web') {
href = `https:${href}`;
}
Linking.openURL(href);
return;
}
if (href === '..' || href === '../') {
assertIsReady();
const navigationRef = router_store_1.store.navigationRef.current;
if (navigationRef == null) {
throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
}
if (!router_store_1.store.linking) {
throw new Error('Attempted to link to route when no routes are present');
}
navigationRef.goBack();
return;
}
const linkAction = {
type: 'ROUTER_LINK',
payload: {
href,
options,
},
};
exports.routingQueue.add(linkAction);
}
function getNavigateAction(baseHref, options, type = 'NAVIGATE', withAnchor, singular, isPreviewNavigation) {
let href = baseHref;
assertIsReady();
const navigationRef = router_store_1.store.navigationRef.current;
if (navigationRef == null) {
throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
}
if (!router_store_1.store.linking) {
throw new Error('Attempted to link to route when no routes are present');
}
const rootState = navigationRef.getRootState();
href = (0, href_1.resolveHrefStringWithSegments)(href, router_store_1.store.getRouteInfo(), options);
href = (0, getRoutesRedirects_1.applyRedirects)(href, router_store_1.store.redirects) ?? undefined;
// If the href is undefined, it means that the redirect has already been handled the navigation
if (!href) {
return;
}
const state = router_store_1.store.linking.getStateFromPath(href, router_store_1.store.linking.config);
if (!state || state.routes.length === 0) {
console.error('Could not generate a valid navigation state for the given path: ' + href);
return;
}
/**
* We need to find the deepest navigator where the action and current state diverge, If they do not diverge, the
* lowest navigator is the target.
*
* By default React Navigation will target the current navigator, but this doesn't work for all actions
* For example:
* - /deeply/nested/route -> /top-level-route the target needs to be the top-level navigator
* - /stack/nestedStack/page -> /stack1/nestedStack/other-page needs to target the nestedStack navigator
*
* This matching needs to done by comparing the route names and the dynamic path, for example
* - /1/page -> /2/anotherPage needs to target the /[id] navigator
*
* Other parameters such as search params and hash are not evaluated.
*/
const { actionStateRoute, navigationState } = findDivergentState(state, rootState, type === 'PRELOAD');
/*
* We found the target navigator, but the payload is in the incorrect format
* We need to convert the action state to a payload that can be dispatched
*/
const rootPayload = getPayloadFromStateRoute(actionStateRoute || {});
if (type === 'PUSH' && navigationState.type !== 'stack') {
type = 'NAVIGATE';
}
else if (navigationState.type === 'expo-tab') {
type = 'JUMP_TO';
}
else if (type === 'REPLACE' && navigationState.type === 'drawer') {
type = 'JUMP_TO';
}
if (withAnchor) {
if (rootPayload.params.initial) {
if (process.env.NODE_ENV !== 'production') {
console.warn(`The parameter 'initial' is a reserved parameter name in React Navigation`);
}
}
/*
* The logic for initial can seen backwards depending on your perspective
* True: The initialRouteName is not loaded. The incoming screen is the initial screen (default)
* False: The initialRouteName is loaded. THe incoming screen is placed after the initialRouteName
*
* withAnchor flips the perspective.
* True: You want the initialRouteName to load.
* False: You do not want the initialRouteName to load.
*/
// Set initial on root and all nested params so anchors are loaded at every level
let currentParams = rootPayload.params;
while (currentParams) {
currentParams.initial = !withAnchor;
currentParams = currentParams.params;
}
}
const expoParams = isPreviewNavigation
? {
[navigationParams_1.INTERNAL_EXPO_ROUTER_IS_PREVIEW_NAVIGATION_PARAM_NAME]: true,
[navigationParams_1.INTERNAL_EXPO_ROUTER_NO_ANIMATION_PARAM_NAME]: true,
}
: {};
const params = (0, navigationParams_1.appendInternalExpoRouterParams)(rootPayload.params, expoParams);
return {
type,
target: navigationState.key,
payload: {
// key: rootPayload.key,
name: rootPayload.screen,
params,
singular,
},
};
}
/**
* React Navigation uses params to store information about the screens, rather then create new state for each level.
* This function traverses the action state that will not be part of state and returns a payload that can be used in action.
*/
function getPayloadFromStateRoute(_actionStateRoute) {
const rootPayload = { params: {} };
let payload = rootPayload;
let params = payload.params;
let actionStateRoute = _actionStateRoute;
while (actionStateRoute) {
Object.assign(params, { ...payload.params, ...actionStateRoute.params });
// Assign the screen name to the payload
payload.screen = actionStateRoute.name;
// Merge the params, ensuring that we create a new object
payload.params = { ...params };
// Params don't include the screen, thats a separate attribute
delete payload.params['screen'];
// Continue down the payload tree
// Initially these values are separate, but React Nav merges them after the first layer
payload = payload.params;
params = payload;
actionStateRoute = actionStateRoute.state?.routes[actionStateRoute.state?.routes.length - 1];
}
return rootPayload;
}
/*
* Traverse the state tree comparing the current state and the action state until we find where they diverge
*/
function findDivergentState(_actionState, _navigationState,
// If true, look through all tabs to find the target state, rather then just the current tab
lookThroughAllTabs = false) {
let actionState = _actionState;
let navigationState = _navigationState;
let actionStateRoute;
const navigationRoutes = [];
while (actionState && navigationState) {
actionStateRoute = actionState.routes[actionState.routes.length - 1];
const stateRoute = (() => {
if (navigationState.type === 'tab' && lookThroughAllTabs) {
return (navigationState.routes.find((route) => route.name === actionStateRoute?.name) ||
navigationState.routes[navigationState.index ?? 0]);
}
return navigationState.routes[navigationState.index ?? 0];
})();
const childState = actionStateRoute.state;
const nextNavigationState = stateRoute.state;
const dynamicName = (0, matchers_1.matchDynamicName)(actionStateRoute.name);
const didActionAndCurrentStateDiverge = actionStateRoute.name !== stateRoute.name ||
!childState ||
!nextNavigationState ||
(dynamicName &&
// @ts-expect-error: TODO(@kitten): This isn't properly typed, so the index access fails
actionStateRoute.params?.[dynamicName.name] !== stateRoute.params?.[dynamicName.name]);
if (didActionAndCurrentStateDiverge) {
// If we are looking through all tabs, we need to add new tab id if this is the last route
// Otherwise we wouldn't be able to change the tab
if (navigationState.type === 'tab' && lookThroughAllTabs) {
navigationRoutes.push(stateRoute);
}
break;
}
navigationRoutes.push(stateRoute);
actionState = childState;
navigationState = nextNavigationState;
}
return {
actionState,
navigationState,
actionStateRoute,
navigationRoutes,
};
}
//# sourceMappingURL=routing.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
export type ServerContextType = {
location?: {
pathname: string;
search: string;
};
};
export declare const ServerContext: import("react").Context<ServerContextType | undefined>;
//# sourceMappingURL=serverLocationContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"serverLocationContext.d.ts","sourceRoot":"","sources":["../../src/global-state/serverLocationContext.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,aAAa,wDAA0D,CAAC"}

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServerContext = void 0;
// This is file should mirror https://github.com/react-navigation/react-navigation/blob/6.x/packages/native/src/ServerContext.tsx
const react_1 = require("react");
exports.ServerContext = (0, react_1.createContext)(undefined);
//# sourceMappingURL=serverLocationContext.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"serverLocationContext.js","sourceRoot":"","sources":["../../src/global-state/serverLocationContext.ts"],"names":[],"mappings":";;;AAAA,iIAAiI;AACjI,iCAAsC;AASzB,QAAA,aAAa,GAAG,IAAA,qBAAa,EAAgC,SAAS,CAAC,CAAC","sourcesContent":["// This is file should mirror https://github.com/react-navigation/react-navigation/blob/6.x/packages/native/src/ServerContext.tsx\nimport { createContext } from 'react';\n\nexport type ServerContextType = {\n location?: {\n pathname: string;\n search: string;\n };\n};\n\nexport const ServerContext = createContext<ServerContextType | undefined>(undefined);\n"]}

View File

@@ -0,0 +1,3 @@
import type { RouterStore } from './router-store';
export declare function getSortedRoutes(this: RouterStore): import("../Route").RouteNode[];
//# sourceMappingURL=sort-routes.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sort-routes.d.ts","sourceRoot":"","sources":["../../src/global-state/sort-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,kCAMhD"}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSortedRoutes = getSortedRoutes;
const Route_1 = require("../Route");
function getSortedRoutes() {
if (!this.routeNode) {
throw new Error('No routes found');
}
return this.routeNode.children.filter((route) => !route.internal).sort(Route_1.sortRoutes);
}
//# sourceMappingURL=sort-routes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sort-routes.js","sourceRoot":"","sources":["../../src/global-state/sort-routes.ts"],"names":[],"mappings":";;AAGA,0CAMC;AARD,oCAAsC;AAEtC,SAAgB,eAAe;IAC7B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,kBAAU,CAAC,CAAC;AACrF,CAAC","sourcesContent":["import type { RouterStore } from './router-store';\nimport { sortRoutes } from '../Route';\n\nexport function getSortedRoutes(this: RouterStore) {\n if (!this.routeNode) {\n throw new Error('No routes found');\n }\n\n return this.routeNode.children.filter((route) => !route.internal).sort(sortRoutes);\n}\n"]}

View File

@@ -0,0 +1,79 @@
export declare const StoreContext: import("react").Context<{
shouldShowTutorial(): boolean;
readonly state: import("./router-store").ReactNavigationState | undefined;
readonly navigationRef: import("@react-navigation/core").NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
readonly routeNode: import("../Route").RouteNode | null;
getRouteInfo(): import("./routeInfo").UrlObject;
readonly redirects: import("./router-store").StoreRedirects[];
readonly rootComponent: import("react").ComponentType<any>;
getStateForHref(href: import("..").Href, options?: import("./routing").LinkToOptions): (Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/routers").NavigationRoute<import("@react-navigation/routers").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/routers").PartialRoute<import("@react-navigation/routers").Route<string, object | undefined>>[];
}> & {
state?: Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/routers").NavigationRoute<import("@react-navigation/routers").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/routers").PartialRoute<import("@react-navigation/routers").Route<string, object | undefined>>[];
}> & /*elided*/ any;
}) | undefined;
readonly linking: import("../getLinkingConfig").ExpoLinkingOptions | undefined;
setFocusedState(state: import("./router-store").FocusedRouteState): void;
onReady(): void;
onStateChange(newState: import("./router-store").ReactNavigationState | undefined): void;
assertIsReady(): void;
} | null>;
export declare const useExpoRouterStore: () => {
shouldShowTutorial(): boolean;
readonly state: import("./router-store").ReactNavigationState | undefined;
readonly navigationRef: import("@react-navigation/core").NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;
readonly routeNode: import("../Route").RouteNode | null;
getRouteInfo(): import("./routeInfo").UrlObject;
readonly redirects: import("./router-store").StoreRedirects[];
readonly rootComponent: import("react").ComponentType<any>;
getStateForHref(href: import("..").Href, options?: import("./routing").LinkToOptions): (Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/routers").NavigationRoute<import("@react-navigation/routers").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/routers").PartialRoute<import("@react-navigation/routers").Route<string, object | undefined>>[];
}> & {
state?: Partial<Omit<Readonly<{
key: string;
index: number;
routeNames: string[];
history?: unknown[];
routes: import("@react-navigation/routers").NavigationRoute<import("@react-navigation/routers").ParamListBase, string>[];
type: string;
stale: false;
}>, "stale" | "routes">> & Readonly<{
stale?: true;
routes: import("@react-navigation/routers").PartialRoute<import("@react-navigation/routers").Route<string, object | undefined>>[];
}> & /*elided*/ any;
}) | undefined;
readonly linking: import("../getLinkingConfig").ExpoLinkingOptions | undefined;
setFocusedState(state: import("./router-store").FocusedRouteState): void;
onReady(): void;
onStateChange(newState: import("./router-store").ReactNavigationState | undefined): void;
assertIsReady(): void;
};
//# sourceMappingURL=storeContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"storeContext.d.ts","sourceRoot":"","sources":["../../src/global-state/storeContext.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA0C,CAAC;AAEpE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA2B,CAAC"}

View File

@@ -0,0 +1,9 @@
"use strict";
'use client';
Object.defineProperty(exports, "__esModule", { value: true });
exports.useExpoRouterStore = exports.StoreContext = void 0;
const react_1 = require("react");
exports.StoreContext = (0, react_1.createContext)(null);
const useExpoRouterStore = () => (0, react_1.use)(exports.StoreContext);
exports.useExpoRouterStore = useExpoRouterStore;
//# sourceMappingURL=storeContext.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"storeContext.js","sourceRoot":"","sources":["../../src/global-state/storeContext.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AACb,iCAA2C;AAI9B,QAAA,YAAY,GAAG,IAAA,qBAAa,EAAqB,IAAI,CAAC,CAAC;AAE7D,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,IAAA,WAAG,EAAC,oBAAY,CAAE,CAAC;AAA9C,QAAA,kBAAkB,sBAA4B","sourcesContent":["'use client';\nimport { createContext, use } from 'react';\n\nimport { RouterStore } from './router-store';\n\nexport const StoreContext = createContext<RouterStore | null>(null);\n\nexport const useExpoRouterStore = () => use(StoreContext)!;\n"]}

View File

@@ -0,0 +1,6 @@
export declare function shouldAppendSitemap(): boolean;
export declare function shouldAppendNotFound(): boolean;
export declare function shouldReactToColorSchemeChanges(): boolean;
export declare const useColorSchemeChangesIfNeeded: () => void;
export declare function getRootStackRouteNames(): string[];
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/global-state/utils.ts"],"names":[],"mappings":"AAKA,wBAAgB,mBAAmB,YAGlC;AAED,wBAAgB,oBAAoB,YAGnC;AAED,wBAAgB,+BAA+B,YAG9C;AAID,eAAO,MAAM,6BAA6B,YAExB,CAAC;AAEnB,wBAAgB,sBAAsB,aASrC"}

41
node_modules/expo-router/build/global-state/utils.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useColorSchemeChangesIfNeeded = void 0;
exports.shouldAppendSitemap = shouldAppendSitemap;
exports.shouldAppendNotFound = shouldAppendNotFound;
exports.shouldReactToColorSchemeChanges = shouldReactToColorSchemeChanges;
exports.getRootStackRouteNames = getRootStackRouteNames;
const expo_constants_1 = __importDefault(require("expo-constants"));
const react_native_1 = require("react-native");
const constants_1 = require("../constants");
function shouldAppendSitemap() {
const config = expo_constants_1.default.expoConfig?.extra?.router;
return config?.sitemap !== false;
}
function shouldAppendNotFound() {
const config = expo_constants_1.default.expoConfig?.extra?.router;
return config?.notFound !== false;
}
function shouldReactToColorSchemeChanges() {
const config = expo_constants_1.default.expoConfig?.extra?.router;
return config?.adaptiveColors !== false;
}
// TODO(@ubax): Replace this with a custom theme provider, once we can pass ColorValue objects through the React Navigation theme.
// https://linear.app/expo/issue/ENG-19168/replace-global-usecolorschme-with-a-custom-theme-provider-once-we-can
exports.useColorSchemeChangesIfNeeded = shouldReactToColorSchemeChanges()
? react_native_1.useColorScheme
: function () { };
function getRootStackRouteNames() {
const routes = [constants_1.INTERNAL_SLOT_NAME];
if (shouldAppendNotFound()) {
routes.push(constants_1.NOT_FOUND_ROUTE_NAME);
}
if (shouldAppendSitemap()) {
routes.push(constants_1.SITEMAP_ROUTE_NAME);
}
return routes;
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/global-state/utils.ts"],"names":[],"mappings":";;;;;;AAKA,kDAGC;AAED,oDAGC;AAED,0EAGC;AAQD,wDASC;AAnCD,oEAAuC;AACvC,+CAA8C;AAE9C,4CAA4F;AAE5F,SAAgB,mBAAmB;IACjC,MAAM,MAAM,GAAG,wBAAS,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC;IACnD,OAAO,MAAM,EAAE,OAAO,KAAK,KAAK,CAAC;AACnC,CAAC;AAED,SAAgB,oBAAoB;IAClC,MAAM,MAAM,GAAG,wBAAS,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC;IACnD,OAAO,MAAM,EAAE,QAAQ,KAAK,KAAK,CAAC;AACpC,CAAC;AAED,SAAgB,+BAA+B;IAC7C,MAAM,MAAM,GAAG,wBAAS,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC;IACnD,OAAO,MAAM,EAAE,cAAc,KAAK,KAAK,CAAC;AAC1C,CAAC;AAED,kIAAkI;AAClI,gHAAgH;AACnG,QAAA,6BAA6B,GAAG,+BAA+B,EAAE;IAC5E,CAAC,CAAC,6BAAc;IAChB,CAAC,CAAC,cAAa,CAAC,CAAC;AAEnB,SAAgB,sBAAsB;IACpC,MAAM,MAAM,GAAG,CAAC,8BAAkB,CAAC,CAAC;IACpC,IAAI,oBAAoB,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,IAAI,CAAC,gCAAoB,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,mBAAmB,EAAE,EAAE,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,8BAAkB,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport { useColorScheme } from 'react-native';\n\nimport { INTERNAL_SLOT_NAME, NOT_FOUND_ROUTE_NAME, SITEMAP_ROUTE_NAME } from '../constants';\n\nexport function shouldAppendSitemap() {\n const config = Constants.expoConfig?.extra?.router;\n return config?.sitemap !== false;\n}\n\nexport function shouldAppendNotFound() {\n const config = Constants.expoConfig?.extra?.router;\n return config?.notFound !== false;\n}\n\nexport function shouldReactToColorSchemeChanges() {\n const config = Constants.expoConfig?.extra?.router;\n return config?.adaptiveColors !== false;\n}\n\n// TODO(@ubax): Replace this with a custom theme provider, once we can pass ColorValue objects through the React Navigation theme.\n// https://linear.app/expo/issue/ENG-19168/replace-global-usecolorschme-with-a-custom-theme-provider-once-we-can\nexport const useColorSchemeChangesIfNeeded = shouldReactToColorSchemeChanges()\n ? useColorScheme\n : function () {};\n\nexport function getRootStackRouteNames() {\n const routes = [INTERNAL_SLOT_NAME];\n if (shouldAppendNotFound()) {\n routes.push(NOT_FOUND_ROUTE_NAME);\n }\n if (shouldAppendSitemap()) {\n routes.push(SITEMAP_ROUTE_NAME);\n }\n return routes;\n}\n"]}