@prismicio/vue 3.1.0 → 3.1.2
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/components/PrismicEmbed.cjs +36 -0
- package/dist/components/PrismicEmbed.cjs.map +1 -0
- package/dist/components/PrismicEmbed.d.ts +63 -0
- package/dist/components/PrismicEmbed.js +36 -0
- package/dist/components/PrismicEmbed.js.map +1 -0
- package/dist/components/PrismicImage.cjs +122 -0
- package/dist/components/PrismicImage.cjs.map +1 -0
- package/dist/components/PrismicImage.d.ts +162 -0
- package/dist/components/PrismicImage.js +122 -0
- package/dist/components/PrismicImage.js.map +1 -0
- package/dist/components/PrismicLink.cjs +115 -0
- package/dist/components/PrismicLink.cjs.map +1 -0
- package/dist/components/PrismicLink.d.ts +191 -0
- package/dist/components/PrismicLink.js +115 -0
- package/dist/components/PrismicLink.js.map +1 -0
- package/dist/components/PrismicRichText.cjs +103 -0
- package/dist/components/PrismicRichText.cjs.map +1 -0
- package/dist/components/PrismicRichText.d.ts +139 -0
- package/dist/components/PrismicRichText.js +103 -0
- package/dist/components/PrismicRichText.js.map +1 -0
- package/dist/components/PrismicText.cjs +57 -0
- package/dist/components/PrismicText.cjs.map +1 -0
- package/dist/components/PrismicText.d.ts +117 -0
- package/dist/components/PrismicText.js +57 -0
- package/dist/components/PrismicText.js.map +1 -0
- package/dist/components/SliceZone.cjs +134 -0
- package/dist/components/SliceZone.cjs.map +1 -0
- package/dist/components/SliceZone.d.ts +359 -0
- package/dist/components/SliceZone.js +134 -0
- package/dist/components/SliceZone.js.map +1 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/composables.cjs +40 -0
- package/dist/composables.cjs.map +1 -0
- package/dist/composables.d.ts +366 -0
- package/dist/composables.js +40 -0
- package/dist/composables.js.map +1 -0
- package/dist/createPrismic.cjs +87 -0
- package/dist/createPrismic.cjs.map +1 -0
- package/dist/createPrismic.d.ts +12 -0
- package/dist/createPrismic.js +69 -0
- package/dist/createPrismic.js.map +1 -0
- package/dist/globalExtensions.d.ts +11 -0
- package/dist/index.cjs +46 -764
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -1404
- package/dist/index.js +45 -707
- package/dist/index.js.map +1 -1
- package/dist/injectionSymbols.cjs +5 -0
- package/dist/injectionSymbols.cjs.map +1 -0
- package/dist/injectionSymbols.d.ts +9 -0
- package/dist/injectionSymbols.js +5 -0
- package/dist/injectionSymbols.js.map +1 -0
- package/dist/lib/__PRODUCTION__.cjs +8 -0
- package/dist/lib/__PRODUCTION__.cjs.map +1 -0
- package/dist/lib/__PRODUCTION__.d.ts +7 -0
- package/dist/lib/__PRODUCTION__.js +8 -0
- package/dist/lib/__PRODUCTION__.js.map +1 -0
- package/dist/lib/getSlots.cjs +19 -0
- package/dist/lib/getSlots.cjs.map +1 -0
- package/dist/lib/getSlots.d.ts +14 -0
- package/dist/lib/getSlots.js +19 -0
- package/dist/lib/getSlots.js.map +1 -0
- package/dist/lib/isInternalURL.cjs +9 -0
- package/dist/lib/isInternalURL.cjs.map +1 -0
- package/dist/lib/isInternalURL.d.ts +8 -0
- package/dist/lib/isInternalURL.js +9 -0
- package/dist/lib/isInternalURL.js.map +1 -0
- package/dist/lib/simplyResolveComponent.cjs +8 -0
- package/dist/lib/simplyResolveComponent.cjs.map +1 -0
- package/dist/lib/simplyResolveComponent.d.ts +12 -0
- package/dist/lib/simplyResolveComponent.js +8 -0
- package/dist/lib/simplyResolveComponent.js.map +1 -0
- package/dist/types.d.ts +357 -0
- package/dist/usePrismic.cjs +9 -0
- package/dist/usePrismic.cjs.map +1 -0
- package/dist/usePrismic.d.ts +21 -0
- package/dist/usePrismic.js +9 -0
- package/dist/usePrismic.js.map +1 -0
- package/dist/useStatefulPrismicClientMethod.cjs +36 -0
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -0
- package/dist/useStatefulPrismicClientMethod.d.ts +64 -0
- package/dist/useStatefulPrismicClientMethod.js +36 -0
- package/dist/useStatefulPrismicClientMethod.js.map +1 -0
- package/package.json +28 -28
- package/src/components/PrismicEmbed.ts +2 -1
- package/src/components/PrismicImage.ts +8 -5
- package/src/components/PrismicLink.ts +4 -2
- package/src/components/PrismicRichText.ts +4 -2
- package/src/components/PrismicText.ts +6 -3
- package/src/components/SliceZone.ts +12 -7
- package/src/composables.ts +56 -46
- package/src/injectionSymbols.ts +2 -1
- package/src/types.ts +14 -7
- package/src/useStatefulPrismicClientMethod.ts +6 -3
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, PropType, VNodeProps } from "vue";
|
|
2
|
+
import { HTMLFunctionSerializer, HTMLMapSerializer, LinkResolverFunction } from "@prismicio/helpers";
|
|
3
|
+
import { RichTextField } from "@prismicio/types";
|
|
4
|
+
import { VueUseOptions } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* Props for `<PrismicRichText />`.
|
|
7
|
+
*/
|
|
8
|
+
export type PrismicRichTextProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The Prismic rich text or title field to render.
|
|
11
|
+
*/
|
|
12
|
+
field: RichTextField | null | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* A link resolver function used to resolve link when not using the route
|
|
15
|
+
* resolver parameter with `@prismicio/client`.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
|
|
18
|
+
*
|
|
19
|
+
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
20
|
+
*/
|
|
21
|
+
linkResolver?: LinkResolverFunction;
|
|
22
|
+
/**
|
|
23
|
+
* An HTML serializer to customize the way rich text fields are rendered.
|
|
24
|
+
*
|
|
25
|
+
* @defaultValue The HTML serializer provided to `@prismicio/vue` plugin if configured.
|
|
26
|
+
*
|
|
27
|
+
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
28
|
+
*/
|
|
29
|
+
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;
|
|
30
|
+
/**
|
|
31
|
+
* An HTML tag name, a component, or a functional component used to wrap the
|
|
32
|
+
* output.
|
|
33
|
+
*
|
|
34
|
+
* @defaultValue `"div"`
|
|
35
|
+
*/
|
|
36
|
+
wrapper?: string | ConcreteComponent;
|
|
37
|
+
/**
|
|
38
|
+
* The HTML value to be rendered when the field is empty. If a fallback is not
|
|
39
|
+
* given, `""` (nothing) will be rendered.
|
|
40
|
+
*/
|
|
41
|
+
fallback?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for {@link usePrismicRichText}.
|
|
45
|
+
*/
|
|
46
|
+
export type UsePrismicRichTextOptions = VueUseOptions<Omit<PrismicRichTextProps, "wrapper">>;
|
|
47
|
+
/**
|
|
48
|
+
* Return type of {@link usePrismicRichText}.
|
|
49
|
+
*/
|
|
50
|
+
export type UsePrismicRichTextReturnType = {
|
|
51
|
+
/**
|
|
52
|
+
* Serialized rich text field as HTML.
|
|
53
|
+
*/
|
|
54
|
+
html: ComputedRef<string>;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* A low level composable that returns a serialized rich text field as HTML.
|
|
58
|
+
*
|
|
59
|
+
* @param props - {@link UsePrismicRichTextOptions}
|
|
60
|
+
*
|
|
61
|
+
* @returns - Serialized rich text field as HTML
|
|
62
|
+
* {@link UsePrismicRichTextReturnType}
|
|
63
|
+
*/
|
|
64
|
+
export declare const usePrismicRichText: (props: UsePrismicRichTextOptions) => UsePrismicRichTextReturnType;
|
|
65
|
+
/**
|
|
66
|
+
* `<PrismicRichText />` implementation.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare const PrismicRichTextImpl: import("vue").DefineComponent<{
|
|
71
|
+
field: {
|
|
72
|
+
type: PropType<[] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | null | undefined>;
|
|
73
|
+
default: undefined;
|
|
74
|
+
required: false;
|
|
75
|
+
};
|
|
76
|
+
linkResolver: {
|
|
77
|
+
type: PropType<LinkResolverFunction<string>>;
|
|
78
|
+
default: undefined;
|
|
79
|
+
required: false;
|
|
80
|
+
};
|
|
81
|
+
htmlSerializer: {
|
|
82
|
+
type: PropType<HTMLFunctionSerializer | HTMLMapSerializer>;
|
|
83
|
+
default: undefined;
|
|
84
|
+
required: false;
|
|
85
|
+
};
|
|
86
|
+
wrapper: {
|
|
87
|
+
type: PropType<string | ConcreteComponent<{}, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>>;
|
|
88
|
+
default: undefined;
|
|
89
|
+
required: false;
|
|
90
|
+
};
|
|
91
|
+
fallback: {
|
|
92
|
+
type: PropType<string>;
|
|
93
|
+
default: undefined;
|
|
94
|
+
required: false;
|
|
95
|
+
};
|
|
96
|
+
}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
99
|
+
field: {
|
|
100
|
+
type: PropType<[] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | null | undefined>;
|
|
101
|
+
default: undefined;
|
|
102
|
+
required: false;
|
|
103
|
+
};
|
|
104
|
+
linkResolver: {
|
|
105
|
+
type: PropType<LinkResolverFunction<string>>;
|
|
106
|
+
default: undefined;
|
|
107
|
+
required: false;
|
|
108
|
+
};
|
|
109
|
+
htmlSerializer: {
|
|
110
|
+
type: PropType<HTMLFunctionSerializer | HTMLMapSerializer>;
|
|
111
|
+
default: undefined;
|
|
112
|
+
required: false;
|
|
113
|
+
};
|
|
114
|
+
wrapper: {
|
|
115
|
+
type: PropType<string | ConcreteComponent<{}, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>>;
|
|
116
|
+
default: undefined;
|
|
117
|
+
required: false;
|
|
118
|
+
};
|
|
119
|
+
fallback: {
|
|
120
|
+
type: PropType<string>;
|
|
121
|
+
default: undefined;
|
|
122
|
+
required: false;
|
|
123
|
+
};
|
|
124
|
+
}>>, {
|
|
125
|
+
wrapper: string | ConcreteComponent<{}, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>;
|
|
126
|
+
field: [] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | null | undefined;
|
|
127
|
+
linkResolver: LinkResolverFunction<string>;
|
|
128
|
+
fallback: string;
|
|
129
|
+
htmlSerializer: HTMLFunctionSerializer | HTMLMapSerializer;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Component to render a Prismic rich text field as HTML.
|
|
133
|
+
*
|
|
134
|
+
* @see Component props {@link PrismicRichTextProps}
|
|
135
|
+
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
|
|
136
|
+
*/
|
|
137
|
+
export declare const PrismicRichText: new () => {
|
|
138
|
+
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & PrismicRichTextProps;
|
|
139
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { computed, unref, defineComponent, ref, inject, watch, nextTick, onBeforeUnmount, h } from "vue";
|
|
2
|
+
import { routerKey } from "vue-router";
|
|
3
|
+
import { isFilled, asHTML } from "@prismicio/helpers";
|
|
4
|
+
import { usePrismic } from "../usePrismic.js";
|
|
5
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent.js";
|
|
6
|
+
import { isInternalURL } from "../lib/isInternalURL.js";
|
|
7
|
+
const defaultWrapper = "div";
|
|
8
|
+
const usePrismicRichText = (props) => {
|
|
9
|
+
const { options } = usePrismic();
|
|
10
|
+
const html = computed(() => {
|
|
11
|
+
const field = unref(props.field);
|
|
12
|
+
if (!isFilled.richText(field)) {
|
|
13
|
+
return unref(props.fallback) ?? "";
|
|
14
|
+
}
|
|
15
|
+
const linkResolver = unref(props.linkResolver) ?? options.linkResolver;
|
|
16
|
+
const htmlSerializer = unref(props.htmlSerializer) ?? options.htmlSerializer;
|
|
17
|
+
return asHTML(unref(field), linkResolver, htmlSerializer);
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
html
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const PrismicRichTextImpl = /* @__PURE__ */ defineComponent({
|
|
24
|
+
name: "PrismicRichText",
|
|
25
|
+
props: {
|
|
26
|
+
field: {
|
|
27
|
+
type: Array,
|
|
28
|
+
default: void 0,
|
|
29
|
+
required: false
|
|
30
|
+
},
|
|
31
|
+
linkResolver: {
|
|
32
|
+
type: Function,
|
|
33
|
+
default: void 0,
|
|
34
|
+
required: false
|
|
35
|
+
},
|
|
36
|
+
htmlSerializer: {
|
|
37
|
+
type: [Function, Object],
|
|
38
|
+
default: void 0,
|
|
39
|
+
required: false
|
|
40
|
+
},
|
|
41
|
+
wrapper: {
|
|
42
|
+
type: [String, Object, Function],
|
|
43
|
+
default: void 0,
|
|
44
|
+
required: false
|
|
45
|
+
},
|
|
46
|
+
fallback: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: void 0,
|
|
49
|
+
required: false
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
setup(props) {
|
|
53
|
+
const { html } = usePrismicRichText(props);
|
|
54
|
+
const root = ref(null);
|
|
55
|
+
const maybeRouter = inject(routerKey, null);
|
|
56
|
+
if (maybeRouter) {
|
|
57
|
+
let links = [];
|
|
58
|
+
const navigate = function(event) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
maybeRouter.push(this.href);
|
|
61
|
+
};
|
|
62
|
+
const addListeners = () => {
|
|
63
|
+
const node = root.value && "$el" in root.value ? root.value.$el : root.value;
|
|
64
|
+
if (node && "querySelectorAll" in node) {
|
|
65
|
+
links = Array.from(node.querySelectorAll("a")).map((element) => {
|
|
66
|
+
const href = element.getAttribute("href");
|
|
67
|
+
if (href && isInternalURL(href)) {
|
|
68
|
+
const listener = navigate.bind({ href });
|
|
69
|
+
element.addEventListener("click", listener);
|
|
70
|
+
return { element, listener };
|
|
71
|
+
} else {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}).filter((link) => link);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const removeListeners = () => {
|
|
78
|
+
links.forEach(({ element, listener }) => element.removeEventListener("click", listener));
|
|
79
|
+
links = [];
|
|
80
|
+
};
|
|
81
|
+
watch(html, () => {
|
|
82
|
+
removeListeners();
|
|
83
|
+
nextTick(addListeners);
|
|
84
|
+
}, { immediate: true });
|
|
85
|
+
onBeforeUnmount(() => {
|
|
86
|
+
removeListeners();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return () => {
|
|
90
|
+
return h(simplyResolveComponent(props.wrapper || defaultWrapper), {
|
|
91
|
+
innerHTML: html.value,
|
|
92
|
+
ref: root
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const PrismicRichText = PrismicRichTextImpl;
|
|
98
|
+
export {
|
|
99
|
+
PrismicRichText,
|
|
100
|
+
PrismicRichTextImpl,
|
|
101
|
+
usePrismicRichText
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=PrismicRichText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicRichText.js","sources":["../../../src/components/PrismicRichText.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponent,\n\tComponentCustomProps,\n\tcomputed,\n\tComputedRef,\n\tConcreteComponent,\n\tdefineComponent,\n\th,\n\tinject,\n\tnextTick,\n\tonBeforeUnmount,\n\tPropType,\n\tref,\n\tunref,\n\tVNodeProps,\n\twatch,\n} from \"vue\";\nimport { routerKey } from \"vue-router\";\n\nimport {\n\tasHTML,\n\tHTMLFunctionSerializer,\n\tHTMLMapSerializer,\n\tisFilled,\n\tLinkResolverFunction,\n} from \"@prismicio/helpers\";\nimport { RichTextField } from \"@prismicio/types\";\n\nimport { VueUseOptions } from \"../types\";\nimport { usePrismic } from \"../usePrismic\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered to wrap the HTML output.\n */\nconst defaultWrapper = \"div\";\n\n/**\n * Props for `<PrismicRichText />`.\n */\nexport type PrismicRichTextProps = {\n\t/**\n\t * The Prismic rich text or title field to render.\n\t */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * A link resolver function used to resolve link when not using the route\n\t * resolver parameter with `@prismicio/client`.\n\t *\n\t * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * An HTML serializer to customize the way rich text fields are rendered.\n\t *\n\t * @defaultValue The HTML serializer provided to `@prismicio/vue` plugin if configured.\n\t *\n\t * @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}\n\t */\n\thtmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to wrap the\n\t * output.\n\t *\n\t * @defaultValue `\"div\"`\n\t */\n\twrapper?: string | ConcreteComponent;\n\n\t/**\n\t * The HTML value to be rendered when the field is empty. If a fallback is not\n\t * given, `\"\"` (nothing) will be rendered.\n\t */\n\tfallback?: string;\n};\n\n/**\n * Options for {@link usePrismicRichText}.\n */\nexport type UsePrismicRichTextOptions = VueUseOptions<\n\tOmit<PrismicRichTextProps, \"wrapper\">\n>;\n\n/**\n * Return type of {@link usePrismicRichText}.\n */\nexport type UsePrismicRichTextReturnType = {\n\t/**\n\t * Serialized rich text field as HTML.\n\t */\n\thtml: ComputedRef<string>;\n};\n\n/**\n * A low level composable that returns a serialized rich text field as HTML.\n *\n * @param props - {@link UsePrismicRichTextOptions}\n *\n * @returns - Serialized rich text field as HTML\n * {@link UsePrismicRichTextReturnType}\n */\nexport const usePrismicRichText = (\n\tprops: UsePrismicRichTextOptions,\n): UsePrismicRichTextReturnType => {\n\tconst { options } = usePrismic();\n\n\tconst html = computed(() => {\n\t\tconst field = unref(props.field);\n\n\t\tif (!isFilled.richText(field)) {\n\t\t\treturn unref(props.fallback) ?? \"\";\n\t\t}\n\n\t\tconst linkResolver = unref(props.linkResolver) ?? options.linkResolver;\n\t\tconst htmlSerializer =\n\t\t\tunref(props.htmlSerializer) ?? options.htmlSerializer;\n\n\t\treturn asHTML(unref(field), linkResolver, htmlSerializer);\n\t});\n\n\treturn {\n\t\thtml,\n\t};\n};\n\n/**\n * `<PrismicRichText />` implementation.\n *\n * @internal\n */\nexport const PrismicRichTextImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicRichText\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Array as unknown as PropType<RichTextField | null | undefined>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tlinkResolver: {\n\t\t\ttype: Function as PropType<LinkResolverFunction>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\thtmlSerializer: {\n\t\t\ttype: [Function, Object] as PropType<\n\t\t\t\tHTMLFunctionSerializer | HTMLMapSerializer\n\t\t\t>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\twrapper: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tfallback: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props) {\n\t\tconst { html } = usePrismicRichText(props);\n\n\t\tconst root = ref<HTMLElement | Comment | Component | null>(null);\n\n\t\tconst maybeRouter = inject(routerKey, null);\n\t\tif (maybeRouter) {\n\t\t\ttype InternalLink = {\n\t\t\t\telement: HTMLAnchorElement;\n\t\t\t\tlistener: EventListener;\n\t\t\t};\n\t\t\tlet links: InternalLink[] = [];\n\n\t\t\tconst navigate: EventListener = function (\n\t\t\t\tthis: { href: string },\n\t\t\t\tevent: Event,\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tmaybeRouter.push(this.href);\n\t\t\t};\n\n\t\t\tconst addListeners = () => {\n\t\t\t\tconst node: HTMLElement | Comment | null =\n\t\t\t\t\troot.value && \"$el\" in root.value ? root.value.$el : root.value;\n\t\t\t\tif (node && \"querySelectorAll\" in node) {\n\t\t\t\t\t// Get all internal link tags and add listeners on them\n\t\t\t\t\tlinks = Array.from(node.querySelectorAll(\"a\"))\n\t\t\t\t\t\t.map((element) => {\n\t\t\t\t\t\t\tconst href = element.getAttribute(\"href\");\n\n\t\t\t\t\t\t\tif (href && isInternalURL(href)) {\n\t\t\t\t\t\t\t\tconst listener = navigate.bind({ href });\n\t\t\t\t\t\t\t\telement.addEventListener(\"click\", listener);\n\n\t\t\t\t\t\t\t\treturn { element, listener };\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter((link): link is InternalLink => link as boolean);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst removeListeners = () => {\n\t\t\t\tlinks.forEach(({ element, listener }) =>\n\t\t\t\t\telement.removeEventListener(\"click\", listener),\n\t\t\t\t);\n\t\t\t\tlinks = [];\n\t\t\t};\n\n\t\t\twatch(\n\t\t\t\thtml,\n\t\t\t\t() => {\n\t\t\t\t\tremoveListeners();\n\t\t\t\t\tnextTick(addListeners);\n\t\t\t\t},\n\t\t\t\t{ immediate: true },\n\t\t\t);\n\n\t\t\tonBeforeUnmount(() => {\n\t\t\t\tremoveListeners();\n\t\t\t});\n\t\t}\n\n\t\treturn () => {\n\t\t\treturn h(simplyResolveComponent(props.wrapper || defaultWrapper), {\n\t\t\t\tinnerHTML: html.value,\n\t\t\t\tref: root,\n\t\t\t});\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic rich text field as HTML.\n *\n * @see Component props {@link PrismicRichTextProps}\n * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}\n */\nexport const PrismicRichText = PrismicRichTextImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicRichTextProps;\n\t};\n};\n"],"names":[],"mappings":";;;;;;AAqCA,MAAM,iBAAiB;AAsEV,MAAA,qBAAqB,CACjC,UACiC;AAC3B,QAAA,EAAE,YAAY;AAEd,QAAA,OAAO,SAAS,MAAK;AACpB,UAAA,QAAQ,MAAM,MAAM,KAAK;AAE/B,QAAI,CAAC,SAAS,SAAS,KAAK,GAAG;AACvB,aAAA,MAAM,MAAM,QAAQ,KAAK;AAAA,IAChC;AAED,UAAM,eAAe,MAAM,MAAM,YAAY,KAAK,QAAQ;AAC1D,UAAM,iBACL,MAAM,MAAM,cAAc,KAAK,QAAQ;AAExC,WAAO,OAAO,MAAM,KAAK,GAAG,cAAc,cAAc;AAAA,EAAA,CACxD;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;AAOO,MAAM,sBAAoD,gCAAA;AAAA,EAChE,MAAM;AAAA,EACN,OAAO;AAAA,IACN,OAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,cAAc;AAAA,MACb,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,gBAAgB;AAAA,MACf,MAAM,CAAC,UAAU,MAAM;AAAA,MAGvB,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,SAAS;AAAA,MACR,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,UAAU;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,EACD;AAAA,EACD,MAAM,OAAK;AACV,UAAM,EAAE,KAAA,IAAS,mBAAmB,KAAK;AAEnC,UAAA,OAAO,IAA8C,IAAI;AAEzD,UAAA,cAAc,OAAO,WAAW,IAAI;AAC1C,QAAI,aAAa;AAKhB,UAAI,QAAwB,CAAA;AAEtB,YAAA,WAA0B,SAE/B,OAAY;AAEZ,cAAM,eAAc;AACR,oBAAA,KAAK,KAAK,IAAI;AAAA,MAAA;AAG3B,YAAM,eAAe,MAAK;AACnB,cAAA,OACL,KAAK,SAAS,SAAS,KAAK,QAAQ,KAAK,MAAM,MAAM,KAAK;AACvD,YAAA,QAAQ,sBAAsB,MAAM;AAE/B,kBAAA,MAAM,KAAK,KAAK,iBAAiB,GAAG,CAAC,EAC3C,IAAI,CAAC,YAAW;AACV,kBAAA,OAAO,QAAQ,aAAa,MAAM;AAEpC,gBAAA,QAAQ,cAAc,IAAI,GAAG;AAChC,oBAAM,WAAW,SAAS,KAAK,EAAE,KAAM,CAAA;AAC/B,sBAAA,iBAAiB,SAAS,QAAQ;AAEnC,qBAAA,EAAE,SAAS;mBACZ;AACC,qBAAA;AAAA,YACP;AAAA,UACD,CAAA,EACA,OAAO,CAAC,SAA+B,IAAe;AAAA,QACxD;AAAA,MAAA;AAGF,YAAM,kBAAkB,MAAK;AACtB,cAAA,QAAQ,CAAC,EAAE,SAAS,SAAA,MACzB,QAAQ,oBAAoB,SAAS,QAAQ,CAAC;AAE/C,gBAAQ,CAAA;AAAA;AAGT,YACC,MACA,MAAK;;AAEJ,iBAAS,YAAY;AAAA,MAAA,GAEtB,EAAE,WAAW,KAAA,CAAM;AAGpB,sBAAgB,MAAK;;OAEpB;AAAA,IACD;AAED,WAAO,MAAK;AACX,aAAO,EAAE,uBAAuB,MAAM,WAAW,cAAc,GAAG;AAAA,QACjE,WAAW,KAAK;AAAA,QAChB,KAAK;AAAA,MAAA,CACL;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,kBAAkB;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const helpers = require("@prismicio/helpers");
|
|
5
|
+
const simplyResolveComponent = require("../lib/simplyResolveComponent.cjs");
|
|
6
|
+
const defaultWrapper = "div";
|
|
7
|
+
const usePrismicText = (props) => {
|
|
8
|
+
const text = vue.computed(() => {
|
|
9
|
+
const field = vue.unref(props.field);
|
|
10
|
+
if (!helpers.isFilled.richText(field)) {
|
|
11
|
+
return vue.unref(props.fallback) ?? "";
|
|
12
|
+
}
|
|
13
|
+
return helpers.asText(vue.unref(field), vue.unref(props.separator));
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
text
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const PrismicTextImpl = /* @__PURE__ */ vue.defineComponent({
|
|
20
|
+
name: "PrismicText",
|
|
21
|
+
props: {
|
|
22
|
+
field: {
|
|
23
|
+
type: Array,
|
|
24
|
+
default: void 0,
|
|
25
|
+
required: false
|
|
26
|
+
},
|
|
27
|
+
separator: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: void 0,
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
wrapper: {
|
|
33
|
+
type: [String, Object, Function],
|
|
34
|
+
default: void 0,
|
|
35
|
+
required: false
|
|
36
|
+
},
|
|
37
|
+
fallback: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: void 0,
|
|
40
|
+
required: false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
setup(props) {
|
|
44
|
+
const { text } = usePrismicText(props);
|
|
45
|
+
return () => {
|
|
46
|
+
const parent = simplyResolveComponent.simplyResolveComponent(props.wrapper || defaultWrapper);
|
|
47
|
+
return vue.h(parent, null, {
|
|
48
|
+
default: () => text.value
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const PrismicText = PrismicTextImpl;
|
|
54
|
+
exports.PrismicText = PrismicText;
|
|
55
|
+
exports.PrismicTextImpl = PrismicTextImpl;
|
|
56
|
+
exports.usePrismicText = usePrismicText;
|
|
57
|
+
//# sourceMappingURL=PrismicText.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicText.cjs","sources":["../../../src/components/PrismicText.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponentCustomProps,\n\tcomputed,\n\tComputedRef,\n\tConcreteComponent,\n\tdefineComponent,\n\th,\n\tPropType,\n\tunref,\n\tVNode,\n\tVNodeProps,\n} from \"vue\";\n\nimport { asText, isFilled } from \"@prismicio/helpers\";\nimport { RichTextField } from \"@prismicio/types\";\n\nimport { VueUseOptions } from \"../types\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\n\n/**\n * The default component rendered to wrap the text output.\n */\nconst defaultWrapper = \"div\";\n/**\n * Props for `<PrismicText />`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic rich text or title field to render.\n\t */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue `\" \"` (a space)\n\t */\n\tseparator?: string;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to wrap the\n\t * output.\n\t *\n\t * @defaultValue `\"div\"`\n\t */\n\twrapper?: string | ConcreteComponent;\n\n\t/**\n\t * The string value to be rendered when the field is empty. If a fallback is\n\t * not given, `\"\"` (nothing) will be rendered.\n\t */\n\tfallback?: string;\n};\n\n/**\n * Options for {@link usePrismicText}.\n */\nexport type UsePrismicTextOptions = VueUseOptions<\n\tOmit<PrismicTextProps, \"wrapper\">\n>;\n\n/**\n * Return type of {@link usePrismicText}.\n */\nexport type UsePrismicTextReturnType = {\n\t/**\n\t * Serialized rich text field as plain text.\n\t */\n\ttext: ComputedRef<string>;\n};\n\n/**\n * A low level composable that returns a serialized rich text field as plain\n * text.\n *\n * @param props - {@link UsePrismicTextOptions}\n *\n * @returns - Serialized rich text field as plain text\n * {@link UsePrismicTextReturnType}\n */\nexport const usePrismicText = (\n\tprops: UsePrismicTextOptions,\n): UsePrismicTextReturnType => {\n\tconst text = computed(() => {\n\t\tconst field = unref(props.field);\n\n\t\tif (!isFilled.richText(field)) {\n\t\t\treturn unref(props.fallback) ?? \"\";\n\t\t}\n\n\t\treturn asText(unref(field), unref(props.separator));\n\t});\n\n\treturn {\n\t\ttext,\n\t};\n};\n\n/**\n * `<PrismicText />` implementation.\n *\n * @internal\n */\nexport const PrismicTextImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicText\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Array as unknown as PropType<RichTextField | null | undefined>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tseparator: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\twrapper: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tfallback: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props) {\n\t\tconst { text } = usePrismicText(props);\n\n\t\treturn () => {\n\t\t\tconst parent = simplyResolveComponent(props.wrapper || defaultWrapper);\n\n\t\t\t// This works but is absurd\n\t\t\t// if (typeof parent === \"string\") {\n\t\t\t// \treturn h(parent, null, { default: () => text.value });\n\t\t\t// } else {\n\t\t\t// \treturn h(parent, null, { default: () => text.value });\n\t\t\t// }\n\n\t\t\treturn h(parent as VNode, null, {\n\t\t\t\tdefault: () => text.value,\n\t\t\t});\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic rich text field as plain text.\n *\n * @see Component props {@link PrismicTextProps}\n * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}\n */\nexport const PrismicText = PrismicTextImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicTextProps;\n\t};\n};\n"],"names":["computed","unref","isFilled","asText","defineComponent","simplyResolveComponent","h"],"mappings":";;;;;AAuBA,MAAM,iBAAiB;AA0DV,MAAA,iBAAiB,CAC7B,UAC6B;AACvB,QAAA,OAAOA,IAAAA,SAAS,MAAK;AACpB,UAAA,QAAQC,IAAAA,MAAM,MAAM,KAAK;AAE/B,QAAI,CAACC,QAAA,SAAS,SAAS,KAAK,GAAG;AACvB,aAAAD,UAAM,MAAM,QAAQ,KAAK;AAAA,IAChC;AAED,WAAOE,QAAAA,OAAOF,IAAAA,MAAM,KAAK,GAAGA,IAAAA,MAAM,MAAM,SAAS,CAAC;AAAA,EAAA,CAClD;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;AAOO,MAAM,kBAAgDG,oBAAAA,gBAAA;AAAA,EAC5D,MAAM;AAAA,EACN,OAAO;AAAA,IACN,OAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,WAAW;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,SAAS;AAAA,MACR,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,UAAU;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,EACD;AAAA,EACD,MAAM,OAAK;AACV,UAAM,EAAE,KAAA,IAAS,eAAe,KAAK;AAErC,WAAO,MAAK;AACX,YAAM,SAASC,uBAAA,uBAAuB,MAAM,WAAW,cAAc;AAS9D,aAAAC,IAAA,EAAE,QAAiB,MAAM;AAAA,QAC/B,SAAS,MAAM,KAAK;AAAA,MAAA,CACpB;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,cAAc;;;;"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { AllowedComponentProps, ComponentCustomProps, ComputedRef, ConcreteComponent, PropType, VNode, VNodeProps } from "vue";
|
|
2
|
+
import { RichTextField } from "@prismicio/types";
|
|
3
|
+
import { VueUseOptions } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Props for `<PrismicText />`.
|
|
6
|
+
*/
|
|
7
|
+
export type PrismicTextProps = {
|
|
8
|
+
/**
|
|
9
|
+
* The Prismic rich text or title field to render.
|
|
10
|
+
*/
|
|
11
|
+
field: RichTextField | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Separator used to join each element.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue `" "` (a space)
|
|
16
|
+
*/
|
|
17
|
+
separator?: string;
|
|
18
|
+
/**
|
|
19
|
+
* An HTML tag name, a component, or a functional component used to wrap the
|
|
20
|
+
* output.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue `"div"`
|
|
23
|
+
*/
|
|
24
|
+
wrapper?: string | ConcreteComponent;
|
|
25
|
+
/**
|
|
26
|
+
* The string value to be rendered when the field is empty. If a fallback is
|
|
27
|
+
* not given, `""` (nothing) will be rendered.
|
|
28
|
+
*/
|
|
29
|
+
fallback?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Options for {@link usePrismicText}.
|
|
33
|
+
*/
|
|
34
|
+
export type UsePrismicTextOptions = VueUseOptions<Omit<PrismicTextProps, "wrapper">>;
|
|
35
|
+
/**
|
|
36
|
+
* Return type of {@link usePrismicText}.
|
|
37
|
+
*/
|
|
38
|
+
export type UsePrismicTextReturnType = {
|
|
39
|
+
/**
|
|
40
|
+
* Serialized rich text field as plain text.
|
|
41
|
+
*/
|
|
42
|
+
text: ComputedRef<string>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A low level composable that returns a serialized rich text field as plain
|
|
46
|
+
* text.
|
|
47
|
+
*
|
|
48
|
+
* @param props - {@link UsePrismicTextOptions}
|
|
49
|
+
*
|
|
50
|
+
* @returns - Serialized rich text field as plain text
|
|
51
|
+
* {@link UsePrismicTextReturnType}
|
|
52
|
+
*/
|
|
53
|
+
export declare const usePrismicText: (props: UsePrismicTextOptions) => UsePrismicTextReturnType;
|
|
54
|
+
/**
|
|
55
|
+
* `<PrismicText />` implementation.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare const PrismicTextImpl: import("vue").DefineComponent<{
|
|
60
|
+
field: {
|
|
61
|
+
type: PropType<[] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | null | undefined>;
|
|
62
|
+
default: undefined;
|
|
63
|
+
required: false;
|
|
64
|
+
};
|
|
65
|
+
separator: {
|
|
66
|
+
type: PropType<string>;
|
|
67
|
+
default: undefined;
|
|
68
|
+
required: false;
|
|
69
|
+
};
|
|
70
|
+
wrapper: {
|
|
71
|
+
type: PropType<string | ConcreteComponent<{}, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>>;
|
|
72
|
+
default: undefined;
|
|
73
|
+
required: false;
|
|
74
|
+
};
|
|
75
|
+
fallback: {
|
|
76
|
+
type: PropType<string>;
|
|
77
|
+
default: undefined;
|
|
78
|
+
required: false;
|
|
79
|
+
};
|
|
80
|
+
}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
83
|
+
field: {
|
|
84
|
+
type: PropType<[] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | null | undefined>;
|
|
85
|
+
default: undefined;
|
|
86
|
+
required: false;
|
|
87
|
+
};
|
|
88
|
+
separator: {
|
|
89
|
+
type: PropType<string>;
|
|
90
|
+
default: undefined;
|
|
91
|
+
required: false;
|
|
92
|
+
};
|
|
93
|
+
wrapper: {
|
|
94
|
+
type: PropType<string | ConcreteComponent<{}, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>>;
|
|
95
|
+
default: undefined;
|
|
96
|
+
required: false;
|
|
97
|
+
};
|
|
98
|
+
fallback: {
|
|
99
|
+
type: PropType<string>;
|
|
100
|
+
default: undefined;
|
|
101
|
+
required: false;
|
|
102
|
+
};
|
|
103
|
+
}>>, {
|
|
104
|
+
wrapper: string | ConcreteComponent<{}, any, any, import("vue").ComputedOptions, import("vue").MethodOptions>;
|
|
105
|
+
field: [] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | null | undefined;
|
|
106
|
+
separator: string;
|
|
107
|
+
fallback: string;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Component to render a Prismic rich text field as plain text.
|
|
111
|
+
*
|
|
112
|
+
* @see Component props {@link PrismicTextProps}
|
|
113
|
+
* @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}
|
|
114
|
+
*/
|
|
115
|
+
export declare const PrismicText: new () => {
|
|
116
|
+
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & PrismicTextProps;
|
|
117
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { computed, unref, defineComponent, h } from "vue";
|
|
2
|
+
import { isFilled, asText } from "@prismicio/helpers";
|
|
3
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent.js";
|
|
4
|
+
const defaultWrapper = "div";
|
|
5
|
+
const usePrismicText = (props) => {
|
|
6
|
+
const text = computed(() => {
|
|
7
|
+
const field = unref(props.field);
|
|
8
|
+
if (!isFilled.richText(field)) {
|
|
9
|
+
return unref(props.fallback) ?? "";
|
|
10
|
+
}
|
|
11
|
+
return asText(unref(field), unref(props.separator));
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
text
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const PrismicTextImpl = /* @__PURE__ */ defineComponent({
|
|
18
|
+
name: "PrismicText",
|
|
19
|
+
props: {
|
|
20
|
+
field: {
|
|
21
|
+
type: Array,
|
|
22
|
+
default: void 0,
|
|
23
|
+
required: false
|
|
24
|
+
},
|
|
25
|
+
separator: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: void 0,
|
|
28
|
+
required: false
|
|
29
|
+
},
|
|
30
|
+
wrapper: {
|
|
31
|
+
type: [String, Object, Function],
|
|
32
|
+
default: void 0,
|
|
33
|
+
required: false
|
|
34
|
+
},
|
|
35
|
+
fallback: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: void 0,
|
|
38
|
+
required: false
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
setup(props) {
|
|
42
|
+
const { text } = usePrismicText(props);
|
|
43
|
+
return () => {
|
|
44
|
+
const parent = simplyResolveComponent(props.wrapper || defaultWrapper);
|
|
45
|
+
return h(parent, null, {
|
|
46
|
+
default: () => text.value
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const PrismicText = PrismicTextImpl;
|
|
52
|
+
export {
|
|
53
|
+
PrismicText,
|
|
54
|
+
PrismicTextImpl,
|
|
55
|
+
usePrismicText
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=PrismicText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicText.js","sources":["../../../src/components/PrismicText.ts"],"sourcesContent":["import {\n\tAllowedComponentProps,\n\tComponentCustomProps,\n\tcomputed,\n\tComputedRef,\n\tConcreteComponent,\n\tdefineComponent,\n\th,\n\tPropType,\n\tunref,\n\tVNode,\n\tVNodeProps,\n} from \"vue\";\n\nimport { asText, isFilled } from \"@prismicio/helpers\";\nimport { RichTextField } from \"@prismicio/types\";\n\nimport { VueUseOptions } from \"../types\";\nimport { simplyResolveComponent } from \"../lib/simplyResolveComponent\";\n\n/**\n * The default component rendered to wrap the text output.\n */\nconst defaultWrapper = \"div\";\n/**\n * Props for `<PrismicText />`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic rich text or title field to render.\n\t */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * Separator used to join each element.\n\t *\n\t * @defaultValue `\" \"` (a space)\n\t */\n\tseparator?: string;\n\n\t/**\n\t * An HTML tag name, a component, or a functional component used to wrap the\n\t * output.\n\t *\n\t * @defaultValue `\"div\"`\n\t */\n\twrapper?: string | ConcreteComponent;\n\n\t/**\n\t * The string value to be rendered when the field is empty. If a fallback is\n\t * not given, `\"\"` (nothing) will be rendered.\n\t */\n\tfallback?: string;\n};\n\n/**\n * Options for {@link usePrismicText}.\n */\nexport type UsePrismicTextOptions = VueUseOptions<\n\tOmit<PrismicTextProps, \"wrapper\">\n>;\n\n/**\n * Return type of {@link usePrismicText}.\n */\nexport type UsePrismicTextReturnType = {\n\t/**\n\t * Serialized rich text field as plain text.\n\t */\n\ttext: ComputedRef<string>;\n};\n\n/**\n * A low level composable that returns a serialized rich text field as plain\n * text.\n *\n * @param props - {@link UsePrismicTextOptions}\n *\n * @returns - Serialized rich text field as plain text\n * {@link UsePrismicTextReturnType}\n */\nexport const usePrismicText = (\n\tprops: UsePrismicTextOptions,\n): UsePrismicTextReturnType => {\n\tconst text = computed(() => {\n\t\tconst field = unref(props.field);\n\n\t\tif (!isFilled.richText(field)) {\n\t\t\treturn unref(props.fallback) ?? \"\";\n\t\t}\n\n\t\treturn asText(unref(field), unref(props.separator));\n\t});\n\n\treturn {\n\t\ttext,\n\t};\n};\n\n/**\n * `<PrismicText />` implementation.\n *\n * @internal\n */\nexport const PrismicTextImpl = /*#__PURE__*/ defineComponent({\n\tname: \"PrismicText\",\n\tprops: {\n\t\tfield: {\n\t\t\ttype: Array as unknown as PropType<RichTextField | null | undefined>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tseparator: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\twrapper: {\n\t\t\ttype: [String, Object, Function] as PropType<string | ConcreteComponent>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t\tfallback: {\n\t\t\ttype: String as PropType<string>,\n\t\t\tdefault: undefined,\n\t\t\trequired: false,\n\t\t},\n\t},\n\tsetup(props) {\n\t\tconst { text } = usePrismicText(props);\n\n\t\treturn () => {\n\t\t\tconst parent = simplyResolveComponent(props.wrapper || defaultWrapper);\n\n\t\t\t// This works but is absurd\n\t\t\t// if (typeof parent === \"string\") {\n\t\t\t// \treturn h(parent, null, { default: () => text.value });\n\t\t\t// } else {\n\t\t\t// \treturn h(parent, null, { default: () => text.value });\n\t\t\t// }\n\n\t\t\treturn h(parent as VNode, null, {\n\t\t\t\tdefault: () => text.value,\n\t\t\t});\n\t\t};\n\t},\n});\n\n// export the public type for h/tsx inference\n// also to avoid inline import() in generated d.ts files\n/**\n * Component to render a Prismic rich text field as plain text.\n *\n * @see Component props {@link PrismicTextProps}\n * @see Templating rich text and title fields {@link https://prismic.io/docs/technologies/vue-template-content#rich-text-and-titles}\n */\nexport const PrismicText = PrismicTextImpl as unknown as {\n\tnew (): {\n\t\t$props: AllowedComponentProps &\n\t\t\tComponentCustomProps &\n\t\t\tVNodeProps &\n\t\t\tPrismicTextProps;\n\t};\n};\n"],"names":[],"mappings":";;;AAuBA,MAAM,iBAAiB;AA0DV,MAAA,iBAAiB,CAC7B,UAC6B;AACvB,QAAA,OAAO,SAAS,MAAK;AACpB,UAAA,QAAQ,MAAM,MAAM,KAAK;AAE/B,QAAI,CAAC,SAAS,SAAS,KAAK,GAAG;AACvB,aAAA,MAAM,MAAM,QAAQ,KAAK;AAAA,IAChC;AAED,WAAO,OAAO,MAAM,KAAK,GAAG,MAAM,MAAM,SAAS,CAAC;AAAA,EAAA,CAClD;AAEM,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;AAOO,MAAM,kBAAgD,gCAAA;AAAA,EAC5D,MAAM;AAAA,EACN,OAAO;AAAA,IACN,OAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,WAAW;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,SAAS;AAAA,MACR,MAAM,CAAC,QAAQ,QAAQ,QAAQ;AAAA,MAC/B,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,IACD,UAAU;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU;AAAA,IACV;AAAA,EACD;AAAA,EACD,MAAM,OAAK;AACV,UAAM,EAAE,KAAA,IAAS,eAAe,KAAK;AAErC,WAAO,MAAK;AACX,YAAM,SAAS,uBAAuB,MAAM,WAAW,cAAc;AAS9D,aAAA,EAAE,QAAiB,MAAM;AAAA,QAC/B,SAAS,MAAM,KAAK;AAAA,MAAA,CACpB;AAAA,IAAA;AAAA,EAEH;AACA,CAAA;AAUM,MAAM,cAAc;"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const simplyResolveComponent = require("../lib/simplyResolveComponent.cjs");
|
|
5
|
+
const __PRODUCTION__ = require("../lib/__PRODUCTION__.cjs");
|
|
6
|
+
const usePrismic = require("../usePrismic.cjs");
|
|
7
|
+
const getSliceComponentProps = (propsHint) => ({
|
|
8
|
+
slice: {
|
|
9
|
+
type: Object,
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
index: {
|
|
13
|
+
type: Number,
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
slices: {
|
|
17
|
+
type: Array,
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
context: {
|
|
21
|
+
type: null,
|
|
22
|
+
required: true
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const TODOSliceComponent = __PRODUCTION__.__PRODUCTION__ ? () => null : /* @__PURE__ */ vue.defineComponent({
|
|
26
|
+
name: "TODOSliceComponent",
|
|
27
|
+
props: getSliceComponentProps(),
|
|
28
|
+
setup(props) {
|
|
29
|
+
const type = vue.computed(() => "slice_type" in props.slice ? props.slice.slice_type : props.slice.type);
|
|
30
|
+
vue.watchEffect(() => {
|
|
31
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${type.value}"`, props.slice);
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
return vue.h("section", {
|
|
35
|
+
"data-slice-zone-todo-component": "",
|
|
36
|
+
"data-slice-type": type.value
|
|
37
|
+
}, [`Could not find a component for Slice type "${type.value}"`]);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const defineSliceZoneComponents = (components) => {
|
|
42
|
+
const result = {};
|
|
43
|
+
let type;
|
|
44
|
+
for (type in components) {
|
|
45
|
+
const component = components[type];
|
|
46
|
+
result[type] = typeof component === "string" ? component : vue.markRaw(component);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
const SliceZoneImpl = /* @__PURE__ */ vue.defineComponent({
|
|
51
|
+
name: "SliceZone",
|
|
52
|
+
props: {
|
|
53
|
+
slices: {
|
|
54
|
+
type: Array,
|
|
55
|
+
required: true
|
|
56
|
+
},
|
|
57
|
+
components: {
|
|
58
|
+
type: Object,
|
|
59
|
+
default: void 0,
|
|
60
|
+
required: false
|
|
61
|
+
},
|
|
62
|
+
resolver: {
|
|
63
|
+
type: Function,
|
|
64
|
+
default: void 0,
|
|
65
|
+
required: false
|
|
66
|
+
},
|
|
67
|
+
context: {
|
|
68
|
+
type: null,
|
|
69
|
+
default: void 0,
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
72
|
+
defaultComponent: {
|
|
73
|
+
type: Object,
|
|
74
|
+
default: void 0,
|
|
75
|
+
required: false
|
|
76
|
+
},
|
|
77
|
+
wrapper: {
|
|
78
|
+
type: [String, Object, Function],
|
|
79
|
+
default: void 0,
|
|
80
|
+
required: false
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
setup(props) {
|
|
84
|
+
if (!props.slices) {
|
|
85
|
+
return () => null;
|
|
86
|
+
}
|
|
87
|
+
const { options } = usePrismic.usePrismic();
|
|
88
|
+
const renderedSlices = vue.computed(() => {
|
|
89
|
+
return props.slices.map((slice, index) => {
|
|
90
|
+
var _a;
|
|
91
|
+
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
92
|
+
let component = props.components && type in props.components ? props.components[type] : props.defaultComponent || ((_a = options.components) == null ? void 0 : _a.sliceZoneDefaultComponent) || TODOSliceComponent;
|
|
93
|
+
if (props.resolver) {
|
|
94
|
+
const resolvedComponent = props.resolver({
|
|
95
|
+
slice,
|
|
96
|
+
sliceName: type,
|
|
97
|
+
i: index
|
|
98
|
+
});
|
|
99
|
+
if (resolvedComponent) {
|
|
100
|
+
component = resolvedComponent;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
104
|
+
const p = {
|
|
105
|
+
key,
|
|
106
|
+
slice,
|
|
107
|
+
index,
|
|
108
|
+
context: props.context,
|
|
109
|
+
slices: props.slices
|
|
110
|
+
};
|
|
111
|
+
return vue.h(simplyResolveComponent.simplyResolveComponent(component), p);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return () => {
|
|
115
|
+
if (props.wrapper) {
|
|
116
|
+
const parent = simplyResolveComponent.simplyResolveComponent(props.wrapper);
|
|
117
|
+
if (typeof parent === "string") {
|
|
118
|
+
return vue.h(parent, null, renderedSlices.value);
|
|
119
|
+
} else {
|
|
120
|
+
return vue.h(parent, null, { default: () => renderedSlices.value });
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
return renderedSlices.value;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const SliceZone = SliceZoneImpl;
|
|
129
|
+
exports.SliceZone = SliceZone;
|
|
130
|
+
exports.SliceZoneImpl = SliceZoneImpl;
|
|
131
|
+
exports.TODOSliceComponent = TODOSliceComponent;
|
|
132
|
+
exports.defineSliceZoneComponents = defineSliceZoneComponents;
|
|
133
|
+
exports.getSliceComponentProps = getSliceComponentProps;
|
|
134
|
+
//# sourceMappingURL=SliceZone.cjs.map
|