mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Add WithShortcut
This commit is contained in:
parent
e3a7d1a9e3
commit
5152dce7b8
2 changed files with 44 additions and 0 deletions
7
ts/editor-toolbar/WithShortcut.d.ts
vendored
Normal file
7
ts/editor-toolbar/WithShortcut.d.ts
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import type { ToolbarItem } from "./types";
|
||||
|
||||
export interface WithShortcutProps {
|
||||
button: ToolbarItem;
|
||||
}
|
37
ts/editor-toolbar/WithShortcut.svelte
Normal file
37
ts/editor-toolbar/WithShortcut.svelte
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!--
|
||||
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";
|
||||
|
||||
export let button: ToolbarItem;
|
||||
/* export let event: string; */
|
||||
|
||||
function extend({
|
||||
className,
|
||||
...rest
|
||||
}: DynamicSvelteComponent): DynamicSvelteComponent {
|
||||
return {
|
||||
...rest,
|
||||
};
|
||||
}
|
||||
|
||||
function createShortcut({ detail }: CustomEvent): void {
|
||||
const button: HTMLButtonElement = detail.button;
|
||||
|
||||
document.addEventListener("click", () => {
|
||||
const event = new MouseEvent("click");
|
||||
|
||||
if (code === "KeyP") {
|
||||
button.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:component
|
||||
this={button.component}
|
||||
{...extend(button)}
|
||||
on:mount={createShortcut} />
|
Loading…
Reference in a new issue