@prismicio/vue 3.1.1 → 3.1.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.
Files changed (85) hide show
  1. package/dist/components/PrismicEmbed.cjs +36 -0
  2. package/dist/components/PrismicEmbed.cjs.map +1 -0
  3. package/dist/components/PrismicEmbed.d.ts +63 -0
  4. package/dist/components/PrismicEmbed.js +36 -0
  5. package/dist/components/PrismicEmbed.js.map +1 -0
  6. package/dist/components/PrismicImage.cjs +122 -0
  7. package/dist/components/PrismicImage.cjs.map +1 -0
  8. package/dist/components/PrismicImage.d.ts +162 -0
  9. package/dist/components/PrismicImage.js +122 -0
  10. package/dist/components/PrismicImage.js.map +1 -0
  11. package/dist/components/PrismicLink.cjs +115 -0
  12. package/dist/components/PrismicLink.cjs.map +1 -0
  13. package/dist/components/PrismicLink.d.ts +191 -0
  14. package/dist/components/PrismicLink.js +115 -0
  15. package/dist/components/PrismicLink.js.map +1 -0
  16. package/dist/components/PrismicRichText.cjs +103 -0
  17. package/dist/components/PrismicRichText.cjs.map +1 -0
  18. package/dist/components/PrismicRichText.d.ts +139 -0
  19. package/dist/components/PrismicRichText.js +103 -0
  20. package/dist/components/PrismicRichText.js.map +1 -0
  21. package/dist/components/PrismicText.cjs +57 -0
  22. package/dist/components/PrismicText.cjs.map +1 -0
  23. package/dist/components/PrismicText.d.ts +117 -0
  24. package/dist/components/PrismicText.js +57 -0
  25. package/dist/components/PrismicText.js.map +1 -0
  26. package/dist/components/SliceZone.cjs +134 -0
  27. package/dist/components/SliceZone.cjs.map +1 -0
  28. package/dist/components/SliceZone.d.ts +359 -0
  29. package/dist/components/SliceZone.js +134 -0
  30. package/dist/components/SliceZone.js.map +1 -0
  31. package/dist/components/index.d.ts +12 -0
  32. package/dist/composables.cjs +40 -0
  33. package/dist/composables.cjs.map +1 -0
  34. package/dist/composables.d.ts +366 -0
  35. package/dist/composables.js +40 -0
  36. package/dist/composables.js.map +1 -0
  37. package/dist/createPrismic.cjs +87 -0
  38. package/dist/createPrismic.cjs.map +1 -0
  39. package/dist/createPrismic.d.ts +12 -0
  40. package/dist/createPrismic.js +69 -0
  41. package/dist/createPrismic.js.map +1 -0
  42. package/dist/globalExtensions.d.ts +11 -0
  43. package/dist/index.cjs +46 -764
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.ts +10 -1439
  46. package/dist/index.js +45 -707
  47. package/dist/index.js.map +1 -1
  48. package/dist/injectionSymbols.cjs +5 -0
  49. package/dist/injectionSymbols.cjs.map +1 -0
  50. package/dist/injectionSymbols.d.ts +9 -0
  51. package/dist/injectionSymbols.js +5 -0
  52. package/dist/injectionSymbols.js.map +1 -0
  53. package/dist/lib/__PRODUCTION__.cjs +8 -0
  54. package/dist/lib/__PRODUCTION__.cjs.map +1 -0
  55. package/dist/lib/__PRODUCTION__.d.ts +7 -0
  56. package/dist/lib/__PRODUCTION__.js +8 -0
  57. package/dist/lib/__PRODUCTION__.js.map +1 -0
  58. package/dist/lib/getSlots.cjs +19 -0
  59. package/dist/lib/getSlots.cjs.map +1 -0
  60. package/dist/lib/getSlots.d.ts +14 -0
  61. package/dist/lib/getSlots.js +19 -0
  62. package/dist/lib/getSlots.js.map +1 -0
  63. package/dist/lib/isInternalURL.cjs +9 -0
  64. package/dist/lib/isInternalURL.cjs.map +1 -0
  65. package/dist/lib/isInternalURL.d.ts +8 -0
  66. package/dist/lib/isInternalURL.js +9 -0
  67. package/dist/lib/isInternalURL.js.map +1 -0
  68. package/dist/lib/simplyResolveComponent.cjs +8 -0
  69. package/dist/lib/simplyResolveComponent.cjs.map +1 -0
  70. package/dist/lib/simplyResolveComponent.d.ts +12 -0
  71. package/dist/lib/simplyResolveComponent.js +8 -0
  72. package/dist/lib/simplyResolveComponent.js.map +1 -0
  73. package/dist/types.d.ts +357 -0
  74. package/dist/usePrismic.cjs +9 -0
  75. package/dist/usePrismic.cjs.map +1 -0
  76. package/dist/usePrismic.d.ts +21 -0
  77. package/dist/usePrismic.js +9 -0
  78. package/dist/usePrismic.js.map +1 -0
  79. package/dist/useStatefulPrismicClientMethod.cjs +36 -0
  80. package/dist/useStatefulPrismicClientMethod.cjs.map +1 -0
  81. package/dist/useStatefulPrismicClientMethod.d.ts +64 -0
  82. package/dist/useStatefulPrismicClientMethod.js +36 -0
  83. package/dist/useStatefulPrismicClientMethod.js.map +1 -0
  84. package/package.json +22 -22
  85. package/src/components/PrismicImage.ts +2 -2
package/dist/index.js CHANGED
@@ -1,709 +1,47 @@
1
- import { createClient, predicate, cookie } from '@prismicio/client';
2
- import { isFilled, asImageWidthSrcSet, asImagePixelDensitySrcSet, asImageSrc, asLink, asText, asHTML, asDate, documentToLinkField } from '@prismicio/helpers';
3
- import { resolveDynamicComponent, defineComponent, h, inject, computed, unref, reactive, ref, watch, nextTick, onBeforeUnmount, watchEffect, markRaw, shallowRef, isRef } from 'vue';
4
- import { routerKey } from 'vue-router';
5
-
6
- const simplyResolveComponent = (component) => {
7
- return resolveDynamicComponent(component);
1
+ import { createPrismic } from "./createPrismic.js";
2
+ import { usePrismic } from "./usePrismic.js";
3
+ import { PrismicEmbed } from "./components/PrismicEmbed.js";
4
+ import { PrismicImage, usePrismicImage } from "./components/PrismicImage.js";
5
+ import { PrismicLink, usePrismicLink } from "./components/PrismicLink.js";
6
+ import { PrismicText, usePrismicText } from "./components/PrismicText.js";
7
+ import { PrismicRichText, usePrismicRichText } from "./components/PrismicRichText.js";
8
+ import { SliceZone, TODOSliceComponent, defineSliceZoneComponents, getSliceComponentProps } from "./components/SliceZone.js";
9
+ import { dangerouslyUseAllPrismicDocuments, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument } from "./composables.js";
10
+ import { prismicKey } from "./injectionSymbols.js";
11
+ export {
12
+ PrismicEmbed,
13
+ PrismicImage,
14
+ PrismicLink,
15
+ PrismicRichText,
16
+ PrismicText,
17
+ SliceZone,
18
+ TODOSliceComponent,
19
+ createPrismic,
20
+ dangerouslyUseAllPrismicDocuments,
21
+ defineSliceZoneComponents,
22
+ getSliceComponentProps,
23
+ prismicKey,
24
+ useAllPrismicDocumentsByEveryTag,
25
+ useAllPrismicDocumentsByIDs,
26
+ useAllPrismicDocumentsBySomeTags,
27
+ useAllPrismicDocumentsByTag,
28
+ useAllPrismicDocumentsByType,
29
+ useAllPrismicDocumentsByUIDs,
30
+ useFirstPrismicDocument,
31
+ usePrismic,
32
+ usePrismicDocumentByID,
33
+ usePrismicDocumentByUID,
34
+ usePrismicDocuments,
35
+ usePrismicDocumentsByEveryTag,
36
+ usePrismicDocumentsByIDs,
37
+ usePrismicDocumentsBySomeTags,
38
+ usePrismicDocumentsByTag,
39
+ usePrismicDocumentsByType,
40
+ usePrismicDocumentsByUIDs,
41
+ usePrismicImage,
42
+ usePrismicLink,
43
+ usePrismicRichText,
44
+ usePrismicText,
45
+ useSinglePrismicDocument
8
46
  };
9
-
10
- const defaultWrapper$2 = "div";
11
- const PrismicEmbedImpl = /* @__PURE__ */ defineComponent({
12
- name: "PrismicEmbed",
13
- props: {
14
- field: {
15
- type: Object,
16
- required: true
17
- },
18
- wrapper: {
19
- type: [String, Object, Function],
20
- default: void 0,
21
- required: false
22
- }
23
- },
24
- setup(props) {
25
- if (!props.field) {
26
- return () => null;
27
- }
28
- return () => {
29
- return h(simplyResolveComponent(props.wrapper || defaultWrapper$2), {
30
- "data-oembed": props.field.embed_url,
31
- "data-oembed-type": props.field.type,
32
- "data-oembed-provider": props.field.provider_name,
33
- innerHTML: props.field.html || null
34
- });
35
- };
36
- }
37
- });
38
- const PrismicEmbed = PrismicEmbedImpl;
39
-
40
- if (typeof process === "undefined") {
41
- globalThis.process = { env: {} };
42
- }
43
- const __PRODUCTION__ = process.env.NODE_ENV === "production";
44
-
45
- const prismicKey = Symbol("prismic");
46
-
47
- const usePrismic = () => {
48
- return inject(prismicKey, { options: { endpoint: "" } });
49
- };
50
-
51
- const defaultImageComponent = "img";
52
- const usePrismicImage = (props) => {
53
- const { options } = usePrismic();
54
- const asImage = computed(() => {
55
- var _a, _b;
56
- const field = unref(props.field);
57
- if (!isFilled.image(field)) {
58
- return {
59
- src: null,
60
- srcset: null
61
- };
62
- }
63
- const imgixParams = unref(props.imgixParams);
64
- const widths = unref(props.widths);
65
- const pixelDensities = unref(props.pixelDensities);
66
- if (widths) {
67
- if (!__PRODUCTION__ && pixelDensities) {
68
- console.warn(
69
- "[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.",
70
- props
71
- );
72
- }
73
- return asImageWidthSrcSet(field, {
74
- ...imgixParams,
75
- widths: widths === "defaults" ? (_a = options.components) == null ? void 0 : _a.imageWidthSrcSetDefaults : widths
76
- });
77
- } else if (pixelDensities) {
78
- return asImagePixelDensitySrcSet(field, {
79
- ...imgixParams,
80
- pixelDensities: pixelDensities === "defaults" ? (_b = options.components) == null ? void 0 : _b.imagePixelDensitySrcSetDefaults : pixelDensities
81
- });
82
- } else {
83
- return {
84
- src: asImageSrc(field, imgixParams),
85
- srcset: null
86
- };
87
- }
88
- });
89
- const src = computed(() => {
90
- return asImage.value.src;
91
- });
92
- const srcset = computed(() => {
93
- return asImage.value.srcset;
94
- });
95
- const alt = computed(() => {
96
- return unref(props.field).alt || "";
97
- });
98
- const copyright = computed(() => {
99
- return unref(props.field).copyright || null;
100
- });
101
- return {
102
- src,
103
- srcset,
104
- alt,
105
- copyright
106
- };
107
- };
108
- const PrismicImageImpl = /* @__PURE__ */ defineComponent({
109
- name: "PrismicImage",
110
- props: {
111
- field: {
112
- type: Object,
113
- required: true
114
- },
115
- imageComponent: {
116
- type: [String, Object],
117
- default: void 0,
118
- required: false
119
- },
120
- imgixParams: {
121
- type: Object,
122
- default: void 0,
123
- required: false
124
- },
125
- widths: {
126
- type: [String, Object],
127
- default: void 0,
128
- required: false
129
- },
130
- pixelDensities: {
131
- type: [String, Object],
132
- default: void 0,
133
- required: false
134
- }
135
- },
136
- setup(props) {
137
- if (!props.field) {
138
- return () => null;
139
- }
140
- const { options } = usePrismic();
141
- const type = computed(() => {
142
- var _a;
143
- return props.imageComponent || ((_a = options.components) == null ? void 0 : _a.imageComponent) || defaultImageComponent;
144
- });
145
- const { src, srcset, alt, copyright } = usePrismicImage(props);
146
- return () => {
147
- const attributes = {
148
- src: src.value,
149
- srcset: srcset.value,
150
- alt: alt.value
151
- };
152
- switch (type.value) {
153
- case "img":
154
- return h("img", attributes);
155
- default:
156
- return h(simplyResolveComponent(type.value), {
157
- ...attributes,
158
- copyright: copyright.value
159
- });
160
- }
161
- };
162
- }
163
- });
164
- const PrismicImage = PrismicImageImpl;
165
-
166
- const isInternalURL = (url) => {
167
- const isInternal = /^\/(?!\/)/.test(url);
168
- const isSpecialLink = !isInternal && !/^https?:\/\//i.test(url);
169
- return isInternal && !isSpecialLink;
170
- };
171
-
172
- const getSlots = (parent, slots, defaultPayload) => {
173
- if (typeof parent === "string") {
174
- return slots.default && slots.default(defaultPayload);
175
- } else {
176
- if (slots.default) {
177
- const content = slots.default(defaultPayload);
178
- return {
179
- ...slots,
180
- default: () => content
181
- };
182
- } else {
183
- return slots;
184
- }
185
- }
186
- };
187
-
188
- const defaultInternalComponent = "router-link";
189
- const defaultExternalComponent = "a";
190
- const defaultBlankTargetRelAttribute = "noopener noreferrer";
191
- const usePrismicLink = (props) => {
192
- const { options } = usePrismic();
193
- const type = computed(() => {
194
- var _a, _b;
195
- const internalComponent = unref(props.internalComponent) || ((_a = options.components) == null ? void 0 : _a.linkInternalComponent) || defaultInternalComponent;
196
- const externalComponent = unref(props.externalComponent) || ((_b = options.components) == null ? void 0 : _b.linkExternalComponent) || defaultExternalComponent;
197
- return href.value && isInternalURL(href.value) && !target.value ? internalComponent : externalComponent;
198
- });
199
- const href = computed(() => {
200
- var _a, _b;
201
- const field = unref(props.field);
202
- const linkResolver = (_a = unref(props.linkResolver)) != null ? _a : options.linkResolver;
203
- return (_b = asLink(field, linkResolver)) != null ? _b : "";
204
- });
205
- const target = computed(() => {
206
- const field = unref(props.field);
207
- const target2 = unref(props.target);
208
- if (typeof target2 !== "undefined") {
209
- return target2;
210
- } else {
211
- return field && "target" in field && field.target ? field.target : null;
212
- }
213
- });
214
- const rel = computed(() => {
215
- var _a;
216
- const rel2 = unref(props.rel);
217
- if (typeof rel2 !== "undefined") {
218
- return rel2;
219
- } else if (target.value === "_blank") {
220
- const blankTargetRelAttribute = unref(props.blankTargetRelAttribute);
221
- if (typeof blankTargetRelAttribute !== "undefined") {
222
- return blankTargetRelAttribute;
223
- } else {
224
- return typeof ((_a = options.components) == null ? void 0 : _a.linkBlankTargetRelAttribute) !== "undefined" ? options.components.linkBlankTargetRelAttribute : defaultBlankTargetRelAttribute;
225
- }
226
- } else {
227
- return null;
228
- }
229
- });
230
- return {
231
- type,
232
- href,
233
- target,
234
- rel
235
- };
236
- };
237
- const PrismicLinkImpl = /* @__PURE__ */ defineComponent({
238
- name: "PrismicLink",
239
- props: {
240
- field: {
241
- type: Object,
242
- required: true
243
- },
244
- linkResolver: {
245
- type: Function,
246
- default: void 0,
247
- required: false
248
- },
249
- target: {
250
- type: String,
251
- default: void 0,
252
- required: false
253
- },
254
- rel: {
255
- type: String,
256
- default: void 0,
257
- required: false
258
- },
259
- blankTargetRelAttribute: {
260
- type: String,
261
- default: void 0,
262
- required: false
263
- },
264
- internalComponent: {
265
- type: [String, Object, Function],
266
- default: void 0,
267
- required: false
268
- },
269
- externalComponent: {
270
- type: [String, Object, Function],
271
- default: void 0,
272
- required: false
273
- }
274
- },
275
- setup(props, { slots }) {
276
- if (!props.field) {
277
- return () => null;
278
- }
279
- const { type, href, target, rel } = usePrismicLink(props);
280
- return () => {
281
- const parent = type.value === "a" ? "a" : simplyResolveComponent(type.value);
282
- const computedSlots = getSlots(
283
- parent,
284
- slots,
285
- reactive({ href: href.value })
286
- );
287
- if (typeof parent === "string") {
288
- return h(
289
- parent,
290
- { href: href.value, target: target.value, rel: rel.value },
291
- computedSlots
292
- );
293
- } else {
294
- return h(parent, { to: href.value }, computedSlots);
295
- }
296
- };
297
- }
298
- });
299
- const PrismicLink = PrismicLinkImpl;
300
-
301
- const defaultWrapper$1 = "div";
302
- const usePrismicText = (props) => {
303
- const text = computed(() => {
304
- var _a;
305
- const field = unref(props.field);
306
- if (!isFilled.richText(field)) {
307
- return (_a = unref(props.fallback)) != null ? _a : "";
308
- }
309
- return asText(unref(field), unref(props.separator));
310
- });
311
- return {
312
- text
313
- };
314
- };
315
- const PrismicTextImpl = /* @__PURE__ */ defineComponent({
316
- name: "PrismicText",
317
- props: {
318
- field: {
319
- type: Array,
320
- default: void 0,
321
- required: false
322
- },
323
- separator: {
324
- type: String,
325
- default: void 0,
326
- required: false
327
- },
328
- wrapper: {
329
- type: [String, Object, Function],
330
- default: void 0,
331
- required: false
332
- },
333
- fallback: {
334
- type: String,
335
- default: void 0,
336
- required: false
337
- }
338
- },
339
- setup(props) {
340
- const { text } = usePrismicText(props);
341
- return () => {
342
- const parent = simplyResolveComponent(props.wrapper || defaultWrapper$1);
343
- return h(parent, null, {
344
- default: () => text.value
345
- });
346
- };
347
- }
348
- });
349
- const PrismicText = PrismicTextImpl;
350
-
351
- const defaultWrapper = "div";
352
- const usePrismicRichText = (props) => {
353
- const { options } = usePrismic();
354
- const html = computed(() => {
355
- var _a, _b, _c;
356
- const field = unref(props.field);
357
- if (!isFilled.richText(field)) {
358
- return (_a = unref(props.fallback)) != null ? _a : "";
359
- }
360
- const linkResolver = (_b = unref(props.linkResolver)) != null ? _b : options.linkResolver;
361
- const htmlSerializer = (_c = unref(props.htmlSerializer)) != null ? _c : options.htmlSerializer;
362
- return asHTML(unref(field), linkResolver, htmlSerializer);
363
- });
364
- return {
365
- html
366
- };
367
- };
368
- const PrismicRichTextImpl = /* @__PURE__ */ defineComponent({
369
- name: "PrismicRichText",
370
- props: {
371
- field: {
372
- type: Array,
373
- default: void 0,
374
- required: false
375
- },
376
- linkResolver: {
377
- type: Function,
378
- default: void 0,
379
- required: false
380
- },
381
- htmlSerializer: {
382
- type: [Function, Object],
383
- default: void 0,
384
- required: false
385
- },
386
- wrapper: {
387
- type: [String, Object, Function],
388
- default: void 0,
389
- required: false
390
- },
391
- fallback: {
392
- type: String,
393
- default: void 0,
394
- required: false
395
- }
396
- },
397
- setup(props) {
398
- const { html } = usePrismicRichText(props);
399
- const root = ref(null);
400
- const maybeRouter = inject(routerKey, null);
401
- if (maybeRouter) {
402
- let links = [];
403
- const navigate = function(event) {
404
- event.preventDefault();
405
- maybeRouter.push(this.href);
406
- };
407
- const addListeners = () => {
408
- const node = root.value && "$el" in root.value ? root.value.$el : root.value;
409
- if (node && "querySelectorAll" in node) {
410
- links = Array.from(node.querySelectorAll("a")).map((element) => {
411
- const href = element.getAttribute("href");
412
- if (href && isInternalURL(href)) {
413
- const listener = navigate.bind({ href });
414
- element.addEventListener("click", listener);
415
- return { element, listener };
416
- } else {
417
- return false;
418
- }
419
- }).filter((link) => link);
420
- }
421
- };
422
- const removeListeners = () => {
423
- links.forEach(
424
- ({ element, listener }) => element.removeEventListener("click", listener)
425
- );
426
- links = [];
427
- };
428
- watch(
429
- html,
430
- () => {
431
- removeListeners();
432
- nextTick(addListeners);
433
- },
434
- { immediate: true }
435
- );
436
- onBeforeUnmount(() => {
437
- removeListeners();
438
- });
439
- }
440
- return () => {
441
- return h(simplyResolveComponent(props.wrapper || defaultWrapper), {
442
- innerHTML: html.value,
443
- ref: root
444
- });
445
- };
446
- }
447
- });
448
- const PrismicRichText = PrismicRichTextImpl;
449
-
450
- const getSliceComponentProps = (propsHint) => ({
451
- slice: {
452
- type: Object,
453
- required: true
454
- },
455
- index: {
456
- type: Number,
457
- required: true
458
- },
459
- slices: {
460
- type: Array,
461
- required: true
462
- },
463
- context: {
464
- type: null,
465
- required: true
466
- }
467
- });
468
- const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ defineComponent({
469
- name: "TODOSliceComponent",
470
- props: getSliceComponentProps(),
471
- setup(props) {
472
- const type = computed(
473
- () => "slice_type" in props.slice ? props.slice.slice_type : props.slice.type
474
- );
475
- watchEffect(() => {
476
- console.warn(
477
- `[SliceZone] Could not find a component for Slice type "${type.value}"`,
478
- props.slice
479
- );
480
- });
481
- return () => {
482
- return h(
483
- "section",
484
- {
485
- "data-slice-zone-todo-component": "",
486
- "data-slice-type": type.value
487
- },
488
- [`Could not find a component for Slice type "${type.value}"`]
489
- );
490
- };
491
- }
492
- });
493
- const defineSliceZoneComponents = (components) => {
494
- const result = {};
495
- let type;
496
- for (type in components) {
497
- const component = components[type];
498
- result[type] = typeof component === "string" ? component : markRaw(
499
- component
500
- );
501
- }
502
- return result;
503
- };
504
- const SliceZoneImpl = /* @__PURE__ */ defineComponent({
505
- name: "SliceZone",
506
- props: {
507
- slices: {
508
- type: Array,
509
- required: true
510
- },
511
- components: {
512
- type: Object,
513
- default: void 0,
514
- required: false
515
- },
516
- resolver: {
517
- type: Function,
518
- default: void 0,
519
- required: false
520
- },
521
- context: {
522
- type: null,
523
- default: void 0,
524
- required: false
525
- },
526
- defaultComponent: {
527
- type: Object,
528
- default: void 0,
529
- required: false
530
- },
531
- wrapper: {
532
- type: [String, Object, Function],
533
- default: void 0,
534
- required: false
535
- }
536
- },
537
- setup(props) {
538
- if (!props.slices) {
539
- return () => null;
540
- }
541
- const { options } = usePrismic();
542
- const renderedSlices = computed(() => {
543
- return props.slices.map((slice, index) => {
544
- var _a;
545
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
546
- let component = props.components && type in props.components ? props.components[type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
547
- if (props.resolver) {
548
- const resolvedComponent = props.resolver({
549
- slice,
550
- sliceName: type,
551
- i: index
552
- });
553
- if (resolvedComponent) {
554
- component = resolvedComponent;
555
- }
556
- }
557
- const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
558
- const p = {
559
- key,
560
- slice,
561
- index,
562
- context: props.context,
563
- slices: props.slices
564
- };
565
- return h(simplyResolveComponent(component), p);
566
- });
567
- });
568
- return () => {
569
- if (props.wrapper) {
570
- const parent = simplyResolveComponent(props.wrapper);
571
- if (typeof parent === "string") {
572
- return h(parent, null, renderedSlices.value);
573
- } else {
574
- return h(parent, null, { default: () => renderedSlices.value });
575
- }
576
- } else {
577
- return renderedSlices.value;
578
- }
579
- };
580
- }
581
- });
582
- const SliceZone = SliceZoneImpl;
583
-
584
- const createPrismic = (options) => {
585
- let client;
586
- if (options.client) {
587
- client = options.client;
588
- } else {
589
- client = createClient(options.endpoint, {
590
- fetch: async (endpoint, options2) => {
591
- let fetchFunction;
592
- if (typeof globalThis.fetch === "function") {
593
- fetchFunction = globalThis.fetch;
594
- } else {
595
- fetchFunction = (await import('isomorphic-unfetch')).default;
596
- }
597
- return await fetchFunction(endpoint, options2);
598
- },
599
- ...options.clientConfig
600
- });
601
- }
602
- const prismicClient = {
603
- client,
604
- predicate,
605
- cookie
606
- };
607
- const prismicHelpers = {
608
- asText,
609
- asHTML: (richTextField, linkResolver, htmlSerializer) => {
610
- return asHTML(
611
- richTextField,
612
- linkResolver || options.linkResolver,
613
- htmlSerializer || options.htmlSerializer
614
- );
615
- },
616
- asLink: (linkField, linkResolver) => {
617
- return asLink(linkField, linkResolver || options.linkResolver);
618
- },
619
- asDate,
620
- asImageSrc,
621
- asImageWidthSrcSet,
622
- asImagePixelDensitySrcSet,
623
- documentToLinkField
624
- };
625
- const prismic = {
626
- options,
627
- ...prismicClient,
628
- ...prismicHelpers,
629
- install(app) {
630
- app.provide(prismicKey, this);
631
- app.config.globalProperties.$prismic = this;
632
- if (options.injectComponents !== false) {
633
- app.component(PrismicLink.name, PrismicLink);
634
- app.component(PrismicEmbed.name, PrismicEmbed);
635
- app.component(PrismicImage.name, PrismicImage);
636
- app.component(PrismicText.name, PrismicText);
637
- app.component(PrismicRichText.name, PrismicRichText);
638
- app.component(SliceZone.name, SliceZone);
639
- }
640
- }
641
- };
642
- return prismic;
643
- };
644
-
645
- var PrismicClientComposableState = /* @__PURE__ */ ((PrismicClientComposableState2) => {
646
- PrismicClientComposableState2["Idle"] = "idle";
647
- PrismicClientComposableState2["Pending"] = "pending";
648
- PrismicClientComposableState2["Success"] = "success";
649
- PrismicClientComposableState2["Error"] = "error";
650
- return PrismicClientComposableState2;
651
- })(PrismicClientComposableState || {});
652
-
653
- const isParams = (value) => {
654
- return typeof value === "object" && value !== null && !Array.isArray(value);
655
- };
656
- const useStatefulPrismicClientMethod = (methodName, args) => {
657
- const { client } = usePrismic();
658
- const state = ref(
659
- PrismicClientComposableState.Idle
660
- );
661
- const data = shallowRef(null);
662
- const error = ref(null);
663
- const refresh = async () => {
664
- const lastArg = unref(args[args.length - 1]);
665
- const { client: explicitClient, ...params } = isParams(lastArg) ? lastArg : {};
666
- const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
667
- state.value = PrismicClientComposableState.Pending;
668
- data.value = null;
669
- error.value = null;
670
- try {
671
- data.value = await (unref(explicitClient) || client)[methodName](
672
- ...argsWithoutParams.map((arg) => unref(arg)),
673
- params
674
- );
675
- state.value = PrismicClientComposableState.Success;
676
- } catch (err) {
677
- state.value = PrismicClientComposableState.Error;
678
- error.value = err;
679
- }
680
- };
681
- const refArgs = args.filter((arg) => isRef(arg));
682
- if (refArgs.length) {
683
- watch(refArgs, refresh, { deep: true });
684
- }
685
- refresh();
686
- return { state, data, error, refresh };
687
- };
688
-
689
- const usePrismicDocuments = (...args) => useStatefulPrismicClientMethod("get", args);
690
- const useFirstPrismicDocument = (...args) => useStatefulPrismicClientMethod("getFirst", args);
691
- const usePrismicDocumentByID = (...args) => useStatefulPrismicClientMethod("getByID", args);
692
- const usePrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getByIDs", args);
693
- const useAllPrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getAllByIDs", args);
694
- const usePrismicDocumentByUID = (...args) => useStatefulPrismicClientMethod("getByUID", args);
695
- const usePrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getByUIDs", args);
696
- const useAllPrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getAllByUIDs", args);
697
- const useSinglePrismicDocument = (...args) => useStatefulPrismicClientMethod("getSingle", args);
698
- const usePrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getByType", args);
699
- const useAllPrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getAllByType", args);
700
- const usePrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getByTag", args);
701
- const useAllPrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getAllByTag", args);
702
- const usePrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getByEveryTag", args);
703
- const useAllPrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getAllByEveryTag", args);
704
- const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getBySomeTags", args);
705
- const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
706
- const dangerouslyUseAllPrismicDocuments = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
707
-
708
- 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 };
709
47
  //# sourceMappingURL=index.js.map