@prismicio/vue 4.2.3 → 5.0.0-alpha.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.
Files changed (245) hide show
  1. package/README.md +4 -4
  2. package/dist/PrismicEmbed.vue.cjs +25 -0
  3. package/dist/PrismicEmbed.vue.cjs.map +1 -0
  4. package/dist/PrismicEmbed.vue.d.ts +19 -0
  5. package/dist/PrismicEmbed.vue.js +26 -0
  6. package/dist/PrismicEmbed.vue.js.map +1 -0
  7. package/dist/PrismicEmbed.vue2.cjs +4 -0
  8. package/dist/PrismicEmbed.vue2.cjs.map +1 -0
  9. package/dist/PrismicEmbed.vue2.js +5 -0
  10. package/dist/PrismicEmbed.vue2.js.map +1 -0
  11. package/dist/PrismicImage.vue.cjs +84 -0
  12. package/dist/PrismicImage.vue.cjs.map +1 -0
  13. package/dist/PrismicImage.vue.d.ts +224 -0
  14. package/dist/PrismicImage.vue.js +85 -0
  15. package/dist/PrismicImage.vue.js.map +1 -0
  16. package/dist/PrismicImage.vue2.cjs +4 -0
  17. package/dist/PrismicImage.vue2.cjs.map +1 -0
  18. package/dist/PrismicImage.vue2.js +5 -0
  19. package/dist/PrismicImage.vue2.js.map +1 -0
  20. package/dist/PrismicLink.vue.cjs +100 -0
  21. package/dist/PrismicLink.vue.cjs.map +1 -0
  22. package/dist/PrismicLink.vue.d.ts +278 -0
  23. package/dist/PrismicLink.vue.js +101 -0
  24. package/dist/PrismicLink.vue.js.map +1 -0
  25. package/dist/PrismicLink.vue2.cjs +4 -0
  26. package/dist/PrismicLink.vue2.cjs.map +1 -0
  27. package/dist/PrismicLink.vue2.js +5 -0
  28. package/dist/PrismicLink.vue2.js.map +1 -0
  29. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue.cjs +90 -0
  30. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue.cjs.map +1 -0
  31. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue.d.ts +7 -0
  32. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue.js +91 -0
  33. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue.js.map +1 -0
  34. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue2.cjs +4 -0
  35. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue2.cjs.map +1 -0
  36. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue2.js +5 -0
  37. package/dist/PrismicRichText/DeprecatedPrismicRichText.vue2.js.map +1 -0
  38. package/dist/PrismicRichText/PrismicRichText.vue.cjs +85 -0
  39. package/dist/PrismicRichText/PrismicRichText.vue.cjs.map +1 -0
  40. package/dist/PrismicRichText/PrismicRichText.vue.d.ts +57 -0
  41. package/dist/PrismicRichText/PrismicRichText.vue.js +86 -0
  42. package/dist/PrismicRichText/PrismicRichText.vue.js.map +1 -0
  43. package/dist/PrismicRichText/PrismicRichText.vue2.cjs +4 -0
  44. package/dist/PrismicRichText/PrismicRichText.vue2.cjs.map +1 -0
  45. package/dist/PrismicRichText/PrismicRichText.vue2.js +5 -0
  46. package/dist/PrismicRichText/PrismicRichText.vue2.js.map +1 -0
  47. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue.cjs +133 -0
  48. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue.cjs.map +1 -0
  49. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue.d.ts +37 -0
  50. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue.js +134 -0
  51. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue.js.map +1 -0
  52. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue2.cjs +4 -0
  53. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue2.cjs.map +1 -0
  54. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue2.js +5 -0
  55. package/dist/PrismicRichText/PrismicRichTextDefaultComponent.vue2.js.map +1 -0
  56. package/dist/PrismicRichText/PrismicRichTextSerialize.vue.cjs +47 -0
  57. package/dist/PrismicRichText/PrismicRichTextSerialize.vue.cjs.map +1 -0
  58. package/dist/PrismicRichText/PrismicRichTextSerialize.vue.d.ts +10 -0
  59. package/dist/PrismicRichText/PrismicRichTextSerialize.vue.js +48 -0
  60. package/dist/PrismicRichText/PrismicRichTextSerialize.vue.js.map +1 -0
  61. package/dist/PrismicRichText/PrismicRichTextSerialize.vue2.cjs +4 -0
  62. package/dist/PrismicRichText/PrismicRichTextSerialize.vue2.cjs.map +1 -0
  63. package/dist/PrismicRichText/PrismicRichTextSerialize.vue2.js +5 -0
  64. package/dist/PrismicRichText/PrismicRichTextSerialize.vue2.js.map +1 -0
  65. package/dist/PrismicRichText/getRichTextComponentProps.cjs +10 -0
  66. package/dist/PrismicRichText/getRichTextComponentProps.cjs.map +1 -0
  67. package/dist/PrismicRichText/getRichTextComponentProps.d.ts +49 -0
  68. package/dist/PrismicRichText/getRichTextComponentProps.js +10 -0
  69. package/dist/PrismicRichText/getRichTextComponentProps.js.map +1 -0
  70. package/dist/PrismicRichText/index.d.ts +2 -0
  71. package/dist/PrismicRichText/types.d.ts +22 -0
  72. package/dist/PrismicText.vue.cjs +43 -0
  73. package/dist/PrismicText.vue.cjs.map +1 -0
  74. package/dist/PrismicText.vue.d.ts +31 -0
  75. package/dist/PrismicText.vue.js +44 -0
  76. package/dist/PrismicText.vue.js.map +1 -0
  77. package/dist/PrismicText.vue2.cjs +4 -0
  78. package/dist/PrismicText.vue2.cjs.map +1 -0
  79. package/dist/PrismicText.vue2.js +5 -0
  80. package/dist/PrismicText.vue2.js.map +1 -0
  81. package/dist/SliceZone/SliceZone.vue.cjs +63 -0
  82. package/dist/SliceZone/SliceZone.vue.cjs.map +1 -0
  83. package/dist/SliceZone/SliceZone.vue.d.ts +40 -0
  84. package/dist/SliceZone/SliceZone.vue.js +64 -0
  85. package/dist/SliceZone/SliceZone.vue.js.map +1 -0
  86. package/dist/SliceZone/SliceZone.vue2.cjs +4 -0
  87. package/dist/SliceZone/SliceZone.vue2.cjs.map +1 -0
  88. package/dist/SliceZone/SliceZone.vue2.js +5 -0
  89. package/dist/SliceZone/SliceZone.vue2.js.map +1 -0
  90. package/dist/SliceZone/TODOSliceComponent.cjs +29 -0
  91. package/dist/SliceZone/TODOSliceComponent.cjs.map +1 -0
  92. package/dist/SliceZone/TODOSliceComponent.d.ts +9 -0
  93. package/dist/SliceZone/TODOSliceComponent.js +29 -0
  94. package/dist/SliceZone/TODOSliceComponent.js.map +1 -0
  95. package/dist/SliceZone/defineSliceZoneComponents.cjs +14 -0
  96. package/dist/SliceZone/defineSliceZoneComponents.cjs.map +1 -0
  97. package/dist/SliceZone/defineSliceZoneComponents.d.ts +36 -0
  98. package/dist/SliceZone/defineSliceZoneComponents.js +14 -0
  99. package/dist/SliceZone/defineSliceZoneComponents.js.map +1 -0
  100. package/dist/SliceZone/getSliceComponentProps.cjs +22 -0
  101. package/dist/SliceZone/getSliceComponentProps.cjs.map +1 -0
  102. package/dist/SliceZone/getSliceComponentProps.d.ts +66 -0
  103. package/dist/SliceZone/getSliceComponentProps.js +22 -0
  104. package/dist/SliceZone/getSliceComponentProps.js.map +1 -0
  105. package/dist/SliceZone/index.d.ts +4 -0
  106. package/dist/SliceZone/types.d.ts +97 -0
  107. package/dist/createPrismic.cjs +17 -50
  108. package/dist/createPrismic.cjs.map +1 -1
  109. package/dist/createPrismic.d.ts +10 -0
  110. package/dist/createPrismic.js +16 -27
  111. package/dist/createPrismic.js.map +1 -1
  112. package/dist/index.cjs +21 -40
  113. package/dist/index.cjs.map +1 -1
  114. package/dist/index.d.ts +19 -9
  115. package/dist/index.js +19 -38
  116. package/dist/index.js.map +1 -1
  117. package/dist/lib/Wrapper.vue.cjs +20 -0
  118. package/dist/lib/Wrapper.vue.cjs.map +1 -0
  119. package/dist/lib/Wrapper.vue.d.ts +34 -0
  120. package/dist/lib/Wrapper.vue.js +21 -0
  121. package/dist/lib/Wrapper.vue.js.map +1 -0
  122. package/dist/lib/Wrapper.vue2.cjs +4 -0
  123. package/dist/lib/Wrapper.vue2.cjs.map +1 -0
  124. package/dist/lib/Wrapper.vue2.js +5 -0
  125. package/dist/lib/Wrapper.vue2.js.map +1 -0
  126. package/dist/lib/devMsg.cjs +8 -0
  127. package/dist/lib/devMsg.cjs.map +1 -0
  128. package/dist/lib/devMsg.d.ts +16 -0
  129. package/dist/lib/devMsg.js +8 -0
  130. package/dist/lib/devMsg.js.map +1 -0
  131. package/dist/lib/isInternalURL.cjs.map +1 -1
  132. package/dist/lib/isInternalURL.js.map +1 -1
  133. package/dist/package.json.cjs +5 -0
  134. package/dist/package.json.cjs.map +1 -0
  135. package/dist/package.json.js +5 -0
  136. package/dist/package.json.js.map +1 -0
  137. package/dist/types.d.ts +42 -58
  138. package/dist/usePrismic.cjs +3 -2
  139. package/dist/usePrismic.cjs.map +1 -1
  140. package/dist/usePrismic.d.ts +13 -5
  141. package/dist/usePrismic.js +2 -1
  142. package/dist/usePrismic.js.map +1 -1
  143. package/package.json +33 -36
  144. package/src/PrismicEmbed.vue +42 -0
  145. package/src/PrismicImage.vue +160 -0
  146. package/src/PrismicLink.vue +191 -0
  147. package/src/PrismicRichText/DeprecatedPrismicRichText.vue +130 -0
  148. package/src/PrismicRichText/PrismicRichText.vue +157 -0
  149. package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +63 -0
  150. package/src/PrismicRichText/PrismicRichTextSerialize.vue +52 -0
  151. package/src/PrismicRichText/getRichTextComponentProps.ts +63 -0
  152. package/src/PrismicRichText/index.ts +3 -0
  153. package/src/PrismicRichText/types.ts +37 -0
  154. package/src/PrismicText.vue +63 -0
  155. package/src/SliceZone/SliceZone.vue +113 -0
  156. package/src/SliceZone/TODOSliceComponent.ts +49 -0
  157. package/src/SliceZone/defineSliceZoneComponents.ts +67 -0
  158. package/src/SliceZone/getSliceComponentProps.ts +98 -0
  159. package/src/SliceZone/index.ts +13 -0
  160. package/src/SliceZone/types.ts +163 -0
  161. package/src/createPrismic.ts +54 -53
  162. package/src/index.ts +33 -58
  163. package/src/lib/Wrapper.vue +22 -0
  164. package/src/lib/devMsg.ts +20 -0
  165. package/src/lib/isInternalURL.ts +4 -4
  166. package/src/types.ts +91 -109
  167. package/src/usePrismic.ts +16 -9
  168. package/dist/components/PrismicEmbed.cjs +0 -36
  169. package/dist/components/PrismicEmbed.cjs.map +0 -1
  170. package/dist/components/PrismicEmbed.d.ts +0 -59
  171. package/dist/components/PrismicEmbed.js +0 -36
  172. package/dist/components/PrismicEmbed.js.map +0 -1
  173. package/dist/components/PrismicImage.cjs +0 -122
  174. package/dist/components/PrismicImage.cjs.map +0 -1
  175. package/dist/components/PrismicImage.d.ts +0 -163
  176. package/dist/components/PrismicImage.js +0 -122
  177. package/dist/components/PrismicImage.js.map +0 -1
  178. package/dist/components/PrismicLink.cjs +0 -115
  179. package/dist/components/PrismicLink.cjs.map +0 -1
  180. package/dist/components/PrismicLink.d.ts +0 -192
  181. package/dist/components/PrismicLink.js +0 -115
  182. package/dist/components/PrismicLink.js.map +0 -1
  183. package/dist/components/PrismicRichText.cjs +0 -108
  184. package/dist/components/PrismicRichText.cjs.map +0 -1
  185. package/dist/components/PrismicRichText.d.ts +0 -161
  186. package/dist/components/PrismicRichText.js +0 -108
  187. package/dist/components/PrismicRichText.js.map +0 -1
  188. package/dist/components/PrismicText.cjs +0 -57
  189. package/dist/components/PrismicText.cjs.map +0 -1
  190. package/dist/components/PrismicText.d.ts +0 -119
  191. package/dist/components/PrismicText.js +0 -57
  192. package/dist/components/PrismicText.js.map +0 -1
  193. package/dist/components/SliceZone.cjs +0 -156
  194. package/dist/components/SliceZone.cjs.map +0 -1
  195. package/dist/components/SliceZone.d.ts +0 -375
  196. package/dist/components/SliceZone.js +0 -156
  197. package/dist/components/SliceZone.js.map +0 -1
  198. package/dist/components/index.d.ts +0 -12
  199. package/dist/composables.cjs +0 -40
  200. package/dist/composables.cjs.map +0 -1
  201. package/dist/composables.d.ts +0 -384
  202. package/dist/composables.js +0 -40
  203. package/dist/composables.js.map +0 -1
  204. package/dist/globalExtensions.d.ts +0 -11
  205. package/dist/injectionSymbols.cjs +0 -5
  206. package/dist/injectionSymbols.cjs.map +0 -1
  207. package/dist/injectionSymbols.d.ts +0 -9
  208. package/dist/injectionSymbols.js +0 -5
  209. package/dist/injectionSymbols.js.map +0 -1
  210. package/dist/lib/__PRODUCTION__.cjs +0 -8
  211. package/dist/lib/__PRODUCTION__.cjs.map +0 -1
  212. package/dist/lib/__PRODUCTION__.d.ts +0 -7
  213. package/dist/lib/__PRODUCTION__.js +0 -8
  214. package/dist/lib/__PRODUCTION__.js.map +0 -1
  215. package/dist/lib/getSlots.cjs +0 -19
  216. package/dist/lib/getSlots.cjs.map +0 -1
  217. package/dist/lib/getSlots.d.ts +0 -14
  218. package/dist/lib/getSlots.js +0 -19
  219. package/dist/lib/getSlots.js.map +0 -1
  220. package/dist/lib/simplyResolveComponent.cjs +0 -8
  221. package/dist/lib/simplyResolveComponent.cjs.map +0 -1
  222. package/dist/lib/simplyResolveComponent.d.ts +0 -12
  223. package/dist/lib/simplyResolveComponent.js +0 -8
  224. package/dist/lib/simplyResolveComponent.js.map +0 -1
  225. package/dist/useStatefulPrismicClientMethod.cjs +0 -39
  226. package/dist/useStatefulPrismicClientMethod.cjs.map +0 -1
  227. package/dist/useStatefulPrismicClientMethod.d.ts +0 -64
  228. package/dist/useStatefulPrismicClientMethod.js +0 -39
  229. package/dist/useStatefulPrismicClientMethod.js.map +0 -1
  230. package/src/components/PrismicEmbed.ts +0 -91
  231. package/src/components/PrismicImage.ts +0 -309
  232. package/src/components/PrismicLink.ts +0 -313
  233. package/src/components/PrismicRichText.ts +0 -282
  234. package/src/components/PrismicText.ts +0 -167
  235. package/src/components/SliceZone.ts +0 -619
  236. package/src/components/index.ts +0 -46
  237. package/src/composables.ts +0 -474
  238. package/src/globalExtensions.ts +0 -12
  239. package/src/injectionSymbols.ts +0 -17
  240. package/src/lib/__PRODUCTION__.ts +0 -12
  241. package/src/lib/getSlots.ts +0 -34
  242. package/src/lib/simplyResolveComponent.ts +0 -23
  243. package/src/useStatefulPrismicClientMethod.ts +0 -156
  244. package/vetur/attributes.json +0 -113
  245. package/vetur/tags.json +0 -60
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ const vue = require("vue");
3
+ const client = require("@prismicio/client");
4
+ const esmEnv = require("esm-env");
5
+ const devMsg = require("./lib/devMsg.cjs");
6
+ const isInternalURL = require("./lib/isInternalURL.cjs");
7
+ const usePrismic = require("./usePrismic.cjs");
8
+ const defaultInternalComponent = "router-link";
9
+ const defaultExternalComponent = "a";
10
+ const defaultExternalRelAttribute = "noreferrer";
11
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
12
+ ...{ name: "PrismicLink" },
13
+ __name: "PrismicLink",
14
+ props: {
15
+ linkResolver: {},
16
+ rel: { type: [String, Function] },
17
+ internalComponent: {},
18
+ externalComponent: {},
19
+ field: {},
20
+ document: {}
21
+ },
22
+ setup(__props) {
23
+ const props = __props;
24
+ const { options } = usePrismic.usePrismic();
25
+ if (esmEnv.DEV) {
26
+ vue.watchEffect(() => {
27
+ if (props.field) {
28
+ if (!props.field.link_type) {
29
+ console.error(
30
+ `[PrismicLink] This "field" prop value caused an error to be thrown.
31
+ `,
32
+ props.field
33
+ );
34
+ throw new Error(
35
+ `[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg.devMsg(
36
+ "missing-link-properties"
37
+ )}`
38
+ );
39
+ } else if (("text" in props.field ? Object.keys(props.field).length > 2 : Object.keys(props.field).length > 1) && !("url" in props.field || "uid" in props.field || "id" in props.field)) {
40
+ console.warn(
41
+ `[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg.devMsg(
42
+ "missing-link-properties"
43
+ )}`,
44
+ props.field
45
+ );
46
+ }
47
+ } else if (props.document) {
48
+ if (!("url" in props.document || "id" in props.document)) {
49
+ console.warn(
50
+ `[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg.devMsg(
51
+ "missing-link-properties"
52
+ )}`,
53
+ props.document
54
+ );
55
+ }
56
+ }
57
+ });
58
+ }
59
+ const rawAttrs = vue.computed(() => {
60
+ return client.asLinkAttrs(props.field || props.document, {
61
+ linkResolver: props.linkResolver || options.linkResolver,
62
+ rel(args) {
63
+ var _a;
64
+ const maybeRel = props.rel || ((_a = options.components) == null ? void 0 : _a.linkRel);
65
+ if (maybeRel) {
66
+ return typeof maybeRel === "function" ? maybeRel(args) : maybeRel;
67
+ }
68
+ return args.isExternal ? defaultExternalRelAttribute : void 0;
69
+ }
70
+ });
71
+ });
72
+ const component = vue.computed(() => {
73
+ var _a, _b;
74
+ return isInternalURL.isInternalURL(rawAttrs.value.href || "") ? props.internalComponent || ((_a = options.components) == null ? void 0 : _a.linkInternalComponent) || defaultInternalComponent : props.externalComponent || ((_b = options.components) == null ? void 0 : _b.linkExternalComponent) || defaultExternalComponent;
75
+ });
76
+ const attrs = vue.computed(() => {
77
+ return component.value === "a" ? {
78
+ href: rawAttrs.value.href,
79
+ target: rawAttrs.value.target,
80
+ rel: rawAttrs.value.rel
81
+ } : {
82
+ to: rawAttrs.value.href,
83
+ target: rawAttrs.value.target,
84
+ rel: rawAttrs.value.rel
85
+ };
86
+ });
87
+ return (_ctx, _cache) => {
88
+ return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(component.value), vue.normalizeProps(vue.guardReactiveProps(attrs.value)), {
89
+ default: vue.withCtx(() => [
90
+ vue.renderSlot(_ctx.$slots, "default", {}, () => [
91
+ vue.createTextVNode(vue.toDisplayString(props.field && "text" in props.field ? props.field.text : void 0), 1)
92
+ ])
93
+ ]),
94
+ _: 3
95
+ }, 16);
96
+ };
97
+ }
98
+ });
99
+ module.exports = _sfc_main;
100
+ //# sourceMappingURL=PrismicLink.vue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.vue.cjs","sources":["../src/PrismicLink.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { AsLinkAttrsConfig } from \"@prismicio/client\"\nimport {\n\ttype LinkField,\n\ttype LinkResolverFunction,\n\ttype PrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport { computed, watchEffect } from \"vue\"\n\nimport { devMsg } from \"./lib/devMsg\"\nimport { isInternalURL } from \"./lib/isInternalURL\"\n\nimport type { ComponentOrTagName } from \"./types\"\n\nimport { usePrismic } from \"./usePrismic\"\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 external URLs.\n */\nconst defaultExternalRelAttribute = \"noreferrer\"\n\n/**\n * Props for `<PrismicLink />`.\n */\nexport type PrismicLinkProps = {\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 * 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\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"]\n\n\t/**\n\t * An HTML tag name or a component used to render 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 *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.\n\t */\n\tinternalComponent?: ComponentOrTagName\n\n\t/**\n\t * An HTML tag name or a component used to render 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 *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"a\"` otherwise.\n\t */\n\texternalComponent?: ComponentOrTagName\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * The Prismic link field to render.\n\t\t\t */\n\t\t\tfield: LinkField\n\t\t\tdocument?: never\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * The Prismic document to render as a link.\n\t\t\t */\n\t\t\tdocument: PrismicDocument\n\t\t\tfield?: never\n\t }\n)\n\nconst props = defineProps<PrismicLinkProps>()\ndefineOptions({ name: \"PrismicLink\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\twatchEffect(() => {\n\t\tif (props.field) {\n\t\t\tif (!props.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\tprops.field,\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 props.field\n\t\t\t\t\t? Object.keys(props.field).length > 2\n\t\t\t\t\t: Object.keys(props.field).length > 1) &&\n\t\t\t\t!(\"url\" in props.field || \"uid\" in props.field || \"id\" in props.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\tprops.field,\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (props.document) {\n\t\t\tif (!(\"url\" in props.document || \"id\" in props.document)) {\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\tprops.document,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t})\n}\n\nconst rawAttrs = computed(() => {\n\treturn asLinkAttrs(props.field || props.document, {\n\t\tlinkResolver: props.linkResolver || options.linkResolver,\n\t\trel(args) {\n\t\t\tconst maybeRel = props.rel || options.components?.linkRel\n\t\t\tif (maybeRel) {\n\t\t\t\treturn typeof maybeRel === \"function\" ? maybeRel(args) : maybeRel\n\t\t\t}\n\n\t\t\treturn args.isExternal ? defaultExternalRelAttribute : undefined\n\t\t},\n\t})\n})\n\nconst component = computed(() => {\n\treturn isInternalURL(rawAttrs.value.href || \"\")\n\t\t? props.internalComponent ||\n\t\t\t\toptions.components?.linkInternalComponent ||\n\t\t\t\tdefaultInternalComponent\n\t\t: props.externalComponent ||\n\t\t\t\toptions.components?.linkExternalComponent ||\n\t\t\t\tdefaultExternalComponent\n})\n\n// Match Vue Router's `<RouterLink />` interface unless the component is an anchor tag.\nconst attrs = computed(() => {\n\treturn component.value === \"a\"\n\t\t? {\n\t\t\t\thref: rawAttrs.value.href,\n\t\t\t\ttarget: rawAttrs.value.target,\n\t\t\t\trel: rawAttrs.value.rel,\n\t\t\t}\n\t\t: {\n\t\t\t\tto: rawAttrs.value.href,\n\t\t\t\ttarget: rawAttrs.value.target,\n\t\t\t\trel: rawAttrs.value.rel,\n\t\t\t}\n})\n</script>\n\n<template>\n\t<component :is=\"component\" v-bind=\"attrs\">\n\t\t<slot>\n\t\t\t{{ props.field && \"text\" in props.field ? props.field.text : undefined }}\n\t\t</slot>\n\t</component>\n</template>\n"],"names":["usePrismic","DEV","watchEffect","devMsg","computed","asLinkAttrs","isInternalURL"],"mappings":";;;;;;;AAqBA,MAAM,2BAA2B;AAKjC,MAAM,2BAA2B;AAKjC,MAAM,8BAA8B;;;;;;;;;;;;;AAqEpC,UAAM,QAAQ;AAGR,UAAA,EAAE,QAAQ,IAAIA,sBAAW;AAE/B,QAAIC,YAAK;AACRC,UAAAA,YAAY,MAAM;AACjB,YAAI,MAAM,OAAO;AACZ,cAAA,CAAC,MAAM,MAAM,WAAW;AACnB,oBAAA;AAAA,cACP;AAAA;AAAA,cACA,MAAM;AAAA,YACP;AACA,kBAAM,IAAI;AAAA,cACT,8IAA8IC,OAAA;AAAA,gBAC7I;AAAA,cAAA,CACA;AAAA,YACF;AAAA,UACD,YACE,UAAU,MAAM,QACd,OAAO,KAAK,MAAM,KAAK,EAAE,SAAS,IAClC,OAAO,KAAK,MAAM,KAAK,EAAE,SAAS,MACrC,EAAE,SAAS,MAAM,SAAS,SAAS,MAAM,SAAS,QAAQ,MAAM,QAC/D;AACO,oBAAA;AAAA,cACP,uJAAuJA,OAAA;AAAA,gBACtJ;AAAA,cAAA,CACA;AAAA,cACD,MAAM;AAAA,YACP;AAAA,UAAA;AAAA,QACD,WACU,MAAM,UAAU;AAC1B,cAAI,EAAE,SAAS,MAAM,YAAY,QAAQ,MAAM,WAAW;AACjD,oBAAA;AAAA,cACP,0JAA0JA,OAAA;AAAA,gBACzJ;AAAA,cAAA,CACA;AAAA,cACD,MAAM;AAAA,YACP;AAAA,UAAA;AAAA,QACD;AAAA,MACD,CACA;AAAA,IAAA;AAGI,UAAA,WAAWC,IAAAA,SAAS,MAAM;AAC/B,aAAOC,OAAY,YAAA,MAAM,SAAS,MAAM,UAAU;AAAA,QACjD,cAAc,MAAM,gBAAgB,QAAQ;AAAA,QAC5C,IAAI,MAAM;;AACT,gBAAM,WAAW,MAAM,SAAO,aAAQ,eAAR,mBAAoB;AAClD,cAAI,UAAU;AACb,mBAAO,OAAO,aAAa,aAAa,SAAS,IAAI,IAAI;AAAA,UAAA;AAGnD,iBAAA,KAAK,aAAa,8BAA8B;AAAA,QAAA;AAAA,MACxD,CACA;AAAA,IAAA,CACD;AAEK,UAAA,YAAYD,IAAAA,SAAS,MAAM;;AAChC,aAAOE,cAAAA,cAAc,SAAS,MAAM,QAAQ,EAAE,IAC3C,MAAM,uBACN,aAAQ,eAAR,mBAAoB,0BACpB,2BACA,MAAM,uBACN,aAAQ,eAAR,mBAAoB,0BACpB;AAAA,IAAA,CACH;AAGK,UAAA,QAAQF,IAAAA,SAAS,MAAM;AACrB,aAAA,UAAU,UAAU,MACxB;AAAA,QACA,MAAM,SAAS,MAAM;AAAA,QACrB,QAAQ,SAAS,MAAM;AAAA,QACvB,KAAK,SAAS,MAAM;AAAA,MAAA,IAEpB;AAAA,QACA,IAAI,SAAS,MAAM;AAAA,QACnB,QAAQ,SAAS,MAAM;AAAA,QACvB,KAAK,SAAS,MAAM;AAAA,MACrB;AAAA,IAAA,CACF;;;;;;;;;;;;;;"}
@@ -0,0 +1,278 @@
1
+ import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from '@prismicio/client';
2
+ import { ComponentOrTagName } from './types';
3
+ /**
4
+ * Props for `<PrismicLink />`.
5
+ */
6
+ export type PrismicLinkProps = {
7
+ /**
8
+ * A link resolver function used to resolve links when not using the route
9
+ * resolver parameter with `@prismicio/client`.
10
+ *
11
+ * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
12
+ *
13
+ * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
14
+ */
15
+ linkResolver?: LinkResolverFunction;
16
+ /**
17
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
18
+ * the link's URL is external. This prop can be provided a function to use the
19
+ * link's metadata to determine the `rel` value.
20
+ *
21
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured.
22
+ */
23
+ rel?: string | AsLinkAttrsConfig["rel"];
24
+ /**
25
+ * An HTML tag name or a component used to render internal links.
26
+ *
27
+ * @remarks
28
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
29
+ * `target`, and `rel` attributes).
30
+ * @remarks
31
+ * Components will be rendered using Vue Router {@link RouterLink} interface
32
+ * (`to` props).
33
+ *
34
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
35
+ */
36
+ internalComponent?: ComponentOrTagName;
37
+ /**
38
+ * An HTML tag name or a component used to render external links.
39
+ *
40
+ * @remarks
41
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
42
+ * `target`, and `rel` attributes).
43
+ * @remarks
44
+ * Components will be rendered using Vue Router {@link RouterLink} interface
45
+ * (`to` props).
46
+ *
47
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
48
+ */
49
+ externalComponent?: ComponentOrTagName;
50
+ } & ({
51
+ /**
52
+ * The Prismic link field to render.
53
+ */
54
+ field: LinkField;
55
+ document?: never;
56
+ } | {
57
+ /**
58
+ * The Prismic document to render as a link.
59
+ */
60
+ document: PrismicDocument;
61
+ field?: never;
62
+ });
63
+ declare function __VLS_template(): {
64
+ slots: {
65
+ default?(_: {}): any;
66
+ };
67
+ refs: {};
68
+ attrs: Partial<{}>;
69
+ };
70
+ type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
71
+ declare const __VLS_component: import('vue').DefineComponent<({
72
+ /**
73
+ * A link resolver function used to resolve links when not using the route
74
+ * resolver parameter with `@prismicio/client`.
75
+ *
76
+ * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
77
+ *
78
+ * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
79
+ */
80
+ linkResolver?: LinkResolverFunction;
81
+ /**
82
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
83
+ * the link's URL is external. This prop can be provided a function to use the
84
+ * link's metadata to determine the `rel` value.
85
+ *
86
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured.
87
+ */
88
+ rel?: string | AsLinkAttrsConfig["rel"];
89
+ /**
90
+ * An HTML tag name or a component used to render internal links.
91
+ *
92
+ * @remarks
93
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
94
+ * `target`, and `rel` attributes).
95
+ * @remarks
96
+ * Components will be rendered using Vue Router {@link RouterLink} interface
97
+ * (`to` props).
98
+ *
99
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
100
+ */
101
+ internalComponent?: ComponentOrTagName;
102
+ /**
103
+ * An HTML tag name or a component used to render external links.
104
+ *
105
+ * @remarks
106
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
107
+ * `target`, and `rel` attributes).
108
+ * @remarks
109
+ * Components will be rendered using Vue Router {@link RouterLink} interface
110
+ * (`to` props).
111
+ *
112
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
113
+ */
114
+ externalComponent?: ComponentOrTagName;
115
+ } & {
116
+ /**
117
+ * The Prismic link field to render.
118
+ */
119
+ field: LinkField;
120
+ document?: never;
121
+ }) | ({
122
+ /**
123
+ * A link resolver function used to resolve links when not using the route
124
+ * resolver parameter with `@prismicio/client`.
125
+ *
126
+ * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
127
+ *
128
+ * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
129
+ */
130
+ linkResolver?: LinkResolverFunction;
131
+ /**
132
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
133
+ * the link's URL is external. This prop can be provided a function to use the
134
+ * link's metadata to determine the `rel` value.
135
+ *
136
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured.
137
+ */
138
+ rel?: string | AsLinkAttrsConfig["rel"];
139
+ /**
140
+ * An HTML tag name or a component used to render internal links.
141
+ *
142
+ * @remarks
143
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
144
+ * `target`, and `rel` attributes).
145
+ * @remarks
146
+ * Components will be rendered using Vue Router {@link RouterLink} interface
147
+ * (`to` props).
148
+ *
149
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
150
+ */
151
+ internalComponent?: ComponentOrTagName;
152
+ /**
153
+ * An HTML tag name or a component used to render external links.
154
+ *
155
+ * @remarks
156
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
157
+ * `target`, and `rel` attributes).
158
+ * @remarks
159
+ * Components will be rendered using Vue Router {@link RouterLink} interface
160
+ * (`to` props).
161
+ *
162
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
163
+ */
164
+ externalComponent?: ComponentOrTagName;
165
+ } & {
166
+ /**
167
+ * The Prismic document to render as a link.
168
+ */
169
+ document: PrismicDocument;
170
+ field?: never;
171
+ }), {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<({
172
+ /**
173
+ * A link resolver function used to resolve links when not using the route
174
+ * resolver parameter with `@prismicio/client`.
175
+ *
176
+ * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
177
+ *
178
+ * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
179
+ */
180
+ linkResolver?: LinkResolverFunction;
181
+ /**
182
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
183
+ * the link's URL is external. This prop can be provided a function to use the
184
+ * link's metadata to determine the `rel` value.
185
+ *
186
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured.
187
+ */
188
+ rel?: string | AsLinkAttrsConfig["rel"];
189
+ /**
190
+ * An HTML tag name or a component used to render internal links.
191
+ *
192
+ * @remarks
193
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
194
+ * `target`, and `rel` attributes).
195
+ * @remarks
196
+ * Components will be rendered using Vue Router {@link RouterLink} interface
197
+ * (`to` props).
198
+ *
199
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
200
+ */
201
+ internalComponent?: ComponentOrTagName;
202
+ /**
203
+ * An HTML tag name or a component used to render external links.
204
+ *
205
+ * @remarks
206
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
207
+ * `target`, and `rel` attributes).
208
+ * @remarks
209
+ * Components will be rendered using Vue Router {@link RouterLink} interface
210
+ * (`to` props).
211
+ *
212
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
213
+ */
214
+ externalComponent?: ComponentOrTagName;
215
+ } & {
216
+ /**
217
+ * The Prismic link field to render.
218
+ */
219
+ field: LinkField;
220
+ document?: never;
221
+ }) | ({
222
+ /**
223
+ * A link resolver function used to resolve links when not using the route
224
+ * resolver parameter with `@prismicio/client`.
225
+ *
226
+ * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
227
+ *
228
+ * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
229
+ */
230
+ linkResolver?: LinkResolverFunction;
231
+ /**
232
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
233
+ * the link's URL is external. This prop can be provided a function to use the
234
+ * link's metadata to determine the `rel` value.
235
+ *
236
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured.
237
+ */
238
+ rel?: string | AsLinkAttrsConfig["rel"];
239
+ /**
240
+ * An HTML tag name or a component used to render internal links.
241
+ *
242
+ * @remarks
243
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
244
+ * `target`, and `rel` attributes).
245
+ * @remarks
246
+ * Components will be rendered using Vue Router {@link RouterLink} interface
247
+ * (`to` props).
248
+ *
249
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
250
+ */
251
+ internalComponent?: ComponentOrTagName;
252
+ /**
253
+ * An HTML tag name or a component used to render external links.
254
+ *
255
+ * @remarks
256
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
257
+ * `target`, and `rel` attributes).
258
+ * @remarks
259
+ * Components will be rendered using Vue Router {@link RouterLink} interface
260
+ * (`to` props).
261
+ *
262
+ * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
263
+ */
264
+ externalComponent?: ComponentOrTagName;
265
+ } & {
266
+ /**
267
+ * The Prismic document to render as a link.
268
+ */
269
+ document: PrismicDocument;
270
+ field?: never;
271
+ })> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
272
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
273
+ export default _default;
274
+ type __VLS_WithTemplateSlots<T, S> = T & {
275
+ new (): {
276
+ $slots: S;
277
+ };
278
+ };
@@ -0,0 +1,101 @@
1
+ import { defineComponent, watchEffect, computed, openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, withCtx, renderSlot, createTextVNode, toDisplayString } from "vue";
2
+ import { asLinkAttrs } from "@prismicio/client";
3
+ import { DEV } from "esm-env";
4
+ import { devMsg } from "./lib/devMsg.js";
5
+ import { isInternalURL } from "./lib/isInternalURL.js";
6
+ import { usePrismic } from "./usePrismic.js";
7
+ const defaultInternalComponent = "router-link";
8
+ const defaultExternalComponent = "a";
9
+ const defaultExternalRelAttribute = "noreferrer";
10
+ const _sfc_main = /* @__PURE__ */ defineComponent({
11
+ ...{ name: "PrismicLink" },
12
+ __name: "PrismicLink",
13
+ props: {
14
+ linkResolver: {},
15
+ rel: { type: [String, Function] },
16
+ internalComponent: {},
17
+ externalComponent: {},
18
+ field: {},
19
+ document: {}
20
+ },
21
+ setup(__props) {
22
+ const props = __props;
23
+ const { options } = usePrismic();
24
+ if (DEV) {
25
+ watchEffect(() => {
26
+ if (props.field) {
27
+ if (!props.field.link_type) {
28
+ console.error(
29
+ `[PrismicLink] This "field" prop value caused an error to be thrown.
30
+ `,
31
+ props.field
32
+ );
33
+ throw new Error(
34
+ `[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(
35
+ "missing-link-properties"
36
+ )}`
37
+ );
38
+ } else if (("text" in props.field ? Object.keys(props.field).length > 2 : Object.keys(props.field).length > 1) && !("url" in props.field || "uid" in props.field || "id" in props.field)) {
39
+ console.warn(
40
+ `[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(
41
+ "missing-link-properties"
42
+ )}`,
43
+ props.field
44
+ );
45
+ }
46
+ } else if (props.document) {
47
+ if (!("url" in props.document || "id" in props.document)) {
48
+ console.warn(
49
+ `[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(
50
+ "missing-link-properties"
51
+ )}`,
52
+ props.document
53
+ );
54
+ }
55
+ }
56
+ });
57
+ }
58
+ const rawAttrs = computed(() => {
59
+ return asLinkAttrs(props.field || props.document, {
60
+ linkResolver: props.linkResolver || options.linkResolver,
61
+ rel(args) {
62
+ var _a;
63
+ const maybeRel = props.rel || ((_a = options.components) == null ? void 0 : _a.linkRel);
64
+ if (maybeRel) {
65
+ return typeof maybeRel === "function" ? maybeRel(args) : maybeRel;
66
+ }
67
+ return args.isExternal ? defaultExternalRelAttribute : void 0;
68
+ }
69
+ });
70
+ });
71
+ const component = computed(() => {
72
+ var _a, _b;
73
+ return isInternalURL(rawAttrs.value.href || "") ? props.internalComponent || ((_a = options.components) == null ? void 0 : _a.linkInternalComponent) || defaultInternalComponent : props.externalComponent || ((_b = options.components) == null ? void 0 : _b.linkExternalComponent) || defaultExternalComponent;
74
+ });
75
+ const attrs = computed(() => {
76
+ return component.value === "a" ? {
77
+ href: rawAttrs.value.href,
78
+ target: rawAttrs.value.target,
79
+ rel: rawAttrs.value.rel
80
+ } : {
81
+ to: rawAttrs.value.href,
82
+ target: rawAttrs.value.target,
83
+ rel: rawAttrs.value.rel
84
+ };
85
+ });
86
+ return (_ctx, _cache) => {
87
+ return openBlock(), createBlock(resolveDynamicComponent(component.value), normalizeProps(guardReactiveProps(attrs.value)), {
88
+ default: withCtx(() => [
89
+ renderSlot(_ctx.$slots, "default", {}, () => [
90
+ createTextVNode(toDisplayString(props.field && "text" in props.field ? props.field.text : void 0), 1)
91
+ ])
92
+ ]),
93
+ _: 3
94
+ }, 16);
95
+ };
96
+ }
97
+ });
98
+ export {
99
+ _sfc_main as default
100
+ };
101
+ //# sourceMappingURL=PrismicLink.vue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.vue.js","sources":["../src/PrismicLink.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { AsLinkAttrsConfig } from \"@prismicio/client\"\nimport {\n\ttype LinkField,\n\ttype LinkResolverFunction,\n\ttype PrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport { computed, watchEffect } from \"vue\"\n\nimport { devMsg } from \"./lib/devMsg\"\nimport { isInternalURL } from \"./lib/isInternalURL\"\n\nimport type { ComponentOrTagName } from \"./types\"\n\nimport { usePrismic } from \"./usePrismic\"\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 external URLs.\n */\nconst defaultExternalRelAttribute = \"noreferrer\"\n\n/**\n * Props for `<PrismicLink />`.\n */\nexport type PrismicLinkProps = {\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 * 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\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"]\n\n\t/**\n\t * An HTML tag name or a component used to render 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 *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.\n\t */\n\tinternalComponent?: ComponentOrTagName\n\n\t/**\n\t * An HTML tag name or a component used to render 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 *\n\t * @defaultValue The one provided to `@prismicio/vue` plugin if configured, `\"a\"` otherwise.\n\t */\n\texternalComponent?: ComponentOrTagName\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * The Prismic link field to render.\n\t\t\t */\n\t\t\tfield: LinkField\n\t\t\tdocument?: never\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * The Prismic document to render as a link.\n\t\t\t */\n\t\t\tdocument: PrismicDocument\n\t\t\tfield?: never\n\t }\n)\n\nconst props = defineProps<PrismicLinkProps>()\ndefineOptions({ name: \"PrismicLink\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\twatchEffect(() => {\n\t\tif (props.field) {\n\t\t\tif (!props.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\tprops.field,\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 props.field\n\t\t\t\t\t? Object.keys(props.field).length > 2\n\t\t\t\t\t: Object.keys(props.field).length > 1) &&\n\t\t\t\t!(\"url\" in props.field || \"uid\" in props.field || \"id\" in props.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\tprops.field,\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (props.document) {\n\t\t\tif (!(\"url\" in props.document || \"id\" in props.document)) {\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\tprops.document,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t})\n}\n\nconst rawAttrs = computed(() => {\n\treturn asLinkAttrs(props.field || props.document, {\n\t\tlinkResolver: props.linkResolver || options.linkResolver,\n\t\trel(args) {\n\t\t\tconst maybeRel = props.rel || options.components?.linkRel\n\t\t\tif (maybeRel) {\n\t\t\t\treturn typeof maybeRel === \"function\" ? maybeRel(args) : maybeRel\n\t\t\t}\n\n\t\t\treturn args.isExternal ? defaultExternalRelAttribute : undefined\n\t\t},\n\t})\n})\n\nconst component = computed(() => {\n\treturn isInternalURL(rawAttrs.value.href || \"\")\n\t\t? props.internalComponent ||\n\t\t\t\toptions.components?.linkInternalComponent ||\n\t\t\t\tdefaultInternalComponent\n\t\t: props.externalComponent ||\n\t\t\t\toptions.components?.linkExternalComponent ||\n\t\t\t\tdefaultExternalComponent\n})\n\n// Match Vue Router's `<RouterLink />` interface unless the component is an anchor tag.\nconst attrs = computed(() => {\n\treturn component.value === \"a\"\n\t\t? {\n\t\t\t\thref: rawAttrs.value.href,\n\t\t\t\ttarget: rawAttrs.value.target,\n\t\t\t\trel: rawAttrs.value.rel,\n\t\t\t}\n\t\t: {\n\t\t\t\tto: rawAttrs.value.href,\n\t\t\t\ttarget: rawAttrs.value.target,\n\t\t\t\trel: rawAttrs.value.rel,\n\t\t\t}\n})\n</script>\n\n<template>\n\t<component :is=\"component\" v-bind=\"attrs\">\n\t\t<slot>\n\t\t\t{{ props.field && \"text\" in props.field ? props.field.text : undefined }}\n\t\t</slot>\n\t</component>\n</template>\n"],"names":[],"mappings":";;;;;;AAqBA,MAAM,2BAA2B;AAKjC,MAAM,2BAA2B;AAKjC,MAAM,8BAA8B;;;;;;;;;;;;;AAqEpC,UAAM,QAAQ;AAGR,UAAA,EAAE,QAAQ,IAAI,WAAW;AAE/B,QAAI,KAAK;AACR,kBAAY,MAAM;AACjB,YAAI,MAAM,OAAO;AACZ,cAAA,CAAC,MAAM,MAAM,WAAW;AACnB,oBAAA;AAAA,cACP;AAAA;AAAA,cACA,MAAM;AAAA,YACP;AACA,kBAAM,IAAI;AAAA,cACT,8IAA8I;AAAA,gBAC7I;AAAA,cAAA,CACA;AAAA,YACF;AAAA,UACD,YACE,UAAU,MAAM,QACd,OAAO,KAAK,MAAM,KAAK,EAAE,SAAS,IAClC,OAAO,KAAK,MAAM,KAAK,EAAE,SAAS,MACrC,EAAE,SAAS,MAAM,SAAS,SAAS,MAAM,SAAS,QAAQ,MAAM,QAC/D;AACO,oBAAA;AAAA,cACP,uJAAuJ;AAAA,gBACtJ;AAAA,cAAA,CACA;AAAA,cACD,MAAM;AAAA,YACP;AAAA,UAAA;AAAA,QACD,WACU,MAAM,UAAU;AAC1B,cAAI,EAAE,SAAS,MAAM,YAAY,QAAQ,MAAM,WAAW;AACjD,oBAAA;AAAA,cACP,0JAA0J;AAAA,gBACzJ;AAAA,cAAA,CACA;AAAA,cACD,MAAM;AAAA,YACP;AAAA,UAAA;AAAA,QACD;AAAA,MACD,CACA;AAAA,IAAA;AAGI,UAAA,WAAW,SAAS,MAAM;AAC/B,aAAO,YAAY,MAAM,SAAS,MAAM,UAAU;AAAA,QACjD,cAAc,MAAM,gBAAgB,QAAQ;AAAA,QAC5C,IAAI,MAAM;;AACT,gBAAM,WAAW,MAAM,SAAO,aAAQ,eAAR,mBAAoB;AAClD,cAAI,UAAU;AACb,mBAAO,OAAO,aAAa,aAAa,SAAS,IAAI,IAAI;AAAA,UAAA;AAGnD,iBAAA,KAAK,aAAa,8BAA8B;AAAA,QAAA;AAAA,MACxD,CACA;AAAA,IAAA,CACD;AAEK,UAAA,YAAY,SAAS,MAAM;;AAChC,aAAO,cAAc,SAAS,MAAM,QAAQ,EAAE,IAC3C,MAAM,uBACN,aAAQ,eAAR,mBAAoB,0BACpB,2BACA,MAAM,uBACN,aAAQ,eAAR,mBAAoB,0BACpB;AAAA,IAAA,CACH;AAGK,UAAA,QAAQ,SAAS,MAAM;AACrB,aAAA,UAAU,UAAU,MACxB;AAAA,QACA,MAAM,SAAS,MAAM;AAAA,QACrB,QAAQ,SAAS,MAAM;AAAA,QACvB,KAAK,SAAS,MAAM;AAAA,MAAA,IAEpB;AAAA,QACA,IAAI,SAAS,MAAM;AAAA,QACnB,QAAQ,SAAS,MAAM;AAAA,QACvB,KAAK,SAAS,MAAM;AAAA,MACrB;AAAA,IAAA,CACF;;;;;;;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const PrismicLink_vue_vue_type_script_setup_true_lang = require("./PrismicLink.vue.cjs");
3
+ module.exports = PrismicLink_vue_vue_type_script_setup_true_lang;
4
+ //# sourceMappingURL=PrismicLink.vue2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.vue2.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,5 @@
1
+ import _sfc_main from "./PrismicLink.vue.js";
2
+ export {
3
+ _sfc_main as default
4
+ };
5
+ //# sourceMappingURL=PrismicLink.vue2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.vue2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ const vue = require("vue");
3
+ const client = require("@prismicio/client");
4
+ const esmEnv = require("esm-env");
5
+ const vueRouter = require("vue-router");
6
+ const devMsg = require("../lib/devMsg.cjs");
7
+ const isInternalURL = require("../lib/isInternalURL.cjs");
8
+ const usePrismic = require("../usePrismic.cjs");
9
+ const defaultWrapper = "div";
10
+ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
11
+ ...{ name: "DeprecatedPrismicRichText" },
12
+ __name: "DeprecatedPrismicRichText",
13
+ props: {
14
+ field: {},
15
+ linkResolver: {},
16
+ serializer: { type: Function },
17
+ wrapper: {},
18
+ fallback: {}
19
+ },
20
+ setup(__props) {
21
+ const props = __props;
22
+ const { options } = usePrismic.usePrismic();
23
+ if (esmEnv.DEV) {
24
+ vue.onMounted(() => {
25
+ console.warn(
26
+ `[PrismicRichText] You're using the deprecated version of \`<PrismicRichText>\` because either the \`serializer\` prop or the plugin \`richTextSerializer\` option were provided. This API will be removed in a future major. For more details, see ${devMsg.devMsg(
27
+ "html-serialization-is-deprecated-with-prismic-rich-text.md"
28
+ )}`
29
+ );
30
+ });
31
+ }
32
+ const html = vue.computed(() => {
33
+ if (!client.isFilled.richText(props.field)) {
34
+ return props.fallback ?? "";
35
+ }
36
+ const linkResolver = props.linkResolver ?? options.linkResolver;
37
+ const serializer = props.serializer ?? options.richTextSerializer;
38
+ return client.asHTML(props.field, { linkResolver, serializer });
39
+ });
40
+ const root = vue.ref(null);
41
+ const maybeRouter = vue.inject(vueRouter.routerKey, null);
42
+ let links = [];
43
+ const navigate = function(event) {
44
+ event.preventDefault();
45
+ maybeRouter == null ? void 0 : maybeRouter.push(this.href);
46
+ };
47
+ const addListeners = () => {
48
+ const node = root.value && "$el" in root.value ? root.value.$el : root.value;
49
+ if (node && "querySelectorAll" in node) {
50
+ links = Array.from(node.querySelectorAll("a")).map((element) => {
51
+ const href = element.getAttribute("href");
52
+ if (href && isInternalURL.isInternalURL(href)) {
53
+ const listener = navigate.bind({ href });
54
+ element.addEventListener("click", listener);
55
+ return { element, listener };
56
+ } else {
57
+ return false;
58
+ }
59
+ }).filter((link) => link);
60
+ }
61
+ };
62
+ const removeListeners = () => {
63
+ links.forEach(
64
+ ({ element, listener }) => element.removeEventListener("click", listener)
65
+ );
66
+ links = [];
67
+ };
68
+ vue.watch(
69
+ html,
70
+ () => {
71
+ removeListeners();
72
+ vue.nextTick(addListeners);
73
+ },
74
+ { immediate: true }
75
+ );
76
+ vue.onBeforeUnmount(() => {
77
+ removeListeners();
78
+ });
79
+ return (_ctx, _cache) => {
80
+ return vue.unref(client.isFilled).richText(_ctx.field) || _ctx.fallback ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.wrapper || defaultWrapper), {
81
+ key: 0,
82
+ ref_key: "root",
83
+ ref: root,
84
+ innerHTML: html.value
85
+ }, null, 8, ["innerHTML"])) : vue.createCommentVNode("", true);
86
+ };
87
+ }
88
+ });
89
+ module.exports = _sfc_main;
90
+ //# sourceMappingURL=DeprecatedPrismicRichText.vue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeprecatedPrismicRichText.vue.cjs","sources":["../../src/PrismicRichText/DeprecatedPrismicRichText.vue"],"sourcesContent":["<script lang=\"ts\" setup>\n// TODO: Remove in v6\nimport { asHTML, isFilled } from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport type { Component } from \"vue\"\nimport {\n\tcomputed,\n\tinject,\n\tnextTick,\n\tonBeforeUnmount,\n\tonMounted,\n\tref,\n\twatch,\n} from \"vue\"\nimport { routerKey } from \"vue-router\"\n\nimport { devMsg } from \"../lib/devMsg\"\nimport { isInternalURL } from \"../lib/isInternalURL\"\n\nimport { usePrismic } from \"../usePrismic\"\n\nimport type { PrismicRichTextProps } from \"./PrismicRichText.vue\"\n\n/**\n * The default component rendered to wrap the HTML output.\n */\nconst defaultWrapper = \"div\"\n\nconst props = defineProps<\n\tPick<\n\t\tPrismicRichTextProps,\n\t\t\"field\" | \"linkResolver\" | \"serializer\" | \"wrapper\"\n\t> & { fallback?: string }\n>()\ndefineOptions({ name: \"DeprecatedPrismicRichText\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\tonMounted(() => {\n\t\tconsole.warn(\n\t\t\t`[PrismicRichText] You're using the deprecated version of \\`<PrismicRichText>\\` because either the \\`serializer\\` prop or the plugin \\`richTextSerializer\\` option were provided. This API will be removed in a future major. For more details, see ${devMsg(\n\t\t\t\t\"html-serialization-is-deprecated-with-prismic-rich-text.md\",\n\t\t\t)}`,\n\t\t)\n\t})\n}\n\nconst html = computed(() => {\n\tif (!isFilled.richText(props.field)) {\n\t\treturn props.fallback ?? \"\"\n\t}\n\n\tconst linkResolver = props.linkResolver ?? options.linkResolver\n\tconst serializer = props.serializer ?? options.richTextSerializer\n\n\treturn asHTML(props.field, { linkResolver, serializer })\n})\n\n// Internal links handling\nconst root = ref<HTMLElement | Comment | Component | null>(null)\n\nconst maybeRouter = inject(routerKey, null)\n\ntype InternalLink = {\n\telement: HTMLAnchorElement\n\tlistener: EventListener\n}\n\nlet links: InternalLink[] = []\n\nconst navigate: EventListener = function (\n\tthis: { href: string },\n\tevent: Event,\n) {\n\tevent.preventDefault()\n\tmaybeRouter?.push(this.href)\n}\n\nconst addListeners = () => {\n\tconst node: HTMLElement | Comment | null =\n\t\troot.value && \"$el\" in root.value ? root.value.$el : root.value\n\tif (node && \"querySelectorAll\" in node) {\n\t\t// Get all internal link tags and add listeners on them\n\t\tlinks = Array.from(node.querySelectorAll(\"a\"))\n\t\t\t.map((element) => {\n\t\t\t\tconst href = element.getAttribute(\"href\")\n\n\t\t\t\tif (href && isInternalURL(href)) {\n\t\t\t\t\tconst listener = navigate.bind({ href })\n\t\t\t\t\telement.addEventListener(\"click\", listener)\n\n\t\t\t\t\treturn { element, listener }\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t})\n\t\t\t.filter((link): link is InternalLink => link as boolean)\n\t}\n}\n\nconst removeListeners = () => {\n\tlinks.forEach(({ element, listener }) =>\n\t\telement.removeEventListener(\"click\", listener),\n\t)\n\tlinks = []\n}\n\nwatch(\n\thtml,\n\t() => {\n\t\tremoveListeners()\n\t\tnextTick(addListeners)\n\t},\n\t{ immediate: true },\n)\n\nonBeforeUnmount(() => {\n\tremoveListeners()\n})\n</script>\n\n<template>\n\t<component\n\t\tv-if=\"isFilled.richText(field) || fallback\"\n\t\tref=\"root\"\n\t\t:is=\"wrapper || defaultWrapper\"\n\t\tv-html=\"html\"\n\t/>\n</template>\n"],"names":["usePrismic","DEV","onMounted","devMsg","computed","isFilled","asHTML","ref","inject","routerKey","isInternalURL","watch","nextTick","onBeforeUnmount"],"mappings":";;;;;;;;AA0BA,MAAM,iBAAiB;;;;;;;;;;;;AAEvB,UAAM,QAAQ;AAQR,UAAA,EAAE,QAAQ,IAAIA,sBAAW;AAE/B,QAAIC,YAAK;AACRC,UAAAA,UAAU,MAAM;AACP,gBAAA;AAAA,UACP,sPAAsPC,OAAA;AAAA,YACrP;AAAA,UAAA,CACA;AAAA,QACF;AAAA,MAAA,CACA;AAAA,IAAA;AAGI,UAAA,OAAOC,IAAAA,SAAS,MAAM;AAC3B,UAAI,CAACC,OAAAA,SAAS,SAAS,MAAM,KAAK,GAAG;AACpC,eAAO,MAAM,YAAY;AAAA,MAAA;AAGpB,YAAA,eAAe,MAAM,gBAAgB,QAAQ;AAC7C,YAAA,aAAa,MAAM,cAAc,QAAQ;AAE/C,aAAOC,OAAAA,OAAO,MAAM,OAAO,EAAE,cAAc,YAAY;AAAA,IAAA,CACvD;AAGK,UAAA,OAAOC,QAA8C,IAAI;AAEzD,UAAA,cAAcC,IAAAA,OAAOC,UAAA,WAAW,IAAI;AAO1C,QAAI,QAAwB,CAAC;AAEvB,UAAA,WAA0B,SAE/B,OACC;AACD,YAAM,eAAe;AACR,iDAAA,KAAK,KAAK;AAAA,IACxB;AAEA,UAAM,eAAe,MAAM;AACpB,YAAA,OACL,KAAK,SAAS,SAAS,KAAK,QAAQ,KAAK,MAAM,MAAM,KAAK;AACvD,UAAA,QAAQ,sBAAsB,MAAM;AAE/B,gBAAA,MAAM,KAAK,KAAK,iBAAiB,GAAG,CAAC,EAC3C,IAAI,CAAC,YAAY;AACX,gBAAA,OAAO,QAAQ,aAAa,MAAM;AAEpC,cAAA,QAAQC,4BAAc,IAAI,GAAG;AAChC,kBAAM,WAAW,SAAS,KAAK,EAAE,MAAM;AAC/B,oBAAA,iBAAiB,SAAS,QAAQ;AAEnC,mBAAA,EAAE,SAAS,SAAS;AAAA,UAAA,OACrB;AACC,mBAAA;AAAA,UAAA;AAAA,QAER,CAAA,EACA,OAAO,CAAC,SAA+B,IAAe;AAAA,MAAA;AAAA,IAE1D;AAEA,UAAM,kBAAkB,MAAM;AACvB,YAAA;AAAA,QAAQ,CAAC,EAAE,SAAS,SAAA,MACzB,QAAQ,oBAAoB,SAAS,QAAQ;AAAA,MAC9C;AACA,cAAQ,CAAC;AAAA,IACV;AAEAC,QAAA;AAAA,MACC;AAAA,MACA,MAAM;AACW,wBAAA;AAChBC,YAAAA,SAAS,YAAY;AAAA,MACtB;AAAA,MACA,EAAE,WAAW,KAAK;AAAA,IACnB;AAEAC,QAAAA,gBAAgB,MAAM;AACL,sBAAA;AAAA,IAAA,CAChB;;;;;;;;;;;;"}
@@ -0,0 +1,7 @@
1
+ import { PrismicRichTextProps } from './PrismicRichText.vue';
2
+ declare const _default: import('vue').DefineComponent<Pick<PrismicRichTextProps, "wrapper" | "field" | "linkResolver" | "serializer"> & {
3
+ fallback?: string;
4
+ }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Pick<PrismicRichTextProps, "wrapper" | "field" | "linkResolver" | "serializer"> & {
5
+ fallback?: string;
6
+ }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
7
+ export default _default;