feat: Parse remap.layout_options extension in keyboard.json - #928
Open
yoichiro wants to merge 1 commit into
Open
feat: Parse remap.layout_options extension in keyboard.json#928yoichiro wants to merge 1 commit into
yoichiro wants to merge 1 commit into
Conversation
Adds the phase 1 types and parser for the runtime layout options extension embedded in a QMK keyboard.json. QMK ignores the unknown `remap` field, and the `remap-qmk-module` build tool later converts it into VIA-style `layouts.labels` + KLE-encoded `layouts.keymap`. The parser mirrors the invariants that will be enforced server-side: - one-element labels are the implicit Off/On idiom; two-element labels are ambiguous and rejected up-front - variants[].option must index into labels, variants[].choice must fit that option's choice count, and every required (option, choice) must be covered by at least one variant - a matrix cell cannot appear both in LAYOUT_default and in variants, and cannot repeat within the same (option, choice) The next phases will surface this in the Form Editor UI and in the Visual Editor preview.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of the runtime layout options work coordinated with the
remap-qmk-moduleandremap-build-serversessions: the type definitions and validating parser for a new Remap-only extension field in QMK'skeyboard.json.RemapLayoutOptions/RemapLayoutVarianttypes undersrc/services/workbench/types/RemapLayoutOptions.ts, mirroring the exchanged spec (remap.layout_options.{labels, variants}).parseRemapLayoutOptions()undersrc/services/workbench/RemapLayoutOptionsParser.ts. A missingremap.layout_optionsis a valid state and yields{ success: true, data: null }; a present-but-broken field yields{ success: false, errors: [...] }with a full list of human-readable errors.remapfield, andremap-qmk-modulewill convert it into VIA-stylelayouts.labels+ KLE-encodedlayouts.keymapat firmware-build time. Client-side validation mirrors the invariants the converter enforces so any keyboard.json that the Form Editor accepts will convert cleanly server-side.Invariants enforced by the parser
labels(e.g.["Split Backspace"]) is the implicit Off/On idiom. Two-elementlabelsare ambiguous and are rejected up-front so a well-defined mapping to VIA JSON is always possible.variants[].optionmust index intolabels.variants[].choicemust fit that option's choice count (two for a one-element label,labels[option].length - 1for an explicit multi-choice label).(option, choice)pair must be covered by at least one variant.variants, and cannot repeat within the same(option, choice).layoutDefaultKeysinput drives the LAYOUT-vs-variants matrix-collision check; callers that only want to validate theremapsection in isolation can omit it.Test plan
npm run type-checkpasses.npm run lint— no new errors from the touched files.npm test -- --run— all tests pass (1237 total).npm test -- RemapLayoutOptionsParser.test.ts --run— 24 targeted cases pass, covering: absence handling (null/ non-object inputs), a minimal Split Backspace layout, implicit Off/On labels, an explicit three-choice layout, optional key fields (w,h,r,rx,ry) round-trip, two-element label rejection, empty label / non-array label rejection, emptyvariantsrejection, emptyvariants[].keysrejection, out-of-rangeoption/choice, malformedmatrix/ missingx/y, missing choice coverage (implicit and explicit), matrix collision withLAYOUT_default,(option, choice, matrix)duplication withinvariants, same matrix allowed across different(option, choice)pairs, and the LAYOUT cross-check being skipped whenlayoutDefaultKeysis omitted.