@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/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,64 @@ const usePrismic = () => {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
const defaultImageComponent = "img";
|
|
69
|
+
const usePrismicImage = (props) => {
|
|
70
|
+
const { options } = usePrismic();
|
|
71
|
+
const asImage = vue.computed(() => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const field = vue.unref(props.field);
|
|
74
|
+
if (!helpers.isFilled.image(field)) {
|
|
75
|
+
return {
|
|
76
|
+
src: null,
|
|
77
|
+
srcset: null
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const imgixParams = vue.unref(props.imgixParams);
|
|
81
|
+
const widths = vue.unref(props.widths);
|
|
82
|
+
const pixelDensities = vue.unref(props.pixelDensities);
|
|
83
|
+
if (widths) {
|
|
84
|
+
if (pixelDensities) {
|
|
85
|
+
console.warn("[PrismicImage] `widths` and `pixelDensities` props should not be use alongside each others, only `widths` will be applied", props);
|
|
86
|
+
}
|
|
87
|
+
if (widths === "auto") {
|
|
88
|
+
return helpers.asImageWidthSrcSet(field, imgixParams);
|
|
89
|
+
} else {
|
|
90
|
+
const { url, dimensions, alt: alt2, copyright: copyright2 } = field;
|
|
91
|
+
return helpers.asImageWidthSrcSet({ url, dimensions, alt: alt2, copyright: copyright2 }, {
|
|
92
|
+
...imgixParams,
|
|
93
|
+
widths: widths === "defaults" ? (_a = options.components) == null ? void 0 : _a.imageWidthSrcSetDefaults : widths
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
} else if (pixelDensities) {
|
|
97
|
+
return helpers.asImagePixelDensitySrcSet(field, {
|
|
98
|
+
...imgixParams,
|
|
99
|
+
pixelDensities: pixelDensities === "defaults" ? (_b = options.components) == null ? void 0 : _b.imagePixelDensitySrcSetDefaults : pixelDensities
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
return {
|
|
103
|
+
src: helpers.asImageSrc(field, imgixParams),
|
|
104
|
+
srcset: null
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const src = vue.computed(() => {
|
|
109
|
+
return asImage.value.src;
|
|
110
|
+
});
|
|
111
|
+
const srcset = vue.computed(() => {
|
|
112
|
+
return asImage.value.srcset;
|
|
113
|
+
});
|
|
114
|
+
const alt = vue.computed(() => {
|
|
115
|
+
return vue.unref(props.field).alt || "";
|
|
116
|
+
});
|
|
117
|
+
const copyright = vue.computed(() => {
|
|
118
|
+
return vue.unref(props.field).copyright || null;
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
src,
|
|
122
|
+
srcset,
|
|
123
|
+
alt,
|
|
124
|
+
copyright
|
|
125
|
+
};
|
|
126
|
+
};
|
|
69
127
|
const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
70
128
|
name: "PrismicImage",
|
|
71
129
|
props: {
|
|
@@ -78,10 +136,20 @@ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
78
136
|
default: void 0,
|
|
79
137
|
required: false
|
|
80
138
|
},
|
|
81
|
-
|
|
139
|
+
imgixParams: {
|
|
82
140
|
type: Object,
|
|
83
141
|
default: void 0,
|
|
84
142
|
required: false
|
|
143
|
+
},
|
|
144
|
+
widths: {
|
|
145
|
+
type: [String, Object],
|
|
146
|
+
default: void 0,
|
|
147
|
+
required: false
|
|
148
|
+
},
|
|
149
|
+
pixelDensities: {
|
|
150
|
+
type: [String, Object],
|
|
151
|
+
default: void 0,
|
|
152
|
+
required: false
|
|
85
153
|
}
|
|
86
154
|
},
|
|
87
155
|
setup(props) {
|
|
@@ -93,10 +161,12 @@ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
93
161
|
var _a;
|
|
94
162
|
return props.imageComponent || ((_a = options.components) == null ? void 0 : _a.imageComponent) || defaultImageComponent;
|
|
95
163
|
});
|
|
164
|
+
const { src, srcset, alt, copyright } = usePrismicImage(props);
|
|
96
165
|
return () => {
|
|
97
166
|
const attributes = {
|
|
98
|
-
src:
|
|
99
|
-
|
|
167
|
+
src: src.value,
|
|
168
|
+
srcset: srcset.value,
|
|
169
|
+
alt: alt.value
|
|
100
170
|
};
|
|
101
171
|
switch (type.value) {
|
|
102
172
|
case "img":
|
|
@@ -104,8 +174,7 @@ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
104
174
|
default:
|
|
105
175
|
return vue.h(simplyResolveComponent(type.value), {
|
|
106
176
|
...attributes,
|
|
107
|
-
copyright:
|
|
108
|
-
...props.imageComponentAdditionalProps
|
|
177
|
+
copyright: copyright.value
|
|
109
178
|
});
|
|
110
179
|
}
|
|
111
180
|
};
|
|
@@ -243,7 +312,7 @@ const PrismicLink = PrismicLinkImpl;
|
|
|
243
312
|
const defaultWrapper$1 = "div";
|
|
244
313
|
const usePrismicText = (props) => {
|
|
245
314
|
const text = vue.computed(() => {
|
|
246
|
-
return helpers.asText(vue.unref(props.field), vue.unref(props.separator));
|
|
315
|
+
return helpers.asText(vue.unref(props.field), vue.unref(props.separator)) || "";
|
|
247
316
|
});
|
|
248
317
|
return {
|
|
249
318
|
text
|
|
@@ -289,7 +358,7 @@ const usePrismicRichText = (props) => {
|
|
|
289
358
|
var _a, _b;
|
|
290
359
|
const linkResolver = (_a = vue.unref(props.linkResolver)) != null ? _a : options.linkResolver;
|
|
291
360
|
const htmlSerializer = (_b = vue.unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
|
|
292
|
-
return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer);
|
|
361
|
+
return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer) || "";
|
|
293
362
|
});
|
|
294
363
|
return {
|
|
295
364
|
html
|
|
@@ -392,7 +461,7 @@ const getSliceComponentProps = (propsHint) => ({
|
|
|
392
461
|
}
|
|
393
462
|
});
|
|
394
463
|
const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ vue.defineComponent({
|
|
395
|
-
name: "
|
|
464
|
+
name: "TODOSliceComponent",
|
|
396
465
|
props: getSliceComponentProps(),
|
|
397
466
|
setup(props) {
|
|
398
467
|
vue.watchEffect(() => {
|
|
@@ -500,23 +569,18 @@ const createPrismic = (options) => {
|
|
|
500
569
|
if (options.client) {
|
|
501
570
|
client$1 = options.client;
|
|
502
571
|
} else {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
let fetchFunction;
|
|
511
|
-
if (typeof globalThis.fetch === "function") {
|
|
512
|
-
fetchFunction = globalThis.fetch;
|
|
513
|
-
} else {
|
|
514
|
-
fetchFunction = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('isomorphic-unfetch')); })).default;
|
|
515
|
-
}
|
|
516
|
-
return await fetchFunction(endpoint2, options2);
|
|
572
|
+
client$1 = client.createClient(options.endpoint, {
|
|
573
|
+
fetch: async (endpoint, options2) => {
|
|
574
|
+
let fetchFunction;
|
|
575
|
+
if (typeof globalThis.fetch === "function") {
|
|
576
|
+
fetchFunction = globalThis.fetch;
|
|
577
|
+
} else {
|
|
578
|
+
fetchFunction = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('isomorphic-unfetch')); })).default;
|
|
517
579
|
}
|
|
518
|
-
|
|
519
|
-
|
|
580
|
+
return await fetchFunction(endpoint, options2);
|
|
581
|
+
},
|
|
582
|
+
...options.clientConfig
|
|
583
|
+
});
|
|
520
584
|
}
|
|
521
585
|
const prismicClient = {
|
|
522
586
|
client: client$1,
|
|
@@ -532,6 +596,9 @@ const createPrismic = (options) => {
|
|
|
532
596
|
return helpers.asLink(linkField, linkResolver || options.linkResolver);
|
|
533
597
|
},
|
|
534
598
|
asDate: helpers.asDate,
|
|
599
|
+
asImageSrc: helpers.asImageSrc,
|
|
600
|
+
asImageWidthSrcSet: helpers.asImageWidthSrcSet,
|
|
601
|
+
asImagePixelDensitySrcSet: helpers.asImagePixelDensitySrcSet,
|
|
535
602
|
documentToLinkField: helpers.documentToLinkField
|
|
536
603
|
};
|
|
537
604
|
const prismic = {
|
|
@@ -618,7 +685,6 @@ exports.PrismicLink = PrismicLink;
|
|
|
618
685
|
exports.PrismicRichText = PrismicRichText;
|
|
619
686
|
exports.PrismicText = PrismicText;
|
|
620
687
|
exports.SliceZone = SliceZone;
|
|
621
|
-
exports.SliceZoneImpl = SliceZoneImpl;
|
|
622
688
|
exports.TODOSliceComponent = TODOSliceComponent;
|
|
623
689
|
exports.createPrismic = createPrismic;
|
|
624
690
|
exports.dangerouslyUseAllPrismicDocuments = dangerouslyUseAllPrismicDocuments;
|
|
@@ -642,6 +708,7 @@ exports.usePrismicDocumentsBySomeTags = usePrismicDocumentsBySomeTags;
|
|
|
642
708
|
exports.usePrismicDocumentsByTag = usePrismicDocumentsByTag;
|
|
643
709
|
exports.usePrismicDocumentsByType = usePrismicDocumentsByType;
|
|
644
710
|
exports.usePrismicDocumentsByUIDs = usePrismicDocumentsByUIDs;
|
|
711
|
+
exports.usePrismicImage = usePrismicImage;
|
|
645
712
|
exports.usePrismicLink = usePrismicLink;
|
|
646
713
|
exports.usePrismicRichText = usePrismicRichText;
|
|
647
714
|
exports.usePrismicText = usePrismicText;
|