11import { BlockSchema , InlineContentSchema , StyleSchema } from "@blocknote/core" ;
22import { SuggestionMenu } from "@blocknote/core/extensions" ;
3- import { flip , offset , shift , size } from "@floating-ui/react" ;
3+ import { autoPlacement , offset , shift , size } from "@floating-ui/react" ;
44import { FC , useEffect , useMemo } from "react" ;
55
66import { useBlockNoteEditor } from "../../../hooks/useBlockNoteEditor.js" ;
@@ -9,10 +9,7 @@ import {
99 useExtensionState ,
1010} from "../../../hooks/useExtension.js" ;
1111import { FloatingUIOptions } from "../../Popovers/FloatingUIOptions.js" ;
12- import {
13- GenericPopover ,
14- GenericPopoverReference ,
15- } from "../../Popovers/GenericPopover.js" ;
12+ import { GenericPopover } from "../../Popovers/GenericPopover.js" ;
1613import { getDefaultReactEmojiPickerItems } from "./getDefaultReactEmojiPickerItems.js" ;
1714import { GridSuggestionMenu } from "./GridSuggestionMenu.js" ;
1815import { GridSuggestionMenuWrapper } from "./GridSuggestionMenuWrapper.js" ;
@@ -97,20 +94,15 @@ export function GridSuggestionMenuController<
9794 } , [ suggestionMenu , triggerCharacter ] ) ;
9895
9996 const state = useExtensionState ( SuggestionMenu ) ;
100- const referencePos = useExtensionState ( SuggestionMenu , {
101- selector : ( state ) => state ?. referencePos || new DOMRect ( ) ,
102- } ) ;
103-
104- const reference = useMemo < GenericPopoverReference > (
105- ( ) => ( {
97+ const reference = useExtensionState ( SuggestionMenu , {
98+ selector : ( state ) => ( {
10699 // Use first child as the editor DOM element may itself be scrollable.
107100 // For FloatingUI to auto-update the position during scrolling, the
108101 // `contextElement` must be a descendant of the scroll container.
109102 element : editor . domElement ?. firstChild || undefined ,
110- getBoundingClientRect : ( ) => referencePos ,
103+ getBoundingClientRect : ( ) => state ?. referencePos || new DOMRect ( ) ,
111104 } ) ,
112- [ editor . domElement ?. firstChild , referencePos ] ,
113- ) ;
105+ } ) ;
114106
115107 const floatingUIOptions = useMemo < FloatingUIOptions > (
116108 ( ) => ( {
@@ -126,17 +118,16 @@ export function GridSuggestionMenuController<
126118 offset ( 10 ) ,
127119 // Flips the menu placement to maximize the space available, and prevents
128120 // the menu from being cut off by the confines of the screen.
129- flip ( {
130- mainAxis : true ,
131- crossAxis : false ,
121+ autoPlacement ( {
122+ allowedPlacements : [ "bottom-start" , "top-start" ] ,
123+ padding : 10 ,
132124 } ) ,
133125 shift ( ) ,
134126 size ( {
135- apply ( { availableHeight, elements } ) {
136- Object . assign ( elements . floating . style , {
137- maxHeight : `${ availableHeight - 10 } px` ,
138- } ) ;
127+ apply ( { elements, availableHeight } ) {
128+ elements . floating . style . maxHeight = `${ Math . max ( 0 , availableHeight ) } px` ;
139129 } ,
130+ padding : 10 ,
140131 } ) ,
141132 ] ,
142133 } ,
0 commit comments