Skip to content

Commit 61f881e

Browse files
authored
fix: conditionally access the TableHandles extension from React (#2248)
1 parent ca26d5c commit 61f881e

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

packages/react/src/components/FormattingToolbar/DefaultButtons/TableCellMergeButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useEditorState } from "../../../hooks/useEditorState.js";
1313
import { useExtension } from "../../../hooks/useExtension.js";
1414
import { useDictionary } from "../../../i18n/dictionary.js";
1515

16-
export const TableCellMergeButton = () => {
16+
const TableCellMergeButtonInner = () => {
1717
const dict = useDictionary();
1818
const Components = useComponentsContext()!;
1919

@@ -77,3 +77,11 @@ export const TableCellMergeButton = () => {
7777
/>
7878
);
7979
};
80+
81+
export const TableCellMergeButton = () => {
82+
const editor = useBlockNoteEditor();
83+
if (!editor.getExtension(TableHandlesExtension)) {
84+
return null;
85+
}
86+
return <TableCellMergeButtonInner />;
87+
};

packages/react/src/components/FormattingToolbar/DefaultButtons/TextAlignButton.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
import { useComponentsContext } from "../../../editor/ComponentsContext.js";
2323
import { useBlockNoteEditor } from "../../../hooks/useBlockNoteEditor.js";
2424
import { useEditorState } from "../../../hooks/useEditorState.js";
25-
import { useExtension } from "../../../hooks/useExtension.js";
2625
import { useDictionary } from "../../../i18n/dictionary.js";
2726

2827
type TextAlignment = DefaultProps["textAlignment"];
@@ -44,8 +43,6 @@ export const TextAlignButton = (props: { textAlignment: TextAlignment }) => {
4443
StyleSchema
4544
>();
4645

47-
const tableHandles = useExtension(TableHandlesExtension);
48-
4946
const state = useEditorState({
5047
editor,
5148
selector: ({ editor }) => {
@@ -74,7 +71,10 @@ export const TextAlignButton = (props: { textAlignment: TextAlignment }) => {
7471
selectedBlocks.length === 1 &&
7572
blockHasType(firstBlock, editor, "table")
7673
) {
77-
const cellSelection = tableHandles.getCellSelection();
74+
const cellSelection = editor
75+
.getExtension(TableHandlesExtension)
76+
?.getCellSelection();
77+
7878
if (!cellSelection) {
7979
return undefined;
8080
}
@@ -112,7 +112,9 @@ export const TextAlignButton = (props: { textAlignment: TextAlignment }) => {
112112
props: { textAlignment: textAlignment },
113113
});
114114
} else if (block.type === "table") {
115-
const cellSelection = tableHandles.getCellSelection();
115+
const cellSelection = editor
116+
.getExtension(TableHandlesExtension)
117+
?.getCellSelection();
116118
if (!cellSelection) {
117119
continue;
118120
}
@@ -148,7 +150,7 @@ export const TextAlignButton = (props: { textAlignment: TextAlignment }) => {
148150
}
149151
}
150152
},
151-
[editor, state, tableHandles],
153+
[editor, state],
152154
);
153155

154156
if (state === undefined) {

0 commit comments

Comments
 (0)