@contentstack/live-preview-utils 3.4.0 → 4.0.1
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/README.md +1 -1
- package/dist/legacy/common/inIframe.cjs +15 -2
- package/dist/legacy/common/inIframe.cjs.map +1 -1
- package/dist/legacy/common/inIframe.d.cts +2 -1
- package/dist/legacy/common/inIframe.d.ts +2 -1
- package/dist/legacy/common/inIframe.js +13 -1
- package/dist/legacy/common/inIframe.js.map +1 -1
- package/dist/legacy/light-sdk.cjs +1 -1
- package/dist/legacy/light-sdk.js +1 -1
- package/dist/legacy/livePreview/editButton/editButton.cjs +1 -1
- package/dist/legacy/livePreview/editButton/editButton.cjs.map +1 -1
- package/dist/legacy/livePreview/editButton/editButton.js +2 -2
- package/dist/legacy/livePreview/editButton/editButton.js.map +1 -1
- package/dist/legacy/livePreview/eventManager/livePreviewEventManager.cjs +7 -2
- package/dist/legacy/livePreview/eventManager/livePreviewEventManager.cjs.map +1 -1
- package/dist/legacy/livePreview/eventManager/livePreviewEventManager.js +7 -2
- package/dist/legacy/livePreview/eventManager/livePreviewEventManager.js.map +1 -1
- package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.cjs +44 -8
- package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.cjs.map +1 -1
- package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.js +46 -8
- package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.js.map +1 -1
- package/dist/legacy/livePreview/eventManager/types/livePreviewPostMessageEvent.type.cjs +15 -0
- package/dist/legacy/livePreview/eventManager/types/livePreviewPostMessageEvent.type.cjs.map +1 -1
- package/dist/legacy/livePreview/eventManager/types/livePreviewPostMessageEvent.type.d.cts +11 -1
- package/dist/legacy/livePreview/eventManager/types/livePreviewPostMessageEvent.type.d.ts +11 -1
- package/dist/legacy/livePreview/eventManager/types/livePreviewPostMessageEvent.type.js +10 -0
- package/dist/legacy/livePreview/eventManager/types/livePreviewPostMessageEvent.type.js.map +1 -1
- package/dist/legacy/preview/contentstack-live-preview-HOC.cjs +1 -1
- package/dist/legacy/preview/contentstack-live-preview-HOC.js +1 -1
- package/dist/legacy/utils/index.cjs +10 -0
- package/dist/legacy/utils/index.cjs.map +1 -1
- package/dist/legacy/utils/index.d.cts +2 -1
- package/dist/legacy/utils/index.d.ts +2 -1
- package/dist/legacy/utils/index.js +9 -0
- package/dist/legacy/utils/index.js.map +1 -1
- package/dist/legacy/visualBuilder/components/FieldToolbar.cjs +4 -2
- package/dist/legacy/visualBuilder/components/FieldToolbar.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/FieldToolbar.d.cts +3 -1
- package/dist/legacy/visualBuilder/components/FieldToolbar.d.ts +3 -1
- package/dist/legacy/visualBuilder/components/FieldToolbar.js +4 -2
- package/dist/legacy/visualBuilder/components/FieldToolbar.js.map +1 -1
- package/dist/legacy/visualBuilder/components/VisualBuilder.cjs +3 -1
- package/dist/legacy/visualBuilder/components/VisualBuilder.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/VisualBuilder.js +4 -2
- package/dist/legacy/visualBuilder/components/VisualBuilder.js.map +1 -1
- package/dist/legacy/visualBuilder/components/fieldLabelWrapper.cjs +6 -4
- package/dist/legacy/visualBuilder/components/fieldLabelWrapper.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/fieldLabelWrapper.js +6 -4
- package/dist/legacy/visualBuilder/components/fieldLabelWrapper.js.map +1 -1
- package/dist/legacy/visualBuilder/components/index.cjs +2 -1
- package/dist/legacy/visualBuilder/components/index.cjs.map +1 -1
- package/dist/legacy/visualBuilder/components/index.js +3 -2
- package/dist/legacy/visualBuilder/components/index.js.map +1 -1
- package/dist/legacy/visualBuilder/generators/generateToolbar.cjs +6 -4
- package/dist/legacy/visualBuilder/generators/generateToolbar.cjs.map +1 -1
- package/dist/legacy/visualBuilder/generators/generateToolbar.js +6 -4
- package/dist/legacy/visualBuilder/generators/generateToolbar.js.map +1 -1
- package/dist/legacy/visualBuilder/listeners/mouseClick.cjs +16 -17
- package/dist/legacy/visualBuilder/listeners/mouseClick.cjs.map +1 -1
- package/dist/legacy/visualBuilder/listeners/mouseClick.js +16 -17
- package/dist/legacy/visualBuilder/listeners/mouseClick.js.map +1 -1
- package/dist/legacy/visualBuilder/listeners/mouseHover.cjs +63 -58
- package/dist/legacy/visualBuilder/listeners/mouseHover.cjs.map +1 -1
- package/dist/legacy/visualBuilder/listeners/mouseHover.js +63 -58
- package/dist/legacy/visualBuilder/listeners/mouseHover.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.cjs +72 -0
- package/dist/legacy/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.cjs.map +1 -0
- package/dist/legacy/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.d.cts +14 -0
- package/dist/legacy/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.d.ts +14 -0
- package/dist/legacy/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.js +49 -0
- package/dist/legacy/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.js.map +1 -0
- package/dist/legacy/visualBuilder/utils/getEntryPermissions.cjs +2 -1
- package/dist/legacy/visualBuilder/utils/getEntryPermissions.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/getEntryPermissions.js +2 -1
- package/dist/legacy/visualBuilder/utils/getEntryPermissions.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/getWorkflowStageDetails.cjs +79 -0
- package/dist/legacy/visualBuilder/utils/getWorkflowStageDetails.cjs.map +1 -0
- package/dist/legacy/visualBuilder/utils/getWorkflowStageDetails.d.cts +18 -0
- package/dist/legacy/visualBuilder/utils/getWorkflowStageDetails.d.ts +18 -0
- package/dist/legacy/visualBuilder/utils/getWorkflowStageDetails.js +46 -0
- package/dist/legacy/visualBuilder/utils/getWorkflowStageDetails.js.map +1 -0
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.cjs +4 -3
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.js +4 -3
- package/dist/legacy/visualBuilder/utils/handleIndividualFields.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/isFieldDisabled.cjs +43 -14
- package/dist/legacy/visualBuilder/utils/isFieldDisabled.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/isFieldDisabled.d.cts +3 -12
- package/dist/legacy/visualBuilder/utils/isFieldDisabled.d.ts +3 -12
- package/dist/legacy/visualBuilder/utils/isFieldDisabled.js +43 -14
- package/dist/legacy/visualBuilder/utils/isFieldDisabled.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/types/postMessage.types.cjs +2 -0
- package/dist/legacy/visualBuilder/utils/types/postMessage.types.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/types/postMessage.types.d.cts +2 -0
- package/dist/legacy/visualBuilder/utils/types/postMessage.types.d.ts +2 -0
- package/dist/legacy/visualBuilder/utils/types/postMessage.types.js +2 -0
- package/dist/legacy/visualBuilder/utils/types/postMessage.types.js.map +1 -1
- package/dist/legacy/visualBuilder/utils/updateFocussedState.cjs +6 -4
- package/dist/legacy/visualBuilder/utils/updateFocussedState.cjs.map +1 -1
- package/dist/legacy/visualBuilder/utils/updateFocussedState.js +6 -4
- package/dist/legacy/visualBuilder/utils/updateFocussedState.js.map +1 -1
- package/dist/legacy/visualBuilder/visualBuilder.style.cjs +3 -3
- package/dist/legacy/visualBuilder/visualBuilder.style.cjs.map +1 -1
- package/dist/legacy/visualBuilder/visualBuilder.style.js +3 -3
- package/dist/legacy/visualBuilder/visualBuilder.style.js.map +1 -1
- package/dist/modern/common/inIframe.cjs +15 -2
- package/dist/modern/common/inIframe.cjs.map +1 -1
- package/dist/modern/common/inIframe.d.cts +2 -1
- package/dist/modern/common/inIframe.d.ts +2 -1
- package/dist/modern/common/inIframe.js +13 -1
- package/dist/modern/common/inIframe.js.map +1 -1
- package/dist/modern/light-sdk.cjs +1 -1
- package/dist/modern/light-sdk.js +1 -1
- package/dist/modern/livePreview/editButton/editButton.cjs +1 -1
- package/dist/modern/livePreview/editButton/editButton.cjs.map +1 -1
- package/dist/modern/livePreview/editButton/editButton.js +2 -2
- package/dist/modern/livePreview/editButton/editButton.js.map +1 -1
- package/dist/modern/livePreview/eventManager/livePreviewEventManager.cjs +7 -2
- package/dist/modern/livePreview/eventManager/livePreviewEventManager.cjs.map +1 -1
- package/dist/modern/livePreview/eventManager/livePreviewEventManager.js +7 -2
- package/dist/modern/livePreview/eventManager/livePreviewEventManager.js.map +1 -1
- package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.cjs +43 -8
- package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.cjs.map +1 -1
- package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.js +45 -8
- package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.js.map +1 -1
- package/dist/modern/livePreview/eventManager/types/livePreviewPostMessageEvent.type.cjs +15 -0
- package/dist/modern/livePreview/eventManager/types/livePreviewPostMessageEvent.type.cjs.map +1 -1
- package/dist/modern/livePreview/eventManager/types/livePreviewPostMessageEvent.type.d.cts +11 -1
- package/dist/modern/livePreview/eventManager/types/livePreviewPostMessageEvent.type.d.ts +11 -1
- package/dist/modern/livePreview/eventManager/types/livePreviewPostMessageEvent.type.js +10 -0
- package/dist/modern/livePreview/eventManager/types/livePreviewPostMessageEvent.type.js.map +1 -1
- package/dist/modern/preview/contentstack-live-preview-HOC.cjs +1 -1
- package/dist/modern/preview/contentstack-live-preview-HOC.js +1 -1
- package/dist/modern/utils/index.cjs +10 -0
- package/dist/modern/utils/index.cjs.map +1 -1
- package/dist/modern/utils/index.d.cts +2 -1
- package/dist/modern/utils/index.d.ts +2 -1
- package/dist/modern/utils/index.js +9 -0
- package/dist/modern/utils/index.js.map +1 -1
- package/dist/modern/visualBuilder/components/FieldToolbar.cjs +4 -2
- package/dist/modern/visualBuilder/components/FieldToolbar.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/FieldToolbar.d.cts +3 -1
- package/dist/modern/visualBuilder/components/FieldToolbar.d.ts +3 -1
- package/dist/modern/visualBuilder/components/FieldToolbar.js +4 -2
- package/dist/modern/visualBuilder/components/FieldToolbar.js.map +1 -1
- package/dist/modern/visualBuilder/components/VisualBuilder.cjs +3 -1
- package/dist/modern/visualBuilder/components/VisualBuilder.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/VisualBuilder.js +4 -2
- package/dist/modern/visualBuilder/components/VisualBuilder.js.map +1 -1
- package/dist/modern/visualBuilder/components/fieldLabelWrapper.cjs +6 -4
- package/dist/modern/visualBuilder/components/fieldLabelWrapper.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/fieldLabelWrapper.js +6 -4
- package/dist/modern/visualBuilder/components/fieldLabelWrapper.js.map +1 -1
- package/dist/modern/visualBuilder/components/index.cjs +2 -1
- package/dist/modern/visualBuilder/components/index.cjs.map +1 -1
- package/dist/modern/visualBuilder/components/index.js +3 -2
- package/dist/modern/visualBuilder/components/index.js.map +1 -1
- package/dist/modern/visualBuilder/generators/generateToolbar.cjs +6 -4
- package/dist/modern/visualBuilder/generators/generateToolbar.cjs.map +1 -1
- package/dist/modern/visualBuilder/generators/generateToolbar.js +6 -4
- package/dist/modern/visualBuilder/generators/generateToolbar.js.map +1 -1
- package/dist/modern/visualBuilder/listeners/mouseClick.cjs +16 -17
- package/dist/modern/visualBuilder/listeners/mouseClick.cjs.map +1 -1
- package/dist/modern/visualBuilder/listeners/mouseClick.js +16 -17
- package/dist/modern/visualBuilder/listeners/mouseClick.js.map +1 -1
- package/dist/modern/visualBuilder/listeners/mouseHover.cjs +63 -58
- package/dist/modern/visualBuilder/listeners/mouseHover.cjs.map +1 -1
- package/dist/modern/visualBuilder/listeners/mouseHover.js +63 -58
- package/dist/modern/visualBuilder/listeners/mouseHover.js.map +1 -1
- package/dist/modern/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.cjs +72 -0
- package/dist/modern/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.cjs.map +1 -0
- package/dist/modern/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.d.cts +14 -0
- package/dist/modern/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.d.ts +14 -0
- package/dist/modern/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.js +49 -0
- package/dist/modern/visualBuilder/utils/fetchEntryPermissionsAndStageDetails.js.map +1 -0
- package/dist/modern/visualBuilder/utils/getEntryPermissions.cjs +2 -1
- package/dist/modern/visualBuilder/utils/getEntryPermissions.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/getEntryPermissions.js +2 -1
- package/dist/modern/visualBuilder/utils/getEntryPermissions.js.map +1 -1
- package/dist/modern/visualBuilder/utils/getWorkflowStageDetails.cjs +78 -0
- package/dist/modern/visualBuilder/utils/getWorkflowStageDetails.cjs.map +1 -0
- package/dist/modern/visualBuilder/utils/getWorkflowStageDetails.d.cts +18 -0
- package/dist/modern/visualBuilder/utils/getWorkflowStageDetails.d.ts +18 -0
- package/dist/modern/visualBuilder/utils/getWorkflowStageDetails.js +45 -0
- package/dist/modern/visualBuilder/utils/getWorkflowStageDetails.js.map +1 -0
- package/dist/modern/visualBuilder/utils/handleIndividualFields.cjs +4 -3
- package/dist/modern/visualBuilder/utils/handleIndividualFields.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/handleIndividualFields.js +4 -3
- package/dist/modern/visualBuilder/utils/handleIndividualFields.js.map +1 -1
- package/dist/modern/visualBuilder/utils/isFieldDisabled.cjs +42 -13
- package/dist/modern/visualBuilder/utils/isFieldDisabled.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/isFieldDisabled.d.cts +3 -12
- package/dist/modern/visualBuilder/utils/isFieldDisabled.d.ts +3 -12
- package/dist/modern/visualBuilder/utils/isFieldDisabled.js +42 -13
- package/dist/modern/visualBuilder/utils/isFieldDisabled.js.map +1 -1
- package/dist/modern/visualBuilder/utils/types/postMessage.types.cjs +2 -0
- package/dist/modern/visualBuilder/utils/types/postMessage.types.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/types/postMessage.types.d.cts +2 -0
- package/dist/modern/visualBuilder/utils/types/postMessage.types.d.ts +2 -0
- package/dist/modern/visualBuilder/utils/types/postMessage.types.js +2 -0
- package/dist/modern/visualBuilder/utils/types/postMessage.types.js.map +1 -1
- package/dist/modern/visualBuilder/utils/updateFocussedState.cjs +6 -4
- package/dist/modern/visualBuilder/utils/updateFocussedState.cjs.map +1 -1
- package/dist/modern/visualBuilder/utils/updateFocussedState.js +6 -4
- package/dist/modern/visualBuilder/utils/updateFocussedState.js.map +1 -1
- package/dist/modern/visualBuilder/visualBuilder.style.cjs +3 -3
- package/dist/modern/visualBuilder/visualBuilder.style.cjs.map +1 -1
- package/dist/modern/visualBuilder/visualBuilder.style.js +3 -3
- package/dist/modern/visualBuilder/visualBuilder.style.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/livePreview/eventManager/livePreviewEventManager.ts"],"sourcesContent":["import { EventManager } from \"@contentstack/advanced-post-message\";\nimport { LIVE_PREVIEW_CHANNEL_ID } from \"./livePreviewEventManager.constant\";\n\nlet livePreviewPostMessage: EventManager | undefined;\n\nif (typeof window !== \"undefined\") {\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/livePreview/eventManager/livePreviewEventManager.ts"],"sourcesContent":["import { EventManager } from \"@contentstack/advanced-post-message\";\nimport { LIVE_PREVIEW_CHANNEL_ID } from \"./livePreviewEventManager.constant\";\nimport { isOpeningInNewTab } from \"../../common/inIframe\";\n\nlet livePreviewPostMessage: EventManager | undefined;\n\nif (typeof window !== \"undefined\") {\n const eventOptions = {\n target: window.parent,\n debug: false,\n suppressErrors: true\n };\n\n if (isOpeningInNewTab()) {\n eventOptions.target = window.opener;\n }\n\n livePreviewPostMessage = new EventManager(LIVE_PREVIEW_CHANNEL_ID, eventOptions);\n}\n\nexport default livePreviewPostMessage;\n"],"mappings":";;;;;;;;AAAA,mCAA6B;AAC7B,SAAS,+BAA+B;AACxC,SAAS,yBAAyB;AAElC,IAAI;AAEJ,IAAI,OAAO,WAAW,aAAa;AAC/B,QAAM,eAAe;AAAA,IACjB,QAAQ,OAAO;AAAA,IACf,OAAO;AAAA,IACP,gBAAgB;AAAA,EACpB;AAEA,MAAI,kBAAkB,GAAG;AACrB,iBAAa,SAAS,OAAO;AAAA,EACjC;AAEA,2BAAyB,IAAI,0CAAa,yBAAyB,YAAY;AACnF;AAEA,IAAO,kCAAQ;","names":[]}
|
|
@@ -35,11 +35,14 @@ __export(postMessageEvent_hooks_exports, {
|
|
|
35
35
|
useOnEntryUpdatePostMessageEvent: () => useOnEntryUpdatePostMessageEvent
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(postMessageEvent_hooks_exports);
|
|
38
|
+
var import_inIframe = require("../../common/inIframe.cjs");
|
|
38
39
|
var import_configManager = __toESM(require("../../configManager/configManager.cjs"), 1);
|
|
40
|
+
var import_logger = require("../../logger/logger.cjs");
|
|
39
41
|
var import_types = require("../../types/types.cjs");
|
|
40
42
|
var import_utils = require("../../utils/index.cjs");
|
|
41
43
|
var import_livePreviewEventManager = __toESM(require("./livePreviewEventManager.cjs"), 1);
|
|
42
44
|
var import_livePreviewEventManager2 = require("./livePreviewEventManager.constant.cjs");
|
|
45
|
+
var import_livePreviewPostMessageEvent = require("./types/livePreviewPostMessageEvent.type.cjs");
|
|
43
46
|
function useHistoryPostMessageEvent() {
|
|
44
47
|
import_livePreviewEventManager.default?.on(
|
|
45
48
|
import_livePreviewEventManager2.LIVE_PREVIEW_POST_MESSAGE_EVENTS.HISTORY,
|
|
@@ -69,12 +72,44 @@ function useOnEntryUpdatePostMessageEvent() {
|
|
|
69
72
|
import_livePreviewEventManager.default?.on(
|
|
70
73
|
import_livePreviewEventManager2.LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,
|
|
71
74
|
(event) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
try {
|
|
76
|
+
const { ssr, onChange } = import_configManager.default.get();
|
|
77
|
+
const event_type = event.data._metadata?.event_type;
|
|
78
|
+
(0, import_configManager.setConfigFromParams)({
|
|
79
|
+
live_preview: event.data.hash
|
|
80
|
+
});
|
|
81
|
+
if (!ssr && !event_type) {
|
|
82
|
+
onChange();
|
|
83
|
+
}
|
|
84
|
+
if ((0, import_inIframe.isOpeningInNewTab)()) {
|
|
85
|
+
if (!window) {
|
|
86
|
+
import_logger.PublicLogger.error("window is not defined");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
;
|
|
90
|
+
if (ssr && !event_type) {
|
|
91
|
+
if (window.location.href.includes("live_preview")) {
|
|
92
|
+
window.location.reload();
|
|
93
|
+
} else {
|
|
94
|
+
const url = new URL(window.location.href);
|
|
95
|
+
url.searchParams.set("live_preview", event.data.hash);
|
|
96
|
+
url.searchParams.set("content_type_uid", import_configManager.default.get().stackDetails.contentTypeUid || "");
|
|
97
|
+
url.searchParams.set("entry_uid", import_configManager.default.get().stackDetails.entryUid || "");
|
|
98
|
+
window.location.href = url.toString();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (event_type === import_livePreviewPostMessageEvent.OnChangeLivePreviewPostMessageEventTypes.HASH_CHANGE) {
|
|
102
|
+
const newUrl = new URL(window.location.href);
|
|
103
|
+
newUrl.searchParams.set("live_preview", event.data.hash);
|
|
104
|
+
window.history.pushState({}, "", newUrl.toString());
|
|
105
|
+
}
|
|
106
|
+
if (event_type === import_livePreviewPostMessageEvent.OnChangeLivePreviewPostMessageEventTypes.URL_CHANGE && event.data.url) {
|
|
107
|
+
window.location.href = event.data.url;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
import_logger.PublicLogger.error("Error handling live preview update:", error);
|
|
112
|
+
return;
|
|
78
113
|
}
|
|
79
114
|
}
|
|
80
115
|
);
|
|
@@ -86,7 +121,7 @@ function sendInitializeLivePreviewPostMessageEvent() {
|
|
|
86
121
|
config: {
|
|
87
122
|
shouldReload: import_configManager.default.get().ssr,
|
|
88
123
|
href: window.location.href,
|
|
89
|
-
sdkVersion: "
|
|
124
|
+
sdkVersion: "4.0.1",
|
|
90
125
|
mode: import_configManager.default.get().mode
|
|
91
126
|
}
|
|
92
127
|
}
|
|
@@ -106,7 +141,7 @@ function sendInitializeLivePreviewPostMessageEvent() {
|
|
|
106
141
|
});
|
|
107
142
|
} else {
|
|
108
143
|
}
|
|
109
|
-
if (import_configManager.default.get().ssr || (0, import_utils.isOpeningInTimeline)()) {
|
|
144
|
+
if (import_configManager.default.get().ssr || (0, import_utils.isOpeningInTimeline)() || (0, import_inIframe.isOpeningInNewTab)()) {
|
|
110
145
|
(0, import_utils.addParamsToUrl)();
|
|
111
146
|
}
|
|
112
147
|
import_configManager.default.set("windowType", windowType);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/livePreview/eventManager/postMessageEvent.hooks.ts"],"sourcesContent":["import Config, { setConfigFromParams } from \"../../configManager/configManager\";\nimport { ILivePreviewWindowType } from \"../../types/types\";\nimport { addParamsToUrl, isOpeningInTimeline } from \"../../utils\";\nimport livePreviewPostMessage from \"./livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./livePreviewEventManager.constant\";\nimport {\n HistoryLivePreviewPostMessageEventData,\n LivePreviewInitEventResponse,\n OnChangeLivePreviewPostMessageEventData,\n} from \"./types/livePreviewPostMessageEvent.type\";\n\n/**\n * Registers a post message event listener for history-related events.\n * The listener handles events for forward, backward, and reload actions on the browser history.\n */\nexport function useHistoryPostMessageEvent(): void {\n livePreviewPostMessage?.on<HistoryLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.HISTORY,\n (event) => {\n switch (event.data.type) {\n case \"forward\": {\n window.history.forward();\n break;\n }\n case \"backward\": {\n window.history.back();\n break;\n }\n case \"reload\": {\n window.history.go();\n break;\n }\n default: {\n const exhaustiveCheck: never = event.data.type;\n throw new Error(`Unhandled event: ${exhaustiveCheck}`);\n }\n }\n }\n );\n}\n\n/**\n * Registers a post message event listener for updating the entry in the live preview.\n */\nexport function useOnEntryUpdatePostMessageEvent(): void {\n livePreviewPostMessage?.on<OnChangeLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,\n (event) => {\n setConfigFromParams({\n live_preview: event.data.hash,\n });\n const { ssr, onChange } = Config.get();\n if (!ssr) {\n onChange();\n }\n }\n );\n}\n\nexport function sendInitializeLivePreviewPostMessageEvent(): void {\n livePreviewPostMessage\n ?.send<LivePreviewInitEventResponse>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.INIT,\n {\n config: {\n shouldReload: Config.get().ssr,\n href: window.location.href,\n sdkVersion: process?.env?.PACKAGE_VERSION,\n mode: Config.get().mode,\n },\n }\n )\n .then((data) => {\n const {\n contentTypeUid,\n entryUid,\n windowType = ILivePreviewWindowType.PREVIEW,\n } = data || {};\n\n // TODO: This is a fix for the issue where we were calling sending init in the builder\n // Let's remove this condition when we fix it.\n if (Config?.get()?.windowType && Config.get().windowType === ILivePreviewWindowType.BUILDER) {\n return;\n }\n\n if (contentTypeUid && entryUid) {\n // TODO: we should not use this function. Instead we should have sideEffect run automatically when we set the config.\n setConfigFromParams({\n content_type_uid: contentTypeUid,\n entry_uid: entryUid,\n });\n } else {\n // TODO: add debug logs that runs conditionally\n // PublicLogger.debug(\n // \"init message did not contain contentTypeUid or entryUid.\"\n // );\n }\n if (Config.get().ssr || isOpeningInTimeline()) {\n addParamsToUrl();\n }\n Config.set(\"windowType\", windowType);\n\n // set timeout for client side (use to show warning: You are not editing this page)\n if (!Config.get().ssr) {\n setInterval(() => {\n sendCurrentPageUrlPostMessageEvent();\n }, 1500);\n }\n\n useHistoryPostMessageEvent();\n useOnEntryUpdatePostMessageEvent();\n })\n .catch((e) => {\n // TODO: add debug logs that runs conditionally\n // PublicLogger.debug(\"Error while sending init message\", e);\n });\n}\n\nfunction sendCurrentPageUrlPostMessageEvent(): void {\n livePreviewPostMessage\n ?.send(LIVE_PREVIEW_POST_MESSAGE_EVENTS.CHECK_ENTRY_PAGE, {\n href: window.location.href,\n })\n .catch(() => {\n // TODO: add debug logs that runs conditionally\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA4C;AAC5C,mBAAuC;AACvC,mBAAoD;AACpD,qCAAmC;AACnC,IAAAA,kCAAiD;AAW1C,SAAS,6BAAmC;AAC/C,iCAAAC,SAAwB;AAAA,IACpB,iEAAiC;AAAA,IACjC,CAAC,UAAU;AACP,cAAQ,MAAM,KAAK,MAAM;AAAA,QACrB,KAAK,WAAW;AACZ,iBAAO,QAAQ,QAAQ;AACvB;AAAA,QACJ;AAAA,QACA,KAAK,YAAY;AACb,iBAAO,QAAQ,KAAK;AACpB;AAAA,QACJ;AAAA,QACA,KAAK,UAAU;AACX,iBAAO,QAAQ,GAAG;AAClB;AAAA,QACJ;AAAA,QACA,SAAS;AACL,gBAAM,kBAAyB,MAAM,KAAK;AAC1C,gBAAM,IAAI,MAAM,oBAAoB,eAAe,EAAE;AAAA,QACzD;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAKO,SAAS,mCAAyC;AACrD,iCAAAA,SAAwB;AAAA,IACpB,iEAAiC;AAAA,IACjC,CAAC,UAAU;AACP,oDAAoB;AAAA,QAChB,cAAc,MAAM,KAAK;AAAA,MAC7B,CAAC;AACD,YAAM,EAAE,KAAK,SAAS,IAAI,qBAAAC,QAAO,IAAI;AACrC,UAAI,CAAC,KAAK;AACN,iBAAS;AAAA,MACb;AAAA,IACJ;AAAA,EACJ;AACJ;AAEO,SAAS,4CAAkD;AAC9D,iCAAAD,SACM;AAAA,IACE,iEAAiC;AAAA,IACjC;AAAA,MACI,QAAQ;AAAA,QACJ,cAAc,qBAAAC,QAAO,IAAI,EAAE;AAAA,QAC3B,MAAM,OAAO,SAAS;AAAA,QACtB,YAAY;AAAA,QACZ,MAAM,qBAAAA,QAAO,IAAI,EAAE;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ,EACC,KAAK,CAAC,SAAS;AACZ,UAAM;AAAA,MACF;AAAA,MACA;AAAA,MACA,aAAa,oCAAuB;AAAA,IACxC,IAAI,QAAQ,CAAC;AAIb,QAAI,qBAAAA,SAAQ,IAAI,GAAG,cAAc,qBAAAA,QAAO,IAAI,EAAE,eAAe,oCAAuB,SAAS;AACzF;AAAA,IACJ;AAEA,QAAI,kBAAkB,UAAU;AAE5B,oDAAoB;AAAA,QAChB,kBAAkB;AAAA,QAClB,WAAW;AAAA,MACf,CAAC;AAAA,IACL,OAAO;AAAA,IAKP;AACA,QAAI,qBAAAA,QAAO,IAAI,EAAE,WAAO,kCAAoB,GAAG;AAC3C,uCAAe;AAAA,IACnB;AACA,yBAAAA,QAAO,IAAI,cAAc,UAAU;AAGnC,QAAI,CAAC,qBAAAA,QAAO,IAAI,EAAE,KAAK;AACnB,kBAAY,MAAM;AACd,2CAAmC;AAAA,MACvC,GAAG,IAAI;AAAA,IACX;AAEA,+BAA2B;AAC3B,qCAAiC;AAAA,EACrC,CAAC,EACA,MAAM,CAAC,MAAM;AAAA,EAGd,CAAC;AACT;AAEA,SAAS,qCAA2C;AAChD,iCAAAD,SACM,KAAK,iEAAiC,kBAAkB;AAAA,IACtD,MAAM,OAAO,SAAS;AAAA,EAC1B,CAAC,EACA,MAAM,MAAM;AAAA,EAEb,CAAC;AACT;","names":["import_livePreviewEventManager","livePreviewPostMessage","Config"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/livePreview/eventManager/postMessageEvent.hooks.ts"],"sourcesContent":["import { isOpeningInNewTab } from \"../../common/inIframe\";\nimport Config, { setConfigFromParams } from \"../../configManager/configManager\";\nimport { PublicLogger } from \"../../logger/logger\";\nimport { ILivePreviewWindowType } from \"../../types/types\";\nimport { addParamsToUrl, isOpeningInTimeline } from \"../../utils\";\nimport livePreviewPostMessage from \"./livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./livePreviewEventManager.constant\";\nimport {\n HistoryLivePreviewPostMessageEventData,\n LivePreviewInitEventResponse,\n OnChangeLivePreviewPostMessageEventData,\n OnChangeLivePreviewPostMessageEventTypes,\n} from \"./types/livePreviewPostMessageEvent.type\";\n\n/**\n * Registers a post message event listener for history-related events.\n * The listener handles events for forward, backward, and reload actions on the browser history.\n */\nexport function useHistoryPostMessageEvent(): void {\n livePreviewPostMessage?.on<HistoryLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.HISTORY,\n (event) => {\n switch (event.data.type) {\n case \"forward\": {\n window.history.forward();\n break;\n }\n case \"backward\": {\n window.history.back();\n break;\n }\n case \"reload\": {\n window.history.go();\n break;\n }\n default: {\n const exhaustiveCheck: never = event.data.type;\n throw new Error(`Unhandled event: ${exhaustiveCheck}`);\n }\n }\n }\n );\n}\n\n/**\n * Registers a post message event listener for updating the entry in the live preview.\n */\nexport function useOnEntryUpdatePostMessageEvent(): void {\n livePreviewPostMessage?.on<OnChangeLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,\n (event) => {\n try {\n const { ssr, onChange } = Config.get();\n const event_type = event.data._metadata?.event_type;\n setConfigFromParams({\n live_preview: event.data.hash,\n });\n\n // This section will run when there is a change in the entry and the website is CSR\n if (!ssr && !event_type) {\n onChange();\n } \n\n if(isOpeningInNewTab()) {\n if(!window) {\n PublicLogger.error(\"window is not defined\");\n return;\n };\n \n // This section will run when there is a change in the entry and the website is SSR\n if(ssr && !event_type) {\n if(window.location.href.includes(\"live_preview\")) {\n window.location.reload();\n } else {\n const url = new URL(window.location.href);\n url.searchParams.set(\"live_preview\", event.data.hash);\n url.searchParams.set(\"content_type_uid\", Config.get().stackDetails.contentTypeUid || \"\");\n url.searchParams.set(\"entry_uid\", Config.get().stackDetails.entryUid || \"\");\n window.location.href = url.toString();\n }\n }\n \n // This section will run when the hash changes and the website is SSR or CSR\n if(event_type === OnChangeLivePreviewPostMessageEventTypes.HASH_CHANGE){\n const newUrl = new URL(window.location.href);\n newUrl.searchParams.set(\"live_preview\", event.data.hash);\n window.history.pushState({}, \"\", newUrl.toString());\n }\n \n // This section will run when the URL of the page changes\n if(event_type === OnChangeLivePreviewPostMessageEventTypes.URL_CHANGE && event.data.url){\n window.location.href = event.data.url;\n }\n }\n\n \n } catch (error) {\n PublicLogger.error(\"Error handling live preview update:\", error);\n return;\n }\n }\n );\n}\n\nexport function sendInitializeLivePreviewPostMessageEvent(): void {\n livePreviewPostMessage\n ?.send<LivePreviewInitEventResponse>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.INIT,\n {\n config: {\n shouldReload: Config.get().ssr,\n href: window.location.href,\n sdkVersion: process?.env?.PACKAGE_VERSION,\n mode: Config.get().mode,\n },\n }\n )\n .then((data) => {\n const {\n contentTypeUid,\n entryUid,\n windowType = ILivePreviewWindowType.PREVIEW,\n } = data || {};\n\n // TODO: This is a fix for the issue where we were calling sending init in the builder\n // Let's remove this condition when we fix it.\n if (Config?.get()?.windowType && Config.get().windowType === ILivePreviewWindowType.BUILDER) {\n return;\n }\n\n if (contentTypeUid && entryUid) {\n // TODO: we should not use this function. Instead we should have sideEffect run automatically when we set the config.\n setConfigFromParams({\n content_type_uid: contentTypeUid,\n entry_uid: entryUid,\n });\n } else {\n // TODO: add debug logs that runs conditionally\n // PublicLogger.debug(\n // \"init message did not contain contentTypeUid or entryUid.\"\n // );\n }\n if (Config.get().ssr || isOpeningInTimeline() || isOpeningInNewTab()) {\n addParamsToUrl();\n }\n Config.set(\"windowType\", windowType);\n\n // set timeout for client side (use to show warning: You are not editing this page)\n if (!Config.get().ssr) {\n setInterval(() => {\n sendCurrentPageUrlPostMessageEvent();\n }, 1500);\n }\n\n useHistoryPostMessageEvent();\n useOnEntryUpdatePostMessageEvent();\n })\n .catch((e) => {\n // TODO: add debug logs that runs conditionally\n // PublicLogger.debug(\"Error while sending init message\", e);\n });\n}\n\nfunction sendCurrentPageUrlPostMessageEvent(): void {\n livePreviewPostMessage\n ?.send(LIVE_PREVIEW_POST_MESSAGE_EVENTS.CHECK_ENTRY_PAGE, {\n href: window.location.href,\n })\n .catch(() => {\n // TODO: add debug logs that runs conditionally\n });\n}\n"],"mappings":"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","names":["import_livePreviewEventManager","livePreviewPostMessage","Config"]}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import "../../chunk-5WRI5ZAA.js";
|
|
2
2
|
|
|
3
3
|
// src/livePreview/eventManager/postMessageEvent.hooks.ts
|
|
4
|
+
import { isOpeningInNewTab } from "../../common/inIframe.js";
|
|
4
5
|
import Config, { setConfigFromParams } from "../../configManager/configManager.js";
|
|
6
|
+
import { PublicLogger } from "../../logger/logger.js";
|
|
5
7
|
import { ILivePreviewWindowType } from "../../types/types.js";
|
|
6
8
|
import { addParamsToUrl, isOpeningInTimeline } from "../../utils/index.js";
|
|
7
9
|
import livePreviewPostMessage from "./livePreviewEventManager.js";
|
|
8
10
|
import { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from "./livePreviewEventManager.constant.js";
|
|
11
|
+
import {
|
|
12
|
+
OnChangeLivePreviewPostMessageEventTypes
|
|
13
|
+
} from "./types/livePreviewPostMessageEvent.type.js";
|
|
9
14
|
function useHistoryPostMessageEvent() {
|
|
10
15
|
livePreviewPostMessage?.on(
|
|
11
16
|
LIVE_PREVIEW_POST_MESSAGE_EVENTS.HISTORY,
|
|
@@ -35,12 +40,44 @@ function useOnEntryUpdatePostMessageEvent() {
|
|
|
35
40
|
livePreviewPostMessage?.on(
|
|
36
41
|
LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,
|
|
37
42
|
(event) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
try {
|
|
44
|
+
const { ssr, onChange } = Config.get();
|
|
45
|
+
const event_type = event.data._metadata?.event_type;
|
|
46
|
+
setConfigFromParams({
|
|
47
|
+
live_preview: event.data.hash
|
|
48
|
+
});
|
|
49
|
+
if (!ssr && !event_type) {
|
|
50
|
+
onChange();
|
|
51
|
+
}
|
|
52
|
+
if (isOpeningInNewTab()) {
|
|
53
|
+
if (!window) {
|
|
54
|
+
PublicLogger.error("window is not defined");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
;
|
|
58
|
+
if (ssr && !event_type) {
|
|
59
|
+
if (window.location.href.includes("live_preview")) {
|
|
60
|
+
window.location.reload();
|
|
61
|
+
} else {
|
|
62
|
+
const url = new URL(window.location.href);
|
|
63
|
+
url.searchParams.set("live_preview", event.data.hash);
|
|
64
|
+
url.searchParams.set("content_type_uid", Config.get().stackDetails.contentTypeUid || "");
|
|
65
|
+
url.searchParams.set("entry_uid", Config.get().stackDetails.entryUid || "");
|
|
66
|
+
window.location.href = url.toString();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (event_type === OnChangeLivePreviewPostMessageEventTypes.HASH_CHANGE) {
|
|
70
|
+
const newUrl = new URL(window.location.href);
|
|
71
|
+
newUrl.searchParams.set("live_preview", event.data.hash);
|
|
72
|
+
window.history.pushState({}, "", newUrl.toString());
|
|
73
|
+
}
|
|
74
|
+
if (event_type === OnChangeLivePreviewPostMessageEventTypes.URL_CHANGE && event.data.url) {
|
|
75
|
+
window.location.href = event.data.url;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
PublicLogger.error("Error handling live preview update:", error);
|
|
80
|
+
return;
|
|
44
81
|
}
|
|
45
82
|
}
|
|
46
83
|
);
|
|
@@ -52,7 +89,7 @@ function sendInitializeLivePreviewPostMessageEvent() {
|
|
|
52
89
|
config: {
|
|
53
90
|
shouldReload: Config.get().ssr,
|
|
54
91
|
href: window.location.href,
|
|
55
|
-
sdkVersion: "
|
|
92
|
+
sdkVersion: "4.0.1",
|
|
56
93
|
mode: Config.get().mode
|
|
57
94
|
}
|
|
58
95
|
}
|
|
@@ -72,7 +109,7 @@ function sendInitializeLivePreviewPostMessageEvent() {
|
|
|
72
109
|
});
|
|
73
110
|
} else {
|
|
74
111
|
}
|
|
75
|
-
if (Config.get().ssr || isOpeningInTimeline()) {
|
|
112
|
+
if (Config.get().ssr || isOpeningInTimeline() || isOpeningInNewTab()) {
|
|
76
113
|
addParamsToUrl();
|
|
77
114
|
}
|
|
78
115
|
Config.set("windowType", windowType);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/livePreview/eventManager/postMessageEvent.hooks.ts"],"sourcesContent":["import Config, { setConfigFromParams } from \"../../configManager/configManager\";\nimport { ILivePreviewWindowType } from \"../../types/types\";\nimport { addParamsToUrl, isOpeningInTimeline } from \"../../utils\";\nimport livePreviewPostMessage from \"./livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./livePreviewEventManager.constant\";\nimport {\n HistoryLivePreviewPostMessageEventData,\n LivePreviewInitEventResponse,\n OnChangeLivePreviewPostMessageEventData,\n} from \"./types/livePreviewPostMessageEvent.type\";\n\n/**\n * Registers a post message event listener for history-related events.\n * The listener handles events for forward, backward, and reload actions on the browser history.\n */\nexport function useHistoryPostMessageEvent(): void {\n livePreviewPostMessage?.on<HistoryLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.HISTORY,\n (event) => {\n switch (event.data.type) {\n case \"forward\": {\n window.history.forward();\n break;\n }\n case \"backward\": {\n window.history.back();\n break;\n }\n case \"reload\": {\n window.history.go();\n break;\n }\n default: {\n const exhaustiveCheck: never = event.data.type;\n throw new Error(`Unhandled event: ${exhaustiveCheck}`);\n }\n }\n }\n );\n}\n\n/**\n * Registers a post message event listener for updating the entry in the live preview.\n */\nexport function useOnEntryUpdatePostMessageEvent(): void {\n livePreviewPostMessage?.on<OnChangeLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,\n (event) => {\n setConfigFromParams({\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/livePreview/eventManager/postMessageEvent.hooks.ts"],"sourcesContent":["import { isOpeningInNewTab } from \"../../common/inIframe\";\nimport Config, { setConfigFromParams } from \"../../configManager/configManager\";\nimport { PublicLogger } from \"../../logger/logger\";\nimport { ILivePreviewWindowType } from \"../../types/types\";\nimport { addParamsToUrl, isOpeningInTimeline } from \"../../utils\";\nimport livePreviewPostMessage from \"./livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./livePreviewEventManager.constant\";\nimport {\n HistoryLivePreviewPostMessageEventData,\n LivePreviewInitEventResponse,\n OnChangeLivePreviewPostMessageEventData,\n OnChangeLivePreviewPostMessageEventTypes,\n} from \"./types/livePreviewPostMessageEvent.type\";\n\n/**\n * Registers a post message event listener for history-related events.\n * The listener handles events for forward, backward, and reload actions on the browser history.\n */\nexport function useHistoryPostMessageEvent(): void {\n livePreviewPostMessage?.on<HistoryLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.HISTORY,\n (event) => {\n switch (event.data.type) {\n case \"forward\": {\n window.history.forward();\n break;\n }\n case \"backward\": {\n window.history.back();\n break;\n }\n case \"reload\": {\n window.history.go();\n break;\n }\n default: {\n const exhaustiveCheck: never = event.data.type;\n throw new Error(`Unhandled event: ${exhaustiveCheck}`);\n }\n }\n }\n );\n}\n\n/**\n * Registers a post message event listener for updating the entry in the live preview.\n */\nexport function useOnEntryUpdatePostMessageEvent(): void {\n livePreviewPostMessage?.on<OnChangeLivePreviewPostMessageEventData>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,\n (event) => {\n try {\n const { ssr, onChange } = Config.get();\n const event_type = event.data._metadata?.event_type;\n setConfigFromParams({\n live_preview: event.data.hash,\n });\n\n // This section will run when there is a change in the entry and the website is CSR\n if (!ssr && !event_type) {\n onChange();\n } \n\n if(isOpeningInNewTab()) {\n if(!window) {\n PublicLogger.error(\"window is not defined\");\n return;\n };\n \n // This section will run when there is a change in the entry and the website is SSR\n if(ssr && !event_type) {\n if(window.location.href.includes(\"live_preview\")) {\n window.location.reload();\n } else {\n const url = new URL(window.location.href);\n url.searchParams.set(\"live_preview\", event.data.hash);\n url.searchParams.set(\"content_type_uid\", Config.get().stackDetails.contentTypeUid || \"\");\n url.searchParams.set(\"entry_uid\", Config.get().stackDetails.entryUid || \"\");\n window.location.href = url.toString();\n }\n }\n \n // This section will run when the hash changes and the website is SSR or CSR\n if(event_type === OnChangeLivePreviewPostMessageEventTypes.HASH_CHANGE){\n const newUrl = new URL(window.location.href);\n newUrl.searchParams.set(\"live_preview\", event.data.hash);\n window.history.pushState({}, \"\", newUrl.toString());\n }\n \n // This section will run when the URL of the page changes\n if(event_type === OnChangeLivePreviewPostMessageEventTypes.URL_CHANGE && event.data.url){\n window.location.href = event.data.url;\n }\n }\n\n \n } catch (error) {\n PublicLogger.error(\"Error handling live preview update:\", error);\n return;\n }\n }\n );\n}\n\nexport function sendInitializeLivePreviewPostMessageEvent(): void {\n livePreviewPostMessage\n ?.send<LivePreviewInitEventResponse>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.INIT,\n {\n config: {\n shouldReload: Config.get().ssr,\n href: window.location.href,\n sdkVersion: process?.env?.PACKAGE_VERSION,\n mode: Config.get().mode,\n },\n }\n )\n .then((data) => {\n const {\n contentTypeUid,\n entryUid,\n windowType = ILivePreviewWindowType.PREVIEW,\n } = data || {};\n\n // TODO: This is a fix for the issue where we were calling sending init in the builder\n // Let's remove this condition when we fix it.\n if (Config?.get()?.windowType && Config.get().windowType === ILivePreviewWindowType.BUILDER) {\n return;\n }\n\n if (contentTypeUid && entryUid) {\n // TODO: we should not use this function. Instead we should have sideEffect run automatically when we set the config.\n setConfigFromParams({\n content_type_uid: contentTypeUid,\n entry_uid: entryUid,\n });\n } else {\n // TODO: add debug logs that runs conditionally\n // PublicLogger.debug(\n // \"init message did not contain contentTypeUid or entryUid.\"\n // );\n }\n if (Config.get().ssr || isOpeningInTimeline() || isOpeningInNewTab()) {\n addParamsToUrl();\n }\n Config.set(\"windowType\", windowType);\n\n // set timeout for client side (use to show warning: You are not editing this page)\n if (!Config.get().ssr) {\n setInterval(() => {\n sendCurrentPageUrlPostMessageEvent();\n }, 1500);\n }\n\n useHistoryPostMessageEvent();\n useOnEntryUpdatePostMessageEvent();\n })\n .catch((e) => {\n // TODO: add debug logs that runs conditionally\n // PublicLogger.debug(\"Error while sending init message\", e);\n });\n}\n\nfunction sendCurrentPageUrlPostMessageEvent(): void {\n livePreviewPostMessage\n ?.send(LIVE_PREVIEW_POST_MESSAGE_EVENTS.CHECK_ENTRY_PAGE, {\n href: window.location.href,\n })\n .catch(() => {\n // TODO: add debug logs that runs conditionally\n });\n}\n"],"mappings":";;;AAAA,SAAS,yBAAyB;AAClC,OAAO,UAAU,2BAA2B;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AACvC,SAAS,gBAAgB,2BAA2B;AACpD,OAAO,4BAA4B;AACnC,SAAS,wCAAwC;AACjD;AAAA,EAII;AAAA,OACG;AAMA,SAAS,6BAAmC;AAC/C,0BAAwB;AAAA,IACpB,iCAAiC;AAAA,IACjC,CAAC,UAAU;AACP,cAAQ,MAAM,KAAK,MAAM;AAAA,QACrB,KAAK,WAAW;AACZ,iBAAO,QAAQ,QAAQ;AACvB;AAAA,QACJ;AAAA,QACA,KAAK,YAAY;AACb,iBAAO,QAAQ,KAAK;AACpB;AAAA,QACJ;AAAA,QACA,KAAK,UAAU;AACX,iBAAO,QAAQ,GAAG;AAClB;AAAA,QACJ;AAAA,QACA,SAAS;AACL,gBAAM,kBAAyB,MAAM,KAAK;AAC1C,gBAAM,IAAI,MAAM,oBAAoB,eAAe,EAAE;AAAA,QACzD;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAKO,SAAS,mCAAyC;AACrD,0BAAwB;AAAA,IACpB,iCAAiC;AAAA,IACjC,CAAC,UAAU;AACP,UAAI;AACA,cAAM,EAAE,KAAK,SAAS,IAAI,OAAO,IAAI;AACrC,cAAM,aAAa,MAAM,KAAK,WAAW;AACzC,4BAAoB;AAAA,UAChB,cAAc,MAAM,KAAK;AAAA,QAC7B,CAAC;AAGD,YAAI,CAAC,OAAO,CAAC,YAAY;AACrB,mBAAS;AAAA,QACb;AAEA,YAAG,kBAAkB,GAAG;AACpB,cAAG,CAAC,QAAQ;AACR,yBAAa,MAAM,uBAAuB;AAC1C;AAAA,UACJ;AAAC;AAGD,cAAG,OAAO,CAAC,YAAY;AACnB,gBAAG,OAAO,SAAS,KAAK,SAAS,cAAc,GAAG;AAC9C,qBAAO,SAAS,OAAO;AAAA,YAC3B,OAAO;AACH,oBAAM,MAAM,IAAI,IAAI,OAAO,SAAS,IAAI;AACxC,kBAAI,aAAa,IAAI,gBAAgB,MAAM,KAAK,IAAI;AACpD,kBAAI,aAAa,IAAI,oBAAoB,OAAO,IAAI,EAAE,aAAa,kBAAkB,EAAE;AACvF,kBAAI,aAAa,IAAI,aAAa,OAAO,IAAI,EAAE,aAAa,YAAY,EAAE;AAC1E,qBAAO,SAAS,OAAO,IAAI,SAAS;AAAA,YACxC;AAAA,UACJ;AAGA,cAAG,eAAe,yCAAyC,aAAY;AACnE,kBAAM,SAAS,IAAI,IAAI,OAAO,SAAS,IAAI;AAC3C,mBAAO,aAAa,IAAI,gBAAgB,MAAM,KAAK,IAAI;AACvD,mBAAO,QAAQ,UAAU,CAAC,GAAG,IAAI,OAAO,SAAS,CAAC;AAAA,UACtD;AAGA,cAAG,eAAe,yCAAyC,cAAc,MAAM,KAAK,KAAI;AACpF,mBAAO,SAAS,OAAO,MAAM,KAAK;AAAA,UACtC;AAAA,QACJ;AAAA,MAGJ,SAAS,OAAO;AACZ,qBAAa,MAAM,uCAAuC,KAAK;AAC/D;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAEO,SAAS,4CAAkD;AAC9D,0BACM;AAAA,IACE,iCAAiC;AAAA,IACjC;AAAA,MACI,QAAQ;AAAA,QACJ,cAAc,OAAO,IAAI,EAAE;AAAA,QAC3B,MAAM,OAAO,SAAS;AAAA,QACtB,YAAY;AAAA,QACZ,MAAM,OAAO,IAAI,EAAE;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ,EACC,KAAK,CAAC,SAAS;AACZ,UAAM;AAAA,MACF;AAAA,MACA;AAAA,MACA,aAAa,uBAAuB;AAAA,IACxC,IAAI,QAAQ,CAAC;AAIb,QAAI,QAAQ,IAAI,GAAG,cAAc,OAAO,IAAI,EAAE,eAAe,uBAAuB,SAAS;AACzF;AAAA,IACJ;AAEA,QAAI,kBAAkB,UAAU;AAE5B,0BAAoB;AAAA,QAChB,kBAAkB;AAAA,QAClB,WAAW;AAAA,MACf,CAAC;AAAA,IACL,OAAO;AAAA,IAKP;AACA,QAAI,OAAO,IAAI,EAAE,OAAO,oBAAoB,KAAK,kBAAkB,GAAG;AAClE,qBAAe;AAAA,IACnB;AACA,WAAO,IAAI,cAAc,UAAU;AAGnC,QAAI,CAAC,OAAO,IAAI,EAAE,KAAK;AACnB,kBAAY,MAAM;AACd,2CAAmC;AAAA,MACvC,GAAG,IAAI;AAAA,IACX;AAEA,+BAA2B;AAC3B,qCAAiC;AAAA,EACrC,CAAC,EACA,MAAM,CAAC,MAAM;AAAA,EAGd,CAAC;AACT;AAEA,SAAS,qCAA2C;AAChD,0BACM,KAAK,iCAAiC,kBAAkB;AAAA,IACtD,MAAM,OAAO,SAAS;AAAA,EAC1B,CAAC,EACA,MAAM,MAAM;AAAA,EAEb,CAAC;AACT;","names":[]}
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,5 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// src/livePreview/eventManager/types/livePreviewPostMessageEvent.type.ts
|
|
17
21
|
var livePreviewPostMessageEvent_type_exports = {};
|
|
22
|
+
__export(livePreviewPostMessageEvent_type_exports, {
|
|
23
|
+
OnChangeLivePreviewPostMessageEventTypes: () => OnChangeLivePreviewPostMessageEventTypes
|
|
24
|
+
});
|
|
18
25
|
module.exports = __toCommonJS(livePreviewPostMessageEvent_type_exports);
|
|
26
|
+
var OnChangeLivePreviewPostMessageEventTypes = {
|
|
27
|
+
HASH_CHANGE: "hash_change",
|
|
28
|
+
URL_CHANGE: "url_change"
|
|
29
|
+
};
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
OnChangeLivePreviewPostMessageEventTypes
|
|
33
|
+
});
|
|
19
34
|
//# sourceMappingURL=livePreviewPostMessageEvent.type.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/livePreview/eventManager/types/livePreviewPostMessageEvent.type.ts"],"sourcesContent":["import { ILivePreviewWindowType } from \"../../../types/types\";\n\nexport interface HistoryLivePreviewPostMessageEventData {\n type: \"forward\" | \"backward\" | \"reload\";\n}\n\nexport interface OnChangeLivePreviewPostMessageEventData {\n hash: string;\n}\n\nexport interface LivePreviewInitEventResponse {\n contentTypeUid: string;\n entryUid: string;\n windowType: ILivePreviewWindowType;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/livePreview/eventManager/types/livePreviewPostMessageEvent.type.ts"],"sourcesContent":["import { ILivePreviewWindowType } from \"../../../types/types\";\n\nexport const OnChangeLivePreviewPostMessageEventTypes = {\n HASH_CHANGE: \"hash_change\",\n URL_CHANGE: \"url_change\"\n} as const;\n\nexport interface HistoryLivePreviewPostMessageEventData {\n type: \"forward\" | \"backward\" | \"reload\";\n}\n\nexport interface OnChangeLivePreviewPostMessageEventData {\n hash: string;\n entry_uid?: string;\n content_type_uid?: string;\n url?: string;\n _metadata?: {\n event_type: typeof OnChangeLivePreviewPostMessageEventTypes[keyof typeof OnChangeLivePreviewPostMessageEventTypes];\n }\n}\n\nexport interface LivePreviewInitEventResponse {\n contentTypeUid: string;\n entryUid: string;\n windowType: ILivePreviewWindowType;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,2CAA2C;AAAA,EACpD,aAAa;AAAA,EACb,YAAY;AAChB;","names":[]}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { ILivePreviewWindowType } from '../../../types/types.cjs';
|
|
2
2
|
import '../../../visualBuilder/types/collab.types.cjs';
|
|
3
3
|
|
|
4
|
+
declare const OnChangeLivePreviewPostMessageEventTypes: {
|
|
5
|
+
readonly HASH_CHANGE: "hash_change";
|
|
6
|
+
readonly URL_CHANGE: "url_change";
|
|
7
|
+
};
|
|
4
8
|
interface HistoryLivePreviewPostMessageEventData {
|
|
5
9
|
type: "forward" | "backward" | "reload";
|
|
6
10
|
}
|
|
7
11
|
interface OnChangeLivePreviewPostMessageEventData {
|
|
8
12
|
hash: string;
|
|
13
|
+
entry_uid?: string;
|
|
14
|
+
content_type_uid?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
_metadata?: {
|
|
17
|
+
event_type: typeof OnChangeLivePreviewPostMessageEventTypes[keyof typeof OnChangeLivePreviewPostMessageEventTypes];
|
|
18
|
+
};
|
|
9
19
|
}
|
|
10
20
|
interface LivePreviewInitEventResponse {
|
|
11
21
|
contentTypeUid: string;
|
|
@@ -13,4 +23,4 @@ interface LivePreviewInitEventResponse {
|
|
|
13
23
|
windowType: ILivePreviewWindowType;
|
|
14
24
|
}
|
|
15
25
|
|
|
16
|
-
export type
|
|
26
|
+
export { type HistoryLivePreviewPostMessageEventData, type LivePreviewInitEventResponse, type OnChangeLivePreviewPostMessageEventData, OnChangeLivePreviewPostMessageEventTypes };
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { ILivePreviewWindowType } from '../../../types/types.js';
|
|
2
2
|
import '../../../visualBuilder/types/collab.types.js';
|
|
3
3
|
|
|
4
|
+
declare const OnChangeLivePreviewPostMessageEventTypes: {
|
|
5
|
+
readonly HASH_CHANGE: "hash_change";
|
|
6
|
+
readonly URL_CHANGE: "url_change";
|
|
7
|
+
};
|
|
4
8
|
interface HistoryLivePreviewPostMessageEventData {
|
|
5
9
|
type: "forward" | "backward" | "reload";
|
|
6
10
|
}
|
|
7
11
|
interface OnChangeLivePreviewPostMessageEventData {
|
|
8
12
|
hash: string;
|
|
13
|
+
entry_uid?: string;
|
|
14
|
+
content_type_uid?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
_metadata?: {
|
|
17
|
+
event_type: typeof OnChangeLivePreviewPostMessageEventTypes[keyof typeof OnChangeLivePreviewPostMessageEventTypes];
|
|
18
|
+
};
|
|
9
19
|
}
|
|
10
20
|
interface LivePreviewInitEventResponse {
|
|
11
21
|
contentTypeUid: string;
|
|
@@ -13,4 +23,4 @@ interface LivePreviewInitEventResponse {
|
|
|
13
23
|
windowType: ILivePreviewWindowType;
|
|
14
24
|
}
|
|
15
25
|
|
|
16
|
-
export type
|
|
26
|
+
export { type HistoryLivePreviewPostMessageEventData, type LivePreviewInitEventResponse, type OnChangeLivePreviewPostMessageEventData, OnChangeLivePreviewPostMessageEventTypes };
|
|
@@ -1 +1,11 @@
|
|
|
1
|
+
import "../../../chunk-5WRI5ZAA.js";
|
|
2
|
+
|
|
3
|
+
// src/livePreview/eventManager/types/livePreviewPostMessageEvent.type.ts
|
|
4
|
+
var OnChangeLivePreviewPostMessageEventTypes = {
|
|
5
|
+
HASH_CHANGE: "hash_change",
|
|
6
|
+
URL_CHANGE: "url_change"
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
OnChangeLivePreviewPostMessageEventTypes
|
|
10
|
+
};
|
|
1
11
|
//# sourceMappingURL=livePreviewPostMessageEvent.type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/livePreview/eventManager/types/livePreviewPostMessageEvent.type.ts"],"sourcesContent":["import { ILivePreviewWindowType } from \"../../../types/types\";\n\nexport const OnChangeLivePreviewPostMessageEventTypes = {\n HASH_CHANGE: \"hash_change\",\n URL_CHANGE: \"url_change\"\n} as const;\n\nexport interface HistoryLivePreviewPostMessageEventData {\n type: \"forward\" | \"backward\" | \"reload\";\n}\n\nexport interface OnChangeLivePreviewPostMessageEventData {\n hash: string;\n entry_uid?: string;\n content_type_uid?: string;\n url?: string;\n _metadata?: {\n event_type: typeof OnChangeLivePreviewPostMessageEventTypes[keyof typeof OnChangeLivePreviewPostMessageEventTypes];\n }\n}\n\nexport interface LivePreviewInitEventResponse {\n contentTypeUid: string;\n entryUid: string;\n windowType: ILivePreviewWindowType;\n}\n"],"mappings":";;;AAEO,IAAM,2CAA2C;AAAA,EACpD,aAAa;AAAA,EACb,YAAY;AAChB;","names":[]}
|
|
@@ -227,7 +227,7 @@ var _ContentstackLivePreview = class _ContentstackLivePreview {
|
|
|
227
227
|
* @returns The version of the SDK as a string.
|
|
228
228
|
*/
|
|
229
229
|
static getSdkVersion() {
|
|
230
|
-
return "
|
|
230
|
+
return "4.0.1";
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
_ContentstackLivePreview.previewConstructors = {};
|
|
@@ -195,7 +195,7 @@ var _ContentstackLivePreview = class _ContentstackLivePreview {
|
|
|
195
195
|
* @returns The version of the SDK as a string.
|
|
196
196
|
*/
|
|
197
197
|
static getSdkVersion() {
|
|
198
|
-
return "
|
|
198
|
+
return "4.0.1";
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
_ContentstackLivePreview.previewConstructors = {};
|
|
@@ -24,6 +24,7 @@ __export(utils_exports, {
|
|
|
24
24
|
addParamsToUrl: () => addParamsToUrl,
|
|
25
25
|
hasWindow: () => hasWindow,
|
|
26
26
|
isOpenInBuilder: () => isOpenInBuilder,
|
|
27
|
+
isOpenInPreviewShare: () => isOpenInPreviewShare,
|
|
27
28
|
isOpeningInTimeline: () => isOpeningInTimeline
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -62,12 +63,21 @@ function isOpenInBuilder() {
|
|
|
62
63
|
}
|
|
63
64
|
return false;
|
|
64
65
|
}
|
|
66
|
+
function isOpenInPreviewShare() {
|
|
67
|
+
if (hasWindow()) {
|
|
68
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
69
|
+
const previewShare = urlParams.get("preview_share");
|
|
70
|
+
return !!previewShare;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
65
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
75
|
0 && (module.exports = {
|
|
67
76
|
addLivePreviewQueryTags,
|
|
68
77
|
addParamsToUrl,
|
|
69
78
|
hasWindow,
|
|
70
79
|
isOpenInBuilder,
|
|
80
|
+
isOpenInPreviewShare,
|
|
71
81
|
isOpeningInTimeline
|
|
72
82
|
});
|
|
73
83
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["import { PublicLogger } from \"../logger/logger\";\nimport { addLivePreviewQueryTags } from \"./addLivePreviewQueryTags\";\nexport function hasWindow(): boolean {\n return typeof window !== \"undefined\";\n}\nexport { addLivePreviewQueryTags };\nexport function addParamsToUrl() {\n // Setting the query params to all the click events related to current domain\n window.addEventListener(\"click\", (event: any) => {\n const clickedElement = event.target;\n const anchorElement = clickedElement.closest('a');\n \n // Only proceed if the clicked element is either an anchor or a direct/indirect child of an anchor\n if (!anchorElement || !anchorElement.contains(clickedElement)) {\n return;\n }\n\n const targetHref: string | any = anchorElement.href;\n const docOrigin: string = document.location.origin;\n if (\n targetHref &&\n targetHref.includes(docOrigin) &&\n !targetHref.includes(\"live_preview\")\n ) {\n const newUrl = addLivePreviewQueryTags(targetHref);\n anchorElement.href = newUrl || targetHref;\n }\n });\n}\nexport function isOpeningInTimeline(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const previewTimestamp = urlParams.get(\"preview_timestamp\");\n return !!previewTimestamp;\n }\n return false;\n}\n\nexport function isOpenInBuilder(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const builder = urlParams.get(\"builder\");\n return !!builder;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qCAAwC;AACjC,SAAS,YAAqB;AACjC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,iBAAiB;AAE7B,SAAO,iBAAiB,SAAS,CAAC,UAAe;AAC7C,UAAM,iBAAiB,MAAM;AAC7B,UAAM,gBAAgB,eAAe,QAAQ,GAAG;AAGhD,QAAI,CAAC,iBAAiB,CAAC,cAAc,SAAS,cAAc,GAAG;AAC3D;AAAA,IACJ;AAEA,UAAM,aAA2B,cAAc;AAC/C,UAAM,YAAoB,SAAS,SAAS;AAC5C,QACI,cACA,WAAW,SAAS,SAAS,KAC7B,CAAC,WAAW,SAAS,cAAc,GACrC;AACE,YAAM,aAAS,wDAAwB,UAAU;AACjD,oBAAc,OAAO,UAAU;AAAA,IACnC;AAAA,EACJ,CAAC;AACL;AACO,SAAS,sBAA+B;AAC3C,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,mBAAmB,UAAU,IAAI,mBAAmB;AAC1D,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;AAEO,SAAS,kBAA2B;AACvC,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,UAAU,UAAU,IAAI,SAAS;AACvC,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["import { PublicLogger } from \"../logger/logger\";\nimport { addLivePreviewQueryTags } from \"./addLivePreviewQueryTags\";\nexport function hasWindow(): boolean {\n return typeof window !== \"undefined\";\n}\nexport { addLivePreviewQueryTags };\nexport function addParamsToUrl() {\n // Setting the query params to all the click events related to current domain\n window.addEventListener(\"click\", (event: any) => {\n const clickedElement = event.target;\n const anchorElement = clickedElement.closest('a');\n \n // Only proceed if the clicked element is either an anchor or a direct/indirect child of an anchor\n if (!anchorElement || !anchorElement.contains(clickedElement)) {\n return;\n }\n\n const targetHref: string | any = anchorElement.href;\n const docOrigin: string = document.location.origin;\n if (\n targetHref &&\n targetHref.includes(docOrigin) &&\n !targetHref.includes(\"live_preview\")\n ) {\n const newUrl = addLivePreviewQueryTags(targetHref);\n anchorElement.href = newUrl || targetHref;\n }\n });\n}\nexport function isOpeningInTimeline(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const previewTimestamp = urlParams.get(\"preview_timestamp\");\n return !!previewTimestamp;\n }\n return false;\n}\n\nexport function isOpenInBuilder(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const builder = urlParams.get(\"builder\");\n return !!builder;\n }\n return false;\n}\n\n\nexport function isOpenInPreviewShare(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const previewShare = urlParams.get(\"preview_share\");\n return !!previewShare;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qCAAwC;AACjC,SAAS,YAAqB;AACjC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,iBAAiB;AAE7B,SAAO,iBAAiB,SAAS,CAAC,UAAe;AAC7C,UAAM,iBAAiB,MAAM;AAC7B,UAAM,gBAAgB,eAAe,QAAQ,GAAG;AAGhD,QAAI,CAAC,iBAAiB,CAAC,cAAc,SAAS,cAAc,GAAG;AAC3D;AAAA,IACJ;AAEA,UAAM,aAA2B,cAAc;AAC/C,UAAM,YAAoB,SAAS,SAAS;AAC5C,QACI,cACA,WAAW,SAAS,SAAS,KAC7B,CAAC,WAAW,SAAS,cAAc,GACrC;AACE,YAAM,aAAS,wDAAwB,UAAU;AACjD,oBAAc,OAAO,UAAU;AAAA,IACnC;AAAA,EACJ,CAAC;AACL;AACO,SAAS,sBAA+B;AAC3C,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,mBAAmB,UAAU,IAAI,mBAAmB;AAC1D,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;AAEO,SAAS,kBAA2B;AACvC,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,UAAU,UAAU,IAAI,SAAS;AACvC,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;AAGO,SAAS,uBAAgC;AAC5C,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,eAAe,UAAU,IAAI,eAAe;AAClD,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;","names":[]}
|
|
@@ -5,5 +5,6 @@ declare function hasWindow(): boolean;
|
|
|
5
5
|
declare function addParamsToUrl(): void;
|
|
6
6
|
declare function isOpeningInTimeline(): boolean;
|
|
7
7
|
declare function isOpenInBuilder(): boolean;
|
|
8
|
+
declare function isOpenInPreviewShare(): boolean;
|
|
8
9
|
|
|
9
|
-
export { addParamsToUrl, hasWindow, isOpenInBuilder, isOpeningInTimeline };
|
|
10
|
+
export { addParamsToUrl, hasWindow, isOpenInBuilder, isOpenInPreviewShare, isOpeningInTimeline };
|
|
@@ -5,5 +5,6 @@ declare function hasWindow(): boolean;
|
|
|
5
5
|
declare function addParamsToUrl(): void;
|
|
6
6
|
declare function isOpeningInTimeline(): boolean;
|
|
7
7
|
declare function isOpenInBuilder(): boolean;
|
|
8
|
+
declare function isOpenInPreviewShare(): boolean;
|
|
8
9
|
|
|
9
|
-
export { addParamsToUrl, hasWindow, isOpenInBuilder, isOpeningInTimeline };
|
|
10
|
+
export { addParamsToUrl, hasWindow, isOpenInBuilder, isOpenInPreviewShare, isOpeningInTimeline };
|
|
@@ -36,11 +36,20 @@ function isOpenInBuilder() {
|
|
|
36
36
|
}
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
39
|
+
function isOpenInPreviewShare() {
|
|
40
|
+
if (hasWindow()) {
|
|
41
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
42
|
+
const previewShare = urlParams.get("preview_share");
|
|
43
|
+
return !!previewShare;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
39
47
|
export {
|
|
40
48
|
addLivePreviewQueryTags,
|
|
41
49
|
addParamsToUrl,
|
|
42
50
|
hasWindow,
|
|
43
51
|
isOpenInBuilder,
|
|
52
|
+
isOpenInPreviewShare,
|
|
44
53
|
isOpeningInTimeline
|
|
45
54
|
};
|
|
46
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["import { PublicLogger } from \"../logger/logger\";\nimport { addLivePreviewQueryTags } from \"./addLivePreviewQueryTags\";\nexport function hasWindow(): boolean {\n return typeof window !== \"undefined\";\n}\nexport { addLivePreviewQueryTags };\nexport function addParamsToUrl() {\n // Setting the query params to all the click events related to current domain\n window.addEventListener(\"click\", (event: any) => {\n const clickedElement = event.target;\n const anchorElement = clickedElement.closest('a');\n \n // Only proceed if the clicked element is either an anchor or a direct/indirect child of an anchor\n if (!anchorElement || !anchorElement.contains(clickedElement)) {\n return;\n }\n\n const targetHref: string | any = anchorElement.href;\n const docOrigin: string = document.location.origin;\n if (\n targetHref &&\n targetHref.includes(docOrigin) &&\n !targetHref.includes(\"live_preview\")\n ) {\n const newUrl = addLivePreviewQueryTags(targetHref);\n anchorElement.href = newUrl || targetHref;\n }\n });\n}\nexport function isOpeningInTimeline(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const previewTimestamp = urlParams.get(\"preview_timestamp\");\n return !!previewTimestamp;\n }\n return false;\n}\n\nexport function isOpenInBuilder(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const builder = urlParams.get(\"builder\");\n return !!builder;\n }\n return false;\n}\n"],"mappings":";;;AACA,SAAS,+BAA+B;AACjC,SAAS,YAAqB;AACjC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,iBAAiB;AAE7B,SAAO,iBAAiB,SAAS,CAAC,UAAe;AAC7C,UAAM,iBAAiB,MAAM;AAC7B,UAAM,gBAAgB,eAAe,QAAQ,GAAG;AAGhD,QAAI,CAAC,iBAAiB,CAAC,cAAc,SAAS,cAAc,GAAG;AAC3D;AAAA,IACJ;AAEA,UAAM,aAA2B,cAAc;AAC/C,UAAM,YAAoB,SAAS,SAAS;AAC5C,QACI,cACA,WAAW,SAAS,SAAS,KAC7B,CAAC,WAAW,SAAS,cAAc,GACrC;AACE,YAAM,SAAS,wBAAwB,UAAU;AACjD,oBAAc,OAAO,UAAU;AAAA,IACnC;AAAA,EACJ,CAAC;AACL;AACO,SAAS,sBAA+B;AAC3C,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,mBAAmB,UAAU,IAAI,mBAAmB;AAC1D,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;AAEO,SAAS,kBAA2B;AACvC,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,UAAU,UAAU,IAAI,SAAS;AACvC,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/index.ts"],"sourcesContent":["import { PublicLogger } from \"../logger/logger\";\nimport { addLivePreviewQueryTags } from \"./addLivePreviewQueryTags\";\nexport function hasWindow(): boolean {\n return typeof window !== \"undefined\";\n}\nexport { addLivePreviewQueryTags };\nexport function addParamsToUrl() {\n // Setting the query params to all the click events related to current domain\n window.addEventListener(\"click\", (event: any) => {\n const clickedElement = event.target;\n const anchorElement = clickedElement.closest('a');\n \n // Only proceed if the clicked element is either an anchor or a direct/indirect child of an anchor\n if (!anchorElement || !anchorElement.contains(clickedElement)) {\n return;\n }\n\n const targetHref: string | any = anchorElement.href;\n const docOrigin: string = document.location.origin;\n if (\n targetHref &&\n targetHref.includes(docOrigin) &&\n !targetHref.includes(\"live_preview\")\n ) {\n const newUrl = addLivePreviewQueryTags(targetHref);\n anchorElement.href = newUrl || targetHref;\n }\n });\n}\nexport function isOpeningInTimeline(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const previewTimestamp = urlParams.get(\"preview_timestamp\");\n return !!previewTimestamp;\n }\n return false;\n}\n\nexport function isOpenInBuilder(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const builder = urlParams.get(\"builder\");\n return !!builder;\n }\n return false;\n}\n\n\nexport function isOpenInPreviewShare(): boolean {\n if (hasWindow()) {\n const urlParams = new URLSearchParams(window.location.search);\n const previewShare = urlParams.get(\"preview_share\");\n return !!previewShare;\n }\n return false;\n}\n"],"mappings":";;;AACA,SAAS,+BAA+B;AACjC,SAAS,YAAqB;AACjC,SAAO,OAAO,WAAW;AAC7B;AAEO,SAAS,iBAAiB;AAE7B,SAAO,iBAAiB,SAAS,CAAC,UAAe;AAC7C,UAAM,iBAAiB,MAAM;AAC7B,UAAM,gBAAgB,eAAe,QAAQ,GAAG;AAGhD,QAAI,CAAC,iBAAiB,CAAC,cAAc,SAAS,cAAc,GAAG;AAC3D;AAAA,IACJ;AAEA,UAAM,aAA2B,cAAc;AAC/C,UAAM,YAAoB,SAAS,SAAS;AAC5C,QACI,cACA,WAAW,SAAS,SAAS,KAC7B,CAAC,WAAW,SAAS,cAAc,GACrC;AACE,YAAM,SAAS,wBAAwB,UAAU;AACjD,oBAAc,OAAO,UAAU;AAAA,IACnC;AAAA,EACJ,CAAC;AACL;AACO,SAAS,sBAA+B;AAC3C,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,mBAAmB,UAAU,IAAI,mBAAmB;AAC1D,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;AAEO,SAAS,kBAA2B;AACvC,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,UAAU,UAAU,IAAI,SAAS;AACvC,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;AAGO,SAAS,uBAAgC;AAC5C,MAAI,UAAU,GAAG;AACb,UAAM,YAAY,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC5D,UAAM,eAAe,UAAU,IAAI,eAAe;AAClD,WAAO,CAAC,CAAC;AAAA,EACb;AACA,SAAO;AACX;","names":[]}
|
|
@@ -100,7 +100,8 @@ function FieldToolbarComponent(props) {
|
|
|
100
100
|
const {
|
|
101
101
|
eventDetails,
|
|
102
102
|
isVariant: isVariantOrParentOfVariant,
|
|
103
|
-
entryPermissions
|
|
103
|
+
entryPermissions,
|
|
104
|
+
entryWorkflowStageDetails
|
|
104
105
|
} = props;
|
|
105
106
|
const { fieldMetadata, editableElement: targetElement } = eventDetails;
|
|
106
107
|
const [isFormLoading, setIsFormLoading] = (0, import_compat.useState)(false);
|
|
@@ -134,7 +135,8 @@ function FieldToolbarComponent(props) {
|
|
|
134
135
|
editableElement: targetElement,
|
|
135
136
|
fieldMetadata
|
|
136
137
|
},
|
|
137
|
-
entryPermissions
|
|
138
|
+
entryPermissions,
|
|
139
|
+
entryWorkflowStageDetails
|
|
138
140
|
);
|
|
139
141
|
disableFieldActions = isDisabled;
|
|
140
142
|
fieldType = (0, import_getFieldType.getFieldType)(fieldSchema);
|