@contentful/experiences-svelte 0.6.2 → 0.6.3

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +49 -1
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -0
  6. package/dist/test-fixtures/ExperiencePlanProbe.svelte +9 -0
  7. package/dist/test-fixtures/ExperiencePlanProbe.svelte.d.ts +8 -0
  8. package/dist/test-fixtures/ExperiencePlanProbe.svelte.d.ts.map +1 -0
  9. package/dist/test-fixtures/LivePreviewExperienceProbe.svelte +9 -0
  10. package/dist/test-fixtures/LivePreviewExperienceProbe.svelte.d.ts +8 -0
  11. package/dist/test-fixtures/LivePreviewExperienceProbe.svelte.d.ts.map +1 -0
  12. package/dist/test-fixtures/LivePreviewPlanProbe.svelte +9 -0
  13. package/dist/test-fixtures/LivePreviewPlanProbe.svelte.d.ts +8 -0
  14. package/dist/test-fixtures/LivePreviewPlanProbe.svelte.d.ts.map +1 -0
  15. package/dist/use-experience-plan.svelte.d.ts +14 -0
  16. package/dist/use-experience-plan.svelte.d.ts.map +1 -0
  17. package/dist/use-experience-plan.svelte.js +28 -0
  18. package/dist/use-experience-plan.test.d.ts +2 -0
  19. package/dist/use-experience-plan.test.d.ts.map +1 -0
  20. package/dist/use-experience-plan.test.js +80 -0
  21. package/dist/use-live-preview-experience.svelte.d.ts +11 -0
  22. package/dist/use-live-preview-experience.svelte.d.ts.map +1 -0
  23. package/dist/use-live-preview-experience.svelte.js +28 -0
  24. package/dist/use-live-preview-experience.test.d.ts +2 -0
  25. package/dist/use-live-preview-experience.test.d.ts.map +1 -0
  26. package/dist/use-live-preview-experience.test.js +137 -0
  27. package/dist/use-live-preview.svelte.d.ts +14 -0
  28. package/dist/use-live-preview.svelte.d.ts.map +1 -0
  29. package/dist/use-live-preview.svelte.js +12 -0
  30. package/dist/use-live-preview.test.d.ts +2 -0
  31. package/dist/use-live-preview.test.d.ts.map +1 -0
  32. package/dist/use-live-preview.test.js +33 -0
  33. package/package.json +5 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.6.3 (2026-09-11)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **live-preview:** expose preview status helper [SPA-5289] ([#170](https://github.com/contentful/experiences/pull/170))
6
+ - **live-preview:** add framework adapters [SPA-5161] ([#165](https://github.com/contentful/experiences/pull/165))
7
+
8
+ ### 🧱 Updated Dependencies
9
+
10
+ - Updated live-preview to 0.1.1
11
+ - Updated client to 0.4.3
12
+ - Updated design to 0.8.3
13
+ - Updated core to 0.8.3
14
+
1
15
  ## 0.6.2 (2026-09-10)
2
16
 
3
17
  ### 🧱 Updated Dependencies
package/README.md CHANGED
@@ -8,7 +8,7 @@ The Svelte adapter for the Contentful Experiences SDK. You bring your own Svelte
8
8
  npm install @contentful/experiences-svelte
9
9
  ```
10
10
 
11
- This is the **only SDK package you install**. It re-exports everything you need from `@contentful/experiences-sdk-core` and `@contentful/experiences-design`. The other packages are workspace-internal.
11
+ This is the only rendering SDK package you install. It re-exports everything you need from `@contentful/experiences-sdk-core`, `@contentful/experiences-design`, and `@contentful/experiences-client`. The optional `@contentful/experiences-live-preview` package is also customer-facing and provides the framework-neutral live-preview client.
12
12
 
13
13
  The public API mirrors `@contentful/experiences-react` 1:1 in shape; only the rendering primitives change (Svelte 5 `Component`s, Snippets instead of `children: ReactNode`, and `getDesignValues()` instead of `useDesignValues()`).
14
14
 
@@ -29,6 +29,54 @@ defineExperienceTemplate<Props>(config); // Same shape, for coded Experience Tem
29
29
  resolveExperience(payload, config, opts?); // Async; walks payload, runs resolveData, returns a PortableRenderPlan
30
30
  ```
31
31
 
32
+ ### Live preview
33
+
34
+ Use `useLivePreview` when the app should subscribe to Preview Session updates,
35
+ resolve each payload, and render the resulting plan from `data`:
36
+
37
+ ```svelte
38
+ <script lang="ts">
39
+ const livePreview = useLivePreview(() => ({
40
+ previewSessionOptions,
41
+ initialPayload,
42
+ initialPlan,
43
+ resolveOptions: { config: experienceConfig },
44
+ }));
45
+ </script>
46
+
47
+ <ClientExperienceRenderer experience={livePreview.data} config={experienceConfig} />
48
+ ```
49
+
50
+ For separate access to the raw payload and rendered plan, use
51
+ `useLivePreviewExperience` and `useExperiencePlan`:
52
+
53
+ ```svelte
54
+ <script lang="ts">
55
+ const livePreview = useLivePreviewExperience(() => ({
56
+ previewSessionOptions: {
57
+ spaceId,
58
+ environmentId,
59
+ previewToken,
60
+ sessionId,
61
+ },
62
+ initialPayload,
63
+ }));
64
+
65
+ const plan = useExperiencePlan(() => ({
66
+ payload: livePreview.data,
67
+ initialPlan,
68
+ resolveOptions: { config: experienceConfig },
69
+ }));
70
+ </script>
71
+
72
+ <ClientExperienceRenderer experience={plan.data} config={experienceConfig} />
73
+ ```
74
+
75
+ `useLivePreviewExperience` returns the latest raw Experience payload.
76
+ `initialPayload` seeds the first value. `useExperiencePlan` turns that payload
77
+ into the `PortableRenderPlan` consumed by the renderer and keeps the current rendered
78
+ experience while an update is being resolved.
79
+
32
80
  ### Renderers
33
81
 
34
82
  ```ts
package/dist/index.d.ts CHANGED
@@ -7,6 +7,13 @@ export { default as DebugExperience } from './DebugExperience.svelte';
7
7
  export { default as NodesRenderer } from './NodesRenderer.svelte';
8
8
  export { useActiveViewport } from './use-active-viewport.svelte.js';
9
9
  export type { UseActiveViewportResult } from './use-active-viewport.svelte.js';
10
+ export { useLivePreviewExperience } from './use-live-preview-experience.svelte.js';
11
+ export type { UseLivePreviewExperienceOptions, UseLivePreviewExperienceResult, } from './use-live-preview-experience.svelte.js';
12
+ export { useLivePreview } from './use-live-preview.svelte.js';
13
+ export type { UseLivePreviewOptions, UseLivePreviewResult } from './use-live-preview.svelte.js';
14
+ export { useExperiencePlan } from './use-experience-plan.svelte.js';
15
+ export type { ExperiencePlanResolveOptions, UseExperiencePlanOptions, UseExperiencePlanResult, } from './use-experience-plan.svelte.js';
16
+ export type { LivePreviewClient, PreviewSessionOptions, } from '@contentful/experiences-live-preview';
10
17
  export { getExperience, getContentfulComponent, getContentfulExperienceTemplate, } from './context.js';
11
18
  export { getDesignValues } from './get-design-values.js';
12
19
  export { toCss } from './design-utils.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAKtE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,YAAY,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAG/E,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,+BAA+B,GAChC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,YAAY,EACV,6BAA6B,EAC7B,6BAA6B,IAAI,uBAAuB,EACxD,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,8BAA8B,EAC9B,uCAAuC,GACxC,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,eAAe,EACf,UAAU,EACV,MAAM,EACN,mBAAmB,EACnB,4BAA4B,EAC5B,wBAAwB,EACxB,8BAA8B,EAC9B,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,YAAY,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAGjG,YAAY,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,QAAQ,EACR,eAAe,GAChB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACb,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
package/dist/index.js CHANGED
@@ -23,6 +23,9 @@ export { default as DebugExperience } from './DebugExperience.svelte';
23
23
  // e.g. `<NodesRenderer nodes={contentful.slots.header as PortableRenderNode[]} ... />`.
24
24
  export { default as NodesRenderer } from './NodesRenderer.svelte';
25
25
  export { useActiveViewport } from './use-active-viewport.svelte.js';
26
+ export { useLivePreviewExperience } from './use-live-preview-experience.svelte.js';
27
+ export { useLivePreview } from './use-live-preview.svelte.js';
28
+ export { useExperiencePlan } from './use-experience-plan.svelte.js';
26
29
  // ─── Runtime context helpers ─────────────────────────────────────────────
27
30
  export { getExperience, getContentfulComponent, getContentfulExperienceTemplate, } from './context.js';
28
31
  export { getDesignValues } from './get-design-values.js';
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import type { UseExperiencePlanOptions } from '../use-experience-plan.svelte.js';
3
+ import { useExperiencePlan } from '../use-experience-plan.svelte.js';
4
+
5
+ let { options }: { options: UseExperiencePlanOptions } = $props();
6
+ const resolved = useExperiencePlan(() => options);
7
+ </script>
8
+
9
+ <output>{resolved.data?.nodes[0]?.props.content.title ?? ''}</output>
@@ -0,0 +1,8 @@
1
+ import type { UseExperiencePlanOptions } from '../use-experience-plan.svelte.js';
2
+ type $$ComponentProps = {
3
+ options: UseExperiencePlanOptions;
4
+ };
5
+ declare const ExperiencePlanProbe: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type ExperiencePlanProbe = ReturnType<typeof ExperiencePlanProbe>;
7
+ export default ExperiencePlanProbe;
8
+ //# sourceMappingURL=ExperiencePlanProbe.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExperiencePlanProbe.svelte.d.ts","sourceRoot":"","sources":["../../src/test-fixtures/ExperiencePlanProbe.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAGhF,KAAK,gBAAgB,GAAI;IAAE,OAAO,EAAE,wBAAwB,CAAA;CAAE,CAAC;AAahE,QAAA,MAAM,mBAAmB,sDAAwC,CAAC;AAClE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import type { UseLivePreviewExperienceOptions } from '../use-live-preview-experience.svelte.js';
3
+ import { useLivePreviewExperience } from '../use-live-preview-experience.svelte.js';
4
+
5
+ let { options }: { options: UseLivePreviewExperienceOptions } = $props();
6
+ const livePreview = useLivePreviewExperience(() => options);
7
+ </script>
8
+
9
+ <output>{livePreview.data?.nodes[0]?.contentProperties?.title ?? ''}</output>
@@ -0,0 +1,8 @@
1
+ import type { UseLivePreviewExperienceOptions } from '../use-live-preview-experience.svelte.js';
2
+ type $$ComponentProps = {
3
+ options: UseLivePreviewExperienceOptions;
4
+ };
5
+ declare const LivePreviewExperienceProbe: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type LivePreviewExperienceProbe = ReturnType<typeof LivePreviewExperienceProbe>;
7
+ export default LivePreviewExperienceProbe;
8
+ //# sourceMappingURL=LivePreviewExperienceProbe.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LivePreviewExperienceProbe.svelte.d.ts","sourceRoot":"","sources":["../../src/test-fixtures/LivePreviewExperienceProbe.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAG/F,KAAK,gBAAgB,GAAI;IAAE,OAAO,EAAE,+BAA+B,CAAA;CAAE,CAAC;AAavE,QAAA,MAAM,0BAA0B,sDAAwC,CAAC;AACzE,KAAK,0BAA0B,GAAG,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAChF,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import type { UseLivePreviewOptions } from '../use-live-preview.svelte.js';
3
+ import { useLivePreview } from '../use-live-preview.svelte.js';
4
+
5
+ let { options }: { options: UseLivePreviewOptions } = $props();
6
+ const livePreview = useLivePreview(() => options);
7
+ </script>
8
+
9
+ <output>{livePreview.data?.nodes[0]?.props.content.title ?? ''}</output>
@@ -0,0 +1,8 @@
1
+ import type { UseLivePreviewOptions } from '../use-live-preview.svelte.js';
2
+ type $$ComponentProps = {
3
+ options: UseLivePreviewOptions;
4
+ };
5
+ declare const LivePreviewPlanProbe: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type LivePreviewPlanProbe = ReturnType<typeof LivePreviewPlanProbe>;
7
+ export default LivePreviewPlanProbe;
8
+ //# sourceMappingURL=LivePreviewPlanProbe.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LivePreviewPlanProbe.svelte.d.ts","sourceRoot":"","sources":["../../src/test-fixtures/LivePreviewPlanProbe.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAG1E,KAAK,gBAAgB,GAAI;IAAE,OAAO,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAa7D,QAAA,MAAM,oBAAoB,sDAAwC,CAAC;AACnE,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACpE,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ExperiencePayload, PortableRenderPlan, ResolveExperienceOptions, ResolverConfig } from '@contentful/experiences-sdk-core';
2
+ export interface ExperiencePlanResolveOptions extends ResolveExperienceOptions {
3
+ config: ResolverConfig;
4
+ }
5
+ export interface UseExperiencePlanOptions {
6
+ payload: ExperiencePayload | undefined;
7
+ initialPlan?: PortableRenderPlan;
8
+ resolveOptions: ExperiencePlanResolveOptions;
9
+ }
10
+ export interface UseExperiencePlanResult {
11
+ readonly data: PortableRenderPlan | undefined;
12
+ }
13
+ export declare function useExperiencePlan(getOptions: () => UseExperiencePlanOptions): UseExperiencePlanResult;
14
+ //# sourceMappingURL=use-experience-plan.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-experience-plan.svelte.d.ts","sourceRoot":"","sources":["../src/use-experience-plan.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACf,MAAM,kCAAkC,CAAC;AAE1C,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACvC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,cAAc,EAAE,4BAA4B,CAAC;CAC9C;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC/C;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,wBAAwB,GACzC,uBAAuB,CA+BzB"}
@@ -0,0 +1,28 @@
1
+ import { resolveExperience } from '@contentful/experiences-sdk-core';
2
+ export function useExperiencePlan(getOptions) {
3
+ let plan = $state(getOptions().initialPlan);
4
+ $effect(() => {
5
+ const { payload, resolveOptions } = getOptions();
6
+ if (payload === undefined)
7
+ return;
8
+ let isCurrent = true;
9
+ const { config, ...resolveExperienceOptions } = resolveOptions;
10
+ void resolveExperience(payload, config, resolveExperienceOptions)
11
+ .then((nextPlan) => {
12
+ if (isCurrent && nextPlan.diagnostics.length === 0) {
13
+ plan = nextPlan;
14
+ }
15
+ })
16
+ .catch(() => {
17
+ // Keep the last usable experience when resolving an update fails.
18
+ });
19
+ return () => {
20
+ isCurrent = false;
21
+ };
22
+ });
23
+ return {
24
+ get data() {
25
+ return plan;
26
+ },
27
+ };
28
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=use-experience-plan.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-experience-plan.test.d.ts","sourceRoot":"","sources":["../src/use-experience-plan.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,80 @@
1
+ import { render } from '@testing-library/svelte';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ import ExperiencePlanProbe from './test-fixtures/ExperiencePlanProbe.svelte';
4
+ const payload = (title) => ({
5
+ nodes: [
6
+ {
7
+ component: {
8
+ sys: {
9
+ type: 'ResourceLink',
10
+ linkType: 'Contentful:Component',
11
+ urn: 'crn:contentful:::experience:components/hero',
12
+ },
13
+ },
14
+ contentProperties: { title },
15
+ designProperties: {},
16
+ slots: {},
17
+ },
18
+ ],
19
+ sys: { type: 'Experience' },
20
+ viewports: [
21
+ {
22
+ displayName: 'Default',
23
+ id: 'default',
24
+ previewSize: '1024px',
25
+ query: '*',
26
+ },
27
+ ],
28
+ });
29
+ const initialPlan = {
30
+ fallbackViewportIndex: 0,
31
+ nodes: [
32
+ {
33
+ nodeId: 'initial',
34
+ registration: { kind: 'component', id: 'hero' },
35
+ props: { content: { title: 'initial' }, design: {}, designRaw: {} },
36
+ slots: {},
37
+ },
38
+ ],
39
+ viewports: payload('initial').viewports,
40
+ metadata: {},
41
+ debug: false,
42
+ diagnostics: [],
43
+ };
44
+ const resolveOptions = {
45
+ config: { components: {} },
46
+ };
47
+ describe('useExperiencePlan', () => {
48
+ it('resolves raw data into an experience', async () => {
49
+ const view = render(ExperiencePlanProbe, {
50
+ props: {
51
+ options: {
52
+ payload: payload('updated'),
53
+ initialPlan,
54
+ resolveOptions,
55
+ },
56
+ },
57
+ });
58
+ await vi.waitFor(() => expect(view.container.textContent).toBe('updated'));
59
+ });
60
+ it('keeps the initial experience when resolving raw data fails', async () => {
61
+ const view = render(ExperiencePlanProbe, {
62
+ props: {
63
+ options: {
64
+ payload: payload('failed'),
65
+ initialPlan,
66
+ resolveOptions: {
67
+ config: {
68
+ components: {
69
+ hero: {
70
+ resolveData: () => Promise.reject(new Error('resolver failed')),
71
+ },
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ });
78
+ await vi.waitFor(() => expect(view.container.textContent).toBe('initial'));
79
+ });
80
+ });
@@ -0,0 +1,11 @@
1
+ import { type PreviewSessionOptions } from '@contentful/experiences-live-preview';
2
+ import type { ExperiencePayload } from '@contentful/experiences-sdk-core';
3
+ export type UseLivePreviewExperienceOptions = {
4
+ previewSessionOptions?: PreviewSessionOptions;
5
+ initialPayload?: ExperiencePayload;
6
+ };
7
+ export interface UseLivePreviewExperienceResult {
8
+ readonly data: ExperiencePayload | undefined;
9
+ }
10
+ export declare function useLivePreviewExperience(getOptions: () => UseLivePreviewExperienceOptions): UseLivePreviewExperienceResult;
11
+ //# sourceMappingURL=use-live-preview-experience.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-live-preview-experience.svelte.d.ts","sourceRoot":"","sources":["../src/use-live-preview-experience.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEF,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC9C;AAED,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,+BAA+B,GAChD,8BAA8B,CA+BhC"}
@@ -0,0 +1,28 @@
1
+ import { createLivePreviewClient, sendPreviewStatus, } from '@contentful/experiences-live-preview';
2
+ export function useLivePreviewExperience(getOptions) {
3
+ const initialPayload = getOptions().initialPayload;
4
+ let data = $state(initialPayload);
5
+ $effect(() => {
6
+ const { previewSessionOptions } = getOptions();
7
+ data = initialPayload;
8
+ if (previewSessionOptions === undefined) {
9
+ sendPreviewStatus('static');
10
+ return;
11
+ }
12
+ const client = createLivePreviewClient(previewSessionOptions, initialPayload);
13
+ const unsubscribeStatus = client.subscribeStatus(sendPreviewStatus);
14
+ data = client.getSnapshot();
15
+ const unsubscribe = client.subscribe(() => {
16
+ data = client.getSnapshot();
17
+ });
18
+ return () => {
19
+ unsubscribeStatus();
20
+ unsubscribe();
21
+ };
22
+ });
23
+ return {
24
+ get data() {
25
+ return data;
26
+ },
27
+ };
28
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=use-live-preview-experience.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-live-preview-experience.test.d.ts","sourceRoot":"","sources":["../src/use-live-preview-experience.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,137 @@
1
+ import { render } from '@testing-library/svelte';
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import LivePreviewExperienceProbe from './test-fixtures/LivePreviewExperienceProbe.svelte';
4
+ class FakeWebSocket {
5
+ static instances = [];
6
+ url;
7
+ close = vi.fn();
8
+ onopen = null;
9
+ onclose = null;
10
+ onmessage = null;
11
+ constructor(url) {
12
+ this.url = url;
13
+ FakeWebSocket.instances.push(this);
14
+ }
15
+ emitOpen() {
16
+ this.onopen?.({ type: 'open' });
17
+ }
18
+ emitClose(event) {
19
+ this.onclose?.(event);
20
+ }
21
+ emitMessage(data) {
22
+ this.onmessage?.({ data });
23
+ }
24
+ }
25
+ const payload = (title) => ({
26
+ nodes: [
27
+ {
28
+ component: {
29
+ sys: {
30
+ type: 'ResourceLink',
31
+ linkType: 'Contentful:Component',
32
+ urn: 'crn:contentful:::experience:components/hero',
33
+ },
34
+ },
35
+ contentProperties: { title },
36
+ designProperties: {},
37
+ slots: {},
38
+ },
39
+ ],
40
+ sys: { type: 'Experience' },
41
+ viewports: [
42
+ {
43
+ displayName: 'Default',
44
+ id: 'default',
45
+ previewSize: '1024px',
46
+ query: '*',
47
+ },
48
+ ],
49
+ });
50
+ const previewSessionOptions = {
51
+ environmentId: 'environment-id',
52
+ previewToken: 'preview-token',
53
+ sessionHost: 'wss://preview-session.example.test',
54
+ sessionId: 'session-id',
55
+ spaceId: 'space-id',
56
+ };
57
+ const options = (overrides = {}) => ({
58
+ previewSessionOptions,
59
+ ...overrides,
60
+ });
61
+ describe('useLivePreviewExperience', () => {
62
+ beforeEach(() => {
63
+ FakeWebSocket.instances = [];
64
+ vi.stubGlobal('WebSocket', FakeWebSocket);
65
+ });
66
+ afterEach(() => {
67
+ vi.restoreAllMocks();
68
+ vi.useRealTimers();
69
+ vi.unstubAllGlobals();
70
+ });
71
+ it('returns initial raw data and updates from the Preview Session', async () => {
72
+ const initialPayload = payload('initial');
73
+ const view = render(LivePreviewExperienceProbe, {
74
+ props: { options: options({ initialPayload }) },
75
+ });
76
+ expect(view.container.textContent).toBe('initial');
77
+ expect(FakeWebSocket.instances).toHaveLength(1);
78
+ FakeWebSocket.instances[0]?.emitMessage(JSON.stringify({ type: 'next', data: payload('updated') }));
79
+ await vi.waitFor(() => expect(view.container.textContent).toBe('updated'));
80
+ });
81
+ it('does not connect when a session credential is missing', () => {
82
+ const postMessage = vi.spyOn(window.parent, 'postMessage').mockImplementation(() => undefined);
83
+ const view = render(LivePreviewExperienceProbe, {
84
+ props: {
85
+ options: options({
86
+ initialPayload: payload('initial'),
87
+ previewSessionOptions: { ...previewSessionOptions, sessionId: undefined },
88
+ }),
89
+ },
90
+ });
91
+ expect(view.container.textContent).toBe('initial');
92
+ expect(FakeWebSocket.instances).toHaveLength(0);
93
+ expect(postMessage).toHaveBeenCalledWith({
94
+ source: 'experiences/live-preview',
95
+ type: 'status',
96
+ status: 'static',
97
+ }, '*');
98
+ });
99
+ it('sends live status after the session socket opens', async () => {
100
+ const postMessage = vi.spyOn(window.parent, 'postMessage').mockImplementation(() => undefined);
101
+ render(LivePreviewExperienceProbe, { props: { options: options() } });
102
+ expect(postMessage).not.toHaveBeenCalled();
103
+ FakeWebSocket.instances[0]?.emitOpen();
104
+ await vi.waitFor(() => expect(postMessage).toHaveBeenCalledWith({
105
+ source: 'experiences/live-preview',
106
+ type: 'status',
107
+ status: 'live',
108
+ }, '*'));
109
+ });
110
+ it('does not send static status while the session socket reconnects', async () => {
111
+ vi.useFakeTimers();
112
+ const postMessage = vi.spyOn(window.parent, 'postMessage').mockImplementation(() => undefined);
113
+ render(LivePreviewExperienceProbe, { props: { options: options() } });
114
+ FakeWebSocket.instances[0]?.emitOpen();
115
+ FakeWebSocket.instances[0]?.emitClose({ code: 1006, reason: 'network' });
116
+ vi.advanceTimersByTime(100);
117
+ FakeWebSocket.instances[1]?.emitOpen();
118
+ expect(postMessage).toHaveBeenCalledTimes(1);
119
+ expect(postMessage).toHaveBeenLastCalledWith({
120
+ source: 'experiences/live-preview',
121
+ type: 'status',
122
+ status: 'live',
123
+ }, '*');
124
+ });
125
+ it('sends static status without Preview Session options', () => {
126
+ const postMessage = vi.spyOn(window.parent, 'postMessage').mockImplementation(() => undefined);
127
+ render(LivePreviewExperienceProbe, {
128
+ props: { options: { initialPayload: payload('initial') } },
129
+ });
130
+ expect(FakeWebSocket.instances).toHaveLength(0);
131
+ expect(postMessage).toHaveBeenCalledWith({
132
+ source: 'experiences/live-preview',
133
+ type: 'status',
134
+ status: 'static',
135
+ }, '*');
136
+ });
137
+ });
@@ -0,0 +1,14 @@
1
+ import type { ExperiencePayload, PortableRenderPlan } from '@contentful/experiences-sdk-core';
2
+ import type { PreviewSessionOptions } from '@contentful/experiences-live-preview';
3
+ import { type ExperiencePlanResolveOptions } from './use-experience-plan.svelte.js';
4
+ export interface UseLivePreviewOptions {
5
+ previewSessionOptions?: PreviewSessionOptions;
6
+ initialPayload?: ExperiencePayload;
7
+ initialPlan?: PortableRenderPlan;
8
+ resolveOptions: ExperiencePlanResolveOptions;
9
+ }
10
+ export interface UseLivePreviewResult {
11
+ readonly data: PortableRenderPlan | undefined;
12
+ }
13
+ export declare function useLivePreview(getOptions: () => UseLivePreviewOptions): UseLivePreviewResult;
14
+ //# sourceMappingURL=use-live-preview.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-live-preview.svelte.d.ts","sourceRoot":"","sources":["../src/use-live-preview.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAElF,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,iCAAiC,CAAC;AAGzC,MAAM,WAAW,qBAAqB;IACpC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,cAAc,EAAE,4BAA4B,CAAC;CAC9C;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC/C;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,qBAAqB,GAAG,oBAAoB,CAU5F"}
@@ -0,0 +1,12 @@
1
+ import { useExperiencePlan, } from './use-experience-plan.svelte.js';
2
+ import { useLivePreviewExperience } from './use-live-preview-experience.svelte.js';
3
+ export function useLivePreview(getOptions) {
4
+ const livePreview = useLivePreviewExperience(() => {
5
+ const { previewSessionOptions, initialPayload } = getOptions();
6
+ return { previewSessionOptions, initialPayload };
7
+ });
8
+ return useExperiencePlan(() => {
9
+ const { initialPlan, resolveOptions } = getOptions();
10
+ return { payload: livePreview.data, initialPlan, resolveOptions };
11
+ });
12
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=use-live-preview.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-live-preview.test.d.ts","sourceRoot":"","sources":["../src/use-live-preview.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { render } from '@testing-library/svelte';
2
+ import { describe, expect, it } from 'vitest';
3
+ import LivePreviewPlanProbe from './test-fixtures/LivePreviewPlanProbe.svelte';
4
+ const payload = {
5
+ nodes: [],
6
+ sys: { type: 'Experience' },
7
+ viewports: [{ displayName: 'Default', id: 'default', previewSize: '1024px', query: '*' }],
8
+ };
9
+ const initialPlan = {
10
+ fallbackViewportIndex: 0,
11
+ nodes: [
12
+ {
13
+ nodeId: 'initial',
14
+ registration: { kind: 'component', id: 'hero' },
15
+ props: { content: { title: 'initial' }, design: {}, designRaw: {} },
16
+ slots: {},
17
+ },
18
+ ],
19
+ viewports: payload.viewports,
20
+ metadata: {},
21
+ debug: false,
22
+ diagnostics: [],
23
+ };
24
+ describe('useLivePreview', () => {
25
+ it('returns the initial plan when no Preview Session is configured', () => {
26
+ const options = {
27
+ initialPlan,
28
+ resolveOptions: { config: { components: {} } },
29
+ };
30
+ const view = render(LivePreviewPlanProbe, { props: { options } });
31
+ expect(view.container.textContent).toBe('initial');
32
+ });
33
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-svelte",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Svelte adapter for Contentful Experiences — Server and Client renderers over a PortableRenderPlan",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,9 +35,10 @@
35
35
  "check": "svelte-check --tsconfig ./tsconfig.json"
36
36
  },
37
37
  "dependencies": {
38
- "@contentful/experiences-client": "0.4.2",
39
- "@contentful/experiences-sdk-core": "0.8.2",
40
- "@contentful/experiences-design": "0.8.2"
38
+ "@contentful/experiences-client": "0.4.3",
39
+ "@contentful/experiences-sdk-core": "0.8.3",
40
+ "@contentful/experiences-design": "0.8.3",
41
+ "@contentful/experiences-live-preview": "0.1.1"
41
42
  },
42
43
  "peerDependencies": {
43
44
  "svelte": "^5.55.7"