mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-03 15:33:13 +03:00
fix tinykeys ssr import
This commit is contained in:
parent
2ec56747da
commit
23069658b0
@ -1,24 +1,26 @@
|
|||||||
import { building } from '$app/environment';
|
import { building } from '$app/environment';
|
||||||
import tinykeys from 'tinykeys';
|
|
||||||
import type Events from '$lib/events';
|
import type Events from '$lib/events';
|
||||||
|
|
||||||
export default (events: ReturnType<typeof Events>) => ({
|
export default async (events: ReturnType<typeof Events>) =>
|
||||||
on: (combo: string, callback: (event: KeyboardEvent) => void) => {
|
building
|
||||||
if (building) return () => {};
|
? { on: () => () => {} }
|
||||||
const comboContainsControlKeys =
|
: await import('tinykeys').then(({ default: tinykeys }) => ({
|
||||||
combo.includes('Meta') || combo.includes('Alt') || combo.includes('Ctrl');
|
on: (combo: string, callback: (event: KeyboardEvent) => void) => {
|
||||||
return tinykeys(window, {
|
if (building) return () => {};
|
||||||
[combo]: (event) => {
|
const comboContainsControlKeys =
|
||||||
const target = event.target as HTMLElement;
|
combo.includes('Meta') || combo.includes('Alt') || combo.includes('Ctrl');
|
||||||
const isInput = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
|
return tinykeys(window, {
|
||||||
if (isInput && !comboContainsControlKeys) return;
|
[combo]: (event) => {
|
||||||
|
const target = event.target as HTMLElement;
|
||||||
|
const isInput = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
|
||||||
|
if (isInput && !comboContainsControlKeys) return;
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
events.closeCommandPalette();
|
events.closeCommandPalette();
|
||||||
callback(event);
|
callback(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
@ -46,6 +46,6 @@ export const load: LayoutLoad = wrapLoadWithSentry(async ({ fetch }) => {
|
|||||||
posthog: Posthog(),
|
posthog: Posthog(),
|
||||||
sentry: Sentry(),
|
sentry: Sentry(),
|
||||||
events,
|
events,
|
||||||
hotkeys: Hotkeys(events)
|
hotkeys: await Hotkeys(events)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user