GT2/Ejectable/node_modules/@react-navigation/native/lib/commonjs/useLinkProps.js.map

1 line
3.9 KiB
Plaintext
Raw Normal View History

2021-08-16 00:14:59 +00:00
{"version":3,"sources":["useLinkProps.tsx"],"names":["useLinkProps","to","action","navigation","React","useContext","NavigationHelpersContext","linkTo","onPress","e","shouldHandle","Platform","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","undefined","includes","currentTarget","target","preventDefault","dispatch","Error","String","href","accessibilityRole"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAIA;;;;;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAsB;AAAEC,EAAAA,EAAF;AAAMC,EAAAA;AAAN,CAAtB,EAA6C;AAC1D,QAAMC,UAAU,GAAGC,KAAK,CAACC,UAAN,CAAiBC,8BAAjB,CAAnB;AACA,QAAMC,MAAM,GAAG,yBAAf;;AAEA,QAAMC,OAAO,GACXC,CADc,IAEX;AAAA;;AACH,QAAIC,YAAY,GAAG,KAAnB;;AAEA,QAAIC,sBAASC,EAAT,KAAgB,KAAhB,IAAyB,CAACH,CAA9B,EAAiC;AAC/BC,MAAAA,YAAY,GAAGD,CAAC,GAAG,CAACA,CAAC,CAACI,gBAAN,GAAyB,IAAzC;AACD,KAFD,MAEO,IACL,CAACJ,CAAC,CAACI,gBAAH,IAAuB;AACvB;AACA,MAAEJ,CAAC,CAACK,OAAF,IAAaL,CAAC,CAACM,MAAf,IAAyBN,CAAC,CAACO,OAA3B,IAAsCP,CAAC,CAACQ,QAA1C,CAFA,MAEuD;AACvD;AACCR,IAAAA,CAAC,CAACS,MAAF,IAAY,IAAZ,IAAoBT,CAAC,CAACS,MAAF,KAAa,CAJlC,KAIwC;AACxC;AACA,KAACC,SAAD,EAAY,IAAZ,EAAkB,EAAlB,EAAsB,MAAtB,EAA8BC,QAA9B,qBAAuCX,CAAC,CAACY,aAAzC,qDAAuC,iBAAiBC,MAAxD,CAPK,CAO2D;AAP3D,MAQL;AACAb,QAAAA,CAAC,CAACc,cAAF;AACAb,QAAAA,YAAY,GAAG,IAAf;AACD;;AAED,QAAIA,YAAJ,EAAkB;AAChB,UAAIR,MAAJ,EAAY;AACV,YAAIC,UAAJ,EAAgB;AACdA,UAAAA,UAAU,CAACqB,QAAX,CAAoBtB,MAApB;AACD,SAFD,MAEO;AACL,gBAAM,IAAIuB,KAAJ,CAAU,oCAAV,CAAN;AACD;AACF,OAND,MAMO;AACL,YAAI,OAAOxB,EAAP,KAAc,QAAlB,EAA4B;AAC1B,gBAAM,IAAIwB,KAAJ,6CACiCC,MAAM,CACzCzB,EADyC,CADvC,kDAAN;AAKD;;AAEDM,QAAAA,MAAM,CAACN,EAAD,CAAN;AACD;AACF;AACF,GAvCD;;AAyCA,SAAO;AACL0B,IAAAA,IAAI,EAAE1B,EADD;AAEL2B,IAAAA,iBAAiB,EAAE,MAFd;AAGLpB,IAAAA;AAHK,GAAP;AAKD","sourcesContent":["import * as React from 'react';\nimport { Platform, GestureResponderEvent } from 'react-native';\nimport {\n NavigationAction,\n NavigationHelpersContext,\n} from '@react-navigation/core';\nimport useLinkTo from './useLinkTo';\n\ntype Props = {\n to: string;\n action?: NavigationAction;\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({ to, action }: Props) {\n const navigation = React.useContext(NavigationHelpersContext);\n const linkTo = useLinkTo();\n\n const onPress = (\n e?: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent\n ) => {\n let shouldHandle = false;\n\n if (Platform.OS !== 'web' || !e) {\n shouldHandle = e ? !e.defaultPrevented : true;\n } else if (\n !e.defaultPrevented && // 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) && // 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) && // 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?.target) // let browser handle \"target=_blank\" etc.\n ) {\n e.preventDefault();\n shouldHandle = true;\n }\n\n if (shouldHandle) {\n if (action) {\n if (navigation) {\n navigation.dispatch(action);\n } else {\n throw new Error(\"Couldn't find a navigation object.\");\n }\n } else {\n if (typeof to !== 'string') {\n throw new Error(\n `To 'to' option is invalid (found '${String(\n to\n )}'. It must be a valid string for navigation.`\n );\n }\n\n linkTo(to);\n }\n }\n };\n\n return {\n href: to,\n accessibilityRole: 'link' as const,\n onPress,\n };\n}\n"]}