@prismicio/vue 5.3.0-pr.86.915aa0e → 5.3.0-pr.88.72388e2
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/dist/PrismicImage.vue.d.cts +26 -54
- package/dist/PrismicImage.vue.d.cts.map +1 -1
- package/dist/PrismicLink.vue.d.cts +56 -48
- package/dist/PrismicLink.vue.d.cts.map +1 -1
- package/dist/PrismicRichText/PrismicRichText.vue.d.cts +18 -41
- package/dist/PrismicRichText/PrismicRichText.vue.d.cts.map +1 -1
- package/dist/PrismicRichText/types.d.cts +3 -3
- package/dist/PrismicRichText/types.d.cts.map +1 -1
- package/dist/PrismicTable/PrismicTable.vue.d.cts +4 -4
- package/dist/PrismicTable/PrismicTable.vue.d.cts.map +1 -1
- package/dist/PrismicTable/types.d.cts +1 -2
- package/dist/PrismicTable/types.d.cts.map +1 -1
- package/dist/PrismicText.vue.d.cts +1 -3
- package/dist/PrismicText.vue.d.cts.map +1 -1
- package/dist/SliceZone/SliceZone.vue.d.cts +3 -14
- package/dist/SliceZone/SliceZone.vue.d.cts.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/src/PrismicImage.cjs.map +1 -1
- package/dist/src/PrismicImage.js.map +1 -1
- package/dist/src/PrismicImage.vue.d.ts +30 -58
- package/dist/src/PrismicImage.vue.d.ts.map +1 -1
- package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicLink.cjs.map +1 -1
- package/dist/src/PrismicLink.js.map +1 -1
- package/dist/src/PrismicLink.vue.d.ts +60 -52
- package/dist/src/PrismicLink.vue.d.ts.map +1 -1
- package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts +22 -45
- package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs +39 -22
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js +39 -22
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs +6 -26
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js +6 -26
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs +7 -48
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js +7 -48
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/types.d.ts +3 -3
- package/dist/src/PrismicRichText/types.d.ts.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue.d.ts +6 -6
- package/dist/src/PrismicTable/PrismicTable.vue.d.ts.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs +43 -15
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js +44 -16
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs +13 -10
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js +14 -11
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicTable/types.d.ts +1 -2
- package/dist/src/PrismicTable/types.d.ts.map +1 -1
- package/dist/src/PrismicText.cjs.map +1 -1
- package/dist/src/PrismicText.js.map +1 -1
- package/dist/src/PrismicText.vue.d.ts +3 -5
- package/dist/src/PrismicText.vue.d.ts.map +1 -1
- package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/SliceZone/SliceZone.cjs.map +1 -1
- package/dist/src/SliceZone/SliceZone.js.map +1 -1
- package/dist/src/SliceZone/SliceZone.vue.d.ts +5 -16
- package/dist/src/SliceZone/SliceZone.vue.d.ts.map +1 -1
- package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/types.cjs +9 -0
- package/dist/src/types.cjs.map +1 -0
- package/dist/src/types.d.ts +3 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -0
- package/dist/types.d.cts +3 -2
- package/dist/types.d.cts.map +1 -1
- package/package.json +1 -1
- package/src/PrismicImage.vue +8 -16
- package/src/PrismicLink.vue +12 -12
- package/src/PrismicRichText/PrismicRichText.vue +69 -49
- package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +38 -22
- package/src/PrismicRichText/PrismicRichTextSerialize.vue +5 -51
- package/src/PrismicRichText/types.ts +17 -13
- package/src/PrismicTable/PrismicTable.vue +44 -17
- package/src/PrismicTable/PrismicTableDefaultComponents.ts +14 -8
- package/src/PrismicTable/PrismicTableRow.vue +17 -24
- package/src/PrismicTable/types.ts +14 -11
- package/src/PrismicText.vue +1 -3
- package/src/SliceZone/SliceZone.vue +3 -14
- package/src/types.ts +31 -1
- package/src/lib/Wrapper.vue +0 -22
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import type { LinkResolverFunction } from "@prismicio/client"
|
|
3
3
|
import { computed } from "vue"
|
|
4
4
|
|
|
5
|
-
import type { ComponentOrTagName } from "../types"
|
|
6
5
|
import type { RichTextComponentProps, VueShorthand } from "./types"
|
|
7
6
|
|
|
8
7
|
import PrismicImage from "../PrismicImage.vue"
|
|
@@ -11,19 +10,21 @@ import PrismicLink from "../PrismicLink.vue"
|
|
|
11
10
|
const props = defineProps<
|
|
12
11
|
RichTextComponentProps & {
|
|
13
12
|
linkResolver?: LinkResolverFunction
|
|
14
|
-
internalLinkComponent?: ComponentOrTagName
|
|
15
|
-
externalLinkComponent?: ComponentOrTagName
|
|
16
13
|
shorthand?: VueShorthand
|
|
17
14
|
}
|
|
18
15
|
>()
|
|
19
16
|
defineOptions({ name: "PrismicRichTextDefaultComponent" })
|
|
20
17
|
|
|
21
18
|
const as = computed(() => {
|
|
22
|
-
return props.node.type !== "image" && props.node.type !== "span"
|
|
19
|
+
return props.node.type !== "image" && props.node.type !== "span"
|
|
20
|
+
? props.shorthand?.as
|
|
21
|
+
: undefined
|
|
23
22
|
})
|
|
24
23
|
|
|
25
24
|
const attrs = computed(() => {
|
|
26
|
-
|
|
25
|
+
const { as, ...attrs } = props.shorthand ?? {}
|
|
26
|
+
|
|
27
|
+
return attrs
|
|
27
28
|
})
|
|
28
29
|
|
|
29
30
|
const dir = computed(() => {
|
|
@@ -35,18 +36,36 @@ const dir = computed(() => {
|
|
|
35
36
|
|
|
36
37
|
<template>
|
|
37
38
|
<component v-if="as" :is="as" :dir="dir" v-bind="attrs"><slot /></component>
|
|
38
|
-
<h1 v-else-if="node.type === 'heading1'" :dir="dir" v-bind="attrs"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<
|
|
39
|
+
<h1 v-else-if="node.type === 'heading1'" :dir="dir" v-bind="attrs">
|
|
40
|
+
<slot />
|
|
41
|
+
</h1>
|
|
42
|
+
<h2 v-else-if="node.type === 'heading2'" :dir="dir" v-bind="attrs">
|
|
43
|
+
<slot />
|
|
44
|
+
</h2>
|
|
45
|
+
<h3 v-else-if="node.type === 'heading3'" :dir="dir" v-bind="attrs">
|
|
46
|
+
<slot />
|
|
47
|
+
</h3>
|
|
48
|
+
<h4 v-else-if="node.type === 'heading4'" :dir="dir" v-bind="attrs">
|
|
49
|
+
<slot />
|
|
50
|
+
</h4>
|
|
51
|
+
<h5 v-else-if="node.type === 'heading5'" :dir="dir" v-bind="attrs">
|
|
52
|
+
<slot />
|
|
53
|
+
</h5>
|
|
54
|
+
<h6 v-else-if="node.type === 'heading6'" :dir="dir" v-bind="attrs">
|
|
55
|
+
<slot />
|
|
56
|
+
</h6>
|
|
57
|
+
<p v-else-if="node.type === 'paragraph'" :dir="dir" v-bind="attrs">
|
|
58
|
+
<slot />
|
|
59
|
+
</p>
|
|
45
60
|
<pre v-else-if="node.type === 'preformatted'" v-bind="attrs"><slot /></pre>
|
|
46
61
|
<strong v-else-if="node.type === 'strong'" v-bind="attrs"><slot /></strong>
|
|
47
62
|
<em v-else-if="node.type === 'em'" v-bind="attrs"><slot /></em>
|
|
48
|
-
<li v-else-if="node.type === 'list-item'" :dir="dir" v-bind="attrs"
|
|
49
|
-
|
|
63
|
+
<li v-else-if="node.type === 'list-item'" :dir="dir" v-bind="attrs">
|
|
64
|
+
<slot />
|
|
65
|
+
</li>
|
|
66
|
+
<li v-else-if="node.type === 'o-list-item'" :dir="dir" v-bind="attrs">
|
|
67
|
+
<slot />
|
|
68
|
+
</li>
|
|
50
69
|
<ul v-else-if="node.type === 'group-list-item'" v-bind="attrs">
|
|
51
70
|
<slot />
|
|
52
71
|
</ul>
|
|
@@ -54,11 +73,7 @@ const dir = computed(() => {
|
|
|
54
73
|
<slot />
|
|
55
74
|
</ol>
|
|
56
75
|
<p class="block-img" v-else-if="node.type === 'image'">
|
|
57
|
-
<PrismicLink
|
|
58
|
-
v-if="node.linkTo"
|
|
59
|
-
:field="node.linkTo"
|
|
60
|
-
:internal-component="internalLinkComponent"
|
|
61
|
-
:external-component="externalLinkComponent"
|
|
76
|
+
<PrismicLink v-if="node.linkTo" :field="node.linkTo"
|
|
62
77
|
><PrismicImage :field="node"
|
|
63
78
|
/></PrismicLink>
|
|
64
79
|
<PrismicImage v-else :field="node" v-bind="attrs" />
|
|
@@ -75,12 +90,13 @@ const dir = computed(() => {
|
|
|
75
90
|
v-else-if="node.type === 'hyperlink'"
|
|
76
91
|
:field="node.data"
|
|
77
92
|
:link-resolver="linkResolver"
|
|
78
|
-
:internal-component="internalLinkComponent"
|
|
79
|
-
:external-component="externalLinkComponent"
|
|
80
93
|
v-bind="attrs"
|
|
81
94
|
><slot
|
|
82
95
|
/></PrismicLink>
|
|
83
|
-
<span
|
|
96
|
+
<span
|
|
97
|
+
v-else-if="node.type === 'label'"
|
|
98
|
+
:class="node.data.label"
|
|
99
|
+
v-bind="attrs"
|
|
84
100
|
><slot
|
|
85
101
|
/></span>
|
|
86
102
|
<template v-else v-for="(line, index) in node.text.split('\n')" :key="line"
|
|
@@ -1,73 +1,27 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import type { LinkResolverFunction } from "@prismicio/client"
|
|
3
2
|
import type { asTree } from "@prismicio/client/richtext"
|
|
4
3
|
|
|
5
|
-
import type {
|
|
6
|
-
import type { VueRichTextSerializer, VueShorthand } from "./types"
|
|
7
|
-
|
|
8
|
-
import PrismicRichTextDefaultComponent from "./PrismicRichTextDefaultComponent.vue"
|
|
9
|
-
|
|
10
|
-
const CHILD_TYPE_RENAMES = {
|
|
11
|
-
"list-item": "listItem",
|
|
12
|
-
"o-list-item": "oListItem",
|
|
13
|
-
"group-list-item": "list",
|
|
14
|
-
"group-o-list-item": "oList",
|
|
15
|
-
} as const
|
|
4
|
+
import type { InternalVueRichTextComponent } from "./types"
|
|
16
5
|
|
|
17
6
|
type PrismicRichTextSerializeProps = {
|
|
18
|
-
components?: VueRichTextSerializer
|
|
19
7
|
children: ReturnType<typeof asTree>["children"]
|
|
20
|
-
|
|
21
|
-
internalLinkComponent?: ComponentOrTagName
|
|
22
|
-
externalLinkComponent?: ComponentOrTagName
|
|
8
|
+
internalComponents: InternalVueRichTextComponent
|
|
23
9
|
}
|
|
24
10
|
|
|
25
11
|
const props = defineProps<PrismicRichTextSerializeProps>()
|
|
26
12
|
defineOptions({ name: "PrismicRichTextSerialize" })
|
|
27
|
-
|
|
28
|
-
function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
|
|
29
|
-
const maybeComponentOrShorthand =
|
|
30
|
-
props.components?.[
|
|
31
|
-
CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
|
|
32
|
-
(child.type as keyof typeof props.components)
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
typeof maybeComponentOrShorthand === "function" ||
|
|
37
|
-
(typeof maybeComponentOrShorthand === "object" &&
|
|
38
|
-
(typeof maybeComponentOrShorthand.render === "function" ||
|
|
39
|
-
typeof maybeComponentOrShorthand.setup === "function" ||
|
|
40
|
-
!!maybeComponentOrShorthand.__file ||
|
|
41
|
-
!!maybeComponentOrShorthand.__name) || typeof maybeComponentOrShorthand?.props === "object")
|
|
42
|
-
) {
|
|
43
|
-
return { is: maybeComponentOrShorthand }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
is: PrismicRichTextDefaultComponent,
|
|
48
|
-
props: {
|
|
49
|
-
linkResolver: props.linkResolver,
|
|
50
|
-
internalLinkComponent: props.internalLinkComponent,
|
|
51
|
-
externalLinkComponent: props.externalLinkComponent,
|
|
52
|
-
shorthand: maybeComponentOrShorthand,
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
13
|
</script>
|
|
57
14
|
|
|
58
15
|
<template>
|
|
59
16
|
<component
|
|
60
17
|
v-for="child in props.children"
|
|
61
18
|
:key="JSON.stringify(child)"
|
|
62
|
-
:is="
|
|
19
|
+
:is="internalComponents[child.type].is"
|
|
63
20
|
:node="child.node"
|
|
64
|
-
v-bind="
|
|
21
|
+
v-bind="internalComponents[child.type].props"
|
|
65
22
|
><PrismicRichTextSerialize
|
|
66
23
|
v-if="child.children.length"
|
|
67
24
|
:children="child.children"
|
|
68
|
-
:components="
|
|
69
|
-
:link-resolver="linkResolver"
|
|
70
|
-
:internal-link-component="internalLinkComponent"
|
|
71
|
-
:external-link-component="externalLinkComponent"
|
|
25
|
+
:internal-components="internalComponents"
|
|
72
26
|
/></component>
|
|
73
27
|
</template>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { RTAnyNode, RichTextNodeType } from "@prismicio/client"
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "
|
|
2
|
+
LinkResolverFunction,
|
|
3
|
+
RTAnyNode,
|
|
4
|
+
RichTextNodeType,
|
|
5
|
+
} from "@prismicio/client"
|
|
6
|
+
|
|
7
|
+
import type { VueComponent } from "../types"
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* A map of Rich Text block types to Vue Components. It is used to render Rich
|
|
@@ -27,14 +28,9 @@ export type RichTextComponentProps<TRTNode extends RTAnyNode = RTAnyNode> = {
|
|
|
27
28
|
*
|
|
28
29
|
* @typeParam TRTNode - The type of rich text node(s) this component handles
|
|
29
30
|
*/
|
|
30
|
-
type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| DefineComponent<{}, {}, any>
|
|
34
|
-
// Likewise, for reference with TypeScript files.
|
|
35
|
-
| ReturnType<typeof defineAsyncComponent>
|
|
36
|
-
| DefineComponent<RichTextComponentProps<TRTNode>>
|
|
37
|
-
| FunctionalComponent<RichTextComponentProps<TRTNode>>
|
|
31
|
+
type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> = VueComponent<
|
|
32
|
+
RichTextComponentProps<TRTNode>
|
|
33
|
+
>
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
36
|
* A shorthand definition for {@link VueRichTextSerializer} component types.
|
|
@@ -50,3 +46,11 @@ export type VueShorthand = {
|
|
|
50
46
|
*/
|
|
51
47
|
[Attribute: string]: string | boolean | null | undefined
|
|
52
48
|
}
|
|
49
|
+
|
|
50
|
+
export type InternalVueRichTextComponent = Record<
|
|
51
|
+
(typeof RichTextNodeType)[keyof typeof RichTextNodeType],
|
|
52
|
+
{
|
|
53
|
+
is: VueRichTextComponent
|
|
54
|
+
props?: { linkResolver?: LinkResolverFunction; shorthand?: VueShorthand }
|
|
55
|
+
}
|
|
56
|
+
>
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { type TableField, isFilled } from "@prismicio/client"
|
|
3
3
|
import { computed } from "vue"
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import type
|
|
5
|
+
import type { VueShorthand } from "../PrismicRichText/types"
|
|
6
|
+
import { type ComponentOrTagName, isVueComponent } from "../types"
|
|
7
|
+
import type { InternalVueTableComponents, VueTableComponents } from "./types"
|
|
7
8
|
|
|
8
9
|
import type { VueRichTextSerializer } from "../PrismicRichText"
|
|
9
10
|
|
|
@@ -14,19 +15,19 @@ import PrismicTableRow from "./PrismicTableRow.vue"
|
|
|
14
15
|
* Props for `<PrismicTable />`.
|
|
15
16
|
*/
|
|
16
17
|
export type PrismicTableProps = {
|
|
17
|
-
/**
|
|
18
|
-
* The Prismic table field to render.
|
|
19
|
-
*/
|
|
18
|
+
/** The Prismic table field to render. */
|
|
20
19
|
field: TableField | undefined
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
|
-
* An object that maps a table block type to a Vue component.
|
|
22
|
+
* An object that maps a table block type to a Vue component or a shorthand definition.
|
|
24
23
|
*
|
|
25
24
|
* @example
|
|
26
25
|
*
|
|
27
26
|
* ```javascript
|
|
28
27
|
* {
|
|
29
28
|
* table: Table,
|
|
29
|
+
* thead: { class: 'bg-black text-white' },
|
|
30
|
+
* th: { as: 'td', class: 'font-bold' },
|
|
30
31
|
* }
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
@@ -42,39 +43,65 @@ export type PrismicTableProps = {
|
|
|
42
43
|
const props = defineProps<PrismicTableProps>()
|
|
43
44
|
defineOptions({ name: "PrismicTable" })
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
function getInternalComponent(type: keyof VueTableComponents) {
|
|
47
|
+
const maybeComponentOrShorthand = props.components?.[type]
|
|
48
|
+
|
|
49
|
+
if (isVueComponent(maybeComponentOrShorthand)) {
|
|
50
|
+
return { is: maybeComponentOrShorthand }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
is: defaultTableComponents[type],
|
|
55
|
+
shorthand: maybeComponentOrShorthand as VueShorthand,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const tableComponents = computed<InternalVueTableComponents>(() => {
|
|
60
|
+
return {
|
|
61
|
+
table: getInternalComponent("table"),
|
|
62
|
+
thead: getInternalComponent("thead"),
|
|
63
|
+
tbody: getInternalComponent("tbody"),
|
|
64
|
+
tr: getInternalComponent("tr"),
|
|
65
|
+
th: getInternalComponent("th"),
|
|
66
|
+
td: getInternalComponent("td"),
|
|
67
|
+
}
|
|
68
|
+
})
|
|
49
69
|
</script>
|
|
50
70
|
|
|
51
71
|
<template>
|
|
52
72
|
<component
|
|
53
73
|
v-if="isFilled.table(field)"
|
|
54
|
-
:is="
|
|
74
|
+
:is="tableComponents.table.is"
|
|
55
75
|
:table="field"
|
|
56
|
-
v-bind="
|
|
76
|
+
v-bind="{ ...$attrs, ...tableComponents.table.shorthand }"
|
|
57
77
|
>
|
|
58
78
|
<component
|
|
59
79
|
v-if="field.head"
|
|
60
|
-
:is="
|
|
80
|
+
:is="tableComponents.thead.is"
|
|
61
81
|
:head="field.head"
|
|
82
|
+
v-bind="tableComponents.thead.shorthand"
|
|
62
83
|
>
|
|
63
84
|
<PrismicTableRow
|
|
64
85
|
v-for="row in field.head.rows"
|
|
65
86
|
:key="row.key"
|
|
66
87
|
:row="row"
|
|
67
|
-
:
|
|
88
|
+
:internalTableComponents="tableComponents"
|
|
89
|
+
:components="components"
|
|
68
90
|
/>
|
|
69
91
|
</component>
|
|
70
|
-
<component
|
|
92
|
+
<component
|
|
93
|
+
:is="tableComponents.tbody.is"
|
|
94
|
+
:body="field.body"
|
|
95
|
+
v-bind="tableComponents.tbody.shorthand"
|
|
96
|
+
>
|
|
71
97
|
<PrismicTableRow
|
|
72
98
|
v-for="row in field.body.rows"
|
|
73
99
|
:key="row.key"
|
|
74
100
|
:row="row"
|
|
75
|
-
:
|
|
101
|
+
:internalTableComponents="tableComponents"
|
|
102
|
+
:components="components"
|
|
76
103
|
/>
|
|
77
104
|
</component>
|
|
78
105
|
</component>
|
|
79
|
-
<component v-else-if="fallback" :is="fallback" />
|
|
106
|
+
<component v-else-if="fallback" :is="fallback" v-bind="$attrs" />
|
|
80
107
|
</template>
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { defineComponent, h } from "vue"
|
|
2
2
|
import type { PropType } from "vue"
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { DefaultVueTableComponents } from "./types"
|
|
5
5
|
|
|
6
6
|
import * as getTableComponentProps from "./getTableComponentProps"
|
|
7
7
|
|
|
8
|
-
export const defaultTableComponents:
|
|
8
|
+
export const defaultTableComponents: DefaultVueTableComponents = {
|
|
9
9
|
table: defineComponent({
|
|
10
10
|
props: {
|
|
11
11
|
...getTableComponentProps.table(),
|
|
12
12
|
as: { type: String as PropType<string | undefined> },
|
|
13
13
|
},
|
|
14
14
|
setup(props, { attrs, slots }) {
|
|
15
|
-
return () =>
|
|
15
|
+
return () =>
|
|
16
|
+
h(props.as ?? "table", attrs, slots.default ? slots.default() : [])
|
|
16
17
|
},
|
|
17
18
|
}),
|
|
18
19
|
thead: defineComponent({
|
|
@@ -21,7 +22,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
|
|
|
21
22
|
as: { type: String as PropType<string | undefined> },
|
|
22
23
|
},
|
|
23
24
|
setup(props, { attrs, slots }) {
|
|
24
|
-
return () =>
|
|
25
|
+
return () =>
|
|
26
|
+
h(props.as ?? "thead", attrs, slots.default ? slots.default() : [])
|
|
25
27
|
},
|
|
26
28
|
}),
|
|
27
29
|
tbody: defineComponent({
|
|
@@ -30,7 +32,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
|
|
|
30
32
|
as: { type: String as PropType<string | undefined> },
|
|
31
33
|
},
|
|
32
34
|
setup(props, { attrs, slots }) {
|
|
33
|
-
return () =>
|
|
35
|
+
return () =>
|
|
36
|
+
h(props.as ?? "tbody", attrs, slots.default ? slots.default() : [])
|
|
34
37
|
},
|
|
35
38
|
}),
|
|
36
39
|
tr: defineComponent({
|
|
@@ -39,7 +42,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
|
|
|
39
42
|
as: { type: String as PropType<string | undefined> },
|
|
40
43
|
},
|
|
41
44
|
setup(props, { attrs, slots }) {
|
|
42
|
-
return () =>
|
|
45
|
+
return () =>
|
|
46
|
+
h(props.as ?? "tr", attrs, slots.default ? slots.default() : [])
|
|
43
47
|
},
|
|
44
48
|
}),
|
|
45
49
|
th: defineComponent({
|
|
@@ -48,7 +52,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
|
|
|
48
52
|
as: { type: String as PropType<string | undefined> },
|
|
49
53
|
},
|
|
50
54
|
setup(props, { attrs, slots }) {
|
|
51
|
-
return () =>
|
|
55
|
+
return () =>
|
|
56
|
+
h(props.as ?? "th", attrs, slots.default ? slots.default() : [])
|
|
52
57
|
},
|
|
53
58
|
}),
|
|
54
59
|
td: defineComponent({
|
|
@@ -57,7 +62,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
|
|
|
57
62
|
as: { type: String as PropType<string | undefined> },
|
|
58
63
|
},
|
|
59
64
|
setup(props, { attrs, slots }) {
|
|
60
|
-
return () =>
|
|
65
|
+
return () =>
|
|
66
|
+
h(props.as ?? "td", attrs, slots.default ? slots.default() : [])
|
|
61
67
|
},
|
|
62
68
|
}),
|
|
63
69
|
}
|
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import type { TableFieldBodyRow, TableFieldHeadRow } from "@prismicio/client"
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { InternalVueTableComponents } from "./types"
|
|
5
5
|
|
|
6
6
|
import type { VueRichTextSerializer } from "../PrismicRichText"
|
|
7
7
|
import PrismicRichText from "../PrismicRichText/PrismicRichText.vue"
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Props for `<PrismicRowTable />`.
|
|
11
|
-
*/
|
|
12
9
|
export type PrismicTableRowProps = {
|
|
13
|
-
/**
|
|
14
|
-
* The Prismic table row to render.
|
|
15
|
-
*/
|
|
16
10
|
row: TableFieldHeadRow | TableFieldBodyRow
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* An object that maps a table block type to a Vue component.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
*
|
|
23
|
-
* ```javascript
|
|
24
|
-
* {
|
|
25
|
-
* tr: TableRow,
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
components: VueTableComponents & VueRichTextSerializer
|
|
11
|
+
internalTableComponents: InternalVueTableComponents
|
|
12
|
+
components?: VueRichTextSerializer
|
|
30
13
|
}
|
|
31
14
|
|
|
32
15
|
const props = defineProps<PrismicTableRowProps>()
|
|
@@ -34,17 +17,27 @@ defineOptions({ name: "PrismicTableRow" })
|
|
|
34
17
|
</script>
|
|
35
18
|
|
|
36
19
|
<template>
|
|
37
|
-
<component
|
|
20
|
+
<component
|
|
21
|
+
:is="internalTableComponents.tr.is"
|
|
22
|
+
:row="row"
|
|
23
|
+
v-bind="internalTableComponents.tr.shorthand"
|
|
24
|
+
>
|
|
38
25
|
<template v-for="cell in row.cells" :key="cell.key">
|
|
39
26
|
<component
|
|
40
27
|
v-if="cell.type === 'header'"
|
|
41
|
-
:is="
|
|
28
|
+
:is="internalTableComponents.th.is"
|
|
42
29
|
:cell="cell"
|
|
30
|
+
v-bind="internalTableComponents.th.shorthand"
|
|
43
31
|
>
|
|
44
32
|
<PrismicRichText :field="cell.content" :components="components" />
|
|
45
33
|
</component>
|
|
46
|
-
<component
|
|
47
|
-
|
|
34
|
+
<component
|
|
35
|
+
v-else
|
|
36
|
+
:is="internalTableComponents.td.is"
|
|
37
|
+
:cell="cell"
|
|
38
|
+
v-bind="internalTableComponents.td.shorthand"
|
|
39
|
+
>
|
|
40
|
+
<PrismicRichText :field="cell.content" :components="components" />
|
|
48
41
|
</component>
|
|
49
42
|
</template>
|
|
50
43
|
</component>
|
|
@@ -7,12 +7,9 @@ import type {
|
|
|
7
7
|
TableFieldHeadRow,
|
|
8
8
|
TableFieldHeaderCell,
|
|
9
9
|
} from "@prismicio/client"
|
|
10
|
-
|
|
11
|
-
DefineComponent,
|
|
12
|
-
FunctionalComponent,
|
|
13
|
-
defineAsyncComponent,
|
|
14
|
-
} from "vue"
|
|
10
|
+
|
|
15
11
|
import type { VueShorthand } from "../PrismicRichText/types"
|
|
12
|
+
import type { VueComponent } from "../types"
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* A map of Table block types to Vue Components. It is used to render table
|
|
@@ -24,12 +21,14 @@ export type VueTableComponents = {
|
|
|
24
21
|
table?: VueComponent<{ table: TableField<"filled"> }> | VueShorthand
|
|
25
22
|
thead?: VueComponent<{ head: TableFieldHead }> | VueShorthand
|
|
26
23
|
tbody?: VueComponent<{ body: TableFieldBody }> | VueShorthand
|
|
27
|
-
tr?:
|
|
24
|
+
tr?:
|
|
25
|
+
| VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow }>
|
|
26
|
+
| VueShorthand
|
|
28
27
|
th?: VueComponent<{ cell: TableFieldHeaderCell }> | VueShorthand
|
|
29
28
|
td?: VueComponent<{ cell: TableFieldDataCell }> | VueShorthand
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
export type
|
|
31
|
+
export type DefaultVueTableComponents = {
|
|
33
32
|
table: VueComponent<{ table: TableField<"filled">; as?: string }>
|
|
34
33
|
thead: VueComponent<{ head: TableFieldHead; as?: string }>
|
|
35
34
|
tbody: VueComponent<{ body: TableFieldBody; as?: string }>
|
|
@@ -38,7 +37,11 @@ export type InternalVueTableComponents = {
|
|
|
38
37
|
td: VueComponent<{ cell: TableFieldDataCell; as?: string }>
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
export type InternalVueTableComponents = {
|
|
41
|
+
table: { is: VueTableComponents["table"]; shorthand?: VueShorthand }
|
|
42
|
+
thead: { is: VueTableComponents["thead"]; shorthand?: VueShorthand }
|
|
43
|
+
tbody: { is: VueTableComponents["tbody"]; shorthand?: VueShorthand }
|
|
44
|
+
tr: { is: VueTableComponents["tr"]; shorthand?: VueShorthand }
|
|
45
|
+
th: { is: VueTableComponents["th"]; shorthand?: VueShorthand }
|
|
46
|
+
td: { is: VueTableComponents["td"]; shorthand?: VueShorthand }
|
|
47
|
+
}
|
package/src/PrismicText.vue
CHANGED
|
@@ -10,9 +10,7 @@ import { devMsg } from "./lib/devMsg"
|
|
|
10
10
|
* Props for `<PrismicText />`.
|
|
11
11
|
*/
|
|
12
12
|
export type PrismicTextProps = {
|
|
13
|
-
/**
|
|
14
|
-
* The Prismic rich text field to render.
|
|
15
|
-
*/
|
|
13
|
+
/** The Prismic rich text field to render. */
|
|
16
14
|
field: RichTextField | null | undefined
|
|
17
15
|
|
|
18
16
|
/**
|
|
@@ -16,31 +16,20 @@ import { TODOSliceComponent } from "./TODOSliceComponent"
|
|
|
16
16
|
* @typeParam TContext - Arbitrary data made available to all Slice components
|
|
17
17
|
*/
|
|
18
18
|
export type SliceZoneProps<TContext = unknown> = {
|
|
19
|
-
/**
|
|
20
|
-
* List of Slice data from the Slice Zone.
|
|
21
|
-
*/
|
|
19
|
+
/** List of slice data from the slice zone. */
|
|
22
20
|
slices: SliceZoneLike<SliceLike | (SliceLike & Record<string, unknown>)>
|
|
23
21
|
|
|
24
|
-
/**
|
|
25
|
-
* A record mapping Slice types to Vue components.
|
|
26
|
-
*/
|
|
22
|
+
/** A record mapping slice types to React components. */
|
|
27
23
|
components?: SliceZoneComponents
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
26
|
* The Vue component rendered if a component mapping from the `components`
|
|
31
27
|
* prop cannot be found.
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* Components will be rendered using the {@link SliceComponentProps} interface.
|
|
35
|
-
*
|
|
36
|
-
* @defaultValue The Slice Zone default component provided to `@prismicio/vue` plugin if configured, otherwise `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}.
|
|
37
28
|
*/
|
|
38
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
30
|
defaultComponent?: SliceComponentType<any, TContext>
|
|
40
31
|
|
|
41
|
-
/**
|
|
42
|
-
* Arbitrary data made available to all Slice components.
|
|
43
|
-
*/
|
|
32
|
+
/** Arbitrary data made available to all slice components. */
|
|
44
33
|
context?: TContext
|
|
45
34
|
}
|
|
46
35
|
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ConcreteComponent,
|
|
3
|
+
DefineComponent,
|
|
4
|
+
FunctionalComponent,
|
|
5
|
+
Raw,
|
|
6
|
+
defineAsyncComponent,
|
|
7
|
+
} from "vue"
|
|
2
8
|
|
|
3
9
|
export type ComponentOrTagName =
|
|
4
10
|
| string
|
|
5
11
|
| ConcreteComponent
|
|
6
12
|
| Raw<DefineComponent>
|
|
13
|
+
|
|
14
|
+
export type VueComponent<TProps> =
|
|
15
|
+
// For reference within TypeScript files when `*.vue` type cannot be inferred
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any
|
|
17
|
+
| DefineComponent<{}, {}, any>
|
|
18
|
+
// Likewise, for reference with TypeScript files.
|
|
19
|
+
| ReturnType<typeof defineAsyncComponent>
|
|
20
|
+
| DefineComponent<TProps>
|
|
21
|
+
| FunctionalComponent<TProps>
|
|
22
|
+
|
|
23
|
+
export const isVueComponent = <T>(
|
|
24
|
+
component: VueComponent<T> | unknown,
|
|
25
|
+
): component is VueComponent<T> => {
|
|
26
|
+
return (
|
|
27
|
+
!!component &&
|
|
28
|
+
(typeof component === "function" ||
|
|
29
|
+
(typeof component === "object" &&
|
|
30
|
+
(("render" in component && typeof component.render === "function") ||
|
|
31
|
+
("setup" in component && typeof component.setup === "function") ||
|
|
32
|
+
("__file" in component && !!component.__file) ||
|
|
33
|
+
("__name" in component && !!component.__name) ||
|
|
34
|
+
("props" in component && typeof component.props === "object"))))
|
|
35
|
+
)
|
|
36
|
+
}
|
package/src/lib/Wrapper.vue
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import type { ComponentOrTagName } from "../types"
|
|
3
|
-
|
|
4
|
-
defineProps<{
|
|
5
|
-
/**
|
|
6
|
-
* An HTML tag name or a component used to wrap the output. Output is not
|
|
7
|
-
* wrapped by default.
|
|
8
|
-
*
|
|
9
|
-
* @defaultValue `"template"` (no wrapper)
|
|
10
|
-
*/
|
|
11
|
-
wrapper?: ComponentOrTagName
|
|
12
|
-
}>()
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
<template>
|
|
16
|
-
<component v-if="wrapper" :is="wrapper" v-bind="$attrs">
|
|
17
|
-
<slot />
|
|
18
|
-
</component>
|
|
19
|
-
<template v-else>
|
|
20
|
-
<slot />
|
|
21
|
-
</template>
|
|
22
|
-
</template>
|