@tanstack/solid-hotkeys 0.8.3 → 0.9.0
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/README.md +1 -0
- package/dist/createHotkey.cjs +20 -18
- package/dist/createHotkey.cjs.map +1 -1
- package/dist/createHotkey.js +21 -19
- package/dist/createHotkey.js.map +1 -1
- package/dist/createHotkeyRegistrations.cjs +26 -0
- package/dist/createHotkeyRegistrations.cjs.map +1 -0
- package/dist/createHotkeyRegistrations.d.cts +26 -0
- package/dist/createHotkeyRegistrations.d.ts +26 -0
- package/dist/createHotkeyRegistrations.js +26 -0
- package/dist/createHotkeyRegistrations.js.map +1 -0
- package/dist/createHotkeySequence.cjs +20 -18
- package/dist/createHotkeySequence.cjs.map +1 -1
- package/dist/createHotkeySequence.js +21 -19
- package/dist/createHotkeySequence.js.map +1 -1
- package/dist/createHotkeySequences.cjs +26 -24
- package/dist/createHotkeySequences.cjs.map +1 -1
- package/dist/createHotkeySequences.js +27 -25
- package/dist/createHotkeySequences.js.map +1 -1
- package/dist/createHotkeys.cjs +26 -24
- package/dist/createHotkeys.cjs.map +1 -1
- package/dist/createHotkeys.js +27 -25
- package/dist/createHotkeys.js.map +1 -1
- package/dist/createKeyHold.cjs.map +1 -1
- package/dist/createKeyHold.d.cts +2 -2
- package/dist/createKeyHold.d.ts +2 -2
- package/dist/createKeyHold.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +3 -3
- package/src/createHotkey.ts +29 -24
- package/src/createHotkeyRegistrations.ts +45 -0
- package/src/createHotkeySequence.ts +29 -24
- package/src/createHotkeySequences.ts +35 -30
- package/src/createHotkeys.ts +37 -32
- package/src/createKeyHold.ts +4 -2
- package/src/index.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from 'solid-js'
|
|
1
|
+
import { createEffect, onCleanup, untrack } from 'solid-js'
|
|
2
2
|
import { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'
|
|
3
3
|
import { useDefaultHotkeysOptions } from './HotkeysProvider'
|
|
4
4
|
import type {
|
|
@@ -119,32 +119,37 @@ export function createHotkeySequence(
|
|
|
119
119
|
|
|
120
120
|
const sequenceKey = formatHotkeySequence(resolvedSequence)
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
// Untrack store mutations so that registering/updating the sequence doesn't
|
|
123
|
+
// create a circular reactive dependency when createHotkeyRegistrations
|
|
124
|
+
// subscribes to the same store.
|
|
125
|
+
untrack(() => {
|
|
126
|
+
if (
|
|
127
|
+
registration?.isActive &&
|
|
128
|
+
lastSequenceKey === sequenceKey &&
|
|
129
|
+
lastTarget === resolvedTarget
|
|
130
|
+
) {
|
|
131
|
+
registration.callback = callback
|
|
132
|
+
registration.setOptions(optionsWithoutTarget)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
if (registration?.isActive) {
|
|
137
|
+
registration.unregister()
|
|
138
|
+
registration = null
|
|
139
|
+
}
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
registration = manager.register(resolvedSequence, callback, {
|
|
142
|
+
...mergedOptions,
|
|
143
|
+
target: resolvedTarget,
|
|
144
|
+
})
|
|
141
145
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
if (registration.isActive) {
|
|
147
|
+
registration.callback = callback
|
|
148
|
+
registration.setOptions(optionsWithoutTarget)
|
|
149
|
+
}
|
|
146
150
|
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
lastSequenceKey = sequenceKey
|
|
152
|
+
lastTarget = resolvedTarget
|
|
153
|
+
})
|
|
149
154
|
})
|
|
150
155
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from 'solid-js'
|
|
1
|
+
import { createEffect, onCleanup, untrack } from 'solid-js'
|
|
2
2
|
import { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'
|
|
3
3
|
import { useDefaultHotkeysOptions } from './HotkeysProvider'
|
|
4
4
|
import type { CreateHotkeySequenceOptions } from './createHotkeySequence'
|
|
@@ -137,40 +137,45 @@ export function createHotkeySequences(
|
|
|
137
137
|
})
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
// Untrack store mutations so that registering/updating sequences doesn't
|
|
141
|
+
// create a circular reactive dependency when createHotkeyRegistrations
|
|
142
|
+
// subscribes to the same store.
|
|
143
|
+
untrack(() => {
|
|
144
|
+
for (const [key, record] of [...registrations.entries()]) {
|
|
145
|
+
if (!nextKeys.has(key)) {
|
|
146
|
+
if (record.handle.isActive) {
|
|
147
|
+
record.handle.unregister()
|
|
148
|
+
}
|
|
149
|
+
registrations.delete(key)
|
|
144
150
|
}
|
|
145
|
-
registrations.delete(key)
|
|
146
151
|
}
|
|
147
|
-
}
|
|
148
152
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
for (const p of prepared) {
|
|
154
|
+
const existing = registrations.get(p.registrationKey)
|
|
155
|
+
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
156
|
+
existing.handle.callback = p.def.callback
|
|
157
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions
|
|
158
|
+
existing.handle.setOptions(optionsWithoutTarget)
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
157
161
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
if (existing) {
|
|
163
|
+
if (existing.handle.isActive) {
|
|
164
|
+
existing.handle.unregister()
|
|
165
|
+
}
|
|
166
|
+
registrations.delete(p.registrationKey)
|
|
161
167
|
}
|
|
162
|
-
registrations.delete(p.registrationKey)
|
|
163
|
-
}
|
|
164
168
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions
|
|
170
|
+
const handle = manager.register(p.def.sequence, p.def.callback, {
|
|
171
|
+
...optionsWithoutTarget,
|
|
172
|
+
target: p.resolvedTarget,
|
|
173
|
+
})
|
|
174
|
+
registrations.set(p.registrationKey, {
|
|
175
|
+
handle,
|
|
176
|
+
target: p.resolvedTarget,
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
})
|
|
175
180
|
})
|
|
176
181
|
}
|
package/src/createHotkeys.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from 'solid-js'
|
|
1
|
+
import { createEffect, onCleanup, untrack } from 'solid-js'
|
|
2
2
|
import {
|
|
3
3
|
detectPlatform,
|
|
4
4
|
getHotkeyManager,
|
|
@@ -141,42 +141,47 @@ export function createHotkeys(
|
|
|
141
141
|
})
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
// Untrack store mutations so that registering/updating hotkeys doesn't
|
|
145
|
+
// create a circular reactive dependency when createHotkeyRegistrations
|
|
146
|
+
// subscribes to the same store.
|
|
147
|
+
untrack(() => {
|
|
148
|
+
// Drop stale keys first so list index shifts don't briefly double-register
|
|
149
|
+
// the same hotkey+target (conflictBehavior: 'warn' + devtools can loop).
|
|
150
|
+
for (const [key, record] of [...registrations.entries()]) {
|
|
151
|
+
if (!nextKeys.has(key)) {
|
|
152
|
+
if (record.handle.isActive) {
|
|
153
|
+
record.handle.unregister()
|
|
154
|
+
}
|
|
155
|
+
registrations.delete(key)
|
|
150
156
|
}
|
|
151
|
-
registrations.delete(key)
|
|
152
157
|
}
|
|
153
|
-
}
|
|
154
158
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
for (const p of prepared) {
|
|
160
|
+
const existing = registrations.get(p.registrationKey)
|
|
161
|
+
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
162
|
+
existing.handle.callback = p.def.callback
|
|
163
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions
|
|
164
|
+
existing.handle.setOptions(optionsWithoutTarget)
|
|
165
|
+
continue
|
|
166
|
+
}
|
|
163
167
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
if (existing) {
|
|
169
|
+
if (existing.handle.isActive) {
|
|
170
|
+
existing.handle.unregister()
|
|
171
|
+
}
|
|
172
|
+
registrations.delete(p.registrationKey)
|
|
167
173
|
}
|
|
168
|
-
registrations.delete(p.registrationKey)
|
|
169
|
-
}
|
|
170
174
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions
|
|
176
|
+
const handle = manager.register(p.hotkeyString, p.def.callback, {
|
|
177
|
+
...optionsWithoutTarget,
|
|
178
|
+
target: p.resolvedTarget,
|
|
179
|
+
})
|
|
180
|
+
registrations.set(p.registrationKey, {
|
|
181
|
+
handle,
|
|
182
|
+
target: p.resolvedTarget,
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
})
|
|
181
186
|
})
|
|
182
187
|
}
|
package/src/createKeyHold.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createMemo } from 'solid-js'
|
|
2
2
|
import { useStore } from '@tanstack/solid-store'
|
|
3
3
|
import { getKeyStateTracker } from '@tanstack/hotkeys'
|
|
4
|
-
import type {
|
|
4
|
+
import type { IndividualKey } from '@tanstack/hotkeys'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* SolidJS primitive that returns whether a specific key is currently being held.
|
|
@@ -43,7 +43,9 @@ import type { HeldKey } from '@tanstack/hotkeys'
|
|
|
43
43
|
* }
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
export function createKeyHold(
|
|
46
|
+
export function createKeyHold(
|
|
47
|
+
key: IndividualKey | (() => IndividualKey),
|
|
48
|
+
): () => boolean {
|
|
47
49
|
const tracker = getKeyStateTracker()
|
|
48
50
|
const heldKeysSelector = useStore(tracker.store, (state) => state.heldKeys)
|
|
49
51
|
|
package/src/index.ts
CHANGED