diff --git a/src/lib/hotkeys.ts b/src/lib/hotkeys.ts index 522c49336..ebc78a26a 100644 --- a/src/lib/hotkeys.ts +++ b/src/lib/hotkeys.ts @@ -1,24 +1,26 @@ import { building } from '$app/environment'; -import tinykeys from 'tinykeys'; import type Events from '$lib/events'; -export default (events: ReturnType) => ({ - on: (combo: string, callback: (event: KeyboardEvent) => void) => { - if (building) return () => {}; - const comboContainsControlKeys = - combo.includes('Meta') || combo.includes('Alt') || combo.includes('Ctrl'); - return tinykeys(window, { - [combo]: (event) => { - const target = event.target as HTMLElement; - const isInput = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA'; - if (isInput && !comboContainsControlKeys) return; +export default async (events: ReturnType) => + building + ? { on: () => () => {} } + : await import('tinykeys').then(({ default: tinykeys }) => ({ + on: (combo: string, callback: (event: KeyboardEvent) => void) => { + if (building) return () => {}; + const comboContainsControlKeys = + combo.includes('Meta') || combo.includes('Alt') || combo.includes('Ctrl'); + return tinykeys(window, { + [combo]: (event) => { + const target = event.target as HTMLElement; + const isInput = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA'; + if (isInput && !comboContainsControlKeys) return; - event.preventDefault(); - event.stopPropagation(); + event.preventDefault(); + event.stopPropagation(); - events.closeCommandPalette(); - callback(event); - } - }); - } -}); + events.closeCommandPalette(); + callback(event); + } + }); + } + })); diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 5619ede66..1ca3c54eb 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -46,6 +46,6 @@ export const load: LayoutLoad = wrapLoadWithSentry(async ({ fetch }) => { posthog: Posthog(), sentry: Sentry(), events, - hotkeys: Hotkeys(events) + hotkeys: await Hotkeys(events) }; });