UNPKG

@prismicio/next

Version:

Helpers to integrate Prismic into Next.js apps

1 lines 2.46 kB
{"version":3,"file":"PrismicNextLink.cjs","sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import { ComponentProps, forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\";\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<\n\tHTMLAnchorElement,\n\tPrismicNextLinkProps\n>(function PrismicNextLink(props, ref) {\n\tconst { field, document, linkResolver, children, ...restProps } = props;\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? document, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tlet rel = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst ResolvedLink = resolveDefaultExport(Link);\n\n\treturn (\n\t\t<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</ResolvedLink>\n\t);\n});\n"],"names":["forwardRef","PrismicNextLink","asLinkAttrs","resolveDefaultExport","_jsx"],"mappings":";;;;;;;AAoCO,MAAM,kBAAkBA,MAAAA,WAG7B,SAASC,iBAAgB,OAAO,KAAG;AACpC,QAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;AAC5D,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACAC,OAAAA,YAAY,SAAS,UAAU;AAAA,IAClC;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,MAAI,MAAM;AACV,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAAA;AAGX,QAAA,eAAeC,0CAAqB,IAAI;AAE9C,SACCC,WAAAA,IAAC,cAAY,EAAC,KAAc,GAAA,UAAW,WAAW,MAAY,eAC5D,cAAc,QAAQ,WAAW,+BAAO,MAAI;AAGhD,CAAC;;"}