@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.
- package/dist/cjs/context/devtools-store.cjs +7 -0
- package/dist/cjs/context/devtools-store.cjs.map +1 -1
- package/dist/cjs/context/devtools-store.d.cts +1 -0
- package/dist/cjs/devtools.cjs +11 -5
- package/dist/cjs/devtools.cjs.map +1 -1
- package/dist/cjs/styles/use-styles.cjs +4 -0
- package/dist/cjs/styles/use-styles.cjs.map +1 -1
- package/dist/cjs/styles/use-styles.d.cts +1 -0
- package/dist/cjs/tabs/settings-tab.cjs +93 -18
- package/dist/cjs/tabs/settings-tab.cjs.map +1 -1
- package/dist/cjs/utils/sanitize.cjs +17 -0
- package/dist/cjs/utils/sanitize.cjs.map +1 -1
- package/dist/cjs/utils/sanitize.d.cts +1 -0
- package/dist/esm/context/devtools-store.d.ts +1 -0
- package/dist/esm/context/devtools-store.js +8 -1
- package/dist/esm/context/devtools-store.js.map +1 -1
- package/dist/esm/devtools.js +11 -5
- package/dist/esm/devtools.js.map +1 -1
- package/dist/esm/styles/use-styles.d.ts +1 -0
- package/dist/esm/styles/use-styles.js +4 -0
- package/dist/esm/styles/use-styles.js.map +1 -1
- package/dist/esm/tabs/settings-tab.js +95 -20
- package/dist/esm/tabs/settings-tab.js.map +1 -1
- package/dist/esm/utils/sanitize.d.ts +1 -0
- package/dist/esm/utils/sanitize.js +17 -0
- package/dist/esm/utils/sanitize.js.map +1 -1
- package/package.json +1 -1
- package/src/context/devtools-store.ts +6 -0
- package/src/devtools.tsx +18 -4
- package/src/styles/use-styles.ts +4 -0
- package/src/tabs/settings-tab.tsx +82 -13
- package/src/utils/sanitize.ts +19 -0
|
@@ -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., '
|
|
143
|
-
placeholder="
|
|
144
|
-
value={
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
package/src/utils/sanitize.ts
CHANGED
|
@@ -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
|
+
}
|