@tanstack/devtools 0.4.2 → 0.4.4
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 +30 -3
- 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 +106 -31
- 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 +31 -4
- 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 +108 -33
- 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 +3 -3
- package/src/context/devtools-store.ts +6 -0
- package/src/devtools.tsx +44 -4
- package/src/styles/use-styles.ts +4 -0
- package/src/tabs/settings-tab.tsx +82 -13
- package/src/utils/sanitize.ts +19 -0
package/src/devtools.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Show, createEffect, createSignal } from 'solid-js'
|
|
1
|
+
import { Show, createEffect, createSignal, onCleanup } from 'solid-js'
|
|
2
2
|
import { createShortcut } from '@solid-primitives/keyboard'
|
|
3
3
|
import {
|
|
4
4
|
useDevtoolsSettings,
|
|
@@ -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,50 @@ export default function DevTools() {
|
|
|
131
133
|
}
|
|
132
134
|
})
|
|
133
135
|
createEffect(() => {
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
createEffect(() => {
|
|
155
|
+
// this will only work with the Vite plugin
|
|
156
|
+
const openSourceHandler = (e: Event) => {
|
|
157
|
+
const isShiftHeld = (e as KeyboardEvent).shiftKey
|
|
158
|
+
const isCtrlHeld =
|
|
159
|
+
(e as KeyboardEvent).ctrlKey || (e as KeyboardEvent).metaKey
|
|
160
|
+
if (!isShiftHeld || !isCtrlHeld) return
|
|
161
|
+
|
|
162
|
+
if (e.target instanceof HTMLElement) {
|
|
163
|
+
const dataSource = e.target.getAttribute('data-tsd-source')
|
|
164
|
+
window.getSelection()?.removeAllRanges()
|
|
165
|
+
if (dataSource) {
|
|
166
|
+
e.preventDefault()
|
|
167
|
+
e.stopPropagation()
|
|
168
|
+
fetch(
|
|
169
|
+
`http://localhost:__TSD_PORT__/__tsd/open-source?source=${dataSource}`,
|
|
170
|
+
).catch(() => {})
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
window.addEventListener('click', openSourceHandler)
|
|
175
|
+
onCleanup(() => {
|
|
176
|
+
window.removeEventListener('click', openSourceHandler)
|
|
136
177
|
})
|
|
137
178
|
})
|
|
138
179
|
|
|
139
|
-
createEffect(() => {})
|
|
140
180
|
return (
|
|
141
181
|
<div ref={setRootEl} data-testid={TANSTACK_DEVTOOLS}>
|
|
142
182
|
<Show
|
package/src/styles/use-styles.ts
CHANGED
|
@@ -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
|
+
}
|