Fix website output

This commit is contained in:
Kasper 2025-06-17 08:41:41 +02:00
parent 9b49d8c418
commit 9c56b4ddb5
No known key found for this signature in database
GPG Key ID: 3E47D7CD99820B85

View File

@ -10,17 +10,19 @@
cpc = mod; cpc = mod;
}); });
let input = $state(""); function wasm_eval(input: string) {
let output = $derived.by(() => {
try {
if (!cpc || input.trim().length === 0) { if (!cpc || input.trim().length === 0) {
return ""; return "";
} }
try {
return cpc.wasm_eval(input); return cpc.wasm_eval(input);
} catch (e) { } catch (e) {
return ""; return "";
} }
}); }
let input = $state("");
let output = $derived(wasm_eval(input));
let saved_queries: { id: number; in: string; out: string }[] = $state([]); let saved_queries: { id: number; in: string; out: string }[] = $state([]);
</script> </script>
@ -62,22 +64,18 @@
type="text" type="text"
class="border border-gray-500/50 w-full rounded-lg px-3 py-2 outline-none" class="border border-gray-500/50 w-full rounded-lg px-3 py-2 outline-none"
bind:value={input} bind:value={input}
onkeydown={(e) => { onkeydown={async (e) => {
if (check_shortcut(e, "Enter")) { const input_el = e.currentTarget;
const input = e.currentTarget.value; const input = e.currentTarget.value;
let out; if (check_shortcut(e, "Enter")) {
try { const out = wasm_eval(input)
out = wasm_eval(e.currentTarget.value);
} catch (e) {
out = "";
}
console.log(out); console.log(out);
saved_queries.unshift({ saved_queries.unshift({
id: saved_queries.length, id: saved_queries.length,
in: input, in: input,
out, out,
}); });
e.currentTarget.value = ""; input_el.value = "";
output = ""; output = "";
} }
}} }}