Skip to content

Commit f81fdf5

Browse files
committed
fix: live preview doc
1 parent 3e1eb9e commit f81fdf5

1 file changed

Lines changed: 34 additions & 47 deletions

File tree

docs/live-preview-configs.md

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The init data has following structure
66
- [`init(config: IConfig)`](#initconfig-iconfig)
77
- [`enable`](#enable)
88
- [`ssr`](#ssr)
9+
- [`mode`](#mode)
910
- [`editButton`](#editbutton)
1011
- [`cleanCslpOnProduction`](#cleancslponproduction)
1112
- [`stackDetails`](#stackdetails)
@@ -50,6 +51,18 @@ When you set the property to `false`, then app is rendered from the client side
5051

5152
> **Note:** For CSR mode, [stackSDK](#stacksdk) is required. Hence, we automatically switch mode to CSR when you pass this object. This config is provided to override the default behavior.
5253
54+
### `mode`
55+
56+
| type | default | optional |
57+
| ------- | --------- | -------- |
58+
| string | `preview` | Yes |
59+
60+
The `mode` property specifies whether the site is editable in the Live Preview or Visual Builder environment.
61+
62+
If set to `preview`, clicking the hovered edit button navigates to the Contentstack Live Preview panel.
63+
64+
If set to `builder`, clicking the Start Editing button navigates to the Contentstack Visual Builder. Note that the site will still function in the Live Preview panel even when set to 'builder'.
65+
5366
### `editButton`
5467
The editButton object allows you to manage the "Edit" button both within and outside the Live Preview portal. It offers the following features:
5568
- Enable/disable the "Edit" button
@@ -274,55 +287,29 @@ The `hash` property returns the live preview hash of the entry. It returns an em
274287
console.log(ContentstackLivePreview.hash); // "hash"
275288
```
276289

277-
## setConfigFromParams(config: ConstructorParameters<typeof URLSearchParams>[0])
278-
279-
The `setConfigFromParams` method allows you to set the configuration from the URL parameters. It accepts the URLSearchParams object as a parameter. This method is used in the SSR mode to set the live preview hash received from the URL.
280-
281-
**For example:**
282-
283-
```js
284-
console.log(ContentstackLivePreview.hash); // ""
285-
ContentstackLivePreview.setConfigFromParams(window.location.search); // https://example.com?live_preview=hash
286-
console.log(ContentstackLivePreview.hash); // "hash"
287-
```
288-
289-
## `getGatsbyDataFormat(sdkQuery: IStackSdk, prefix: string)`
290-
291-
Gatsby primarily fetches data using the [`gatsby-source-contentstack` plugin](https://www.gatsbyjs.com/plugins/gatsby-source-contentstack/). But, Live Preview currently works only on the [contentstack SDK](https://www.npmjs.com/package/contentstack).
290+
## config
292291

293-
Hence, for Gatsby, we fetch the data from the contentstack SDK and store it in React state. Post that, we re-render the page using the `onEntryChange()` method. As the data format is different for the gatsby-source-contentstack plugin, it returns a prefix and the entry name in Camel case. Hence, we use `getGatsbyDataFormat()` to change the entry's name.
294-
295-
The `getGatsbyDataFormat()` method accepts the Contentstack `Stack` object as the first parameter and the prefix as the second. The prefix is set inside the `gatsby-config.js` file. The default value set for the prefix is `contentstack`.
292+
The `config` property returns the following properties and their values:
296293

297-
**For example:**
294+
1. [`ssr`](#ssr)
295+
2. [`enable`](#enable)
296+
3. [`cleanCslpOnProduction`](#cleancslponproduction)
297+
4. `stackDetails`
298+
The stackDetails object provides information relevant to the live preview context, including:
298299

299-
```js
300-
const query = Stack.ContentType("your-contentype").Entry("entry-uid");
301-
302-
const formattedData = ContentstackLivePreview.getGatsbyDataFormat(
303-
query,
304-
"contentstack"
305-
);
306-
307-
setData(formattedData);
308-
```
309-
310-
**Difference in data:**
311-
312-
```js
313-
// not passed to function
314-
{
315-
"footer_lib": {
316-
"title": "footer",
317-
...
318-
}
319-
}
320-
321-
// passed to function with prefix as 'contentstack'
322-
{
323-
"contentstackFooterLib": {
324-
"title": "footer",
325-
...
326-
}
300+
```ts
301+
stackDetails {
302+
apiKey: string; // API key of the stack
303+
environment: string; // Environment in which the preview is running
304+
contentTypeUid: string; // UID of the content type
305+
entryUid: string; // UID of the specific entry
327306
}
328307
```
308+
5. [`clientUrlParams`](#clienturlparams)
309+
6. `windowType`: The windowType property determines the context of the parent window. It can have one of the following values:
310+
- `preview`: The site is loaded as an iframe within a Live Preview or Timeline preview environment.
311+
- `builder`: The site is loaded as an iframe within the Visual Builder environment.
312+
- `independent`: The site is loaded directly outside the Contentstack platform.
313+
7. [`hash`](#hash)
314+
8. [`editButton`](#editbutton)
315+
9. [`mode`](#mode)

0 commit comments

Comments
 (0)