@prismicio/svelte 2.0.0 → 2.1.0-canary.fa6f08e

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 CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
6
- [![Codecov][codecov-src]][codecov-href]
7
- [![Conventional Commits][conventional-commits-src]][conventional-commits-href]
8
- [![License][license-src]][license-href]
9
5
 
10
6
  [Svelte][svelte] components to present [Prismic][prismic] content.
11
7
 
@@ -93,11 +89,3 @@ limitations under the License.
93
89
  [npm-version-href]: https://npmjs.com/package/@prismicio/svelte
94
90
  [npm-downloads-src]: https://img.shields.io/npm/dm/@prismicio/svelte.svg
95
91
  [npm-downloads-href]: https://npmjs.com/package/@prismicio/svelte
96
- [github-actions-ci-src]: https://github.com/prismicio/prismic-svelte/workflows/ci/badge.svg
97
- [github-actions-ci-href]: https://github.com/prismicio/prismic-svelte/actions?query=workflow%3Aci
98
- [codecov-src]: https://img.shields.io/codecov/c/github/prismicio/prismic-svelte.svg
99
- [codecov-href]: https://codecov.io/gh/prismicio/prismic-svelte
100
- [conventional-commits-src]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white
101
- [conventional-commits-href]: https://conventionalcommits.org
102
- [license-src]: https://img.shields.io/npm/l/@prismicio/svelte.svg
103
- [license-href]: https://npmjs.com/package/@prismicio/svelte
@@ -1,57 +1,70 @@
1
1
  <script lang="ts">
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+
2
4
  import type { RichTextComponentProps } from "../types";
3
5
 
4
6
  import PrismicEmbed from "../PrismicEmbed.svelte";
5
7
  import PrismicImage from "../PrismicImage.svelte";
6
8
  import PrismicLink from "../PrismicLink.svelte";
7
9
 
8
- type Props = RichTextComponentProps;
10
+ type Props = RichTextComponentProps &
11
+ HTMLAttributes<HTMLElement> & { as?: string };
9
12
 
10
- const { node, children }: Props = $props();
13
+ const { node, children, as, ...attrs }: Props = $props();
11
14
 
12
15
  const dirProp = $derived(
13
16
  "direction" in node && node.direction === "rtl" ? { direction: "rtl" } : {},
14
17
  );
15
18
  </script>
16
19
 
17
- {#if node.type === "heading1"}
18
- <h1 {...dirProp}>{@render children()}</h1>
20
+ {#if as}
21
+ <svelte:element this={as} {...dirProp} {...attrs} {...attrs}
22
+ >{@render children()}</svelte:element
23
+ >
24
+ {:else if node.type === "heading1"}
25
+ <h1 {...dirProp} {...attrs}>{@render children()}</h1>
19
26
  {:else if node.type === "heading2"}
20
- <h2 {...dirProp}>{@render children()}</h2>
27
+ <h2 {...dirProp} {...attrs}>{@render children()}</h2>
21
28
  {:else if node.type === "heading3"}
22
- <h3 {...dirProp}>{@render children()}</h3>
29
+ <h3 {...dirProp} {...attrs}>{@render children()}</h3>
23
30
  {:else if node.type === "heading4"}
24
- <h4 {...dirProp}>{@render children()}</h4>
31
+ <h4 {...dirProp} {...attrs}>{@render children()}</h4>
25
32
  {:else if node.type === "heading5"}
26
- <h5 {...dirProp}>{@render children()}</h5>
33
+ <h5 {...dirProp} {...attrs}>{@render children()}</h5>
27
34
  {:else if node.type === "heading6"}
28
- <h6 {...dirProp}>{@render children()}</h6>
35
+ <h6 {...dirProp} {...attrs}>{@render children()}</h6>
29
36
  {:else if node.type === "paragraph"}
30
- <p {...dirProp}>{@render children()}</p>
37
+ <p {...dirProp} {...attrs}>{@render children()}</p>
31
38
  {:else if node.type === "preformatted"}
32
- <pre>{@render children()}</pre>
39
+ <pre {...attrs}>{@render children()}</pre>
33
40
  {:else if node.type === "strong"}
34
- <strong>{@render children()}</strong>
41
+ <strong {...attrs}>{@render children()}</strong>
35
42
  {:else if node.type === "em"}
36
- <em>{@render children()}</em>
43
+ <em {...attrs}>{@render children()}</em>
37
44
  {:else if node.type === "list-item"}
38
- <li {...dirProp}>{@render children()}</li>
45
+ <li {...dirProp} {...attrs}>{@render children()}</li>
39
46
  {:else if node.type === "o-list-item"}
40
- <li {...dirProp}>{@render children()}</li>
47
+ <li {...dirProp} {...attrs}>{@render children()}</li>
41
48
  {:else if node.type === "group-list-item"}
42
- <ul>{@render children()}</ul>
49
+ <ul {...attrs}>{@render children()}</ul>
43
50
  {:else if node.type === "group-o-list-item"}
44
- <ol>{@render children()}</ol>
51
+ <ol {...attrs}>{@render children()}</ol>
45
52
  {:else if node.type === "image"}
46
53
  <p class="block-img">
47
- <PrismicImage field={node} />
54
+ {#if node.linkTo}
55
+ <PrismicLink field={node.linkTo}>
56
+ <PrismicImage field={node} {...attrs} />
57
+ </PrismicLink>
58
+ {:else}
59
+ <PrismicImage field={node} {...attrs} />
60
+ {/if}
48
61
  </p>
49
62
  {:else if node.type === "embed"}
50
- <PrismicEmbed field={node.oembed} />
63
+ <PrismicEmbed field={node.oembed} {...attrs} />
51
64
  {:else if node.type === "hyperlink"}
52
- <PrismicLink field={node.data}>{@render children()}</PrismicLink>
65
+ <PrismicLink field={node.data} {...attrs}>{@render children()}</PrismicLink>
53
66
  {:else if node.type === "label"}
54
- <span class={node.data.label}>{@render children()}</span>
67
+ <span class={node.data.label} {...attrs}>{@render children()}</span>
55
68
  {:else}
56
69
  {#each node.text.split("\n") as line, index (index)}
57
70
  {#if index > 0}<br />{/if}{line}
@@ -1,5 +1,8 @@
1
+ import type { HTMLAttributes } from "svelte/elements";
1
2
  import type { RichTextComponentProps } from "../types";
2
- type Props = RichTextComponentProps;
3
+ type Props = RichTextComponentProps & HTMLAttributes<HTMLElement> & {
4
+ as?: string;
5
+ };
3
6
  declare const DefaultComponent: import("svelte").Component<Props, {}, "">;
4
7
  type DefaultComponent = ReturnType<typeof DefaultComponent>;
5
8
  export default DefaultComponent;
@@ -1,7 +1,11 @@
1
1
  <script lang="ts">
2
2
  import type { asTree } from "@prismicio/client/richtext";
3
3
 
4
- import type { RichTextComponent, RichTextComponents } from "../types";
4
+ import type {
5
+ ComponentShorthand,
6
+ RichTextComponent,
7
+ RichTextComponents,
8
+ } from "../types";
5
9
 
6
10
  import DefaultComponent from "./DefaultComponent.svelte";
7
11
  import Serialize from "./Serialize.svelte";
@@ -21,22 +25,27 @@
21
25
  } as const;
22
26
 
23
27
  function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
24
- return (
25
- (components[
26
- CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
27
- (child.type as keyof typeof components)
28
- ] as RichTextComponent) || DefaultComponent
29
- );
28
+ return components[
29
+ CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
30
+ (child.type as keyof typeof components)
31
+ ] as RichTextComponent | ComponentShorthand;
30
32
  }
31
33
  </script>
32
34
 
33
35
  {#each children as child (child.key)}
34
36
  {@const Component = getComponent(child)}
35
- <Component node={child.node}>
37
+ {#snippet serializedChildren()}
36
38
  <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
37
39
  {#if child.children.length > 0}<Serialize
38
40
  children={child.children}
39
41
  {components}
40
- />{/if}</Component
41
- >
42
+ />{/if}
43
+ {/snippet}
44
+ {#if typeof Component === "function"}
45
+ <Component node={child.node}>{@render serializedChildren()}</Component>
46
+ {:else}
47
+ <DefaultComponent {...Component} node={child.node}
48
+ >{@render serializedChildren()}</DefaultComponent
49
+ >
50
+ {/if}
42
51
  {/each}
@@ -0,0 +1,103 @@
1
+ <script lang="ts">
2
+ import {
3
+ type TableField,
4
+ TableFieldBody,
5
+ TableFieldBodyRow,
6
+ TableFieldDataCell,
7
+ TableFieldHead,
8
+ TableFieldHeadRow,
9
+ TableFieldHeaderCell,
10
+ isFilled,
11
+ } from "@prismicio/client";
12
+ import { type Component } from "svelte";
13
+
14
+ import { type RichTextComponents, type TableComponents } from "./types";
15
+
16
+ import PrismicRichText from "./PrismicRichText/PrismicRichText.svelte";
17
+
18
+ type Props = {
19
+ /**
20
+ * The Prismic table field to render.
21
+ */
22
+ field: TableField;
23
+
24
+ /**
25
+ * An object that maps a rich text block type to a Svelte component.
26
+ */
27
+ components?: TableComponents & RichTextComponents;
28
+
29
+ /**
30
+ * The component rendered when the field is empty. If a fallback is not
31
+ * given, `null` will be rendered.
32
+ */
33
+ fallback?: Component;
34
+ };
35
+
36
+ const { field, components = {}, fallback: Fallback }: Props = $props();
37
+
38
+ const Table = components.table;
39
+ const Thead = components.thead;
40
+ const Tbody = components.tbody;
41
+ const Tr = components.tr;
42
+ const Th = components.th;
43
+ const Td = components.td;
44
+ </script>
45
+
46
+ {#snippet thead(head: TableFieldHead)}
47
+ {#if typeof Thead === "function"}<Thead {head}
48
+ >{#each head.rows as row (row.key)}{@render tr(row)}{/each}</Thead
49
+ >{:else}<thead {...Thead}
50
+ >{#each head.rows as row (row.key)}{@render tr(row)}{/each}</thead
51
+ >{/if}
52
+ {/snippet}
53
+
54
+ {#snippet tbody(body: TableFieldBody)}
55
+ {#if typeof Tbody === "function"}<Tbody {body}
56
+ >{#each body.rows as row (row.key)}{@render tr(row)}{/each}</Tbody
57
+ >{:else}<tbody {...Tbody}
58
+ >{#each body.rows as row (row.key)}{@render tr(row)}{/each}</tbody
59
+ >{/if}
60
+ {/snippet}
61
+
62
+ {#snippet tr(row: TableFieldHeadRow | TableFieldBodyRow)}
63
+ {#if typeof Tr === "function"}<Tr {row}
64
+ >{#each row.cells as cell (cell.key)}{#if cell.type === "header"}{@render th(
65
+ cell,
66
+ )}{:else}{@render td(cell)}{/if}{/each}</Tr
67
+ >{:else}<tr {...Tr}
68
+ >{#each row.cells as cell (cell.key)}{#if cell.type === "header"}{@render th(
69
+ cell,
70
+ )}{:else}{@render td(cell)}{/if}{/each}</tr
71
+ >{/if}
72
+ {/snippet}
73
+
74
+ {#snippet th(cell: TableFieldHeaderCell)}
75
+ {#if typeof Th === "function"}<Th {cell}
76
+ ><PrismicRichText field={cell.content} {components} /></Th
77
+ >{:else}<th {...Th}
78
+ ><PrismicRichText field={cell.content} {components} /></th
79
+ >{/if}
80
+ {/snippet}
81
+
82
+ {#snippet td(cell: TableFieldDataCell)}
83
+ {#if typeof Td === "function"}<Td {cell}
84
+ ><PrismicRichText field={cell.content} {components} /></Td
85
+ >{:else}<td {...Td}
86
+ ><PrismicRichText field={cell.content} {components} /></td
87
+ >{/if}
88
+ {/snippet}
89
+
90
+ <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
91
+ {#if isFilled.table(field)}
92
+ {#if typeof Table === "function"}<Table table={field}
93
+ >{#if field?.head}{@render thead(field.head)}{/if}{@render tbody(
94
+ field.body,
95
+ )}</Table
96
+ >{:else}<table {...Table}>
97
+ {#if field?.head}{@render thead(field.head)}{/if}{@render tbody(
98
+ field.body,
99
+ )}
100
+ </table>{/if}
101
+ {:else if Fallback}
102
+ <Fallback />
103
+ {/if}
@@ -1,6 +1,6 @@
1
1
  import { type TableField } from "@prismicio/client";
2
2
  import { type Component } from "svelte";
3
- import type { RichTextComponents, TableComponents } from "../types";
3
+ import { type RichTextComponents, type TableComponents } from "./types";
4
4
  type Props = {
5
5
  /**
6
6
  * The Prismic table field to render.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { RichTextComponents } from "./types";
1
+ import type { RichTextComponents } from "./types";
2
2
  export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
3
3
  export { default as PrismicImage } from "./PrismicImage.svelte";
4
4
  export { default as PrismicLink } from "./PrismicLink.svelte";
5
5
  export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
6
- export { default as PrismicTable } from "./PrismicTable/PrismicTable.svelte";
6
+ export { default as PrismicTable } from "./PrismicTable.svelte";
7
7
  export { default as PrismicText } from "./PrismicText.svelte";
8
8
  export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
9
9
  /**
package/dist/index.js CHANGED
@@ -2,6 +2,6 @@ export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
2
2
  export { default as PrismicImage } from "./PrismicImage.svelte";
3
3
  export { default as PrismicLink } from "./PrismicLink.svelte";
4
4
  export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
5
- export { default as PrismicTable } from "./PrismicTable/PrismicTable.svelte";
5
+ export { default as PrismicTable } from "./PrismicTable.svelte";
6
6
  export { default as PrismicText } from "./PrismicText.svelte";
7
7
  export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
@@ -1,5 +1,5 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import { Cookies } from "@sveltejs/kit";
2
+ import type { Cookies } from "@sveltejs/kit";
3
3
  /**
4
4
  * Configuration for `enableAutoPreviews`.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import { Cookies } from "@sveltejs/kit";
2
+ import type { Cookies } from "@sveltejs/kit";
3
3
  export type RedirectToPreviewURLConfig = {
4
4
  /**
5
5
  * The Prismic client configured for the preview session's repository.
@@ -1,5 +1,5 @@
1
- import { ClientConfig } from "@prismicio/client";
2
- import { Cookies } from "@sveltejs/kit";
1
+ import type { ClientConfig } from "@prismicio/client";
2
+ import type { Cookies } from "@sveltejs/kit";
3
3
  /**
4
4
  * Configuration for creating a Prismic client with automatic preview support in
5
5
  * SvelteKit apps.
package/dist/types.d.ts CHANGED
@@ -1,24 +1,34 @@
1
1
  import type { RTAnyNode, RTEmNode, RTEmbedNode, RTHeading1Node, RTHeading2Node, RTHeading3Node, RTHeading4Node, RTHeading5Node, RTHeading6Node, RTImageNode, RTLabelNode, RTLinkNode, RTListItemNode, RTListNode, RTOListItemNode, RTOListNode, RTParagraphNode, RTPreformattedNode, RTSpanNode, RTStrongNode, Slice, TableField, TableFieldBody, TableFieldBodyRow, TableFieldDataCell, TableFieldHead, TableFieldHeadRow, TableFieldHeaderCell } from "@prismicio/client";
2
2
  import type { Component, Snippet } from "svelte";
3
+ import type { HTMLAttributes } from "svelte/elements";
4
+ /**
5
+ * A shorthand definition for `<PrismicRichText />` component types.
6
+ */
7
+ export type ComponentShorthand = {
8
+ /**
9
+ * The HTML element type rendered for this node type.
10
+ */
11
+ as?: string;
12
+ } & HTMLAttributes<HTMLElement>;
3
13
  export type RichTextComponents = {
4
- heading1?: RichTextComponent<RTHeading1Node>;
5
- heading2?: RichTextComponent<RTHeading2Node>;
6
- heading3?: RichTextComponent<RTHeading3Node>;
7
- heading4?: RichTextComponent<RTHeading4Node>;
8
- heading5?: RichTextComponent<RTHeading5Node>;
9
- heading6?: RichTextComponent<RTHeading6Node>;
10
- paragraph?: RichTextComponent<RTParagraphNode>;
11
- preformatted?: RichTextComponent<RTPreformattedNode>;
12
- strong?: RichTextComponent<RTStrongNode>;
13
- em?: RichTextComponent<RTEmNode>;
14
- listItem?: RichTextComponent<RTListItemNode>;
15
- oListItem?: RichTextComponent<RTOListItemNode>;
16
- list?: RichTextComponent<RTListNode>;
17
- oList?: RichTextComponent<RTOListNode>;
18
- image?: RichTextComponent<RTImageNode>;
19
- embed?: RichTextComponent<RTEmbedNode>;
20
- hyperlink?: RichTextComponent<RTLinkNode>;
21
- label?: RichTextComponent<RTLabelNode>;
14
+ heading1?: RichTextComponent<RTHeading1Node> | ComponentShorthand;
15
+ heading2?: RichTextComponent<RTHeading2Node> | ComponentShorthand;
16
+ heading3?: RichTextComponent<RTHeading3Node> | ComponentShorthand;
17
+ heading4?: RichTextComponent<RTHeading4Node> | ComponentShorthand;
18
+ heading5?: RichTextComponent<RTHeading5Node> | ComponentShorthand;
19
+ heading6?: RichTextComponent<RTHeading6Node> | ComponentShorthand;
20
+ paragraph?: RichTextComponent<RTParagraphNode> | ComponentShorthand;
21
+ preformatted?: RichTextComponent<RTPreformattedNode> | ComponentShorthand;
22
+ strong?: RichTextComponent<RTStrongNode> | ComponentShorthand;
23
+ em?: RichTextComponent<RTEmNode> | ComponentShorthand;
24
+ listItem?: RichTextComponent<RTListItemNode> | ComponentShorthand;
25
+ oListItem?: RichTextComponent<RTOListItemNode> | ComponentShorthand;
26
+ list?: RichTextComponent<RTListNode> | ComponentShorthand;
27
+ oList?: RichTextComponent<RTOListNode> | ComponentShorthand;
28
+ image?: RichTextComponent<RTImageNode> | HTMLAttributes<HTMLImageElement>;
29
+ embed?: RichTextComponent<RTEmbedNode> | HTMLAttributes<HTMLDivElement>;
30
+ hyperlink?: RichTextComponent<RTLinkNode> | HTMLAttributes<HTMLAnchorElement>;
31
+ label?: RichTextComponent<RTLabelNode> | HTMLAttributes<HTMLSpanElement>;
22
32
  span?: RichTextComponent<RTSpanNode>;
23
33
  };
24
34
  export type RichTextComponent<TNode extends RTAnyNode = RTAnyNode> = Component<RichTextComponentProps<TNode>>;
@@ -30,27 +40,27 @@ export type TableComponents = {
30
40
  table?: Component<{
31
41
  table: TableField<"filled">;
32
42
  children: Snippet;
33
- }>;
43
+ }> | HTMLAttributes<HTMLTableElement>;
34
44
  thead?: Component<{
35
45
  head: TableFieldHead;
36
46
  children: Snippet;
37
- }>;
47
+ }> | HTMLAttributes<HTMLTableSectionElement>;
38
48
  tbody?: Component<{
39
49
  body: TableFieldBody;
40
50
  children: Snippet;
41
- }>;
51
+ }> | HTMLAttributes<HTMLTableSectionElement>;
42
52
  tr?: Component<{
43
53
  row: TableFieldHeadRow | TableFieldBodyRow;
44
54
  children: Snippet;
45
- }>;
55
+ }> | HTMLAttributes<HTMLTableRowElement>;
46
56
  th?: Component<{
47
57
  cell: TableFieldHeaderCell;
48
58
  children: Snippet;
49
- }>;
59
+ }> | HTMLAttributes<HTMLTableCellElement>;
50
60
  td?: Component<{
51
61
  cell: TableFieldDataCell;
52
62
  children: Snippet;
53
- }>;
63
+ }> | HTMLAttributes<HTMLTableCellElement>;
54
64
  };
55
65
  /**
56
66
  * Props for a component rendering content from a Prismic Slice using the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/svelte",
3
- "version": "2.0.0",
3
+ "version": "2.1.0-canary.fa6f08e",
4
4
  "description": "Svelte components to present Prismic content.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -47,51 +47,36 @@
47
47
  "build": "svelte-package --input ./src",
48
48
  "dev": "svelte-package --input ./src --watch",
49
49
  "format": "prettier --write --plugin prettier-plugin-svelte .",
50
- "lint": "eslint",
51
50
  "prepare": "npm run build",
52
- "release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
53
- "release:alpha": "npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
54
- "release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run",
55
- "release:dry": "standard-version --release-as patch --dry-run",
56
- "size": "size-limit",
57
- "test": "npm run lint && npm run types && npm run unit && npm run build && npm run size",
51
+ "lint": "oxlint --deny-warnings",
58
52
  "types": "tsc --noEmit",
59
- "types:watch": "vitest watch --typecheck.only",
60
53
  "unit": "vitest run --coverage",
61
- "unit:watch": "vitest watch"
54
+ "unit:watch": "vitest watch",
55
+ "test": "npm run lint && npm run types && npm run unit && npm run build"
62
56
  },
63
57
  "dependencies": {
64
58
  "esm-env": "^1.2.2"
65
59
  },
66
60
  "devDependencies": {
67
- "@eslint/compat": "^1.2.9",
68
- "@eslint/js": "^9.27.0",
69
- "@prismicio/client": "^7.17.2",
61
+ "@prismicio/client": "^7.21.0",
70
62
  "@prismicio/mock": "^0.7.1",
71
- "@size-limit/preset-small-lib": "^11.2.0",
72
- "@sveltejs/kit": "^2.21.0",
73
- "@sveltejs/package": "^2.3.11",
74
- "@sveltejs/vite-plugin-svelte": "^5.0.3",
75
- "@testing-library/svelte": "^5.2.7",
76
- "@trivago/prettier-plugin-sort-imports": "^5.2.2",
77
- "@types/node": "^22.15.18",
78
- "@vitest/coverage-v8": "^3.1.3",
79
- "eslint": "^9.27.0",
80
- "eslint-config-prettier": "^10.1.5",
81
- "eslint-plugin-prettier": "^5.4.0",
82
- "eslint-plugin-svelte": "^3.7.0",
83
- "eslint-plugin-tsdoc": "^0.4.0",
84
- "globals": "^16.1.0",
85
- "happy-dom": "^17.4.7",
86
- "prettier": "^3.5.3",
87
- "prettier-plugin-jsdoc": "^1.3.2",
88
- "prettier-plugin-svelte": "^3.4.0",
89
- "size-limit": "^11.2.0",
63
+ "@sveltejs/kit": "^2.49.2",
64
+ "@sveltejs/package": "^2.5.7",
65
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
66
+ "@testing-library/svelte": "^5.2.9",
67
+ "@trivago/prettier-plugin-sort-imports": "^6.0.0",
68
+ "@types/node": "^25.0.3",
69
+ "@vitest/coverage-v8": "^4.0.16",
70
+ "globals": "^16.5.0",
71
+ "happy-dom": "^20.0.11",
72
+ "oxlint": "^1.33.0",
73
+ "prettier": "^3.7.4",
74
+ "prettier-plugin-jsdoc": "^1.8.0",
75
+ "prettier-plugin-svelte": "^3.4.1",
90
76
  "standard-version": "^9.5.0",
91
- "svelte": "^5.30.1",
92
- "typescript": "^5.8.3",
93
- "typescript-eslint": "^8.32.1",
94
- "vitest": "^3.1.3"
77
+ "svelte": "^5.46.0",
78
+ "typescript": "^5.9.3",
79
+ "vitest": "^4.0.16"
95
80
  },
96
81
  "peerDependencies": {
97
82
  "@prismicio/client": ">=7",
@@ -1,57 +1,70 @@
1
1
  <script lang="ts">
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+
2
4
  import type { RichTextComponentProps } from "../types";
3
5
 
4
6
  import PrismicEmbed from "../PrismicEmbed.svelte";
5
7
  import PrismicImage from "../PrismicImage.svelte";
6
8
  import PrismicLink from "../PrismicLink.svelte";
7
9
 
8
- type Props = RichTextComponentProps;
10
+ type Props = RichTextComponentProps &
11
+ HTMLAttributes<HTMLElement> & { as?: string };
9
12
 
10
- const { node, children }: Props = $props();
13
+ const { node, children, as, ...attrs }: Props = $props();
11
14
 
12
15
  const dirProp = $derived(
13
16
  "direction" in node && node.direction === "rtl" ? { direction: "rtl" } : {},
14
17
  );
15
18
  </script>
16
19
 
17
- {#if node.type === "heading1"}
18
- <h1 {...dirProp}>{@render children()}</h1>
20
+ {#if as}
21
+ <svelte:element this={as} {...dirProp} {...attrs} {...attrs}
22
+ >{@render children()}</svelte:element
23
+ >
24
+ {:else if node.type === "heading1"}
25
+ <h1 {...dirProp} {...attrs}>{@render children()}</h1>
19
26
  {:else if node.type === "heading2"}
20
- <h2 {...dirProp}>{@render children()}</h2>
27
+ <h2 {...dirProp} {...attrs}>{@render children()}</h2>
21
28
  {:else if node.type === "heading3"}
22
- <h3 {...dirProp}>{@render children()}</h3>
29
+ <h3 {...dirProp} {...attrs}>{@render children()}</h3>
23
30
  {:else if node.type === "heading4"}
24
- <h4 {...dirProp}>{@render children()}</h4>
31
+ <h4 {...dirProp} {...attrs}>{@render children()}</h4>
25
32
  {:else if node.type === "heading5"}
26
- <h5 {...dirProp}>{@render children()}</h5>
33
+ <h5 {...dirProp} {...attrs}>{@render children()}</h5>
27
34
  {:else if node.type === "heading6"}
28
- <h6 {...dirProp}>{@render children()}</h6>
35
+ <h6 {...dirProp} {...attrs}>{@render children()}</h6>
29
36
  {:else if node.type === "paragraph"}
30
- <p {...dirProp}>{@render children()}</p>
37
+ <p {...dirProp} {...attrs}>{@render children()}</p>
31
38
  {:else if node.type === "preformatted"}
32
- <pre>{@render children()}</pre>
39
+ <pre {...attrs}>{@render children()}</pre>
33
40
  {:else if node.type === "strong"}
34
- <strong>{@render children()}</strong>
41
+ <strong {...attrs}>{@render children()}</strong>
35
42
  {:else if node.type === "em"}
36
- <em>{@render children()}</em>
43
+ <em {...attrs}>{@render children()}</em>
37
44
  {:else if node.type === "list-item"}
38
- <li {...dirProp}>{@render children()}</li>
45
+ <li {...dirProp} {...attrs}>{@render children()}</li>
39
46
  {:else if node.type === "o-list-item"}
40
- <li {...dirProp}>{@render children()}</li>
47
+ <li {...dirProp} {...attrs}>{@render children()}</li>
41
48
  {:else if node.type === "group-list-item"}
42
- <ul>{@render children()}</ul>
49
+ <ul {...attrs}>{@render children()}</ul>
43
50
  {:else if node.type === "group-o-list-item"}
44
- <ol>{@render children()}</ol>
51
+ <ol {...attrs}>{@render children()}</ol>
45
52
  {:else if node.type === "image"}
46
53
  <p class="block-img">
47
- <PrismicImage field={node} />
54
+ {#if node.linkTo}
55
+ <PrismicLink field={node.linkTo}>
56
+ <PrismicImage field={node} {...attrs} />
57
+ </PrismicLink>
58
+ {:else}
59
+ <PrismicImage field={node} {...attrs} />
60
+ {/if}
48
61
  </p>
49
62
  {:else if node.type === "embed"}
50
- <PrismicEmbed field={node.oembed} />
63
+ <PrismicEmbed field={node.oembed} {...attrs} />
51
64
  {:else if node.type === "hyperlink"}
52
- <PrismicLink field={node.data}>{@render children()}</PrismicLink>
65
+ <PrismicLink field={node.data} {...attrs}>{@render children()}</PrismicLink>
53
66
  {:else if node.type === "label"}
54
- <span class={node.data.label}>{@render children()}</span>
67
+ <span class={node.data.label} {...attrs}>{@render children()}</span>
55
68
  {:else}
56
69
  {#each node.text.split("\n") as line, index (index)}
57
70
  {#if index > 0}<br />{/if}{line}
@@ -1,7 +1,11 @@
1
1
  <script lang="ts">
2
2
  import type { asTree } from "@prismicio/client/richtext";
3
3
 
4
- import type { RichTextComponent, RichTextComponents } from "../types";
4
+ import type {
5
+ ComponentShorthand,
6
+ RichTextComponent,
7
+ RichTextComponents,
8
+ } from "../types";
5
9
 
6
10
  import DefaultComponent from "./DefaultComponent.svelte";
7
11
  import Serialize from "./Serialize.svelte";
@@ -21,22 +25,27 @@
21
25
  } as const;
22
26
 
23
27
  function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
24
- return (
25
- (components[
26
- CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
27
- (child.type as keyof typeof components)
28
- ] as RichTextComponent) || DefaultComponent
29
- );
28
+ return components[
29
+ CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
30
+ (child.type as keyof typeof components)
31
+ ] as RichTextComponent | ComponentShorthand;
30
32
  }
31
33
  </script>
32
34
 
33
35
  {#each children as child (child.key)}
34
36
  {@const Component = getComponent(child)}
35
- <Component node={child.node}>
37
+ {#snippet serializedChildren()}
36
38
  <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
37
39
  {#if child.children.length > 0}<Serialize
38
40
  children={child.children}
39
41
  {components}
40
- />{/if}</Component
41
- >
42
+ />{/if}
43
+ {/snippet}
44
+ {#if typeof Component === "function"}
45
+ <Component node={child.node}>{@render serializedChildren()}</Component>
46
+ {:else}
47
+ <DefaultComponent {...Component} node={child.node}
48
+ >{@render serializedChildren()}</DefaultComponent
49
+ >
50
+ {/if}
42
51
  {/each}
@@ -0,0 +1,103 @@
1
+ <script lang="ts">
2
+ import {
3
+ type TableField,
4
+ TableFieldBody,
5
+ TableFieldBodyRow,
6
+ TableFieldDataCell,
7
+ TableFieldHead,
8
+ TableFieldHeadRow,
9
+ TableFieldHeaderCell,
10
+ isFilled,
11
+ } from "@prismicio/client";
12
+ import { type Component } from "svelte";
13
+
14
+ import { type RichTextComponents, type TableComponents } from "./types";
15
+
16
+ import PrismicRichText from "./PrismicRichText/PrismicRichText.svelte";
17
+
18
+ type Props = {
19
+ /**
20
+ * The Prismic table field to render.
21
+ */
22
+ field: TableField;
23
+
24
+ /**
25
+ * An object that maps a rich text block type to a Svelte component.
26
+ */
27
+ components?: TableComponents & RichTextComponents;
28
+
29
+ /**
30
+ * The component rendered when the field is empty. If a fallback is not
31
+ * given, `null` will be rendered.
32
+ */
33
+ fallback?: Component;
34
+ };
35
+
36
+ const { field, components = {}, fallback: Fallback }: Props = $props();
37
+
38
+ const Table = components.table;
39
+ const Thead = components.thead;
40
+ const Tbody = components.tbody;
41
+ const Tr = components.tr;
42
+ const Th = components.th;
43
+ const Td = components.td;
44
+ </script>
45
+
46
+ {#snippet thead(head: TableFieldHead)}
47
+ {#if typeof Thead === "function"}<Thead {head}
48
+ >{#each head.rows as row (row.key)}{@render tr(row)}{/each}</Thead
49
+ >{:else}<thead {...Thead}
50
+ >{#each head.rows as row (row.key)}{@render tr(row)}{/each}</thead
51
+ >{/if}
52
+ {/snippet}
53
+
54
+ {#snippet tbody(body: TableFieldBody)}
55
+ {#if typeof Tbody === "function"}<Tbody {body}
56
+ >{#each body.rows as row (row.key)}{@render tr(row)}{/each}</Tbody
57
+ >{:else}<tbody {...Tbody}
58
+ >{#each body.rows as row (row.key)}{@render tr(row)}{/each}</tbody
59
+ >{/if}
60
+ {/snippet}
61
+
62
+ {#snippet tr(row: TableFieldHeadRow | TableFieldBodyRow)}
63
+ {#if typeof Tr === "function"}<Tr {row}
64
+ >{#each row.cells as cell (cell.key)}{#if cell.type === "header"}{@render th(
65
+ cell,
66
+ )}{:else}{@render td(cell)}{/if}{/each}</Tr
67
+ >{:else}<tr {...Tr}
68
+ >{#each row.cells as cell (cell.key)}{#if cell.type === "header"}{@render th(
69
+ cell,
70
+ )}{:else}{@render td(cell)}{/if}{/each}</tr
71
+ >{/if}
72
+ {/snippet}
73
+
74
+ {#snippet th(cell: TableFieldHeaderCell)}
75
+ {#if typeof Th === "function"}<Th {cell}
76
+ ><PrismicRichText field={cell.content} {components} /></Th
77
+ >{:else}<th {...Th}
78
+ ><PrismicRichText field={cell.content} {components} /></th
79
+ >{/if}
80
+ {/snippet}
81
+
82
+ {#snippet td(cell: TableFieldDataCell)}
83
+ {#if typeof Td === "function"}<Td {cell}
84
+ ><PrismicRichText field={cell.content} {components} /></Td
85
+ >{:else}<td {...Td}
86
+ ><PrismicRichText field={cell.content} {components} /></td
87
+ >{/if}
88
+ {/snippet}
89
+
90
+ <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
91
+ {#if isFilled.table(field)}
92
+ {#if typeof Table === "function"}<Table table={field}
93
+ >{#if field?.head}{@render thead(field.head)}{/if}{@render tbody(
94
+ field.body,
95
+ )}</Table
96
+ >{:else}<table {...Table}>
97
+ {#if field?.head}{@render thead(field.head)}{/if}{@render tbody(
98
+ field.body,
99
+ )}
100
+ </table>{/if}
101
+ {:else if Fallback}
102
+ <Fallback />
103
+ {/if}
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { RichTextComponents } from "./types";
1
+ import type { RichTextComponents } from "./types";
2
2
 
3
3
  export { default as PrismicEmbed } from "./PrismicEmbed.svelte";
4
4
  export { default as PrismicImage } from "./PrismicImage.svelte";
5
5
  export { default as PrismicLink } from "./PrismicLink.svelte";
6
6
  export { default as PrismicRichText } from "./PrismicRichText/PrismicRichText.svelte";
7
- export { default as PrismicTable } from "./PrismicTable/PrismicTable.svelte";
7
+ export { default as PrismicTable } from "./PrismicTable.svelte";
8
8
  export { default as PrismicText } from "./PrismicText.svelte";
9
9
  export { default as SliceZone } from "./SliceZone/SliceZone.svelte";
10
10
 
@@ -1,5 +1,5 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import { Cookies } from "@sveltejs/kit";
2
+ import type { Cookies } from "@sveltejs/kit";
3
3
 
4
4
  /**
5
5
  * Configuration for `enableAutoPreviews`.
@@ -1,5 +1,5 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import { Cookies } from "@sveltejs/kit";
2
+ import type { Cookies } from "@sveltejs/kit";
3
3
 
4
4
  export type RedirectToPreviewURLConfig = {
5
5
  /**
package/src/kit/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ClientConfig } from "@prismicio/client";
2
- import { Cookies } from "@sveltejs/kit";
1
+ import type { ClientConfig } from "@prismicio/client";
2
+ import type { Cookies } from "@sveltejs/kit";
3
3
 
4
4
  /**
5
5
  * Configuration for creating a Prismic client with automatic preview support in
package/src/types.ts CHANGED
@@ -29,26 +29,37 @@ import type {
29
29
  TableFieldHeaderCell,
30
30
  } from "@prismicio/client";
31
31
  import type { Component, Snippet } from "svelte";
32
+ import type { HTMLAttributes } from "svelte/elements";
33
+
34
+ /**
35
+ * A shorthand definition for `<PrismicRichText />` component types.
36
+ */
37
+ export type ComponentShorthand = {
38
+ /**
39
+ * The HTML element type rendered for this node type.
40
+ */
41
+ as?: string;
42
+ } & HTMLAttributes<HTMLElement>;
32
43
 
33
44
  export type RichTextComponents = {
34
- heading1?: RichTextComponent<RTHeading1Node>;
35
- heading2?: RichTextComponent<RTHeading2Node>;
36
- heading3?: RichTextComponent<RTHeading3Node>;
37
- heading4?: RichTextComponent<RTHeading4Node>;
38
- heading5?: RichTextComponent<RTHeading5Node>;
39
- heading6?: RichTextComponent<RTHeading6Node>;
40
- paragraph?: RichTextComponent<RTParagraphNode>;
41
- preformatted?: RichTextComponent<RTPreformattedNode>;
42
- strong?: RichTextComponent<RTStrongNode>;
43
- em?: RichTextComponent<RTEmNode>;
44
- listItem?: RichTextComponent<RTListItemNode>;
45
- oListItem?: RichTextComponent<RTOListItemNode>;
46
- list?: RichTextComponent<RTListNode>;
47
- oList?: RichTextComponent<RTOListNode>;
48
- image?: RichTextComponent<RTImageNode>;
49
- embed?: RichTextComponent<RTEmbedNode>;
50
- hyperlink?: RichTextComponent<RTLinkNode>;
51
- label?: RichTextComponent<RTLabelNode>;
45
+ heading1?: RichTextComponent<RTHeading1Node> | ComponentShorthand;
46
+ heading2?: RichTextComponent<RTHeading2Node> | ComponentShorthand;
47
+ heading3?: RichTextComponent<RTHeading3Node> | ComponentShorthand;
48
+ heading4?: RichTextComponent<RTHeading4Node> | ComponentShorthand;
49
+ heading5?: RichTextComponent<RTHeading5Node> | ComponentShorthand;
50
+ heading6?: RichTextComponent<RTHeading6Node> | ComponentShorthand;
51
+ paragraph?: RichTextComponent<RTParagraphNode> | ComponentShorthand;
52
+ preformatted?: RichTextComponent<RTPreformattedNode> | ComponentShorthand;
53
+ strong?: RichTextComponent<RTStrongNode> | ComponentShorthand;
54
+ em?: RichTextComponent<RTEmNode> | ComponentShorthand;
55
+ listItem?: RichTextComponent<RTListItemNode> | ComponentShorthand;
56
+ oListItem?: RichTextComponent<RTOListItemNode> | ComponentShorthand;
57
+ list?: RichTextComponent<RTListNode> | ComponentShorthand;
58
+ oList?: RichTextComponent<RTOListNode> | ComponentShorthand;
59
+ image?: RichTextComponent<RTImageNode> | HTMLAttributes<HTMLImageElement>;
60
+ embed?: RichTextComponent<RTEmbedNode> | HTMLAttributes<HTMLDivElement>;
61
+ hyperlink?: RichTextComponent<RTLinkNode> | HTMLAttributes<HTMLAnchorElement>;
62
+ label?: RichTextComponent<RTLabelNode> | HTMLAttributes<HTMLSpanElement>;
52
63
  span?: RichTextComponent<RTSpanNode>;
53
64
  };
54
65
 
@@ -63,30 +74,42 @@ export type RichTextComponentProps<TNode extends RTAnyNode = RTAnyNode> = {
63
74
 
64
75
  // Define the type for the components prop
65
76
  export type TableComponents = {
66
- table?: Component<{
67
- table: TableField<"filled">;
68
- children: Snippet;
69
- }>;
70
- thead?: Component<{
71
- head: TableFieldHead;
72
- children: Snippet;
73
- }>;
74
- tbody?: Component<{
75
- body: TableFieldBody;
76
- children: Snippet;
77
- }>;
78
- tr?: Component<{
79
- row: TableFieldHeadRow | TableFieldBodyRow;
80
- children: Snippet;
81
- }>;
82
- th?: Component<{
83
- cell: TableFieldHeaderCell;
84
- children: Snippet;
85
- }>;
86
- td?: Component<{
87
- cell: TableFieldDataCell;
88
- children: Snippet;
89
- }>;
77
+ table?:
78
+ | Component<{
79
+ table: TableField<"filled">;
80
+ children: Snippet;
81
+ }>
82
+ | HTMLAttributes<HTMLTableElement>;
83
+ thead?:
84
+ | Component<{
85
+ head: TableFieldHead;
86
+ children: Snippet;
87
+ }>
88
+ | HTMLAttributes<HTMLTableSectionElement>;
89
+ tbody?:
90
+ | Component<{
91
+ body: TableFieldBody;
92
+ children: Snippet;
93
+ }>
94
+ | HTMLAttributes<HTMLTableSectionElement>;
95
+ tr?:
96
+ | Component<{
97
+ row: TableFieldHeadRow | TableFieldBodyRow;
98
+ children: Snippet;
99
+ }>
100
+ | HTMLAttributes<HTMLTableRowElement>;
101
+ th?:
102
+ | Component<{
103
+ cell: TableFieldHeaderCell;
104
+ children: Snippet;
105
+ }>
106
+ | HTMLAttributes<HTMLTableCellElement>;
107
+ td?:
108
+ | Component<{
109
+ cell: TableFieldDataCell;
110
+ children: Snippet;
111
+ }>
112
+ | HTMLAttributes<HTMLTableCellElement>;
90
113
  };
91
114
 
92
115
  /**
@@ -1,14 +0,0 @@
1
- <script lang="ts">
2
- import type { Snippet } from "svelte";
3
-
4
- import type { TableComponents } from "../types";
5
-
6
- type Props = {
7
- type: keyof TableComponents;
8
- children: Snippet;
9
- };
10
-
11
- const { type, children }: Props = $props();
12
- </script>
13
-
14
- <svelte:element this={type}>{@render children()}</svelte:element>
@@ -1,9 +0,0 @@
1
- import type { Snippet } from "svelte";
2
- import type { TableComponents } from "../types";
3
- type Props = {
4
- type: keyof TableComponents;
5
- children: Snippet;
6
- };
7
- declare const DefaultComponent: import("svelte").Component<Props, {}, "">;
8
- type DefaultComponent = ReturnType<typeof DefaultComponent>;
9
- export default DefaultComponent;
@@ -1,67 +0,0 @@
1
- <script lang="ts">
2
- import { type TableField, isFilled } from "@prismicio/client";
3
- import { type Component } from "svelte";
4
-
5
- import type { RichTextComponents, TableComponents } from "../types";
6
-
7
- import PrismicRichText from "../PrismicRichText/PrismicRichText.svelte";
8
-
9
- import DefaultComponent from "./DefaultComponent.svelte";
10
-
11
- type Props = {
12
- /**
13
- * The Prismic table field to render.
14
- */
15
- field: TableField;
16
-
17
- /**
18
- * An object that maps a rich text block type to a Svelte component.
19
- */
20
- components?: TableComponents & RichTextComponents;
21
-
22
- /**
23
- * The component rendered when the field is empty. If a fallback is not
24
- * given, `null` will be rendered.
25
- */
26
- fallback?: Component;
27
- };
28
-
29
- const { field, components = {}, fallback: Fallback }: Props = $props();
30
-
31
- const Table = components.table ?? DefaultComponent;
32
- const Thead = components.thead ?? DefaultComponent;
33
- const Tbody = components.tbody ?? DefaultComponent;
34
- const Tr = components.tr ?? DefaultComponent;
35
- const Th = components.th ?? DefaultComponent;
36
- const Td = components.td ?? DefaultComponent;
37
- </script>
38
-
39
- <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
40
- {#if isFilled.table(field)}
41
- <Table type="table" table={field}>
42
- {#if field?.head}
43
- <Thead type="thead" head={field.head}>
44
- {#each field.head.rows as row (row.key)}
45
- <Tr type="tr" {row}>
46
- {#each row.cells as cell (cell.key)}
47
- <Th type="th" {cell}>
48
- <PrismicRichText field={cell.content} {components} /></Th
49
- >{/each}</Tr
50
- >{/each}</Thead
51
- >{/if}<Tbody type="tbody" body={field.body}>
52
- {#each field.body.rows as row (row.key)}
53
- <Tr type="tr" {row}>
54
- {#each row.cells as cell (cell.key)}
55
- {#if cell.type === "header"}
56
- <Th type="th" {cell}>
57
- <PrismicRichText field={cell.content} {components} /></Th
58
- >{:else}<Td type="td" {cell}>
59
- <PrismicRichText field={cell.content} {components} /></Td
60
- >{/if}{/each}</Tr
61
- >
62
- {/each}
63
- </Tbody>
64
- </Table>
65
- {:else if Fallback}
66
- <Fallback />
67
- {/if}
@@ -1,14 +0,0 @@
1
- <script lang="ts">
2
- import type { Snippet } from "svelte";
3
-
4
- import type { TableComponents } from "../types";
5
-
6
- type Props = {
7
- type: keyof TableComponents;
8
- children: Snippet;
9
- };
10
-
11
- const { type, children }: Props = $props();
12
- </script>
13
-
14
- <svelte:element this={type}>{@render children()}</svelte:element>
@@ -1,67 +0,0 @@
1
- <script lang="ts">
2
- import { type TableField, isFilled } from "@prismicio/client";
3
- import { type Component } from "svelte";
4
-
5
- import type { RichTextComponents, TableComponents } from "../types";
6
-
7
- import PrismicRichText from "../PrismicRichText/PrismicRichText.svelte";
8
-
9
- import DefaultComponent from "./DefaultComponent.svelte";
10
-
11
- type Props = {
12
- /**
13
- * The Prismic table field to render.
14
- */
15
- field: TableField;
16
-
17
- /**
18
- * An object that maps a rich text block type to a Svelte component.
19
- */
20
- components?: TableComponents & RichTextComponents;
21
-
22
- /**
23
- * The component rendered when the field is empty. If a fallback is not
24
- * given, `null` will be rendered.
25
- */
26
- fallback?: Component;
27
- };
28
-
29
- const { field, components = {}, fallback: Fallback }: Props = $props();
30
-
31
- const Table = components.table ?? DefaultComponent;
32
- const Thead = components.thead ?? DefaultComponent;
33
- const Tbody = components.tbody ?? DefaultComponent;
34
- const Tr = components.tr ?? DefaultComponent;
35
- const Th = components.th ?? DefaultComponent;
36
- const Td = components.td ?? DefaultComponent;
37
- </script>
38
-
39
- <!-- This formatting is intentional to prevent unwanted whitespace between elements. -->
40
- {#if isFilled.table(field)}
41
- <Table type="table" table={field}>
42
- {#if field?.head}
43
- <Thead type="thead" head={field.head}>
44
- {#each field.head.rows as row (row.key)}
45
- <Tr type="tr" {row}>
46
- {#each row.cells as cell (cell.key)}
47
- <Th type="th" {cell}>
48
- <PrismicRichText field={cell.content} {components} /></Th
49
- >{/each}</Tr
50
- >{/each}</Thead
51
- >{/if}<Tbody type="tbody" body={field.body}>
52
- {#each field.body.rows as row (row.key)}
53
- <Tr type="tr" {row}>
54
- {#each row.cells as cell (cell.key)}
55
- {#if cell.type === "header"}
56
- <Th type="th" {cell}>
57
- <PrismicRichText field={cell.content} {components} /></Th
58
- >{:else}<Td type="td" {cell}>
59
- <PrismicRichText field={cell.content} {components} /></Td
60
- >{/if}{/each}</Tr
61
- >
62
- {/each}
63
- </Tbody>
64
- </Table>
65
- {:else if Fallback}
66
- <Fallback />
67
- {/if}