UNPKG

18.5 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../client/link.tsx"],"names":["prefetched","prefetch","router","href","as","options","window","catch","err","process","env","NODE_ENV","curLocale","locale","isModifiedEvent","event","target","currentTarget","metaKey","ctrlKey","shiftKey","altKey","nativeEvent","which","linkClicked","e","replace","shallow","scroll","nodeName","preventDefault","indexOf","Link","props","createPropError","args","Error","key","expected","actual","requiredPropsGuard","requiredProps","Object","keys","forEach","_","optionalPropsGuard","passHref","optionalProps","valType","hasWarned","React","useRef","current","console","warn","p","useMemo","resolvedHref","resolvedAs","children","child","Children","only","childRef","ref","setIntersectionRef","isVisible","rootMargin","setRef","useCallback","el","shouldPrefetch","isPrefetched","childProps","onClick","defaultPrevented","onMouseEnter","priority","type","localeDomain","isLocaleDomain","locales","domainLocales","defaultLocale","cloneElement"],"mappings":"iJAAA,qDAEA,wDASA,iCACA,mDAuBA,KAAMA,CAAAA,UAA2C,CAAG,EAApD,CAEA,QAASC,CAAAA,QAAT,CACEC,MADF,CAEEC,IAFF,CAGEC,EAHF,CAIEC,OAJF,CAKQ,CACN,GAAI,MAAOC,CAAAA,MAAP,GAAkB,WAAlB,EAAiC,CAACJ,MAAtC,CAA8C,OAC9C,GAAI,CAAC,uBAAWC,IAAX,CAAL,CAAuB,OACvB;AACA;AACA;AACA;AACAD,MAAM,CAACD,QAAP,CAAgBE,IAAhB,CAAsBC,EAAtB,CAA0BC,OAA1B,EAAmCE,KAAnC,CAA0CC,GAAD,EAAS,CAChD,GAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,GAAyB,YAA7B,CAA2C,CACzC;AACA,KAAMH,CAAAA,GAAN,CACD,CACF,CALD,EAMA,KAAMI,CAAAA,SAAS,CACbP,OAAO,EAAI,MAAOA,CAAAA,OAAO,CAACQ,MAAf,GAA0B,WAArC,CACIR,OAAO,CAACQ,MADZ,CAEIX,MAAM,EAAIA,MAAM,CAACW,MAHvB,CAKA;AACAb,UAAU,CAACG,IAAI,CAAG,GAAP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,cADP,EAEA,4BACE7E,EADF,CAEEQ,SAFF,CAGEV,MAAM,EAAIA,MAAM,CAACgF,OAHnB,CAIEhF,MAAM,EAAIA,MAAM,CAACiF,aAJnB,CAHF,CAUAT,UAAU,CAACvE,IAAX,CACE6E,YAAY,EACZ,wBAAY,sBAAU5E,EAAV,CAAcQ,SAAd,CAAyBV,MAAM,EAAIA,MAAM,CAACkF,aAA1C,CAAZ,CAFF,CAGD,CAED,mBAAOjC,eAAMkC,YAAN,CAAmBxB,KAAnB,CAA0Ba,UAA1B,CAAP,CACD,C,aAEc1C,I","sourcesContent":["import React, { Children, useEffect } from 'react'\nimport { UrlObject } from 'url'\nimport {\n addBasePath,\n addLocale,\n getDomainLocale,\n isLocalURL,\n NextRouter,\n PrefetchOptions,\n resolveHref,\n} from '../next-server/lib/router/router'\nimport { useRouter } from './router'\nimport { useIntersection } from './use-intersection'\n\ntype Url = string | UrlObject\ntype RequiredKeys<T> = {\n [K in keyof T]-?: {} extends Pick<T, K> ? never : K\n}[keyof T]\ntype OptionalKeys<T> = {\n [K in keyof T]-?: {} extends Pick<T, K> ? K : never\n}[keyof T]\n\nexport type LinkProps = {\n href: Url\n as?: Url\n replace?: boolean\n scroll?: boolean\n shallow?: boolean\n passHref?: boolean\n prefetch?: boolean\n locale?: string | false\n}\ntype LinkPropsRequired = RequiredKeys<LinkProps>\ntype LinkPropsOptional = OptionalKeys<LinkProps>\n\nconst prefetched: { [cacheKey: string]: boolean } = {}\n\nfunction prefetch(\n router: NextRouter,\n href: string,\n as: string,\n options?: PrefetchOptions\n): void {\n if (typeof window === 'undefined' || !router) return\n if (!isLocalURL(href)) return\n // Prefetch the JSON page if asked (only in the client)\n // We need to handle a prefetch error here since we may be\n // loading with priority which can reject but we don't\n // want to force navigation since this is only a prefetch\n router.prefetch(href, as, options).catch((err) => {\n if (process.env.NODE_ENV !== 'production') {\n // rethrow to show invalid URL errors\n throw err\n }\n })\n const curLocale =\n options && typeof options.locale !== 'undefined'\n ? options.locale\n : router && router.locale\n\n // Join on an invalid URI character\n prefetched[href + '%' + as + (curLocale ? '%' + curLocale : '')] = true\n}\n\nfunction isModifiedEvent(event: React.MouseEvent): boolean {\n const { target } = event.currentTarget as HTMLAnchorElement\n return (\n (target && target !== '_self') ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey || // triggers resource download\n (event.nativeEvent && event.nativeEvent.which === 2)\n )\n}\n\nfunction linkClicked(\n e: React.MouseEvent,\n router: NextRouter,\n href: string,\n as: string,\n replace?: boolean,\n shallow?: boolean,\n scroll?: boolean,\n locale?: string | false\n): void {\n const { nodeName } = e.currentTarget\n\n if (nodeName === 'A' && (isModifiedEvent(e) || !isLocalURL(href))) {\n // ignore click for browser’s default behavior\n return\n }\n\n e.preventDefault()\n\n // avoid scroll for urls with anchor refs\n if (scroll == null && as.indexOf('#') >= 0) {\n scroll = false\n }\n\n // replace state instead of push if prop is present\n router[replace ? 'replace' : 'push'](href, as, {\n shallow,\n locale,\n scroll,\n })\n}\n\nfunction Link(props: React.PropsWithChildren<LinkProps>) {\n if (process.env.NODE_ENV !== 'production') {\n function createPropError(args: {\n key: string\n expected: string\n actual: string\n }) {\n return new Error(\n `Failed prop type: The prop \\`${args.key}\\` expects a ${args.expected} in \\`<Link>\\`, but got \\`${args.actual}\\` instead.` +\n (typeof window !== 'undefined'\n ? \"\\nOpen your browser's console to view the Component stack trace.\"\n : '')\n )\n }\n\n // TypeScript trick for type-guarding:\n const requiredPropsGuard: Record<LinkPropsRequired, true> = {\n href: true,\n } as const\n const requiredProps: LinkPropsRequired[] = Object.keys(\n requiredPropsGuard\n ) as LinkPropsRequired[]\n requiredProps.forEach((key: LinkPropsRequired) => {\n if (key === 'href') {\n if (\n props[key] == null ||\n (typeof props[key] !== 'string' && typeof props[key] !== 'object')\n ) {\n throw createPropError({\n key,\n expected: '`string` or `object`',\n actual: props[key] === null ? 'null' : typeof props[key],\n })\n }\n } else {\n // TypeScript trick for type-guarding:\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const _: never = key\n }\n })\n\n // TypeScript trick for type-guarding:\n const optionalPropsGuard: Record<LinkPropsOptional, true> = {\n as: true,\n replace: true,\n scroll: true,\n shallow: true,\n passHref: true,\n prefetch: true,\n locale: true,\n } as const\n const optionalProps: LinkPropsOptional[] = Object.keys(\n optionalPropsGuard\n ) as LinkPropsOptional[]\n optionalProps.forEach((key: LinkPropsOptional) => {\n const valType = typeof props[key]\n\n if (key === 'as') {\n if (props[key] && valType !== 'string' && valType !== 'object') {\n throw createPropError({\n key,\n expected: '`string` or `object`',\n actual: valType,\n })\n }\n } else if (key === 'locale') {\n if (props[key] && valType !== 'string') {\n throw createPropError({\n key,\n expected: '`string`',\n actual: valType,\n })\n }\n } else if (\n key === 'replace' ||\n key === 'scroll' ||\n key === 'shallow' ||\n key === 'passHref' ||\n key === 'prefetch'\n ) {\n if (props[key] != null && valType !== 'boolean') {\n throw createPropError({\n key,\n expected: '`boolean`',\n actual: valType,\n })\n }\n } else {\n // TypeScript trick for type-guarding:\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const _: never = key\n }\n })\n\n // This hook is in a conditional but that is ok because `process.env.NODE_ENV` never changes\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const hasWarned = React.useRef(false)\n if (props.prefetch && !hasWarned.current) {\n hasWarned.current = true\n console.warn(\n 'Next.js auto-prefetches automatically based on viewport. The prefetch attribute is no longer needed. More: https://nextjs.org/docs/messages/prefetch-true-deprecated'\n )\n }\n }\n const p = props.prefetch !== false\n const router = useRouter()\n\n const { href, as } = React.useMemo(() => {\n const [resolvedHref, resolvedAs] = resolveHref(router, props.href, true)\n return {\n href: resolvedHref,\n as: props.as ? resolveHref(router, props.as) : resolvedAs || resolvedHref,\n }\n }, [router, props.href, props.as])\n\n let { children, replace, shallow, scroll, locale } = props\n\n // Deprecated. Warning shown by propType check. If the children provided is a string (<Link>example</Link>) we wrap it in an <a> tag\n if (typeof children === 'string') {\n children = <a>{children}</a>\n }\n\n // This will return the first child, if multiple are provided it will throw an error\n let child: any\n if (process.env.NODE_ENV === 'development') {\n try {\n child = Children.only(children)\n } catch (err) {\n throw new Error(\n `Multiple children were passed to <Link> with \\`href\\` of \\`${props.href}\\` but only one child is supported https://nextjs.org/docs/messages/link-multiple-children` +\n (typeof window !== 'undefined'\n ? \"\\nOpen your browser's console to view the Component stack trace.\"\n : '')\n )\n }\n } else {\n child = Children.only(children)\n }\n const childRef: any = child && typeof child === 'object' && child.ref\n\n const [setIntersectionRef, isVisible] = useIntersection({\n rootMargin: '200px',\n })\n const setRef = React.useCallback(\n (el: Element) => {\n setIntersectionRef(el)\n if (childRef) {\n if (typeof childRef === 'function') childRef(el)\n else if (typeof childRef === 'object') {\n childRef.current = el\n }\n }\n },\n [childRef, setIntersectionRef]\n )\n useEffect(() => {\n const shouldPrefetch = isVisible && p && isLocalURL(href)\n const curLocale =\n typeof locale !== 'undefined' ? locale : router && router.locale\n const isPrefetched =\n prefetched[href + '%' + as + (curLocale ? '%' + curLocale : '')]\n if (shouldPrefetch && !isPrefetched) {\n prefetch(router, href, as, {\n locale: curLocale,\n })\n }\n }, [as, href, isVisible, locale, p, router])\n\n const childProps: {\n onMouseEnter?: React.MouseEventHandler\n onClick: React.MouseEventHandler\n href?: string\n ref?: any\n } = {\n ref: setRef,\n onClick: (e: React.MouseEvent) => {\n if (child.props && typeof child.props.onClick === 'function') {\n child.props.onClick(e)\n }\n if (!e.defaultPrevented) {\n linkClicked(e, router, href, as, replace, shallow, scroll, locale)\n }\n },\n }\n\n childProps.onMouseEnter = (e: React.MouseEvent) => {\n if (!isLocalURL(href)) return\n if (child.props && typeof child.props.onMouseEnter === 'function') {\n child.props.onMouseEnter(e)\n }\n prefetch(router, href, as, { priority: true })\n }\n\n // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is\n // defined, we specify the current 'href', so that repetition is not needed by the user\n if (props.passHref || (child.type === 'a' && !('href' in child.props))) {\n const curLocale =\n typeof locale !== 'undefined' ? locale : router && router.locale\n\n // we only render domain locales if we are currently on a domain locale\n // so that locale links are still visitable in development/preview envs\n const localeDomain =\n router &&\n router.isLocaleDomain &&\n getDomainLocale(\n as,\n curLocale,\n router && router.locales,\n router && router.domainLocales\n )\n\n childProps.href =\n localeDomain ||\n addBasePath(addLocale(as, curLocale, router && router.defaultLocale))\n }\n\n return React.cloneElement(child, childProps)\n}\n\nexport default Link\n"]}
\No newline at end of file