@tanstack/devtools 0.4.1 → 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.
Files changed (37) hide show
  1. package/dist/cjs/context/devtools-context.cjs +1 -1
  2. package/dist/cjs/context/devtools-context.cjs.map +1 -1
  3. package/dist/cjs/context/devtools-store.cjs +7 -0
  4. package/dist/cjs/context/devtools-store.cjs.map +1 -1
  5. package/dist/cjs/context/devtools-store.d.cts +1 -0
  6. package/dist/cjs/devtools.cjs +11 -5
  7. package/dist/cjs/devtools.cjs.map +1 -1
  8. package/dist/cjs/styles/use-styles.cjs +4 -0
  9. package/dist/cjs/styles/use-styles.cjs.map +1 -1
  10. package/dist/cjs/styles/use-styles.d.cts +1 -0
  11. package/dist/cjs/tabs/settings-tab.cjs +93 -18
  12. package/dist/cjs/tabs/settings-tab.cjs.map +1 -1
  13. package/dist/cjs/utils/sanitize.cjs +17 -0
  14. package/dist/cjs/utils/sanitize.cjs.map +1 -1
  15. package/dist/cjs/utils/sanitize.d.cts +1 -0
  16. package/dist/esm/context/devtools-context.js +1 -1
  17. package/dist/esm/context/devtools-context.js.map +1 -1
  18. package/dist/esm/context/devtools-store.d.ts +1 -0
  19. package/dist/esm/context/devtools-store.js +8 -1
  20. package/dist/esm/context/devtools-store.js.map +1 -1
  21. package/dist/esm/devtools.js +11 -5
  22. package/dist/esm/devtools.js.map +1 -1
  23. package/dist/esm/styles/use-styles.d.ts +1 -0
  24. package/dist/esm/styles/use-styles.js +4 -0
  25. package/dist/esm/styles/use-styles.js.map +1 -1
  26. package/dist/esm/tabs/settings-tab.js +95 -20
  27. package/dist/esm/tabs/settings-tab.js.map +1 -1
  28. package/dist/esm/utils/sanitize.d.ts +1 -0
  29. package/dist/esm/utils/sanitize.js +17 -0
  30. package/dist/esm/utils/sanitize.js.map +1 -1
  31. package/package.json +2 -2
  32. package/src/context/devtools-context.tsx +1 -1
  33. package/src/context/devtools-store.ts +6 -0
  34. package/src/devtools.tsx +18 -4
  35. package/src/styles/use-styles.ts +4 -0
  36. package/src/tabs/settings-tab.tsx +82 -13
  37. package/src/utils/sanitize.ts +19 -0
package/src/devtools.tsx CHANGED
@@ -12,6 +12,8 @@ import { MainPanel } from './components/main-panel'
12
12
  import { ContentPanel } from './components/content-panel'
13
13
  import { Tabs } from './components/tabs'
14
14
  import { TabContent } from './components/tab-content'
15
+ import { keyboardModifiers } from './context/devtools-store'
16
+ import { getAllPermutations } from './utils/sanitize'
15
17
 
16
18
  export default function DevTools() {
17
19
  const { settings } = useDevtoolsSettings()
@@ -131,12 +133,24 @@ export default function DevTools() {
131
133
  }
132
134
  })
133
135
  createEffect(() => {
134
- createShortcut(settings().openHotkey, () => {
135
- toggleOpen()
136
- })
136
+ // we create all combinations of modifiers
137
+ const modifiers = settings().openHotkey.filter((key) =>
138
+ keyboardModifiers.includes(key as any),
139
+ )
140
+ const nonModifiers = settings().openHotkey.filter(
141
+ (key) => !keyboardModifiers.includes(key as any),
142
+ )
143
+
144
+ const allModifierCombinations = getAllPermutations(modifiers)
145
+
146
+ for (const combination of allModifierCombinations) {
147
+ const permutation = [...combination, ...nonModifiers]
148
+ createShortcut(permutation, () => {
149
+ toggleOpen()
150
+ })
151
+ }
137
152
  })
138
153
 
139
- createEffect(() => {})
140
154
  return (
141
155
  <div ref={setRootEl} data-testid={TANSTACK_DEVTOOLS}>
142
156
  <Show
@@ -313,6 +313,10 @@ const stylesFactory = () => {
313
313
  grid-template-columns: 1fr;
314
314
  }
315
315
  `,
316
+ settingsModifiers: css`
317
+ display: flex;
318
+ gap: 0.5rem;
319
+ `,
316
320
  }
317
321
  }
318
322
 
@@ -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
+ }