Skip to content

Commit f513fe5

Browse files
committed
Merge branch 'main' of https://github.com/contentstack/live-preview-sdk into VE-4232
2 parents f89064c + 86a52c4 commit f513fe5

63 files changed

Lines changed: 6776 additions & 185 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish Alpha Package to npmjs
2+
on:
3+
push:
4+
branches:
5+
- "alpha/*"
6+
tags:
7+
- "v*.*.*-alpha.*"
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
# Setup Node.js and npm registry
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: "18"
22+
registry-url: "https://registry.npmjs.org"
23+
always-auth: true
24+
25+
- run: npm ci
26+
- run: npm run build
27+
28+
# Publish package to npm under the "alpha" tag
29+
- run: npm publish --tag alpha --provenance
30+
env:
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 159 additions & 15 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ npm install @contentstack/live-preview-utils
1515
Alternatively, if you want to include the package directly in your website HTML code, use the following command:
1616

1717
```html
18-
<script type='module' integrity='sha384-LQQFdnInqHR0YPq3ypmbejKtYGi+kb43FlR7STQHgZtSrkLXPrN1eovxsdlxofuL' crossorigin="anonymous">
19-
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@3.1.3';
18+
<script type='module' integrity='sha384-Q1kNLAr9TbfZ9lsUUXH&#x2F;vW79LERzfbYJc7aLNSYjKFLzBZQDp&#x2F;Jk09+ADHo9mhEq' crossorigin="anonymous">
19+
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@3.2.0';
2020
2121
ContentstackLivePreview.init({
2222
stackDetails: {

package-lock.json

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

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/live-preview-utils",
3-
"version": "3.1.3",
3+
"version": "3.2.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",
@@ -28,7 +28,7 @@
2828
"test": "vitest",
2929
"test:once": "vitest run",
3030
"test:coverage": "vitest --coverage",
31-
"dev": "tsup --watch",
31+
"dev": "NODE_OPTIONS='--max-old-space-size=16384' tsup --watch",
3232
"prepare": "husky",
3333
"lint": "eslint src",
3434
"lint:fix": "eslint --fix",
@@ -89,7 +89,10 @@
8989
"@preact/compat": "17.1.2",
9090
"@preact/signals": "1.2.2",
9191
"classnames": "^2.5.1",
92+
"dayjs": "^1.11.13",
9293
"deepsignal": "^1.5.0",
94+
"dompurify": "^3.2.3",
95+
"get-xpath": "^3.2.0",
9396
"goober": "^2.1.14",
9497
"lodash-es": "^4.17.21",
9598
"mustache": "^4.2.0",

src/configManager/config.default.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,20 @@ export function getDefaultConfig(): IConfig {
9595
elements: {
9696
highlightedElement: null,
9797
},
98+
collab: {
99+
enable: false,
100+
fromShare: false,
101+
pauseFeedback: false,
102+
isFeedbackMode: false,
103+
inviteMetadata: {
104+
currentUser: {
105+
email: "",
106+
uid: "",
107+
},
108+
users: [],
109+
inviteUid: "",
110+
},
111+
payload: [],
112+
},
98113
};
99114
}

src/index.ts

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,64 @@
11
import ContentstackLivePreviewHOC from "./preview/contentstack-live-preview-HOC";
2-
32
import { IStackSdk as ExternalStackSdkType } from "./types/types";
3+
4+
import {
5+
OnEntryChangeCallback,
6+
OnEntryChangeCallbackUID,
7+
OnEntryChangeConfig,
8+
} from "./livePreview/types/onEntryChangeCallback.type";
9+
410
export type IStackSdk = ExternalStackSdkType;
5-
class LightLivePreviewHoC implements ContentstackLivePreviewHOC {
6-
static init() {}
711

8-
get hash() {
12+
class LightLivePreviewHoC {
13+
private static previewConstructors = {};
14+
private static onEntryChangeCallbacks = {};
15+
16+
static init() {
17+
if (typeof window === "undefined") {
18+
return Promise.resolve(LightLivePreviewHoC.previewConstructors);
19+
}
20+
21+
return LightLivePreviewHoC.initializePreview();
22+
}
23+
24+
private static initializePreview() {
25+
LightLivePreviewHoC.previewConstructors = {
26+
livePreview: {},
27+
visualBuilder: {},
28+
};
29+
30+
LightLivePreviewHoC.onEntryChangeCallbacks = {};
31+
32+
return Promise.resolve(LightLivePreviewHoC.previewConstructors);
33+
}
34+
35+
static get hash() {
936
return "";
1037
}
1138

12-
static onEntryChange(callback: (...args: any[]) => void) {
13-
return callback();
39+
static get config() {
40+
return {};
1441
}
1542

16-
static onLiveEdit() {
17-
// intentionally empty
43+
static isInitialized() {
44+
return false;
45+
}
46+
47+
static onEntryChange(
48+
callback: OnEntryChangeCallback,
49+
config: OnEntryChangeConfig = {}
50+
): OnEntryChangeCallbackUID {
51+
const { skipInitialRender = false } = config;
52+
53+
if (!skipInitialRender) {
54+
callback();
55+
}
56+
57+
return "live-preview-id";
58+
}
59+
60+
static onLiveEdit(callback: OnEntryChangeCallback) {
61+
return "live-preview-id";
1862
}
1963

2064
static unsubscribeOnEntryChange() {
@@ -26,8 +70,10 @@ class LightLivePreviewHoC implements ContentstackLivePreviewHOC {
2670
}
2771
}
2872

29-
// export const ContentstackLivePreview: ContentstackLivePreviewHOC =
30-
// ContentstackLivePreviewHOC;
73+
const ContentstackLivePreview =
74+
process.env.PURGE_PREVIEW_SDK || process.env.REACT_APP_PURGE_PREVIEW_SDK
75+
? LightLivePreviewHoC
76+
: ContentstackLivePreviewHOC;
3177

3278
export const VB_EmptyBlockParentClass = "visual-builder__empty-block-parent";
33-
export default ContentstackLivePreviewHOC;
79+
export default ContentstackLivePreview;

0 commit comments

Comments
 (0)