Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/src/blocks/Video/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const FILE_VIDEO_ICON_SVG =

export interface VideoOptions {
icon?: string;
preload?: "none" | "metadata" | "auto";
}

export type VideoBlockConfig = ReturnType<typeof createVideoBlockConfig>;
Expand Down Expand Up @@ -93,6 +94,9 @@ export const createVideoBlockSpec = createBlockSpec(
video.contentEditable = "false";
video.draggable = false;
video.width = block.props.previewWidth;
if (config.preload) {
video.preload = config.preload;
}
videoWrapper.appendChild(video);

return createResizableFileBlockWrapper(
Expand Down
17 changes: 10 additions & 7 deletions packages/react/src/blocks/Video/block.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createVideoBlockConfig, videoParse } from "@blocknote/core";
import { createVideoBlockConfig, VideoOptions, videoParse } from "@blocknote/core";
import { RiVideoFill } from "react-icons/ri";

import {
createReactBlockSpec,
ReactCustomBlockRenderProps,
} from "../../schema/ReactBlockSpec.js";
import { useResolveUrl } from "../File/useResolveUrl.js";
import { FigureWithCaption } from "../File/helpers/toExternalHTML/FigureWithCaption.js";
import { ResizableFileBlockWrapper } from "../File/helpers/render/ResizableFileBlockWrapper.js";
import { FigureWithCaption } from "../File/helpers/toExternalHTML/FigureWithCaption.js";
import { LinkWithCaption } from "../File/helpers/toExternalHTML/LinkWithCaption.js";
import { useResolveUrl } from "../File/useResolveUrl.js";

export const VideoPreview = (
props: Omit<
Expand All @@ -18,7 +18,9 @@ export const VideoPreview = (
ReturnType<typeof createVideoBlockConfig>["content"]
>,
"contentRef"
>,
> & {
preload?: "none" | "metadata" | "auto";
},
) => {
const resolved = useResolveUrl(props.block.props.url!);

Expand All @@ -33,6 +35,7 @@ export const VideoPreview = (
controls={true}
contentEditable={false}
draggable={false}
preload={props.preload}
/>
);
};
Expand Down Expand Up @@ -74,7 +77,7 @@ export const VideoToExternalHTML = (
return video;
};

export const VideoBlock = (
export const VideoBlock = (config: VideoOptions) => (
props: ReactCustomBlockRenderProps<
ReturnType<typeof createVideoBlockConfig>["type"],
ReturnType<typeof createVideoBlockConfig>["propSchema"],
Expand All @@ -86,15 +89,15 @@ export const VideoBlock = (
{...(props as any)}
buttonIcon={<RiVideoFill size={24} />}
>
<VideoPreview {...(props as any)} />
<VideoPreview preload={config.preload} {...(props as any)} />
</ResizableFileBlockWrapper>
);
};

export const ReactVideoBlock = createReactBlockSpec(
createVideoBlockConfig,
(config) => ({
render: VideoBlock,
render: VideoBlock(config),
parse: videoParse(config),
toExternalHTML: VideoToExternalHTML,
}),
Expand Down
Loading