{"version":3,"sources":["TabRouter.tsx"],"names":["TYPE_ROUTE","TabActions","jumpTo","name","params","type","payload","getRouteHistory","routes","index","backBehavior","initialRouteName","history","key","initialRouteIndex","i","unshift","findIndex","route","changeIndex","state","currentKey","filter","it","concat","TabRouter","router","BaseRouter","getInitialState","routeNames","routeParamList","undefined","includes","indexOf","map","stale","getRehydratedState","partialState","find","r","Math","min","max","length","getStateForRouteNamesChange","getStateForRouteFocus","getStateForAction","action","merge","previousKey","slice","shouldActionChangeFocus","actionCreators"],"mappings":";;;;;;;;AAAA;;AACA;;;;AAyDA,MAAMA,UAAU,GAAG,OAAnB;AAEO,MAAMC,UAAU,GAAG;AACxBC,EAAAA,MAAM,CAACC,IAAD,EAAeC,MAAf,EAA+C;AACnD,WAAO;AAAEC,MAAAA,IAAI,EAAE,SAAR;AAAmBC,MAAAA,OAAO,EAAE;AAAEH,QAAAA,IAAF;AAAQC,QAAAA;AAAR;AAA5B,KAAP;AACD;;AAHuB,CAAnB;;;AAMP,MAAMG,eAAe,GAAG,CACtBC,MADsB,EAEtBC,KAFsB,EAGtBC,YAHsB,EAItBC,gBAJsB,KAKnB;AACH,QAAMC,OAAO,GAAG,CAAC;AAAEP,IAAAA,IAAI,EAAEL,UAAR;AAAoBa,IAAAA,GAAG,EAAEL,MAAM,CAACC,KAAD,CAAN,CAAcI;AAAvC,GAAD,CAAhB;AACA,MAAIC,iBAAJ;;AAEA,UAAQJ,YAAR;AACE,SAAK,OAAL;AACE,WAAK,IAAIK,CAAC,GAAGN,KAAb,EAAoBM,CAAC,GAAG,CAAxB,EAA2BA,CAAC,EAA5B,EAAgC;AAC9BH,QAAAA,OAAO,CAACI,OAAR,CAAgB;AAAEX,UAAAA,IAAI,EAAEL,UAAR;AAAoBa,UAAAA,GAAG,EAAEL,MAAM,CAACO,CAAC,GAAG,CAAL,CAAN,CAAcF;AAAvC,SAAhB;AACD;;AACD;;AACF,SAAK,YAAL;AACE,UAAIJ,KAAK,KAAK,CAAd,EAAiB;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,CAACR,OAAN,CAAcQ,KAAK,CAACR,OAAN,CAAc+B,MAAd,GAAuB,CAArC,EAAwC9B,GAA5D;AACA,kBAAMJ,KAAK,GAAGW,KAAK,CAACZ,MAAN,CAAaS,SAAb,CACXC,KAAD,IAAWA,KAAK,CAACL,GAAN,KAAcoC,WADb,CAAd;;AAIA,gBAAIxC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,qBAAO,IAAP;AACD;;AAED,mBAAO,EACL,GAAGW,KADE;AAELR,cAAAA,OAAO,EAAEQ,KAAK,CAACR,OAAN,CAAcsC,KAAd,CAAoB,CAApB,EAAuB,CAAC,CAAxB,CAFJ;AAGLzC,cAAAA;AAHK,aAAP;AAKD;;AAED;AACE,iBAAOkB,oBAAWmB,iBAAX,CAA6B1B,KAA7B,EAAoC2B,MAApC,CAAP;AArFJ;AAuFD,KAnOC;;AAqOFI,IAAAA,uBAAuB,CAACJ,MAAD,EAAS;AAC9B,aAAOA,MAAM,CAAC1C,IAAP,KAAgB,UAAvB;AACD,KAvOC;;AAyOF+C,IAAAA,cAAc,EAAEnD;AAzOd,GAHJ;AA+OA,SAAOyB,MAAP;AACD","sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport BaseRouter from './BaseRouter';\nimport type {\n NavigationState,\n PartialState,\n CommonNavigationAction,\n Router,\n DefaultRouterOptions,\n Route,\n ParamListBase,\n} from './types';\n\nexport type TabActionType = {\n type: 'JUMP_TO';\n payload: { name: string; params?: object };\n source?: string;\n target?: string;\n};\n\nexport type BackBehavior =\n | 'initialRoute'\n | 'firstRoute'\n | 'history'\n | 'order'\n | 'none';\n\nexport type TabRouterOptions = DefaultRouterOptions & {\n backBehavior?: BackBehavior;\n};\n\nexport type TabNavigationState = Omit<\n NavigationState,\n 'history'\n> & {\n /**\n * Type of the router, in this case, it's tab.\n */\n type: 'tab';\n /**\n * List of previously visited route keys.\n */\n history: { type: 'route'; key: string }[];\n};\n\nexport type TabActionHelpers = {\n /**\n * Jump to an existing tab.\n *\n * @param name Name of the route for the tab.\n * @param [params] Params object for the route.\n */\n jumpTo>(\n ...args: undefined extends ParamList[RouteName]\n ? [RouteName] | [RouteName, ParamList[RouteName]]\n : [RouteName, ParamList[RouteName]]\n ): void;\n};\n\nconst TYPE_ROUTE = 'route' as const;\n\nexport const TabActions = {\n jumpTo(name: string, params?: object): TabActionType {\n return { type: 'JUMP_TO', payload: { name, params } };\n },\n};\n\nconst getRouteHistory = (\n routes: Route[],\n index: number,\n backBehavior: BackBehavior,\n initialRouteName: string | undefined\n) => {\n const history = [{ type: TYPE_ROUTE, key: routes[index].key }];\n let initialRouteIndex;\n\n switch (backBehavior) {\n case 'order':\n for (let i = index; i > 0; i--) {\n history.unshift({ type: TYPE_ROUTE, key: routes[i - 1].key });\n }\n break;\n case 'firstRoute':\n if (index !== 0) {\n history.unshift({\n type: TYPE_ROUTE,\n key: routes[0].key,\n });\n }\n break;\n case 'initialRoute':\n initialRouteIndex = routes.findIndex(\n (route) => route.name === initialRouteName\n );\n initialRouteIndex = initialRouteIndex === -1 ? 0 : initialRouteIndex;\n\n if (index !== initialRouteIndex) {\n history.unshift({\n type: TYPE_ROUTE,\n key: routes[initialRouteIndex].key,\n });\n }\n break;\n case 'history':\n // The history will fill up on navigation\n break;\n }\n\n return history;\n};\n\nconst changeIndex = (\n state: TabNavigationState,\n index: number,\n backBehavior: BackBehavior,\n initialRouteName: string | undefined\n) => {\n let history;\n\n if (backBehavior === 'history') {\n const currentKey = state.routes[index].key;\n\n history = state.history\n .filter((it) => (it.type === 'route' ? it.key !== currentKey : false))\n .concat({ type: TYPE_ROUTE, key: currentKey });\n } else {\n history = getRouteHistory(\n state.routes,\n index,\n backBehavior,\n initialRouteName\n );\n }\n\n return {\n ...state,\n index,\n history,\n };\n};\n\nexport default function TabRouter({\n initialRouteName,\n backBehavior = 'history',\n}: TabRouterOptions) {\n const router: Router<\n TabNavigationState,\n TabActionType | CommonNavigationAction\n > = {\n ...BaseRouter,\n\n type: 'tab',\n\n getInitialState({ routeNames, routeParamList }) {\n const index =\n initialRouteName !== undefined && routeNames.includes(initialRouteName)\n ? routeNames.indexOf(initialRouteName)\n : 0;\n\n const routes = routeNames.map((name) => ({\n name,\n key: `${name}-${nanoid()}`,\n params: routeParamList[name],\n }));\n\n const history = getRouteHistory(\n routes,\n index,\n backBehavior,\n initialRouteName\n );\n\n return {\n stale: false,\n type: 'tab',\n key: `tab-${nanoid()}`,\n index,\n routeNames,\n history,\n routes,\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 = routeNames.map((name) => {\n const route = (state as PartialState<\n TabNavigationState\n >).routes.find((r) => r.name === name);\n\n return {\n ...route,\n name,\n key:\n route && route.name === name && route.key\n ? route.key\n : `${name}-${nanoid()}`,\n params:\n routeParamList[name] !== undefined\n ? {\n ...routeParamList[name],\n ...(route ? route.params : undefined),\n }\n : route\n ? route.params\n : undefined,\n } as Route;\n });\n\n const index = Math.min(\n Math.max(routeNames.indexOf(state.routes[state?.index ?? 0]?.name), 0),\n routes.length - 1\n );\n\n const history =\n state.history?.filter((it) => routes.find((r) => r.key === it.key)) ??\n [];\n\n return changeIndex(\n {\n stale: false,\n type: 'tab',\n key: `tab-${nanoid()}`,\n index,\n routeNames,\n history,\n routes,\n },\n index,\n backBehavior,\n initialRouteName\n );\n },\n\n getStateForRouteNamesChange(state, { routeNames, routeParamList }) {\n const routes = routeNames.map(\n (name) =>\n state.routes.find((r) => r.name === name) || {\n name,\n key: `${name}-${nanoid()}`,\n params: routeParamList[name],\n }\n );\n\n const index = Math.max(\n 0,\n routeNames.indexOf(state.routes[state.index].name)\n );\n\n let history = state.history.filter(\n // Type will always be 'route' for tabs, but could be different in a router extending this (e.g. drawer)\n (it) => it.type !== 'route' || routes.find((r) => r.key === it.key)\n );\n\n if (!history.length) {\n history = getRouteHistory(\n routes,\n index,\n backBehavior,\n initialRouteName\n );\n }\n\n return {\n ...state,\n history,\n routeNames,\n routes,\n index,\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 changeIndex(state, index, backBehavior, initialRouteName);\n },\n\n getStateForAction(state, action, { routeParamList }) {\n switch (action.type) {\n case 'JUMP_TO':\n case 'NAVIGATE': {\n let index = -1;\n\n if (action.type === 'NAVIGATE' && action.payload.key) {\n index = state.routes.findIndex(\n (route) => route.key === action.payload.key\n );\n } else {\n index = state.routes.findIndex(\n (route) => route.name === action.payload.name\n );\n }\n\n if (index === -1) {\n return null;\n }\n\n return changeIndex(\n {\n ...state,\n routes:\n action.payload.params !== undefined\n ? state.routes.map((route, i) => {\n if (i !== index) {\n return route;\n }\n\n let params;\n\n if (\n action.type === 'NAVIGATE' &&\n action.payload.merge === false\n ) {\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 params !== route.params\n ? { ...route, params }\n : route;\n })\n : state.routes,\n },\n index,\n backBehavior,\n initialRouteName\n );\n }\n\n case 'GO_BACK': {\n if (state.history.length === 1) {\n return null;\n }\n\n const previousKey = state.history[state.history.length - 2].key;\n const index = state.routes.findIndex(\n (route) => route.key === previousKey\n );\n\n if (index === -1) {\n return null;\n }\n\n return {\n ...state,\n history: state.history.slice(0, -1),\n index,\n };\n }\n\n default:\n return BaseRouter.getStateForAction(state, action);\n }\n },\n\n shouldActionChangeFocus(action) {\n return action.type === 'NAVIGATE';\n },\n\n actionCreators: TabActions,\n };\n\n return router;\n}\n"]}