@comet/site-react 9.0.0-beta.3 → 9.0.0-beta.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 (71) hide show
  1. package/lib/blockLoader/blockLoader.js +1 -59
  2. package/lib/blocks/DamFileDownloadLinkBlock.js +1 -27
  3. package/lib/blocks/DamVideoBlock.js +5 -99
  4. package/lib/blocks/DamVideoBlock.module.scss.js +1 -14
  5. package/lib/blocks/EmailLinkBlock.js +1 -21
  6. package/lib/blocks/ExternalLinkBlock.js +1 -47
  7. package/lib/blocks/PhoneLinkBlock.js +1 -21
  8. package/lib/blocks/SvgImageBlock.js +1 -30
  9. package/lib/blocks/VimeoVideoBlock.js +4 -129
  10. package/lib/blocks/VimeoVideoBlock.module.scss.js +1 -14
  11. package/lib/blocks/YouTubeVideoBlock.js +4 -136
  12. package/lib/blocks/YouTubeVideoBlock.module.scss.js +1 -14
  13. package/lib/blocks/factories/BlocksBlock.js +1 -27
  14. package/lib/blocks/factories/ListBlock.js +1 -13
  15. package/lib/blocks/factories/OneOfBlock.js +1 -23
  16. package/lib/blocks/factories/OptionalBlock.js +1 -10
  17. package/lib/blocks/helpers/PlayPauseButton.js +1 -9
  18. package/lib/blocks/helpers/PlayPauseButton.module.scss.js +1 -14
  19. package/lib/blocks/helpers/RichTextBlockHelper.js +1 -7
  20. package/lib/blocks/helpers/TipTapRichTextRenderer.d.ts +35 -0
  21. package/lib/blocks/helpers/TipTapRichTextRenderer.d.ts.map +1 -0
  22. package/lib/blocks/helpers/TipTapRichTextRenderer.js +3 -0
  23. package/lib/blocks/helpers/VideoPreviewImage.js +2 -23
  24. package/lib/blocks/helpers/VideoPreviewImage.module.scss.js +1 -17
  25. package/lib/blocks/helpers/useIsElementInViewport.js +1 -21
  26. package/lib/cookies/CookieApiContext.js +2 -18
  27. package/lib/cookies/CookieSafe.js +2 -18
  28. package/lib/cookies/useCookieBotCookieApi.js +1 -33
  29. package/lib/cookies/useLocalStorageCookieApi.js +1 -40
  30. package/lib/cookies/useOneTrustCookieApi.js +1 -45
  31. package/lib/errorHandler/ErrorHandlerBoundary.js +2 -10
  32. package/lib/errorHandler/ErrorHandlerBoundaryInternal.js +1 -26
  33. package/lib/errorHandler/ErrorHandlerProvider.js +2 -20
  34. package/lib/graphQLFetch/fetchInMemoryCache.js +1 -37
  35. package/lib/graphQLFetch/graphQLFetch.js +1 -125
  36. package/lib/iframebridge/IFrameBridge.js +4 -253
  37. package/lib/iframebridge/IFrameBridge.module.scss.js +1 -8
  38. package/lib/iframebridge/IFrameMessage.js +1 -21
  39. package/lib/iframebridge/Preview.js +1 -56
  40. package/lib/iframebridge/Preview.module.scss.js +1 -8
  41. package/lib/iframebridge/PreviewOverlay.js +1 -28
  42. package/lib/iframebridge/PreviewOverlay.module.scss.js +1 -8
  43. package/lib/iframebridge/PreviewOverlayElement.js +2 -36
  44. package/lib/iframebridge/PreviewOverlayElement.module.scss.js +1 -20
  45. package/lib/iframebridge/useBlockPreviewFetch.js +1 -29
  46. package/lib/iframebridge/useIFrameBridge.js +1 -8
  47. package/lib/iframebridge/utils.js +1 -46
  48. package/lib/iframebridge/withPreview.js +1 -33
  49. package/lib/image/Image.js +2 -10
  50. package/lib/image/image.utils.js +1 -55
  51. package/lib/index.d.ts +2 -2
  52. package/lib/index.d.ts.map +1 -1
  53. package/lib/index.js +1 -96
  54. package/lib/jsonLd/JsonLd.d.ts +7 -0
  55. package/lib/jsonLd/JsonLd.d.ts.map +1 -0
  56. package/lib/jsonLd/JsonLd.js +1 -0
  57. package/lib/persistedQueries/createPersistedQueryGraphQLFetch.js +1 -70
  58. package/lib/persistedQueries/persistedQueryRoute.js +1 -100
  59. package/lib/persistedQueries/webpackPersistedQueriesLoader.js +1 -51
  60. package/lib/preview/BlockPreviewProvider.js +1 -32
  61. package/lib/preview/PreviewContext.js +1 -9
  62. package/lib/preview/usePreview.js +1 -41
  63. package/lib/previewskeleton/PreviewSkeleton.js +8 -64
  64. package/lib/previewskeleton/PreviewSkeleton.module.scss.js +1 -17
  65. package/lib/server.d.ts +2 -0
  66. package/lib/server.d.ts.map +1 -0
  67. package/lib/server.js +1 -0
  68. package/lib/sitePreview/iframebridge/SitePreviewIFrameMessage.js +1 -8
  69. package/lib/sitePreview/iframebridge/sendSitePreviewIFrameMessage.js +1 -6
  70. package/lib/style.css +1 -1
  71. package/package.json +15 -8
@@ -1,125 +1 @@
1
- function convertPreviewDataToHeaders(previewData) {
2
- const { includeInvisibleBlocks, includeInvisiblePages } = {
3
- includeInvisiblePages: !!previewData,
4
- includeInvisibleBlocks: previewData && previewData.includeInvisible
5
- };
6
- const headers = {};
7
- const includeInvisibleContentHeaderEntries = [];
8
- if (includeInvisiblePages) {
9
- includeInvisibleContentHeaderEntries.push("Pages:Unpublished");
10
- }
11
- if (includeInvisibleBlocks) {
12
- includeInvisibleContentHeaderEntries.push("Blocks:Invisible");
13
- }
14
- if (includeInvisibleContentHeaderEntries.length > 0) {
15
- headers["x-include-invisible-content"] = includeInvisibleContentHeaderEntries.join(",");
16
- headers["x-preview-dam-urls"] = "1";
17
- }
18
- return headers;
19
- }
20
- const gql = (chunks, ...variables) => {
21
- return chunks.reduce((acc, chunk, index) => {
22
- let variable;
23
- if (index in variables) {
24
- if (typeof variables[index] !== "string") {
25
- let errorMessage = `Non-string variable in the GraphQL document
26
-
27
- This is most likely due to importing a GraphQL document from a React Client Component.
28
- All GraphQL documents need to be imported from React Server Components (i.e. no "use client" notation).`;
29
- if (chunk.trim().length > 0) {
30
- errorMessage += `
31
-
32
- The error occurred in the following GraphQL document:
33
- ${chunk}`;
34
- }
35
- throw new Error(errorMessage);
36
- } else {
37
- variable = variables[index];
38
- }
39
- } else {
40
- variable = "";
41
- }
42
- return `${acc}${chunk}${variable}`;
43
- }, ``);
44
- };
45
- function createFetchWithPreviewHeaders(fetch, previewData) {
46
- const defaultHeaders = convertPreviewDataToHeaders(previewData);
47
- return createFetchWithDefaults(fetch, { headers: defaultHeaders });
48
- }
49
- function createFetchWithDefaults(fetch, defaults) {
50
- return async function(input, init) {
51
- return fetch(input, {
52
- ...defaults,
53
- ...init,
54
- headers: {
55
- ...defaults.headers,
56
- ...init == null ? void 0 : init.headers
57
- }
58
- });
59
- };
60
- }
61
- function createGraphQLFetch(fetch, url) {
62
- return async function(query, variables, init) {
63
- let response;
64
- if ((init == null ? void 0 : init.method) === "GET") {
65
- const fetchUrl = new URL(url);
66
- fetchUrl.searchParams.append("query", query);
67
- fetchUrl.searchParams.append("variables", JSON.stringify(variables));
68
- response = await fetch(fetchUrl, {
69
- ...init,
70
- headers: {
71
- /**
72
- * It's recommended to add the `Apollo-Require-Preflight` header to GET requests, running on an Apollo Server 4.
73
- *
74
- * If this header is missing, Apollo Server 4 will return: This operation has been blocked as a potential Cross-Site Request Forgery (CSRF).
75
- *
76
- * see: https://www.apollographql.com/docs/graphos/routing/security/csrf#enable-csrf-prevention
77
- */
78
- "Apollo-Require-Preflight": "true",
79
- ...init.headers
80
- }
81
- });
82
- } else {
83
- response = await fetch(url, {
84
- method: "POST",
85
- ...init,
86
- headers: { "Content-Type": "application/json", ...init == null ? void 0 : init.headers },
87
- body: JSON.stringify({
88
- query,
89
- variables
90
- })
91
- });
92
- }
93
- if (!response.ok) {
94
- let errorMessage = `Network response was not ok. Status: ${response.status}`;
95
- const body = await response.text();
96
- try {
97
- const json = JSON.parse(body);
98
- const { errors: errors2 } = json;
99
- if (errors2) {
100
- errorMessage += `
101
-
102
- GraphQL error(s):
103
- - ${errors2.map((error) => error.message).join("\n- ")}`;
104
- }
105
- } catch {
106
- errorMessage += `
107
- ${body}`;
108
- }
109
- throw new Error(errorMessage);
110
- }
111
- const { data, errors } = await response.json();
112
- if (errors) {
113
- throw new Error(`GraphQL error(s):
114
- - ${errors.map((error) => error.message).join("\n- ")}`);
115
- }
116
- return data;
117
- };
118
- }
119
- export {
120
- convertPreviewDataToHeaders,
121
- createFetchWithDefaults,
122
- createFetchWithPreviewHeaders,
123
- createGraphQLFetch,
124
- gql
125
- };
1
+ function e(e){const{includeInvisibleBlocks:n,includeInvisiblePages:r}={includeInvisiblePages:!!e,includeInvisibleBlocks:e&&e.includeInvisible},t={},i=[];return r&&i.push("Pages:Unpublished"),n&&i.push("Blocks:Invisible"),i.length>0&&(t["x-include-invisible-content"]=i.join(","),t["x-preview-dam-urls"]="1"),t}const n=(e,...n)=>e.reduce((e,r,t)=>{let i;if(t in n){if("string"!=typeof n[t]){let e='Non-string variable in the GraphQL document\n\nThis is most likely due to importing a GraphQL document from a React Client Component.\nAll GraphQL documents need to be imported from React Server Components (i.e. no "use client" notation).';throw r.trim().length>0&&(e+=`\n\nThe error occurred in the following GraphQL document:\n${r}`),new Error(e)}i=n[t]}else i="";return`${e}${r}${i}`},"");function r(n,r){return t(n,{headers:e(r)})}function t(e,n){return async function(r,t){return e(r,{...n,...t,headers:{...n.headers,...t?.headers}})}}function i(e,n){return async function(r,t,i){let o;if("GET"===i?.method){const s=new URL(n);s.searchParams.append("query",r),s.searchParams.append("variables",JSON.stringify(t)),o=await e(s,{...i,headers:{"Apollo-Require-Preflight":"true",...i.headers}})}else o=await e(n,{method:"POST",...i,headers:{"Content-Type":"application/json",...i?.headers},body:JSON.stringify({query:r,variables:t})});if(!o.ok){let e=`Network response was not ok. Status: ${o.status}`;const n=await o.text();try{const r=JSON.parse(n),{errors:t}=r;t&&(e+=`\n\nGraphQL error(s):\n- ${t.map(e=>e.message).join("\n- ")}`)}catch{e+=`\n${n}`}throw new Error(e)}const{data:s,errors:a}=await o.json();if(a)throw new Error(`GraphQL error(s):\n- ${a.map(e=>e.message).join("\n- ")}`);return s}}export{e as convertPreviewDataToHeaders,t as createFetchWithDefaults,r as createFetchWithPreviewHeaders,i as createGraphQLFetch,n as gql};
@@ -1,254 +1,5 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { decodeJwt } from "jose";
4
- import isEqual from "lodash.isequal";
5
- import { useState, useRef, useCallback, useEffect, useMemo, createContext } from "react";
6
- import { useDebounceCallback } from "usehooks-ts";
7
- import styles from "./IFrameBridge.module.scss.js";
8
- import { AdminMessageType, IFrameMessageType } from "./IFrameMessage.js";
9
- import { PreviewOverlay } from "./PreviewOverlay.js";
10
- import { getRecursiveChildrenOfPreviewElement, getCombinedPositioningOfElements, PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT } from "./utils.js";
11
- const IFrameBridgeContext = createContext({
12
- hasBridge: false,
13
- showOutlines: false,
14
- showOnlyVisible: false,
15
- sendSelectComponent: () => {
16
- },
17
- sendHoverComponent: () => {
18
- },
19
- sendMessage: () => {
20
- },
21
- contentScope: void 0,
22
- contentScopeJwt: "",
23
- graphQLApiUrl: void 0,
24
- previewElementsData: [],
25
- removePreviewElement: () => {
26
- },
27
- addPreviewElement: () => {
28
- }
29
- });
30
- function getContentScopeFromJwt(jwt) {
31
- try {
32
- const parsedJwt = decodeJwt(jwt);
33
- return parsedJwt.scope;
34
- } catch (e) {
35
- console.error("Failed to parse content scope JWT", e);
36
- return void 0;
37
- }
38
- }
39
- const IFrameBridgeProvider = ({ children }) => {
40
- var _a;
41
- const [block, setBlock] = useState(void 0);
42
- const [showOnlyVisible, setShowOnlyVisible] = useState(false);
43
- const [selectedAdminRoute, setSelectedAdminRoute] = useState(void 0);
44
- const [hoveredAdminRoute, setHoveredAdminRoute] = useState(null);
45
- const [showOutlines, setShowOutlines] = useState(false);
46
- const [contentScope, setContentScope] = useState(void 0);
47
- const [contentScopeJwt, setContentScopeJwt] = useState("");
48
- const [graphQLApiUrl, setGraphQLApiUrl] = useState("");
49
- const [previewElements, setPreviewElements] = useState([]);
50
- const [previewElementsData, setPreviewElementsData] = useState([]);
51
- const childrenWrapperRef = useRef(null);
52
- const childrenWrapperWidth = (_a = childrenWrapperRef.current) == null ? void 0 : _a.offsetWidth;
53
- const recalculatePreviewElementsData = useCallback(() => {
54
- if (!childrenWrapperWidth) {
55
- return;
56
- }
57
- const newPreviewElementsData = previewElements.map((previewElement) => {
58
- const childNodes = getRecursiveChildrenOfPreviewElement(previewElement.element);
59
- const positioning = getCombinedPositioningOfElements(childNodes);
60
- const isRenderedOutsideOfViewportWidth = positioning.left > childrenWrapperWidth;
61
- if (isRenderedOutsideOfViewportWidth) {
62
- return {
63
- adminRoute: previewElement.adminRoute,
64
- label: previewElement.label,
65
- position: {
66
- top: positioning.top,
67
- left: positioning.left,
68
- width: 0,
69
- height: positioning.height
70
- }
71
- };
72
- }
73
- const spaceBetweenRightEdgeOfElementAndRightEdgeOfViewport = positioning.left + positioning.width - childrenWrapperWidth;
74
- const tooWideForPreviewViewportByPixels = spaceBetweenRightEdgeOfElementAndRightEdgeOfViewport > 0 ? spaceBetweenRightEdgeOfElementAndRightEdgeOfViewport : 0;
75
- return {
76
- adminRoute: previewElement.adminRoute,
77
- label: previewElement.label,
78
- position: {
79
- top: positioning.top,
80
- left: positioning.left,
81
- width: positioning.width - tooWideForPreviewViewportByPixels,
82
- height: positioning.height
83
- }
84
- };
85
- }).filter((elementData) => elementData.position.width !== 0).sort((previousElementData, nextElementData) => {
86
- const previousSize = previousElementData.position.width * previousElementData.position.height;
87
- const nextSize = nextElementData.position.width * nextElementData.position.height;
88
- return nextSize - previousSize;
89
- }).map((elementData, index) => {
90
- return {
91
- ...elementData,
92
- position: {
93
- ...elementData.position,
94
- zIndex: index + 1
95
- }
96
- };
97
- });
98
- setPreviewElementsData((previousElementsData) => {
99
- const dataDidNotChange = isEqual(previousElementsData, newPreviewElementsData);
100
- if (dataDidNotChange) {
101
- return previousElementsData;
102
- }
103
- return newPreviewElementsData;
104
- });
105
- }, [previewElements, childrenWrapperWidth]);
106
- useEffect(() => {
107
- if (childrenWrapperRef.current) {
108
- const mutationObserver = new MutationObserver(() => {
109
- recalculatePreviewElementsData();
110
- });
111
- const resizeObserver = new ResizeObserver(() => {
112
- recalculatePreviewElementsData();
113
- });
114
- mutationObserver.observe(childrenWrapperRef.current, { childList: true, subtree: true, attributes: true });
115
- resizeObserver.observe(childrenWrapperRef.current);
116
- return () => {
117
- mutationObserver.disconnect();
118
- resizeObserver.disconnect();
119
- };
120
- }
121
- }, [recalculatePreviewElementsData]);
122
- useEffect(() => {
123
- previewElements.forEach((previewElement) => {
124
- previewElement.element.addEventListener(PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT, recalculatePreviewElementsData);
125
- });
126
- return () => {
127
- previewElements.forEach((previewElement) => {
128
- previewElement.element.removeEventListener(PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT, recalculatePreviewElementsData);
129
- });
130
- };
131
- }, [previewElements, recalculatePreviewElementsData]);
132
- const sendMessage = useCallback((message) => {
133
- window.parent.postMessage(JSON.stringify(message), "*");
134
- }, []);
135
- const debounceDeactivateOutlines = useDebounceCallback(() => {
136
- setShowOutlines(false);
137
- }, 2500);
138
- const onReceiveMessage = useCallback(
139
- (message) => {
140
- switch (message.cometType) {
141
- case AdminMessageType.Block:
142
- setBlock(message.data.block);
143
- break;
144
- case AdminMessageType.ShowOnlyVisible:
145
- setShowOnlyVisible(message.data.showOnlyVisible);
146
- break;
147
- case AdminMessageType.SelectComponent:
148
- setSelectedAdminRoute(
149
- message.data.adminRoute.lastIndexOf("#") > 0 ? message.data.adminRoute.substr(0, message.data.adminRoute.lastIndexOf("#")) : message.data.adminRoute
150
- );
151
- break;
152
- case AdminMessageType.HoverComponent:
153
- setHoveredAdminRoute(message.data.adminRoute);
154
- setShowOutlines(true);
155
- debounceDeactivateOutlines();
156
- break;
157
- case AdminMessageType.ContentScope:
158
- setContentScope(getContentScopeFromJwt(message.data.contentScopeJwt));
159
- setContentScopeJwt(message.data.contentScopeJwt);
160
- break;
161
- case AdminMessageType.GraphQLApiUrl:
162
- setGraphQLApiUrl(message.data.graphQLApiUrl);
163
- break;
164
- }
165
- },
166
- [debounceDeactivateOutlines]
167
- );
168
- useEffect(() => {
169
- if (typeof window === "undefined") {
170
- return;
171
- }
172
- const handleMessage = (e) => {
173
- try {
174
- const message = JSON.parse(e.data);
175
- if (message.hasOwnProperty("cometType")) {
176
- onReceiveMessage(message);
177
- }
178
- } catch {
179
- }
180
- };
181
- window.addEventListener("message", handleMessage, false);
182
- sendMessage({ cometType: IFrameMessageType.Ready });
183
- return () => {
184
- window.removeEventListener("message", handleMessage, false);
185
- };
186
- }, [onReceiveMessage, sendMessage]);
187
- const addPreviewElement = useCallback(
188
- (element) => {
189
- setPreviewElements((prev) => [...prev, element]);
190
- },
191
- [setPreviewElements]
192
- );
193
- const removePreviewElement = useCallback(
194
- (element) => {
195
- setPreviewElements((prev) => prev.filter((el) => el.adminRoute !== element.adminRoute));
196
- },
197
- [setPreviewElements]
198
- );
199
- const iFrameBridgeValues = useMemo(
200
- () => ({
201
- showOutlines,
202
- hasBridge: true,
203
- block,
204
- showOnlyVisible,
205
- selectedAdminRoute,
206
- hoveredAdminRoute,
207
- sendSelectComponent: (adminRoute) => {
208
- setSelectedAdminRoute(adminRoute);
209
- sendMessage({ cometType: IFrameMessageType.SelectComponent, data: { adminRoute } });
210
- },
211
- sendHoverComponent: (route) => {
212
- sendMessage({ cometType: IFrameMessageType.HoverComponent, data: { route } });
213
- },
214
- sendMessage,
215
- contentScope,
216
- contentScopeJwt,
217
- graphQLApiUrl,
218
- previewElementsData,
219
- addPreviewElement,
220
- removePreviewElement
221
- }),
222
- [
223
- showOutlines,
224
- block,
225
- showOnlyVisible,
226
- selectedAdminRoute,
227
- hoveredAdminRoute,
228
- sendMessage,
229
- contentScope,
230
- contentScopeJwt,
231
- graphQLApiUrl,
232
- previewElementsData,
233
- addPreviewElement,
234
- removePreviewElement
235
- ]
236
- );
237
- return /* @__PURE__ */ jsx(IFrameBridgeContext.Provider, { value: iFrameBridgeValues, children: /* @__PURE__ */ jsxs(
238
- "div",
239
- {
240
- onMouseMove: () => {
241
- setShowOutlines(true);
242
- debounceDeactivateOutlines();
243
- },
244
- children: [
245
- /* @__PURE__ */ jsx(PreviewOverlay, {}),
246
- /* @__PURE__ */ jsx("div", { ref: childrenWrapperRef, className: styles.childrenWrapper, children })
247
- ]
248
- }
249
- ) });
250
- };
251
- export {
252
- IFrameBridgeContext,
253
- IFrameBridgeProvider
254
- };
2
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import{decodeJwt as o}from"jose";import n from"lodash.isequal";import{useState as r,useRef as i,useCallback as s,useEffect as a,useMemo as d,createContext as c}from"react";import{useDebounceCallback as l}from"usehooks-ts";import m from"./IFrameBridge.module.scss.js";import{AdminMessageType as p,IFrameMessageType as h}from"./IFrameMessage.js";import{PreviewOverlay as u}from"./PreviewOverlay.js";import{getRecursiveChildrenOfPreviewElement as v,getCombinedPositioningOfElements as w,PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT as f}from"./utils.js";const b=c({hasBridge:!1,showOutlines:!1,showOnlyVisible:!1,sendSelectComponent:()=>{},sendHoverComponent:()=>{},sendMessage:()=>{},contentScope:void 0,contentScopeJwt:"",graphQLApiUrl:void 0,previewElementsData:[],removePreviewElement:()=>{},addPreviewElement:()=>{}});const g=({children:c})=>{const[g,y]=r(void 0),[R,O]=r(!1),[S,E]=r(void 0),[k,C]=r(null),[L,J]=r(!1),[M,P]=r(void 0),[j,A]=r(""),[T,x]=r(""),[I,B]=r([]),[H,Q]=r([]),U=i(null),V=U.current?.offsetWidth,F=s(()=>{if(!V)return;const e=I.map(e=>{const t=v(e.element),o=w(t);if(o.left>V)return{adminRoute:e.adminRoute,label:e.label,position:{top:o.top,left:o.left,width:0,height:o.height}};const n=o.left+o.width-V,r=n>0?n:0;return{adminRoute:e.adminRoute,label:e.label,position:{top:o.top,left:o.left,width:o.width-r,height:o.height}}}).filter(e=>0!==e.position.width).sort((e,t)=>{const o=e.position.width*e.position.height;return t.position.width*t.position.height-o}).map((e,t)=>({...e,position:{...e.position,zIndex:t+1}}));Q(t=>n(t,e)?t:e)},[I,V]);a(()=>{if(U.current){const e=new MutationObserver(()=>{F()}),t=new ResizeObserver(()=>{F()});return e.observe(U.current,{childList:!0,subtree:!0,attributes:!0}),t.observe(U.current),()=>{e.disconnect(),t.disconnect()}}},[F]),a(()=>(I.forEach(e=>{e.element.addEventListener(f,F)}),()=>{I.forEach(e=>{e.element.removeEventListener(f,F)})}),[I,F]);const N=s(e=>{window.parent.postMessage(JSON.stringify(e),"*")},[]),W=l(()=>{J(!1)},2500),z=s(e=>{switch(e.cometType){case p.Block:y(e.data.block);break;case p.ShowOnlyVisible:O(e.data.showOnlyVisible);break;case p.SelectComponent:E(e.data.adminRoute.lastIndexOf("#")>0?e.data.adminRoute.substr(0,e.data.adminRoute.lastIndexOf("#")):e.data.adminRoute);break;case p.HoverComponent:C(e.data.adminRoute),J(!0),W();break;case p.ContentScope:P(function(e){try{return o(e).scope}catch(t){return void console.error("Failed to parse content scope JWT",t)}}(e.data.contentScopeJwt)),A(e.data.contentScopeJwt);break;case p.GraphQLApiUrl:x(e.data.graphQLApiUrl)}},[W]);a(()=>{if("undefined"==typeof window)return;const e=e=>{try{const t=JSON.parse(e.data);t.hasOwnProperty("cometType")&&z(t)}catch{}};return window.addEventListener("message",e,!1),N({cometType:h.Ready}),()=>{window.removeEventListener("message",e,!1)}},[z,N]);const D=s(e=>{B(t=>[...t,e])},[B]),q=s(e=>{B(t=>t.filter(t=>t.adminRoute!==e.adminRoute))},[B]),G=d(()=>({showOutlines:L,hasBridge:!0,block:g,showOnlyVisible:R,selectedAdminRoute:S,hoveredAdminRoute:k,sendSelectComponent:e=>{E(e),N({cometType:h.SelectComponent,data:{adminRoute:e}})},sendHoverComponent:e=>{N({cometType:h.HoverComponent,data:{route:e}})},sendMessage:N,contentScope:M,contentScopeJwt:j,graphQLApiUrl:T,previewElementsData:H,addPreviewElement:D,removePreviewElement:q}),[L,g,R,S,k,N,M,j,T,H,D,q]);/* @__PURE__ */
3
+ return e(b.Provider,{value:G,children:/* @__PURE__ */t("div",{onMouseMove:()=>{J(!0),W()},children:[
4
+ /* @__PURE__ */e(u,{}),
5
+ /* @__PURE__ */e("div",{ref:U,className:m.childrenWrapper,children:c})]})})};export{b as IFrameBridgeContext,g as IFrameBridgeProvider};
@@ -1,8 +1 @@
1
- const childrenWrapper = "_childrenWrapper_qguhx_1";
2
- const styles = {
3
- childrenWrapper
4
- };
5
- export {
6
- childrenWrapper,
7
- styles as default
8
- };
1
+ const r="_childrenWrapper_qguhx_1",e={childrenWrapper:r};export{r as childrenWrapper,e as default};
@@ -1,21 +1 @@
1
- var IFrameMessageType = /* @__PURE__ */ ((IFrameMessageType2) => {
2
- IFrameMessageType2["Ready"] = "Ready";
3
- IFrameMessageType2["SelectComponent"] = "SelectComponent";
4
- IFrameMessageType2["HoverComponent"] = "HoverComponent";
5
- IFrameMessageType2["OpenLink"] = "OpenLink";
6
- IFrameMessageType2["SitePreviewLocation"] = "SitePreviewLocation";
7
- return IFrameMessageType2;
8
- })(IFrameMessageType || {});
9
- var AdminMessageType = /* @__PURE__ */ ((AdminMessageType2) => {
10
- AdminMessageType2["Block"] = "Block";
11
- AdminMessageType2["ShowOnlyVisible"] = "ShowOnlyVisible";
12
- AdminMessageType2["SelectComponent"] = "SelectComponent";
13
- AdminMessageType2["HoverComponent"] = "HoverComponent";
14
- AdminMessageType2["ContentScope"] = "ContentScope";
15
- AdminMessageType2["GraphQLApiUrl"] = "GraphQLApiUrl";
16
- return AdminMessageType2;
17
- })(AdminMessageType || {});
18
- export {
19
- AdminMessageType,
20
- IFrameMessageType
21
- };
1
+ var e=/* @__PURE__ */(e=>(e.Ready="Ready",e.SelectComponent="SelectComponent",e.HoverComponent="HoverComponent",e.OpenLink="OpenLink",e.SitePreviewLocation="SitePreviewLocation",e))(e||{}),o=/* @__PURE__ */(e=>(e.Block="Block",e.ShowOnlyVisible="ShowOnlyVisible",e.SelectComponent="SelectComponent",e.HoverComponent="HoverComponent",e.ContentScope="ContentScope",e.GraphQLApiUrl="GraphQLApiUrl",e))(o||{});export{o as AdminMessageType,e as IFrameMessageType};
@@ -1,57 +1,2 @@
1
1
  "use client";
2
- import { jsx, Fragment } from "react/jsx-runtime";
3
- import { useRef, useEffect } from "react";
4
- import scrollIntoView from "scroll-into-view-if-needed";
5
- import styles from "./Preview.module.scss.js";
6
- import { useIFrameBridge } from "./useIFrameBridge.js";
7
- import { PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT, BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE } from "./utils.js";
8
- const Preview = ({ adminRoute, children, label, enabledAutoScrolling = true }) => {
9
- const { addPreviewElement, removePreviewElement, ...iFrameBridge } = useIFrameBridge();
10
- const isSelected = adminRoute === iFrameBridge.selectedAdminRoute;
11
- const isHovered = adminRoute === iFrameBridge.hoveredAdminRoute;
12
- const previewElementContainerRef = useRef(null);
13
- useEffect(() => {
14
- const previewElement = previewElementContainerRef.current ? {
15
- label,
16
- adminRoute,
17
- element: previewElementContainerRef.current
18
- } : null;
19
- if (previewElement) {
20
- addPreviewElement(previewElement);
21
- return () => {
22
- removePreviewElement(previewElement);
23
- };
24
- }
25
- }, [label, adminRoute, addPreviewElement, removePreviewElement]);
26
- useEffect(() => {
27
- const timeout = setTimeout(() => {
28
- var _a;
29
- if (enabledAutoScrolling) {
30
- if (isHovered || isSelected) {
31
- if ((_a = previewElementContainerRef.current) == null ? void 0 : _a.firstElementChild) {
32
- scrollIntoView(previewElementContainerRef.current.firstElementChild, {
33
- scrollMode: "if-needed",
34
- block: "center",
35
- inline: "nearest",
36
- behavior: "smooth"
37
- });
38
- setTimeout(() => {
39
- var _a2;
40
- (_a2 = previewElementContainerRef.current) == null ? void 0 : _a2.dispatchEvent(new Event(PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT));
41
- }, 600);
42
- }
43
- }
44
- }
45
- }, 500);
46
- return () => {
47
- clearTimeout(timeout);
48
- };
49
- }, [enabledAutoScrolling, isHovered, isSelected]);
50
- if (iFrameBridge.hasBridge) {
51
- return /* @__PURE__ */ jsx("div", { ref: previewElementContainerRef, className: styles.previewElementContainer, ...{ [BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE]: "" }, children });
52
- }
53
- return /* @__PURE__ */ jsx(Fragment, { children });
54
- };
55
- export {
56
- Preview
57
- };
2
+ import{jsx as e,Fragment as r}from"react/jsx-runtime";import{useRef as t,useEffect as n}from"react";import i from"scroll-into-view-if-needed";import o from"./Preview.module.scss.js";import{useIFrameBridge as l}from"./useIFrameBridge.js";import{PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT as m,BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE as s}from"./utils.js";const c=({adminRoute:c,children:d,label:u,enabledAutoScrolling:a=!0})=>{const{addPreviewElement:f,removePreviewElement:v,...h}=l(),p=c===h.selectedAdminRoute,E=c===h.hoveredAdminRoute,w=t(null);return n(()=>{const e=w.current?{label:u,adminRoute:c,element:w.current}:null;if(e)return f(e),()=>{v(e)}},[u,c,f,v]),n(()=>{const e=setTimeout(()=>{a&&(E||p)&&w.current?.firstElementChild&&(i(w.current.firstElementChild,{scrollMode:"if-needed",block:"center",inline:"nearest",behavior:"smooth"}),setTimeout(()=>{w.current?.dispatchEvent(new Event(m))},600))},500);return()=>{clearTimeout(e)}},[a,E,p]),h.hasBridge?/* @__PURE__ */e("div",{ref:w,className:o.previewElementContainer,[s]:"",children:d}):/* @__PURE__ */e(r,{children:d})};export{c as Preview};
@@ -1,8 +1 @@
1
- const previewElementContainer = "_previewElementContainer_nwhl6_1";
2
- const styles = {
3
- previewElementContainer
4
- };
5
- export {
6
- styles as default,
7
- previewElementContainer
8
- };
1
+ const e="_previewElementContainer_nwhl6_1",n={previewElementContainer:e};export{n as default,e as previewElementContainer};
@@ -1,28 +1 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import styles from "./PreviewOverlay.module.scss.js";
3
- import { PreviewOverlayElement } from "./PreviewOverlayElement.js";
4
- import { useIFrameBridge } from "./useIFrameBridge.js";
5
- let lastSelectedElementPath = "";
6
- const PreviewOverlay = () => {
7
- const iFrameBridge = useIFrameBridge();
8
- let bottomMostElementPosition = 0;
9
- iFrameBridge.previewElementsData.forEach((element) => {
10
- if (element.position.zIndex > 1) {
11
- return;
12
- }
13
- const elementBottom = element.position.top + element.position.height;
14
- if (elementBottom > bottomMostElementPosition) {
15
- bottomMostElementPosition = elementBottom;
16
- }
17
- });
18
- return /* @__PURE__ */ jsx("div", { className: styles.root, style: { "--height": `${bottomMostElementPosition}px` }, children: iFrameBridge.previewElementsData.map((element, index) => {
19
- const isSelected = element.adminRoute === iFrameBridge.selectedAdminRoute;
20
- if (isSelected && lastSelectedElementPath !== element.adminRoute) {
21
- lastSelectedElementPath = element.adminRoute;
22
- }
23
- return /* @__PURE__ */ jsx(PreviewOverlayElement, { element }, index);
24
- }) });
25
- };
26
- export {
27
- PreviewOverlay
28
- };
1
+ import{jsx as e}from"react/jsx-runtime";import t from"./PreviewOverlay.module.scss.js";import{PreviewOverlayElement as o}from"./PreviewOverlayElement.js";import{useIFrameBridge as r}from"./useIFrameBridge.js";let i="";const m=()=>{const m=r();let s=0;return m.previewElementsData.forEach(e=>{if(e.position.zIndex>1)return;const t=e.position.top+e.position.height;t>s&&(s=t)}),/* @__PURE__ */e("div",{className:t.root,style:{"--height":`${s}px`},children:m.previewElementsData.map((t,r)=>(t.adminRoute===m.selectedAdminRoute&&i!==t.adminRoute&&(i=t.adminRoute),/* @__PURE__ */e(o,{element:t},r)))})};export{m as PreviewOverlay};
@@ -1,8 +1 @@
1
- const root = "_root_v4248_1";
2
- const styles = {
3
- root
4
- };
5
- export {
6
- styles as default,
7
- root
8
- };
1
+ const o="_root_v4248_1",t={root:o};export{t as default,o as root};
@@ -1,36 +1,2 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import clsx from "clsx";
3
- import styles from "./PreviewOverlayElement.module.scss.js";
4
- import { useIFrameBridge } from "./useIFrameBridge.js";
5
- const PreviewOverlayElement = ({ element }) => {
6
- const iFrameBridge = useIFrameBridge();
7
- const isSelected = element.adminRoute === iFrameBridge.selectedAdminRoute;
8
- const isHovered = element.adminRoute === iFrameBridge.hoveredAdminRoute;
9
- return /* @__PURE__ */ jsx(
10
- "div",
11
- {
12
- className: clsx(
13
- styles.root,
14
- iFrameBridge.showOutlines && !isHovered && styles.showBlockOutlines,
15
- isSelected && styles.blockIsSelected,
16
- isHovered && styles.isHoveredInBlockList
17
- ),
18
- title: element.label,
19
- onClick: () => {
20
- iFrameBridge.sendSelectComponent(element.adminRoute);
21
- },
22
- onMouseEnter: () => {
23
- iFrameBridge.sendHoverComponent(element.adminRoute);
24
- },
25
- onMouseLeave: () => {
26
- iFrameBridge.sendHoverComponent(null);
27
- },
28
- style: element.position,
29
- children: /* @__PURE__ */ jsx("div", { className: styles.label, children: element.label })
30
- },
31
- element.adminRoute
32
- );
33
- };
34
- export {
35
- PreviewOverlayElement
36
- };
1
+ import{jsx as e}from"react/jsx-runtime";import o from"clsx";import t from"./PreviewOverlayElement.module.scss.js";import{useIFrameBridge as n}from"./useIFrameBridge.js";const s=({element:s})=>{const l=n(),i=s.adminRoute===l.selectedAdminRoute,m=s.adminRoute===l.hoveredAdminRoute;/* @__PURE__ */
2
+ return e("div",{className:o(t.root,l.showOutlines&&!m&&t.showBlockOutlines,i&&t.blockIsSelected,m&&t.isHoveredInBlockList),title:s.label,onClick:()=>{l.sendSelectComponent(s.adminRoute)},onMouseEnter:()=>{l.sendHoverComponent(s.adminRoute)},onMouseLeave:()=>{l.sendHoverComponent(null)},style:s.position,children:/* @__PURE__ */e("div",{className:t.label,children:s.label})},s.adminRoute)};export{s as PreviewOverlayElement};
@@ -1,20 +1 @@
1
- const root = "_root_1ya0k_1";
2
- const isHoveredInBlockList = "_isHoveredInBlockList_1ya0k_24";
3
- const showBlockOutlines = "_showBlockOutlines_1ya0k_32";
4
- const blockIsSelected = "_blockIsSelected_1ya0k_37";
5
- const label = "_label_1ya0k_40";
6
- const styles = {
7
- root,
8
- isHoveredInBlockList,
9
- showBlockOutlines,
10
- blockIsSelected,
11
- label
12
- };
13
- export {
14
- blockIsSelected,
15
- styles as default,
16
- isHoveredInBlockList,
17
- label,
18
- root,
19
- showBlockOutlines
20
- };
1
+ const e="_root_1ya0k_1",o="_isHoveredInBlockList_1ya0k_24",l="_showBlockOutlines_1ya0k_32",_="_blockIsSelected_1ya0k_37",s="_label_1ya0k_40",k={root:e,isHoveredInBlockList:o,showBlockOutlines:l,blockIsSelected:_,label:s};export{_ as blockIsSelected,k as default,o as isHoveredInBlockList,s as label,e as root,l as showBlockOutlines};
@@ -1,30 +1,2 @@
1
1
  "use client";
2
- import { useState, useEffect } from "react";
3
- import { createFetchInMemoryCache } from "../graphQLFetch/fetchInMemoryCache.js";
4
- import { createGraphQLFetch, createFetchWithDefaults, convertPreviewDataToHeaders } from "../graphQLFetch/graphQLFetch.js";
5
- import { useIFrameBridge } from "./useIFrameBridge.js";
6
- const cachingFetch = createFetchInMemoryCache(fetch);
7
- function useBlockPreviewFetch(apiUrl) {
8
- const { showOnlyVisible, graphQLApiUrl } = useIFrameBridge();
9
- const [graphQLFetch, setGraphQLFetch] = useState(
10
- () => apiUrl ? createBlockPreviewFetch(apiUrl, !showOnlyVisible) : void 0
11
- );
12
- useEffect(() => {
13
- if (graphQLApiUrl) {
14
- setGraphQLFetch(() => createBlockPreviewFetch(graphQLApiUrl, !showOnlyVisible));
15
- }
16
- }, [showOnlyVisible, graphQLApiUrl]);
17
- return {
18
- graphQLFetch,
19
- fetch: cachingFetch
20
- };
21
- }
22
- function createBlockPreviewFetch(graphqlApiUrl, includeInvisible) {
23
- return createGraphQLFetch(
24
- createFetchWithDefaults(cachingFetch, { headers: convertPreviewDataToHeaders({ includeInvisible }), credentials: "include" }),
25
- graphqlApiUrl
26
- );
27
- }
28
- export {
29
- useBlockPreviewFetch
30
- };
2
+ import{useState as r,useEffect as e}from"react";import{createFetchInMemoryCache as t}from"../graphQLFetch/fetchInMemoryCache.js";import{createGraphQLFetch as c,createFetchWithDefaults as i,convertPreviewDataToHeaders as o}from"../graphQLFetch/graphQLFetch.js";import{useIFrameBridge as h}from"./useIFrameBridge.js";const n=t(fetch);function p(t){const{showOnlyVisible:c,graphQLApiUrl:i}=h(),[o,p]=r(()=>t?s(t,!c):void 0);return e(()=>{i&&p(()=>s(i,!c))},[c,i]),{graphQLFetch:o,fetch:n}}function s(r,e){return c(i(n,{headers:o({includeInvisible:e}),credentials:"include"}),r)}export{p as useBlockPreviewFetch};
@@ -1,8 +1 @@
1
- import { useContext } from "react";
2
- import { IFrameBridgeContext } from "./IFrameBridge.js";
3
- function useIFrameBridge() {
4
- return useContext(IFrameBridgeContext);
5
- }
6
- export {
7
- useIFrameBridge
8
- };
1
+ import{useContext as r}from"react";import{IFrameBridgeContext as o}from"./IFrameBridge.js";function t(){return r(o)}export{t as useIFrameBridge};