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