@prismicio/vue 2.1.0-alpha.0 → 2.1.0-alpha.1

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.
@@ -73,13 +73,15 @@ export default ({ component = "a" }) => ({
73
73
  if (typeof props.target !== "undefined" || field.target) {
74
74
  data.attrs.target =
75
75
  typeof props.target !== "undefined" ? props.target : field.target;
76
+ }
76
77
 
77
- if (data.attrs.target === "_blank") {
78
- data.attrs.rel =
79
- typeof props.rel !== "undefined"
80
- ? props.rel
81
- : props.blankTargetRelAttribute;
82
- }
78
+ if (data.attrs.target === "_blank") {
79
+ data.attrs.rel =
80
+ typeof props.rel !== "undefined"
81
+ ? props.rel
82
+ : props.blankTargetRelAttribute;
83
+ } else if (typeof props.rel !== "undefined") {
84
+ data.attrs.rel = props.rel;
83
85
  }
84
86
 
85
87
  return h("a", data, children);
@@ -30,8 +30,8 @@ export default {
30
30
  }
31
31
  const innerHTML = RichText.asHtml(
32
32
  field,
33
- linkResolver || parent.$prismic.linkResolver,
34
- htmlSerializer || parent.$prismic.htmlSerializer
33
+ linkResolver ? linkResolver : parent.$prismic ? parent.$prismic.linkResolver : undefined,
34
+ htmlSerializer ? htmlSerializer : parent.$prismic ? parent.$prismic.htmlSerializer : undefined,
35
35
  );
36
36
 
37
37
  return h(wrapper, {
@@ -31,30 +31,31 @@ export const getSliceComponentProps = (propsHint) => ({
31
31
  });
32
32
 
33
33
  export const TODOSliceComponent = __PRODUCTION__
34
- ? () => null
34
+ ? null
35
35
  : {
36
36
  name: "TODOSliceCOmponent",
37
37
  functional: true,
38
38
  props: getSliceComponentProps(),
39
- renfer(h, { props, data }) {
39
+ render(h, { props, data }) {
40
40
  console.warn(
41
41
  `[SliceZone] Could not find a component for Slice type "${props.slice.slice_type}"`,
42
42
  props.slice
43
43
  );
44
44
 
45
- return () => {
46
- return h(
47
- "section",
48
- {
49
- ...data,
45
+ return h(
46
+ "section",
47
+ {
48
+ ...data,
49
+ attrs: {
50
+ ...data.attrs,
50
51
  "data-slice-zone-todo-component": "",
51
- "data-slice-type": props.slice.slice_type,
52
+ "data-slice-type": props.slice.slice_type
52
53
  },
53
- [
54
- `Could not find a component for Slice type "${props.slice.slice_type}"`,
55
- ]
56
- );
57
- };
54
+ },
55
+ [
56
+ `Could not find a component for Slice type "${props.slice.slice_type}"`,
57
+ ]
58
+ );
58
59
  },
59
60
  };
60
61
 
@@ -63,7 +64,6 @@ export const defineSliceZoneComponents = (components) => components;
63
64
 
64
65
  export const SliceZone = {
65
66
  name: "SliceZone",
66
- functional: true,
67
67
  props: {
68
68
  slices: {
69
69
  type: Array,
@@ -95,22 +95,21 @@ export const SliceZone = {
95
95
  required: false,
96
96
  },
97
97
  },
98
- render(h, { props, data }) {
99
- // Prevent fatal if user didn't check for field, throws `Invalid prop` warn
100
- if (!props.slices) {
101
- return () => null;
102
- }
98
+ computed:{
99
+ renderedSlices() {
100
+ if (!this.slices) {
101
+ return null;
102
+ }
103
103
 
104
- const renderedSlices = computed(() => {
105
- return props.slices.map((slice, index) => {
104
+ return this.slices.map((slice, index) => {
106
105
  let component =
107
- props.components && slice.slice_type in props.components
108
- ? props.components[slice.slice_type]
109
- : props.defaultComponent || TODOSliceComponent;
106
+ this.components && slice.slice_type in this.components
107
+ ? this.components[slice.slice_type]
108
+ : this.defaultComponent || TODOSliceComponent;
110
109
 
111
110
  // TODO: Remove `resolver` in v3 in favor of `components`.
112
- if (props.resolver) {
113
- const resolvedComponent = props.resolver({
111
+ if (this.resolver) {
112
+ const resolvedComponent = this.resolver({
114
113
  slice,
115
114
  sliceName: slice.slice_type,
116
115
  i: index,
@@ -123,22 +122,24 @@ export const SliceZone = {
123
122
 
124
123
  const p = {
125
124
  key: `${slice.slice_type}-${index}`,
126
- slice,
127
- index,
128
- context: props.context,
129
- slices: props.slices,
125
+ props: {
126
+ slice,
127
+ index,
128
+ context: this.context,
129
+ slices: this.slices,
130
+ }
130
131
  };
131
132
 
132
- return h(component, p);
133
+ return { component, p };
133
134
  });
134
- });
135
-
136
- const parent = props.wrapper;
137
-
138
- if (typeof parent === "string") {
139
- return h(parent, data, renderedSlices.value);
140
- } else {
141
- return h(parent, data, { default: () => renderedSlices.value });
142
135
  }
143
136
  },
137
+ render(h) {
138
+ // Prevent fatal if user didn't check for field, throws `Invalid prop` warn
139
+ if (!this.slices) {
140
+ return null;
141
+ }
142
+
143
+ return h(this.wrapper, this.renderedSlices.map(({ component, p }) => h(component, p)));
144
+ },
144
145
  };
package/src/index.js CHANGED
@@ -1,46 +1,47 @@
1
1
  import prismicJS from "@prismicio/client";
2
+ const { client } = prismicJS;
2
3
 
3
4
  import Components from "./components";
4
5
  import { asHtml, asText, asDate, asLink } from "./methods";
5
6
 
6
7
  function attachMethods(Vue, options) {
7
- Vue.prototype.$prismic.asHtml = function(
8
+ Vue.prototype.$prismic.asHtml = function (
8
9
  richText,
9
10
  linkResolver,
10
- htmlSerializer
11
+ htmlSerializer,
11
12
  ) {
12
13
  return asHtml(
13
14
  richText,
14
15
  linkResolver || options.linkResolver,
15
- htmlSerializer || options.htmlSerializer
16
+ htmlSerializer || options.htmlSerializer,
16
17
  );
17
18
  };
18
19
  Vue.prototype.$prismic.asHTML = Vue.prototype.$prismic.asHtml;
19
20
  Vue.prototype.$prismic.asText = asText;
20
21
  Vue.prototype.$prismic.richTextAsPlain = asText;
21
22
  Vue.prototype.$prismic.asDate = asDate;
22
- Vue.prototype.$prismic.asLink = function(link, linkResolver) {
23
+ Vue.prototype.$prismic.asLink = function (link, linkResolver) {
23
24
  return asLink(link, linkResolver || options.linkResolver);
24
25
  };
25
26
  }
26
27
 
27
28
  const PrismicVue = {
28
- install: function(Vue, options) {
29
+ install: function (Vue, options) {
29
30
  const { linkType = "vueRouter" } = options;
30
31
  Vue.prototype.$prismic = prismicJS;
31
32
  Vue.prototype.$prismic.endpoint = options.endpoint;
32
33
  Vue.prototype.$prismic.linkResolver = options.linkResolver;
33
34
  Vue.prototype.$prismic.htmlSerializer = options.htmlSerializer;
34
- Vue.prototype.$prismic.client = prismicJS.client(
35
+ Vue.prototype.$prismic.client = client(
35
36
  options.endpoint,
36
- options.apiOptions
37
+ options.apiOptions,
37
38
  );
38
39
 
39
40
  attachMethods(Vue, options);
40
41
 
41
42
  const components = {
42
43
  ...Components.common,
43
- ...Components[linkType]
44
+ ...Components[linkType],
44
45
  };
45
46
 
46
47
  /**
@@ -50,7 +51,7 @@ const PrismicVue = {
50
51
  Object.entries(components).forEach(([_, c]) => {
51
52
  Vue.component(c.name, c);
52
53
  });
53
- }
54
+ },
54
55
  };
55
56
 
56
57
  export default PrismicVue;
package/src/methods.js CHANGED
@@ -1,31 +1,25 @@
1
- import PrismicDOM from 'prismic-dom'
1
+ import PrismicDOM from "prismic-dom";
2
2
 
3
3
  export function asHtml(richText, linkResolver, htmlSerializer) {
4
- if (richText) {
5
- return PrismicDOM.RichText.asHtml(
6
- richText,
7
- linkResolver,
8
- htmlSerializer
9
- )
10
- }
4
+ if (richText) {
5
+ return PrismicDOM.RichText.asHtml(richText, linkResolver, htmlSerializer);
6
+ }
11
7
  }
12
8
  export function asText(richText, joinString) {
13
- if (richText) {
14
- return PrismicDOM.RichText.asText(richText, joinString)
15
- }
16
- return ''
9
+ if (richText) {
10
+ return PrismicDOM.RichText.asText(richText, joinString);
11
+ }
12
+
13
+ return "";
17
14
  }
18
15
 
19
16
  export function asLink(link, linkResolver) {
20
- if (link) {
21
- return PrismicDOM.Link.url(
22
- link,
23
- linkResolver
24
- )
25
- }
17
+ if (link) {
18
+ return PrismicDOM.Link.url(link, linkResolver);
19
+ }
26
20
  }
27
21
  export function asDate(date) {
28
- if (date) {
29
- return PrismicDOM.Date(date)
30
- }
31
- }
22
+ if (date) {
23
+ return PrismicDOM.Date(date);
24
+ }
25
+ }
@@ -0,0 +1,86 @@
1
+ {
2
+ "prismic-embed/field": {
3
+ "type": "object",
4
+ "description": "The Prismic embed field to render."
5
+ },
6
+ "prismic-embed/wrapper": {
7
+ "type": "string | object | function",
8
+ "description": "An HTML tag name, a component, or a functional component used to wrap the output. Defaults to `\"div\"`."
9
+ },
10
+
11
+ "prismic-image/field": {
12
+ "type": "object",
13
+ "description": "The Prismic image field to render."
14
+ },
15
+
16
+ "prismic-link/field": {
17
+ "type": "object",
18
+ "description": "The Prismic link field or document to render."
19
+ },
20
+ "prismic-link/link-resolver": {
21
+ "type": "function",
22
+ "description": "A link resolver function used to resolve links when not using the route resolver parameter with `@prismicio/client`. Defaults to the link resolver provided to `@prismicio/vue` plugin if configured."
23
+ },
24
+ "prismic-link/target": {
25
+ "type": "string",
26
+ "description": "An explicit `target` attribute to apply to the rendered link."
27
+ },
28
+ "prismic-link/rel": {
29
+ "type": "string",
30
+ "description": "An explicit `rel` attribute to apply to the rendered link."
31
+ },
32
+ "prismic-link/blank-target-rel-attribute": {
33
+ "type": "string",
34
+ "description": "Value of the `rel` attribute to use on links rendered with `target=\"_blank\"`. Defaults to the one provided to `@prismicio/vue` plugin if configured, `\"noopener noreferrer\"` otherwise."
35
+ },
36
+
37
+ "prismic-rich-text/field": {
38
+ "type": "array",
39
+ "description": "The Prismic rich text or title field to render."
40
+ },
41
+ "prismic-rich-text/link-resolver": {
42
+ "type": "function",
43
+ "description": "A link resolver function used to resolve links when not using the route resolver parameter with `@prismicio/client`. Defaults to the link resolver provided to `@prismicio/vue` plugin if configured."
44
+ },
45
+ "prismic-rich-text/html-serializer": {
46
+ "type": "function | object",
47
+ "description": "An HTML serializer to customize the way rich text fields are rendered. Defaults to the HTML serializer provided to `@prismicio/vue` plugin if configured."
48
+ },
49
+ "prismic-rich-text/wrapper": {
50
+ "type": "string | object | function",
51
+ "description": "An HTML tag name, a component, or a functional component used to wrap the output. Defaults to `\"div\"`."
52
+ },
53
+
54
+ "prismic-text/field": {
55
+ "type": "array",
56
+ "description": "The Prismic rich text or title field to render."
57
+ },
58
+ "prismic-text/separator": {
59
+ "type": "string",
60
+ "description": "Separator used to join each element. Defaults to `\" \"` (a space)"
61
+ },
62
+ "prismic-text/wrapper": {
63
+ "type": "string | object | function",
64
+ "description": "An HTML tag name, a component, or a functional component used to wrap the output. Defaults to `\"div\"`."
65
+ },
66
+
67
+ "slice-zone/slices": {
68
+ "type": "array",
69
+ "description": "List of Slice data from the Slice Zone."
70
+ },
71
+ "slice-zone/components": {
72
+ "type": "array",
73
+ "description": "A record mapping Slice types to Vue components."
74
+ },
75
+ "slice-zone/context": {
76
+ "description": "Arbitrary data made available to all Slice components."
77
+ },
78
+ "slice-zone/default-component": {
79
+ "type": "string | object | function",
80
+ "description": "A component or a functional component rendered if a component mapping from the `components` prop cannot be found. Defaults to the Slice Zone default component provided to `@prismicio/vue` plugin if configured, otherwise `null` when `process.env.NODE_ENV === \"production\"` else `\"todo-slice-component\"`"
81
+ },
82
+ "slice-zone/wrapper": {
83
+ "type": "string | object | function",
84
+ "description": "An HTML tag name, a component, or a functional component used to wrap the output. Defaults to `\"div\"`."
85
+ }
86
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "prismic-embed": {
3
+ "attributes": ["field", "wrapper"],
4
+ "description": "Component to render a Prismic embed field."
5
+ },
6
+ "prismic-image": {
7
+ "attributes": ["field"],
8
+ "description": "Component to render a Prismic image field."
9
+ },
10
+ "prismic-link": {
11
+ "attributes": [
12
+ "field",
13
+ "link-resolver",
14
+ "target",
15
+ "rel",
16
+ "blank-target-rel-attribute"
17
+ ],
18
+ "description": "Component to render a Prismic link field."
19
+ },
20
+ "prismic-rich-text": {
21
+ "attributes": ["field", "link-resolver", "html-serializer", "wrapper"],
22
+ "description": "Component to render a Prismic rich text field as HTML."
23
+ },
24
+ "prismic-text": {
25
+ "attributes": ["field", "separator", "wrapper"],
26
+ "description": "Component to render a Prismic rich text field as plain text."
27
+ },
28
+ "slice-zone": {
29
+ "attributes": [
30
+ "slices",
31
+ "components",
32
+ "context",
33
+ "default-component",
34
+ "wrapper"
35
+ ],
36
+ "description": "Component to render a Prismic Slice Zone."
37
+ }
38
+ }