anki/ts/editor/TemplateButtons.svelte

193 lines
6.6 KiB
Svelte
Raw Normal View History

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import * as tr from "lib/i18n";
import { bridgeCommand } from "lib/bridgecommand";
import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
import IconButton from "components/IconButton.svelte";
import DropdownMenu from "components/DropdownMenu.svelte";
import DropdownItem from "components/DropdownItem.svelte";
import WithDropdownMenu from "components/WithDropdownMenu.svelte";
import WithShortcut from "components/WithShortcut.svelte";
2021-06-17 15:30:05 +02:00
import WithState from "components/WithState.svelte";
import ClozeButton from "./ClozeButton.svelte";
import { wrap } from "./wrap";
import { appendInParentheses } from "./helpers";
2021-06-17 17:08:33 +02:00
import { forEditorField } from ".";
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
export let api = {};
function onAttachment(): void {
bridgeCommand("attach");
}
function onRecord(): void {
bridgeCommand("record");
}
2021-06-17 17:08:33 +02:00
function onHtmlEdit() {
forEditorField([], (field) => {
field.editingArea.toggleHtmlEdit();
})
}
</script>
<ButtonGroup {api}>
<ButtonGroupItem>
<WithShortcut shortcut={"F3"} let:createShortcut let:shortcutLabel>
<IconButton
tooltip={appendInParentheses(
tr.editingAttachPicturesaudiovideo(),
shortcutLabel
)}
2021-05-30 21:44:05 +02:00
iconSize={70}
on:click={onAttachment}
on:mount={createShortcut}
>
{@html paperclipIcon}
</IconButton>
</WithShortcut>
</ButtonGroupItem>
<ButtonGroupItem>
<WithShortcut shortcut={"F5"} let:createShortcut let:shortcutLabel>
<IconButton
tooltip={appendInParentheses(tr.editingRecordAudio(), shortcutLabel)}
2021-05-30 21:44:05 +02:00
iconSize={70}
2021-05-06 02:49:59 +02:00
on:click={onRecord}
on:mount={createShortcut}
>
{@html micIcon}
</IconButton>
</WithShortcut>
</ButtonGroupItem>
<ButtonGroupItem id="cloze">
<ClozeButton />
</ButtonGroupItem>
<ButtonGroupItem>
<WithDropdownMenu let:createDropdown let:menuId>
<IconButton on:mount={createDropdown}>
{@html functionIcon}
</IconButton>
<DropdownMenu id={menuId}>
<WithShortcut
shortcut={"Control+M, M"}
let:createShortcut
let:shortcutLabel
>
<DropdownItem
on:click={() => wrap("\\(", "\\)")}
on:mount={createShortcut}
>
{tr.editingMathjaxInline()}
<span class="ps-1 float-end">{shortcutLabel}</span>
</DropdownItem>
</WithShortcut>
<WithShortcut
shortcut={"Control+M, E"}
let:createShortcut
let:shortcutLabel
>
<DropdownItem
on:click={() => wrap("\\[", "\\]")}
on:mount={createShortcut}
>
{tr.editingMathjaxBlock()}
<span class="ps-1 float-end">{shortcutLabel}</span>
</DropdownItem>
</WithShortcut>
<WithShortcut
shortcut={"Control+M, C"}
let:createShortcut
let:shortcutLabel
>
<DropdownItem
on:click={() => wrap("\\(\\ce{", "}\\)")}
on:mount={createShortcut}
>
{tr.editingMathjaxChemistry()}
<span class="ps-1 float-end">{shortcutLabel}</span>
</DropdownItem>
</WithShortcut>
<WithShortcut
shortcut={"Control+T, T"}
let:createShortcut
let:shortcutLabel
>
<DropdownItem
on:click={() => wrap("[latex]", "[/latex]")}
on:mount={createShortcut}
>
{tr.editingLatex()}
<span class="ps-1 float-end">{shortcutLabel}</span>
</DropdownItem>
</WithShortcut>
<WithShortcut
shortcut={"Control+T, E"}
let:createShortcut
let:shortcutLabel
>
<DropdownItem
on:click={() => wrap("[$]", "[/$]")}
on:mount={createShortcut}
>
{tr.editingLatexEquation()}
<span class="ps-1 float-end">{shortcutLabel}</span>
</DropdownItem>
</WithShortcut>
<WithShortcut
shortcut={"Control+T, M"}
let:createShortcut
let:shortcutLabel
>
<DropdownItem
on:click={() => wrap("[$$]", "[/$$]")}
on:mount={createShortcut}
>
{tr.editingLatexMathEnv()}
<span class="ps-1 float-end">{shortcutLabel}</span>
</DropdownItem>
</WithShortcut>
</DropdownMenu>
</WithDropdownMenu>
</ButtonGroupItem>
<ButtonGroupItem>
<WithShortcut shortcut={"Control+Shift+X"} let:createShortcut let:shortcutLabel>
2021-06-17 15:30:05 +02:00
<WithState
key="htmledit"
update={(event) => { console.log(event); return true }}
let:state={active}
let:updateState
>
2021-06-17 15:30:05 +02:00
<IconButton
tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)}
iconSize={70}
{active}
on:click={(event) => {
2021-06-17 17:08:33 +02:00
onHtmlEdit();
2021-06-17 15:30:05 +02:00
updateState(event);
}}
on:mount={createShortcut}
>
{@html xmlIcon}
</IconButton>
</WithState>
</WithShortcut>
</ButtonGroupItem>
</ButtonGroup>