@prismicio/vue 3.2.1 → 4.0.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.
- package/dist/components/PrismicEmbed.cjs.map +1 -1
- package/dist/components/PrismicEmbed.d.ts +1 -1
- package/dist/components/PrismicEmbed.js.map +1 -1
- package/dist/components/PrismicImage.cjs +5 -5
- package/dist/components/PrismicImage.cjs.map +1 -1
- package/dist/components/PrismicImage.d.ts +1 -2
- package/dist/components/PrismicImage.js +1 -1
- package/dist/components/PrismicImage.js.map +1 -1
- package/dist/components/PrismicLink.cjs +2 -2
- package/dist/components/PrismicLink.cjs.map +1 -1
- package/dist/components/PrismicLink.d.ts +1 -2
- package/dist/components/PrismicLink.js +1 -1
- package/dist/components/PrismicLink.js.map +1 -1
- package/dist/components/PrismicRichText.cjs +3 -3
- package/dist/components/PrismicRichText.cjs.map +1 -1
- package/dist/components/PrismicRichText.d.ts +7 -8
- package/dist/components/PrismicRichText.js +1 -1
- package/dist/components/PrismicRichText.js.map +1 -1
- package/dist/components/PrismicText.cjs +3 -3
- package/dist/components/PrismicText.cjs.map +1 -1
- package/dist/components/PrismicText.d.ts +1 -1
- package/dist/components/PrismicText.js +1 -1
- package/dist/components/PrismicText.js.map +1 -1
- package/dist/components/SliceZone.cjs.map +1 -1
- package/dist/components/SliceZone.d.ts +8 -7
- package/dist/components/SliceZone.js.map +1 -1
- package/dist/composables.cjs.map +1 -1
- package/dist/composables.d.ts +19 -1
- package/dist/composables.js.map +1 -1
- package/dist/createPrismic.cjs +32 -12
- package/dist/createPrismic.cjs.map +1 -1
- package/dist/createPrismic.js +27 -7
- package/dist/createPrismic.js.map +1 -1
- package/dist/types.d.ts +27 -18
- package/package.json +4 -6
- package/src/components/PrismicEmbed.ts +1 -2
- package/src/components/PrismicImage.ts +2 -2
- package/src/components/PrismicLink.ts +6 -2
- package/src/components/PrismicRichText.ts +2 -2
- package/src/components/PrismicText.ts +1 -2
- package/src/components/SliceZone.ts +8 -8
- package/src/composables.ts +1 -1
- package/src/createPrismic.ts +44 -12
- package/src/types.ts +35 -26
package/src/createPrismic.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Client,
|
|
3
3
|
FetchLike,
|
|
4
|
-
|
|
5
|
-
createClient,
|
|
6
|
-
predicate,
|
|
7
|
-
} from "@prismicio/client";
|
|
8
|
-
import {
|
|
4
|
+
LinkResolverFunction,
|
|
9
5
|
asDate,
|
|
10
6
|
asHTML,
|
|
11
7
|
asImagePixelDensitySrcSet,
|
|
12
8
|
asImageSrc,
|
|
13
9
|
asImageWidthSrcSet,
|
|
14
10
|
asLink,
|
|
11
|
+
asLinkAttrs,
|
|
15
12
|
asText,
|
|
13
|
+
cookie,
|
|
14
|
+
createClient,
|
|
16
15
|
documentToLinkField,
|
|
17
|
-
|
|
16
|
+
filter,
|
|
17
|
+
} from "@prismicio/client";
|
|
18
18
|
import { App } from "vue";
|
|
19
19
|
|
|
20
20
|
import type {
|
|
@@ -67,22 +67,54 @@ export const createPrismic = (options: PrismicPluginOptions): PrismicPlugin => {
|
|
|
67
67
|
|
|
68
68
|
const prismicClient: PrismicPluginClient = {
|
|
69
69
|
client,
|
|
70
|
-
|
|
70
|
+
filter,
|
|
71
71
|
cookie,
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
// Create plugin helpers
|
|
75
75
|
const prismicHelpers: PrismicPluginHelpers = {
|
|
76
76
|
asText,
|
|
77
|
-
asHTML: (richTextField,
|
|
77
|
+
asHTML: (richTextField, ...config) => {
|
|
78
|
+
const [configOrLinkResolver, maybeHTMLSerializer] = config;
|
|
79
|
+
|
|
78
80
|
return asHTML(
|
|
79
81
|
richTextField,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
typeof configOrLinkResolver === "function" ||
|
|
83
|
+
configOrLinkResolver == null
|
|
84
|
+
? {
|
|
85
|
+
linkResolver: configOrLinkResolver || options.linkResolver,
|
|
86
|
+
serializer:
|
|
87
|
+
maybeHTMLSerializer ||
|
|
88
|
+
options.richTextSerializer ||
|
|
89
|
+
options.htmlSerializer,
|
|
90
|
+
}
|
|
91
|
+
: {
|
|
92
|
+
linkResolver: options.linkResolver,
|
|
93
|
+
serializer: options.richTextSerializer || options.htmlSerializer,
|
|
94
|
+
...configOrLinkResolver,
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
asLink: (linkField, config) => {
|
|
99
|
+
return asLink(
|
|
100
|
+
linkField,
|
|
101
|
+
typeof config === "function"
|
|
102
|
+
? { linkResolver: config }
|
|
103
|
+
: {
|
|
104
|
+
linkResolver: options.linkResolver,
|
|
105
|
+
// TODO: For some reasons, TypeScript narrows the type to "unknown" where it's supposed to be a union
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
...(config as any),
|
|
108
|
+
},
|
|
82
109
|
);
|
|
83
110
|
},
|
|
84
|
-
|
|
85
|
-
return
|
|
111
|
+
asLinkAttrs: (linkField, config) => {
|
|
112
|
+
return asLinkAttrs(linkField, {
|
|
113
|
+
// TODO: We can't really retrieve the generic type here, this might cause some unexpected type error in some edge-case scenario
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
|
+
linkResolver: options.linkResolver as LinkResolverFunction<any>,
|
|
116
|
+
...config,
|
|
117
|
+
});
|
|
86
118
|
},
|
|
87
119
|
asDate,
|
|
88
120
|
asImageSrc,
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ClientConfig,
|
|
3
3
|
CreateClient,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@prismicio/client";
|
|
7
|
-
import type {
|
|
8
|
-
HTMLFunctionSerializer,
|
|
9
|
-
HTMLMapSerializer,
|
|
4
|
+
HTMLRichTextFunctionSerializer,
|
|
5
|
+
HTMLRichTextMapSerializer,
|
|
10
6
|
LinkResolverFunction,
|
|
11
7
|
asDate,
|
|
12
8
|
asHTML,
|
|
@@ -14,9 +10,12 @@ import type {
|
|
|
14
10
|
asImageSrc,
|
|
15
11
|
asImageWidthSrcSet,
|
|
16
12
|
asLink,
|
|
13
|
+
asLinkAttrs,
|
|
17
14
|
asText,
|
|
15
|
+
cookie,
|
|
18
16
|
documentToLinkField,
|
|
19
|
-
|
|
17
|
+
filter,
|
|
18
|
+
} from "@prismicio/client";
|
|
20
19
|
import type { App, ConcreteComponent, DefineComponent, Raw, Ref } from "vue";
|
|
21
20
|
|
|
22
21
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
@@ -92,7 +91,7 @@ type PrismicPluginComponentsOptions = {
|
|
|
92
91
|
* Consider configuring image widths within your content type definition and
|
|
93
92
|
* using `widths="auto"` instead to give content writers the ability to crop
|
|
94
93
|
* images in the editor.
|
|
95
|
-
* @defaultValue `@prismicio/
|
|
94
|
+
* @defaultValue `@prismicio/client` defaults
|
|
96
95
|
*/
|
|
97
96
|
imageWidthSrcSetDefaults?: number[];
|
|
98
97
|
|
|
@@ -100,7 +99,7 @@ type PrismicPluginComponentsOptions = {
|
|
|
100
99
|
* Default pixel densities to use when rendering an image with
|
|
101
100
|
* `pixel-densities="defaults"`
|
|
102
101
|
*
|
|
103
|
-
* @defaultValue `@prismicio/
|
|
102
|
+
* @defaultValue `@prismicio/client` defaults
|
|
104
103
|
*/
|
|
105
104
|
imagePixelDensitySrcSetDefaults?: number[];
|
|
106
105
|
|
|
@@ -135,7 +134,9 @@ type PrismicPluginOptionsBase = {
|
|
|
135
134
|
*
|
|
136
135
|
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
137
136
|
*/
|
|
138
|
-
richTextSerializer?:
|
|
137
|
+
richTextSerializer?:
|
|
138
|
+
| HTMLRichTextFunctionSerializer
|
|
139
|
+
| HTMLRichTextMapSerializer;
|
|
139
140
|
|
|
140
141
|
/**
|
|
141
142
|
* An optional HTML serializer to customize the way rich text fields are
|
|
@@ -146,7 +147,7 @@ type PrismicPluginOptionsBase = {
|
|
|
146
147
|
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
147
148
|
*/
|
|
148
149
|
// TODO: Remove in v5
|
|
149
|
-
htmlSerializer?:
|
|
150
|
+
htmlSerializer?: HTMLRichTextFunctionSerializer | HTMLRichTextMapSerializer;
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
153
|
* Whether or not to inject components globally.
|
|
@@ -287,9 +288,9 @@ export type PrismicPluginClient = {
|
|
|
287
288
|
client: ReturnType<CreateClient>;
|
|
288
289
|
|
|
289
290
|
/**
|
|
290
|
-
* Query
|
|
291
|
+
* Query filters from `@prismicio/client`.
|
|
291
292
|
*/
|
|
292
|
-
|
|
293
|
+
filter: typeof filter;
|
|
293
294
|
|
|
294
295
|
/**
|
|
295
296
|
* Prismic cookies from `@prismicio/client`.
|
|
@@ -298,13 +299,13 @@ export type PrismicPluginClient = {
|
|
|
298
299
|
};
|
|
299
300
|
|
|
300
301
|
/**
|
|
301
|
-
* `@prismicio/
|
|
302
|
+
* `@prismicio/client` related methods exposed by `@prismicio/vue` plugin and
|
|
302
303
|
* accessible through `this.$prismic` and `usePrismic()`.
|
|
303
304
|
*/
|
|
304
305
|
export type PrismicPluginHelpers = {
|
|
305
306
|
/**
|
|
306
307
|
* Serializes a rich text or title field to a plain text string. This is
|
|
307
|
-
* `@prismicio/
|
|
308
|
+
* `@prismicio/client` {@link asText} function.
|
|
308
309
|
*
|
|
309
310
|
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
|
|
310
311
|
*/
|
|
@@ -312,7 +313,7 @@ export type PrismicPluginHelpers = {
|
|
|
312
313
|
|
|
313
314
|
/**
|
|
314
315
|
* Serializes a rich text or title field to an HTML string. This is
|
|
315
|
-
* `@prismicio/
|
|
316
|
+
* `@prismicio/client` {@link asHTML} function.
|
|
316
317
|
*
|
|
317
318
|
* @remarks
|
|
318
319
|
* If no `linkResolver` is provided the function will use the one provided to
|
|
@@ -326,34 +327,42 @@ export type PrismicPluginHelpers = {
|
|
|
326
327
|
|
|
327
328
|
/**
|
|
328
329
|
* Resolves any type of link field or document to a URL. This is
|
|
329
|
-
* `@prismicio/
|
|
330
|
+
* `@prismicio/client` {@link asLink} function.
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* If no `linkResolver` is provided the function will use the one provided to
|
|
334
|
+
* the plugin at {@link PrismicPluginOptions.linkResolver} if available.
|
|
335
|
+
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
|
|
336
|
+
*/
|
|
337
|
+
asLink: typeof asLink;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Resolves any type of link field or document to a set of link attributes.
|
|
341
|
+
* This is `@prismicio/client` {@link asLinkAttrs} function.
|
|
330
342
|
*
|
|
331
343
|
* @remarks
|
|
332
344
|
* If no `linkResolver` is provided the function will use the one provided to
|
|
333
345
|
* the plugin at {@link PrismicPluginOptions.linkResolver} if available.
|
|
334
346
|
* @see Templating link fields {@link https://prismic.io/docs/technologies/vue-template-content#links-and-content-relationships}
|
|
335
347
|
*/
|
|
336
|
-
|
|
337
|
-
linkField: Parameters<typeof asLink>[0],
|
|
338
|
-
linkResolver?: LinkResolverFunction,
|
|
339
|
-
) => string | null;
|
|
348
|
+
asLinkAttrs: typeof asLinkAttrs;
|
|
340
349
|
|
|
341
350
|
/**
|
|
342
351
|
* Transforms a date or timestamp field into a JavaScript Date object. This is
|
|
343
|
-
* `@prismicio/
|
|
352
|
+
* `@prismicio/client` {@link asDate} function.
|
|
344
353
|
*/
|
|
345
354
|
asDate: typeof asDate;
|
|
346
355
|
|
|
347
356
|
/**
|
|
348
357
|
* Returns the URL of an Image field with optional image transformations (via
|
|
349
|
-
* Imgix URL parameters). This is `@prismicio/
|
|
358
|
+
* Imgix URL parameters). This is `@prismicio/client` {@link asImageSrc}
|
|
350
359
|
* function.
|
|
351
360
|
*/
|
|
352
361
|
asImageSrc: typeof asImageSrc;
|
|
353
362
|
|
|
354
363
|
/**
|
|
355
364
|
* Creates a width-based `srcset` from an Image field with optional image
|
|
356
|
-
* transformations (via Imgix URL parameters). This is `@prismicio/
|
|
365
|
+
* transformations (via Imgix URL parameters). This is `@prismicio/client`
|
|
357
366
|
* {@link asImageWidthSrcSet} function.
|
|
358
367
|
*/
|
|
359
368
|
asImageWidthSrcSet: typeof asImageWidthSrcSet;
|
|
@@ -361,12 +370,12 @@ export type PrismicPluginHelpers = {
|
|
|
361
370
|
/**
|
|
362
371
|
* Creates a pixel-density-based `srcset` from an Image field with optional
|
|
363
372
|
* image transformations (via Imgix URL parameters). This is
|
|
364
|
-
* `@prismicio/
|
|
373
|
+
* `@prismicio/client` {@link asImagePixelDensitySrcSet} function.
|
|
365
374
|
*/
|
|
366
375
|
asImagePixelDensitySrcSet: typeof asImagePixelDensitySrcSet;
|
|
367
376
|
|
|
368
377
|
/**
|
|
369
|
-
* Converts a document into a link field. This is `@prismicio/
|
|
378
|
+
* Converts a document into a link field. This is `@prismicio/client`
|
|
370
379
|
* {@link documentToLinkField} function.
|
|
371
380
|
*
|
|
372
381
|
* @internal
|