repoweaver
Version:
A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies
1 lines • 9.54 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nimport { CommonActions, findFocusedRoute, getActionFromState, getPathFromState, getStateFromPath, NavigationHelpersContext, NavigationRouteContext, useStateForPath } from '@react-navigation/core';\nimport * as React from 'react';\nimport { LinkingContext } from \"./LinkingContext.js\";\nexport function useLinkBuilder() {\n const navigation = React.useContext(NavigationHelpersContext);\n const route = React.useContext(NavigationRouteContext);\n const {\n options\n } = React.useContext(LinkingContext);\n const focusedRouteState = useStateForPath();\n const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;\n const getStateFromPathHelper = options?.getStateFromPath ?? getStateFromPath;\n const getActionFromStateHelper = options?.getActionFromState ?? getActionFromState;\n const buildHref = React.useCallback((name, params) => {\n if (options?.enabled === false) {\n return undefined;\n }\n const isScreen = navigation && route?.key && focusedRouteState ? route.key === findFocusedRoute(focusedRouteState)?.key && navigation.getState().routes.some(r => r.key === route.key) : false;\n const stateForRoute = {\n routes: [{\n name,\n params\n }]\n };\n const constructState = state => {\n if (state) {\n const route = state.routes[0];\n if (isScreen && !route.state) {\n return stateForRoute;\n }\n return {\n routes: [Object.assign({}, route, {\n state: constructState(route.state)\n })]\n };\n }\n return stateForRoute;\n };\n const state = constructState(focusedRouteState);\n const path = getPathFromStateHelper(state, options?.config);\n return path;\n }, [options?.enabled, options?.config, route?.key, navigation, focusedRouteState, getPathFromStateHelper]);\n const buildAction = React.useCallback(href => {\n if (!href.startsWith('/')) {\n throw new Error(`The href must start with '/' (${href}).`);\n }\n const state = getStateFromPathHelper(href, options?.config);\n if (state) {\n const action = getActionFromStateHelper(state, options?.config);\n return action ?? CommonActions.reset(state);\n } else {\n throw new Error('Failed to parse the href to a navigation state.');\n }\n }, [options?.config, getStateFromPathHelper, getActionFromStateHelper]);\n return {\n buildHref,\n buildAction\n };\n}","map":{"version":3,"names":["CommonActions","findFocusedRoute","getActionFromState","getPathFromState","getStateFromPath","NavigationHelpersContext","NavigationRouteContext","useStateForPath","React","LinkingContext","useLinkBuilder","navigation","useContext","route","options","focusedRouteState","getPathFromStateHelper","getStateFromPathHelper","getActionFromStateHelper","buildHref","useCallback","name","params","enabled","undefined","isScreen","key","getState","routes","some","r","stateForRoute","constructState","state","Object","assign","path","config","buildAction","href","startsWith","Error","action","reset"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/native/src/useLinkBuilder.tsx"],"sourcesContent":["import {\n CommonActions,\n findFocusedRoute,\n getActionFromState,\n getPathFromState,\n getStateFromPath,\n NavigationHelpersContext,\n NavigationRouteContext,\n useStateForPath,\n} from '@react-navigation/core';\nimport * as React from 'react';\n\nimport { LinkingContext } from './LinkingContext';\n\ntype MinimalState = {\n routes: [{ name: string; params?: object; state?: MinimalState }];\n};\n\n/**\n * Helpers to build href or action based on the linking options.\n *\n * @returns `buildHref` to build an `href` for screen and `buildAction` to build an action from an `href`.\n */\nexport function useLinkBuilder() {\n const navigation = React.useContext(NavigationHelpersContext);\n const route = React.useContext(NavigationRouteContext);\n\n const { options } = React.useContext(LinkingContext);\n\n const focusedRouteState = useStateForPath();\n\n const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;\n const getStateFromPathHelper = options?.getStateFromPath ?? getStateFromPath;\n const getActionFromStateHelper =\n options?.getActionFromState ?? getActionFromState;\n\n const buildHref = React.useCallback(\n (name: string, params?: object) => {\n if (options?.enabled === false) {\n return undefined;\n }\n\n // Check that we're inside:\n // - navigator's context\n // - route context of the navigator (could be a screen, tab, etc.)\n // - route matches the state for path (from the screen's context)\n // This ensures that we're inside a screen\n const isScreen =\n navigation && route?.key && focusedRouteState\n ? route.key === findFocusedRoute(focusedRouteState)?.key &&\n navigation.getState().routes.some((r) => r.key === route.key)\n : false;\n\n const stateForRoute: MinimalState = {\n routes: [{ name, params }],\n };\n\n const constructState = (\n state: MinimalState | undefined\n ): MinimalState => {\n if (state) {\n const route = state.routes[0];\n\n // If we're inside a screen and at the innermost route\n // We need to replace the state with the provided one\n // This assumes that we're navigating to a sibling route\n if (isScreen && !route.state) {\n return stateForRoute;\n }\n\n // Otherwise, dive into the nested state of the route\n return {\n routes: [\n {\n ...route,\n state: constructState(route.state),\n },\n ],\n };\n }\n\n // Once there is no more nested state, we're at the innermost route\n // We can add a state based on provided parameters\n // This assumes that we're navigating to a child of this route\n // In this case, the helper is used in a navigator for its routes\n return stateForRoute;\n };\n\n const state = constructState(focusedRouteState);\n const path = getPathFromStateHelper(state, options?.config);\n\n return path;\n },\n [\n options?.enabled,\n options?.config,\n route?.key,\n navigation,\n focusedRouteState,\n getPathFromStateHelper,\n ]\n );\n\n const buildAction = React.useCallback(\n (href: string) => {\n if (!href.startsWith('/')) {\n throw new Error(`The href must start with '/' (${href}).`);\n }\n\n const state = getStateFromPathHelper(href, options?.config);\n\n if (state) {\n const action = getActionFromStateHelper(state, options?.config);\n\n return action ?? CommonActions.reset(state);\n } else {\n throw new Error('Failed to parse the href to a navigation state.');\n }\n },\n [options?.config, getStateFromPathHelper, getActionFromStateHelper]\n );\n\n return {\n buildHref,\n buildAction,\n };\n}\n"],"mappings":";;AAAA,SACEA,aAAa,EACbC,gBAAgB,EAChBC,kBAAkB,EAClBC,gBAAgB,EAChBC,gBAAgB,EAChBC,wBAAwB,EACxBC,sBAAsB,EACtBC,eAAe,QACV,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,SAASC,cAAc;AAWvB,OAAO,SAASC,cAAcA,CAAA,EAAG;EAC/B,MAAMC,UAAU,GAAGH,KAAK,CAACI,UAAU,CAACP,wBAAwB,CAAC;EAC7D,MAAMQ,KAAK,GAAGL,KAAK,CAACI,UAAU,CAACN,sBAAsB,CAAC;EAEtD,MAAM;IAAEQ;EAAQ,CAAC,GAAGN,KAAK,CAACI,UAAU,CAACH,cAAc,CAAC;EAEpD,MAAMM,iBAAiB,GAAGR,eAAe,CAAC,CAAC;EAE3C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