@prismicio/svelte 0.0.11 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -30
- package/dist/PrismicEmbed.svelte +8 -7
- package/dist/PrismicEmbed.svelte.d.ts +7 -7
- package/dist/PrismicImage.svelte +58 -64
- package/dist/PrismicImage.svelte.d.ts +270 -44
- package/dist/PrismicLink.svelte +16 -13
- package/dist/PrismicLink.svelte.d.ts +242 -35
- package/dist/PrismicRichText/DefaultComponent.svelte +1 -8
- package/dist/PrismicRichText/DefaultComponent.svelte.d.ts +4 -9
- package/dist/PrismicRichText/PrismicRichText.svelte +8 -14
- package/dist/PrismicRichText/PrismicRichText.svelte.d.ts +12 -33
- package/dist/PrismicRichText/Serialize.svelte +16 -15
- package/dist/PrismicRichText/Serialize.svelte.d.ts +7 -8
- package/dist/PrismicText.svelte +28 -4
- package/dist/PrismicText.svelte.d.ts +7 -10
- package/dist/SliceZone/SliceZone.svelte +12 -9
- package/dist/SliceZone/SliceZone.svelte.d.ts +41 -13
- package/dist/SliceZone/{TodoSliceComponent.svelte → TodoComponent.svelte} +2 -1
- package/dist/SliceZone/TodoComponent.svelte.d.ts +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib/devMsg.d.ts +16 -0
- package/dist/lib/devMsg.js +19 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/package.json +52 -112
- package/src/PrismicEmbed.svelte +30 -0
- package/src/PrismicImage.svelte +168 -0
- package/src/PrismicLink.svelte +60 -0
- package/{dist/src/lib → src}/PrismicRichText/DefaultComponent.svelte +3 -15
- package/src/PrismicRichText/PrismicRichText.svelte +32 -0
- package/src/PrismicRichText/Serialize.svelte +36 -0
- package/src/PrismicText.svelte +58 -0
- package/{dist/src/lib → src}/SliceZone/SliceZone.svelte +29 -21
- package/{dist/src/lib/SliceZone/TodoSliceComponent.svelte → src/SliceZone/TodoComponent.svelte} +2 -1
- package/{dist/src/lib → src}/index.ts +2 -0
- package/src/lib/devMsg.ts +20 -0
- package/src/types.ts +15 -0
- package/dist/SliceZone/TodoSliceComponent.svelte.d.ts +0 -20
- package/dist/src/app.html +0 -12
- package/dist/src/global.d.ts +0 -1
- package/dist/src/lib/PrismicEmbed.svelte +0 -29
- package/dist/src/lib/PrismicImage.svelte +0 -192
- package/dist/src/lib/PrismicLink.svelte +0 -64
- package/dist/src/lib/PrismicRichText/PrismicRichText.svelte +0 -67
- package/dist/src/lib/PrismicRichText/Serialize.svelte +0 -33
- package/dist/src/lib/PrismicText.svelte +0 -29
- package/dist/src/routes/+page.server.ts +0 -19
- package/dist/src/routes/+page.svelte +0 -62
- package/dist/src/routes/components/Emphasis.svelte +0 -3
- package/dist/src/routes/slices/CodeSnippet.svelte +0 -19
- package/dist/src/routes/slices/RichText.svelte +0 -12
- package/dist/src/types/CodeSnippetSlice.type.ts +0 -7
- package/dist/src/types/ExampleDocument.type.ts +0 -8
- package/dist/src/types/PageDocument.type.ts +0 -7
- package/dist/src/types/RichTextSlice.type.ts +0 -7
- package/dist/src/types/Route.type.ts +0 -14
- package/dist/src/types/index.ts +0 -5
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type {
|
|
3
|
-
import type { TreeNode } from "@prismicio/richtext";
|
|
2
|
+
import type { RTAnyNode } from "@prismicio/client";
|
|
4
3
|
|
|
5
4
|
import PrismicEmbed from "../PrismicEmbed.svelte";
|
|
6
5
|
import PrismicImage from "../PrismicImage.svelte";
|
|
7
6
|
import PrismicLink from "../PrismicLink.svelte";
|
|
8
7
|
|
|
9
|
-
export let node:
|
|
10
|
-
export let key: TreeNode["key"];
|
|
11
|
-
export let text: TreeNode["text"];
|
|
12
|
-
export let type: TreeNode["type"];
|
|
13
|
-
|
|
14
|
-
// These variables are not used in the component, but we need to
|
|
15
|
-
// superficially use them to supress development warnings.
|
|
16
|
-
key;
|
|
17
|
-
text;
|
|
18
|
-
type;
|
|
19
|
-
|
|
20
|
-
export let linkResolver: LinkResolverFunction | undefined = undefined;
|
|
8
|
+
export let node: RTAnyNode;
|
|
21
9
|
</script>
|
|
22
10
|
|
|
23
11
|
{#if node.type === "heading1"}
|
|
@@ -55,7 +43,7 @@
|
|
|
55
43
|
{:else if node.type === "embed"}
|
|
56
44
|
<PrismicEmbed field={node.oembed} />
|
|
57
45
|
{:else if node.type === "hyperlink"}
|
|
58
|
-
<PrismicLink
|
|
46
|
+
<PrismicLink field={node.data}><slot /></PrismicLink>
|
|
59
47
|
{:else if node.type === "label"}
|
|
60
48
|
<span class={node.data.label}><slot /></span>
|
|
61
49
|
{:else}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { asTree } from "@prismicio/richtext";
|
|
3
|
+
import type { RichTextField } from "@prismicio/client";
|
|
4
|
+
|
|
5
|
+
import type { SvelteRichTextSerializer } from "../types";
|
|
6
|
+
|
|
7
|
+
import Serialize from "./Serialize.svelte";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Prismic rich text field to render.
|
|
11
|
+
*/
|
|
12
|
+
export let field: RichTextField;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An object that maps a rich text block type to a Svelte component.
|
|
16
|
+
*/
|
|
17
|
+
export let components: SvelteRichTextSerializer = {};
|
|
18
|
+
|
|
19
|
+
$: children = asTree(field).children;
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<!--
|
|
23
|
+
@component
|
|
24
|
+
Component to render a Prismic rich text field.
|
|
25
|
+
|
|
26
|
+
@example Rendering a rich text field:
|
|
27
|
+
```svelte
|
|
28
|
+
<PrismicRichText field={document.data.example_rich_text} />
|
|
29
|
+
```
|
|
30
|
+
-->
|
|
31
|
+
|
|
32
|
+
<Serialize {children} {components} />
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { RichTextNodeType } from "@prismicio/client";
|
|
3
|
+
import type { asTree } from "@prismicio/richtext";
|
|
4
|
+
|
|
5
|
+
import type { SvelteRichTextSerializer } from "../types";
|
|
6
|
+
|
|
7
|
+
import DefaultComponent from "./DefaultComponent.svelte";
|
|
8
|
+
|
|
9
|
+
export let components: SvelteRichTextSerializer = {};
|
|
10
|
+
export let children: ReturnType<typeof asTree>["children"];
|
|
11
|
+
|
|
12
|
+
const rewrittenNodeTypes: Partial<
|
|
13
|
+
Record<
|
|
14
|
+
(typeof RichTextNodeType)[keyof typeof RichTextNodeType],
|
|
15
|
+
keyof typeof RichTextNodeType
|
|
16
|
+
>
|
|
17
|
+
> = {
|
|
18
|
+
"list-item": "listItem",
|
|
19
|
+
"o-list-item": "oListItem",
|
|
20
|
+
"group-list-item": "list",
|
|
21
|
+
"group-o-list-item": "oList",
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
{#each children as child}
|
|
26
|
+
<svelte:component
|
|
27
|
+
this={components[rewrittenNodeTypes[child.type] || child.type] ||
|
|
28
|
+
DefaultComponent}
|
|
29
|
+
node={child.node}
|
|
30
|
+
key={child.key}
|
|
31
|
+
>
|
|
32
|
+
{#if child.children.length > 0}
|
|
33
|
+
<svelte:self children={child.children} {components} />
|
|
34
|
+
{/if}
|
|
35
|
+
</svelte:component>
|
|
36
|
+
{/each}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { RichTextField } from "@prismicio/client";
|
|
3
|
+
import { isFilled, asText } from "@prismicio/client";
|
|
4
|
+
import { DEV } from "esm-env";
|
|
5
|
+
|
|
6
|
+
import { devMsg } from "./lib/devMsg";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A Rich Text or Title field from Prismic.
|
|
10
|
+
*/
|
|
11
|
+
export let field: RichTextField;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The separator used between blocks. Defaults to `\n`.
|
|
15
|
+
*/
|
|
16
|
+
export let separator: string | undefined = undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The string rendered when the field is empty. If a fallback is not given,
|
|
20
|
+
* `null` will be rendered.
|
|
21
|
+
*/
|
|
22
|
+
export let fallback: string | undefined = undefined;
|
|
23
|
+
|
|
24
|
+
if (DEV) {
|
|
25
|
+
if ("className" in $$restProps) {
|
|
26
|
+
console.warn(
|
|
27
|
+
`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg(
|
|
28
|
+
"classname-is-not-a-valid-prop",
|
|
29
|
+
)}.`,
|
|
30
|
+
field,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof field === "string") {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
|
|
37
|
+
"prismictext-works-only-with-rich-text-and-title-fields",
|
|
38
|
+
)}`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<!--
|
|
45
|
+
@component
|
|
46
|
+
Component to render a Prismic Rich Text or Title field as plain text.
|
|
47
|
+
|
|
48
|
+
@example Rendering a Rich Text field:
|
|
49
|
+
```svelte
|
|
50
|
+
<PrismicText field={document.data.example_rich_text} />
|
|
51
|
+
```
|
|
52
|
+
-->
|
|
53
|
+
|
|
54
|
+
{#if isFilled.richText(field)}
|
|
55
|
+
{asText(field, { separator })}
|
|
56
|
+
{:else if fallback !== undefined}
|
|
57
|
+
{fallback}
|
|
58
|
+
{/if}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import
|
|
2
|
+
import TodoComponent from "./TodoComponent.svelte";
|
|
3
3
|
|
|
4
|
-
import type * as
|
|
4
|
+
import type * as prismic from "@prismicio/client";
|
|
5
5
|
import type { SvelteComponent } from "svelte";
|
|
6
6
|
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
type SvelteSliceComponent = new (
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
...args: any[]
|
|
10
|
+
) => SvelteComponent<{
|
|
11
|
+
slice?: SliceLike;
|
|
12
|
+
slices?: SliceLike[];
|
|
13
|
+
context?: unknown;
|
|
14
|
+
index?: number;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
type SliceComponents = Record<string, SvelteSliceComponent>;
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* The minimum required properties to represent a Prismic Slice from the
|
|
@@ -19,7 +26,7 @@
|
|
|
19
26
|
* @typeParam SliceType - Type name of the Slice.
|
|
20
27
|
*/
|
|
21
28
|
type SliceLikeRestV2<SliceType extends string = string> = {
|
|
22
|
-
slice_type:
|
|
29
|
+
slice_type: prismic.Slice<SliceType>["slice_type"];
|
|
23
30
|
};
|
|
24
31
|
|
|
25
32
|
/**
|
|
@@ -29,7 +36,7 @@
|
|
|
29
36
|
* @typeParam SliceType - Type name of the Slice.
|
|
30
37
|
*/
|
|
31
38
|
type SliceLikeGraphQL<SliceType extends string = string> = {
|
|
32
|
-
type:
|
|
39
|
+
type: prismic.Slice<SliceType>["slice_type"];
|
|
33
40
|
};
|
|
34
41
|
|
|
35
42
|
/**
|
|
@@ -52,7 +59,7 @@
|
|
|
52
59
|
export let slices: SliceLike[] = [];
|
|
53
60
|
|
|
54
61
|
/**
|
|
55
|
-
* An object that maps Slice components to their corresponding API IDs
|
|
62
|
+
* An object that maps Slice components to their corresponding API IDs.
|
|
56
63
|
*
|
|
57
64
|
* @example An example map:
|
|
58
65
|
*
|
|
@@ -71,29 +78,30 @@
|
|
|
71
78
|
/**
|
|
72
79
|
* Arbitrary data passed to all Slice components as a `context` prop.
|
|
73
80
|
*/
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
82
|
export let context: any = {};
|
|
75
83
|
|
|
76
84
|
/**
|
|
77
85
|
* The Svelte component rendered if a component mapping from the `components`
|
|
78
86
|
* prop cannot be found.
|
|
79
87
|
*/
|
|
80
|
-
export let defaultComponent:
|
|
81
|
-
| SvelteComponent
|
|
82
|
-
| (new (...args: any[]) => SvelteComponent)
|
|
83
|
-
| undefined = undefined;
|
|
88
|
+
export let defaultComponent: SvelteSliceComponent | undefined = undefined;
|
|
84
89
|
</script>
|
|
85
90
|
|
|
86
91
|
<!--
|
|
87
92
|
@component
|
|
88
|
-
Component to render an array of Prismic
|
|
93
|
+
Component to render an array of Prismic slices.
|
|
89
94
|
|
|
90
|
-
@example Rendering a
|
|
95
|
+
@example Rendering a Slice Zone:
|
|
91
96
|
```svelte
|
|
92
|
-
<SliceZone
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
<SliceZone
|
|
98
|
+
slices={document.data.slices}
|
|
99
|
+
components={{
|
|
100
|
+
block_quote: BlockQuote,
|
|
101
|
+
hero_image: HeroImage
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
```
|
|
97
105
|
-->
|
|
98
106
|
|
|
99
107
|
{#each slices as slice, index}
|
|
@@ -102,6 +110,6 @@
|
|
|
102
110
|
{#if Component}
|
|
103
111
|
<svelte:component this={Component} {slice} {slices} {context} {index} />
|
|
104
112
|
{:else}
|
|
105
|
-
<
|
|
113
|
+
<TodoComponent {slice} />
|
|
106
114
|
{/if}
|
|
107
115
|
{/each}
|
|
@@ -4,3 +4,5 @@ export { default as PrismicLink } from "./PrismicLink.svelte";
|
|
|
4
4
|
export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
|
|
5
5
|
export { default as PrismicText } from "./PrismicText.svelte";
|
|
6
6
|
export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
|
|
7
|
+
|
|
8
|
+
export type { SvelteRichTextSerializer } from "./types";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { version } from "../../package.json";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* devMsg("missing-param");
|
|
10
|
+
* // => "https://prismic.dev/msg/svelte/v1.2.3/missing-param.md"
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
14
|
+
* the Git repository's `/messages` directory.
|
|
15
|
+
*
|
|
16
|
+
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
17
|
+
*/
|
|
18
|
+
export const devMsg = (slug: string): string => {
|
|
19
|
+
return `https://prismic.dev/msg/react/v${version}/${slug}`;
|
|
20
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RTAnyNode, RichTextNodeType } from "@prismicio/client";
|
|
2
|
+
import type { SvelteComponent } from "svelte";
|
|
3
|
+
|
|
4
|
+
export type SvelteRichTextSerializer = Partial<
|
|
5
|
+
Record<keyof typeof RichTextNodeType, SvelteRichTextComponent>
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
type SvelteRichTextComponent = new (
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
...args: any[]
|
|
11
|
+
) => SvelteComponent<
|
|
12
|
+
Partial<{
|
|
13
|
+
node: RTAnyNode;
|
|
14
|
+
}>
|
|
15
|
+
>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
slice: {
|
|
5
|
-
slice_type: string;
|
|
6
|
-
} | {
|
|
7
|
-
type: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
events: {
|
|
11
|
-
[evt: string]: CustomEvent<any>;
|
|
12
|
-
};
|
|
13
|
-
slots: {};
|
|
14
|
-
};
|
|
15
|
-
export type TodoSliceComponentProps = typeof __propDef.props;
|
|
16
|
-
export type TodoSliceComponentEvents = typeof __propDef.events;
|
|
17
|
-
export type TodoSliceComponentSlots = typeof __propDef.slots;
|
|
18
|
-
export default class TodoSliceComponent extends SvelteComponentTyped<TodoSliceComponentProps, TodoSliceComponentEvents, TodoSliceComponentSlots> {
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/dist/src/app.html
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<link rel="icon" href="/favicon.png" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
-
%sveltekit.head%
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="svelte">%sveltekit.body%</div>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
package/dist/src/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="@sveltejs/kit" />
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import * as prismicH from "@prismicio/helpers";
|
|
3
|
-
import type * as prismicT from "@prismicio/types";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An Embed field from Prismic.
|
|
7
|
-
*/
|
|
8
|
-
export let field: prismicT.EmbedField;
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<!--
|
|
12
|
-
@component
|
|
13
|
-
Component to render a Prismic Embed field.
|
|
14
|
-
|
|
15
|
-
@example Rendering an Embed field:
|
|
16
|
-
```svelte
|
|
17
|
-
<PrismicEmbed field={document.data.example_embed} />
|
|
18
|
-
```
|
|
19
|
-
-->
|
|
20
|
-
|
|
21
|
-
{#if prismicH.isFilled.embed(field)}
|
|
22
|
-
<div
|
|
23
|
-
data-oembed={field.embed_url}
|
|
24
|
-
data-oembed-type={field.type}
|
|
25
|
-
data-oembed-provider={field.provider_name}
|
|
26
|
-
>
|
|
27
|
-
{@html field.html}
|
|
28
|
-
</div>
|
|
29
|
-
{/if}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import * as prismicH from "@prismicio/helpers";
|
|
3
|
-
import type * as prismicT from "@prismicio/types";
|
|
4
|
-
import type { HTMLImgAttributes } from "svelte/elements";
|
|
5
|
-
import { DEV } from "esm-env";
|
|
6
|
-
|
|
7
|
-
type PrismicImageProps = {
|
|
8
|
-
/**
|
|
9
|
-
* A Prismic Image field.
|
|
10
|
-
*/
|
|
11
|
-
field: prismicT.ImageField;
|
|
12
|
-
/**
|
|
13
|
-
* An object of Imgix URL API parameters to transform the image.
|
|
14
|
-
*
|
|
15
|
-
* See: https://docs.imgix.com/apis/rendering
|
|
16
|
-
*/
|
|
17
|
-
imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
|
|
18
|
-
/**
|
|
19
|
-
* Widths used to build a `srcset` value for the Image field.
|
|
20
|
-
*
|
|
21
|
-
* If a `widths` prop is not given or `"defaults"` is passed, the following
|
|
22
|
-
* widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
23
|
-
*
|
|
24
|
-
* If the Image field contains responsive views, each responsive view can be
|
|
25
|
-
* used as a width in the resulting `srcset` by passing `"thumbnails"` as
|
|
26
|
-
* the `widths` prop.
|
|
27
|
-
*/
|
|
28
|
-
widths?:
|
|
29
|
-
| NonNullable<Parameters<typeof prismicH.asImageWidthSrcSet>[1]>["widths"]
|
|
30
|
-
| "defaults";
|
|
31
|
-
/**
|
|
32
|
-
* Pixel densities used to build a `srcset` value for the Image field.
|
|
33
|
-
*
|
|
34
|
-
* If a `pixelDensities` prop is passed `"defaults"`, the following pixel
|
|
35
|
-
* densities will be used: 1, 2, 3.
|
|
36
|
-
*/
|
|
37
|
-
pixelDensities?:
|
|
38
|
-
| NonNullable<
|
|
39
|
-
Parameters<typeof prismicH.asImagePixelDensitySrcSet>[1]
|
|
40
|
-
>["pixelDensities"]
|
|
41
|
-
| "defaults";
|
|
42
|
-
/**
|
|
43
|
-
* Declare an image as decorative by providing `alt=""`.
|
|
44
|
-
*
|
|
45
|
-
* See:
|
|
46
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
47
|
-
*/
|
|
48
|
-
alt?: "";
|
|
49
|
-
/**
|
|
50
|
-
* Declare an image as decorative only if the Image field does not have
|
|
51
|
-
* alternative text by providing `fallbackAlt=""`.
|
|
52
|
-
*
|
|
53
|
-
* See:
|
|
54
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
55
|
-
*/
|
|
56
|
-
fallbackAlt?: "";
|
|
57
|
-
/**
|
|
58
|
-
* PrismicImage will ignore any provided `src` property. The `src` property
|
|
59
|
-
* is generated based on the provided `field`.
|
|
60
|
-
*/
|
|
61
|
-
src?: undefined;
|
|
62
|
-
/**
|
|
63
|
-
* PrismicImage will ignore any provided `srcset` property. The `srcset`
|
|
64
|
-
* property is generated based on the provided `field`.
|
|
65
|
-
*/
|
|
66
|
-
srcset?: undefined;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
type $$Props = Omit<HTMLImgAttributes, "alt" | "src" | "srcset"> &
|
|
70
|
-
PrismicImageProps;
|
|
71
|
-
|
|
72
|
-
export let field: $$Props["field"];
|
|
73
|
-
|
|
74
|
-
export let imgixParams: $$Props["imgixParams"] = {};
|
|
75
|
-
|
|
76
|
-
export let widths: $$Props["widths"] = undefined;
|
|
77
|
-
|
|
78
|
-
export let pixelDensities: $$Props["pixelDensities"] = undefined;
|
|
79
|
-
|
|
80
|
-
export let width: $$Props["width"] = undefined;
|
|
81
|
-
|
|
82
|
-
export let height: $$Props["height"] = undefined;
|
|
83
|
-
|
|
84
|
-
export let alt: $$Props["alt"] = undefined;
|
|
85
|
-
|
|
86
|
-
export let fallbackAlt: $$Props["fallbackAlt"] = undefined;
|
|
87
|
-
|
|
88
|
-
delete $$restProps.src;
|
|
89
|
-
delete $$restProps.srcset;
|
|
90
|
-
|
|
91
|
-
const castInt = (
|
|
92
|
-
input: string | number | null | undefined,
|
|
93
|
-
): number | undefined | null => {
|
|
94
|
-
if (
|
|
95
|
-
typeof input === "number" ||
|
|
96
|
-
typeof input === "undefined" ||
|
|
97
|
-
input === null
|
|
98
|
-
) {
|
|
99
|
-
return input;
|
|
100
|
-
} else {
|
|
101
|
-
const parsed = Number.parseInt(input);
|
|
102
|
-
|
|
103
|
-
if (Number.isNaN(parsed)) {
|
|
104
|
-
return undefined;
|
|
105
|
-
} else {
|
|
106
|
-
return parsed;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const ar =
|
|
112
|
-
field.dimensions && field.dimensions.width / field.dimensions.height;
|
|
113
|
-
|
|
114
|
-
const castedWidth = castInt(width);
|
|
115
|
-
const castedHeight = castInt(height);
|
|
116
|
-
|
|
117
|
-
let resolvedWidth =
|
|
118
|
-
castedWidth ?? (field.dimensions && field.dimensions.width);
|
|
119
|
-
let resolvedHeight =
|
|
120
|
-
castedHeight ?? (field.dimensions && field.dimensions.height);
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
ar &&
|
|
124
|
-
castedWidth != null &&
|
|
125
|
-
(castedHeight == null || typeof castedWidth !== "undefined")
|
|
126
|
-
) {
|
|
127
|
-
resolvedHeight = castedWidth / ar;
|
|
128
|
-
} else if (
|
|
129
|
-
ar &&
|
|
130
|
-
castedHeight != null &&
|
|
131
|
-
(castedWidth == null || typeof castedWidth !== "undefined")
|
|
132
|
-
) {
|
|
133
|
-
resolvedWidth = castedHeight * ar;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (DEV) {
|
|
137
|
-
if (widths && pixelDensities) {
|
|
138
|
-
console.warn(
|
|
139
|
-
`[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.`,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (typeof alt === "string" && alt !== "") {
|
|
144
|
-
console.warn(
|
|
145
|
-
`[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="".`,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
150
|
-
console.warn(
|
|
151
|
-
`[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="".`,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
</script>
|
|
156
|
-
|
|
157
|
-
<!--
|
|
158
|
-
@component
|
|
159
|
-
Component to render a Prismic Image field as an `img` element with `width`, `height`, `alt`, `src`, and `srcset` attributes.
|
|
160
|
-
|
|
161
|
-
@example Rendering an Image field:
|
|
162
|
-
```svelte
|
|
163
|
-
<PrismicImage
|
|
164
|
-
field={document.data.example_image}
|
|
165
|
-
imgixParams={{ sat: -100 }}
|
|
166
|
-
/>
|
|
167
|
-
```
|
|
168
|
-
-->
|
|
169
|
-
|
|
170
|
-
{#if prismicH.isFilled.image(field)}
|
|
171
|
-
{@const { src, srcset } =
|
|
172
|
-
pixelDensities && !widths
|
|
173
|
-
? prismicH.asImagePixelDensitySrcSet(field, {
|
|
174
|
-
pixelDensities:
|
|
175
|
-
pixelDensities === "defaults" ? undefined : pixelDensities,
|
|
176
|
-
...imgixParams,
|
|
177
|
-
})
|
|
178
|
-
: prismicH.asImageWidthSrcSet(field, {
|
|
179
|
-
widths: widths === "defaults" ? undefined : widths,
|
|
180
|
-
...imgixParams,
|
|
181
|
-
})}
|
|
182
|
-
<img
|
|
183
|
-
{src}
|
|
184
|
-
{srcset}
|
|
185
|
-
alt={alt ?? field.alt ?? fallbackAlt}
|
|
186
|
-
width={width || height ? resolvedWidth : field.dimensions.width}
|
|
187
|
-
height={height || (width ? resolvedHeight : field.dimensions.height)}
|
|
188
|
-
{...$$restProps}
|
|
189
|
-
/>
|
|
190
|
-
{:else}
|
|
191
|
-
<img alt={field.alt || ""} {...$$restProps} />
|
|
192
|
-
{/if}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import * as prismicH from "@prismicio/helpers";
|
|
3
|
-
import type * as prismicT from "@prismicio/types";
|
|
4
|
-
import type { HTMLAnchorAttributes } from "svelte/elements";
|
|
5
|
-
// import { usePrismic } from "../usePrismic";
|
|
6
|
-
|
|
7
|
-
type PrismicLinkProps = {
|
|
8
|
-
/**
|
|
9
|
-
* A Prismic Link field, Content Relationship field, Link to Media field or
|
|
10
|
-
* Document.
|
|
11
|
-
*/
|
|
12
|
-
field: prismicT.LinkField | prismicT.PrismicDocument;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The Link Resolver used to resolve links.
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* If your app uses Route Resolvers when querying for your Prismic
|
|
19
|
-
* repository's content, a Link Resolver does not need to be provided.
|
|
20
|
-
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
21
|
-
*/
|
|
22
|
-
linkResolver?: prismicH.LinkResolverFunction | undefined;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* PrismicLink does not accept an `href` property. The `href` attribute is
|
|
26
|
-
* generated based on the field provided. If an `href` attribute is
|
|
27
|
-
* provided, it will be ignored.
|
|
28
|
-
*/
|
|
29
|
-
href?: undefined;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type $$Props = Omit<HTMLAnchorAttributes, "href"> & PrismicLinkProps;
|
|
33
|
-
|
|
34
|
-
export let field: $$Props["field"];
|
|
35
|
-
export let linkResolver: $$Props["linkResolver"] = undefined;
|
|
36
|
-
|
|
37
|
-
export let target: $$Props["target"] = undefined;
|
|
38
|
-
const resolvedTarget =
|
|
39
|
-
target || (field && "target" in field && field.target) || undefined;
|
|
40
|
-
|
|
41
|
-
export let rel: $$Props["rel"] = undefined;
|
|
42
|
-
const resolvedRel =
|
|
43
|
-
rel || (target === "_blank" ? "noopener noreferrer" : undefined);
|
|
44
|
-
|
|
45
|
-
const href = (field ? prismicH.asLink(field, linkResolver) : "") || "";
|
|
46
|
-
|
|
47
|
-
delete $$restProps.href;
|
|
48
|
-
</script>
|
|
49
|
-
|
|
50
|
-
<!--
|
|
51
|
-
@component
|
|
52
|
-
Component to render a Prismic Link, Link to Media, Content Relationship, or whole Document as an `a` tag.
|
|
53
|
-
|
|
54
|
-
@example Rendering a Link field:
|
|
55
|
-
```svelte
|
|
56
|
-
<PrismicLink field={document.data.example_link}>
|
|
57
|
-
Example anchor text.
|
|
58
|
-
</PrismicLink>
|
|
59
|
-
```
|
|
60
|
-
-->
|
|
61
|
-
|
|
62
|
-
<a {href} {...$$restProps} rel={resolvedRel} target={resolvedTarget}>
|
|
63
|
-
<slot />
|
|
64
|
-
</a>
|