@prismicio/vue 3.1.3 → 3.2.0
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.
- package/README.md +1 -1
- package/dist/components/PrismicEmbed.cjs.map +1 -1
- package/dist/components/PrismicEmbed.d.ts +57 -63
- package/dist/components/PrismicEmbed.js.map +1 -1
- package/dist/components/PrismicImage.cjs.map +1 -1
- package/dist/components/PrismicImage.d.ts +162 -162
- package/dist/components/PrismicImage.js.map +1 -1
- package/dist/components/PrismicLink.cjs.map +1 -1
- package/dist/components/PrismicLink.d.ts +191 -191
- package/dist/components/PrismicLink.js.map +1 -1
- package/dist/components/PrismicRichText.cjs +7 -2
- package/dist/components/PrismicRichText.cjs.map +1 -1
- package/dist/components/PrismicRichText.d.ts +160 -139
- package/dist/components/PrismicRichText.js +7 -2
- package/dist/components/PrismicRichText.js.map +1 -1
- package/dist/components/PrismicText.cjs.map +1 -1
- package/dist/components/PrismicText.d.ts +117 -117
- package/dist/components/PrismicText.js.map +1 -1
- package/dist/components/SliceZone.cjs.map +1 -1
- package/dist/components/SliceZone.d.ts +357 -359
- package/dist/components/SliceZone.js.map +1 -1
- package/dist/components/index.d.ts +12 -12
- package/dist/composables.d.ts +366 -366
- package/dist/createPrismic.cjs +3 -3
- package/dist/createPrismic.cjs.map +1 -1
- package/dist/createPrismic.d.ts +12 -12
- package/dist/createPrismic.js +3 -3
- package/dist/createPrismic.js.map +1 -1
- package/dist/globalExtensions.d.ts +11 -11
- package/dist/index.cjs +16 -16
- package/dist/index.d.ts +10 -10
- package/dist/index.js +3 -3
- package/dist/injectionSymbols.d.ts +9 -9
- package/dist/lib/__PRODUCTION__.d.ts +7 -7
- package/dist/lib/getSlots.d.ts +14 -14
- package/dist/lib/isInternalURL.d.ts +8 -8
- package/dist/lib/simplyResolveComponent.cjs.map +1 -1
- package/dist/lib/simplyResolveComponent.d.ts +12 -12
- package/dist/lib/simplyResolveComponent.js.map +1 -1
- package/dist/types.d.ts +366 -357
- package/dist/usePrismic.d.ts +21 -21
- package/dist/useStatefulPrismicClientMethod.d.ts +64 -64
- package/package.json +15 -15
- package/src/components/PrismicEmbed.ts +6 -2
- package/src/components/PrismicImage.ts +6 -2
- package/src/components/PrismicLink.ts +11 -5
- package/src/components/PrismicRichText.ts +30 -5
- package/src/components/PrismicText.ts +6 -2
- package/src/components/SliceZone.ts +8 -2
- package/src/createPrismic.ts +3 -6
- package/src/lib/simplyResolveComponent.ts +8 -2
- package/src/types.ts +15 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.cjs","sources":["../../../src/components/PrismicLink.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponentCustomProps,\n\tdefineComponent,\n\th,\n\tPropType,\n\tVNodeProps,\n\tunref,\n\treactive,\n\tConcreteComponent,\n\tcomputed,\n\tComputedRef,\n} from \"vue\";\n\nimport { asLink, LinkResolverFunction } from \"@prismicio/helpers\";\nimport { LinkField, PrismicDocument } from \"@prismicio/types\";\n\nimport { isInternalURL } from \"../lib/isInternalURL\";\nimport { usePrismic } from \"../usePrismic\";\nimport { VueUseOptions } from \"../types\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { getSlots } from \"../lib/getSlots\";\n\n/**\n * The default component rendered for internal URLs.\n */\nconst defaultInternalComponent = \"router-link\";\n\n/**\n * The default component rendered for external URLs.\n */\nconst defaultExternalComponent = \"a\";\n\n/**\n * The default rel attribute rendered for blank target URLs.\n */\nconst defaultBlankTargetRelAttribute = \"noopener noreferrer\";\n\n/**\n * Props for `<PrismicLink />`.\n */\nexport type PrismicLinkProps = {\n\t/**\n\t * The Prismic link field or document to render.\n\t */\n\tfield: LinkField | PrismicDocument;\n\n\t/**\n\t * A link resolver function used to resolve links when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An explicit `target` attribute to apply to the rendered link.\n\t */\n\ttarget?: string | null;\n\n\t/**\n\t * An explicit `rel` attribute to apply to the rendered link.\n\t */\n\trel?: string | null;\n\n\t/**\n\t * Value of the `rel` attribute to use on links rendered with\n\t * `target=\"_blank\"`.\n\t *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"noopener noreferrer\"` otherwise.\n\t */\n\tblankTargetRelAttribute?: string | null;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * internal links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.\n\t */\n\tinternalComponent?: string | ConcreteComponent;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * external links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"a\"` otherwise.\n\t */\n\texternalComponent?: string | ConcreteComponent;\n};\n\n/**\n * Options for {@link usePrismicLink}.\n */\nexport type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>;\n\n/**\n * Return type of {@link usePrismicLink}.\n */\nexport type UsePrismicLinkReturnType = {\n\t/**\n\t * Suggested component to render for provided link field.\n\t */\n\ttype: ComputedRef<string | ConcreteComponent>;\n\n\t/**\n\t * Resolved anchor `href` value.\n\t */\n\thref: ComputedRef<string>;\n\n\t/**\n\t * Resolved anchor `target` value.\n\t */\n\ttarget: ComputedRef<string | null>;\n\n\t/**\n\t * Resolved anchor `rel` value.\n\t */\n\trel: ComputedRef<string | null>;\n};\n\n/**\n * A low level composable that returns resolved information about a Prismic link\n * field.\n *\n * @param props - {@link UsePrismicLinkOptions}\n *\n * @returns - Resolved link information {@link UsePrismicLinkReturnType}\n */\nexport const usePrismicLink = (\n\tprops: UsePrismicLinkOptions,\n): UsePrismicLinkReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst type = computed(() => {\n\t\tconst internalComponent =\n\t\t\tunref(props.internalComponent) ||\n\t\t\toptions.components?.linkInternalComponent ||\n\t\t\tdefaultInternalComponent;\n\n\t\tconst externalComponent =\n\t\t\tunref(props.externalComponent) ||\n\t\t\toptions.components?.linkExternalComponent ||\n\t\t\tdefaultExternalComponent;\n\n\t\treturn href.value && isInternalURL(href.value) && !target.value\n\t\t\t? internalComponent\n\t\t\t: externalComponent;\n\t});\n\tconst href = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\n\t\treturn asLink(field, linkResolver) ?? \"\";\n\t});\n\tconst target = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst target = unref(props.target);\n\n\t\tif (typeof target !== \"undefined\") {\n\t\t\treturn target;\n\t\t} else {\n\t\t\treturn field && \"target\" in field && field.target ? field.target : null;\n\t\t}\n\t});\n\tconst rel = computed(() => {\n\t\tconst rel = unref(props.rel);\n\n\t\tif (typeof rel !== \"undefined\") {\n\t\t\treturn rel;\n\t\t} else if (target.value === \"_blank\") {\n\t\t\tconst blankTargetRelAttribute = unref(props.blankTargetRelAttribute);\n\n\t\t\tif (typeof blankTargetRelAttribute !== \"undefined\") {\n\t\t\t\treturn blankTargetRelAttribute;\n\t\t\t} else {\n\t\t\t\treturn typeof options.components?.linkBlankTargetRelAttribute !==\n\t\t\t\t\t\"undefined\"\n\t\t\t\t\t? options.components.linkBlankTargetRelAttribute\n\t\t\t\t\t: defaultBlankTargetRelAttribute;\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t});\n\n\treturn {\n\t\ttype,\n\t\thref,\n\t\ttarget,\n\t\trel,\n\t};\n};\n\n/**\n * `<PrismicLink />` implementation.\n *\n * @internal\n */\nexport const PrismicLinkImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicLink\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Object as PropType<LinkField | PrismicDocument>,\n\t\t\trequired: true,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\ttarget: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\trel: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tblankTargetRelAttribute: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tinternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\texternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props, { slots }) {\n\t\t// Prevent fatal if user didn't check for field, throws `Invalid prop` warn\n\t\tif (!props.field) {\n\t\t\treturn () => null;\n\t\t}\n\n\t\tconst { type, href, target, rel } = usePrismicLink(props);\n\n\t\treturn () => {\n\t\t\tconst parent =\n\t\t\t\ttype.value === \"a\" ? \"a\" : simplyResolveComponent(type.value);\n\t\t\tconst computedSlots = getSlots(\n\t\t\t\tparent,\n\t\t\t\tslots,\n\t\t\t\treactive({ href: href.value }),\n\t\t\t);\n\n\t\t\tif (typeof parent === \"string\") {\n\t\t\t\t// Fitting anchor tag interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ href: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Fitting Vue Router Link interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ to: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic link field.\n *\n * @see Component props {@link PrismicLinkProps}\n * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}\n */\nexport const PrismicLink = PrismicLinkImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicLinkProps;\n\t};\n};\n"],"names":["usePrismic","computed","unref","isInternalURL","asLink","target","rel","defineComponent","simplyResolveComponent","getSlots","reactive","h"],"mappings":";;;;;;;;AA0BA,MAAM,2BAA2B;AAKjC,MAAM,2BAA2B;AAKjC,MAAM,iCAAiC;AA0G1B,MAAA,iBAAiB,CAC7B,UAC6B;AACvB,QAAA,EAAE,YAAYA,WAAAA;AAEd,QAAA,OAAOC,IAAAA,SAAS,MAAK;;AAC1B,UAAM,oBACLC,IAAM,MAAA,MAAM,iBAAiB,OAC7B,aAAQ,eAAR,mBAAoB,0BACpB;AAED,UAAM,oBACLA,IAAM,MAAA,MAAM,iBAAiB,OAC7B,aAAQ,eAAR,mBAAoB,0BACpB;AAEM,WAAA,KAAK,SAASC,cAAc,cAAA,KAAK,KAAK,KAAK,CAAC,OAAO,QACvD,oBACA;AAAA,EAAA,CACH;AACK,QAAA,OAAOF,IAAAA,SAAS,MAAK;AACpB,UAAA,QAAQC,IAAAA,MAAM,MAAM,KAAK;AAC/B,UAAM,eAAeA,IAAAA,MAAM,MAAM,YAAY,KAAK,QAAQ;AAEnD,WAAAE,eAAO,OA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AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,mBAAmB;AAAA,MAClB,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,mBAAmB;AAAA,MAClB,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,EACD;AAAA,EACD,MAAM,OAAO,EAAE,SAAO;AAEjB,QAAA,CAAC,MAAM,OAAO;AACjB,aAAO,MAAM;AAAA,IACb;AAED,UAAM,EAAE,MAAM,MAAM,QAAQ,QAAQ,eAAe,KAAK;AAExD,WAAO,MAAK;AACX,YAAM,SACL,KAAK,UAAU,MAAM,MAAMC,uBAAA,uBAAuB,KAAK,KAAK;AACvD,YAAA,gBAAgBC,SAAAA,SACrB,QACA,OACAC,IAAAA,SAAS,EAAE,MAAM,KAAK,MAAO,CAAA,CAAC;AAG3B,UAAA,OAAO,WAAW,UAAU;AAE/B,eAAOC,IACN,EAAA,QACA,EAAE,MAAM,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACnD,aAAa;AAAA,MAAA,OAER;AAEN,eAAOA,IACN,EAAA,QACA,EAAE,IAAI,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACjD,aAAa;AAAA,MAEd;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,cAAc;;;;"}
|
|
1
|
+
{"version":3,"file":"PrismicLink.cjs","sources":["../../../src/components/PrismicLink.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponentCustomProps,\n\tdefineComponent,\n\th,\n\tPropType,\n\tVNodeProps,\n\tunref,\n\treactive,\n\tConcreteComponent,\n\tcomputed,\n\tComputedRef,\n\tRaw,\n\tDefineComponent,\n} from \"vue\";\n\nimport { asLink, LinkResolverFunction } from \"@prismicio/helpers\";\nimport { LinkField, PrismicDocument } from \"@prismicio/types\";\n\nimport { isInternalURL } from \"../lib/isInternalURL\";\nimport { usePrismic } from \"../usePrismic\";\nimport { VueUseOptions } from \"../types\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { getSlots } from \"../lib/getSlots\";\n\n/**\n * The default component rendered for internal URLs.\n */\nconst defaultInternalComponent = \"router-link\";\n\n/**\n * The default component rendered for external URLs.\n */\nconst defaultExternalComponent = \"a\";\n\n/**\n * The default rel attribute rendered for blank target URLs.\n */\nconst defaultBlankTargetRelAttribute = \"noopener noreferrer\";\n\n/**\n * Props for `<PrismicLink />`.\n */\nexport type PrismicLinkProps = {\n\t/**\n\t * The Prismic link field or document to render.\n\t */\n\tfield: LinkField | PrismicDocument;\n\n\t/**\n\t * A link resolver function used to resolve links when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An explicit `target` attribute to apply to the rendered link.\n\t */\n\ttarget?: string | null;\n\n\t/**\n\t * An explicit `rel` attribute to apply to the rendered link.\n\t */\n\trel?: string | null;\n\n\t/**\n\t * Value of the `rel` attribute to use on links rendered with\n\t * `target=\"_blank\"`.\n\t *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"noopener noreferrer\"` otherwise.\n\t */\n\tblankTargetRelAttribute?: string | null;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * internal links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.\n\t */\n\tinternalComponent?: string | ConcreteComponent | Raw<DefineComponent>;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * external links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"a\"` otherwise.\n\t */\n\texternalComponent?: string | ConcreteComponent | Raw<DefineComponent>;\n};\n\n/**\n * Options for {@link usePrismicLink}.\n */\nexport type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>;\n\n/**\n * Return type of {@link usePrismicLink}.\n */\nexport type UsePrismicLinkReturnType = {\n\t/**\n\t * Suggested component to render for provided link field.\n\t */\n\ttype: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>>;\n\n\t/**\n\t * Resolved anchor `href` value.\n\t */\n\thref: ComputedRef<string>;\n\n\t/**\n\t * Resolved anchor `target` value.\n\t */\n\ttarget: ComputedRef<string | null>;\n\n\t/**\n\t * Resolved anchor `rel` value.\n\t */\n\trel: ComputedRef<string | null>;\n};\n\n/**\n * A low level composable that returns resolved information about a Prismic link\n * field.\n *\n * @param props - {@link UsePrismicLinkOptions}\n *\n * @returns - Resolved link information {@link UsePrismicLinkReturnType}\n */\nexport const usePrismicLink = (\n\tprops: UsePrismicLinkOptions,\n): UsePrismicLinkReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst type = computed(() => {\n\t\tconst internalComponent =\n\t\t\tunref(props.internalComponent) ||\n\t\t\toptions.components?.linkInternalComponent ||\n\t\t\tdefaultInternalComponent;\n\n\t\tconst externalComponent =\n\t\t\tunref(props.externalComponent) ||\n\t\t\toptions.components?.linkExternalComponent ||\n\t\t\tdefaultExternalComponent;\n\n\t\treturn href.value && isInternalURL(href.value) && !target.value\n\t\t\t? internalComponent\n\t\t\t: externalComponent;\n\t});\n\tconst href = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\n\t\treturn asLink(field, linkResolver) ?? \"\";\n\t});\n\tconst target = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst target = unref(props.target);\n\n\t\tif (typeof target !== \"undefined\") {\n\t\t\treturn target;\n\t\t} else {\n\t\t\treturn field && \"target\" in field && field.target ? field.target : null;\n\t\t}\n\t});\n\tconst rel = computed(() => {\n\t\tconst rel = unref(props.rel);\n\n\t\tif (typeof rel !== \"undefined\") {\n\t\t\treturn rel;\n\t\t} else if (target.value === \"_blank\") {\n\t\t\tconst blankTargetRelAttribute = unref(props.blankTargetRelAttribute);\n\n\t\t\tif (typeof blankTargetRelAttribute !== \"undefined\") {\n\t\t\t\treturn blankTargetRelAttribute;\n\t\t\t} else {\n\t\t\t\treturn typeof options.components?.linkBlankTargetRelAttribute !==\n\t\t\t\t\t\"undefined\"\n\t\t\t\t\t? options.components.linkBlankTargetRelAttribute\n\t\t\t\t\t: defaultBlankTargetRelAttribute;\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t});\n\n\treturn {\n\t\ttype,\n\t\thref,\n\t\ttarget,\n\t\trel,\n\t};\n};\n\n/**\n * `<PrismicLink />` implementation.\n *\n * @internal\n */\nexport const PrismicLinkImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicLink\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Object as PropType<LinkField | PrismicDocument>,\n\t\t\trequired: true,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\ttarget: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\trel: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tblankTargetRelAttribute: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tinternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<\n\t\t\t\tstring | ConcreteComponent | Raw<DefineComponent>\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\texternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<\n\t\t\t\tstring | ConcreteComponent | Raw<DefineComponent>\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props, { slots }) {\n\t\t// Prevent fatal if user didn't check for field, throws `Invalid prop` warn\n\t\tif (!props.field) {\n\t\t\treturn () => null;\n\t\t}\n\n\t\tconst { type, href, target, rel } = usePrismicLink(props);\n\n\t\treturn () => {\n\t\t\tconst parent =\n\t\t\t\ttype.value === \"a\" ? \"a\" : simplyResolveComponent(type.value);\n\t\t\tconst computedSlots = getSlots(\n\t\t\t\tparent,\n\t\t\t\tslots,\n\t\t\t\treactive({ href: href.value }),\n\t\t\t);\n\n\t\t\tif (typeof parent === \"string\") {\n\t\t\t\t// Fitting anchor tag interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ href: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Fitting Vue Router Link interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ to: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic link field.\n *\n * @see Component props {@link PrismicLinkProps}\n * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}\n */\nexport const PrismicLink = PrismicLinkImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicLinkProps;\n\t};\n};\n"],"names":["usePrismic","computed","unref","isInternalURL","asLink","target","rel","defineComponent","simplyResolveComponent","getSlots","reactive","h"],"mappings":";;;;;;;;AA4BA,MAAM,2BAA2B;AAKjC,MAAM,2BAA2B;AAKjC,MAAM,iCAAiC;AA0G1B,MAAA,iBAAiB,CAC7B,UAC6B;AACvB,QAAA,EAAE,YAAYA,WAAAA;AAEd,QAAA,OAAOC,IAAAA,SAAS,MAAK;;AAC1B,UAAM,oBACLC,IAAM,MAAA,MAAM,iBAAiB,OAC7B,aAAQ,eAAR,mBAAoB,0BACpB;AAED,UAAM,oBACLA,IAAM,MAAA,MAAM,iBAAiB,OAC7B,aAAQ,eAAR,mBAAoB,0BACpB;AAEM,WAAA,KAAK,SAASC,cAAc,cAAA,KAAK,KAAK,KAAK,CAAC,OAAO,QACvD,oBACA;AAAA,EAAA,CACH;AACK,QAAA,OAAOF,IAAAA,SAAS,MAAK;AACpB,UAAA,QAAQC,IAAAA,MAAM,MAAM,KAAK;AAC/B,UAAM,eAAeA,IAAAA,MAAM,MAAM,YAAY,KAAK,QAAQ;AAEnD,WAAAE,eAAO,OAAO,YAAY,KAAK;AAAA,EAAA,CACtC;AACK,QAAA,SAASH,IAAAA,SAAS,MAAK;AACtB,UAAA,QAAQC,IAAAA,MAAM,MAAM,KAAK;AACzBG,UAAAA,UAASH,IAAAA,MAAM,MAAM,MAAM;AAE7B,QAAA,OAAOG,YAAW,aAAa;AAC3BA,aAAAA;AAAAA,IAAA,OACD;AACN,aAAO,SAAS,YAAY,SAAS,MAAM,SAAS,MAAM,SAAS;AAAA,IACnE;AAAA,EAAA,CACD;AACK,QAAA,MAAMJ,IAAAA,SAAS,MAAK;;AACnBK,UAAAA,OAAMJ,IAAAA,MAAM,MAAM,GAAG;AAEvB,QAAA,OAAOI,SAAQ,aAAa;AACxBA,aAAAA;AAAAA,IAAA,WACG,OAAO,UAAU,UAAU;AAC/B,YAAA,0BAA0BJ,IAAAA,MAAM,MAA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SAAAA,SACrB,QACA,OACAC,IAAAA,SAAS,EAAE,MAAM,KAAK,MAAO,CAAA,CAAC;AAG3B,UAAA,OAAO,WAAW,UAAU;AAE/B,eAAOC,IACN,EAAA,QACA,EAAE,MAAM,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACnD,aAAa;AAAA,MAAA,OAER;AAEN,eAAOA,IACN,EAAA,QACA,EAAE,IAAI,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACjD,aAAa;AAAA,MAEd;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,cAAc;;;;"}
|
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import { AllowedComponentProps, ComponentCustomProps, PropType, VNodeProps, ConcreteComponent, ComputedRef } from "vue";
|
|
2
|
-
import { LinkResolverFunction } from "@prismicio/helpers";
|
|
3
|
-
import { LinkField, PrismicDocument } from "@prismicio/types";
|
|
4
|
-
import { VueUseOptions } from "../types";
|
|
5
|
-
/**
|
|
6
|
-
* Props for `<PrismicLink />`.
|
|
7
|
-
*/
|
|
8
|
-
export type PrismicLinkProps = {
|
|
9
|
-
/**
|
|
10
|
-
* The Prismic link field or document to render.
|
|
11
|
-
*/
|
|
12
|
-
field: LinkField | PrismicDocument;
|
|
13
|
-
/**
|
|
14
|
-
* A link resolver function used to resolve links when not using the route
|
|
15
|
-
* resolver parameter with `@prismicio/client`.
|
|
16
|
-
*
|
|
17
|
-
* @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
|
|
18
|
-
*
|
|
19
|
-
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
20
|
-
*/
|
|
21
|
-
linkResolver?: LinkResolverFunction;
|
|
22
|
-
/**
|
|
23
|
-
* An explicit `target` attribute to apply to the rendered link.
|
|
24
|
-
*/
|
|
25
|
-
target?: string | null;
|
|
26
|
-
/**
|
|
27
|
-
* An explicit `rel` attribute to apply to the rendered link.
|
|
28
|
-
*/
|
|
29
|
-
rel?: string | null;
|
|
30
|
-
/**
|
|
31
|
-
* Value of the `rel` attribute to use on links rendered with
|
|
32
|
-
* `target="_blank"`.
|
|
33
|
-
*
|
|
34
|
-
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"noopener noreferrer"` otherwise.
|
|
35
|
-
*/
|
|
36
|
-
blankTargetRelAttribute?: string | null;
|
|
37
|
-
/**
|
|
38
|
-
* An HTML tag name, a component, or a functional component used to render
|
|
39
|
-
* internal links.
|
|
40
|
-
*
|
|
41
|
-
* @remarks
|
|
42
|
-
* HTML tag names will be rendered using the anchor tag interface (`href`,
|
|
43
|
-
* `target`, and `rel` attributes).
|
|
44
|
-
* @remarks
|
|
45
|
-
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
46
|
-
* (`to` props).
|
|
47
|
-
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
|
|
48
|
-
*/
|
|
49
|
-
internalComponent?: string | ConcreteComponent
|
|
50
|
-
/**
|
|
51
|
-
* An HTML tag name, a component, or a functional component used to render
|
|
52
|
-
* external links.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* HTML tag names will be rendered using the anchor tag interface (`href`,
|
|
56
|
-
* `target`, and `rel` attributes).
|
|
57
|
-
* @remarks
|
|
58
|
-
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
59
|
-
* (`to` props).
|
|
60
|
-
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
|
|
61
|
-
*/
|
|
62
|
-
externalComponent?: string | ConcreteComponent
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Options for {@link usePrismicLink}.
|
|
66
|
-
*/
|
|
67
|
-
export type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>;
|
|
68
|
-
/**
|
|
69
|
-
* Return type of {@link usePrismicLink}.
|
|
70
|
-
*/
|
|
71
|
-
export type UsePrismicLinkReturnType = {
|
|
72
|
-
/**
|
|
73
|
-
* Suggested component to render for provided link field.
|
|
74
|
-
*/
|
|
75
|
-
type: ComputedRef<string | ConcreteComponent
|
|
76
|
-
/**
|
|
77
|
-
* Resolved anchor `href` value.
|
|
78
|
-
*/
|
|
79
|
-
href: ComputedRef<string>;
|
|
80
|
-
/**
|
|
81
|
-
* Resolved anchor `target` value.
|
|
82
|
-
*/
|
|
83
|
-
target: ComputedRef<string | null>;
|
|
84
|
-
/**
|
|
85
|
-
* Resolved anchor `rel` value.
|
|
86
|
-
*/
|
|
87
|
-
rel: ComputedRef<string | null>;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* A low level composable that returns resolved information about a Prismic link
|
|
91
|
-
* field.
|
|
92
|
-
*
|
|
93
|
-
* @param props - {@link UsePrismicLinkOptions}
|
|
94
|
-
*
|
|
95
|
-
* @returns - Resolved link information {@link UsePrismicLinkReturnType}
|
|
96
|
-
*/
|
|
97
|
-
export declare const usePrismicLink: (props: UsePrismicLinkOptions) => UsePrismicLinkReturnType;
|
|
98
|
-
/**
|
|
99
|
-
* `<PrismicLink />` implementation.
|
|
100
|
-
*
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
export declare const PrismicLinkImpl:
|
|
104
|
-
field: {
|
|
105
|
-
type: PropType<
|
|
106
|
-
required: true;
|
|
107
|
-
};
|
|
108
|
-
linkResolver: {
|
|
109
|
-
type: PropType<LinkResolverFunction
|
|
110
|
-
default: undefined;
|
|
111
|
-
required: false;
|
|
112
|
-
};
|
|
113
|
-
target: {
|
|
114
|
-
type: PropType<string | null>;
|
|
115
|
-
default: undefined;
|
|
116
|
-
required: false;
|
|
117
|
-
};
|
|
118
|
-
rel: {
|
|
119
|
-
type: PropType<string | null>;
|
|
120
|
-
default: undefined;
|
|
121
|
-
required: false;
|
|
122
|
-
};
|
|
123
|
-
blankTargetRelAttribute: {
|
|
124
|
-
type: PropType<string | null>;
|
|
125
|
-
default: undefined;
|
|
126
|
-
required: false;
|
|
127
|
-
};
|
|
128
|
-
internalComponent: {
|
|
129
|
-
type: PropType<string | ConcreteComponent
|
|
130
|
-
default: undefined;
|
|
131
|
-
required: false;
|
|
132
|
-
};
|
|
133
|
-
externalComponent: {
|
|
134
|
-
type: PropType<string | ConcreteComponent
|
|
135
|
-
default: undefined;
|
|
136
|
-
required: false;
|
|
137
|
-
};
|
|
138
|
-
}, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
139
|
-
[key: string]: any;
|
|
140
|
-
}>), unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
141
|
-
field: {
|
|
142
|
-
type: PropType<
|
|
143
|
-
required: true;
|
|
144
|
-
};
|
|
145
|
-
linkResolver: {
|
|
146
|
-
type: PropType<LinkResolverFunction
|
|
147
|
-
default: undefined;
|
|
148
|
-
required: false;
|
|
149
|
-
};
|
|
150
|
-
target: {
|
|
151
|
-
type: PropType<string | null>;
|
|
152
|
-
default: undefined;
|
|
153
|
-
required: false;
|
|
154
|
-
};
|
|
155
|
-
rel: {
|
|
156
|
-
type: PropType<string | null>;
|
|
157
|
-
default: undefined;
|
|
158
|
-
required: false;
|
|
159
|
-
};
|
|
160
|
-
blankTargetRelAttribute: {
|
|
161
|
-
type: PropType<string | null>;
|
|
162
|
-
default: undefined;
|
|
163
|
-
required: false;
|
|
164
|
-
};
|
|
165
|
-
internalComponent: {
|
|
166
|
-
type: PropType<string | ConcreteComponent
|
|
167
|
-
default: undefined;
|
|
168
|
-
required: false;
|
|
169
|
-
};
|
|
170
|
-
externalComponent: {
|
|
171
|
-
type: PropType<string | ConcreteComponent
|
|
172
|
-
default: undefined;
|
|
173
|
-
required: false;
|
|
174
|
-
};
|
|
175
|
-
}>>, {
|
|
176
|
-
target: string | null;
|
|
177
|
-
linkResolver: LinkResolverFunction
|
|
178
|
-
rel: string | null;
|
|
179
|
-
blankTargetRelAttribute: string | null;
|
|
180
|
-
internalComponent: string | ConcreteComponent
|
|
181
|
-
externalComponent: string | ConcreteComponent
|
|
182
|
-
}>;
|
|
183
|
-
/**
|
|
184
|
-
* Component to render a Prismic link field.
|
|
185
|
-
*
|
|
186
|
-
* @see Component props {@link PrismicLinkProps}
|
|
187
|
-
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
|
|
188
|
-
*/
|
|
189
|
-
export declare const PrismicLink: new () => {
|
|
190
|
-
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & PrismicLinkProps;
|
|
191
|
-
};
|
|
1
|
+
import { AllowedComponentProps, ComponentCustomProps, PropType, VNodeProps, ConcreteComponent, ComputedRef, Raw, DefineComponent } from "vue";
|
|
2
|
+
import { LinkResolverFunction } from "@prismicio/helpers";
|
|
3
|
+
import { LinkField, PrismicDocument } from "@prismicio/types";
|
|
4
|
+
import { VueUseOptions } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* Props for `<PrismicLink />`.
|
|
7
|
+
*/
|
|
8
|
+
export type PrismicLinkProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The Prismic link field or document to render.
|
|
11
|
+
*/
|
|
12
|
+
field: LinkField | PrismicDocument;
|
|
13
|
+
/**
|
|
14
|
+
* A link resolver function used to resolve links when not using the route
|
|
15
|
+
* resolver parameter with `@prismicio/client`.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
|
|
18
|
+
*
|
|
19
|
+
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
20
|
+
*/
|
|
21
|
+
linkResolver?: LinkResolverFunction;
|
|
22
|
+
/**
|
|
23
|
+
* An explicit `target` attribute to apply to the rendered link.
|
|
24
|
+
*/
|
|
25
|
+
target?: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* An explicit `rel` attribute to apply to the rendered link.
|
|
28
|
+
*/
|
|
29
|
+
rel?: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Value of the `rel` attribute to use on links rendered with
|
|
32
|
+
* `target="_blank"`.
|
|
33
|
+
*
|
|
34
|
+
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"noopener noreferrer"` otherwise.
|
|
35
|
+
*/
|
|
36
|
+
blankTargetRelAttribute?: string | null;
|
|
37
|
+
/**
|
|
38
|
+
* An HTML tag name, a component, or a functional component used to render
|
|
39
|
+
* internal links.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* HTML tag names will be rendered using the anchor tag interface (`href`,
|
|
43
|
+
* `target`, and `rel` attributes).
|
|
44
|
+
* @remarks
|
|
45
|
+
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
46
|
+
* (`to` props).
|
|
47
|
+
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
|
|
48
|
+
*/
|
|
49
|
+
internalComponent?: string | ConcreteComponent | Raw<DefineComponent>;
|
|
50
|
+
/**
|
|
51
|
+
* An HTML tag name, a component, or a functional component used to render
|
|
52
|
+
* external links.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* HTML tag names will be rendered using the anchor tag interface (`href`,
|
|
56
|
+
* `target`, and `rel` attributes).
|
|
57
|
+
* @remarks
|
|
58
|
+
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
59
|
+
* (`to` props).
|
|
60
|
+
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
|
|
61
|
+
*/
|
|
62
|
+
externalComponent?: string | ConcreteComponent | Raw<DefineComponent>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Options for {@link usePrismicLink}.
|
|
66
|
+
*/
|
|
67
|
+
export type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>;
|
|
68
|
+
/**
|
|
69
|
+
* Return type of {@link usePrismicLink}.
|
|
70
|
+
*/
|
|
71
|
+
export type UsePrismicLinkReturnType = {
|
|
72
|
+
/**
|
|
73
|
+
* Suggested component to render for provided link field.
|
|
74
|
+
*/
|
|
75
|
+
type: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>>;
|
|
76
|
+
/**
|
|
77
|
+
* Resolved anchor `href` value.
|
|
78
|
+
*/
|
|
79
|
+
href: ComputedRef<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Resolved anchor `target` value.
|
|
82
|
+
*/
|
|
83
|
+
target: ComputedRef<string | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Resolved anchor `rel` value.
|
|
86
|
+
*/
|
|
87
|
+
rel: ComputedRef<string | null>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* A low level composable that returns resolved information about a Prismic link
|
|
91
|
+
* field.
|
|
92
|
+
*
|
|
93
|
+
* @param props - {@link UsePrismicLinkOptions}
|
|
94
|
+
*
|
|
95
|
+
* @returns - Resolved link information {@link UsePrismicLinkReturnType}
|
|
96
|
+
*/
|
|
97
|
+
export declare const usePrismicLink: (props: UsePrismicLinkOptions) => UsePrismicLinkReturnType;
|
|
98
|
+
/**
|
|
99
|
+
* `<PrismicLink />` implementation.
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
export declare const PrismicLinkImpl: DefineComponent<{
|
|
104
|
+
field: {
|
|
105
|
+
type: PropType<LinkField | PrismicDocument<Record<string, any>, string, string>>;
|
|
106
|
+
required: true;
|
|
107
|
+
};
|
|
108
|
+
linkResolver: {
|
|
109
|
+
type: PropType<LinkResolverFunction>;
|
|
110
|
+
default: undefined;
|
|
111
|
+
required: false;
|
|
112
|
+
};
|
|
113
|
+
target: {
|
|
114
|
+
type: PropType<string | null>;
|
|
115
|
+
default: undefined;
|
|
116
|
+
required: false;
|
|
117
|
+
};
|
|
118
|
+
rel: {
|
|
119
|
+
type: PropType<string | null>;
|
|
120
|
+
default: undefined;
|
|
121
|
+
required: false;
|
|
122
|
+
};
|
|
123
|
+
blankTargetRelAttribute: {
|
|
124
|
+
type: PropType<string | null>;
|
|
125
|
+
default: undefined;
|
|
126
|
+
required: false;
|
|
127
|
+
};
|
|
128
|
+
internalComponent: {
|
|
129
|
+
type: PropType<string | ConcreteComponent | Raw<DefineComponent>>;
|
|
130
|
+
default: undefined;
|
|
131
|
+
required: false;
|
|
132
|
+
};
|
|
133
|
+
externalComponent: {
|
|
134
|
+
type: PropType<string | ConcreteComponent | Raw<DefineComponent>>;
|
|
135
|
+
default: undefined;
|
|
136
|
+
required: false;
|
|
137
|
+
};
|
|
138
|
+
}, (() => null) | (() => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
139
|
+
[key: string]: any;
|
|
140
|
+
}>), unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
141
|
+
field: {
|
|
142
|
+
type: PropType<LinkField | PrismicDocument<Record<string, any>, string, string>>;
|
|
143
|
+
required: true;
|
|
144
|
+
};
|
|
145
|
+
linkResolver: {
|
|
146
|
+
type: PropType<LinkResolverFunction>;
|
|
147
|
+
default: undefined;
|
|
148
|
+
required: false;
|
|
149
|
+
};
|
|
150
|
+
target: {
|
|
151
|
+
type: PropType<string | null>;
|
|
152
|
+
default: undefined;
|
|
153
|
+
required: false;
|
|
154
|
+
};
|
|
155
|
+
rel: {
|
|
156
|
+
type: PropType<string | null>;
|
|
157
|
+
default: undefined;
|
|
158
|
+
required: false;
|
|
159
|
+
};
|
|
160
|
+
blankTargetRelAttribute: {
|
|
161
|
+
type: PropType<string | null>;
|
|
162
|
+
default: undefined;
|
|
163
|
+
required: false;
|
|
164
|
+
};
|
|
165
|
+
internalComponent: {
|
|
166
|
+
type: PropType<string | ConcreteComponent | Raw<DefineComponent>>;
|
|
167
|
+
default: undefined;
|
|
168
|
+
required: false;
|
|
169
|
+
};
|
|
170
|
+
externalComponent: {
|
|
171
|
+
type: PropType<string | ConcreteComponent | Raw<DefineComponent>>;
|
|
172
|
+
default: undefined;
|
|
173
|
+
required: false;
|
|
174
|
+
};
|
|
175
|
+
}>>, {
|
|
176
|
+
target: string | null;
|
|
177
|
+
linkResolver: LinkResolverFunction;
|
|
178
|
+
rel: string | null;
|
|
179
|
+
blankTargetRelAttribute: string | null;
|
|
180
|
+
internalComponent: string | ConcreteComponent | Raw<DefineComponent>;
|
|
181
|
+
externalComponent: string | ConcreteComponent | Raw<DefineComponent>;
|
|
182
|
+
}>;
|
|
183
|
+
/**
|
|
184
|
+
* Component to render a Prismic link field.
|
|
185
|
+
*
|
|
186
|
+
* @see Component props {@link PrismicLinkProps}
|
|
187
|
+
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
|
|
188
|
+
*/
|
|
189
|
+
export declare const PrismicLink: new () => {
|
|
190
|
+
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & PrismicLinkProps;
|
|
191
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.js","sources":["../../../src/components/PrismicLink.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponentCustomProps,\n\tdefineComponent,\n\th,\n\tPropType,\n\tVNodeProps,\n\tunref,\n\treactive,\n\tConcreteComponent,\n\tcomputed,\n\tComputedRef,\n} from \"vue\";\n\nimport { asLink, LinkResolverFunction } from \"@prismicio/helpers\";\nimport { LinkField, PrismicDocument } from \"@prismicio/types\";\n\nimport { isInternalURL } from \"../lib/isInternalURL\";\nimport { usePrismic } from \"../usePrismic\";\nimport { VueUseOptions } from \"../types\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { getSlots } from \"../lib/getSlots\";\n\n/**\n * The default component rendered for internal URLs.\n */\nconst defaultInternalComponent = \"router-link\";\n\n/**\n * The default component rendered for external URLs.\n */\nconst defaultExternalComponent = \"a\";\n\n/**\n * The default rel attribute rendered for blank target URLs.\n */\nconst defaultBlankTargetRelAttribute = \"noopener noreferrer\";\n\n/**\n * Props for `<PrismicLink />`.\n */\nexport type PrismicLinkProps = {\n\t/**\n\t * The Prismic link field or document to render.\n\t */\n\tfield: LinkField | PrismicDocument;\n\n\t/**\n\t * A link resolver function used to resolve links when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An explicit `target` attribute to apply to the rendered link.\n\t */\n\ttarget?: string | null;\n\n\t/**\n\t * An explicit `rel` attribute to apply to the rendered link.\n\t */\n\trel?: string | null;\n\n\t/**\n\t * Value of the `rel` attribute to use on links rendered with\n\t * `target=\"_blank\"`.\n\t *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"noopener noreferrer\"` otherwise.\n\t */\n\tblankTargetRelAttribute?: string | null;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * internal links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.\n\t */\n\tinternalComponent?: string | ConcreteComponent;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * external links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"a\"` otherwise.\n\t */\n\texternalComponent?: string | ConcreteComponent;\n};\n\n/**\n * Options for {@link usePrismicLink}.\n */\nexport type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>;\n\n/**\n * Return type of {@link usePrismicLink}.\n */\nexport type UsePrismicLinkReturnType = {\n\t/**\n\t * Suggested component to render for provided link field.\n\t */\n\ttype: ComputedRef<string | ConcreteComponent>;\n\n\t/**\n\t * Resolved anchor `href` value.\n\t */\n\thref: ComputedRef<string>;\n\n\t/**\n\t * Resolved anchor `target` value.\n\t */\n\ttarget: ComputedRef<string | null>;\n\n\t/**\n\t * Resolved anchor `rel` value.\n\t */\n\trel: ComputedRef<string | null>;\n};\n\n/**\n * A low level composable that returns resolved information about a Prismic link\n * field.\n *\n * @param props - {@link UsePrismicLinkOptions}\n *\n * @returns - Resolved link information {@link UsePrismicLinkReturnType}\n */\nexport const usePrismicLink = (\n\tprops: UsePrismicLinkOptions,\n): UsePrismicLinkReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst type = computed(() => {\n\t\tconst internalComponent =\n\t\t\tunref(props.internalComponent) ||\n\t\t\toptions.components?.linkInternalComponent ||\n\t\t\tdefaultInternalComponent;\n\n\t\tconst externalComponent =\n\t\t\tunref(props.externalComponent) ||\n\t\t\toptions.components?.linkExternalComponent ||\n\t\t\tdefaultExternalComponent;\n\n\t\treturn href.value && isInternalURL(href.value) && !target.value\n\t\t\t? internalComponent\n\t\t\t: externalComponent;\n\t});\n\tconst href = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\n\t\treturn asLink(field, linkResolver) ?? \"\";\n\t});\n\tconst target = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst target = unref(props.target);\n\n\t\tif (typeof target !== \"undefined\") {\n\t\t\treturn target;\n\t\t} else {\n\t\t\treturn field && \"target\" in field && field.target ? field.target : null;\n\t\t}\n\t});\n\tconst rel = computed(() => {\n\t\tconst rel = unref(props.rel);\n\n\t\tif (typeof rel !== \"undefined\") {\n\t\t\treturn rel;\n\t\t} else if (target.value === \"_blank\") {\n\t\t\tconst blankTargetRelAttribute = unref(props.blankTargetRelAttribute);\n\n\t\t\tif (typeof blankTargetRelAttribute !== \"undefined\") {\n\t\t\t\treturn blankTargetRelAttribute;\n\t\t\t} else {\n\t\t\t\treturn typeof options.components?.linkBlankTargetRelAttribute !==\n\t\t\t\t\t\"undefined\"\n\t\t\t\t\t? options.components.linkBlankTargetRelAttribute\n\t\t\t\t\t: defaultBlankTargetRelAttribute;\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t});\n\n\treturn {\n\t\ttype,\n\t\thref,\n\t\ttarget,\n\t\trel,\n\t};\n};\n\n/**\n * `<PrismicLink />` implementation.\n *\n * @internal\n */\nexport const PrismicLinkImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicLink\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Object as PropType<LinkField | PrismicDocument>,\n\t\t\trequired: true,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\ttarget: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\trel: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tblankTargetRelAttribute: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tinternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\texternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props, { slots }) {\n\t\t// Prevent fatal if user didn't check for field, throws `Invalid prop` warn\n\t\tif (!props.field) {\n\t\t\treturn () => null;\n\t\t}\n\n\t\tconst { type, href, target, rel } = usePrismicLink(props);\n\n\t\treturn () => {\n\t\t\tconst parent =\n\t\t\t\ttype.value === \"a\" ? \"a\" : simplyResolveComponent(type.value);\n\t\t\tconst computedSlots = getSlots(\n\t\t\t\tparent,\n\t\t\t\tslots,\n\t\t\t\treactive({ href: href.value }),\n\t\t\t);\n\n\t\t\tif (typeof parent === \"string\") {\n\t\t\t\t// Fitting anchor tag interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ href: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Fitting Vue Router Link interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ to: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic link field.\n *\n * @see Component props {@link PrismicLinkProps}\n * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}\n */\nexport const PrismicLink = PrismicLinkImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicLinkProps;\n\t};\n};\n"],"names":["target","rel"],"mappings":";;;;;;AA0BA,MAAM,2BAA2B;AAKjC,MAAM,2BAA2B;AAKjC,MAAM,iCAAiC;AA0G1B,MAAA,iBAAiB,CAC7B,UAC6B;AACvB,QAAA,EAAE,YAAY;AAEd,QAAA,OAAO,SAAS,MAAK;;AAC1B,UAAM,oBACL,MAAM,MAAM,iBAAiB,OAC7B,aAAQ,eAAR,mBAAoB,0BACpB;AAED,UAAM,oBACL,MAAM,MAAM,iBAAiB,OAC7B,aAAQ,eAAR,mBAAoB,0BACpB;AAEM,WAAA,KAAK,SAAS,cAAc,KAAK,KAAK,KAA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AAK;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,yBAAyB;AAAA,MACxB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,mBAAmB;AAAA,MAClB,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,mBAAmB;AAAA,MAClB,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,EACD;AAAA,EACD,MAAM,OAAO,EAAE,SAAO;AAEjB,QAAA,CAAC,MAAM,OAAO;AACjB,aAAO,MAAM;AAAA,IACb;AAED,UAAM,EAAE,MAAM,MAAM,QAAQ,QAAQ,eAAe,KAAK;AAExD,WAAO,MAAK;AACX,YAAM,SACL,KAAK,UAAU,MAAM,MAAM,uBAAuB,KAAK,KAAK;AACvD,YAAA,gBAAgB,SACrB,QACA,OACA,SAAS,EAAE,MAAM,KAAK,MAAO,CAAA,CAAC;AAG3B,UAAA,OAAO,WAAW,UAAU;AAE/B,eAAO,EACN,QACA,EAAE,MAAM,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACnD,aAAa;AAAA,MAAA,OAER;AAEN,eAAO,EACN,QACA,EAAE,IAAI,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACjD,aAAa;AAAA,MAEd;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,cAAc;"}
|
|
1
|
+
{"version":3,"file":"PrismicLink.js","sources":["../../../src/components/PrismicLink.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponentCustomProps,\n\tdefineComponent,\n\th,\n\tPropType,\n\tVNodeProps,\n\tunref,\n\treactive,\n\tConcreteComponent,\n\tcomputed,\n\tComputedRef,\n\tRaw,\n\tDefineComponent,\n} from \"vue\";\n\nimport { asLink, LinkResolverFunction } from \"@prismicio/helpers\";\nimport { LinkField, PrismicDocument } from \"@prismicio/types\";\n\nimport { isInternalURL } from \"../lib/isInternalURL\";\nimport { usePrismic } from \"../usePrismic\";\nimport { VueUseOptions } from \"../types\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { getSlots } from \"../lib/getSlots\";\n\n/**\n * The default component rendered for internal URLs.\n */\nconst defaultInternalComponent = \"router-link\";\n\n/**\n * The default component rendered for external URLs.\n */\nconst defaultExternalComponent = \"a\";\n\n/**\n * The default rel attribute rendered for blank target URLs.\n */\nconst defaultBlankTargetRelAttribute = \"noopener noreferrer\";\n\n/**\n * Props for `<PrismicLink />`.\n */\nexport type PrismicLinkProps = {\n\t/**\n\t * The Prismic link field or document to render.\n\t */\n\tfield: LinkField | PrismicDocument;\n\n\t/**\n\t * A link resolver function used to resolve links when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An explicit `target` attribute to apply to the rendered link.\n\t */\n\ttarget?: string | null;\n\n\t/**\n\t * An explicit `rel` attribute to apply to the rendered link.\n\t */\n\trel?: string | null;\n\n\t/**\n\t * Value of the `rel` attribute to use on links rendered with\n\t * `target=\"_blank\"`.\n\t *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"noopener noreferrer\"` otherwise.\n\t */\n\tblankTargetRelAttribute?: string | null;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * internal links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.\n\t */\n\tinternalComponent?: string | ConcreteComponent | Raw<DefineComponent>;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to render\n\t * external links.\n\t *\n\t * @remarks\n\t * HTML tag names will be rendered using the anchor tag interface (`href`,\n\t * `target`, and `rel` attributes).\n\t * @remarks\n\t * Components will be rendered using Vue Router {@link RouterLink} interface\n\t * (`to` props).\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"a\"` otherwise.\n\t */\n\texternalComponent?: string | ConcreteComponent | Raw<DefineComponent>;\n};\n\n/**\n * Options for {@link usePrismicLink}.\n */\nexport type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>;\n\n/**\n * Return type of {@link usePrismicLink}.\n */\nexport type UsePrismicLinkReturnType = {\n\t/**\n\t * Suggested component to render for provided link field.\n\t */\n\ttype: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>>;\n\n\t/**\n\t * Resolved anchor `href` value.\n\t */\n\thref: ComputedRef<string>;\n\n\t/**\n\t * Resolved anchor `target` value.\n\t */\n\ttarget: ComputedRef<string | null>;\n\n\t/**\n\t * Resolved anchor `rel` value.\n\t */\n\trel: ComputedRef<string | null>;\n};\n\n/**\n * A low level composable that returns resolved information about a Prismic link\n * field.\n *\n * @param props - {@link UsePrismicLinkOptions}\n *\n * @returns - Resolved link information {@link UsePrismicLinkReturnType}\n */\nexport const usePrismicLink = (\n\tprops: UsePrismicLinkOptions,\n): UsePrismicLinkReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst type = computed(() => {\n\t\tconst internalComponent =\n\t\t\tunref(props.internalComponent) ||\n\t\t\toptions.components?.linkInternalComponent ||\n\t\t\tdefaultInternalComponent;\n\n\t\tconst externalComponent =\n\t\t\tunref(props.externalComponent) ||\n\t\t\toptions.components?.linkExternalComponent ||\n\t\t\tdefaultExternalComponent;\n\n\t\treturn href.value && isInternalURL(href.value) && !target.value\n\t\t\t? internalComponent\n\t\t\t: externalComponent;\n\t});\n\tconst href = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\n\t\treturn asLink(field, linkResolver) ?? \"\";\n\t});\n\tconst target = computed(() => {\n\t\tconst field = unref(props.field);\n\t\tconst target = unref(props.target);\n\n\t\tif (typeof target !== \"undefined\") {\n\t\t\treturn target;\n\t\t} else {\n\t\t\treturn field && \"target\" in field && field.target ? field.target : null;\n\t\t}\n\t});\n\tconst rel = computed(() => {\n\t\tconst rel = unref(props.rel);\n\n\t\tif (typeof rel !== \"undefined\") {\n\t\t\treturn rel;\n\t\t} else if (target.value === \"_blank\") {\n\t\t\tconst blankTargetRelAttribute = unref(props.blankTargetRelAttribute);\n\n\t\t\tif (typeof blankTargetRelAttribute !== \"undefined\") {\n\t\t\t\treturn blankTargetRelAttribute;\n\t\t\t} else {\n\t\t\t\treturn typeof options.components?.linkBlankTargetRelAttribute !==\n\t\t\t\t\t\"undefined\"\n\t\t\t\t\t? options.components.linkBlankTargetRelAttribute\n\t\t\t\t\t: defaultBlankTargetRelAttribute;\n\t\t\t}\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t});\n\n\treturn {\n\t\ttype,\n\t\thref,\n\t\ttarget,\n\t\trel,\n\t};\n};\n\n/**\n * `<PrismicLink />` implementation.\n *\n * @internal\n */\nexport const PrismicLinkImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicLink\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Object as PropType<LinkField | PrismicDocument>,\n\t\t\trequired: true,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\ttarget: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\trel: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tblankTargetRelAttribute: {\n\t\t\ttype: String as PropType<string | null>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tinternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<\n\t\t\t\tstring | ConcreteComponent | Raw<DefineComponent>\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\texternalComponent: {\n\t\t\ttype: [String, Object, Function] as PropType<\n\t\t\t\tstring | ConcreteComponent | Raw<DefineComponent>\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props, { slots }) {\n\t\t// Prevent fatal if user didn't check for field, throws `Invalid prop` warn\n\t\tif (!props.field) {\n\t\t\treturn () => null;\n\t\t}\n\n\t\tconst { type, href, target, rel } = usePrismicLink(props);\n\n\t\treturn () => {\n\t\t\tconst parent =\n\t\t\t\ttype.value === \"a\" ? \"a\" : simplyResolveComponent(type.value);\n\t\t\tconst computedSlots = getSlots(\n\t\t\t\tparent,\n\t\t\t\tslots,\n\t\t\t\treactive({ href: href.value }),\n\t\t\t);\n\n\t\t\tif (typeof parent === \"string\") {\n\t\t\t\t// Fitting anchor tag interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ href: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Fitting Vue Router Link interface\n\t\t\t\treturn h(\n\t\t\t\t\tparent,\n\t\t\t\t\t{ to: href.value, target: target.value, rel: rel.value },\n\t\t\t\t\tcomputedSlots,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic link field.\n *\n * @see Component props {@link PrismicLinkProps}\n * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}\n */\nexport const PrismicLink = PrismicLinkImpl as unknown as {\n\tn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AAM,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACnD,aAAa;AAAA,MAAA,OAER;AAEN,eAAO,EACN,QACA,EAAE,IAAI,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAK,IAAI,SACjD,aAAa;AAAA,MAEd;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,cAAc;"}
|
|
@@ -15,8 +15,8 @@ const usePrismicRichText = (props) => {
|
|
|
15
15
|
return vue.unref(props.fallback) ?? "";
|
|
16
16
|
}
|
|
17
17
|
const linkResolver = vue.unref(props.linkResolver) ?? options.linkResolver;
|
|
18
|
-
const
|
|
19
|
-
return helpers.asHTML(vue.unref(field), linkResolver,
|
|
18
|
+
const serializer = vue.unref(props.serializer) ?? vue.unref(props.htmlSerializer) ?? options.richTextSerializer ?? options.htmlSerializer;
|
|
19
|
+
return helpers.asHTML(vue.unref(field), linkResolver, serializer);
|
|
20
20
|
});
|
|
21
21
|
return {
|
|
22
22
|
html
|
|
@@ -35,6 +35,11 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
35
35
|
default: void 0,
|
|
36
36
|
required: false
|
|
37
37
|
},
|
|
38
|
+
serializer: {
|
|
39
|
+
type: [Function, Object],
|
|
40
|
+
default: void 0,
|
|
41
|
+
required: false
|
|
42
|
+
},
|
|
38
43
|
htmlSerializer: {
|
|
39
44
|
type: [Function, Object],
|
|
40
45
|
default: void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichText.cjs","sources":["../../../src/components/PrismicRichText.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponent,\n\tComponentCustomProps,\n\tcomputed,\n\tComputedRef,\n\tConcreteComponent,\n\tdefineComponent,\n\th,\n\tinject,\n\tnextTick,\n\tonBeforeUnmount,\n\tPropType,\n\tref,\n\tunref,\n\tVNodeProps,\n\twatch,\n} from \"vue\";\nimport { routerKey } from \"vue-router\";\n\nimport {\n\tasHTML,\n\tHTMLFunctionSerializer,\n\tHTMLMapSerializer,\n\tisFilled,\n\tLinkResolverFunction,\n} from \"@prismicio/helpers\";\nimport { RichTextField } from \"@prismicio/types\";\n\nimport { VueUseOptions } from \"../types\";\nimport { usePrismic } from \"../usePrismic\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered to wrap the HTML output.\n */\nconst defaultWrapper = \"div\";\n\n/**\n * Props for `<PrismicRichText />`.\n */\nexport type PrismicRichTextProps = {\n\t/**\n\t * The Prismic rich text or title field to render.\n\t */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * A link resolver function used to resolve link when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An HTML serializer to customize the way rich text fields are rendered.\n\t *\n\t * @defaultValue The HTML serializer provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}\n\t */\n\thtmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to wrap the\n\t * output.\n\t *\n\t * @defaultValue `\"div\"`\n\t */\n\twrapper?: string | ConcreteComponent;\n\n\t/**\n\t * The HTML value to be rendered when the field is empty. If a fallback is not\n\t * given, `\"\"` (nothing) will be rendered.\n\t */\n\tfallback?: string;\n};\n\n/**\n * Options for {@link usePrismicRichText}.\n */\nexport type UsePrismicRichTextOptions = VueUseOptions<\n\tOmit<PrismicRichTextProps, \"wrapper\">\n>;\n\n/**\n * Return type of {@link usePrismicRichText}.\n */\nexport type UsePrismicRichTextReturnType = {\n\t/**\n\t * Serialized rich text field as HTML.\n\t */\n\thtml: ComputedRef<string>;\n};\n\n/**\n * A low level composable that returns a serialized rich text field as HTML.\n *\n * @param props - {@link UsePrismicRichTextOptions}\n *\n * @returns - Serialized rich text field as HTML\n * {@link UsePrismicRichTextReturnType}\n */\nexport const usePrismicRichText = (\n\tprops: UsePrismicRichTextOptions,\n): UsePrismicRichTextReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst html = computed(() => {\n\t\tconst field = unref(props.field);\n\n\t\tif (!isFilled.richText(field)) {\n\t\t\treturn unref(props.fallback) ?? \"\";\n\t\t}\n\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\t\tconst htmlSerializer =\n\t\t\tunref(props.htmlSerializer) ?? options.htmlSerializer;\n\n\t\treturn asHTML(unref(field), linkResolver, htmlSerializer);\n\t});\n\n\treturn {\n\t\thtml,\n\t};\n};\n\n/**\n * `<PrismicRichText />` implementation.\n *\n * @internal\n */\nexport const PrismicRichTextImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicRichText\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Array as unknown as PropType<RichTextField | null | undefined>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\thtmlSerializer: {\n\t\t\ttype: [Function, Object] as PropType<\n\t\t\t\tHTMLFunctionSerializer | HTMLMapSerializer\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\twrapper: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tfallback: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props) {\n\t\tconst { html } = usePrismicRichText(props);\n\n\t\tconst root = ref<HTMLElement | Comment | Component | null>(null);\n\n\t\tconst maybeRouter = inject(routerKey, null);\n\t\tif (maybeRouter) {\n\t\t\ttype InternalLink = {\n\t\t\t\telement: HTMLAnchorElement;\n\t\t\t\tlistener: EventListener;\n\t\t\t};\n\t\t\tlet links: InternalLink[] = [];\n\n\t\t\tconst navigate: EventListener = function (\n\t\t\t\tthis: { href: string },\n\t\t\t\tevent: Event,\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tmaybeRouter.push(this.href);\n\t\t\t};\n\n\t\t\tconst addListeners = () => {\n\t\t\t\tconst node: HTMLElement | Comment | null =\n\t\t\t\t\troot.value && \"$el\" in root.value ? root.value.$el : root.value;\n\t\t\t\tif (node && \"querySelectorAll\" in node) {\n\t\t\t\t\t// Get all internal link tags and add listeners on them\n\t\t\t\t\tlinks = Array.from(node.querySelectorAll(\"a\"))\n\t\t\t\t\t\t.map((element) => {\n\t\t\t\t\t\t\tconst href = element.getAttribute(\"href\");\n\n\t\t\t\t\t\t\tif (href && isInternalURL(href)) {\n\t\t\t\t\t\t\t\tconst listener = navigate.bind({ href });\n\t\t\t\t\t\t\t\telement.addEventListener(\"click\", listener);\n\n\t\t\t\t\t\t\t\treturn { element, listener };\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter((link): link is InternalLink => link as boolean);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst removeListeners = () => {\n\t\t\t\tlinks.forEach(({ element, listener }) =>\n\t\t\t\t\telement.removeEventListener(\"click\", listener),\n\t\t\t\t);\n\t\t\t\tlinks = [];\n\t\t\t};\n\n\t\t\twatch(\n\t\t\t\thtml,\n\t\t\t\t() => {\n\t\t\t\t\tremoveListeners();\n\t\t\t\t\tnextTick(addListeners);\n\t\t\t\t},\n\t\t\t\t{ immediate: true },\n\t\t\t);\n\n\t\t\tonBeforeUnmount(() => {\n\t\t\t\tremoveListeners();\n\t\t\t});\n\t\t}\n\n\t\treturn () => {\n\t\t\treturn h(simplyResolveComponent(props.wrapper || defaultWrapper), {\n\t\t\t\tinnerHTML: html.value,\n\t\t\t\tref: root,\n\t\t\t});\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic rich text field as HTML.\n *\n * @see Component props {@link PrismicRichTextProps}\n * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}\n */\nexport const PrismicRichText = PrismicRichTextImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicRichTextProps;\n\t};\n};\n"],"names":["usePrismic","computed","unref","isFilled","asHTML","defineComponent","ref","inject","routerKey","isInternalURL","watch","nextTick","onBeforeUnmount","h","simplyResolveComponent"],"mappings":";;;;;;;;AAqCA,MAAM,iBAAiB;AAsEV,MAAA,qBAAqB,CACjC,UACiC;AAC3B,QAAA,EAAE,YAAYA,WAAAA;AAEd,QAAA,OAAOC,IAAAA,SAAS,MAAK;AACpB,UAAA,QAAQC,IAAAA,MAAM,MAAM,KAAK;AAE/B,QAAI,CAACC,QAAA,SAAS,SAAS,KAAK,GAAG;AACvB,aAAAD,UAAM,MAAM,QAAQ,KAAK;AAAA,IAChC;AAED,UAAM,eAAeA,IAAAA,MAAM,MAAM,YAAY,KAAK,QAAQ;AAC1D,UAAM,iBACLA,IAAAA,MAAM,MAAM,cAAc,KAAK,QAAQ;AAExC,WAAOE,QAAAA,OAAOF,IAAAA,MAAM,KAAK,GAAG,cAAc,cAAc;AAAA,EAAA,CACxD;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;AAOO,MAAM,sBAAoDG,oBAAAA,gBAAA;AAAA,EAChE,MAAM;AAAA,EACN,OAAO;AAAA,IACN,OAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;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S,SAAA,MACzB,QAAQ,oBAAoB,SAAS,QAAQ,CAAC;AAE/C,gBAAQ,CAAA;AAAA;AAGTC,UAAA,MACC,MACA,MAAK;;AAEJC,YAAA,SAAS,YAAY;AAAA,MAAA,GAEtB,EAAE,WAAW,KAAA,CAAM;AAGpBC,UAAAA,gBAAgB,MAAK;;OAEpB;AAAA,IACD;AAED,WAAO,MAAK;AACX,aAAOC,IAAE,EAAAC,uBAAA,uBAAuB,MAAM,WAAW,cAAc,GAAG;AAAA,QACjE,WAAW,KAAK;AAAA,QAChB,KAAK;AAAA,MAAA,CACL;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,kBAAkB;;;;"}
|
|
1
|
+
{"version":3,"file":"PrismicRichText.cjs","sources":["../../../src/components/PrismicRichText.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponent,\n\tComponentCustomProps,\n\tcomputed,\n\tComputedRef,\n\tConcreteComponent,\n\tDefineComponent,\n\tdefineComponent,\n\th,\n\tinject,\n\tnextTick,\n\tonBeforeUnmount,\n\tPropType,\n\tRaw,\n\tref,\n\tunref,\n\tVNodeProps,\n\twatch,\n} from \"vue\";\nimport { routerKey } from \"vue-router\";\n\nimport {\n\tasHTML,\n\tHTMLFunctionSerializer,\n\tHTMLMapSerializer,\n\tisFilled,\n\tLinkResolverFunction,\n} from \"@prismicio/helpers\";\nimport { RichTextField } from \"@prismicio/types\";\n\nimport { VueUseOptions } from \"../types\";\nimport { usePrismic } from \"../usePrismic\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered to wrap the HTML output.\n */\nconst defaultWrapper = \"div\";\n\n/**\n * Props for `<PrismicRichText />`.\n */\nexport type PrismicRichTextProps = {\n\t/**\n\t * The Prismic rich text or title field to render.\n\t */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * A link resolver function used to resolve link when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An HTML serializer to customize the way rich text fields are rendered.\n\t *\n\t * @defaultValue The HTML serializer provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}\n\t */\n\tserializer?: HTMLFunctionSerializer | HTMLMapSerializer;\n\n\t/**\n\t * An HTML serializer to customize the way rich text fields are rendered.\n\t *\n\t * @deprecated Use `serializer` instead.\n\t *\n\t * @defaultValue The HTML serializer provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}\n\t */\n\thtmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to wrap the\n\t * output.\n\t *\n\t * @defaultValue `\"div\"`\n\t */\n\twrapper?: string | ConcreteComponent | Raw<DefineComponent>;\n\n\t/**\n\t * The HTML value to be rendered when the field is empty. If a fallback is not\n\t * given, `\"\"` (nothing) will be rendered.\n\t */\n\tfallback?: string;\n};\n\n/**\n * Options for {@link usePrismicRichText}.\n */\nexport type UsePrismicRichTextOptions = VueUseOptions<\n\tOmit<PrismicRichTextProps, \"wrapper\">\n>;\n\n/**\n * Return type of {@link usePrismicRichText}.\n */\nexport type UsePrismicRichTextReturnType = {\n\t/**\n\t * Serialized rich text field as HTML.\n\t */\n\thtml: ComputedRef<string>;\n};\n\n/**\n * A low level composable that returns a serialized rich text field as HTML.\n *\n * @param props - {@link UsePrismicRichTextOptions}\n *\n * @returns - Serialized rich text field as HTML\n * {@link UsePrismicRichTextReturnType}\n */\nexport const usePrismicRichText = (\n\tprops: UsePrismicRichTextOptions,\n): UsePrismicRichTextReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst html = computed(() => {\n\t\tconst field = unref(props.field);\n\n\t\tif (!isFilled.richText(field)) {\n\t\t\treturn unref(props.fallback) ?? \"\";\n\t\t}\n\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\t\tconst serializer =\n\t\t\tunref(props.serializer) ??\n\t\t\tunref(props.htmlSerializer) ??\n\t\t\toptions.richTextSerializer ??\n\t\t\toptions.htmlSerializer;\n\n\t\treturn asHTML(unref(field), linkResolver, serializer);\n\t});\n\n\treturn {\n\t\thtml,\n\t};\n};\n\n/**\n * `<PrismicRichText />` implementation.\n *\n * @internal\n */\nexport const PrismicRichTextImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicRichText\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Array as unknown as PropType<RichTextField | null | undefined>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tserializer: {\n\t\t\ttype: [Function, Object] as PropType<\n\t\t\t\tHTMLFunctionSerializer | HTMLMapSerializer\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\thtmlSerializer: {\n\t\t\ttype: [Function, Object] as PropType<\n\t\t\t\tHTMLFunctionSerializer | HTMLMapSerializer\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\twrapper: {\n\t\t\ttype: [String, Object, Function] as PropType<\n\t\t\t\tstring | ConcreteComponent | Raw<DefineComponent>\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tfallback: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props) {\n\t\tconst { html } = usePrismicRichText(props);\n\n\t\tconst root = ref<HTMLElement | Comment | Component | null>(null);\n\n\t\tconst maybeRouter = inject(routerKey, null);\n\t\tif (maybeRouter) {\n\t\t\ttype InternalLink = {\n\t\t\t\telement: HTMLAnchorElement;\n\t\t\t\tlistener: EventListener;\n\t\t\t};\n\t\t\tlet links: InternalLink[] = [];\n\n\t\t\tconst navigate: EventListener = function (\n\t\t\t\tthis: { href: string },\n\t\t\t\tevent: Event,\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tmaybeRouter.push(this.href);\n\t\t\t};\n\n\t\t\tconst addListeners = () => {\n\t\t\t\tconst node: HTMLElement | Comment | null =\n\t\t\t\t\troot.value && \"$el\" in root.value ? root.value.$el : root.value;\n\t\t\t\tif (node && \"querySelectorAll\" in node) {\n\t\t\t\t\t// Get all internal link tags and add listeners on them\n\t\t\t\t\tlinks = Array.from(node.querySelectorAll(\"a\"))\n\t\t\t\t\t\t.map((element) => {\n\t\t\t\t\t\t\tconst href = element.getAttribute(\"href\");\n\n\t\t\t\t\t\t\tif (href && isInternalURL(href)) {\n\t\t\t\t\t\t\t\tconst listener = navigate.bind({ href });\n\t\t\t\t\t\t\t\telement.addEventListener(\"click\", listener);\n\n\t\t\t\t\t\t\t\treturn { element, listener };\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter((link): link is InternalLink => link as boolean);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst removeListeners = () => {\n\t\t\t\tlinks.forEach(({ element, listener }) =>\n\t\t\t\t\telement.removeEventListener(\"click\", listener),\n\t\t\t\t);\n\t\t\t\tlinks = [];\n\t\t\t};\n\n\t\t\twatch(\n\t\t\t\thtml,\n\t\t\t\t() => {\n\t\t\t\t\tremoveListeners();\n\t\t\t\t\tnextTick(addListeners);\n\t\t\t\t},\n\t\t\t\t{ immediate: true },\n\t\t\t);\n\n\t\t\tonBeforeUnmount(() => {\n\t\t\t\tremoveListeners();\n\t\t\t});\n\t\t}\n\n\t\treturn () => {\n\t\t\treturn h(simplyResolveComponent(props.wrapper || defaultWrapper), {\n\t\t\t\tinnerHTML: html.value,\n\t\t\t\tref: root,\n\t\t\t});\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic rich text field as HTML.\n *\n * @see Component props {@link PrismicRichTextProps}\n * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}\n */\nexport const PrismicRichText = PrismicRichTextImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicRichTextProps;\n\t};\n};\n"],"names":["usePrismic","computed","unref","isFilled","asHTML","defineComponent","ref","inject","routerKey","isInternalURL","watch","nextTick","onBeforeUnmount","h","simplyResolveComponent"],"mappings":";;;;;;;;AAuCA,MAAM,iBAAiB;AAiFV,MAAA,qBAAqB,CACjC,UACiC;AAC3B,QAAA,EAAE,YAAYA,WAAAA;AAEd,QAAA,OAAOC,IAAAA,SAAS,MAAK;AACpB,UAAA,QAAQC,IAAAA,MAAM,MAAM,KAAK;AAE/B,QAAI,CAACC,QAAA,SAAS,SAAS,KAAK,GAAG;AACvB,aAAAD,UAAM,MAAM,QAAQ,KAAK;AAAA,IAChC;AAED,UAAM,eAAeA,IAAAA,MAAM,MAAM,YAAY,KAAK,QAAQ;AACpD,UAAA,aACLA,IAAM,MAAA,MAAM,UAAU,KACtBA,IAAM,MAAA,MAAM,cAAc,KAC1B,QAAQ,sBACR,QAAQ;AAET,WAAOE,QAAAA,OAAOF,IAAAA,MAAM,KAAK,GAAG,cAAc,UAAU;AAAA,EAAA,CACpD;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;AAOO,MAAM,sBAAoDG,oBAAAA,gBAAA;AAAA,EAChE,MAAM;AAAA,EACN,OAAO;AAAA,IACN,OAAO;AAAA,MACN,MAAM;AAAA,MACN,S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