@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.
- package/lib/blockLoader/blockLoader.js +1 -59
- package/lib/blocks/DamFileDownloadLinkBlock.js +1 -27
- package/lib/blocks/DamVideoBlock.js +5 -99
- package/lib/blocks/DamVideoBlock.module.scss.js +1 -14
- package/lib/blocks/EmailLinkBlock.js +1 -21
- package/lib/blocks/ExternalLinkBlock.js +1 -47
- package/lib/blocks/PhoneLinkBlock.js +1 -21
- package/lib/blocks/SvgImageBlock.js +1 -30
- package/lib/blocks/VimeoVideoBlock.js +4 -129
- package/lib/blocks/VimeoVideoBlock.module.scss.js +1 -14
- package/lib/blocks/YouTubeVideoBlock.js +4 -136
- package/lib/blocks/YouTubeVideoBlock.module.scss.js +1 -14
- package/lib/blocks/factories/BlocksBlock.js +1 -27
- package/lib/blocks/factories/ListBlock.js +1 -13
- package/lib/blocks/factories/OneOfBlock.js +1 -23
- package/lib/blocks/factories/OptionalBlock.js +1 -10
- package/lib/blocks/helpers/PlayPauseButton.js +1 -9
- package/lib/blocks/helpers/PlayPauseButton.module.scss.js +1 -14
- package/lib/blocks/helpers/RichTextBlockHelper.js +1 -7
- package/lib/blocks/helpers/TipTapRichTextRenderer.d.ts +35 -0
- package/lib/blocks/helpers/TipTapRichTextRenderer.d.ts.map +1 -0
- package/lib/blocks/helpers/TipTapRichTextRenderer.js +3 -0
- package/lib/blocks/helpers/VideoPreviewImage.js +2 -23
- package/lib/blocks/helpers/VideoPreviewImage.module.scss.js +1 -17
- package/lib/blocks/helpers/useIsElementInViewport.js +1 -21
- package/lib/cookies/CookieApiContext.js +2 -18
- package/lib/cookies/CookieSafe.js +2 -18
- package/lib/cookies/useCookieBotCookieApi.js +1 -33
- package/lib/cookies/useLocalStorageCookieApi.js +1 -40
- package/lib/cookies/useOneTrustCookieApi.js +1 -45
- package/lib/errorHandler/ErrorHandlerBoundary.js +2 -10
- package/lib/errorHandler/ErrorHandlerBoundaryInternal.js +1 -26
- package/lib/errorHandler/ErrorHandlerProvider.js +2 -20
- package/lib/graphQLFetch/fetchInMemoryCache.js +1 -37
- package/lib/graphQLFetch/graphQLFetch.js +1 -125
- package/lib/iframebridge/IFrameBridge.js +4 -253
- package/lib/iframebridge/IFrameBridge.module.scss.js +1 -8
- package/lib/iframebridge/IFrameMessage.js +1 -21
- package/lib/iframebridge/Preview.js +1 -56
- package/lib/iframebridge/Preview.module.scss.js +1 -8
- package/lib/iframebridge/PreviewOverlay.js +1 -28
- package/lib/iframebridge/PreviewOverlay.module.scss.js +1 -8
- package/lib/iframebridge/PreviewOverlayElement.js +2 -36
- package/lib/iframebridge/PreviewOverlayElement.module.scss.js +1 -20
- package/lib/iframebridge/useBlockPreviewFetch.js +1 -29
- package/lib/iframebridge/useIFrameBridge.js +1 -8
- package/lib/iframebridge/utils.js +1 -46
- package/lib/iframebridge/withPreview.js +1 -33
- package/lib/image/Image.js +2 -10
- package/lib/image/image.utils.js +1 -55
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -96
- package/lib/jsonLd/JsonLd.d.ts +7 -0
- package/lib/jsonLd/JsonLd.d.ts.map +1 -0
- package/lib/jsonLd/JsonLd.js +1 -0
- package/lib/persistedQueries/createPersistedQueryGraphQLFetch.js +1 -70
- package/lib/persistedQueries/persistedQueryRoute.js +1 -100
- package/lib/persistedQueries/webpackPersistedQueriesLoader.js +1 -51
- package/lib/preview/BlockPreviewProvider.js +1 -32
- package/lib/preview/PreviewContext.js +1 -9
- package/lib/preview/usePreview.js +1 -41
- package/lib/previewskeleton/PreviewSkeleton.js +8 -64
- package/lib/previewskeleton/PreviewSkeleton.module.scss.js +1 -17
- package/lib/server.d.ts +2 -0
- package/lib/server.d.ts.map +1 -0
- package/lib/server.js +1 -0
- package/lib/sitePreview/iframebridge/SitePreviewIFrameMessage.js +1 -8
- package/lib/sitePreview/iframebridge/sendSitePreviewIFrameMessage.js +1 -6
- package/lib/style.css +1 -1
- package/package.json +15 -8
|
@@ -1,46 +1 @@
|
|
|
1
|
-
const
|
|
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",o="comet-preview-element-scrolled-into-view",e=o=>{const n=[];return o.childNodes.forEach(o=>{o instanceof Element&&(o.hasAttribute(t)?n.push(...e(o)):n.push(o))}),n},n=t=>{const o=[],e=[];t.forEach(t=>{const{top:n,left:c,bottom:i,right:h}=t.getBoundingClientRect();o.push(n+window.scrollY),e.push(c+window.scrollX)});const n=Math.min(...o),c=Math.min(...e),i=[],h=[];return t.forEach(t=>{const{right:o,bottom:e}=t.getBoundingClientRect();i.push(o-c),h.push(e-n+window.scrollY)}),{top:n,left:c,width:Math.max(...i),height:Math.max(...h)}};export{t as BLOCK_PREVIEW_CONTAINER_DATA_ATTRIBUTE,o as PREVIEW_ELEMENT_SCROLLED_INTO_VIEW_EVENT,n as getCombinedPositioningOfElements,e as getRecursiveChildrenOfPreviewElement};
|
|
@@ -1,34 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
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}),l=(a,{label:n="No type",enabledChildrenAutoScrolling:l=!0})=>({...i})=>{const{parentRoute:d,parentEnabledAutoScrolling:u}=t(o);return i.data?.adminMeta&&i.data?.adminMeta.route!==d?/* @__PURE__ */e(o.Provider,{value:{parentRoute:i.data?.adminMeta.route,parentEnabledAutoScrolling:!!u&&l},children:/* @__PURE__ */e(r,{adminRoute:i.data?.adminMeta.route,label:n,enabledAutoScrolling:u,children:/* @__PURE__ */e(a,{...i})})}):/* @__PURE__ */e(a,{...i})};export{n as isWithPreviewPropsData,l as withPreview};
|
package/lib/image/Image.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function Image({ aspectRatio, src, width, ...imgProps }) {
|
|
4
|
-
const usedAspectRatio = parseAspectRatio(aspectRatio);
|
|
5
|
-
const imageUrl = generateImageUrl({ src, width: Number(width) }, usedAspectRatio);
|
|
6
|
-
return /* @__PURE__ */ jsx("img", { src: imageUrl, ...imgProps });
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
Image
|
|
10
|
-
};
|
|
1
|
+
import{jsx as r}from"react/jsx-runtime";import{parseAspectRatio as t,generateImageUrl as i}from"./image.utils.js";function m({aspectRatio:m,src:o,width:s,...c}){const e=t(m),n=i({src:o,width:Number(s)},e);/* @__PURE__ */
|
|
2
|
+
return r("img",{src:n,...c})}export{m as Image};
|
package/lib/image/image.utils.js
CHANGED
|
@@ -1,55 +1 @@
|
|
|
1
|
-
function
|
|
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,r;if("string"==typeof t?([i,r]=t.split(/[x/:]/).map(t=>{let i=parseFloat(t);return isNaN(i)&&(i=void 0),i}),i&&!r&&(r=1)):(i=t,r=1),!i||!r)throw Error(`An error occurred while parsing the aspect ratio: ${t}`);return i/r}function i(t,i){let r,e;return i<1?(r=Math.min(t.height*i,t.width),e=r/i):(e=Math.min(t.width/i,t.height),r=e*i),{width:r,height:e}}function r(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 e({src:t,width:i},r){return t.replace("$resizeWidth",String(i)).replace("$resizeHeight",String(Math.ceil(i/r)))}export{r as calculateInheritAspectRatio,e as generateImageUrl,i as getMaxDimensionsFromArea,t as parseAspectRatio};
|
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { OptionalBlock } from './blocks/factories/OptionalBlock';
|
|
|
10
10
|
export type { SupportedBlocks } from './blocks/factories/types';
|
|
11
11
|
export { type PlayPauseButtonProps } from './blocks/helpers/PlayPauseButton';
|
|
12
12
|
export { hasRichTextBlockContent } from './blocks/helpers/RichTextBlockHelper';
|
|
13
|
+
export { hasTipTapRichTextContent, renderTipTapRichText, type RenderTipTapRichTextOptions, type TipTapMark, type TipTapMarkHandler, type TipTapMarkHandlerProps, type TipTapNode, type TipTapNodeHandler, type TipTapNodeHandlerProps, } from './blocks/helpers/TipTapRichTextRenderer';
|
|
13
14
|
export { useIsElementInViewport } from './blocks/helpers/useIsElementInViewport';
|
|
14
15
|
export type { VideoPreviewImageProps } from './blocks/helpers/VideoPreviewImage';
|
|
15
16
|
export { VideoPreviewImage } from './blocks/helpers/VideoPreviewImage';
|
|
@@ -35,9 +36,8 @@ export { useIFrameBridge } from './iframebridge/useIFrameBridge';
|
|
|
35
36
|
export { isWithPreviewPropsData, withPreview, type WithPreviewProps } from './iframebridge/withPreview';
|
|
36
37
|
export { Image } from './image/Image';
|
|
37
38
|
export { calculateInheritAspectRatio, generateImageUrl, getMaxDimensionsFromArea, type ImageDimensions, parseAspectRatio } from './image/image.utils';
|
|
39
|
+
export { JsonLd, type JsonLdProps } from './jsonLd/JsonLd';
|
|
38
40
|
export { createPersistedQueryGraphQLFetch } from './persistedQueries/createPersistedQueryGraphQLFetch';
|
|
39
|
-
export { persistedQueryRoute } from './persistedQueries/persistedQueryRoute';
|
|
40
|
-
export { default as webpackPersistedQueriesLoader } from './persistedQueries/webpackPersistedQueriesLoader';
|
|
41
41
|
export { BlockPreviewProvider } from './preview/BlockPreviewProvider';
|
|
42
42
|
export { PreviewContext } from './preview/PreviewContext';
|
|
43
43
|
export { usePreview } from './preview/usePreview';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAA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B,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACxG,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,KAAK,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtJ,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,qDAAqD,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yDAAyD,CAAC;AACvG,OAAO,EAAE,KAAK,gCAAgC,EAAE,4BAA4B,EAAE,MAAM,qDAAqD,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,96 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DamFileDownloadLinkBlock } from "./blocks/DamFileDownloadLinkBlock.js";
|
|
3
|
-
import { DamVideoBlock } from "./blocks/DamVideoBlock.js";
|
|
4
|
-
import { EmailLinkBlock } from "./blocks/EmailLinkBlock.js";
|
|
5
|
-
import { ExternalLinkBlock } from "./blocks/ExternalLinkBlock.js";
|
|
6
|
-
import { BlocksBlock } from "./blocks/factories/BlocksBlock.js";
|
|
7
|
-
import { ListBlock } from "./blocks/factories/ListBlock.js";
|
|
8
|
-
import { OneOfBlock } from "./blocks/factories/OneOfBlock.js";
|
|
9
|
-
import { OptionalBlock } from "./blocks/factories/OptionalBlock.js";
|
|
10
|
-
import { hasRichTextBlockContent } from "./blocks/helpers/RichTextBlockHelper.js";
|
|
11
|
-
import { useIsElementInViewport } from "./blocks/helpers/useIsElementInViewport.js";
|
|
12
|
-
import { VideoPreviewImage } from "./blocks/helpers/VideoPreviewImage.js";
|
|
13
|
-
import { PhoneLinkBlock } from "./blocks/PhoneLinkBlock.js";
|
|
14
|
-
import { SvgImageBlock } from "./blocks/SvgImageBlock.js";
|
|
15
|
-
import { VimeoVideoBlock } from "./blocks/VimeoVideoBlock.js";
|
|
16
|
-
import { YouTubeVideoBlock } from "./blocks/YouTubeVideoBlock.js";
|
|
17
|
-
import { CookieApiProvider, useCookieApi } from "./cookies/CookieApiContext.js";
|
|
18
|
-
import { CookieSafe } from "./cookies/CookieSafe.js";
|
|
19
|
-
import { useCookieBotCookieApi } from "./cookies/useCookieBotCookieApi.js";
|
|
20
|
-
import { useLocalStorageCookieApi } from "./cookies/useLocalStorageCookieApi.js";
|
|
21
|
-
import { useOneTrustCookieApi } from "./cookies/useOneTrustCookieApi.js";
|
|
22
|
-
import { ErrorHandlerBoundary } from "./errorHandler/ErrorHandlerBoundary.js";
|
|
23
|
-
import { ErrorHandlerProvider } from "./errorHandler/ErrorHandlerProvider.js";
|
|
24
|
-
import { createFetchInMemoryCache } from "./graphQLFetch/fetchInMemoryCache.js";
|
|
25
|
-
import { convertPreviewDataToHeaders, createFetchWithDefaults, createFetchWithPreviewHeaders, createGraphQLFetch, gql } from "./graphQLFetch/graphQLFetch.js";
|
|
26
|
-
import { IFrameBridgeProvider } from "./iframebridge/IFrameBridge.js";
|
|
27
|
-
import { AdminMessageType, IFrameMessageType } from "./iframebridge/IFrameMessage.js";
|
|
28
|
-
import { Preview } from "./iframebridge/Preview.js";
|
|
29
|
-
import { useBlockPreviewFetch } from "./iframebridge/useBlockPreviewFetch.js";
|
|
30
|
-
import { useIFrameBridge } from "./iframebridge/useIFrameBridge.js";
|
|
31
|
-
import { isWithPreviewPropsData, withPreview } from "./iframebridge/withPreview.js";
|
|
32
|
-
import { Image } from "./image/Image.js";
|
|
33
|
-
import { calculateInheritAspectRatio, generateImageUrl, getMaxDimensionsFromArea, parseAspectRatio } from "./image/image.utils.js";
|
|
34
|
-
import { createPersistedQueryGraphQLFetch } from "./persistedQueries/createPersistedQueryGraphQLFetch.js";
|
|
35
|
-
import { persistedQueryRoute } from "./persistedQueries/persistedQueryRoute.js";
|
|
36
|
-
import { default as default2 } from "./persistedQueries/webpackPersistedQueriesLoader.js";
|
|
37
|
-
import { BlockPreviewProvider } from "./preview/BlockPreviewProvider.js";
|
|
38
|
-
import { PreviewContext } from "./preview/PreviewContext.js";
|
|
39
|
-
import { usePreview } from "./preview/usePreview.js";
|
|
40
|
-
import { PreviewSkeleton } from "./previewskeleton/PreviewSkeleton.js";
|
|
41
|
-
import { sendSitePreviewIFrameMessage } from "./sitePreview/iframebridge/sendSitePreviewIFrameMessage.js";
|
|
42
|
-
import { SitePreviewIFrameMessageType } from "./sitePreview/iframebridge/SitePreviewIFrameMessage.js";
|
|
43
|
-
export {
|
|
44
|
-
AdminMessageType,
|
|
45
|
-
BlockPreviewProvider,
|
|
46
|
-
BlocksBlock,
|
|
47
|
-
CookieApiProvider,
|
|
48
|
-
CookieSafe,
|
|
49
|
-
DamFileDownloadLinkBlock,
|
|
50
|
-
DamVideoBlock,
|
|
51
|
-
EmailLinkBlock,
|
|
52
|
-
ErrorHandlerBoundary,
|
|
53
|
-
ErrorHandlerProvider,
|
|
54
|
-
ExternalLinkBlock,
|
|
55
|
-
IFrameBridgeProvider,
|
|
56
|
-
IFrameMessageType,
|
|
57
|
-
Image,
|
|
58
|
-
ListBlock,
|
|
59
|
-
OneOfBlock,
|
|
60
|
-
OptionalBlock,
|
|
61
|
-
PhoneLinkBlock,
|
|
62
|
-
Preview,
|
|
63
|
-
PreviewContext,
|
|
64
|
-
PreviewSkeleton,
|
|
65
|
-
SitePreviewIFrameMessageType,
|
|
66
|
-
SvgImageBlock,
|
|
67
|
-
VideoPreviewImage,
|
|
68
|
-
VimeoVideoBlock,
|
|
69
|
-
YouTubeVideoBlock,
|
|
70
|
-
calculateInheritAspectRatio,
|
|
71
|
-
convertPreviewDataToHeaders,
|
|
72
|
-
createFetchInMemoryCache,
|
|
73
|
-
createFetchWithDefaults,
|
|
74
|
-
createFetchWithPreviewHeaders,
|
|
75
|
-
createGraphQLFetch,
|
|
76
|
-
createPersistedQueryGraphQLFetch,
|
|
77
|
-
generateImageUrl,
|
|
78
|
-
getMaxDimensionsFromArea,
|
|
79
|
-
gql,
|
|
80
|
-
hasRichTextBlockContent,
|
|
81
|
-
isWithPreviewPropsData,
|
|
82
|
-
parseAspectRatio,
|
|
83
|
-
persistedQueryRoute,
|
|
84
|
-
recursivelyLoadBlockData,
|
|
85
|
-
sendSitePreviewIFrameMessage,
|
|
86
|
-
useBlockPreviewFetch,
|
|
87
|
-
useCookieApi,
|
|
88
|
-
useCookieBotCookieApi,
|
|
89
|
-
useIFrameBridge,
|
|
90
|
-
useIsElementInViewport,
|
|
91
|
-
useLocalStorageCookieApi,
|
|
92
|
-
useOneTrustCookieApi,
|
|
93
|
-
usePreview,
|
|
94
|
-
default2 as webpackPersistedQueriesLoader,
|
|
95
|
-
withPreview
|
|
96
|
-
};
|
|
1
|
+
import{recursivelyLoadBlockData as o}from"./blockLoader/blockLoader.js";import{DamFileDownloadLinkBlock as r}from"./blocks/DamFileDownloadLinkBlock.js";import{DamVideoBlock as e}from"./blocks/DamVideoBlock.js";import{EmailLinkBlock as i}from"./blocks/EmailLinkBlock.js";import{ExternalLinkBlock as m}from"./blocks/ExternalLinkBlock.js";import{BlocksBlock as s}from"./blocks/factories/BlocksBlock.js";import{ListBlock as t}from"./blocks/factories/ListBlock.js";import{OneOfBlock as p}from"./blocks/factories/OneOfBlock.js";import{OptionalBlock as f}from"./blocks/factories/OptionalBlock.js";import{hasRichTextBlockContent as c}from"./blocks/helpers/RichTextBlockHelper.js";import{hasTipTapRichTextContent as l,renderTipTapRichText as k}from"./blocks/helpers/TipTapRichTextRenderer.js";import{useIsElementInViewport as a}from"./blocks/helpers/useIsElementInViewport.js";import{VideoPreviewImage as j}from"./blocks/helpers/VideoPreviewImage.js";import{PhoneLinkBlock as d}from"./blocks/PhoneLinkBlock.js";import{SvgImageBlock as b}from"./blocks/SvgImageBlock.js";import{VimeoVideoBlock as n}from"./blocks/VimeoVideoBlock.js";import{YouTubeVideoBlock as g}from"./blocks/YouTubeVideoBlock.js";import{CookieApiProvider as B,useCookieApi as h}from"./cookies/CookieApiContext.js";import{CookieSafe as v}from"./cookies/CookieSafe.js";import{useCookieBotCookieApi as w}from"./cookies/useCookieBotCookieApi.js";import{useLocalStorageCookieApi as P}from"./cookies/useLocalStorageCookieApi.js";import{useOneTrustCookieApi as u}from"./cookies/useOneTrustCookieApi.js";import{ErrorHandlerBoundary as L}from"./errorHandler/ErrorHandlerBoundary.js";import{ErrorHandlerProvider as F}from"./errorHandler/ErrorHandlerProvider.js";import{createFetchInMemoryCache as I}from"./graphQLFetch/fetchInMemoryCache.js";import{convertPreviewDataToHeaders as C,createFetchWithDefaults as x,createFetchWithPreviewHeaders as Q,createGraphQLFetch as S,gql as T}from"./graphQLFetch/graphQLFetch.js";import{IFrameBridgeProvider as V}from"./iframebridge/IFrameBridge.js";import{AdminMessageType as E,IFrameMessageType as H}from"./iframebridge/IFrameMessage.js";import{Preview as A}from"./iframebridge/Preview.js";import{useBlockPreviewFetch as M}from"./iframebridge/useBlockPreviewFetch.js";import{useIFrameBridge as O}from"./iframebridge/useIFrameBridge.js";import{isWithPreviewPropsData as y,withPreview as D}from"./iframebridge/withPreview.js";import{Image as R}from"./image/Image.js";import{calculateInheritAspectRatio as G,generateImageUrl as J,getMaxDimensionsFromArea as Y,parseAspectRatio as q}from"./image/image.utils.js";import{JsonLd as z}from"./jsonLd/JsonLd.js";import{createPersistedQueryGraphQLFetch as K}from"./persistedQueries/createPersistedQueryGraphQLFetch.js";import{BlockPreviewProvider as N}from"./preview/BlockPreviewProvider.js";import{PreviewContext as U}from"./preview/PreviewContext.js";import{usePreview as W}from"./preview/usePreview.js";import{PreviewSkeleton as X}from"./previewskeleton/PreviewSkeleton.js";import{sendSitePreviewIFrameMessage as Z}from"./sitePreview/iframebridge/sendSitePreviewIFrameMessage.js";import{SitePreviewIFrameMessageType as $}from"./sitePreview/iframebridge/SitePreviewIFrameMessage.js";export{E as AdminMessageType,N as BlockPreviewProvider,s as BlocksBlock,B as CookieApiProvider,v as CookieSafe,r as DamFileDownloadLinkBlock,e as DamVideoBlock,i as EmailLinkBlock,L as ErrorHandlerBoundary,F as ErrorHandlerProvider,m as ExternalLinkBlock,V as IFrameBridgeProvider,H as IFrameMessageType,R as Image,z as JsonLd,t as ListBlock,p as OneOfBlock,f as OptionalBlock,d as PhoneLinkBlock,A as Preview,U as PreviewContext,X as PreviewSkeleton,$ as SitePreviewIFrameMessageType,b as SvgImageBlock,j as VideoPreviewImage,n as VimeoVideoBlock,g as YouTubeVideoBlock,G as calculateInheritAspectRatio,C as convertPreviewDataToHeaders,I as createFetchInMemoryCache,x as createFetchWithDefaults,Q as createFetchWithPreviewHeaders,S as createGraphQLFetch,K as createPersistedQueryGraphQLFetch,J as generateImageUrl,Y as getMaxDimensionsFromArea,T as gql,c as hasRichTextBlockContent,l as hasTipTapRichTextContent,y as isWithPreviewPropsData,q as parseAspectRatio,o as recursivelyLoadBlockData,k as renderTipTapRichText,Z as sendSitePreviewIFrameMessage,M as useBlockPreviewFetch,h as useCookieApi,w as useCookieBotCookieApi,O as useIFrameBridge,a as useIsElementInViewport,P as useLocalStorageCookieApi,u as useOneTrustCookieApi,W as usePreview,D as withPreview};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JSX } from 'react';
|
|
2
|
+
import { Thing, WithContext } from 'schema-dts';
|
|
3
|
+
export type JsonLdProps<T extends Thing> = {
|
|
4
|
+
data: WithContext<T>;
|
|
5
|
+
};
|
|
6
|
+
export declare const JsonLd: <T extends Thing>({ data }: JsonLdProps<T>) => JSX.Element;
|
|
7
|
+
//# sourceMappingURL=JsonLd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonLd.d.ts","sourceRoot":"","sources":["../../src/jsonLd/JsonLd.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,KAAK,IAAI;IACvC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACxB,CAAC;AAOF,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,KAAK,EAAE,UAAU,WAAW,CAAC,CAAC,CAAC,KAAG,GAAG,CAAC,OAEtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as r}from"react/jsx-runtime";const t=({data:t})=>{/* @__PURE__ */return r("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:(e=JSON.stringify(t),e.replace(/</g,"\\u003c"))}});var e};export{t as JsonLd};
|
|
@@ -1,70 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
return async function(query, variables, init) {
|
|
3
|
-
if (typeof query === "string") {
|
|
4
|
-
throw new Error("at runtime only hashed queries are supported");
|
|
5
|
-
}
|
|
6
|
-
const hash = query.hash;
|
|
7
|
-
let response;
|
|
8
|
-
if ((init == null ? void 0 : init.method) === "GET") {
|
|
9
|
-
const fetchUrl = new URL(url, window.location.origin);
|
|
10
|
-
fetchUrl.searchParams.append("extensions.persistedQuery.sha256Hash", hash);
|
|
11
|
-
fetchUrl.searchParams.append("variables", JSON.stringify(variables));
|
|
12
|
-
response = await fetch(fetchUrl, {
|
|
13
|
-
...init,
|
|
14
|
-
headers: {
|
|
15
|
-
/**
|
|
16
|
-
* It's recommended to add the `Apollo-Require-Preflight` header to GET requests, running on an Apollo Server 4.
|
|
17
|
-
*
|
|
18
|
-
* If this header is missing, Apollo Server 4 will return: This operation has been blocked as a potential Cross-Site Request Forgery (CSRF).
|
|
19
|
-
*
|
|
20
|
-
* see: https://www.apollographql.com/docs/graphos/routing/security/csrf#enable-csrf-prevention
|
|
21
|
-
*/
|
|
22
|
-
"Apollo-Require-Preflight": "true",
|
|
23
|
-
...init.headers
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
response = await fetch(url, {
|
|
28
|
-
method: "POST",
|
|
29
|
-
...init,
|
|
30
|
-
headers: { "Content-Type": "application/json", ...init == null ? void 0 : init.headers },
|
|
31
|
-
body: JSON.stringify({
|
|
32
|
-
extensions: {
|
|
33
|
-
persistedQuery: {
|
|
34
|
-
version: 1,
|
|
35
|
-
sha256Hash: hash
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
variables
|
|
39
|
-
})
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
let errorMessage = `Network response was not ok. Status: ${response.status}`;
|
|
44
|
-
const body = await response.text();
|
|
45
|
-
try {
|
|
46
|
-
const json = JSON.parse(body);
|
|
47
|
-
const { errors: errors2 } = json;
|
|
48
|
-
if (errors2) {
|
|
49
|
-
errorMessage += `
|
|
50
|
-
|
|
51
|
-
GraphQL error(s):
|
|
52
|
-
- ${errors2.map((error) => error.message).join("\n- ")}`;
|
|
53
|
-
}
|
|
54
|
-
} catch {
|
|
55
|
-
errorMessage += `
|
|
56
|
-
${body}`;
|
|
57
|
-
}
|
|
58
|
-
throw new Error(errorMessage);
|
|
59
|
-
}
|
|
60
|
-
const { data, errors } = await response.json();
|
|
61
|
-
if (errors) {
|
|
62
|
-
throw new Error(`GraphQL error(s):
|
|
63
|
-
- ${errors.map((error) => error.message).join("\n- ")}`);
|
|
64
|
-
}
|
|
65
|
-
return data;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
createPersistedQueryGraphQLFetch
|
|
70
|
-
};
|
|
1
|
+
function e(e,r){return async function(s,a,t){if("string"==typeof s)throw new Error("at runtime only hashed queries are supported");const n=s.hash;let o;if("GET"===t?.method){const s=new URL(r,window.location.origin);s.searchParams.append("extensions.persistedQuery.sha256Hash",n),s.searchParams.append("variables",JSON.stringify(a)),o=await e(s,{...t,headers:{"Apollo-Require-Preflight":"true",...t.headers}})}else o=await e(r,{method:"POST",...t,headers:{"Content-Type":"application/json",...t?.headers},body:JSON.stringify({extensions:{persistedQuery:{version:1,sha256Hash:n}},variables:a})});if(!o.ok){let e=`Network response was not ok. Status: ${o.status}`;const r=await o.text();try{const s=JSON.parse(r),{errors:a}=s;a&&(e+=`\n\nGraphQL error(s):\n- ${a.map(e=>e.message).join("\n- ")}`)}catch{e+=`\n${r}`}throw new Error(e)}const{data:i,errors:h}=await o.json();if(h)throw new Error(`GraphQL error(s):\n- ${h.map(e=>e.message).join("\n- ")}`);return i}}export{e as createPersistedQueryGraphQLFetch};
|
|
@@ -1,100 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
let queryMap;
|
|
3
|
-
let fragmentsMap;
|
|
4
|
-
async function loadPersistedQueries(path) {
|
|
5
|
-
const file = await readFile(path, { encoding: "utf-8" });
|
|
6
|
-
queryMap = JSON.parse(file.toString());
|
|
7
|
-
fragmentsMap = {};
|
|
8
|
-
for (const [, query] of Object.entries(queryMap)) {
|
|
9
|
-
const match = query.match(/^\s*fragment\s+(\w+)\s+on\s+\w+/m);
|
|
10
|
-
if (match) {
|
|
11
|
-
const fragmentName = match[1];
|
|
12
|
-
fragmentsMap[fragmentName] = query.replace(/\${.*?}/g, "");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function injectFragments(query) {
|
|
17
|
-
query = query.replace(/\${.*?}/g, "");
|
|
18
|
-
const injected = /* @__PURE__ */ new Set();
|
|
19
|
-
for (const m of query.matchAll(/^\s*fragment\s+(\w+)\s+on\s+\w+/gm)) {
|
|
20
|
-
injected.add(m[1]);
|
|
21
|
-
}
|
|
22
|
-
function inject(q) {
|
|
23
|
-
const spreads = Array.from(q.matchAll(/\.\.\.(\w+)/g)).map((m) => m[1]);
|
|
24
|
-
let result = q;
|
|
25
|
-
for (const fragmentName of spreads) {
|
|
26
|
-
if (!injected.has(fragmentName) && fragmentsMap[fragmentName]) {
|
|
27
|
-
injected.add(fragmentName);
|
|
28
|
-
result += `
|
|
29
|
-
${inject(fragmentsMap[fragmentName])}`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
query = inject(query);
|
|
35
|
-
return query;
|
|
36
|
-
}
|
|
37
|
-
async function persistedQueryRoute(req, {
|
|
38
|
-
graphqlTarget,
|
|
39
|
-
headers: headersInit,
|
|
40
|
-
persistedQueriesPath = ".persisted-queries.json",
|
|
41
|
-
cacheMaxAge
|
|
42
|
-
}) {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
if (!queryMap) {
|
|
45
|
-
await loadPersistedQueries(persistedQueriesPath);
|
|
46
|
-
}
|
|
47
|
-
let hash;
|
|
48
|
-
let variables;
|
|
49
|
-
if (req.method === "POST") {
|
|
50
|
-
const body = await req.json();
|
|
51
|
-
hash = (_b = (_a = body.extensions) == null ? void 0 : _a.persistedQuery) == null ? void 0 : _b.sha256Hash;
|
|
52
|
-
variables = body.variables;
|
|
53
|
-
} else if (req.method === "GET") {
|
|
54
|
-
const url = new URL(req.url);
|
|
55
|
-
hash = url.searchParams.get("extensions.persistedQuery.sha256Hash");
|
|
56
|
-
const variablesParam = url.searchParams.get("variables");
|
|
57
|
-
variables = variablesParam ? JSON.parse(variablesParam) : void 0;
|
|
58
|
-
} else {
|
|
59
|
-
return Response.json({ error: "MethodNotAllowed" }, { status: 405 });
|
|
60
|
-
}
|
|
61
|
-
if (!hash) {
|
|
62
|
-
return Response.json({ error: "OnlyPersistedQueriesAllowed" }, { status: 400 });
|
|
63
|
-
}
|
|
64
|
-
let query = queryMap[hash];
|
|
65
|
-
if (!query) {
|
|
66
|
-
return Response.json({ error: "PersistedQueryNotFound", hash }, { status: 400 });
|
|
67
|
-
}
|
|
68
|
-
query = injectFragments(query);
|
|
69
|
-
if (req.method === "GET") {
|
|
70
|
-
const apolloPreflight = req.headers.get("Apollo-Require-Preflight");
|
|
71
|
-
if (apolloPreflight !== "true") {
|
|
72
|
-
return Response.json({ error: "CSRFProtection", message: "Missing Apollo-Require-Preflight header" }, { status: 403 });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const headers = new Headers(headersInit);
|
|
76
|
-
headers.set("Content-Type", "application/json");
|
|
77
|
-
for (const header of ["x-include-invisible-content", "x-preview-dam-urls"]) {
|
|
78
|
-
const value = req.headers.get(header);
|
|
79
|
-
if (value !== null) {
|
|
80
|
-
headers.set(header, value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const upstreamRes = await fetch(graphqlTarget, {
|
|
84
|
-
method: "POST",
|
|
85
|
-
headers,
|
|
86
|
-
body: JSON.stringify({ query, variables })
|
|
87
|
-
});
|
|
88
|
-
const responseHeaders = {
|
|
89
|
-
"Content-Type": "application/json"
|
|
90
|
-
};
|
|
91
|
-
if (req.method === "GET" && upstreamRes.ok && cacheMaxAge !== void 0) {
|
|
92
|
-
responseHeaders["Cache-Control"] = `public, max-age=${cacheMaxAge}`;
|
|
93
|
-
}
|
|
94
|
-
return new Response(upstreamRes.body, {
|
|
95
|
-
headers: responseHeaders
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
export {
|
|
99
|
-
persistedQueryRoute
|
|
100
|
-
};
|
|
1
|
+
import{readFile as e}from"fs/promises";let s,t;async function r(r,{graphqlTarget:o,headers:n,persistedQueriesPath:a=".persisted-queries.json",cacheMaxAge:i}){let c,l;if(s||await async function(r){const o=await e(r,{encoding:"utf-8"});s=JSON.parse(o.toString()),t={};for(const[,e]of Object.entries(s)){const s=e.match(/^\s*fragment\s+(\w+)\s+on\s+\w+/m);if(s){const r=s[1];t[r]=e.replace(/\${.*?}/g,"")}}}(a),"POST"===r.method){const e=await r.json();c=e.extensions?.persistedQuery?.sha256Hash,l=e.variables}else{if("GET"!==r.method)return Response.json({error:"MethodNotAllowed"},{status:405});{const e=new URL(r.url);c=e.searchParams.get("extensions.persistedQuery.sha256Hash");const s=e.searchParams.get("variables");l=s?JSON.parse(s):void 0}}if(!c)return Response.json({error:"OnlyPersistedQueriesAllowed"},{status:400});let d=s[c];if(!d)return Response.json({error:"PersistedQueryNotFound",hash:c},{status:400});if(d=function(e){e=e.replace(/\${.*?}/g,"");const s=/* @__PURE__ */new Set;for(const t of e.matchAll(/^\s*fragment\s+(\w+)\s+on\s+\w+/gm))s.add(t[1]);return e=function e(r){const o=Array.from(r.matchAll(/\.\.\.(\w+)/g)).map(e=>e[1]);let n=r;for(const a of o)!s.has(a)&&t[a]&&(s.add(a),n+=`\n${e(t[a])}`);return n}(e),e}(d),"GET"===r.method){if("true"!==r.headers.get("Apollo-Require-Preflight"))return Response.json({error:"CSRFProtection",message:"Missing Apollo-Require-Preflight header"},{status:403})}const u=new Headers(n);u.set("Content-Type","application/json");for(const e of["x-include-invisible-content","x-preview-dam-urls"]){const s=r.headers.get(e);null!==s&&u.set(e,s)}const h=await fetch(o,{method:"POST",headers:u,body:JSON.stringify({query:d,variables:l})}),f={"Content-Type":"application/json"};return"GET"===r.method&&h.ok&&void 0!==i&&(f["Cache-Control"]=`public, max-age=${i}`),new Response(h.body,{headers:f})}export{r as persistedQueryRoute};
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
function loadHashMap(path) {
|
|
4
|
-
if (fs.existsSync(path)) {
|
|
5
|
-
return JSON.parse(fs.readFileSync(path, "utf-8"));
|
|
6
|
-
}
|
|
7
|
-
return {};
|
|
8
|
-
}
|
|
9
|
-
function saveHashMap(path, hashMap) {
|
|
10
|
-
fs.writeFileSync(path, JSON.stringify(hashMap, null, 2));
|
|
11
|
-
}
|
|
12
|
-
function hashQuery(query) {
|
|
13
|
-
return createHash("sha256").update(query).digest("hex");
|
|
14
|
-
}
|
|
15
|
-
const gqlTagRegex = /gql`([\s\S]*?)`/gm;
|
|
16
|
-
const webpackPersistedQueriesLoader = function(source) {
|
|
17
|
-
const options = this.getOptions() || {};
|
|
18
|
-
const persistedQueriesPath = options.persistedQueriesPath || ".persisted-queries.json";
|
|
19
|
-
const hashMap = loadHashMap(persistedQueriesPath);
|
|
20
|
-
const replacements = [];
|
|
21
|
-
let match;
|
|
22
|
-
while ((match = gqlTagRegex.exec(source)) !== null) {
|
|
23
|
-
const query = match[1];
|
|
24
|
-
const hash = hashQuery(query);
|
|
25
|
-
hashMap[hash] = query;
|
|
26
|
-
const fragmentVariables = Array.from(query.matchAll(/\${.*?}/g) ?? []).map((m) => m[0]).join(" ");
|
|
27
|
-
if (query.match(/^\s*fragment\s+(\w+)\s+on\s+\w+/)) {
|
|
28
|
-
replacements.push({
|
|
29
|
-
start: match.index,
|
|
30
|
-
end: match.index + match[0].length,
|
|
31
|
-
replacement: `{ fragment: true, fragmentVariables: \`${fragmentVariables}\` }`
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
replacements.push({
|
|
35
|
-
start: match.index,
|
|
36
|
-
end: match.index + match[0].length,
|
|
37
|
-
replacement: `{ hash: "${hash}", fragmentVariables: \`${fragmentVariables}\` }`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
let modifiedSource = source;
|
|
42
|
-
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
43
|
-
const { start, end, replacement } = replacements[i];
|
|
44
|
-
modifiedSource = modifiedSource.slice(0, start) + replacement + modifiedSource.slice(end);
|
|
45
|
-
}
|
|
46
|
-
saveHashMap(persistedQueriesPath, hashMap);
|
|
47
|
-
return modifiedSource;
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
webpackPersistedQueriesLoader as default
|
|
51
|
-
};
|
|
1
|
+
import{createHash as e}from"crypto";import*as t from"fs";function n(t){return e("sha256").update(t).digest("hex")}const s=/gql`([\s\S]*?)`/gm,r=function(e){const r=(this.getOptions()||{}).persistedQueriesPath||".persisted-queries.json",a=(i=r,t.existsSync(i)?JSON.parse(t.readFileSync(i,"utf-8")):{});var i;const l=[];let o;for(;null!==(o=s.exec(e));){const e=o[1],t=n(e);a[t]=e;const s=Array.from(e.matchAll(/\${.*?}/g)??[]).map(e=>e[0]).join(" ");e.match(/^\s*fragment\s+(\w+)\s+on\s+\w+/)?l.push({start:o.index,end:o.index+o[0].length,replacement:`{ fragment: true, fragmentVariables: \`${s}\` }`}):l.push({start:o.index,end:o.index+o[0].length,replacement:`{ hash: "${t}", fragmentVariables: \`${s}\` }`})}let c=e;for(let t=l.length-1;t>=0;t--){const{start:e,end:n,replacement:s}=l[t];c=c.slice(0,e)+s+c.slice(n)}return function(e,n){t.writeFileSync(e,JSON.stringify(n,null,2))}(r,a),c};export{r as default};
|
|
@@ -1,33 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import { useIFrameBridge } from "../iframebridge/useIFrameBridge.js";
|
|
4
|
-
import { PreviewContext } from "./PreviewContext.js";
|
|
5
|
-
let currentContentScopeJwt = null;
|
|
6
|
-
if (typeof window !== "undefined") {
|
|
7
|
-
const originalFetch = window.fetch;
|
|
8
|
-
window.fetch = async (input, init = {}) => {
|
|
9
|
-
const headers = new Headers(init.headers);
|
|
10
|
-
const url = new URL(typeof input === "string" ? input : input.toString(), window.location.origin);
|
|
11
|
-
if (url.host === window.location.host && currentContentScopeJwt) {
|
|
12
|
-
headers.set("X-Block-Preview", currentContentScopeJwt);
|
|
13
|
-
}
|
|
14
|
-
return originalFetch(input, { ...init, headers });
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const BlockPreviewProvider = ({ children }) => {
|
|
18
|
-
const { contentScopeJwt } = useIFrameBridge();
|
|
19
|
-
currentContentScopeJwt = contentScopeJwt;
|
|
20
|
-
return /* @__PURE__ */ jsx(
|
|
21
|
-
PreviewContext.Provider,
|
|
22
|
-
{
|
|
23
|
-
value: {
|
|
24
|
-
previewType: "BlockPreview",
|
|
25
|
-
showPreviewSkeletons: true
|
|
26
|
-
},
|
|
27
|
-
children
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
BlockPreviewProvider
|
|
33
|
-
};
|
|
2
|
+
import{jsx as e}from"react/jsx-runtime";import{useIFrameBridge as o}from"../iframebridge/useIFrameBridge.js";import{PreviewContext as r}from"./PreviewContext.js";let t=null;if("undefined"!=typeof window){const e=window.fetch;window.fetch=async(o,r={})=>{const n=new Headers(r.headers);return new URL("string"==typeof o?o:o.toString(),window.location.origin).host===window.location.host&&t&&n.set("X-Block-Preview",t),e(o,{...r,headers:n})}}const n=({children:n})=>{const{contentScopeJwt:i}=o();return t=i,/* @__PURE__ */e(r.Provider,{value:{previewType:"BlockPreview",showPreviewSkeletons:!0},children:n})};export{n as BlockPreviewProvider};
|
|
@@ -1,10 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
const defaultPreviewContextValue = {
|
|
4
|
-
previewType: "NoPreview",
|
|
5
|
-
showPreviewSkeletons: false
|
|
6
|
-
};
|
|
7
|
-
const PreviewContext = createContext(defaultPreviewContextValue);
|
|
8
|
-
export {
|
|
9
|
-
PreviewContext
|
|
10
|
-
};
|
|
2
|
+
import{createContext as e}from"react";const o=e({previewType:"NoPreview",showPreviewSkeletons:!1});export{o as PreviewContext};
|
|
@@ -1,41 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useIFrameBridge } from "../iframebridge/useIFrameBridge.js";
|
|
3
|
-
import { PreviewContext } from "./PreviewContext.js";
|
|
4
|
-
function usePreview() {
|
|
5
|
-
const iFrameBridge = useIFrameBridge();
|
|
6
|
-
const previewContext = useContext(PreviewContext);
|
|
7
|
-
const isSelected = useCallback(
|
|
8
|
-
(url, options) => {
|
|
9
|
-
var _a;
|
|
10
|
-
if (!iFrameBridge.selectedAdminRoute) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const exactMatch = (options == null ? void 0 : options.exactMatch) ?? true;
|
|
14
|
-
if (exactMatch) {
|
|
15
|
-
return url === iFrameBridge.selectedAdminRoute;
|
|
16
|
-
} else {
|
|
17
|
-
return (_a = iFrameBridge.selectedAdminRoute) == null ? void 0 : _a.startsWith(url);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
[iFrameBridge.selectedAdminRoute]
|
|
21
|
-
);
|
|
22
|
-
const isHovered = useCallback(
|
|
23
|
-
(url, options) => {
|
|
24
|
-
var _a;
|
|
25
|
-
if (!iFrameBridge.hoveredAdminRoute) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const exactMatch = (options == null ? void 0 : options.exactMatch) ?? true;
|
|
29
|
-
if (exactMatch) {
|
|
30
|
-
return url === iFrameBridge.hoveredAdminRoute;
|
|
31
|
-
} else {
|
|
32
|
-
return (_a = iFrameBridge.hoveredAdminRoute) == null ? void 0 : _a.startsWith(url);
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
[iFrameBridge.hoveredAdminRoute]
|
|
36
|
-
);
|
|
37
|
-
return { ...previewContext, isSelected, isHovered };
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
usePreview
|
|
41
|
-
};
|
|
1
|
+
import{useContext as e,useCallback as t}from"react";import{useIFrameBridge as r}from"../iframebridge/useIFrameBridge.js";import{PreviewContext as o}from"./PreviewContext.js";function i(){const i=r();return{...e(o),isSelected:t((e,t)=>{if(!i.selectedAdminRoute)return!1;return t?.exactMatch??!0?e===i.selectedAdminRoute:i.selectedAdminRoute?.startsWith(e)},[i.selectedAdminRoute]),isHovered:t((e,t)=>{if(!i.hoveredAdminRoute)return!1;return t?.exactMatch??!0?e===i.hoveredAdminRoute:i.hoveredAdminRoute?.startsWith(e)},[i.hoveredAdminRoute])}}export{i as usePreview};
|