payload-richtext-tiptap 0.0.136 → 0.0.137
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/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.js +10 -5
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.js.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.js +27 -15
- package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoBlockView.d.ts","sourceRoot":"","sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAmB,MAAM,eAAe,CAAC;AACxD,OAAO,KAAkD,MAAM,OAAO,CAAC;AAIvE,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,MAAM,CAAC;IACrB,IAAI,EAAE,IAAI,GAAG;QACX,KAAK,EAAE;YACL,GAAG,EAAE,MAAM,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,CAAC;IACF,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,mBAAmB,
|
|
1
|
+
{"version":3,"file":"VideoBlockView.d.ts","sourceRoot":"","sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAmB,MAAM,eAAe,CAAC;AACxD,OAAO,KAAkD,MAAM,OAAO,CAAC;AAIvE,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,MAAM,CAAC;IACrB,IAAI,EAAE,IAAI,GAAG;QACX,KAAK,EAAE;YACL,GAAG,EAAE,MAAM,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,CAAC;IACF,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,mBAAmB,sBAwGxD,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -8,13 +8,18 @@ export const VideoBlockView = (props)=>{
|
|
|
8
8
|
const videoWrapperRef = useRef(null);
|
|
9
9
|
const { src, poster, playlistUrl, caption, title } = node.attrs;
|
|
10
10
|
const [playlistContent, setPlaylistContent] = React.useState();
|
|
11
|
-
const [error, setError] = React.useState();
|
|
11
|
+
const [error, setError] = React.useState("");
|
|
12
12
|
useEffect(()=>{
|
|
13
13
|
async function getPlaylistContent() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetch(playlistUrl, {
|
|
16
|
+
cache: "no-cache"
|
|
17
|
+
});
|
|
18
|
+
return await res.json();
|
|
19
|
+
} catch {
|
|
20
|
+
setError("Issue with getting asset info");
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
if (playlistUrl) {
|
|
20
25
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.tsx"],"sourcesContent":["import { Node } from \"@tiptap/pm/model\";\nimport { Editor, NodeViewWrapper } from \"@tiptap/react\";\nimport React, { useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { cn } from \"../../../lib/utils/index.js\";\nimport VideoPlayer from \"./videojs/VideoPlayer.js\";\n\ninterface VideoBlockViewProps {\n editor: Editor;\n getPos: () => number;\n node: Node & {\n attrs: {\n src: string;\n poster: string;\n assetId: string;\n playlistUrl?: string;\n };\n };\n updateAttributes: (attrs: Record<string, string>) => void;\n}\n\nexport type Playlist = {\n id: string;\n title: string;\n description: string;\n poster: string;\n items: Item[];\n};\n\nexport type Item = {\n src: string;\n type: string;\n label: string;\n width: number;\n height: number;\n};\n\nexport const VideoBlockView = (props: VideoBlockViewProps) => {\n const { editor, getPos, node } = props;\n const videoWrapperRef = useRef<HTMLDivElement>(null);\n const { src, poster, playlistUrl, caption, title } = node.attrs;\n const [playlistContent, setPlaylistContent] = React.useState<\n Playlist | undefined\n >();\n const [error, setError] = React.useState();\n\n useEffect(() => {\n async function getPlaylistContent() {\n const res = await fetch(playlistUrl, {\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockView.tsx"],"sourcesContent":["import { Node } from \"@tiptap/pm/model\";\nimport { Editor, NodeViewWrapper } from \"@tiptap/react\";\nimport React, { useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { cn } from \"../../../lib/utils/index.js\";\nimport VideoPlayer from \"./videojs/VideoPlayer.js\";\n\ninterface VideoBlockViewProps {\n editor: Editor;\n getPos: () => number;\n node: Node & {\n attrs: {\n src: string;\n poster: string;\n assetId: string;\n playlistUrl?: string;\n };\n };\n updateAttributes: (attrs: Record<string, string>) => void;\n}\n\nexport type Playlist = {\n id: string;\n title: string;\n description: string;\n poster: string;\n items: Item[];\n};\n\nexport type Item = {\n src: string;\n type: string;\n label: string;\n width: number;\n height: number;\n};\n\nexport const VideoBlockView = (props: VideoBlockViewProps) => {\n const { editor, getPos, node } = props;\n const videoWrapperRef = useRef<HTMLDivElement>(null);\n const { src, poster, playlistUrl, caption, title } = node.attrs;\n const [playlistContent, setPlaylistContent] = React.useState<\n Playlist | undefined\n >();\n const [error, setError] = React.useState(\"\");\n\n useEffect(() => {\n async function getPlaylistContent() {\n try {\n const res = await fetch(playlistUrl, {\n cache: \"no-cache\",\n });\n return await res.json();\n } catch {\n setError(\"Issue with getting asset info\");\n return undefined;\n }\n }\n\n if (playlistUrl) {\n try {\n getPlaylistContent()\n .then((data) => {\n setPlaylistContent(data);\n })\n .catch((err) => {\n setError(err);\n });\n } catch (error) {\n setError(error);\n }\n }\n }, [playlistUrl]);\n\n const wrapperClassName = cn(\n node.attrs.align === \"left\" ? \"ml-0\" : \"ml-auto\",\n node.attrs.align === \"right\" ? \"mr-0\" : \"mr-auto\",\n node.attrs.align === \"center\" && \"mx-auto\"\n );\n\n const onClick = useCallback(() => {\n editor.commands.setNodeSelection(getPos());\n }, [getPos, editor.commands]);\n\n const videoJsOptions = useMemo(() => {\n if (playlistContent == undefined) return {};\n\n if (\n playlistContent.items.some(\n (item) =>\n item.type === \"application/x-mpegURL\" ||\n item.type === \"application/vnd.apple.mpegurl\"\n )\n ) {\n return {\n sources: playlistContent.items\n .filter(\n (item) =>\n item.type === \"application/x-mpegURL\" ||\n item.type === \"application/vnd.apple.mpegurl\"\n )\n .map((item) => ({\n src: item.src,\n type: item.type,\n label: item.label,\n })),\n poster: playlistContent.poster,\n };\n }\n return {\n sources: playlistContent.items.map((item) => ({\n src: item.src,\n type: item.type,\n label: item.label,\n })),\n poster: playlistContent.poster,\n };\n }, [playlistContent]);\n return (\n <NodeViewWrapper>\n <div className={wrapperClassName} style={{ width: node.attrs.width }}>\n <div ref={videoWrapperRef}>\n {error && <div>{error}</div>}\n {/* <video\n controls\n className=\"block\"\n src={src}\n poster={poster}\n title=\"\"\n onClick={onClick}\n /> */}\n {playlistContent && <VideoPlayer options={videoJsOptions} />}\n {caption && playlistContent?.title && (\n <caption className=\"text-center block text-sm text-gray-500\">\n {title || playlistContent?.title}\n </caption>\n )}\n </div>\n </div>\n </NodeViewWrapper>\n );\n};\n\nexport default VideoBlockView;\n"],"names":["NodeViewWrapper","React","useCallback","useEffect","useMemo","useRef","cn","VideoPlayer","VideoBlockView","props","editor","getPos","node","videoWrapperRef","src","poster","playlistUrl","caption","title","attrs","playlistContent","setPlaylistContent","useState","error","setError","getPlaylistContent","res","fetch","cache","json","undefined","then","data","catch","err","wrapperClassName","align","onClick","commands","setNodeSelection","videoJsOptions","items","some","item","type","sources","filter","map","label","div","className","style","width","ref","options"],"mappings":";AACA,SAAiBA,eAAe,QAAQ,gBAAgB;AACxD,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACvE,SAASC,EAAE,QAAQ,8BAA8B;AACjD,OAAOC,iBAAiB,2BAA2B;AAgCnD,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGH;IACjC,MAAMI,kBAAkBR,OAAuB;IAC/C,MAAM,EAAES,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,OAAO,EAAEC,KAAK,EAAE,GAAGN,KAAKO,KAAK;IAC/D,MAAM,CAACC,iBAAiBC,mBAAmB,GAAGpB,MAAMqB,QAAQ;IAG5D,MAAM,CAACC,OAAOC,SAAS,GAAGvB,MAAMqB,QAAQ,CAAC;IAEzCnB,UAAU;QACR,eAAesB;YACb,IAAI;gBACF,MAAMC,MAAM,MAAMC,MAAMX,aAAa;oBACnCY,OAAO;gBACT;gBACA,OAAO,MAAMF,IAAIG,IAAI;YACvB,EAAE,OAAM;gBACNL,SAAS;gBACT,OAAOM;YACT;QACF;QAEA,IAAId,aAAa;YACf,IAAI;gBACFS,qBACGM,IAAI,CAAC,CAACC;oBACLX,mBAAmBW;gBACrB,GACCC,KAAK,CAAC,CAACC;oBACNV,SAASU;gBACX;YACJ,EAAE,OAAOX,OAAO;gBACdC,SAASD;YACX;QACF;IACF,GAAG;QAACP;KAAY;IAEhB,MAAMmB,mBAAmB7B,GACvBM,KAAKO,KAAK,CAACiB,KAAK,KAAK,SAAS,SAAS,WACvCxB,KAAKO,KAAK,CAACiB,KAAK,KAAK,UAAU,SAAS,WACxCxB,KAAKO,KAAK,CAACiB,KAAK,KAA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@
|
|
|
1
|
-
{"version":3,"file":"VideoBlockViewClientside.d.ts","sourceRoot":"","sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,KAAqC,MAAM,OAAO,CAAC;AAK1D,UAAU,mBAAmB;IAC3B,IAAI,EAAE,IAAI,GAAG;QACX,KAAK,EAAE;YACL,GAAG,EAAE,MAAM,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,wBAAwB,4CAIlC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"VideoBlockViewClientside.d.ts","sourceRoot":"","sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,KAAqC,MAAM,OAAO,CAAC;AAK1D,UAAU,mBAAmB;IAC3B,IAAI,EAAE,IAAI,GAAG;QACX,KAAK,EAAE;YACL,GAAG,EAAE,MAAM,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,wBAAwB,4CAIlC,mBAAmB,sBAuIrB,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
package/dist/src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.js
CHANGED
|
@@ -71,32 +71,44 @@ export const VideoBlockViewClientside = ({ className, getVideoAspect, ...props }
|
|
|
71
71
|
}, [
|
|
72
72
|
playlistContent
|
|
73
73
|
]);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
const style = useMemo(()=>{
|
|
75
|
+
if (aspectRatio) {
|
|
76
|
+
return {
|
|
77
|
+
aspectRatio,
|
|
78
|
+
maxHeight: "80vh",
|
|
79
79
|
width: node.attrs.width
|
|
80
|
-
}
|
|
81
|
-
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
width: node.attrs.width
|
|
84
|
+
};
|
|
85
|
+
}, [
|
|
86
|
+
aspectRatio
|
|
87
|
+
]);
|
|
88
|
+
return /*#__PURE__*/ _jsxs(NodeViewWrapper, {
|
|
89
|
+
className: className,
|
|
90
|
+
children: [
|
|
91
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
92
|
+
className: cn(wrapperClassName, "main-videojs-wrapper"),
|
|
82
93
|
ref: videoWrapperRef,
|
|
83
|
-
style:
|
|
84
|
-
aspectRatio
|
|
85
|
-
},
|
|
94
|
+
style: style,
|
|
86
95
|
children: [
|
|
87
96
|
error && /*#__PURE__*/ _jsx("div", {
|
|
88
97
|
children: error
|
|
89
98
|
}),
|
|
90
99
|
playlistContent && /*#__PURE__*/ _jsx(VideoPlayer, {
|
|
91
100
|
options: videoJsOptions
|
|
92
|
-
}),
|
|
93
|
-
caption && playlistContent?.title && /*#__PURE__*/ _jsx("div", {
|
|
94
|
-
className: "text-center block text-sm text-gray-500",
|
|
95
|
-
children: playlistContent?.title
|
|
96
101
|
})
|
|
97
102
|
]
|
|
103
|
+
}),
|
|
104
|
+
caption && playlistContent?.title && /*#__PURE__*/ _jsx("div", {
|
|
105
|
+
className: "block mx-auto text-sm text-gray-500",
|
|
106
|
+
style: {
|
|
107
|
+
width: node.attrs.width
|
|
108
|
+
},
|
|
109
|
+
children: playlistContent?.title
|
|
98
110
|
})
|
|
99
|
-
|
|
111
|
+
]
|
|
100
112
|
});
|
|
101
113
|
};
|
|
102
114
|
export default VideoBlockViewClientside;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.tsx"],"sourcesContent":["import { Node } from \"@tiptap/pm/model\";\nimport { NodeViewWrapper } from \"@tiptap/react\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport { cn } from \"../../../lib/utils/index.js\";\nimport VideoPlayer from \"./videojs/VideoPlayer.js\";\nimport { useGetAssetsAspectRatio } from \"../../serverside/getAssetsAspectRatio.js\";\n\ninterface VideoBlockViewProps {\n node: Node & {\n attrs: {\n src: string;\n poster: string;\n assetId: string;\n playlistUrl?: string;\n };\n };\n className?: string;\n getVideoAspect?: () => void;\n}\n\nexport type Playlist = {\n id: string;\n title: string;\n description: string;\n poster: string;\n items: Item[];\n};\n\nexport type Item = {\n src: string;\n type: string;\n label: string;\n width: number;\n height: number;\n};\n\nexport const VideoBlockViewClientside = ({\n className,\n getVideoAspect,\n ...props\n}: VideoBlockViewProps) => {\n const { node } = props;\n const videoWrapperRef = useRef<HTMLDivElement>(null);\n const { src, poster, playlistUrl, caption, actualWidth, actualHeight } =\n node.attrs;\n const { aspectRatio, calculateAspectRatio } = useGetAssetsAspectRatio();\n const [playlistContent, setPlaylistContent] = React.useState<\n Playlist | undefined\n >();\n const [error, setError] = React.useState();\n\n useEffect(() => {\n async function getPlaylistContent() {\n const res = await fetch(playlistUrl, {\n cache: \"no-cache\",\n });\n return await res.json();\n }\n\n if (playlistUrl) {\n try {\n getPlaylistContent()\n .then((data) => {\n setPlaylistContent(data);\n })\n .catch((err) => {\n setError(err);\n });\n } catch (error) {\n setError(error);\n }\n }\n }, [playlistUrl]);\n\n const wrapperClassName = cn(\n node.attrs.align === \"left\" ? \"ml-0\" : \"ml-auto\",\n node.attrs.align === \"right\" ? \"mr-0\" : \"mr-auto\",\n node.attrs.align === \"center\" && \"mx-auto\"\n );\n\n const videoJsOptions = useMemo(() => {\n if (playlistContent == undefined) return {};\n\n if (\n playlistContent.items.some(\n (item) =>\n item.type === \"application/x-mpegURL\" ||\n item.type === \"application/vnd.apple.mpegurl\"\n )\n ) {\n return {\n sources: playlistContent.items\n .filter(\n (item) =>\n item.type === \"application/x-mpegURL\" ||\n item.type === \"application/vnd.apple.mpegurl\"\n )\n .map((item) => ({\n src: item.src,\n type: item.type,\n label: item.label,\n })),\n poster: playlistContent.poster,\n preload: \"auto\",\n };\n }\n return {\n sources: playlistContent.items.map((item) => ({\n src: item.src,\n type: item.type,\n label: item.label,\n })),\n poster: playlistContent.poster,\n preload: \"auto\",\n };\n }, [playlistContent]);\n\n useEffect(() => {\n const anySrc = playlistContent?.items?.some((item) => item.src);\n\n if (!aspectRatio && anySrc) {\n const source = playlistContent.items.find(\n (item) => item.src && item.width && item.height\n );\n calculateAspectRatio(\n {\n src,\n actualWidth: actualWidth || source?.width,\n actualHeight: actualHeight || source?.height,\n },\n \"VIDEO\",\n getVideoAspect\n );\n }\n }, [playlistContent]);\n\n return (\n <NodeViewWrapper className={className}>\n <div
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/fields/TiptapEditor/extensions/VideoBlock/components/VideoBlockViewClientside.tsx"],"sourcesContent":["import { Node } from \"@tiptap/pm/model\";\nimport { NodeViewWrapper } from \"@tiptap/react\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport { cn } from \"../../../lib/utils/index.js\";\nimport VideoPlayer from \"./videojs/VideoPlayer.js\";\nimport { useGetAssetsAspectRatio } from \"../../serverside/getAssetsAspectRatio.js\";\n\ninterface VideoBlockViewProps {\n node: Node & {\n attrs: {\n src: string;\n poster: string;\n assetId: string;\n playlistUrl?: string;\n };\n };\n className?: string;\n getVideoAspect?: () => void;\n}\n\nexport type Playlist = {\n id: string;\n title: string;\n description: string;\n poster: string;\n items: Item[];\n};\n\nexport type Item = {\n src: string;\n type: string;\n label: string;\n width: number;\n height: number;\n};\n\nexport const VideoBlockViewClientside = ({\n className,\n getVideoAspect,\n ...props\n}: VideoBlockViewProps) => {\n const { node } = props;\n const videoWrapperRef = useRef<HTMLDivElement>(null);\n const { src, poster, playlistUrl, caption, actualWidth, actualHeight } =\n node.attrs;\n const { aspectRatio, calculateAspectRatio } = useGetAssetsAspectRatio();\n const [playlistContent, setPlaylistContent] = React.useState<\n Playlist | undefined\n >();\n const [error, setError] = React.useState();\n\n useEffect(() => {\n async function getPlaylistContent() {\n const res = await fetch(playlistUrl, {\n cache: \"no-cache\",\n });\n return await res.json();\n }\n\n if (playlistUrl) {\n try {\n getPlaylistContent()\n .then((data) => {\n setPlaylistContent(data);\n })\n .catch((err) => {\n setError(err);\n });\n } catch (error) {\n setError(error);\n }\n }\n }, [playlistUrl]);\n\n const wrapperClassName = cn(\n node.attrs.align === \"left\" ? \"ml-0\" : \"ml-auto\",\n node.attrs.align === \"right\" ? \"mr-0\" : \"mr-auto\",\n node.attrs.align === \"center\" && \"mx-auto\"\n );\n\n const videoJsOptions = useMemo(() => {\n if (playlistContent == undefined) return {};\n\n if (\n playlistContent.items.some(\n (item) =>\n item.type === \"application/x-mpegURL\" ||\n item.type === \"application/vnd.apple.mpegurl\"\n )\n ) {\n return {\n sources: playlistContent.items\n .filter(\n (item) =>\n item.type === \"application/x-mpegURL\" ||\n item.type === \"application/vnd.apple.mpegurl\"\n )\n .map((item) => ({\n src: item.src,\n type: item.type,\n label: item.label,\n })),\n poster: playlistContent.poster,\n preload: \"auto\",\n };\n }\n return {\n sources: playlistContent.items.map((item) => ({\n src: item.src,\n type: item.type,\n label: item.label,\n })),\n poster: playlistContent.poster,\n preload: \"auto\",\n };\n }, [playlistContent]);\n\n useEffect(() => {\n const anySrc = playlistContent?.items?.some((item) => item.src);\n\n if (!aspectRatio && anySrc) {\n const source = playlistContent.items.find(\n (item) => item.src && item.width && item.height\n );\n calculateAspectRatio(\n {\n src,\n actualWidth: actualWidth || source?.width,\n actualHeight: actualHeight || source?.height,\n },\n \"VIDEO\",\n getVideoAspect\n );\n }\n }, [playlistContent]);\n const style = useMemo(() => {\n if (aspectRatio) {\n return {\n aspectRatio,\n maxHeight: \"80vh\",\n width: node.attrs.width,\n };\n }\n return {\n width: node.attrs.width,\n };\n }, [aspectRatio]);\n return (\n <NodeViewWrapper className={className}>\n <div\n className={cn(wrapperClassName, \"main-videojs-wrapper\")}\n ref={videoWrapperRef}\n style={style}\n >\n {error && <div>{error}</div>}\n {/* <video\n controls\n className=\"block\"\n src={src}\n poster={poster}\n title=\"\"\n onClick={onClick}\n /> */}\n {playlistContent && <VideoPlayer options={videoJsOptions} />}\n </div>\n {caption && playlistContent?.title && (\n <div\n className=\"block mx-auto text-sm text-gray-500\"\n style={{ width: node.attrs.width }}\n >\n {playlistContent?.title}\n </div>\n )}\n </NodeViewWrapper>\n );\n};\n\nexport default VideoBlockViewClientside;\n"],"names":["NodeViewWrapper","React","useEffect","useMemo","useRef","cn","VideoPlayer","useGetAssetsAspectRatio","VideoBlockViewClientside","className","getVideoAspect","props","node","videoWrapperRef","src","poster","playlistUrl","caption","actualWidth","actualHeight","attrs","aspectRatio","calculateAspectRatio","playlistContent","setPlaylistContent","useState","error","setError","getPlaylistContent","res","fetch","cache","json","then","data","catch","err","wrapperClassName","align","videoJsOptions","undefined","items","some","item","type","sources","filter","map","label","preload","anySrc","source","find","width","height","style","maxHeight","div","ref","options","title"],"mappings":";AACA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,OAAOC,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAC1D,SAASC,EAAE,QAAQ,8BAA8B;AACjD,OAAOC,iBAAiB,2BAA2B;AACnD,SAASC,uBAAuB,QAAQ,2CAA2C;AA+BnF,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,SAAS,EACTC,cAAc,EACd,GAAGC,OACiB;IACpB,MAAM,EAAEC,IAAI,EAAE,GAAGD;IACjB,MAAME,kBAAkBT,OAAuB;IAC/C,MAAM,EAAEU,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,OAAO,EAAEC,WAAW,EAAEC,YAAY,EAAE,GACpEP,KAAKQ,KAAK;IACZ,MAAM,EAAEC,WAAW,EAAEC,oBAAoB,EAAE,GAAGf;IAC9C,MAAM,CAACgB,iBAAiBC,mBAAmB,GAAGvB,MAAMwB,QAAQ;IAG5D,MAAM,CAACC,OAAOC,SAAS,GAAG1B,MAAMwB,QAAQ;IAExCvB,UAAU;QACR,eAAe0B;YACb,MAAMC,MAAM,MAAMC,MAAMd,aAAa;gBACnCe,OAAO;YACT;YACA,OAAO,MAAMF,IAAIG,IAAI;QACvB;QAEA,I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