first commit

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

View File

@@ -0,0 +1,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,GAC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K,IACjCA,KAAK,CAACR,GAAG,GAAGQ,KAAK,GAAG;gBAAE,GAAGA,KAAK;gBAAER,GAAG,EAAE,GAAGQ,KAAK,CAACG,IAAI,IAAItB,MAAM,CAAC,CAAC;cAAG,CACnE;YACF,CAAC;UACH;UAEA,OAAOgB,SAAS;QAClB;MAEA;QACE,OAAO,IAAI;IACf;EACF,CAAC;EAEDQ,uBAAuBA,CAACpB,MAA8B,EAAE;IACtD,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,IAAID,MAAM,CAACC,IAAI,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,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;IAC/B,MAAM,CAACC,IAAI,EAAEC,MAAM,EAAEC,OAAO,CAAC,GAAGH,IAAI;IAEpC,IAAI,OAAOG,OAAO,KAAK,SAAS,EAAE;MAChCC,OAAO,CAACC,IAAI,CACV,sGACF,CAAC;IACH;IAEA,OAAO;MACLP,IAAI,EAAE,UAAU;MAChBQ,OAAO,EAAE;QACPL,IAAI;QACJC,MAAM;QACNK,KAAK,EAAE,OAAOJ,OAAO,KAAK,SAAS,GAAGA,OAAO,GAAGA,OAAO,EAAEI,KAAK;QAC9DC,GAAG,EAAEL,OAAO,EAAEK;MAChB;IACF,CAAC;EACH,CAAC,MAAM;IACL,MAAMF,OAAO,GAAGN,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,EAAE,MAAM,IAAIM,OAAO,CAAC,EAAE;MACxB,MAAM,IAAIG,KAAK,CACb,8JACF,CAAC;IACH;IAEA,OAAO;MAAEX,IAAI,EAAE,UAAU;MAAEQ;IAAQ,CAAC;EACtC;AACF;AAEA,OAAO,SAASI,kBAAkBA,CAChC,GAAGV,IAG6C,EACxC;EACR,IAAI,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;IAC/B,OAAO;MACLF,IAAI,EAAE,qBAAqB;MAC3BQ,OAAO,EAAE;QAAEL,IAAI,EAAED,IAAI,CAAC,CAAC,CAAC;QAAEE,MAAM,EAAEF,IAAI,CAAC,CAAC;MAAE;IAC5C,CAAC;EACH,CAAC,MAAM;IACL,MAAMM,OAAO,GAAGN,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,EAAE,MAAM,IAAIM,OAAO,CAAC,EAAE;MACxB,MAAM,IAAIG,KAAK,CACb,8KACF,CAAC;IACH;IAEA,OAAO;MAAEX,IAAI,EAAE,qBAAqB;MAAEQ;IAAQ,CAAC;EACjD;AACF;AAEA,OAAO,SAASK,KAAKA,CAACC,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":";;AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,SAEEC,UAAU,EAGVC,SAAS,QAEJ,gBAAa;AA4DpB,OAAO,MAAMC,aAAa,GAAG;EAC3B,GAAGF,UAAU;EACbG,UAAUA,CAAA,EAAG;IACX,OAAO;MAAEC,IAAI,EAAE;IAAc,CAAC;EAChC,CAAC;EACDC,WAAWA,CAAA,EAAG;IACZ,OAAO;MAAED,IAAI,EAAE;IAAe,CAAC;EACjC,CAAC;EACDE,YAAYA,CAAA,EAAG;IACb,OAAO;MAAEF,IAAI,EAAE;IAAgB,CAAC;EAClC;AACF,CAAC;AAED,OAAO,SAASG,YAAYA,CAAC;EAC3BC,aAAa,GAAG,QAAQ;EACxB,GAAGC;AACgB,CAAC,EAGpB;EACA,MAAMC,MAAM,GAAGT,SAAS,CAACQ,IAAI,CAG5B;EAED,MAAME,iBAAiB,GACrBC,KAEsD,IACnDC,OAAO,CAACD,KAAK,CAACE,OAAO,EAAEC,IAAI,CAAEC,EAAE,IAAKA,EAAE,CAACZ,IAAI,KAAK,QAAQ,CAAC,CAAC;EAE/D,MAAMa,kBAAkB,GACtBL,KAA2C,IACF;IACzC,IAAID,iBAAiB,CAACC,KAAK,CAAC,EAAE;MAC5B,OAAOA,KAAK;IACd;IAEA,OAAO;MACL,GAAGA,KAAK;MACRE,OAAO,EAAE,CACP,GAAGF,KAAK,CAACE,OAAO,EAChB;QACEV,IAAI,EAAE,QAAQ;QAC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AKvB,KAAK,CAACuB,KAAK,EAAE;cAClD,OAAO9B,WAAW,CAAC0B,MAA8C,CAAC;YACpE;YAEA,OAAOA,MAAM;UACf;QAEA,KAAK,SAAS;UACZ,IAAIpB,iBAAiB,CAACC,KAAK,CAAC,EAAE;YAC5B,OAAOO,uBAAuB,CAACP,KAAK,CAAC;UACvC;UAEA,OAAOF,MAAM,CAACsB,iBAAiB,CAACpB,KAAK,EAAEqB,MAAM,EAAEC,OAAO,CAAC;QAEzD;UACE,OAAOxB,MAAM,CAACsB,iBAAiB,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":[]}