@prismicio/vue 3.0.0-beta.1 → 3.0.0-beta.2
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 +78 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +340 -43
- package/dist/index.js +79 -9
- package/dist/index.js.map +1 -1
- package/package.json +24 -21
- package/src/components/PrismicImage.ts +189 -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 +5 -1
- package/src/components/index.ts +6 -2
- package/src/composables.ts +54 -0
- package/src/createPrismic.ts +9 -3
- package/src/index.ts +2 -0
- package/src/lib/getSlots.ts +1 -0
- package/src/lib/simplyResolveComponent.ts +1 -0
- package/src/types.ts +24 -0
- package/src/useStatefulPrismicClientMethod.ts +2 -0
- package/vetur/attributes.json +10 -2
- package/vetur/tags.json +3 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ For more clarity on this project and its structure you can also check out the de
|
|
|
52
52
|
## License
|
|
53
53
|
|
|
54
54
|
```
|
|
55
|
-
Copyright 2013-
|
|
55
|
+
Copyright 2013-2022 Prismic <contact@prismic.io> (https://prismic.io)
|
|
56
56
|
|
|
57
57
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
58
58
|
you may not use this file except in compliance with the License.
|
package/dist/index.cjs
CHANGED
|
@@ -66,6 +66,62 @@ const usePrismic = () => {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
const defaultImageComponent = "img";
|
|
69
|
+
const usePrismicImage = (props) => {
|
|
70
|
+
const asImage = vue.computed(() => {
|
|
71
|
+
const field = vue.unref(props.field);
|
|
72
|
+
if (!helpers.isFilled.image(field)) {
|
|
73
|
+
return {
|
|
74
|
+
src: null,
|
|
75
|
+
srcset: null
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const imgixParams = vue.unref(props.imgixParams);
|
|
79
|
+
const widths = vue.unref(props.widths);
|
|
80
|
+
const pixelDensities = vue.unref(props.pixelDensities);
|
|
81
|
+
if (widths) {
|
|
82
|
+
if (pixelDensities) {
|
|
83
|
+
console.warn("[PrismicImage] `widths` and `pixelDensities` props should not be use alongside each others, only `widths` will be applied", props);
|
|
84
|
+
}
|
|
85
|
+
if (widths === "auto") {
|
|
86
|
+
return helpers.asImageWidthSrcSet(field, imgixParams);
|
|
87
|
+
} else {
|
|
88
|
+
const { url, dimensions, alt: alt2, copyright: copyright2 } = field;
|
|
89
|
+
return helpers.asImageWidthSrcSet({ url, dimensions, alt: alt2, copyright: copyright2 }, {
|
|
90
|
+
...imgixParams,
|
|
91
|
+
widths: widths === "defaults" ? void 0 : widths
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} else if (pixelDensities) {
|
|
95
|
+
return helpers.asImagePixelDensitySrcSet(field, {
|
|
96
|
+
...imgixParams,
|
|
97
|
+
pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
return {
|
|
101
|
+
src: helpers.asImageSrc(field, imgixParams),
|
|
102
|
+
srcset: null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const src = vue.computed(() => {
|
|
107
|
+
return asImage.value.src;
|
|
108
|
+
});
|
|
109
|
+
const srcset = vue.computed(() => {
|
|
110
|
+
return asImage.value.srcset;
|
|
111
|
+
});
|
|
112
|
+
const alt = vue.computed(() => {
|
|
113
|
+
return vue.unref(props.field).alt || null;
|
|
114
|
+
});
|
|
115
|
+
const copyright = vue.computed(() => {
|
|
116
|
+
return vue.unref(props.field).copyright || null;
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
src,
|
|
120
|
+
srcset,
|
|
121
|
+
alt,
|
|
122
|
+
copyright
|
|
123
|
+
};
|
|
124
|
+
};
|
|
69
125
|
const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
70
126
|
name: "PrismicImage",
|
|
71
127
|
props: {
|
|
@@ -78,10 +134,20 @@ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
78
134
|
default: void 0,
|
|
79
135
|
required: false
|
|
80
136
|
},
|
|
81
|
-
|
|
137
|
+
imgixParams: {
|
|
82
138
|
type: Object,
|
|
83
139
|
default: void 0,
|
|
84
140
|
required: false
|
|
141
|
+
},
|
|
142
|
+
widths: {
|
|
143
|
+
type: [String, Object],
|
|
144
|
+
default: void 0,
|
|
145
|
+
required: false
|
|
146
|
+
},
|
|
147
|
+
pixelDensities: {
|
|
148
|
+
type: [String, Object],
|
|
149
|
+
default: void 0,
|
|
150
|
+
required: false
|
|
85
151
|
}
|
|
86
152
|
},
|
|
87
153
|
setup(props) {
|
|
@@ -93,10 +159,12 @@ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
93
159
|
var _a;
|
|
94
160
|
return props.imageComponent || ((_a = options.components) == null ? void 0 : _a.imageComponent) || defaultImageComponent;
|
|
95
161
|
});
|
|
162
|
+
const { src, srcset, alt, copyright } = usePrismicImage(props);
|
|
96
163
|
return () => {
|
|
97
164
|
const attributes = {
|
|
98
|
-
src:
|
|
99
|
-
|
|
165
|
+
src: src.value,
|
|
166
|
+
srcset: srcset.value,
|
|
167
|
+
alt: alt.value
|
|
100
168
|
};
|
|
101
169
|
switch (type.value) {
|
|
102
170
|
case "img":
|
|
@@ -104,8 +172,7 @@ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
104
172
|
default:
|
|
105
173
|
return vue.h(simplyResolveComponent(type.value), {
|
|
106
174
|
...attributes,
|
|
107
|
-
copyright:
|
|
108
|
-
...props.imageComponentAdditionalProps
|
|
175
|
+
copyright: copyright.value
|
|
109
176
|
});
|
|
110
177
|
}
|
|
111
178
|
};
|
|
@@ -243,7 +310,7 @@ const PrismicLink = PrismicLinkImpl;
|
|
|
243
310
|
const defaultWrapper$1 = "div";
|
|
244
311
|
const usePrismicText = (props) => {
|
|
245
312
|
const text = vue.computed(() => {
|
|
246
|
-
return helpers.asText(vue.unref(props.field), vue.unref(props.separator));
|
|
313
|
+
return helpers.asText(vue.unref(props.field), vue.unref(props.separator)) || "";
|
|
247
314
|
});
|
|
248
315
|
return {
|
|
249
316
|
text
|
|
@@ -289,7 +356,7 @@ const usePrismicRichText = (props) => {
|
|
|
289
356
|
var _a, _b;
|
|
290
357
|
const linkResolver = (_a = vue.unref(props.linkResolver)) != null ? _a : options.linkResolver;
|
|
291
358
|
const htmlSerializer = (_b = vue.unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
|
|
292
|
-
return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer);
|
|
359
|
+
return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer) || "";
|
|
293
360
|
});
|
|
294
361
|
return {
|
|
295
362
|
html
|
|
@@ -532,6 +599,9 @@ const createPrismic = (options) => {
|
|
|
532
599
|
return helpers.asLink(linkField, linkResolver || options.linkResolver);
|
|
533
600
|
},
|
|
534
601
|
asDate: helpers.asDate,
|
|
602
|
+
asImageSrc: helpers.asImageSrc,
|
|
603
|
+
asImageWidthSrcSet: helpers.asImageWidthSrcSet,
|
|
604
|
+
asImagePixelDensitySrcSet: helpers.asImagePixelDensitySrcSet,
|
|
535
605
|
documentToLinkField: helpers.documentToLinkField
|
|
536
606
|
};
|
|
537
607
|
const prismic = {
|
|
@@ -642,6 +712,7 @@ exports.usePrismicDocumentsBySomeTags = usePrismicDocumentsBySomeTags;
|
|
|
642
712
|
exports.usePrismicDocumentsByTag = usePrismicDocumentsByTag;
|
|
643
713
|
exports.usePrismicDocumentsByType = usePrismicDocumentsByType;
|
|
644
714
|
exports.usePrismicDocumentsByUIDs = usePrismicDocumentsByUIDs;
|
|
715
|
+
exports.usePrismicImage = usePrismicImage;
|
|
645
716
|
exports.usePrismicLink = usePrismicLink;
|
|
646
717
|
exports.usePrismicRichText = usePrismicRichText;
|
|
647
718
|
exports.usePrismicText = usePrismicText;
|