@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.
- package/components/common.js +52 -46
- package/components/index.js +52 -46
- package/components/umd.js +52 -46
- package/dist/prismic-vue.common.js +56 -48
- package/dist/prismic-vue.esm.js +56 -48
- package/dist/prismic-vue.js +56 -48
- package/dist/prismic-vue.min.js +1 -1
- package/package.json +54 -19
- package/src/components/Embed.js +32 -32
- package/src/components/Image.js +27 -22
- package/src/components/Link.js +8 -6
- package/src/components/RichText.js +2 -2
- package/src/components/SliceZone.js +40 -39
- package/src/index.js +10 -9
- package/src/methods.js +16 -22
- package/vetur/attributes.json +86 -0
- package/vetur/tags.json +38 -0
package/src/components/Link.js
CHANGED
|
@@ -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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
34
|
-
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
|
-
?
|
|
34
|
+
? null
|
|
35
35
|
: {
|
|
36
36
|
name: "TODOSliceCOmponent",
|
|
37
37
|
functional: true,
|
|
38
38
|
props: getSliceComponentProps(),
|
|
39
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
computed:{
|
|
99
|
+
renderedSlices() {
|
|
100
|
+
if (!this.slices) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
return props.slices.map((slice, index) => {
|
|
104
|
+
return this.slices.map((slice, index) => {
|
|
106
105
|
let component =
|
|
107
|
-
|
|
108
|
-
?
|
|
109
|
-
:
|
|
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 (
|
|
113
|
-
const resolvedComponent =
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
props: {
|
|
126
|
+
slice,
|
|
127
|
+
index,
|
|
128
|
+
context: this.context,
|
|
129
|
+
slices: this.slices,
|
|
130
|
+
}
|
|
130
131
|
};
|
|
131
132
|
|
|
132
|
-
return
|
|
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 =
|
|
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
|
|
1
|
+
import PrismicDOM from "prismic-dom";
|
|
2
2
|
|
|
3
3
|
export function asHtml(richText, linkResolver, htmlSerializer) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
linkResolver
|
|
24
|
-
)
|
|
25
|
-
}
|
|
17
|
+
if (link) {
|
|
18
|
+
return PrismicDOM.Link.url(link, linkResolver);
|
|
19
|
+
}
|
|
26
20
|
}
|
|
27
21
|
export function asDate(date) {
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
}
|
package/vetur/tags.json
ADDED
|
@@ -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
|
+
}
|