@prismicio/vue 3.0.0-beta.1 → 3.0.0-beta.4
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 +1 -1
- package/dist/index.cjs +92 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +326 -88
- package/dist/index.js +94 -27
- package/dist/index.js.map +1 -1
- package/package.json +24 -21
- package/src/components/PrismicImage.ts +196 -11
- package/src/components/PrismicLink.ts +1 -0
- package/src/components/PrismicRichText.ts +4 -1
- package/src/components/PrismicText.ts +2 -2
- package/src/components/SliceZone.ts +6 -2
- package/src/components/index.ts +6 -2
- package/src/composables.ts +54 -0
- package/src/createPrismic.ts +21 -31
- package/src/index.ts +2 -1
- package/src/lib/getSlots.ts +1 -0
- package/src/lib/simplyResolveComponent.ts +1 -0
- package/src/types.ts +43 -0
- package/src/useStatefulPrismicClientMethod.ts +2 -0
- package/vetur/attributes.json +10 -2
- package/vetur/tags.json +3 -1
package/src/createPrismic.ts
CHANGED
|
@@ -2,17 +2,19 @@ import { App } from "vue";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createClient,
|
|
5
|
-
getEndpoint,
|
|
6
5
|
predicate,
|
|
7
6
|
cookie,
|
|
8
7
|
Client,
|
|
9
8
|
FetchLike,
|
|
10
9
|
} from "@prismicio/client";
|
|
11
10
|
import {
|
|
12
|
-
|
|
11
|
+
asText,
|
|
13
12
|
asHTML,
|
|
14
13
|
asLink,
|
|
15
|
-
|
|
14
|
+
asDate,
|
|
15
|
+
asImageSrc,
|
|
16
|
+
asImageWidthSrcSet,
|
|
17
|
+
asImagePixelDensitySrcSet,
|
|
16
18
|
documentToLinkField,
|
|
17
19
|
} from "@prismicio/helpers";
|
|
18
20
|
|
|
@@ -38,6 +40,7 @@ import type {
|
|
|
38
40
|
* @param options - {@link PrismicPluginOptions}
|
|
39
41
|
*
|
|
40
42
|
* @returns `@prismicio/vue` plugin instance {@link PrismicPlugin}
|
|
43
|
+
*
|
|
41
44
|
* @see Prismic Official Vue.js documentation: {@link https://prismic.io/docs/technologies/vuejs}
|
|
42
45
|
* @see Plugin repository: {@link https://github.com/prismicio/prismic-vue}
|
|
43
46
|
*/
|
|
@@ -47,34 +50,19 @@ export const createPrismic = (options: PrismicPluginOptions): PrismicPlugin => {
|
|
|
47
50
|
if (options.client) {
|
|
48
51
|
client = options.client;
|
|
49
52
|
} else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
options.clientConfig &&
|
|
60
|
-
typeof options.clientConfig.fetch === "function"
|
|
61
|
-
) {
|
|
62
|
-
client = createClient(endpoint, options.clientConfig);
|
|
63
|
-
} else {
|
|
64
|
-
client = createClient(endpoint, {
|
|
65
|
-
...options.clientConfig,
|
|
66
|
-
fetch: async (endpoint, options) => {
|
|
67
|
-
let fetchFunction: FetchLike;
|
|
68
|
-
if (typeof globalThis.fetch === "function") {
|
|
69
|
-
fetchFunction = globalThis.fetch;
|
|
70
|
-
} else {
|
|
71
|
-
fetchFunction = (await import("isomorphic-unfetch")).default;
|
|
72
|
-
}
|
|
53
|
+
client = createClient(options.endpoint, {
|
|
54
|
+
fetch: async (endpoint, options) => {
|
|
55
|
+
let fetchFunction: FetchLike;
|
|
56
|
+
if (typeof globalThis.fetch === "function") {
|
|
57
|
+
fetchFunction = globalThis.fetch;
|
|
58
|
+
} else {
|
|
59
|
+
fetchFunction = (await import("isomorphic-unfetch")).default;
|
|
60
|
+
}
|
|
73
61
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
62
|
+
return await fetchFunction(endpoint, options);
|
|
63
|
+
},
|
|
64
|
+
...options.clientConfig,
|
|
65
|
+
});
|
|
78
66
|
}
|
|
79
67
|
|
|
80
68
|
const prismicClient: PrismicPluginClient = {
|
|
@@ -97,7 +85,9 @@ export const createPrismic = (options: PrismicPluginOptions): PrismicPlugin => {
|
|
|
97
85
|
return asLink(linkField, linkResolver || options.linkResolver);
|
|
98
86
|
},
|
|
99
87
|
asDate,
|
|
100
|
-
|
|
88
|
+
asImageSrc,
|
|
89
|
+
asImageWidthSrcSet,
|
|
90
|
+
asImagePixelDensitySrcSet,
|
|
101
91
|
documentToLinkField,
|
|
102
92
|
};
|
|
103
93
|
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { usePrismic } from "./usePrismic";
|
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
5
|
// Composables
|
|
6
|
+
usePrismicImage,
|
|
6
7
|
usePrismicLink,
|
|
7
8
|
usePrismicText,
|
|
8
9
|
usePrismicRichText,
|
|
@@ -16,11 +17,11 @@ export {
|
|
|
16
17
|
getSliceComponentProps,
|
|
17
18
|
TODOSliceComponent,
|
|
18
19
|
defineSliceZoneComponents,
|
|
19
|
-
SliceZoneImpl,
|
|
20
20
|
SliceZone,
|
|
21
21
|
} from "./components";
|
|
22
22
|
export type {
|
|
23
23
|
// Composables
|
|
24
|
+
UsePrismicImageOptions,
|
|
24
25
|
UsePrismicLinkOptions,
|
|
25
26
|
UsePrismicTextOptions,
|
|
26
27
|
UsePrismicRichTextOptions,
|
package/src/lib/getSlots.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { ConcreteComponent, resolveDynamicComponent, VNode } from "vue";
|
|
|
7
7
|
* @param component - An HTML tag name, a component, or a functional component
|
|
8
8
|
*
|
|
9
9
|
* @returns Resolved component as a {@link VNode} or provided `string`.
|
|
10
|
+
*
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
export const simplyResolveComponent = (
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,9 @@ import type {
|
|
|
15
15
|
HTMLFunctionSerializer,
|
|
16
16
|
HTMLMapSerializer,
|
|
17
17
|
LinkResolverFunction,
|
|
18
|
+
asImageSrc,
|
|
19
|
+
asImageWidthSrcSet,
|
|
20
|
+
asImagePixelDensitySrcSet,
|
|
18
21
|
} from "@prismicio/helpers";
|
|
19
22
|
|
|
20
23
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
@@ -83,12 +86,32 @@ type PrismicPluginComponentsOptions = {
|
|
|
83
86
|
*/
|
|
84
87
|
imageComponent?: string | ConcreteComponent;
|
|
85
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Default widths to use when rendering an image with `widths="defaults"`
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* Consider configuring image widths within your content type definition and
|
|
94
|
+
* using `widths="auto"` instead to give content writers the ability to crop
|
|
95
|
+
* images in the editor.
|
|
96
|
+
* @defaultValue `@prismicio/helpers` defaults
|
|
97
|
+
*/
|
|
98
|
+
imageWidthSrcSetDefaults?: number[];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Default pixel densities to use when rendering an image with
|
|
102
|
+
* `pixel-densities="defaults"`
|
|
103
|
+
*
|
|
104
|
+
* @defaultValue `@prismicio/helpers` defaults
|
|
105
|
+
*/
|
|
106
|
+
imagePixelDensitySrcSetDefaults?: number[];
|
|
107
|
+
|
|
86
108
|
/**
|
|
87
109
|
* A component or a functional component rendered if a component mapping from
|
|
88
110
|
* the `components` prop cannot be found.
|
|
89
111
|
*
|
|
90
112
|
* @remarks
|
|
91
113
|
* Components will be rendered using the {@link SliceComponentProps} interface.
|
|
114
|
+
*
|
|
92
115
|
* @defaultValue `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}
|
|
93
116
|
*/
|
|
94
117
|
sliceZoneDefaultComponent?: SliceComponentType;
|
|
@@ -308,6 +331,26 @@ export type PrismicPluginHelpers = {
|
|
|
308
331
|
*/
|
|
309
332
|
asDate: typeof asDate;
|
|
310
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Returns the URL of an Image field with optional image transformations (via
|
|
336
|
+
* Imgix URL parameters). This is `@prismicio/helpers` {@link asImageSrc} function.
|
|
337
|
+
*/
|
|
338
|
+
asImageSrc: typeof asImageSrc;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Creates a width-based `srcset` from an Image field with optional image
|
|
342
|
+
* transformations (via Imgix URL parameters). This is `@prismicio/helpers`
|
|
343
|
+
* {@link asImageWidthSrcSet} function.
|
|
344
|
+
*/
|
|
345
|
+
asImageWidthSrcSet: typeof asImageWidthSrcSet;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Creates a pixel-density-based `srcset` from an Image field with optional
|
|
349
|
+
* image transformations (via Imgix URL parameters). This is
|
|
350
|
+
* `@prismicio/helpers` {@link asImagePixelDensitySrcSet} function.
|
|
351
|
+
*/
|
|
352
|
+
asImagePixelDensitySrcSet: typeof asImagePixelDensitySrcSet;
|
|
353
|
+
|
|
311
354
|
/**
|
|
312
355
|
* Converts a document into a link field. This is `@prismicio/helpers`
|
|
313
356
|
* {@link documentToLinkField} function.
|
|
@@ -91,10 +91,12 @@ const isParams = (
|
|
|
91
91
|
* @typeParam TClientMethodName - A method name from `@prismicio/client`
|
|
92
92
|
* @typeParam TClientMethodArguments - The method expected arguments
|
|
93
93
|
* @typeParam TClientMethodReturnType - The method expected return type
|
|
94
|
+
*
|
|
94
95
|
* @param method - The `@prismicio/client` method name to use
|
|
95
96
|
* @param args - The arguments to use with requested method
|
|
96
97
|
*
|
|
97
98
|
* @returns The composable payload {@link ClientComposableReturnType}
|
|
99
|
+
*
|
|
98
100
|
* @internal
|
|
99
101
|
*/
|
|
100
102
|
export const useStatefulPrismicClientMethod = <
|
package/vetur/attributes.json
CHANGED
|
@@ -16,9 +16,17 @@
|
|
|
16
16
|
"type": "string | object | function",
|
|
17
17
|
"description": "An HTML tag name, a component, or a functional component used to render images. Defaults to the one provided to `@prismicio/vue` plugin if configured, `\"img\"` otherwise."
|
|
18
18
|
},
|
|
19
|
-
"prismic-image/
|
|
19
|
+
"prismic-image/imgix-params": {
|
|
20
20
|
"type": "object",
|
|
21
|
-
"description": "
|
|
21
|
+
"description": "An object of Imgix URL API parameters."
|
|
22
|
+
},
|
|
23
|
+
"prismic-image/widths": {
|
|
24
|
+
"type": "array | string",
|
|
25
|
+
"description": "Adds an additional `srcset` attribute to the image following given widths."
|
|
26
|
+
},
|
|
27
|
+
"prismic-image/pixel-densities": {
|
|
28
|
+
"type": "array | string",
|
|
29
|
+
"description": "Adds an additional `srcset` attribute to the image following giving pixel densities."
|
|
22
30
|
},
|
|
23
31
|
|
|
24
32
|
"prismic-link/field": {
|