Skip to content

Commit 25ed5d4

Browse files
committed
fix: add visual editing components, bump api version
1 parent 8213e79 commit 25ed5d4

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

sveltekit-app/src/lib/sanity/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export const dataset = assertEnvVar(PUBLIC_SANITY_DATASET, 'PUBLIC_SANITY_DATASE
1616

1717
export const projectId = assertEnvVar(PUBLIC_SANITY_PROJECT_ID, 'PUBLIC_SANITY_PROJECT_ID')
1818

19-
export const apiVersion = PUBLIC_SANITY_API_VERSION || '2024-03-15'
19+
export const apiVersion = PUBLIC_SANITY_API_VERSION || '2025-10-22'
2020

2121
export const studioUrl = PUBLIC_SANITY_STUDIO_URL || 'http://localhost:3333'

sveltekit-app/src/routes/+layout.svelte

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,56 @@
11
<script lang="ts">
2-
import {PreviewMode} from '@sanity/sveltekit'
2+
import {PreviewMode, QueryLoader, VisualEditing} from '@sanity/sveltekit'
33
import type {LayoutProps} from './$types'
44
import {page} from '$app/state'
55
import {resolve} from '$app/paths'
6+
import {client} from '$lib/sanity/client'
67
const {children, data}: LayoutProps = $props()
78
const {previewEnabled} = data
89
</script>
910

1011
<PreviewMode enabled={previewEnabled}>
11-
{#if previewEnabled}
12-
<a
13-
href={resolve('/preview/disable', {
14-
redirect: page.url.pathname,
15-
})}
16-
class="preview-toggle"
17-
>
18-
<span>Preview Enabled</span>
19-
<span>Disable Preview</span>
20-
</a>
21-
{/if}
22-
23-
<div class="container">
24-
<header class="header">
25-
<a class="header__title" href="/">SvelteKit + Sanity</a>
26-
</header>
27-
<main>
28-
{@render children()}
29-
</main>
30-
<footer class="footer">
31-
<p class="footer__text">
32-
Made with <svg
33-
data-sanity-icon="heart-filled"
34-
width="1em"
35-
height="1em"
36-
viewBox="0 0 25 25"
37-
fill="none"
38-
xmlns="http://www.w3.org/2000/svg"
39-
><path
40-
d="M17 16C15.8 17.3235 12.5 20.5 12.5 20.5C12.5 20.5 9.2 17.3235 8 16C5.2 12.9118 4.5 11.7059 4.5 9.5C4.5 7.29412 6.1 5.5 8.5 5.5C10.5 5.5 11.7 6.82353 12.5 8.14706C13.3 6.82353 14.5 5.5 16.5 5.5C18.9 5.5 20.5 7.29412 20.5 9.5C20.5 11.7059 19.8 12.9118 17 16Z"
41-
fill="currentColor"
42-
stroke="currentColor"
43-
stroke-width="1.2"
44-
/></svg
45-
> at Sanity
46-
</p>
47-
</footer>
48-
</div>
12+
<VisualEditing enabled={previewEnabled}>
13+
<QueryLoader enabled={previewEnabled} {client}>
14+
{#if previewEnabled}
15+
<a
16+
href={resolve('/preview/disable', {
17+
redirect: page.url.pathname,
18+
})}
19+
class="preview-toggle"
20+
>
21+
<span>Preview Enabled</span>
22+
<span>Disable Preview</span>
23+
</a>
24+
{/if}
25+
26+
<div class="container">
27+
<header class="header">
28+
<a class="header__title" href="/">SvelteKit + Sanity</a>
29+
</header>
30+
<main>
31+
{@render children()}
32+
</main>
33+
<footer class="footer">
34+
<p class="footer__text">
35+
Made with <svg
36+
data-sanity-icon="heart-filled"
37+
width="1em"
38+
height="1em"
39+
viewBox="0 0 25 25"
40+
fill="none"
41+
xmlns="http://www.w3.org/2000/svg"
42+
><path
43+
d="M17 16C15.8 17.3235 12.5 20.5 12.5 20.5C12.5 20.5 9.2 17.3235 8 16C5.2 12.9118 4.5 11.7059 4.5 9.5C4.5 7.29412 6.1 5.5 8.5 5.5C10.5 5.5 11.7 6.82353 12.5 8.14706C13.3 6.82353 14.5 5.5 16.5 5.5C18.9 5.5 20.5 7.29412 20.5 9.5C20.5 11.7059 19.8 12.9118 17 16Z"
44+
fill="currentColor"
45+
stroke="currentColor"
46+
stroke-width="1.2"
47+
/></svg
48+
> at Sanity
49+
</p>
50+
</footer>
51+
</div>
52+
</QueryLoader>
53+
</VisualEditing>
4954
</PreviewMode>
5055

5156
<style>

0 commit comments

Comments
 (0)