@prismicio/svelte 3.0.0 → 3.1.0-pr.78.a757d06

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.
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ const { sliceId, children }: { sliceId: string; children: Snippet } = $props()
5
+
6
+ const id = $derived(sliceId.replaceAll(">", "&gt;"))
7
+ </script>
8
+
9
+ {@html `<!--prismic-slice-start:${id}-->`}{@render children()}{@html `<!--prismic-slice-end:${id}-->`}
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ sliceId: string;
4
+ children: Snippet;
5
+ };
6
+ declare const SliceBoundary: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type SliceBoundary = ReturnType<typeof SliceBoundary>;
8
+ export default SliceBoundary;
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { Component } from "svelte"
3
3
 
4
- import type { SliceComponentProps, SliceZoneLike } from "../types"
4
+ import type { SliceComponentProps, SliceLike, SliceZoneLike } from "../types"
5
+ import SliceBoundary from "./SliceBoundary.svelte"
5
6
  import TodoComponent from "./TodoComponent.svelte"
6
7
 
7
8
  type Props = {
@@ -39,6 +40,10 @@
39
40
  }
40
41
 
41
42
  const { slices = [], components = {}, context = {}, defaultComponent }: Props = $props()
43
+
44
+ function getSliceId(slice: SliceLike): string | undefined {
45
+ return "id" in slice ? slice.id : undefined
46
+ }
42
47
  </script>
43
48
 
44
49
  <!--
@@ -57,17 +62,25 @@
57
62
  ```
58
63
  -->
59
64
 
60
- {#each slices as slice, index ("id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`)}
65
+ {#each slices as slice, index (getSliceId(slice) || `${index}-${JSON.stringify(slice)}`)}
66
+ {@const sliceId = getSliceId(slice)}
61
67
  {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
62
68
  {@const Component = components[type] || defaultComponent}
63
- {#if Component}
64
- {#if slice.__mapped}
65
- {@const { __mapped, ...mappedProps } = slice}
66
- <Component {...mappedProps} />
69
+ {#snippet content()}
70
+ {#if Component}
71
+ {#if slice.__mapped}
72
+ {@const { __mapped, ...mappedProps } = slice}
73
+ <Component {...mappedProps} />
74
+ {:else}
75
+ <Component {slice} {slices} {context} {index} />
76
+ {/if}
67
77
  {:else}
68
- <Component {slice} {slices} {context} {index} />
78
+ <TodoComponent {slice} />
69
79
  {/if}
80
+ {/snippet}
81
+ {#if sliceId}
82
+ <SliceBoundary {sliceId}>{@render content()}</SliceBoundary>
70
83
  {:else}
71
- <TodoComponent {slice} />
84
+ {@render content()}
72
85
  {/if}
73
86
  {/each}
package/dist/types.d.ts CHANGED
@@ -84,9 +84,7 @@ export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext =
84
84
  *
85
85
  * @typeParam SliceType - Type name of the Slice.
86
86
  */
87
- type SliceLikeRestV2<SliceType extends string = string> = {
88
- slice_type: Slice<SliceType>["slice_type"];
89
- };
87
+ type SliceLikeRestV2<SliceType extends string = string> = Pick<Slice<SliceType>, "id" | "slice_type">;
90
88
  /**
91
89
  * The minimum required properties to represent a Prismic Slice from the Prismic GraphQL API for the
92
90
  * `<SliceZone>` component.
@@ -104,7 +102,7 @@ type SliceLikeGraphQL<SliceType extends string = string> = {
104
102
  *
105
103
  * @typeParam SliceType - Type name of the Slice.
106
104
  */
107
- type SliceLike<SliceType extends string = string> = (SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>) & {
105
+ export type SliceLike<SliceType extends string = string> = (SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>) & {
108
106
  /**
109
107
  * If `true`, this Slice has been modified from its original value using a mapper and
110
108
  * `@prismicio/client`'s `mapSliceZone()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/svelte",
3
- "version": "3.0.0",
3
+ "version": "3.1.0-pr.78.a757d06",
4
4
  "description": "Svelte components to present Prismic content.",
5
5
  "keywords": [
6
6
  "prismic",
@@ -65,19 +65,19 @@
65
65
  "@prismicio/client": "^7.22.3",
66
66
  "@prismicio/mock": "^0.7.2",
67
67
  "@sveltejs/kit": "^3.0.1",
68
- "@sveltejs/package": "^3.0.0",
68
+ "@sveltejs/package": "^3.0.1",
69
69
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
70
70
  "@testing-library/svelte": "^5.4.2",
71
71
  "@types/node": "^26.6.5",
72
- "@vitest/coverage-v8": "^5.0.4",
72
+ "@vitest/coverage-v8": "^5.0.5",
73
73
  "globals": "^17.13.0",
74
- "happy-dom": "^21.0.1",
75
- "oxfmt": "^0.73.0",
76
- "oxlint": "^1.88.0",
74
+ "happy-dom": "^21.0.4",
75
+ "oxfmt": "^0.74.0",
76
+ "oxlint": "^1.89.0",
77
77
  "standard-version": "^9.5.0",
78
78
  "svelte": "^5.57.2",
79
79
  "typescript": "^6.0.3",
80
- "vitest": "^5.0.4"
80
+ "vitest": "^5.0.5"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "@prismicio/client": ">=7",
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ const { sliceId, children }: { sliceId: string; children: Snippet } = $props()
5
+
6
+ const id = $derived(sliceId.replaceAll(">", "&gt;"))
7
+ </script>
8
+
9
+ {@html `<!--prismic-slice-start:${id}-->`}{@render children()}{@html `<!--prismic-slice-end:${id}-->`}
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { Component } from "svelte"
3
3
 
4
- import type { SliceComponentProps, SliceZoneLike } from "../types"
4
+ import type { SliceComponentProps, SliceLike, SliceZoneLike } from "../types"
5
+ import SliceBoundary from "./SliceBoundary.svelte"
5
6
  import TodoComponent from "./TodoComponent.svelte"
6
7
 
7
8
  type Props = {
@@ -39,6 +40,10 @@
39
40
  }
40
41
 
41
42
  const { slices = [], components = {}, context = {}, defaultComponent }: Props = $props()
43
+
44
+ function getSliceId(slice: SliceLike): string | undefined {
45
+ return "id" in slice ? slice.id : undefined
46
+ }
42
47
  </script>
43
48
 
44
49
  <!--
@@ -57,17 +62,25 @@
57
62
  ```
58
63
  -->
59
64
 
60
- {#each slices as slice, index ("id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`)}
65
+ {#each slices as slice, index (getSliceId(slice) || `${index}-${JSON.stringify(slice)}`)}
66
+ {@const sliceId = getSliceId(slice)}
61
67
  {@const type = "slice_type" in slice ? slice.slice_type : slice.type}
62
68
  {@const Component = components[type] || defaultComponent}
63
- {#if Component}
64
- {#if slice.__mapped}
65
- {@const { __mapped, ...mappedProps } = slice}
66
- <Component {...mappedProps} />
69
+ {#snippet content()}
70
+ {#if Component}
71
+ {#if slice.__mapped}
72
+ {@const { __mapped, ...mappedProps } = slice}
73
+ <Component {...mappedProps} />
74
+ {:else}
75
+ <Component {slice} {slices} {context} {index} />
76
+ {/if}
67
77
  {:else}
68
- <Component {slice} {slices} {context} {index} />
78
+ <TodoComponent {slice} />
69
79
  {/if}
80
+ {/snippet}
81
+ {#if sliceId}
82
+ <SliceBoundary {sliceId}>{@render content()}</SliceBoundary>
70
83
  {:else}
71
- <TodoComponent {slice} />
84
+ {@render content()}
72
85
  {/if}
73
86
  {/each}
package/src/types.ts CHANGED
@@ -142,9 +142,10 @@ export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext =
142
142
  *
143
143
  * @typeParam SliceType - Type name of the Slice.
144
144
  */
145
- type SliceLikeRestV2<SliceType extends string = string> = {
146
- slice_type: Slice<SliceType>["slice_type"]
147
- }
145
+ type SliceLikeRestV2<SliceType extends string = string> = Pick<
146
+ Slice<SliceType>,
147
+ "id" | "slice_type"
148
+ >
148
149
 
149
150
  /**
150
151
  * The minimum required properties to represent a Prismic Slice from the Prismic GraphQL API for the
@@ -164,7 +165,7 @@ type SliceLikeGraphQL<SliceType extends string = string> = {
164
165
  *
165
166
  * @typeParam SliceType - Type name of the Slice.
166
167
  */
167
- type SliceLike<SliceType extends string = string> = (
168
+ export type SliceLike<SliceType extends string = string> = (
168
169
  | SliceLikeRestV2<SliceType>
169
170
  | SliceLikeGraphQL<SliceType>
170
171
  ) & {