1 line
3.8 KiB
Plaintext
1 line
3.8 KiB
Plaintext
|
{"version":3,"sources":["useLinkBuilder.tsx"],"names":["getRootStateForNavigate","navigation","state","parent","dangerouslyGetParent","parentState","dangerouslyGetState","index","routes","useLinkBuilder","React","useContext","NavigationHelpersContext","linking","LinkingContext","buildLink","useCallback","name","params","options","enabled","undefined","path","getPathFromState","config"],"mappings":";;;;;;;AAAA;;AACA;;AAOA;;;;;;;;AAWA,MAAMA,uBAAuB,GAAG,CAC9BC,UAD8B,EAE9BC,KAF8B,KAGb;AACjB,QAAMC,MAAM,GAAGF,UAAU,CAACG,oBAAX,EAAf;;AAEA,MAAID,MAAJ,EAAY;AACV,UAAME,WAAW,GAAGF,MAAM,CAACG,mBAAP,EAApB;AAEA,WAAON,uBAAuB,CAACG,MAAD,EAAS;AACrCI,MAAAA,KAAK,EAAE,CAD8B;AAErCC,MAAAA,MAAM,EAAE,CACN,EACE,GAAGH,WAAW,CAACG,MAAZ,CAAmBH,WAAW,CAACE,KAA/B,CADL;AAEEL,QAAAA,KAAK,EAAEA;AAFT,OADM;AAF6B,KAAT,CAA9B;AASD;;AAED,SAAOA,KAAP;AACD,CArBD;AAuBA;AACA;AACA;AACA;;;AACe,SAASO,cAAT,GAA0B;AACvC,QAAMR,UAAU,GAAGS,KAAK,CAACC,UAAN,CAAiBC,8BAAjB,CAAnB;AACA,QAAMC,OAAO,GAAGH,KAAK,CAACC,UAAN,CAAiBG,uBAAjB,CAAhB;AAEA,QAAMC,SAAS,GAAGL,KAAK,CAACM,WAAN,CAChB,CAACC,IAAD,EAAeC,MAAf,KAAmC;AACjC,UAAM;AAAEC,MAAAA;AAAF,QAAcN,OAApB;;AAEA,QAAI,CAAAM,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,OAAT,MAAqB,KAAzB,EAAgC;AAC9B,aAAOC,SAAP;AACD;;AAED,UAAMnB,KAAK,GAAGD,UAAU,GACpBD,uBAAuB,CAACC,UAAD,EAAa;AAClCM,MAAAA,KAAK,EAAE,CAD2B;AAElCC,MAAAA,MAAM,EAAE,CAAC;AAAES,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAD;AAF0B,KAAb,CADH,GAKpB;AACA;AACA;AACEX,MAAAA,KAAK,EAAE,CADT;AAEEC,MAAAA,MAAM,EAAE,CAAC;AAAES,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAD;AAFV,KAPJ;AAYA,UAAMI,IAAI,GAAG,CAAAH,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEI,gBAAT,IACTJ,OAAO,CAACI,gBAAR,CAAyBrB,KAAzB,EAAgCiB,OAAhC,aAAgCA,OAAhC,uBAAgCA,OAAO,CAAEK,MAAzC,CADS,GAET,4BAAiBtB,KAAjB,EAAwBiB,OAAxB,aAAwBA,OAAxB,uBAAwBA,OAAO,CAAEK,MAAjC,CAFJ;AAIA,WAAOF,IAAP;AACD,GAzBe,EA0BhB,CAACT,OAAD,EAAUZ,UAAV,CA1BgB,CAAlB;AA6BA,SAAOc,SAAP;AACD","sourcesContent":["import * as React from 'react';\nimport {\n NavigationHelpers,\n NavigationHelpersContext,\n NavigationProp,\n ParamListBase,\n getPathFromState,\n} from '@react-navigation/core';\nimport LinkingContext from './LinkingContext';\n\ntype NavigationObject =\n | NavigationHelpers<ParamListBase>\n | NavigationProp<ParamListBase>;\n\ntype MinimalState = {\n index: number;\n routes: { name: string; params?: object; state?: MinimalState }[];\n};\n\nconst getRootStateForNavigate = (\n navigation: NavigationObject,\n state: MinimalState\n): MinimalState => {\n const parent = navigation.dangerouslyGetParent();\n\n if (parent) {\n const parentState = parent.dangerouslyGetState();\n\n return getRootStateForNavigate(parent, {\n index: 0,\n routes: [\n {\n ...parentState.routes[parentState.index],\n state: state,\n },\n ],\n });\n }\n\n return state;\n};\n\n/**\n * Build destination link for a navigate action.\n * Useful for showing anchor tags on the web for buttons that perform navigation.\n */\nexport default function useLinkBuilder() {\n const navigation = React.useContext(NavigationHelpersContext);\n const linking = React.useContext(LinkingContext);\n\n const buildLink = React.useCallback(\n (name: string, params?: object) => {\n const { options } = linking;\n\n if (options?.enabled === false) {\n return undefined;\n }\n\n const state = navigation\n ? getRootStateForNavigate(navigation, {\n index: 0,\n routes: [{ name, params }],\n })\n : // If we couldn't find a navigation object in context, we're at root\n // So we'll construct a basic state object to use\n {\n index: 0,\n routes: [{ name, params }],\n };\n\n const path = options?.getPathFromState\n ? options.getPathFromState(state, options?.config)\n : getPathFromState(state, options?.config);\n\n return path;\n },\n [linking, navigation]\n );\n\n return buildLink;\n}\n"]}
|