@prismicio/vue 3.0.0-beta.4 → 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 +52 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +106 -20
- package/dist/index.js +47 -39
- package/dist/index.js.map +1 -1
- package/package.json +26 -26
- package/src/components/PrismicImage.ts +15 -24
- package/src/components/PrismicRichText.ts +22 -10
- package/src/components/PrismicText.ts +21 -10
- package/src/components/SliceZone.ts +71 -29
- package/src/components/index.ts +2 -0
- package/src/index.ts +2 -0
- package/vetur/attributes.json +8 -0
- package/vetur/tags.json +2 -2
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,18 +86,13 @@ 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`
|
|
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
|
-
});
|
|
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);
|
|
95
91
|
}
|
|
92
|
+
return helpers.asImageWidthSrcSet(field, {
|
|
93
|
+
...imgixParams,
|
|
94
|
+
widths: widths === "defaults" ? (_a = options.components) == null ? void 0 : _a.imageWidthSrcSetDefaults : widths
|
|
95
|
+
});
|
|
96
96
|
} else if (pixelDensities) {
|
|
97
97
|
return helpers.asImagePixelDensitySrcSet(field, {
|
|
98
98
|
...imgixParams,
|
|
@@ -312,7 +312,12 @@ const PrismicLink = PrismicLinkImpl;
|
|
|
312
312
|
const defaultWrapper$1 = "div";
|
|
313
313
|
const usePrismicText = (props) => {
|
|
314
314
|
const text = vue.computed(() => {
|
|
315
|
-
|
|
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));
|
|
316
321
|
});
|
|
317
322
|
return {
|
|
318
323
|
text
|
|
@@ -334,12 +339,14 @@ const PrismicTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
334
339
|
type: [String, Object, Function],
|
|
335
340
|
default: void 0,
|
|
336
341
|
required: false
|
|
342
|
+
},
|
|
343
|
+
fallback: {
|
|
344
|
+
type: String,
|
|
345
|
+
default: void 0,
|
|
346
|
+
required: false
|
|
337
347
|
}
|
|
338
348
|
},
|
|
339
349
|
setup(props) {
|
|
340
|
-
if (!props.field) {
|
|
341
|
-
return () => null;
|
|
342
|
-
}
|
|
343
350
|
const { text } = usePrismicText(props);
|
|
344
351
|
return () => {
|
|
345
352
|
const parent = simplyResolveComponent(props.wrapper || defaultWrapper$1);
|
|
@@ -355,10 +362,14 @@ const defaultWrapper = "div";
|
|
|
355
362
|
const usePrismicRichText = (props) => {
|
|
356
363
|
const { options } = usePrismic();
|
|
357
364
|
const html = vue.computed(() => {
|
|
358
|
-
var _a, _b;
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
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);
|
|
362
373
|
});
|
|
363
374
|
return {
|
|
364
375
|
html
|
|
@@ -385,16 +396,18 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
385
396
|
type: [String, Object, Function],
|
|
386
397
|
default: void 0,
|
|
387
398
|
required: false
|
|
399
|
+
},
|
|
400
|
+
fallback: {
|
|
401
|
+
type: String,
|
|
402
|
+
default: void 0,
|
|
403
|
+
required: false
|
|
388
404
|
}
|
|
389
405
|
},
|
|
390
406
|
setup(props) {
|
|
391
|
-
if (!props.field) {
|
|
392
|
-
return () => null;
|
|
393
|
-
}
|
|
394
407
|
const { html } = usePrismicRichText(props);
|
|
395
408
|
const root = vue.ref(null);
|
|
396
409
|
const maybeRouter = vue.inject(vueRouter.routerKey, null);
|
|
397
|
-
if (maybeRouter) {
|
|
410
|
+
if (maybeRouter && html.value) {
|
|
398
411
|
let links = [];
|
|
399
412
|
const navigate = function(event) {
|
|
400
413
|
event.preventDefault();
|
|
@@ -437,11 +450,6 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
437
450
|
});
|
|
438
451
|
const PrismicRichText = PrismicRichTextImpl;
|
|
439
452
|
|
|
440
|
-
if (typeof process === "undefined") {
|
|
441
|
-
globalThis.process = { env: {} };
|
|
442
|
-
}
|
|
443
|
-
const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
444
|
-
|
|
445
453
|
const getSliceComponentProps = (propsHint) => ({
|
|
446
454
|
slice: {
|
|
447
455
|
type: Object,
|
|
@@ -464,16 +472,15 @@ const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ vue.def
|
|
|
464
472
|
name: "TODOSliceComponent",
|
|
465
473
|
props: getSliceComponentProps(),
|
|
466
474
|
setup(props) {
|
|
475
|
+
const type = vue.computed(() => "slice_type" in props.slice ? props.slice.slice_type : props.slice.type);
|
|
467
476
|
vue.watchEffect(() => {
|
|
468
|
-
console.warn(`[SliceZone] Could not find a component for Slice type "${
|
|
477
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${type.value}"`, props.slice);
|
|
469
478
|
});
|
|
470
479
|
return () => {
|
|
471
480
|
return vue.h("section", {
|
|
472
481
|
"data-slice-zone-todo-component": "",
|
|
473
|
-
"data-slice-type":
|
|
474
|
-
}, [
|
|
475
|
-
`Could not find a component for Slice type "${props.slice.slice_type}"`
|
|
476
|
-
]);
|
|
482
|
+
"data-slice-type": type.value
|
|
483
|
+
}, [`Could not find a component for Slice type "${type.value}"`]);
|
|
477
484
|
};
|
|
478
485
|
}
|
|
479
486
|
});
|
|
@@ -527,11 +534,12 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
527
534
|
const renderedSlices = vue.computed(() => {
|
|
528
535
|
return props.slices.map((slice, index) => {
|
|
529
536
|
var _a;
|
|
530
|
-
|
|
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;
|
|
531
539
|
if (props.resolver) {
|
|
532
540
|
const resolvedComponent = props.resolver({
|
|
533
541
|
slice,
|
|
534
|
-
sliceName:
|
|
542
|
+
sliceName: type,
|
|
535
543
|
i: index
|
|
536
544
|
});
|
|
537
545
|
if (resolvedComponent) {
|
|
@@ -539,7 +547,7 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
539
547
|
}
|
|
540
548
|
}
|
|
541
549
|
const p = {
|
|
542
|
-
key: `${
|
|
550
|
+
key: `${index}-${JSON.stringify(slice)}`,
|
|
543
551
|
slice,
|
|
544
552
|
index,
|
|
545
553
|
context: props.context,
|
|
@@ -621,34 +629,34 @@ const createPrismic = (options) => {
|
|
|
621
629
|
return prismic;
|
|
622
630
|
};
|
|
623
631
|
|
|
624
|
-
|
|
625
|
-
(function(PrismicClientComposableState2) {
|
|
632
|
+
var PrismicClientComposableState = /* @__PURE__ */ ((PrismicClientComposableState2) => {
|
|
626
633
|
PrismicClientComposableState2["Idle"] = "idle";
|
|
627
634
|
PrismicClientComposableState2["Pending"] = "pending";
|
|
628
635
|
PrismicClientComposableState2["Success"] = "success";
|
|
629
636
|
PrismicClientComposableState2["Error"] = "error";
|
|
630
|
-
|
|
637
|
+
return PrismicClientComposableState2;
|
|
638
|
+
})(PrismicClientComposableState || {});
|
|
631
639
|
|
|
632
640
|
const isParams = (value) => {
|
|
633
641
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
634
642
|
};
|
|
635
643
|
const useStatefulPrismicClientMethod = (methodName, args) => {
|
|
636
644
|
const { client } = usePrismic();
|
|
637
|
-
const state = vue.ref(
|
|
645
|
+
const state = vue.ref(PrismicClientComposableState.Idle);
|
|
638
646
|
const data = vue.shallowRef(null);
|
|
639
647
|
const error = vue.ref(null);
|
|
640
648
|
const refresh = async () => {
|
|
641
649
|
const lastArg = vue.unref(args[args.length - 1]);
|
|
642
650
|
const { client: explicitClient, ...params } = isParams(lastArg) ? lastArg : {};
|
|
643
651
|
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
644
|
-
state.value =
|
|
652
|
+
state.value = PrismicClientComposableState.Pending;
|
|
645
653
|
data.value = null;
|
|
646
654
|
error.value = null;
|
|
647
655
|
try {
|
|
648
656
|
data.value = await (vue.unref(explicitClient) || client)[methodName](...argsWithoutParams.map((arg) => vue.unref(arg)), params);
|
|
649
|
-
state.value =
|
|
657
|
+
state.value = PrismicClientComposableState.Success;
|
|
650
658
|
} catch (err) {
|
|
651
|
-
state.value =
|
|
659
|
+
state.value = PrismicClientComposableState.Error;
|
|
652
660
|
error.value = err;
|
|
653
661
|
}
|
|
654
662
|
};
|
|
@@ -679,6 +687,7 @@ const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMetho
|
|
|
679
687
|
const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
|
|
680
688
|
const dangerouslyUseAllPrismicDocuments = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
|
|
681
689
|
|
|
690
|
+
exports.PrismicClientComposableState = PrismicClientComposableState;
|
|
682
691
|
exports.PrismicEmbed = PrismicEmbed;
|
|
683
692
|
exports.PrismicImage = PrismicImage;
|
|
684
693
|
exports.PrismicLink = PrismicLink;
|