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

1 line
4.0 KiB
Plaintext
Raw Normal View History

2021-08-16 00:14:59 +00:00
{"version":3,"sources":["useLinkProps.tsx"],"names":["React","Platform","NavigationHelpersContext","useLinkTo","useLinkProps","to","action","navigation","useContext","linkTo","onPress","e","shouldHandle","OS","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","button","undefined","includes","currentTarget","target","preventDefault","dispatch","Error","String","href","accessibilityRole"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,QAAgD,cAAhD;AACA,SAEEC,wBAFF,QAGO,wBAHP;AAIA,OAAOC,SAAP,MAAsB,aAAtB;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,YAAT,CAAsB;AAAEC,EAAAA,EAAF;AAAMC,EAAAA;AAAN,CAAtB,EAA6C;AAC1D,QAAMC,UAAU,GAAGP,KAAK,CAACQ,UAAN,CAAiBN,wBAAjB,CAAnB;AACA,QAAMO,MAAM,GAAGN,SAAS,EAAxB;;AAEA,QAAMO,OAAO,GACXC,CADc,IAEX;AAAA;;AACH,QAAIC,YAAY,GAAG,KAAnB;;AAEA,QAAIX,QAAQ,CAACY,EAAT,KAAgB,KAAhB,IAAyB,CAACF,CAA9B,EAAiC;AAC/BC,MAAAA,YAAY,GAAGD,CAAC,GAAG,CAACA,CAAC,CAACG,gBAAN,GAAyB,IAAzC;AACD,KAFD,MAEO,IACL,CAACH,CAAC,CAACG,gBAAH,IAAuB;AACvB;AACA,MAAEH,CAAC,CAACI,OAAF,IAAaJ,CAAC,CAACK,MAAf,IAAyBL,CAAC,CAACM,OAA3B,IAAsCN,CAAC,CAACO,QAA1C,CAFA,MAEuD;AACvD;AACCP,IAAAA,CAAC,CAACQ,MAAF,IAAY,IAAZ,IAAoBR,CAAC,CAACQ,MAAF,KAAa,CAJlC,KAIwC;AACxC;AACA,KAACC,SAAD,EAAY,IAAZ,EAAkB,EAAlB,EAAsB,MAAtB,EAA8BC,QAA9B,qBAAuCV,CAAC,CAACW,aAAzC,qDAAuC,iBAAiBC,MAAxD,CAPK,CAO2D;AAP3D,MAQL;AACAZ,QAAAA,CAAC,CAACa,cAAF;AACAZ,QAAAA,YAAY,GAAG,IAAf;AACD;;AAED,QAAIA,YAAJ,EAAkB;AAChB,UAAIN,MAAJ,EAAY;AACV,YAAIC,UAAJ,EAAgB;AACdA,UAAAA,UAAU,CAACkB,QAAX,CAAoBnB,MAApB;AACD,SAFD,MAEO;AACL,gBAAM,IAAIoB,KAAJ,CAAU,oCAAV,CAAN;AACD;AACF,OAND,MAMO;AACL,YAAI,OAAOrB,EAAP,KAAc,QAAlB,EAA4B;AAC1B,gBAAM,IAAIqB,KAAJ,6CACiCC,MAAM,CACzCtB,EADyC,CADvC,kDAAN;AAKD;;AAEDI,QAAAA,MAAM,CAACJ,EAAD,CAAN;AACD;AACF;AACF,GAvCD;;AAyCA,SAAO;AACLuB,IAAAA,IAAI,EAAEvB,EADD;AAELwB,IAAAA,iBAAiB,EAAE,MAFd;AAGLnB,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,