Add WithShortcut

This commit is contained in:
Henrik Giesel 2021-04-21 16:05:08 +02:00
parent e3a7d1a9e3
commit 5152dce7b8
2 changed files with 44 additions and 0 deletions

7
ts/editor-toolbar/WithShortcut.d.ts vendored Normal file
View 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;
}

View 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} />