Skip to content

Commit a0fdddb

Browse files
authored
feature: expose floatingOptions on react elements
1 parent f53faa1 commit a0fdddb

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

packages/react/src/components/FilePanel/FilePanelController.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
InlineContentSchema,
77
StyleSchema,
88
} from "@blocknote/core";
9-
import { flip, offset } from "@floating-ui/react";
9+
import { UseFloatingOptions, flip, offset } from "@floating-ui/react";
1010
import { FC } from "react";
1111

1212
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
@@ -21,6 +21,7 @@ export const FilePanelController = <
2121
S extends StyleSchema = DefaultStyleSchema
2222
>(props: {
2323
filePanel?: FC<FilePanelProps<I, S>>;
24+
floatingOptions?: Partial<UseFloatingOptions>;
2425
}) => {
2526
const editor = useBlockNoteEditor<B, I, S>();
2627

@@ -47,6 +48,7 @@ export const FilePanelController = <
4748
editor.focus();
4849
}
4950
},
51+
...props.floatingOptions,
5052
}
5153
);
5254

packages/react/src/components/FormattingToolbar/FormattingToolbarController.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
InlineContentSchema,
55
StyleSchema,
66
} from "@blocknote/core";
7-
import { flip, offset } from "@floating-ui/react";
7+
import { UseFloatingOptions, flip, offset } from "@floating-ui/react";
88
import { FC, useMemo, useRef, useState } from "react";
99

1010
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
@@ -32,6 +32,7 @@ const textAlignmentToPlacement = (
3232

3333
export const FormattingToolbarController = (props: {
3434
formattingToolbar?: FC<FormattingToolbarProps>;
35+
floatingOptions?: Partial<UseFloatingOptions>;
3536
}) => {
3637
const divRef = useRef<HTMLDivElement>(null);
3738

@@ -87,6 +88,7 @@ export const FormattingToolbarController = (props: {
8788
editor.focus();
8889
}
8990
},
91+
...props.floatingOptions,
9092
}
9193
);
9294

packages/react/src/components/LinkToolbar/LinkToolbarController.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
InlineContentSchema,
77
StyleSchema,
88
} from "@blocknote/core";
9-
import { flip, offset } from "@floating-ui/react";
9+
import { UseFloatingOptions, flip, offset } from "@floating-ui/react";
1010
import { FC } from "react";
1111

1212
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
@@ -21,6 +21,7 @@ export const LinkToolbarController = <
2121
S extends StyleSchema = DefaultStyleSchema
2222
>(props: {
2323
linkToolbar?: FC<LinkToolbarProps>;
24+
floatingOptions?: Partial<UseFloatingOptions>;
2425
}) => {
2526
const editor = useBlockNoteEditor<BSchema, I, S>();
2627

@@ -47,6 +48,7 @@ export const LinkToolbarController = <
4748
editor.focus();
4849
}
4950
},
51+
...props.floatingOptions,
5052
}
5153
);
5254

packages/react/src/components/SideMenu/SideMenuController.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@blocknote/core";
99
import { FC } from "react";
1010

11+
import { UseFloatingOptions } from "@floating-ui/react";
1112
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
1213
import { useUIElementPositioning } from "../../hooks/useUIElementPositioning.js";
1314
import { useUIPluginState } from "../../hooks/useUIPluginState.js";
@@ -20,6 +21,7 @@ export const SideMenuController = <
2021
S extends StyleSchema = DefaultStyleSchema
2122
>(props: {
2223
sideMenu?: FC<SideMenuProps<BSchema, I, S>>;
24+
floatingOptions?: Partial<UseFloatingOptions>;
2325
}) => {
2426
const editor = useBlockNoteEditor<BSchema, I, S>();
2527

@@ -39,6 +41,7 @@ export const SideMenuController = <
3941
1000,
4042
{
4143
placement: "left-start",
44+
...props.floatingOptions,
4245
}
4346
);
4447

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
StyleSchema,
55
SuggestionMenuState,
66
} from "@blocknote/core";
7-
import { flip, offset, size } from "@floating-ui/react";
7+
import { flip, offset, size, UseFloatingOptions } from "@floating-ui/react";
88
import { FC, useCallback, useMemo } from "react";
99

1010
import { useBlockNoteEditor } from "../../../hooks/useBlockNoteEditor.js";
@@ -35,6 +35,7 @@ export function GridSuggestionMenuController<
3535
getItems?: GetItemsType;
3636
columns: number;
3737
minQueryLength?: number;
38+
floatingOptions?: Partial<UseFloatingOptions>;
3839
} & (ItemType<GetItemsType> extends DefaultReactGridSuggestionItem
3940
? {
4041
// can be undefined
@@ -64,6 +65,7 @@ export function GridSuggestionMenuController<
6465
minQueryLength,
6566
onItemClick,
6667
getItems,
68+
floatingOptions,
6769
} = props;
6870

6971
const onItemClickOrDefault = useMemo(() => {
@@ -124,6 +126,7 @@ export function GridSuggestionMenuController<
124126
editor.suggestionMenus.closeMenu();
125127
}
126128
},
129+
...floatingOptions,
127130
}
128131
);
129132

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import {
55
SuggestionMenuState,
66
filterSuggestionItems,
77
} from "@blocknote/core";
8-
import { flip, offset, shift, size } from "@floating-ui/react";
8+
import {
9+
UseFloatingOptions,
10+
flip,
11+
offset,
12+
shift,
13+
size,
14+
} from "@floating-ui/react";
915
import { FC, useCallback, useMemo } from "react";
1016

1117
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
@@ -32,6 +38,7 @@ export function SuggestionMenuController<
3238
triggerCharacter: string;
3339
getItems?: GetItemsType;
3440
minQueryLength?: number;
41+
floatingOptions?: Partial<UseFloatingOptions>;
3542
} & (ItemType<GetItemsType> extends DefaultReactSuggestionItem
3643
? {
3744
// can be undefined
@@ -60,6 +67,7 @@ export function SuggestionMenuController<
6067
minQueryLength,
6168
onItemClick,
6269
getItems,
70+
floatingOptions,
6371
} = props;
6472

6573
const onItemClickOrDefault = useMemo(() => {
@@ -124,6 +132,7 @@ export function SuggestionMenuController<
124132
editor.suggestionMenus.closeMenu();
125133
}
126134
},
135+
...floatingOptions,
127136
}
128137
);
129138

0 commit comments

Comments
 (0)