Skip to content

feat : import support both app and VIA format#26

Open
AayushM0 wants to merge 4 commits into
Keylab-dev:mainfrom
AayushM0:feat/via-import-export
Open

feat : import support both app and VIA format#26
AayushM0 wants to merge 4 commits into
Keylab-dev:mainfrom
AayushM0:feat/via-import-export

Conversation

@AayushM0
Copy link
Copy Markdown

@AayushM0 AayushM0 commented Mar 23, 2026

Overview

Adds full support for importing and exporting VIA-compatible keymap JSON files.

This enables interoperability with the VIA ecosystem while preserving compatibility with KeyLab’s internal keymap format.


Problem

Previously, the application only supported its internal keymap format:

{ "name": "...", "keyboard": "...", "layers": [...] }

This made it incompatible with VIA keymaps, which use:

{ "version": 1, "layers": [...] }

Solution

Import

  • Added importAnyKeymap to support both:
    • VIA format: { version, layers }
    • KeyLab format: { name, keyboard, layers }
  • Centralized import logic in keymap.ts:
    • JSON parsing
    • Structure validation (validateLayers)
    • Layer normalization
  • Implemented normalization:
    • Pads layers with "KC_NO" if too short
    • Trims layers if too long
    • Ensures a minimum number of layers
  • Simplified handleImport in page.tsx to only handle state updates

Export

  • Added exportToVIA for VIA-compatible export:
{ "version": 1, "layers": [...] }
  • Retained exportKeymap for internal KeyLab format:
{ "name": "...", "keyboard": "...", "layers": [...] }
  • Ensures exported keymaps reflect normalized internal state

UI Changes

  • Updated toolbar to include two export options:
    • Export VIA (primary)
    • Export KeyLab (secondary)
  • Added separate handlers:
    • handleExportVIA
    • handleExportKeyLab
  • Kept UI simple and consistent with existing design

Behavior

Import

  • Accepts:
    • VIA format: { version, layers }
    • KeyLab format: { name, keyboard, layers }
  • Validates structure and keycodes
  • Automatically normalizes:
    • Layer length to match keyboard layout
    • Ensures minimum number of layers

Export

  • VIA export produces standard VIA-compatible JSON
  • KeyLab export preserves metadata for re-import

Design Notes

  • Import logic is fully self-contained in keymap.ts
  • UI layer is simplified and only manages state
  • No breaking changes to existing functionality
  • Code formatting and style aligned with project conventions

Related to issue #4

Updates

  • Moved normalization logic from page.tsx to keymap.ts
  • Simplified importAnyKeymap
  • Removed old importKeymap
  • Addressed initial review feedback
  • Ensured consistent formatting across the codebase

Adding images for reference

on importing

data = {
"version": 1,
"layers": [
[
"KC_Q","KC_W","KC_E","KC_R","KC_T",
"KC_Y","KC_U","KC_I","KC_O","KC_P",
"KC_A","KC_S","KC_D","KC_F","KC_G"
]
]
}

we get

image

Final UI

image

Export VIA - highlighted

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 23, 2026

@AayushM0 is attempting to deploy a commit to the Ava Consult Team on Vercel.

A member of the Team first needs to authorize it.

@AayushM0 AayushM0 marked this pull request as ready for review March 24, 2026 13:36
Copy link
Copy Markdown

@karava karava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Clean separation of import/export logic, and the VIA format support is solid.

One small typo to fix:

  • In page.tsx, the KeyLab export filename is "kyelab-keymap.json" — should be "keylab-keymap.json"

(Or "zumap-keymap.json" if we're going with the new name 😄)

Otherwise, ready to merge. Nice work @AayushM0! 🎉

@AayushM0
Copy link
Copy Markdown
Author

Hello i have fixed the typo and the final PR should be good to go now

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.

2 participants