@tanstack/hotkeys 0.16.0 → 0.16.1

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.
@@ -8,14 +8,19 @@ function normalizeKeyboardEvent(event, platform) {
8
8
  altGraph = platform !== "mac" && typeof event.getModifierState === "function" && event.getModifierState("AltGraph");
9
9
  } catch {}
10
10
  const key = (event.key || "").normalize("NFC");
11
+ const normalizedKey = normalizeKeyName(key);
12
+ const controlAlt = platform === "windows" && altGraph && !altGraphTypedCharacter({
13
+ key: normalizedKey,
14
+ altGraph
15
+ });
11
16
  return {
12
- key: normalizeKeyName(key),
17
+ key: normalizedKey,
13
18
  code: event.code || "",
14
- ctrl: Boolean(event.ctrlKey),
19
+ ctrl: controlAlt || Boolean(event.ctrlKey),
15
20
  shift: Boolean(event.shiftKey),
16
- alt: Boolean(event.altKey),
21
+ alt: controlAlt || Boolean(event.altKey),
17
22
  meta: Boolean(event.metaKey),
18
- altGraph,
23
+ altGraph: altGraph && !controlAlt,
19
24
  location: event.location,
20
25
  isComposing: Boolean(event.isComposing) || key === "Process" || key === "Unidentified"
21
26
  };
@@ -41,6 +46,17 @@ function codeToLogicalKey(code) {
41
46
  Space: "Space"
42
47
  }[code];
43
48
  }
49
+ /**
50
+ * Whether AltGr changed what a key typed, as in AltGr+Q typing `@`. False when
51
+ * AltGr is not held, or when the key typed its plain value: a named key such
52
+ * as Home, or an ASCII letter or digit (AltGr+F typing `f` on layouts with
53
+ * nothing on that key).
54
+ */
55
+ function altGraphTypedCharacter(event) {
56
+ if (!event.altGraph) return false;
57
+ if (event.key === "Dead") return true;
58
+ return isPrintableKey(event.key) && !/^[A-Za-z0-9]$/.test(event.key);
59
+ }
44
60
  /** Tests for one Unicode code point, including characters represented by a surrogate pair. */
45
61
  function isPrintableKey(key) {
46
62
  return key !== "" && Array.from(key).length === 1;
@@ -88,4 +104,4 @@ function assertLogicalKey(key) {
88
104
  }
89
105
 
90
106
  //#endregion
91
- export { assertLogicalKey, codeToLogicalKey, isAsciiLetter, isCodeName, isLatinLetter, isPrintableKey, keysEqual, modifierAlias, normalizeKeyboardEvent, physicalCodeOf, splitChordParts };
107
+ export { altGraphTypedCharacter, assertLogicalKey, codeToLogicalKey, isAsciiLetter, isCodeName, isLatinLetter, isPrintableKey, keysEqual, modifierAlias, normalizeKeyboardEvent, physicalCodeOf, splitChordParts };
package/dist/_match.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { detectPlatform } from "./platform.js";
2
- import { codeToLogicalKey, isAsciiLetter, isLatinLetter, isPrintableKey, keysEqual, normalizeKeyboardEvent } from "./_keyboard-event.js";
2
+ import { altGraphTypedCharacter, codeToLogicalKey, isAsciiLetter, isLatinLetter, isPrintableKey, keysEqual, normalizeKeyboardEvent } from "./_keyboard-event.js";
3
3
  import { parseHotkey } from "./parse.js";
4
4
 
5
5
  //#region src/_match.ts
@@ -13,6 +13,7 @@ function matchKeyboardEvent(event, hotkey, platform = detectPlatform()) {
13
13
  };
14
14
  if (normalized.isComposing && (parsed.code !== void 0 || isPrintableKey(parsed.key))) return noMatch;
15
15
  if (normalized.altGraph && (parsed.ctrl || parsed.alt)) return noMatch;
16
+ if (normalized.altGraph && !altGraphTypedCharacter(normalized)) return noMatch;
16
17
  if (parsed.code !== void 0) {
17
18
  if (normalized.altGraph) return noMatch;
18
19
  if (!modifiersMatch(normalized, parsed, false)) return noMatch;
@@ -113,7 +113,8 @@ var HotkeyRecorder = class {
113
113
  if (!this.#keydownHandler) return;
114
114
  if (this.#options.ignoreInputs !== false && event.key !== "Escape" && isTypingEvent(event, document)) return;
115
115
  const platform = this.#options.platform ?? this.#platform;
116
- if (normalizeKeyboardEvent(event, platform).isComposing) return;
116
+ const normalized = normalizeKeyboardEvent(event, platform);
117
+ if (normalized.isComposing) return;
117
118
  captureRecordingEvent(event);
118
119
  event.preventDefault();
119
120
  event.stopPropagation();
@@ -122,7 +123,7 @@ var HotkeyRecorder = class {
122
123
  this.cancel();
123
124
  return;
124
125
  }
125
- const unmodified = !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey;
126
+ const unmodified = !normalized.ctrl && !normalized.shift && !normalized.alt && !normalized.meta && !normalized.altGraph;
126
127
  const multiStep = this.#maxSteps > 1;
127
128
  if ((event.key === "Backspace" || event.key === "Delete") && unmodified) {
128
129
  if (this.store.state.steps.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/hotkeys",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Type-safe, framework-agnostic keyboard hotkey management for the browser",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",