@comet/site-nextjs 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 (85) hide show
  1. package/lib/blocks/DamVideoBlock.js +2 -13
  2. package/lib/blocks/InternalLinkBlock.js +2 -18
  3. package/lib/blocks/PixelImageBlock.d.ts.map +1 -1
  4. package/lib/blocks/PixelImageBlock.js +2 -69
  5. package/lib/blocks/PixelImageBlock.module.scss.js +1 -8
  6. package/lib/blocks/VimeoVideoBlock.js +2 -13
  7. package/lib/blocks/YouTubeVideoBlock.js +2 -13
  8. package/lib/blocks/factories/SeoBlock.js +5 -39
  9. package/lib/blocks/helpers/VideoPreviewImage.js +2 -9
  10. package/lib/graphQLFetch/graphQLFetch.js +1 -36
  11. package/lib/image/Image.d.ts.map +1 -1
  12. package/lib/image/Image.js +2 -10
  13. package/lib/index.d.ts +2 -5
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +1 -112
  16. package/lib/persistedQueries/webpackPersistedQueriesLoader.d.ts +2 -0
  17. package/lib/persistedQueries/webpackPersistedQueriesLoader.d.ts.map +1 -0
  18. package/lib/persistedQueries/webpackPersistedQueriesLoader.js +1 -0
  19. package/lib/server.d.ts +5 -0
  20. package/lib/server.d.ts.map +1 -0
  21. package/lib/server.js +1 -0
  22. package/lib/site-react/lib/blockLoader/blockLoader.js +1 -59
  23. package/lib/site-react/lib/blocks/DamFileDownloadLinkBlock.js +1 -27
  24. package/lib/site-react/lib/blocks/DamVideoBlock.js +3 -99
  25. package/lib/site-react/lib/blocks/DamVideoBlock.module.scss.js +1 -14
  26. package/lib/site-react/lib/blocks/EmailLinkBlock.js +1 -21
  27. package/lib/site-react/lib/blocks/ExternalLinkBlock.js +1 -47
  28. package/lib/site-react/lib/blocks/PhoneLinkBlock.js +1 -21
  29. package/lib/site-react/lib/blocks/SvgImageBlock.js +1 -30
  30. package/lib/site-react/lib/blocks/VimeoVideoBlock.js +2 -129
  31. package/lib/site-react/lib/blocks/VimeoVideoBlock.module.scss.js +1 -14
  32. package/lib/site-react/lib/blocks/YouTubeVideoBlock.js +2 -136
  33. package/lib/site-react/lib/blocks/YouTubeVideoBlock.module.scss.js +1 -14
  34. package/lib/site-react/lib/blocks/factories/BlocksBlock.js +1 -27
  35. package/lib/site-react/lib/blocks/factories/ListBlock.js +1 -13
  36. package/lib/site-react/lib/blocks/factories/OneOfBlock.js +1 -23
  37. package/lib/site-react/lib/blocks/factories/OptionalBlock.js +1 -10
  38. package/lib/site-react/lib/blocks/helpers/PlayPauseButton.js +1 -9
  39. package/lib/site-react/lib/blocks/helpers/PlayPauseButton.module.scss.js +1 -14
  40. package/lib/site-react/lib/blocks/helpers/RichTextBlockHelper.js +1 -7
  41. package/lib/site-react/lib/blocks/helpers/TipTapRichTextRenderer.js +1 -0
  42. package/lib/site-react/lib/blocks/helpers/VideoPreviewImage.js +2 -23
  43. package/lib/site-react/lib/blocks/helpers/VideoPreviewImage.module.scss.js +1 -17
  44. package/lib/site-react/lib/blocks/helpers/useIsElementInViewport.js +1 -21
  45. package/lib/site-react/lib/cookies/CookieApiContext.js +1 -18
  46. package/lib/site-react/lib/cookies/CookieSafe.js +1 -18
  47. package/lib/site-react/lib/cookies/useCookieBotCookieApi.js +1 -33
  48. package/lib/site-react/lib/cookies/useLocalStorageCookieApi.js +1 -40
  49. package/lib/site-react/lib/cookies/useOneTrustCookieApi.js +1 -45
  50. package/lib/site-react/lib/errorHandler/ErrorHandlerBoundary.js +1 -10
  51. package/lib/site-react/lib/errorHandler/ErrorHandlerBoundaryInternal.js +1 -26
  52. package/lib/site-react/lib/errorHandler/ErrorHandlerProvider.js +1 -20
  53. package/lib/site-react/lib/graphQLFetch/fetchInMemoryCache.js +1 -37
  54. package/lib/site-react/lib/graphQLFetch/graphQLFetch.js +1 -125
  55. package/lib/site-react/lib/iframebridge/IFrameBridge.js +3 -253
  56. package/lib/site-react/lib/iframebridge/IFrameBridge.module.scss.js +1 -8
  57. package/lib/site-react/lib/iframebridge/IFrameMessage.js +1 -21
  58. package/lib/site-react/lib/iframebridge/Preview.js +1 -56
  59. package/lib/site-react/lib/iframebridge/Preview.module.scss.js +1 -8
  60. package/lib/site-react/lib/iframebridge/PreviewOverlay.js +1 -28
  61. package/lib/site-react/lib/iframebridge/PreviewOverlay.module.scss.js +1 -8
  62. package/lib/site-react/lib/iframebridge/PreviewOverlayElement.js +1 -36
  63. package/lib/site-react/lib/iframebridge/PreviewOverlayElement.module.scss.js +1 -20
  64. package/lib/site-react/lib/iframebridge/useBlockPreviewFetch.js +1 -29
  65. package/lib/site-react/lib/iframebridge/useIFrameBridge.js +1 -8
  66. package/lib/site-react/lib/iframebridge/utils.js +1 -46
  67. package/lib/site-react/lib/iframebridge/withPreview.js +1 -33
  68. package/lib/site-react/lib/image/image.utils.js +1 -55
  69. package/lib/site-react/lib/jsonLd/JsonLd.js +1 -0
  70. package/lib/site-react/lib/persistedQueries/createPersistedQueryGraphQLFetch.js +1 -70
  71. package/lib/site-react/lib/persistedQueries/persistedQueryRoute.js +1 -100
  72. package/lib/site-react/lib/persistedQueries/webpackPersistedQueriesLoader.js +1 -51
  73. package/lib/site-react/lib/preview/BlockPreviewProvider.js +1 -32
  74. package/lib/site-react/lib/preview/PreviewContext.js +1 -9
  75. package/lib/site-react/lib/preview/usePreview.js +1 -41
  76. package/lib/site-react/lib/previewskeleton/PreviewSkeleton.js +4 -64
  77. package/lib/site-react/lib/previewskeleton/PreviewSkeleton.module.scss.js +1 -17
  78. package/lib/site-react/lib/sitePreview/iframebridge/SitePreviewIFrameMessage.js +1 -8
  79. package/lib/site-react/lib/sitePreview/iframebridge/sendSitePreviewIFrameMessage.js +1 -6
  80. package/lib/sitePreview/SitePreviewProvider.js +1 -40
  81. package/lib/sitePreview/appRouter/sitePreviewRoute.js +1 -27
  82. package/lib/sitePreview/pagesRouter/legacyPagesRouterSitePreviewApiHandler.js +1 -20
  83. package/lib/sitePreview/previewUtils.js +1 -54
  84. package/lib/style.css +1 -1
  85. package/package.json +15 -11
@@ -1,254 +1,4 @@
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 m}from"usehooks-ts";import l 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 g=c({hasBridge:!1,showOutlines:!1,showOnlyVisible:!1,sendSelectComponent:()=>{},sendHoverComponent:()=>{},sendMessage:()=>{},contentScope:void 0,contentScopeJwt:"",graphQLApiUrl:void 0,previewElementsData:[],removePreviewElement:()=>{},addPreviewElement:()=>{}}),b=({children:c})=>{const[b,E]=r(void 0),[y,O]=r(!1),[R,S]=r(void 0),[C,L]=r(null),[P,I]=r(!1),[T,M]=r(void 0),[k,A]=r(""),[J,V]=r(""),[j,x]=r([]),[B,F]=r([]),N=i(null),W=N.current?.offsetWidth,_=s(()=>{if(!W)return;const e=j.map(e=>{const t=v(e.element),o=w(t);if(o.left>W)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-W,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}}));F(t=>n(t,e)?t:e)},[j,W]);a(()=>{if(N.current){const e=new MutationObserver(()=>{_()}),t=new ResizeObserver(()=>{_()});return e.observe(N.current,{childList:!0,subtree:!0,attributes:!0}),t.observe(N.current),()=>{e.disconnect(),t.disconnect()}}},[_]),a(()=>(j.forEach(e=>{e.element.addEventListener(f,_)}),()=>{j.forEach(e=>{e.element.removeEventListener(f,_)})}),[j,_]);const H=s(e=>{window.parent.postMessage(JSON.stringify(e),"*")},[]),Q=m(()=>{I(!1)},2500),U=s(e=>{switch(e.cometType){case p.Block:E(e.data.block);break;case p.ShowOnlyVisible:O(e.data.showOnlyVisible);break;case p.SelectComponent:S(e.data.adminRoute.lastIndexOf("#")>0?e.data.adminRoute.substr(0,e.data.adminRoute.lastIndexOf("#")):e.data.adminRoute);break;case p.HoverComponent:L(e.data.adminRoute),I(!0),Q();break;case p.ContentScope:M(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:V(e.data.graphQLApiUrl)}},[Q]);a(()=>{if("undefined"==typeof window)return;const e=e=>{try{const t=JSON.parse(e.data);t.hasOwnProperty("cometType")&&U(t)}catch{}};return window.addEventListener("message",e,!1),H({cometType:h.Ready}),()=>{window.removeEventListener("message",e,!1)}},[U,H]);const D=s(e=>{x(t=>[...t,e])},[x]),z=s(e=>{x(t=>t.filter(t=>t.adminRoute!==e.adminRoute))},[x]),q=d(()=>({showOutlines:P,hasBridge:!0,block:b,showOnlyVisible:y,selectedAdminRoute:R,hoveredAdminRoute:C,sendSelectComponent:e=>{S(e),H({cometType:h.SelectComponent,data:{adminRoute:e}})},sendHoverComponent:e=>{H({cometType:h.HoverComponent,data:{route:e}})},sendMessage:H,contentScope:T,contentScopeJwt:k,graphQLApiUrl:J,previewElementsData:B,addPreviewElement:D,removePreviewElement:z}),[P,b,y,R,C,H,T,k,J,B,D,z]);return e(g.Provider,{value:q,children:/* @__PURE__ */t("div",{onMouseMove:()=>{I(!0),Q()},children:[
3
+ /* @__PURE__ */e(u,{}),
4
+ /* @__PURE__ */e("div",{ref:N,className:l.childrenWrapper,children:c})]})})};export{g as IFrameBridgeContext,b 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 i}from"react";import n 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 d=({adminRoute:d,children:c,label:u,enabledAutoScrolling:a=!0})=>{const{addPreviewElement:E,removePreviewElement:f,...v}=l(),T=d===v.selectedAdminRoute,h=d===v.hoveredAdminRoute,p=t(null);return i(()=>{const e=p.current?{label:u,adminRoute:d,element:p.current}:null;if(e)return E(e),()=>{f(e)}},[u,d,E,f]),i(()=>{const e=setTimeout(()=>{a&&(h||T)&&p.current?.firstElementChild&&(n(p.current.firstElementChild,{scrollMode:"if-needed",block:"center",inline:"nearest",behavior:"smooth"}),setTimeout(()=>{p.current?.dispatchEvent(new Event(m))},600))},500);return()=>{clearTimeout(e)}},[a,h,T]),v.hasBridge?/* @__PURE__ */e("div",{ref:p,className:o.previewElementContainer,[s]:"",children:c}):/* @__PURE__ */e(r,{children:c})};export{d 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 r}from"./PreviewOverlayElement.js";import{useIFrameBridge as i}from"./useIFrameBridge.js";let o="";const s=()=>{const s=i();let m=0;return s.previewElementsData.forEach(e=>{if(e.position.zIndex>1)return;const t=e.position.top+e.position.height;t>m&&(m=t)}),/* @__PURE__ */e("div",{className:t.root,style:{"--height":`${m}px`},children:s.previewElementsData.map((t,i)=>(t.adminRoute===s.selectedAdminRoute&&o!==t.adminRoute&&(o=t.adminRoute),/* @__PURE__ */e(r,{element:t},i)))})};export{s 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 @@
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(),r=s.adminRoute===l.selectedAdminRoute,i=s.adminRoute===l.hoveredAdminRoute;return e("div",{className:o(t.root,l.showOutlines&&!i&&t.showBlockOutlines,r&&t.blockIsSelected,i&&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",s="_blockIsSelected_1ya0k_37",a="_label_1ya0k_40",t={root:e,isHoveredInBlockList:o,showBlockOutlines:l,blockIsSelected:s,label:a};export{s as blockIsSelected,t as default,o as isHoveredInBlockList,a 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 e,useEffect as r}from"react";import{createFetchInMemoryCache as t}from"../graphQLFetch/fetchInMemoryCache.js";import{createGraphQLFetch as a,createFetchWithDefaults as c,convertPreviewDataToHeaders as h}from"../graphQLFetch/graphQLFetch.js";import{useIFrameBridge as s}from"./useIFrameBridge.js";const i=t(fetch);function o(t){const{showOnlyVisible:a,graphQLApiUrl:c}=s(),[h,o]=e(()=>t?n(t,!a):void 0);return r(()=>{c&&o(()=>n(c,!a))},[a,c]),{graphQLFetch:h,fetch:i}}function n(e,r){return a(c(i,{headers:h({includeInvisible:r}),credentials:"include"}),e)}export{o 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 e}from"./IFrameBridge.js";function t(){return r(e)}export{t as useIFrameBridge};
@@ -1,46 +1 @@
1
- const BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE = "data-comet-block-preview-container";
2
- const PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT = "comet-preview-element-scrolled-into-view";
3
- const getRecursiveChildrenOfPreviewElement = (rootElement) => {
4
- const previewElementChildNodes = [];
5
- rootElement.childNodes.forEach((childNode) => {
6
- if (!(childNode instanceof Element)) {
7
- return;
8
- }
9
- if (childNode.hasAttribute(BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE)) {
10
- previewElementChildNodes.push(...getRecursiveChildrenOfPreviewElement(childNode));
11
- } else {
12
- previewElementChildNodes.push(childNode);
13
- }
14
- });
15
- return previewElementChildNodes;
16
- };
17
- const getCombinedPositioningOfElements = (elements) => {
18
- const topPositions = [];
19
- const leftPositions = [];
20
- elements.forEach((element) => {
21
- const { top, left, bottom, right } = element.getBoundingClientRect();
22
- topPositions.push(top + window.scrollY);
23
- leftPositions.push(left + window.scrollX);
24
- });
25
- const highestTopPosition = Math.min(...topPositions);
26
- const highestLeftPosition = Math.min(...leftPositions);
27
- const widthValues = [];
28
- const heightValues = [];
29
- elements.forEach((element) => {
30
- const { right, bottom } = element.getBoundingClientRect();
31
- widthValues.push(right - highestLeftPosition);
32
- heightValues.push(bottom - highestTopPosition + window.scrollY);
33
- });
34
- return {
35
- top: highestTopPosition,
36
- left: highestLeftPosition,
37
- width: Math.max(...widthValues),
38
- height: Math.max(...heightValues)
39
- };
40
- };
41
- export {
42
- BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE,
43
- PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT,
44
- getCombinedPositioningOfElements,
45
- getRecursiveChildrenOfPreviewElement
46
- };
1
+ const t="data-comet-block-preview-container",e="comet-preview-element-scrolled-into-view",o=e=>{const n=[];return e.childNodes.forEach(e=>{e instanceof Element&&(e.hasAttribute(t)?n.push(...o(e)):n.push(e))}),n},n=t=>{const e=[],o=[];t.forEach(t=>{const{top:n,left:i,bottom:s,right:c}=t.getBoundingClientRect();e.push(n+window.scrollY),o.push(i+window.scrollX)});const n=Math.min(...e),i=Math.min(...o),s=[],c=[];return t.forEach(t=>{const{right:e,bottom:o}=t.getBoundingClientRect();s.push(e-i),c.push(o-n+window.scrollY)}),{top:n,left:i,width:Math.max(...s),height:Math.max(...c)}};export{t as BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE,e as PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT,n as getCombinedPositioningOfElements,o as getRecursiveChildrenOfPreviewElement};
@@ -1,34 +1,2 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { useContext, createContext } from "react";
4
- import { Preview } from "./Preview.js";
5
- function isWithPreviewPropsData(block) {
6
- return block.adminMeta !== void 0;
7
- }
8
- const AdminRouteContext = createContext({
9
- parentRoute: "",
10
- parentEnabledAutoScrolling: true
11
- });
12
- const withPreview = (Component, { label = "No type", enabledChildrenAutoScrolling = true }) => {
13
- return ({ ...componentProps }) => {
14
- var _a, _b, _c, _d;
15
- const { parentRoute, parentEnabledAutoScrolling } = useContext(AdminRouteContext);
16
- if (((_a = componentProps.data) == null ? void 0 : _a.adminMeta) && ((_b = componentProps.data) == null ? void 0 : _b.adminMeta.route) !== parentRoute) {
17
- return /* @__PURE__ */ jsx(
18
- AdminRouteContext.Provider,
19
- {
20
- value: {
21
- parentRoute: (_c = componentProps.data) == null ? void 0 : _c.adminMeta.route,
22
- parentEnabledAutoScrolling: !parentEnabledAutoScrolling ? false : enabledChildrenAutoScrolling
23
- },
24
- children: /* @__PURE__ */ jsx(Preview, { adminRoute: (_d = componentProps.data) == null ? void 0 : _d.adminMeta.route, label, enabledAutoScrolling: parentEnabledAutoScrolling, children: /* @__PURE__ */ jsx(Component, { ...componentProps }) })
25
- }
26
- );
27
- }
28
- return /* @__PURE__ */ jsx(Component, { ...componentProps });
29
- };
30
- };
31
- export {
32
- isWithPreviewPropsData,
33
- withPreview
34
- };
2
+ import{jsx as e}from"react/jsx-runtime";import{useContext as t,createContext as a}from"react";import{Preview as r}from"./Preview.js";function n(e){return void 0!==e.adminMeta}const o=a({parentRoute:"",parentEnabledAutoScrolling:!0}),i=(a,{label:n="No type",enabledChildrenAutoScrolling:i=!0})=>({...l})=>{const{parentRoute:d,parentEnabledAutoScrolling:u}=t(o);return l.data?.adminMeta&&l.data?.adminMeta.route!==d?/* @__PURE__ */e(o.Provider,{value:{parentRoute:l.data?.adminMeta.route,parentEnabledAutoScrolling:!!u&&i},children:/* @__PURE__ */e(r,{adminRoute:l.data?.adminMeta.route,label:n,enabledAutoScrolling:u,children:/* @__PURE__ */e(a,{...l})})}):/* @__PURE__ */e(a,{...l})};export{n as isWithPreviewPropsData,i as withPreview};
@@ -1,55 +1 @@
1
- function parseAspectRatio(value) {
2
- let width, height;
3
- if (typeof value === "string") {
4
- [width, height] = value.split(/[x/:]/).map((v) => {
5
- let ret = parseFloat(v);
6
- if (isNaN(ret)) {
7
- ret = void 0;
8
- }
9
- return ret;
10
- });
11
- if (width && !height) {
12
- height = 1;
13
- }
14
- } else {
15
- width = value;
16
- height = 1;
17
- }
18
- if (!width || !height) {
19
- throw Error(`An error occurred while parsing the aspect ratio: ${value}`);
20
- }
21
- return width / height;
22
- }
23
- function getMaxDimensionsFromArea(area, aspectRatio) {
24
- let width, height;
25
- if (aspectRatio < 1) {
26
- width = Math.min(area.height * aspectRatio, area.width);
27
- height = width / aspectRatio;
28
- } else {
29
- height = Math.min(area.width / aspectRatio, area.height);
30
- width = height * aspectRatio;
31
- }
32
- return {
33
- width,
34
- height
35
- };
36
- }
37
- function calculateInheritAspectRatio(imageDimensions, cropArea) {
38
- if (cropArea.focalPoint === "SMART") {
39
- return imageDimensions.width / imageDimensions.height;
40
- } else {
41
- if (cropArea.width === void 0 || cropArea.height === void 0) {
42
- throw new Error("Missing crop dimensions");
43
- }
44
- return cropArea.width * imageDimensions.width / 100 / (cropArea.height * imageDimensions.height / 100);
45
- }
46
- }
47
- function generateImageUrl({ src, width }, aspectRatio) {
48
- return src.replace("$resizeWidth", String(width)).replace("$resizeHeight", String(Math.ceil(width / aspectRatio)));
49
- }
50
- export {
51
- calculateInheritAspectRatio,
52
- generateImageUrl,
53
- getMaxDimensionsFromArea,
54
- parseAspectRatio
55
- };
1
+ function t(t){let i,e;if("string"==typeof t?([i,e]=t.split(/[x/:]/).map(t=>{let i=parseFloat(t);return isNaN(i)&&(i=void 0),i}),i&&!e&&(e=1)):(i=t,e=1),!i||!e)throw Error(`An error occurred while parsing the aspect ratio: ${t}`);return i/e}function i(t,i){let e,r;return i<1?(e=Math.min(t.height*i,t.width),r=e/i):(r=Math.min(t.width/i,t.height),e=r*i),{width:e,height:r}}function e(t,i){if("SMART"===i.focalPoint)return t.width/t.height;if(void 0===i.width||void 0===i.height)throw new Error("Missing crop dimensions");return i.width*t.width/100/(i.height*t.height/100)}function r({src:t,width:i},e){return t.replace("$resizeWidth",String(i)).replace("$resizeHeight",String(Math.ceil(i/e)))}export{e as calculateInheritAspectRatio,r as generateImageUrl,i as getMaxDimensionsFromArea,t as parseAspectRatio};
@@ -0,0 +1 @@
1
+ import{jsx as r}from"react/jsx-runtime";const t=({data:t})=>{return r("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:(e=JSON.stringify(t),e.replace(/</g,"\\u003c"))}});var e};export{t as JsonLd};