@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,59 +1 @@
1
- async function recursivelyLoadBlockData({
2
- blockType,
3
- blockData,
4
- blocksMeta,
5
- loaders,
6
- ...dependencies
7
- }) {
8
- function iterateField(block, passedBlockData) {
9
- const blockData2 = { ...passedBlockData };
10
- for (const field of block.fields) {
11
- if (!blockData2[field.name]) {
12
- continue;
13
- } else if (field.kind == "NestedObjectList") {
14
- blockData2[field.name] = blockData2[field.name].map((i) => {
15
- return iterateField(field.object, i);
16
- });
17
- } else if (field.kind == "NestedObject") {
18
- blockData2[field.name] = iterateField(field.object, blockData2[field.name]);
19
- } else if (field.kind == "OneOfBlocks") {
20
- const oneOfBlockType = field.blocks[blockData2.type];
21
- if (!oneOfBlockType) {
22
- throw new Error("invalid blockType");
23
- }
24
- blockData2[field.name] = iterateBlock({
25
- blockType: oneOfBlockType,
26
- blockData: blockData2[field.name]
27
- });
28
- } else if (field.kind == "Block") {
29
- blockData2[field.name] = iterateBlock({
30
- blockType: field.block,
31
- blockData: blockData2[field.name]
32
- });
33
- }
34
- }
35
- return blockData2;
36
- }
37
- const loadedBlockData = [];
38
- function iterateBlock({ blockType: blockType2, blockData: blockData2 }) {
39
- const block = blocksMeta.find((block2) => block2.name === blockType2);
40
- if (!block) {
41
- throw new Error("invalid blockType");
42
- }
43
- const newBlockData = iterateField(block, blockData2);
44
- if (loaders[blockType2]) {
45
- newBlockData.loaded = loaders[blockType2]({ blockData: blockData2, ...dependencies });
46
- loadedBlockData.push(newBlockData);
47
- }
48
- return newBlockData;
49
- }
50
- const ret = iterateBlock({ blockType, blockData });
51
- await Promise.all(loadedBlockData.map((blockData2) => blockData2.loaded));
52
- for (const blockData2 of loadedBlockData) {
53
- blockData2.loaded = await blockData2.loaded;
54
- }
55
- return ret;
56
- }
57
- export {
58
- recursivelyLoadBlockData
59
- };
1
+ async function e({blockType:e,blockData:o,blocksMeta:a,loaders:n,...c}){function t(e,o){const a={...o};for(const n of e.fields)if(a[n.name])if("NestedObjectList"==n.kind)a[n.name]=a[n.name].map(e=>t(n.object,e));else if("NestedObject"==n.kind)a[n.name]=t(n.object,a[n.name]);else if("OneOfBlocks"==n.kind){const e=n.blocks[a.type];if(!e)throw new Error("invalid blockType");a[n.name]=i({blockType:e,blockData:a[n.name]})}else"Block"==n.kind&&(a[n.name]=i({blockType:n.block,blockData:a[n.name]}));return a}const l=[];function i({blockType:e,blockData:o}){const i=a.find(o=>o.name===e);if(!i)throw new Error("invalid blockType");const k=t(i,o);return n[e]&&(k.loaded=n[e]({blockData:o,...c}),l.push(k)),k}const k=i({blockType:e,blockData:o});await Promise.all(l.map(e=>e.loaded));for(const s of l)s.loaded=await s.loaded;return k}export{e as recursivelyLoadBlockData};
@@ -1,28 +1,2 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { cloneElement } from "react";
4
- import { withPreview } from "../iframebridge/withPreview.js";
5
- const DamFileDownloadLinkBlock = withPreview(
6
- ({ data: { file, openFileType }, children, legacyBehavior, ...anchorProps }) => {
7
- if (!file) {
8
- if (legacyBehavior) {
9
- return children;
10
- }
11
- return /* @__PURE__ */ jsx("span", { className: anchorProps.className, children });
12
- }
13
- const href = file.fileUrl;
14
- const target = openFileType === "NewTab" ? "_blank" : anchorProps.target;
15
- if (legacyBehavior) {
16
- return cloneElement(children, {
17
- ...anchorProps,
18
- href,
19
- target
20
- });
21
- }
22
- return /* @__PURE__ */ jsx("a", { ...anchorProps, href, target, children });
23
- },
24
- { label: "DamFileDownloadLink" }
25
- );
26
- export {
27
- DamFileDownloadLinkBlock
28
- };
2
+ import{jsx as e}from"react/jsx-runtime";import{cloneElement as r}from"react";import{withPreview as a}from"../iframebridge/withPreview.js";const t=a(({data:{file:a,openFileType:t},children:i,legacyBehavior:l,...n})=>{if(!a)return l?i:/* @__PURE__ */e("span",{className:n.className,children:i});const o=a.fileUrl,m="NewTab"===t?"_blank":n.target;return l?r(i,{...n,href:o,target:m}):/* @__PURE__ */e("a",{...n,href:o,target:m,children:i})},{label:"DamFileDownloadLink"});export{t as DamFileDownloadLinkBlock};
@@ -1,100 +1,6 @@
1
1
  "use client";
2
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import clsx from "clsx";
4
- import { useState, useCallback } from "react";
5
- import { withPreview } from "../iframebridge/withPreview.js";
6
- import { PreviewSkeleton } from "../previewskeleton/PreviewSkeleton.js";
7
- import styles from "./DamVideoBlock.module.scss.js";
8
- import { PlayPauseButton } from "./helpers/PlayPauseButton.js";
9
- import { useIsElementInViewport } from "./helpers/useIsElementInViewport.js";
10
- const DamVideoBlock = withPreview(
11
- ({
12
- data: { damFile, autoplay, loop, showControls, previewImage },
13
- aspectRatio = "16x9",
14
- previewImageSizes,
15
- renderPreviewImage,
16
- fill,
17
- previewImageIcon,
18
- playButtonAriaLabel,
19
- pauseButtonAriaLabel,
20
- playPauseButton: PlayPauseButtonComponent
21
- }) => {
22
- var _a;
23
- if (damFile === void 0) {
24
- return /* @__PURE__ */ jsx(PreviewSkeleton, { type: "media", hasContent: false, aspectRatio });
25
- }
26
- const [showPreviewImage, setShowPreviewImage] = useState(true);
27
- const [isPlaying, setIsPlaying] = useState(autoplay ?? false);
28
- const [isHandledManually, setIsHandledManually] = useState(false);
29
- const hasPreviewImage = Boolean(previewImage && previewImage.damFile);
30
- const [videoElement, setVideoElement] = useState(null);
31
- const videoRef = setVideoElement;
32
- const handleInView = useCallback(
33
- (inView) => {
34
- if (!isHandledManually && videoElement) {
35
- if (inView && autoplay) {
36
- videoElement.play();
37
- setIsPlaying(true);
38
- } else {
39
- videoElement.pause();
40
- setIsPlaying(false);
41
- }
42
- }
43
- },
44
- [autoplay, isHandledManually, videoElement]
45
- );
46
- useIsElementInViewport({ current: videoElement }, handleInView);
47
- const handlePlayPauseClick = () => {
48
- if (isPlaying) {
49
- setIsPlaying(false);
50
- setIsHandledManually(true);
51
- videoElement == null ? void 0 : videoElement.pause();
52
- } else {
53
- setIsPlaying(true);
54
- videoElement == null ? void 0 : videoElement.play();
55
- }
56
- };
57
- return /* @__PURE__ */ jsx(Fragment, { children: hasPreviewImage && showPreviewImage ? renderPreviewImage({
58
- onPlay: () => setShowPreviewImage(false),
59
- image: previewImage,
60
- aspectRatio,
61
- sizes: previewImageSizes,
62
- fill,
63
- icon: previewImageIcon,
64
- playButtonAriaLabel
65
- }) : /* @__PURE__ */ jsxs("div", { className: styles.root, children: [
66
- /* @__PURE__ */ jsxs(
67
- "video",
68
- {
69
- autoPlay: autoplay || hasPreviewImage && !showPreviewImage,
70
- controls: showControls,
71
- loop,
72
- playsInline: true,
73
- muted: autoplay,
74
- ref: videoRef,
75
- className: clsx(styles.video, fill && styles.fill),
76
- style: !fill ? { "--aspect-ratio": aspectRatio.replace("x", " / ") } : void 0,
77
- children: [
78
- (_a = damFile.captions) == null ? void 0 : _a.map((caption) => {
79
- return /* @__PURE__ */ jsx("track", { src: caption.fileUrl, kind: "captions", srcLang: caption.language }, caption.id);
80
- }),
81
- /* @__PURE__ */ jsx("source", { src: damFile.fileUrl, type: damFile.mimetype })
82
- ]
83
- }
84
- ),
85
- !showControls && (PlayPauseButtonComponent ? /* @__PURE__ */ jsx(PlayPauseButtonComponent, { isPlaying, onClick: handlePlayPauseClick }) : /* @__PURE__ */ jsx(
86
- PlayPauseButton,
87
- {
88
- isPlaying,
89
- onClick: handlePlayPauseClick,
90
- ariaLabelPlay: playButtonAriaLabel,
91
- ariaLabelPause: pauseButtonAriaLabel
92
- }
93
- ))
94
- ] }) });
95
- },
96
- { label: "Video" }
97
- );
98
- export {
99
- DamVideoBlock
100
- };
2
+ import{jsx as e,Fragment as a,jsxs as i}from"react/jsx-runtime";import o from"clsx";import{useState as r,useCallback as l}from"react";import{withPreview as t}from"../iframebridge/withPreview.js";import{PreviewSkeleton as s}from"../previewskeleton/PreviewSkeleton.js";import n from"./DamVideoBlock.module.scss.js";import{PlayPauseButton as p}from"./helpers/PlayPauseButton.js";import{useIsElementInViewport as m}from"./helpers/useIsElementInViewport.js";const c=t(({data:{damFile:t,autoplay:c,loop:u,showControls:d,previewImage:y},aspectRatio:f="16x9",previewImageSizes:v,renderPreviewImage:P,fill:g,previewImageIcon:w,playButtonAriaLabel:h,pauseButtonAriaLabel:I,playPauseButton:b})=>{if(void 0===t)/* @__PURE__ */
3
+ return e(s,{type:"media",hasContent:!1,aspectRatio:f});const[k,B]=r(!0),[j,L]=r(c??!1),[x,C]=r(!1),A=Boolean(y&&y.damFile),[R,V]=r(null),z=V,F=l(e=>{!x&&R&&(e&&c?(R.play(),L(!0)):(R.pause(),L(!1)))},[c,x,R]);m({current:R},F);const N=()=>{j?(L(!1),C(!0),R?.pause()):(L(!0),R?.play())};/* @__PURE__ */
4
+ return e(a,{children:A&&k?P({onPlay:()=>B(!1),image:y,aspectRatio:f,sizes:v,fill:g,icon:w,playButtonAriaLabel:h}):/* @__PURE__ */i("div",{className:n.root,children:[
5
+ /* @__PURE__ */i("video",{autoPlay:c||A&&!k,controls:d,loop:u,playsInline:!0,muted:c,ref:z,className:o(n.video,g&&n.fill),style:g?void 0:{"--aspect-ratio":f.replace("x"," / ")},children:[t.captions?.map(a=>/* @__PURE__ */e("track",{src:a.fileUrl,kind:"captions",srcLang:a.language},a.id)),
6
+ /* @__PURE__ */e("source",{src:t.fileUrl,type:t.mimetype})]}),!d&&(b?/* @__PURE__ */e(b,{isPlaying:j,onClick:N}):/* @__PURE__ */e(p,{isPlaying:j,onClick:N,ariaLabelPlay:h,ariaLabelPause:I}))]})})},{label:"Video"});export{c as DamVideoBlock};
@@ -1,14 +1 @@
1
- const root = "_root_1jlho_1";
2
- const video = "_video_1jlho_6";
3
- const fill = "_fill_1jlho_12";
4
- const styles = {
5
- root,
6
- video,
7
- fill
8
- };
9
- export {
10
- styles as default,
11
- fill,
12
- root,
13
- video
14
- };
1
+ const o="_root_1jlho_1",_="_video_1jlho_6",l="_fill_1jlho_12",t={root:o,video:_,fill:l};export{t as default,l as fill,o as root,_ as video};
@@ -1,21 +1 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { cloneElement } from "react";
3
- const EmailLinkBlock = ({ data: { email }, children, legacyBehavior, ...anchorProps }) => {
4
- if (!email) {
5
- if (legacyBehavior) {
6
- return children;
7
- }
8
- return /* @__PURE__ */ jsx("span", { className: anchorProps.className, children });
9
- }
10
- const href = `mailto:${email}`;
11
- if (legacyBehavior) {
12
- return cloneElement(children, {
13
- ...anchorProps,
14
- href
15
- });
16
- }
17
- return /* @__PURE__ */ jsx("a", { ...anchorProps, href, children });
18
- };
19
- export {
20
- EmailLinkBlock
21
- };
1
+ import{jsx as r}from"react/jsx-runtime";import{cloneElement as e}from"react";const a=({data:{email:a},children:t,legacyBehavior:c,...i})=>{if(!a)return c?t:/* @__PURE__ */r("span",{className:i.className,children:t});const m=`mailto:${a}`;return c?e(t,{...i,href:m}):/* @__PURE__ */r("a",{...i,href:m,children:t})};export{a as EmailLinkBlock};
@@ -1,48 +1,2 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { cloneElement } from "react";
4
- import { usePreview } from "../preview/usePreview.js";
5
- import { sendSitePreviewIFrameMessage } from "../sitePreview/iframebridge/sendSitePreviewIFrameMessage.js";
6
- import { SitePreviewIFrameMessageType } from "../sitePreview/iframebridge/SitePreviewIFrameMessage.js";
7
- function ExternalLinkBlock({ data: { targetUrl, openInNewWindow }, children, legacyBehavior, ...anchorProps }) {
8
- const preview = usePreview();
9
- if (preview.previewType === "SitePreview" || preview.previewType === "BlockPreview") {
10
- const onClick = (event) => {
11
- event.preventDefault();
12
- if (preview.previewType === "SitePreview") {
13
- sendSitePreviewIFrameMessage({
14
- cometType: SitePreviewIFrameMessageType.OpenLink,
15
- data: { link: { openInNewWindow, targetUrl } }
16
- });
17
- }
18
- };
19
- if (legacyBehavior) {
20
- return cloneElement(children, {
21
- ...anchorProps,
22
- href: "#",
23
- onClick
24
- });
25
- }
26
- return /* @__PURE__ */ jsx("a", { ...anchorProps, href: "#", onClick, children });
27
- } else {
28
- if (!targetUrl) {
29
- if (legacyBehavior) {
30
- return children;
31
- }
32
- return /* @__PURE__ */ jsx("span", { className: anchorProps.className, children });
33
- }
34
- const href = targetUrl;
35
- const target = openInNewWindow ? "_blank" : anchorProps.target;
36
- if (legacyBehavior) {
37
- return cloneElement(children, {
38
- ...anchorProps,
39
- href,
40
- target
41
- });
42
- }
43
- return /* @__PURE__ */ jsx("a", { ...anchorProps, href, target, children });
44
- }
45
- }
46
- export {
47
- ExternalLinkBlock
48
- };
2
+ import{jsx as e}from"react/jsx-runtime";import{cloneElement as r}from"react";import{usePreview as i}from"../preview/usePreview.js";import{sendSitePreviewIFrameMessage as t}from"../sitePreview/iframebridge/sendSitePreviewIFrameMessage.js";import{SitePreviewIFrameMessageType as a}from"../sitePreview/iframebridge/SitePreviewIFrameMessage.js";function n({data:{targetUrl:n,openInNewWindow:o},children:s,legacyBehavior:p,...m}){const c=i();if("SitePreview"===c.previewType||"BlockPreview"===c.previewType){const i=e=>{e.preventDefault(),"SitePreview"===c.previewType&&t({cometType:a.OpenLink,data:{link:{openInNewWindow:o,targetUrl:n}}})};return p?r(s,{...m,href:"#",onClick:i}):/* @__PURE__ */e("a",{...m,href:"#",onClick:i,children:s})}{if(!n)return p?s:/* @__PURE__ */e("span",{className:m.className,children:s});const i=n,t=o?"_blank":m.target;return p?r(s,{...m,href:i,target:t}):/* @__PURE__ */e("a",{...m,href:i,target:t,children:s})}}export{n as ExternalLinkBlock};
@@ -1,21 +1 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { cloneElement } from "react";
3
- const PhoneLinkBlock = ({ data: { phone }, children, legacyBehavior, ...anchorProps }) => {
4
- if (!phone) {
5
- if (legacyBehavior) {
6
- return children;
7
- }
8
- return /* @__PURE__ */ jsx("span", { className: anchorProps.className, children });
9
- }
10
- const href = `tel:${phone}`;
11
- if (legacyBehavior) {
12
- return cloneElement(children, {
13
- ...anchorProps,
14
- href
15
- });
16
- }
17
- return /* @__PURE__ */ jsx("a", { ...anchorProps, href, children });
18
- };
19
- export {
20
- PhoneLinkBlock
21
- };
1
+ import{jsx as r}from"react/jsx-runtime";import{cloneElement as e}from"react";const a=({data:{phone:a},children:t,legacyBehavior:c,...n})=>{if(!a)return c?t:/* @__PURE__ */r("span",{className:n.className,children:t});const o=`tel:${a}`;return c?e(t,{...n,href:o}):/* @__PURE__ */r("a",{...n,href:o,children:t})};export{a as PhoneLinkBlock};
@@ -1,31 +1,2 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { withPreview } from "../iframebridge/withPreview.js";
4
- import { PreviewSkeleton } from "../previewskeleton/PreviewSkeleton.js";
5
- const SvgImageBlock = withPreview(
6
- ({
7
- data: { damFile },
8
- width = "100%",
9
- height = "auto",
10
- ...restProps
11
- }) => {
12
- if (!damFile) {
13
- return /* @__PURE__ */ jsx(PreviewSkeleton, { type: "media", hasContent: false, height: height === "auto" ? void 0 : height });
14
- }
15
- return /* @__PURE__ */ jsx(
16
- "img",
17
- {
18
- src: damFile.fileUrl,
19
- width: width === "auto" ? void 0 : width,
20
- height: height === "auto" ? void 0 : height,
21
- alt: damFile.altText ?? "",
22
- title: damFile.title ?? "",
23
- ...restProps
24
- }
25
- );
26
- },
27
- { label: "SvgImage" }
28
- );
29
- export {
30
- SvgImageBlock
31
- };
2
+ import{jsx as t}from"react/jsx-runtime";import{withPreview as e}from"../iframebridge/withPreview.js";import{PreviewSkeleton as i}from"../previewskeleton/PreviewSkeleton.js";const o=e(({data:{damFile:e},width:o="100%",height:r="auto",...a})=>e?/* @__PURE__ */t("img",{src:e.fileUrl,width:"auto"===o?void 0:o,height:"auto"===r?void 0:r,alt:e.altText??"",title:e.title??"",...a}):/* @__PURE__ */t(i,{type:"media",hasContent:!1,height:"auto"===r?void 0:r}),{label:"SvgImage"});export{o as SvgImageBlock};
@@ -1,130 +1,5 @@
1
1
  "use client";
2
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import clsx from "clsx";
4
- import { useState, useRef, useCallback } from "react";
5
- import { withPreview } from "../iframebridge/withPreview.js";
6
- import { PreviewSkeleton } from "../previewskeleton/PreviewSkeleton.js";
7
- import { PlayPauseButton } from "./helpers/PlayPauseButton.js";
8
- import { useIsElementInViewport } from "./helpers/useIsElementInViewport.js";
9
- import styles from "./VimeoVideoBlock.module.scss.js";
10
- function parseVimeoIdentifier(vimeoIdentifier) {
11
- const urlRegEx = /^(https?:\/\/)?((www\.|player\.)?vimeo\.com\/?(showcase\/)*([0-9a-z]*\/)*([0-9]{6,11})[?]?.*)$/;
12
- const idRegEx = /^([0-9]{6,11})$/;
13
- const urlRegExMatch = vimeoIdentifier.match(urlRegEx);
14
- const idRegExMatch = vimeoIdentifier.match(idRegEx);
15
- if (!urlRegExMatch && !idRegExMatch) {
16
- return void 0;
17
- }
18
- if (urlRegExMatch) {
19
- return urlRegExMatch[6];
20
- } else if (idRegExMatch) {
21
- return idRegExMatch[1];
22
- }
23
- }
24
- const VimeoVideoBlock = withPreview(
25
- ({
26
- data: { vimeoIdentifier, autoplay, loop, showControls, previewImage },
27
- aspectRatio = "16x9",
28
- previewImageSizes,
29
- renderPreviewImage,
30
- fill,
31
- previewImageIcon,
32
- playButtonAriaLabel,
33
- pauseButtonAriaLabel,
34
- playPauseButton: PlayPauseButtonComponent
35
- }) => {
36
- const [showPreviewImage, setShowPreviewImage] = useState(true);
37
- const hasPreviewImage = !!(previewImage && previewImage.damFile);
38
- const inViewRef = useRef(null);
39
- const [iframeElement, setIframeElement] = useState(null);
40
- const iframeRef = setIframeElement;
41
- const [isPlaying, setIsPlaying] = useState(autoplay ?? false);
42
- const [isHandledManually, setIsHandledManually] = useState(false);
43
- const pauseVimeoVideo = useCallback(() => {
44
- var _a;
45
- (_a = iframeElement == null ? void 0 : iframeElement.contentWindow) == null ? void 0 : _a.postMessage(JSON.stringify({ method: "pause" }), "https://player.vimeo.com");
46
- }, [iframeElement]);
47
- const playVimeoVideo = useCallback(() => {
48
- var _a;
49
- (_a = iframeElement == null ? void 0 : iframeElement.contentWindow) == null ? void 0 : _a.postMessage(JSON.stringify({ method: "play" }), "https://player.vimeo.com");
50
- }, [iframeElement]);
51
- const handleInView = useCallback(
52
- (isVisible) => {
53
- if (!isHandledManually) {
54
- if (isVisible && autoplay) {
55
- playVimeoVideo();
56
- setIsPlaying(true);
57
- } else {
58
- pauseVimeoVideo();
59
- setIsPlaying(false);
60
- }
61
- }
62
- },
63
- [autoplay, isHandledManually, playVimeoVideo, pauseVimeoVideo]
64
- );
65
- useIsElementInViewport(inViewRef, handleInView);
66
- if (!vimeoIdentifier) {
67
- return /* @__PURE__ */ jsx(PreviewSkeleton, { type: "media", hasContent: false, aspectRatio });
68
- }
69
- const identifier = parseVimeoIdentifier(vimeoIdentifier);
70
- const searchParams = new URLSearchParams();
71
- if (hasPreviewImage && !showPreviewImage) {
72
- searchParams.append("autoplay", "1");
73
- }
74
- if (autoplay) {
75
- searchParams.append("muted", "1");
76
- }
77
- if (loop !== void 0) {
78
- searchParams.append("loop", Number(loop).toString());
79
- }
80
- if (showControls !== void 0) {
81
- searchParams.append("controls", Number(showControls).toString());
82
- }
83
- searchParams.append("dnt", "1");
84
- const vimeoBaseUrl = "https://player.vimeo.com/video/";
85
- const vimeoUrl = new URL(`${vimeoBaseUrl}${identifier ?? ""}`);
86
- vimeoUrl.search = searchParams.toString();
87
- const handlePlayPauseClick = () => {
88
- if (isPlaying) {
89
- setIsPlaying(false);
90
- setIsHandledManually(true);
91
- pauseVimeoVideo();
92
- } else {
93
- setIsPlaying(true);
94
- playVimeoVideo();
95
- }
96
- };
97
- return /* @__PURE__ */ jsx(Fragment, { children: hasPreviewImage && showPreviewImage ? renderPreviewImage({
98
- onPlay: () => setShowPreviewImage(false),
99
- image: previewImage,
100
- aspectRatio,
101
- sizes: previewImageSizes,
102
- fill,
103
- icon: previewImageIcon,
104
- playButtonAriaLabel
105
- }) : /* @__PURE__ */ jsxs(
106
- "div",
107
- {
108
- ref: inViewRef,
109
- className: clsx(styles.videoContainer, fill && styles.fill),
110
- style: !fill ? { "--aspect-ratio": aspectRatio.replace("x", "/") } : void 0,
111
- children: [
112
- /* @__PURE__ */ jsx("iframe", { ref: iframeRef, className: styles.vimeoContainer, src: vimeoUrl.toString(), allow: "autoplay", allowFullScreen: true }),
113
- !showControls && (PlayPauseButtonComponent ? /* @__PURE__ */ jsx(PlayPauseButtonComponent, { isPlaying, onClick: handlePlayPauseClick }) : /* @__PURE__ */ jsx(
114
- PlayPauseButton,
115
- {
116
- isPlaying,
117
- onClick: handlePlayPauseClick,
118
- ariaLabelPlay: playButtonAriaLabel,
119
- ariaLabelPause: pauseButtonAriaLabel
120
- }
121
- ))
122
- ]
123
- }
124
- ) });
125
- },
126
- { label: "Video" }
127
- );
128
- export {
129
- VimeoVideoBlock
130
- };
2
+ import{jsx as e,Fragment as o,jsxs as t}from"react/jsx-runtime";import a from"clsx";import{useState as i,useRef as r,useCallback as n}from"react";import{withPreview as s}from"../iframebridge/withPreview.js";import{PreviewSkeleton as l}from"../previewskeleton/PreviewSkeleton.js";import{PlayPauseButton as p}from"./helpers/PlayPauseButton.js";import{useIsElementInViewport as m}from"./helpers/useIsElementInViewport.js";import c from"./VimeoVideoBlock.module.scss.js";const d=s(({data:{vimeoIdentifier:s,autoplay:d,loop:u,showControls:f,previewImage:v},aspectRatio:w="16x9",previewImageSizes:y,renderPreviewImage:h,fill:g,previewImageIcon:P,playButtonAriaLabel:S,pauseButtonAriaLabel:b,playPauseButton:I})=>{const[L,j]=i(!0),B=!(!v||!v.damFile),C=r(null),[N,k]=i(null),x=k,[R,V]=i(d??!1),[z,A]=i(!1),$=n(()=>{N?.contentWindow?.postMessage(JSON.stringify({method:"pause"}),"https://player.vimeo.com")},[N]),F=n(()=>{N?.contentWindow?.postMessage(JSON.stringify({method:"play"}),"https://player.vimeo.com")},[N]),J=n(e=>{z||(e&&d?(F(),V(!0)):($(),V(!1)))},[d,z,F,$]);if(m(C,J),!s)/* @__PURE__ */
3
+ return e(l,{type:"media",hasContent:!1,aspectRatio:w});const M=function(e){const o=e.match(/^(https?:\/\/)?((www\.|player\.)?vimeo\.com\/?(showcase\/)*([0-9a-z]*\/)*([0-9]{6,11})[?]?.*)$/),t=e.match(/^([0-9]{6,11})$/);if(o||t)return o?o[6]:t?t[1]:void 0}(s),O=new URLSearchParams;B&&!L&&O.append("autoplay","1"),d&&O.append("muted","1"),void 0!==u&&O.append("loop",Number(u).toString()),void 0!==f&&O.append("controls",Number(f).toString()),O.append("dnt","1");const U=new URL(`https://player.vimeo.com/video/${M??""}`);U.search=O.toString();const W=()=>{R?(V(!1),A(!0),$()):(V(!0),F())};/* @__PURE__ */
4
+ return e(o,{children:B&&L?h({onPlay:()=>j(!1),image:v,aspectRatio:w,sizes:y,fill:g,icon:P,playButtonAriaLabel:S}):/* @__PURE__ */t("div",{ref:C,className:a(c.videoContainer,g&&c.fill),style:g?void 0:{"--aspect-ratio":w.replace("x","/")},children:[
5
+ /* @__PURE__ */e("iframe",{ref:x,className:c.vimeoContainer,src:U.toString(),allow:"autoplay",allowFullScreen:!0}),!f&&(I?/* @__PURE__ */e(I,{isPlaying:R,onClick:W}):/* @__PURE__ */e(p,{isPlaying:R,onClick:W,ariaLabelPlay:S,ariaLabelPause:b}))]})})},{label:"Video"});export{d as VimeoVideoBlock};
@@ -1,14 +1 @@
1
- const videoContainer = "_videoContainer_1flq1_1";
2
- const fill = "_fill_1flq1_7";
3
- const vimeoContainer = "_vimeoContainer_1flq1_12";
4
- const styles = {
5
- videoContainer,
6
- fill,
7
- vimeoContainer
8
- };
9
- export {
10
- styles as default,
11
- fill,
12
- videoContainer,
13
- vimeoContainer
14
- };
1
+ const e="_videoContainer_1flq1_1",i="_fill_1flq1_7",o="_vimeoContainer_1flq1_12",n={videoContainer:e,fill:i,vimeoContainer:o};export{n as default,i as fill,e as videoContainer,o as vimeoContainer};
@@ -1,137 +1,5 @@
1
1
  "use client";
2
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import clsx from "clsx";
4
- import { useState, useRef, useCallback } from "react";
5
- import { withPreview } from "../iframebridge/withPreview.js";
6
- import { PreviewSkeleton } from "../previewskeleton/PreviewSkeleton.js";
7
- import { PlayPauseButton } from "./helpers/PlayPauseButton.js";
8
- import { useIsElementInViewport } from "./helpers/useIsElementInViewport.js";
9
- import styles from "./YouTubeVideoBlock.module.scss.js";
10
- const EXPECTED_YT_ID_LENGTH = 11;
11
- const parseYoutubeIdentifier = (value) => {
12
- const regExp = /(https?:\/\/)?(((m|www)\.)?(youtube(-nocookie)?|youtube.googleapis)\.com.*(v\/|v=|vi=|vi\/|e\/|embed\/|user\/.*\/u\/\d+\/)|youtu\.be\/)([_0-9a-zA-Z-]+)/;
13
- const match = value.match(regExp);
14
- const youtubeId = value.length === EXPECTED_YT_ID_LENGTH ? value : match && match[8].length === EXPECTED_YT_ID_LENGTH ? match[8] : null;
15
- return youtubeId ?? void 0;
16
- };
17
- const YouTubeVideoBlock = withPreview(
18
- ({
19
- data: { youtubeIdentifier, autoplay, loop, showControls, previewImage },
20
- aspectRatio = "16x9",
21
- previewImageSizes,
22
- renderPreviewImage,
23
- fill,
24
- previewImageIcon,
25
- playButtonAriaLabel,
26
- pauseButtonAriaLabel,
27
- playPauseButton: PlayPauseButtonComponent
28
- }) => {
29
- const [showPreviewImage, setShowPreviewImage] = useState(true);
30
- const [isPlaying, setIsPlaying] = useState(autoplay ?? false);
31
- const [isHandledManually, setIsHandledManually] = useState(false);
32
- const hasPreviewImage = !!(previewImage && previewImage.damFile);
33
- const [iframeElement, setIframeElement] = useState(null);
34
- const iframeRef = setIframeElement;
35
- const inViewRef = useRef(null);
36
- const pauseYouTubeVideo = useCallback(() => {
37
- var _a;
38
- (_a = iframeElement == null ? void 0 : iframeElement.contentWindow) == null ? void 0 : _a.postMessage(`{"event":"command","func":"pauseVideo","args":""}`, "https://www.youtube-nocookie.com");
39
- }, [iframeElement]);
40
- const playYouTubeVideo = useCallback(() => {
41
- var _a;
42
- (_a = iframeElement == null ? void 0 : iframeElement.contentWindow) == null ? void 0 : _a.postMessage(`{"event":"command","func":"playVideo","args":""}`, "https://www.youtube-nocookie.com");
43
- }, [iframeElement]);
44
- const handleInView = useCallback(
45
- (inView) => {
46
- if (!isHandledManually) {
47
- if (inView && autoplay) {
48
- playYouTubeVideo();
49
- setIsPlaying(true);
50
- } else {
51
- pauseYouTubeVideo();
52
- setIsPlaying(false);
53
- }
54
- }
55
- },
56
- [autoplay, isHandledManually, playYouTubeVideo, pauseYouTubeVideo]
57
- );
58
- useIsElementInViewport(inViewRef, handleInView);
59
- if (!youtubeIdentifier) {
60
- return /* @__PURE__ */ jsx(PreviewSkeleton, { type: "media", hasContent: false, aspectRatio });
61
- }
62
- const identifier = parseYoutubeIdentifier(youtubeIdentifier);
63
- const searchParams = new URLSearchParams();
64
- searchParams.append("modestbranding", "1");
65
- searchParams.append("rel", "0");
66
- searchParams.append("enablejsapi", "1");
67
- if (hasPreviewImage && !showPreviewImage) {
68
- searchParams.append("autoplay", "1");
69
- }
70
- if (autoplay) {
71
- searchParams.append("mute", "1");
72
- }
73
- if (showControls !== void 0) {
74
- searchParams.append("controls", Number(showControls).toString());
75
- }
76
- if (loop !== void 0) {
77
- searchParams.append("loop", Number(loop).toString());
78
- }
79
- if (loop && identifier) {
80
- searchParams.append("playlist", identifier);
81
- }
82
- const youtubeBaseUrl = "https://www.youtube-nocookie.com/embed/";
83
- const youtubeUrl = new URL(`${youtubeBaseUrl}${identifier ?? ""}`);
84
- youtubeUrl.search = searchParams.toString();
85
- const handlePlayPauseClick = () => {
86
- if (isPlaying) {
87
- setIsPlaying(false);
88
- setIsHandledManually(true);
89
- pauseYouTubeVideo();
90
- } else {
91
- setIsPlaying(true);
92
- playYouTubeVideo();
93
- }
94
- };
95
- return /* @__PURE__ */ jsx(Fragment, { children: hasPreviewImage && showPreviewImage ? renderPreviewImage({
96
- onPlay: () => setShowPreviewImage(false),
97
- image: previewImage,
98
- aspectRatio,
99
- sizes: previewImageSizes,
100
- fill,
101
- icon: previewImageIcon,
102
- playButtonAriaLabel
103
- }) : /* @__PURE__ */ jsxs(
104
- "div",
105
- {
106
- ref: inViewRef,
107
- className: clsx(styles.videoContainer, fill && styles.fill),
108
- style: !fill ? { "--aspect-ratio": aspectRatio.replace("x", "/") } : void 0,
109
- children: [
110
- !showControls && (PlayPauseButtonComponent ? /* @__PURE__ */ jsx(PlayPauseButtonComponent, { isPlaying, onClick: handlePlayPauseClick }) : /* @__PURE__ */ jsx(
111
- PlayPauseButton,
112
- {
113
- isPlaying,
114
- onClick: handlePlayPauseClick,
115
- ariaLabelPlay: playButtonAriaLabel,
116
- ariaLabelPause: pauseButtonAriaLabel
117
- }
118
- )),
119
- /* @__PURE__ */ jsx(
120
- "iframe",
121
- {
122
- ref: iframeRef,
123
- className: styles.youtubeContainer,
124
- allow: "autoplay",
125
- referrerPolicy: "strict-origin-when-cross-origin",
126
- src: youtubeUrl.toString()
127
- }
128
- )
129
- ]
130
- }
131
- ) });
132
- },
133
- { label: "Video" }
134
- );
135
- export {
136
- YouTubeVideoBlock
137
- };
2
+ import{jsx as e,Fragment as o,jsxs as t}from"react/jsx-runtime";import a from"clsx";import{useState as i,useRef as r,useCallback as n}from"react";import{withPreview as s}from"../iframebridge/withPreview.js";import{PreviewSkeleton as l}from"../previewskeleton/PreviewSkeleton.js";import{PlayPauseButton as p}from"./helpers/PlayPauseButton.js";import{useIsElementInViewport as m}from"./helpers/useIsElementInViewport.js";import u from"./YouTubeVideoBlock.module.scss.js";const c=s(({data:{youtubeIdentifier:s,autoplay:c,loop:d,showControls:w,previewImage:y},aspectRatio:g="16x9",previewImageSizes:b,renderPreviewImage:f,fill:v,previewImageIcon:h,playButtonAriaLabel:P,pauseButtonAriaLabel:k,playPauseButton:I})=>{const[j,L]=i(!0),[S,B]=i(c??!1),[C,x]=i(!1),R=!(!y||!y.damFile),[V,A]=i(null),N=A,z=r(null),M=n(()=>{V?.contentWindow?.postMessage('{"event":"command","func":"pauseVideo","args":""}',"https://www.youtube-nocookie.com")},[V]),U=n(()=>{V?.contentWindow?.postMessage('{"event":"command","func":"playVideo","args":""}',"https://www.youtube-nocookie.com")},[V]),W=n(e=>{C||(e&&c?(U(),B(!0)):(M(),B(!1)))},[c,C,U,M]);if(m(z,W),!s)/* @__PURE__ */
3
+ return e(l,{type:"media",hasContent:!1,aspectRatio:g});const E=(e=>{const o=e.match(/(https?:\/\/)?(((m|www)\.)?(youtube(-nocookie)?|youtube.googleapis)\.com.*(v\/|v=|vi=|vi\/|e\/|embed\/|user\/.*\/u\/\d+\/)|youtu\.be\/)([_0-9a-zA-Z-]+)/);return(11===e.length?e:o&&11===o[8].length?o[8]:null)??void 0})(s),F=new URLSearchParams;F.append("modestbranding","1"),F.append("rel","0"),F.append("enablejsapi","1"),R&&!j&&F.append("autoplay","1"),c&&F.append("mute","1"),void 0!==w&&F.append("controls",Number(w).toString()),void 0!==d&&F.append("loop",Number(d).toString()),d&&E&&F.append("playlist",E);const T=new URL(`https://www.youtube-nocookie.com/embed/${E??""}`);T.search=F.toString();const Y=()=>{S?(B(!1),x(!0),M()):(B(!0),U())};/* @__PURE__ */
4
+ return e(o,{children:R&&j?f({onPlay:()=>L(!1),image:y,aspectRatio:g,sizes:b,fill:v,icon:h,playButtonAriaLabel:P}):/* @__PURE__ */t("div",{ref:z,className:a(u.videoContainer,v&&u.fill),style:v?void 0:{"--aspect-ratio":g.replace("x","/")},children:[!w&&(I?/* @__PURE__ */e(I,{isPlaying:S,onClick:Y}):/* @__PURE__ */e(p,{isPlaying:S,onClick:Y,ariaLabelPlay:P,ariaLabelPause:k})),
5
+ /* @__PURE__ */e("iframe",{ref:N,className:u.youtubeContainer,allow:"autoplay",referrerPolicy:"strict-origin-when-cross-origin",src:T.toString()})]})})},{label:"Video"});export{c as YouTubeVideoBlock};