Skip to content

Commit fe8d7e7

Browse files
committed
moved tinykeys to onMount dynamic import
1 parent 99a0774 commit fe8d7e7

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/lib/components/CommandPalette.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { paletteStore } from '../store/PaletteStore';
33
import { onDestroy, onMount, afterUpdate } from 'svelte';
4-
import tinyKeys, { parseKeybinding } from 'tinykeys';
4+
// import tinyKeys, { parseKeybinding } from 'tinykeys';
55
import Portal from './Portal.svelte';
66
import ResultPanel from './ResultPanel.svelte';
77
import KeyboardButton from './KeyboardButton.svelte';
@@ -27,6 +27,7 @@
2727
2828
const storeMethods = createStoreMethods();
2929
const actionMap = createActionMap(commands);
30+
let formattedEscKey = ''
3031
const { togglePalette, closePalette: closeCommandPalette } = storeMethods;
3132
3233
const updateStore = () => {
@@ -106,11 +107,14 @@
106107
}
107108
};
108109
109-
onMount(() => {
110+
onMount(async () => {
111+
const tinyKeys = await import('tinykeys')
112+
const {default: tiny, parseKeybinding} = tinyKeys
113+
formattedEscKey = parseKeybinding('Esc').flat().join('');
110114
const shortcuts = createShortcuts({
111115
actions: commands
112116
});
113-
unsubscribeKbdListener = tinyKeys(window, {
117+
unsubscribeKbdListener = tiny(window, {
114118
...shortcuts,
115119
'$mod+k': togglePalette,
116120
Escape: closePalette,
@@ -158,7 +162,7 @@
158162
wrapperElement?.removeEventListener?.('click', handleOutsideClick);
159163
});
160164
161-
const formattedEscKey = parseKeybinding('Esc').flat().join('');
165+
162166
</script>
163167

164168
<Portal target="body">

src/lib/components/Result.svelte

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<script lang="ts">
22
import { paletteStore } from '../store/PaletteStore';
3-
import { afterUpdate } from 'svelte';
3+
import { afterUpdate, onMount } from 'svelte';
44
import { runAction } from '../utils';
55
import KeyboardButton from './KeyboardButton.svelte';
6-
import * as tinykeys from 'tinykeys';
76
import type { action } from '$lib/types';
87
98
export let action: action;
@@ -31,10 +30,16 @@
3130
});
3231
};
3332
34-
if (action.shortcut) {
35-
const parsedShortcut = tinykeys.parseKeybinding(action.shortcut);
33+
onMount(async () => {
34+
const tinyKeys = await import('tinykeys');
35+
const {parseKeybinding} = tinyKeys
36+
if (action.shortcut) {
37+
const parsedShortcut = parseKeybinding(action.shortcut);
3638
formattedShortcut = parsedShortcut.flat().filter((s) => s.length > 0);
3739
}
40+
})
41+
42+
3843
3944
const onMouseEnter = () => {
4045
isActive = true;

0 commit comments

Comments
 (0)