1 line
25 KiB
Plaintext
1 line
25 KiB
Plaintext
{"version":3,"sources":["StackRouter.tsx"],"names":["nanoid","BaseRouter","StackActions","replace","name","params","type","payload","push","pop","count","popToTop","StackRouter","options","router","getInitialState","routeNames","routeParamList","initialRouteName","undefined","includes","stale","key","index","routes","getRehydratedState","partialState","state","filter","route","map","length","getStateForRouteNamesChange","Math","min","getStateForRouteFocus","findIndex","r","slice","getStateForAction","action","target","source","i","getId","routeGetIdList","id","find","max","concat","merge","actionCreators"],"mappings":"AAAA,SAASA,MAAT,QAAuB,mBAAvB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAkFA,OAAO,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,OAAO,CAACC,IAAD,EAAeC,MAAf,EAAiD;AACtD,WAAO;AAAEC,MAAAA,IAAI,EAAE,SAAR;AAAmBC,MAAAA,OAAO,EAAE;AAAEH,QAAAA,IAAF;AAAQC,QAAAA;AAAR;AAA5B,KAAP;AACD,GAHyB;;AAI1BG,EAAAA,IAAI,CAACJ,IAAD,EAAeC,MAAf,EAAiD;AACnD,WAAO;AAAEC,MAAAA,IAAI,EAAE,MAAR;AAAgBC,MAAAA,OAAO,EAAE;AAAEH,QAAAA,IAAF;AAAQC,QAAAA;AAAR;AAAzB,KAAP;AACD,GANyB;;AAO1BI,EAAAA,GAAG,CAACC,KAAa,GAAG,CAAjB,EAAqC;AACtC,WAAO;AAAEJ,MAAAA,IAAI,EAAE,KAAR;AAAeC,MAAAA,OAAO,EAAE;AAAEG,QAAAA;AAAF;AAAxB,KAAP;AACD,GATyB;;AAU1BC,EAAAA,QAAQ,GAAoB;AAC1B,WAAO;AAAEL,MAAAA,IAAI,EAAE;AAAR,KAAP;AACD;;AAZyB,CAArB;AAeP,eAAe,SAASM,WAAT,CAAqBC,OAArB,EAAkD;AAC/D,QAAMC,MAGL,GAAG,EACF,GAAGb,UADD;AAGFK,IAAAA,IAAI,EAAE,OAHJ;;AAKFS,IAAAA,eAAe,CAAC;AAAEC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xB,MAAjB,GACI,EAAE,GAAGwB,KAAL;AAAYxB,gBAAAA;AAAZ,eADJ,GAEIsB,KAAK,CAACH,MAAN,CAAaD,KAAb,CAJE;AAHH,aAAP;AAUD;;AAED,iBAAO,IAAP;;AAEF,aAAK,SAAL;AACE,cAAII,KAAK,CAACJ,KAAN,GAAc,CAAlB,EAAqB;AACnB,mBAAOT,MAAM,CAACyB,iBAAP,CACLZ,KADK,EAEL;AACErB,cAAAA,IAAI,EAAE,KADR;AAEEC,cAAAA,OAAO,EAAE;AAAEG,gBAAAA,KAAK,EAAE;AAAT,eAFX;AAGE+B,cAAAA,MAAM,EAAED,MAAM,CAACC,MAHjB;AAIEC,cAAAA,MAAM,EAAEF,MAAM,CAACE;AAJjB,aAFK,EAQL7B,OARK,CAAP;AAUD;;AAED,iBAAO,IAAP;;AAEF;AACE,iBAAOZ,UAAU,CAACsC,iBAAX,CAA6BZ,KAA7B,EAAoCa,MAApC,CAAP;AAnQJ;AAqQD,KA5XC;;AA8XFW,IAAAA,cAAc,EAAEjD;AA9Xd,GAHJ;AAoYA,SAAOY,MAAP;AACD","sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport BaseRouter from './BaseRouter';\nimport type {\n NavigationState,\n CommonNavigationAction,\n Router,\n DefaultRouterOptions,\n Route,\n ParamListBase,\n} from './types';\n\nexport type StackActionType =\n | {\n type: 'REPLACE';\n payload: { name: string; key?: string | undefined; params?: object };\n source?: string;\n target?: string;\n }\n | {\n type: 'PUSH';\n payload: { name: string; key?: string | undefined; params?: object };\n source?: string;\n target?: string;\n }\n | {\n type: 'POP';\n payload: { count: number };\n source?: string;\n target?: string;\n }\n | {\n type: 'POP_TO_TOP';\n source?: string;\n target?: string;\n };\n\nexport type StackRouterOptions = DefaultRouterOptions;\n\nexport type StackNavigationState<\n ParamList extends ParamListBase\n> = NavigationState<ParamList> & {\n /**\n * Type of the router, in this case, it's stack.\n */\n type: 'stack';\n};\n\nexport type StackActionHelpers<ParamList extends ParamListBase> = {\n /**\n * Replace the current route with a new one.\n *\n * @param name Route name of the new route.\n * @param [params] Params object for the new route.\n */\n replace<RouteName extends keyof ParamList>(\n ...args: undefined extends ParamList[RouteName]\n ? [RouteName] | [RouteName, ParamList[RouteName]]\n : [RouteName, ParamList[RouteName]]\n ): void;\n\n /**\n * Push a new screen onto the stack.\n *\n * @param name Name of the route for the tab.\n * @param [params] Params object for the route.\n */\n push<RouteName extends keyof ParamList>(\n ...args: undefined extends ParamList[RouteName]\n ? [RouteName] | [RouteName, ParamList[RouteName]]\n : [RouteName, ParamList[RouteName]]\n ): void;\n\n /**\n * Pop a screen from the stack.\n */\n pop(count?: number): void;\n\n /**\n * Pop to the first route in the stack, dismissing all other screens.\n */\n popToTop(): void;\n};\n\nexport const StackActions = {\n replace(name: string, params?: object): StackActionType {\n return { type: 'REPLACE', payload: { name, params } };\n },\n push(name: string, params?: object): StackActionType {\n return { type: 'PUSH', payload: { name, params } };\n },\n pop(count: number = 1): StackActionType {\n return { type: 'POP', payload: { count } };\n },\n popToTop(): StackActionType {\n return { type: 'POP_TO_TOP' };\n },\n};\n\nexport default function StackRouter(options: StackRouterOptions) {\n const router: Router<\n StackNavigationState<ParamListBase>,\n CommonNavigationAction | StackActionType\n > = {\n ...BaseRouter,\n\n type: 'stack',\n\n getInitialState({ routeNames, routeParamList }) {\n const initialRouteName =\n options.initialRouteName !== undefined &&\n routeNames.includes(options.initialRouteName)\n ? options.initialRouteName\n : routeNames[0];\n\n return {\n stale: false,\n type: 'stack',\n key: `stack-${nanoid()}`,\n index: 0,\n routeNames,\n routes: [\n {\n key: `${initialRouteName}-${nanoid()}`,\n name: initialRouteName,\n params: routeParamList[initialRouteName],\n },\n ],\n };\n },\n\n getRehydratedState(partialState, { routeNames, routeParamList }) {\n let state = partialState;\n\n if (state.stale === false) {\n return state;\n }\n\n const routes = state.routes\n .filter((route) => routeNames.includes(route.name))\n .map(\n (route) =>\n ({\n ...route,\n key: route.key || `${route.name}-${nanoid()}`,\n params:\n routeParamList[route.name] !== undefined\n ? {\n ...routeParamList[route.name],\n ...route.params,\n }\n : route.params,\n } as Route<string>)\n );\n\n if (routes.length === 0) {\n const initialRouteName =\n options.initialRouteName !== undefined\n ? options.initialRouteName\n : routeNames[0];\n\n routes.push({\n key: `${initialRouteName}-${nanoid()}`,\n name: initialRouteName,\n params: routeParamList[initialRouteName],\n });\n }\n\n return {\n stale: false,\n type: 'stack',\n key: `stack-${nanoid()}`,\n index: routes.length - 1,\n routeNames,\n routes,\n };\n },\n\n getStateForRouteNamesChange(state, { routeNames, routeParamList }) {\n const routes = state.routes.filter((route) =>\n routeNames.includes(route.name)\n );\n\n if (routes.length === 0) {\n const initialRouteName =\n options.initialRouteName !== undefined &&\n routeNames.includes(options.initialRouteName)\n ? options.initialRouteName\n : routeNames[0];\n\n routes.push({\n key: `${initialRouteName}-${nanoid()}`,\n name: initialRouteName,\n params: routeParamList[initialRouteName],\n });\n }\n\n return {\n ...state,\n routeNames,\n routes,\n index: Math.min(state.index, routes.length - 1),\n };\n },\n\n getStateForRouteFocus(state, key) {\n const index = state.routes.findIndex((r) => r.key === key);\n\n if (index === -1 || index === state.index) {\n return state;\n }\n\n return {\n ...state,\n index,\n routes: state.routes.slice(0, index + 1),\n };\n },\n\n getStateForAction(state, action, options) {\n const { routeParamList } = options;\n\n switch (action.type) {\n case 'REPLACE': {\n const index =\n action.target === state.key && action.source\n ? state.routes.findIndex((r) => r.key === action.source)\n : state.index;\n\n if (index === -1) {\n return null;\n }\n\n const { name, key, params } = action.payload;\n\n if (!state.routeNames.includes(name)) {\n return null;\n }\n\n return {\n ...state,\n routes: state.routes.map((route, i) =>\n i === index\n ? {\n key: key !== undefined ? key : `${name}-${nanoid()}`,\n name,\n params:\n routeParamList[name] !== undefined\n ? {\n ...routeParamList[name],\n ...params,\n }\n : params,\n }\n : route\n ),\n };\n }\n\n case 'PUSH':\n if (state.routeNames.includes(action.payload.name)) {\n const getId = options.routeGetIdList[action.payload.name];\n const id = getId?.({ params: action.payload.params });\n\n const route =\n action.payload.name && action.payload.key\n ? state.routes.find(\n (route) =>\n route.name === action.payload.name &&\n route.key === action.payload.key\n )\n : id\n ? state.routes.find(\n (route) =>\n route.name === action.payload.name &&\n id === getId?.({ params: route.params })\n )\n : undefined;\n\n let routes: Route<string>[];\n\n if (route) {\n routes = state.routes.filter((r) => r.key !== route.key);\n routes.push({\n ...route,\n params:\n action.payload.params !== undefined\n ? {\n ...route.params,\n ...action.payload.params,\n }\n : route.params,\n });\n } else {\n routes = [\n ...state.routes,\n {\n key:\n action.payload.key ?? `${action.payload.name}-${nanoid()}`,\n name: action.payload.name,\n params:\n routeParamList[action.payload.name] !== undefined\n ? {\n ...routeParamList[action.payload.name],\n ...action.payload.params,\n }\n : action.payload.params,\n },\n ];\n }\n\n return {\n ...state,\n index: routes.length - 1,\n routes,\n };\n }\n\n return null;\n\n case 'POP': {\n const index =\n action.target === state.key && action.source\n ? state.routes.findIndex((r) => r.key === action.source)\n : state.index;\n\n if (index > 0) {\n const count = Math.max(index - action.payload.count + 1, 1);\n const routes = state.routes\n .slice(0, count)\n .concat(state.routes.slice(index + 1));\n\n return {\n ...state,\n index: routes.length - 1,\n routes,\n };\n }\n\n return null;\n }\n\n case 'POP_TO_TOP':\n return router.getStateForAction(\n state,\n {\n type: 'POP',\n payload: { count: state.routes.length - 1 },\n },\n options\n );\n\n case 'NAVIGATE':\n if (\n action.payload.name !== undefined &&\n !state.routeNames.includes(action.payload.name)\n ) {\n return null;\n }\n\n if (action.payload.key || action.payload.name) {\n // If the route already exists, navigate to that\n let index = -1;\n\n const getId =\n // `getId` and `key` can't be used together\n action.payload.key === undefined &&\n action.payload.name !== undefined\n ? options.routeGetIdList[action.payload.name]\n : undefined;\n const id = getId?.({ params: action.payload.params });\n\n if (id) {\n index = state.routes.findIndex(\n (route) =>\n route.name === action.payload.name &&\n id === getId?.({ params: route.params })\n );\n } else if (\n (state.routes[state.index].name === action.payload.name &&\n action.payload.key === undefined) ||\n state.routes[state.index].key === action.payload.key\n ) {\n index = state.index;\n } else {\n for (let i = state.routes.length - 1; i >= 0; i--) {\n if (\n (state.routes[i].name === action.payload.name &&\n action.payload.key === undefined) ||\n state.routes[i].key === action.payload.key\n ) {\n index = i;\n break;\n }\n }\n }\n\n if (\n index === -1 &&\n action.payload.key &&\n action.payload.name === undefined\n ) {\n return null;\n }\n\n if (index === -1 && action.payload.name !== undefined) {\n const routes = [\n ...state.routes,\n {\n key:\n action.payload.key ?? `${action.payload.name}-${nanoid()}`,\n name: action.payload.name,\n params:\n routeParamList[action.payload.name] !== undefined\n ? {\n ...routeParamList[action.payload.name],\n ...action.payload.params,\n }\n : action.payload.params,\n },\n ];\n\n return {\n ...state,\n routes,\n index: routes.length - 1,\n };\n }\n\n const route = state.routes[index];\n\n let params;\n\n if (action.payload.merge === false) {\n params =\n routeParamList[route.name] !== undefined\n ? {\n ...routeParamList[route.name],\n ...action.payload.params,\n }\n : action.payload.params;\n } else {\n params = action.payload.params\n ? {\n ...route.params,\n ...action.payload.params,\n }\n : route.params;\n }\n\n return {\n ...state,\n index,\n routes: [\n ...state.routes.slice(0, index),\n params !== route.params\n ? { ...route, params }\n : state.routes[index],\n ],\n };\n }\n\n return null;\n\n case 'GO_BACK':\n if (state.index > 0) {\n return router.getStateForAction(\n state,\n {\n type: 'POP',\n payload: { count: 1 },\n target: action.target,\n source: action.source,\n },\n options\n );\n }\n\n return null;\n\n default:\n return BaseRouter.getStateForAction(state, action);\n }\n },\n\n actionCreators: StackActions,\n };\n\n return router;\n}\n"]} |