@pyreon/hotkeys 0.25.1 → 0.26.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/lib/analysis/index.js.html +1 -1
- package/lib/index.js +63 -4
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +12 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +7 -8
|
@@ -5386,7 +5386,7 @@ var drawChart = (function (exports) {
|
|
|
5386
5386
|
</script>
|
|
5387
5387
|
<script>
|
|
5388
5388
|
/*<!--*/
|
|
5389
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"
|
|
5389
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"e4846332-1","name":"parse.ts"},{"uid":"e4846332-3","name":"registry.ts"},{"uid":"e4846332-5","name":"use-hotkey.ts"},{"uid":"e4846332-7","name":"use-hotkey-scope.ts"},{"uid":"e4846332-9","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"e4846332-1":{"renderedLength":1941,"gzipLength":838,"brotliLength":0,"metaUid":"e4846332-0"},"e4846332-3":{"renderedLength":5039,"gzipLength":1621,"brotliLength":0,"metaUid":"e4846332-2"},"e4846332-5":{"renderedLength":496,"gzipLength":295,"brotliLength":0,"metaUid":"e4846332-4"},"e4846332-7":{"renderedLength":421,"gzipLength":264,"brotliLength":0,"metaUid":"e4846332-6"},"e4846332-9":{"renderedLength":774,"gzipLength":462,"brotliLength":0,"metaUid":"e4846332-8"}},"nodeMetas":{"e4846332-0":{"id":"/src/parse.ts","moduleParts":{"index.js":"e4846332-1"},"imported":[],"importedBy":[{"uid":"e4846332-8"},{"uid":"e4846332-2"}]},"e4846332-2":{"id":"/src/registry.ts","moduleParts":{"index.js":"e4846332-3"},"imported":[{"uid":"e4846332-10"},{"uid":"e4846332-0"}],"importedBy":[{"uid":"e4846332-8"},{"uid":"e4846332-4"},{"uid":"e4846332-6"}]},"e4846332-4":{"id":"/src/use-hotkey.ts","moduleParts":{"index.js":"e4846332-5"},"imported":[{"uid":"e4846332-11"},{"uid":"e4846332-2"}],"importedBy":[{"uid":"e4846332-8"}]},"e4846332-6":{"id":"/src/use-hotkey-scope.ts","moduleParts":{"index.js":"e4846332-7"},"imported":[{"uid":"e4846332-11"},{"uid":"e4846332-2"}],"importedBy":[{"uid":"e4846332-8"}]},"e4846332-8":{"id":"/src/index.ts","moduleParts":{"index.js":"e4846332-9"},"imported":[{"uid":"e4846332-10"},{"uid":"e4846332-4"},{"uid":"e4846332-6"},{"uid":"e4846332-2"},{"uid":"e4846332-0"}],"importedBy":[],"isEntry":true},"e4846332-10":{"id":"@pyreon/reactivity","moduleParts":{},"imported":[],"importedBy":[{"uid":"e4846332-8"},{"uid":"e4846332-2"}]},"e4846332-11":{"id":"@pyreon/core","moduleParts":{},"imported":[],"importedBy":[{"uid":"e4846332-4"},{"uid":"e4846332-6"}]}},"env":{"rollup":"4.23.0"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
5390
5390
|
|
|
5391
5391
|
const run = () => {
|
|
5392
5392
|
const width = window.innerWidth;
|
package/lib/index.js
CHANGED
|
@@ -76,6 +76,20 @@ const entries = [];
|
|
|
76
76
|
const activeScopes = signal(new Set(["global"]));
|
|
77
77
|
let listenerAttached = false;
|
|
78
78
|
let keydownHandler = null;
|
|
79
|
+
const SEQUENCE_TIMEOUT_MS = 1e3;
|
|
80
|
+
let pending = [];
|
|
81
|
+
let pendingTimer = null;
|
|
82
|
+
function clearPending() {
|
|
83
|
+
pending = [];
|
|
84
|
+
if (pendingTimer) {
|
|
85
|
+
clearTimeout(pendingTimer);
|
|
86
|
+
pendingTimer = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function armSequenceTimeout() {
|
|
90
|
+
if (pendingTimer) clearTimeout(pendingTimer);
|
|
91
|
+
pendingTimer = setTimeout(clearPending, SEQUENCE_TIMEOUT_MS);
|
|
92
|
+
}
|
|
79
93
|
const INPUT_TAGS = new Set([
|
|
80
94
|
"INPUT",
|
|
81
95
|
"TEXTAREA",
|
|
@@ -94,14 +108,52 @@ function attachListener() {
|
|
|
94
108
|
listenerAttached = true;
|
|
95
109
|
keydownHandler = (event) => {
|
|
96
110
|
const scopes = activeScopes.peek();
|
|
111
|
+
if (pending.length > 0) {
|
|
112
|
+
const surviving = [];
|
|
113
|
+
let fired = false;
|
|
114
|
+
for (const p of pending) {
|
|
115
|
+
const expected = p.entry.sequence[p.next];
|
|
116
|
+
if (!expected) continue;
|
|
117
|
+
if (!matchesCombo(event, expected)) continue;
|
|
118
|
+
if (p.next + 1 === p.entry.sequence.length) {
|
|
119
|
+
if (p.entry.options.preventDefault) event.preventDefault();
|
|
120
|
+
if (p.entry.options.stopPropagation) event.stopPropagation();
|
|
121
|
+
p.entry.handler(event);
|
|
122
|
+
fired = true;
|
|
123
|
+
} else surviving.push({
|
|
124
|
+
entry: p.entry,
|
|
125
|
+
next: p.next + 1
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (fired || surviving.length > 0) {
|
|
129
|
+
pending = surviving;
|
|
130
|
+
if (surviving.length > 0) armSequenceTimeout();
|
|
131
|
+
else clearPending();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
clearPending();
|
|
135
|
+
}
|
|
136
|
+
const newPending = [];
|
|
97
137
|
for (const entry of entries) {
|
|
98
138
|
if (!scopes.has(entry.options.scope)) continue;
|
|
99
139
|
if (!(typeof entry.options.enabled === "function" ? entry.options.enabled() : entry.options.enabled)) continue;
|
|
100
140
|
if (!entry.options.enableOnInputs && isInputFocused(event)) continue;
|
|
101
141
|
if (!matchesCombo(event, entry.combo)) continue;
|
|
102
|
-
if (entry.
|
|
103
|
-
|
|
104
|
-
|
|
142
|
+
if (entry.sequence.length === 0) {
|
|
143
|
+
if (entry.options.preventDefault) event.preventDefault();
|
|
144
|
+
if (entry.options.stopPropagation) event.stopPropagation();
|
|
145
|
+
entry.handler(event);
|
|
146
|
+
} else {
|
|
147
|
+
if (entry.options.preventDefault) event.preventDefault();
|
|
148
|
+
newPending.push({
|
|
149
|
+
entry,
|
|
150
|
+
next: 0
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (newPending.length > 0) {
|
|
155
|
+
pending = newPending;
|
|
156
|
+
armSequenceTimeout();
|
|
105
157
|
}
|
|
106
158
|
};
|
|
107
159
|
window.addEventListener("keydown", keydownHandler);
|
|
@@ -124,9 +176,15 @@ function detachListener() {
|
|
|
124
176
|
*/
|
|
125
177
|
function registerHotkey(shortcut, handler, options) {
|
|
126
178
|
attachListener();
|
|
179
|
+
const subShortcuts = shortcut.split(/\s+/).map((s) => s.trim()).filter(Boolean);
|
|
180
|
+
if (subShortcuts.length === 0) throw new Error(`[@pyreon/hotkeys] empty shortcut: ${JSON.stringify(shortcut)}`);
|
|
181
|
+
const combos = subShortcuts.map(parseShortcut);
|
|
182
|
+
const firstCombo = combos[0];
|
|
183
|
+
if (!firstCombo) throw new Error(`[@pyreon/hotkeys] invalid shortcut: ${JSON.stringify(shortcut)}`);
|
|
127
184
|
const entry = {
|
|
128
185
|
shortcut,
|
|
129
|
-
combo:
|
|
186
|
+
combo: firstCombo,
|
|
187
|
+
sequence: combos.slice(1),
|
|
130
188
|
handler,
|
|
131
189
|
options: {
|
|
132
190
|
scope: options?.scope ?? "global",
|
|
@@ -184,6 +242,7 @@ function getRegisteredHotkeys() {
|
|
|
184
242
|
function _resetHotkeys() {
|
|
185
243
|
entries.length = 0;
|
|
186
244
|
activeScopes.set(new Set(["global"]));
|
|
245
|
+
clearPending();
|
|
187
246
|
detachListener();
|
|
188
247
|
}
|
|
189
248
|
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/parse.ts","../src/registry.ts","../src/use-hotkey.ts","../src/use-hotkey-scope.ts","../src/index.ts"],"sourcesContent":["import type { KeyCombo } from './types'\n\n// ─── Key aliases ─────────────────────────────────────────────────────────────\n\nconst KEY_ALIASES: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n del: 'delete',\n ins: 'insert',\n space: ' ',\n spacebar: ' ',\n up: 'arrowup',\n down: 'arrowdown',\n left: 'arrowleft',\n right: 'arrowright',\n plus: '+',\n}\n\n/**\n * Parse a shortcut string like 'ctrl+shift+s' into a KeyCombo.\n * Supports aliases (esc, del, space, etc.) and mod (ctrl on Windows/Linux, meta on Mac).\n */\nexport function parseShortcut(shortcut: string): KeyCombo {\n const parts = shortcut.toLowerCase().trim().split('+')\n const combo: KeyCombo = {\n ctrl: false,\n shift: false,\n alt: false,\n meta: false,\n key: '',\n }\n\n for (const part of parts) {\n const p = part.trim()\n if (p === 'ctrl' || p === 'control') {\n combo.ctrl = true\n } else if (p === 'shift') {\n combo.shift = true\n } else if (p === 'alt') {\n combo.alt = true\n } else if (p === 'meta' || p === 'cmd' || p === 'command') {\n combo.meta = true\n } else if (p === 'mod') {\n // mod = meta on Mac, ctrl elsewhere\n if (isMac()) {\n combo.meta = true\n } else {\n combo.ctrl = true\n }\n } else {\n combo.key = KEY_ALIASES[p] ?? p\n }\n }\n\n return combo\n}\n\n/**\n * Check if a KeyboardEvent matches a KeyCombo.\n */\nexport function matchesCombo(event: KeyboardEvent, combo: KeyCombo): boolean {\n if (event.ctrlKey !== combo.ctrl) return false\n if (event.shiftKey !== combo.shift) return false\n if (event.altKey !== combo.alt) return false\n if (event.metaKey !== combo.meta) return false\n\n const eventKey = event.key.toLowerCase()\n return eventKey === combo.key\n}\n\n/**\n * Format a KeyCombo back to a human-readable string.\n */\nexport function formatCombo(combo: KeyCombo): string {\n const parts: string[] = []\n if (combo.ctrl) parts.push('Ctrl')\n if (combo.shift) parts.push('Shift')\n if (combo.alt) parts.push('Alt')\n if (combo.meta) parts.push(isMac() ? '⌘' : 'Meta')\n parts.push(combo.key.length === 1 ? combo.key.toUpperCase() : capitalize(combo.key))\n return parts.join('+')\n}\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction isMac(): boolean {\n if (typeof navigator === 'undefined') return false\n return /mac|iphone|ipad|ipod/i.test(navigator.userAgent)\n}\n","import type { Signal } from '@pyreon/reactivity'\nimport { signal } from '@pyreon/reactivity'\nimport { matchesCombo, parseShortcut } from './parse'\nimport type { HotkeyEntry, HotkeyOptions } from './types'\n\n// ─── State ───────────────────────────────────────────────────────────────────\n\n// Linear array on purpose. Per-keystroke dispatch (line 35) iterates entries\n// in registration order — O(n) where n = registered hotkeys. For real apps\n// (single-digit to low-tens) the cost is sub-microsecond and well under the\n// 16ms frame budget. Switching to a Map<comboKey, entries[]> would help only\n// past ~5,000 hotkeys, which is unrealistic. The array also preserves\n// registration order for the rare case where two hotkeys match the same\n// combo on different scopes — first-registered wins. Don't replace with a\n// Map without confirming a real app actually hits the perf wall.\nconst entries: HotkeyEntry[] = []\nconst activeScopes = signal<Set<string>>(new Set(['global']))\nlet listenerAttached = false\nlet keydownHandler: ((event: KeyboardEvent) => void) | null = null\n\n// ─── Input detection ─────────────────────────────────────────────────────────\n\nconst INPUT_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT'])\n\nfunction isInputFocused(event: KeyboardEvent): boolean {\n const target = event.target as HTMLElement | null\n if (!target) return false\n if (INPUT_TAGS.has(target.tagName)) return true\n if (target.isContentEditable) return true\n return false\n}\n\n// ─── Global listener ─────────────────────────────────────────────────────────\n\nfunction attachListener(): void {\n if (listenerAttached) return\n if (typeof window === 'undefined') return\n listenerAttached = true\n\n keydownHandler = (event) => {\n const scopes = activeScopes.peek()\n\n for (const entry of entries) {\n // Check scope\n if (!scopes.has(entry.options.scope)) continue\n\n // Check enabled\n const enabled =\n typeof entry.options.enabled === 'function'\n ? entry.options.enabled()\n : entry.options.enabled\n if (!enabled) continue\n\n // Check input focus\n if (!entry.options.enableOnInputs && isInputFocused(event)) continue\n\n // Check key match\n if (!matchesCombo(event, entry.combo)) continue\n\n // Match found\n if (entry.options.preventDefault) event.preventDefault()\n if (entry.options.stopPropagation) event.stopPropagation()\n entry.handler(event)\n }\n }\n\n window.addEventListener('keydown', keydownHandler)\n}\n\nfunction detachListener(): void {\n if (typeof window === 'undefined') return\n if (!listenerAttached || !keydownHandler) return\n window.removeEventListener('keydown', keydownHandler)\n listenerAttached = false\n keydownHandler = null\n}\n\n// ─── Registration ────────────────────────────────────────────────────────────\n\n/**\n * Register a keyboard shortcut. Returns an unregister function.\n *\n * @example\n * ```ts\n * const unregister = registerHotkey('ctrl+s', (e) => save(), { description: 'Save' })\n * // later: unregister()\n * ```\n */\nexport function registerHotkey(\n shortcut: string,\n handler: (event: KeyboardEvent) => void,\n options?: HotkeyOptions,\n): () => void {\n attachListener()\n\n const entry: HotkeyEntry = {\n shortcut,\n combo: parseShortcut(shortcut),\n handler,\n options: {\n scope: options?.scope ?? 'global',\n preventDefault: options?.preventDefault !== false,\n stopPropagation: options?.stopPropagation === true,\n enableOnInputs: options?.enableOnInputs === true,\n enabled: options?.enabled ?? true,\n ...(options?.description != null ? { description: options.description } : {}),\n },\n }\n\n entries.push(entry)\n\n return () => {\n const idx = entries.indexOf(entry)\n if (idx !== -1) entries.splice(idx, 1)\n\n // Detach listener if no more entries\n if (entries.length === 0) {\n detachListener()\n }\n }\n}\n\n// ─── Scope management ────────────────────────────────────────────────────────\n\n/**\n * Activate a hotkey scope. 'global' is always active.\n */\nexport function enableScope(scope: string): void {\n const current = activeScopes.peek()\n if (current.has(scope)) return\n const next = new Set(current)\n next.add(scope)\n activeScopes.set(next)\n}\n\n/**\n * Deactivate a hotkey scope. Cannot deactivate 'global'.\n */\nexport function disableScope(scope: string): void {\n if (scope === 'global') return\n const current = activeScopes.peek()\n if (!current.has(scope)) return\n const next = new Set(current)\n next.delete(scope)\n activeScopes.set(next)\n}\n\n/**\n * Get the currently active scopes as a reactive signal.\n */\nexport function getActiveScopes(): Signal<Set<string>> {\n return activeScopes\n}\n\n/**\n * Get all registered hotkeys (for building help dialogs).\n */\nexport function getRegisteredHotkeys(): ReadonlyArray<{\n shortcut: string\n scope: string\n description?: string\n}> {\n return entries.map((e) => ({\n shortcut: e.shortcut,\n scope: e.options.scope,\n ...(e.options.description != null ? { description: e.options.description } : {}),\n }))\n}\n\n// ─── Reset (for testing) ────────────────────────────────────────────────\n\nexport function _resetHotkeys(): void {\n entries.length = 0\n activeScopes.set(new Set(['global']))\n detachListener()\n}\n","import { onUnmount } from '@pyreon/core'\nimport { registerHotkey } from './registry'\nimport type { HotkeyOptions } from './types'\n\n/**\n * Register a keyboard shortcut scoped to a component's lifecycle.\n * Automatically unregisters when the component unmounts.\n *\n * @example\n * ```ts\n * function Editor() {\n * useHotkey('ctrl+s', () => save(), { description: 'Save document' })\n * useHotkey('ctrl+z', () => undo())\n * useHotkey('ctrl+shift+z', () => redo())\n * // ...\n * }\n * ```\n */\nexport function useHotkey(\n shortcut: string,\n handler: (event: KeyboardEvent) => void,\n options?: HotkeyOptions,\n): void {\n const unregister = registerHotkey(shortcut, handler, options)\n onUnmount(unregister)\n}\n","import { onUnmount } from '@pyreon/core'\nimport { disableScope, enableScope } from './registry'\n\n/**\n * Activate a hotkey scope for the lifetime of a component.\n * When the component unmounts, the scope is deactivated.\n *\n * @example\n * ```tsx\n * function Modal() {\n * useHotkeyScope('modal')\n * useHotkey('escape', () => closeModal(), { scope: 'modal' })\n * // ...\n * }\n * ```\n */\nexport function useHotkeyScope(scope: string): void {\n enableScope(scope)\n onUnmount(() => disableScope(scope))\n}\n","/**\n * @pyreon/hotkeys — Reactive keyboard shortcut management for Pyreon.\n *\n * Register global or scoped keyboard shortcuts with automatic lifecycle\n * management. Supports modifier keys, aliases, input filtering, and\n * scope-based activation.\n *\n * @example\n * ```ts\n * import { useHotkey, useHotkeyScope } from '@pyreon/hotkeys'\n *\n * // Global shortcut\n * useHotkey('ctrl+s', () => save(), { description: 'Save' })\n *\n * // Scoped shortcut — only active when scope is enabled\n * useHotkeyScope('editor')\n * useHotkey('ctrl+z', () => undo(), { scope: 'editor' })\n *\n * // Platform-aware — mod = ⌘ on Mac, Ctrl elsewhere\n * useHotkey('mod+k', () => openCommandPalette())\n * ```\n */\n\nimport { registerSingleton } from '@pyreon/reactivity'\n\n// Singleton sentinel — fail-loud detection of duplicate @pyreon/hotkeys\n// instances in the same heap. See @pyreon/reactivity/singleton-sentinel for\n// full rationale. Hardcoded version is acceptable here — it's a diagnostic\n// aid, not a load-bearing identity check.\nregisterSingleton('@pyreon/hotkeys', '0.24.6', import.meta.url)\n\n// ─── Hooks ───────────────────────────────────────────────────────────────────\n\nexport { useHotkey } from './use-hotkey'\nexport { useHotkeyScope } from './use-hotkey-scope'\n\n// ─── Imperative API ──────────────────────────────────────────────────────────\n\nexport {\n disableScope,\n enableScope,\n getActiveScopes,\n getRegisteredHotkeys,\n registerHotkey,\n} from './registry'\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n\nexport { formatCombo, matchesCombo, parseShortcut } from './parse'\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\nexport type { HotkeyEntry, HotkeyOptions, KeyCombo } from './types'\n\n// ─── Testing ─────────────────────────────────────────────────────────────────\n\nexport { _resetHotkeys } from './registry'\n"],"mappings":";;;;AAIA,MAAM,cAAsC;CAC1C,KAAK;CACL,QAAQ;CACR,KAAK;CACL,KAAK;CACL,OAAO;CACP,UAAU;CACV,IAAI;CACJ,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;AACR;;;;;AAMA,SAAgB,cAAc,UAA4B;CACxD,MAAM,QAAQ,SAAS,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG;CACrD,MAAM,QAAkB;EACtB,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,KAAK;CACP;CAEA,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,IAAI,KAAK,KAAK;EACpB,IAAI,MAAM,UAAU,MAAM,WACxB,MAAM,OAAO;OACR,IAAI,MAAM,SACf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;;;;;;;;;;ACUA,kBAAkB,mBAAmB,UAAU,OAAO,KAAK,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/parse.ts","../src/registry.ts","../src/use-hotkey.ts","../src/use-hotkey-scope.ts","../src/index.ts"],"sourcesContent":["import type { KeyCombo } from './types'\n\n// ─── Key aliases ─────────────────────────────────────────────────────────────\n\nconst KEY_ALIASES: Record<string, string> = {\n esc: 'escape',\n return: 'enter',\n del: 'delete',\n ins: 'insert',\n space: ' ',\n spacebar: ' ',\n up: 'arrowup',\n down: 'arrowdown',\n left: 'arrowleft',\n right: 'arrowright',\n plus: '+',\n}\n\n/**\n * Parse a shortcut string like 'ctrl+shift+s' into a KeyCombo.\n * Supports aliases (esc, del, space, etc.) and mod (ctrl on Windows/Linux, meta on Mac).\n */\nexport function parseShortcut(shortcut: string): KeyCombo {\n const parts = shortcut.toLowerCase().trim().split('+')\n const combo: KeyCombo = {\n ctrl: false,\n shift: false,\n alt: false,\n meta: false,\n key: '',\n }\n\n for (const part of parts) {\n const p = part.trim()\n if (p === 'ctrl' || p === 'control') {\n combo.ctrl = true\n } else if (p === 'shift') {\n combo.shift = true\n } else if (p === 'alt') {\n combo.alt = true\n } else if (p === 'meta' || p === 'cmd' || p === 'command') {\n combo.meta = true\n } else if (p === 'mod') {\n // mod = meta on Mac, ctrl elsewhere\n if (isMac()) {\n combo.meta = true\n } else {\n combo.ctrl = true\n }\n } else {\n combo.key = KEY_ALIASES[p] ?? p\n }\n }\n\n return combo\n}\n\n/**\n * Check if a KeyboardEvent matches a KeyCombo.\n */\nexport function matchesCombo(event: KeyboardEvent, combo: KeyCombo): boolean {\n if (event.ctrlKey !== combo.ctrl) return false\n if (event.shiftKey !== combo.shift) return false\n if (event.altKey !== combo.alt) return false\n if (event.metaKey !== combo.meta) return false\n\n const eventKey = event.key.toLowerCase()\n return eventKey === combo.key\n}\n\n/**\n * Format a KeyCombo back to a human-readable string.\n */\nexport function formatCombo(combo: KeyCombo): string {\n const parts: string[] = []\n if (combo.ctrl) parts.push('Ctrl')\n if (combo.shift) parts.push('Shift')\n if (combo.alt) parts.push('Alt')\n if (combo.meta) parts.push(isMac() ? '⌘' : 'Meta')\n parts.push(combo.key.length === 1 ? combo.key.toUpperCase() : capitalize(combo.key))\n return parts.join('+')\n}\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction isMac(): boolean {\n if (typeof navigator === 'undefined') return false\n return /mac|iphone|ipad|ipod/i.test(navigator.userAgent)\n}\n","import type { Signal } from '@pyreon/reactivity'\nimport { signal } from '@pyreon/reactivity'\nimport { matchesCombo, parseShortcut } from './parse'\nimport type { HotkeyEntry, HotkeyOptions } from './types'\n\n// ─── State ───────────────────────────────────────────────────────────────────\n\n// Linear array on purpose. Per-keystroke dispatch (line 35) iterates entries\n// in registration order — O(n) where n = registered hotkeys. For real apps\n// (single-digit to low-tens) the cost is sub-microsecond and well under the\n// 16ms frame budget. Switching to a Map<comboKey, entries[]> would help only\n// past ~5,000 hotkeys, which is unrealistic. The array also preserves\n// registration order for the rare case where two hotkeys match the same\n// combo on different scopes — first-registered wins. Don't replace with a\n// Map without confirming a real app actually hits the perf wall.\nconst entries: HotkeyEntry[] = []\nconst activeScopes = signal<Set<string>>(new Set(['global']))\nlet listenerAttached = false\nlet keydownHandler: ((event: KeyboardEvent) => void) | null = null\n\n// ─── Sequence state ──────────────────────────────────────────────────────────\n\n/**\n * Active sequence-tracking state. When a user presses a key that matches the\n * FIRST combo of one-or-more sequential hotkeys (`'g t'`, `'g n'`, etc.), we\n * remember the matched prefix and wait for the next keystroke. If it matches\n * the next combo in any pending sequence, we keep narrowing. A full match\n * fires the handler; a non-match clears the pending state. The state also\n * times out after `SEQUENCE_TIMEOUT_MS` so a stranded prefix doesn't trap\n * the next single-key shortcut.\n */\ninterface PendingSequence {\n /** The entry whose remaining keys we're tracking. */\n entry: HotkeyEntry\n /** Index of the NEXT combo we expect to match in `entry.sequence`. */\n next: number\n}\n\nconst SEQUENCE_TIMEOUT_MS = 1000\nlet pending: PendingSequence[] = []\nlet pendingTimer: ReturnType<typeof setTimeout> | null = null\n\nfunction clearPending(): void {\n pending = []\n if (pendingTimer) {\n clearTimeout(pendingTimer)\n pendingTimer = null\n }\n}\n\nfunction armSequenceTimeout(): void {\n if (pendingTimer) clearTimeout(pendingTimer)\n pendingTimer = setTimeout(clearPending, SEQUENCE_TIMEOUT_MS)\n}\n\n// ─── Input detection ─────────────────────────────────────────────────────────\n\nconst INPUT_TAGS = new Set(['INPUT', 'TEXTAREA', 'SELECT'])\n\nfunction isInputFocused(event: KeyboardEvent): boolean {\n const target = event.target as HTMLElement | null\n if (!target) return false\n if (INPUT_TAGS.has(target.tagName)) return true\n if (target.isContentEditable) return true\n return false\n}\n\n// ─── Global listener ─────────────────────────────────────────────────────────\n\nfunction attachListener(): void {\n if (listenerAttached) return\n if (typeof window === 'undefined') return\n listenerAttached = true\n\n keydownHandler = (event) => {\n const scopes = activeScopes.peek()\n\n // ─── Stage 1: advance any pending sequences ──────────────────────────\n // If we're mid-sequence, the user's next keystroke must match the\n // NEXT combo of at least one pending entry. Non-matches drop that\n // pending entry; a full match (last combo) fires the handler and\n // clears all pending state. If anything advanced, return early so\n // single-key shortcuts (like 't' alone) don't ALSO fire on this\n // keystroke — sequence ownership of the keystroke beats fresh\n // single-combo matches.\n if (pending.length > 0) {\n const surviving: PendingSequence[] = []\n let fired = false\n for (const p of pending) {\n const expected = p.entry.sequence[p.next]\n if (!expected) continue // defensive — shouldn't happen\n if (!matchesCombo(event, expected)) continue\n // Advance\n if (p.next + 1 === p.entry.sequence.length) {\n // Full match — fire\n if (p.entry.options.preventDefault) event.preventDefault()\n if (p.entry.options.stopPropagation) event.stopPropagation()\n p.entry.handler(event)\n fired = true\n } else {\n surviving.push({ entry: p.entry, next: p.next + 1 })\n }\n }\n if (fired || surviving.length > 0) {\n pending = surviving\n if (surviving.length > 0) armSequenceTimeout()\n else clearPending()\n return\n }\n // No pending sequence matched — fall through to fresh dispatch\n // but clear the stale pending state.\n clearPending()\n }\n\n // ─── Stage 2: fresh dispatch ────────────────────────────────────────\n const newPending: PendingSequence[] = []\n for (const entry of entries) {\n // Check scope\n if (!scopes.has(entry.options.scope)) continue\n\n // Check enabled\n const enabled =\n typeof entry.options.enabled === 'function'\n ? entry.options.enabled()\n : entry.options.enabled\n if (!enabled) continue\n\n // Check input focus\n if (!entry.options.enableOnInputs && isInputFocused(event)) continue\n\n // Check FIRST combo match\n if (!matchesCombo(event, entry.combo)) continue\n\n if (entry.sequence.length === 0) {\n // Single-combo hotkey — fire immediately\n if (entry.options.preventDefault) event.preventDefault()\n if (entry.options.stopPropagation) event.stopPropagation()\n entry.handler(event)\n } else {\n // Sequential hotkey — record as pending; consume the keystroke\n // (preventDefault so 'g' doesn't trigger a browser shortcut)\n // but DON'T fire the handler yet.\n if (entry.options.preventDefault) event.preventDefault()\n newPending.push({ entry, next: 0 })\n }\n }\n\n if (newPending.length > 0) {\n pending = newPending\n armSequenceTimeout()\n }\n }\n\n window.addEventListener('keydown', keydownHandler)\n}\n\nfunction detachListener(): void {\n if (typeof window === 'undefined') return\n if (!listenerAttached || !keydownHandler) return\n window.removeEventListener('keydown', keydownHandler)\n listenerAttached = false\n keydownHandler = null\n}\n\n// ─── Registration ────────────────────────────────────────────────────────────\n\n/**\n * Register a keyboard shortcut. Returns an unregister function.\n *\n * @example\n * ```ts\n * const unregister = registerHotkey('ctrl+s', (e) => save(), { description: 'Save' })\n * // later: unregister()\n * ```\n */\nexport function registerHotkey(\n shortcut: string,\n handler: (event: KeyboardEvent) => void,\n options?: HotkeyOptions,\n): () => void {\n attachListener()\n\n // Sequential combo support: space-separated combos like `'g t'` are\n // treated as ordered sequences — user presses `g`, then `t` within\n // `SEQUENCE_TIMEOUT_MS`, the handler fires. Each sub-combo is parsed\n // through the existing `parseShortcut` (so `'ctrl+k p'` works: `ctrl+k`\n // followed by `p`). Single-combo shortcuts have `sequence: []` and\n // behave identically to the pre-sequence code path.\n const subShortcuts = shortcut\n .split(/\\s+/)\n .map((s) => s.trim())\n .filter(Boolean)\n if (subShortcuts.length === 0) {\n throw new Error(`[@pyreon/hotkeys] empty shortcut: ${JSON.stringify(shortcut)}`)\n }\n const combos = subShortcuts.map(parseShortcut)\n const firstCombo = combos[0]\n if (!firstCombo) {\n // Unreachable given the length check above, but keeps TS happy.\n throw new Error(`[@pyreon/hotkeys] invalid shortcut: ${JSON.stringify(shortcut)}`)\n }\n const rest = combos.slice(1)\n\n const entry: HotkeyEntry = {\n shortcut,\n combo: firstCombo,\n sequence: rest,\n handler,\n options: {\n scope: options?.scope ?? 'global',\n preventDefault: options?.preventDefault !== false,\n stopPropagation: options?.stopPropagation === true,\n enableOnInputs: options?.enableOnInputs === true,\n enabled: options?.enabled ?? true,\n ...(options?.description != null ? { description: options.description } : {}),\n },\n }\n\n entries.push(entry)\n\n return () => {\n const idx = entries.indexOf(entry)\n if (idx !== -1) entries.splice(idx, 1)\n\n // Detach listener if no more entries\n if (entries.length === 0) {\n detachListener()\n }\n }\n}\n\n// ─── Scope management ────────────────────────────────────────────────────────\n\n/**\n * Activate a hotkey scope. 'global' is always active.\n */\nexport function enableScope(scope: string): void {\n const current = activeScopes.peek()\n if (current.has(scope)) return\n const next = new Set(current)\n next.add(scope)\n activeScopes.set(next)\n}\n\n/**\n * Deactivate a hotkey scope. Cannot deactivate 'global'.\n */\nexport function disableScope(scope: string): void {\n if (scope === 'global') return\n const current = activeScopes.peek()\n if (!current.has(scope)) return\n const next = new Set(current)\n next.delete(scope)\n activeScopes.set(next)\n}\n\n/**\n * Get the currently active scopes as a reactive signal.\n */\nexport function getActiveScopes(): Signal<Set<string>> {\n return activeScopes\n}\n\n/**\n * Get all registered hotkeys (for building help dialogs).\n */\nexport function getRegisteredHotkeys(): ReadonlyArray<{\n shortcut: string\n scope: string\n description?: string\n}> {\n return entries.map((e) => ({\n shortcut: e.shortcut,\n scope: e.options.scope,\n ...(e.options.description != null ? { description: e.options.description } : {}),\n }))\n}\n\n// ─── Reset (for testing) ────────────────────────────────────────────────\n\nexport function _resetHotkeys(): void {\n entries.length = 0\n activeScopes.set(new Set(['global']))\n clearPending()\n detachListener()\n}\n","import { onUnmount } from '@pyreon/core'\nimport { registerHotkey } from './registry'\nimport type { HotkeyOptions } from './types'\n\n/**\n * Register a keyboard shortcut scoped to a component's lifecycle.\n * Automatically unregisters when the component unmounts.\n *\n * @example\n * ```ts\n * function Editor() {\n * useHotkey('ctrl+s', () => save(), { description: 'Save document' })\n * useHotkey('ctrl+z', () => undo())\n * useHotkey('ctrl+shift+z', () => redo())\n * // ...\n * }\n * ```\n */\nexport function useHotkey(\n shortcut: string,\n handler: (event: KeyboardEvent) => void,\n options?: HotkeyOptions,\n): void {\n const unregister = registerHotkey(shortcut, handler, options)\n onUnmount(unregister)\n}\n","import { onUnmount } from '@pyreon/core'\nimport { disableScope, enableScope } from './registry'\n\n/**\n * Activate a hotkey scope for the lifetime of a component.\n * When the component unmounts, the scope is deactivated.\n *\n * @example\n * ```tsx\n * function Modal() {\n * useHotkeyScope('modal')\n * useHotkey('escape', () => closeModal(), { scope: 'modal' })\n * // ...\n * }\n * ```\n */\nexport function useHotkeyScope(scope: string): void {\n enableScope(scope)\n onUnmount(() => disableScope(scope))\n}\n","/**\n * @pyreon/hotkeys — Reactive keyboard shortcut management for Pyreon.\n *\n * Register global or scoped keyboard shortcuts with automatic lifecycle\n * management. Supports modifier keys, aliases, input filtering, and\n * scope-based activation.\n *\n * @example\n * ```ts\n * import { useHotkey, useHotkeyScope } from '@pyreon/hotkeys'\n *\n * // Global shortcut\n * useHotkey('ctrl+s', () => save(), { description: 'Save' })\n *\n * // Scoped shortcut — only active when scope is enabled\n * useHotkeyScope('editor')\n * useHotkey('ctrl+z', () => undo(), { scope: 'editor' })\n *\n * // Platform-aware — mod = ⌘ on Mac, Ctrl elsewhere\n * useHotkey('mod+k', () => openCommandPalette())\n * ```\n */\n\nimport { registerSingleton } from '@pyreon/reactivity'\n\n// Singleton sentinel — fail-loud detection of duplicate @pyreon/hotkeys\n// instances in the same heap. See @pyreon/reactivity/singleton-sentinel for\n// full rationale. Hardcoded version is acceptable here — it's a diagnostic\n// aid, not a load-bearing identity check.\nregisterSingleton('@pyreon/hotkeys', '0.24.6', import.meta.url)\n\n// ─── Hooks ───────────────────────────────────────────────────────────────────\n\nexport { useHotkey } from './use-hotkey'\nexport { useHotkeyScope } from './use-hotkey-scope'\n\n// ─── Imperative API ──────────────────────────────────────────────────────────\n\nexport {\n disableScope,\n enableScope,\n getActiveScopes,\n getRegisteredHotkeys,\n registerHotkey,\n} from './registry'\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n\nexport { formatCombo, matchesCombo, parseShortcut } from './parse'\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\nexport type { HotkeyEntry, HotkeyOptions, KeyCombo } from './types'\n\n// ─── Testing ─────────────────────────────────────────────────────────────────\n\nexport { _resetHotkeys } from './registry'\n"],"mappings":";;;;AAIA,MAAM,cAAsC;CAC1C,KAAK;CACL,QAAQ;CACR,KAAK;CACL,KAAK;CACL,OAAO;CACP,UAAU;CACV,IAAI;CACJ,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;AACR;;;;;AAMA,SAAgB,cAAc,UAA4B;CACxD,MAAM,QAAQ,SAAS,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG;CACrD,MAAM,QAAkB;EACtB,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,KAAK;CACP;CAEA,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,IAAI,KAAK,KAAK;EACpB,IAAI,MAAM,UAAU,MAAM,WACxB,MAAM,OAAO;OACR,IAAI,MAAM,SACf,MAAM,QAAQ;OACT,IAAI,MAAM,OACf,MAAM,MAAM;OACP,IAAI,MAAM,UAAU,MAAM,SAAS,MAAM,WAC9C,MAAM,OAAO;OACR,IAAI,MAAM,OAEf,IAAI,MAAM,GACR,MAAM,O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YAAY,KAAK;CACjB,gBAAgB,aAAa,KAAK,CAAC;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;ACUA,kBAAkB,mBAAmB,UAAU,OAAO,KAAK,GAAG"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -35,8 +35,19 @@ interface HotkeyOptions {
|
|
|
35
35
|
interface HotkeyEntry {
|
|
36
36
|
/** The original shortcut string (e.g. 'ctrl+s') */
|
|
37
37
|
shortcut: string;
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Parsed key combination — for SEQUENTIAL combos (`'g t'`) this is the
|
|
40
|
+
* FIRST combo in the sequence; `sequence` carries the remaining combos.
|
|
41
|
+
* Non-sequential combos have empty `sequence`.
|
|
42
|
+
*/
|
|
39
43
|
combo: KeyCombo;
|
|
44
|
+
/**
|
|
45
|
+
* Remaining combos for sequential shortcuts (`'g t'` → [{ key: 't' }]).
|
|
46
|
+
* Empty for single-combo hotkeys. Each subsequent keystroke must match
|
|
47
|
+
* `sequence[0]`, then `sequence[1]`, etc., within `SEQUENCE_TIMEOUT_MS`.
|
|
48
|
+
* Defaults to empty.
|
|
49
|
+
*/
|
|
50
|
+
sequence: KeyCombo[];
|
|
40
51
|
/** The callback to invoke */
|
|
41
52
|
handler: (event: KeyboardEvent) => void;
|
|
42
53
|
/** Options */
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../../src/types.ts","../../../src/use-hotkey.ts","../../../src/use-hotkey-scope.ts","../../../src/registry.ts","../../../src/parse.ts"],"mappings":";;;;;;AAMA;UAAiB,QAAA;EACf,IAAA;EACA,KAAA;EACA,GAAA;EACA,IAAA;EACA,GAAA;AAAA;;;AAAG;UAMY,aAAA;EAAa;EAE5B,KAAA;EAF4B;EAI5B,cAAA;EAAA;EAEA,eAAA;EAEA;EAAA,cAAA;EAIA;EAFA,WAAA;EAEO;EAAP,OAAA;AAAA;;;;UAMe,WAAA;
|
|
1
|
+
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../../src/types.ts","../../../src/use-hotkey.ts","../../../src/use-hotkey-scope.ts","../../../src/registry.ts","../../../src/parse.ts"],"mappings":";;;;;;AAMA;UAAiB,QAAA;EACf,IAAA;EACA,KAAA;EACA,GAAA;EACA,IAAA;EACA,GAAA;AAAA;;;AAAG;UAMY,aAAA;EAAa;EAE5B,KAAA;EAF4B;EAI5B,cAAA;EAAA;EAEA,eAAA;EAEA;EAAA,cAAA;EAIA;EAFA,WAAA;EAEO;EAAP,OAAA;AAAA;;;;UAMe,WAAA;EAqBX;EAnBJ,QAAA;EAiBS;;;;;EAXT,KAAA,EAAO,QAAA;EAOP;;;;;;EAAA,QAAA,EAAU,QAAA;EAKR;EAHF,OAAA,GAAU,KAAA,EAAO,aAAA;EAOX;EALN,OAAA,EAAS,QAAA,CACP,IAAA,CACE,aAAA;IAGE,WAAA;EAAA;AAAA;;;;;AArDR;;;;;;;;;;AAKK;AAML;iBCCgB,SAAA,CACd,QAAA,UACA,OAAA,GAAU,KAAA,EAAO,aAAA,WACjB,OAAA,GAAU,aAAa;;;;;;ADfzB;;;;;;;;;;iBEUgB,cAAA,CAAe,KAAa;;;;AFV5C;;;;;;;;iBGyKgB,cAAA,CACd,QAAA,UACA,OAAA,GAAU,KAAA,EAAO,aAAA,WACjB,OAAA,GAAU,aAAa;;AHvKpB;AAML;iBG2NgB,WAAA,CAAY,KAAa;;;;iBAWzB,YAAA,CAAa,KAAa;;;;iBAY1B,eAAA,CAAA,GAAmB,MAAM,CAAC,GAAA;;AHtOjC;AAMT;iBGuOgB,oBAAA,CAAA,GAAwB,aAAa;EACnD,QAAA;EACA,KAAA;EACA,WAAA;AAAA;AAAA,iBAWc,aAAA,CAAA;;;;;AHlRhB;;iBIgBgB,aAAA,CAAc,QAAA,WAAmB,QAAQ;;;;iBAsCzC,YAAA,CAAa,KAAA,EAAO,aAAA,EAAe,KAAA,EAAO,QAAQ;;;;iBAalD,WAAA,CAAY,KAAe,EAAR,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyreon/hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Reactive keyboard shortcut management for Pyreon — scope-aware, conflict detection",
|
|
5
5
|
"homepage": "https://github.com/pyreon/pyreon/tree/main/packages/hotkeys#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -39,14 +39,13 @@
|
|
|
39
39
|
"lint": "oxlint ."
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@happy-dom/global-registrator": "^20.
|
|
43
|
-
"@pyreon/core": "^0.25.1",
|
|
42
|
+
"@happy-dom/global-registrator": "^20.9.0",
|
|
44
43
|
"@pyreon/manifest": "0.13.1",
|
|
45
|
-
"@pyreon/
|
|
46
|
-
"@vitus-labs/tools-lint": "^2.
|
|
44
|
+
"@pyreon/vitest-config": "0.13.1",
|
|
45
|
+
"@vitus-labs/tools-lint": "^2.5.0"
|
|
47
46
|
},
|
|
48
|
-
"
|
|
49
|
-
"@pyreon/core": "^0.
|
|
50
|
-
"@pyreon/reactivity": "^0.
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@pyreon/core": "^0.26.0",
|
|
49
|
+
"@pyreon/reactivity": "^0.26.0"
|
|
51
50
|
}
|
|
52
51
|
}
|