aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/services
diff options
context:
space:
mode:
authorNick Coutsos <[email protected]>2021-11-13 19:29:55 -0500
committerNick Coutsos <[email protected]>2021-11-13 19:29:55 -0500
commit85d905380bfe64c1acb8172b2333ac969a8d8e2c (patch)
tree7377e5308211c874a534668abc77013a593529b9 /api/services
parent7207529cc23bba88d1d24e53d56163dc11afb6c3 (diff)
downloadkeymap-editor-85d905380bfe64c1acb8172b2333ac969a8d8e2c.tar.gz
keymap-editor-85d905380bfe64c1acb8172b2333ac969a8d8e2c.zip
Support layouts that don't define row/col positions
Diffstat (limited to 'api/services')
-rw-r--r--api/services/zmk/layout.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/api/services/zmk/layout.js b/api/services/zmk/layout.js
index 0e6ff96..383e710 100644
--- a/api/services/zmk/layout.js
+++ b/api/services/zmk/layout.js
@@ -16,9 +16,9 @@ function renderTable (layout, layer, opts={}) {
} = opts
const minWidth = useQuotes ? 9 : 7
const table = layer.reduce((map, code, i) => {
- const { row, col } = layout[i]
+ const { row = 0, col } = layout[i]
map[row] = map[row] || []
- map[row][col] = code
+ map[row][col || map[row].length] = code
return map
}, [])
@@ -68,6 +68,11 @@ function validateInfoJson(info) {
} else if (!Array.isArray(layout.layout)) {
errors.push(`layout ${name} must define "layout" array`)
} else {
+ const anyKeyHasPosition = layout.layout.some(key => (
+ key?.row !== undefined ||
+ key?.col !== undefined
+ ))
+
for (let i in layout.layout) {
const key = layout.layout[i]
const keyPath = `layouts[${name}].layout[${i}]`
@@ -87,6 +92,13 @@ function validateInfoJson(info) {
errors.push(`Key definition at ${keyPath} optional "${prop}" must be number`)
}
}
+ for (let prop of ['row', 'col']) {
+ if (anyKeyHasPosition && !(prop in key)) {
+ errors.push(`Key definition at ${keyPath} is missing "${prop}"`)
+ } else if (prop in key && (!Number.isInteger(key[prop]) || key[prop] < 0)) {
+ errors.push(`Key definition at ${keyPath} "${prop}" must be a non-negative integer`)
+ }
+ }
}
}
}