@prismicio/svelte 0.0.6 → 0.0.8-dev.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/dist/__PRODUCTION__.d.ts +7 -0
- package/dist/__PRODUCTION__.js +11 -0
- package/dist/components/PrismicEmbed.svelte +26 -0
- package/{lib → dist}/components/PrismicEmbed.svelte.d.ts +11 -1
- package/dist/components/PrismicImage.svelte +90 -0
- package/dist/components/PrismicImage.svelte.d.ts +71 -0
- package/dist/components/PrismicRichText/DefaultComponent.svelte +51 -0
- package/dist/components/PrismicRichText/DefaultComponent.svelte.d.ts +21 -0
- package/dist/components/PrismicRichText/PrismicRichText.svelte +49 -0
- package/dist/components/PrismicRichText/PrismicRichText.svelte.d.ts +53 -0
- package/dist/components/PrismicRichText/Serialize.svelte +19 -0
- package/dist/components/PrismicRichText/Serialize.svelte.d.ts +21 -0
- package/dist/components/PrismicText.svelte +22 -0
- package/{lib → dist}/components/PrismicText.svelte.d.ts +14 -2
- package/dist/components/SliceZone.svelte +59 -0
- package/dist/components/SliceZone.svelte.d.ts +60 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/src/lib/__PRODUCTION__.ts +12 -0
- package/dist/src/lib/components/PrismicEmbed.svelte +29 -0
- package/dist/src/lib/components/PrismicImage.svelte +178 -0
- package/{src → dist/src}/lib/components/PrismicLink.svelte +1 -0
- package/dist/src/lib/components/PrismicRichText/DefaultComponent.svelte +56 -0
- package/dist/src/lib/components/PrismicRichText/PrismicRichText.svelte +69 -0
- package/dist/src/lib/components/PrismicRichText/Serialize.svelte +30 -0
- package/dist/src/lib/components/PrismicText.svelte +29 -0
- package/{src → dist/src}/lib/components/SliceZone.svelte +47 -1
- package/dist/src/lib/components/index.ts +11 -0
- package/dist/src/lib/index.ts +9 -0
- package/{src → dist/src}/routes/+page.server.ts +1 -1
- package/dist/src/routes/+page.svelte +61 -0
- package/dist/src/routes/components/Emphasis.svelte +3 -0
- package/dist/src/routes/components/index.js +1 -0
- package/dist/src/routes/slices/RichText/index.svelte +9 -0
- package/{src → dist/src}/types/ExampleDocument.type.ts +2 -0
- package/{src → dist/src}/types/index.ts +0 -2
- package/package.json +144 -77
- package/CHANGELOG.md +0 -77
- package/PrismicProvider.svelte +0 -21
- package/components/PrismicEmbed.svelte +0 -10
- package/components/PrismicImage.svelte +0 -15
- package/components/PrismicPreview.svelte +0 -26
- package/components/PrismicRichText.svelte +0 -8
- package/components/PrismicText.svelte +0 -7
- package/components/SliceZone.svelte +0 -17
- package/components/index.js +0 -7
- package/configurePrismic.js +0 -17
- package/index.js +0 -13
- package/injectionSymbols.js +0 -1
- package/lib/PrismicProvider.svelte.d.ts +0 -24
- package/lib/components/PrismicImage.svelte.d.ts +0 -18
- package/lib/components/PrismicPreview.svelte.d.ts +0 -20
- package/lib/components/PrismicRichText.svelte.d.ts +0 -20
- package/lib/components/SliceZone.svelte.d.ts +0 -25
- package/lib/components/index.d.ts +0 -2
- package/lib/configurePrismic.d.ts +0 -9
- package/lib/index.d.ts +0 -1
- package/lib/injectionSymbols.d.ts +0 -1
- package/lib/usePrismic.d.ts +0 -2
- package/src/lib/PrismicProvider.svelte +0 -26
- package/src/lib/components/PrismicEmbed.svelte +0 -14
- package/src/lib/components/PrismicImage.svelte +0 -20
- package/src/lib/components/PrismicPreview.svelte +0 -29
- package/src/lib/components/PrismicRichText.svelte +0 -14
- package/src/lib/components/PrismicText.svelte +0 -12
- package/src/lib/components/index.ts +0 -13
- package/src/lib/configurePrismic.ts +0 -30
- package/src/lib/index.ts +0 -18
- package/src/lib/injectionSymbols.ts +0 -1
- package/src/lib/usePrismic.ts +0 -12
- package/src/routes/+page.svelte +0 -35
- package/src/routes/slices/RichText/index.svelte +0 -8
- package/src/types/PrismicConfig.type.ts +0 -8
- package/src/types/PrismicContext.type.ts +0 -13
- package/types/PrismicContext.type.d.ts +0 -7
- package/usePrismic.js +0 -10
- /package/{components → dist/components}/PrismicLink.svelte +0 -0
- /package/{lib → dist}/components/PrismicLink.svelte.d.ts +0 -0
- /package/{components → dist/components}/TodoSliceComponent.svelte +0 -0
- /package/{lib → dist}/components/TodoSliceComponent.svelte.d.ts +0 -0
- /package/{src → dist/src}/app.html +0 -0
- /package/{src → dist/src}/global.d.ts +0 -0
- /package/{src → dist/src}/lib/components/TodoSliceComponent.svelte +0 -0
- /package/{src → dist/src}/routes/slices/CodeSnippet/index.svelte +0 -0
- /package/{src → dist/src}/routes/slices/index.ts +0 -0
- /package/{src → dist/src}/types/CodeSnippetSlice.type.ts +0 -0
- /package/{src → dist/src}/types/PageDocument.type.ts +0 -0
- /package/{src → dist/src}/types/RichTextSlice.type.ts +0 -0
- /package/{src → dist/src}/types/Route.type.ts +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
* `true` if in the production environment, `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This boolean can be used to perform actions only in development environments,
|
|
9
|
+
* such as logging.
|
|
10
|
+
*/
|
|
11
|
+
export const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script>import * as prismicH from "@prismicio/helpers";
|
|
2
|
+
/**
|
|
3
|
+
* An Embed field from Prismic.
|
|
4
|
+
*/
|
|
5
|
+
export let field;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<!--
|
|
9
|
+
@component
|
|
10
|
+
Component to render a Prismic Embed field.
|
|
11
|
+
|
|
12
|
+
@example Rendering an Embed field:
|
|
13
|
+
```svelte
|
|
14
|
+
<PrismicEmbed field={document.data.example_embed} />
|
|
15
|
+
```
|
|
16
|
+
-->
|
|
17
|
+
|
|
18
|
+
{#if prismicH.isFilled.embed(field)}
|
|
19
|
+
<div
|
|
20
|
+
data-oembed={field.embed_url}
|
|
21
|
+
data-oembed-type={field.type}
|
|
22
|
+
data-oembed-provider={field.provider_name}
|
|
23
|
+
>
|
|
24
|
+
{@html field.html}
|
|
25
|
+
</div>
|
|
26
|
+
{/if}
|
|
@@ -2,7 +2,9 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
import type * as prismicT from "@prismicio/types";
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* An Embed field from Prismic.
|
|
7
|
+
*/ field: prismicT.EmbedField;
|
|
6
8
|
};
|
|
7
9
|
events: {
|
|
8
10
|
[evt: string]: CustomEvent<any>;
|
|
@@ -12,6 +14,14 @@ declare const __propDef: {
|
|
|
12
14
|
export type PrismicEmbedProps = typeof __propDef.props;
|
|
13
15
|
export type PrismicEmbedEvents = typeof __propDef.events;
|
|
14
16
|
export type PrismicEmbedSlots = typeof __propDef.slots;
|
|
17
|
+
/**
|
|
18
|
+
* Component to render a Prismic Embed field.
|
|
19
|
+
*
|
|
20
|
+
* @example Rendering an Embed field:
|
|
21
|
+
* ```svelte
|
|
22
|
+
* <PrismicEmbed field={document.data.example_embed} />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
15
25
|
export default class PrismicEmbed extends SvelteComponentTyped<PrismicEmbedProps, PrismicEmbedEvents, PrismicEmbedSlots> {
|
|
16
26
|
}
|
|
17
27
|
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script>import * as prismicH from "@prismicio/helpers";
|
|
2
|
+
import { __PRODUCTION__ } from "../__PRODUCTION__";
|
|
3
|
+
export let field;
|
|
4
|
+
export let imgixParams = {};
|
|
5
|
+
export let widths = undefined;
|
|
6
|
+
export let pixelDensities = undefined;
|
|
7
|
+
export let width = undefined;
|
|
8
|
+
export let height = undefined;
|
|
9
|
+
export let alt = undefined;
|
|
10
|
+
export let fallbackAlt = undefined;
|
|
11
|
+
const castInt = (input) => {
|
|
12
|
+
if (typeof input === "number" ||
|
|
13
|
+
typeof input === "undefined" ||
|
|
14
|
+
input === null) {
|
|
15
|
+
return input;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const parsed = Number.parseInt(input);
|
|
19
|
+
if (Number.isNaN(parsed)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const ar = field.dimensions && field.dimensions.width / field.dimensions.height;
|
|
28
|
+
const castedWidth = castInt(width);
|
|
29
|
+
const castedHeight = castInt(height);
|
|
30
|
+
let resolvedWidth = castedWidth ?? (field.dimensions && field.dimensions.width);
|
|
31
|
+
let resolvedHeight = castedHeight ?? (field.dimensions && field.dimensions.height);
|
|
32
|
+
if (ar &&
|
|
33
|
+
castedWidth != null &&
|
|
34
|
+
(castedHeight == null || typeof castedWidth !== "undefined")) {
|
|
35
|
+
resolvedHeight = castedWidth / ar;
|
|
36
|
+
}
|
|
37
|
+
else if (ar &&
|
|
38
|
+
castedHeight != null &&
|
|
39
|
+
(castedWidth == null || typeof castedWidth !== "undefined")) {
|
|
40
|
+
resolvedWidth = castedHeight * ar;
|
|
41
|
+
}
|
|
42
|
+
if (!__PRODUCTION__) {
|
|
43
|
+
if (widths && pixelDensities) {
|
|
44
|
+
console.warn(`[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`);
|
|
45
|
+
}
|
|
46
|
+
if (typeof alt === "string" && alt !== "") {
|
|
47
|
+
console.warn(`[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="".`);
|
|
48
|
+
}
|
|
49
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
50
|
+
console.warn(`[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="".`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<!--
|
|
56
|
+
@component
|
|
57
|
+
Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
|
|
58
|
+
|
|
59
|
+
@example Rendering an Image field:
|
|
60
|
+
```svelte
|
|
61
|
+
<PrismicImage
|
|
62
|
+
field={document.data.example_image}
|
|
63
|
+
imgixParams={{ sat: -100 }}
|
|
64
|
+
/>
|
|
65
|
+
```
|
|
66
|
+
-->
|
|
67
|
+
|
|
68
|
+
{#if prismicH.isFilled.image(field)}
|
|
69
|
+
{@const { src, srcset } =
|
|
70
|
+
pixelDensities && !widths
|
|
71
|
+
? prismicH.asImagePixelDensitySrcSet(field, {
|
|
72
|
+
pixelDensities:
|
|
73
|
+
pixelDensities === "defaults" ? undefined : pixelDensities,
|
|
74
|
+
...imgixParams,
|
|
75
|
+
})
|
|
76
|
+
: prismicH.asImageWidthSrcSet(field, {
|
|
77
|
+
widths: widths === "defaults" ? undefined : widths,
|
|
78
|
+
...imgixParams,
|
|
79
|
+
})}
|
|
80
|
+
<img
|
|
81
|
+
{src}
|
|
82
|
+
{srcset}
|
|
83
|
+
alt={alt ?? field.alt ?? fallbackAlt}
|
|
84
|
+
width={width || height ? resolvedWidth : field.dimensions.width}
|
|
85
|
+
height={height || (width ? resolvedHeight : field.dimensions.height)}
|
|
86
|
+
{...$$restProps}
|
|
87
|
+
/>
|
|
88
|
+
{:else}
|
|
89
|
+
<img alt={field.alt || ""} {...$$restProps} />
|
|
90
|
+
{/if}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import * as prismicH from "@prismicio/helpers";
|
|
3
|
+
import type * as prismicT from "@prismicio/types";
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
/**
|
|
7
|
+
* A Prismic Image field.
|
|
8
|
+
*/
|
|
9
|
+
field: prismicT.ImageField;
|
|
10
|
+
/**
|
|
11
|
+
* An object of Imgix URL API parameters to transform the image.
|
|
12
|
+
*
|
|
13
|
+
* See: https://docs.imgix.com/apis/rendering
|
|
14
|
+
*/
|
|
15
|
+
imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
|
|
16
|
+
/**
|
|
17
|
+
* Widths used to build a `srcset` value for the Image field.
|
|
18
|
+
*
|
|
19
|
+
* If a `widths` prop is not given or `"defaults"` is passed, the following
|
|
20
|
+
* widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
21
|
+
*
|
|
22
|
+
* If the Image field contains responsive views, each responsive view can be
|
|
23
|
+
* used as a width in the resulting `srcset` by passing `"thumbnails"` as
|
|
24
|
+
* the `widths` prop.
|
|
25
|
+
*/
|
|
26
|
+
widths?: NonNullable<Parameters<typeof prismicH.asImageWidthSrcSet>[1]>["widths"] | "defaults";
|
|
27
|
+
/**
|
|
28
|
+
* Pixel densities used to build a `srcset` value for the Image field.
|
|
29
|
+
*
|
|
30
|
+
* If a `pixelDensities` prop is passed `"defaults"`, the following pixel
|
|
31
|
+
* densities will be used: 1, 2, 3.
|
|
32
|
+
*/
|
|
33
|
+
pixelDensities?: NonNullable<Parameters<typeof prismicH.asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
|
|
34
|
+
/**
|
|
35
|
+
* Declare an image as decorative by providing `alt=""`.
|
|
36
|
+
*
|
|
37
|
+
* See:
|
|
38
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
39
|
+
*/
|
|
40
|
+
alt?: "" | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Declare an image as decorative only if the Image field does not have
|
|
43
|
+
* alternative text by providing `fallbackAlt=""`.
|
|
44
|
+
*
|
|
45
|
+
* See:
|
|
46
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
47
|
+
*/
|
|
48
|
+
fallbackAlt?: "" | undefined;
|
|
49
|
+
};
|
|
50
|
+
events: {
|
|
51
|
+
[evt: string]: CustomEvent<any>;
|
|
52
|
+
};
|
|
53
|
+
slots: {};
|
|
54
|
+
};
|
|
55
|
+
export type PrismicImageProps = typeof __propDef.props;
|
|
56
|
+
export type PrismicImageEvents = typeof __propDef.events;
|
|
57
|
+
export type PrismicImageSlots = typeof __propDef.slots;
|
|
58
|
+
/**
|
|
59
|
+
* Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
|
|
60
|
+
*
|
|
61
|
+
* @example Rendering an Image field:
|
|
62
|
+
* ```svelte
|
|
63
|
+
* <PrismicImage
|
|
64
|
+
* field={document.data.example_image}
|
|
65
|
+
* imgixParams={{ sat: -100 }}
|
|
66
|
+
* />
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export default class PrismicImage extends SvelteComponentTyped<PrismicImageProps, PrismicImageEvents, PrismicImageSlots> {
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script>import { PrismicImage, PrismicEmbed, PrismicLink } from "..";
|
|
2
|
+
export let node;
|
|
3
|
+
export let linkResolver = undefined;
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
{#if node.type === "heading1"}
|
|
7
|
+
<h1><slot /></h1>
|
|
8
|
+
{:else if node.type === "heading2"}
|
|
9
|
+
<h2><slot /></h2>
|
|
10
|
+
{:else if node.type === "heading3"}
|
|
11
|
+
<h3><slot /></h3>
|
|
12
|
+
{:else if node.type === "heading4"}
|
|
13
|
+
<h4><slot /></h4>
|
|
14
|
+
{:else if node.type === "heading5"}
|
|
15
|
+
<h5><slot /></h5>
|
|
16
|
+
{:else if node.type === "heading6"}
|
|
17
|
+
<h6><slot /></h6>
|
|
18
|
+
{:else if node.type === "paragraph"}
|
|
19
|
+
<p><slot /></p>
|
|
20
|
+
{:else if node.type === "preformatted"}
|
|
21
|
+
<pre><slot /></pre>
|
|
22
|
+
{:else if node.type === "strong"}
|
|
23
|
+
<strong><slot /></strong>
|
|
24
|
+
{:else if node.type === "em"}
|
|
25
|
+
<em><slot /></em>
|
|
26
|
+
{:else if node.type === "list-item"}
|
|
27
|
+
<li><slot /></li>
|
|
28
|
+
{:else if node.type === "o-list-item"}
|
|
29
|
+
<li><slot /></li>
|
|
30
|
+
{:else if node.type === "group-list-item"}
|
|
31
|
+
<ul><slot /></ul>
|
|
32
|
+
{:else if node.type === "group-o-list-item"}
|
|
33
|
+
<ol><slot /></ol>
|
|
34
|
+
{:else if node.type === "image"}
|
|
35
|
+
<p class="block-img">
|
|
36
|
+
<PrismicImage field={node} />
|
|
37
|
+
</p>
|
|
38
|
+
{:else if node.type === "embed"}
|
|
39
|
+
<PrismicEmbed field={node.oembed} />
|
|
40
|
+
{:else if node.type === "hyperlink"}
|
|
41
|
+
<PrismicLink {linkResolver} field={node.data}><slot /></PrismicLink>
|
|
42
|
+
{:else if node.type === "label"}
|
|
43
|
+
<span class={node.data.label}><slot /></span>
|
|
44
|
+
{:else}
|
|
45
|
+
{#each node.text.split("\n") as line, index}
|
|
46
|
+
{#if index > 0}
|
|
47
|
+
<br />
|
|
48
|
+
{/if}
|
|
49
|
+
{line}
|
|
50
|
+
{/each}
|
|
51
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { LinkResolverFunction } from "@prismicio/helpers";
|
|
3
|
+
import type { RTAnyNode } from "@prismicio/types";
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
node: RTAnyNode;
|
|
7
|
+
linkResolver?: LinkResolverFunction | undefined;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type DefaultComponentProps = typeof __propDef.props;
|
|
17
|
+
export type DefaultComponentEvents = typeof __propDef.events;
|
|
18
|
+
export type DefaultComponentSlots = typeof __propDef.slots;
|
|
19
|
+
export default class DefaultComponent extends SvelteComponentTyped<DefaultComponentProps, DefaultComponentEvents, DefaultComponentSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script>import { asTree, wrapMapSerializer, } from "@prismicio/richtext";
|
|
2
|
+
import Serialize from "./Serialize.svelte";
|
|
3
|
+
/**
|
|
4
|
+
* The Prismic Rich Text field to render.
|
|
5
|
+
*/
|
|
6
|
+
export let field = [];
|
|
7
|
+
/**
|
|
8
|
+
* The Link Resolver used to resolve links.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* If your app uses Route Resolvers when querying for your Prismic
|
|
12
|
+
* repository's content, a Link Resolver does not need to be provided.
|
|
13
|
+
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/route-resolver}
|
|
14
|
+
*/
|
|
15
|
+
export let linkResolver = undefined;
|
|
16
|
+
/**
|
|
17
|
+
* An object that maps Rich Text blocks to functions.
|
|
18
|
+
*
|
|
19
|
+
* @example A serializer that modififes `h1` and `em` elements:
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* import Title from "./Title.svelte";
|
|
23
|
+
*
|
|
24
|
+
* const field = exampleRichText;
|
|
25
|
+
*
|
|
26
|
+
* const richTextSerializer = {
|
|
27
|
+
* h1: () => Title,
|
|
28
|
+
* em: ({ children }) => `<mark>${children}</mark>`,
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export let richTextSerializer = undefined;
|
|
33
|
+
const resolvedSerializer = typeof richTextSerializer === "object"
|
|
34
|
+
? wrapMapSerializer(richTextSerializer)
|
|
35
|
+
: richTextSerializer;
|
|
36
|
+
const nodes = asTree(field).children;
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<!--
|
|
40
|
+
@component
|
|
41
|
+
Component to render a Prismic Rich Text or Title field as HTML.
|
|
42
|
+
|
|
43
|
+
@example Rendering a Link field:
|
|
44
|
+
```svelte
|
|
45
|
+
<PrismicRichText field={document.data.example_rich_text} />
|
|
46
|
+
```
|
|
47
|
+
-->
|
|
48
|
+
|
|
49
|
+
<Serialize {nodes} serializer={resolvedSerializer} {linkResolver} />
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { SvelteComponent } from "svelte";
|
|
3
|
+
import { type RichTextFunctionSerializer, type RichTextMapSerializer, type TreeNode } from "@prismicio/richtext";
|
|
4
|
+
import type { LinkResolverFunction } from "@prismicio/helpers";
|
|
5
|
+
declare const __propDef: {
|
|
6
|
+
props: {
|
|
7
|
+
/**
|
|
8
|
+
* The Prismic Rich Text field to render.
|
|
9
|
+
*/ field?: [] | [import("@prismicio/types").RTNode, ...import("@prismicio/types").RTNode[]] | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The Link Resolver used to resolve links.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* If your app uses Route Resolvers when querying for your Prismic
|
|
15
|
+
* repository's content, a Link Resolver does not need to be provided.
|
|
16
|
+
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/route-resolver}
|
|
17
|
+
*/ linkResolver?: LinkResolverFunction | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* An object that maps Rich Text blocks to functions.
|
|
20
|
+
*
|
|
21
|
+
* @example A serializer that modififes `h1` and `em` elements:
|
|
22
|
+
*
|
|
23
|
+
* ```js
|
|
24
|
+
* import Title from "./Title.svelte";
|
|
25
|
+
*
|
|
26
|
+
* const field = exampleRichText;
|
|
27
|
+
*
|
|
28
|
+
* const richTextSerializer = {
|
|
29
|
+
* h1: () => Title,
|
|
30
|
+
* em: ({ children }) => `<mark>${children}</mark>`,
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*/ richTextSerializer?: RichTextMapSerializer<typeof SvelteComponent, TreeNode> | RichTextFunctionSerializer<typeof SvelteComponent, TreeNode> | undefined;
|
|
34
|
+
};
|
|
35
|
+
events: {
|
|
36
|
+
[evt: string]: CustomEvent<any>;
|
|
37
|
+
};
|
|
38
|
+
slots: {};
|
|
39
|
+
};
|
|
40
|
+
export type PrismicRichTextProps = typeof __propDef.props;
|
|
41
|
+
export type PrismicRichTextEvents = typeof __propDef.events;
|
|
42
|
+
export type PrismicRichTextSlots = typeof __propDef.slots;
|
|
43
|
+
/**
|
|
44
|
+
* Component to render a Prismic Rich Text or Title field as HTML.
|
|
45
|
+
*
|
|
46
|
+
* @example Rendering a Link field:
|
|
47
|
+
* ```svelte
|
|
48
|
+
* <PrismicRichText field={document.data.example_rich_text} />
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export default class PrismicRichText extends SvelteComponentTyped<PrismicRichTextProps, PrismicRichTextEvents, PrismicRichTextSlots> {
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script>import Default from "./DefaultComponent.svelte";
|
|
2
|
+
export let serializer;
|
|
3
|
+
export let nodes = [];
|
|
4
|
+
export let linkResolver = undefined;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#each nodes as node}
|
|
8
|
+
<svelte:component
|
|
9
|
+
this={(serializer &&
|
|
10
|
+
serializer(node.type, node.node, node.text, node.children, node.key)) ||
|
|
11
|
+
Default}
|
|
12
|
+
{...node}
|
|
13
|
+
{linkResolver}
|
|
14
|
+
>
|
|
15
|
+
{#if node.children.length > 0}
|
|
16
|
+
<svelte:self nodes={node.children} {serializer} />
|
|
17
|
+
{/if}
|
|
18
|
+
</svelte:component>
|
|
19
|
+
{/each}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { SvelteComponent } from "svelte";
|
|
3
|
+
import type { RichTextFunctionSerializer, TreeNode } from "@prismicio/richtext";
|
|
4
|
+
import type { LinkResolverFunction } from "@prismicio/helpers";
|
|
5
|
+
declare const __propDef: {
|
|
6
|
+
props: {
|
|
7
|
+
serializer: RichTextFunctionSerializer<typeof SvelteComponent, TreeNode> | undefined;
|
|
8
|
+
nodes?: TreeNode[] | undefined;
|
|
9
|
+
linkResolver?: LinkResolverFunction | undefined;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {};
|
|
15
|
+
};
|
|
16
|
+
export type SerializeProps = typeof __propDef.props;
|
|
17
|
+
export type SerializeEvents = typeof __propDef.events;
|
|
18
|
+
export type SerializeSlots = typeof __propDef.slots;
|
|
19
|
+
export default class Serialize extends SvelteComponentTyped<SerializeProps, SerializeEvents, SerializeSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>import * as prismicH from "@prismicio/helpers";
|
|
2
|
+
/**
|
|
3
|
+
* A Rich Text or Title field from Prismic.
|
|
4
|
+
*/
|
|
5
|
+
export let field;
|
|
6
|
+
/**
|
|
7
|
+
* The separator used between blocks. Defaults to `\n`.
|
|
8
|
+
*/
|
|
9
|
+
export let separator = undefined;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<!--
|
|
13
|
+
@component
|
|
14
|
+
Component to render a Prismic Rich Text or Title field as plain text.
|
|
15
|
+
|
|
16
|
+
@example Rendering a Rich Text field:
|
|
17
|
+
```svelte
|
|
18
|
+
<PrismicText field={document.data.example_rich_text} />
|
|
19
|
+
```
|
|
20
|
+
-->
|
|
21
|
+
|
|
22
|
+
{@html prismicH.asText(field, separator)}
|
|
@@ -3,8 +3,12 @@ import type { RichTextField as RichTextFieldType } from "@prismicio/types";
|
|
|
3
3
|
import type { TitleField as TitleFieldType } from "@prismicio/types";
|
|
4
4
|
declare const __propDef: {
|
|
5
5
|
props: {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* A Rich Text or Title field from Prismic.
|
|
8
|
+
*/ field: TitleFieldType | RichTextFieldType;
|
|
9
|
+
/**
|
|
10
|
+
* The separator used between blocks. Defaults to `\n`.
|
|
11
|
+
*/ separator?: string | undefined;
|
|
8
12
|
};
|
|
9
13
|
events: {
|
|
10
14
|
[evt: string]: CustomEvent<any>;
|
|
@@ -14,6 +18,14 @@ declare const __propDef: {
|
|
|
14
18
|
export type PrismicTextProps = typeof __propDef.props;
|
|
15
19
|
export type PrismicTextEvents = typeof __propDef.events;
|
|
16
20
|
export type PrismicTextSlots = typeof __propDef.slots;
|
|
21
|
+
/**
|
|
22
|
+
* Component to render a Prismic Rich Text or Title field as plain text.
|
|
23
|
+
*
|
|
24
|
+
* @example Rendering a Rich Text field:
|
|
25
|
+
* ```svelte
|
|
26
|
+
* <PrismicText field={document.data.example_rich_text} />
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
17
29
|
export default class PrismicText extends SvelteComponentTyped<PrismicTextProps, PrismicTextEvents, PrismicTextSlots> {
|
|
18
30
|
}
|
|
19
31
|
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script>import TodoSliceComponent from "./TodoSliceComponent.svelte";
|
|
2
|
+
/**
|
|
3
|
+
* An array of Prismic Slices, such as the `slices` property from a Prismic document.
|
|
4
|
+
*/
|
|
5
|
+
export let slices = [];
|
|
6
|
+
/**
|
|
7
|
+
* An object that maps Slice components to their corresponding API IDs
|
|
8
|
+
*
|
|
9
|
+
* @example An example map:
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* import BlockQuote from "./BlockQuote.svelte";
|
|
13
|
+
* import HeroImage from "./HeroImage.svelte";
|
|
14
|
+
*
|
|
15
|
+
* const components = {
|
|
16
|
+
* block_quote: BlockQuote,
|
|
17
|
+
* hero_image: HeroImage,
|
|
18
|
+
* };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export let components = {};
|
|
22
|
+
/**
|
|
23
|
+
* Arbitrary data passed to all Slice components as a `context` prop.
|
|
24
|
+
*/
|
|
25
|
+
export let context = {};
|
|
26
|
+
/**
|
|
27
|
+
* The Svelte component rendered if a component mapping from the `components`
|
|
28
|
+
* prop cannot be found.
|
|
29
|
+
*/
|
|
30
|
+
export let defaultComponent = undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the app is in development mode. When true, the SliceZone may
|
|
33
|
+
* display error messages in the UI.
|
|
34
|
+
*/
|
|
35
|
+
export let dev = false;
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<!--
|
|
39
|
+
@component
|
|
40
|
+
Component to render an array of Prismic Slices.
|
|
41
|
+
|
|
42
|
+
@example Rendering a Rich Text field:
|
|
43
|
+
```svelte
|
|
44
|
+
<SliceZone slices={document.data.slices} components={{
|
|
45
|
+
block_quote: BlockQuote,
|
|
46
|
+
hero_image: HeroImage
|
|
47
|
+
}} />
|
|
48
|
+
```
|
|
49
|
+
-->
|
|
50
|
+
|
|
51
|
+
{#each slices as slice, index}
|
|
52
|
+
{@const type = "slice_type" in slice ? slice.slice_type : slice.type}
|
|
53
|
+
{@const Component = components[type] || defaultComponent}
|
|
54
|
+
{#if Component}
|
|
55
|
+
<svelte:component this={Component} {slice} {slices} {context} {index} />
|
|
56
|
+
{:else}
|
|
57
|
+
<TodoSliceComponent {slice} {dev} />
|
|
58
|
+
{/if}
|
|
59
|
+
{/each}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { SvelteComponent } from "svelte";
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
/**
|
|
6
|
+
* An array of Prismic Slices, such as the `slices` property from a Prismic document.
|
|
7
|
+
*/ slices?: ({
|
|
8
|
+
slice_type: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: string;
|
|
11
|
+
})[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* An object that maps Slice components to their corresponding API IDs
|
|
14
|
+
*
|
|
15
|
+
* @example An example map:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import BlockQuote from "./BlockQuote.svelte";
|
|
19
|
+
* import HeroImage from "./HeroImage.svelte";
|
|
20
|
+
*
|
|
21
|
+
* const components = {
|
|
22
|
+
* block_quote: BlockQuote,
|
|
23
|
+
* hero_image: HeroImage,
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/ components?: Record<string, new (...args: any[]) => SvelteComponent> | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Arbitrary data passed to all Slice components as a `context` prop.
|
|
29
|
+
*/ context?: any;
|
|
30
|
+
/**
|
|
31
|
+
* The Svelte component rendered if a component mapping from the `components`
|
|
32
|
+
* prop cannot be found.
|
|
33
|
+
*/ defaultComponent?: SvelteComponent | (new (...args: any[]) => SvelteComponent) | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the app is in development mode. When true, the SliceZone may
|
|
36
|
+
* display error messages in the UI.
|
|
37
|
+
*/ dev?: boolean | undefined;
|
|
38
|
+
};
|
|
39
|
+
events: {
|
|
40
|
+
[evt: string]: CustomEvent<any>;
|
|
41
|
+
};
|
|
42
|
+
slots: {};
|
|
43
|
+
};
|
|
44
|
+
export type SliceZoneProps = typeof __propDef.props;
|
|
45
|
+
export type SliceZoneEvents = typeof __propDef.events;
|
|
46
|
+
export type SliceZoneSlots = typeof __propDef.slots;
|
|
47
|
+
/**
|
|
48
|
+
* Component to render an array of Prismic Slices.
|
|
49
|
+
*
|
|
50
|
+
* @example Rendering a Rich Text field:
|
|
51
|
+
* ```svelte
|
|
52
|
+
* <SliceZone slices={document.data.slices} components={{
|
|
53
|
+
* block_quote: BlockQuote,
|
|
54
|
+
* hero_image: HeroImage
|
|
55
|
+
* }} />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export default class SliceZone extends SvelteComponentTyped<SliceZoneProps, SliceZoneEvents, SliceZoneSlots> {
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
|
|
2
|
+
export { default as PrismicImage } from "./PrismicImage.svelte";
|
|
3
|
+
export { default as PrismicLink } from "./PrismicLink.svelte";
|
|
4
|
+
export { default as PrismicText } from "./PrismicText.svelte";
|
|
5
|
+
export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
|
|
6
|
+
export { default as SliceZone } from "./SliceZone.svelte";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
|
|
2
|
+
export { default as PrismicImage } from "./PrismicImage.svelte";
|
|
3
|
+
export { default as PrismicLink } from "./PrismicLink.svelte";
|
|
4
|
+
export { default as PrismicText } from "./PrismicText.svelte";
|
|
5
|
+
export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
|
|
6
|
+
export { default as SliceZone } from "./SliceZone.svelte";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PrismicEmbed, PrismicImage, PrismicLink, PrismicText, PrismicRichText, SliceZone, } from "./components";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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: {} } as typeof process;
|
|
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
|
+
export const __PRODUCTION__ = process.env.NODE_ENV === "production";
|