Skip to content

Commit 7dbe992

Browse files
authored
Merge pull request #578 from contentstack/stage_v4
2 parents 1582dc8 + 07a10be commit 7dbe992

16 files changed

Lines changed: 1313 additions & 171 deletions

CHANGELOG.md

Lines changed: 204 additions & 65 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 96 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,126 @@
1-
# Contentstack Live Preview Utils SDK
1+
# @contentstack/live-preview-utils
22

3-
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest.
3+
[![npm](https://img.shields.io/npm/v/@contentstack/live-preview-utils.svg)](https://www.npmjs.com/package/@contentstack/live-preview-utils)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
45

5-
Contentstack provides the Live Preview Utils SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane. [Read More](https://www.contentstack.com/docs/content-managers/live-preview/).
6+
The **Live Preview Utils** package runs on your website and establishes a communication channel between the page and Contentstack. This enables live content updates, edit controls, and Visual Editor UI within the preview surface.
67

7-
# Installation
8+
This SDK is not a replacement for Contentstack delivery SDKs. Instead, it acts as a client-side bridge for preview and Visual Editor functionality.
89

9-
To install the package via npm, use the following command:
10+
## Where this SDK runs
11+
12+
The SDK works across multiple Contentstack preview and editing experiences:
13+
14+
- [**Live Preview**](https://www.contentstack.com/docs/content-managers/author-content/about-live-preview): Preview entries while your site loads inside the preview panel.
15+
- [**Timeline**](https://www.contentstack.com/docs/content-managers/timeline/about-timeline): Preview how your site appears across future dates and scheduled updates using the same Live Preview setup.
16+
- [**Visual Editor**](https://www.contentstack.com/docs/content-managers/visual-editor/about-visual-editor): Enable WYSIWYG editing with your site inside an iframe. Use [`mode: "builder"`](docs/live-preview-configs.md#mode) so “Start Editing” targets Visual Editor; the SDK still works when the same site is opened in Live Preview.
17+
- [**Studio**](https://www.contentstack.com/docs/studio/about-studio): Use alongside Studio to structure pages from reusable components, bind CMS data, and preview changes in real time. It is designed to work with [Live Preview and Visual Editor](https://www.contentstack.com/docs/studio/live-preview-and-visual-editing-with-studio) on your connected site.
18+
19+
## Requirements
20+
21+
- **Browser:** Initialize only on the client (`window` must exist). Avoid calling `init` during server-side rendering.
22+
- **SSR vs CSR:** Defaults assume SSR-friendly behavior. For **client-side rendering**, pass [`stackSdk`](docs/live-preview-configs.md#stacksdk) and set [`ssr: false`](docs/live-preview-configs.md#ssr) as described in the config reference.
23+
24+
## Installation
1025

1126
```bash
1227
npm install @contentstack/live-preview-utils
1328
```
1429

15-
Alternatively, if you want to include the package directly in your website HTML code, use the following command:
30+
### Load from a CDN (advanced)
31+
32+
Pin the version to match your app (update `4.3.0` when you upgrade):
1633

1734
```html
18-
<script type='module' crossorigin="anonymous">
19-
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@4.3.0';
20-
21-
ContentstackLivePreview.init({
22-
stackDetails: {
23-
apiKey: "your-stack-api-key",
24-
},
25-
});
35+
<script type="module" crossorigin="anonymous">
36+
import ContentstackLivePreview from "https://esm.sh/@contentstack/live-preview-utils@4.3.0";
37+
38+
ContentstackLivePreview.init({
39+
stackDetails: {
40+
apiKey: "your-stack-api-key",
41+
},
42+
});
2643
</script>
2744
```
28-
> [!NOTE]
29-
> This step involves incorporating the package into your HTML code and initializing it, eliminating the need for re-initialization in the subsequent step.
3045

46+
> [!TIP]
47+
> If you initialize the SDK using this snippet, do not initialize it again in your app bundle on the same page.
3148
32-
# Initializing the SDK
49+
## Quick start
3350

34-
### Live Preview Utils
35-
36-
Since the Live Preview Utils SDK is responsible for communication, you need to only initialize it.
37-
Use the following command to initialize the SDK:
51+
Initialize the SDK to enable communication between your site and Contentstack:
3852

3953
```javascript
4054
import ContentstackLivePreview from "@contentstack/live-preview-utils";
4155

4256
ContentstackLivePreview.init({
43-
stackDetails: {
44-
apiKey: "your-stack-api-key",
45-
},
57+
stackDetails: {
58+
apiKey: "your-stack-api-key",
59+
},
4660
});
4761
```
4862

63+
See the [`init` configuration properties](docs/live-preview-configs.md#initconfig-iconfig) in **[docs/live-preview-configs.md](docs/live-preview-configs.md)** for every option you can pass to `init`.
64+
65+
## Configuration
66+
67+
You can configure the SDK using the following options:
68+
69+
- [`enable`](docs/live-preview-configs.md#enable)
70+
- [`ssr`](docs/live-preview-configs.md#ssr)
71+
- [`mode`](docs/live-preview-configs.md#mode) (`preview` vs `builder`)
72+
- [`editButton`](docs/live-preview-configs.md#editbutton)
73+
- [`editInVisualBuilderButton`](docs/live-preview-configs.md#editinvisualbuilderbutton) (Start Editing outside Visual Editor)
74+
- [`cleanCslpOnProduction`](docs/live-preview-configs.md#cleancslponproduction)
75+
- [`stackDetails`](docs/live-preview-configs.md#stackdetails) ([`apiKey`](docs/live-preview-configs.md#apikey), [`environment`](docs/live-preview-configs.md#environment))
76+
- [`clientUrlParams`](docs/live-preview-configs.md#clienturlparams)[NA](docs/live-preview-configs.md#na-config) / [EU](docs/live-preview-configs.md#eu-config)
77+
- [`stackSdk`](docs/live-preview-configs.md#stacksdk)
78+
79+
Full tables and examples: **[docs/live-preview-configs.md](docs/live-preview-configs.md)**.
80+
81+
### Methods and properties
82+
83+
- [`onLiveEdit`](docs/live-preview-configs.md#onliveeditcallback---void): Trigger actions on live edits
84+
- [`onEntryChange`](docs/live-preview-configs.md#onentrychangecallback---void): Listen for entry updates
85+
- [`hash`](docs/live-preview-configs.md#hash): Access preview state identifier
86+
- [`config`](docs/live-preview-configs.md#config): Includes runtime context (for example Live Preview / Timeline preview, Visual Editor, or independent)
87+
88+
The [configs table of contents](docs/live-preview-configs.md#contentstack-live-preview-utils-sdk-configs) also lists `setConfigFromParams` and `getGatsbyDataFormat` for deeper workflows.
89+
90+
## Advanced: stripping the SDK at build time
91+
92+
Set `PURGE_PREVIEW_SDK` or `REACT_APP_PURGE_PREVIEW_SDK` to `"true"` during build to exclude preview code from production bundles.
93+
94+
**Note:** This reduces bundle size by replacing the SDK with a lightweight stub in production.
95+
96+
## Resources
97+
98+
- **Source:** [github.com/contentstack/live-preview-sdk](https://github.com/contentstack/live-preview-sdk)
99+
- **Typed API (local):** `npm run docs`
100+
101+
## Documentation and learning
102+
103+
### Developers
104+
105+
- [Set up Live Preview for your website](https://www.contentstack.com/docs/developers/set-up-live-preview/set-up-live-preview-for-your-website)
106+
- [How Live Preview works](https://www.contentstack.com/docs/developers/set-up-live-preview/how-live-preview-works)
107+
- [Preview API](https://www.contentstack.com/docs/developers/set-up-timeline/preview-api)
108+
- [Set up Timeline for your website](https://www.contentstack.com/docs/developers/set-up-timeline/set-up-timeline-for-your-website)
49109

50-
# License
110+
### Content managers
51111

52-
MIT License
112+
- [About Live Preview](https://www.contentstack.com/docs/content-managers/author-content/about-live-preview)
113+
- [Preview content across a Timeline](https://www.contentstack.com/docs/content-managers/timeline/preview-content-across-a-timeline)
114+
- [About Visual Editor](https://www.contentstack.com/docs/content-managers/visual-editor/about-visual-editor)
53115

54-
Copyright © 2021-2026 [Contentstack](https://www.contentstack.com/). All Rights Reserved
116+
### Studio
55117

56-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
118+
- [Studio](https://www.contentstack.com/docs/studio)
119+
- [Get started with Studio](https://www.contentstack.com/docs/studio/get-started-with-studio)
57120

58-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
121+
### Academy
59122

60-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
123+
- [Implementing Live Preview (course)](https://www.contentstack.com/academy/courses/implementing-live-preview)
124+
- [Contentstack Live Preview under the hood](https://www.contentstack.com/academy/content/contentstack-live-preview-under-the-hood)
125+
- [Understanding Timeline](https://www.contentstack.com/academy/content/understanding-timeline)
126+
- [Understanding Visual Editor](https://www.contentstack.com/academy/content/understanding-visual-builder)

main.mustache

Lines changed: 96 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,126 @@
1-
# Contentstack Live Preview Utils SDK
1+
# @contentstack/live-preview-utils
22

3-
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest.
3+
[![npm](https://img.shields.io/npm/v/@contentstack/live-preview-utils.svg)](https://www.npmjs.com/package/@contentstack/live-preview-utils)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
45

5-
Contentstack provides the Live Preview Utils SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane. [Read More](https://www.contentstack.com/docs/content-managers/live-preview/).
6+
The **Live Preview Utils** package runs on your website and establishes a communication channel between the page and Contentstack. This enables live content updates, edit controls, and Visual Editor UI within the preview surface.
67

7-
# Installation
8+
This SDK is not a replacement for Contentstack delivery SDKs. Instead, it acts as a client-side bridge for preview and Visual Editor functionality.
89

9-
To install the package via npm, use the following command:
10+
## Where this SDK runs
11+
12+
The SDK works across multiple Contentstack preview and editing experiences:
13+
14+
- [**Live Preview**](https://www.contentstack.com/docs/content-managers/author-content/about-live-preview): Preview entries while your site loads inside the preview panel.
15+
- [**Timeline**](https://www.contentstack.com/docs/content-managers/timeline/about-timeline): Preview how your site appears across future dates and scheduled updates using the same Live Preview setup.
16+
- [**Visual Editor**](https://www.contentstack.com/docs/content-managers/visual-editor/about-visual-editor): Enable WYSIWYG editing with your site inside an iframe. Use [`mode: "builder"`](docs/live-preview-configs.md#mode) so “Start Editing” targets Visual Editor; the SDK still works when the same site is opened in Live Preview.
17+
- [**Studio**](https://www.contentstack.com/docs/studio/about-studio): Use alongside Studio to structure pages from reusable components, bind CMS data, and preview changes in real time. It is designed to work with [Live Preview and Visual Editor](https://www.contentstack.com/docs/studio/live-preview-and-visual-editing-with-studio) on your connected site.
18+
19+
## Requirements
20+
21+
- **Browser:** Initialize only on the client (`window` must exist). Avoid calling `init` during server-side rendering.
22+
- **SSR vs CSR:** Defaults assume SSR-friendly behavior. For **client-side rendering**, pass [`stackSdk`](docs/live-preview-configs.md#stacksdk) and set [`ssr: false`](docs/live-preview-configs.md#ssr) as described in the config reference.
23+
24+
## Installation
1025

1126
```bash
1227
npm install @contentstack/live-preview-utils
1328
```
1429

15-
Alternatively, if you want to include the package directly in your website HTML code, use the following command:
30+
### Load from a CDN (advanced)
31+
32+
Pin the version to match your app (update `{{packageVersion}}` when you upgrade):
1633

1734
```html
18-
<script type='module' crossorigin="anonymous">
19-
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@{{packageVersion}}';
20-
21-
ContentstackLivePreview.init({
22-
stackDetails: {
23-
apiKey: "your-stack-api-key",
24-
},
25-
});
35+
<script type="module" crossorigin="anonymous">
36+
import ContentstackLivePreview from "https://esm.sh/@contentstack/live-preview-utils@{{packageVersion}}";
37+
38+
ContentstackLivePreview.init({
39+
stackDetails: {
40+
apiKey: "your-stack-api-key",
41+
},
42+
});
2643
</script>
2744
```
28-
> [!NOTE]
29-
> This step involves incorporating the package into your HTML code and initializing it, eliminating the need for re-initialization in the subsequent step.
3045

46+
> [!TIP]
47+
> If you initialize the SDK using this snippet, do not initialize it again in your app bundle on the same page.
3148

32-
# Initializing the SDK
49+
## Quick start
3350

34-
### Live Preview Utils
35-
36-
Since the Live Preview Utils SDK is responsible for communication, you need to only initialize it.
37-
Use the following command to initialize the SDK:
51+
Initialize the SDK to enable communication between your site and Contentstack:
3852

3953
```javascript
4054
import ContentstackLivePreview from "@contentstack/live-preview-utils";
4155

4256
ContentstackLivePreview.init({
43-
stackDetails: {
44-
apiKey: "your-stack-api-key",
45-
},
57+
stackDetails: {
58+
apiKey: "your-stack-api-key",
59+
},
4660
});
4761
```
4862

63+
See the [`init` configuration properties](docs/live-preview-configs.md#initconfig-iconfig) in **[docs/live-preview-configs.md](docs/live-preview-configs.md)** for every option you can pass to `init`.
64+
65+
## Configuration
66+
67+
You can configure the SDK using the following options:
68+
69+
- [`enable`](docs/live-preview-configs.md#enable)
70+
- [`ssr`](docs/live-preview-configs.md#ssr)
71+
- [`mode`](docs/live-preview-configs.md#mode) (`preview` vs `builder`)
72+
- [`editButton`](docs/live-preview-configs.md#editbutton)
73+
- [`editInVisualBuilderButton`](docs/live-preview-configs.md#editinvisualbuilderbutton) (Start Editing outside Visual Editor)
74+
- [`cleanCslpOnProduction`](docs/live-preview-configs.md#cleancslponproduction)
75+
- [`stackDetails`](docs/live-preview-configs.md#stackdetails) ([`apiKey`](docs/live-preview-configs.md#apikey), [`environment`](docs/live-preview-configs.md#environment))
76+
- [`clientUrlParams`](docs/live-preview-configs.md#clienturlparams) — [NA](docs/live-preview-configs.md#na-config) / [EU](docs/live-preview-configs.md#eu-config)
77+
- [`stackSdk`](docs/live-preview-configs.md#stacksdk)
78+
79+
Full tables and examples: **[docs/live-preview-configs.md](docs/live-preview-configs.md)**.
80+
81+
### Methods and properties
82+
83+
- [`onLiveEdit`](docs/live-preview-configs.md#onliveeditcallback---void): Trigger actions on live edits
84+
- [`onEntryChange`](docs/live-preview-configs.md#onentrychangecallback---void): Listen for entry updates
85+
- [`hash`](docs/live-preview-configs.md#hash): Access preview state identifier
86+
- [`config`](docs/live-preview-configs.md#config): Includes runtime context (for example Live Preview / Timeline preview, Visual Editor, or independent)
87+
88+
The [configs table of contents](docs/live-preview-configs.md#contentstack-live-preview-utils-sdk-configs) also lists `setConfigFromParams` and `getGatsbyDataFormat` for deeper workflows.
89+
90+
## Advanced: stripping the SDK at build time
91+
92+
Set `PURGE_PREVIEW_SDK` or `REACT_APP_PURGE_PREVIEW_SDK` to `"true"` during build to exclude preview code from production bundles.
93+
94+
**Note:** This reduces bundle size by replacing the SDK with a lightweight stub in production.
95+
96+
## Resources
97+
98+
- **Source:** [github.com/contentstack/live-preview-sdk](https://github.com/contentstack/live-preview-sdk)
99+
- **Typed API (local):** `npm run docs`
100+
101+
## Documentation and learning
102+
103+
### Developers
104+
105+
- [Set up Live Preview for your website](https://www.contentstack.com/docs/developers/set-up-live-preview/set-up-live-preview-for-your-website)
106+
- [How Live Preview works](https://www.contentstack.com/docs/developers/set-up-live-preview/how-live-preview-works)
107+
- [Preview API](https://www.contentstack.com/docs/developers/set-up-timeline/preview-api)
108+
- [Set up Timeline for your website](https://www.contentstack.com/docs/developers/set-up-timeline/set-up-timeline-for-your-website)
49109

50-
# License
110+
### Content managers
51111

52-
MIT License
112+
- [About Live Preview](https://www.contentstack.com/docs/content-managers/author-content/about-live-preview)
113+
- [Preview content across a Timeline](https://www.contentstack.com/docs/content-managers/timeline/preview-content-across-a-timeline)
114+
- [About Visual Editor](https://www.contentstack.com/docs/content-managers/visual-editor/about-visual-editor)
53115

54-
Copyright © 2021-{{currentYear}} [Contentstack](https://www.contentstack.com/). All Rights Reserved
116+
### Studio
55117

56-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
118+
- [Studio](https://www.contentstack.com/docs/studio)
119+
- [Get started with Studio](https://www.contentstack.com/docs/studio/get-started-with-studio)
57120

58-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
121+
### Academy
59122

60-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
123+
- [Implementing Live Preview (course)](https://www.contentstack.com/academy/courses/implementing-live-preview)
124+
- [Contentstack Live Preview under the hood](https://www.contentstack.com/academy/content/contentstack-live-preview-under-the-hood)
125+
- [Understanding Timeline](https://www.contentstack.com/academy/content/understanding-timeline)
126+
- [Understanding Visual Editor](https://www.contentstack.com/academy/content/understanding-visual-builder)

mustache.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const MUSTACHE_MAIN_DIR = './main.mustache';
1111
*/
1212
const DATA = {
1313
packageVersion: packageJson.version,
14-
currentYear: new Date().getFullYear(),
1514
};
1615
function generateReadMe() {
1716

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/live-preview-utils",
3-
"version": "4.3.0",
3+
"version": "4.4.0",
44
"description": "Contentstack provides the Live Preview SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane.",
55
"type": "module",
66
"types": "dist/legacy/index.d.ts",

0 commit comments

Comments
 (0)