mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-08 11:02:50 +00:00
feat: add vocabulary export
This commit is contained in:
@@ -124,6 +124,7 @@ const de = {
|
|||||||
CONFIRM: "Überschreiben",
|
CONFIRM: "Überschreiben",
|
||||||
ABORT: "Überspringen",
|
ABORT: "Überspringen",
|
||||||
},
|
},
|
||||||
|
VOCABULARY: "Vokabelliste",
|
||||||
TRY_TYPING: "Versuche hier zu tippen",
|
TRY_TYPING: "Versuche hier zu tippen",
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ const en = {
|
|||||||
CONFIRM: "Overwrite",
|
CONFIRM: "Overwrite",
|
||||||
ABORT: "Skip",
|
ABORT: "Skip",
|
||||||
},
|
},
|
||||||
|
VOCABULARY: "Vocabulary",
|
||||||
TRY_TYPING: "Try typing here",
|
TRY_TYPING: "Try typing here",
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
|
|||||||
@@ -43,6 +43,24 @@
|
|||||||
buildIndex($chords, $osLayout).then(searchIndex.set);
|
buildIndex($chords, $osLayout).then(searchIndex.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function plainPhrase(phrase: number[], osLayout: Map<string, string>) {
|
||||||
|
return phrase
|
||||||
|
.map((it) => {
|
||||||
|
const info = KEYMAP_CODES.get(it);
|
||||||
|
if (!info) return "";
|
||||||
|
|
||||||
|
const bestGuess =
|
||||||
|
(info.keyCode && osLayout.get(info.keyCode)) ||
|
||||||
|
info.display ||
|
||||||
|
info.id ||
|
||||||
|
"";
|
||||||
|
|
||||||
|
return bestGuess.length === 1 ? bestGuess : "";
|
||||||
|
})
|
||||||
|
.filter((it) => !!it)
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
async function buildIndex(
|
async function buildIndex(
|
||||||
chords: ChordInfo[],
|
chords: ChordInfo[],
|
||||||
osLayout: Map<string, string>,
|
osLayout: Map<string, string>,
|
||||||
@@ -60,20 +78,7 @@
|
|||||||
progress = i;
|
progress = i;
|
||||||
|
|
||||||
if ("phrase" in chord) {
|
if ("phrase" in chord) {
|
||||||
await index.addAsync(
|
await index.addAsync(i, plainPhrase(chord.phrase, osLayout));
|
||||||
i,
|
|
||||||
chord.phrase
|
|
||||||
.map((it) => {
|
|
||||||
const info = KEYMAP_CODES.get(it);
|
|
||||||
if (!info) return "";
|
|
||||||
|
|
||||||
return (
|
|
||||||
(info.keyCode && osLayout.get(info.keyCode)) || info.id || ""
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.filter((it) => !!it)
|
|
||||||
.join(""),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
@@ -108,6 +113,24 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function downloadVocabulary() {
|
||||||
|
const vocabulary = new Set(
|
||||||
|
$chords.map((it) =>
|
||||||
|
"phrase" in it ? plainPhrase(it.phrase, $osLayout).trim() : "",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
vocabulary.delete("");
|
||||||
|
const blob = new Blob([Array.from(vocabulary).join("|")], {
|
||||||
|
type: "text/plain",
|
||||||
|
});
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = "vocabulary.txt";
|
||||||
|
a.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
const items = derived(
|
const items = derived(
|
||||||
[searchFilter, chords],
|
[searchFilter, chords],
|
||||||
([filter, chords]) =>
|
([filter, chords]) =>
|
||||||
@@ -182,11 +205,17 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<textarea
|
<div class="sidebar">
|
||||||
placeholder={$LL.configure.chords.TRY_TYPING() +
|
<textarea
|
||||||
"\n\nDid you know? " +
|
placeholder={$LL.configure.chords.TRY_TYPING() +
|
||||||
randomTips[Math.floor(randomTips.length * Math.random())]}
|
"\n\nDid you know? " +
|
||||||
></textarea>
|
randomTips[Math.floor(randomTips.length * Math.random())]}
|
||||||
|
></textarea>
|
||||||
|
<button on:click={downloadVocabulary}
|
||||||
|
><span class="icon">download</span>
|
||||||
|
{$LL.configure.chords.VOCABULARY()}</button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
{/await}
|
{/await}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -207,7 +236,17 @@
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
> button {
|
||||||
|
padding-inline-start: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
|
flex: 1;
|
||||||
transition: outline-color 250ms ease;
|
transition: outline-color 250ms ease;
|
||||||
background: none;
|
background: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
|
|||||||
Reference in New Issue
Block a user