@@ -3,16 +3,11 @@ import {
33 useState ,
44 useEffect ,
55 useCallback ,
6- ReactNode ,
76 useRef ,
87 useLayoutEffect ,
98} from "react" ;
10-
11- interface CommandItemProps {
12- title : string ;
13- description : string ;
14- icon : ReactNode ;
15- }
9+ import { SlashCommandItem } from "./slash-command" ;
10+ //https://github.com/steven-tey/novel from steven-tey helped a lot with this implmentation
1611
1712export const updateScrollView = ( container : HTMLElement , item : HTMLElement ) => {
1813 const containerHeight = container . offsetHeight ;
@@ -35,8 +30,8 @@ export const CommandMenu = React.forwardRef(
3530 command,
3631 editor,
3732 } : {
38- items : CommandItemProps [ ] ;
39- command : ( item : CommandItemProps ) => void ;
33+ items : SlashCommandItem [ ] ;
34+ command : ( item : SlashCommandItem ) => void ;
4035 editor : any ;
4136 } ,
4237 ref
@@ -70,20 +65,18 @@ export const CommandMenu = React.forwardRef(
7065 } ) ) ;
7166
7267 useEffect ( ( ) => {
73- const navigationKeys = [ "ArrowUp" , "ArrowDown" ] ;
7468 const onKeyDown = ( e : KeyboardEvent ) => {
75- if ( navigationKeys . includes ( e . key ) ) {
69+ if ( e . key === "ArrowUp" ) {
7670 e . preventDefault ( ) ;
77- if ( e . key === "ArrowUp" ) {
78- setSelectedIndex ( ( selectedIndex + items . length - 1 ) % items . length ) ;
79- return true ;
80- }
81- if ( e . key === "ArrowDown" ) {
82- setSelectedIndex ( ( selectedIndex + 1 ) % items . length ) ;
83- return true ;
84- }
85- return false ;
71+ setSelectedIndex ( ( selectedIndex + items . length - 1 ) % items . length ) ;
72+ return true ;
8673 }
74+ if ( e . key === "ArrowDown" ) {
75+ e . preventDefault ( ) ;
76+ setSelectedIndex ( ( selectedIndex + 1 ) % items . length ) ;
77+ return true ;
78+ }
79+ return false ;
8780 } ;
8881 document . addEventListener ( "keydown" , onKeyDown ) ;
8982 return ( ) => {
@@ -111,7 +104,7 @@ export const CommandMenu = React.forwardRef(
111104 ref = { commandListContainer }
112105 className = "eddies-z-50 eddies-h-auto eddies-max-h-[330px] eddies-w-72 eddies-overflow-y-auto eddies-rounded-md eddies-bg-color-bg eddies-px-1 eddies-py-2 eddies-transition-all"
113106 >
114- { items . map ( ( item : CommandItemProps , index : number ) => {
107+ { items . map ( ( item : SlashCommandItem , index : number ) => {
115108 return (
116109 < button
117110 className = { `eddies-flex eddies-w-full eddies-items-center eddies-space-x-2 eddies-rounded-md eddies-px-2 eddies-py-1 eddies-text-left eddies-text-sm eddies-text-color-text hover:eddies-bg-color-bg-secondary ${
0 commit comments