@tanstack/devtools 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,31 @@
1
- import { Show } from 'solid-js'
2
- import { Checkbox, Input, Select } from '@tanstack/devtools-ui'
1
+ import { Show, createMemo } from 'solid-js'
2
+ import { Button, Checkbox, Input, Select } from '@tanstack/devtools-ui'
3
3
  import { useDevtoolsSettings } from '../context/use-devtools-context'
4
4
  import { uppercaseFirstLetter } from '../utils/sanitize'
5
5
  import { useStyles } from '../styles/use-styles'
6
+ import type { ModifierKey } from '@solid-primitives/keyboard'
6
7
 
7
8
  export const SettingsTab = () => {
8
9
  const { setSettings, settings } = useDevtoolsSettings()
9
10
  const styles = useStyles()
10
-
11
+ const hotkey = createMemo(() => settings().openHotkey)
12
+ const modifiers: Array<ModifierKey> = ['Control', 'Alt', 'Meta', 'Shift']
13
+ const changeHotkey = (newHotkey: ModifierKey) => () => {
14
+ if (hotkey().includes(newHotkey)) {
15
+ return setSettings({
16
+ openHotkey: hotkey().filter((key) => key !== newHotkey),
17
+ })
18
+ }
19
+ const existingModifiers = hotkey().filter((key) =>
20
+ modifiers.includes(key as any),
21
+ )
22
+ const otherModifiers = hotkey().filter(
23
+ (key) => !modifiers.includes(key as any),
24
+ )
25
+ setSettings({
26
+ openHotkey: [...existingModifiers, newHotkey, ...otherModifiers],
27
+ })
28
+ }
11
29
  return (
12
30
  <div class={styles().settingsContainer}>
13
31
  {/* General Settings */}
@@ -137,20 +155,71 @@ export const SettingsTab = () => {
137
155
  Customize keyboard shortcuts for quick access.
138
156
  </p>
139
157
  <div class={styles().settingsGroup}>
158
+ <div class={styles().settingsModifiers}>
159
+ <Show keyed when={hotkey()}>
160
+ <Button
161
+ variant="success"
162
+ onclick={changeHotkey('Shift')}
163
+ outline={!hotkey().includes('Shift')}
164
+ >
165
+ Shift
166
+ </Button>
167
+ <Button
168
+ variant="success"
169
+ onclick={changeHotkey('Alt')}
170
+ outline={!hotkey().includes('Alt')}
171
+ >
172
+ Alt
173
+ </Button>
174
+ <Button
175
+ variant="success"
176
+ onclick={changeHotkey('Meta')}
177
+ outline={!hotkey().includes('Meta')}
178
+ >
179
+ Meta
180
+ </Button>
181
+ <Button
182
+ variant="success"
183
+ onclick={changeHotkey('Control')}
184
+ outline={!hotkey().includes('Control')}
185
+ >
186
+ Control
187
+ </Button>
188
+ </Show>
189
+ </div>
140
190
  <Input
141
191
  label="Hotkey to open/close devtools"
142
- description="Use '+' to combine keys (e.g., 'Ctrl+Shift+D' or 'Alt+D')"
143
- placeholder="Ctrl+Shift+D"
144
- value={settings().openHotkey.join('+')}
145
- onChange={(e) =>
146
- setSettings({
147
- openHotkey: e
148
- .split('+')
149
- .map((key) => uppercaseFirstLetter(key))
150
- .filter(Boolean),
192
+ description="Use '+' to combine keys (e.g., 'a+b' or 'd'). This will be used with the enabled modifiers from above"
193
+ placeholder="a"
194
+ value={hotkey()
195
+ .filter((key) => !['Shift', 'Meta', 'Alt', 'Ctrl'].includes(key))
196
+ .join('+')}
197
+ onChange={(e) => {
198
+ const makeModifierArray = (key: string) => {
199
+ if (key.length === 1) return [uppercaseFirstLetter(key)]
200
+ const modifiers: Array<string> = []
201
+ for (const character of key) {
202
+ const newLetter = uppercaseFirstLetter(character)
203
+ if (!modifiers.includes(newLetter)) modifiers.push(newLetter)
204
+ }
205
+ return modifiers
206
+ }
207
+ const modifiers = e
208
+ .split('+')
209
+ .flatMap((key) => makeModifierArray(key))
210
+ .filter(Boolean)
211
+ console.log(e, modifiers)
212
+ return setSettings({
213
+ openHotkey: [
214
+ ...hotkey().filter((key) =>
215
+ ['Shift', 'Meta', 'Alt', 'Ctrl'].includes(key),
216
+ ),
217
+ ...modifiers,
218
+ ],
151
219
  })
152
- }
220
+ }}
153
221
  />
222
+ Final shortcut is: {hotkey().join(' + ')}
154
223
  </div>
155
224
  </div>
156
225
 
@@ -9,3 +9,22 @@ export const tryParseJson = <T>(json: string | null): T | undefined => {
9
9
 
10
10
  export const uppercaseFirstLetter = (value: string) =>
11
11
  value.charAt(0).toUpperCase() + value.slice(1)
12
+
13
+ export const getAllPermutations = <T extends any>(arr: Array<T>) => {
14
+ const res: Array<Array<T>> = []
15
+
16
+ function permutate(arr: Array<T>, start: number) {
17
+ if (start === arr.length - 1) {
18
+ res.push([...arr] as any)
19
+ return
20
+ }
21
+ for (let i = start; i < arr.length; i++) {
22
+ ;[arr[start], arr[i]] = [arr[i]!, arr[start]!]
23
+ permutate(arr, start + 1)
24
+ ;[arr[start], arr[i]] = [arr[i]!, arr[start]]
25
+ }
26
+ }
27
+ permutate(arr, 0)
28
+
29
+ return res
30
+ }