@contentful/experiences-svelte 0.6.5 → 0.6.7
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 +27 -0
- package/README.md +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/server-renderer.test.js +18 -0
- package/dist/test-fixtures/LivePreviewExperienceProbe.svelte +3 -1
- package/dist/test-fixtures/LivePreviewExperienceProbe.svelte.d.ts.map +1 -1
- package/dist/use-active-viewport.svelte.d.ts +9 -0
- package/dist/use-active-viewport.svelte.d.ts.map +1 -1
- package/dist/use-active-viewport.svelte.js +4 -0
- package/dist/use-live-preview-experience.svelte.d.ts +1 -0
- package/dist/use-live-preview-experience.svelte.d.ts.map +1 -1
- package/dist/use-live-preview-experience.svelte.js +11 -5
- package/dist/use-live-preview-experience.test.js +12 -0
- package/dist/use-live-preview.svelte.d.ts +1 -0
- package/dist/use-live-preview.svelte.d.ts.map +1 -1
- package/dist/use-live-preview.svelte.js +9 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
## 0.6.7 (2026-09-22)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **live-preview:** expose connection errors [SPA-5151] ([#198](https://github.com/contentful/experiences/pull/198))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated live-preview to 0.1.5
|
|
10
|
+
|
|
11
|
+
## 0.6.6 (2026-09-21)
|
|
12
|
+
|
|
13
|
+
### 🚀 Features
|
|
14
|
+
|
|
15
|
+
- deprecate the SDK viewport surface, guard absent viewports [SPA-5272] ([4a74473](https://github.com/contentful/experiences/commit/4a74473))
|
|
16
|
+
|
|
17
|
+
### 🩹 Fixes
|
|
18
|
+
|
|
19
|
+
- reword deprecation notices, drop internal ticket link [SPA-5272] ([8361460](https://github.com/contentful/experiences/commit/8361460))
|
|
20
|
+
|
|
21
|
+
### 🧱 Updated Dependencies
|
|
22
|
+
|
|
23
|
+
- Updated live-preview to 0.1.4
|
|
24
|
+
- Updated client to 0.4.5
|
|
25
|
+
- Updated design to 0.8.4
|
|
26
|
+
- Updated core to 0.8.4
|
|
27
|
+
|
|
1
28
|
## 0.6.5 (2026-09-21)
|
|
2
29
|
|
|
3
30
|
### 🧱 Updated Dependencies
|
package/README.md
CHANGED
|
@@ -101,6 +101,9 @@ For separate access to the raw payload and rendered plan, use
|
|
|
101
101
|
into the `PortableRenderPlan` consumed by the renderer and keeps the current rendered
|
|
102
102
|
experience while an update is being resolved.
|
|
103
103
|
|
|
104
|
+
The live-preview results also expose `error` when the Preview Session connection
|
|
105
|
+
fails. The last valid `data` remains available.
|
|
106
|
+
|
|
104
107
|
### Renderers
|
|
105
108
|
|
|
106
109
|
```ts
|
|
@@ -145,6 +148,7 @@ isCssProperty, toCssKey, CSS_PROPERTIES
|
|
|
145
148
|
// From client
|
|
146
149
|
fetchExperience, fetchPreviewSession, createClient, ContentfulViewDelivery,
|
|
147
150
|
ContentfulViewDeliveryClient, NotFoundError, PreviewSessionFetchError,
|
|
151
|
+
LivePreviewConnectionError,
|
|
148
152
|
DELIVERY_HOST, PREVIEW_HOST, PREVIEW_WEBSOCKET_HOST
|
|
149
153
|
|
|
150
154
|
type ExperienceOptions, PreviewSessionExperienceOptions, PreviewSessionClientOptions,
|
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export { useLivePreview } from './use-live-preview.svelte.js';
|
|
|
13
13
|
export type { UseLivePreviewOptions, UseLivePreviewResult } from './use-live-preview.svelte.js';
|
|
14
14
|
export { useExperiencePlan } from './use-experience-plan.svelte.js';
|
|
15
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';
|
|
16
|
+
export type { LivePreviewClient, LivePreviewResult, PreviewSessionClientOptions, PreviewSessionExperienceOptions, PreviewSessionOptions, PreviewSessionResolveOptions, } from '@contentful/experiences-live-preview';
|
|
17
|
+
export { fetchPreviewSession, LivePreviewConnectionError, PREVIEW_WEBSOCKET_HOST, PreviewSessionFetchError, } from '@contentful/experiences-live-preview';
|
|
18
18
|
export { getExperience, getContentfulComponent, getContentfulExperienceTemplate, } from './context.js';
|
|
19
19
|
export { getDesignValues } from './get-design-values.js';
|
|
20
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;AAE/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,YA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;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"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ export { useActiveViewport } from './use-active-viewport.svelte.js';
|
|
|
26
26
|
export { useLivePreviewExperience } from './use-live-preview-experience.svelte.js';
|
|
27
27
|
export { useLivePreview } from './use-live-preview.svelte.js';
|
|
28
28
|
export { useExperiencePlan } from './use-experience-plan.svelte.js';
|
|
29
|
-
export { fetchPreviewSession, PREVIEW_WEBSOCKET_HOST, PreviewSessionFetchError, } from '@contentful/experiences-live-preview';
|
|
29
|
+
export { fetchPreviewSession, LivePreviewConnectionError, PREVIEW_WEBSOCKET_HOST, PreviewSessionFetchError, } from '@contentful/experiences-live-preview';
|
|
30
30
|
// ─── Runtime context helpers ─────────────────────────────────────────────
|
|
31
31
|
export { getExperience, getContentfulComponent, getContentfulExperienceTemplate, } from './context.js';
|
|
32
32
|
export { getDesignValues } from './get-design-values.js';
|
|
@@ -767,6 +767,24 @@ describe('ServerExperienceRenderer — server pre-resolved design values', () =>
|
|
|
767
767
|
expect(container.innerHTML).toContain('data-padding="12px"');
|
|
768
768
|
});
|
|
769
769
|
});
|
|
770
|
+
describe('ServerExperienceRenderer — absent payload.viewports', () => {
|
|
771
|
+
it('renders flat design values when the payload has no viewports field', async () => {
|
|
772
|
+
const cfg = { components: { heading: HeadingFixture } };
|
|
773
|
+
const plan = await resolveExperience({
|
|
774
|
+
nodes: [
|
|
775
|
+
componentNode('heading', {
|
|
776
|
+
id: 'h',
|
|
777
|
+
designProperties: { cfFontSize: m('32px') },
|
|
778
|
+
}),
|
|
779
|
+
],
|
|
780
|
+
}, cfg);
|
|
781
|
+
expect(plan.viewports).toEqual([]);
|
|
782
|
+
const { container } = render(ServerExperienceRenderer, {
|
|
783
|
+
props: { experience: plan, config: cfg },
|
|
784
|
+
});
|
|
785
|
+
expect(container.innerHTML).toContain('data-font-size="32px"');
|
|
786
|
+
});
|
|
787
|
+
});
|
|
770
788
|
describe('toCss (Svelte)', () => {
|
|
771
789
|
it('converts bare (non-cf) CSS keys — the shape real payloads use', () => {
|
|
772
790
|
expect(toCss({ fontSize: '20px', backgroundColor: '#4f39f6' })).toEqual({
|
|
@@ -6,4 +6,6 @@
|
|
|
6
6
|
const livePreview = useLivePreviewExperience(() => options);
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
|
-
<output
|
|
9
|
+
<output data-error={livePreview.error?.name ?? ''}>
|
|
10
|
+
{livePreview.data?.nodes[0]?.contentProperties?.title ?? ''}
|
|
11
|
+
</output>
|
|
@@ -1 +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;
|
|
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;AAevE,QAAA,MAAM,0BAA0B,sDAAwC,CAAC;AACzE,KAAK,0BAA0B,GAAG,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAChF,eAAe,0BAA0B,CAAC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ViewportDef } from '@contentful/experiences-sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Viewports are being removed from the Experiences APIs, with no
|
|
4
|
+
* direct replacement — use CSS media queries or `window.matchMedia` instead.
|
|
5
|
+
* Will not be removed before 2026-10-06.
|
|
6
|
+
*/
|
|
2
7
|
export interface UseActiveViewportResult {
|
|
3
8
|
readonly activeViewportIndex: number;
|
|
4
9
|
}
|
|
@@ -9,6 +14,10 @@ export interface UseActiveViewportResult {
|
|
|
9
14
|
*
|
|
10
15
|
* Must be called at the top level of a `.svelte` component or a function
|
|
11
16
|
* that's itself called during component setup (because of `$effect`).
|
|
17
|
+
*
|
|
18
|
+
* @deprecated Viewports are being removed from the Experiences APIs, with no
|
|
19
|
+
* direct replacement — use CSS media queries or `window.matchMedia` instead.
|
|
20
|
+
* Will not be removed before 2026-10-06.
|
|
12
21
|
*/
|
|
13
22
|
export declare function useActiveViewport(viewports: ViewportDef[], initialViewportId?: string): UseActiveViewportResult;
|
|
14
23
|
//# sourceMappingURL=use-active-viewport.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-active-viewport.svelte.d.ts","sourceRoot":"","sources":["../src/use-active-viewport.svelte.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAGpE,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACtC;AAED
|
|
1
|
+
{"version":3,"file":"use-active-viewport.svelte.d.ts","sourceRoot":"","sources":["../src/use-active-viewport.svelte.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAGpE;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACtC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,WAAW,EAAE,EACxB,iBAAiB,CAAC,EAAE,MAAM,GACzB,uBAAuB,CAiDzB"}
|
|
@@ -18,6 +18,10 @@ import { createMediaQueryMatchers, getViewportIndex } from '@contentful/experien
|
|
|
18
18
|
*
|
|
19
19
|
* Must be called at the top level of a `.svelte` component or a function
|
|
20
20
|
* that's itself called during component setup (because of `$effect`).
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Viewports are being removed from the Experiences APIs, with no
|
|
23
|
+
* direct replacement — use CSS media queries or `window.matchMedia` instead.
|
|
24
|
+
* Will not be removed before 2026-10-06.
|
|
21
25
|
*/
|
|
22
26
|
export function useActiveViewport(viewports, initialViewportId) {
|
|
23
27
|
const initialIndex = getViewportIndex(viewports, initialViewportId);
|
|
@@ -6,6 +6,7 @@ export type UseLivePreviewExperienceOptions = {
|
|
|
6
6
|
};
|
|
7
7
|
export interface UseLivePreviewExperienceResult {
|
|
8
8
|
readonly data: ExperiencePayload | undefined;
|
|
9
|
+
readonly error: Error | undefined;
|
|
9
10
|
}
|
|
10
11
|
export declare function useLivePreviewExperience(getOptions: () => UseLivePreviewExperienceOptions): UseLivePreviewExperienceResult;
|
|
11
12
|
//# sourceMappingURL=use-live-preview-experience.svelte.d.ts.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"use-live-preview-experience.svelte.d.ts","sourceRoot":"","sources":["../src/use-live-preview-experience.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,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;IAC7C,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CACnC;AAED,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,+BAA+B,GAChD,8BAA8B,CAqChC"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { createLivePreviewClient, sendPreviewStatus, } from '@contentful/experiences-live-preview';
|
|
2
2
|
export function useLivePreviewExperience(getOptions) {
|
|
3
3
|
const initialPayload = getOptions().initialPayload;
|
|
4
|
-
let
|
|
4
|
+
let result = $state({
|
|
5
|
+
data: initialPayload,
|
|
6
|
+
error: undefined,
|
|
7
|
+
});
|
|
5
8
|
$effect(() => {
|
|
6
9
|
const { previewSessionOptions } = getOptions();
|
|
7
|
-
|
|
10
|
+
result = { data: initialPayload, error: undefined };
|
|
8
11
|
if (previewSessionOptions === undefined) {
|
|
9
12
|
sendPreviewStatus('static');
|
|
10
13
|
return;
|
|
11
14
|
}
|
|
12
15
|
const client = createLivePreviewClient(previewSessionOptions, initialPayload);
|
|
13
16
|
const unsubscribeStatus = client.subscribeStatus(sendPreviewStatus);
|
|
14
|
-
|
|
17
|
+
result = client.getResult();
|
|
15
18
|
const unsubscribe = client.subscribe(() => {
|
|
16
|
-
|
|
19
|
+
result = client.getResult();
|
|
17
20
|
});
|
|
18
21
|
return () => {
|
|
19
22
|
unsubscribeStatus();
|
|
@@ -22,7 +25,10 @@ export function useLivePreviewExperience(getOptions) {
|
|
|
22
25
|
});
|
|
23
26
|
return {
|
|
24
27
|
get data() {
|
|
25
|
-
return data;
|
|
28
|
+
return result.data;
|
|
29
|
+
},
|
|
30
|
+
get error() {
|
|
31
|
+
return result.error;
|
|
26
32
|
},
|
|
27
33
|
};
|
|
28
34
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { render } from '@testing-library/svelte';
|
|
2
|
+
import { tick } from 'svelte';
|
|
2
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
4
|
import LivePreviewExperienceProbe from './test-fixtures/LivePreviewExperienceProbe.svelte';
|
|
4
5
|
class FakeWebSocket {
|
|
@@ -122,6 +123,17 @@ describe('useLivePreviewExperience', () => {
|
|
|
122
123
|
status: 'live',
|
|
123
124
|
}, '*');
|
|
124
125
|
});
|
|
126
|
+
it('exposes a connection error after retries are exhausted', async () => {
|
|
127
|
+
vi.useFakeTimers();
|
|
128
|
+
const view = render(LivePreviewExperienceProbe, { props: { options: options() } });
|
|
129
|
+
for (let retry = 0; retry < 3; retry += 1) {
|
|
130
|
+
FakeWebSocket.instances.at(-1)?.emitClose({ code: 1006, reason: 'network' });
|
|
131
|
+
vi.runOnlyPendingTimers();
|
|
132
|
+
}
|
|
133
|
+
FakeWebSocket.instances.at(-1)?.emitClose({ code: 1006, reason: 'network' });
|
|
134
|
+
await tick();
|
|
135
|
+
expect(view.container.querySelector('output')?.dataset.error).toBe('LivePreviewConnectionError');
|
|
136
|
+
});
|
|
125
137
|
it('sends static status without Preview Session options', () => {
|
|
126
138
|
const postMessage = vi.spyOn(window.parent, 'postMessage').mockImplementation(() => undefined);
|
|
127
139
|
render(LivePreviewExperienceProbe, {
|
|
@@ -9,6 +9,7 @@ export interface UseLivePreviewOptions {
|
|
|
9
9
|
}
|
|
10
10
|
export interface UseLivePreviewResult {
|
|
11
11
|
readonly data: PortableRenderPlan | undefined;
|
|
12
|
+
readonly error: Error | undefined;
|
|
12
13
|
}
|
|
13
14
|
export declare function useLivePreview(getOptions: () => UseLivePreviewOptions): UseLivePreviewResult;
|
|
14
15
|
//# sourceMappingURL=use-live-preview.svelte.d.ts.map
|
|
@@ -1 +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;
|
|
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;IAC9C,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CACnC;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,qBAAqB,GAAG,oBAAoB,CAmB5F"}
|
|
@@ -5,8 +5,16 @@ export function useLivePreview(getOptions) {
|
|
|
5
5
|
const { previewSessionOptions, initialPayload } = getOptions();
|
|
6
6
|
return { previewSessionOptions, initialPayload };
|
|
7
7
|
});
|
|
8
|
-
|
|
8
|
+
const plan = useExperiencePlan(() => {
|
|
9
9
|
const { initialPlan, resolveOptions } = getOptions();
|
|
10
10
|
return { payload: livePreview.data, initialPlan, resolveOptions };
|
|
11
11
|
});
|
|
12
|
+
return {
|
|
13
|
+
get data() {
|
|
14
|
+
return plan.data;
|
|
15
|
+
},
|
|
16
|
+
get error() {
|
|
17
|
+
return livePreview.error;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
12
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-svelte",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "Svelte adapter for Contentful Experiences — Server and Client renderers over a PortableRenderPlan",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,10 +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.
|
|
41
|
-
"@contentful/experiences-live-preview": "0.1.
|
|
38
|
+
"@contentful/experiences-client": "0.4.5",
|
|
39
|
+
"@contentful/experiences-sdk-core": "0.8.4",
|
|
40
|
+
"@contentful/experiences-design": "0.8.4",
|
|
41
|
+
"@contentful/experiences-live-preview": "0.1.5"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"svelte": "^5.55.7"
|