@prismicio/vue 3.0.0-beta.6 → 3.0.0-beta.7

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/dist/index.cjs CHANGED
@@ -59,6 +59,11 @@ const PrismicEmbedImpl = /* @__PURE__ */ vue.defineComponent({
59
59
  });
60
60
  const PrismicEmbed = PrismicEmbedImpl;
61
61
 
62
+ if (typeof process === "undefined") {
63
+ globalThis.process = { env: {} };
64
+ }
65
+ const __PRODUCTION__ = process.env.NODE_ENV === "production";
66
+
62
67
  const prismicKey = Symbol("prismic");
63
68
 
64
69
  const usePrismic = () => {
@@ -81,8 +86,8 @@ const usePrismicImage = (props) => {
81
86
  const widths = vue.unref(props.widths);
82
87
  const pixelDensities = vue.unref(props.pixelDensities);
83
88
  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);
89
+ if (!__PRODUCTION__ && pixelDensities) {
90
+ console.warn("[PrismicImage] Only one of `widths` or `pixelDensities` props can be provided. You can resolve this warning by removing either the `widths` or `pixelDensities` prop. `widths` will be used in this case.", props);
86
91
  }
87
92
  return helpers.asImageWidthSrcSet(field, {
88
93
  ...imgixParams,
@@ -307,7 +312,12 @@ const PrismicLink = PrismicLinkImpl;
307
312
  const defaultWrapper$1 = "div";
308
313
  const usePrismicText = (props) => {
309
314
  const text = vue.computed(() => {
310
- return helpers.asText(vue.unref(props.field), vue.unref(props.separator));
315
+ var _a;
316
+ const field = vue.unref(props.field);
317
+ if (!helpers.isFilled.richText(field)) {
318
+ return (_a = vue.unref(props.fallback)) != null ? _a : "";
319
+ }
320
+ return helpers.asText(vue.unref(field), vue.unref(props.separator));
311
321
  });
312
322
  return {
313
323
  text
@@ -329,12 +339,14 @@ const PrismicTextImpl = /* @__PURE__ */ vue.defineComponent({
329
339
  type: [String, Object, Function],
330
340
  default: void 0,
331
341
  required: false
342
+ },
343
+ fallback: {
344
+ type: String,
345
+ default: void 0,
346
+ required: false
332
347
  }
333
348
  },
334
349
  setup(props) {
335
- if (!props.field) {
336
- return () => null;
337
- }
338
350
  const { text } = usePrismicText(props);
339
351
  return () => {
340
352
  const parent = simplyResolveComponent(props.wrapper || defaultWrapper$1);
@@ -350,10 +362,14 @@ const defaultWrapper = "div";
350
362
  const usePrismicRichText = (props) => {
351
363
  const { options } = usePrismic();
352
364
  const html = vue.computed(() => {
353
- var _a, _b;
354
- const linkResolver = (_a = vue.unref(props.linkResolver)) != null ? _a : options.linkResolver;
355
- const htmlSerializer = (_b = vue.unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
356
- return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer);
365
+ var _a, _b, _c;
366
+ const field = vue.unref(props.field);
367
+ if (!helpers.isFilled.richText(field)) {
368
+ return (_a = vue.unref(props.fallback)) != null ? _a : "";
369
+ }
370
+ const linkResolver = (_b = vue.unref(props.linkResolver)) != null ? _b : options.linkResolver;
371
+ const htmlSerializer = (_c = vue.unref(props.htmlSerializer)) != null ? _c : options.htmlSerializer;
372
+ return helpers.asHTML(vue.unref(field), linkResolver, htmlSerializer);
357
373
  });
358
374
  return {
359
375
  html
@@ -380,16 +396,18 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
380
396
  type: [String, Object, Function],
381
397
  default: void 0,
382
398
  required: false
399
+ },
400
+ fallback: {
401
+ type: String,
402
+ default: void 0,
403
+ required: false
383
404
  }
384
405
  },
385
406
  setup(props) {
386
- if (!props.field) {
387
- return () => null;
388
- }
389
407
  const { html } = usePrismicRichText(props);
390
408
  const root = vue.ref(null);
391
409
  const maybeRouter = vue.inject(vueRouter.routerKey, null);
392
- if (maybeRouter) {
410
+ if (maybeRouter && html.value) {
393
411
  let links = [];
394
412
  const navigate = function(event) {
395
413
  event.preventDefault();
@@ -432,11 +450,6 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
432
450
  });
433
451
  const PrismicRichText = PrismicRichTextImpl;
434
452
 
435
- if (typeof process === "undefined") {
436
- globalThis.process = { env: {} };
437
- }
438
- const __PRODUCTION__ = process.env.NODE_ENV === "production";
439
-
440
453
  const getSliceComponentProps = (propsHint) => ({
441
454
  slice: {
442
455
  type: Object,
@@ -459,16 +472,15 @@ const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ vue.def
459
472
  name: "TODOSliceComponent",
460
473
  props: getSliceComponentProps(),
461
474
  setup(props) {
475
+ const type = vue.computed(() => "slice_type" in props.slice ? props.slice.slice_type : props.slice.type);
462
476
  vue.watchEffect(() => {
463
- console.warn(`[SliceZone] Could not find a component for Slice type "${props.slice.slice_type}"`, props.slice);
477
+ console.warn(`[SliceZone] Could not find a component for Slice type "${type.value}"`, props.slice);
464
478
  });
465
479
  return () => {
466
480
  return vue.h("section", {
467
481
  "data-slice-zone-todo-component": "",
468
- "data-slice-type": props.slice.slice_type
469
- }, [
470
- `Could not find a component for Slice type "${props.slice.slice_type}"`
471
- ]);
482
+ "data-slice-type": type.value
483
+ }, [`Could not find a component for Slice type "${type.value}"`]);
472
484
  };
473
485
  }
474
486
  });
@@ -522,11 +534,12 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
522
534
  const renderedSlices = vue.computed(() => {
523
535
  return props.slices.map((slice, index) => {
524
536
  var _a;
525
- 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;
537
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
538
+ let component = props.components && type in props.components ? props.components[type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
526
539
  if (props.resolver) {
527
540
  const resolvedComponent = props.resolver({
528
541
  slice,
529
- sliceName: slice.slice_type,
542
+ sliceName: type,
530
543
  i: index
531
544
  });
532
545
  if (resolvedComponent) {
@@ -534,7 +547,7 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
534
547
  }
535
548
  }
536
549
  const p = {
537
- key: `${slice.slice_type}-${index}`,
550
+ key: `${index}-${JSON.stringify(slice)}`,
538
551
  slice,
539
552
  index,
540
553
  context: props.context,