import React from "react" ; import { ActionMenuItemProvider , IActionMenuItem , NoteActionMenu } from "./NoteActionMenu" ; import { deepMemo } from "../react/ReactUtils" ; import { BlockIDStr } from "./store/BlocksStore" ; function useItemsProvider ( ) { const defaultAction = ( ) => { return undefined ; } ; const items = React . useMemo ( ( ) : ReadonlyArray < IActionMenuItem > => [ { id : 'today' , text : 'Today' , action : defaultAction } , { id : 'tomorrow' , text : 'Tomorrow' , action : defaultAction } , { id : 'table' , text : 'Table' , action : ( id ) => { return undefined ; } } , ] , [ ] ) ; return React . useCallback ( ( prompt ) : ReadonlyArray < IActionMenuItem > => { const predicate = ( item ) => { return prompt === undefined || item . text . toLowerCase ( ) . indexOf ( prompt . toLowerCase ( ) ) !== - 1 ; } ; return items . filter ( predicate ) ; } , [ items ] ) ; } interface IProps { readonly id : BlockIDStr ; readonly children : JSX . Element ; } export const NoteActionMenuForCommands = deepMemo ( function NoteActionMenuForCommands ( props ) { const itemsProvider = useItemsProvider ( ) ; return ( < NoteActionMenu id = { props . id } trigger = '/' itemsProvider = { itemsProvider } > { props . children } < /NoteActionMenu>); } ) ;