@prismicio/next
Version:
Helpers to integrate Prismic into Next.js apps
1 lines • 2.5 kB
Source Map (JSON)
{"version":3,"file":"PrismicNextLink.cjs","names":["resolveDefaultExport","Link"],"sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import type {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n} from \"@prismicio/client\"\nimport { asLinkAttrs } from \"@prismicio/client\"\nimport Link from \"next/link\"\nimport type { ComponentProps } from \"react\"\nimport { forwardRef } from \"react\"\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\"\n\nexport type PrismicNextLinkProps = Omit<\n\tComponentProps<typeof Link>,\n\t\"field\" | \"document\" | \"href\" | \"rel\"\n> & {\n\tlinkResolver?: LinkResolverFunction\n\trel?: string | AsLinkAttrsConfig[\"rel\"]\n} & (\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined\n\t\t\t\tdocument?: never\n\t\t\t\thref?: never\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never\n\t\t\t\tdocument: PrismicDocument | null | undefined\n\t\t\t\thref?: never\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never\n\t\t\t\tdocument?: never\n\t\t\t\thref: ComponentProps<typeof Link>[\"href\"]\n\t\t }\n\t)\n\nexport const PrismicNextLink = forwardRef<HTMLAnchorElement, PrismicNextLinkProps>(\n\tfunction PrismicNextLink(props, ref) {\n\t\tconst { field, document, linkResolver, children, ...restProps } = props\n\t\tconst {\n\t\t\thref: computedHref,\n\t\t\trel: computedRel,\n\t\t\t...attrs\n\t\t} = asLinkAttrs(field ?? document, {\n\t\t\tlinkResolver,\n\t\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t\t})\n\n\t\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\"\n\n\t\tlet rel = computedRel\n\t\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\t\trel = restProps.rel\n\t\t}\n\n\t\tconst ResolvedLink = resolveDefaultExport(Link)\n\n\t\treturn (\n\t\t\t<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t\t{\"children\" in props ? children : field?.text}\n\t\t\t</ResolvedLink>\n\t\t)\n\t},\n)\n"],"mappings":";;;;;;;;AAqCA,MAAa,mBAAA,GAAA,MAAA,YACZ,SAAS,gBAAgB,OAAO,KAAK;CACpC,MAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;CAClE,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,WAAA,GAAA,kBAAA,aACY,SAAS,UAAU;EAClC;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM,KAAA;EAC3D,CAAC;CAEF,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,IAAI,MAAM;AACV,KAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,WAClD,OAAM,UAAU;AAKjB,QACC,iBAAA,GAAA,kBAAA,KAHoBA,6BAAAA,qBAAqBC,aAAAA,QAAK,EAG9C;EAAmB;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;YACjE,cAAc,QAAQ,WAAW,OAAO;EAC3B,CAAA;EAGjB"}