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">
|
2021-04-22 01:14:38 +02:00
|
|
|
import { onDestroy } from "svelte";
|
2021-04-23 02:16:40 +02:00
|
|
|
import { registerShortcut, getPlatformString } from "lib/shortcuts";
|
2021-04-22 01:14:38 +02:00
|
|
|
|
2021-05-20 18:28:59 +02:00
|
|
|
export let shortcut: string[][];
|
2021-05-21 22:45:55 +02:00
|
|
|
export let useCode = false;
|
2021-04-21 16:05:08 +02:00
|
|
|
|
2021-04-27 21:01:44 +02:00
|
|
|
const shortcutLabel = getPlatformString(shortcut);
|
2021-04-21 16:05:08 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
let deregister: () => void;
|
2021-04-22 01:14:38 +02:00
|
|
|
|
2021-04-21 16:05:08 +02:00
|
|
|
function createShortcut({ detail }: CustomEvent): void {
|
2021-04-22 02:36:54 +02:00
|
|
|
const mounted: HTMLButtonElement = detail.button;
|
2021-04-22 17:52:27 +02:00
|
|
|
deregister = registerShortcut(
|
|
|
|
(event: KeyboardEvent) => {
|
2021-05-07 14:41:31 +02:00
|
|
|
mounted.dispatchEvent(new MouseEvent("click", event));
|
2021-04-22 03:25:31 +02:00
|
|
|
event.preventDefault();
|
2021-04-22 17:52:27 +02:00
|
|
|
},
|
|
|
|
shortcut,
|
2021-05-21 22:45:55 +02:00
|
|
|
useCode
|
2021-04-22 03:25:31 +02:00
|
|
|
);
|
2021-04-21 16:05:08 +02:00
|
|
|
}
|
2021-04-22 01:14:38 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
onDestroy(() => deregister());
|
2021-04-21 16:05:08 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-27 21:01:44 +02:00
|
|
|
<slot {createShortcut} {shortcutLabel} />
|