GT2/Ejectable/node_modules/@react-navigation/routers/lib/module/TabRouter.js.map

1 line
18 KiB
Plaintext

{"version":3,"sources":["TabRouter.tsx"],"names":["nanoid","BaseRouter","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","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,SAASA,MAAT,QAAuB,mBAAvB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAyDA,MAAMC,UAAU,GAAG,OAAnB;AAEA,OAAO,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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AK,SAAL;AAAgB;AACd,gBAAIS,KAAK,CAACR,OAAN,CAAc8B,MAAd,KAAyB,CAA7B,EAAgC;AAC9B,qBAAO,IAAP;AACD;;AAED,kBAAMM,WAAW,GAAG5B,KAAK,CAACR,OAAN,CAAcQ,KAAK,CAACR,OAAN,CAAc8B,MAAd,GAAuB,CAArC,EAAwC7B,GAA5D;AACA,kBAAMJ,KAAK,GAAGW,KAAK,CAACZ,MAAN,CAAaS,SAAb,CACXC,KAAD,IAAWA,KAAK,CAACL,GAAN,KAAcmC,WADb,CAAd;;AAIA,gBAAIvC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,qBAAO,IAAP;AACD;;AAED,mBAAO,EACL,GAAGW,KADE;AAELR,cAAAA,OAAO,EAAEQ,KAAK,CAACR,OAAN,CAAcqC,KAAd,CAAoB,CAApB,EAAuB,CAAC,CAAxB,CAFJ;AAGLxC,cAAAA;AAHK,aAAP;AAKD;;AAED;AACE,iBAAOV,UAAU,CAAC8C,iBAAX,CAA6BzB,KAA7B,EAAoC0B,MAApC,CAAP;AArFJ;AAuFD,KAnOC;;AAqOFI,IAAAA,uBAAuB,CAACJ,MAAD,EAAS;AAC9B,aAAOA,MAAM,CAACzC,IAAP,KAAgB,UAAvB;AACD,KAvOC;;AAyOF8C,IAAAA,cAAc,EAAElD;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<ParamList extends ParamListBase> = Omit<\n NavigationState<ParamList>,\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<ParamList extends ParamListBase> = {\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<RouteName extends Extract<keyof ParamList, string>>(\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<string>[],\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<ParamListBase>,\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<ParamListBase>,\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<ParamListBase>\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<string>;\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"]}