@prismicio/vue 3.0.0-alpha.2 → 3.0.0-alpha.6

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/README.md CHANGED
@@ -1,6 +1,53 @@
1
+ <!--
2
+
3
+ Replace all on all files (README.md, CONTRIBUTING.md, bug_report.md, package.json):
4
+ - @prismicio/vue
5
+ - Vue plugin, components, and composables to fetch and present Prismic content
6
+ - prismicio/prismic-vue
7
+ - prismic-vue
8
+
9
+ -->
10
+
1
11
  # @prismicio/vue
2
12
 
3
- [WIP]
13
+ [![npm version][npm-version-src]][npm-version-href]
14
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
15
+ [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
16
+ [![Codecov][codecov-src]][codecov-href]
17
+ [![Conventional Commits][conventional-commits-src]][conventional-commits-href]
18
+ [![License][license-src]][license-href]
19
+
20
+ <!-- TODO: Replacing link to Prismic with [Prismic][prismic] is useful here -->
21
+
22
+ [Vue][vue] plugin, components, and composables to fetch and present [Prismic][prismic] content.
23
+
24
+ - 📝 &nbsp;Display content from Prismic like [Rich Text][prismic-rich-text] and [Link][prismic-link] fields;
25
+ - 🍡 &nbsp;Render Prismic [Slice Zones][prismic-slices] declaratively with Vue components;
26
+ - 🎣 &nbsp;Fetch Prismic content using Vue [composition API][composition-api] or [options-api].
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ npm install @prismicio/vue
32
+ ```
33
+
34
+ ## Documentation
35
+
36
+ To discover what's new on this package check out [the changelog][changelog]. For full documentation, visit the [official Prismic documentation][prismic-docs].
37
+
38
+ ## Contributing
39
+
40
+ Whether you're helping us fix bugs, improve the docs, or spread the word, we'd love to have you as part of the Prismic developer community!
41
+
42
+ **Asking a question**: [Open a new topic][forum-question] on our community forum explaining what you want to achieve / your question. Our support team will get back to you shortly.
43
+
44
+ **Reporting a bug**: [Open an issue][repo-bug-report] explaining your application's setup and the bug you're encountering.
45
+
46
+ **Suggesting an improvement**: [Open an issue][repo-feature-request] explaining your improvement or feature so we can discuss and learn more.
47
+
48
+ **Submitting code changes**: For small fixes, feel free to [open a pull request][repo-pull-requests] with a description of your changes. For large changes, please first [open an issue][repo-feature-request] so we can discuss if and how the changes should be implemented.
49
+
50
+ For more clarity on this project and its structure you can also check out the detailed [CONTRIBUTING.md][contributing] document.
4
51
 
5
52
  ## License
6
53
 
@@ -19,3 +66,41 @@
19
66
  See the License for the specific language governing permissions and
20
67
  limitations under the License.
21
68
  ```
69
+
70
+ <!-- Links -->
71
+
72
+ [prismic]: https://prismic.io
73
+
74
+ <!-- TODO: Replace link with a more useful one if available -->
75
+
76
+ [prismic-docs]: https://prismic.io/docs/technologies/vuejs
77
+ [changelog]: ./CHANGELOG.md
78
+ [contributing]: ./CONTRIBUTING.md
79
+ [vue]: https://v3.vuejs.org
80
+ [prismic-rich-text]: https://prismic.io/docs/core-concepts/rich-text-title
81
+ [prismic-link]: https://prismic.io/docs/core-concepts/link-content-relationship
82
+ [prismic-slices]: https://prismic.io/docs/core-concepts/slices
83
+ [vue-composition]: https://v3.vuejs.org/guide/composition-api-introduction.html
84
+ [vue-options]: https://v3.vuejs.org/guide/introduction.html
85
+
86
+ <!-- TODO: Replace link with a more useful one if available -->
87
+
88
+ [forum-question]: https://community.prismic.io/c/kits-and-dev-languages/vue-js/16
89
+ [repo-bug-report]: https://github.com/prismicio/prismic-vue/issues/new?assignees=&labels=bug&template=bug_report.md&title=
90
+ [repo-feature-request]: https://github.com/prismicio/prismic-vue/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=
91
+ [repo-pull-requests]: https://github.com/prismicio/prismic-vue/pulls
92
+
93
+ <!-- Badges -->
94
+
95
+ [npm-version-src]: https://img.shields.io/npm/v/@prismicio/vue/latest.svg
96
+ [npm-version-href]: https://npmjs.com/package/@prismicio/vue
97
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@prismicio/vue.svg
98
+ [npm-downloads-href]: https://npmjs.com/package/@prismicio/vue
99
+ [github-actions-ci-src]: https://github.com/prismicio/prismic-vue/workflows/ci/badge.svg
100
+ [github-actions-ci-href]: https://github.com/prismicio/prismic-vue/actions?query=workflow%3Aci
101
+ [codecov-src]: https://img.shields.io/codecov/c/github/prismicio/prismic-vue.svg
102
+ [codecov-href]: https://codecov.io/gh/prismicio/prismic-vue
103
+ [conventional-commits-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
104
+ [conventional-commits-href]: https://conventionalcommits.org
105
+ [license-src]: https://img.shields.io/npm/l/@prismicio/vue.svg
106
+ [license-href]: https://npmjs.com/package/@prismicio/vue
package/dist/index.cjs CHANGED
@@ -6,40 +6,31 @@ const client = require('@prismicio/client');
6
6
  const helpers = require('@prismicio/helpers');
7
7
  const vue = require('vue');
8
8
  const vueRouter = require('vue-router');
9
- const escapeHTML = require('escape-html');
10
- const types = require('@prismicio/types');
11
- const richtext = require('@prismicio/richtext');
12
-
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
9
 
15
10
  function _interopNamespace(e) {
16
11
  if (e && e.__esModule) return e;
17
- var n = Object.create(null);
12
+ const n = Object.create(null);
18
13
  if (e) {
19
- Object.keys(e).forEach(function (k) {
14
+ for (const k in e) {
20
15
  if (k !== 'default') {
21
- var d = Object.getOwnPropertyDescriptor(e, k);
16
+ const d = Object.getOwnPropertyDescriptor(e, k);
22
17
  Object.defineProperty(n, k, d.get ? d : {
23
18
  enumerable: true,
24
- get: function () {
25
- return e[k];
26
- }
19
+ get: function () { return e[k]; }
27
20
  });
28
21
  }
29
- });
22
+ }
30
23
  }
31
- n['default'] = e;
24
+ n["default"] = e;
32
25
  return Object.freeze(n);
33
26
  }
34
27
 
35
- const escapeHTML__default = /*#__PURE__*/_interopDefaultLegacy(escapeHTML);
36
-
37
28
  const simplyResolveComponent = (component) => {
38
29
  return vue.resolveDynamicComponent(component);
39
30
  };
40
31
 
41
32
  const defaultWrapper$2 = "div";
42
- const PrismicEmbedImpl = vue.defineComponent({
33
+ const PrismicEmbedImpl = /* @__PURE__ */ vue.defineComponent({
43
34
  name: "PrismicEmbed",
44
35
  props: {
45
36
  field: {
@@ -75,7 +66,7 @@ const usePrismic = () => {
75
66
  };
76
67
 
77
68
  const defaultImageComponent = "img";
78
- const PrismicImageImpl = vue.defineComponent({
69
+ const PrismicImageImpl = /* @__PURE__ */ vue.defineComponent({
79
70
  name: "PrismicImage",
80
71
  props: {
81
72
  field: {
@@ -156,19 +147,35 @@ const usePrismicLink = (props) => {
156
147
  return href.value && isInternalURL(href.value) && !target.value ? internalComponent : externalComponent;
157
148
  });
158
149
  const href = vue.computed(() => {
159
- var _a, _b, _c;
150
+ var _a, _b;
160
151
  const field = vue.unref(props.field);
161
152
  const linkResolver = (_a = vue.unref(props.linkResolver)) != null ? _a : options.linkResolver;
162
- return "data" in field && field.data ? (_b = helpers.documentAsLink(field, linkResolver)) != null ? _b : "" : (_c = helpers.asLink(field, linkResolver)) != null ? _c : "";
153
+ return (_b = helpers.asLink(field, linkResolver)) != null ? _b : "";
163
154
  });
164
155
  const target = vue.computed(() => {
165
156
  const field = vue.unref(props.field);
166
- return vue.unref(props.target) || (field && "target" in field && field.target ? field.target : null);
157
+ const target2 = vue.unref(props.target);
158
+ if (typeof target2 !== "undefined") {
159
+ return target2;
160
+ } else {
161
+ return field && "target" in field && field.target ? field.target : null;
162
+ }
167
163
  });
168
164
  const rel = vue.computed(() => {
169
165
  var _a;
170
- const field = vue.unref(props.field);
171
- return vue.unref(props.rel) || (target.value === "_blank" && field && "target" in field && field ? vue.unref(props.blankTargetRelAttribute) || ((_a = options.components) == null ? void 0 : _a.linkBlankTargetRelAttribute) || defaultBlankTargetRelAttribute : null);
166
+ const rel2 = vue.unref(props.rel);
167
+ if (typeof rel2 !== "undefined") {
168
+ return rel2;
169
+ } else if (target.value === "_blank") {
170
+ const blankTargetRelAttribute = vue.unref(props.blankTargetRelAttribute);
171
+ if (typeof blankTargetRelAttribute !== "undefined") {
172
+ return blankTargetRelAttribute;
173
+ } else {
174
+ return typeof ((_a = options.components) == null ? void 0 : _a.linkBlankTargetRelAttribute) !== "undefined" ? options.components.linkBlankTargetRelAttribute : defaultBlankTargetRelAttribute;
175
+ }
176
+ } else {
177
+ return null;
178
+ }
172
179
  });
173
180
  return {
174
181
  type,
@@ -177,7 +184,7 @@ const usePrismicLink = (props) => {
177
184
  rel
178
185
  };
179
186
  };
180
- const PrismicLinkImpl = vue.defineComponent({
187
+ const PrismicLinkImpl = /* @__PURE__ */ vue.defineComponent({
181
188
  name: "PrismicLink",
182
189
  props: {
183
190
  field: {
@@ -242,7 +249,7 @@ const usePrismicText = (props) => {
242
249
  text
243
250
  };
244
251
  };
245
- const PrismicTextImpl = vue.defineComponent({
252
+ const PrismicTextImpl = /* @__PURE__ */ vue.defineComponent({
246
253
  name: "PrismicText",
247
254
  props: {
248
255
  field: {
@@ -276,43 +283,19 @@ const PrismicTextImpl = vue.defineComponent({
276
283
  const PrismicText = PrismicTextImpl;
277
284
 
278
285
  const defaultWrapper = "div";
279
- const serializeVueHyperlink = (linkResolver, node, children) => {
280
- switch (node.data.link_type) {
281
- case types.LinkType.Web: {
282
- return `<a href="${escapeHTML__default['default'](node.data.url)}" target="${node.data.target}" rel="noopener noreferrer">${children.join("")}</a>`;
283
- }
284
- case types.LinkType.Document: {
285
- return `<a data-router-link href="${helpers.asLink(node.data, linkResolver)}">${children.join("")}</a>`;
286
- }
287
- case types.LinkType.Media: {
288
- return `<a href="${node.data.url}">${children.join("")}</a>`;
289
- }
290
- }
291
- };
292
286
  const usePrismicRichText = (props) => {
293
287
  const { options } = usePrismic();
294
288
  const html = vue.computed(() => {
295
289
  var _a, _b;
296
290
  const linkResolver = (_a = vue.unref(props.linkResolver)) != null ? _a : options.linkResolver;
297
- const maybeSerializer = (_b = vue.unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
298
- let serializer = (_type, node, _content, children, _key) => {
299
- switch (node.type) {
300
- case helpers.Element.hyperlink:
301
- return serializeVueHyperlink(linkResolver, node, children);
302
- default:
303
- return null;
304
- }
305
- };
306
- if (maybeSerializer) {
307
- serializer = richtext.composeSerializers(typeof maybeSerializer === "object" ? richtext.wrapMapSerializer(maybeSerializer) : maybeSerializer, serializer);
308
- }
309
- return helpers.asHTML(vue.unref(props.field), linkResolver, serializer);
291
+ const htmlSerializer = (_b = vue.unref(props.htmlSerializer)) != null ? _b : options.htmlSerializer;
292
+ return helpers.asHTML(vue.unref(props.field), linkResolver, htmlSerializer);
310
293
  });
311
294
  return {
312
295
  html
313
296
  };
314
297
  };
315
- const PrismicRichTextImpl = vue.defineComponent({
298
+ const PrismicRichTextImpl = /* @__PURE__ */ vue.defineComponent({
316
299
  name: "PrismicRichText",
317
300
  props: {
318
301
  field: {
@@ -343,31 +326,29 @@ const PrismicRichTextImpl = vue.defineComponent({
343
326
  const root = vue.ref(null);
344
327
  const maybeRouter = vue.inject(vueRouter.routerKey, null);
345
328
  if (maybeRouter) {
346
- let links = null;
347
- const navigate = (event) => {
348
- let target = event.target;
349
- let i = 0;
350
- while (i < 5 && target && !(target instanceof HTMLAnchorElement) && target.parentNode) {
351
- target = target.parentNode;
352
- i++;
353
- }
354
- if (!(target instanceof HTMLAnchorElement)) {
355
- return;
356
- }
357
- const href = target.getAttribute("href");
358
- if (href && isInternalURL(href)) {
359
- event.preventDefault();
360
- maybeRouter.push(href);
361
- }
329
+ let links = [];
330
+ const navigate = function(event) {
331
+ event.preventDefault();
332
+ maybeRouter.push(this.href);
362
333
  };
363
334
  const addListeners = () => {
364
335
  const node = root.value && "$el" in root.value ? root.value.$el : root.value;
365
- links = node && node.querySelectorAll && node.querySelectorAll("a[data-router-link]");
366
- links && links.forEach((link) => link.addEventListener("click", navigate));
336
+ if (node && "querySelectorAll" in node) {
337
+ links = Array.from(node.querySelectorAll("a")).map((element) => {
338
+ const href = element.getAttribute("href");
339
+ if (href && isInternalURL(href)) {
340
+ const listener = navigate.bind({ href });
341
+ element.addEventListener("click", listener);
342
+ return { element, listener };
343
+ } else {
344
+ return false;
345
+ }
346
+ }).filter((link) => link);
347
+ }
367
348
  };
368
349
  const removeListeners = () => {
369
- links == null ? void 0 : links.forEach((link) => link.removeEventListener("click", navigate));
370
- links = null;
350
+ links.forEach(({ element, listener }) => element.removeEventListener("click", listener));
351
+ links = [];
371
352
  };
372
353
  vue.watch(html, () => {
373
354
  removeListeners();
@@ -410,7 +391,7 @@ const getSliceComponentProps = (propsHint) => ({
410
391
  required: true
411
392
  }
412
393
  });
413
- const TODOSliceComponent = __PRODUCTION__ ? () => null : vue.defineComponent({
394
+ const TODOSliceComponent = __PRODUCTION__ ? () => null : /* @__PURE__ */ vue.defineComponent({
414
395
  name: "TODOSliceCOmponent",
415
396
  props: getSliceComponentProps(),
416
397
  setup(props) {
@@ -427,7 +408,7 @@ const TODOSliceComponent = __PRODUCTION__ ? () => null : vue.defineComponent({
427
408
  };
428
409
  }
429
410
  });
430
- const getSliceZoneComponents = (components) => {
411
+ const defineSliceZoneComponents = (components) => {
431
412
  const result = {};
432
413
  let type;
433
414
  for (type in components) {
@@ -436,7 +417,7 @@ const getSliceZoneComponents = (components) => {
436
417
  }
437
418
  return result;
438
419
  };
439
- const SliceZoneImpl = vue.defineComponent({
420
+ const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
440
421
  name: "SliceZone",
441
422
  props: {
442
423
  slices: {
@@ -445,7 +426,13 @@ const SliceZoneImpl = vue.defineComponent({
445
426
  },
446
427
  components: {
447
428
  type: Object,
448
- required: true
429
+ default: void 0,
430
+ required: false
431
+ },
432
+ resolver: {
433
+ type: Function,
434
+ default: void 0,
435
+ required: false
449
436
  },
450
437
  context: {
451
438
  type: null,
@@ -471,8 +458,19 @@ const SliceZoneImpl = vue.defineComponent({
471
458
  const renderedSlices = vue.computed(() => {
472
459
  return props.slices.map((slice, index) => {
473
460
  var _a;
474
- const component = slice.slice_type in props.components ? props.components[slice.slice_type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
461
+ 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;
462
+ if (props.resolver) {
463
+ const resolvedComponent = props.resolver({
464
+ slice,
465
+ sliceName: slice.slice_type,
466
+ i: index
467
+ });
468
+ if (resolvedComponent) {
469
+ component = resolvedComponent;
470
+ }
471
+ }
475
472
  const p = {
473
+ key: `${slice.slice_type}-${index}`,
476
474
  slice,
477
475
  index,
478
476
  context: props.context,
@@ -534,10 +532,7 @@ const createPrismic = (options) => {
534
532
  return helpers.asLink(linkField, linkResolver || options.linkResolver);
535
533
  },
536
534
  asDate: helpers.asDate,
537
- documentToLinkField: helpers.documentToLinkField,
538
- documentAsLink: (prismicDocument, linkResolver) => {
539
- return helpers.documentAsLink(prismicDocument, linkResolver || options.linkResolver);
540
- }
535
+ documentToLinkField: helpers.documentToLinkField
541
536
  };
542
537
  const prismic = {
543
538
  options,
@@ -600,18 +595,22 @@ const useStatefulPrismicClientMethod = (methodName, args) => {
600
595
 
601
596
  const usePrismicDocuments = (...args) => useStatefulPrismicClientMethod("get", args);
602
597
  const useFirstPrismicDocument = (...args) => useStatefulPrismicClientMethod("getFirst", args);
603
- const useAllPrismicDocuments = (...args) => useStatefulPrismicClientMethod("getAll", args);
604
598
  const usePrismicDocumentByID = (...args) => useStatefulPrismicClientMethod("getByID", args);
605
599
  const usePrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getByIDs", args);
606
600
  const useAllPrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getAllByIDs", args);
607
601
  const usePrismicDocumentByUID = (...args) => useStatefulPrismicClientMethod("getByUID", args);
602
+ const usePrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getByUIDs", args);
603
+ const useAllPrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getAllByUIDs", args);
608
604
  const useSinglePrismicDocument = (...args) => useStatefulPrismicClientMethod("getSingle", args);
609
605
  const usePrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getByType", args);
610
606
  const useAllPrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getAllByType", args);
611
607
  const usePrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getByTag", args);
612
608
  const useAllPrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getAllByTag", args);
613
- const usePrismicDocumentsByTags = (...args) => useStatefulPrismicClientMethod("getByTags", args);
614
- const useAllPrismicDocumentsByTags = (...args) => useStatefulPrismicClientMethod("getAllByTags", args);
609
+ const usePrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getByEveryTag", args);
610
+ const useAllPrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getAllByEveryTag", args);
611
+ const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getBySomeTags", args);
612
+ const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
613
+ const dangerouslyUseAllPrismicDocuments = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
615
614
 
616
615
  exports.PrismicEmbed = PrismicEmbed;
617
616
  exports.PrismicImage = PrismicImage;
@@ -622,24 +621,29 @@ exports.SliceZone = SliceZone;
622
621
  exports.SliceZoneImpl = SliceZoneImpl;
623
622
  exports.TODOSliceComponent = TODOSliceComponent;
624
623
  exports.createPrismic = createPrismic;
624
+ exports.dangerouslyUseAllPrismicDocuments = dangerouslyUseAllPrismicDocuments;
625
+ exports.defineSliceZoneComponents = defineSliceZoneComponents;
625
626
  exports.getSliceComponentProps = getSliceComponentProps;
626
- exports.getSliceZoneComponents = getSliceZoneComponents;
627
627
  exports.prismicKey = prismicKey;
628
- exports.useAllPrismicDocuments = useAllPrismicDocuments;
628
+ exports.useAllPrismicDocumentsByEveryTag = useAllPrismicDocumentsByEveryTag;
629
629
  exports.useAllPrismicDocumentsByIDs = useAllPrismicDocumentsByIDs;
630
+ exports.useAllPrismicDocumentsBySomeTags = useAllPrismicDocumentsBySomeTags;
630
631
  exports.useAllPrismicDocumentsByTag = useAllPrismicDocumentsByTag;
631
- exports.useAllPrismicDocumentsByTags = useAllPrismicDocumentsByTags;
632
632
  exports.useAllPrismicDocumentsByType = useAllPrismicDocumentsByType;
633
+ exports.useAllPrismicDocumentsByUIDs = useAllPrismicDocumentsByUIDs;
633
634
  exports.useFirstPrismicDocument = useFirstPrismicDocument;
634
635
  exports.usePrismic = usePrismic;
635
636
  exports.usePrismicDocumentByID = usePrismicDocumentByID;
636
637
  exports.usePrismicDocumentByUID = usePrismicDocumentByUID;
637
638
  exports.usePrismicDocuments = usePrismicDocuments;
639
+ exports.usePrismicDocumentsByEveryTag = usePrismicDocumentsByEveryTag;
638
640
  exports.usePrismicDocumentsByIDs = usePrismicDocumentsByIDs;
641
+ exports.usePrismicDocumentsBySomeTags = usePrismicDocumentsBySomeTags;
639
642
  exports.usePrismicDocumentsByTag = usePrismicDocumentsByTag;
640
- exports.usePrismicDocumentsByTags = usePrismicDocumentsByTags;
641
643
  exports.usePrismicDocumentsByType = usePrismicDocumentsByType;
644
+ exports.usePrismicDocumentsByUIDs = usePrismicDocumentsByUIDs;
642
645
  exports.usePrismicLink = usePrismicLink;
643
646
  exports.usePrismicRichText = usePrismicRichText;
644
647
  exports.usePrismicText = usePrismicText;
645
648
  exports.useSinglePrismicDocument = useSinglePrismicDocument;
649
+ //# sourceMappingURL=index.cjs.map