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

21
node_modules/@react-navigation/routers/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 React Navigation Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

17
node_modules/@react-navigation/routers/README.md generated vendored Normal file
View File

@@ -0,0 +1,17 @@
# `@react-navigation/routers`
Routers to help build custom navigators.
You probably don't need to use this package directly if you're not building custom navigators.
## Installation
Open a Terminal in your project's folder and run,
```sh
npm install @react-navigation/routers
```
## Usage
Documentation can be found on the [React Navigation website](https://reactnavigation.org/docs/custom-routers/).

View File

@@ -0,0 +1,57 @@
"use strict";
import { nanoid } from 'nanoid/non-secure';
/**
* Base router object that can be used when writing custom routers.
* This provides few helper methods to handle common actions such as `RESET`.
*/
export const BaseRouter = {
getStateForAction(state, action) {
switch (action.type) {
case 'SET_PARAMS':
case 'REPLACE_PARAMS':
{
const index = action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
if (index === -1) {
return null;
}
return {
...state,
routes: state.routes.map((r, i) => i === index ? {
...r,
params: action.type === 'REPLACE_PARAMS' ? action.payload.params : {
...r.params,
...action.payload.params
}
} : r)
};
}
case 'RESET':
{
const nextState = action.payload;
if (nextState.routes.length === 0 || nextState.routes.some(route => !state.routeNames.includes(route.name))) {
return null;
}
if (nextState.stale === false) {
if (state.routeNames.length !== nextState.routeNames.length || nextState.routeNames.some(name => !state.routeNames.includes(name))) {
return null;
}
return {
...nextState,
routes: nextState.routes.map(route => route.key ? route : {
...route,
key: `${route.name}-${nanoid()}`
})
};
}
return nextState;
}
default:
return null;
}
},
shouldActionChangeFocus(action) {
return action.type === 'NAVIGATE' || action.type === 'NAVIGATE_DEPRECATED';
}
};
//# sourceMappingURL=BaseRouter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["nanoid","BaseRouter","getStateForAction","state","action","type","index","source","routes","findIndex","r","key","map","i","params","payload","nextState","length","some","route","routeNames","includes","name","stale","shouldActionChangeFocus"],"sourceRoot":"../../src","sources":["BaseRouter.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAQ1C;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG;EACxBC,iBAAiBA,CACfC,KAAY,EACZC,MAA8B,EACM;IACpC,QAAQA,MAAM,CAACC,IAAI;MACjB,KAAK,YAAY;MACjB,KAAK,gBAAgB;QAAE;UACrB,MAAMC,KAAK,GAAGF,MAAM,CAACG,MAAM,GACvBJ,KAAK,CAACK,MAAM,CAACC,SAAS,CAAEC,CAAC,IAAKA,CAAC,CAACC,GAAG,KAAKP,MAAM,CAACG,MAAM,CAAC,GACtDJ,KAAK,CAACG,KAAK;UAEf,IAAIA,KAAK,KAAK,CAAC,CAAC,EAAE;YAChB,OAAO,IAAI;UACb;UAEA,OAAO;YACL,GAAGH,KAAK;YACRK,MAAM,EAAEL,KAAK,CAACK,MAAM,CAACI,GAAG,CAAC,CAACF,CAAC,EAAEG,CAAC,KAC5BA,CAAC,KAAKP,KAAK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I,KAAK,qBAAqB;EAC5E;AACF,CAAC","ignoreList":[]}

View File

@@ -0,0 +1,85 @@
"use strict";
export function goBack() {
return {
type: 'GO_BACK'
};
}
export function navigate(...args) {
if (typeof args[0] === 'string') {
const [name, params, options] = args;
if (typeof options === 'boolean') {
console.warn(`Passing a boolean as the third argument to 'navigate' is deprecated. Pass '{ merge: true }' instead.`);
}
return {
type: 'NAVIGATE',
payload: {
name,
params,
merge: typeof options === 'boolean' ? options : options?.merge,
pop: options?.pop
}
};
} else {
const payload = args[0] || {};
if (!('name' in payload)) {
throw new Error('You need to specify a name when calling navigate with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigate for usage.');
}
return {
type: 'NAVIGATE',
payload
};
}
}
export function navigateDeprecated(...args) {
if (typeof args[0] === 'string') {
return {
type: 'NAVIGATE_DEPRECATED',
payload: {
name: args[0],
params: args[1]
}
};
} else {
const payload = args[0] || {};
if (!('name' in payload)) {
throw new Error('You need to specify a name when calling navigateDeprecated with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigatelegacy for usage.');
}
return {
type: 'NAVIGATE_DEPRECATED',
payload
};
}
}
export function reset(state) {
return {
type: 'RESET',
payload: state
};
}
export function setParams(params) {
return {
type: 'SET_PARAMS',
payload: {
params
}
};
}
export function replaceParams(params) {
return {
type: 'REPLACE_PARAMS',
payload: {
params
}
};
}
export function preload(name, params) {
return {
type: 'PRELOAD',
payload: {
name,
params
}
};
}
//# sourceMappingURL=CommonActions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["goBack","type","navigate","args","name","params","options","console","warn","payload","merge","pop","Error","navigateDeprecated","reset","state","setParams","replaceParams","preload"],"sourceRoot":"../../src","sources":["CommonActions.tsx"],"mappings":";;AA+EA,OAAO,SAASA,MAAMA,CAAA,EAAW;EAC/B,OAAO;IAAEC,IAAI,EAAE;EAAU,CAAC;AAC5B;AAmBA,OAAO,SAASC,QAAQA,CAAC,GAAGC,IAAS,EAAU;EAC7C,IAAI,OAAOA,I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ACC,KAA6B,EAAE;EACnD,OAAO;IAAEd,IAAI,EAAE,OAAO;IAAEQ,OAAO,EAAEM;EAAM,CAAC;AAC1C;AAEA,OAAO,SAASC,SAASA,CAACX,MAAc,EAAE;EACxC,OAAO;IACLJ,IAAI,EAAE,YAAY;IAClBQ,OAAO,EAAE;MAAEJ;IAAO;EACpB,CAAC;AACH;AAEA,OAAO,SAASY,aAAaA,CAACZ,MAAc,EAAE;EAC5C,OAAO;IACLJ,IAAI,EAAE,gBAAgB;IACtBQ,OAAO,EAAE;MAAEJ;IAAO;EACpB,CAAC;AACH;AAEA,OAAO,SAASa,OAAOA,CAACd,IAAY,EAAEC,MAAe,EAAE;EACrD,OAAO;IACLJ,IAAI,EAAE,SAAS;IACfQ,OAAO,EAAE;MAAEL,IAAI;MAAEC;IAAO;EAC1B,CAAC;AACH","ignoreList":[]}

View File

@@ -0,0 +1,145 @@
"use strict";
import { nanoid } from 'nanoid/non-secure';
import { TabActions, TabRouter } from "./TabRouter.js";
export const DrawerActions = {
...TabActions,
openDrawer() {
return {
type: 'OPEN_DRAWER'
};
},
closeDrawer() {
return {
type: 'CLOSE_DRAWER'
};
},
toggleDrawer() {
return {
type: 'TOGGLE_DRAWER'
};
}
};
export function DrawerRouter({
defaultStatus = 'closed',
...rest
}) {
const router = TabRouter(rest);
const isDrawerInHistory = state => Boolean(state.history?.some(it => it.type === 'drawer'));
const addDrawerToHistory = state => {
if (isDrawerInHistory(state)) {
return state;
}
return {
...state,
history: [...state.history, {
type: 'drawer',
status: defaultStatus === 'open' ? 'closed' : 'open'
}]
};
};
const removeDrawerFromHistory = state => {
if (!isDrawerInHistory(state)) {
return state;
}
return {
...state,
history: state.history.filter(it => it.type !== 'drawer')
};
};
const openDrawer = state => {
if (defaultStatus === 'open') {
return removeDrawerFromHistory(state);
}
return addDrawerToHistory(state);
};
const closeDrawer = state => {
if (defaultStatus === 'open') {
return addDrawerToHistory(state);
}
return removeDrawerFromHistory(state);
};
return {
...router,
type: 'drawer',
getInitialState({
routeNames,
routeParamList,
routeGetIdList
}) {
const state = router.getInitialState({
routeNames,
routeParamList,
routeGetIdList
});
return {
...state,
default: defaultStatus,
stale: false,
type: 'drawer',
key: `drawer-${nanoid()}`
};
},
getRehydratedState(partialState, {
routeNames,
routeParamList,
routeGetIdList
}) {
if (partialState.stale === false) {
return partialState;
}
let state = router.getRehydratedState(partialState, {
routeNames,
routeParamList,
routeGetIdList
});
if (isDrawerInHistory(partialState)) {
// Re-sync the drawer entry in history to correct it if it was wrong
state = removeDrawerFromHistory(state);
state = addDrawerToHistory(state);
}
return {
...state,
default: defaultStatus,
type: 'drawer',
key: `drawer-${nanoid()}`
};
},
getStateForRouteFocus(state, key) {
const result = router.getStateForRouteFocus(state, key);
return closeDrawer(result);
},
getStateForAction(state, action, options) {
switch (action.type) {
case 'OPEN_DRAWER':
return openDrawer(state);
case 'CLOSE_DRAWER':
return closeDrawer(state);
case 'TOGGLE_DRAWER':
if (isDrawerInHistory(state)) {
return removeDrawerFromHistory(state);
}
return addDrawerToHistory(state);
case 'JUMP_TO':
case 'NAVIGATE':
case 'NAVIGATE_DEPRECATED':
{
const result = router.getStateForAction(state, action, options);
if (result != null && result.index !== state.index) {
return closeDrawer(result);
}
return result;
}
case 'GO_BACK':
if (isDrawerInHistory(state)) {
return removeDrawerFromHistory(state);
}
return router.getStateForAction(state, action, options);
default:
return router.getStateForAction(state, action, options);
}
},
actionCreators: DrawerActions
};
}
//# sourceMappingURL=DrawerRouter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["nanoid","TabActions","TabRouter","DrawerActions","openDrawer","type","closeDrawer","toggleDrawer","DrawerRouter","defaultStatus","rest","router","isDrawerInHistory","state","Boolean","history","some","it","addDrawerToHistory","status","removeDrawerFromHistory","filter","getInitialState","routeNames","routeParamList","routeGetIdList","default","stale","key","getRehydratedState","partialState","getStateForRouteFocus","result","getStateForAction","action","options","index","actionCreators"],"sourceRoot":"../../src","sources":["DrawerRouter.tsx"],"mappings":";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iB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;MAC3D;IACF,CAAC;IAEDE,cAAc,EAAElC;EAClB,CAAC;AACH","ignoreList":[]}

View File

@@ -0,0 +1,483 @@
"use strict";
import { nanoid } from 'nanoid/non-secure';
import { BaseRouter } from "./BaseRouter.js";
import { createParamsFromAction } from "./createParamsFromAction.js";
import { createRouteFromAction } from "./createRouteFromAction.js";
export const StackActions = {
replace(name, params) {
return {
type: 'REPLACE',
payload: {
name,
params
}
};
},
push(name, params) {
return {
type: 'PUSH',
payload: {
name,
params
}
};
},
pop(count = 1) {
return {
type: 'POP',
payload: {
count
}
};
},
popToTop() {
return {
type: 'POP_TO_TOP'
};
},
popTo(name, params, options) {
if (typeof options === 'boolean') {
console.warn(`Passing a boolean as the third argument to 'popTo' is deprecated. Pass '{ merge: true }' instead.`);
}
return {
type: 'POP_TO',
payload: {
name,
params,
merge: typeof options === 'boolean' ? options : options?.merge
}
};
}
};
export function StackRouter(options) {
const router = {
...BaseRouter,
type: 'stack',
getInitialState({
routeNames,
routeParamList
}) {
const initialRouteName = options.initialRouteName !== undefined && routeNames.includes(options.initialRouteName) ? options.initialRouteName : routeNames[0];
return {
stale: false,
type: 'stack',
key: `stack-${nanoid()}`,
index: 0,
routeNames,
preloadedRoutes: [],
routes: [{
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName]
}]
};
},
getRehydratedState(partialState, {
routeNames,
routeParamList
}) {
const state = partialState;
if (state.stale === false) {
return state;
}
const routes = state.routes.filter(route => routeNames.includes(route.name)).map(route => ({
...route,
key: route.key || `${route.name}-${nanoid()}`,
params: routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params
} : route.params
}));
const preloadedRoutes = state.preloadedRoutes?.filter(route => routeNames.includes(route.name)).map(route => ({
...route,
key: route.key || `${route.name}-${nanoid()}`,
params: routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params
} : route.params
})) ?? [];
if (routes.length === 0) {
const initialRouteName = options.initialRouteName !== undefined ? options.initialRouteName : routeNames[0];
routes.push({
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName]
});
}
return {
stale: false,
type: 'stack',
key: `stack-${nanoid()}`,
index: routes.length - 1,
routeNames,
routes,
preloadedRoutes
};
},
getStateForRouteNamesChange(state, {
routeNames,
routeParamList,
routeKeyChanges
}) {
const routes = state.routes.filter(route => routeNames.includes(route.name) && !routeKeyChanges.includes(route.name));
if (routes.length === 0) {
const initialRouteName = options.initialRouteName !== undefined && routeNames.includes(options.initialRouteName) ? options.initialRouteName : routeNames[0];
routes.push({
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName]
});
}
return {
...state,
routeNames,
routes,
index: Math.min(state.index, routes.length - 1)
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex(r => r.key === key);
if (index === -1 || index === state.index) {
return state;
}
return {
...state,
index,
routes: state.routes.slice(0, index + 1)
};
},
getStateForAction(state, action, options) {
const {
routeParamList
} = options;
switch (action.type) {
case 'REPLACE':
{
const currentIndex = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
if (currentIndex === -1) {
return null;
}
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({
params: action.payload.params
});
// Re-use preloaded route if available
let route = state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
if (!route) {
route = createRouteFromAction({
action,
routeParamList
});
}
return {
...state,
routes: state.routes.map((r, i) => i === currentIndex ? route : r),
preloadedRoutes: state.preloadedRoutes.filter(r => r.key !== route.key)
};
}
case 'PUSH':
case 'NAVIGATE':
{
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({
params: action.payload.params
});
let route;
if (id !== undefined) {
route = state.routes.findLast(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
} else if (action.type === 'NAVIGATE') {
const currentRoute = state.routes[state.index];
// If the route matches the current one, then navigate to it
if (action.payload.name === currentRoute.name) {
route = currentRoute;
} else if (action.payload.pop) {
route = state.routes.findLast(route => route.name === action.payload.name);
}
}
if (!route) {
route = state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
}
let params;
if (action.type === 'NAVIGATE' && action.payload.merge && route) {
params = action.payload.params !== undefined || routeParamList[action.payload.name] !== undefined ? {
...routeParamList[action.payload.name],
...route.params,
...action.payload.params
} : route.params;
} else {
params = createParamsFromAction({
action,
routeParamList
});
}
let routes;
if (route) {
if (action.type === 'NAVIGATE' && action.payload.pop) {
routes = [];
// Get all routes until the matching one
for (const r of state.routes) {
if (r.key === route.key) {
routes.push({
...route,
path: action.payload.path !== undefined ? action.payload.path : route.path,
params
});
break;
}
routes.push(r);
}
} else {
routes = state.routes.filter(r => r.key !== route.key);
routes.push({
...route,
path: action.type === 'NAVIGATE' && action.payload.path !== undefined ? action.payload.path : route.path,
params
});
}
} else {
routes = [...state.routes, {
key: `${action.payload.name}-${nanoid()}`,
name: action.payload.name,
path: action.type === 'NAVIGATE' ? action.payload.path : undefined,
params
}];
}
return {
...state,
index: routes.length - 1,
preloadedRoutes: state.preloadedRoutes.filter(route => routes[routes.length - 1].key !== route.key),
routes
};
}
case 'NAVIGATE_DEPRECATED':
{
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
if (state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
params: route.params
}))) {
return null;
}
// If the route already exists, navigate to that
let index = -1;
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({
params: action.payload.params
});
if (id !== undefined) {
index = state.routes.findIndex(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
} else if (state.routes[state.index].name === action.payload.name) {
index = state.index;
} else {
index = state.routes.findLastIndex(route => route.name === action.payload.name);
}
if (index === -1) {
const routes = [...state.routes, createRouteFromAction({
action,
routeParamList
})];
return {
...state,
routes,
index: routes.length - 1
};
}
const route = state.routes[index];
let params;
if (action.payload.merge) {
params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params,
...action.payload.params
} : route.params;
} else {
params = createParamsFromAction({
action,
routeParamList
});
}
return {
...state,
index,
routes: [...state.routes.slice(0, index), params !== route.params ? {
...route,
params
} : state.routes[index]]
};
}
case 'POP':
{
const currentIndex = action.target === state.key && action.source ? state.routes.findIndex(r => r.key === action.source) : state.index;
if (currentIndex > 0) {
const count = Math.max(currentIndex - action.payload.count + 1, 1);
const routes = state.routes.slice(0, count).concat(state.routes.slice(currentIndex + 1));
return {
...state,
index: routes.length - 1,
routes
};
}
return null;
}
case 'POP_TO_TOP':
return router.getStateForAction(state, {
type: 'POP',
payload: {
count: state.routes.length - 1
}
}, options);
case 'POP_TO':
{
const currentIndex = action.target === state.key && action.source ? state.routes.findLastIndex(r => r.key === action.source) : state.index;
if (currentIndex === -1) {
return null;
}
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
// If the route already exists, navigate to it
let index = -1;
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({
params: action.payload.params
});
if (id !== undefined) {
index = state.routes.findIndex(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
} else if (state.routes[currentIndex].name === action.payload.name) {
index = currentIndex;
} else {
for (let i = currentIndex; i >= 0; i--) {
if (state.routes[i].name === action.payload.name) {
index = i;
break;
}
}
}
// If the route doesn't exist, remove the current route and add the new one
if (index === -1) {
// Re-use preloaded route if available
let route = state.preloadedRoutes.find(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
if (!route) {
route = createRouteFromAction({
action,
routeParamList
});
}
const routes = state.routes.slice(0, currentIndex).concat(route);
return {
...state,
index: routes.length - 1,
routes,
preloadedRoutes: state.preloadedRoutes.filter(r => r.key !== route.key)
};
}
const route = state.routes[index];
let params;
if (action.payload.merge) {
params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params,
...action.payload.params
} : route.params;
} else {
params = createParamsFromAction({
action,
routeParamList
});
}
return {
...state,
index,
routes: [...state.routes.slice(0, index), params !== route.params ? {
...route,
params
} : state.routes[index]]
};
}
case 'GO_BACK':
if (state.index > 0) {
return router.getStateForAction(state, {
type: 'POP',
payload: {
count: 1
},
target: action.target,
source: action.source
}, options);
}
return null;
case 'PRELOAD':
{
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({
params: action.payload.params
});
let route;
if (id !== undefined) {
route = state.routes.find(route => route.name === action.payload.name && id === getId?.({
params: route.params
}));
}
if (route) {
return {
...state,
routes: state.routes.map(r => {
if (r.key !== route?.key) {
return r;
}
return {
...r,
params: createParamsFromAction({
action,
routeParamList
})
};
})
};
} else {
return {
...state,
preloadedRoutes: state.preloadedRoutes.filter(r => r.name !== action.payload.name || id !== getId?.({
params: r.params
})).concat(createRouteFromAction({
action,
routeParamList
}))
};
}
}
default:
return BaseRouter.getStateForAction(state, action);
}
},
actionCreators: StackActions
};
return router;
}
//# sourceMappingURL=StackRouter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,328 @@
"use strict";
import { nanoid } from 'nanoid/non-secure';
import { BaseRouter } from "./BaseRouter.js";
import { createParamsFromAction } from "./createParamsFromAction.js";
const TYPE_ROUTE = 'route';
export const TabActions = {
jumpTo(name, params) {
return {
type: 'JUMP_TO',
payload: {
name,
params
}
};
}
};
const getRouteHistory = (routes, index, backBehavior, initialRouteName) => {
const history = [{
type: TYPE_ROUTE,
key: routes[index].key
}];
let initialRouteIndex;
switch (backBehavior) {
case 'order':
for (let i = index; i > 0; i--) {
history.unshift({
type: TYPE_ROUTE,
key: routes[i - 1].key
});
}
break;
case 'firstRoute':
if (index !== 0) {
history.unshift({
type: TYPE_ROUTE,
key: routes[0].key
});
}
break;
case 'initialRoute':
initialRouteIndex = routes.findIndex(route => route.name === initialRouteName);
initialRouteIndex = initialRouteIndex === -1 ? 0 : initialRouteIndex;
if (index !== initialRouteIndex) {
history.unshift({
type: TYPE_ROUTE,
key: routes[initialRouteIndex].key
});
}
break;
case 'history':
case 'fullHistory':
// The history will fill up on navigation
break;
}
return history;
};
const changeIndex = (state, index, backBehavior, initialRouteName) => {
let history = state.history;
if (backBehavior === 'history' || backBehavior === 'fullHistory') {
const currentRoute = state.routes[index];
if (backBehavior === 'history') {
// Remove the existing key from the history to de-duplicate it
history = history.filter(it => it.type === 'route' ? it.key !== currentRoute.key : false);
} else if (backBehavior === 'fullHistory') {
const lastHistoryRouteItemIndex = history.findLastIndex(item => item.type === 'route');
if (currentRoute.key === history[lastHistoryRouteItemIndex]?.key) {
// For full-history, only remove if it matches the last route
// Useful for drawer, if current route was in history, then drawer state changed
// Then we only need to move the route to the front
history = [...history.slice(0, lastHistoryRouteItemIndex), ...history.slice(lastHistoryRouteItemIndex + 1)];
}
}
history = history.concat({
type: TYPE_ROUTE,
key: currentRoute.key,
params: backBehavior === 'fullHistory' ? currentRoute.params : undefined
});
} else {
history = getRouteHistory(state.routes, index, backBehavior, initialRouteName);
}
return {
...state,
index,
history
};
};
export function TabRouter({
initialRouteName,
backBehavior = 'firstRoute'
}) {
const router = {
...BaseRouter,
type: 'tab',
getInitialState({
routeNames,
routeParamList
}) {
const index = initialRouteName !== undefined && routeNames.includes(initialRouteName) ? routeNames.indexOf(initialRouteName) : 0;
const routes = routeNames.map(name => ({
name,
key: `${name}-${nanoid()}`,
params: routeParamList[name]
}));
const history = getRouteHistory(routes, index, backBehavior, initialRouteName);
return {
stale: false,
type: 'tab',
key: `tab-${nanoid()}`,
index,
routeNames,
history,
routes,
preloadedRouteKeys: []
};
},
getRehydratedState(partialState, {
routeNames,
routeParamList
}) {
const state = partialState;
if (state.stale === false) {
return state;
}
const routes = routeNames.map(name => {
const route = state.routes.find(r => r.name === name);
return {
...route,
name,
key: route && route.name === name && route.key ? route.key : `${name}-${nanoid()}`,
params: routeParamList[name] !== undefined ? {
...routeParamList[name],
...(route ? route.params : undefined)
} : route ? route.params : undefined
};
});
const index = Math.min(Math.max(routeNames.indexOf(state.routes[state?.index ?? 0]?.name), 0), routes.length - 1);
const routeKeys = routes.map(route => route.key);
const history = state.history?.filter(it => routeKeys.includes(it.key)) ?? [];
return changeIndex({
stale: false,
type: 'tab',
key: `tab-${nanoid()}`,
index,
routeNames,
history,
routes,
preloadedRouteKeys: state.preloadedRouteKeys?.filter(key => routeKeys.includes(key)) ?? []
}, index, backBehavior, initialRouteName);
},
getStateForRouteNamesChange(state, {
routeNames,
routeParamList,
routeKeyChanges
}) {
const routes = routeNames.map(name => state.routes.find(r => r.name === name && !routeKeyChanges.includes(r.name)) || {
name,
key: `${name}-${nanoid()}`,
params: routeParamList[name]
});
const index = Math.max(0, routeNames.indexOf(state.routes[state.index].name));
let history = state.history.filter(
// Type will always be 'route' for tabs, but could be different in a router extending this (e.g. drawer)
it => it.type !== 'route' || routes.find(r => r.key === it.key));
if (!history.length) {
history = getRouteHistory(routes, index, backBehavior, initialRouteName);
}
return {
...state,
history,
routeNames,
routes,
index
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex(r => r.key === key);
if (index === -1 || index === state.index) {
return state;
}
return changeIndex(state, index, backBehavior, initialRouteName);
},
getStateForAction(state, action, {
routeParamList,
routeGetIdList
}) {
switch (action.type) {
case 'JUMP_TO':
case 'NAVIGATE':
case 'NAVIGATE_DEPRECATED':
{
const index = state.routes.findIndex(route => route.name === action.payload.name);
if (index === -1) {
return null;
}
const updatedState = changeIndex({
...state,
routes: state.routes.map(route => {
if (route.name !== action.payload.name) {
return route;
}
const getId = routeGetIdList[route.name];
const currentId = getId?.({
params: route.params
});
const nextId = getId?.({
params: action.payload.params
});
const key = currentId === nextId ? route.key : `${route.name}-${nanoid()}`;
let params;
if ((action.type === 'NAVIGATE' || action.type === 'NAVIGATE_DEPRECATED') && action.payload.merge && currentId === nextId) {
params = action.payload.params !== undefined || routeParamList[route.name] !== undefined ? {
...routeParamList[route.name],
...route.params,
...action.payload.params
} : route.params;
} else {
params = createParamsFromAction({
action,
routeParamList
});
}
const path = action.type === 'NAVIGATE' && action.payload.path != null ? action.payload.path : route.path;
return params !== route.params || path !== route.path ? {
...route,
key,
path,
params
} : route;
})
}, index, backBehavior, initialRouteName);
return {
...updatedState,
preloadedRouteKeys: updatedState.preloadedRouteKeys.filter(key => key !== state.routes[updatedState.index].key)
};
}
case 'SET_PARAMS':
case 'REPLACE_PARAMS':
{
const nextState = BaseRouter.getStateForAction(state, action);
if (nextState !== null) {
const index = nextState.index;
if (index != null) {
const focusedRoute = nextState.routes[index];
const historyItemIndex = state.history.findLastIndex(item => item.key === focusedRoute.key);
let updatedHistory = state.history;
if (historyItemIndex !== -1) {
updatedHistory = [...state.history];
updatedHistory[historyItemIndex] = {
...updatedHistory[historyItemIndex],
params: focusedRoute.params
};
}
return {
...nextState,
history: updatedHistory
};
}
}
return nextState;
}
case 'GO_BACK':
{
if (state.history.length === 1) {
return null;
}
const previousHistoryItem = state.history[state.history.length - 2];
const previousKey = previousHistoryItem?.key;
const index = state.routes.findLastIndex(route => route.key === previousKey);
if (index === -1) {
return null;
}
let routes = state.routes;
if (backBehavior === 'fullHistory' && routes[index].params !== previousHistoryItem.params) {
routes = [...state.routes];
routes[index] = {
...routes[index],
params: previousHistoryItem.params
};
}
return {
...state,
routes,
preloadedRouteKeys: state.preloadedRouteKeys.filter(key => key !== state.routes[index].key),
history: state.history.slice(0, -1),
index
};
}
case 'PRELOAD':
{
const routeIndex = state.routes.findIndex(route => route.name === action.payload.name);
if (routeIndex === -1) {
return null;
}
const route = state.routes[routeIndex];
const getId = routeGetIdList[route.name];
const currentId = getId?.({
params: route.params
});
const nextId = getId?.({
params: action.payload.params
});
const key = currentId === nextId ? route.key : `${route.name}-${nanoid()}`;
const params = createParamsFromAction({
action,
routeParamList
});
const newRoute = params !== route.params ? {
...route,
key,
params
} : route;
return {
...state,
preloadedRouteKeys: state.preloadedRouteKeys.filter(key => key !== route.key).concat(newRoute.key),
routes: state.routes.map((route, index) => index === routeIndex ? newRoute : route),
history: key === route.key ? state.history : state.history.filter(record => record.key !== route.key)
};
}
default:
return BaseRouter.getStateForAction(state, action);
}
},
actionCreators: TabActions
};
return router;
}
//# sourceMappingURL=TabRouter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,16 @@
"use strict";
export function createParamsFromAction({
action,
routeParamList
}) {
const {
name,
params
} = action.payload;
return routeParamList[name] !== undefined ? {
...routeParamList[name],
...params
} : params;
}
//# sourceMappingURL=createParamsFromAction.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createParamsFromAction","action","routeParamList","name","params","payload","undefined"],"sourceRoot":"../../src","sources":["createParamsFromAction.tsx"],"mappings":";;AAYA,OAAO,SAASA,sBAAsBA,CAAC;EAAEC,MAAM;EAAEC;AAAwB,CAAC,EAAE;EAC1E,MAAM;IAAEC,IAAI;IAAEC;EAAO,CAAC,GAAGH,MAAM,CAACI,OAAO;EAEvC,OAAOH,cAAc,CAACC,IAAI,CAAC,KAAKG,SAAS,GACrC;IACE,GAAGJ,cAAc,CAACC,IAAI,CAAC;IACvB,GAAGC;EACL,CAAC,GACDA,MAAM;AACZ","ignoreList":[]}

View File

@@ -0,0 +1,21 @@
"use strict";
import { nanoid } from 'nanoid/non-secure';
import { createParamsFromAction } from "./createParamsFromAction.js";
export function createRouteFromAction({
action,
routeParamList
}) {
const {
name
} = action.payload;
return {
key: `${name}-${nanoid()}`,
name,
params: createParamsFromAction({
action,
routeParamList
})
};
}
//# sourceMappingURL=createRouteFromAction.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["nanoid","createParamsFromAction","createRouteFromAction","action","routeParamList","name","payload","key","params"],"sourceRoot":"../../src","sources":["createRouteFromAction.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,sBAAsB,QAAQ,6BAA0B;AAajE,OAAO,SAASC,qBAAqBA,CAAC;EAAEC,MAAM;EAAEC;AAAwB,CAAC,EAAE;EACzE,MAAM;IAAEC;EAAK,CAAC,GAAGF,MAAM,CAACG,OAAO;EAE/B,OAAO;IACLC,GAAG,EAAE,GAAGF,IAAI,IAAIL,MAAM,CAAC,CAAC,EAAE;IAC1BK,IAAI;IACJG,MAAM,EAAEP,sBAAsB,CAAC;MAAEE,MAAM;MAAEC;IAAe,CAAC;EAC3D,CAAC;AACH","ignoreList":[]}

View File

@@ -0,0 +1,10 @@
"use strict";
import * as CommonActions from "./CommonActions.js";
export { CommonActions };
export { BaseRouter } from "./BaseRouter.js";
export { DrawerActions, DrawerRouter } from "./DrawerRouter.js";
export { StackActions, StackRouter } from "./StackRouter.js";
export { TabActions, TabRouter } from "./TabRouter.js";
export * from "./types.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["CommonActions","BaseRouter","DrawerActions","DrawerRouter","StackActions","StackRouter","TabActions","TabRouter"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAO,KAAKA,aAAa,MAAM,oBAAiB;AAEhD,SAASA,aAAa;AAEtB,SAASC,UAAU,QAAQ,iBAAc;AAQzC,SAASC,aAAa,EAAEC,YAAY,QAAQ,mBAAgB;AAO5D,SAASC,YAAY,EAAEC,WAAW,QAAQ,kBAAe;AAOzD,SAASC,UAAU,EAAEC,SAAS,QAAQ,gBAAa;AACnD,cAAc,YAAS","ignoreList":[]}

View File

@@ -0,0 +1 @@
{"type":"module"}

View File

@@ -0,0 +1,4 @@
"use strict";
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.tsx"],"mappings":"","ignoreList":[]}

View File

@@ -0,0 +1 @@
{"type":"module"}

View File

@@ -0,0 +1,30 @@
import type { CommonNavigationAction, NavigationState, PartialState } from './types';
/**
* Base router object that can be used when writing custom routers.
* This provides few helper methods to handle common actions such as `RESET`.
*/
export declare const BaseRouter: {
getStateForAction<State extends NavigationState>(state: State, action: CommonNavigationAction): State | PartialState<State> | null;
shouldActionChangeFocus(action: CommonNavigationAction): action is {
type: "NAVIGATE";
payload: {
name: string;
params?: object;
path?: string;
merge?: boolean;
pop?: boolean;
};
source?: string;
target?: string;
} | {
type: "NAVIGATE_DEPRECATED";
payload: {
name: string;
params?: object;
merge?: boolean;
};
source?: string;
target?: string;
};
};
//# sourceMappingURL=BaseRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BaseRouter.d.ts","sourceRoot":"","sources":["../../../src/BaseRouter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,UAAU;sBACH,KAAK,SAAS,eAAe,SACtC,KAAK,UACJ,sBAAsB,GAC7B,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI;oCAkEL,sBAAsB;;;;kBAnE3C,CAAC;gBAAkB,CAAC;iBAChB,CAAC;eAAkB,CAAC;;;;;;;;kBAKG,CAAC;iBAAmB,CAAC;;;;;CAgE5D,CAAC"}

View File

@@ -0,0 +1,104 @@
import type { NavigationState, PartialState, Route } from './types';
type ResetState = PartialState<NavigationState> | NavigationState | (Omit<NavigationState, 'routes'> & {
routes: Omit<Route<string>, 'key'>[];
});
type GoBackAction = {
type: 'GO_BACK';
source?: string;
target?: string;
};
type NavigateAction = {
type: 'NAVIGATE';
payload: {
name: string;
params?: object;
path?: string;
merge?: boolean;
pop?: boolean;
};
source?: string;
target?: string;
};
type NavigateDeprecatedAction = {
type: 'NAVIGATE_DEPRECATED';
payload: {
name: string;
params?: object;
merge?: boolean;
};
source?: string;
target?: string;
};
type ResetAction = {
type: 'RESET';
payload: ResetState | undefined;
source?: string;
target?: string;
};
type SetParamsAction = {
type: 'SET_PARAMS';
payload: {
params?: object;
};
source?: string;
target?: string;
};
type ReplaceParamsAction = {
type: 'REPLACE_PARAMS';
payload: {
params?: object;
};
source?: string;
target?: string;
};
type PreloadAction = {
type: 'PRELOAD';
payload: {
name: string;
params?: object;
};
source?: string;
target?: string;
};
export type Action = GoBackAction | NavigateAction | NavigateDeprecatedAction | ResetAction | SetParamsAction | ReplaceParamsAction | PreloadAction;
export declare function goBack(): Action;
export declare function navigate(name: string, params?: object, options?: {
merge?: boolean;
pop?: boolean;
}): Action;
export declare function navigate(options: {
name: string;
params?: object;
path?: string;
merge?: boolean;
pop?: boolean;
}): Action;
export declare function navigateDeprecated(...args: [name: string] | [name: string, params: object | undefined] | [options: {
name: string;
params?: object;
}]): Action;
export declare function reset(state: ResetState | undefined): {
readonly type: "RESET";
readonly payload: ResetState | undefined;
};
export declare function setParams(params: object): {
readonly type: "SET_PARAMS";
readonly payload: {
readonly params: object;
};
};
export declare function replaceParams(params: object): {
readonly type: "REPLACE_PARAMS";
readonly payload: {
readonly params: object;
};
};
export declare function preload(name: string, params?: object): {
readonly type: "PRELOAD";
readonly payload: {
readonly name: string;
readonly params: object | undefined;
};
};
export {};
//# sourceMappingURL=CommonActions.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CommonActions.d.ts","sourceRoot":"","sources":["../../../src/CommonActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEpE,KAAK,UAAU,GACX,YAAY,CAAC,eAAe,CAAC,GAC7B,eAAe,GACf,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,GAAG;IACjC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;CACtC,CAAC,CAAC;AAEP,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EA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AM;;;;;;EAKpD"}

View File

@@ -0,0 +1,65 @@
import { type TabActionHelpers, type TabActionType, type TabNavigationState, type TabRouterOptions } from './TabRouter';
import type { CommonNavigationAction, ParamListBase, Router } from './types';
export type DrawerStatus = 'open' | 'closed';
export type DrawerActionType = TabActionType | {
type: 'OPEN_DRAWER' | 'CLOSE_DRAWER' | 'TOGGLE_DRAWER';
source?: string;
target?: string;
};
export type DrawerRouterOptions = TabRouterOptions & {
defaultStatus?: DrawerStatus;
};
export type DrawerNavigationState<ParamList extends ParamListBase> = Omit<TabNavigationState<ParamList>, 'type' | 'history'> & {
/**
* Type of the router, in this case, it's drawer.
*/
type: 'drawer';
/**
* Default status of the drawer.
*/
default: DrawerStatus;
/**
* List of previously visited route keys and drawer open status.
*/
history: ({
type: 'route';
key: string;
} | {
type: 'drawer';
status: DrawerStatus;
})[];
};
export type DrawerActionHelpers<ParamList extends ParamListBase> = TabActionHelpers<ParamList> & {
/**
* Open the drawer sidebar.
*/
openDrawer(): void;
/**
* Close the drawer sidebar.
*/
closeDrawer(): void;
/**
* Open the drawer sidebar if closed, or close if opened.
*/
toggleDrawer(): void;
};
export declare const DrawerActions: {
openDrawer(): {
readonly type: "OPEN_DRAWER";
};
closeDrawer(): {
readonly type: "CLOSE_DRAWER";
};
toggleDrawer(): {
readonly type: "TOGGLE_DRAWER";
};
jumpTo(name: string, params?: object): {
readonly type: "JUMP_TO";
readonly payload: {
readonly name: string;
readonly params: object | undefined;
};
};
};
export declare function DrawerRouter({ defaultStatus, ...rest }: DrawerRouterOptions): Router<DrawerNavigationState<ParamListBase>, DrawerActionType | CommonNavigationAction>;
//# sourceMappingURL=DrawerRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"DrawerRouter.d.ts","sourceRoot":"","sources":["../../../src/DrawerRouter.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAEvB,KAAK,gBAAgB,EACt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,CAC7B,qBAAqB,CAAC,aAAa,CAAC,EACpC,gBAAgB,GAAG,sBAAsB,CAC1C,CAgKA"}

View File

@@ -0,0 +1,131 @@
import type { DefaultRouterOptions, NavigationRoute, NavigationState, ParamListBase, Router } from './types';
export type StackActionType = {
type: 'REPLACE';
payload: {
name: string;
params?: object;
};
source?: string;
target?: string;
} | {
type: 'PUSH';
payload: {
name: string;
params?: object;
};
source?: string;
target?: string;
} | {
type: 'POP';
payload: {
count: number;
};
source?: string;
target?: string;
} | {
type: 'POP_TO_TOP';
source?: string;
target?: string;
} | {
type: 'POP_TO';
payload: {
name: string;
params?: object;
merge?: boolean;
};
source?: string;
target?: string;
};
export type StackRouterOptions = DefaultRouterOptions;
export type StackNavigationState<ParamList extends ParamListBase> = NavigationState<ParamList> & {
/**
* Type of the router, in this case, it's stack.
*/
type: 'stack';
/**
* List of routes, which are supposed to be preloaded before navigating to.
*/
preloadedRoutes: NavigationRoute<ParamList, keyof ParamList>[];
};
export type StackActionHelpers<ParamList extends ParamListBase> = {
/**
* Replace the current route with a new one.
*
* @param screen Name of the new route that will replace the current one.
* @param [params] Params object for the new route.
*/
replace<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [screen: RouteName, params?: ParamList[RouteName]] : [screen: RouteName, params: ParamList[RouteName]] : never): void;
/**
* Push a new screen onto the stack.
*
* @param screen Name of the route to push onto the stack.
* @param [params] Params object for the route.
*/
push<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [screen: RouteName, params?: ParamList[RouteName]] : [screen: RouteName, params: ParamList[RouteName]] : never): void;
/**
* Pop a screen from the stack.
*/
pop(count?: number): void;
/**
* Pop to the first route in the stack, dismissing all other screens.
*/
popToTop(): void;
/**
* Pop any screens to go back to the specified screen.
* If the specified screen doesn't exist, it'll be added to the stack.
*
* @param screen Name of the route to pop to.
* @param [params] Params object for the route.
* @param [options.merge] Whether to merge the params onto the route. Defaults to `false`.
*/
popTo<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [
screen: RouteName,
params?: ParamList[RouteName],
options?: {
merge?: boolean;
}
] : [
screen: RouteName,
params: ParamList[RouteName],
options?: {
merge?: boolean;
}
] : never): void;
};
export declare const StackActions: {
replace(name: string, params?: object): {
readonly type: "REPLACE";
readonly payload: {
readonly name: string;
readonly params: object | undefined;
};
};
push(name: string, params?: object): {
readonly type: "PUSH";
readonly payload: {
readonly name: string;
readonly params: object | undefined;
};
};
pop(count?: number): {
readonly type: "POP";
readonly payload: {
readonly count: number;
};
};
popToTop(): {
readonly type: "POP_TO_TOP";
};
popTo(name: string, params?: object, options?: {
merge?: boolean;
}): {
readonly type: "POP_TO";
readonly payload: {
readonly name: string;
readonly params: object | undefined;
readonly merge: boolean | undefined;
};
};
};
export declare function StackRouter(options: StackRouterOptions): Router<StackNavigationState<ParamListBase>, import("./CommonActions").Action | StackActionType>;
//# sourceMappingURL=StackRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"StackRouter.d.ts","sourceRoot":"","sources":["../../../src/StackRouter.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,aAAa,EAEb,MAAM,EACP,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,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, ParamListBase, Router } from './types';
export type TabActionType = {
type: 'JUMP_TO';
payload: {
name: string;
params?: object;
};
source?: string;
target?: string;
};
export type BackBehavior = 'firstRoute' | 'initialRoute' | 'order' | 'history' | 'fullHistory' | 'none';
export type TabRouterOptions = DefaultRouterOptions & {
/**
* Control how going back should behave
* - `firstRoute` - return to the first defined route
* - `initialRoute` - return to the route from `initialRouteName`
* - `order` - return to the route defined before the focused route
* - `history` - return to last visited route; if the same route is visited multiple times, the older entries are dropped from the history
* - `fullHistory` - return to last visited route; doesn't drop duplicate entries unlike `history` - matches behavior of web pages
* - `none` - do not handle going back
*/
backBehavior?: BackBehavior;
};
export type TabNavigationState<ParamList extends ParamListBase> = Omit<NavigationState<ParamList>, 'history'> & {
/**
* Type of the router, in this case, it's tab.
*/
type: 'tab';
/**
* List of previously visited route keys.
*/
history: {
type: 'route';
key: string;
params?: object | undefined;
}[];
/**
* List of routes' key, which are supposed to be preloaded before navigating to.
*/
preloadedRouteKeys: string[];
};
export type TabActionHelpers<ParamList extends ParamListBase> = {
/**
* Jump to an existing tab.
*
* @param screen Name of the route to jump to.
* @param [params] Params object for the route.
*/
jumpTo<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [screen: RouteName, params?: ParamList[RouteName]] : [screen: RouteName, params: ParamList[RouteName]] : never): void;
};
export declare const TabActions: {
jumpTo(name: string, params?: object): {
readonly type: "JUMP_TO";
readonly payload: {
readonly name: string;
readonly params: object | undefined;
};
};
};
export declare function TabRouter({ initialRouteName, backBehavior, }: TabRouterOptions): Router<TabNavigationState<ParamListBase>, import("./CommonActions").Action | TabActionType>;
//# sourceMappingURL=TabRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TabRouter.d.ts","sourceRoot":"","sources":["../../../src/TabRouter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,oBAAoB,EACpB,eAAe,EACf,aAAa,EAGb,MAAM,EACP,MAAM,SAAS,CAAC;AA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AC;AAIF,eAAO,MAAM,UAAU;iBACR,MAAM,WAAW,MAAM;;;;;;;CAMrC,CAAC;AA6GF,wBAAgB,SAAS,CAAC,EACxB,gBAAgB,EAChB,YAA2B,GAC5B,EAAE,gBAAgB,+FA4VlB"}

View File

@@ -0,0 +1,13 @@
import type { ParamListBase } from './types';
type Options = {
action: {
payload: {
name: string;
params?: object;
};
};
routeParamList: ParamListBase;
};
export declare function createParamsFromAction({ action, routeParamList }: Options): object | undefined;
export {};
//# sourceMappingURL=createParamsFromAction.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createParamsFromAction.d.ts","sourceRoot":"","sources":["../../../src/createParamsFromAction.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,KAAK,OAAO,GAAG;IACb,MAAM,EAAE;QACN,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,CAAC,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,cAAc,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,OAAO,sBASzE"}

View File

@@ -0,0 +1,17 @@
import type { ParamListBase } from './types';
type Options = {
action: {
payload: {
name: string;
params?: object;
};
};
routeParamList: ParamListBase;
};
export declare function createRouteFromAction({ action, routeParamList }: Options): {
key: string;
name: string;
params: object | undefined;
};
export {};
//# sourceMappingURL=createRouteFromAction.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createRouteFromAction.d.ts","sourceRoot":"","sources":["../../../src/createRouteFromAction.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,KAAK,OAAO,GAAG;IACb,MAAM,EAAE;QACN,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,CAAC,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,cAAc,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,OAAO;;;;EAQxE"}

View File

@@ -0,0 +1,11 @@
import * as CommonActions from './CommonActions';
export { CommonActions };
export { BaseRouter } from './BaseRouter';
export type { DrawerActionHelpers, DrawerActionType, DrawerNavigationState, DrawerRouterOptions, DrawerStatus, } from './DrawerRouter';
export { DrawerActions, DrawerRouter } from './DrawerRouter';
export type { StackActionHelpers, StackActionType, StackNavigationState, StackRouterOptions, } from './StackRouter';
export { StackActions, StackRouter } from './StackRouter';
export type { TabActionHelpers, TabActionType, TabNavigationState, TabRouterOptions, } from './TabRouter';
export { TabActions, TabRouter } from './TabRouter';
export * from './types';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EACV,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,cAAc,SAAS,CAAC"}

View File

@@ -0,0 +1,176 @@
import type * as CommonActions from './CommonActions';
export type CommonNavigationAction = CommonActions.Action;
export type NavigationRoute<ParamList extends ParamListBase, RouteName extends keyof ParamList> = Route<Extract<RouteName, string>, ParamList[RouteName]> & {
state?: NavigationState | PartialState<NavigationState>;
};
export type NavigationState<ParamList extends ParamListBase = ParamListBase> = Readonly<{
/**
* Unique key for the navigation state.
*/
key: string;
/**
* Index of the currently focused route.
*/
index: number;
/**
* List of valid route names as defined in the screen components.
*/
routeNames: Extract<keyof ParamList, string>[];
/**
* Alternative entries for history.
*/
history?: unknown[];
/**
* List of rendered routes.
*/
routes: NavigationRoute<ParamList, keyof ParamList>[];
/**
* Custom type for the state, whether it's for tab, stack, drawer etc.
* During rehydration, the state will be discarded if type doesn't match with router type.
* It can also be used to detect the type of the navigator we're dealing with.
*/
type: string;
/**
* Whether the navigation state has been rehydrated.
*/
stale: false;
}>;
export type InitialState = Readonly<Partial<Omit<NavigationState, 'stale' | 'routes'>> & {
routes: (Omit<Route<string>, 'key'> & {
state?: InitialState;
})[];
}>;
export type PartialRoute<R extends Route<string>> = Omit<R, 'key'> & {
key?: string;
state?: PartialState<NavigationState>;
};
export type PartialState<State extends NavigationState> = Partial<Omit<State, 'stale' | 'routes'>> & Readonly<{
stale?: true;
routes: PartialRoute<Route<State['routeNames'][number]>>[];
}>;
export type Route<RouteName extends string, Params extends object | undefined = object | undefined> = Readonly<{
/**
* Unique key for the route.
*/
key: string;
/**
* User-provided name for the route.
*/
name: RouteName;
/**
* Path associated with the route.
* Usually present when the screen was opened from a deep link.
*/
path?: string;
}> & (undefined extends Params ? Readonly<{
/**
* Params for this route
*/
params?: Readonly<Params>;
}> : Readonly<{
/**
* Params for this route
*/
params: Readonly<Params>;
}>);
export type ParamListBase = Record<string, object | undefined>;
export type NavigationAction = Readonly<{
/**
* Type of the action (e.g. `NAVIGATE`)
*/
type: string;
/**
* Additional data for the action
*/
payload?: object;
/**
* Key of the route which dispatched this action.
*/
source?: string;
/**
* Key of the navigator which should handle this action.
*/
target?: string;
}>;
export type ActionCreators<Action extends NavigationAction> = {
[key: string]: (...args: any) => Action;
};
export type DefaultRouterOptions<RouteName extends string = string> = {
/**
* Name of the route to focus by on initial render.
* If not specified, usually the first route is used.
*/
initialRouteName?: RouteName;
};
export type RouterFactory<State extends NavigationState, Action extends NavigationAction, RouterOptions extends DefaultRouterOptions> = (options: RouterOptions) => Router<State, Action>;
export type RouterConfigOptions = {
routeNames: string[];
routeParamList: ParamListBase;
routeGetIdList: Record<string, ((options: {
params?: Record<string, any>;
}) => string | undefined) | undefined>;
};
export type Router<State extends NavigationState, Action extends NavigationAction> = {
/**
* Type of the router. Should match the `type` property in state.
* If the type doesn't match, the state will be discarded during rehydration.
*/
type: State['type'];
/**
* Initialize the navigation state.
*
* @param options.routeNames List of valid route names as defined in the screen components.
* @param options.routeParamsList Object containing params for each route.
*/
getInitialState(options: RouterConfigOptions): State;
/**
* Rehydrate the full navigation state from a given partial state.
*
* @param partialState Navigation state to rehydrate from.
* @param options.routeNames List of valid route names as defined in the screen components.
* @param options.routeParamsList Object containing params for each route.
*/
getRehydratedState(partialState: PartialState<State> | State, options: RouterConfigOptions): State;
/**
* Take the current state and updated list of route names, and return a new state.
*
* @param state State object to update.
* @param options.routeNames New list of route names.
* @param options.routeParamsList Object containing params for each route.
*/
getStateForRouteNamesChange(state: State, options: RouterConfigOptions & {
/**
* List of routes whose key has changed even if they still have the same name.
* This allows to remove screens declaratively.
*/
routeKeyChanges: string[];
}): State;
/**
* Take the current state and key of a route, and return a new state with the route focused
*
* @param state State object to apply the action on.
* @param key Key of the route to focus.
*/
getStateForRouteFocus(state: State, key: string): State;
/**
* Take the current state and action, and return a new state.
* If the action cannot be handled, return `null`.
*
* @param state State object to apply the action on.
* @param action Action object to apply.
* @param options.routeNames List of valid route names as defined in the screen components.
* @param options.routeParamsList Object containing params for each route.
*/
getStateForAction(state: State, action: Action, options: RouterConfigOptions): State | PartialState<State> | null;
/**
* Whether the action should also change focus in parent navigator
*
* @param action Action object to check.
*/
shouldActionChangeFocus(action: NavigationAction): boolean;
/**
* Action creators for the router.
*/
actionCreators?: ActionCreators<Action>;
};
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,aAAa,MAAM,iBAAiB,CAAC;AAEtD,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC,MAAM,CAAC;AAE1D,MAAM,MAAM,eAAe,CACzB,SAAS,SAAS,aAAa,EAC/B,SAAS,SAAS,MAAM,SAAS,IAC/B,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,GAAG;IAC5D,KAAK,CAAC,EAAE,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,aAAa,GAAG,aAAa,IACzE,QAAQ,CAAC;IACP;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC,MAAM,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC;IAC/C;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC,SAAS,EAAE,MAAM,SAAS,CAAC,EAAE,CAAC;IACtD;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;CACd,CAAC,CAAC;AAEL,MAAM,MAAM,YAAY,GAAG,QAAQ,CACjC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC,GAAG;IACnD,MAAM,EAAE,CAAC,IAAI,CAAC,KAA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IAErD;;;;;;OAMG;IACH,kBAAkB,CAChB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,EACzC,OAAO,EAAE,mBAAmB,GAC3B,KAAK,CAAC;IAET;;;;;;OAMG;IACH,2BAA2B,CACzB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,mBAAmB,GAAG;QAC7B;;;WAGG;QACH,eAAe,EAAE,MAAM,EAAE,CAAC;KAC3B,GACA,KAAK,CAAC;IAET;;;;;OAKG;IACH,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;IAExD;;;;;;;;OAQG;IACH,iBAAiB,CACf,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,GAC3B,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAEtC;;;;OAIG;IACH,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC;IAE3D;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC"}

71
node_modules/@react-navigation/routers/package.json generated vendored Normal file
View File

@@ -0,0 +1,71 @@
{
"name": "@react-navigation/routers",
"description": "Routers to help build custom navigators",
"version": "7.5.3",
"keywords": [
"react",
"react-native",
"react-navigation"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/react-navigation/react-navigation.git",
"directory": "packages/routers"
},
"bugs": {
"url": "https://github.com/react-navigation/react-navigation/issues"
},
"homepage": "https://reactnavigation.org/docs/custom-routers/",
"main": "./lib/module/index.js",
"types": "./lib/typescript/src/index.d.ts",
"exports": {
".": {
"source": "./src/index.tsx",
"types": "./lib/typescript/src/index.d.ts",
"default": "./lib/module/index.js"
},
"./package.json": "./package.json"
},
"files": [
"src",
"lib",
"!**/__tests__"
],
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"scripts": {
"prepack": "bob build",
"clean": "del lib"
},
"dependencies": {
"nanoid": "^3.3.11"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
"del-cli": "^6.0.0",
"react-native-builder-bob": "^0.40.17",
"typescript": "^5.9.2"
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
[
"module",
{
"esm": true
}
],
[
"typescript",
{
"project": "tsconfig.build.json"
}
]
]
},
"gitHead": "2b7ee0d2d1b1ef0390b690f59c0c1dd8bd57e9eb"
}

View File

@@ -0,0 +1,86 @@
import { nanoid } from 'nanoid/non-secure';
import type {
CommonNavigationAction,
NavigationState,
PartialState,
} from './types';
/**
* Base router object that can be used when writing custom routers.
* This provides few helper methods to handle common actions such as `RESET`.
*/
export const BaseRouter = {
getStateForAction<State extends NavigationState>(
state: State,
action: CommonNavigationAction
): State | PartialState<State> | null {
switch (action.type) {
case 'SET_PARAMS':
case 'REPLACE_PARAMS': {
const index = action.source
? state.routes.findIndex((r) => r.key === action.source)
: state.index;
if (index === -1) {
return null;
}
return {
...state,
routes: state.routes.map((r, i) =>
i === index
? {
...r,
params:
action.type === 'REPLACE_PARAMS'
? action.payload.params
: { ...r.params, ...action.payload.params },
}
: r
),
};
}
case 'RESET': {
const nextState = action.payload as State | PartialState<State>;
if (
nextState.routes.length === 0 ||
nextState.routes.some(
(route: { name: string }) => !state.routeNames.includes(route.name)
)
) {
return null;
}
if (nextState.stale === false) {
if (
state.routeNames.length !== nextState.routeNames.length ||
nextState.routeNames.some(
(name) => !state.routeNames.includes(name)
)
) {
return null;
}
return {
...nextState,
routes: nextState.routes.map((route) =>
route.key ? route : { ...route, key: `${route.name}-${nanoid()}` }
),
};
}
return nextState;
}
default:
return null;
}
},
shouldActionChangeFocus(action: CommonNavigationAction) {
return action.type === 'NAVIGATE' || action.type === 'NAVIGATE_DEPRECATED';
},
};

View File

@@ -0,0 +1,180 @@
import type { NavigationState, PartialState, Route } from './types';
type ResetState =
| PartialState<NavigationState>
| NavigationState
| (Omit<NavigationState, 'routes'> & {
routes: Omit<Route<string>, 'key'>[];
});
type GoBackAction = {
type: 'GO_BACK';
source?: string;
target?: string;
};
type NavigateAction = {
type: 'NAVIGATE';
payload: {
name: string;
params?: object;
path?: string;
merge?: boolean;
pop?: boolean;
};
source?: string;
target?: string;
};
type NavigateDeprecatedAction = {
type: 'NAVIGATE_DEPRECATED';
payload: {
name: string;
params?: object;
merge?: boolean;
};
source?: string;
target?: string;
};
type ResetAction = {
type: 'RESET';
payload: ResetState | undefined;
source?: string;
target?: string;
};
type SetParamsAction = {
type: 'SET_PARAMS';
payload: { params?: object };
source?: string;
target?: string;
};
type ReplaceParamsAction = {
type: 'REPLACE_PARAMS';
payload: { params?: object };
source?: string;
target?: string;
};
type PreloadAction = {
type: 'PRELOAD';
payload: {
name: string;
params?: object;
};
source?: string;
target?: string;
};
export type Action =
| GoBackAction
| NavigateAction
| NavigateDeprecatedAction
| ResetAction
| SetParamsAction
| ReplaceParamsAction
| PreloadAction;
export function goBack(): Action {
return { type: 'GO_BACK' };
}
export function navigate(
name: string,
params?: object,
options?: {
merge?: boolean;
pop?: boolean;
}
): Action;
export function navigate(options: {
name: string;
params?: object;
path?: string;
merge?: boolean;
pop?: boolean;
}): Action;
export function navigate(...args: any): Action {
if (typeof args[0] === 'string') {
const [name, params, options] = args;
if (typeof options === 'boolean') {
console.warn(
`Passing a boolean as the third argument to 'navigate' is deprecated. Pass '{ merge: true }' instead.`
);
}
return {
type: 'NAVIGATE',
payload: {
name,
params,
merge: typeof options === 'boolean' ? options : options?.merge,
pop: options?.pop,
},
};
} else {
const payload = args[0] || {};
if (!('name' in payload)) {
throw new Error(
'You need to specify a name when calling navigate with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigate for usage.'
);
}
return { type: 'NAVIGATE', payload };
}
}
export function navigateDeprecated(
...args:
| [name: string]
| [name: string, params: object | undefined]
| [options: { name: string; params?: object }]
): Action {
if (typeof args[0] === 'string') {
return {
type: 'NAVIGATE_DEPRECATED',
payload: { name: args[0], params: args[1] },
};
} else {
const payload = args[0] || {};
if (!('name' in payload)) {
throw new Error(
'You need to specify a name when calling navigateDeprecated with an object as the argument. See https://reactnavigation.org/docs/navigation-actions#navigatelegacy for usage.'
);
}
return { type: 'NAVIGATE_DEPRECATED', payload };
}
}
export function reset(state: ResetState | undefined) {
return { type: 'RESET', payload: state } as const satisfies ResetAction;
}
export function setParams(params: object) {
return {
type: 'SET_PARAMS',
payload: { params },
} as const satisfies SetParamsAction;
}
export function replaceParams(params: object) {
return {
type: 'REPLACE_PARAMS',
payload: { params },
} as const satisfies ReplaceParamsAction;
}
export function preload(name: string, params?: object) {
return {
type: 'PRELOAD',
payload: { name, params },
} as const satisfies PreloadAction;
}

View File

@@ -0,0 +1,249 @@
import { nanoid } from 'nanoid/non-secure';
import {
type TabActionHelpers,
TabActions,
type TabActionType,
type TabNavigationState,
TabRouter,
type TabRouterOptions,
} from './TabRouter';
import type {
CommonNavigationAction,
ParamListBase,
PartialState,
Router,
} from './types';
export type DrawerStatus = 'open' | 'closed';
export type DrawerActionType =
| TabActionType
| {
type: 'OPEN_DRAWER' | 'CLOSE_DRAWER' | 'TOGGLE_DRAWER';
source?: string;
target?: string;
};
export type DrawerRouterOptions = TabRouterOptions & {
defaultStatus?: DrawerStatus;
};
export type DrawerNavigationState<ParamList extends ParamListBase> = Omit<
TabNavigationState<ParamList>,
'type' | 'history'
> & {
/**
* Type of the router, in this case, it's drawer.
*/
type: 'drawer';
/**
* Default status of the drawer.
*/
default: DrawerStatus;
/**
* List of previously visited route keys and drawer open status.
*/
history: (
| { type: 'route'; key: string }
| { type: 'drawer'; status: DrawerStatus }
)[];
};
export type DrawerActionHelpers<ParamList extends ParamListBase> =
TabActionHelpers<ParamList> & {
/**
* Open the drawer sidebar.
*/
openDrawer(): void;
/**
* Close the drawer sidebar.
*/
closeDrawer(): void;
/**
* Open the drawer sidebar if closed, or close if opened.
*/
toggleDrawer(): void;
};
export const DrawerActions = {
...TabActions,
openDrawer() {
return { type: 'OPEN_DRAWER' } as const satisfies DrawerActionType;
},
closeDrawer() {
return { type: 'CLOSE_DRAWER' } as const satisfies DrawerActionType;
},
toggleDrawer() {
return { type: 'TOGGLE_DRAWER' } as const satisfies DrawerActionType;
},
};
export function DrawerRouter({
defaultStatus = 'closed',
...rest
}: DrawerRouterOptions): Router<
DrawerNavigationState<ParamListBase>,
DrawerActionType | CommonNavigationAction
> {
const router = TabRouter(rest) as unknown as Router<
DrawerNavigationState<ParamListBase>,
TabActionType | CommonNavigationAction
>;
const isDrawerInHistory = (
state:
| DrawerNavigationState<ParamListBase>
| PartialState<DrawerNavigationState<ParamListBase>>
) => Boolean(state.history?.some((it) => it.type === 'drawer'));
const addDrawerToHistory = (
state: DrawerNavigationState<ParamListBase>
): DrawerNavigationState<ParamListBase> => {
if (isDrawerInHistory(state)) {
return state;
}
return {
...state,
history: [
...state.history,
{
type: 'drawer',
status: defaultStatus === 'open' ? 'closed' : 'open',
},
],
};
};
const removeDrawerFromHistory = (
state: DrawerNavigationState<ParamListBase>
): DrawerNavigationState<ParamListBase> => {
if (!isDrawerInHistory(state)) {
return state;
}
return {
...state,
history: state.history.filter((it) => it.type !== 'drawer'),
};
};
const openDrawer = (
state: DrawerNavigationState<ParamListBase>
): DrawerNavigationState<ParamListBase> => {
if (defaultStatus === 'open') {
return removeDrawerFromHistory(state);
}
return addDrawerToHistory(state);
};
const closeDrawer = (
state: DrawerNavigationState<ParamListBase>
): DrawerNavigationState<ParamListBase> => {
if (defaultStatus === 'open') {
return addDrawerToHistory(state);
}
return removeDrawerFromHistory(state);
};
return {
...router,
type: 'drawer',
getInitialState({ routeNames, routeParamList, routeGetIdList }) {
const state = router.getInitialState({
routeNames,
routeParamList,
routeGetIdList,
});
return {
...state,
default: defaultStatus,
stale: false,
type: 'drawer',
key: `drawer-${nanoid()}`,
};
},
getRehydratedState(
partialState,
{ routeNames, routeParamList, routeGetIdList }
) {
if (partialState.stale === false) {
return partialState;
}
let state = router.getRehydratedState(partialState, {
routeNames,
routeParamList,
routeGetIdList,
});
if (isDrawerInHistory(partialState)) {
// Re-sync the drawer entry in history to correct it if it was wrong
state = removeDrawerFromHistory(state);
state = addDrawerToHistory(state);
}
return {
...state,
default: defaultStatus,
type: 'drawer',
key: `drawer-${nanoid()}`,
};
},
getStateForRouteFocus(state, key) {
const result = router.getStateForRouteFocus(state, key);
return closeDrawer(result);
},
getStateForAction(state, action, options) {
switch (action.type) {
case 'OPEN_DRAWER':
return openDrawer(state);
case 'CLOSE_DRAWER':
return closeDrawer(state);
case 'TOGGLE_DRAWER':
if (isDrawerInHistory(state)) {
return removeDrawerFromHistory(state);
}
return addDrawerToHistory(state);
case 'JUMP_TO':
case 'NAVIGATE':
case 'NAVIGATE_DEPRECATED': {
const result = router.getStateForAction(state, action, options);
if (result != null && result.index !== state.index) {
return closeDrawer(result as DrawerNavigationState<ParamListBase>);
}
return result;
}
case 'GO_BACK':
if (isDrawerInHistory(state)) {
return removeDrawerFromHistory(state);
}
return router.getStateForAction(state, action, options);
default:
return router.getStateForAction(state, action, options);
}
},
actionCreators: DrawerActions,
};
}

View File

@@ -0,0 +1,733 @@
import { nanoid } from 'nanoid/non-secure';
import { BaseRouter } from './BaseRouter';
import { createParamsFromAction } from './createParamsFromAction';
import { createRouteFromAction } from './createRouteFromAction';
import type {
CommonNavigationAction,
DefaultRouterOptions,
NavigationRoute,
NavigationState,
ParamListBase,
Route,
Router,
} from './types';
export type StackActionType =
| {
type: 'REPLACE';
payload: { name: string; params?: object };
source?: string;
target?: string;
}
| {
type: 'PUSH';
payload: { name: string; params?: object };
source?: string;
target?: string;
}
| {
type: 'POP';
payload: { count: number };
source?: string;
target?: string;
}
| {
type: 'POP_TO_TOP';
source?: string;
target?: string;
}
| {
type: 'POP_TO';
payload: {
name: string;
params?: object;
merge?: boolean;
};
source?: string;
target?: string;
};
export type StackRouterOptions = DefaultRouterOptions;
export type StackNavigationState<ParamList extends ParamListBase> =
NavigationState<ParamList> & {
/**
* Type of the router, in this case, it's stack.
*/
type: 'stack';
/**
* List of routes, which are supposed to be preloaded before navigating to.
*/
preloadedRoutes: NavigationRoute<ParamList, keyof ParamList>[];
};
export type StackActionHelpers<ParamList extends ParamListBase> = {
/**
* Replace the current route with a new one.
*
* @param screen Name of the new route that will replace the current one.
* @param [params] Params object for the new route.
*/
replace<RouteName extends keyof ParamList>(
...args: RouteName extends unknown
? undefined extends ParamList[RouteName]
? [screen: RouteName, params?: ParamList[RouteName]]
: [screen: RouteName, params: ParamList[RouteName]]
: never
): void;
/**
* Push a new screen onto the stack.
*
* @param screen Name of the route to push onto the stack.
* @param [params] Params object for the route.
*/
push<RouteName extends keyof ParamList>(
...args: RouteName extends unknown
? undefined extends ParamList[RouteName]
? [screen: RouteName, params?: ParamList[RouteName]]
: [screen: RouteName, params: ParamList[RouteName]]
: never
): void;
/**
* Pop a screen from the stack.
*/
pop(count?: number): void;
/**
* Pop to the first route in the stack, dismissing all other screens.
*/
popToTop(): void;
/**
* Pop any screens to go back to the specified screen.
* If the specified screen doesn't exist, it'll be added to the stack.
*
* @param screen Name of the route to pop to.
* @param [params] Params object for the route.
* @param [options.merge] Whether to merge the params onto the route. Defaults to `false`.
*/
popTo<RouteName extends keyof ParamList>(
...args: RouteName extends unknown
? undefined extends ParamList[RouteName]
? [
screen: RouteName,
params?: ParamList[RouteName],
options?: { merge?: boolean },
]
: [
screen: RouteName,
params: ParamList[RouteName],
options?: { merge?: boolean },
]
: never
): void;
};
export const StackActions = {
replace(name: string, params?: object) {
return {
type: 'REPLACE',
payload: { name, params },
} as const satisfies StackActionType;
},
push(name: string, params?: object) {
return {
type: 'PUSH',
payload: { name, params },
} as const satisfies StackActionType;
},
pop(count: number = 1) {
return {
type: 'POP',
payload: { count },
} as const satisfies StackActionType;
},
popToTop() {
return { type: 'POP_TO_TOP' } as const satisfies StackActionType;
},
popTo(name: string, params?: object, options?: { merge?: boolean }) {
if (typeof options === 'boolean') {
console.warn(
`Passing a boolean as the third argument to 'popTo' is deprecated. Pass '{ merge: true }' instead.`
);
}
return {
type: 'POP_TO',
payload: {
name,
params,
merge: typeof options === 'boolean' ? options : options?.merge,
},
} as const satisfies StackActionType;
},
};
export function StackRouter(options: StackRouterOptions) {
const router: Router<
StackNavigationState<ParamListBase>,
CommonNavigationAction | StackActionType
> = {
...BaseRouter,
type: 'stack',
getInitialState({ routeNames, routeParamList }) {
const initialRouteName =
options.initialRouteName !== undefined &&
routeNames.includes(options.initialRouteName)
? options.initialRouteName
: routeNames[0];
return {
stale: false,
type: 'stack',
key: `stack-${nanoid()}`,
index: 0,
routeNames,
preloadedRoutes: [],
routes: [
{
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName],
},
],
};
},
getRehydratedState(partialState, { routeNames, routeParamList }) {
const state = partialState;
if (state.stale === false) {
return state;
}
const routes = state.routes
.filter((route) => routeNames.includes(route.name))
.map((route) => ({
...route,
key: route.key || `${route.name}-${nanoid()}`,
params:
routeParamList[route.name] !== undefined
? {
...routeParamList[route.name],
...route.params,
}
: route.params,
}));
const preloadedRoutes =
state.preloadedRoutes
?.filter((route) => routeNames.includes(route.name))
.map(
(route) =>
({
...route,
key: route.key || `${route.name}-${nanoid()}`,
params:
routeParamList[route.name] !== undefined
? {
...routeParamList[route.name],
...route.params,
}
: route.params,
}) as Route<string>
) ?? [];
if (routes.length === 0) {
const initialRouteName =
options.initialRouteName !== undefined
? options.initialRouteName
: routeNames[0];
routes.push({
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName],
});
}
return {
stale: false,
type: 'stack',
key: `stack-${nanoid()}`,
index: routes.length - 1,
routeNames,
routes,
preloadedRoutes,
};
},
getStateForRouteNamesChange(
state,
{ routeNames, routeParamList, routeKeyChanges }
) {
const routes = state.routes.filter(
(route) =>
routeNames.includes(route.name) &&
!routeKeyChanges.includes(route.name)
);
if (routes.length === 0) {
const initialRouteName =
options.initialRouteName !== undefined &&
routeNames.includes(options.initialRouteName)
? options.initialRouteName
: routeNames[0];
routes.push({
key: `${initialRouteName}-${nanoid()}`,
name: initialRouteName,
params: routeParamList[initialRouteName],
});
}
return {
...state,
routeNames,
routes,
index: Math.min(state.index, routes.length - 1),
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex((r) => r.key === key);
if (index === -1 || index === state.index) {
return state;
}
return {
...state,
index,
routes: state.routes.slice(0, index + 1),
};
},
getStateForAction(state, action, options) {
const { routeParamList } = options;
switch (action.type) {
case 'REPLACE': {
const currentIndex =
action.target === state.key && action.source
? state.routes.findIndex((r) => r.key === action.source)
: state.index;
if (currentIndex === -1) {
return null;
}
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({ params: action.payload.params });
// Re-use preloaded route if available
let route = state.preloadedRoutes.find(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
if (!route) {
route = createRouteFromAction({ action, routeParamList });
}
return {
...state,
routes: state.routes.map((r, i) =>
i === currentIndex ? route : r
),
preloadedRoutes: state.preloadedRoutes.filter(
(r) => r.key !== route.key
),
};
}
case 'PUSH':
case 'NAVIGATE': {
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({ params: action.payload.params });
let route: Route<string> | undefined;
if (id !== undefined) {
route = state.routes.findLast(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
} else if (action.type === 'NAVIGATE') {
const currentRoute = state.routes[state.index];
// If the route matches the current one, then navigate to it
if (action.payload.name === currentRoute.name) {
route = currentRoute;
} else if (action.payload.pop) {
route = state.routes.findLast(
(route) => route.name === action.payload.name
);
}
}
if (!route) {
route = state.preloadedRoutes.find(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
}
let params;
if (action.type === 'NAVIGATE' && action.payload.merge && route) {
params =
action.payload.params !== undefined ||
routeParamList[action.payload.name] !== undefined
? {
...routeParamList[action.payload.name],
...route.params,
...action.payload.params,
}
: route.params;
} else {
params = createParamsFromAction({ action, routeParamList });
}
let routes: Route<string>[];
if (route) {
if (action.type === 'NAVIGATE' && action.payload.pop) {
routes = [];
// Get all routes until the matching one
for (const r of state.routes) {
if (r.key === route.key) {
routes.push({
...route,
path:
action.payload.path !== undefined
? action.payload.path
: route.path,
params,
});
break;
}
routes.push(r);
}
} else {
routes = state.routes.filter((r) => r.key !== route.key);
routes.push({
...route,
path:
action.type === 'NAVIGATE' &&
action.payload.path !== undefined
? action.payload.path
: route.path,
params,
});
}
} else {
routes = [
...state.routes,
{
key: `${action.payload.name}-${nanoid()}`,
name: action.payload.name,
path:
action.type === 'NAVIGATE' ? action.payload.path : undefined,
params,
},
];
}
return {
...state,
index: routes.length - 1,
preloadedRoutes: state.preloadedRoutes.filter(
(route) => routes[routes.length - 1].key !== route.key
),
routes,
};
}
case 'NAVIGATE_DEPRECATED': {
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
if (
state.preloadedRoutes.find(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
)
) {
return null;
}
// If the route already exists, navigate to that
let index = -1;
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({ params: action.payload.params });
if (id !== undefined) {
index = state.routes.findIndex(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
} else if (state.routes[state.index].name === action.payload.name) {
index = state.index;
} else {
index = state.routes.findLastIndex(
(route) => route.name === action.payload.name
);
}
if (index === -1) {
const routes = [
...state.routes,
createRouteFromAction({ action, routeParamList }),
];
return {
...state,
routes,
index: routes.length - 1,
};
}
const route = state.routes[index];
let params;
if (action.payload.merge) {
params =
action.payload.params !== undefined ||
routeParamList[route.name] !== undefined
? {
...routeParamList[route.name],
...route.params,
...action.payload.params,
}
: route.params;
} else {
params = createParamsFromAction({ action, routeParamList });
}
return {
...state,
index,
routes: [
...state.routes.slice(0, index),
params !== route.params
? { ...route, params }
: state.routes[index],
],
};
}
case 'POP': {
const currentIndex =
action.target === state.key && action.source
? state.routes.findIndex((r) => r.key === action.source)
: state.index;
if (currentIndex > 0) {
const count = Math.max(currentIndex - action.payload.count + 1, 1);
const routes = state.routes
.slice(0, count)
.concat(state.routes.slice(currentIndex + 1));
return {
...state,
index: routes.length - 1,
routes,
};
}
return null;
}
case 'POP_TO_TOP':
return router.getStateForAction(
state,
{
type: 'POP',
payload: { count: state.routes.length - 1 },
},
options
);
case 'POP_TO': {
const currentIndex =
action.target === state.key && action.source
? state.routes.findLastIndex((r) => r.key === action.source)
: state.index;
if (currentIndex === -1) {
return null;
}
if (!state.routeNames.includes(action.payload.name)) {
return null;
}
// If the route already exists, navigate to it
let index = -1;
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({ params: action.payload.params });
if (id !== undefined) {
index = state.routes.findIndex(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
} else if (state.routes[currentIndex].name === action.payload.name) {
index = currentIndex;
} else {
for (let i = currentIndex; i >= 0; i--) {
if (state.routes[i].name === action.payload.name) {
index = i;
break;
}
}
}
// If the route doesn't exist, remove the current route and add the new one
if (index === -1) {
// Re-use preloaded route if available
let route = state.preloadedRoutes.find(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
if (!route) {
route = createRouteFromAction({ action, routeParamList });
}
const routes = state.routes.slice(0, currentIndex).concat(route);
return {
...state,
index: routes.length - 1,
routes,
preloadedRoutes: state.preloadedRoutes.filter(
(r) => r.key !== route.key
),
};
}
const route = state.routes[index];
let params;
if (action.payload.merge) {
params =
action.payload.params !== undefined ||
routeParamList[route.name] !== undefined
? {
...routeParamList[route.name],
...route.params,
...action.payload.params,
}
: route.params;
} else {
params = createParamsFromAction({ action, routeParamList });
}
return {
...state,
index,
routes: [
...state.routes.slice(0, index),
params !== route.params
? { ...route, params }
: state.routes[index],
],
};
}
case 'GO_BACK':
if (state.index > 0) {
return router.getStateForAction(
state,
{
type: 'POP',
payload: { count: 1 },
target: action.target,
source: action.source,
},
options
);
}
return null;
case 'PRELOAD': {
const getId = options.routeGetIdList[action.payload.name];
const id = getId?.({ params: action.payload.params });
let route: Route<string> | undefined;
if (id !== undefined) {
route = state.routes.find(
(route) =>
route.name === action.payload.name &&
id === getId?.({ params: route.params })
);
}
if (route) {
return {
...state,
routes: state.routes.map((r) => {
if (r.key !== route?.key) {
return r;
}
return {
...r,
params: createParamsFromAction({ action, routeParamList }),
};
}),
};
} else {
return {
...state,
preloadedRoutes: state.preloadedRoutes
.filter(
(r) =>
r.name !== action.payload.name ||
id !== getId?.({ params: r.params })
)
.concat(createRouteFromAction({ action, routeParamList })),
};
}
}
default:
return BaseRouter.getStateForAction(state, action);
}
},
actionCreators: StackActions,
};
return router;
}

View File

@@ -0,0 +1,546 @@
import { nanoid } from 'nanoid/non-secure';
import { BaseRouter } from './BaseRouter';
import { createParamsFromAction } from './createParamsFromAction';
import type {
CommonNavigationAction,
DefaultRouterOptions,
NavigationState,
ParamListBase,
PartialState,
Route,
Router,
} from './types';
export type TabActionType = {
type: 'JUMP_TO';
payload: { name: string; params?: object };
source?: string;
target?: string;
};
export type BackBehavior =
| 'firstRoute'
| 'initialRoute'
| 'order'
| 'history'
| 'fullHistory'
| 'none';
export type TabRouterOptions = DefaultRouterOptions & {
/**
* Control how going back should behave
* - `firstRoute` - return to the first defined route
* - `initialRoute` - return to the route from `initialRouteName`
* - `order` - return to the route defined before the focused route
* - `history` - return to last visited route; if the same route is visited multiple times, the older entries are dropped from the history
* - `fullHistory` - return to last visited route; doesn't drop duplicate entries unlike `history` - matches behavior of web pages
* - `none` - do not handle going back
*/
backBehavior?: BackBehavior;
};
export type TabNavigationState<ParamList extends ParamListBase> = Omit<
NavigationState<ParamList>,
'history'
> & {
/**
* Type of the router, in this case, it's tab.
*/
type: 'tab';
/**
* List of previously visited route keys.
*/
history: { type: 'route'; key: string; params?: object | undefined }[];
/**
* List of routes' key, which are supposed to be preloaded before navigating to.
*/
preloadedRouteKeys: string[];
};
export type TabActionHelpers<ParamList extends ParamListBase> = {
/**
* Jump to an existing tab.
*
* @param screen Name of the route to jump to.
* @param [params] Params object for the route.
*/
jumpTo<RouteName extends keyof ParamList>(
...args: RouteName extends unknown
? undefined extends ParamList[RouteName]
? [screen: RouteName, params?: ParamList[RouteName]]
: [screen: RouteName, params: ParamList[RouteName]]
: never
): void;
};
const TYPE_ROUTE = 'route' as const;
export const TabActions = {
jumpTo(name: string, params?: object) {
return {
type: 'JUMP_TO',
payload: { name, params },
} as const satisfies TabActionType;
},
};
const getRouteHistory = (
routes: Route<string>[],
index: number,
backBehavior: BackBehavior,
initialRouteName: string | undefined
) => {
const history = [
{
type: TYPE_ROUTE,
key: routes[index].key,
},
];
let initialRouteIndex;
switch (backBehavior) {
case 'order':
for (let i = index; i > 0; i--) {
history.unshift({
type: TYPE_ROUTE,
key: routes[i - 1].key,
});
}
break;
case 'firstRoute':
if (index !== 0) {
history.unshift({
type: TYPE_ROUTE,
key: routes[0].key,
});
}
break;
case 'initialRoute':
initialRouteIndex = routes.findIndex(
(route) => route.name === initialRouteName
);
initialRouteIndex = initialRouteIndex === -1 ? 0 : initialRouteIndex;
if (index !== initialRouteIndex) {
history.unshift({
type: TYPE_ROUTE,
key: routes[initialRouteIndex].key,
});
}
break;
case 'history':
case 'fullHistory':
// The history will fill up on navigation
break;
}
return history;
};
const changeIndex = (
state: TabNavigationState<ParamListBase>,
index: number,
backBehavior: BackBehavior,
initialRouteName: string | undefined
) => {
let history = state.history;
if (backBehavior === 'history' || backBehavior === 'fullHistory') {
const currentRoute = state.routes[index];
if (backBehavior === 'history') {
// Remove the existing key from the history to de-duplicate it
history = history.filter((it) =>
it.type === 'route' ? it.key !== currentRoute.key : false
);
} else if (backBehavior === 'fullHistory') {
const lastHistoryRouteItemIndex = history.findLastIndex(
(item) => item.type === 'route'
);
if (currentRoute.key === history[lastHistoryRouteItemIndex]?.key) {
// For full-history, only remove if it matches the last route
// Useful for drawer, if current route was in history, then drawer state changed
// Then we only need to move the route to the front
history = [
...history.slice(0, lastHistoryRouteItemIndex),
...history.slice(lastHistoryRouteItemIndex + 1),
];
}
}
history = history.concat({
type: TYPE_ROUTE,
key: currentRoute.key,
params: backBehavior === 'fullHistory' ? currentRoute.params : undefined,
});
} else {
history = getRouteHistory(
state.routes,
index,
backBehavior,
initialRouteName
);
}
return {
...state,
index,
history,
};
};
export function TabRouter({
initialRouteName,
backBehavior = 'firstRoute',
}: TabRouterOptions) {
const router: Router<
TabNavigationState<ParamListBase>,
TabActionType | CommonNavigationAction
> = {
...BaseRouter,
type: 'tab',
getInitialState({ routeNames, routeParamList }) {
const index =
initialRouteName !== undefined && routeNames.includes(initialRouteName)
? routeNames.indexOf(initialRouteName)
: 0;
const routes = routeNames.map((name) => ({
name,
key: `${name}-${nanoid()}`,
params: routeParamList[name],
}));
const history = getRouteHistory(
routes,
index,
backBehavior,
initialRouteName
);
return {
stale: false,
type: 'tab',
key: `tab-${nanoid()}`,
index,
routeNames,
history,
routes,
preloadedRouteKeys: [],
};
},
getRehydratedState(partialState, { routeNames, routeParamList }) {
const state = partialState;
if (state.stale === false) {
return state;
}
const routes = routeNames.map((name) => {
const route = (
state as PartialState<TabNavigationState<ParamListBase>>
).routes.find((r) => r.name === name);
return {
...route,
name,
key:
route && route.name === name && route.key
? route.key
: `${name}-${nanoid()}`,
params:
routeParamList[name] !== undefined
? {
...routeParamList[name],
...(route ? route.params : undefined),
}
: route
? route.params
: undefined,
} as Route<string>;
});
const index = Math.min(
Math.max(routeNames.indexOf(state.routes[state?.index ?? 0]?.name), 0),
routes.length - 1
);
const routeKeys = routes.map((route) => route.key);
const history =
state.history?.filter((it) => routeKeys.includes(it.key)) ?? [];
return changeIndex(
{
stale: false,
type: 'tab',
key: `tab-${nanoid()}`,
index,
routeNames,
history,
routes,
preloadedRouteKeys:
state.preloadedRouteKeys?.filter((key) =>
routeKeys.includes(key)
) ?? [],
},
index,
backBehavior,
initialRouteName
);
},
getStateForRouteNamesChange(
state,
{ routeNames, routeParamList, routeKeyChanges }
) {
const routes = routeNames.map(
(name) =>
state.routes.find(
(r) => r.name === name && !routeKeyChanges.includes(r.name)
) || {
name,
key: `${name}-${nanoid()}`,
params: routeParamList[name],
}
);
const index = Math.max(
0,
routeNames.indexOf(state.routes[state.index].name)
);
let history = state.history.filter(
// Type will always be 'route' for tabs, but could be different in a router extending this (e.g. drawer)
(it) => it.type !== 'route' || routes.find((r) => r.key === it.key)
);
if (!history.length) {
history = getRouteHistory(
routes,
index,
backBehavior,
initialRouteName
);
}
return {
...state,
history,
routeNames,
routes,
index,
};
},
getStateForRouteFocus(state, key) {
const index = state.routes.findIndex((r) => r.key === key);
if (index === -1 || index === state.index) {
return state;
}
return changeIndex(state, index, backBehavior, initialRouteName);
},
getStateForAction(state, action, { routeParamList, routeGetIdList }) {
switch (action.type) {
case 'JUMP_TO':
case 'NAVIGATE':
case 'NAVIGATE_DEPRECATED': {
const index = state.routes.findIndex(
(route) => route.name === action.payload.name
);
if (index === -1) {
return null;
}
const updatedState = changeIndex(
{
...state,
routes: state.routes.map((route) => {
if (route.name !== action.payload.name) {
return route;
}
const getId = routeGetIdList[route.name];
const currentId = getId?.({ params: route.params });
const nextId = getId?.({ params: action.payload.params });
const key =
currentId === nextId
? route.key
: `${route.name}-${nanoid()}`;
let params;
if (
(action.type === 'NAVIGATE' ||
action.type === 'NAVIGATE_DEPRECATED') &&
action.payload.merge &&
currentId === nextId
) {
params =
action.payload.params !== undefined ||
routeParamList[route.name] !== undefined
? {
...routeParamList[route.name],
...route.params,
...action.payload.params,
}
: route.params;
} else {
params = createParamsFromAction({ action, routeParamList });
}
const path =
action.type === 'NAVIGATE' && action.payload.path != null
? action.payload.path
: route.path;
return params !== route.params || path !== route.path
? { ...route, key, path, params }
: route;
}),
},
index,
backBehavior,
initialRouteName
);
return {
...updatedState,
preloadedRouteKeys: updatedState.preloadedRouteKeys.filter(
(key) => key !== state.routes[updatedState.index].key
),
};
}
case 'SET_PARAMS':
case 'REPLACE_PARAMS': {
const nextState = BaseRouter.getStateForAction(state, action);
if (nextState !== null) {
const index = nextState.index;
if (index != null) {
const focusedRoute = nextState.routes[index];
const historyItemIndex = state.history.findLastIndex(
(item) => item.key === focusedRoute.key
);
let updatedHistory = state.history;
if (historyItemIndex !== -1) {
updatedHistory = [...state.history];
updatedHistory[historyItemIndex] = {
...updatedHistory[historyItemIndex],
params: focusedRoute.params,
};
}
return {
...nextState,
history: updatedHistory,
};
}
}
return nextState;
}
case 'GO_BACK': {
if (state.history.length === 1) {
return null;
}
const previousHistoryItem = state.history[state.history.length - 2];
const previousKey = previousHistoryItem?.key;
const index = state.routes.findLastIndex(
(route) => route.key === previousKey
);
if (index === -1) {
return null;
}
let routes = state.routes;
if (
backBehavior === 'fullHistory' &&
routes[index].params !== previousHistoryItem.params
) {
routes = [...state.routes];
routes[index] = {
...routes[index],
params: previousHistoryItem.params,
};
}
return {
...state,
routes,
preloadedRouteKeys: state.preloadedRouteKeys.filter(
(key) => key !== state.routes[index].key
),
history: state.history.slice(0, -1),
index,
};
}
case 'PRELOAD': {
const routeIndex = state.routes.findIndex(
(route) => route.name === action.payload.name
);
if (routeIndex === -1) {
return null;
}
const route = state.routes[routeIndex];
const getId = routeGetIdList[route.name];
const currentId = getId?.({ params: route.params });
const nextId = getId?.({ params: action.payload.params });
const key =
currentId === nextId ? route.key : `${route.name}-${nanoid()}`;
const params = createParamsFromAction({ action, routeParamList });
const newRoute =
params !== route.params ? { ...route, key, params } : route;
return {
...state,
preloadedRouteKeys: state.preloadedRouteKeys
.filter((key) => key !== route.key)
.concat(newRoute.key),
routes: state.routes.map((route, index) =>
index === routeIndex ? newRoute : route
),
history:
key === route.key
? state.history
: state.history.filter((record) => record.key !== route.key),
};
}
default:
return BaseRouter.getStateForAction(state, action);
}
},
actionCreators: TabActions,
};
return router;
}

View File

@@ -0,0 +1,22 @@
import type { ParamListBase } from './types';
type Options = {
action: {
payload: {
name: string;
params?: object;
};
};
routeParamList: ParamListBase;
};
export function createParamsFromAction({ action, routeParamList }: Options) {
const { name, params } = action.payload;
return routeParamList[name] !== undefined
? {
...routeParamList[name],
...params,
}
: params;
}

View File

@@ -0,0 +1,24 @@
import { nanoid } from 'nanoid/non-secure';
import { createParamsFromAction } from './createParamsFromAction';
import type { ParamListBase } from './types';
type Options = {
action: {
payload: {
name: string;
params?: object;
};
};
routeParamList: ParamListBase;
};
export function createRouteFromAction({ action, routeParamList }: Options) {
const { name } = action.payload;
return {
key: `${name}-${nanoid()}`,
name,
params: createParamsFromAction({ action, routeParamList }),
};
}

28
node_modules/@react-navigation/routers/src/index.tsx generated vendored Normal file
View File

@@ -0,0 +1,28 @@
import * as CommonActions from './CommonActions';
export { CommonActions };
export { BaseRouter } from './BaseRouter';
export type {
DrawerActionHelpers,
DrawerActionType,
DrawerNavigationState,
DrawerRouterOptions,
DrawerStatus,
} from './DrawerRouter';
export { DrawerActions, DrawerRouter } from './DrawerRouter';
export type {
StackActionHelpers,
StackActionType,
StackNavigationState,
StackRouterOptions,
} from './StackRouter';
export { StackActions, StackRouter } from './StackRouter';
export type {
TabActionHelpers,
TabActionType,
TabNavigationState,
TabRouterOptions,
} from './TabRouter';
export { TabActions, TabRouter } from './TabRouter';
export * from './types';

228
node_modules/@react-navigation/routers/src/types.tsx generated vendored Normal file
View File

@@ -0,0 +1,228 @@
import type * as CommonActions from './CommonActions';
export type CommonNavigationAction = CommonActions.Action;
export type NavigationRoute<
ParamList extends ParamListBase,
RouteName extends keyof ParamList,
> = Route<Extract<RouteName, string>, ParamList[RouteName]> & {
state?: NavigationState | PartialState<NavigationState>;
};
export type NavigationState<ParamList extends ParamListBase = ParamListBase> =
Readonly<{
/**
* Unique key for the navigation state.
*/
key: string;
/**
* Index of the currently focused route.
*/
index: number;
/**
* List of valid route names as defined in the screen components.
*/
routeNames: Extract<keyof ParamList, string>[];
/**
* Alternative entries for history.
*/
history?: unknown[];
/**
* List of rendered routes.
*/
routes: NavigationRoute<ParamList, keyof ParamList>[];
/**
* Custom type for the state, whether it's for tab, stack, drawer etc.
* During rehydration, the state will be discarded if type doesn't match with router type.
* It can also be used to detect the type of the navigator we're dealing with.
*/
type: string;
/**
* Whether the navigation state has been rehydrated.
*/
stale: false;
}>;
export type InitialState = Readonly<
Partial<Omit<NavigationState, 'stale' | 'routes'>> & {
routes: (Omit<Route<string>, 'key'> & { state?: InitialState })[];
}
>;
export type PartialRoute<R extends Route<string>> = Omit<R, 'key'> & {
key?: string;
state?: PartialState<NavigationState>;
};
export type PartialState<State extends NavigationState> = Partial<
Omit<State, 'stale' | 'routes'>
> &
Readonly<{
stale?: true;
routes: PartialRoute<Route<State['routeNames'][number]>>[];
}>;
export type Route<
RouteName extends string,
Params extends object | undefined = object | undefined,
> = Readonly<{
/**
* Unique key for the route.
*/
key: string;
/**
* User-provided name for the route.
*/
name: RouteName;
/**
* Path associated with the route.
* Usually present when the screen was opened from a deep link.
*/
path?: string;
}> &
(undefined extends Params
? Readonly<{
/**
* Params for this route
*/
params?: Readonly<Params>;
}>
: Readonly<{
/**
* Params for this route
*/
params: Readonly<Params>;
}>);
export type ParamListBase = Record<string, object | undefined>;
export type NavigationAction = Readonly<{
/**
* Type of the action (e.g. `NAVIGATE`)
*/
type: string;
/**
* Additional data for the action
*/
payload?: object;
/**
* Key of the route which dispatched this action.
*/
source?: string;
/**
* Key of the navigator which should handle this action.
*/
target?: string;
}>;
export type ActionCreators<Action extends NavigationAction> = {
[key: string]: (...args: any) => Action;
};
export type DefaultRouterOptions<RouteName extends string = string> = {
/**
* Name of the route to focus by on initial render.
* If not specified, usually the first route is used.
*/
initialRouteName?: RouteName;
};
export type RouterFactory<
State extends NavigationState,
Action extends NavigationAction,
RouterOptions extends DefaultRouterOptions,
> = (options: RouterOptions) => Router<State, Action>;
export type RouterConfigOptions = {
routeNames: string[];
routeParamList: ParamListBase;
routeGetIdList: Record<
string,
| ((options: { params?: Record<string, any> }) => string | undefined)
| undefined
>;
};
export type Router<
State extends NavigationState,
Action extends NavigationAction,
> = {
/**
* Type of the router. Should match the `type` property in state.
* If the type doesn't match, the state will be discarded during rehydration.
*/
type: State['type'];
/**
* Initialize the navigation state.
*
* @param options.routeNames List of valid route names as defined in the screen components.
* @param options.routeParamsList Object containing params for each route.
*/
getInitialState(options: RouterConfigOptions): State;
/**
* Rehydrate the full navigation state from a given partial state.
*
* @param partialState Navigation state to rehydrate from.
* @param options.routeNames List of valid route names as defined in the screen components.
* @param options.routeParamsList Object containing params for each route.
*/
getRehydratedState(
partialState: PartialState<State> | State,
options: RouterConfigOptions
): State;
/**
* Take the current state and updated list of route names, and return a new state.
*
* @param state State object to update.
* @param options.routeNames New list of route names.
* @param options.routeParamsList Object containing params for each route.
*/
getStateForRouteNamesChange(
state: State,
options: RouterConfigOptions & {
/**
* List of routes whose key has changed even if they still have the same name.
* This allows to remove screens declaratively.
*/
routeKeyChanges: string[];
}
): State;
/**
* Take the current state and key of a route, and return a new state with the route focused
*
* @param state State object to apply the action on.
* @param key Key of the route to focus.
*/
getStateForRouteFocus(state: State, key: string): State;
/**
* Take the current state and action, and return a new state.
* If the action cannot be handled, return `null`.
*
* @param state State object to apply the action on.
* @param action Action object to apply.
* @param options.routeNames List of valid route names as defined in the screen components.
* @param options.routeParamsList Object containing params for each route.
*/
getStateForAction(
state: State,
action: Action,
options: RouterConfigOptions
): State | PartialState<State> | null;
/**
* Whether the action should also change focus in parent navigator
*
* @param action Action object to check.
*/
shouldActionChangeFocus(action: NavigationAction): boolean;
/**
* Action creators for the router.
*/
actionCreators?: ActionCreators<Action>;
};