@tanstack/hotkeys 0.10.0 → 0.10.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.
- package/dist/format.d.ts +3 -2
- package/dist/format.js +9 -1
- package/package.json +1 -1
package/dist/format.d.ts
CHANGED
|
@@ -31,7 +31,8 @@ export type DisplayHotkey = RegisterableHotkey | ParsedHotkey | (string & {});
|
|
|
31
31
|
/**
|
|
32
32
|
* Formats a hotkey for display in a user interface.
|
|
33
33
|
*
|
|
34
|
-
* On macOS, uses symbols (
|
|
34
|
+
* On macOS, uses symbols (⇧⌘S) in Control, Option, Shift, Command order.
|
|
35
|
+
* Display ordering does not change the normalized hotkey used for registration.
|
|
35
36
|
* On Windows/Linux, uses text (Ctrl+Shift+S) with `+` separators.
|
|
36
37
|
* The separator can be customized with `separatorToken`.
|
|
37
38
|
* Physical codes use conventional display labels: `[KeyS]` becomes `S` and
|
|
@@ -46,7 +47,7 @@ export type DisplayHotkey = RegisterableHotkey | ParsedHotkey | (string & {});
|
|
|
46
47
|
* @example
|
|
47
48
|
* ```ts
|
|
48
49
|
* formatForDisplay('Mod+Shift+S', { platform: 'mac' })
|
|
49
|
-
* // Returns: '⌘
|
|
50
|
+
* // Returns: '⇧ ⌘ S' (symbols separated by spaces on macOS)
|
|
50
51
|
*
|
|
51
52
|
* formatForDisplay('Mod+Shift+S', { platform: 'windows' })
|
|
52
53
|
* // Returns: 'Ctrl+Shift+S'
|
package/dist/format.js
CHANGED
|
@@ -47,7 +47,15 @@ function formatForDisplay(hotkey, options = {}) {
|
|
|
47
47
|
const keySymbols = typeof symbols === "boolean" ? symbols : symbols.keys ?? true;
|
|
48
48
|
const separator = options.separatorToken ?? (platform === "mac" && modifierSymbols ? " " : "+");
|
|
49
49
|
const normalized = typeof hotkey === "object" && "modifiers" in hotkey ? normalizeHotkeyFromParsed(hotkey, platform) : normalizeRegisterableHotkey(hotkey, platform);
|
|
50
|
-
const
|
|
50
|
+
const segments = splitHotkeyParts(normalized);
|
|
51
|
+
if (platform === "mac") {
|
|
52
|
+
const modifierIndex = (segment) => {
|
|
53
|
+
const index = MODIFIER_ORDER.indexOf(segment === "Mod" ? "Meta" : segment);
|
|
54
|
+
return index === -1 ? MODIFIER_ORDER.length : index;
|
|
55
|
+
};
|
|
56
|
+
segments.sort((a, b) => modifierIndex(a) - modifierIndex(b));
|
|
57
|
+
}
|
|
58
|
+
const parts = segments.map((segment) => {
|
|
51
59
|
if (isModifierKey(segment)) {
|
|
52
60
|
const modifier = MODIFIER_ALIASES[segment] ?? MODIFIER_ALIASES[segment.toLowerCase()];
|
|
53
61
|
return platform === "mac" ? modifierSymbols ? MAC_MODIFIER_SYMBOLS[modifier] : MAC_MODIFIER_LABELS[modifier] : platform === "windows" ? WINDOWS_MODIFIER_LABELS[modifier] : LINUX_MODIFIER_LABELS[modifier];
|