@contentful/experiences-react 0.8.2 → 0.8.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.8.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.8.2 (2026-09-10)
2
16
 
3
17
  ### 🧱 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
 
@@ -38,6 +38,50 @@ type ExperienceOptions, ClientOptions, ResolveOptions, CreateClientOptions
38
38
  resolveExperience(payload, config, opts?) // Async; walks payload, runs resolveData, returns a PortableRenderPlan
39
39
  ```
40
40
 
41
+ ### Live preview
42
+
43
+ Use `useLivePreview` when the app should subscribe to Preview Session updates,
44
+ resolve each payload, and render the resulting plan from `data`:
45
+
46
+ ```tsx
47
+ const livePreview = useLivePreview({
48
+ previewSessionOptions,
49
+ initialPayload,
50
+ initialPlan,
51
+ resolveOptions: { config: experienceConfig },
52
+ });
53
+
54
+ <ClientExperienceRenderer experience={livePreview.data} config={experienceConfig} />;
55
+ ```
56
+
57
+ For separate access to the raw payload and rendered plan, use
58
+ `useLivePreviewExperience` and `useExperiencePlan`:
59
+
60
+ ```tsx
61
+ const livePreview = useLivePreviewExperience({
62
+ previewSessionOptions: {
63
+ spaceId,
64
+ environmentId,
65
+ previewToken,
66
+ sessionId,
67
+ },
68
+ initialPayload,
69
+ });
70
+
71
+ const plan = useExperiencePlan({
72
+ payload: livePreview.data,
73
+ initialPlan,
74
+ resolveOptions: { config: experienceConfig },
75
+ });
76
+
77
+ <ClientExperienceRenderer experience={plan.data} config={experienceConfig} />;
78
+ ```
79
+
80
+ `useLivePreviewExperience` returns the latest raw Experience payload.
81
+ `initialPayload` seeds the first value. `useExperiencePlan` turns that payload
82
+ into the `PortableRenderPlan` consumed by the renderer and keeps the current rendered
83
+ experience while an update is being resolved.
84
+
41
85
  ### Renderers
42
86
 
43
87
  ```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, PreviewSessionOptions } 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,9 @@ 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";
10
13
  import { useExperience, useContentfulComponent, useContentfulExperienceTemplate } from "./context";
11
14
  import { useDesignValues } from "./use-design-values";
12
15
  import { toCss } from "./design-utils";
@@ -72,6 +75,9 @@ export {
72
75
  useContentfulComponent,
73
76
  useContentfulExperienceTemplate,
74
77
  useDesignValues,
75
- useExperience
78
+ useExperience,
79
+ useExperiencePlan,
80
+ useLivePreview,
81
+ useLivePreviewExperience
76
82
  };
77
83
  //# 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 PreviewSessionOptions,\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;AAYlC,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,41 @@
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?.sessionHost,
18
+ previewSessionOptions?.debug
19
+ ]);
20
+ const emptySource = useMemo(
21
+ () => ({
22
+ getSnapshot: () => initialPayload,
23
+ subscribe: () => () => void 0
24
+ }),
25
+ [initialPayload]
26
+ );
27
+ const source = client ?? emptySource;
28
+ const data = useSyncExternalStore(source.subscribe, source.getSnapshot, source.getSnapshot);
29
+ useEffect(() => {
30
+ if (client === void 0) {
31
+ sendPreviewStatus("static");
32
+ return;
33
+ }
34
+ return client.subscribeStatus(sendPreviewStatus);
35
+ }, [client]);
36
+ return { data };
37
+ }
38
+ export {
39
+ useLivePreviewExperience
40
+ };
41
+ //# 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?.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,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.3",
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.1"
37
+ },
38
+ "devDependencies": {
39
+ "jsdom": "^30.0.1"
36
40
  },
37
41
  "peerDependencies": {
38
42
  "react": "^18.0.0 || ^19.0.0",