Skip to content

Commit 0910662

Browse files
committed
Merge branch 'main' into new-releases
2 parents db56511 + cd6e1ae commit 0910662

File tree

14 files changed

+151
-20
lines changed

14 files changed

+151
-20
lines changed

packages/core/src/blocks/ImageBlockContent/ImageBlockContent.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ export const renderImage = (
148148
// offset from when the resize began, and which resize handle is being used.
149149
const windowMouseMoveHandler = (event: MouseEvent) => {
150150
if (!resizeParams) {
151+
if (
152+
!editor.isEditable &&
153+
imageWrapper.contains(leftResizeHandle) &&
154+
imageWrapper.contains(rightResizeHandle)
155+
) {
156+
imageWrapper.removeChild(leftResizeHandle);
157+
imageWrapper.removeChild(rightResizeHandle);
158+
}
159+
151160
return;
152161
}
153162

@@ -192,20 +201,22 @@ export const renderImage = (
192201
// Stops mouse movements from resizing the image and updates the block's
193202
// `width` prop to the new value.
194203
const windowMouseUpHandler = (event: MouseEvent) => {
195-
if (!resizeParams) {
196-
return;
197-
}
198-
199204
// Hides the drag handles if the cursor is no longer over the image.
200205
if (
201-
(!event.target || !imageWrapper.contains(event.target as Node)) &&
206+
(!event.target ||
207+
!imageWrapper.contains(event.target as Node) ||
208+
!editor.isEditable) &&
202209
imageWrapper.contains(leftResizeHandle) &&
203210
imageWrapper.contains(rightResizeHandle)
204211
) {
205212
imageWrapper.removeChild(leftResizeHandle);
206213
imageWrapper.removeChild(rightResizeHandle);
207214
}
208215

216+
if (!resizeParams) {
217+
return;
218+
}
219+
209220
resizeParams = undefined;
210221

211222
editor.updateBlock(block, {
@@ -235,9 +246,6 @@ export const renderImage = (
235246
if (editor.isEditable) {
236247
imageWrapper.appendChild(leftResizeHandle);
237248
imageWrapper.appendChild(rightResizeHandle);
238-
} else {
239-
imageWrapper.removeChild(leftResizeHandle);
240-
imageWrapper.removeChild(rightResizeHandle);
241249
}
242250
};
243251
// Hides the resize handles when the cursor leaves the image, unless the
@@ -254,8 +262,14 @@ export const renderImage = (
254262
return;
255263
}
256264

257-
imageWrapper.removeChild(leftResizeHandle);
258-
imageWrapper.removeChild(rightResizeHandle);
265+
if (
266+
editor.isEditable &&
267+
imageWrapper.contains(leftResizeHandle) &&
268+
imageWrapper.contains(rightResizeHandle)
269+
) {
270+
imageWrapper.removeChild(leftResizeHandle);
271+
imageWrapper.removeChild(rightResizeHandle);
272+
}
259273
};
260274

261275
// Sets the resize params, allowing the user to begin resizing the image by

packages/core/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const BulletListItemBlockContent = createStronglyTypedTiptapNode({
3737
addKeyboardShortcuts() {
3838
return {
3939
Enter: () => handleEnter(this.editor),
40-
"Mod-Shift-7": () =>
40+
"Mod-Shift-8": () =>
4141
this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor, {
4242
type: "bulletListItem",
4343
props: {},

packages/core/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
5252
addKeyboardShortcuts() {
5353
return {
5454
Enter: () => handleEnter(this.editor),
55-
"Mod-Shift-8": () =>
55+
"Mod-Shift-7": () =>
5656
this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor, {
5757
type: "numberedListItem",
5858
props: {},

packages/core/src/editor/Block.css

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ NESTED BLOCKS
6565
height: 0;
6666
}
6767

68+
.bn-inline-content code {
69+
font-family: monospace;
70+
}
71+
6872
/* NESTED BLOCK ANIMATIONS (change in indent) */
6973

7074
[data-prev-depth-change="1"] {

packages/core/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export class FormattingToolbarView {
5252

5353
pmView.dom.addEventListener("mousedown", this.viewMousedownHandler);
5454
pmView.dom.addEventListener("mouseup", this.viewMouseupHandler);
55-
pmView.dom.addEventListener("dragstart", this.dragstartHandler);
55+
pmView.dom.addEventListener("dragstart", this.dragHandler);
56+
pmView.dom.addEventListener("dragover", this.dragHandler);
5657

5758
pmView.dom.addEventListener("focus", this.focusHandler);
5859
pmView.dom.addEventListener("blur", this.blurHandler);
@@ -70,7 +71,7 @@ export class FormattingToolbarView {
7071
};
7172

7273
// For dragging the whole editor.
73-
dragstartHandler = () => {
74+
dragHandler = () => {
7475
if (this.formattingToolbarState?.show) {
7576
this.formattingToolbarState.show = false;
7677
this.updateFormattingToolbar();
@@ -177,7 +178,8 @@ export class FormattingToolbarView {
177178
destroy() {
178179
this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler);
179180
this.pmView.dom.removeEventListener("mouseup", this.viewMouseupHandler);
180-
this.pmView.dom.removeEventListener("dragstart", this.dragstartHandler);
181+
this.pmView.dom.removeEventListener("dragstart", this.dragHandler);
182+
this.pmView.dom.removeEventListener("dragover", this.dragHandler);
181183

182184
this.pmView.dom.removeEventListener("focus", this.focusHandler);
183185
this.pmView.dom.removeEventListener("blur", this.blurHandler);

packages/core/src/extensions/SideMenu/SideMenuPlugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ export class SideMenuView<
550550
const { contentNode, startPos, endPos } = blockInfo;
551551

552552
// Creates a new block if current one is not empty for the suggestion menu to open in.
553-
if (contentNode.textContent.length !== 0) {
553+
if (
554+
contentNode.type.spec.content !== "inline*" ||
555+
contentNode.textContent.length !== 0
556+
) {
554557
const newBlockInsertionPos = endPos + 1;
555558
const newBlockContentPos = newBlockInsertionPos + 2;
556559

packages/react/src/editor/styles.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
}
159159

160160
/* Mantine Popover component base styles */
161-
.mantine-Popover-dropdown {
161+
.bn-container .mantine-Popover-dropdown {
162162
background-color: transparent;
163163
border: none;
164164
border-radius: 0;

packages/react/src/slashMenuItems/defaultReactSlashMenuItems.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ const extraFields: Record<
4949
group: "Basic blocks",
5050
icon: <RiListOrdered size={18} />,
5151
hint: "Used to display a numbered list",
52-
shortcut: formatKeyboardShortcut("Mod-Alt-7"),
52+
shortcut: formatKeyboardShortcut("Mod-Shift-7"),
5353
},
5454
"Bullet List": {
5555
group: "Basic blocks",
5656
icon: <RiListUnordered size={18} />,
5757
hint: "Used to display an unordered list",
58-
shortcut: formatKeyboardShortcut("Mod-Alt-9"),
58+
shortcut: formatKeyboardShortcut("Mod-Shift-8"),
5959
},
6060
Paragraph: {
6161
group: "Basic blocks",

packages/website/docs/.vitepress/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ const EXAMPLES_SIDEBAR = [
137137
text: "Changing Font",
138138
link: "/examples/changing-font",
139139
},
140+
{
141+
text: "Formatting Toolbar Buttons",
142+
link: "/examples/formatting-toolbar-buttons",
143+
},
140144
],
141145
},
142146
{

packages/website/docs/.vitepress/theme/components/Examples/BlockNote/ReactBlockNote.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { uploadToTmpFilesDotOrg_DEV_ONLY } from "@blocknote/core";
2-
import "@blocknote/core/style.css";
32
import { BlockNoteView, useBlockNote } from "@blocknote/react";
3+
import "@blocknote/react/style.css";
44
import { useEffect, useMemo } from "react";
55
import YPartyKitProvider from "y-partykit/provider";
66
import * as Y from "yjs";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Formatting Toolbar Buttons
3+
description: In this example, we change add a code styles button to the formatting toolbar.
4+
imageTitle: Formatting Toolbar Buttons
5+
path: /examples/formatting-toolbar-buttons
6+
---
7+
8+
<script setup>
9+
import { useData } from 'vitepress';
10+
import { getTheme, getStyles } from "../demoUtils";
11+
12+
const { isDark } = useData();
13+
</script>
14+
15+
# Formatting Toolbar Buttons
16+
17+
In this example, we add a code style toggle button to the Formatting Toolbar.
18+
19+
**Relevant Docs:**
20+
21+
- [Custom Formatting Toolbar](/docs/formatting-toolbar#custom-formatting-toolbar)
22+
23+
::: sandbox {template=react-ts}
24+
25+
```typescript-vue /App.tsx
26+
import { BlockNoteEditor } from "@blocknote/core";
27+
import {
28+
BlockNoteView,
29+
BlockTypeDropdown,
30+
ColorStyleButton,
31+
CreateLinkButton,
32+
FormattingToolbarPositioner,
33+
FormattingToolbarProps,
34+
HyperlinkToolbarPositioner,
35+
ImageCaptionButton,
36+
ImageToolbarPositioner,
37+
NestBlockButton,
38+
ReplaceImageButton,
39+
SideMenuPositioner,
40+
SlashMenuPositioner,
41+
TableHandlesPositioner,
42+
TextAlignButton,
43+
ToggledStyleButton,
44+
Toolbar,
45+
UnnestBlockButton,
46+
useBlockNote,
47+
} from "@blocknote/react";
48+
import "@blocknote/react/style.css";
49+
50+
// From https://github.com/TypeCellOS/BlockNote/blob/main/packages/react/src/components/FormattingToolbar/DefaultFormattingToolbar.tsx
51+
function CustomFormattingToolbar(props: FormattingToolbarProps) {
52+
return (
53+
<Toolbar>
54+
<BlockTypeDropdown {...props} />
55+
56+
<ImageCaptionButton editor={props.editor} />
57+
<ReplaceImageButton editor={props.editor} />
58+
59+
<ToggledStyleButton editor={props.editor} toggledStyle={"bold"} />
60+
<ToggledStyleButton editor={props.editor} toggledStyle={"italic"} />
61+
<ToggledStyleButton editor={props.editor} toggledStyle={"underline"} />
62+
<ToggledStyleButton editor={props.editor} toggledStyle={"strike"} />
63+
{/* Added code toggle button */}
64+
<ToggledStyleButton editor={props.editor} toggledStyle={"code"} />
65+
66+
<TextAlignButton editor={props.editor as any} textAlignment={"left"} />
67+
<TextAlignButton editor={props.editor as any} textAlignment={"center"} />
68+
<TextAlignButton editor={props.editor as any} textAlignment={"right"} />
69+
70+
<ColorStyleButton editor={props.editor} />
71+
72+
<NestBlockButton editor={props.editor} />
73+
<UnnestBlockButton editor={props.editor} />
74+
75+
<CreateLinkButton editor={props.editor} />
76+
</Toolbar>
77+
);
78+
}
79+
80+
export default function App() {
81+
// Creates a new editor instance.
82+
const editor: BlockNoteEditor = useBlockNote();
83+
84+
// Renders the editor instance using a React component.
85+
return (
86+
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}>
87+
<FormattingToolbarPositioner
88+
editor={editor}
89+
formattingToolbar={CustomFormattingToolbar}
90+
/>
91+
<HyperlinkToolbarPositioner editor={editor} />
92+
<SlashMenuPositioner editor={editor} />
93+
<SideMenuPositioner editor={editor} />
94+
<ImageToolbarPositioner editor={editor} />
95+
<TableHandlesPositioner editor={editor} />
96+
</BlockNoteView>
97+
);
98+
}
99+
100+
```
101+
102+
```css-vue /styles.css [hidden]
103+
{{ getStyles(isDark) }}
104+
```
Loading
Loading
Loading

0 commit comments

Comments
 (0)