@prismicio/react 3.2.2-pr.235.0d79482 → 3.2.2-pr.235.5fa03d2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,10 @@ import { forwardRef } from "react";
3
3
  import { asLinkAttrs } from "@prismicio/client";
4
4
  import { DEV } from "esm-env";
5
5
  import { devMsg } from "./lib/devMsg.js";
6
- import { getGlobalConfig } from "./config.js";
6
+ const defaultInternalComponentConfigKey = Symbol.for("@prismicio/react/PrismicLink/defaultInternalComponent");
7
7
  const defaultComponent = "a";
8
8
  const PrismicLink = forwardRef(function PrismicLink2(props, ref) {
9
- const globalConfig = getGlobalConfig();
10
- const { field, document: doc, linkResolver, internalComponent = globalConfig.internalLinkComponent, externalComponent, children, ...restProps } = props;
9
+ const { field, document: doc, linkResolver, internalComponent = globalThis[defaultInternalComponentConfigKey], externalComponent, children, ...restProps } = props;
11
10
  if (DEV) {
12
11
  if (field) {
13
12
  if (!field.link_type) {
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicLink.js","sources":["../src/PrismicLink.tsx"],"sourcesContent":["import {\n\tComponentProps,\n\tComponentType,\n\tForwardedRef,\n\tHTMLAttributeAnchorTarget,\n\tReactNode,\n\tforwardRef,\n} from \"react\";\nimport {\n\ttype LinkField,\n\ttype LinkResolverFunction,\n\ttype PrismicDocument,\n\tasLinkAttrs,\n\ttype AsLinkAttrsConfig,\n} from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nimport { getGlobalConfig } from \"./config.js\";\n\n/** The default component rendered for internal and external links. */\nconst defaultComponent = \"a\";\n\n/** Props provided to a component when rendered with `<PrismicLink>`. */\nexport interface LinkProps {\n\t/** The URL to link. */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/** Children for the component. */\n\tchildren?: ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n> = Omit<\n\tInternalComponentProps & ExternalComponentProps,\n\t\"rel\" | \"href\" | \"children\"\n> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if\n\t * the link's URL is external. This prop can be provided a function to use the\n\t * link's metadata to determine the `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link\n\t * component, provide the Link component to this prop.\n\t */\n\tinternalComponent?: ComponentType<InternalComponentProps>;\n\n\t/** The component rendered for external URLs. Defaults to `<a>`. */\n\texternalComponent?: ComponentType<ExternalComponentProps>;\n\n\t/**\n\t * The children to render for the link. If no children are provided, the\n\t * link's `text` property will be used.\n\t */\n\tchildren?: ReactNode;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\n/**\n * Renders a link from a Prismic link field or page.\n *\n * @example\n *\n * ```tsx\n * <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;\n * ```\n *\n * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}\n */\nexport const PrismicLink = forwardRef(function PrismicLink<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: ForwardedRef<Element>,\n) {\n\tconst globalConfig = getGlobalConfig();\n\n\tconst {\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent = globalConfig.internalLinkComponent,\n\t\texternalComponent,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t(\"text\" in field\n\t\t\t\t\t? Object.keys(field).length > 2\n\t\t\t\t\t: Object.keys(field).length > 1) &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent ||\n\t\tdefaultComponent) as ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent ||\n\t\tdefaultComponent) as ComponentType<LinkProps>;\n\tconst Component = href\n\t\t? isInternalURL(href)\n\t\t\t? InternalComponent\n\t\t\t: ExternalComponent\n\t\t: InternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Component>\n\t);\n}) as <\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: ForwardedRef<Element>;\n\t},\n) => ReactNode;\n\n/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport function isInternalURL(url: string): boolean {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url);\n\tconst isSpecialLink = !isInternal && !/^https?:\\/\\//.test(url);\n\n\treturn isInternal && !isSpecialLink;\n}\n"],"names":["PrismicLink","_jsx"],"mapp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W,+BAAO,MAAI;AAGhD,CAAC;AAiBK,SAAU,cAAc,KAAW;AAClC,QAAA,aAAa,gBAAgB,KAAK,GAAG;AAC3C,QAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,GAAG;AAE7D,SAAO,cAAc,CAAC;AACvB;"}
1
+ {"version":3,"file":"PrismicLink.js","sources":["../src/PrismicLink.tsx"],"sourcesContent":["import {\n\tComponentProps,\n\tComponentType,\n\tForwardedRef,\n\tHTMLAttributeAnchorTarget,\n\tReactNode,\n\tforwardRef,\n} from \"react\";\nimport {\n\ttype LinkField,\n\ttype LinkResolverFunction,\n\ttype PrismicDocument,\n\tasLinkAttrs,\n\ttype AsLinkAttrsConfig,\n} from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nconst defaultInternalComponentConfigKey = Symbol.for(\n\t\"@prismicio/react/PrismicLink/defaultInternalComponent\",\n);\n\n/** The default component rendered for internal and external links. */\nconst defaultComponent = \"a\";\n\n/** Props provided to a component when rendered with `<PrismicLink>`. */\nexport interface LinkProps {\n\t/** The URL to link. */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/** Children for the component. */\n\tchildren?: ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n> = Omit<\n\tInternalComponentProps & ExternalComponentProps,\n\t\"rel\" | \"href\" | \"children\"\n> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if\n\t * the link's URL is external. This prop can be provided a function to use the\n\t * link's metadata to determine the `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link\n\t * component, provide the Link component to this prop.\n\t */\n\tinternalComponent?: ComponentType<InternalComponentProps>;\n\n\t/** The component rendered for external URLs. Defaults to `<a>`. */\n\texternalComponent?: ComponentType<ExternalComponentProps>;\n\n\t/**\n\t * The children to render for the link. If no children are provided, the\n\t * link's `text` property will be used.\n\t */\n\tchildren?: ReactNode;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\n/**\n * Renders a link from a Prismic link field or page.\n *\n * @example\n *\n * ```tsx\n * <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;\n * ```\n *\n * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}\n */\nexport const PrismicLink = forwardRef(function PrismicLink<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: ForwardedRef<Element>,\n) {\n\tconst {\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent = (\n\t\t\tglobalThis as {\n\t\t\t\t[defaultInternalComponentConfigKey]?: ComponentType<LinkProps>;\n\t\t\t}\n\t\t)[defaultInternalComponentConfigKey],\n\t\texternalComponent,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t(\"text\" in field\n\t\t\t\t\t? Object.keys(field).length > 2\n\t\t\t\t\t: Object.keys(field).length > 1) &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent ||\n\t\tdefaultComponent) as ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent ||\n\t\tdefaultComponent) as ComponentType<LinkProps>;\n\tconst Component = href\n\t\t? isInternalURL(href)\n\t\t\t? InternalComponent\n\t\t\t: ExternalComponent\n\t\t: InternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Component>\n\t);\n}) as <\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: ForwardedRef<Element>;\n\t},\n) => ReactNode;\n\n/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport function isInternalURL(url: string): boolean {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url);\n\tconst isSpecialLink = !isInternal && !/^https?:\\/\\//.test(url);\n\n\treturn isInternal && !isSpecialLink;\n}\n"],"names":["PrismicLink","_jsx"],"mappings":";;;;;AAmBA,MAAM,oCAAoC,OAAO,IAChD,uDAAuD;AAIxD,MAAM,mBAAmB;AA6FlB,MAAM,cAAc,WAAW,SAASA,aAI9C,OACA,KAA0B;AAE1B,QAAM,EACL,OACA,UAAU,KACV,cACA,oBACC,WAGC,iCAAiC,GACnC,mBACA,UACA,GAAG,UACA,IAAA;AAEJ,MAAI,KAAK;AACR,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8I,OAC7I,yBAAyB,CACzB,EAAE;AAAA,MAAA,YAGH,UAAU,QACR,OAAO,KAAK,KAAK,EAAE,SAAS,IAC5B,OAAO,KAAK,KAAK,EAAE,SAAS,MAC/B,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,QAC7C;AACD,gBAAQ,KACP,uJAAuJ,OACtJ,yBAAyB,CACzB,IACD,KAAK;AAAA,MAAA;AAAA,eAGG,KAAK;AACf,UAAI,EAAE,SAAS,OAAO,QAAQ,MAAM;AACnC,gBAAQ,KACP,0JAA0J,OACzJ,yBAAyB,CACzB,IACD,GAAG;AAAA,MAAA;AAAA,IAEL;AAAA,EACD;AAGK,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,MAAI,MAA0B;AAC9B,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAAA;AAGjB,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,QAAM,oBAAqB,qBAC1B;AACD,QAAM,oBAAqB,qBAC1B;AACD,QAAM,YAAY,OACf,cAAc,IAAI,IACjB,oBACA,oBACD;AAEH,SACCC,IAAC,WAAS,EAAC,KAAc,GAAA,UAAW,WAAW,MAAY,eACzD,cAAc,QAAQ,WAAW,+BAAO,MAAI;AAGhD,CAAC;AAiBK,SAAU,cAAc,KAAW;AAClC,QAAA,aAAa,gBAAgB,KAAK,GAAG;AAC3C,QAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,GAAG;AAE7D,SAAO,cAAc,CAAC;AACvB;"}
@@ -4,7 +4,6 @@ import { isFilled } from "@prismicio/client";
4
4
  import { composeSerializers, wrapMapSerializer, serialize } from "@prismicio/client/richtext";
5
5
  import { DEV } from "esm-env";
6
6
  import { devMsg } from "./lib/devMsg.js";
7
- import { getGlobalConfig } from "./config.js";
8
7
  import { PrismicLink } from "./PrismicLink.js";
9
8
  const getDir = (node) => {
10
9
  if ("direction" in node && node.direction === "rtl") {
@@ -47,8 +46,7 @@ const createDefaultSerializer = (args) => wrapMapSerializer({
47
46
  }
48
47
  });
49
48
  const PrismicRichText = (props) => {
50
- const globalConfig = getGlobalConfig();
51
- const { linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent = globalConfig.internalLinkComponent, ...restProps } = props;
49
+ const { linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent, ...restProps } = props;
52
50
  if (DEV) {
53
51
  if ("className" in restProps) {
54
52
  console.warn(`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, field);
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichText.js","sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import {\n\tcloneElement,\n\tComponentType,\n\tFC,\n\tFragment,\n\tisValidElement,\n\tReactNode,\n} from \"react\";\nimport {\n\tisFilled,\n\tLinkResolverFunction,\n\tRichTextField,\n\tRTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nimport { getGlobalConfig } from \"./config.js\";\nimport { LinkProps, PrismicLink } from \"./PrismicLink.js\";\n\n/**\n * A function mapping rich text block types to React Components. It is used to\n * render rich text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of rich text block types to React Components. It is used to render rich\n * text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXMapSerializer = RichTextMapSerializer<ReactNode>;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a rich text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: JSXMapSerializer | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * Renders content from a Prismic rich text field as React components.\n *\n * @example\n *\n * ```tsx\n * <PrismicRichText field={slice.primary.text} />;\n * ```\n *\n * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = (props) => {\n\tconst globalConfig = getGlobalConfig();\n\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent = globalConfig.internalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(\n\t\tfield,\n\t\t(type, node, text, children, key) => {\n\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\tif (isValidElement(result) && result.key == null) {\n\t\t\t\treturn cloneElement(result, { key });\n\t\t\t} else {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t},\n\t);\n\n\tif (!serialized) {\n\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QAAQ,EAAE,KAAK;AAAA,IAAA,OAC7B;AACC,aAAA;AAAA,IAAA;AAAA,EACR,CACA;AAGF,MAAI,CAAC,YAAY;AACT,WAAA,YAAY,OAAOF,IAAGE,UAAA,EAAA,UAAA,SAAY,CAAA,IAAG;AAAA,EAAA;AAG7C,SAAOF,IAAAE,UAAA,EAAA,UAAG,YAAU;AACrB;"}
1
+ {"version":3,"file":"PrismicRichText.js","sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import {\n\tcloneElement,\n\tComponentType,\n\tFC,\n\tFragment,\n\tisValidElement,\n\tReactNode,\n} from \"react\";\nimport {\n\tisFilled,\n\tLinkResolverFunction,\n\tRichTextField,\n\tRTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nimport { LinkProps, PrismicLink } from \"./PrismicLink.js\";\n\n/**\n * A function mapping rich text block types to React Components. It is used to\n * render rich text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of rich text block types to React Components. It is used to render rich\n * text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXMapSerializer = RichTextMapSerializer<ReactNode>;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a rich text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: JSXMapSerializer | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * Renders content from a Prismic rich text field as React components.\n *\n * @example\n *\n * ```tsx\n * <PrismicRichText field={slice.primary.text} />;\n * ```\n *\n * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = (props) => {\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(\n\t\tfield,\n\t\t(type, node, text, children, key) => {\n\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\tif (isValidElement(result) && result.key == null) {\n\t\t\t\treturn cloneElement(result, { key });\n\t\t\t} else {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t},\n\t);\n\n\tif (!serialized) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{serialized}</>;\n};\n"],"names":["_jsx","Fragment","_Fragment"],"mappings":";;;;;;;AAmHA,MAAM,SAAS,CAAC,SAAsC;AACrD,MAAI,eAAe,QAAQ,KAAK,cAAc,OAAO;AAC7C,WAAA;AAAA,EAAA;AAET;AAEA,MAAM,0BAA0B,CAC/B,SAEA,kBAA6B;AAAA,EAC5B,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAA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": "@prismicio/react",
3
- "version": "3.2.2-pr.235.0d79482",
3
+ "version": "3.2.2-pr.235.5fa03d2",
4
4
  "description": "React components and hooks to fetch and present Prismic content",
5
5
  "keywords": [
6
6
  "typescript",
@@ -17,7 +17,9 @@ import { DEV } from "esm-env";
17
17
 
18
18
  import { devMsg } from "./lib/devMsg.js";
19
19
 
20
- import { getGlobalConfig } from "./config.js";
20
+ const defaultInternalComponentConfigKey = Symbol.for(
21
+ "@prismicio/react/PrismicLink/defaultInternalComponent",
22
+ );
21
23
 
22
24
  /** The default component rendered for internal and external links. */
23
25
  const defaultComponent = "a";
@@ -120,13 +122,15 @@ export const PrismicLink = forwardRef(function PrismicLink<
120
122
  props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,
121
123
  ref: ForwardedRef<Element>,
122
124
  ) {
123
- const globalConfig = getGlobalConfig();
124
-
125
125
  const {
126
126
  field,
127
127
  document: doc,
128
128
  linkResolver,
129
- internalComponent = globalConfig.internalLinkComponent,
129
+ internalComponent = (
130
+ globalThis as {
131
+ [defaultInternalComponentConfigKey]?: ComponentType<LinkProps>;
132
+ }
133
+ )[defaultInternalComponentConfigKey],
130
134
  externalComponent,
131
135
  children,
132
136
  ...restProps
@@ -23,7 +23,6 @@ import { DEV } from "esm-env";
23
23
 
24
24
  import { devMsg } from "./lib/devMsg.js";
25
25
 
26
- import { getGlobalConfig } from "./config.js";
27
26
  import { LinkProps, PrismicLink } from "./PrismicLink.js";
28
27
 
29
28
  /**
@@ -255,15 +254,13 @@ const createDefaultSerializer = (
255
254
  * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
256
255
  */
257
256
  export const PrismicRichText: FC<PrismicRichTextProps> = (props) => {
258
- const globalConfig = getGlobalConfig();
259
-
260
257
  const {
261
258
  linkResolver,
262
259
  field,
263
260
  fallback,
264
261
  components,
265
262
  externalLinkComponent,
266
- internalLinkComponent = globalConfig.internalLinkComponent,
263
+ internalLinkComponent,
267
264
  ...restProps
268
265
  } = props;
269
266
 
package/dist/config.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { ComponentType } from "react";
2
- import type { LinkProps } from "./PrismicLink.js";
3
- type GlobalPrismicReactConfig = {
4
- internalLinkComponent?: ComponentType<LinkProps>;
5
- };
6
- export declare function getGlobalConfig(): GlobalPrismicReactConfig;
7
- export {};
package/dist/config.js DELETED
@@ -1,8 +0,0 @@
1
- const globalConfigKey = Symbol.for("@prismicio/react/config");
2
- function getGlobalConfig() {
3
- return globalThis[globalConfigKey] ?? {};
4
- }
5
- export {
6
- getGlobalConfig
7
- };
8
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sources":["../src/config.ts"],"sourcesContent":["import { ComponentType } from \"react\";\n\nimport type { LinkProps } from \"./PrismicLink.js\";\n\nconst globalConfigKey = Symbol.for(\"@prismicio/react/config\");\n\ntype GlobalThis = {\n\t[globalConfigKey]?: GlobalPrismicReactConfig;\n};\n\ntype GlobalPrismicReactConfig = {\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nexport function getGlobalConfig(): GlobalPrismicReactConfig {\n\treturn (globalThis as GlobalThis)[globalConfigKey] ?? {};\n}\n"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,OAAO,IAAI,yBAAyB;SAU5C,kBAAe;AACtB,SAAA,WAA0B,eAAe,KAAK;AACvD;"}
package/src/config.ts DELETED
@@ -1,17 +0,0 @@
1
- import { ComponentType } from "react";
2
-
3
- import type { LinkProps } from "./PrismicLink.js";
4
-
5
- const globalConfigKey = Symbol.for("@prismicio/react/config");
6
-
7
- type GlobalThis = {
8
- [globalConfigKey]?: GlobalPrismicReactConfig;
9
- };
10
-
11
- type GlobalPrismicReactConfig = {
12
- internalLinkComponent?: ComponentType<LinkProps>;
13
- };
14
-
15
- export function getGlobalConfig(): GlobalPrismicReactConfig {
16
- return (globalThis as GlobalThis)[globalConfigKey] ?? {};
17
- }