Skip to content

refactor(keycodes): Consolidate ZMK names and picker labels into one TS table#10

Merged
numachang merged 2 commits into
mainfrom
refactor/keycodes-ssot
May 25, 2026
Merged

refactor(keycodes): Consolidate ZMK names and picker labels into one TS table#10
numachang merged 2 commits into
mainfrom
refactor/keycodes-ssot

Conversation

@numachang

Copy link
Copy Markdown
Owner

Summary

Resolves the triple-defined key naming problem tracked in #2: ZMK keymap names and picker UI labels used to live in two independent files (an inline ZMK_KEYCODES array in keymap-parser.ts and hid-usage-metadata.json from upstream PR zmkfirmware#159), and could drift — HID 7:230 was famously labelled AltGr in the picker but exported as &kp RALT.

This PR promotes both into a single TypeScript table in src/keycodes.ts, so editing one row updates both the picker label and the export name.

  • New src/keycodes.ts (one Keycode row per (page, usage), carrying name + short / med / long + category).
  • keymap-parser.ts derives lookups from rows with name; parser also accepts any curated short / med / long as an alias (so hand-edited files using picker labels still resolve).
  • hid-usages.ts looks up labels from the same table; HID spec table remains as the fallback for usages we don't curate.
  • hid-usage-metadata.json removed.
  • Adds Vitest and snapshot baselines (npm test) that lock in the pre-refactor behaviour. Snapshots are byte-for-byte identical post-refactor — proof there's no visual regression.

Closes #2.

Test plan

  • npx vitest run — 7/7 pass.
  • npx tsc -p . — clean.
  • npx vite build — clean.
  • Snapshot baselines match (no picker label changes).

🤖 Generated with Claude Code

numachang and others added 2 commits May 25, 2026 21:07
Lock in the current behaviour of the picker label pipeline
(hid_usage_get_metadata / hid_usage_get_label) and the keymap-parser
canonical table before consolidating them into a single source of
truth. Any drift introduced by the upcoming SSOT refactor will trip
the snapshots loudly.

- Add Vitest as a devDependency with `npm test` / `npm run test:watch`.
- src/hid-usages.test.ts snapshots every (page, usage) pair that
  surfaces a label today, plus the page list.
- src/keymap-parser.test.ts snapshots the full canonical name table
  and asserts forward/reverse name<->code round-trip plus modifier
  wrapper round-trip.

Co-Authored-By: Claude <noreply@anthropic.com>
…TS table

ZMK keymap text names (used by import / export) and picker UI labels
(used by the keycap grid) used to live in two independent places — an
inline `ZMK_KEYCODES` array inside keymap-parser.ts and the
hid-usage-metadata.json from upstream PR zmkfirmware#159. Both could drift; HID
7:230 famously labelled "AltGr" in the picker but exported as
`&kp RALT`.

Promote both to a single TS table in src/keycodes.ts:

- One `Keycode` row per (page, usage) carries the ZMK `name`, picker
  `short` / `med` / `long`, and picker `category`. Editing one row
  updates both the picker and the exporter.
- keymap-parser.ts derives `keycodeLookup` / `codeToZmkName` from the
  rows whose `name` is set; the parser-side alias map widens to also
  accept any `short` / `med` / `long` label as a parser input, so
  hand-edited keymaps using picker labels (e.g. "Volume Up") still
  resolve.
- hid-usages.ts looks up labels from the same table, falling back to
  the HID spec name for usages we don't curate.
- hid-usage-metadata.json is removed.

The Vitest snapshot baselines from the previous commit catch any
visual regression — picker labels and the canonical name table are
byte-for-byte identical post-refactor. Closes #2.

Co-Authored-By: Claude <noreply@anthropic.com>
@numachang numachang merged commit f19baba into main May 25, 2026
1 check was pending
@numachang numachang deleted the refactor/keycodes-ssot branch May 25, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Triple-defined key naming: pick a SSOT and derive labels from it

1 participant