@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/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { asLink, asText, asHTML, asDate, documentToLinkField } from '@prismicio/helpers';
|
|
1
|
+
import { createClient, predicate, cookie } from '@prismicio/client';
|
|
2
|
+
import { isFilled, asImageWidthSrcSet, asImagePixelDensitySrcSet, asImageSrc, asLink, asText, asHTML, asDate, documentToLinkField } from '@prismicio/helpers';
|
|
3
3
|
import { resolveDynamicComponent, defineComponent, h, inject, computed, unref, reactive, ref, watch, nextTick, onBeforeUnmount, watchEffect, markRaw, shallowRef, isRef } from 'vue';
|
|
4
4
|
import { routerKey } from 'vue-router';
|
|
5
5
|
|
|
@@ -44,6 +44,64 @@ const usePrismic = () => {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const defaultImageComponent = "img";
|
|
47
|
+
const usePrismicImage = (props) => {
|
|
48
|
+
const { options } = usePrismic();
|
|
49
|
+
const asImage = computed(() => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const field = unref(props.field);
|
|
52
|
+
if (!isFilled.image(field)) {
|
|
53
|
+
return {
|
|
54
|
+
src: null,
|
|
55
|
+
srcset: null
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const imgixParams = unref(props.imgixParams);
|
|
59
|
+
const widths = unref(props.widths);
|
|
60
|
+
const pixelDensities = unref(props.pixelDensities);
|
|
61
|
+
if (widths) {
|
|
62
|
+
if (pixelDensities) {
|
|
63
|
+
console.warn("[PrismicImage] `widths` and `pixelDensities` props should not be use alongside each others, only `widths` will be applied", props);
|
|
64
|
+
}
|
|
65
|
+
if (widths === "auto") {
|
|
66
|
+
return asImageWidthSrcSet(field, imgixParams);
|
|
67
|
+
} else {
|
|
68
|
+
const { url, dimensions, alt: alt2, copyright: copyright2 } = field;
|
|
69
|
+
return asImageWidthSrcSet({ url, dimensions, alt: alt2, copyright: copyright2 }, {
|
|
70
|
+
...imgixParams,
|
|
71
|
+
widths: widths === "defaults" ? (_a = options.components) == null ? void 0 : _a.imageWidthSrcSetDefaults : widths
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
} else if (pixelDensities) {
|
|
75
|
+
return asImagePixelDensitySrcSet(field, {
|
|
76
|
+
...imgixParams,
|
|
77
|
+
pixelDensities: pixelDensities === "defaults" ? (_b = options.components) == null ? void 0 : _b.imagePixelDensitySrcSetDefaults : pixelDensities
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
return {
|
|
81
|
+
src: asImageSrc(field, imgixParams),
|
|
82
|
+
srcset: null
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const src = computed(() => {
|
|
87
|
+
return asImage.value.src;
|
|
88
|
+
});
|
|
89
|
+
const srcset = computed(() => {
|
|
90
|
+
return asImage.value.srcset;
|
|
91
|
+
});
|
|
92
|
+
const alt = computed(() => {
|
|
93
|
+
return unref(props.field).alt || "";
|
|
94
|
+
});
|
|
95
|
+
const copyright = computed(() => {
|
|
96
|
+
return unref(props.field).copyright || null;
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
src,
|
|
100
|
+
srcset,
|
|
101
|
+
alt,
|
|
102
|
+
copyright
|
|
103
|
+
};
|
|
104
|
+
};
|
|
47
105
|
const PrismicImageImpl = /* @__PURE__ */ defineComponent({
|
|
48
106
|
name: "PrismicImage",
|
|
49
107
|
props: {
|
|
@@ -56,10 +114,20 @@ const PrismicImageImpl = /* @__PURE__ */ defineComponent({
|
|
|
56
114
|
default: void 0,
|
|
57
115
|
required: false
|
|
58
116
|
},
|
|
59
|
-
|
|
117
|
+
imgixParams: {
|
|
60
118
|
type: Object,
|
|
61
119
|
default: void 0,
|
|
62
120
|
required: false
|
|
121
|
+
},
|
|
122
|
+
widths: {
|
|
123
|
+
type: [String, Object],
|
|
124
|
+
default: void 0,
|
|
125
|
+
required: false
|
|
126
|
+
},
|
|
127
|
+
pixelDensities: {
|
|
128
|
+
type: [String, Object],
|
|
129
|
+
default: void 0,
|
|
130
|
+
required: false
|
|
63
131
|
}
|
|
64
132
|
},
|
|
65
133
|
setup(props) {
|
|
@@ -71,10 +139,12 @@ const PrismicImageImpl = /* @__PURE__ */ defineComponent({
|
|
|
71
139
|
var _a;
|
|
72
140
|
return props.imageComponent || ((_a = options.components) == null ? void 0 : _a.imageComponent) || defaultImageComponent;
|
|
73
141
|
});
|
|
142
|
+
const { src, srcset, alt, copyright } = usePrismicImage(props);
|
|
74
143
|
return () => {
|
|
75
144
|
const attributes = {
|
|
76
|
-
src:
|
|
77
|
-
|
|
145
|
+
src: src.value,
|
|
146
|
+
srcset: srcset.value,
|
|
147
|
+
alt: alt.value
|
|
78
148
|
};
|
|
79
149
|
switch (type.value) {
|
|
80
150
|
case "img":
|
|
@@ -82,8 +152,7 @@ const PrismicImageImpl = /* @__PURE__ */ defineComponent({
|
|
|
82
152
|
default:
|
|
83
153
|
return h(simplyResolveComponent(type.value), {
|
|
84
154
|
...attributes,
|
|
85
|
-
copyright:
|
|
86
|
-
...props.imageComponentAdditionalProps
|
|
155
|
+
copyright: copyright.value
|
|
87
156
|
});
|
|
88
157
|
}
|
|
89
158
|
};
|
|
@@ -221,7 +290,7 @@ const PrismicLink = PrismicLinkImpl;
|
|
|
221
290
|
const defaultWrapper$1 = "div";
|
|
222
291
|
const usePrismicText = (props) => {
|
|
223
292
|
const text = computed(() => {
|
|
224
|
-
return asText(unref(props.field), unref(props.separator));
|
|
293
|
+
return asText(unref(props.field), unref(props.separator)) || "";
|
|
225
294
|
});
|
|
226
295
|
return {
|
|
227
296
|
text
|
|
@@ -267,7 +336,7 @@ const usePrismicRichText = (props) => {
|
|
|
267
336
|
var _a, _b;
|
|
268
337
|
const linkResolver = (_a = unref(props.linkResolver)) != null ? _a : options.linkResolver;
|
|
269
338
|
const htmlSerializer = (_b = unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
|
|
270
|
-
return asHTML(unref(props.field), linkResolver, htmlSerializer);
|
|
339
|
+
return asHTML(unref(props.field), linkResolver, htmlSerializer) || "";
|
|
271
340
|
});
|
|
272
341
|
return {
|
|
273
342
|
html
|
|
@@ -370,7 +439,7 @@ const getSliceComponentProps = (propsHint) => ({
|
|
|
370
439
|
}
|
|
371
440
|
});
|
|
372
441
|
const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ defineComponent({
|
|
373
|
-
name: "
|
|
442
|
+
name: "TODOSliceComponent",
|
|
374
443
|
props: getSliceComponentProps(),
|
|
375
444
|
setup(props) {
|
|
376
445
|
watchEffect(() => {
|
|
@@ -478,23 +547,18 @@ const createPrismic = (options) => {
|
|
|
478
547
|
if (options.client) {
|
|
479
548
|
client = options.client;
|
|
480
549
|
} else {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
let fetchFunction;
|
|
489
|
-
if (typeof globalThis.fetch === "function") {
|
|
490
|
-
fetchFunction = globalThis.fetch;
|
|
491
|
-
} else {
|
|
492
|
-
fetchFunction = (await import('isomorphic-unfetch')).default;
|
|
493
|
-
}
|
|
494
|
-
return await fetchFunction(endpoint2, options2);
|
|
550
|
+
client = createClient(options.endpoint, {
|
|
551
|
+
fetch: async (endpoint, options2) => {
|
|
552
|
+
let fetchFunction;
|
|
553
|
+
if (typeof globalThis.fetch === "function") {
|
|
554
|
+
fetchFunction = globalThis.fetch;
|
|
555
|
+
} else {
|
|
556
|
+
fetchFunction = (await import('isomorphic-unfetch')).default;
|
|
495
557
|
}
|
|
496
|
-
|
|
497
|
-
|
|
558
|
+
return await fetchFunction(endpoint, options2);
|
|
559
|
+
},
|
|
560
|
+
...options.clientConfig
|
|
561
|
+
});
|
|
498
562
|
}
|
|
499
563
|
const prismicClient = {
|
|
500
564
|
client,
|
|
@@ -510,6 +574,9 @@ const createPrismic = (options) => {
|
|
|
510
574
|
return asLink(linkField, linkResolver || options.linkResolver);
|
|
511
575
|
},
|
|
512
576
|
asDate,
|
|
577
|
+
asImageSrc,
|
|
578
|
+
asImageWidthSrcSet,
|
|
579
|
+
asImagePixelDensitySrcSet,
|
|
513
580
|
documentToLinkField
|
|
514
581
|
};
|
|
515
582
|
const prismic = {
|
|
@@ -590,5 +657,5 @@ const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMetho
|
|
|
590
657
|
const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
|
|
591
658
|
const dangerouslyUseAllPrismicDocuments = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
|
|
592
659
|
|
|
593
|
-
export { PrismicClientComposableState, PrismicEmbed, PrismicImage, PrismicLink, PrismicRichText, PrismicText, SliceZone,
|
|
660
|
+
export { PrismicClientComposableState, PrismicEmbed, PrismicImage, PrismicLink, PrismicRichText, PrismicText, SliceZone, TODOSliceComponent, createPrismic, dangerouslyUseAllPrismicDocuments, defineSliceZoneComponents, getSliceComponentProps, prismicKey, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useFirstPrismicDocument, usePrismic, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, usePrismicImage, usePrismicLink, usePrismicRichText, usePrismicText, useSinglePrismicDocument };
|
|
594
661
|
//# sourceMappingURL=index.js.map
|