Skip to content

Commit

Permalink
feat(SliceZone): add support for mapped Slice Zones created with `@pr…
Browse files Browse the repository at this point in the history
…ismicio/client`'s `unstable_mapSliceZone()` (#19)

* feat(SliceZone): add support for mapped Slice Zones created with `@prismicio/client`'s `unstable_mapSliceZone()`

* chore: update `@prismicio/client` dev dependency
  • Loading branch information
angeloashmore committed Mar 27, 2024
1 parent 8c00747 commit f9d1162
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"esm-env": "^1.0.0"
},
"devDependencies": {
"@prismicio/client": "^7.2.0",
"@prismicio/client": "^7.4.0",
"@prismicio/mock": "^0.3.1",
"@size-limit/preset-small-lib": "^11.0.1",
"@sveltejs/kit": "^2.0.0",
Expand Down
20 changes: 17 additions & 3 deletions src/SliceZone/SliceZone.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@
*
* @typeParam SliceType - Type name of the Slice.
*/
type SliceLike<SliceType extends string = string> =
type SliceLike<SliceType extends string = string> = (
| SliceLikeRestV2<SliceType>
| SliceLikeGraphQL<SliceType>;
| SliceLikeGraphQL<SliceType>
) & {
/**
* If `true`, this Slice has been modified from its original value using a
* mapper and `@prismicio/client`'s `mapSliceZone()`.
*
* @internal
*/
__mapped?: true;
};
/**
* An array of Prismic Slices, such as the `slices` property from a Prismic
Expand Down Expand Up @@ -108,7 +117,12 @@
{@const type = "slice_type" in slice ? slice.slice_type : slice.type}
{@const Component = components[type] || defaultComponent}
{#if Component}
<svelte:component this={Component} {slice} {slices} {context} {index} />
{#if slice.__mapped}
{@const { __mapped, ...mappedProps } = slice}
<svelte:component this={Component} {...mappedProps} />
{:else}
<svelte:component this={Component} {slice} {slices} {context} {index} />
{/if}
{:else}
<TodoComponent {slice} />
{/if}
Expand Down

0 comments on commit f9d1162

Please sign in to comment.