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
28 changes: 27 additions & 1 deletion packages/core/src/blocks/Audio/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@ export const FILE_AUDIO_ICON_SVG =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>';

export interface AudioOptions {
/**
* The icon to use for the audio block. As an HTML string.
*/
icon?: string;
/**
* Allows overriding the default audio element rendering.
*/
render?: (ctx: {
/**
* The default audio element which you can modify.
*/
element: HTMLAudioElement;
/**
* The block being rendered.
*/
block: BlockFromConfig<AudioBlockConfig, any, any>;
/**
* The editor instance.
*/
editor: BlockNoteEditor<{ audio: AudioBlockConfig }, any, any>;
}) => HTMLAudioElement;
}

export type AudioBlockConfig = ReturnType<typeof createAudioBlockConfig>;
Expand Down Expand Up @@ -110,10 +130,16 @@ export const audioRender =
audio.contentEditable = "false";
audio.draggable = false;

const audioElement = config.render?.({
element: audio,
block,
editor,
});

return createFileBlockWrapper(
block,
editor,
{ dom: audio },
{ dom: audioElement ?? audio },
icon.firstElementChild as HTMLElement,
);
};
Expand Down
34 changes: 32 additions & 2 deletions packages/core/src/blocks/Video/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
import {
BlockFromConfig,
createBlockConfig,
createBlockSpec,
} from "../../schema/index.js";
import { defaultProps, parseDefaultProps } from "../defaultProps.js";
import { parseFigureElement } from "../File/helpers/parse/parseFigureElement.js";
import { createResizableFileBlockWrapper } from "../File/helpers/render/createResizableFileBlockWrapper.js";
Expand All @@ -10,7 +15,27 @@ export const FILE_VIDEO_ICON_SVG =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>';

export interface VideoOptions {
/**
* The icon to use for the video block. As an HTML string.
*/
icon?: string;
/**
* Allows overriding the default video element rendering.
*/
render?: (ctx: {
/**
* The default video element which you can modify.
*/
element: HTMLVideoElement;
/**
* The block being rendered.
*/
block: BlockFromConfig<VideoBlockConfig, any, any>;
/**
* The editor instance.
*/
editor: BlockNoteEditor<{ video: VideoBlockConfig }, any, any>;
}) => HTMLVideoElement;
}

export type VideoBlockConfig = ReturnType<typeof createVideoBlockConfig>;
Expand Down Expand Up @@ -93,7 +118,12 @@ export const createVideoBlockSpec = createBlockSpec(
video.contentEditable = "false";
video.draggable = false;
video.width = block.props.previewWidth;
videoWrapper.appendChild(video);
const videoElement = config.render?.({
element: video,
block,
editor,
});
videoWrapper.appendChild(videoElement ?? video);

return createResizableFileBlockWrapper(
block,
Expand Down
Loading