1- import { Show , createMemo } from 'solid-js'
1+ import { Show } from 'solid-js'
22import {
3- Button ,
43 Checkbox ,
54 Input ,
65 MainPanel ,
@@ -16,32 +15,18 @@ import {
1615 Link ,
1716 SettingsCog ,
1817} from '@tanstack/devtools-ui/icons'
18+
1919import { useDevtoolsSettings } from '../context/use-devtools-context'
20- import { uppercaseFirstLetter } from '../utils/sanitize'
2120import { useStyles } from '../styles/use-styles'
22- import type { ModifierKey } from '@solid-primitives/keyboard'
21+ import { HotkeyConfig } from './hotkey-config'
22+ import type { KeyboardKey } from '../context/devtools-store'
2323
2424export const SettingsTab = ( ) => {
2525 const { setSettings, settings } = useDevtoolsSettings ( )
2626 const styles = useStyles ( )
27- const hotkey = createMemo ( ( ) => settings ( ) . openHotkey )
28- const modifiers : Array < ModifierKey > = [ 'Control' , 'Alt' , 'Meta' , 'Shift' ]
29- const changeHotkey = ( newHotkey : ModifierKey ) => ( ) => {
30- if ( hotkey ( ) . includes ( newHotkey ) ) {
31- return setSettings ( {
32- openHotkey : hotkey ( ) . filter ( ( key ) => key !== newHotkey ) ,
33- } )
34- }
35- const existingModifiers = hotkey ( ) . filter ( ( key ) =>
36- modifiers . includes ( key as any ) ,
37- )
38- const otherModifiers = hotkey ( ) . filter (
39- ( key ) => ! modifiers . includes ( key as any ) ,
40- )
41- setSettings ( {
42- openHotkey : [ ...existingModifiers , newHotkey , ...otherModifiers ] ,
43- } )
44- }
27+
28+ const modifiers : Array < KeyboardKey > = [ 'CtrlOrMeta' , 'Alt' , 'Shift' ]
29+
4530 return (
4631 < MainPanel withPadding >
4732 < Section >
@@ -144,71 +129,23 @@ export const SettingsTab = () => {
144129 < SectionDescription >
145130 Customize keyboard shortcuts for quick access.
146131 </ SectionDescription >
147- < div class = { styles ( ) . settingsGroup } >
148- < div class = { styles ( ) . settingsModifiers } >
149- < Show keyed when = { hotkey ( ) } >
150- < Button
151- variant = "success"
152- onclick = { changeHotkey ( 'Shift' ) }
153- outline = { ! hotkey ( ) . includes ( 'Shift' ) }
154- >
155- Shift
156- </ Button >
157- < Button
158- variant = "success"
159- onclick = { changeHotkey ( 'Alt' ) }
160- outline = { ! hotkey ( ) . includes ( 'Alt' ) }
161- >
162- Alt
163- </ Button >
164- < Button
165- variant = "success"
166- onclick = { changeHotkey ( 'Meta' ) }
167- outline = { ! hotkey ( ) . includes ( 'Meta' ) }
168- >
169- Meta
170- </ Button >
171- < Button
172- variant = "success"
173- onclick = { changeHotkey ( 'Control' ) }
174- outline = { ! hotkey ( ) . includes ( 'Control' ) }
175- >
176- Control
177- </ Button >
178- </ Show >
179- </ div >
180- < Input
181- label = "Hotkey to open/close devtools"
182- description = "Use '+' to combine keys (e.g., 'a+b' or 'd'). This will be used with the enabled modifiers from above"
183- placeholder = "a"
184- value = { hotkey ( )
185- . filter ( ( key ) => ! [ 'Shift' , 'Meta' , 'Alt' , 'Ctrl' ] . includes ( key ) )
186- . join ( '+' ) }
187- onChange = { ( e ) => {
188- const makeModifierArray = ( key : string ) => {
189- if ( key . length === 1 ) return [ uppercaseFirstLetter ( key ) ]
190- const modifiers : Array < string > = [ ]
191- for ( const character of key ) {
192- const newLetter = uppercaseFirstLetter ( character )
193- if ( ! modifiers . includes ( newLetter ) ) modifiers . push ( newLetter )
194- }
195- return modifiers
196- }
197- const modifiers = e
198- . split ( '+' )
199- . flatMap ( ( key ) => makeModifierArray ( key ) )
200- . filter ( Boolean )
201- return setSettings ( {
202- openHotkey : [
203- ...hotkey ( ) . filter ( ( key ) =>
204- [ 'Shift' , 'Meta' , 'Alt' , 'Ctrl' ] . includes ( key ) ,
205- ) ,
206- ...modifiers ,
207- ] ,
208- } )
209- } }
132+
133+ < div class = { styles ( ) . settingsStack } >
134+ < HotkeyConfig
135+ title = "Open/Close Devtools"
136+ description = "Hotkey to open/close devtools"
137+ hotkey = { settings ( ) . openHotkey }
138+ modifiers = { modifiers }
139+ onHotkeyChange = { ( hotkey ) => setSettings ( { openHotkey : hotkey } ) }
140+ />
141+
142+ < HotkeyConfig
143+ title = "Source Inspector"
144+ description = "Hotkey to open source inspector"
145+ hotkey = { settings ( ) . inspectHotkey }
146+ modifiers = { modifiers }
147+ onHotkeyChange = { ( hotkey ) => setSettings ( { inspectHotkey : hotkey } ) }
210148 />
211- Final shortcut is: { hotkey ( ) . join ( ' + ' ) }
212149 </ div >
213150 </ Section >
214151
0 commit comments