@prismicio/vue 4.3.0 → 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 (65) 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.map +1 -1
  8. package/dist/components/PrismicLink.d.ts +10 -8
  9. package/dist/components/PrismicLink.js.map +1 -1
  10. package/dist/components/PrismicRichText.cjs.map +1 -1
  11. package/dist/components/PrismicRichText.d.ts +8 -8
  12. package/dist/components/PrismicRichText.js.map +1 -1
  13. package/dist/components/PrismicText.cjs.map +1 -1
  14. package/dist/components/PrismicText.d.ts +8 -8
  15. package/dist/components/PrismicText.js.map +1 -1
  16. package/dist/components/SliceZone.cjs.map +1 -1
  17. package/dist/components/SliceZone.d.ts +14 -12
  18. package/dist/components/SliceZone.js.map +1 -1
  19. package/dist/components/index.d.ts +1 -1
  20. package/dist/composables.cjs.map +1 -1
  21. package/dist/composables.d.ts +20 -2
  22. package/dist/composables.js.map +1 -1
  23. package/dist/createPrismic.cjs.map +1 -1
  24. package/dist/createPrismic.js.map +1 -1
  25. package/dist/injectionSymbols.cjs.map +1 -1
  26. package/dist/injectionSymbols.js.map +1 -1
  27. package/dist/lib/__PRODUCTION__.cjs.map +1 -1
  28. package/dist/lib/__PRODUCTION__.js.map +1 -1
  29. package/dist/lib/getSlots.cjs +7 -5
  30. package/dist/lib/getSlots.cjs.map +1 -1
  31. package/dist/lib/getSlots.d.ts +2 -2
  32. package/dist/lib/getSlots.js +7 -5
  33. package/dist/lib/getSlots.js.map +1 -1
  34. package/dist/lib/isInternalURL.cjs.map +1 -1
  35. package/dist/lib/isInternalURL.js.map +1 -1
  36. package/dist/lib/simplyResolveComponent.cjs.map +1 -1
  37. package/dist/lib/simplyResolveComponent.d.ts +1 -1
  38. package/dist/lib/simplyResolveComponent.js.map +1 -1
  39. package/dist/types.d.ts +11 -2
  40. package/dist/usePrismic.cjs.map +1 -1
  41. package/dist/usePrismic.d.ts +5 -5
  42. package/dist/usePrismic.js.map +1 -1
  43. package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
  44. package/dist/useStatefulPrismicClientMethod.d.ts +4 -3
  45. package/dist/useStatefulPrismicClientMethod.js.map +1 -1
  46. package/package.json +27 -28
  47. package/src/components/PrismicEmbed.ts +16 -17
  48. package/src/components/PrismicImage.ts +57 -59
  49. package/src/components/PrismicLink.ts +68 -70
  50. package/src/components/PrismicRichText.ts +64 -63
  51. package/src/components/PrismicText.ts +30 -32
  52. package/src/components/SliceZone.ts +94 -96
  53. package/src/components/index.ts +12 -16
  54. package/src/composables.ts +41 -23
  55. package/src/createPrismic.ts +40 -34
  56. package/src/globalExtensions.ts +2 -2
  57. package/src/index.ts +10 -10
  58. package/src/injectionSymbols.ts +4 -4
  59. package/src/lib/__PRODUCTION__.ts +2 -2
  60. package/src/lib/getSlots.ts +18 -12
  61. package/src/lib/isInternalURL.ts +4 -4
  62. package/src/lib/simplyResolveComponent.ts +4 -9
  63. package/src/types.ts +61 -52
  64. package/src/usePrismic.ts +9 -9
  65. package/src/useStatefulPrismicClientMethod.ts +42 -40
package/src/types.ts CHANGED
@@ -16,20 +16,20 @@ import type {
16
16
  documentToLinkField,
17
17
  filter,
18
18
  isFilled,
19
- } from "@prismicio/client";
20
- import type { App, ConcreteComponent, DefineComponent, Raw, Ref } from "vue";
19
+ } from "@prismicio/client"
20
+ import type { App, ConcreteComponent, DefineComponent, Raw, Ref } from "vue"
21
21
 
22
22
  /* eslint-disable @typescript-eslint/no-unused-vars */
23
23
  // Imports for @link references:
24
- import type { RouterLink } from "vue-router";
24
+ import type { RouterLink } from "vue-router"
25
25
 
26
26
  import type {
27
27
  SliceComponentProps,
28
28
  SliceComponentType,
29
29
  TODOSliceComponent,
30
- } from "./components/SliceZone";
30
+ } from "./components/SliceZone"
31
31
 
32
- import type { usePrismicDocuments } from "./composables";
32
+ import type { usePrismicDocuments } from "./composables"
33
33
 
34
34
  /* eslint-enable @typescript-eslint/no-unused-vars */
35
35
 
@@ -43,7 +43,7 @@ type PrismicPluginComponentsOptions = {
43
43
  *
44
44
  * @defaultValue `"noopener noreferrer"`
45
45
  */
46
- linkBlankTargetRelAttribute?: string;
46
+ linkBlankTargetRelAttribute?: string
47
47
 
48
48
  /**
49
49
  * An HTML tag name, a component, or a functional component used to render
@@ -55,9 +55,10 @@ type PrismicPluginComponentsOptions = {
55
55
  * @remarks
56
56
  * Components will be rendered using Vue Router {@link RouterLink} interface
57
57
  * (`to` props).
58
+ *
58
59
  * @defaultValue {@link RouterLink}
59
60
  */
60
- linkInternalComponent?: string | ConcreteComponent | Raw<DefineComponent>;
61
+ linkInternalComponent?: string | ConcreteComponent | Raw<DefineComponent>
61
62
 
62
63
  /**
63
64
  * An HTML tag name, a component, or a functional component used to render
@@ -69,9 +70,10 @@ type PrismicPluginComponentsOptions = {
69
70
  * @remarks
70
71
  * Components will be rendered using Vue Router {@link RouterLink} interface
71
72
  * (`to` props).
73
+ *
72
74
  * @defaultValue `"a"`
73
75
  */
74
- linkExternalComponent?: string | ConcreteComponent | Raw<DefineComponent>;
76
+ linkExternalComponent?: string | ConcreteComponent | Raw<DefineComponent>
75
77
 
76
78
  /**
77
79
  * An HTML tag name, a component, or a functional component used to render
@@ -81,9 +83,10 @@ type PrismicPluginComponentsOptions = {
81
83
  * HTML tag names and components will be rendered using the `img` tag
82
84
  * interface (`src` and `alt` attribute). Components will also receive an
83
85
  * additional `copyright` props.
86
+ *
84
87
  * @defaultValue `"img"`
85
88
  */
86
- imageComponent?: string | ConcreteComponent | Raw<DefineComponent>;
89
+ imageComponent?: string | ConcreteComponent | Raw<DefineComponent>
87
90
 
88
91
  /**
89
92
  * Default widths to use when rendering an image with `widths="defaults"`
@@ -92,9 +95,10 @@ type PrismicPluginComponentsOptions = {
92
95
  * Consider configuring image widths within your content type definition and
93
96
  * using `widths="auto"` instead to give content writers the ability to crop
94
97
  * images in the editor.
98
+ *
95
99
  * @defaultValue `@prismicio/client` defaults
96
100
  */
97
- imageWidthSrcSetDefaults?: number[];
101
+ imageWidthSrcSetDefaults?: number[]
98
102
 
99
103
  /**
100
104
  * Default pixel densities to use when rendering an image with
@@ -102,7 +106,7 @@ type PrismicPluginComponentsOptions = {
102
106
  *
103
107
  * @defaultValue `@prismicio/client` defaults
104
108
  */
105
- imagePixelDensitySrcSetDefaults?: number[];
109
+ imagePixelDensitySrcSetDefaults?: number[]
106
110
 
107
111
  /**
108
112
  * A component or a functional component rendered if a component mapping from
@@ -113,8 +117,8 @@ type PrismicPluginComponentsOptions = {
113
117
  *
114
118
  * @defaultValue `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}
115
119
  */
116
- sliceZoneDefaultComponent?: SliceComponentType;
117
- };
120
+ sliceZoneDefaultComponent?: SliceComponentType
121
+ }
118
122
 
119
123
  /**
120
124
  * Common options supported by `@prismicio/vue` plugin.
@@ -127,7 +131,7 @@ type PrismicPluginOptionsBase = {
127
131
  *
128
132
  * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
129
133
  */
130
- linkResolver?: LinkResolverFunction;
134
+ linkResolver?: LinkResolverFunction
131
135
 
132
136
  /**
133
137
  * An optional HTML serializer to customize the way rich text fields are
@@ -137,7 +141,7 @@ type PrismicPluginOptionsBase = {
137
141
  */
138
142
  richTextSerializer?:
139
143
  | HTMLRichTextFunctionSerializer
140
- | HTMLRichTextMapSerializer;
144
+ | HTMLRichTextMapSerializer
141
145
 
142
146
  /**
143
147
  * An optional HTML serializer to customize the way rich text fields are
@@ -148,22 +152,22 @@ type PrismicPluginOptionsBase = {
148
152
  * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
149
153
  */
150
154
  // TODO: Remove in v5
151
- htmlSerializer?: HTMLRichTextFunctionSerializer | HTMLRichTextMapSerializer;
155
+ htmlSerializer?: HTMLRichTextFunctionSerializer | HTMLRichTextMapSerializer
152
156
 
153
157
  /**
154
158
  * Whether or not to inject components globally.
155
159
  *
156
160
  * @defaultValue `true`
157
161
  */
158
- injectComponents?: boolean;
162
+ injectComponents?: boolean
159
163
 
160
164
  /**
161
165
  * Options used by Prismic Vue components.
162
166
  *
163
167
  * @see Components options {@link PrismicPluginComponentsOptions}
164
168
  */
165
- components?: PrismicPluginComponentsOptions;
166
- };
169
+ components?: PrismicPluginComponentsOptions
170
+ }
167
171
 
168
172
  /**
169
173
  * Options to init `@prismicio/vue` plugin with a client instance.
@@ -179,24 +183,25 @@ type PrismicPluginOptionsWithClient = PrismicPluginOptionsBase & {
179
183
  * The client will be used by `@prismicio/vue` composables, such as
180
184
  * {@link usePrismicDocuments} and exposed through `this.$prismic.client` and
181
185
  * `usePrismic().client`.
186
+ *
182
187
  * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
183
188
  */
184
- client: ReturnType<CreateClient>;
189
+ client: ReturnType<CreateClient>
185
190
 
186
191
  /**
187
192
  * Ensures type union is a strict or.
188
193
  *
189
194
  * @internal
190
195
  */
191
- endpoint?: never;
196
+ endpoint?: never
192
197
 
193
198
  /**
194
199
  * Ensures type union is a strict or.
195
200
  *
196
201
  * @internal
197
202
  */
198
- clientConfig?: never;
199
- };
203
+ clientConfig?: never
204
+ }
200
205
 
201
206
  /**
202
207
  * Options to init `@prismicio/vue` plugin with a repository ID or API endpoint.
@@ -212,19 +217,20 @@ type PrismicPluginOptionsWithEndpoint = PrismicPluginOptionsBase & {
212
217
  * Said client will be used by `@prismicio/vue` composables, such as
213
218
  * {@link usePrismicDocuments} and exposed through `this.$prismic.client` and
214
219
  * `usePrismic().client`.
220
+ *
215
221
  * @example
216
222
  *
217
223
  * ```javascript
218
224
  * // A repository ID
219
- * "my-repo";
225
+ * "my-repo"
220
226
  *
221
227
  * //A full repository endpoint
222
- * "https://my-repo.cdn.prismic.io/api/v2";
228
+ * "https://my-repo.cdn.prismic.io/api/v2"
223
229
  * ```
224
230
  *
225
231
  * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
226
232
  */
227
- endpoint: string;
233
+ endpoint: string
228
234
 
229
235
  /**
230
236
  * An optional object to configure `@prismicio/client` instance further.
@@ -261,15 +267,15 @@ type PrismicPluginOptionsWithEndpoint = PrismicPluginOptionsBase & {
261
267
  * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
262
268
  * @see Route resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
263
269
  */
264
- clientConfig?: ClientConfig;
270
+ clientConfig?: ClientConfig
265
271
 
266
272
  /**
267
273
  * Ensures type union is a strict or.
268
274
  *
269
275
  * @internal
270
276
  */
271
- client?: never;
272
- };
277
+ client?: never
278
+ }
273
279
 
274
280
  /**
275
281
  * `@prismicio/vue` plugin options.
@@ -279,7 +285,7 @@ type PrismicPluginOptionsWithEndpoint = PrismicPluginOptionsBase & {
279
285
  */
280
286
  export type PrismicPluginOptions =
281
287
  | PrismicPluginOptionsWithClient
282
- | PrismicPluginOptionsWithEndpoint;
288
+ | PrismicPluginOptionsWithEndpoint
283
289
 
284
290
  /**
285
291
  * `@prismicio/client` related methods and properties exposed by
@@ -290,18 +296,18 @@ export type PrismicPluginClient = {
290
296
  /**
291
297
  * A `@prismicio/client` instance.
292
298
  */
293
- client: ReturnType<CreateClient>;
299
+ client: ReturnType<CreateClient>
294
300
 
295
301
  /**
296
302
  * Query filters from `@prismicio/client`.
297
303
  */
298
- filter: typeof filter;
304
+ filter: typeof filter
299
305
 
300
306
  /**
301
307
  * Prismic cookies from `@prismicio/client`.
302
308
  */
303
- cookie: typeof cookie;
304
- };
309
+ cookie: typeof cookie
310
+ }
305
311
 
306
312
  /**
307
313
  * `@prismicio/client` related methods exposed by `@prismicio/vue` plugin and
@@ -314,7 +320,7 @@ export type PrismicPluginHelpers = {
314
320
  *
315
321
  * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
316
322
  */
317
- asText: typeof asText;
323
+ asText: typeof asText
318
324
 
319
325
  /**
320
326
  * Serializes a rich text or title field to an HTML string. This is
@@ -326,9 +332,10 @@ export type PrismicPluginHelpers = {
326
332
  * @remarks
327
333
  * If no `htmlSerializer` is provided the function will use the one provided
328
334
  * to the plugin at {@link PrismicPluginOptions.htmlSerializer} if available.
335
+ *
329
336
  * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
330
337
  */
331
- asHTML: typeof asHTML;
338
+ asHTML: typeof asHTML
332
339
 
333
340
  /**
334
341
  * Resolves any type of link field or document to a URL. This is
@@ -337,9 +344,10 @@ export type PrismicPluginHelpers = {
337
344
  * @remarks
338
345
  * If no `linkResolver` is provided the function will use the one provided to
339
346
  * the plugin at {@link PrismicPluginOptions.linkResolver} if available.
347
+ *
340
348
  * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
341
349
  */
342
- asLink: typeof asLink;
350
+ asLink: typeof asLink
343
351
 
344
352
  /**
345
353
  * Resolves any type of link field or document to a set of link attributes.
@@ -348,42 +356,43 @@ export type PrismicPluginHelpers = {
348
356
  * @remarks
349
357
  * If no `linkResolver` is provided the function will use the one provided to
350
358
  * the plugin at {@link PrismicPluginOptions.linkResolver} if available.
359
+ *
351
360
  * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
352
361
  */
353
- asLinkAttrs: typeof asLinkAttrs;
362
+ asLinkAttrs: typeof asLinkAttrs
354
363
 
355
364
  /**
356
365
  * Transforms a date or timestamp field into a JavaScript Date object. This is
357
366
  * `@prismicio/client` {@link asDate} function.
358
367
  */
359
- asDate: typeof asDate;
368
+ asDate: typeof asDate
360
369
 
361
370
  /**
362
371
  * Returns the URL of an Image field with optional image transformations (via
363
372
  * Imgix URL parameters). This is `@prismicio/client` {@link asImageSrc}
364
373
  * function.
365
374
  */
366
- asImageSrc: typeof asImageSrc;
375
+ asImageSrc: typeof asImageSrc
367
376
 
368
377
  /**
369
378
  * Creates a width-based `srcset` from an Image field with optional image
370
379
  * transformations (via Imgix URL parameters). This is `@prismicio/client`
371
380
  * {@link asImageWidthSrcSet} function.
372
381
  */
373
- asImageWidthSrcSet: typeof asImageWidthSrcSet;
382
+ asImageWidthSrcSet: typeof asImageWidthSrcSet
374
383
 
375
384
  /**
376
385
  * Creates a pixel-density-based `srcset` from an Image field with optional
377
386
  * image transformations (via Imgix URL parameters). This is
378
387
  * `@prismicio/client` {@link asImagePixelDensitySrcSet} function.
379
388
  */
380
- asImagePixelDensitySrcSet: typeof asImagePixelDensitySrcSet;
389
+ asImagePixelDensitySrcSet: typeof asImagePixelDensitySrcSet
381
390
 
382
391
  /**
383
392
  * Helpers to determine if a field is filled. This is `@prismicio/client`
384
393
  * {@link isFilled} object.
385
394
  */
386
- isFilled: typeof isFilled;
395
+ isFilled: typeof isFilled
387
396
 
388
397
  /**
389
398
  * Converts a document into a link field. This is `@prismicio/client`
@@ -391,8 +400,8 @@ export type PrismicPluginHelpers = {
391
400
  *
392
401
  * @internal
393
402
  */
394
- documentToLinkField: typeof documentToLinkField;
395
- };
403
+ documentToLinkField: typeof documentToLinkField
404
+ }
396
405
 
397
406
  /**
398
407
  * Methods and properties exposed by `@prismicio/vue` plugin and accessible
@@ -404,16 +413,16 @@ export type PrismicPlugin = {
404
413
  *
405
414
  * @see `@prismicio/vue` plugin options {@link PrismicPluginOptions}
406
415
  */
407
- readonly options: PrismicPluginOptions;
416
+ readonly options: PrismicPluginOptions
408
417
 
409
418
  /**
410
419
  * `@prismicio/vue` plugin install function used by Vue.
411
420
  *
412
421
  * @internal
413
422
  */
414
- install: (app: App) => void;
423
+ install: (app: App) => void
415
424
  } & PrismicPluginClient &
416
- PrismicPluginHelpers;
425
+ PrismicPluginHelpers
417
426
 
418
427
  /**
419
428
  * States of a `@prismicio/client` composable.
@@ -449,8 +458,8 @@ export const enum PrismicClientComposableState {
449
458
  * @internal
450
459
  */
451
460
  export type VueUseOptions<T> = {
452
- [K in keyof T]: Ref<T[K]> | T[K];
453
- };
461
+ [K in keyof T]: Ref<T[K]> | T[K]
462
+ }
454
463
 
455
464
  /**
456
465
  * Type to transform a static tuple into one that allows passing Refs as values.
@@ -458,5 +467,5 @@ export type VueUseOptions<T> = {
458
467
  * @internal
459
468
  */
460
469
  export type VueUseParameters<T> = {
461
- [K in keyof T]: T extends number ? Ref<T[K]> | T[K] : T[K];
462
- };
470
+ [K in keyof T]: T extends number ? Ref<T[K]> | T[K] : T[K]
471
+ }
package/src/usePrismic.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { inject } from "vue";
1
+ import { inject } from "vue"
2
2
 
3
- import { PrismicPlugin } from "./types";
3
+ import type { PrismicPlugin } from "./types"
4
4
 
5
- import { prismicKey } from "./injectionSymbols";
5
+ import { prismicKey } from "./injectionSymbols"
6
6
 
7
7
  /**
8
8
  * Accesses `@prismicio/vue` plugin interface.
@@ -11,19 +11,19 @@ import { prismicKey } from "./injectionSymbols";
11
11
  *
12
12
  * ```javascript
13
13
  * // With the composition API
14
- * import { usePrismic } from "@prismicio/vue";
14
+ * import { usePrismic } from "@prismicio/vue"
15
15
  *
16
16
  * export default {
17
17
  * setup() {
18
- * const prismic = usePrismic();
18
+ * const prismic = usePrismic()
19
19
  *
20
- * return {};
20
+ * return {}
21
21
  * },
22
- * };
22
+ * }
23
23
  * ```
24
24
  *
25
25
  * @returns The interface {@link PrismicPlugin}
26
26
  */
27
27
  export const usePrismic = (): PrismicPlugin => {
28
- return inject(prismicKey, { options: { endpoint: "" } } as PrismicPlugin);
29
- };
28
+ return inject(prismicKey, { options: { endpoint: "" } } as PrismicPlugin)
29
+ }
@@ -1,21 +1,23 @@
1
- import {
1
+ import type {
2
2
  Client,
3
3
  ForbiddenError,
4
4
  ParsingError,
5
5
  PrismicError,
6
- } from "@prismicio/client";
7
- import { Ref, isRef, ref, shallowRef, unref, watch } from "vue";
6
+ } from "@prismicio/client"
7
+ import type { Ref } from "vue"
8
+ import { isRef, ref, shallowRef, unref, watch } from "vue"
8
9
 
9
- import { PrismicClientComposableState, VueUseParameters } from "./types";
10
+ import type { VueUseParameters } from "./types"
11
+ import { PrismicClientComposableState } from "./types"
10
12
 
11
- import { usePrismic } from "./usePrismic";
13
+ import { usePrismic } from "./usePrismic"
12
14
 
13
15
  // Helpers
14
- type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
16
+ type UnwrapPromise<T> = T extends Promise<infer U> ? U : T
15
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- type ClientMethodLike = (...args: any[]) => Promise<any> | any;
17
- type ClientMethods = typeof Client.prototype;
18
- type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;
18
+ type ClientMethodLike = (...args: any[]) => Promise<any> | any
19
+ type ClientMethods = typeof Client.prototype
20
+ type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError
19
21
 
20
22
  // Interfaces
21
23
 
@@ -25,7 +27,7 @@ type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;
25
27
  export type ClientMethodParameters<TMethodName extends keyof ClientMethods> =
26
28
  ClientMethods[TMethodName] extends ClientMethodLike
27
29
  ? VueUseParameters<Parameters<ClientMethods[TMethodName]>>
28
- : never;
30
+ : never
29
31
 
30
32
  /**
31
33
  * @internal
@@ -33,14 +35,14 @@ export type ClientMethodParameters<TMethodName extends keyof ClientMethods> =
33
35
  export type ClientMethodReturnType<TMethodName extends keyof ClientMethods> =
34
36
  ClientMethods[TMethodName] extends ClientMethodLike
35
37
  ? ReturnType<ClientMethods[TMethodName]>
36
- : never;
38
+ : never
37
39
 
38
40
  /**
39
41
  * @internal
40
42
  */
41
43
  export type ComposableOnlyParameters = {
42
- client?: Ref<Client> | Client;
43
- };
44
+ client?: Ref<Client> | Client
45
+ }
44
46
 
45
47
  /**
46
48
  * The return type of a `@prismicio/client` Vue composable.
@@ -52,24 +54,24 @@ export type ClientComposableReturnType<TData = unknown> = {
52
54
  /**
53
55
  * The current state of the composable's client method call.
54
56
  */
55
- state: Ref<PrismicClientComposableState>;
57
+ state: Ref<PrismicClientComposableState>
56
58
 
57
59
  /**
58
60
  * Data returned by the client.
59
61
  */
60
- data: Ref<TData | null>;
62
+ data: Ref<TData | null>
61
63
 
62
64
  /**
63
65
  * Error returned by the composable's client method call if in an errror
64
66
  * state.
65
67
  */
66
- error: Ref<ClientError | Error | null>;
68
+ error: Ref<ClientError | Error | null>
67
69
 
68
70
  /**
69
71
  * Perform the composable's client method call again.
70
72
  */
71
- refresh: () => Promise<void>;
72
- };
73
+ refresh: () => Promise<void>
74
+ }
73
75
 
74
76
  /**
75
77
  * Determines if a value is a `@prismicio/client` params object.
@@ -83,8 +85,8 @@ const isParams = (
83
85
  value: unknown,
84
86
  ): value is ClientMethodParameters<"get">[0] & ComposableOnlyParameters => {
85
87
  // This is a *very* naive check.
86
- return typeof value === "object" && value !== null && !Array.isArray(value);
87
- };
88
+ return typeof value === "object" && value !== null && !Array.isArray(value)
89
+ }
88
90
 
89
91
  /**
90
92
  * A low level Vue composable that uses provided method name on plugin or
@@ -112,45 +114,45 @@ export const useStatefulPrismicClientMethod = <
112
114
  methodName: TClientMethodName,
113
115
  args: TClientMethodArguments,
114
116
  ): ClientComposableReturnType<TClientMethodReturnType> => {
115
- const { client } = usePrismic();
117
+ const { client } = usePrismic()
116
118
 
117
119
  const state = ref<PrismicClientComposableState>(
118
120
  PrismicClientComposableState.Idle,
119
- );
120
- const data = shallowRef<TClientMethodReturnType | null>(null);
121
- const error = ref<ClientError | Error | null>(null);
121
+ )
122
+ const data = shallowRef<TClientMethodReturnType | null>(null)
123
+ const error = ref<ClientError | Error | null>(null)
122
124
  const refresh = async (): Promise<void> => {
123
- const lastArg = unref(args[args.length - 1]);
125
+ const lastArg = unref(args[args.length - 1])
124
126
  const { client: explicitClient, ...params } = isParams(lastArg)
125
127
  ? (lastArg as ClientMethodParameters<"get">[0] & ComposableOnlyParameters)
126
- : ({} as ComposableOnlyParameters);
127
- const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
128
+ : ({} as ComposableOnlyParameters)
129
+ const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args
128
130
 
129
- state.value = PrismicClientComposableState.Pending;
130
- data.value = null;
131
- error.value = null;
131
+ state.value = PrismicClientComposableState.Pending
132
+ data.value = null
133
+ error.value = null
132
134
  try {
133
135
  data.value = await (
134
136
  (unref(explicitClient) || client)[methodName] as ClientMethodLike
135
137
  )(
136
138
  ...argsWithoutParams.map((arg: Ref<unknown> | unknown) => unref(arg)),
137
139
  params,
138
- );
139
- state.value = PrismicClientComposableState.Success;
140
+ )
141
+ state.value = PrismicClientComposableState.Success
140
142
  } catch (err) {
141
- state.value = PrismicClientComposableState.Error;
142
- error.value = err as ClientError | Error;
143
+ state.value = PrismicClientComposableState.Error
144
+ error.value = err as ClientError | Error
143
145
  }
144
- };
146
+ }
145
147
 
146
148
  // Watch reactive args
147
- const refArgs = args.filter((arg) => isRef(arg));
149
+ const refArgs = args.filter((arg) => isRef(arg))
148
150
  if (refArgs.length) {
149
- watch(refArgs, refresh, { deep: true });
151
+ watch(refArgs, refresh, { deep: true })
150
152
  }
151
153
 
152
154
  // Fetch once
153
- refresh();
155
+ refresh()
154
156
 
155
- return { state, data, error, refresh };
156
- };
157
+ return { state, data, error, refresh }
158
+ }