@prismicio/vue 3.0.0-beta.5 → 3.0.0-beta.8
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 +56 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +108 -22
- package/dist/index.js +51 -41
- package/dist/index.js.map +1 -1
- package/package.json +28 -30
- package/src/components/PrismicImage.ts +15 -24
- package/src/components/PrismicRichText.ts +24 -10
- package/src/components/PrismicText.ts +23 -10
- package/src/components/SliceZone.ts +75 -31
- 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
|
|
@@ -323,7 +328,8 @@ const PrismicTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
323
328
|
props: {
|
|
324
329
|
field: {
|
|
325
330
|
type: Array,
|
|
326
|
-
|
|
331
|
+
default: void 0,
|
|
332
|
+
required: false
|
|
327
333
|
},
|
|
328
334
|
separator: {
|
|
329
335
|
type: String,
|
|
@@ -334,12 +340,14 @@ const PrismicTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
334
340
|
type: [String, Object, Function],
|
|
335
341
|
default: void 0,
|
|
336
342
|
required: false
|
|
343
|
+
},
|
|
344
|
+
fallback: {
|
|
345
|
+
type: String,
|
|
346
|
+
default: void 0,
|
|
347
|
+
required: false
|
|
337
348
|
}
|
|
338
349
|
},
|
|
339
350
|
setup(props) {
|
|
340
|
-
if (!props.field) {
|
|
341
|
-
return () => null;
|
|
342
|
-
}
|
|
343
351
|
const { text } = usePrismicText(props);
|
|
344
352
|
return () => {
|
|
345
353
|
const parent = simplyResolveComponent(props.wrapper || defaultWrapper$1);
|
|
@@ -355,10 +363,14 @@ const defaultWrapper = "div";
|
|
|
355
363
|
const usePrismicRichText = (props) => {
|
|
356
364
|
const { options } = usePrismic();
|
|
357
365
|
const html = vue.computed(() => {
|
|
358
|
-
var _a, _b;
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
366
|
+
var _a, _b, _c;
|
|
367
|
+
const field = vue.unref(props.field);
|
|
368
|
+
if (!helpers.isFilled.richText(field)) {
|
|
369
|
+
return (_a = vue.unref(props.fallback)) != null ? _a : "";
|
|
370
|
+
}
|
|
371
|
+
const linkResolver = (_b = vue.unref(props.linkResolver)) != null ? _b : options.linkResolver;
|
|
372
|
+
const htmlSerializer = (_c = vue.unref(props.htmlSerializer)) != null ? _c : options.htmlSerializer;
|
|
373
|
+
return helpers.asHTML(vue.unref(field), linkResolver, htmlSerializer);
|
|
362
374
|
});
|
|
363
375
|
return {
|
|
364
376
|
html
|
|
@@ -369,7 +381,8 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
369
381
|
props: {
|
|
370
382
|
field: {
|
|
371
383
|
type: Array,
|
|
372
|
-
|
|
384
|
+
default: void 0,
|
|
385
|
+
required: false
|
|
373
386
|
},
|
|
374
387
|
linkResolver: {
|
|
375
388
|
type: Function,
|
|
@@ -385,16 +398,18 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
385
398
|
type: [String, Object, Function],
|
|
386
399
|
default: void 0,
|
|
387
400
|
required: false
|
|
401
|
+
},
|
|
402
|
+
fallback: {
|
|
403
|
+
type: String,
|
|
404
|
+
default: void 0,
|
|
405
|
+
required: false
|
|
388
406
|
}
|
|
389
407
|
},
|
|
390
408
|
setup(props) {
|
|
391
|
-
if (!props.field) {
|
|
392
|
-
return () => null;
|
|
393
|
-
}
|
|
394
409
|
const { html } = usePrismicRichText(props);
|
|
395
410
|
const root = vue.ref(null);
|
|
396
411
|
const maybeRouter = vue.inject(vueRouter.routerKey, null);
|
|
397
|
-
if (maybeRouter) {
|
|
412
|
+
if (maybeRouter && html.value) {
|
|
398
413
|
let links = [];
|
|
399
414
|
const navigate = function(event) {
|
|
400
415
|
event.preventDefault();
|
|
@@ -437,11 +452,6 @@ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
437
452
|
});
|
|
438
453
|
const PrismicRichText = PrismicRichTextImpl;
|
|
439
454
|
|
|
440
|
-
if (typeof process === "undefined") {
|
|
441
|
-
globalThis.process = { env: {} };
|
|
442
|
-
}
|
|
443
|
-
const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
444
|
-
|
|
445
455
|
const getSliceComponentProps = (propsHint) => ({
|
|
446
456
|
slice: {
|
|
447
457
|
type: Object,
|
|
@@ -464,16 +474,15 @@ const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ vue.def
|
|
|
464
474
|
name: "TODOSliceComponent",
|
|
465
475
|
props: getSliceComponentProps(),
|
|
466
476
|
setup(props) {
|
|
477
|
+
const type = vue.computed(() => "slice_type" in props.slice ? props.slice.slice_type : props.slice.type);
|
|
467
478
|
vue.watchEffect(() => {
|
|
468
|
-
console.warn(`[SliceZone] Could not find a component for Slice type "${
|
|
479
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${type.value}"`, props.slice);
|
|
469
480
|
});
|
|
470
481
|
return () => {
|
|
471
482
|
return vue.h("section", {
|
|
472
483
|
"data-slice-zone-todo-component": "",
|
|
473
|
-
"data-slice-type":
|
|
474
|
-
}, [
|
|
475
|
-
`Could not find a component for Slice type "${props.slice.slice_type}"`
|
|
476
|
-
]);
|
|
484
|
+
"data-slice-type": type.value
|
|
485
|
+
}, [`Could not find a component for Slice type "${type.value}"`]);
|
|
477
486
|
};
|
|
478
487
|
}
|
|
479
488
|
});
|
|
@@ -527,11 +536,12 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
527
536
|
const renderedSlices = vue.computed(() => {
|
|
528
537
|
return props.slices.map((slice, index) => {
|
|
529
538
|
var _a;
|
|
530
|
-
|
|
539
|
+
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
540
|
+
let component = props.components && type in props.components ? props.components[type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
|
|
531
541
|
if (props.resolver) {
|
|
532
542
|
const resolvedComponent = props.resolver({
|
|
533
543
|
slice,
|
|
534
|
-
sliceName:
|
|
544
|
+
sliceName: type,
|
|
535
545
|
i: index
|
|
536
546
|
});
|
|
537
547
|
if (resolvedComponent) {
|
|
@@ -539,7 +549,7 @@ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
|
|
|
539
549
|
}
|
|
540
550
|
}
|
|
541
551
|
const p = {
|
|
542
|
-
key: `${
|
|
552
|
+
key: `${index}-${JSON.stringify(slice)}`,
|
|
543
553
|
slice,
|
|
544
554
|
index,
|
|
545
555
|
context: props.context,
|
|
@@ -621,34 +631,34 @@ const createPrismic = (options) => {
|
|
|
621
631
|
return prismic;
|
|
622
632
|
};
|
|
623
633
|
|
|
624
|
-
|
|
625
|
-
(function(PrismicClientComposableState2) {
|
|
634
|
+
var PrismicClientComposableState = /* @__PURE__ */ ((PrismicClientComposableState2) => {
|
|
626
635
|
PrismicClientComposableState2["Idle"] = "idle";
|
|
627
636
|
PrismicClientComposableState2["Pending"] = "pending";
|
|
628
637
|
PrismicClientComposableState2["Success"] = "success";
|
|
629
638
|
PrismicClientComposableState2["Error"] = "error";
|
|
630
|
-
|
|
639
|
+
return PrismicClientComposableState2;
|
|
640
|
+
})(PrismicClientComposableState || {});
|
|
631
641
|
|
|
632
642
|
const isParams = (value) => {
|
|
633
643
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
634
644
|
};
|
|
635
645
|
const useStatefulPrismicClientMethod = (methodName, args) => {
|
|
636
646
|
const { client } = usePrismic();
|
|
637
|
-
const state = vue.ref(
|
|
647
|
+
const state = vue.ref(PrismicClientComposableState.Idle);
|
|
638
648
|
const data = vue.shallowRef(null);
|
|
639
649
|
const error = vue.ref(null);
|
|
640
650
|
const refresh = async () => {
|
|
641
651
|
const lastArg = vue.unref(args[args.length - 1]);
|
|
642
652
|
const { client: explicitClient, ...params } = isParams(lastArg) ? lastArg : {};
|
|
643
653
|
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
644
|
-
state.value =
|
|
654
|
+
state.value = PrismicClientComposableState.Pending;
|
|
645
655
|
data.value = null;
|
|
646
656
|
error.value = null;
|
|
647
657
|
try {
|
|
648
658
|
data.value = await (vue.unref(explicitClient) || client)[methodName](...argsWithoutParams.map((arg) => vue.unref(arg)), params);
|
|
649
|
-
state.value =
|
|
659
|
+
state.value = PrismicClientComposableState.Success;
|
|
650
660
|
} catch (err) {
|
|
651
|
-
state.value =
|
|
661
|
+
state.value = PrismicClientComposableState.Error;
|
|
652
662
|
error.value = err;
|
|
653
663
|
}
|
|
654
664
|
};
|
|
@@ -679,6 +689,7 @@ const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMetho
|
|
|
679
689
|
const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
|
|
680
690
|
const dangerouslyUseAllPrismicDocuments = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
|
|
681
691
|
|
|
692
|
+
exports.PrismicClientComposableState = PrismicClientComposableState;
|
|
682
693
|
exports.PrismicEmbed = PrismicEmbed;
|
|
683
694
|
exports.PrismicImage = PrismicImage;
|
|
684
695
|
exports.PrismicLink = PrismicLink;
|