@contentstack/live-preview-utils 4.4.3 → 4.4.4

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.
Files changed (142) hide show
  1. package/README.md +3 -2
  2. package/dist/legacy/common/inIframe.cjs +9 -0
  3. package/dist/legacy/common/inIframe.cjs.map +1 -1
  4. package/dist/legacy/common/inIframe.d.cts +2 -1
  5. package/dist/legacy/common/inIframe.d.ts +2 -1
  6. package/dist/legacy/common/inIframe.js +8 -0
  7. package/dist/legacy/common/inIframe.js.map +1 -1
  8. package/dist/legacy/configManager/config.default.cjs +2 -1
  9. package/dist/legacy/configManager/config.default.cjs.map +1 -1
  10. package/dist/legacy/configManager/config.default.js +2 -1
  11. package/dist/legacy/configManager/config.default.js.map +1 -1
  12. package/dist/legacy/configManager/configManager.cjs +24 -5
  13. package/dist/legacy/configManager/configManager.cjs.map +1 -1
  14. package/dist/legacy/configManager/configManager.d.cts +11 -1
  15. package/dist/legacy/configManager/configManager.d.ts +11 -1
  16. package/dist/legacy/configManager/configManager.js +23 -5
  17. package/dist/legacy/configManager/configManager.js.map +1 -1
  18. package/dist/legacy/configManager/index.d.cts +1 -1
  19. package/dist/legacy/configManager/index.d.ts +1 -1
  20. package/dist/legacy/light-sdk.cjs +1 -1
  21. package/dist/legacy/light-sdk.js +1 -1
  22. package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.cjs +11 -8
  23. package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.cjs.map +1 -1
  24. package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.js +13 -10
  25. package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.js.map +1 -1
  26. package/dist/legacy/livePreview/onPageTraversal.cjs +1 -1
  27. package/dist/legacy/livePreview/onPageTraversal.cjs.map +1 -1
  28. package/dist/legacy/livePreview/onPageTraversal.js +1 -1
  29. package/dist/legacy/livePreview/onPageTraversal.js.map +1 -1
  30. package/dist/legacy/preview/contentstack-live-preview-HOC.cjs +37 -1
  31. package/dist/legacy/preview/contentstack-live-preview-HOC.cjs.map +1 -1
  32. package/dist/legacy/preview/contentstack-live-preview-HOC.d.cts +19 -0
  33. package/dist/legacy/preview/contentstack-live-preview-HOC.d.ts +19 -0
  34. package/dist/legacy/preview/contentstack-live-preview-HOC.js +39 -1
  35. package/dist/legacy/preview/contentstack-live-preview-HOC.js.map +1 -1
  36. package/dist/legacy/types/global.d.cjs +19 -0
  37. package/dist/legacy/types/global.d.cjs.map +1 -0
  38. package/dist/legacy/types/global.d.d.cts +8 -0
  39. package/dist/legacy/types/global.d.d.ts +8 -0
  40. package/dist/legacy/types/global.d.js +1 -0
  41. package/dist/legacy/types/global.d.js.map +1 -0
  42. package/dist/legacy/types/types.cjs.map +1 -1
  43. package/dist/legacy/types/types.d.cts +6 -1
  44. package/dist/legacy/types/types.d.ts +6 -1
  45. package/dist/legacy/types/types.js.map +1 -1
  46. package/dist/legacy/visualBuilder/index.cjs +8 -3
  47. package/dist/legacy/visualBuilder/index.cjs.map +1 -1
  48. package/dist/legacy/visualBuilder/index.js +8 -3
  49. package/dist/legacy/visualBuilder/index.js.map +1 -1
  50. package/dist/legacy/visualBuilder/utils/getVisualBuilderRedirectionUrl.cjs +8 -0
  51. package/dist/legacy/visualBuilder/utils/getVisualBuilderRedirectionUrl.cjs.map +1 -1
  52. package/dist/legacy/visualBuilder/utils/getVisualBuilderRedirectionUrl.js +8 -0
  53. package/dist/legacy/visualBuilder/utils/getVisualBuilderRedirectionUrl.js.map +1 -1
  54. package/dist/legacy/visualBuilder/utils/resolvePageContext.cjs +49 -0
  55. package/dist/legacy/visualBuilder/utils/resolvePageContext.cjs.map +1 -0
  56. package/dist/legacy/visualBuilder/utils/resolvePageContext.d.cts +6 -0
  57. package/dist/legacy/visualBuilder/utils/resolvePageContext.d.ts +6 -0
  58. package/dist/legacy/visualBuilder/utils/resolvePageContext.js +16 -0
  59. package/dist/legacy/visualBuilder/utils/resolvePageContext.js.map +1 -0
  60. package/dist/legacy/visualBuilder/utils/types/postMessage.types.cjs +1 -0
  61. package/dist/legacy/visualBuilder/utils/types/postMessage.types.cjs.map +1 -1
  62. package/dist/legacy/visualBuilder/utils/types/postMessage.types.d.cts +6 -1
  63. package/dist/legacy/visualBuilder/utils/types/postMessage.types.d.ts +6 -1
  64. package/dist/legacy/visualBuilder/utils/types/postMessage.types.js +1 -0
  65. package/dist/legacy/visualBuilder/utils/types/postMessage.types.js.map +1 -1
  66. package/dist/modern/common/inIframe.cjs +9 -0
  67. package/dist/modern/common/inIframe.cjs.map +1 -1
  68. package/dist/modern/common/inIframe.d.cts +2 -1
  69. package/dist/modern/common/inIframe.d.ts +2 -1
  70. package/dist/modern/common/inIframe.js +8 -0
  71. package/dist/modern/common/inIframe.js.map +1 -1
  72. package/dist/modern/configManager/config.default.cjs +2 -1
  73. package/dist/modern/configManager/config.default.cjs.map +1 -1
  74. package/dist/modern/configManager/config.default.js +2 -1
  75. package/dist/modern/configManager/config.default.js.map +1 -1
  76. package/dist/modern/configManager/configManager.cjs +24 -5
  77. package/dist/modern/configManager/configManager.cjs.map +1 -1
  78. package/dist/modern/configManager/configManager.d.cts +11 -1
  79. package/dist/modern/configManager/configManager.d.ts +11 -1
  80. package/dist/modern/configManager/configManager.js +23 -5
  81. package/dist/modern/configManager/configManager.js.map +1 -1
  82. package/dist/modern/configManager/index.d.cts +1 -1
  83. package/dist/modern/configManager/index.d.ts +1 -1
  84. package/dist/modern/light-sdk.cjs +1 -1
  85. package/dist/modern/light-sdk.js +1 -1
  86. package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.cjs +11 -8
  87. package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.cjs.map +1 -1
  88. package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.js +13 -10
  89. package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.js.map +1 -1
  90. package/dist/modern/livePreview/onPageTraversal.cjs +1 -1
  91. package/dist/modern/livePreview/onPageTraversal.cjs.map +1 -1
  92. package/dist/modern/livePreview/onPageTraversal.js +1 -1
  93. package/dist/modern/livePreview/onPageTraversal.js.map +1 -1
  94. package/dist/modern/preview/contentstack-live-preview-HOC.cjs +36 -1
  95. package/dist/modern/preview/contentstack-live-preview-HOC.cjs.map +1 -1
  96. package/dist/modern/preview/contentstack-live-preview-HOC.d.cts +19 -0
  97. package/dist/modern/preview/contentstack-live-preview-HOC.d.ts +19 -0
  98. package/dist/modern/preview/contentstack-live-preview-HOC.js +38 -1
  99. package/dist/modern/preview/contentstack-live-preview-HOC.js.map +1 -1
  100. package/dist/modern/types/global.d.cjs +19 -0
  101. package/dist/modern/types/global.d.cjs.map +1 -0
  102. package/dist/modern/types/global.d.d.cts +8 -0
  103. package/dist/modern/types/global.d.d.ts +8 -0
  104. package/dist/modern/types/global.d.js +1 -0
  105. package/dist/modern/types/global.d.js.map +1 -0
  106. package/dist/modern/types/types.cjs.map +1 -1
  107. package/dist/modern/types/types.d.cts +6 -1
  108. package/dist/modern/types/types.d.ts +6 -1
  109. package/dist/modern/types/types.js.map +1 -1
  110. package/dist/modern/visualBuilder/index.cjs +8 -3
  111. package/dist/modern/visualBuilder/index.cjs.map +1 -1
  112. package/dist/modern/visualBuilder/index.js +8 -3
  113. package/dist/modern/visualBuilder/index.js.map +1 -1
  114. package/dist/modern/visualBuilder/utils/getVisualBuilderRedirectionUrl.cjs +8 -0
  115. package/dist/modern/visualBuilder/utils/getVisualBuilderRedirectionUrl.cjs.map +1 -1
  116. package/dist/modern/visualBuilder/utils/getVisualBuilderRedirectionUrl.js +8 -0
  117. package/dist/modern/visualBuilder/utils/getVisualBuilderRedirectionUrl.js.map +1 -1
  118. package/dist/modern/visualBuilder/utils/resolvePageContext.cjs +48 -0
  119. package/dist/modern/visualBuilder/utils/resolvePageContext.cjs.map +1 -0
  120. package/dist/modern/visualBuilder/utils/resolvePageContext.d.cts +6 -0
  121. package/dist/modern/visualBuilder/utils/resolvePageContext.d.ts +6 -0
  122. package/dist/modern/visualBuilder/utils/resolvePageContext.js +15 -0
  123. package/dist/modern/visualBuilder/utils/resolvePageContext.js.map +1 -0
  124. package/dist/modern/visualBuilder/utils/types/postMessage.types.cjs +1 -0
  125. package/dist/modern/visualBuilder/utils/types/postMessage.types.cjs.map +1 -1
  126. package/dist/modern/visualBuilder/utils/types/postMessage.types.d.cts +6 -1
  127. package/dist/modern/visualBuilder/utils/types/postMessage.types.d.ts +6 -1
  128. package/dist/modern/visualBuilder/utils/types/postMessage.types.js +1 -0
  129. package/dist/modern/visualBuilder/utils/types/postMessage.types.js.map +1 -1
  130. package/package.json +1 -1
  131. package/dist/legacy/utils/handlePageTraversal.cjs +0 -47
  132. package/dist/legacy/utils/handlePageTraversal.cjs.map +0 -1
  133. package/dist/legacy/utils/handlePageTraversal.d.cts +0 -3
  134. package/dist/legacy/utils/handlePageTraversal.d.ts +0 -3
  135. package/dist/legacy/utils/handlePageTraversal.js +0 -24
  136. package/dist/legacy/utils/handlePageTraversal.js.map +0 -1
  137. package/dist/modern/utils/handlePageTraversal.cjs +0 -47
  138. package/dist/modern/utils/handlePageTraversal.cjs.map +0 -1
  139. package/dist/modern/utils/handlePageTraversal.d.cts +0 -3
  140. package/dist/modern/utils/handlePageTraversal.d.ts +0 -3
  141. package/dist/modern/utils/handlePageTraversal.js +0 -24
  142. package/dist/modern/utils/handlePageTraversal.js.map +0 -1
@@ -1 +1 @@
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, stackDetails } = 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 if (ssr && !event_type) {\n const url = new URL(window.location.href);\n let live_preview = url.searchParams.get(\"live_preview\");\n let content_type_uid = url.searchParams.get(\"content_type_uid\");\n let entry_uid = url.searchParams.get(\"entry_uid\");\n\n if (live_preview && content_type_uid && entry_uid) {\n // All required params are present, just reload\n window.location.reload();\n } else {\n live_preview = event.data.hash;\n content_type_uid = event.data.content_type_uid || stackDetails.contentTypeUid?.toString() || \"\";\n entry_uid = event.data.entry_uid || stackDetails.entryUid?.toString() || \"\";\n // Set missing params and redirect\n url.searchParams.set(\"live_preview\", live_preview);\n if (content_type_uid) {\n url.searchParams.set(\n \"content_type_uid\",\n content_type_uid\n );\n }\n if (entry_uid) {\n url.searchParams.set(\n \"entry_uid\",\n entry_uid\n );\n }\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 } catch (error) {\n PublicLogger.error(\"Error handling live preview update:\", error);\n return;\n }\n }\n );\n}\n\nexport function sendInitializeLivePreviewPostMessageEvent(): void {\n const config = Config.get();\n const initConfig: {\n shouldReload: boolean;\n href: string;\n sdkVersion: string | undefined;\n mode: number;\n enableLivePreviewOutsideIframe?: boolean;\n } = {\n shouldReload: config.ssr,\n href: window.location.href,\n sdkVersion: process?.env?.PACKAGE_VERSION,\n mode: config.mode,\n };\n\n if (config.enableLivePreviewOutsideIframe !== undefined) {\n initConfig.enableLivePreviewOutsideIframe = config.enableLivePreviewOutsideIframe;\n }\n\n livePreviewPostMessage\n ?.send<LivePreviewInitEventResponse>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.INIT,\n {\n config: initConfig,\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 (\n Config.get().ssr ||\n isOpeningInTimeline() ||\n isOpeningInNewTab()\n ) {\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;AAlBnD;AAmBI,sDAAwB;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;AAER;AAKO,SAAS,mCAAyC;AA/CzD;AAgDI,sDA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d,2CAAmC;AAAA,MACvC,GAAG,IAAI;AAAA,IACX;AAEA,+BAA2B;AAC3B,qCAAiC;AAAA,EACrC,GACC,MAAM,CAAC,MAAM;AAAA,EAGd;AACR;AAEA,SAAS,qCAA2C;AApMpD;AAqMI,sDACM,KAAK,iCAAiC,kBAAkB;AAAA,IACtD,MAAM,OAAO,SAAS;AAAA,EAC1B,GACC,MAAM,MAAM;AAAA,EAEb;AACR;","names":["_a"]}
1
+ {"version":3,"sources":["../../../../src/livePreview/eventManager/postMessageEvent.hooks.ts"],"sourcesContent":["import { inVisualEditor, isOpeningInNewTab } from \"../../common/inIframe\";\nimport Config, { syncToStackSdk } 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, stackDetails } = Config.get();\n const event_type = event.data._metadata?.event_type;\n // hash is typed as required string, guard is a safety net\n if (event.data.hash) {\n Config.set(\"hash\", event.data.hash);\n syncToStackSdk({ hash: 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 if (ssr && !event_type) {\n const url = new URL(window.location.href);\n let live_preview = url.searchParams.get(\"live_preview\");\n let content_type_uid = url.searchParams.get(\"content_type_uid\");\n let entry_uid = url.searchParams.get(\"entry_uid\");\n\n if (live_preview && content_type_uid && entry_uid) {\n // All required params are present, just reload\n window.location.reload();\n } else {\n live_preview = event.data.hash;\n content_type_uid = event.data.content_type_uid || stackDetails.contentTypeUid?.toString() || \"\";\n entry_uid = event.data.entry_uid || stackDetails.entryUid?.toString() || \"\";\n // Set missing params and redirect\n url.searchParams.set(\"live_preview\", live_preview);\n if (content_type_uid) {\n url.searchParams.set(\n \"content_type_uid\",\n content_type_uid\n );\n }\n if (entry_uid) {\n url.searchParams.set(\n \"entry_uid\",\n entry_uid\n );\n }\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 } catch (error) {\n PublicLogger.error(\"Error handling live preview update:\", error);\n return;\n }\n }\n );\n}\n\nexport function sendInitializeLivePreviewPostMessageEvent(): void {\n const config = Config.get();\n const initConfig: {\n shouldReload: boolean;\n href: string;\n sdkVersion: string | undefined;\n mode: number;\n enableLivePreviewOutsideIframe?: boolean;\n } = {\n shouldReload: config.ssr,\n href: window.location.href,\n sdkVersion: process?.env?.PACKAGE_VERSION,\n mode: config.mode,\n };\n\n if (config.enableLivePreviewOutsideIframe !== undefined) {\n initConfig.enableLivePreviewOutsideIframe = config.enableLivePreviewOutsideIframe;\n }\n\n livePreviewPostMessage\n ?.send<LivePreviewInitEventResponse>(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.INIT,\n {\n config: initConfig,\n }\n )\n .then((data) => {\n const {\n contentTypeUid,\n entryUid,\n windowType = ILivePreviewWindowType.PREVIEW,\n } = data || {};\n\n if(inVisualEditor()){\n return;\n }\n\n // TODO: the upper condition will the handle the visual editor init double firing issue so later we can remove this once verified\n if (Config?.get()?.windowType && Config.get().windowType === ILivePreviewWindowType.BUILDER) {\n return;\n }\n\n if (contentTypeUid && entryUid) {\n // Sync is explicit here intentionally: auto-effects via deepsignal would go blind when Config.reset() is called.\n Config.set(\"stackDetails.contentTypeUid\", contentTypeUid);\n Config.set(\"stackDetails.entryUid\", entryUid);\n syncToStackSdk({ contentTypeUid, entryUid });\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 (\n Config.get().ssr ||\n isOpeningInTimeline() ||\n isOpeningInNewTab()\n ) {\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_MESSAG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"]}
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(onPageTraversal_exports);
36
36
  var import_livePreviewEventManager = __toESM(require("./eventManager/livePreviewEventManager.cjs"), 1);
37
37
  var import_livePreviewEventManager2 = require("./eventManager/livePreviewEventManager.constant.cjs");
38
38
  function handlePageTraversal() {
39
- window.addEventListener("unload", () => {
39
+ window.addEventListener("pagehide", () => {
40
40
  var _a;
41
41
  const targetURL = document.activeElement.href;
42
42
  if (targetURL) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/livePreview/onPageTraversal.ts"],"sourcesContent":["import livePreviewPostMessage from \"./eventManager/livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./eventManager/livePreviewEventManager.constant\";\n\nexport function handlePageTraversal(): void {\n window.addEventListener(\"unload\", () => {\n const targetURL = (document.activeElement as HTMLAnchorElement).href;\n if (targetURL) {\n livePreviewPostMessage?.send(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.URL_CHANGE,\n {\n targetURL,\n }\n );\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAAmC;AACnC,IAAAA,kCAAiD;AAE1C,SAAS,sBAA4B;AACxC,SAAO,iBAAiB,UAAU,MAAM;AAJ5C;AAKQ,UAAM,YAAa,SAAS,cAAoC;AAChE,QAAI,WAAW;AACX,2CAAAC,YAAA,mBAAwB;AAAA,QACpB,iEAAiC;AAAA,QACjC;AAAA,UACI;AAAA,QACJ;AAAA;AAAA,IAER;AAAA,EACJ,CAAC;AACL;","names":["import_livePreviewEventManager","livePreviewPostMessage"]}
1
+ {"version":3,"sources":["../../../src/livePreview/onPageTraversal.ts"],"sourcesContent":["import livePreviewPostMessage from \"./eventManager/livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./eventManager/livePreviewEventManager.constant\";\n\nexport function handlePageTraversal(): void {\n window.addEventListener(\"pagehide\", () => {\n const targetURL = (document.activeElement as HTMLAnchorElement).href;\n if (targetURL) {\n livePreviewPostMessage?.send(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.URL_CHANGE,\n {\n targetURL,\n }\n );\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAAmC;AACnC,IAAAA,kCAAiD;AAE1C,SAAS,sBAA4B;AACxC,SAAO,iBAAiB,YAAY,MAAM;AAJ9C;AAKQ,UAAM,YAAa,SAAS,cAAoC;AAChE,QAAI,WAAW;AACX,2CAAAC,YAAA,mBAAwB;AAAA,QACpB,iEAAiC;AAAA,QACjC;AAAA,UACI;AAAA,QACJ;AAAA;AAAA,IAER;AAAA,EACJ,CAAC;AACL;","names":["import_livePreviewEventManager","livePreviewPostMessage"]}
@@ -4,7 +4,7 @@ import "../chunk-5WRI5ZAA.js";
4
4
  import livePreviewPostMessage from "./eventManager/livePreviewEventManager.js";
5
5
  import { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from "./eventManager/livePreviewEventManager.constant.js";
6
6
  function handlePageTraversal() {
7
- window.addEventListener("unload", () => {
7
+ window.addEventListener("pagehide", () => {
8
8
  var _a;
9
9
  const targetURL = document.activeElement.href;
10
10
  if (targetURL) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/livePreview/onPageTraversal.ts"],"sourcesContent":["import livePreviewPostMessage from \"./eventManager/livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./eventManager/livePreviewEventManager.constant\";\n\nexport function handlePageTraversal(): void {\n window.addEventListener(\"unload\", () => {\n const targetURL = (document.activeElement as HTMLAnchorElement).href;\n if (targetURL) {\n livePreviewPostMessage?.send(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.URL_CHANGE,\n {\n targetURL,\n }\n );\n }\n });\n}\n"],"mappings":";;;AAAA,OAAO,4BAA4B;AACnC,SAAS,wCAAwC;AAE1C,SAAS,sBAA4B;AACxC,SAAO,iBAAiB,UAAU,MAAM;AAJ5C;AAKQ,UAAM,YAAa,SAAS,cAAoC;AAChE,QAAI,WAAW;AACX,0DAAwB;AAAA,QACpB,iCAAiC;AAAA,QACjC;AAAA,UACI;AAAA,QACJ;AAAA;AAAA,IAER;AAAA,EACJ,CAAC;AACL;","names":[]}
1
+ {"version":3,"sources":["../../../src/livePreview/onPageTraversal.ts"],"sourcesContent":["import livePreviewPostMessage from \"./eventManager/livePreviewEventManager\";\nimport { LIVE_PREVIEW_POST_MESSAGE_EVENTS } from \"./eventManager/livePreviewEventManager.constant\";\n\nexport function handlePageTraversal(): void {\n window.addEventListener(\"pagehide\", () => {\n const targetURL = (document.activeElement as HTMLAnchorElement).href;\n if (targetURL) {\n livePreviewPostMessage?.send(\n LIVE_PREVIEW_POST_MESSAGE_EVENTS.URL_CHANGE,\n {\n targetURL,\n }\n );\n }\n });\n}\n"],"mappings":";;;AAAA,OAAO,4BAA4B;AACnC,SAAS,wCAAwC;AAE1C,SAAS,sBAA4B;AACxC,SAAO,iBAAiB,YAAY,MAAM;AAJ9C;AAKQ,UAAM,YAAa,SAAS,cAAoC;AAChE,QAAI,WAAW;AACX,0DAAwB;AAAA,QACpB,iCAAiC;AAAA,QACjC;AAAA,UACI;AAAA,QACJ;AAAA;AAAA,IAER;AAAA,EACJ,CAAC;AACL;","names":[]}
@@ -35,6 +35,7 @@ __export(contentstack_live_preview_HOC_exports, {
35
35
  module.exports = __toCommonJS(contentstack_live_preview_HOC_exports);
36
36
  var import_lodash_es = require("lodash-es");
37
37
  var import_uuid = require("uuid");
38
+ var import_inIframe = require("../common/inIframe.cjs");
38
39
  var import_config = require("../configManager/config.default.cjs");
39
40
  var import_configManager = __toESM(require("../configManager/configManager.cjs"), 1);
40
41
  var import_live_preview = __toESM(require("../livePreview/live-preview.cjs"), 1);
@@ -43,6 +44,8 @@ var import_removeFromOnChangeSubscribers = require("../livePreview/removeFromOnC
43
44
  var import_logger = require("../logger/logger.cjs");
44
45
  var import_compare = require("../timeline/compare/compare.cjs");
45
46
  var import_visualBuilder = require("../visualBuilder/index.cjs");
47
+ var import_visualBuilderPostMessage = __toESM(require("../visualBuilder/utils/visualBuilderPostMessage.cjs"), 1);
48
+ var import_postMessage = require("../visualBuilder/utils/types/postMessage.types.cjs");
46
49
  var _ContentstackLivePreview = class _ContentstackLivePreview {
47
50
  /**
48
51
  * Initializes the Live Preview SDK with the provided user configuration.
@@ -222,12 +225,45 @@ var _ContentstackLivePreview = class _ContentstackLivePreview {
222
225
  callback
223
226
  );
224
227
  }
228
+ /**
229
+ * Sets the page-level entry context for the current page.
230
+ * Used by the Visual Builder "Start Editing" button to know which entry
231
+ * the current page is rendering, enabling accurate VB navigation.
232
+ *
233
+ * Place this call alongside your existing `addEditableTags` call — both
234
+ * reference the same `entry` object so there is no extra lookup.
235
+ *
236
+ * @example
237
+ * ```js
238
+ * // In your page component / useEffect
239
+ * Utils.addEditableTags(entry, "blog_post", true, "en-us");
240
+ * ContentstackLivePreview.setPageContext({ entryUid: entry.uid, contentTypeUid: "blog_post" });
241
+ * ```
242
+ */
243
+ static setPageContext(context) {
244
+ var _a;
245
+ import_configManager.default.set("pageContext", context);
246
+ if ((0, import_inIframe.inIframe)()) {
247
+ (_a = import_visualBuilderPostMessage.default) == null ? void 0 : _a.send(
248
+ import_postMessage.VisualBuilderPostMessageEvents.PAGE_CONTEXT,
249
+ {
250
+ entryUid: context.entryUid,
251
+ contentTypeUid: context.contentTypeUid
252
+ }
253
+ ).catch((error) => {
254
+ import_logger.PublicLogger.error(
255
+ "Failed to send page context to Visual Builder.",
256
+ error
257
+ );
258
+ });
259
+ }
260
+ }
225
261
  /**
226
262
  * Retrieves the version of the SDK.
227
263
  * @returns The version of the SDK as a string.
228
264
  */
229
265
  static getSdkVersion() {
230
- return "4.4.3";
266
+ return "4.4.4";
231
267
  }
232
268
  };
233
269
  _ContentstackLivePreview.previewConstructors = {};
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preview/contentstack-live-preview-HOC.ts"],"sourcesContent":["import { cloneDeep, isEmpty, pick } from \"lodash-es\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { getUserInitData } from \"../configManager/config.default\";\nimport Config, { updateConfigFromUrl } from \"../configManager/configManager\";\nimport LivePreview from \"../livePreview/live-preview\";\nimport { handlePageTraversal } from \"../livePreview/onPageTraversal\";\nimport { removeFromOnChangeSubscribers } from \"../livePreview/removeFromOnChangeSubscribers\";\nimport {\n OnEntryChangeCallback,\n OnEntryChangeCallbackSubscribers,\n OnEntryChangeCallbackUID,\n OnEntryChangeConfig,\n OnEntryChangeUnsubscribeParameters,\n} from \"../livePreview/types/onEntryChangeCallback.type\";\nimport { PublicLogger } from \"../logger/logger\";\nimport { handleWebCompare } from \"../timeline/compare/compare\";\nimport type { IExportedConfig, IInitData } from \"../types/types\";\nimport { VisualBuilder } from \"../visualBuilder\";\n\nclass ContentstackLivePreview {\n private static previewConstructors:\n | {\n livePreview: LivePreview;\n visualBuilder: VisualBuilder;\n }\n | Record<string, never> = {};\n\n /**\n * The subscribers for the onEntryChange event. We store them here when the SDK is not initialized.\n */\n private static onEntryChangeCallbacks: OnEntryChangeCallbackSubscribers =\n {};\n\n /**\n * Initializes the Live Preview SDK with the provided user configuration.\n * If the SDK is already initialized, subsequent calls to this method will return the existing SDK instance.\n * @param userConfig - The user configuration to initialize the SDK with. See {@link https://github.com/contentstack/live-preview-sdk/blob/main/docs/live-preview-configs.md#initconfig-iconfig|Live preview User config} for more details.\n * @returns A promise that resolves to the constructors of the Live Preview SDK.\n */\n static init(\n userConfig: Partial<IInitData> = getUserInitData()\n ): Promise<typeof ContentstackLivePreview.previewConstructors> {\n if (typeof window === \"undefined\") {\n PublicLogger.warn(\"The SDK is not initialized in the browser.\");\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n // handle user config\n Config.replace(userConfig);\n updateConfigFromUrl();\n\n if (ContentstackLivePreview.isInitialized()) {\n PublicLogger.warn(\n \"You have already initialized the Live Preview SDK. So, any subsequent initialization returns the existing SDK instance.\"\n );\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n } else {\n return ContentstackLivePreview.initializePreview();\n }\n }\n\n /**\n * It is the live preview hash.\n * This hash could be used when data is fetched manually.\n */\n static get hash(): string {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n return Config.get().hash;\n }\n\n static get config(): IExportedConfig {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n const config = Config.get();\n const clonedConfig = cloneDeep(config);\n const configToShare = pick(clonedConfig, [\n 'ssr',\n 'enable',\n 'cleanCslpOnProduction',\n 'stackDetails',\n 'clientUrlParams',\n 'windowType',\n 'hash',\n 'editButton',\n 'mode',\n ]);\n return configToShare;\n }\n\n private static isInitialized(): boolean {\n return !isEmpty(ContentstackLivePreview.previewConstructors);\n }\n\n private static initializePreview() {\n ContentstackLivePreview.previewConstructors = {\n livePreview: new LivePreview(),\n visualBuilder: new VisualBuilder(),\n };\n\n // set up onEntryChange callbacks added when the SDK was not initialized\n const livePreview =\n ContentstackLivePreview.previewConstructors.livePreview;\n Object.entries(ContentstackLivePreview.onEntryChangeCallbacks).forEach(\n ([callbackUid, callback]) => {\n livePreview.subscribeToOnEntryChange(callback, callbackUid);\n }\n );\n\n ContentstackLivePreview.onEntryChangeCallbacks = {};\n\n handlePageTraversal();\n handleWebCompare();\n\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n /**\n * Registers a callback function to be called when an entry changes.\n * @param onChangeCallback The callback function to be called when an entry changes.\n * @param config Optional configuration for the callback.\n * @param config.skipInitialRender If true, the callback will not be called when it is first registered.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n */\n static onEntryChange(\n onChangeCallback: OnEntryChangeCallback,\n config: OnEntryChangeConfig = {}\n ): OnEntryChangeCallbackUID {\n const { skipInitialRender = false } = config;\n\n const callbackUid = uuidv4();\n\n if (ContentstackLivePreview.isInitialized()) {\n ContentstackLivePreview.previewConstructors.livePreview.subscribeToOnEntryChange(\n onChangeCallback,\n callbackUid\n );\n } else {\n ContentstackLivePreview.onEntryChangeCallbacks[callbackUid] =\n onChangeCallback;\n }\n\n const searchParams =\n typeof window !== \"undefined\"\n ? new URLSearchParams(window.location.search)\n : null;\n const hasLivePreviewHash =\n searchParams && searchParams.has(\"live_preview\");\n const isBuilder = searchParams && searchParams.has(\"builder\");\n const shouldCallCallback = hasLivePreviewHash && isBuilder;\n // calling onChangeCallback when live_preview search parameter\n // is present because we don't send the initial client-data-send\n // message in visual builder\n if (!skipInitialRender || shouldCallCallback) {\n onChangeCallback();\n }\n\n return callbackUid;\n }\n\n /**\n * Registers a callback function to be called when there is a change in the entry being edited in live preview mode. The difference between this and `onEntryChange` is that this callback will not be called when it is first registered.\n * @param onChangeCallback The callback function to be called when there is a change in the entry.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n */\n static onLiveEdit(\n onChangeCallback: OnEntryChangeCallback\n ): OnEntryChangeCallbackUID {\n return ContentstackLivePreview.onEntryChange(onChangeCallback, {\n skipInitialRender: true,\n });\n }\n\n /**\n * Unsubscribes from the entry change event.\n * @param callback - The callback function to be unsubscribed.\n *\n * @example\n * ```js\n * // unsubscribing using the Callback UID\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n * @example\n * ```js\n * // unsubscribing using the callback function\n * const callback = () => {console.log(\"Entry changed\")};\n * ContentstackLivePreview.onEntryChange(callback);\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callback);\n * ```\n *\n * @example\n * ```js\n * // The same is applicable to onLiveEdit\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n *\n */\n static unsubscribeOnEntryChange(\n callback: OnEntryChangeUnsubscribeParameters\n ): void {\n if (!ContentstackLivePreview.isInitialized()) {\n removeFromOnChangeSubscribers(\n ContentstackLivePreview.onEntryChangeCallbacks,\n callback\n );\n return;\n }\n ContentstackLivePreview.previewConstructors.livePreview.unsubscribeOnEntryChange(\n callback\n );\n }\n\n /**\n * Retrieves the version of the SDK.\n * @returns The version of the SDK as a string.\n */\n static getSdkVersion(): string {\n return process?.env?.PACKAGE_VERSION!;\n }\n}\n\nexport default ContentstackLivePreview;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyC;AACzC,kBAA6B;AAC7B,oBAAgC;AAChC,2BAA4C;AAC5C,0BAAwB;AACxB,6BAAoC;AACpC,2CAA8C;AAQ9C,oBAA6B;AAC7B,qBAAiC;AAEjC,2BAA8B;AAE9B,IAAM,2BAAN,MAAM,yBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,OAAO,KACH,iBAAiC,+BAAgB,GACU;AAC3D,QAAI,OAAO,WAAW,aAAa;AAC/B,iCAAa,KAAK,4CAA4C;AAC9D,aAAO,QAAQ,QAAQ,yBAAwB,mBAAmB;AAAA,IACtE;AAGA,yBAAAA,QAAO,QAAQ,UAAU;AACzB,kDAAoB;AAEpB,QAAI,yBAAwB,cAAc,GAAG;AACzC,iCAAa;A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AAAA;AAAA,EAMA,OAAO,gBAAwB;AAC3B,WAAO;AAAA,EACX;AACJ;AA7OM,yBACa,sBAKe,CAAC;AAAA;AAAA;AAAA;AAN7B,yBAWa,yBACX,CAAC;AAZT,IAAM,0BAAN;AA+OA,IAAO,wCAAQ;","names":["Config","LivePreview","uuidv4"]}
1
+ {"version":3,"sources":["../../../src/preview/contentstack-live-preview-HOC.ts"],"sourcesContent":["import { cloneDeep, isEmpty, pick } from \"lodash-es\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { inIframe } from \"../common/inIframe\";\nimport { getUserInitData } from \"../configManager/config.default\";\nimport Config, { updateConfigFromUrl } from \"../configManager/configManager\";\nimport LivePreview from \"../livePreview/live-preview\";\nimport { handlePageTraversal } from \"../livePreview/onPageTraversal\";\nimport { removeFromOnChangeSubscribers } from \"../livePreview/removeFromOnChangeSubscribers\";\nimport {\n OnEntryChangeCallback,\n OnEntryChangeCallbackSubscribers,\n OnEntryChangeCallbackUID,\n OnEntryChangeConfig,\n OnEntryChangeUnsubscribeParameters,\n} from \"../livePreview/types/onEntryChangeCallback.type\";\nimport { PublicLogger } from \"../logger/logger\";\nimport { handleWebCompare } from \"../timeline/compare/compare\";\nimport type { IExportedConfig, IInitData } from \"../types/types\";\nimport { VisualBuilder } from \"../visualBuilder\";\nimport visualBuilderPostMessage from \"../visualBuilder/utils/visualBuilderPostMessage\";\nimport {\n IPageContextPostMessageEvent,\n VisualBuilderPostMessageEvents,\n} from \"../visualBuilder/utils/types/postMessage.types\";\n\nclass ContentstackLivePreview {\n private static previewConstructors:\n | {\n livePreview: LivePreview;\n visualBuilder: VisualBuilder;\n }\n | Record<string, never> = {};\n\n /**\n * The subscribers for the onEntryChange event. We store them here when the SDK is not initialized.\n */\n private static onEntryChangeCallbacks: OnEntryChangeCallbackSubscribers =\n {};\n\n /**\n * Initializes the Live Preview SDK with the provided user configuration.\n * If the SDK is already initialized, subsequent calls to this method will return the existing SDK instance.\n * @param userConfig - The user configuration to initialize the SDK with. See {@link https://github.com/contentstack/live-preview-sdk/blob/main/docs/live-preview-configs.md#initconfig-iconfig|Live preview User config} for more details.\n * @returns A promise that resolves to the constructors of the Live Preview SDK.\n */\n static init(\n userConfig: Partial<IInitData> = getUserInitData()\n ): Promise<typeof ContentstackLivePreview.previewConstructors> {\n if (typeof window === \"undefined\") {\n PublicLogger.warn(\"The SDK is not initialized in the browser.\");\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n // handle user config\n Config.replace(userConfig);\n updateConfigFromUrl();\n\n if (ContentstackLivePreview.isInitialized()) {\n PublicLogger.warn(\n \"You have already initialized the Live Preview SDK. So, any subsequent initialization returns the existing SDK instance.\"\n );\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n } else {\n return ContentstackLivePreview.initializePreview();\n }\n }\n\n /**\n * It is the live preview hash.\n * This hash could be used when data is fetched manually.\n */\n static get hash(): string {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n return Config.get().hash;\n }\n\n static get config(): IExportedConfig {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n const config = Config.get();\n const clonedConfig = cloneDeep(config);\n const configToShare = pick(clonedConfig, [\n 'ssr',\n 'enable',\n 'cleanCslpOnProduction',\n 'stackDetails',\n 'clientUrlParams',\n 'windowType',\n 'hash',\n 'editButton',\n 'mode',\n ]);\n return configToShare;\n }\n\n private static isInitialized(): boolean {\n return !isEmpty(ContentstackLivePreview.previewConstructors);\n }\n\n private static initializePreview() {\n ContentstackLivePreview.previewConstructors = {\n livePreview: new LivePreview(),\n visualBuilder: new VisualBuilder(),\n };\n\n // set up onEntryChange callbacks added when the SDK was not initialized\n const livePreview =\n ContentstackLivePreview.previewConstructors.livePreview;\n Object.entries(ContentstackLivePreview.onEntryChangeCallbacks).forEach(\n ([callbackUid, callback]) => {\n livePreview.subscribeToOnEntryChange(callback, callbackUid);\n }\n );\n\n ContentstackLivePreview.onEntryChangeCallbacks = {};\n\n handlePageTraversal();\n handleWebCompare();\n\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n /**\n * Registers a callback function to be called when an entry changes.\n * @param onChangeCallback The callback function to be called when an entry changes.\n * @param config Optional configuration for the callback.\n * @param config.skipInitialRender If true, the callback will not be called when it is first registered.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n */\n static onEntryChange(\n onChangeCallback: OnEntryChangeCallback,\n config: OnEntryChangeConfig = {}\n ): OnEntryChangeCallbackUID {\n const { skipInitialRender = false } = config;\n\n const callbackUid = uuidv4();\n\n if (ContentstackLivePreview.isInitialized()) {\n ContentstackLivePreview.previewConstructors.livePreview.subscribeToOnEntryChange(\n onChangeCallback,\n callbackUid\n );\n } else {\n ContentstackLivePreview.onEntryChangeCallbacks[callbackUid] =\n onChangeCallback;\n }\n\n const searchParams =\n typeof window !== \"undefined\"\n ? new URLSearchParams(window.location.search)\n : null;\n const hasLivePreviewHash =\n searchParams && searchParams.has(\"live_preview\");\n const isBuilder = searchParams && searchParams.has(\"builder\");\n const shouldCallCallback = hasLivePreviewHash && isBuilder;\n // calling onChangeCallback when live_preview search parameter\n // is present because we don't send the initial client-data-send\n // message in visual builder\n if (!skipInitialRender || shouldCallCallback) {\n onChangeCallback();\n }\n\n return callbackUid;\n }\n\n /**\n * Registers a callback function to be called when there is a change in the entry being edited in live preview mode. The difference between this and `onEntryChange` is that this callback will not be called when it is first registered.\n * @param onChangeCallback The callback function to be called when there is a change in the entry.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n */\n static onLiveEdit(\n onChangeCallback: OnEntryChangeCallback\n ): OnEntryChangeCallbackUID {\n return ContentstackLivePreview.onEntryChange(onChangeCallback, {\n skipInitialRender: true,\n });\n }\n\n /**\n * Unsubscribes from the entry change event.\n * @param callback - The callback function to be unsubscribed.\n *\n * @example\n * ```js\n * // unsubscribing using the Callback UID\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n * @example\n * ```js\n * // unsubscribing using the callback function\n * const callback = () => {console.log(\"Entry changed\")};\n * ContentstackLivePreview.onEntryChange(callback);\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callback);\n * ```\n *\n * @example\n * ```js\n * // The same is applicable to onLiveEdit\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n *\n */\n static unsubscribeOnEntryChange(\n callback: OnEntryChangeUnsubscribeParameters\n ): void {\n if (!ContentstackLivePreview.isInitialized()) {\n removeFromOnChangeSubscribers(\n ContentstackLivePreview.onEntryChangeCallbacks,\n callback\n );\n return;\n }\n ContentstackLivePreview.previewConstructors.livePreview.unsubscribeOnEntryChange(\n callback\n );\n }\n\n /**\n * Sets the page-level entry context for the current page.\n * Used by the Visual Builder \"Start Editing\" button to know which entry\n * the current page is rendering, enabling accurate VB navigation.\n *\n * Place this call alongside your existing `addEditableTags` call — both\n * reference the same `entry` object so there is no extra lookup.\n *\n * @example\n * ```js\n * // In your page component / useEffect\n * Utils.addEditableTags(entry, \"blog_post\", true, \"en-us\");\n * ContentstackLivePreview.setPageContext({ entryUid: entry.uid, contentTypeUid: \"blog_post\" });\n * ```\n */\n static setPageContext(context: { entryUid: string; contentTypeUid: string }): void {\n Config.set(\"pageContext\", context);\n // init() fires before async data fetching, so the INIT post-message has no\n // entry context in CSR apps. Send it now so VB can update its current entry.\n // Only send when inside an iframe — skip when the site opens in a plain browser tab.\n if (inIframe()) {\n visualBuilderPostMessage\n ?.send<IPageContextPostMessageEvent>(\n VisualBuilderPostMessageEvents.PAGE_CONTEXT,\n {\n entryUid: context.entryUid,\n contentTypeUid: context.contentTypeUid,\n }\n )\n .catch((error) => {\n PublicLogger.error(\n \"Failed to send page context to Visual Builder.\",\n error\n );\n });\n }\n }\n\n /**\n * Retrieves the version of the SDK.\n * @returns The version of the SDK as a string.\n */\n static getSdkVersion(): string {\n return process?.env?.PACKAGE_VERSION!;\n }\n}\n\nexport default ContentstackLivePreview;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyC;AACzC,kBAA6B;AAC7B,sBAAyB;AACzB,oBAAgC;AAChC,2BAA4C;AAC5C,0BAAwB;AACxB,6BAAoC;AACpC,2CAA8C;AAQ9C,oBAA6B;AAC7B,qBAAiC;AAEjC,2BAA8B;AAC9B,sCAAqC;AACrC,yBAGO;AAEP,IAAM,2BAAN,MAAM,yBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,OAAO,KACH,iBAAiC,+BAAgB,GACU;AAC3D,QAAI,OAAO,WAAW,aAAa;AAC/B,iCAAa,KAAK,4CAA4C;AAC9D,aAAO,QAAQ,QAAQ,yBAAwB,mBAAmB;AAAA,IACtE;AAGA,yBAAAA,QAAO,QAAQ,UAAU;AACzB,kDAAoB;AAEpB,QAAI,yBAAwB,cAAc,GAAG;AACzC,iCAAa;AAAA,QACT;AAAA,MACJ;AACA,aAAO,QAAQ,QAAQ,yBAAwB,mBAAmB;AAAA,IACtE,OAAO;AACH,aAAO,yBAAwB,kBAAkB;AAAA,IACrD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,OA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G;AACZ,4CAAAG,YAAA,mBACM;AAAA,QACE,kDAA+B;AAAA,QAC/B;AAAA,UACI,UAAU,QAAQ;AAAA,UAClB,gBAAgB,QAAQ;AAAA,QAC5B;AAAA,QAEH,MAAM,CAAC,UAAU;AACd,mCAAa;AAAA,UACT;AAAA,UACA;AAAA,QACJ;AAAA,MACJ;AAAA,IACR;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,gBAAwB;AAC3B,WAAO;AAAA,EACX;AACJ;AAnRM,yBACa,sBAKe,CAAC;AAAA;AAAA;AAAA;AAN7B,yBAWa,yBACX,CAAC;AAZT,IAAM,0BAAN;AAqRA,IAAO,wCAAQ;","names":["Config","LivePreview","uuidv4","visualBuilderPostMessage"]}
@@ -97,6 +97,25 @@ declare class ContentstackLivePreview {
97
97
  *
98
98
  */
99
99
  static unsubscribeOnEntryChange(callback: OnEntryChangeUnsubscribeParameters): void;
100
+ /**
101
+ * Sets the page-level entry context for the current page.
102
+ * Used by the Visual Builder "Start Editing" button to know which entry
103
+ * the current page is rendering, enabling accurate VB navigation.
104
+ *
105
+ * Place this call alongside your existing `addEditableTags` call — both
106
+ * reference the same `entry` object so there is no extra lookup.
107
+ *
108
+ * @example
109
+ * ```js
110
+ * // In your page component / useEffect
111
+ * Utils.addEditableTags(entry, "blog_post", true, "en-us");
112
+ * ContentstackLivePreview.setPageContext({ entryUid: entry.uid, contentTypeUid: "blog_post" });
113
+ * ```
114
+ */
115
+ static setPageContext(context: {
116
+ entryUid: string;
117
+ contentTypeUid: string;
118
+ }): void;
100
119
  /**
101
120
  * Retrieves the version of the SDK.
102
121
  * @returns The version of the SDK as a string.
@@ -97,6 +97,25 @@ declare class ContentstackLivePreview {
97
97
  *
98
98
  */
99
99
  static unsubscribeOnEntryChange(callback: OnEntryChangeUnsubscribeParameters): void;
100
+ /**
101
+ * Sets the page-level entry context for the current page.
102
+ * Used by the Visual Builder "Start Editing" button to know which entry
103
+ * the current page is rendering, enabling accurate VB navigation.
104
+ *
105
+ * Place this call alongside your existing `addEditableTags` call — both
106
+ * reference the same `entry` object so there is no extra lookup.
107
+ *
108
+ * @example
109
+ * ```js
110
+ * // In your page component / useEffect
111
+ * Utils.addEditableTags(entry, "blog_post", true, "en-us");
112
+ * ContentstackLivePreview.setPageContext({ entryUid: entry.uid, contentTypeUid: "blog_post" });
113
+ * ```
114
+ */
115
+ static setPageContext(context: {
116
+ entryUid: string;
117
+ contentTypeUid: string;
118
+ }): void;
100
119
  /**
101
120
  * Retrieves the version of the SDK.
102
121
  * @returns The version of the SDK as a string.
@@ -3,6 +3,7 @@ import "../chunk-5WRI5ZAA.js";
3
3
  // src/preview/contentstack-live-preview-HOC.ts
4
4
  import { cloneDeep, isEmpty, pick } from "lodash-es";
5
5
  import { v4 as uuidv4 } from "uuid";
6
+ import { inIframe } from "../common/inIframe.js";
6
7
  import { getUserInitData } from "../configManager/config.default.js";
7
8
  import Config, { updateConfigFromUrl } from "../configManager/configManager.js";
8
9
  import LivePreview from "../livePreview/live-preview.js";
@@ -11,6 +12,10 @@ import { removeFromOnChangeSubscribers } from "../livePreview/removeFromOnChange
11
12
  import { PublicLogger } from "../logger/logger.js";
12
13
  import { handleWebCompare } from "../timeline/compare/compare.js";
13
14
  import { VisualBuilder } from "../visualBuilder/index.js";
15
+ import visualBuilderPostMessage from "../visualBuilder/utils/visualBuilderPostMessage.js";
16
+ import {
17
+ VisualBuilderPostMessageEvents
18
+ } from "../visualBuilder/utils/types/postMessage.types.js";
14
19
  var _ContentstackLivePreview = class _ContentstackLivePreview {
15
20
  /**
16
21
  * Initializes the Live Preview SDK with the provided user configuration.
@@ -190,12 +195,45 @@ var _ContentstackLivePreview = class _ContentstackLivePreview {
190
195
  callback
191
196
  );
192
197
  }
198
+ /**
199
+ * Sets the page-level entry context for the current page.
200
+ * Used by the Visual Builder "Start Editing" button to know which entry
201
+ * the current page is rendering, enabling accurate VB navigation.
202
+ *
203
+ * Place this call alongside your existing `addEditableTags` call — both
204
+ * reference the same `entry` object so there is no extra lookup.
205
+ *
206
+ * @example
207
+ * ```js
208
+ * // In your page component / useEffect
209
+ * Utils.addEditableTags(entry, "blog_post", true, "en-us");
210
+ * ContentstackLivePreview.setPageContext({ entryUid: entry.uid, contentTypeUid: "blog_post" });
211
+ * ```
212
+ */
213
+ static setPageContext(context) {
214
+ var _a;
215
+ Config.set("pageContext", context);
216
+ if (inIframe()) {
217
+ (_a = visualBuilderPostMessage) == null ? void 0 : _a.send(
218
+ VisualBuilderPostMessageEvents.PAGE_CONTEXT,
219
+ {
220
+ entryUid: context.entryUid,
221
+ contentTypeUid: context.contentTypeUid
222
+ }
223
+ ).catch((error) => {
224
+ PublicLogger.error(
225
+ "Failed to send page context to Visual Builder.",
226
+ error
227
+ );
228
+ });
229
+ }
230
+ }
193
231
  /**
194
232
  * Retrieves the version of the SDK.
195
233
  * @returns The version of the SDK as a string.
196
234
  */
197
235
  static getSdkVersion() {
198
- return "4.4.3";
236
+ return "4.4.4";
199
237
  }
200
238
  };
201
239
  _ContentstackLivePreview.previewConstructors = {};
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preview/contentstack-live-preview-HOC.ts"],"sourcesContent":["import { cloneDeep, isEmpty, pick } from \"lodash-es\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { getUserInitData } from \"../configManager/config.default\";\nimport Config, { updateConfigFromUrl } from \"../configManager/configManager\";\nimport LivePreview from \"../livePreview/live-preview\";\nimport { handlePageTraversal } from \"../livePreview/onPageTraversal\";\nimport { removeFromOnChangeSubscribers } from \"../livePreview/removeFromOnChangeSubscribers\";\nimport {\n OnEntryChangeCallback,\n OnEntryChangeCallbackSubscribers,\n OnEntryChangeCallbackUID,\n OnEntryChangeConfig,\n OnEntryChangeUnsubscribeParameters,\n} from \"../livePreview/types/onEntryChangeCallback.type\";\nimport { PublicLogger } from \"../logger/logger\";\nimport { handleWebCompare } from \"../timeline/compare/compare\";\nimport type { IExportedConfig, IInitData } from \"../types/types\";\nimport { VisualBuilder } from \"../visualBuilder\";\n\nclass ContentstackLivePreview {\n private static previewConstructors:\n | {\n livePreview: LivePreview;\n visualBuilder: VisualBuilder;\n }\n | Record<string, never> = {};\n\n /**\n * The subscribers for the onEntryChange event. We store them here when the SDK is not initialized.\n */\n private static onEntryChangeCallbacks: OnEntryChangeCallbackSubscribers =\n {};\n\n /**\n * Initializes the Live Preview SDK with the provided user configuration.\n * If the SDK is already initialized, subsequent calls to this method will return the existing SDK instance.\n * @param userConfig - The user configuration to initialize the SDK with. See {@link https://github.com/contentstack/live-preview-sdk/blob/main/docs/live-preview-configs.md#initconfig-iconfig|Live preview User config} for more details.\n * @returns A promise that resolves to the constructors of the Live Preview SDK.\n */\n static init(\n userConfig: Partial<IInitData> = getUserInitData()\n ): Promise<typeof ContentstackLivePreview.previewConstructors> {\n if (typeof window === \"undefined\") {\n PublicLogger.warn(\"The SDK is not initialized in the browser.\");\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n // handle user config\n Config.replace(userConfig);\n updateConfigFromUrl();\n\n if (ContentstackLivePreview.isInitialized()) {\n PublicLogger.warn(\n \"You have already initialized the Live Preview SDK. So, any subsequent initialization returns the existing SDK instance.\"\n );\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n } else {\n return ContentstackLivePreview.initializePreview();\n }\n }\n\n /**\n * It is the live preview hash.\n * This hash could be used when data is fetched manually.\n */\n static get hash(): string {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n return Config.get().hash;\n }\n\n static get config(): IExportedConfig {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n const config = Config.get();\n const clonedConfig = cloneDeep(config);\n const configToShare = pick(clonedConfig, [\n 'ssr',\n 'enable',\n 'cleanCslpOnProduction',\n 'stackDetails',\n 'clientUrlParams',\n 'windowType',\n 'hash',\n 'editButton',\n 'mode',\n ]);\n return configToShare;\n }\n\n private static isInitialized(): boolean {\n return !isEmpty(ContentstackLivePreview.previewConstructors);\n }\n\n private static initializePreview() {\n ContentstackLivePreview.previewConstructors = {\n livePreview: new LivePreview(),\n visualBuilder: new VisualBuilder(),\n };\n\n // set up onEntryChange callbacks added when the SDK was not initialized\n const livePreview =\n ContentstackLivePreview.previewConstructors.livePreview;\n Object.entries(ContentstackLivePreview.onEntryChangeCallbacks).forEach(\n ([callbackUid, callback]) => {\n livePreview.subscribeToOnEntryChange(callback, callbackUid);\n }\n );\n\n ContentstackLivePreview.onEntryChangeCallbacks = {};\n\n handlePageTraversal();\n handleWebCompare();\n\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n /**\n * Registers a callback function to be called when an entry changes.\n * @param onChangeCallback The callback function to be called when an entry changes.\n * @param config Optional configuration for the callback.\n * @param config.skipInitialRender If true, the callback will not be called when it is first registered.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n */\n static onEntryChange(\n onChangeCallback: OnEntryChangeCallback,\n config: OnEntryChangeConfig = {}\n ): OnEntryChangeCallbackUID {\n const { skipInitialRender = false } = config;\n\n const callbackUid = uuidv4();\n\n if (ContentstackLivePreview.isInitialized()) {\n ContentstackLivePreview.previewConstructors.livePreview.subscribeToOnEntryChange(\n onChangeCallback,\n callbackUid\n );\n } else {\n ContentstackLivePreview.onEntryChangeCallbacks[callbackUid] =\n onChangeCallback;\n }\n\n const searchParams =\n typeof window !== \"undefined\"\n ? new URLSearchParams(window.location.search)\n : null;\n const hasLivePreviewHash =\n searchParams && searchParams.has(\"live_preview\");\n const isBuilder = searchParams && searchParams.has(\"builder\");\n const shouldCallCallback = hasLivePreviewHash && isBuilder;\n // calling onChangeCallback when live_preview search parameter\n // is present because we don't send the initial client-data-send\n // message in visual builder\n if (!skipInitialRender || shouldCallCallback) {\n onChangeCallback();\n }\n\n return callbackUid;\n }\n\n /**\n * Registers a callback function to be called when there is a change in the entry being edited in live preview mode. The difference between this and `onEntryChange` is that this callback will not be called when it is first registered.\n * @param onChangeCallback The callback function to be called when there is a change in the entry.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n */\n static onLiveEdit(\n onChangeCallback: OnEntryChangeCallback\n ): OnEntryChangeCallbackUID {\n return ContentstackLivePreview.onEntryChange(onChangeCallback, {\n skipInitialRender: true,\n });\n }\n\n /**\n * Unsubscribes from the entry change event.\n * @param callback - The callback function to be unsubscribed.\n *\n * @example\n * ```js\n * // unsubscribing using the Callback UID\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n * @example\n * ```js\n * // unsubscribing using the callback function\n * const callback = () => {console.log(\"Entry changed\")};\n * ContentstackLivePreview.onEntryChange(callback);\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callback);\n * ```\n *\n * @example\n * ```js\n * // The same is applicable to onLiveEdit\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n *\n */\n static unsubscribeOnEntryChange(\n callback: OnEntryChangeUnsubscribeParameters\n ): void {\n if (!ContentstackLivePreview.isInitialized()) {\n removeFromOnChangeSubscribers(\n ContentstackLivePreview.onEntryChangeCallbacks,\n callback\n );\n return;\n }\n ContentstackLivePreview.previewConstructors.livePreview.unsubscribeOnEntryChange(\n callback\n );\n }\n\n /**\n * Retrieves the version of the SDK.\n * @returns The version of the SDK as a string.\n */\n static getSdkVersion(): string {\n return process?.env?.PACKAGE_VERSION!;\n }\n}\n\nexport default ContentstackLivePreview;"],"mappings":";;;AAAA,SAAS,WAAW,SAAS,YAAY;AACzC,SAAS,MAAM,cAAc;AAC7B,SAAS,uBAAuB;AAChC,OAAO,UAAU,2BAA2B;AAC5C,OAAO,iBAAiB;AACxB,SAAS,2BAA2B;AACpC,SAAS,qCAAqC;AAQ9C,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAEjC,SAAS,qBAAqB;AAE9B,IAAM,2BAAN,MAAM,yBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,OAAO,KACH,aAAiC,gBAAgB,GACU;AAC3D,QAAI,OAAO,WAAW,aAAa;AAC/B,mBAAa,KAAK,4CAA4C;AAC9D,aAAO,QAAQ,QAAQ,yBAAwB,mBAAmB;AAAA,IACtE;AAGA,WAAO,QAAQ,UAAU;AACzB,wBAAoB;AAEpB,QAAI,yBAAwB,cAAc,GAAG;AACzC,mBAAa;AAAA,QACT;AAAA,MACJ;AACA,aAAO,QAAQ,QAAQ,yBAAwB,mBAAmB;AAAA,IACtE,OAAO;AACH,aAAO,yBAAwB,kBAAkB;AAAA,IACrD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,OAAe;AACtB,QAAI,CAAC,yBAAwB,cAAc,GAAG;AAC1C,0BAAoB;AAAA,IACxB;AACA,WAAO,OAAO,IAAI,EAAE;AAAA,EACxB;AAAA,EAEA,WAAW,SAA0B;AACjC,QAAI,CAAC,yBAAwB,cAAc,GAAG;AAC1C,0BAAoB;AAAA,IACxB;AACA,UAAM,SAAS,OAAO,IAAI;AAC1B,UAAM,eAAe,UAAU,MAAM;AACrC,UAAM,gBAAgB,KAAK,cAAc;AAAA,MACrC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;A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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,OAAO,WACH,kBACwB;AACxB,WAAO,yBAAwB,cAAc,kBAAkB;AAAA,MAC3D,mBAAmB;AAAA,IACvB,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwCA,OAAO,yBACH,UACI;AACJ,QAAI,CAAC,yBAAwB,cAAc,GAAG;AAC1C;AAAA,QACI,yBAAwB;AAAA,QACxB;AAAA,MACJ;AACA;AAAA,IACJ;AACA,6BAAwB,oBAAoB,YAAY;AAAA,MACpD;AAAA,IACJ;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,gBAAwB;AAC3B,WAAO;AAAA,EACX;AACJ;AA7OM,yBACa,sBAKe,CAAC;AAAA;AAAA;AAAA;AAN7B,yBAWa,yBACX,CAAC;AAZT,IAAM,0BAAN;AA+OA,IAAO,wCAAQ;","names":[]}
1
+ {"version":3,"sources":["../../../src/preview/contentstack-live-preview-HOC.ts"],"sourcesContent":["import { cloneDeep, isEmpty, pick } from \"lodash-es\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { inIframe } from \"../common/inIframe\";\nimport { getUserInitData } from \"../configManager/config.default\";\nimport Config, { updateConfigFromUrl } from \"../configManager/configManager\";\nimport LivePreview from \"../livePreview/live-preview\";\nimport { handlePageTraversal } from \"../livePreview/onPageTraversal\";\nimport { removeFromOnChangeSubscribers } from \"../livePreview/removeFromOnChangeSubscribers\";\nimport {\n OnEntryChangeCallback,\n OnEntryChangeCallbackSubscribers,\n OnEntryChangeCallbackUID,\n OnEntryChangeConfig,\n OnEntryChangeUnsubscribeParameters,\n} from \"../livePreview/types/onEntryChangeCallback.type\";\nimport { PublicLogger } from \"../logger/logger\";\nimport { handleWebCompare } from \"../timeline/compare/compare\";\nimport type { IExportedConfig, IInitData } from \"../types/types\";\nimport { VisualBuilder } from \"../visualBuilder\";\nimport visualBuilderPostMessage from \"../visualBuilder/utils/visualBuilderPostMessage\";\nimport {\n IPageContextPostMessageEvent,\n VisualBuilderPostMessageEvents,\n} from \"../visualBuilder/utils/types/postMessage.types\";\n\nclass ContentstackLivePreview {\n private static previewConstructors:\n | {\n livePreview: LivePreview;\n visualBuilder: VisualBuilder;\n }\n | Record<string, never> = {};\n\n /**\n * The subscribers for the onEntryChange event. We store them here when the SDK is not initialized.\n */\n private static onEntryChangeCallbacks: OnEntryChangeCallbackSubscribers =\n {};\n\n /**\n * Initializes the Live Preview SDK with the provided user configuration.\n * If the SDK is already initialized, subsequent calls to this method will return the existing SDK instance.\n * @param userConfig - The user configuration to initialize the SDK with. See {@link https://github.com/contentstack/live-preview-sdk/blob/main/docs/live-preview-configs.md#initconfig-iconfig|Live preview User config} for more details.\n * @returns A promise that resolves to the constructors of the Live Preview SDK.\n */\n static init(\n userConfig: Partial<IInitData> = getUserInitData()\n ): Promise<typeof ContentstackLivePreview.previewConstructors> {\n if (typeof window === \"undefined\") {\n PublicLogger.warn(\"The SDK is not initialized in the browser.\");\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n // handle user config\n Config.replace(userConfig);\n updateConfigFromUrl();\n\n if (ContentstackLivePreview.isInitialized()) {\n PublicLogger.warn(\n \"You have already initialized the Live Preview SDK. So, any subsequent initialization returns the existing SDK instance.\"\n );\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n } else {\n return ContentstackLivePreview.initializePreview();\n }\n }\n\n /**\n * It is the live preview hash.\n * This hash could be used when data is fetched manually.\n */\n static get hash(): string {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n return Config.get().hash;\n }\n\n static get config(): IExportedConfig {\n if (!ContentstackLivePreview.isInitialized()) {\n updateConfigFromUrl(); // check if we could extract from the URL\n }\n const config = Config.get();\n const clonedConfig = cloneDeep(config);\n const configToShare = pick(clonedConfig, [\n 'ssr',\n 'enable',\n 'cleanCslpOnProduction',\n 'stackDetails',\n 'clientUrlParams',\n 'windowType',\n 'hash',\n 'editButton',\n 'mode',\n ]);\n return configToShare;\n }\n\n private static isInitialized(): boolean {\n return !isEmpty(ContentstackLivePreview.previewConstructors);\n }\n\n private static initializePreview() {\n ContentstackLivePreview.previewConstructors = {\n livePreview: new LivePreview(),\n visualBuilder: new VisualBuilder(),\n };\n\n // set up onEntryChange callbacks added when the SDK was not initialized\n const livePreview =\n ContentstackLivePreview.previewConstructors.livePreview;\n Object.entries(ContentstackLivePreview.onEntryChangeCallbacks).forEach(\n ([callbackUid, callback]) => {\n livePreview.subscribeToOnEntryChange(callback, callbackUid);\n }\n );\n\n ContentstackLivePreview.onEntryChangeCallbacks = {};\n\n handlePageTraversal();\n handleWebCompare();\n\n return Promise.resolve(ContentstackLivePreview.previewConstructors);\n }\n\n /**\n * Registers a callback function to be called when an entry changes.\n * @param onChangeCallback The callback function to be called when an entry changes.\n * @param config Optional configuration for the callback.\n * @param config.skipInitialRender If true, the callback will not be called when it is first registered.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n */\n static onEntryChange(\n onChangeCallback: OnEntryChangeCallback,\n config: OnEntryChangeConfig = {}\n ): OnEntryChangeCallbackUID {\n const { skipInitialRender = false } = config;\n\n const callbackUid = uuidv4();\n\n if (ContentstackLivePreview.isInitialized()) {\n ContentstackLivePreview.previewConstructors.livePreview.subscribeToOnEntryChange(\n onChangeCallback,\n callbackUid\n );\n } else {\n ContentstackLivePreview.onEntryChangeCallbacks[callbackUid] =\n onChangeCallback;\n }\n\n const searchParams =\n typeof window !== \"undefined\"\n ? new URLSearchParams(window.location.search)\n : null;\n const hasLivePreviewHash =\n searchParams && searchParams.has(\"live_preview\");\n const isBuilder = searchParams && searchParams.has(\"builder\");\n const shouldCallCallback = hasLivePreviewHash && isBuilder;\n // calling onChangeCallback when live_preview search parameter\n // is present because we don't send the initial client-data-send\n // message in visual builder\n if (!skipInitialRender || shouldCallCallback) {\n onChangeCallback();\n }\n\n return callbackUid;\n }\n\n /**\n * Registers a callback function to be called when there is a change in the entry being edited in live preview mode. The difference between this and `onEntryChange` is that this callback will not be called when it is first registered.\n * @param onChangeCallback The callback function to be called when there is a change in the entry.\n * @returns A unique identifier for the registered callback.\n *\n * @example\n * ```js\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n */\n static onLiveEdit(\n onChangeCallback: OnEntryChangeCallback\n ): OnEntryChangeCallbackUID {\n return ContentstackLivePreview.onEntryChange(onChangeCallback, {\n skipInitialRender: true,\n });\n }\n\n /**\n * Unsubscribes from the entry change event.\n * @param callback - The callback function to be unsubscribed.\n *\n * @example\n * ```js\n * // unsubscribing using the Callback UID\n * const callbackUid = ContentstackLivePreview.onEntryChange(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n * @example\n * ```js\n * // unsubscribing using the callback function\n * const callback = () => {console.log(\"Entry changed\")};\n * ContentstackLivePreview.onEntryChange(callback);\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callback);\n * ```\n *\n * @example\n * ```js\n * // The same is applicable to onLiveEdit\n * const callbackUid = ContentstackLivePreview.onLiveEdit(() => {\n * console.log(\"Entry changed\");\n * });\n *\n * // Unsubscribe the callback\n * ContentstackLivePreview.unsubscribeOnEntryChange(callbackUid);\n * ```\n *\n *\n */\n static unsubscribeOnEntryChange(\n callback: OnEntryChangeUnsubscribeParameters\n ): void {\n if (!ContentstackLivePreview.isInitialized()) {\n removeFromOnChangeSubscribers(\n ContentstackLivePreview.onEntryChangeCallbacks,\n callback\n );\n return;\n }\n ContentstackLivePreview.previewConstructors.livePreview.unsubscribeOnEntryChange(\n callback\n );\n }\n\n /**\n * Sets the page-level entry context for the current page.\n * Used by the Visual Builder \"Start Editing\" button to know which entry\n * the current page is rendering, enabling accurate VB navigation.\n *\n * Place this call alongside your existing `addEditableTags` call — both\n * reference the same `entry` object so there is no extra lookup.\n *\n * @example\n * ```js\n * // In your page component / useEffect\n * Utils.addEditableTags(entry, \"blog_post\", true, \"en-us\");\n * ContentstackLivePreview.setPageContext({ entryUid: entry.uid, contentTypeUid: \"blog_post\" });\n * ```\n */\n static setPageContext(context: { entryUid: string; contentTypeUid: string }): void {\n Config.set(\"pageContext\", context);\n // init() fires before async data fetching, so the INIT post-message has no\n // entry context in CSR apps. Send it now so VB can update its current entry.\n // Only send when inside an iframe — skip when the site opens in a plain browser tab.\n if (inIframe()) {\n visualBuilderPostMessage\n ?.send<IPageContextPostMessageEvent>(\n VisualBuilderPostMessageEvents.PAGE_CONTEXT,\n {\n entryUid: context.entryUid,\n contentTypeUid: context.contentTypeUid,\n }\n )\n .catch((error) => {\n PublicLogger.error(\n \"Failed to send page context to Visual Builder.\",\n error\n );\n });\n }\n }\n\n /**\n * Retrieves the version of the SDK.\n * @returns The version of the SDK as a string.\n */\n static getSdkVersion(): string {\n return process?.env?.PACKAGE_VERSION!;\n }\n}\n\nexport default ContentstackLivePreview;"],"mappings":";;;AAAA,SAAS,WAAW,SAAS,YAAY;AACzC,SAAS,MAAM,cAAc;AAC7B,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,OAAO,UAAU,2BAA2B;AAC5C,OAAO,iBAAi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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwCA,OAAO,yBACH,UACI;AACJ,QAAI,CAAC,yBAAwB,cAAc,GAAG;AAC1C;AAAA,QACI,yBAAwB;AAAA,QACxB;AAAA,MACJ;AACA;AAAA,IACJ;AACA,6BAAwB,oBAAoB,YAAY;AAAA,MACpD;AAAA,IACJ;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,OAAO,eAAe,SAA6D;AA9QvF;AA+QQ,WAAO,IAAI,eAAe,OAAO;AAIjC,QAAI,SAAS,GAAG;AACZ,4DACM;AAAA,QACE,+BAA+B;AAAA,QAC/B;AAAA,UACI,UAAU,QAAQ;AAAA,UAClB,gBAAgB,QAAQ;AAAA,QAC5B;AAAA,QAEH,MAAM,CAAC,UAAU;AACd,qBAAa;AAAA,UACT;AAAA,UACA;AAAA,QACJ;AAAA,MACJ;AAAA,IACR;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,gBAAwB;AAC3B,WAAO;AAAA,EACX;AACJ;AAnRM,yBACa,sBAKe,CAAC;AAAA;AAAA;AAAA;AAN7B,yBAWa,yBACX,CAAC;AAZT,IAAM,0BAAN;AAqRA,IAAO,wCAAQ;","names":[]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/types/global.d.ts
17
+ var global_d_exports = {};
18
+ module.exports = __toCommonJS(global_d_exports);
19
+ //# sourceMappingURL=global.d.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/global.d.ts"],"sourcesContent":["import type { IPageContext } from \"./types\";\n\ndeclare global {\n interface Window {\n __CS_PAGE_CONTEXT__?: IPageContext;\n }\n}\n\nexport {};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,8 @@
1
+ import { IPageContext } from './types.cjs';
2
+ import '../visualBuilder/types/collab.types.cjs';
3
+
4
+ declare global {
5
+ interface Window {
6
+ __CS_PAGE_CONTEXT__?: IPageContext;
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ import { IPageContext } from './types.js';
2
+ import '../visualBuilder/types/collab.types.js';
3
+
4
+ declare global {
5
+ interface Window {
6
+ __CS_PAGE_CONTEXT__?: IPageContext;
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=global.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/types.ts"],"sourcesContent":["import { ICollabConfig } from \"../visualBuilder/types/collab.types\";\nexport declare interface IEditEntrySearchParams {\n hash?: string;\n entry_uid?: string;\n content_type_uid?: string;\n /**\n * @deprecated pass this value as hash instead\n */\n live_preview?: string;\n}\n\nexport declare interface IClientUrlParams {\n protocol: \"http\" | \"https\";\n host: string;\n port: string | number;\n url: string;\n}\n\nexport declare interface IStackSdk {\n live_preview: { [key: string]: any } & Partial<IConfig>;\n [key: string]: any;\n environment: string;\n}\n\nexport declare interface IStackDetails {\n apiKey: string;\n environment: string;\n contentTypeUid: string;\n entryUid: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n masterLocale: string;\n}\n\nexport declare interface IInitStackDetails {\n apiKey: string;\n environment: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n}\n\nexport declare type ILivePreviewMode = \"builder\" | \"preview\";\n\n//? We kept it as number so that we could disable only the unrequired features,\n//? since the \"Builder\" mode will contain all the features of the \"Preview\" mode.\nexport enum ILivePreviewModeConfig {\n PREVIEW = 1,\n BUILDER = 2,\n}\n\nexport enum ILivePreviewWindowType {\n PREVIEW = \"preview\",\n PREVIEW_SHARE = \"preview-share\",\n BUILDER = \"builder\",\n INDEPENDENT = \"independent\",\n}\n\nexport declare interface IConfig {\n ssr: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: IStackDetails;\n clientUrlParams: IClientUrlParams;\n stackSdk: IStackSdk;\n onChange: () => void;\n runScriptsOnUpdate: boolean;\n windowType: ILivePreviewWindowType;\n hash: string;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewModeConfig;\n elements: {\n highlightedElement: HTMLElement | null;\n };\n collab: ICollabConfig[\"collab\"];\n enableLivePreviewOutsideIframe: boolean | undefined;\n}\n\n\nexport declare interface IConfigEditInVisualBuilderButton {\n enable: boolean;\n position?:\n | \"top-left\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-right\"\n}\n\nexport declare interface IConfigOverlayPropagation {\n /**\n * When `true`, Visual Builder hover/click detection falls back to\n * `document.elementsFromPoint()` if the immediate `event.target` has no\n * ancestor with `data-cslp`. This allows the SDK to pierce sibling\n * elements (e.g. empty CSS-grid spacer cells) that visually overlap a\n * `data-cslp` field and would otherwise intercept the mouse event.\n *\n * @default false\n */\n enable: boolean;\n}\n\n\nexport declare interface IConfigEditButton {\n enable: boolean;\n exclude?: (\"insideLivePreviewPortal\" | \"outsideLivePreviewPortal\")[];\n includeByQueryParameter?: boolean;\n position?:\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"top-left\"\n | \"top-right\"\n | \"top-center\"\n | \"bottom-left\"\n | \"bottom-right\"\n | \"bottom-center\";\n}\n\nexport declare interface IInitData {\n ssr: boolean;\n runScriptsOnUpdate: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: Partial<IInitStackDetails>;\n clientUrlParams: Partial<Omit<IClientUrlParams, \"url\">>;\n stackSdk: IStackSdk;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewMode;\n enableLivePreviewOutsideIframe: boolean | undefined; // default: undefined\n}\n\n// type PickPartial<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;\n\n// export type IInitData =\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// };\n\n// Post message types\n\nexport declare interface ILivePreviewMessageCommon {\n from: \"live-preview\";\n}\n\nexport declare interface IEditButtonPosition {\n upperBoundOfTooltip: number;\n leftBoundOfTooltip: number;\n}\n\n// end of Post message types\n\nexport interface IVisualBuilderInitEvent {\n windowType: ILivePreviewWindowType;\n stackDetails: {\n masterLocale: string;\n };\n collab?: ICollabConfig[\"collab\"];\n}\n\nexport type IExportedConfig = Pick<\n IConfig,\n | \"ssr\"\n | \"enable\"\n | \"cleanCslpOnProduction\"\n | \"stackDetails\"\n | \"clientUrlParams\"\n | \"windowType\"\n | \"hash\"\n | \"editButton\"\n | \"mode\"\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDO,IAAK,yBAAL,kBAAKA,4BAAL;AACH,EAAAA,gDAAA,aAAU,KAAV;AACA,EAAAA,gDAAA,aAAU,KAAV;AAFQ,SAAAA;AAAA,GAAA;AAKL,IAAK,yBAAL,kBAAKC,4BAAL;AACH,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,mBAAgB;AAChB,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,iBAAc;AAJN,SAAAA;AAAA,GAAA;","names":["ILivePreviewModeConfig","ILivePreviewWindowType"]}
1
+ {"version":3,"sources":["../../../src/types/types.ts"],"sourcesContent":["import { ICollabConfig } from \"../visualBuilder/types/collab.types\";\nexport declare interface IEditEntrySearchParams {\n hash?: string;\n entry_uid?: string;\n content_type_uid?: string;\n /**\n * @deprecated pass this value as hash instead\n */\n live_preview?: string;\n}\n\nexport declare interface IClientUrlParams {\n protocol: \"http\" | \"https\";\n host: string;\n port: string | number;\n url: string;\n}\n\nexport declare interface IStackSdk {\n live_preview: { [key: string]: any } & Partial<IConfig>;\n [key: string]: any;\n environment: string;\n}\n\nexport declare interface IStackDetails {\n apiKey: string;\n environment: string;\n contentTypeUid: string;\n entryUid: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n masterLocale: string;\n}\n\nexport declare interface IInitStackDetails {\n apiKey: string;\n environment: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n}\n\nexport declare type ILivePreviewMode = \"builder\" | \"preview\";\n\n//? We kept it as number so that we could disable only the unrequired features,\n//? since the \"Builder\" mode will contain all the features of the \"Preview\" mode.\nexport enum ILivePreviewModeConfig {\n PREVIEW = 1,\n BUILDER = 2,\n}\n\nexport enum ILivePreviewWindowType {\n PREVIEW = \"preview\",\n PREVIEW_SHARE = \"preview-share\",\n BUILDER = \"builder\",\n INDEPENDENT = \"independent\",\n}\n\nexport declare interface IPageContext {\n entryUid: string;\n contentTypeUid: string;\n}\n\nexport declare interface IConfig {\n ssr: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: IStackDetails;\n clientUrlParams: IClientUrlParams;\n stackSdk: IStackSdk;\n onChange: () => void;\n runScriptsOnUpdate: boolean;\n windowType: ILivePreviewWindowType;\n hash: string;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewModeConfig;\n elements: {\n highlightedElement: HTMLElement | null;\n };\n collab: ICollabConfig[\"collab\"];\n enableLivePreviewOutsideIframe: boolean | undefined;\n pageContext: IPageContext | null;\n}\n\n\nexport declare interface IConfigEditInVisualBuilderButton {\n enable: boolean;\n position?:\n | \"top-left\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-right\"\n}\n\nexport declare interface IConfigOverlayPropagation {\n /**\n * When `true`, Visual Builder hover/click detection falls back to\n * `document.elementsFromPoint()` if the immediate `event.target` has no\n * ancestor with `data-cslp`. This allows the SDK to pierce sibling\n * elements (e.g. empty CSS-grid spacer cells) that visually overlap a\n * `data-cslp` field and would otherwise intercept the mouse event.\n *\n * @default false\n */\n enable: boolean;\n}\n\n\nexport declare interface IConfigEditButton {\n enable: boolean;\n exclude?: (\"insideLivePreviewPortal\" | \"outsideLivePreviewPortal\")[];\n includeByQueryParameter?: boolean;\n position?:\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"top-left\"\n | \"top-right\"\n | \"top-center\"\n | \"bottom-left\"\n | \"bottom-right\"\n | \"bottom-center\";\n}\n\nexport declare interface IInitData {\n ssr: boolean;\n runScriptsOnUpdate: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: Partial<IInitStackDetails>;\n clientUrlParams: Partial<Omit<IClientUrlParams, \"url\">>;\n stackSdk: IStackSdk;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewMode;\n enableLivePreviewOutsideIframe: boolean | undefined; // default: undefined\n}\n\n// type PickPartial<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;\n\n// export type IInitData =\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// };\n\n// Post message types\n\nexport declare interface ILivePreviewMessageCommon {\n from: \"live-preview\";\n}\n\nexport declare interface IEditButtonPosition {\n upperBoundOfTooltip: number;\n leftBoundOfTooltip: number;\n}\n\n// end of Post message types\n\nexport interface IVisualBuilderInitEvent {\n windowType: ILivePreviewWindowType;\n stackDetails: {\n masterLocale: string;\n };\n collab?: ICollabConfig[\"collab\"];\n}\n\nexport type IExportedConfig = Pick<\n IConfig,\n | \"ssr\"\n | \"enable\"\n | \"cleanCslpOnProduction\"\n | \"stackDetails\"\n | \"clientUrlParams\"\n | \"windowType\"\n | \"hash\"\n | \"editButton\"\n | \"mode\"\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDO,IAAK,yBAAL,kBAAKA,4BAAL;AACH,EAAAA,gDAAA,aAAU,KAAV;AACA,EAAAA,gDAAA,aAAU,KAAV;AAFQ,SAAAA;AAAA,GAAA;AAKL,IAAK,yBAAL,kBAAKC,4BAAL;AACH,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,mBAAgB;AAChB,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,iBAAc;AAJN,SAAAA;AAAA,GAAA;","names":["ILivePreviewModeConfig","ILivePreviewWindowType"]}
@@ -58,6 +58,10 @@ declare enum ILivePreviewWindowType {
58
58
  BUILDER = "builder",
59
59
  INDEPENDENT = "independent"
60
60
  }
61
+ declare interface IPageContext {
62
+ entryUid: string;
63
+ contentTypeUid: string;
64
+ }
61
65
  declare interface IConfig {
62
66
  ssr: boolean;
63
67
  enable: boolean;
@@ -82,6 +86,7 @@ declare interface IConfig {
82
86
  };
83
87
  collab: ICollabConfig["collab"];
84
88
  enableLivePreviewOutsideIframe: boolean | undefined;
89
+ pageContext: IPageContext | null;
85
90
  }
86
91
  declare interface IConfigEditInVisualBuilderButton {
87
92
  enable: boolean;
@@ -139,4 +144,4 @@ interface IVisualBuilderInitEvent {
139
144
  }
140
145
  type IExportedConfig = Pick<IConfig, "ssr" | "enable" | "cleanCslpOnProduction" | "stackDetails" | "clientUrlParams" | "windowType" | "hash" | "editButton" | "mode">;
141
146
 
142
- export { type IClientUrlParams, type IConfig, type IConfigEditButton, type IConfigEditInVisualBuilderButton, type IConfigOverlayPropagation, type IEditButtonPosition, type IEditEntrySearchParams, type IExportedConfig, type IInitData, type IInitStackDetails, type ILivePreviewMessageCommon, type ILivePreviewMode, ILivePreviewModeConfig, ILivePreviewWindowType, type IStackDetails, type IStackSdk, type IVisualBuilderInitEvent };
147
+ export { type IClientUrlParams, type IConfig, type IConfigEditButton, type IConfigEditInVisualBuilderButton, type IConfigOverlayPropagation, type IEditButtonPosition, type IEditEntrySearchParams, type IExportedConfig, type IInitData, type IInitStackDetails, type ILivePreviewMessageCommon, type ILivePreviewMode, ILivePreviewModeConfig, ILivePreviewWindowType, type IPageContext, type IStackDetails, type IStackSdk, type IVisualBuilderInitEvent };
@@ -58,6 +58,10 @@ declare enum ILivePreviewWindowType {
58
58
  BUILDER = "builder",
59
59
  INDEPENDENT = "independent"
60
60
  }
61
+ declare interface IPageContext {
62
+ entryUid: string;
63
+ contentTypeUid: string;
64
+ }
61
65
  declare interface IConfig {
62
66
  ssr: boolean;
63
67
  enable: boolean;
@@ -82,6 +86,7 @@ declare interface IConfig {
82
86
  };
83
87
  collab: ICollabConfig["collab"];
84
88
  enableLivePreviewOutsideIframe: boolean | undefined;
89
+ pageContext: IPageContext | null;
85
90
  }
86
91
  declare interface IConfigEditInVisualBuilderButton {
87
92
  enable: boolean;
@@ -139,4 +144,4 @@ interface IVisualBuilderInitEvent {
139
144
  }
140
145
  type IExportedConfig = Pick<IConfig, "ssr" | "enable" | "cleanCslpOnProduction" | "stackDetails" | "clientUrlParams" | "windowType" | "hash" | "editButton" | "mode">;
141
146
 
142
- export { type IClientUrlParams, type IConfig, type IConfigEditButton, type IConfigEditInVisualBuilderButton, type IConfigOverlayPropagation, type IEditButtonPosition, type IEditEntrySearchParams, type IExportedConfig, type IInitData, type IInitStackDetails, type ILivePreviewMessageCommon, type ILivePreviewMode, ILivePreviewModeConfig, ILivePreviewWindowType, type IStackDetails, type IStackSdk, type IVisualBuilderInitEvent };
147
+ export { type IClientUrlParams, type IConfig, type IConfigEditButton, type IConfigEditInVisualBuilderButton, type IConfigOverlayPropagation, type IEditButtonPosition, type IEditEntrySearchParams, type IExportedConfig, type IInitData, type IInitStackDetails, type ILivePreviewMessageCommon, type ILivePreviewMode, ILivePreviewModeConfig, ILivePreviewWindowType, type IPageContext, type IStackDetails, type IStackSdk, type IVisualBuilderInitEvent };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/types.ts"],"sourcesContent":["import { ICollabConfig } from \"../visualBuilder/types/collab.types\";\nexport declare interface IEditEntrySearchParams {\n hash?: string;\n entry_uid?: string;\n content_type_uid?: string;\n /**\n * @deprecated pass this value as hash instead\n */\n live_preview?: string;\n}\n\nexport declare interface IClientUrlParams {\n protocol: \"http\" | \"https\";\n host: string;\n port: string | number;\n url: string;\n}\n\nexport declare interface IStackSdk {\n live_preview: { [key: string]: any } & Partial<IConfig>;\n [key: string]: any;\n environment: string;\n}\n\nexport declare interface IStackDetails {\n apiKey: string;\n environment: string;\n contentTypeUid: string;\n entryUid: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n masterLocale: string;\n}\n\nexport declare interface IInitStackDetails {\n apiKey: string;\n environment: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n}\n\nexport declare type ILivePreviewMode = \"builder\" | \"preview\";\n\n//? We kept it as number so that we could disable only the unrequired features,\n//? since the \"Builder\" mode will contain all the features of the \"Preview\" mode.\nexport enum ILivePreviewModeConfig {\n PREVIEW = 1,\n BUILDER = 2,\n}\n\nexport enum ILivePreviewWindowType {\n PREVIEW = \"preview\",\n PREVIEW_SHARE = \"preview-share\",\n BUILDER = \"builder\",\n INDEPENDENT = \"independent\",\n}\n\nexport declare interface IConfig {\n ssr: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: IStackDetails;\n clientUrlParams: IClientUrlParams;\n stackSdk: IStackSdk;\n onChange: () => void;\n runScriptsOnUpdate: boolean;\n windowType: ILivePreviewWindowType;\n hash: string;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewModeConfig;\n elements: {\n highlightedElement: HTMLElement | null;\n };\n collab: ICollabConfig[\"collab\"];\n enableLivePreviewOutsideIframe: boolean | undefined;\n}\n\n\nexport declare interface IConfigEditInVisualBuilderButton {\n enable: boolean;\n position?:\n | \"top-left\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-right\"\n}\n\nexport declare interface IConfigOverlayPropagation {\n /**\n * When `true`, Visual Builder hover/click detection falls back to\n * `document.elementsFromPoint()` if the immediate `event.target` has no\n * ancestor with `data-cslp`. This allows the SDK to pierce sibling\n * elements (e.g. empty CSS-grid spacer cells) that visually overlap a\n * `data-cslp` field and would otherwise intercept the mouse event.\n *\n * @default false\n */\n enable: boolean;\n}\n\n\nexport declare interface IConfigEditButton {\n enable: boolean;\n exclude?: (\"insideLivePreviewPortal\" | \"outsideLivePreviewPortal\")[];\n includeByQueryParameter?: boolean;\n position?:\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"top-left\"\n | \"top-right\"\n | \"top-center\"\n | \"bottom-left\"\n | \"bottom-right\"\n | \"bottom-center\";\n}\n\nexport declare interface IInitData {\n ssr: boolean;\n runScriptsOnUpdate: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: Partial<IInitStackDetails>;\n clientUrlParams: Partial<Omit<IClientUrlParams, \"url\">>;\n stackSdk: IStackSdk;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewMode;\n enableLivePreviewOutsideIframe: boolean | undefined; // default: undefined\n}\n\n// type PickPartial<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;\n\n// export type IInitData =\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// };\n\n// Post message types\n\nexport declare interface ILivePreviewMessageCommon {\n from: \"live-preview\";\n}\n\nexport declare interface IEditButtonPosition {\n upperBoundOfTooltip: number;\n leftBoundOfTooltip: number;\n}\n\n// end of Post message types\n\nexport interface IVisualBuilderInitEvent {\n windowType: ILivePreviewWindowType;\n stackDetails: {\n masterLocale: string;\n };\n collab?: ICollabConfig[\"collab\"];\n}\n\nexport type IExportedConfig = Pick<\n IConfig,\n | \"ssr\"\n | \"enable\"\n | \"cleanCslpOnProduction\"\n | \"stackDetails\"\n | \"clientUrlParams\"\n | \"windowType\"\n | \"hash\"\n | \"editButton\"\n | \"mode\"\n>;\n"],"mappings":";;;AAuDO,IAAK,yBAAL,kBAAKA,4BAAL;AACH,EAAAA,gDAAA,aAAU,KAAV;AACA,EAAAA,gDAAA,aAAU,KAAV;AAFQ,SAAAA;AAAA,GAAA;AAKL,IAAK,yBAAL,kBAAKC,4BAAL;AACH,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,mBAAgB;AAChB,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,iBAAc;AAJN,SAAAA;AAAA,GAAA;","names":["ILivePreviewModeConfig","ILivePreviewWindowType"]}
1
+ {"version":3,"sources":["../../../src/types/types.ts"],"sourcesContent":["import { ICollabConfig } from \"../visualBuilder/types/collab.types\";\nexport declare interface IEditEntrySearchParams {\n hash?: string;\n entry_uid?: string;\n content_type_uid?: string;\n /**\n * @deprecated pass this value as hash instead\n */\n live_preview?: string;\n}\n\nexport declare interface IClientUrlParams {\n protocol: \"http\" | \"https\";\n host: string;\n port: string | number;\n url: string;\n}\n\nexport declare interface IStackSdk {\n live_preview: { [key: string]: any } & Partial<IConfig>;\n [key: string]: any;\n environment: string;\n}\n\nexport declare interface IStackDetails {\n apiKey: string;\n environment: string;\n contentTypeUid: string;\n entryUid: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n masterLocale: string;\n}\n\nexport declare interface IInitStackDetails {\n apiKey: string;\n environment: string;\n branch: string;\n /**\n * This locale is currently used by the visual builder to\n * redirect to the correct locale if the no data-cslp tag\n * is present in the HTML to extract the locale.\n */\n locale: string;\n}\n\nexport declare type ILivePreviewMode = \"builder\" | \"preview\";\n\n//? We kept it as number so that we could disable only the unrequired features,\n//? since the \"Builder\" mode will contain all the features of the \"Preview\" mode.\nexport enum ILivePreviewModeConfig {\n PREVIEW = 1,\n BUILDER = 2,\n}\n\nexport enum ILivePreviewWindowType {\n PREVIEW = \"preview\",\n PREVIEW_SHARE = \"preview-share\",\n BUILDER = \"builder\",\n INDEPENDENT = \"independent\",\n}\n\nexport declare interface IPageContext {\n entryUid: string;\n contentTypeUid: string;\n}\n\nexport declare interface IConfig {\n ssr: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: IStackDetails;\n clientUrlParams: IClientUrlParams;\n stackSdk: IStackSdk;\n onChange: () => void;\n runScriptsOnUpdate: boolean;\n windowType: ILivePreviewWindowType;\n hash: string;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewModeConfig;\n elements: {\n highlightedElement: HTMLElement | null;\n };\n collab: ICollabConfig[\"collab\"];\n enableLivePreviewOutsideIframe: boolean | undefined;\n pageContext: IPageContext | null;\n}\n\n\nexport declare interface IConfigEditInVisualBuilderButton {\n enable: boolean;\n position?:\n | \"top-left\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-right\"\n}\n\nexport declare interface IConfigOverlayPropagation {\n /**\n * When `true`, Visual Builder hover/click detection falls back to\n * `document.elementsFromPoint()` if the immediate `event.target` has no\n * ancestor with `data-cslp`. This allows the SDK to pierce sibling\n * elements (e.g. empty CSS-grid spacer cells) that visually overlap a\n * `data-cslp` field and would otherwise intercept the mouse event.\n *\n * @default false\n */\n enable: boolean;\n}\n\n\nexport declare interface IConfigEditButton {\n enable: boolean;\n exclude?: (\"insideLivePreviewPortal\" | \"outsideLivePreviewPortal\")[];\n includeByQueryParameter?: boolean;\n position?:\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"top-left\"\n | \"top-right\"\n | \"top-center\"\n | \"bottom-left\"\n | \"bottom-right\"\n | \"bottom-center\";\n}\n\nexport declare interface IInitData {\n ssr: boolean;\n runScriptsOnUpdate: boolean;\n enable: boolean;\n /**\n * @default false\n */\n debug: boolean;\n cleanCslpOnProduction: boolean;\n stackDetails: Partial<IInitStackDetails>;\n clientUrlParams: Partial<Omit<IClientUrlParams, \"url\">>;\n stackSdk: IStackSdk;\n editButton: IConfigEditButton;\n editInVisualBuilderButton: IConfigEditInVisualBuilderButton;\n overlayPropagation: IConfigOverlayPropagation;\n mode: ILivePreviewMode;\n enableLivePreviewOutsideIframe: boolean | undefined; // default: undefined\n}\n\n// type PickPartial<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;\n\n// export type IInitData =\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr?: true;\n// stackSdk?: IStackSdk;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails?: Partial<IInitStackDetails>;\n// clientUrlParams?: Partial<Omit<IClientUrlParams, \"url\">>;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode?: \"preview\";\n// }\n// | {\n// ssr: false;\n// runScriptsOnUpdate?: boolean;\n// enable?: boolean;\n// cleanCslpOnProduction?: boolean;\n// stackDetails: PickPartial<IInitStackDetails, \"branch\">;\n// clientUrlParams: PickPartial<\n// Omit<IClientUrlParams, \"url\">,\n// \"port\" | \"protocol\"\n// >;\n// stackSdk: IStackSdk;\n// editButton?: IConfigEditButton;\n// mode: \"builder\";\n// };\n\n// Post message types\n\nexport declare interface ILivePreviewMessageCommon {\n from: \"live-preview\";\n}\n\nexport declare interface IEditButtonPosition {\n upperBoundOfTooltip: number;\n leftBoundOfTooltip: number;\n}\n\n// end of Post message types\n\nexport interface IVisualBuilderInitEvent {\n windowType: ILivePreviewWindowType;\n stackDetails: {\n masterLocale: string;\n };\n collab?: ICollabConfig[\"collab\"];\n}\n\nexport type IExportedConfig = Pick<\n IConfig,\n | \"ssr\"\n | \"enable\"\n | \"cleanCslpOnProduction\"\n | \"stackDetails\"\n | \"clientUrlParams\"\n | \"windowType\"\n | \"hash\"\n | \"editButton\"\n | \"mode\"\n>;\n"],"mappings":";;;AAuDO,IAAK,yBAAL,kBAAKA,4BAAL;AACH,EAAAA,gDAAA,aAAU,KAAV;AACA,EAAAA,gDAAA,aAAU,KAAV;AAFQ,SAAAA;AAAA,GAAA;AAKL,IAAK,yBAAL,kBAAKC,4BAAL;AACH,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,mBAAgB;AAChB,EAAAA,wBAAA,aAAU;AACV,EAAAA,wBAAA,iBAAc;AAJN,SAAAA;AAAA,GAAA;","names":["ILivePreviewModeConfig","ILivePreviewWindowType"]}