Skip to content

Commit 6791ae9

Browse files
committed
Misc fixes after review
1 parent cfadef4 commit 6791ae9

File tree

32 files changed

+145
-244
lines changed

32 files changed

+145
-244
lines changed

examples/03-ui-components/04-side-menu-buttons/src/RemoveBlockButton.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SideMenuExtension } from "@blocknote/core/extensions";
33
import {
44
useBlockNoteEditor,
55
useComponentsContext,
6-
useExtension,
6+
useExtensionState,
77
} from "@blocknote/react";
88
import { MdDelete } from "react-icons/md";
99

@@ -13,7 +13,13 @@ export function RemoveBlockButton() {
1313

1414
const Components = useComponentsContext()!;
1515

16-
const sideMenu = useExtension(SideMenuExtension);
16+
const block = useExtensionState(SideMenuExtension, {
17+
selector: (state) => state?.block,
18+
});
19+
20+
if (!block) {
21+
return null;
22+
}
1723

1824
return (
1925
<Components.SideMenu.Button
@@ -22,7 +28,7 @@ export function RemoveBlockButton() {
2228
<MdDelete
2329
size={24}
2430
onClick={() => {
25-
editor.removeBlocks([sideMenu.store.state!.block]);
31+
editor.removeBlocks([block]);
2632
}}
2733
/>
2834
}

examples/03-ui-components/05-side-menu-drag-handle-items/src/ResetBlockTypeItem.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SideMenuExtension } from "@blocknote/core/extensions";
33
import {
44
useBlockNoteEditor,
55
useComponentsContext,
6-
useExtension,
6+
useExtensionState,
77
} from "@blocknote/react";
88
import { ReactNode } from "react";
99

@@ -12,12 +12,18 @@ export function ResetBlockTypeItem(props: { children: ReactNode }) {
1212

1313
const Components = useComponentsContext()!;
1414

15-
const sideMenu = useExtension(SideMenuExtension);
15+
const block = useExtensionState(SideMenuExtension, {
16+
selector: (state) => state?.block,
17+
});
18+
19+
if (!block) {
20+
return null;
21+
}
1622

1723
return (
1824
<Components.Generic.Menu.Item
1925
onClick={() => {
20-
editor.updateBlock(sideMenu.store.state!.block, { type: "paragraph" });
26+
editor.updateBlock(block, { type: "paragraph" });
2127
}}
2228
>
2329
{props.children}

examples/03-ui-components/13-custom-ui/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { } from "@blocknote/core";
21
import { filterSuggestionItems } from "@blocknote/core/extensions";
32
import "@blocknote/core/fonts/inter.css";
43
import {

examples/03-ui-components/13-custom-ui/src/MUIFormattingToolbar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function MUIToolbarSelect<Item extends { name: string; icon?: FC }>(props: {
108108
function MUIBlockTypeSelect() {
109109
const editor = useBlockNoteEditor<TextBlockSchema>();
110110

111+
// The block currently containing the text cursor.
111112
const block = useEditorState({
112113
editor,
113114
selector: ({ editor }) => editor.getTextCursorPosition().block,

examples/03-ui-components/13-custom-ui/src/MUISideMenu.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function MUIRemoveBlockItem(
2626
) {
2727
const editor = useBlockNoteEditor();
2828
const sideMenu = useExtension(SideMenuExtension, { editor });
29+
2930
// Deletes the block next to the side menu.
3031
const onClick = useCallback(() => {
3132
sideMenu.unfreezeMenu();
@@ -83,6 +84,11 @@ function MUIDragHandleButton(props: SideMenuProps) {
8384

8485
const editor = useBlockNoteEditor();
8586
const sideMenu = useExtension(SideMenuExtension, { editor });
87+
const block = useExtensionState(SideMenuExtension, {
88+
editor,
89+
selector: (state) => state?.block,
90+
});
91+
8692
// Handles opening and closing the drag handle menu.
8793
const onClick = useCallback(
8894
(event: MouseEvent<HTMLButtonElement>) => {
@@ -95,16 +101,18 @@ function MUIDragHandleButton(props: SideMenuProps) {
95101
setAnchorEl(null);
96102
}, []);
97103

104+
if (!block) {
105+
return null;
106+
}
107+
98108
return (
99109
<>
100110
<IconButton
101111
size={"small"}
102112
component={"button"}
103113
draggable={"true"}
104114
onClick={onClick}
105-
onDragStart={(e) =>
106-
sideMenu.blockDragStart(e, sideMenu.store.state!.block)
107-
}
115+
onDragStart={(e) => sideMenu.blockDragStart(e, block)}
108116
onDragEnd={sideMenu.blockDragEnd}
109117
>
110118
<DragIndicator
@@ -132,7 +140,6 @@ function MUISideMenu(props: SideMenuProps & { children: ReactNode }) {
132140
// centered.
133141
const sideMenuHeight = useExtensionState(SideMenuExtension, {
134142
selector: (state) => {
135-
// TODO this feels like a hack
136143
if (state && state.block.type === "heading") {
137144
if (state.block.props.level === 1) {
138145
return 78;

examples/07-collaboration/05-comments/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ function Document() {
7575
// setup the editor with comments and collaboration
7676
const editor = useCreateBlockNote(
7777
{
78-
extensions: [CommentsExtension({ threadStore, resolveUsers })],
7978
collaboration: {
8079
provider,
8180
fragment: doc.getXmlFragment("blocknote"),
8281
user: { color: getRandomColor(), name: activeUser.username },
8382
},
83+
extensions: [CommentsExtension({ threadStore, resolveUsers })],
8484
},
8585
[activeUser, threadStore],
8686
);

packages/core/src/blocks/Table/block.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Node, mergeAttributes } from "@tiptap/core";
22
import { DOMParser, Fragment, Node as PMNode, Schema } from "prosemirror-model";
33
import { CellSelection, TableView } from "prosemirror-tables";
44
import { NodeView } from "prosemirror-view";
5+
56
import { createExtension } from "../../editor/BlockNoteExtension.js";
67
import {
78
BlockConfig,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from "./extension.js";
2+
export * from "./mark.js";
13
export * from "./threadstore/DefaultThreadStoreAuth.js";
24
export * from "./threadstore/ThreadStore.js";
35
export * from "./threadstore/ThreadStoreAuth.js";
@@ -6,5 +8,3 @@ export * from "./threadstore/yjs/RESTYjsThreadStore.js";
68
export * from "./threadstore/yjs/YjsThreadStore.js";
79
export * from "./threadstore/yjs/YjsThreadStoreBase.js";
810
export * from "./types.js";
9-
export * from "./extension.js";
10-
export * from "./mark.js";

packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { Block, PartialBlock } from "../../blocks/defaultBlocks.js";
2-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3-
42
import { editorHasBlockWithType } from "../../blocks/defaultBlockTypeGuards.js";
3+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
54
import {
65
BlockSchema,
76
InlineContentSchema,
87
StyleSchema,
98
isStyledTextInlineContent,
109
} from "../../schema/index.js";
1110
import { formatKeyboardShortcut } from "../../util/browser.js";
12-
import { DefaultSuggestionItem } from "./DefaultSuggestionItem.js";
1311
import { FilePanelExtension } from "../FilePanel/FilePanel.js";
12+
import { DefaultSuggestionItem } from "./DefaultSuggestionItem.js";
1413
import { SuggestionMenu } from "./SuggestionMenu.js";
1514

1615
// Sets the editor's text cursor position to the next content editable block,

packages/react/src/blocks/File/helpers/render/AddFileButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { FilePanelExtension } from "@blocknote/core/extensions";
33
import { ReactNode, useCallback } from "react";
44
import { RiFile2Line } from "react-icons/ri";
55

6+
import { useBlockNoteEditor } from "../../../../hooks/useBlockNoteEditor.js";
7+
import { useExtension } from "../../../../hooks/useExtension.js";
68
import { useDictionary } from "../../../../i18n/dictionary.js";
79
import { ReactCustomBlockRenderProps } from "../../../../schema/ReactBlockSpec.js";
8-
import { useExtension } from "../../../../hooks/useExtension.js";
9-
import { useBlockNoteEditor } from "../../../../hooks/useBlockNoteEditor.js";
1010

1111
export const AddFileButton = (
1212
props: Omit<

0 commit comments

Comments
 (0)