@contentful/experiences-react 0.8.2 → 0.8.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 CHANGED
@@ -1,3 +1,27 @@
1
+ ## 0.8.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.8.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.8.2 (2026-09-10)
2
26
 
3
27
  ### 🧱 Updated Dependencies
package/README.md CHANGED
@@ -8,7 +8,7 @@ The React adapter for the Contentful Experiences SDK. You bring your own React c
8
8
  npm install @contentful/experiences-react
9
9
  ```
10
10
 
11
- This is the **only SDK package you install**. It re-exports everything you need from `@contentful/experiences-sdk-core`, `@contentful/experiences-design`, and `@contentful/experiences-client`. 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
  ---
14
14
 
@@ -25,19 +25,83 @@ defineExperienceTemplate<Props>(config); // Same shape, for coded Experience Tem
25
25
 
26
26
  ```ts
27
27
  fetchExperience(experienceOptions, clientOptions, resolveOptions) // Async; fetches from XDA and resolves in one call
28
+ fetchPreviewSession(previewSessionOptions, clientOptions, resolveOptions) // Async; fetches and resolves a Preview Session Experience
28
29
  createClient(options) // Functional constructor matching the SDK's option shape
29
30
  ContentfulViewDeliveryClient // Re-exported delivery client for advanced use cases
30
31
  NotFoundError // Thrown when the Experience ID doesn't exist
32
+ PreviewSessionFetchError // Thrown when fetching a Preview Session fails
31
33
  ContentfulViewDelivery // Full error namespace from the delivery client
32
- type ExperienceOptions, ClientOptions, ResolveOptions, CreateClientOptions
34
+ type ExperienceOptions, PreviewSessionExperienceOptions, PreviewSessionClientOptions,
35
+ PreviewSessionResolveOptions, ClientOptions, ResolveOptions, CreateClientOptions
33
36
  ```
34
37
 
38
+ Use `fetchPreviewSession` for the initial render when the Contentful app
39
+ provides a `preview_session_id`. It fetches the current Preview Session
40
+ snapshot and resolves it into a `PortableRenderPlan`. Use `useLivePreview` to
41
+ receive subsequent WebSocket updates:
42
+
43
+ ```tsx
44
+ const plan = await fetchPreviewSession(
45
+ { spaceId, environmentId, sessionId },
46
+ { previewToken },
47
+ { config: experienceConfig }
48
+ );
49
+ ```
50
+
51
+ If the Preview Session references resources from other spaces, pass the same
52
+ encoded `resourceResolution` value in the `previewSessionOptions` passed to
53
+ `fetchPreviewSession` and `useLivePreview`.
54
+
35
55
  ### Resolver
36
56
 
37
57
  ```ts
38
58
  resolveExperience(payload, config, opts?) // Async; walks payload, runs resolveData, returns a PortableRenderPlan
39
59
  ```
40
60
 
61
+ ### Live preview
62
+
63
+ Use `useLivePreview` when the app should subscribe to Preview Session updates,
64
+ resolve each payload, and render the resulting plan from `data`:
65
+
66
+ ```tsx
67
+ const livePreview = useLivePreview({
68
+ previewSessionOptions,
69
+ initialPayload,
70
+ initialPlan,
71
+ resolveOptions: { config: experienceConfig },
72
+ });
73
+
74
+ <ClientExperienceRenderer experience={livePreview.data} config={experienceConfig} />;
75
+ ```
76
+
77
+ For separate access to the raw payload and rendered plan, use
78
+ `useLivePreviewExperience` and `useExperiencePlan`:
79
+
80
+ ```tsx
81
+ const livePreview = useLivePreviewExperience({
82
+ previewSessionOptions: {
83
+ spaceId,
84
+ environmentId,
85
+ previewToken,
86
+ sessionId,
87
+ },
88
+ initialPayload,
89
+ });
90
+
91
+ const plan = useExperiencePlan({
92
+ payload: livePreview.data,
93
+ initialPlan,
94
+ resolveOptions: { config: experienceConfig },
95
+ });
96
+
97
+ <ClientExperienceRenderer experience={plan.data} config={experienceConfig} />;
98
+ ```
99
+
100
+ `useLivePreviewExperience` returns the latest raw Experience payload.
101
+ `initialPayload` seeds the first value. `useExperiencePlan` turns that payload
102
+ into the `PortableRenderPlan` consumed by the renderer and keeps the current rendered
103
+ experience while an update is being resolved.
104
+
41
105
  ### Renderers
42
106
 
43
107
  ```ts
package/dist/index.d.ts CHANGED
@@ -5,6 +5,10 @@ export { ComponentError, ComponentErrorProps } from './component-error.js';
5
5
  export { DebugExperience, DebugExperienceProps } from './debug-experience.js';
6
6
  export { UseActiveViewportResult, useActiveViewport } from './use-active-viewport.js';
7
7
  export { DiagnosticReporter, RenderError, RenderUnknown } from './nodes-renderer.js';
8
+ export { UseLivePreviewExperienceOptions, UseLivePreviewExperienceResult, useLivePreviewExperience } from './use-live-preview-experience.js';
9
+ export { UseLivePreviewOptions, UseLivePreviewResult, useLivePreview } from './use-live-preview.js';
10
+ export { ExperiencePlanResolveOptions, UseExperiencePlanOptions, UseExperiencePlanResult, useExperiencePlan } from './use-experience-plan.js';
11
+ export { LivePreviewClient, PREVIEW_WEBSOCKET_HOST, PreviewSessionClientOptions, PreviewSessionExperienceOptions, PreviewSessionFetchError, PreviewSessionOptions, PreviewSessionResolveOptions, fetchPreviewSession } from '@contentful/experiences-live-preview';
8
12
  export { useContentfulComponent, useContentfulExperienceTemplate, useExperience } from './context.js';
9
13
  export { useDesignValues } from './use-design-values.js';
10
14
  export { ToCssOptions, toCss } from './design-utils.js';
package/dist/index.js CHANGED
@@ -7,6 +7,14 @@ import { MissingComponent } from "./missing-component";
7
7
  import { ComponentError } from "./component-error";
8
8
  import { DebugExperience } from "./debug-experience";
9
9
  import { useActiveViewport } from "./use-active-viewport";
10
+ import { useLivePreviewExperience } from "./use-live-preview-experience";
11
+ import { useLivePreview } from "./use-live-preview";
12
+ import { useExperiencePlan } from "./use-experience-plan";
13
+ import {
14
+ fetchPreviewSession,
15
+ PREVIEW_WEBSOCKET_HOST,
16
+ PreviewSessionFetchError
17
+ } from "@contentful/experiences-live-preview";
10
18
  import { useExperience, useContentfulComponent, useContentfulExperienceTemplate } from "./context";
11
19
  import { useDesignValues } from "./use-design-values";
12
20
  import { toCss } from "./design-utils";
@@ -51,11 +59,14 @@ export {
51
59
  MissingComponent,
52
60
  NotFoundError,
53
61
  PREVIEW_HOST,
62
+ PREVIEW_WEBSOCKET_HOST,
63
+ PreviewSessionFetchError,
54
64
  ServerExperienceRenderer,
55
65
  createClient,
56
66
  defineComponent,
57
67
  defineExperienceTemplate,
58
68
  fetchExperience,
69
+ fetchPreviewSession,
59
70
  getValueForViewport,
60
71
  getViewportIndex,
61
72
  isCssProperty,
@@ -72,6 +83,9 @@ export {
72
83
  useContentfulComponent,
73
84
  useContentfulExperienceTemplate,
74
85
  useDesignValues,
75
- useExperience
86
+ useExperience,
87
+ useExperiencePlan,
88
+ useLivePreview,
89
+ useLivePreviewExperience
76
90
  };
77
91
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*\n * Public API surface for `@contentful/experiences-react`.\n *\n * Customers add ONLY this package to their app's dependencies. Everything\n * needed to render an Experience — types, the resolver, viewport utilities,\n * the renderer components, the authoring helpers — is re-exported from here.\n * The internal `@contentful/experiences-sdk-core` and\n * `@contentful/experiences-design` packages are workspace-only implementation\n * details; they are not part of the public API.\n *\n * `ExperienceRenderer` is an alias for `ClientExperienceRenderer`; SSR\n * consumers explicitly import `ServerExperienceRenderer`.\n */\n\n// ─── Renderers ─────────────────────────────────────────────────────────────\nexport {\n ClientExperienceRenderer as ExperienceRenderer,\n ClientExperienceRenderer,\n} from './client-renderer';\nexport type { ClientExperienceRendererProps as ExperienceRendererProps } from './client-renderer';\nexport type { ClientExperienceRendererProps } from './client-renderer';\n\nexport { ServerExperienceRenderer } from './server-renderer';\nexport type { ServerExperienceRendererProps } from './server-renderer';\n\nexport { MissingComponent } from './missing-component';\nexport type { MissingComponentProps } from './missing-component';\n\nexport { ComponentError } from './component-error';\nexport type { ComponentErrorProps } from './component-error';\n\nexport { DebugExperience } from './debug-experience';\nexport type { DebugExperienceProps } from './debug-experience';\n\nexport { useActiveViewport } from './use-active-viewport';\nexport type { UseActiveViewportResult } from './use-active-viewport';\n\nexport type { DiagnosticReporter, RenderError, RenderUnknown } from './nodes-renderer';\n\n// ─── Runtime context hooks ───────────────────────────────────────────────\nexport { useExperience, useContentfulComponent, useContentfulExperienceTemplate } from './context';\nexport { useDesignValues } from './use-design-values';\nexport { toCss } from './design-utils';\nexport type { ToCssOptions } from './design-utils';\n\n// ─── Authoring helpers + Config types ─────────────────────────────────────\nexport {\n defineComponent,\n defineExperienceTemplate,\n normalizeComponentRegistration,\n normalizeExperienceTemplateRegistration,\n} from './types';\nexport type {\n ComponentConfig,\n Components,\n Config,\n ContentfulComponent,\n ContentfulExperienceTemplate,\n ExperienceTemplateConfig,\n ExperienceTemplateRegistration,\n ExperienceTemplates,\n Registration,\n RenderContext,\n ResolveToken,\n} from './types';\n\n// ─── Resolver (re-exported from render-core) ──────────────────────────────\nexport { resolveExperience } from '@contentful/experiences-sdk-core';\nexport type { ResolverConfig, ResolveExperienceOptions } from '@contentful/experiences-sdk-core';\n\n// ─── Core IR + payload types (re-exported from render-core) ───────────────\nexport type {\n ComponentNode,\n ComponentRef,\n DesignPropValue,\n DesignToken,\n ExperienceContext,\n ExperienceNode,\n ExperiencePayload,\n ExperienceSourceMap,\n ExperienceSys,\n ExperienceTemplateNode,\n ExperienceTemplateRef,\n ManualDesignValue,\n PortableRegistration,\n PortableRenderNode,\n PortableRenderPlan,\n ResolveContext,\n ValuesByViewport,\n ViewportDef,\n} from '@contentful/experiences-sdk-core';\n\n// ─── Design utilities (re-exported from design) ───────────────────────────\nexport {\n CSS_PROPERTIES,\n getValueForViewport,\n getViewportIndex,\n isCssProperty,\n resolveDesignProperties,\n toCssKey,\n toCssMediaQuery,\n} from '@contentful/experiences-design';\n\n// ─── Delivery client + fetchExperience ────────────────────────────────────\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n DELIVERY_HOST,\n ExperienceFetchError,\n NotFoundError,\n PREVIEW_HOST,\n createClient,\n fetchExperience,\n readSourceMap,\n toExperiencePayload,\n} from '@contentful/experiences-client';\nexport type {\n ClientOptions,\n CreateClientOptions,\n ExperienceOptions,\n ExperienceResponse,\n ResolveOptions,\n} from '@contentful/experiences-client';\n"],"mappings":"AAeA;AAAA,EAC8B;AAAA,EAC5B,4BAAAA;AAAA,OACK;AAIP,SAAS,gCAAgC;AAGzC,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAG/B,SAAS,uBAAuB;AAGhC,SAAS,yBAAyB;AAMlC,SAAS,eAAe,wBAAwB,uCAAuC;AACvF,SAAS,uBAAuB;AAChC,SAAS,aAAa;AAItB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgBP,SAAS,yBAAyB;AA0BlC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["ClientExperienceRenderer"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/*\n * Public API surface for `@contentful/experiences-react`.\n *\n * Customers add ONLY this package to their app's dependencies. Everything\n * needed to render an Experience — types, the resolver, viewport utilities,\n * the renderer components, the authoring helpers — is re-exported from here.\n * The internal `@contentful/experiences-sdk-core` and\n * `@contentful/experiences-design` packages are workspace-only implementation\n * details; they are not part of the public API.\n *\n * `ExperienceRenderer` is an alias for `ClientExperienceRenderer`; SSR\n * consumers explicitly import `ServerExperienceRenderer`.\n */\n\n// ─── Renderers ─────────────────────────────────────────────────────────────\nexport {\n ClientExperienceRenderer as ExperienceRenderer,\n ClientExperienceRenderer,\n} from './client-renderer';\nexport type { ClientExperienceRendererProps as ExperienceRendererProps } from './client-renderer';\nexport type { ClientExperienceRendererProps } from './client-renderer';\n\nexport { ServerExperienceRenderer } from './server-renderer';\nexport type { ServerExperienceRendererProps } from './server-renderer';\n\nexport { MissingComponent } from './missing-component';\nexport type { MissingComponentProps } from './missing-component';\n\nexport { ComponentError } from './component-error';\nexport type { ComponentErrorProps } from './component-error';\n\nexport { DebugExperience } from './debug-experience';\nexport type { DebugExperienceProps } from './debug-experience';\n\nexport { useActiveViewport } from './use-active-viewport';\nexport type { UseActiveViewportResult } from './use-active-viewport';\n\nexport type { DiagnosticReporter, RenderError, RenderUnknown } from './nodes-renderer';\n\nexport { useLivePreviewExperience } from './use-live-preview-experience';\nexport type {\n UseLivePreviewExperienceOptions,\n UseLivePreviewExperienceResult,\n} from './use-live-preview-experience';\nexport { useLivePreview } from './use-live-preview';\nexport type { UseLivePreviewOptions, UseLivePreviewResult } from './use-live-preview';\n\nexport { useExperiencePlan } from './use-experience-plan';\nexport type {\n ExperiencePlanResolveOptions,\n UseExperiencePlanOptions,\n UseExperiencePlanResult,\n} from './use-experience-plan';\nexport type {\n LivePreviewClient,\n PreviewSessionClientOptions,\n PreviewSessionExperienceOptions,\n PreviewSessionOptions,\n PreviewSessionResolveOptions,\n} from '@contentful/experiences-live-preview';\nexport {\n fetchPreviewSession,\n PREVIEW_WEBSOCKET_HOST,\n PreviewSessionFetchError,\n} from '@contentful/experiences-live-preview';\n\n// ─── Runtime context hooks ───────────────────────────────────────────────\nexport { useExperience, useContentfulComponent, useContentfulExperienceTemplate } from './context';\nexport { useDesignValues } from './use-design-values';\nexport { toCss } from './design-utils';\nexport type { ToCssOptions } from './design-utils';\n\n// ─── Authoring helpers + Config types ─────────────────────────────────────\nexport {\n defineComponent,\n defineExperienceTemplate,\n normalizeComponentRegistration,\n normalizeExperienceTemplateRegistration,\n} from './types';\nexport type {\n ComponentConfig,\n Components,\n Config,\n ContentfulComponent,\n ContentfulExperienceTemplate,\n ExperienceTemplateConfig,\n ExperienceTemplateRegistration,\n ExperienceTemplates,\n Registration,\n RenderContext,\n ResolveToken,\n} from './types';\n\n// ─── Resolver (re-exported from render-core) ──────────────────────────────\nexport { resolveExperience } from '@contentful/experiences-sdk-core';\nexport type { ResolverConfig, ResolveExperienceOptions } from '@contentful/experiences-sdk-core';\n\n// ─── Core IR + payload types (re-exported from render-core) ───────────────\nexport type {\n ComponentNode,\n ComponentRef,\n DesignPropValue,\n DesignToken,\n ExperienceContext,\n ExperienceNode,\n ExperiencePayload,\n ExperienceSourceMap,\n ExperienceSys,\n ExperienceTemplateNode,\n ExperienceTemplateRef,\n ManualDesignValue,\n PortableRegistration,\n PortableRenderNode,\n PortableRenderPlan,\n ResolveContext,\n ValuesByViewport,\n ViewportDef,\n} from '@contentful/experiences-sdk-core';\n\n// ─── Design utilities (re-exported from design) ───────────────────────────\nexport {\n CSS_PROPERTIES,\n getValueForViewport,\n getViewportIndex,\n isCssProperty,\n resolveDesignProperties,\n toCssKey,\n toCssMediaQuery,\n} from '@contentful/experiences-design';\n\n// ─── Delivery client + fetchExperience ────────────────────────────────────\nexport {\n ContentfulViewDelivery,\n ContentfulViewDeliveryClient,\n DELIVERY_HOST,\n ExperienceFetchError,\n NotFoundError,\n PREVIEW_HOST,\n createClient,\n fetchExperience,\n readSourceMap,\n toExperiencePayload,\n} from '@contentful/experiences-client';\nexport type {\n ClientOptions,\n CreateClientOptions,\n ExperienceOptions,\n ExperienceResponse,\n ResolveOptions,\n} from '@contentful/experiences-client';\n"],"mappings":"AAeA;AAAA,EAC8B;AAAA,EAC5B,4BAAAA;AAAA,OACK;AAIP,SAAS,gCAAgC;AAGzC,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAG/B,SAAS,uBAAuB;AAGhC,SAAS,yBAAyB;AAKlC,SAAS,gCAAgC;AAKzC,SAAS,sBAAsB;AAG/B,SAAS,yBAAyB;AAalC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,eAAe,wBAAwB,uCAAuC;AACvF,SAAS,uBAAuB;AAChC,SAAS,aAAa;AAItB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgBP,SAAS,yBAAyB;AA0BlC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["ClientExperienceRenderer"]}
@@ -0,0 +1,16 @@
1
+ import { ResolveExperienceOptions, ResolverConfig, ExperiencePayload, PortableRenderPlan } from '@contentful/experiences-sdk-core';
2
+
3
+ interface ExperiencePlanResolveOptions extends ResolveExperienceOptions {
4
+ config: ResolverConfig;
5
+ }
6
+ interface UseExperiencePlanOptions {
7
+ payload: ExperiencePayload | undefined;
8
+ initialPlan?: PortableRenderPlan;
9
+ resolveOptions: ExperiencePlanResolveOptions;
10
+ }
11
+ interface UseExperiencePlanResult {
12
+ readonly data: PortableRenderPlan | undefined;
13
+ }
14
+ declare function useExperiencePlan(options: UseExperiencePlanOptions): UseExperiencePlanResult;
15
+
16
+ export { type ExperiencePlanResolveOptions, type UseExperiencePlanOptions, type UseExperiencePlanResult, useExperiencePlan };
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ import { resolveExperience } from "@contentful/experiences-sdk-core";
4
+ function useExperiencePlan(options) {
5
+ const { payload, initialPlan, resolveOptions } = options;
6
+ const [plan, setPlan] = useState(initialPlan);
7
+ const { config, metadata, debug, initialViewportId, sourceMap } = resolveOptions;
8
+ useEffect(() => {
9
+ let isCurrent = true;
10
+ if (payload === void 0) {
11
+ return () => {
12
+ isCurrent = false;
13
+ };
14
+ }
15
+ void resolveExperience(payload, config, { metadata, debug, initialViewportId, sourceMap }).then((nextPlan) => {
16
+ if (isCurrent && nextPlan.diagnostics.length === 0) {
17
+ setPlan(nextPlan);
18
+ }
19
+ }).catch(() => {
20
+ });
21
+ return () => {
22
+ isCurrent = false;
23
+ };
24
+ }, [payload, config, metadata, debug, initialViewportId, sourceMap]);
25
+ return { data: plan };
26
+ }
27
+ export {
28
+ useExperiencePlan
29
+ };
30
+ //# sourceMappingURL=use-experience-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-experience-plan.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useState } from 'react';\n\nimport { resolveExperience } from '@contentful/experiences-sdk-core';\nimport type {\n ExperiencePayload,\n PortableRenderPlan,\n ResolveExperienceOptions,\n ResolverConfig,\n} from '@contentful/experiences-sdk-core';\n\nexport interface ExperiencePlanResolveOptions extends ResolveExperienceOptions {\n config: ResolverConfig;\n}\n\nexport interface UseExperiencePlanOptions {\n payload: ExperiencePayload | undefined;\n initialPlan?: PortableRenderPlan;\n resolveOptions: ExperiencePlanResolveOptions;\n}\n\nexport interface UseExperiencePlanResult {\n readonly data: PortableRenderPlan | undefined;\n}\n\nexport function useExperiencePlan(options: UseExperiencePlanOptions): UseExperiencePlanResult {\n const { payload, initialPlan, resolveOptions } = options;\n const [plan, setPlan] = useState<PortableRenderPlan | undefined>(initialPlan);\n const { config, metadata, debug, initialViewportId, sourceMap } = resolveOptions;\n\n useEffect(() => {\n let isCurrent = true;\n\n if (payload === undefined) {\n return () => {\n isCurrent = false;\n };\n }\n\n void resolveExperience(payload, config, { metadata, debug, initialViewportId, sourceMap })\n .then((nextPlan) => {\n if (isCurrent && nextPlan.diagnostics.length === 0) {\n setPlan(nextPlan);\n }\n })\n .catch(() => {\n // Keep the last usable experience when resolving an update fails.\n });\n\n return () => {\n isCurrent = false;\n };\n }, [payload, config, metadata, debug, initialViewportId, sourceMap]);\n\n return { data: plan };\n}\n"],"mappings":";AAEA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,yBAAyB;AAsB3B,SAAS,kBAAkB,SAA4D;AAC5F,QAAM,EAAE,SAAS,aAAa,eAAe,IAAI;AACjD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAyC,WAAW;AAC5E,QAAM,EAAE,QAAQ,UAAU,OAAO,mBAAmB,UAAU,IAAI;AAElE,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,QAAI,YAAY,QAAW;AACzB,aAAO,MAAM;AACX,oBAAY;AAAA,MACd;AAAA,IACF;AAEA,SAAK,kBAAkB,SAAS,QAAQ,EAAE,UAAU,OAAO,mBAAmB,UAAU,CAAC,EACtF,KAAK,CAAC,aAAa;AAClB,UAAI,aAAa,SAAS,YAAY,WAAW,GAAG;AAClD,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AAAA,IAEb,CAAC;AAEH,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,SAAS,QAAQ,UAAU,OAAO,mBAAmB,SAAS,CAAC;AAEnE,SAAO,EAAE,MAAM,KAAK;AACtB;","names":[]}
@@ -0,0 +1,13 @@
1
+ import { PreviewSessionOptions } from '@contentful/experiences-live-preview';
2
+ import { ExperiencePayload } from '@contentful/experiences-sdk-core';
3
+
4
+ type UseLivePreviewExperienceOptions = {
5
+ previewSessionOptions?: PreviewSessionOptions;
6
+ initialPayload?: ExperiencePayload;
7
+ };
8
+ interface UseLivePreviewExperienceResult {
9
+ readonly data: ExperiencePayload | undefined;
10
+ }
11
+ declare function useLivePreviewExperience(options: UseLivePreviewExperienceOptions): UseLivePreviewExperienceResult;
12
+
13
+ export { type UseLivePreviewExperienceOptions, type UseLivePreviewExperienceResult, useLivePreviewExperience };
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { useEffect, useMemo, useSyncExternalStore } from "react";
3
+ import {
4
+ createLivePreviewClient,
5
+ sendPreviewStatus
6
+ } from "@contentful/experiences-live-preview";
7
+ function useLivePreviewExperience(options) {
8
+ const { previewSessionOptions, initialPayload } = options;
9
+ const client = useMemo(() => {
10
+ if (previewSessionOptions === void 0) return void 0;
11
+ return createLivePreviewClient(previewSessionOptions, initialPayload);
12
+ }, [
13
+ previewSessionOptions?.spaceId,
14
+ previewSessionOptions?.environmentId,
15
+ previewSessionOptions?.previewToken,
16
+ previewSessionOptions?.sessionId,
17
+ previewSessionOptions?.resourceResolution,
18
+ previewSessionOptions?.sessionHost,
19
+ previewSessionOptions?.debug
20
+ ]);
21
+ const emptySource = useMemo(
22
+ () => ({
23
+ getSnapshot: () => initialPayload,
24
+ subscribe: () => () => void 0
25
+ }),
26
+ [initialPayload]
27
+ );
28
+ const source = client ?? emptySource;
29
+ const data = useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);
30
+ useEffect(() => {
31
+ if (client === void 0) {
32
+ sendPreviewStatus("static");
33
+ return;
34
+ }
35
+ return client.subscribeStatus(sendPreviewStatus);
36
+ }, [client]);
37
+ return { data };
38
+ }
39
+ export {
40
+ useLivePreviewExperience
41
+ };
42
+ //# sourceMappingURL=use-live-preview-experience.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-live-preview-experience.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useMemo, useSyncExternalStore } from 'react';\n\nimport {\n createLivePreviewClient,\n sendPreviewStatus,\n type PreviewSessionOptions,\n} from '@contentful/experiences-live-preview';\nimport type { ExperiencePayload } from '@contentful/experiences-sdk-core';\n\nexport type UseLivePreviewExperienceOptions = {\n previewSessionOptions?: PreviewSessionOptions;\n initialPayload?: ExperiencePayload;\n};\n\nexport interface UseLivePreviewExperienceResult {\n readonly data: ExperiencePayload | undefined;\n}\n\nexport function useLivePreviewExperience(\n options: UseLivePreviewExperienceOptions\n): UseLivePreviewExperienceResult {\n const { previewSessionOptions, initialPayload } = options;\n const client = useMemo(() => {\n if (previewSessionOptions === undefined) return undefined;\n\n return createLivePreviewClient(previewSessionOptions, initialPayload);\n }, [\n previewSessionOptions?.spaceId,\n previewSessionOptions?.environmentId,\n previewSessionOptions?.previewToken,\n previewSessionOptions?.sessionId,\n previewSessionOptions?.resourceResolution,\n previewSessionOptions?.sessionHost,\n previewSessionOptions?.debug,\n ]);\n\n const emptySource = useMemo(\n () => ({\n getSnapshot: () => initialPayload,\n subscribe: () => () => undefined,\n }),\n [initialPayload]\n );\n const source = client ?? emptySource;\n const data = useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);\n\n useEffect(() => {\n if (client === undefined) {\n sendPreviewStatus('static');\n return;\n }\n\n return client.subscribeStatus(sendPreviewStatus);\n }, [client]);\n\n return { data };\n}\n"],"mappings":";AAEA,SAAS,WAAW,SAAS,4BAA4B;AAEzD;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAYA,SAAS,yBACd,SACgC;AAChC,QAAM,EAAE,uBAAuB,eAAe,IAAI;AAClD,QAAM,SAAS,QAAQ,MAAM;AAC3B,QAAI,0BAA0B,OAAW,QAAO;AAEhD,WAAO,wBAAwB,uBAAuB,cAAc;AAAA,EACtE,GAAG;AAAA,IACD,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EACzB,CAAC;AAED,QAAM,cAAc;AAAA,IAClB,OAAO;AAAA,MACL,aAAa,MAAM;AAAA,MACnB,WAAW,MAAM,MAAM;AAAA,IACzB;AAAA,IACA,CAAC,cAAc;AAAA,EACjB;AACA,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,qBAAqB,OAAO,WAAW,OAAO,aAAa,OAAO,WAAW;AAE1F,YAAU,MAAM;AACd,QAAI,WAAW,QAAW;AACxB,wBAAkB,QAAQ;AAC1B;AAAA,IACF;AAEA,WAAO,OAAO,gBAAgB,iBAAiB;AAAA,EACjD,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO,EAAE,KAAK;AAChB;","names":[]}
@@ -0,0 +1,16 @@
1
+ import { ExperiencePayload, PortableRenderPlan } from '@contentful/experiences-sdk-core';
2
+ import { PreviewSessionOptions } from '@contentful/experiences-live-preview';
3
+ import { ExperiencePlanResolveOptions } from './use-experience-plan.js';
4
+
5
+ interface UseLivePreviewOptions {
6
+ previewSessionOptions?: PreviewSessionOptions;
7
+ initialPayload?: ExperiencePayload;
8
+ initialPlan?: PortableRenderPlan;
9
+ resolveOptions: ExperiencePlanResolveOptions;
10
+ }
11
+ interface UseLivePreviewResult {
12
+ readonly data: PortableRenderPlan | undefined;
13
+ }
14
+ declare function useLivePreview(options: UseLivePreviewOptions): UseLivePreviewResult;
15
+
16
+ export { type UseLivePreviewOptions, type UseLivePreviewResult, useLivePreview };
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { useLivePreviewExperience } from "./use-live-preview-experience";
3
+ import { useExperiencePlan } from "./use-experience-plan";
4
+ function useLivePreview(options) {
5
+ const livePreview = useLivePreviewExperience({
6
+ previewSessionOptions: options.previewSessionOptions,
7
+ initialPayload: options.initialPayload
8
+ });
9
+ return useExperiencePlan({
10
+ payload: livePreview.data,
11
+ initialPlan: options.initialPlan,
12
+ resolveOptions: options.resolveOptions
13
+ });
14
+ }
15
+ export {
16
+ useLivePreview
17
+ };
18
+ //# sourceMappingURL=use-live-preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/use-live-preview.ts"],"sourcesContent":["'use client';\n\nimport type { ExperiencePayload, PortableRenderPlan } from '@contentful/experiences-sdk-core';\nimport type { PreviewSessionOptions } from '@contentful/experiences-live-preview';\n\nimport { useLivePreviewExperience } from './use-live-preview-experience';\nimport { useExperiencePlan, type ExperiencePlanResolveOptions } from './use-experience-plan';\n\nexport interface UseLivePreviewOptions {\n previewSessionOptions?: PreviewSessionOptions;\n initialPayload?: ExperiencePayload;\n initialPlan?: PortableRenderPlan;\n resolveOptions: ExperiencePlanResolveOptions;\n}\n\nexport interface UseLivePreviewResult {\n readonly data: PortableRenderPlan | undefined;\n}\n\nexport function useLivePreview(options: UseLivePreviewOptions): UseLivePreviewResult {\n const livePreview = useLivePreviewExperience({\n previewSessionOptions: options.previewSessionOptions,\n initialPayload: options.initialPayload,\n });\n\n return useExperiencePlan({\n payload: livePreview.data,\n initialPlan: options.initialPlan,\n resolveOptions: options.resolveOptions,\n });\n}\n"],"mappings":";AAKA,SAAS,gCAAgC;AACzC,SAAS,yBAA4D;AAa9D,SAAS,eAAe,SAAsD;AACnF,QAAM,cAAc,yBAAyB;AAAA,IAC3C,uBAAuB,QAAQ;AAAA,IAC/B,gBAAgB,QAAQ;AAAA,EAC1B,CAAC;AAED,SAAO,kBAAkB;AAAA,IACvB,SAAS,YAAY;AAAA,IACrB,aAAa,QAAQ;AAAA,IACrB,gBAAgB,QAAQ;AAAA,EAC1B,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-react",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "React adapter for Contentful Experiences — Server and Client renderers over a PortableRenderPlan",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,9 +30,13 @@
30
30
  "directory": "packages/adapter-react"
31
31
  },
32
32
  "dependencies": {
33
- "@contentful/experiences-client": "0.4.2",
34
- "@contentful/experiences-sdk-core": "0.8.2",
35
- "@contentful/experiences-design": "0.8.2"
33
+ "@contentful/experiences-client": "0.4.3",
34
+ "@contentful/experiences-sdk-core": "0.8.3",
35
+ "@contentful/experiences-design": "0.8.3",
36
+ "@contentful/experiences-live-preview": "0.1.2"
37
+ },
38
+ "devDependencies": {
39
+ "jsdom": "^30.0.1"
36
40
  },
37
41
  "peerDependencies": {
38
42
  "react": "^18.0.0 || ^19.0.0",