@prismicio/vue 2.0.10 → 2.1.0
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/LICENSE +202 -0
- package/README.md +81 -149
- package/components/common.js +290 -49
- package/components/index.js +285 -48
- package/components/umd.js +293 -51
- package/dist/prismic-vue.common.js +300 -57
- package/dist/prismic-vue.esm.js +294 -53
- package/dist/prismic-vue.js +304 -61
- package/dist/prismic-vue.min.js +1 -1
- package/package.json +86 -46
- package/src/components/Embed.js +32 -32
- package/src/components/Image.js +27 -22
- package/src/components/Link.js +87 -51
- package/src/components/RichText.js +40 -41
- package/src/components/SliceZone.js +145 -0
- package/src/components/Text.js +37 -0
- package/src/components/index.js +26 -22
- package/src/components-bundler.js +10 -5
- package/src/index.js +51 -39
- package/src/methods.js +16 -22
- package/vetur/attributes.json +86 -0
- package/vetur/tags.json +38 -0
package/package.json
CHANGED
|
@@ -1,48 +1,88 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
2
|
+
"name": "@prismicio/vue",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Vue plugin and components to fetch and present Prismic content",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"prismic",
|
|
7
|
+
"vue",
|
|
8
|
+
"plugin"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "ssh://git@github.com/prismicio/prismic-vue.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
16
|
+
"components": "dist/components.esm.js",
|
|
17
|
+
"main": "dist/prismic-vue.common.js",
|
|
18
|
+
"module": "dist/prismic-vue.esm.js",
|
|
19
|
+
"unpkg": "dist/prismic-vue.min.js",
|
|
20
|
+
"jsdelivr": "dist/prismic-vue.min.js",
|
|
21
|
+
"files": [
|
|
22
|
+
"components",
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"vetur"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rollup -c --environment BUILD:production && uglifyjs dist/prismic-vue.js -o dist/prismic-vue.min.js",
|
|
29
|
+
"dev": "rollup -c --watch --environment BUILD:development",
|
|
30
|
+
"prepare": "npm run build",
|
|
31
|
+
"format": "prettier --write .",
|
|
32
|
+
"release": "npm run build && npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
33
|
+
"release:dry": "standard-version --dry-run",
|
|
34
|
+
"release:alpha": "npm run build && npm run test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
35
|
+
"release:alpha:dry": "standard-version --release-as minor --prerelease alpha --dry-run",
|
|
36
|
+
"test": "npm run lint && npm run unit",
|
|
37
|
+
"lint": "eslint --ext .js,.ts .",
|
|
38
|
+
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/core": "^7.16.0",
|
|
42
|
+
"@babel/preset-env": "^7.16.4",
|
|
43
|
+
"@prismicio/client": "^5.1.0",
|
|
44
|
+
"@prismicio/mock": "^0.0.6",
|
|
45
|
+
"@prismicio/types": "^0.1.18",
|
|
46
|
+
"@vue/compiler-sfc": "^3.2.23",
|
|
47
|
+
"@vue/test-utils": "^1.3.0",
|
|
48
|
+
"ava": "^3.15.0",
|
|
49
|
+
"eslint": "^8.3.0",
|
|
50
|
+
"eslint-config-prettier": "^8.3.0",
|
|
51
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
52
|
+
"eslint-plugin-vue": "^8.1.1",
|
|
53
|
+
"esm": "^3.2.25",
|
|
54
|
+
"jsdom": "^18.1.1",
|
|
55
|
+
"jsdom-global": "^3.0.2",
|
|
56
|
+
"nyc": "^15.1.0",
|
|
57
|
+
"prettier": "^2.5.0",
|
|
58
|
+
"prismic-dom": "^2.2.6",
|
|
59
|
+
"rollup": "^2.60.2",
|
|
60
|
+
"rollup-plugin-auto-named-exports": "^1.0.0-beta.3",
|
|
61
|
+
"rollup-plugin-babel": "^4.4.0",
|
|
62
|
+
"rollup-plugin-commonjs": "^10.1.0",
|
|
63
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
64
|
+
"rollup-plugin-visualizer": "^5.5.2",
|
|
65
|
+
"rollup-plugin-vue": "^6.0.0",
|
|
66
|
+
"sinon": "^12.0.1",
|
|
67
|
+
"standard-version": "^9.3.2",
|
|
68
|
+
"uglify-js": "^3.14.3",
|
|
69
|
+
"vue": "^2.6.14",
|
|
70
|
+
"vue-router": "^3.5.3",
|
|
71
|
+
"vue-template-compiler": "2.6.14"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"@prismicio/client": "^4.0.0 || ^5.0.0",
|
|
75
|
+
"prismic-dom": "^2.2.0",
|
|
76
|
+
"vue": "^2.6.0"
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">= 6.0.0"
|
|
80
|
+
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"access": "public"
|
|
83
|
+
},
|
|
84
|
+
"vetur": {
|
|
85
|
+
"tags": "vetur/tags.json",
|
|
86
|
+
"attributes": "vetur/attributes.json"
|
|
87
|
+
}
|
|
48
88
|
}
|
package/src/components/Embed.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
name: 'PrismicEmbed',
|
|
3
|
+
functional: true,
|
|
4
|
+
props: {
|
|
5
|
+
field: {
|
|
6
|
+
type: Object,
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
wrapper: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: false,
|
|
12
|
+
default: 'div'
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
render(h, { props, data }) {
|
|
16
|
+
const { field, wrapper } = props
|
|
17
|
+
if (!field || !field.html) {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const { embed_url: embedUrl, type, provider_name: providerName } = field
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const attrs = {
|
|
24
|
+
...data.attrs,
|
|
25
|
+
...(embedUrl && { 'data-oembed': embedUrl }),
|
|
26
|
+
...(type && { 'data-oembed-type': type }),
|
|
27
|
+
...(providerName && { 'data-oembed-provider': providerName })
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
return h(wrapper, {
|
|
31
|
+
...Object.assign(data, { attrs }),
|
|
32
|
+
domProps: {
|
|
33
|
+
innerHTML: field.html
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
37
|
}
|
package/src/components/Image.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
name: 'PrismicImage',
|
|
3
|
+
functional: true,
|
|
4
|
+
props: {
|
|
5
|
+
field: {
|
|
6
|
+
type: Object,
|
|
7
|
+
required: true,
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
render(h, { props, data }) {
|
|
11
|
+
const { field } = props;
|
|
12
|
+
if (!field) {
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const { url, alt, copyright } = field;
|
|
17
|
+
|
|
18
|
+
return h(
|
|
19
|
+
'img',
|
|
20
|
+
Object.assign(data, {
|
|
21
|
+
attrs: {
|
|
22
|
+
...data.attrs,
|
|
23
|
+
src: url,
|
|
24
|
+
alt,
|
|
25
|
+
copyright
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
},
|
|
25
30
|
};
|
package/src/components/Link.js
CHANGED
|
@@ -1,51 +1,87 @@
|
|
|
1
|
-
import PrismicDom from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
import PrismicDom from "prismic-dom";
|
|
2
|
+
|
|
3
|
+
const isInternalURL = (url) => {
|
|
4
|
+
/**
|
|
5
|
+
* @see Regex101 expression: {@link https://regex101.com/r/1y7iod/1}
|
|
6
|
+
*/
|
|
7
|
+
const isInternal = /^\/(?!\/)/.test(url);
|
|
8
|
+
/**
|
|
9
|
+
* @see Regex101 expression: {@link https://regex101.com/r/RnUseS/1}
|
|
10
|
+
*/
|
|
11
|
+
const isSpecialLink = !isInternal && !/^https?:\/\//i.test(url);
|
|
12
|
+
|
|
13
|
+
return isInternal && !isSpecialLink;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default ({ component = "a" }) => ({
|
|
17
|
+
name: "PrismicLink",
|
|
18
|
+
functional: true,
|
|
19
|
+
props: {
|
|
20
|
+
field: {
|
|
21
|
+
type: Object,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
linkResolver: {
|
|
25
|
+
type: Function,
|
|
26
|
+
required: false,
|
|
27
|
+
},
|
|
28
|
+
target: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: undefined,
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
rel: {
|
|
34
|
+
type: String,
|
|
35
|
+
default: undefined,
|
|
36
|
+
required: false,
|
|
37
|
+
},
|
|
38
|
+
blankTargetRelAttribute: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: "noopener noreferrer",
|
|
41
|
+
required: false,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
render(h, { props, data, children, parent }) {
|
|
45
|
+
const { field, linkResolver } = props;
|
|
46
|
+
|
|
47
|
+
if (!field) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const url = parent.$prismic
|
|
52
|
+
? parent.$prismic.asLink(field, linkResolver)
|
|
53
|
+
: PrismicDom.Link.url(
|
|
54
|
+
field,
|
|
55
|
+
linkResolver ||
|
|
56
|
+
function () {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (isInternalURL(url) && !props.target) {
|
|
62
|
+
data.props = data.props || {};
|
|
63
|
+
data.props.to = url;
|
|
64
|
+
|
|
65
|
+
return h(component, data, children);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
data.attrs = {
|
|
69
|
+
...data.attrs,
|
|
70
|
+
href: url,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (typeof props.target !== "undefined") {
|
|
74
|
+
data.attrs.target = props.target;
|
|
75
|
+
} else if (field.target) {
|
|
76
|
+
data.attrs.target = field.target;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof props.rel !== "undefined") {
|
|
80
|
+
data.attrs.rel = props.rel;
|
|
81
|
+
} else if (data.attrs.target === "_blank") {
|
|
82
|
+
data.attrs.rel = props.blankTargetRelAttribute;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return h("a", data, children);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
import { RichText } from
|
|
1
|
+
import { RichText } from "prismic-dom";
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
name: "PrismicRichText",
|
|
5
|
+
functional: true,
|
|
6
|
+
props: {
|
|
7
|
+
field: {
|
|
8
|
+
type: Array,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
linkResolver: {
|
|
12
|
+
type: Function,
|
|
13
|
+
required: false,
|
|
14
|
+
},
|
|
15
|
+
htmlSerializer: {
|
|
16
|
+
type: Function,
|
|
17
|
+
required: false,
|
|
18
|
+
},
|
|
19
|
+
wrapper: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: false,
|
|
22
|
+
default: "div",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
render(h, { props, data, parent }) {
|
|
26
|
+
const { field, linkResolver, htmlSerializer, wrapper } = props;
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
if (!field) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const innerHTML = RichText.asHtml(
|
|
32
|
+
field,
|
|
33
|
+
linkResolver ? linkResolver : parent.$prismic ? parent.$prismic.linkResolver : undefined,
|
|
34
|
+
htmlSerializer ? htmlSerializer : parent.$prismic ? parent.$prismic.htmlSerializer : undefined,
|
|
35
|
+
);
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
37
|
+
return h(wrapper, {
|
|
38
|
+
...data,
|
|
39
|
+
domProps: {
|
|
40
|
+
innerHTML,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// We need to polyfill process if it doesn't exist, such as in the browser.
|
|
2
|
+
if (typeof process === "undefined") {
|
|
3
|
+
globalThis.process = { env: {} };
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `true` if in the production environment, `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* This boolean can be used to perform actions only in development environments,
|
|
10
|
+
* such as logging.
|
|
11
|
+
*/
|
|
12
|
+
const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
13
|
+
|
|
14
|
+
export const getSliceComponentProps = (propsHint) => ({
|
|
15
|
+
slice: {
|
|
16
|
+
type: Object,
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
index: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
slices: {
|
|
24
|
+
type: Array,
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
context: {
|
|
28
|
+
type: null,
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const TODOSliceComponent = __PRODUCTION__
|
|
34
|
+
? null
|
|
35
|
+
: {
|
|
36
|
+
name: "TODOSliceCOmponent",
|
|
37
|
+
functional: true,
|
|
38
|
+
props: getSliceComponentProps(),
|
|
39
|
+
render(h, { props, data }) {
|
|
40
|
+
console.warn(
|
|
41
|
+
`[SliceZone] Could not find a component for Slice type "${props.slice.slice_type}"`,
|
|
42
|
+
props.slice
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return h(
|
|
46
|
+
"section",
|
|
47
|
+
{
|
|
48
|
+
...data,
|
|
49
|
+
attrs: {
|
|
50
|
+
...data.attrs,
|
|
51
|
+
"data-slice-zone-todo-component": "",
|
|
52
|
+
"data-slice-type": props.slice.slice_type
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
[
|
|
56
|
+
`Could not find a component for Slice type "${props.slice.slice_type}"`,
|
|
57
|
+
]
|
|
58
|
+
);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Just mimiced to prevent confusion but doesn't provide any value with version 2 of this kit
|
|
63
|
+
export const defineSliceZoneComponents = (components) => components;
|
|
64
|
+
|
|
65
|
+
export const SliceZone = {
|
|
66
|
+
name: "SliceZone",
|
|
67
|
+
props: {
|
|
68
|
+
slices: {
|
|
69
|
+
type: Array,
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
components: {
|
|
73
|
+
type: Object,
|
|
74
|
+
default: undefined,
|
|
75
|
+
required: false,
|
|
76
|
+
},
|
|
77
|
+
resolver: {
|
|
78
|
+
type: Function,
|
|
79
|
+
default: undefined,
|
|
80
|
+
required: false,
|
|
81
|
+
},
|
|
82
|
+
context: {
|
|
83
|
+
type: null,
|
|
84
|
+
default: undefined,
|
|
85
|
+
required: false,
|
|
86
|
+
},
|
|
87
|
+
defaultComponent: {
|
|
88
|
+
type: Object,
|
|
89
|
+
default: undefined,
|
|
90
|
+
required: false,
|
|
91
|
+
},
|
|
92
|
+
wrapper: {
|
|
93
|
+
type: [String, Object, Function],
|
|
94
|
+
default: "div",
|
|
95
|
+
required: false,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
computed:{
|
|
99
|
+
renderedSlices() {
|
|
100
|
+
if (!this.slices) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return this.slices.map((slice, index) => {
|
|
105
|
+
let component =
|
|
106
|
+
this.components && slice.slice_type in this.components
|
|
107
|
+
? this.components[slice.slice_type]
|
|
108
|
+
: this.defaultComponent || TODOSliceComponent;
|
|
109
|
+
|
|
110
|
+
// TODO: Remove `resolver` in v3 in favor of `components`.
|
|
111
|
+
if (this.resolver) {
|
|
112
|
+
const resolvedComponent = this.resolver({
|
|
113
|
+
slice,
|
|
114
|
+
sliceName: slice.slice_type,
|
|
115
|
+
i: index,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (resolvedComponent) {
|
|
119
|
+
component = resolvedComponent;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const p = {
|
|
124
|
+
key: `${slice.slice_type}-${index}`,
|
|
125
|
+
props: {
|
|
126
|
+
slice,
|
|
127
|
+
index,
|
|
128
|
+
context: this.context,
|
|
129
|
+
slices: this.slices,
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return { component, p };
|
|
134
|
+
});
|
|
135
|
+
}
|
|
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
|
+
},
|
|
145
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { RichText } from "prismic-dom";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "PrismicText",
|
|
5
|
+
functional: true,
|
|
6
|
+
props: {
|
|
7
|
+
field: {
|
|
8
|
+
type: Array,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
separator: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: undefined,
|
|
14
|
+
required: false,
|
|
15
|
+
},
|
|
16
|
+
wrapper: {
|
|
17
|
+
type: String,
|
|
18
|
+
required: false,
|
|
19
|
+
default: "div",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
render(h, { props, data, children, parent }) {
|
|
23
|
+
const { field, separator, wrapper } = props;
|
|
24
|
+
|
|
25
|
+
if (!field) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const innerHTML = RichText.asText(field, separator);
|
|
29
|
+
|
|
30
|
+
return h(wrapper, {
|
|
31
|
+
...data,
|
|
32
|
+
domProps: {
|
|
33
|
+
innerHTML,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|