Compare commits

...

2 Commits

Author SHA1 Message Date
Daniel Lorch 48240eebe0 Move language name definitions into the keyboard layout files 2025-05-08 20:26:59 +02:00
Daniel Lorch 4d840b65a9 Move guard statements outside of loop 2025-05-08 20:25:53 +02:00
13 changed files with 61 additions and 40 deletions

View File

@ -56,14 +56,13 @@ export default function PasteModal() {
setPasteMode(false); setPasteMode(false);
setDisableVideoFocusTrap(false); setDisableVideoFocusTrap(false);
if (rpcDataChannel?.readyState !== "open" || !TextAreaRef.current) return; if (rpcDataChannel?.readyState !== "open" || !TextAreaRef.current) return;
if (!keyboardLayout) return;
if (!chars[keyboardLayout]) return;
const text = TextAreaRef.current.value; const text = TextAreaRef.current.value;
try { try {
for (const char of text) { for (const char of text) {
if (!keyboardLayout) continue;
if (!chars[keyboardLayout]) continue;
const { key, shift, altRight, deadKey, accentKey } = chars[keyboardLayout][char] const { key, shift, altRight, deadKey, accentKey } = chars[keyboardLayout][char]
if (!key) continue; if (!key) continue;

View File

@ -1,42 +1,42 @@
import { chars as chars_cs_CZ } from "@/keyboardLayouts/cs_CZ" import { chars as chars_cs_CZ, name as name_cs_CZ } from "@/keyboardLayouts/cs_CZ"
import { chars as chars_en_UK } from "@/keyboardLayouts/en_UK" import { chars as chars_en_UK, name as name_en_UK } from "@/keyboardLayouts/en_UK"
import { chars as chars_en_US } from "@/keyboardLayouts/en_US" import { chars as chars_en_US, name as name_en_US } from "@/keyboardLayouts/en_US"
import { chars as chars_fr_FR } from "@/keyboardLayouts/fr_FR" import { chars as chars_fr_FR, name as name_fr_FR } from "@/keyboardLayouts/fr_FR"
import { chars as chars_de_DE } from "@/keyboardLayouts/de_DE" import { chars as chars_de_DE, name as name_de_DE } from "@/keyboardLayouts/de_DE"
import { chars as chars_it_IT } from "@/keyboardLayouts/it_IT" import { chars as chars_it_IT, name as name_it_IT } from "@/keyboardLayouts/it_IT"
import { chars as chars_nb_NO } from "@/keyboardLayouts/nb_NO" import { chars as chars_nb_NO, name as name_nb_NO } from "@/keyboardLayouts/nb_NO"
import { chars as chars_es_ES } from "@/keyboardLayouts/es_ES" import { chars as chars_es_ES, name as name_es_ES } from "@/keyboardLayouts/es_ES"
import { chars as chars_sv_SE } from "@/keyboardLayouts/sv_SE" import { chars as chars_sv_SE, name as name_sv_SE } from "@/keyboardLayouts/sv_SE"
import { chars as chars_fr_CH } from "@/keyboardLayouts/fr_CH" import { chars as chars_fr_CH, name as name_fr_CH } from "@/keyboardLayouts/fr_CH"
import { chars as chars_de_CH } from "@/keyboardLayouts/de_CH" import { chars as chars_de_CH, name as name_de_CH } from "@/keyboardLayouts/de_CH"
type KeyInfo = { key: string | number; shift?: boolean, altRight?: boolean } type KeyInfo = { key: string | number; shift?: boolean, altRight?: boolean }
export type KeyCombo = KeyInfo & { deadKey?: boolean, accentKey?: KeyInfo } export type KeyCombo = KeyInfo & { deadKey?: boolean, accentKey?: KeyInfo }
export const layouts = { export const layouts: Record<string, string> = {
"cs_CZ": "Czech", cs_CZ: name_cs_CZ,
"en_UK": "English (UK)", en_UK: name_en_UK,
"en_US": "English (US)", en_US: name_en_US,
"fr_FR": "French", fr_FR: name_fr_FR,
"de_DE": "German", de_DE: name_de_DE,
"it_IT": "Italian", it_IT: name_it_IT,
"nb_NO": "Norwegian", nb_NO: name_nb_NO,
"es_ES": "Spanish", es_ES: name_es_ES,
"sv_SE": "Swedish", sv_SE: name_sv_SE,
"fr_CH": "Swiss French", fr_CH: name_fr_CH,
"de_CH": "Swiss German" de_CH: name_de_CH,
} as Record<string, string>; }
export const chars = { export const chars: Record<string, Record<string, KeyCombo>> = {
"cs_CZ": chars_cs_CZ, cs_CZ: chars_cs_CZ,
"en_UK": chars_en_UK, en_UK: chars_en_UK,
"en_US": chars_en_US, en_US: chars_en_US,
"fr_FR": chars_fr_FR, fr_FR: chars_fr_FR,
"de_DE": chars_de_DE, de_DE: chars_de_DE,
"it_IT": chars_it_IT, it_IT: chars_it_IT,
"nb_NO": chars_nb_NO, nb_NO: chars_nb_NO,
"es_ES": chars_es_ES, es_ES: chars_es_ES,
"sv_SE": chars_sv_SE, sv_SE: chars_sv_SE,
"fr_CH": chars_fr_CH, fr_CH: chars_fr_CH,
"de_CH": chars_de_CH, de_CH: chars_de_CH,
} as Record<string, Record <string, KeyCombo>> };

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "Czech";
const keyTrema = { key: "Backslash" } // tréma (umlaut), two dots placed above a vowel const keyTrema = { key: "Backslash" } // tréma (umlaut), two dots placed above a vowel
const keyAcute = { key: "Equal" } // accent aigu (acute accent), mark ´ placed above the letter const keyAcute = { key: "Equal" } // accent aigu (acute accent), mark ´ placed above the letter
const keyHat = { key: "Digit3", shift: true, altRight: true } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "Digit3", shift: true, altRight: true } // accent circonflexe (accent hat), mark ^ placed above the letter

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "Swiss German";
const keyTrema = { key: "BracketRight" } // tréma (umlaut), two dots placed above a vowel const keyTrema = { key: "BracketRight" } // tréma (umlaut), two dots placed above a vowel
const keyAcute = { key: "Minus", altRight: true } // accent aigu (acute accent), mark ´ placed above the letter const keyAcute = { key: "Minus", altRight: true } // accent aigu (acute accent), mark ´ placed above the letter
const keyHat = { key: "Equal" } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "Equal" } // accent circonflexe (accent hat), mark ^ placed above the letter

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "German";
const keyAcute = { key: "Equal" } // accent aigu (acute accent), mark ´ placed above the letter const keyAcute = { key: "Equal" } // accent aigu (acute accent), mark ´ placed above the letter
const keyHat = { key: "Backquote" } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "Backquote" } // accent circonflexe (accent hat), mark ^ placed above the letter
const keyGrave = { key: "Equal", shift: true } // accent grave, mark ` placed above the letter const keyGrave = { key: "Equal", shift: true } // accent grave, mark ` placed above the letter

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "English (UK)";
export const chars = { export const chars = {
A: { key: "KeyA", shift: true }, A: { key: "KeyA", shift: true },
B: { key: "KeyB", shift: true }, B: { key: "KeyB", shift: true },

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "English (US)";
export const chars = { export const chars = {
A: { key: "KeyA", shift: true }, A: { key: "KeyA", shift: true },
B: { key: "KeyB", shift: true }, B: { key: "KeyB", shift: true },

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "Spanish";
const keyTrema = { key: "Quote", shift: true } // tréma (umlaut), two dots placed above a vowel const keyTrema = { key: "Quote", shift: true } // tréma (umlaut), two dots placed above a vowel
const keyAcute = { key: "Quote" } // accent aigu (acute accent), mark ´ placed above the letter const keyAcute = { key: "Quote" } // accent aigu (acute accent), mark ´ placed above the letter
const keyHat = { key: "BracketRight", shift: true } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "BracketRight", shift: true } // accent circonflexe (accent hat), mark ^ placed above the letter

View File

@ -1,6 +1,8 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
import { chars as chars_de_CH } from "./de_CH" import { chars as chars_de_CH } from "./de_CH"
export const name = "Swiss French";
export const chars = { export const chars = {
...chars_de_CH, ...chars_de_CH,
"è": { key: "BracketLeft" }, "è": { key: "BracketLeft" },

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "French";
const keyTrema = { key: "BracketLeft", shift: true } // tréma (umlaut), two dots placed above a vowel const keyTrema = { key: "BracketLeft", shift: true } // tréma (umlaut), two dots placed above a vowel
const keyHat = { key: "BracketLeft" } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "BracketLeft" } // accent circonflexe (accent hat), mark ^ placed above the letter

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "Italian";
export const chars = { export const chars = {
A: { key: "KeyA", shift: true }, A: { key: "KeyA", shift: true },
B: { key: "KeyB", shift: true }, B: { key: "KeyB", shift: true },

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "Norwegian";
const keyTrema = { key: "BracketRight" } // tréma (umlaut), two dots placed above a vowel const keyTrema = { key: "BracketRight" } // tréma (umlaut), two dots placed above a vowel
const keyAcute = { key: "Equal", altRight: true } // accent aigu (acute accent), mark ´ placed above the letter const keyAcute = { key: "Equal", altRight: true } // accent aigu (acute accent), mark ´ placed above the letter
const keyHat = { key: "BracketRight", shift: true } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "BracketRight", shift: true } // accent circonflexe (accent hat), mark ^ placed above the letter

View File

@ -1,5 +1,7 @@
import { KeyCombo } from "../keyboardLayouts" import { KeyCombo } from "../keyboardLayouts"
export const name = "Swedish";
const keyTrema = { key: "BracketRight" } // tréma (umlaut), two dots placed above a vowel const keyTrema = { key: "BracketRight" } // tréma (umlaut), two dots placed above a vowel
const keyAcute = { key: "Equal" } // accent aigu (acute accent), mark ´ placed above the letter const keyAcute = { key: "Equal" } // accent aigu (acute accent), mark ´ placed above the letter
const keyHat = { key: "BracketRight", shift: true } // accent circonflexe (accent hat), mark ^ placed above the letter const keyHat = { key: "BracketRight", shift: true } // accent circonflexe (accent hat), mark ^ placed above the letter