prismicio / prismic-svelte

Svelte components and helpers to fetch and present Prismic content
https://prismic.io/docs/technical-reference/prismicio-svelte
Apache License 2.0
22 stars 6 forks source link

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

Closed angeloashmore closed 8 months ago

angeloashmore commented 8 months ago

Types of changes

Description

This PR adds support for @prismicio/client's mapSliceZone() to <SliceZone>.

mapSliceZone() adds a __mapped property used to detect mapped Slices. <SliceZone> detects the __mapped property and automatically spreads the Slice's properties as props. An unmapped Slice will continue to provide the standard { slice, index, slices, context } props.

Example

// +page.server.js

import { mapSliceZone } from "@prismicio/client";
import { createClient } from "$lib/prismicio";

export async function load({ params, fetch, cookies }) {
  const client = createClient({ fetch, cookies });
  const page = await client.getByUID("page", params.uid);

  const slices = await mapSliceZone(
    page.data.slices,
    {
      foo: () => ({ foo: "bar" }),
      bar: () => ({ baz: "qux" }),
    },
  );

  return { slices };
}
<!-- +page.svelte -->

<script>
    import { SliceZone } from '@prismicio/svelte';

    import { components } from '$lib/slices';

    export let data;
</script>

<!-- The `foo` and `bar` components will receive the props returned in the functions above. -->
<SliceZone slices={data.slices} {components} />

Checklist:

šŸ¦†

codecov-commenter commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 67.62%. Comparing base (8c00747) to head (8c9bbb9).

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #19 +/- ## ========================================== + Coverage 67.11% 67.62% +0.50% ========================================== Files 18 18 Lines 894 908 +14 Branches 1 1 ========================================== + Hits 600 614 +14 Misses 294 294 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.