@prismicio/vue 3.0.0-alpha.5 → 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 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-2021 Prismic <contact@prismic.io> (https://prismic.io)
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
- imageComponentAdditionalProps: {
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: props.field.url || null,
99
- alt: props.field.alt || null
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: props.field.copyright || null,
108
- ...props.imageComponentAdditionalProps
175
+ copyright: copyright.value
109
176
  });
110
177
  }
111
178
  };
@@ -154,11 +221,28 @@ const usePrismicLink = (props) => {
154
221
  });
155
222
  const target = vue.computed(() => {
156
223
  const field = vue.unref(props.field);
157
- return vue.unref(props.target) || (field && "target" in field && field.target ? field.target : null);
224
+ const target2 = vue.unref(props.target);
225
+ if (typeof target2 !== "undefined") {
226
+ return target2;
227
+ } else {
228
+ return field && "target" in field && field.target ? field.target : null;
229
+ }
158
230
  });
159
231
  const rel = vue.computed(() => {
160
232
  var _a;
161
- return vue.unref(props.rel) || (target.value === "_blank" ? vue.unref(props.blankTargetRelAttribute) || ((_a = options.components) == null ? void 0 : _a.linkBlankTargetRelAttribute) || defaultBlankTargetRelAttribute : null);
233
+ const rel2 = vue.unref(props.rel);
234
+ if (typeof rel2 !== "undefined") {
235
+ return rel2;
236
+ } else if (target.value === "_blank") {
237
+ const blankTargetRelAttribute = vue.unref(props.blankTargetRelAttribute);
238
+ if (typeof blankTargetRelAttribute !== "undefined") {
239
+ return blankTargetRelAttribute;
240
+ } else {
241
+ return typeof ((_a = options.components) == null ? void 0 : _a.linkBlankTargetRelAttribute) !== "undefined" ? options.components.linkBlankTargetRelAttribute : defaultBlankTargetRelAttribute;
242
+ }
243
+ } else {
244
+ return null;
245
+ }
162
246
  });
163
247
  return {
164
248
  type,
@@ -226,7 +310,7 @@ const PrismicLink = PrismicLinkImpl;
226
310
  const defaultWrapper$1 = "div";
227
311
  const usePrismicText = (props) => {
228
312
  const text = vue.computed(() => {
229
- return helpers.asText(vue.unref(props.field), vue.unref(props.separator));
313
+ return helpers.asText(vue.unref(props.field), vue.unref(props.separator)) || "";
230
314
  });
231
315
  return {
232
316
  text
@@ -272,7 +356,7 @@ const usePrismicRichText = (props) => {
272
356
  var _a, _b;
273
357
  const linkResolver = (_a = vue.unref(props.linkResolver)) != null ? _a : options.linkResolver;
274
358
  const htmlSerializer = (_b = vue.unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
275
- return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer);
359
+ return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer) || "";
276
360
  });
277
361
  return {
278
362
  html
@@ -391,7 +475,7 @@ const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ vue.def
391
475
  };
392
476
  }
393
477
  });
394
- const getSliceZoneComponents = (components) => {
478
+ const defineSliceZoneComponents = (components) => {
395
479
  const result = {};
396
480
  let type;
397
481
  for (type in components) {
@@ -409,7 +493,13 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
409
493
  },
410
494
  components: {
411
495
  type: Object,
412
- required: true
496
+ default: void 0,
497
+ required: false
498
+ },
499
+ resolver: {
500
+ type: Function,
501
+ default: void 0,
502
+ required: false
413
503
  },
414
504
  context: {
415
505
  type: null,
@@ -435,8 +525,19 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
435
525
  const renderedSlices = vue.computed(() => {
436
526
  return props.slices.map((slice, index) => {
437
527
  var _a;
438
- const component = slice.slice_type in props.components ? props.components[slice.slice_type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
528
+ let component = props.components && slice.slice_type in props.components ? props.components[slice.slice_type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
529
+ if (props.resolver) {
530
+ const resolvedComponent = props.resolver({
531
+ slice,
532
+ sliceName: slice.slice_type,
533
+ i: index
534
+ });
535
+ if (resolvedComponent) {
536
+ component = resolvedComponent;
537
+ }
538
+ }
439
539
  const p = {
540
+ key: `${slice.slice_type}-${index}`,
440
541
  slice,
441
542
  index,
442
543
  context: props.context,
@@ -498,6 +599,9 @@ const createPrismic = (options) => {
498
599
  return helpers.asLink(linkField, linkResolver || options.linkResolver);
499
600
  },
500
601
  asDate: helpers.asDate,
602
+ asImageSrc: helpers.asImageSrc,
603
+ asImageWidthSrcSet: helpers.asImageWidthSrcSet,
604
+ asImagePixelDensitySrcSet: helpers.asImagePixelDensitySrcSet,
501
605
  documentToLinkField: helpers.documentToLinkField
502
606
  };
503
607
  const prismic = {
@@ -588,8 +692,8 @@ exports.SliceZoneImpl = SliceZoneImpl;
588
692
  exports.TODOSliceComponent = TODOSliceComponent;
589
693
  exports.createPrismic = createPrismic;
590
694
  exports.dangerouslyUseAllPrismicDocuments = dangerouslyUseAllPrismicDocuments;
695
+ exports.defineSliceZoneComponents = defineSliceZoneComponents;
591
696
  exports.getSliceComponentProps = getSliceComponentProps;
592
- exports.getSliceZoneComponents = getSliceZoneComponents;
593
697
  exports.prismicKey = prismicKey;
594
698
  exports.useAllPrismicDocumentsByEveryTag = useAllPrismicDocumentsByEveryTag;
595
699
  exports.useAllPrismicDocumentsByIDs = useAllPrismicDocumentsByIDs;
@@ -608,6 +712,7 @@ exports.usePrismicDocumentsBySomeTags = usePrismicDocumentsBySomeTags;
608
712
  exports.usePrismicDocumentsByTag = usePrismicDocumentsByTag;
609
713
  exports.usePrismicDocumentsByType = usePrismicDocumentsByType;
610
714
  exports.usePrismicDocumentsByUIDs = usePrismicDocumentsByUIDs;
715
+ exports.usePrismicImage = usePrismicImage;
611
716
  exports.usePrismicLink = usePrismicLink;
612
717
  exports.usePrismicRichText = usePrismicRichText;
613
718
  exports.usePrismicText = usePrismicText;