2021-04-21 16:05:08 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="typescript">
|
|
|
|
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
|
|
|
import type { ToolbarItem } from "./types";
|
|
|
|
|
2021-04-22 01:14:38 +02:00
|
|
|
import { onDestroy } from "svelte";
|
|
|
|
import { registerShortcut } from "anki/shortcuts";
|
|
|
|
|
2021-04-21 16:05:08 +02:00
|
|
|
export let button: ToolbarItem;
|
2021-04-22 01:14:38 +02:00
|
|
|
export let shortcut: string;
|
2021-04-21 16:05:08 +02:00
|
|
|
|
2021-04-22 01:14:38 +02:00
|
|
|
function extend({ ...rest }: DynamicSvelteComponent): DynamicSvelteComponent {
|
2021-04-21 16:05:08 +02:00
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-22 01:14:38 +02:00
|
|
|
let deregister;
|
|
|
|
|
2021-04-21 16:05:08 +02:00
|
|
|
function createShortcut({ detail }: CustomEvent): void {
|
|
|
|
const button: HTMLButtonElement = detail.button;
|
2021-04-22 01:14:38 +02:00
|
|
|
deregister = registerShortcut(() => button.click(), shortcut);
|
2021-04-21 16:05:08 +02:00
|
|
|
}
|
2021-04-22 01:14:38 +02:00
|
|
|
|
|
|
|
onDestroy(() => deregister());
|
2021-04-21 16:05:08 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<svelte:component
|
|
|
|
this={button.component}
|
|
|
|
{...extend(button)}
|
|
|
|
on:mount={createShortcut} />
|