@contentful/experiences-svelte 0.6.2 → 0.6.4
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.
- package/CHANGELOG.md +24 -0
- package/README.md +81 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/test-fixtures/ExperiencePlanProbe.svelte +9 -0
- package/dist/test-fixtures/ExperiencePlanProbe.svelte.d.ts +8 -0
- package/dist/test-fixtures/ExperiencePlanProbe.svelte.d.ts.map +1 -0
- package/dist/test-fixtures/LivePreviewExperienceProbe.svelte +9 -0
- package/dist/test-fixtures/LivePreviewExperienceProbe.svelte.d.ts +8 -0
- package/dist/test-fixtures/LivePreviewExperienceProbe.svelte.d.ts.map +1 -0
- package/dist/test-fixtures/LivePreviewPlanProbe.svelte +9 -0
- package/dist/test-fixtures/LivePreviewPlanProbe.svelte.d.ts +8 -0
- package/dist/test-fixtures/LivePreviewPlanProbe.svelte.d.ts.map +1 -0
- package/dist/use-experience-plan.svelte.d.ts +14 -0
- package/dist/use-experience-plan.svelte.d.ts.map +1 -0
- package/dist/use-experience-plan.svelte.js +28 -0
- package/dist/use-experience-plan.test.d.ts +2 -0
- package/dist/use-experience-plan.test.d.ts.map +1 -0
- package/dist/use-experience-plan.test.js +80 -0
- package/dist/use-live-preview-experience.svelte.d.ts +11 -0
- package/dist/use-live-preview-experience.svelte.d.ts.map +1 -0
- package/dist/use-live-preview-experience.svelte.js +28 -0
- package/dist/use-live-preview-experience.test.d.ts +2 -0
- package/dist/use-live-preview-experience.test.d.ts.map +1 -0
- package/dist/use-live-preview-experience.test.js +137 -0
- package/dist/use-live-preview.svelte.d.ts +14 -0
- package/dist/use-live-preview.svelte.d.ts.map +1 -0
- package/dist/use-live-preview.svelte.js +12 -0
- package/dist/use-live-preview.test.d.ts +2 -0
- package/dist/use-live-preview.test.d.ts.map +1 -0
- package/dist/use-live-preview.test.js +33 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## 0.6.4 (2026-09-18)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **live-preview:** support resource resolution [SPA-5369] ([#193](https://github.com/contentful/experiences/pull/193))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated live-preview to 0.1.2
|
|
10
|
+
|
|
11
|
+
## 0.6.3 (2026-09-11)
|
|
12
|
+
|
|
13
|
+
### 🚀 Features
|
|
14
|
+
|
|
15
|
+
- **live-preview:** expose preview status helper [SPA-5289] ([#170](https://github.com/contentful/experiences/pull/170))
|
|
16
|
+
- **live-preview:** add framework adapters [SPA-5161] ([#165](https://github.com/contentful/experiences/pull/165))
|
|
17
|
+
|
|
18
|
+
### 🧱 Updated Dependencies
|
|
19
|
+
|
|
20
|
+
- Updated live-preview to 0.1.1
|
|
21
|
+
- Updated client to 0.4.3
|
|
22
|
+
- Updated design to 0.8.3
|
|
23
|
+
- Updated core to 0.8.3
|
|
24
|
+
|
|
1
25
|
## 0.6.2 (2026-09-10)
|
|
2
26
|
|
|
3
27
|
### 🧱 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
|
|
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
|
|
|
@@ -23,12 +23,84 @@ defineComponent<Props>(config); // Type-narrowing identity for component-type co
|
|
|
23
23
|
defineExperienceTemplate<Props>(config); // Same shape, for coded Experience Template configs
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
### Fetching
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
fetchExperience(experienceOptions, clientOptions, resolveOptions); // Async; fetches from XDA and resolves in one call
|
|
30
|
+
fetchPreviewSession(previewSessionOptions, clientOptions, resolveOptions); // Async; fetches and resolves a Preview Session Experience
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Use `fetchPreviewSession` for the initial render when the Contentful app
|
|
34
|
+
provides a `preview_session_id`. It fetches the current Preview Session
|
|
35
|
+
snapshot and resolves it into a `PortableRenderPlan`. Use `useLivePreview` to
|
|
36
|
+
receive subsequent WebSocket updates:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
const plan = await fetchPreviewSession(
|
|
40
|
+
{ spaceId, environmentId, sessionId },
|
|
41
|
+
{ previewToken },
|
|
42
|
+
{ config: experienceConfig }
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If the Preview Session references resources from other spaces, pass the same
|
|
47
|
+
encoded `resourceResolution` value in the `previewSessionOptions` passed to
|
|
48
|
+
`fetchPreviewSession` and `useLivePreview`.
|
|
49
|
+
|
|
26
50
|
### Resolver
|
|
27
51
|
|
|
28
52
|
```ts
|
|
29
53
|
resolveExperience(payload, config, opts?); // Async; walks payload, runs resolveData, returns a PortableRenderPlan
|
|
30
54
|
```
|
|
31
55
|
|
|
56
|
+
### Live preview
|
|
57
|
+
|
|
58
|
+
Use `useLivePreview` when the app should subscribe to Preview Session updates,
|
|
59
|
+
resolve each payload, and render the resulting plan from `data`:
|
|
60
|
+
|
|
61
|
+
```svelte
|
|
62
|
+
<script lang="ts">
|
|
63
|
+
const livePreview = useLivePreview(() => ({
|
|
64
|
+
previewSessionOptions,
|
|
65
|
+
initialPayload,
|
|
66
|
+
initialPlan,
|
|
67
|
+
resolveOptions: { config: experienceConfig },
|
|
68
|
+
}));
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<ClientExperienceRenderer experience={livePreview.data} config={experienceConfig} />
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For separate access to the raw payload and rendered plan, use
|
|
75
|
+
`useLivePreviewExperience` and `useExperiencePlan`:
|
|
76
|
+
|
|
77
|
+
```svelte
|
|
78
|
+
<script lang="ts">
|
|
79
|
+
const livePreview = useLivePreviewExperience(() => ({
|
|
80
|
+
previewSessionOptions: {
|
|
81
|
+
spaceId,
|
|
82
|
+
environmentId,
|
|
83
|
+
previewToken,
|
|
84
|
+
sessionId,
|
|
85
|
+
},
|
|
86
|
+
initialPayload,
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
const plan = useExperiencePlan(() => ({
|
|
90
|
+
payload: livePreview.data,
|
|
91
|
+
initialPlan,
|
|
92
|
+
resolveOptions: { config: experienceConfig },
|
|
93
|
+
}));
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<ClientExperienceRenderer experience={plan.data} config={experienceConfig} />
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`useLivePreviewExperience` returns the latest raw Experience payload.
|
|
100
|
+
`initialPayload` seeds the first value. `useExperiencePlan` turns that payload
|
|
101
|
+
into the `PortableRenderPlan` consumed by the renderer and keeps the current rendered
|
|
102
|
+
experience while an update is being resolved.
|
|
103
|
+
|
|
32
104
|
### Renderers
|
|
33
105
|
|
|
34
106
|
```ts
|
|
@@ -69,6 +141,14 @@ type ResolverConfig, ResolveExperienceOptions
|
|
|
69
141
|
// From design (if you want to do your own viewport-aware resolution)
|
|
70
142
|
getValueForViewport, getViewportIndex, resolveDesignProperties, toCssMediaQuery,
|
|
71
143
|
isCssProperty, toCssKey, CSS_PROPERTIES
|
|
144
|
+
|
|
145
|
+
// From client
|
|
146
|
+
fetchExperience, fetchPreviewSession, createClient, ContentfulViewDelivery,
|
|
147
|
+
ContentfulViewDeliveryClient, NotFoundError, PreviewSessionFetchError,
|
|
148
|
+
DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST
|
|
149
|
+
|
|
150
|
+
type ExperienceOptions, PreviewSessionExperienceOptions, PreviewSessionClientOptions,
|
|
151
|
+
PreviewSessionResolveOptions, ClientOptions, ResolveOptions, CreateClientOptions
|
|
72
152
|
```
|
|
73
153
|
|
|
74
154
|
---
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ 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, PreviewSessionClientOptions, PreviewSessionExperienceOptions, PreviewSessionOptions, PreviewSessionResolveOptions, } from '@contentful/experiences-live-preview';
|
|
17
|
+
export { fetchPreviewSession, PREVIEW_WEBSOCKET_HOST, PreviewSessionFetchError, } from '@contentful/experiences-live-preview';
|
|
10
18
|
export { getExperience, getContentfulComponent, getContentfulExperienceTemplate, } from './context.js';
|
|
11
19
|
export { getDesignValues } from './get-design-values.js';
|
|
12
20
|
export { toCss } from './design-utils.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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,10 @@ 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';
|
|
29
|
+
export { fetchPreviewSession, PREVIEW_WEBSOCKET_HOST, PreviewSessionFetchError, } from '@contentful/experiences-live-preview';
|
|
26
30
|
// ─── Runtime context helpers ─────────────────────────────────────────────
|
|
27
31
|
export { getExperience, getContentfulComponent, getContentfulExperienceTemplate, } from './context.js';
|
|
28
32
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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.
|
|
3
|
+
"version": "0.6.4",
|
|
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.
|
|
39
|
-
"@contentful/experiences-sdk-core": "0.8.
|
|
40
|
-
"@contentful/experiences-design": "0.8.
|
|
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.2"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"svelte": "^5.55.7"
|