@prismicio/vue 3.0.0-alpha.3 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/index.cjs +84 -80
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +690 -534
- package/dist/index.mjs +72 -66
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -32
- package/src/components/PrismicEmbed.ts +3 -1
- package/src/components/PrismicImage.ts +21 -35
- package/src/components/PrismicLink.ts +64 -44
- package/src/components/PrismicRichText.ts +47 -108
- package/src/components/PrismicText.ts +9 -5
- package/src/components/SliceZone.ts +151 -56
- package/src/components/index.ts +3 -1
- package/src/composables.ts +182 -95
- package/src/createPrismic.ts +3 -9
- package/src/index.ts +9 -4
- package/src/lib/__PRODUCTION__.ts +2 -1
- package/src/lib/getSlots.ts +2 -2
- package/src/lib/isInternalURL.ts +6 -2
- package/src/lib/simplyResolveComponent.ts +2 -2
- package/src/types.ts +118 -97
- package/src/usePrismic.ts +8 -9
- package/src/useStatefulPrismicClientMethod.ts +31 -17
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,
|
|
@@ -26,6 +25,7 @@ import type { RouterLink } from "vue-router";
|
|
|
26
25
|
|
|
27
26
|
import type {
|
|
28
27
|
SliceComponentProps,
|
|
28
|
+
SliceComponentType,
|
|
29
29
|
TODOSliceComponent,
|
|
30
30
|
} from "./components/SliceZone";
|
|
31
31
|
|
|
@@ -45,23 +45,29 @@ type PrismicPluginComponentsOptions = {
|
|
|
45
45
|
linkBlankTargetRelAttribute?: string;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* An HTML tag name, a component, or a functional component used to render
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
48
|
+
* An HTML tag name, a component, or a functional component used to render
|
|
49
|
+
* internal links.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* HTML tag names will be rendered using the anchor tag interface (`href`,
|
|
53
|
+
* `target`, and `rel` attributes).
|
|
54
|
+
* @remarks
|
|
55
|
+
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
56
|
+
* (`to` props).
|
|
54
57
|
* @defaultValue {@link RouterLink}
|
|
55
58
|
*/
|
|
56
59
|
linkInternalComponent?: string | ConcreteComponent;
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
|
-
* An HTML tag name, a component, or a functional component used to render
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* An HTML tag name, a component, or a functional component used to render
|
|
63
|
+
* external links.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* HTML tag names will be rendered using the anchor tag interface (`href`,
|
|
67
|
+
* `target`, and `rel` attributes).
|
|
68
|
+
* @remarks
|
|
69
|
+
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
70
|
+
* (`to` props).
|
|
65
71
|
* @defaultValue `"a"`
|
|
66
72
|
*/
|
|
67
73
|
linkExternalComponent?: string | ConcreteComponent;
|
|
@@ -69,20 +75,23 @@ type PrismicPluginComponentsOptions = {
|
|
|
69
75
|
/**
|
|
70
76
|
* An HTML tag name, a component, or a functional component used to render images.
|
|
71
77
|
*
|
|
72
|
-
* @remarks
|
|
73
|
-
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* HTML tag names and components will be rendered using the `img` tag
|
|
80
|
+
* interface (`src` and `alt` attribute). Components will also receive an
|
|
81
|
+
* additional `copyright` props.
|
|
74
82
|
* @defaultValue `"img"`
|
|
75
83
|
*/
|
|
76
84
|
imageComponent?: string | ConcreteComponent;
|
|
77
85
|
|
|
78
86
|
/**
|
|
79
|
-
* A component or a functional component rendered if a component mapping from
|
|
80
|
-
*
|
|
81
|
-
* @remarks Components will be rendered using the {@link SliceComponentProps} interface.
|
|
87
|
+
* A component or a functional component rendered if a component mapping from
|
|
88
|
+
* the `components` prop cannot be found.
|
|
82
89
|
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* Components will be rendered using the {@link SliceComponentProps} interface.
|
|
83
92
|
* @defaultValue `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}
|
|
84
93
|
*/
|
|
85
|
-
sliceZoneDefaultComponent?:
|
|
94
|
+
sliceZoneDefaultComponent?: SliceComponentType;
|
|
86
95
|
};
|
|
87
96
|
|
|
88
97
|
/**
|
|
@@ -90,7 +99,8 @@ type PrismicPluginComponentsOptions = {
|
|
|
90
99
|
*/
|
|
91
100
|
type PrismicPluginOptionsBase = {
|
|
92
101
|
/**
|
|
93
|
-
* An optional link resolver function used to resolve links to Prismic
|
|
102
|
+
* An optional link resolver function used to resolve links to Prismic
|
|
103
|
+
* documents when not using the route resolver parameter with `@prismicio/client`.
|
|
94
104
|
*
|
|
95
105
|
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
96
106
|
*/
|
|
@@ -125,10 +135,13 @@ type PrismicPluginOptionsBase = {
|
|
|
125
135
|
*/
|
|
126
136
|
type PrismicPluginOptionsWithClient = PrismicPluginOptionsBase & {
|
|
127
137
|
/**
|
|
128
|
-
* A `@prismicio/client` instance used to fetch content from a Prismic
|
|
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`.
|
|
138
|
+
* A `@prismicio/client` instance used to fetch content from a Prismic
|
|
139
|
+
* repository to configure the plugin with.
|
|
131
140
|
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* The client will be used by `@prismicio/vue` composables, such as
|
|
143
|
+
* {@link usePrismicDocuments} and exposed through `this.$prismic.client` and
|
|
144
|
+
* `usePrismic().client`.
|
|
132
145
|
* @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
|
|
133
146
|
*/
|
|
134
147
|
client: Client;
|
|
@@ -155,62 +168,57 @@ type PrismicPluginOptionsWithClient = PrismicPluginOptionsBase & {
|
|
|
155
168
|
*/
|
|
156
169
|
type PrismicPluginOptionsWithEndpoint = PrismicPluginOptionsBase & {
|
|
157
170
|
/**
|
|
158
|
-
* A Prismic repository endpoint to init the plugin's `@prismicio/client`
|
|
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`.
|
|
171
|
+
* A Prismic repository endpoint to init the plugin's `@prismicio/client`
|
|
172
|
+
* instance used to fetch content from a Prismic repository with.
|
|
161
173
|
*
|
|
162
|
-
* @
|
|
174
|
+
* @remarks
|
|
175
|
+
* Said client will be used by `@prismicio/vue` composables, such as
|
|
176
|
+
* {@link usePrismicDocuments} and exposed through `this.$prismic.client` and
|
|
177
|
+
* `usePrismic().client`.
|
|
178
|
+
* @example A repository ID:
|
|
163
179
|
*
|
|
164
|
-
*
|
|
165
|
-
* A repository ID:
|
|
180
|
+
* "my-repo";
|
|
166
181
|
*
|
|
167
|
-
*
|
|
168
|
-
* "my-repo"
|
|
169
|
-
* ```
|
|
182
|
+
* @example A full repository endpoint:
|
|
170
183
|
*
|
|
171
|
-
*
|
|
172
|
-
* A full repository endpoint:
|
|
184
|
+
* "https://my-repo.cdn.prismic.io/api/v2";
|
|
173
185
|
*
|
|
174
|
-
*
|
|
175
|
-
* "https://my-repo.cdn.prismic.io/api/v2"
|
|
176
|
-
* ```
|
|
186
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
|
|
177
187
|
*/
|
|
178
188
|
endpoint: string;
|
|
179
189
|
|
|
180
190
|
/**
|
|
181
191
|
* An optional object to configure `@prismicio/client` instance further.
|
|
182
192
|
*
|
|
183
|
-
* @
|
|
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:
|
|
193
|
+
* @example Accessing a private private repository:
|
|
188
194
|
*
|
|
189
|
-
* ```
|
|
195
|
+
* ```javascript
|
|
190
196
|
* {
|
|
191
|
-
*
|
|
197
|
+
* "accessToken": "abc"
|
|
192
198
|
* }
|
|
193
199
|
* ```
|
|
194
200
|
*
|
|
195
|
-
* @example
|
|
196
|
-
* Using a route resolver:
|
|
201
|
+
* @example Using a route resolver:
|
|
197
202
|
*
|
|
198
|
-
* ```
|
|
203
|
+
* ```javascript
|
|
199
204
|
* {
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
205
|
+
* "defaultParams": {
|
|
206
|
+
* "routes": [
|
|
207
|
+
* {
|
|
208
|
+
* "type": "page",
|
|
209
|
+
* "path": "/:uid"
|
|
210
|
+
* },
|
|
211
|
+
* {
|
|
212
|
+
* "type": "post",
|
|
213
|
+
* "path": "/blog/:uid"
|
|
214
|
+
* }
|
|
215
|
+
* ]
|
|
216
|
+
* }
|
|
212
217
|
* }
|
|
213
218
|
* ```
|
|
219
|
+
*
|
|
220
|
+
* @see Prismic client documentation {@link https://prismic.io/docs/technologies/javascript}
|
|
221
|
+
* @see Route resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
|
|
214
222
|
*/
|
|
215
223
|
clientConfig?: ClientConfig;
|
|
216
224
|
|
|
@@ -233,46 +241,60 @@ export type PrismicPluginOptions =
|
|
|
233
241
|
| PrismicPluginOptionsWithEndpoint;
|
|
234
242
|
|
|
235
243
|
/**
|
|
236
|
-
* `@prismicio/client` related methods and properties exposed by
|
|
244
|
+
* `@prismicio/client` related methods and properties exposed by
|
|
245
|
+
* `@prismicio/vue` plugin and accessible through `this.$prismic` and `usePrismic()`.
|
|
237
246
|
*/
|
|
238
247
|
export type PrismicPluginClient = {
|
|
239
|
-
/**
|
|
248
|
+
/**
|
|
249
|
+
* A `@prismicio/client` instance.
|
|
250
|
+
*/
|
|
240
251
|
client: Client;
|
|
241
252
|
|
|
242
|
-
/**
|
|
253
|
+
/**
|
|
254
|
+
* Query predicates from `@prismicio/client`.
|
|
255
|
+
*/
|
|
243
256
|
predicate: typeof predicate;
|
|
244
257
|
|
|
245
|
-
/**
|
|
258
|
+
/**
|
|
259
|
+
* Prismic cookies from `@prismicio/client`.
|
|
260
|
+
*/
|
|
246
261
|
cookie: typeof cookie;
|
|
247
262
|
};
|
|
248
263
|
|
|
249
264
|
/**
|
|
250
|
-
* `@prismicio/helpers` related methods exposed by `@prismicio/vue` plugin and
|
|
265
|
+
* `@prismicio/helpers` related methods exposed by `@prismicio/vue` plugin and
|
|
266
|
+
* accessible through `this.$prismic` and `usePrismic()`.
|
|
251
267
|
*/
|
|
252
268
|
export type PrismicPluginHelpers = {
|
|
253
269
|
/**
|
|
254
|
-
* Serializes a rich text or title field to a plain text string. This is
|
|
270
|
+
* Serializes a rich text or title field to a plain text string. This is
|
|
271
|
+
* `@prismicio/helpers` {@link asText} function.
|
|
255
272
|
*
|
|
256
273
|
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
|
|
257
274
|
*/
|
|
258
275
|
asText: typeof asText;
|
|
259
276
|
|
|
260
277
|
/**
|
|
261
|
-
* Serializes a rich text or title field to an HTML string. This is
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
278
|
+
* Serializes a rich text or title field to an HTML string. This is
|
|
279
|
+
* `@prismicio/helpers` {@link asHTML} function.
|
|
280
|
+
*
|
|
281
|
+
* @remarks
|
|
282
|
+
* If no `linkResolver` is provided the function will use the one provided to
|
|
283
|
+
* the plugin at {@link PrismicPluginOptions.linkResolver} if available.
|
|
284
|
+
* @remarks
|
|
285
|
+
* If no `htmlSerializer` is provided the function will use the one provided
|
|
286
|
+
* to the plugin at {@link PrismicPluginOptions.htmlSerializer} if available.
|
|
267
287
|
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
|
|
268
288
|
*/
|
|
269
289
|
asHTML: typeof asHTML;
|
|
270
290
|
|
|
271
291
|
/**
|
|
272
|
-
* Resolves any type of link field to a URL. This is
|
|
273
|
-
*
|
|
274
|
-
* @remarks If no `linkResolver` is provided the function will use the one provided to the plugin at {@link PrismicPluginOptions.linkResolver} if available.
|
|
292
|
+
* Resolves any type of link field or document to a URL. This is
|
|
293
|
+
* `@prismicio/helpers` {@link asLink} function.
|
|
275
294
|
*
|
|
295
|
+
* @remarks
|
|
296
|
+
* If no `linkResolver` is provided the function will use the one provided to
|
|
297
|
+
* the plugin at {@link PrismicPluginOptions.linkResolver} if available.
|
|
276
298
|
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
|
|
277
299
|
*/
|
|
278
300
|
asLink: (
|
|
@@ -281,30 +303,23 @@ export type PrismicPluginHelpers = {
|
|
|
281
303
|
) => string | null;
|
|
282
304
|
|
|
283
305
|
/**
|
|
284
|
-
* Transforms a date or timestamp field into a JavaScript Date object. This is
|
|
306
|
+
* Transforms a date or timestamp field into a JavaScript Date object. This is
|
|
307
|
+
* `@prismicio/helpers` {@link asDate} function.
|
|
285
308
|
*/
|
|
286
309
|
asDate: typeof asDate;
|
|
287
310
|
|
|
288
311
|
/**
|
|
289
|
-
* Converts a document into a link field. This is `@prismicio/helpers`
|
|
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.
|
|
312
|
+
* Converts a document into a link field. This is `@prismicio/helpers`
|
|
313
|
+
* {@link documentToLinkField} function.
|
|
297
314
|
*
|
|
298
|
-
* @
|
|
315
|
+
* @internal
|
|
299
316
|
*/
|
|
300
|
-
|
|
301
|
-
prismicDocument: Parameters<typeof documentAsLink>[0],
|
|
302
|
-
linkResolver?: LinkResolverFunction,
|
|
303
|
-
) => string | null;
|
|
317
|
+
documentToLinkField: typeof documentToLinkField;
|
|
304
318
|
};
|
|
305
319
|
|
|
306
320
|
/**
|
|
307
|
-
* Methods and properties exposed by `@prismicio/vue` plugin and accessible
|
|
321
|
+
* Methods and properties exposed by `@prismicio/vue` plugin and accessible
|
|
322
|
+
* through `this.$prismic` and `usePrismic()`.
|
|
308
323
|
*/
|
|
309
324
|
export type PrismicPlugin = {
|
|
310
325
|
/**
|
|
@@ -327,24 +342,31 @@ export type PrismicPlugin = {
|
|
|
327
342
|
* States of a `@prismicio/client` composable.
|
|
328
343
|
*/
|
|
329
344
|
export const enum PrismicClientComposableState {
|
|
330
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* The composable has not started fetching.
|
|
347
|
+
*/
|
|
331
348
|
Idle = "idle",
|
|
332
349
|
|
|
333
|
-
/**
|
|
350
|
+
/**
|
|
351
|
+
* The composable is fetching data.
|
|
352
|
+
*/
|
|
334
353
|
Pending = "pending",
|
|
335
354
|
|
|
336
|
-
/**
|
|
355
|
+
/**
|
|
356
|
+
* The composable sucessfully fetched data.
|
|
357
|
+
*/
|
|
337
358
|
Success = "success",
|
|
338
359
|
|
|
339
|
-
/**
|
|
360
|
+
/**
|
|
361
|
+
* The composable failed to fetch data.
|
|
362
|
+
*/
|
|
340
363
|
Error = "error",
|
|
341
364
|
}
|
|
342
365
|
|
|
343
366
|
// Helpers
|
|
344
367
|
|
|
345
368
|
/**
|
|
346
|
-
* Type to transform a static object into one that allows passing Refs as
|
|
347
|
-
* values.
|
|
369
|
+
* Type to transform a static object into one that allows passing Refs as values.
|
|
348
370
|
*
|
|
349
371
|
* @internal
|
|
350
372
|
*/
|
|
@@ -353,8 +375,7 @@ export type VueUseOptions<T> = {
|
|
|
353
375
|
};
|
|
354
376
|
|
|
355
377
|
/**
|
|
356
|
-
* Type to transform a static tuple into one that allows passing Refs as
|
|
357
|
-
* values.
|
|
378
|
+
* Type to transform a static tuple into one that allows passing Refs as values.
|
|
358
379
|
*
|
|
359
380
|
* @internal
|
|
360
381
|
*/
|
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
|
-
* @
|
|
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
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* setup() {
|
|
16
|
+
* const prismic = usePrismic();
|
|
20
17
|
*
|
|
21
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* The current state of the composable's client method call.
|
|
53
|
+
*/
|
|
46
54
|
state: Ref<PrismicClientComposableState>;
|
|
47
55
|
|
|
48
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Data returned by the client.
|
|
58
|
+
*/
|
|
49
59
|
data: Ref<TData | null>;
|
|
50
60
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
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
|
-
/**
|
|
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
|
|
74
|
-
*
|
|
75
|
-
*
|
|
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
|
|