Skip to content

Commit ba1c8d6

Browse files
authored
Merge pull request #323 from contentstack/stage_v3
3.1.0
2 parents 944c02c + f81fdf5 commit ba1c8d6

89 files changed

Lines changed: 4818 additions & 10727 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.husky/commit-msg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit "$1"
5+
npm run build
6+
npx tsx mustache.ts
7+
git add README.md
8+
npx lint-staged

.husky/pre-commit

Lines changed: 0 additions & 7 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1223 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Alternatively, if you want to include the package directly in your website HTML
1616

1717
```html
1818
<script type='module' integrity='sha384-9M4o9H23Ax5ZTzsMRLgdlFBYk2hy+ub6XDiZhHWJjfebQ+MZ9iZw+GNep9ac0uFV' crossorigin="anonymous">
19-
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@3.0.1';
19+
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@3.1.0';
2020
2121
ContentstackLivePreview.init({
2222
stackDetails: {

changelog-template.hbs

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# Changelog
2+
3+
{{!--
4+
Introduction
5+
• This template tries to follow conventional commits format https://www.conventionalcommits.org/en/v1.0.0/
6+
• The template uses regex to filter commit types into their own headings (this is more than just fixes and features headings)
7+
• It also uses the replaceText function in package.json to remove the commit type text from the message, because the headers are shown instead.
8+
• The text 'Breaking:' or 'Breaking changes:' can be located anywhere in the commit.
9+
• The types feat:, fix:, chore:, docs:, refactor:, test:, style:, perf: must be at the beginning of the commit subject with an : on end.
10+
• They can optionally have a scope set to outline the module or component that is affected eg feat(bldAssess):
11+
• There is a short hash on the end of every commit that is currently commented out so that change log did not grow too long (due to some system's file size limitations). You can uncomment if you wish [`{{shorthash}}`]({{href}})
12+
13+
Example Definitions
14+
• feat: A new feature
15+
• fix: A bug fix
16+
• perf: A code change that improves performance
17+
• refactor: A code change that neither fixes a bug nor adds a feature
18+
• style: Changes that do not affect the meaning of the code (white-space, formatting, spelling mistakes, missing semi-colons, etc)
19+
• test: Adding missing tests or correcting existing tests
20+
• docs: Adding/updating documentation
21+
• chore: Something like updating a library version, or moving files to be in a better location and updating all file refs
22+
--}}
23+
24+
25+
{{!-- In package.json need to add this to remove label text from the change log output (because the markdown headers are now used to group them).
26+
NOTES • Individual brackets have been escaped twice to be Json compliant.
27+
• For items that define a scope eg feat(bldAssess): We remove the 1st bracket and then re-add it so we can select the right piece of text
28+
{
29+
"name": "my-awesome-package",
30+
"auto-changelog": {
31+
"replaceText": {
32+
"([bB]reaking:)": "",
33+
"([bB]reaking change:)": "",
34+
"(^[bB]uild:)": "",
35+
"(^[bB]uild\\()": "\\(",
36+
"(^[dD]eprecate:)": "",
37+
"(^[dD]eprecate\\()": "\\(",
38+
"(^[fF]eat:)": "",
39+
"(^[fF]eat\\()": "\\(",
40+
"(^[fF]ix:)": "",
41+
"(^[fF]ix\\()": "\\(",
42+
"(^[cC]hore:)": "",
43+
"(^[cC]hore\\()": "\\(",
44+
"(^[dD]ocs:)": "",
45+
"(^[dD]ocs\\()": "\\(",
46+
"(^[rR]efactor:)": "",
47+
"(^[rR]efactor\\()": "\\(",
48+
"(^[tT]est:)": "",
49+
"(^[tT]est\\()": "\\(",
50+
"(^[sS]tyle:)": "",
51+
"(^[sS]tyle\\()": "\\(",
52+
"(^[pP]erf:)": "",
53+
"(^[pP]erf\\()": "\\("
54+
}
55+
}
56+
}
57+
--}}
58+
59+
{{!--
60+
Regex reminders
61+
^ = starts with
62+
\( = ( character (otherwise it is interpreted as a regex lookup group)
63+
* = zero or more of the previous character
64+
\s = whitespace
65+
. = any character except newline
66+
| = or
67+
[aA] = character a or character A
68+
--}}
69+
70+
71+
{{#each releases}}
72+
{{#if href}}
73+
## [{{title}}]({{href}})
74+
{{else}}
75+
## {{title}}
76+
{{/if}}
77+
78+
> {{niceDate}}
79+
80+
{{#if summary}}
81+
{{summary}}
82+
{{/if}}
83+
84+
{{! List commits that fix a given issues}}
85+
{{#each fixes}}
86+
- {{#if commit.breaking}}**Breaking change:** {{/if}}{{commit.subject}}{{#each fixes}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}}){{/each}}
87+
{{/each}}
88+
89+
{{! List merge commits with 'breaking:' or 'Breaking change:' anywhere in the message under a heading}}
90+
{{#commit-list merges heading='### Breaking Changes :warning:' message='[bB]reaking [cC]hange:|[bB]reaking:' exclude='\[skip-changelog\]'}}
91+
- {{message}} @{{author}} <!--[`#{{id}}`]({{href}}) -->
92+
{{/commit-list}}
93+
94+
{{! List commits organised under a heading, but not those already listed in the breaking section }}
95+
{{#commit-list merges heading='### Build' message='^[bB]uild:|^[bB]uild\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
96+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
97+
{{/commit-list}}
98+
99+
{{#commit-list merges heading='### Deprecated Features' message='^[dD]eprecate:|^[dD]eprecate\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
100+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
101+
{{/commit-list}}
102+
103+
{{#commit-list merges heading='### New Features' message='^[fF]eat:|^[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
104+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
105+
{{/commit-list}}
106+
107+
{{#commit-list merges heading='### Fixes' message='^[fF]ix:|^[fF]ix\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
108+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
109+
{{/commit-list}}
110+
111+
{{#commit-list merges heading='### Chores And Housekeeping' message='^[cC]hore:|^[cC]hore\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
112+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
113+
{{/commit-list}}
114+
115+
{{#commit-list merges heading='### Documentation Changes' message='^[dD]ocs:|^[dD]ocs\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
116+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
117+
{{/commit-list}}
118+
119+
{{#commit-list merges heading='### Refactoring and Updates' message='^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
120+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
121+
{{/commit-list}}
122+
123+
{{#commit-list merges heading='### Changes to Test Assests' message='^[tT]est:|^[tT]est\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
124+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
125+
{{/commit-list}}
126+
127+
{{#commit-list merges heading='### Tidying of Code eg Whitespace' message='^[sS]tyle:|^[sS]tyle\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
128+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
129+
{{/commit-list}}
130+
131+
{{#commit-list merges heading='### Performance Improvements' message='^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
132+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
133+
{{/commit-list}}
134+
135+
{{#commit-list merges heading='### CI Improvements' message='^[cC][iI]:|^[cC][iI]\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
136+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
137+
{{/commit-list}}
138+
139+
{{#commit-list merges heading='### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[bB]uild:|^[bB]uild ?\(|^[dD]eprecate:|^[dD]eprecate ?\(|^[fF]eat:|^[fF]eat ?\(|^[fF]ix:|^[fF]ix ?\(|^[cC]hore:|^[cC]hore ?\(|^[cC][iI]:|^[cC][iI] ?\(|^[dD]ocs:|^[dD]ocs ?\(|^[rR]efactor:|^[rR]efactor ?\(|^[tT]est:|^[tT]est ?\(|^[sS]tyle:|^[sS]tyle ?\(|^[pP]erf:|^[pP]erf ?\(|\[skip-changelog\]'}}
140+
- {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}})
141+
{{/commit-list}}
142+
143+
{{! List commits with 'breaking:' or 'Breaking change:' anywhere in the message under a heading}}
144+
{{#commit-list commits heading='### Breaking Changes :warning:' message='[bB]reaking [cC]hange:|[bB]reaking:' exclude='\[skip-changelog\]'}}
145+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
146+
{{/commit-list}}
147+
148+
{{! List commits organised under a heading, but not those already listed in the breaking section }}
149+
{{#commit-list commits heading='### Build' message='^[bB]uild:|^[bB]uild\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
150+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
151+
{{/commit-list}}
152+
153+
{{#commit-list commits heading='### Deprecated Features' message='^[dD]eprecate:|^[dD]eprecate\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
154+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
155+
{{/commit-list}}
156+
157+
{{#commit-list commits heading='### New Features' message='^[fF]eat:|^[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
158+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
159+
{{/commit-list}}
160+
161+
{{#commit-list commits heading='### Fixes' message='^[fF]ix:|^[fF]ix\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
162+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
163+
{{/commit-list}}
164+
165+
{{#commit-list commits heading='### Chores And Housekeeping' message='^[cC]hore:|^[cC]hore\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
166+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
167+
{{/commit-list}}
168+
169+
{{#commit-list commits heading='### Documentation Changes' message='^[dD]ocs:|^[dD]ocs\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
170+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
171+
{{/commit-list}}
172+
173+
{{#commit-list commits heading='### Refactoring and Updates' message='^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
174+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
175+
{{/commit-list}}
176+
177+
{{#commit-list commits heading='### Changes to Test Assests' message='^[tT]est:|^[tT]est\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
178+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
179+
{{/commit-list}}
180+
181+
{{#commit-list commits heading='### Tidying of Code eg Whitespace' message='^[sS]tyle:|^[sS]tyle\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
182+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
183+
{{/commit-list}}
184+
185+
{{#commit-list commits heading='### Performance Improvements' message='^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
186+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
187+
{{/commit-list}}
188+
189+
{{#commit-list commits heading='### CI Improvements' message='^[cC][iI]:|^[cC][iI]\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}}
190+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
191+
{{/commit-list}}
192+
193+
{{#commit-list commits heading='### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[bB]uild:|^[bB]uild ?\(|^[dD]eprecate:|^[dD]eprecate ?\(|^[fF]eat:|^[fF]eat ?\(|^[fF]ix:|^[fF]ix ?\(|^[cC]hore:|^[cC]hore ?\(|^[cC][iI]:|^[cC][iI] ?\(|^[dD]ocs:|^[dD]ocs ?\(|^[rR]efactor:|^[rR]efactor ?\(|^[tT]est:|^[tT]est ?\(|^[sS]tyle:|^[sS]tyle ?\(|^[pP]erf:|^[pP]erf ?\(|\[skip-changelog\]'}}
194+
- {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}})
195+
{{/commit-list}}
196+
197+
{{/each}}

commitlint.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import configConventional from '@commitlint/config-conventional';
2+
3+
export default {
4+
extends: [configConventional],
5+
};

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)