Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(developer): .keyboard_info examples should use keys as a string 🎺 #9711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/schemas/keyboard_info/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Documentation at https://help.keyman.com/developer/cloud/keyboard_info
# .keyboard_info version history

## 2023-08-11 2.0 stable
* Removed legacyId, documentationFilename, documentationFileSize. Source vs distribution keyboard_info distinction is removed.
* Removed legacyId, documentationFilename, documentationFileSize. Source vs distribution keyboard_info distinction is removed. Example key sequences are simplified.

## 2019-09-06 1.0.6 stable
* No changes (see api.keyman.com#36 and api.keyman.com#59. Reverted in 2020-06-10.).
Expand Down
18 changes: 1 addition & 17 deletions common/schemas/keyboard_info/keyboard_info.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,14 @@
"KeyboardExampleInfo": {
"type": "object",
"properties": {
"keys": {
"type": "array",
"items": { "$ref": "#/definitions/KeyboardExampleKeyInfo" }
},
"keys": { "type": "string" },
"text": { "type": "string" },
"note": { "type": "string" }
},
"required": ["keys", "text"],
"additionalProperties": false
},

"KeyboardExampleKeyInfo": {
"type": "object",
"properties": {
"key": { "type": "string" },
"modifiers": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["key"],
"additionalProperties": false
},

"KeyboardPlatformInfo": {
"type": "object",
"patternProperties": {
Expand Down
23 changes: 0 additions & 23 deletions developer/src/kmc-keyboard-info/src/example-keys.ts

This file was deleted.

8 changes: 5 additions & 3 deletions developer/src/kmc-keyboard-info/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { validateMITLicense } from "@keymanapp/developer-utils";
import { KmpCompiler } from "@keymanapp/kmc-package";

import { SchemaValidators } from "@keymanapp/common-types";
import { packageKeysExamplesToKeyboardInfo } from "./example-keys.js";

const regionNames = new Intl.DisplayNames(['en'], { type: "region" });
const scriptNames = new Intl.DisplayNames(['en'], { type: "script" });
Expand Down Expand Up @@ -288,7 +287,10 @@ export class KeyboardInfoCompiler {
if(!SchemaValidators.default.keyboard_info(keyboard_info)) {
// This is an internal fatal error; we should not be capable of producing
// invalid output, so it is best to throw and die
throw new Error((<any>SchemaValidators.default.keyboard_info).errorsText());
throw new Error(JSON.stringify({
keyboard_info: keyboard_info,
error: SchemaValidators.default.keyboard_info.errors
}, null, 2));
}

return new TextEncoder().encode(jsonOutput);
Expand Down Expand Up @@ -390,7 +392,7 @@ export class KeyboardInfoCompiler {
if(example.id == bcp47) {
language.examples.push({
// we don't copy over example.id
keys: packageKeysExamplesToKeyboardInfo(example.keys),
keys: example.keys,
note: example.note,
text: example.text
});
Expand Down
20 changes: 14 additions & 6 deletions developer/src/kmc-keyboard-info/src/keyboard-info-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ export interface KeyboardInfoFileLanguageFont {
}

export interface KeyboardInfoFileExample {
keys?: KeyboardInfoFileExampleKey[];
/**
* A space-separated list of keys.
* - modifiers indicated with "+"
* - spacebar is "space"
* - plus key is "shift+=" or "plus" on US English (all other punctuation as per key cap).
* - Hardware modifiers are: "shift", "ctrl", "alt", "left-ctrl",
* "right-ctrl", "left-alt", "right-alt"
* - Key caps should generally be their character for desktop (Latin script
* case insensitive), or the actual key cap for touch
* - Caps Lock should be indicated with "caps-on", "caps-off"
*
* e.g. "shift+a b right-alt+c space plus z z z" represents something like: "Ab{AltGr+C} +zzz"
*/
keys?: string;
text?: string;
note?: string;
}

export interface KeyboardInfoFileExampleKey {
key: string;
modifiers?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
]
},
"examples": [{
"keys": [
{ "key": "x" },
{ "key": "j" },
{ "key": "m" },
{ "key": "E" },
{ "key": "r" }
],
"keys": "x j m E r",
"text": "\u1781\u17D2\u1798\u17C2\u179A",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this being reverted from #9621? Also, how would this look in regard to #9671, and how would the issue be affected?

Copy link
Member Author

Choose a reason for hiding this comment

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

I opted to go with the much shorter .kps format and not have two different formats for key strings.

For #9671, I don't really have a good answer, not sure what useful test to put in for that at present. The pattern is deliberately open-ended because we don't know what the key caps will have. Only four substrings have meaning:

  • : key delimiter, e.g. x j m shift+e r
  • +: modifier joiner, e.g. shift+ralt+z, or shift+3.
  • space: longhand for spacebar, e.g. k a space m r, and
  • plus: + key, made available to avoid confusion with specs like shift+plus, which would otherwise be shift++.

These are not intended to be used to generate key events -- they are supposed to be human readable keys.

"note": "Name of language"
}],
Expand Down