1 | {"version":3,"names":["getRootStateForNavigate","navigation","state","parent","getParent","parentState","getState","index","routes","useLinkBuilder","React","useContext","NavigationHelpersContext","linking","LinkingContext","buildLink","useCallback","name","params","options","enabled","undefined","path","getPathFromState","config"],"sources":["useLinkBuilder.tsx"],"sourcesContent":["import {\n getPathFromState,\n NavigationHelpers,\n NavigationHelpersContext,\n NavigationProp,\n ParamListBase,\n} from '@react-navigation/core';\nimport * as React from 'react';\n\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.getParent();\n\n if (parent) {\n const parentState = parent.getState();\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"],"mappings":";;;;;;;AAAA;;AAOA;;AAEA;;;;;;;;AAWA,MAAMA,uBAAuB,GAAG,CAC9BC,UAD8B,EAE9BC,KAF8B,KAGb;EACjB,MAAMC,MAAM,GAAGF,UAAU,CA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