fix tinykeys ssr import

This commit is contained in:
Nikita Galaiko 2023-04-27 08:50:26 +02:00
parent 2ec56747da
commit 23069658b0
2 changed files with 22 additions and 20 deletions

View File

@ -1,24 +1,26 @@
import { building } from '$app/environment';
import tinykeys from 'tinykeys';
import type Events from '$lib/events';
export default (events: ReturnType<typeof Events>) => ({
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<typeof Events>) =>
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);
}
});
}
}));

View File

@ -46,6 +46,6 @@ export const load: LayoutLoad = wrapLoadWithSentry(async ({ fetch }) => {
posthog: Posthog(),
sentry: Sentry(),
events,
hotkeys: Hotkeys(events)
hotkeys: await Hotkeys(events)
};
});