@tanstack/hotkeys-devtools 0.9.0 → 1.0.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 +15 -1
- package/dist/_registrations.js +48 -0
- package/dist/_registrations.js.map +1 -0
- package/dist/components/DetailsPanel.js +302 -323
- package/dist/components/DetailsPanel.js.map +1 -1
- package/dist/components/HotkeyList.js +155 -194
- package/dist/components/HotkeyList.js.map +1 -1
- package/package.json +2 -2
- package/src/_registrations.ts +59 -0
- package/src/components/DetailsPanel.tsx +53 -197
- package/src/components/HotkeyList.tsx +48 -140
package/README.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
2
|
+
<picture>
|
|
3
|
+
<source
|
|
4
|
+
media="(prefers-color-scheme: dark)"
|
|
5
|
+
srcset="https://tanstack.com/api/readme/hotkeys.png?theme=dark"
|
|
6
|
+
/>
|
|
7
|
+
<source
|
|
8
|
+
media="(prefers-color-scheme: light)"
|
|
9
|
+
srcset="https://tanstack.com/api/readme/hotkeys.png"
|
|
10
|
+
/>
|
|
11
|
+
<img
|
|
12
|
+
src="https://tanstack.com/api/readme/hotkeys.png"
|
|
13
|
+
alt="TanStack Hotkeys"
|
|
14
|
+
width="900"
|
|
15
|
+
/>
|
|
16
|
+
</picture>
|
|
3
17
|
</div>
|
|
4
18
|
|
|
5
19
|
<br />
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useHotkeysDevtoolsState } from "./HotkeysContextProvider.js";
|
|
2
|
+
import { createMemo } from "solid-js";
|
|
3
|
+
import { findHotkeyConflicts, formatForDisplay, parseHotkey } from "@tanstack/hotkeys";
|
|
4
|
+
|
|
5
|
+
//#region src/_registrations.ts
|
|
6
|
+
/** Refresh shared conflict reporting when either registry changes. */
|
|
7
|
+
function useRegistrationConflicts(registration) {
|
|
8
|
+
const state = useHotkeysDevtoolsState();
|
|
9
|
+
return createMemo(() => {
|
|
10
|
+
state.registrations();
|
|
11
|
+
state.sequenceRegistrations();
|
|
12
|
+
const reg = registration();
|
|
13
|
+
if (reg.options.enabled === false) return {
|
|
14
|
+
overlapping: [],
|
|
15
|
+
separate: []
|
|
16
|
+
};
|
|
17
|
+
const binding = "sequence" in reg ? reg.sequence : reg.hotkey;
|
|
18
|
+
const options = {
|
|
19
|
+
target: reg.target,
|
|
20
|
+
platform: reg.options.platform,
|
|
21
|
+
eventType: reg.options.eventType,
|
|
22
|
+
excludeIds: [reg.id]
|
|
23
|
+
};
|
|
24
|
+
const overlapping = findHotkeyConflicts(binding, options).map((c) => c.registration);
|
|
25
|
+
const ids = new Set(overlapping.map((r) => r.id));
|
|
26
|
+
return {
|
|
27
|
+
overlapping,
|
|
28
|
+
separate: findHotkeyConflicts(binding, {
|
|
29
|
+
...options,
|
|
30
|
+
scope: "all"
|
|
31
|
+
}).map((c) => c.registration).filter((r) => !ids.has(r.id))
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Format either kind of registration, respecting its platform and physical labels. */
|
|
36
|
+
function formatRegistration(reg) {
|
|
37
|
+
return ("sequence" in reg ? reg.sequence : [reg.hotkey]).map((step) => formatForDisplay(step, { platform: reg.options.platform })).join(" → ");
|
|
38
|
+
}
|
|
39
|
+
/** Sequences may mix logical keys and physical codes, so report both when needed. */
|
|
40
|
+
function getBindingKind(reg) {
|
|
41
|
+
const parsed = "sequence" in reg ? reg.sequence.map((step) => parseHotkey(step, reg.options.platform)) : [reg.parsedHotkey];
|
|
42
|
+
const codes = parsed.filter((step) => step.code !== void 0).length;
|
|
43
|
+
return codes === 0 ? "Key" : codes === parsed.length ? "Code" : "Mixed";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { formatRegistration, getBindingKind, useRegistrationConflicts };
|
|
48
|
+
//# sourceMappingURL=_registrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_registrations.js","names":[],"sources":["../src/_registrations.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport {\n findHotkeyConflicts,\n formatForDisplay,\n parseHotkey,\n} from '@tanstack/hotkeys'\nimport { useHotkeysDevtoolsState } from './HotkeysContextProvider'\nimport type { HotkeyConflict } from '@tanstack/hotkeys'\n\n/** Refresh shared conflict reporting when either registry changes. */\nexport function useRegistrationConflicts(\n registration: () => HotkeyConflict['registration'],\n) {\n const state = useHotkeysDevtoolsState()\n return createMemo(() => {\n state.registrations()\n state.sequenceRegistrations()\n const reg = registration()\n if (reg.options.enabled === false) return { overlapping: [], separate: [] }\n const binding = 'sequence' in reg ? reg.sequence : reg.hotkey\n const options = {\n target: reg.target,\n platform: reg.options.platform,\n eventType: reg.options.eventType,\n excludeIds: [reg.id],\n }\n const overlapping = findHotkeyConflicts(binding, options).map(\n (c) => c.registration,\n )\n const ids = new Set(overlapping.map((r) => r.id))\n const separate = findHotkeyConflicts(binding, { ...options, scope: 'all' })\n .map((c) => c.registration)\n .filter((r) => !ids.has(r.id))\n // Without source events, key/code overlap depends on the layout and cannot be inferred.\n return { overlapping, separate }\n })\n}\n\n/** Format either kind of registration, respecting its platform and physical labels. */\nexport function formatRegistration(\n reg: HotkeyConflict['registration'],\n): string {\n const steps = 'sequence' in reg ? reg.sequence : [reg.hotkey]\n return steps\n .map((step) => formatForDisplay(step, { platform: reg.options.platform }))\n .join(' → ')\n}\n\n/** Sequences may mix logical keys and physical codes, so report both when needed. */\nexport function getBindingKind(\n reg: HotkeyConflict['registration'],\n): 'Key' | 'Code' | 'Mixed' {\n const parsed =\n 'sequence' in reg\n ? reg.sequence.map((step) => parseHotkey(step, reg.options.platform))\n : [reg.parsedHotkey]\n const codes = parsed.filter((step) => step.code !== undefined).length\n return codes === 0 ? 'Key' : codes === parsed.length ? 'Code' : 'Mixed'\n}\n"],"mappings":";;;;;;AAUA,SAAgB,yBACd,cACA;CACA,MAAM,QAAQ,yBAAyB;AACvC,QAAO,iBAAi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