Skip to content

Commit 1d5a1ed

Browse files
committed
Merge branch 'main' of github.com:TypeCellOS/BlockNote
2 parents 1a73ecd + 3dfe3e2 commit 1d5a1ed

3 files changed

Lines changed: 30 additions & 17 deletions

File tree

packages/react/src/components/Popovers/GenericPopover.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type GenericPopoverReference =
2727
cacheMountedBoundingClientRect?: boolean;
2828
}
2929
| {
30+
element: undefined;
3031
// When no reference element is provided, this can be provided as an
3132
// alternative "virtual" element to position the popover around.
3233
getBoundingClientRect: () => DOMRect;
@@ -62,7 +63,7 @@ export function getMountedBoundingClientRectCache(
6263

6364
return () => {
6465
if (
65-
"element" in reference &&
66+
reference.element &&
6667
(reference.cacheMountedBoundingClientRect ?? true)
6768
) {
6869
if (reference.element.isConnected) {

packages/react/src/components/SuggestionMenu/GridSuggestionMenu/GridSuggestionMenuController.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
useExtensionState,
1010
} from "../../../hooks/useExtension.js";
1111
import { FloatingUIOptions } from "../../Popovers/FloatingUIOptions.js";
12-
import { GenericPopover } from "../../Popovers/GenericPopover.js";
12+
import {
13+
GenericPopover,
14+
GenericPopoverReference,
15+
} from "../../Popovers/GenericPopover.js";
1316
import { getDefaultReactEmojiPickerItems } from "./getDefaultReactEmojiPickerItems.js";
1417
import { GridSuggestionMenu } from "./GridSuggestionMenu.js";
1518
import { GridSuggestionMenuWrapper } from "./GridSuggestionMenuWrapper.js";
@@ -95,13 +98,16 @@ export function GridSuggestionMenuController<
9598

9699
const state = useExtensionState(SuggestionMenu);
97100
const reference = useExtensionState(SuggestionMenu, {
98-
selector: (state) => ({
99-
// Use first child as the editor DOM element may itself be scrollable.
100-
// For FloatingUI to auto-update the position during scrolling, the
101-
// `contextElement` must be a descendant of the scroll container.
102-
element: editor.domElement?.firstChild || undefined,
103-
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
104-
}),
101+
selector: (state) =>
102+
({
103+
// Use first child as the editor DOM element may itself be scrollable.
104+
// For FloatingUI to auto-update the position during scrolling, the
105+
// `contextElement` must be a descendant of the scroll container.
106+
element: (editor.domElement?.firstChild || undefined) as
107+
| Element
108+
| undefined,
109+
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
110+
}) satisfies GenericPopoverReference,
105111
});
106112

107113
const floatingUIOptions = useMemo<FloatingUIOptions>(

packages/react/src/components/SuggestionMenu/SuggestionMenuController.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { FC, useEffect, useMemo } from "react";
99
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
1010
import { useExtension, useExtensionState } from "../../hooks/useExtension.js";
1111
import { FloatingUIOptions } from "../Popovers/FloatingUIOptions.js";
12-
import { GenericPopover } from "../Popovers/GenericPopover.js";
12+
import {
13+
GenericPopover,
14+
GenericPopoverReference,
15+
} from "../Popovers/GenericPopover.js";
1316
import { SuggestionMenu } from "./SuggestionMenu.js";
1417
import { SuggestionMenuWrapper } from "./SuggestionMenuWrapper.js";
1518
import { getDefaultReactSlashMenuItems } from "./getDefaultReactSlashMenuItems.js";
@@ -90,13 +93,16 @@ export function SuggestionMenuController<
9093

9194
const state = useExtensionState(SuggestionMenuExtension);
9295
const reference = useExtensionState(SuggestionMenuExtension, {
93-
selector: (state) => ({
94-
// Use first child as the editor DOM element may itself be scrollable.
95-
// For FloatingUI to auto-update the position during scrolling, the
96-
// `contextElement` must be a descendant of the scroll container.
97-
element: editor.domElement?.firstChild || undefined,
98-
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
99-
}),
96+
selector: (state) =>
97+
({
98+
// Use first child as the editor DOM element may itself be scrollable.
99+
// For FloatingUI to auto-update the position during scrolling, the
100+
// `contextElement` must be a descendant of the scroll container.
101+
element: (editor.domElement?.firstChild || undefined) as
102+
| Element
103+
| undefined,
104+
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
105+
}) satisfies GenericPopoverReference,
100106
});
101107

102108
const floatingUIOptions = useMemo<FloatingUIOptions>(

0 commit comments

Comments
 (0)