@prismicio/vue 4.2.3 → 4.3.1

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 (67) hide show
  1. package/dist/components/PrismicEmbed.cjs.map +1 -1
  2. package/dist/components/PrismicEmbed.d.ts +7 -7
  3. package/dist/components/PrismicEmbed.js.map +1 -1
  4. package/dist/components/PrismicImage.cjs.map +1 -1
  5. package/dist/components/PrismicImage.d.ts +10 -8
  6. package/dist/components/PrismicImage.js.map +1 -1
  7. package/dist/components/PrismicLink.cjs +8 -3
  8. package/dist/components/PrismicLink.cjs.map +1 -1
  9. package/dist/components/PrismicLink.d.ts +14 -8
  10. package/dist/components/PrismicLink.js +8 -3
  11. package/dist/components/PrismicLink.js.map +1 -1
  12. package/dist/components/PrismicRichText.cjs.map +1 -1
  13. package/dist/components/PrismicRichText.d.ts +8 -8
  14. package/dist/components/PrismicRichText.js.map +1 -1
  15. package/dist/components/PrismicText.cjs.map +1 -1
  16. package/dist/components/PrismicText.d.ts +8 -8
  17. package/dist/components/PrismicText.js.map +1 -1
  18. package/dist/components/SliceZone.cjs.map +1 -1
  19. package/dist/components/SliceZone.d.ts +14 -12
  20. package/dist/components/SliceZone.js.map +1 -1
  21. package/dist/components/index.d.ts +1 -1
  22. package/dist/composables.cjs.map +1 -1
  23. package/dist/composables.d.ts +38 -74
  24. package/dist/composables.js.map +1 -1
  25. package/dist/createPrismic.cjs.map +1 -1
  26. package/dist/createPrismic.js.map +1 -1
  27. package/dist/injectionSymbols.cjs.map +1 -1
  28. package/dist/injectionSymbols.js.map +1 -1
  29. package/dist/lib/__PRODUCTION__.cjs.map +1 -1
  30. package/dist/lib/__PRODUCTION__.js.map +1 -1
  31. package/dist/lib/getSlots.cjs +6 -4
  32. package/dist/lib/getSlots.cjs.map +1 -1
  33. package/dist/lib/getSlots.d.ts +2 -2
  34. package/dist/lib/getSlots.js +6 -4
  35. package/dist/lib/getSlots.js.map +1 -1
  36. package/dist/lib/isInternalURL.cjs.map +1 -1
  37. package/dist/lib/isInternalURL.js.map +1 -1
  38. package/dist/lib/simplyResolveComponent.cjs.map +1 -1
  39. package/dist/lib/simplyResolveComponent.d.ts +1 -1
  40. package/dist/lib/simplyResolveComponent.js.map +1 -1
  41. package/dist/types.d.ts +11 -2
  42. package/dist/usePrismic.cjs.map +1 -1
  43. package/dist/usePrismic.d.ts +5 -5
  44. package/dist/usePrismic.js.map +1 -1
  45. package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
  46. package/dist/useStatefulPrismicClientMethod.d.ts +4 -3
  47. package/dist/useStatefulPrismicClientMethod.js.map +1 -1
  48. package/package.json +28 -29
  49. package/src/components/PrismicEmbed.ts +16 -17
  50. package/src/components/PrismicImage.ts +57 -59
  51. package/src/components/PrismicLink.ts +78 -67
  52. package/src/components/PrismicRichText.ts +64 -63
  53. package/src/components/PrismicText.ts +30 -32
  54. package/src/components/SliceZone.ts +94 -96
  55. package/src/components/index.ts +12 -16
  56. package/src/composables.ts +41 -23
  57. package/src/createPrismic.ts +40 -34
  58. package/src/globalExtensions.ts +2 -2
  59. package/src/index.ts +10 -10
  60. package/src/injectionSymbols.ts +4 -4
  61. package/src/lib/__PRODUCTION__.ts +2 -2
  62. package/src/lib/getSlots.ts +17 -8
  63. package/src/lib/isInternalURL.ts +4 -4
  64. package/src/lib/simplyResolveComponent.ts +4 -9
  65. package/src/types.ts +61 -52
  66. package/src/usePrismic.ts +9 -9
  67. package/src/useStatefulPrismicClientMethod.ts +42 -40
@@ -1,12 +1,11 @@
1
- import {
1
+ import type {
2
2
  HTMLFunctionSerializer,
3
3
  HTMLMapSerializer,
4
4
  LinkResolverFunction,
5
5
  RichTextField,
6
- asHTML,
7
- isFilled,
8
- } from "@prismicio/client";
9
- import {
6
+ } from "@prismicio/client"
7
+ import { asHTML, isFilled } from "@prismicio/client"
8
+ import type {
10
9
  AllowedComponentProps,
11
10
  Component,
12
11
  ComponentCustomProps,
@@ -16,6 +15,8 @@ import {
16
15
  PropType,
17
16
  Raw,
18
17
  VNodeProps,
18
+ } from "vue"
19
+ import {
19
20
  computed,
20
21
  defineComponent,
21
22
  h,
@@ -25,20 +26,20 @@ import {
25
26
  ref,
26
27
  unref,
27
28
  watch,
28
- } from "vue";
29
- import { routerKey } from "vue-router";
29
+ } from "vue"
30
+ import { routerKey } from "vue-router"
30
31
 
31
- import { isInternalURL } from "../lib/isInternalURL";
32
- import { simplyResolveComponent } from "../lib/simplyResolveComponent";
32
+ import { isInternalURL } from "../lib/isInternalURL"
33
+ import { simplyResolveComponent } from "../lib/simplyResolveComponent"
33
34
 
34
- import { VueUseOptions } from "../types";
35
+ import type { VueUseOptions } from "../types"
35
36
 
36
- import { usePrismic } from "../usePrismic";
37
+ import { usePrismic } from "../usePrismic"
37
38
 
38
39
  /**
39
40
  * The default component rendered to wrap the HTML output.
40
41
  */
41
- const defaultWrapper = "div";
42
+ const defaultWrapper = "div"
42
43
 
43
44
  /**
44
45
  * Props for `<PrismicRichText />`.
@@ -47,7 +48,7 @@ export type PrismicRichTextProps = {
47
48
  /**
48
49
  * The Prismic rich text or title field to render.
49
50
  */
50
- field: RichTextField | null | undefined;
51
+ field: RichTextField | null | undefined
51
52
 
52
53
  /**
53
54
  * A link resolver function used to resolve link when not using the route
@@ -57,7 +58,7 @@ export type PrismicRichTextProps = {
57
58
  *
58
59
  * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
59
60
  */
60
- linkResolver?: LinkResolverFunction;
61
+ linkResolver?: LinkResolverFunction
61
62
 
62
63
  /**
63
64
  * An HTML serializer to customize the way rich text fields are rendered.
@@ -66,7 +67,7 @@ export type PrismicRichTextProps = {
66
67
  *
67
68
  * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
68
69
  */
69
- serializer?: HTMLFunctionSerializer | HTMLMapSerializer;
70
+ serializer?: HTMLFunctionSerializer | HTMLMapSerializer
70
71
 
71
72
  /**
72
73
  * An HTML serializer to customize the way rich text fields are rendered.
@@ -77,7 +78,7 @@ export type PrismicRichTextProps = {
77
78
  *
78
79
  * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
79
80
  */
80
- htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;
81
+ htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer
81
82
 
82
83
  /**
83
84
  * An HTML tag name, a component, or a functional component used to wrap the
@@ -85,21 +86,21 @@ export type PrismicRichTextProps = {
85
86
  *
86
87
  * @defaultValue `"div"`
87
88
  */
88
- wrapper?: string | ConcreteComponent | Raw<DefineComponent>;
89
+ wrapper?: string | ConcreteComponent | Raw<DefineComponent>
89
90
 
90
91
  /**
91
92
  * The HTML value to be rendered when the field is empty. If a fallback is not
92
93
  * given, `""` (nothing) will be rendered.
93
94
  */
94
- fallback?: string;
95
- };
95
+ fallback?: string
96
+ }
96
97
 
97
98
  /**
98
99
  * Options for {@link usePrismicRichText}.
99
100
  */
100
101
  export type UsePrismicRichTextOptions = VueUseOptions<
101
102
  Omit<PrismicRichTextProps, "wrapper">
102
- >;
103
+ >
103
104
 
104
105
  /**
105
106
  * Return type of {@link usePrismicRichText}.
@@ -108,8 +109,8 @@ export type UsePrismicRichTextReturnType = {
108
109
  /**
109
110
  * Serialized rich text field as HTML.
110
111
  */
111
- html: ComputedRef<string>;
112
- };
112
+ html: ComputedRef<string>
113
+ }
113
114
 
114
115
  /**
115
116
  * A low level composable that returns a serialized rich text field as HTML.
@@ -122,29 +123,29 @@ export type UsePrismicRichTextReturnType = {
122
123
  export const usePrismicRichText = (
123
124
  props: UsePrismicRichTextOptions,
124
125
  ): UsePrismicRichTextReturnType => {
125
- const { options } = usePrismic();
126
+ const { options } = usePrismic()
126
127
 
127
128
  const html = computed(() => {
128
- const field = unref(props.field);
129
+ const field = unref(props.field)
129
130
 
130
131
  if (!isFilled.richText(field)) {
131
- return unref(props.fallback) ?? "";
132
+ return unref(props.fallback) ?? ""
132
133
  }
133
134
 
134
- const linkResolver = unref(props.linkResolver) ?? options.linkResolver;
135
+ const linkResolver = unref(props.linkResolver) ?? options.linkResolver
135
136
  const serializer =
136
137
  unref(props.serializer) ??
137
138
  unref(props.htmlSerializer) ??
138
139
  options.richTextSerializer ??
139
- options.htmlSerializer;
140
+ options.htmlSerializer
140
141
 
141
- return asHTML(unref(field), linkResolver, serializer);
142
- });
142
+ return asHTML(unref(field), linkResolver, serializer)
143
+ })
143
144
 
144
145
  return {
145
146
  html,
146
- };
147
- };
147
+ }
148
+ }
148
149
 
149
150
  /**
150
151
  * `<PrismicRichText />` implementation.
@@ -192,77 +193,77 @@ export const PrismicRichTextImpl = /*#__PURE__*/ defineComponent({
192
193
  },
193
194
  },
194
195
  setup(props) {
195
- const { html } = usePrismicRichText(props);
196
+ const { html } = usePrismicRichText(props)
196
197
 
197
- const root = ref<HTMLElement | Comment | Component | null>(null);
198
+ const root = ref<HTMLElement | Comment | Component | null>(null)
198
199
 
199
- const maybeRouter = inject(routerKey, null);
200
+ const maybeRouter = inject(routerKey, null)
200
201
  if (maybeRouter) {
201
202
  type InternalLink = {
202
- element: HTMLAnchorElement;
203
- listener: EventListener;
204
- };
205
- let links: InternalLink[] = [];
203
+ element: HTMLAnchorElement
204
+ listener: EventListener
205
+ }
206
+ let links: InternalLink[] = []
206
207
 
207
208
  const navigate: EventListener = function (
208
209
  this: { href: string },
209
210
  event: Event,
210
211
  ) {
211
- event.preventDefault();
212
- maybeRouter.push(this.href);
213
- };
212
+ event.preventDefault()
213
+ maybeRouter.push(this.href)
214
+ }
214
215
 
215
216
  const addListeners = () => {
216
217
  const node: HTMLElement | Comment | null =
217
- root.value && "$el" in root.value ? root.value.$el : root.value;
218
+ root.value && "$el" in root.value ? root.value.$el : root.value
218
219
  if (node && "querySelectorAll" in node) {
219
220
  // Get all internal link tags and add listeners on them
220
221
  links = Array.from(node.querySelectorAll("a"))
221
222
  .map((element) => {
222
- const href = element.getAttribute("href");
223
+ const href = element.getAttribute("href")
223
224
 
224
225
  if (href && isInternalURL(href)) {
225
- const listener = navigate.bind({ href });
226
- element.addEventListener("click", listener);
226
+ const listener = navigate.bind({ href })
227
+ element.addEventListener("click", listener)
227
228
 
228
- return { element, listener };
229
+ return { element, listener }
229
230
  } else {
230
- return false;
231
+ return false
231
232
  }
232
233
  })
233
- .filter((link): link is InternalLink => link as boolean);
234
+ .filter((link): link is InternalLink => link as boolean)
234
235
  }
235
- };
236
+ }
236
237
 
237
238
  const removeListeners = () => {
238
239
  links.forEach(({ element, listener }) =>
239
240
  element.removeEventListener("click", listener),
240
- );
241
- links = [];
242
- };
241
+ )
242
+ links = []
243
+ }
243
244
 
244
245
  watch(
245
246
  html,
246
247
  () => {
247
- removeListeners();
248
- nextTick(addListeners);
248
+ removeListeners()
249
+ nextTick(addListeners)
249
250
  },
250
251
  { immediate: true },
251
- );
252
+ )
252
253
 
253
254
  onBeforeUnmount(() => {
254
- removeListeners();
255
- });
255
+ removeListeners()
256
+ })
256
257
  }
257
258
 
258
259
  return () => {
259
260
  return h(simplyResolveComponent(props.wrapper || defaultWrapper), {
260
261
  innerHTML: html.value,
261
262
  ref: root,
262
- });
263
- };
263
+ })
264
+ }
264
265
  },
265
- });
266
+ })
266
267
 
267
268
  // export the public type for h/tsx inference
268
269
  // also to avoid inline import() in generated d.ts files
@@ -277,6 +278,6 @@ export const PrismicRichText = PrismicRichTextImpl as unknown as {
277
278
  $props: AllowedComponentProps &
278
279
  ComponentCustomProps &
279
280
  VNodeProps &
280
- PrismicRichTextProps;
281
- };
282
- };
281
+ PrismicRichTextProps
282
+ }
283
+ }
@@ -1,5 +1,6 @@
1
- import { RichTextField, asText, isFilled } from "@prismicio/client";
2
- import {
1
+ import type { RichTextField } from "@prismicio/client"
2
+ import { asText, isFilled } from "@prismicio/client"
3
+ import type {
3
4
  AllowedComponentProps,
4
5
  ComponentCustomProps,
5
6
  ComputedRef,
@@ -9,20 +10,17 @@ import {
9
10
  Raw,
10
11
  VNode,
11
12
  VNodeProps,
12
- computed,
13
- defineComponent,
14
- h,
15
- unref,
16
- } from "vue";
13
+ } from "vue"
14
+ import { computed, defineComponent, h, unref } from "vue"
17
15
 
18
- import { simplyResolveComponent } from "../lib/simplyResolveComponent";
16
+ import { simplyResolveComponent } from "../lib/simplyResolveComponent"
19
17
 
20
- import { VueUseOptions } from "../types";
18
+ import type { VueUseOptions } from "../types"
21
19
 
22
20
  /**
23
21
  * The default component rendered to wrap the text output.
24
22
  */
25
- const defaultWrapper = "div";
23
+ const defaultWrapper = "div"
26
24
  /**
27
25
  * Props for `<PrismicText />`.
28
26
  */
@@ -30,14 +28,14 @@ export type PrismicTextProps = {
30
28
  /**
31
29
  * The Prismic rich text or title field to render.
32
30
  */
33
- field: RichTextField | null | undefined;
31
+ field: RichTextField | null | undefined
34
32
 
35
33
  /**
36
34
  * Separator used to join each element.
37
35
  *
38
36
  * @defaultValue `" "` (a space)
39
37
  */
40
- separator?: string;
38
+ separator?: string
41
39
 
42
40
  /**
43
41
  * An HTML tag name, a component, or a functional component used to wrap the
@@ -45,21 +43,21 @@ export type PrismicTextProps = {
45
43
  *
46
44
  * @defaultValue `"div"`
47
45
  */
48
- wrapper?: string | ConcreteComponent | Raw<DefineComponent>;
46
+ wrapper?: string | ConcreteComponent | Raw<DefineComponent>
49
47
 
50
48
  /**
51
49
  * The string value to be rendered when the field is empty. If a fallback is
52
50
  * not given, `""` (nothing) will be rendered.
53
51
  */
54
- fallback?: string;
55
- };
52
+ fallback?: string
53
+ }
56
54
 
57
55
  /**
58
56
  * Options for {@link usePrismicText}.
59
57
  */
60
58
  export type UsePrismicTextOptions = VueUseOptions<
61
59
  Omit<PrismicTextProps, "wrapper">
62
- >;
60
+ >
63
61
 
64
62
  /**
65
63
  * Return type of {@link usePrismicText}.
@@ -68,8 +66,8 @@ export type UsePrismicTextReturnType = {
68
66
  /**
69
67
  * Serialized rich text field as plain text.
70
68
  */
71
- text: ComputedRef<string>;
72
- };
69
+ text: ComputedRef<string>
70
+ }
73
71
 
74
72
  /**
75
73
  * A low level composable that returns a serialized rich text field as plain
@@ -84,19 +82,19 @@ export const usePrismicText = (
84
82
  props: UsePrismicTextOptions,
85
83
  ): UsePrismicTextReturnType => {
86
84
  const text = computed(() => {
87
- const field = unref(props.field);
85
+ const field = unref(props.field)
88
86
 
89
87
  if (!isFilled.richText(field)) {
90
- return unref(props.fallback) ?? "";
88
+ return unref(props.fallback) ?? ""
91
89
  }
92
90
 
93
- return asText(unref(field), unref(props.separator));
94
- });
91
+ return asText(unref(field), unref(props.separator))
92
+ })
95
93
 
96
94
  return {
97
95
  text,
98
- };
99
- };
96
+ }
97
+ }
100
98
 
101
99
  /**
102
100
  * `<PrismicText />` implementation.
@@ -130,10 +128,10 @@ export const PrismicTextImpl = /*#__PURE__*/ defineComponent({
130
128
  },
131
129
  },
132
130
  setup(props) {
133
- const { text } = usePrismicText(props);
131
+ const { text } = usePrismicText(props)
134
132
 
135
133
  return () => {
136
- const parent = simplyResolveComponent(props.wrapper || defaultWrapper);
134
+ const parent = simplyResolveComponent(props.wrapper || defaultWrapper)
137
135
 
138
136
  // This works but is absurd
139
137
  // if (typeof parent === "string") {
@@ -144,10 +142,10 @@ export const PrismicTextImpl = /*#__PURE__*/ defineComponent({
144
142
 
145
143
  return h(parent as VNode, null, {
146
144
  default: () => text.value,
147
- });
148
- };
145
+ })
146
+ }
149
147
  },
150
- });
148
+ })
151
149
 
152
150
  // export the public type for h/tsx inference
153
151
  // also to avoid inline import() in generated d.ts files
@@ -162,6 +160,6 @@ export const PrismicText = PrismicTextImpl as unknown as {
162
160
  $props: AllowedComponentProps &
163
161
  ComponentCustomProps &
164
162
  VNodeProps &
165
- PrismicTextProps;
166
- };
167
- };
163
+ PrismicTextProps
164
+ }
165
+ }