Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ export const createResizableFileBlockWrapper = (
const leftResizeHandle = document.createElement("div");
leftResizeHandle.className = "bn-resize-handle";
leftResizeHandle.style.left = "4px";
leftResizeHandle.style.display = "none";
resizeHandlesContainerElement.appendChild(leftResizeHandle);
const rightResizeHandle = document.createElement("div");
rightResizeHandle.className = "bn-resize-handle";
rightResizeHandle.style.right = "4px";
rightResizeHandle.style.display = "none";
resizeHandlesContainerElement.appendChild(rightResizeHandle);

// This element ensures `mousemove` and `mouseup` events are captured while
// resizing when the cursor is over the wrapper content. This is because
Expand All @@ -75,13 +79,9 @@ export const createResizableFileBlockWrapper = (
// offset from when the resize began, and which resize handle is being used.
const windowMouseMoveHandler = (event: MouseEvent | TouchEvent) => {
if (!resizeParams) {
if (
!editor.isEditable &&
resizeHandlesContainerElement.contains(leftResizeHandle) &&
resizeHandlesContainerElement.contains(rightResizeHandle)
) {
resizeHandlesContainerElement.removeChild(leftResizeHandle);
resizeHandlesContainerElement.removeChild(rightResizeHandle);
if (!editor.isEditable) {
leftResizeHandle.style.display = "none";
rightResizeHandle.style.display = "none";
}

return;
Expand Down Expand Up @@ -128,14 +128,12 @@ export const createResizableFileBlockWrapper = (
const windowMouseUpHandler = (event: MouseEvent | TouchEvent) => {
// Hides the drag handles if the cursor is no longer over the element.
if (
(!event.target ||
!wrapper.contains(event.target as Node) ||
!editor.isEditable) &&
resizeHandlesContainerElement.contains(leftResizeHandle) &&
resizeHandlesContainerElement.contains(rightResizeHandle)
!event.target ||
!wrapper.contains(event.target as Node) ||
!editor.isEditable
) {
resizeHandlesContainerElement.removeChild(leftResizeHandle);
resizeHandlesContainerElement.removeChild(rightResizeHandle);
leftResizeHandle.style.display = "none";
rightResizeHandle.style.display = "none";
}

if (!resizeParams) {
Expand All @@ -158,8 +156,8 @@ export const createResizableFileBlockWrapper = (
// Shows the resize handles when hovering over the wrapper with the cursor.
const wrapperMouseEnterHandler = () => {
if (editor.isEditable) {
resizeHandlesContainerElement.appendChild(leftResizeHandle);
resizeHandlesContainerElement.appendChild(rightResizeHandle);
leftResizeHandle.style.display = "";
rightResizeHandle.style.display = "";
}
};
// Hides the resize handles when the cursor leaves the wrapper, unless the
Expand All @@ -176,13 +174,9 @@ export const createResizableFileBlockWrapper = (
return;
}

if (
editor.isEditable &&
resizeHandlesContainerElement.contains(leftResizeHandle) &&
resizeHandlesContainerElement.contains(rightResizeHandle)
) {
resizeHandlesContainerElement.removeChild(leftResizeHandle);
resizeHandlesContainerElement.removeChild(rightResizeHandle);
if (editor.isEditable) {
leftResizeHandle.style.display = "none";
rightResizeHandle.style.display = "none";
}
};

Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/blocks/Audio/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export const AudioBlock = (
export const ReactAudioBlock = createReactBlockSpec(
createAudioBlockConfig,
(config) => ({
meta: {
fileBlockAccept: ["audio/*"],
},
render: AudioBlock,
parse: audioParse(config),
toExternalHTML: AudioToExternalHTML,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,24 @@ export const ResizableFileBlockWrapper = (
ref={ref}
>
{props.children}
{(hovered || resizeParams) && (
<>
<div
className={"bn-resize-handle"}
style={{ left: "4px" }}
onMouseDown={leftResizeHandleMouseDownHandler}
onTouchStart={leftResizeHandleMouseDownHandler}
/>
<div
className={"bn-resize-handle"}
style={{ right: "4px" }}
onMouseDown={rightResizeHandleMouseDownHandler}
onTouchStart={rightResizeHandleMouseDownHandler}
/>
</>
)}
<div
className={"bn-resize-handle"}
style={{
left: "4px",
display: hovered || resizeParams ? "initial" : "none",
}}
onMouseDown={leftResizeHandleMouseDownHandler}
onTouchStart={leftResizeHandleMouseDownHandler}
/>
<div
className={"bn-resize-handle"}
style={{
right: "4px",
display: hovered || resizeParams ? "initial" : "none",
}}
onMouseDown={rightResizeHandleMouseDownHandler}
onTouchStart={rightResizeHandleMouseDownHandler}
/>
{/* This element ensures `mousemove` and `mouseup` events are captured
while resizing when the cursor is over the wrapper content. This is
because embeds are treated as separate HTML documents, so if the
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/blocks/Image/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ export const ImageBlock = (
export const ReactImageBlock = createReactBlockSpec(
createImageBlockConfig,
(config) => ({
meta: {
fileBlockAccept: ["image/*"],
},
render: ImageBlock,
parse: imageParse(config),
toExternalHTML: ImageToExternalHTML,
runsBefore: ["file"],
}),
);
4 changes: 4 additions & 0 deletions packages/react/src/blocks/Video/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ export const VideoBlock = (
export const ReactVideoBlock = createReactBlockSpec(
createVideoBlockConfig,
(config) => ({
meta: {
fileBlockAccept: ["video/*"],
},
render: VideoBlock,
parse: videoParse(config),
toExternalHTML: VideoToExternalHTML,
runsBefore: ["file"],
}),
);
3 changes: 3 additions & 0 deletions packages/react/src/schema/ReactBlockSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export function createReactBlockSpec<
blockProps={block.props}
propSchema={blockConfig.propSchema}
domAttributes={this.blockContentDOMAttributes}
isFileBlock={
blockImplementation.meta?.fileBlockAccept !== undefined
}
>
<BlockContent
block={block as any}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Test ServerBlockNoteEditor > converts to HTML (blocksToFullHTML) 1`] = `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="heading" data-background-color="blue" data-text-color="yellow" data-text-alignment="right" data-level="2"><h2 class="bn-inline-content"><strong><u>Heading </u></strong><em><s>2</s></em></h2></div><div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2"><div class="bn-block-content" data-content-type="paragraph" data-background-color="red"><p class="bn-inline-content">Paragraph</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="3"><div class="bn-block" data-node-type="blockContainer" data-id="3"><div class="bn-block-content" data-content-type="bulletListItem"><p class="bn-inline-content">list item</p></div></div></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="4"><div class="bn-block" data-node-type="blockContainer" data-id="4"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-preview-width="256" data-file-block=""><div class="bn-file-block-content-wrapper" style="position: relative; width: 256px;"><div class="bn-visual-media-wrapper"><img class="bn-visual-media" src="exampleURL" alt="Example" draggable="false"></div><p class="bn-file-caption">Caption</p></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="5"><div class="bn-block" data-node-type="blockContainer" data-id="5"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-show-preview="false" data-preview-width="256" data-file-block=""><div class="bn-file-block-content-wrapper" style="position: relative;"><div class="bn-file-name-with-icon"><div class="bn-file-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg></div><p class="bn-file-name">Example</p></div><p class="bn-file-caption">Caption</p></div></div></div></div></div>"`;
exports[`Test ServerBlockNoteEditor > converts to HTML (blocksToFullHTML) 1`] = `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="heading" data-background-color="blue" data-text-color="yellow" data-text-alignment="right" data-level="2"><h2 class="bn-inline-content"><strong><u>Heading </u></strong><em><s>2</s></em></h2></div><div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2"><div class="bn-block-content" data-content-type="paragraph" data-background-color="red"><p class="bn-inline-content">Paragraph</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="3"><div class="bn-block" data-node-type="blockContainer" data-id="3"><div class="bn-block-content" data-content-type="bulletListItem"><p class="bn-inline-content">list item</p></div></div></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="4"><div class="bn-block" data-node-type="blockContainer" data-id="4"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-preview-width="256" data-file-block=""><div class="bn-file-block-content-wrapper" style="position: relative; width: 256px;"><div class="bn-visual-media-wrapper"><img class="bn-visual-media" src="exampleURL" alt="Example" draggable="false"><div class="bn-resize-handle" style="left: 4px; display: none;"></div><div class="bn-resize-handle" style="right: 4px; display: none;"></div></div><p class="bn-file-caption">Caption</p></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="5"><div class="bn-block" data-node-type="blockContainer" data-id="5"><div class="bn-block-content" data-content-type="image" data-name="Example" data-url="exampleURL" data-caption="Caption" data-show-preview="false" data-preview-width="256" data-file-block=""><div class="bn-file-block-content-wrapper" style="position: relative;"><div class="bn-file-name-with-icon"><div class="bn-file-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg></div><p class="bn-file-name">Example</p></div><p class="bn-file-caption">Caption</p></div></div></div></div></div>"`;

exports[`Test ServerBlockNoteEditor > converts to and from HTML (blocksToHTMLLossy) 1`] = `"<h2 style="background-color: rgb(221, 235, 241); color: rgb(223, 171, 1); text-align: right;" data-background-color="blue" data-text-color="yellow" data-text-alignment="right" data-level="2"><strong><u>Heading </u></strong><em><s>2</s></em></h2><p style="background-color: rgb(251, 228, 228);" data-background-color="red" data-nesting-level="1">Paragraph</p><ul><li data-nesting-level="1"><p class="bn-inline-content">list item</p></li></ul><figure data-name="Example" data-url="exampleURL" data-caption="Caption" data-preview-width="256"><img src="exampleURL" alt="Example" width="256"><figcaption>Caption</figcaption></figure><div data-name="Example" data-url="exampleURL" data-caption="Caption" data-show-preview="false" data-preview-width="256"><a href="exampleURL">Example</a><p>Caption</p></div>"`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
alt="BlockNote image"
draggable="false"
/>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="Caption" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand All @@ -36,6 +38,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="Caption" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="Caption" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
draggable="false"
width="0"
></video>
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand All @@ -38,6 +40,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="example" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
>
<div class="bn-visual-media-wrapper">
<img class="bn-visual-media" src="exampleURL" alt="Caption" draggable="false" />
<div class="bn-resize-handle" style="left: 4px; display: none;"></div>
<div class="bn-resize-handle" style="right: 4px; display: none;"></div>
</div>
<p class="bn-file-caption">Caption</p>
</div>
Expand Down
Loading