kripke: add math keys

This commit is contained in:
2025-09-09 06:39:02 +09:00
parent 925fd26341
commit 1fe870bdbc

View File

@@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import Katex from "$lib/components/katex.svelte";
import { type Formula, prettyPrint, tryParse } from "@cannorin/kripke"; import { type Formula, prettyPrint, tryParse } from "@cannorin/kripke";
import { formulaHistory } from "../lib/store"; import { formulaHistory } from "../lib/store";
@@ -18,6 +19,7 @@ let history = $derived(
.slice(0, 10) .slice(0, 10)
.map(([a, _ac]) => a), .map(([a, _ac]) => a),
); );
let inputElement: HTMLInputElement;
$effect(() => { $effect(() => {
const fml = tryParse(input); const fml = tryParse(input);
@@ -39,11 +41,36 @@ $effect(() => {
</datalist> </datalist>
{/if} {/if}
<input {#snippet mathKey(latexCommand: string, actualText?: string)}
id="formula" <button onclick={(e) => {
list="formula-history" e.preventDefault();
class={["rounded border border-foreground ring-0 focus:outline-none focus:ring-0 p-2 w-full", error && "border-primary"]} input += actualText ?? latexCommand;
type="text" inputElement.focus();
placeholder="Enter modal formula" }}>
disabled={disabled} <Katex math={latexCommand} />
bind:value={input} /> </button>
{/snippet}
<div class="rounded border border-foreground w-full">
<div class="border-0 border-b border-muted px-2 py-1 flex justify-between">
{@render mathKey("\\top", "")}
{@render mathKey("\\bot", "⊥")}
{@render mathKey("\\neg", "¬")}
{@render mathKey("\\Box", "□")}
{@render mathKey("\\Diamond", "◇")}
{@render mathKey("\\land", "∧")}
{@render mathKey("\\lor", "")}
{@render mathKey("\\to", "→")}
{@render mathKey("\\leftrightarrow", "↔")}
</div>
<input
id="formula"
list="formula-history"
class={["ring-0 rounded focus:outline-none p-2 focus:ring-0 w-full", error && "border-primary"]}
type="text"
placeholder="Enter modal formula"
disabled={disabled}
bind:value={input}
bind:this={inputElement} />
</div>