You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
8.7 KiB
1 line
8.7 KiB
{"ast":null,"code":"import { getPathFromState, NavigationContainerRefContext, NavigationHelpersContext } from '@react-navigation/core';\nimport * as React from 'react';\nimport Platform from \"react-native-web/dist/exports/Platform\";\nimport LinkingContext from \"./LinkingContext\";\nimport useLinkTo from \"./useLinkTo\";\nvar getStateFromParams = function getStateFromParams(params) {\n if (params !== null && params !== void 0 && params.state) {\n return params.state;\n }\n if (params !== null && params !== void 0 && params.screen) {\n return {\n routes: [{\n name: params.screen,\n params: params.params,\n state: params.screen ? getStateFromParams(params.params) : undefined\n }]\n };\n }\n return undefined;\n};\nexport default function useLinkProps(_ref) {\n var _ref2;\n var to = _ref.to,\n action = _ref.action;\n var root = React.useContext(NavigationContainerRefContext);\n var navigation = React.useContext(NavigationHelpersContext);\n var _React$useContext = React.useContext(LinkingContext),\n options = _React$useContext.options;\n var linkTo = useLinkTo();\n var onPress = function onPress(e) {\n var _e$currentTarget;\n var shouldHandle = false;\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (!e.defaultPrevented && !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && (e.button == null || e.button === 0) && [undefined, null, '', 'self'].includes((_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : _e$currentTarget.target)) {\n e.preventDefault();\n shouldHandle = true;\n }\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else if (root) {\n root.dispatch(action);\n } else {\n throw new Error(\"Couldn't find a navigation object. Is your component inside NavigationContainer?\");\n }\n } else {\n linkTo(to);\n }\n }\n };\n var getPathFromStateHelper = (_ref2 = options === null || options === void 0 ? void 0 : options.getPathFromState) != null ? _ref2 : getPathFromState;\n var href = typeof to === 'string' ? to : getPathFromStateHelper({\n routes: [{\n name: to.screen,\n params: to.params,\n state: getStateFromParams(to.params)\n }]\n }, options === null || options === void 0 ? void 0 : options.config);\n return {\n href: href,\n accessibilityRole: 'link',\n onPress: onPress\n };\n}","map":{"version":3,"sources":["useLinkProps.tsx"],"names":["getPathFromState","NavigationContainerRefContext","NavigationHelpersContext","React","LinkingContext","useLinkTo","getStateFromParams","params","state","screen","routes","name","undefined","useLinkProps","to","action","root","useContext","navigation","options","linkTo","onPress","e","shouldHandle","Platform","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","includes","currentTarget","target","preventDefault","dispatch","Error","getPathFromStateHelper","href","config","accessibilityRole"],"mappings":"AAAA,SACEA,gBAAgB,EAEhBC,6BAA6B,EAC7BC,wBAAwB,QAGnB,wBAAwB;AAE/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAAA;AAG9B,OAAOC,cAAc;AACrB,OAAOC,SAAS;AAOhB,IAAMC,kBAAkB,GACtBC,SADID,kBAAkB,CACtBC,MAAyE,EACT;EAChE,IAAIA,MAAM,KAAA,IAAA,IAANA,MAAM,KAAA,KAAA,CAAA,IAANA,MAAM,CAAEC,KAAK,EAAE;IACjB,OAAOD,MAAM,CAACC,KAAK;EACrB;EAEA,IAAID,MAAM,KAAA,IAAA,IAANA,MAAM,KAAA,KAAA,CAAA,IAANA,MAAM,CAAEE,MAAM,EAAE;IAClB,OAAO;MACLC,MAAM,EAAE,CACN;QACEC,IAAI,EAAEJ,MAAM,CAACE,MAAM;QACnBF,MAAM,EAAEA,MAAM,CAACA,MAAM;QAErBC,KAAK,EAAED,MAAM,CAACE,MAAM,GAChBH,kBAAkB,CAChBC,MAAM,CAACA,MAAM,CAGd,GACDK;MACN,CAAC;IAEL,CAAC;EACH;EAEA,OAAOA,SAAS;AAClB,CAAC;AAQD,eAAe,SAASC,YAAY,CAAA,IAAA,EAEA;EAAA;EAAlC,IAAEC,EAAE,GAA4B,IAAA,CAA9BA,EAAE;IAAEC,MAAAA,GAA0B,IAAA,CAA1BA,MAAAA;EACN,IAAMC,IAAI,GAAGb,KAAK,CAACc,UAAU,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AAIsB,KAAK,CACb,kFAAkF,CACnF;QACH;MACF,CAAC,MAAM;QACLjB,MAAM,CAACN,EAAE,CAAC;MACZ;IACF;EACF,CAAC;EAED,IAAMwB,sBAAsB,YAAG,OAAO,KAAA,IAAA,IAAP,OAAO,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAP,OAAO,CAAEtC,gBAAgB,oBAAIA,gBAAgB;EAE5E,IAAMuC,IAAI,GACR,OAAOzB,EAAE,KAAK,QAAQ,GAClBA,EAAE,GACFwB,sBAAsB,CACpB;IACE5B,MAAM,EAAE,CACN;MACEC,IAAI,EAAEG,EAAE,CAACL,MAAM;MAEfF,MAAM,EAAEO,EAAE,CAACP,MAAM;MAEjBC,KAAK,EAAEF,kBAAkB,CAACQ,EAAE,CAACP,MAAM;IACrC,CAAC;EAEL,CAAC,EACDY,OAAO,KAAA,IAAA,IAAPA,OAAO,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAEqB,MAAM,CAChB;EAEP,OAAO;IACLD,IAAI,EAAJA,IAAI;IACJE,iBAAiB,EAAE,MAAe;IAClCpB,OAAAA,EAAAA;EACF,CAAC;AACH","sourceRoot":"../../src","sourcesContent":["import { getPathFromState, NavigationContainerRefContext, NavigationHelpersContext } from '@react-navigation/core';\nimport * as React from 'react';\nimport { Platform } from 'react-native';\nimport LinkingContext from './LinkingContext';\nimport useLinkTo from './useLinkTo';\nconst getStateFromParams = params => {\n if (params !== null && params !== void 0 && params.state) {\n return params.state;\n }\n if (params !== null && params !== void 0 && params.screen) {\n return {\n routes: [{\n name: params.screen,\n params: params.params,\n // @ts-expect-error\n state: params.screen ? getStateFromParams(params.params) : undefined\n }]\n };\n }\n return undefined;\n};\n\n/**\n * Hook to get props for an anchor tag so it can work with in page navigation.\n *\n * @param props.to Absolute path to screen (e.g. `/feeds/hot`).\n * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.\n */\nexport default function useLinkProps(_ref) {\n let {\n to,\n action\n } = _ref;\n const root = React.useContext(NavigationContainerRefContext);\n const navigation = React.useContext(NavigationHelpersContext);\n const {\n options\n } = React.useContext(LinkingContext);\n const linkTo = useLinkTo();\n const onPress = e => {\n var _e$currentTarget;\n let shouldHandle = false;\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (!e.defaultPrevented &&\n // onPress prevented default\n // @ts-expect-error: these properties exist on web, but not in React Native\n !(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && (\n // ignore clicks with modifier keys\n // @ts-expect-error: these properties exist on web, but not in React Native\n e.button == null || e.button === 0) &&\n // ignore everything but left clicks\n // @ts-expect-error: these properties exist on web, but not in React Native\n [undefined, null, '', 'self'].includes((_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : _e$currentTarget.target) // let browser handle \"target=_blank\" etc.\n ) {\n e.preventDefault();\n shouldHandle = true;\n }\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else if (root) {\n root.dispatch(action);\n } else {\n throw new Error(\"Couldn't find a navigation object. Is your component inside NavigationContainer?\");\n }\n } else {\n linkTo(to);\n }\n }\n };\n const getPathFromStateHelper = (options === null || options === void 0 ? void 0 : options.getPathFromState) ?? getPathFromState;\n const href = typeof to === 'string' ? to : getPathFromStateHelper({\n routes: [{\n name: to.screen,\n // @ts-expect-error\n params: to.params,\n // @ts-expect-error\n state: getStateFromParams(to.params)\n }]\n }, options === null || options === void 0 ? void 0 : options.config);\n return {\n href,\n accessibilityRole: 'link',\n onPress\n };\n}\n//# sourceMappingURL=useLinkProps.js.map"]},"metadata":{},"sourceType":"module"} |