@prismicio/vue 3.0.0-alpha.1 → 3.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -11,7 +11,6 @@ import type {
11
11
  asHTML,
12
12
  asLink,
13
13
  asDate,
14
- documentAsLink,
15
14
  documentToLinkField,
16
15
  HTMLFunctionSerializer,
17
16
  HTMLMapSerializer,
@@ -45,23 +44,29 @@ type PrismicPluginComponentsOptions = {
45
44
  linkBlankTargetRelAttribute?: string;
46
45
 
47
46
  /**
48
- * An HTML tag name, a component, or a functional component used to render internal links.
49
- *
50
- * @remarks HTML tag names will be rendered using the anchor tag interface (`href`, `target`, and `rel` attributes).
51
- *
52
- * @remarks Components will be rendered using Vue Router {@link RouterLink} interface (`to` props).
53
- *
47
+ * An HTML tag name, a component, or a functional component used to render
48
+ * internal links.
49
+ *
50
+ * @remarks
51
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
52
+ * `target`, and `rel` attributes).
53
+ * @remarks
54
+ * Components will be rendered using Vue Router {@link RouterLink} interface
55
+ * (`to` props).
54
56
  * @defaultValue {@link RouterLink}
55
57
  */
56
58
  linkInternalComponent?: string | ConcreteComponent;
57
59
 
58
60
  /**
59
- * An HTML tag name, a component, or a functional component used to render external links.
60
- *
61
- * @remarks HTML tag names will be rendered using the anchor tag interface (`href`, `target`, and `rel` attributes).
62
- *
63
- * @remarks Components will be rendered using Vue Router {@link RouterLink} interface (`to` props).
64
- *
61
+ * An HTML tag name, a component, or a functional component used to render
62
+ * external links.
63
+ *
64
+ * @remarks
65
+ * HTML tag names will be rendered using the anchor tag interface (`href`,
66
+ * `target`, and `rel` attributes).
67
+ * @remarks
68
+ * Components will be rendered using Vue Router {@link RouterLink} interface
69
+ * (`to` props).
65
70
  * @defaultValue `"a"`
66
71
  */
67
72
  linkExternalComponent?: string | ConcreteComponent;
@@ -69,17 +74,20 @@ type PrismicPluginComponentsOptions = {
69
74
  /**
70
75
  * An HTML tag name, a component, or a functional component used to render images.
71
76
  *
72
- * @remarks HTML tag names and components will be rendered using the `img` tag interface (`src` and `alt` attribute). Components will also receive an additional `copyright` props.
73
- *
77
+ * @remarks
78
+ * HTML tag names and components will be rendered using the `img` tag
79
+ * interface (`src` and `alt` attribute). Components will also receive an
80
+ * additional `copyright` props.
74
81
  * @defaultValue `"img"`
75
82
  */
76
83
  imageComponent?: string | ConcreteComponent;
77
84
 
78
85
  /**
79
- * A component or a functional component rendered if a component mapping from the `components` prop cannot be found.
80
- *
81
- * @remarks Components will be rendered using the {@link SliceComponentProps} interface.
86
+ * A component or a functional component rendered if a component mapping from
87
+ * the `components` prop cannot be found.
82
88
  *
89
+ * @remarks
90
+ * Components will be rendered using the {@link SliceComponentProps} interface.
83
91
  * @defaultValue `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}
84
92
  */
85
93
  sliceZoneDefaultComponent?: string | ConcreteComponent;
@@ -90,7 +98,8 @@ type PrismicPluginComponentsOptions = {
90
98
  */
91
99
  type PrismicPluginOptionsBase = {
92
100
  /**
93
- * An optional link resolver function used to resolve links to Prismic documents when not using the route resolver parameter with `@prismicio/client`.
101
+ * An optional link resolver function used to resolve links to Prismic
102
+ * documents when not using the route resolver parameter with `@prismicio/client`.
94
103
  *
95
104
  * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
96
105
  */
@@ -125,10 +134,13 @@ type PrismicPluginOptionsBase = {
125
134
  */
126
135
  type PrismicPluginOptionsWithClient = PrismicPluginOptionsBase & {
127
136
  /**
128
- * A `@prismicio/client` instance used to fetch content from a Prismic repository to configure the plugin with.
129
- *
130
- * @remarks The client will be used by `@prismicio/vue` composables, such as {@link usePrismicDocuments} and exposed through `this.$prismic.client` and `usePrismic().client`.
137
+ * A `@prismicio/client` instance used to fetch content from a Prismic
138
+ * repository to configure the plugin with.
131
139
  *
140
+ * @remarks
141
+ * The client will be used by `@prismicio/vue` composables, such as
142
+ * {@link usePrismicDocuments} and exposed through `this.$prismic.client` and
143
+ * `usePrismic().client`.
132
144
  * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
133
145
  */
134
146
  client: Client;
@@ -155,62 +167,57 @@ type PrismicPluginOptionsWithClient = PrismicPluginOptionsBase & {
155
167
  */
156
168
  type PrismicPluginOptionsWithEndpoint = PrismicPluginOptionsBase & {
157
169
  /**
158
- * A Prismic repository endpoint to init the plugin's `@prismicio/client` instance used to fetch content from a Prismic repository with.
159
- *
160
- * @remarks Said client will be used by `@prismicio/vue` composables, such as {@link usePrismicDocuments} and exposed through `this.$prismic.client` and `usePrismic().client`.
170
+ * A Prismic repository endpoint to init the plugin's `@prismicio/client`
171
+ * instance used to fetch content from a Prismic repository with.
161
172
  *
162
- * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
173
+ * @remarks
174
+ * Said client will be used by `@prismicio/vue` composables, such as
175
+ * {@link usePrismicDocuments} and exposed through `this.$prismic.client` and
176
+ * `usePrismic().client`.
177
+ * @example A repository ID:
163
178
  *
164
- * @example
165
- * A repository ID:
179
+ * "my-repo";
166
180
  *
167
- * ```
168
- * "my-repo"
169
- * ```
181
+ * @example A full repository endpoint:
170
182
  *
171
- * @example
172
- * A full repository endpoint:
183
+ * "https://my-repo.cdn.prismic.io/api/v2";
173
184
  *
174
- * ```
175
- * "https://my-repo.cdn.prismic.io/api/v2"
176
- * ```
185
+ * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
177
186
  */
178
187
  endpoint: string;
179
188
 
180
189
  /**
181
190
  * An optional object to configure `@prismicio/client` instance further.
182
191
  *
183
- * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
184
- * @see Route resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
185
- *
186
- * @example
187
- * Accessing a private private repository:
192
+ * @example Accessing a private private repository:
188
193
  *
189
- * ```
194
+ * ```javascript
190
195
  * {
191
- * accessToken: "abc",
196
+ * "accessToken": "abc"
192
197
  * }
193
198
  * ```
194
199
  *
195
- * @example
196
- * Using a route resolver:
200
+ * @example Using a route resolver:
197
201
  *
198
- * ```
202
+ * ```javascript
199
203
  * {
200
- * defaultParams: {
201
- * routes: [
202
- * {
203
- * type: "page",
204
- * path: "/:uid"
205
- * },
206
- * {
207
- * type: "post",
208
- * path: "/blog/:uid"
209
- * }
210
- * ]
211
- * }
204
+ * "defaultParams": {
205
+ * "routes": [
206
+ * {
207
+ * "type": "page",
208
+ * "path": "/:uid"
209
+ * },
210
+ * {
211
+ * "type": "post",
212
+ * "path": "/blog/:uid"
213
+ * }
214
+ * ]
215
+ * }
212
216
  * }
213
217
  * ```
218
+ *
219
+ * @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
220
+ * @see Route resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
214
221
  */
215
222
  clientConfig?: ClientConfig;
216
223
 
@@ -233,46 +240,60 @@ export type PrismicPluginOptions =
233
240
  | PrismicPluginOptionsWithEndpoint;
234
241
 
235
242
  /**
236
- * `@prismicio/client` related methods and properties exposed by `@prismicio/vue` plugin and accessible through `this.$prismic` and `usePrismic()`.
243
+ * `@prismicio/client` related methods and properties exposed by
244
+ * `@prismicio/vue` plugin and accessible through `this.$prismic` and `usePrismic()`.
237
245
  */
238
246
  export type PrismicPluginClient = {
239
- /** A `@prismicio/client` instance. */
247
+ /**
248
+ * A `@prismicio/client` instance.
249
+ */
240
250
  client: Client;
241
251
 
242
- /** Query predicates from `@prismicio/client`. */
252
+ /**
253
+ * Query predicates from `@prismicio/client`.
254
+ */
243
255
  predicate: typeof predicate;
244
256
 
245
- /** Prismic cookies from `@prismicio/client`. */
257
+ /**
258
+ * Prismic cookies from `@prismicio/client`.
259
+ */
246
260
  cookie: typeof cookie;
247
261
  };
248
262
 
249
263
  /**
250
- * `@prismicio/helpers` related methods exposed by `@prismicio/vue` plugin and accessible through `this.$prismic` and `usePrismic()`.
264
+ * `@prismicio/helpers` related methods exposed by `@prismicio/vue` plugin and
265
+ * accessible through `this.$prismic` and `usePrismic()`.
251
266
  */
252
267
  export type PrismicPluginHelpers = {
253
268
  /**
254
- * Serializes a rich text or title field to a plain text string. This is `@prismicio/helpers` {@link asText} function.
269
+ * Serializes a rich text or title field to a plain text string. This is
270
+ * `@prismicio/helpers` {@link asText} function.
255
271
  *
256
272
  * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
257
273
  */
258
274
  asText: typeof asText;
259
275
 
260
276
  /**
261
- * Serializes a rich text or title field to an HTML string. This is `@prismicio/helpers` {@link asHTML} function.
262
- *
263
- * @remarks If no `linkResolver` is provided the function will use the one provided to the plugin at {@link PrismicPluginOptions.linkResolver} if available.
264
- *
265
- * @remarks If no `htmlSerializer` is provided the function will use the one provided to the plugin at {@link PrismicPluginOptions.htmlSerializer} if available.
266
- *
277
+ * Serializes a rich text or title field to an HTML string. This is
278
+ * `@prismicio/helpers` {@link asHTML} function.
279
+ *
280
+ * @remarks
281
+ * If no `linkResolver` is provided the function will use the one provided to
282
+ * the plugin at {@link PrismicPluginOptions.linkResolver} if available.
283
+ * @remarks
284
+ * If no `htmlSerializer` is provided the function will use the one provided
285
+ * to the plugin at {@link PrismicPluginOptions.htmlSerializer} if available.
267
286
  * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
268
287
  */
269
288
  asHTML: typeof asHTML;
270
289
 
271
290
  /**
272
- * Resolves any type of link field to a URL. This is `@prismicio/helpers` {@link asLink} function.
273
- *
274
- * @remarks If no `linkResolver` is provided the function will use the one provided to the plugin at {@link PrismicPluginOptions.linkResolver} if available.
291
+ * Resolves any type of link field or document to a URL. This is
292
+ * `@prismicio/helpers` {@link asLink} function.
275
293
  *
294
+ * @remarks
295
+ * If no `linkResolver` is provided the function will use the one provided to
296
+ * the plugin at {@link PrismicPluginOptions.linkResolver} if available.
276
297
  * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
277
298
  */
278
299
  asLink: (
@@ -281,30 +302,23 @@ export type PrismicPluginHelpers = {
281
302
  ) => string | null;
282
303
 
283
304
  /**
284
- * Transforms a date or timestamp field into a JavaScript Date object. This is `@prismicio/helpers` {@link asDate} function.
305
+ * Transforms a date or timestamp field into a JavaScript Date object. This is
306
+ * `@prismicio/helpers` {@link asDate} function.
285
307
  */
286
308
  asDate: typeof asDate;
287
309
 
288
310
  /**
289
- * Converts a document into a link field. This is `@prismicio/helpers` {@link documentToLinkField} function.
290
- */
291
- documentToLinkField: typeof documentToLinkField;
292
-
293
- /**
294
- * Resolves a document to a URL. This is `@prismicio/helpers` {@link documentAsLink} function.
295
- *
296
- * @remarks If no `linkResolver` is provided the function will use the one provided to the plugin at {@link PrismicPluginOptions.linkResolver} if available.
311
+ * Converts a document into a link field. This is `@prismicio/helpers`
312
+ * {@link documentToLinkField} function.
297
313
  *
298
- * @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
314
+ * @internal
299
315
  */
300
- documentAsLink: (
301
- prismicDocument: Parameters<typeof documentAsLink>[0],
302
- linkResolver?: LinkResolverFunction,
303
- ) => string | null;
316
+ documentToLinkField: typeof documentToLinkField;
304
317
  };
305
318
 
306
319
  /**
307
- * Methods and properties exposed by `@prismicio/vue` plugin and accessible through `this.$prismic` and `usePrismic()`.
320
+ * Methods and properties exposed by `@prismicio/vue` plugin and accessible
321
+ * through `this.$prismic` and `usePrismic()`.
308
322
  */
309
323
  export type PrismicPlugin = {
310
324
  /**
@@ -327,24 +341,31 @@ export type PrismicPlugin = {
327
341
  * States of a `@prismicio/client` composable.
328
342
  */
329
343
  export const enum PrismicClientComposableState {
330
- /** The composable has not started fetching. */
344
+ /**
345
+ * The composable has not started fetching.
346
+ */
331
347
  Idle = "idle",
332
348
 
333
- /** The composable is fetching data. */
349
+ /**
350
+ * The composable is fetching data.
351
+ */
334
352
  Pending = "pending",
335
353
 
336
- /** The composable sucessfully fetched data. */
354
+ /**
355
+ * The composable sucessfully fetched data.
356
+ */
337
357
  Success = "success",
338
358
 
339
- /** The composable failed to fetch data. */
359
+ /**
360
+ * The composable failed to fetch data.
361
+ */
340
362
  Error = "error",
341
363
  }
342
364
 
343
365
  // Helpers
344
366
 
345
367
  /**
346
- * Type to transform a static object into one that allows passing Refs as
347
- * values.
368
+ * Type to transform a static object into one that allows passing Refs as values.
348
369
  *
349
370
  * @internal
350
371
  */
@@ -353,8 +374,7 @@ export type VueUseOptions<T> = {
353
374
  };
354
375
 
355
376
  /**
356
- * Type to transform a static tuple into one that allows passing Refs as
357
- * values.
377
+ * Type to transform a static tuple into one that allows passing Refs as values.
358
378
  *
359
379
  * @internal
360
380
  */
package/src/usePrismic.ts CHANGED
@@ -6,22 +6,21 @@ import { PrismicPlugin } from "./types";
6
6
  /**
7
7
  * Accesses `@prismicio/vue` plugin interface.
8
8
  *
9
- * @returns The interface {@link PrismicPlugin}
10
- *
11
- * @example
12
- * With the composition API:
9
+ * @example With the composition API:
13
10
  *
14
- * ```
11
+ * ```javascript
15
12
  * import { usePrismic } from "@prismicio/vue";
16
13
  *
17
14
  * export default {
18
- * setup() {
19
- * const prismic = usePrismic();
15
+ * setup() {
16
+ * const prismic = usePrismic();
20
17
  *
21
- * return {}
22
- * },
18
+ * return {};
19
+ * },
23
20
  * };
24
21
  * ```
22
+ *
23
+ * @returns The interface {@link PrismicPlugin}
25
24
  */
26
25
  export const usePrismic = (): PrismicPlugin => {
27
26
  return inject(prismicKey, { options: { endpoint: "" } } as PrismicPlugin);
@@ -15,23 +15,29 @@ type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  type ClientMethodLike = (...args: any[]) => Promise<any> | any;
17
17
  type ClientMethods = typeof Client.prototype;
18
- type ClientError = PrismicError | ParsingError | ForbiddenError;
18
+ type ClientError = PrismicError<unknown> | ParsingError | ForbiddenError;
19
19
 
20
20
  // Interfaces
21
21
 
22
- /** @internal */
22
+ /**
23
+ * @internal
24
+ */
23
25
  export type ClientMethodParameters<TMethodName extends keyof ClientMethods> =
24
26
  ClientMethods[TMethodName] extends ClientMethodLike
25
27
  ? VueUseParameters<Parameters<ClientMethods[TMethodName]>>
26
28
  : never;
27
29
 
28
- /** @internal */
30
+ /**
31
+ * @internal
32
+ */
29
33
  export type ClientMethodReturnType<TMethodName extends keyof ClientMethods> =
30
34
  ClientMethods[TMethodName] extends ClientMethodLike
31
35
  ? ReturnType<ClientMethods[TMethodName]>
32
36
  : never;
33
37
 
34
- /** @internal */
38
+ /**
39
+ * @internal
40
+ */
35
41
  export type ComposableOnlyParameters = {
36
42
  client?: Ref<Client> | Client;
37
43
  };
@@ -42,16 +48,24 @@ export type ComposableOnlyParameters = {
42
48
  * @typeParam TData - The expected format of the `data` property of the returned object
43
49
  */
44
50
  export type ClientComposableReturnType<TData = unknown> = {
45
- /** The current state of the composable's client method call. */
51
+ /**
52
+ * The current state of the composable's client method call.
53
+ */
46
54
  state: Ref<PrismicClientComposableState>;
47
55
 
48
- /** Data returned by the client. */
56
+ /**
57
+ * Data returned by the client.
58
+ */
49
59
  data: Ref<TData | null>;
50
60
 
51
- /** Error returned by the composable's client method call if in an errror state. */
52
- error: Ref<ClientError | null>;
61
+ /**
62
+ * Error returned by the composable's client method call if in an errror state.
63
+ */
64
+ error: Ref<ClientError | Error | null>;
53
65
 
54
- /** Perform the composable's client method call again. */
66
+ /**
67
+ * Perform the composable's client method call again.
68
+ */
55
69
  refresh: () => Promise<void>;
56
70
  };
57
71
 
@@ -70,17 +84,17 @@ const isParams = (
70
84
  };
71
85
 
72
86
  /**
73
- * A low level Vue composable that uses provided method name on plugin or provided client with given arguments. The composable has its own internal state manager to report async status, such as pending or error statuses.
74
- *
75
- * @param method - The `@prismicio/client` method name to use
76
- * @param args - The arguments to use with requested method
77
- *
78
- * @returns The composable payload {@link ClientComposableReturnType}
87
+ * A low level Vue composable that uses provided method name on plugin or
88
+ * provided client with given arguments. The composable has its own internal
89
+ * state manager to report async status, such as pending or error statuses.
79
90
  *
80
91
  * @typeParam TClientMethodName - A method name from `@prismicio/client`
81
92
  * @typeParam TClientMethodArguments - The method expected arguments
82
93
  * @typeParam TClientMethodReturnType - The method expected return type
94
+ * @param method - The `@prismicio/client` method name to use
95
+ * @param args - The arguments to use with requested method
83
96
  *
97
+ * @returns The composable payload {@link ClientComposableReturnType}
84
98
  * @internal
85
99
  */
86
100
  export const useStatefulPrismicClientMethod = <
@@ -99,7 +113,7 @@ export const useStatefulPrismicClientMethod = <
99
113
  PrismicClientComposableState.Idle,
100
114
  );
101
115
  const data = shallowRef<TClientMethodReturnType | null>(null);
102
- const error = ref<ClientError | null>(null);
116
+ const error = ref<ClientError | Error | null>(null);
103
117
  const refresh = async (): Promise<void> => {
104
118
  const lastArg = unref(args[args.length - 1]);
105
119
  const { client: explicitClient, ...params } = isParams(lastArg)
@@ -120,7 +134,7 @@ export const useStatefulPrismicClientMethod = <
120
134
  state.value = PrismicClientComposableState.Success;
121
135
  } catch (err) {
122
136
  state.value = PrismicClientComposableState.Error;
123
- error.value = err;
137
+ error.value = err as ClientError | Error;
124
138
  }
125
139
  };
126
140