open-webui/src/lib/components/chat/ShortcutsModal.svelte

100 lines
2.5 KiB
Svelte
Raw Normal View History

2023-12-28 10:46:57 +00:00
<script lang="ts">
import { getContext, onMount } from 'svelte';
2023-12-28 10:46:57 +00:00
import Modal from '../common/Modal.svelte';
import { shortcuts } from '$lib/shortcuts';
2025-10-18 04:32:03 +00:00
import { settings } from '$lib/stores';
import ShortcutItem from './ShortcutItem.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
type CategorizedShortcuts = {
[category: string]: {
left: Shortcut[];
right: Shortcut[];
};
};
2023-12-28 10:46:57 +00:00
const i18n = getContext('i18n');
2023-12-28 10:46:57 +00:00
export let show = false;
let categorizedShortcuts: CategorizedShortcuts = {};
let isMac = false;
onMount(() => {
isMac = /Mac/i.test(navigator.userAgent);
2025-10-18 04:32:03 +00:00
});
$: {
const allShortcuts = Object.values(shortcuts).filter((shortcut) => {
if (!shortcut.setting) {
return true;
}
return $settings[shortcut.setting.id] === shortcut.setting.value;
});
2025-10-22 21:12:05 +00:00
categorizedShortcuts = allShortcuts.reduce((acc, shortcut) => {
const category = shortcut.category;
if (!acc[category]) {
acc[category] = [];
}
acc[category].push(shortcut);
return acc;
}, {});
2025-10-18 04:32:03 +00:00
}
2023-12-28 10:46:57 +00:00
</script>
<Modal bind:show>
2025-10-22 21:12:05 +00:00
<div class="text-gray-700 dark:text-gray-100 px-5 py-4">
<div class="flex justify-between dark:text-gray-300 pb-2">
2025-10-18 04:32:03 +00:00
<div class="text-lg font-medium self-center">{$i18n.t('Keyboard Shortcuts')}</div>
<button class="self-center" on:click={() => (show = false)}>
2025-06-27 11:44:26 +00:00
<XMark className={'size-5'} />
2023-12-28 10:46:57 +00:00
</button>
</div>
2025-10-22 21:12:05 +00:00
{#each Object.entries(categorizedShortcuts) as [category, items], categoryIndex}
{#if categoryIndex > 0}
<div class="py-3">
<div class="w-full border-t dark:border-gray-850 border-gray-50" />
2023-12-28 10:46:57 +00:00
</div>
{/if}
2023-12-28 10:46:57 +00:00
2025-10-22 21:12:05 +00:00
<div class="flex justify-between dark:text-gray-300 pb-2">
<div class="text-base self-center">{$i18n.t(category)}</div>
</div>
2025-10-22 21:12:05 +00:00
<div class="flex flex-col md:flex-row w-full md:space-x-2 dark:text-gray-200">
<div class="flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
2025-10-22 21:12:05 +00:00
<div class=" grid grid-cols-1 sm:grid-cols-2 gap-2 gap-x-4 w-full">
{#each items as shortcut}
<div class="col-span-1 flex items-start">
<ShortcutItem {shortcut} {isMac} />
</div>
{/each}
2023-12-28 10:46:57 +00:00
</div>
</div>
</div>
{/each}
2024-05-03 21:03:22 +00:00
</div>
</Modal>
2023-12-28 10:46:57 +00:00
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
2023-12-28 10:46:57 +00:00
}
.tabs::-webkit-scrollbar {
display: none;
2023-12-28 10:46:57 +00:00
}
.tabs {
-ms-overflow-style: none;
scrollbar-width: none;
2023-12-28 10:46:57 +00:00
}
input[type='number'] {
-moz-appearance: textfield;
2023-12-28 10:46:57 +00:00
}
2025-10-22 21:12:05 +00:00
</style>