mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-26 07:11:00 -05:00
refac
This commit is contained in:
1 parent
3bfc168d6c
commit
e4b969f606
4 files changed
+397
-289
No files matched your search
@@ -273,14 +273,16 @@
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
const labels = controls.querySelectorAll<HTMLElement>('[data-input-label]');
|
||||
const terminalControls = controls.querySelector<HTMLElement>('[data-terminal-controls]');
|
||||
const directoryControl = controls.querySelector<HTMLElement>(
|
||||
'[data-working-directory-control]'
|
||||
);
|
||||
// Measure all labels together so separate controls cannot compete for the same space.
|
||||
for (const label of labels) label.style.display = '';
|
||||
if (terminalControls) terminalControls.style.display = '';
|
||||
terminalControlsInMenu = !!terminalControls && controls.scrollWidth > controls.clientWidth;
|
||||
if (terminalControls && terminalControlsInMenu) terminalControls.style.display = 'none';
|
||||
if (controls.scrollWidth > controls.clientWidth) {
|
||||
if (directoryControl) directoryControl.style.display = '';
|
||||
terminalControlsInMenu = controls.scrollWidth > controls.clientWidth;
|
||||
if (terminalControlsInMenu) {
|
||||
for (const label of labels) label.style.display = 'none';
|
||||
if (directoryControl) directoryControl.style.display = 'none';
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -2232,9 +2234,9 @@
|
||||
<div
|
||||
id={inputId === 'chat-input' ? 'message-input-container' : `${inputId}-wrapper`}
|
||||
data-composer-id={inputId}
|
||||
class="flex-1 flex flex-col relative w-full shadow-lg rounded-3xl border {isTemporary
|
||||
? 'border-dashed border-gray-100 dark:border-gray-800 hover:border-gray-200 focus-within:border-gray-200 hover:dark:border-gray-700 focus-within:dark:border-gray-700'
|
||||
: ' border-gray-100/50 dark:border-gray-850/50 hover:border-gray-200 focus-within:border-gray-100 hover:dark:border-gray-800 focus-within:dark:border-gray-800'} {($settings?.highContrastMode ??
|
||||
class="flex-1 flex flex-col relative w-full shadow-[0_6px_24px_-4px_rgba(0,0,0,0.1)] rounded-3xl border {isTemporary
|
||||
? 'border-dashed border-gray-200 dark:border-gray-800'
|
||||
: ' border-gray-200 dark:border-gray-800'} {($settings?.highContrastMode ??
|
||||
false)
|
||||
? 'focus-within:outline focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-blue-500 [&_.ProseMirror:focus-visible]:outline-none!'
|
||||
: ''} transition px-0.5 bg-white/5 dark:bg-gray-500/5 backdrop-blur-sm dark:text-gray-100"
|
||||
@@ -2654,11 +2656,14 @@
|
||||
{selectedTerminalId}
|
||||
modelId={selectedModels[0] ?? null}
|
||||
inMenu
|
||||
bind:tab={inputMenuTab}
|
||||
{chatId}
|
||||
bind:terminalContext
|
||||
disabled={generating}
|
||||
/>
|
||||
<div class="h-px mx-1 my-1 bg-gray-100 dark:bg-gray-800"></div>
|
||||
{#if inputMenuTab === ''}
|
||||
<div class="h-px mx-1 my-1 bg-gray-100 dark:bg-gray-800"></div>
|
||||
{/if}
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
|
||||
@@ -54,7 +54,16 @@
|
||||
export let tab = '';
|
||||
export let closeOnOutsideClick = true;
|
||||
$: if (!show) tab = '';
|
||||
$: hasInternalList = ['tools', 'skills', 'files', 'notes', 'knowledge', 'chats'].includes(tab);
|
||||
$: hasInternalList = [
|
||||
'tools',
|
||||
'skills',
|
||||
'files',
|
||||
'notes',
|
||||
'knowledge',
|
||||
'chats',
|
||||
'terminal',
|
||||
'directory'
|
||||
].includes(tab);
|
||||
|
||||
let showAttachWebpageModal = false;
|
||||
$: showAddContext =
|
||||
@@ -216,9 +225,13 @@
|
||||
|
||||
<div class="h-px mx-1 my-1 bg-gray-100 dark:bg-gray-800"></div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<slot name="terminal" />
|
||||
<slot name="terminal" />
|
||||
|
||||
{#if tab === ''}
|
||||
<div in:fly={{ x: -20, duration: 150 }}>
|
||||
<Tooltip
|
||||
content={fileUploadCapableModels.length !== selectedModels.length
|
||||
? $i18n.t('Model(s) do not support file upload')
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
import Cog6 from '$lib/components/icons/Cog6.svelte';
|
||||
import Server from '$lib/components/icons/Server.svelte';
|
||||
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
|
||||
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
||||
import { fly } from 'svelte/transition';
|
||||
import TerminalItemMenu from './TerminalItemMenu.svelte';
|
||||
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||
import Check from '$lib/components/icons/Check.svelte';
|
||||
@@ -47,13 +49,18 @@
|
||||
|
||||
export let show = false;
|
||||
export let inMenu = false;
|
||||
export let tab = '';
|
||||
const closeMenu = () => {
|
||||
show = false;
|
||||
if (inMenu) tab = '';
|
||||
};
|
||||
export let disabled = false;
|
||||
export let chatId: string | null = null;
|
||||
export let terminalContext: TerminalContext | null = null;
|
||||
|
||||
// Connections the user may create terminals on; a terminal on one of them is theirs to manage.
|
||||
let writable: { id: string; name: string }[] = [];
|
||||
$: if (show)
|
||||
$: if (inMenu ? tab === 'terminal' : show)
|
||||
templatesApi('/connections')
|
||||
.then((rows) => (writable = rows))
|
||||
.catch(() => (writable = []));
|
||||
@@ -105,7 +112,7 @@
|
||||
};
|
||||
const confirmLifecycle = (id: string, name: string, action: 'restart' | 'stop') => {
|
||||
pending = { id, name, action };
|
||||
show = false;
|
||||
closeMenu();
|
||||
showConfirm = true;
|
||||
};
|
||||
|
||||
@@ -121,7 +128,7 @@
|
||||
].filter((section) => !section.devices || section.terminals.length > 0);
|
||||
|
||||
const toggleTerminal = (id: string) => {
|
||||
show = false;
|
||||
closeMenu();
|
||||
selectTerminal(selectedTerminalId, $selectedTerminalId === id ? null : id, chatId);
|
||||
};
|
||||
|
||||
@@ -138,13 +145,13 @@
|
||||
selectedSystemTerminal?.name ||
|
||||
selectedSystemTerminal?.id ||
|
||||
($selectedTerminalId ? $i18n.t('Unavailable terminal') : $i18n.t('Terminal'));
|
||||
$: if (disabled && show) show = false;
|
||||
$: if (disabled && (show || (inMenu && tab === 'terminal'))) closeMenu();
|
||||
|
||||
let showTerminals = false;
|
||||
let managedTerminalId: string | null = null;
|
||||
const openTerminalDialog = (id: string | null) => {
|
||||
managedTerminalId = id;
|
||||
show = false;
|
||||
closeMenu();
|
||||
showTerminals = true;
|
||||
};
|
||||
let info: { target: TerminalTarget; label: string } | null = null;
|
||||
@@ -155,7 +162,7 @@
|
||||
modelId: modelId
|
||||
});
|
||||
if (!target) return;
|
||||
show = false;
|
||||
closeMenu();
|
||||
await tick();
|
||||
files = { target, label };
|
||||
};
|
||||
@@ -170,7 +177,7 @@
|
||||
modelId: modelId
|
||||
});
|
||||
if (!target) return;
|
||||
show = false;
|
||||
closeMenu();
|
||||
await tick();
|
||||
info = { target, label };
|
||||
};
|
||||
@@ -183,159 +190,198 @@
|
||||
)
|
||||
info = null;
|
||||
|
||||
$: triggerClass = inMenu
|
||||
? `flex w-full min-w-0 items-center gap-2 h-[1.6875rem] px-2 text-[0.8125rem] rounded-xl text-left ${disabled ? 'cursor-not-allowed opacity-40' : 'cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}`
|
||||
: `flex items-center gap-1.5 translate-y-[1px] text-[0.8125rem] transition rounded-lg ${
|
||||
disabled
|
||||
? 'p-1 cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600'
|
||||
: `text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200 cursor-pointer ${
|
||||
$selectedTerminalId && selectedLabel ? ' p-1 ' : ' p-1 opacity-50'
|
||||
}`
|
||||
}`;
|
||||
$: triggerClass = `flex items-center gap-1.5 translate-y-[1px] text-[0.8125rem] transition rounded-lg ${
|
||||
disabled
|
||||
? 'p-1 cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600'
|
||||
: `text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200 cursor-pointer ${
|
||||
$selectedTerminalId && selectedLabel ? ' p-1 ' : ' p-1 opacity-50'
|
||||
}`
|
||||
}`;
|
||||
</script>
|
||||
|
||||
<div class={inMenu ? 'w-full' : 'flex items-center translate-x-0.5'}>
|
||||
{#if disabled}
|
||||
<Tooltip content={selectedLabel} placement="top">
|
||||
{#snippet menuItems()}
|
||||
<!-- Terminals, then the user's own devices -->
|
||||
{#each systemSections as section}
|
||||
<div class="flex items-center justify-between pl-2 pr-1 py-1">
|
||||
<span
|
||||
class="text-[0.625rem] font-normal text-gray-400 dark:text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
{section.devices ? $i18n.t('Your devices') : $i18n.t('Terminals')}
|
||||
</span>
|
||||
{#if !section.devices}
|
||||
<div class="flex items-center gap-0.5">
|
||||
{#if writable.length}
|
||||
<Tooltip content={$i18n.t('New terminal')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('New terminal')}
|
||||
class={headerButtonClass}
|
||||
on:click|stopPropagation={() => openTerminalDialog(null)}
|
||||
>
|
||||
<Plus className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/if}
|
||||
{#if $user?.role === 'admin'}
|
||||
<Tooltip content={$i18n.t('Settings')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Settings')}
|
||||
class={headerButtonClass}
|
||||
on:click|stopPropagation={() => {
|
||||
closeMenu();
|
||||
showSettings.set('admin:integrations');
|
||||
}}
|
||||
>
|
||||
<Cog6 className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#each section.terminals as terminal}
|
||||
{@const label = terminal.name || $i18n.t('Terminal')}
|
||||
{@const owned = canManage(terminal, manageable)}
|
||||
{@const reachable = terminal.scope !== 'chat' || isSavedChatId($activeChatId)}
|
||||
<div class="group/terminal relative rounded-xl">
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={$selectedTerminalId === terminal.id}
|
||||
class="{rowClass} {$selectedTerminalId === terminal.id
|
||||
? 'pr-14 bg-gray-50/40 dark:bg-gray-800/40'
|
||||
: 'pr-8'}"
|
||||
on:click={() => toggleTerminal(terminal.id)}
|
||||
>
|
||||
<div class="flex flex-1 gap-2 items-center truncate">
|
||||
{#if section.devices}
|
||||
<Server className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
{:else}
|
||||
<Cloud className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
{/if}
|
||||
<span class="truncate">{label}</span>
|
||||
</div>
|
||||
{#if $selectedTerminalId === terminal.id}
|
||||
<div class="absolute right-2 text-emerald-600 dark:text-emerald-400">
|
||||
<Check className="size-3.5" />
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
<div
|
||||
class="absolute inset-y-0 {$selectedTerminalId === terminal.id
|
||||
? 'right-6'
|
||||
: 'right-1'} {moreClass}"
|
||||
>
|
||||
<TerminalItemMenu
|
||||
{label}
|
||||
loadStatus={owned && reachable ? () => machineStatus(terminal.id) : null}
|
||||
onRestart={() => confirmLifecycle(terminal.id, label, 'restart')}
|
||||
onStop={() => confirmLifecycle(terminal.id, label, 'stop')}
|
||||
onStart={() => runLifecycle(terminal.id, label, 'start')}
|
||||
onInfo={reachable ? () => openInfo(terminal.id, label) : null}
|
||||
onFiles={reachable ? () => openFiles(terminal.id, label) : null}
|
||||
onSettings={owned ? () => openTerminalDialog(terminal.id) : null}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
{/snippet}
|
||||
|
||||
{#if inMenu}
|
||||
{#if tab === ''}
|
||||
<div in:fly={{ x: -20, duration: 150 }}>
|
||||
<button
|
||||
type="button"
|
||||
disabled
|
||||
aria-disabled="true"
|
||||
aria-label={selectedLabel}
|
||||
class={triggerClass}
|
||||
role="menuitem"
|
||||
{disabled}
|
||||
class="flex w-full min-w-0 gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl text-left hover:bg-gray-50/40 dark:hover:bg-gray-800/40 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
on:click={() => {
|
||||
tab = 'terminal';
|
||||
}}
|
||||
>
|
||||
{#if selectedDevice}
|
||||
<Server className="size-3.5" strokeWidth="2" />
|
||||
{:else}
|
||||
<Cloud className="size-3.5" strokeWidth="2" />
|
||||
{/if}
|
||||
|
||||
{#if inMenu || ($selectedTerminalId && selectedLabel)}
|
||||
<span class="truncate text-[0.8125rem] {inMenu ? 'flex-1' : 'max-w-[9.375rem]'}"
|
||||
>{selectedLabel}</span
|
||||
>
|
||||
{/if}
|
||||
{#if inMenu}<ChevronRight />{/if}
|
||||
{#if selectedDevice}<Server className="size-3.5 shrink-0" strokeWidth="2" />{:else}<Cloud
|
||||
className="size-3.5 shrink-0"
|
||||
strokeWidth="2"
|
||||
/>{/if}
|
||||
<span class="flex-1 truncate">{selectedLabel}</span>
|
||||
<div class="text-gray-500"><ChevronRight /></div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
{:else}
|
||||
<Dropdown bind:show align="start">
|
||||
</div>
|
||||
{:else if tab === 'terminal'}
|
||||
<div class="flex min-h-0 flex-col overflow-hidden" in:fly={{ x: 20, duration: 150 }}>
|
||||
<button
|
||||
role="menuitem"
|
||||
class="flex w-full shrink-0 justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
|
||||
on:click={() => {
|
||||
tab = '';
|
||||
}}
|
||||
>
|
||||
<ChevronLeft />
|
||||
<div class="flex items-center w-full justify-between">
|
||||
<div>{$i18n.t('Terminals')}</div>
|
||||
</div>
|
||||
</button>
|
||||
<div class="min-h-0 overflow-y-auto overflow-x-hidden scrollbar-thin">
|
||||
{@render menuItems()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="flex items-center translate-x-0.5">
|
||||
{#if disabled}
|
||||
<Tooltip content={selectedLabel} placement="top">
|
||||
<button type="button" aria-label={selectedLabel} class={triggerClass}>
|
||||
<button
|
||||
type="button"
|
||||
disabled
|
||||
aria-disabled="true"
|
||||
aria-label={selectedLabel}
|
||||
class={triggerClass}
|
||||
>
|
||||
{#if selectedDevice}
|
||||
<Server className="size-3.5" strokeWidth="2" />
|
||||
{:else}
|
||||
<Cloud className="size-3.5" strokeWidth="2" />
|
||||
{/if}
|
||||
|
||||
{#if inMenu || ($selectedTerminalId && selectedLabel)}
|
||||
<span class="truncate text-[0.8125rem] {inMenu ? 'flex-1' : 'max-w-[9.375rem]'}"
|
||||
{#if $selectedTerminalId && selectedLabel}
|
||||
<span data-input-label class="truncate text-[0.8125rem] max-w-[9.375rem]"
|
||||
>{selectedLabel}</span
|
||||
>
|
||||
{/if}
|
||||
{#if inMenu}<ChevronRight />{/if}
|
||||
</button>
|
||||
</Tooltip>
|
||||
{:else}
|
||||
<Dropdown bind:show align="start">
|
||||
<Tooltip content={selectedLabel} placement="top">
|
||||
<button type="button" aria-label={selectedLabel} class={triggerClass}>
|
||||
{#if selectedDevice}
|
||||
<Server className="size-3.5" strokeWidth="2" />
|
||||
{:else}
|
||||
<Cloud className="size-3.5" strokeWidth="2" />
|
||||
{/if}
|
||||
|
||||
<div slot="content">
|
||||
<DropdownMenu
|
||||
className="{inMenu
|
||||
? 'w-70'
|
||||
: 'w-60'} max-w-[calc(100vw-2rem)] max-h-72 overflow-y-auto overflow-x-hidden scrollbar-thin"
|
||||
>
|
||||
<!-- Terminals, then the user's own devices -->
|
||||
{#each systemSections as section}
|
||||
<div class="flex items-center justify-between pl-2 pr-1 py-1">
|
||||
<span
|
||||
class="text-[0.625rem] font-normal text-gray-400 dark:text-gray-500 uppercase tracking-wider"
|
||||
{#if $selectedTerminalId && selectedLabel}
|
||||
<span data-input-label class="truncate text-[0.8125rem] max-w-[9.375rem]"
|
||||
>{selectedLabel}</span
|
||||
>
|
||||
{section.devices ? $i18n.t('Your devices') : $i18n.t('Terminals')}
|
||||
</span>
|
||||
{#if !section.devices}
|
||||
<div class="flex items-center gap-0.5">
|
||||
{#if writable.length}
|
||||
<Tooltip content={$i18n.t('New terminal')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('New terminal')}
|
||||
class={headerButtonClass}
|
||||
on:click|stopPropagation={() => openTerminalDialog(null)}
|
||||
>
|
||||
<Plus className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/if}
|
||||
{#if $user?.role === 'admin'}
|
||||
<Tooltip content={$i18n.t('Settings')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Settings')}
|
||||
class={headerButtonClass}
|
||||
on:click|stopPropagation={() => {
|
||||
show = false;
|
||||
showSettings.set('admin:integrations');
|
||||
}}
|
||||
>
|
||||
<Cog6 className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
{#each section.terminals as terminal}
|
||||
{@const label = terminal.name || $i18n.t('Terminal')}
|
||||
{@const owned = canManage(terminal, manageable)}
|
||||
{@const reachable = terminal.scope !== 'chat' || isSavedChatId($activeChatId)}
|
||||
<div class="group/terminal relative rounded-xl">
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={$selectedTerminalId === terminal.id}
|
||||
class="{rowClass} {$selectedTerminalId === terminal.id
|
||||
? 'pr-14 bg-gray-50/40 dark:bg-gray-800/40'
|
||||
: 'pr-8'}"
|
||||
on:click={() => toggleTerminal(terminal.id)}
|
||||
>
|
||||
<div class="flex flex-1 gap-2 items-center truncate">
|
||||
{#if section.devices}
|
||||
<Server className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
{:else}
|
||||
<Cloud className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
{/if}
|
||||
<span class="truncate">{label}</span>
|
||||
</div>
|
||||
{#if $selectedTerminalId === terminal.id}
|
||||
<div class="absolute right-2 text-emerald-600 dark:text-emerald-400">
|
||||
<Check className="size-3.5" />
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
<div
|
||||
class="absolute inset-y-0 {$selectedTerminalId === terminal.id
|
||||
? 'right-6'
|
||||
: 'right-1'} {moreClass}"
|
||||
>
|
||||
<TerminalItemMenu
|
||||
{label}
|
||||
loadStatus={owned && reachable ? () => machineStatus(terminal.id) : null}
|
||||
onRestart={() => confirmLifecycle(terminal.id, label, 'restart')}
|
||||
onStop={() => confirmLifecycle(terminal.id, label, 'stop')}
|
||||
onStart={() => runLifecycle(terminal.id, label, 'start')}
|
||||
onInfo={reachable ? () => openInfo(terminal.id, label) : null}
|
||||
onFiles={reachable ? () => openFiles(terminal.id, label) : null}
|
||||
onSettings={owned ? () => openTerminalDialog(terminal.id) : null}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/each}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
{/if}
|
||||
</div>
|
||||
<div slot="content">
|
||||
<DropdownMenu
|
||||
className="w-60 max-w-[calc(100vw-2rem)] max-h-72 overflow-y-auto overflow-x-hidden scrollbar-thin"
|
||||
>
|
||||
{@render menuItems()}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if info}
|
||||
{#key info}
|
||||
@@ -351,6 +397,7 @@
|
||||
{#key `${$user?.id}:${folderTarget.selector}:${chatId ?? ''}`}
|
||||
<WorkingDirectoryMenu
|
||||
{inMenu}
|
||||
bind:tab
|
||||
target={folderTarget}
|
||||
{chatId}
|
||||
userId={$user?.id ?? ''}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
import Folder from '$lib/components/icons/Folder.svelte';
|
||||
import FolderOpen from '$lib/components/icons/FolderOpen.svelte';
|
||||
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
|
||||
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
||||
import { fly } from 'svelte/transition';
|
||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||
import SearchInput from './InputMenu/SearchInput.svelte';
|
||||
import Check from '$lib/components/icons/Check.svelte';
|
||||
@@ -24,6 +26,11 @@
|
||||
export let terminalContext: TerminalContext | null = null;
|
||||
export let disabled = false;
|
||||
export let inMenu = false;
|
||||
export let tab = '';
|
||||
const closeMenu = () => {
|
||||
show = false;
|
||||
if (inMenu) tab = '';
|
||||
};
|
||||
export let onSelect: (path: string) => Promise<void> = async () => {};
|
||||
|
||||
let show = false;
|
||||
@@ -40,13 +47,12 @@
|
||||
const folderName = (path: string) => path.replace(/\/+$/, '').split('/').pop() || '/';
|
||||
const normalize = (path: string) => path.replace(/\/+$/, '') || '/';
|
||||
|
||||
$: if (terminalContext?.terminalId === target.selector)
|
||||
cwd = terminalContext.currentDirectory;
|
||||
$: if (terminalContext?.terminalId === target.selector) cwd = terminalContext.currentDirectory;
|
||||
$: directory = cwd;
|
||||
$: options = [...new Set([directory, ...recent].filter(Boolean).map(normalize))].filter((path) =>
|
||||
path.toLowerCase().includes(search.trim().toLowerCase())
|
||||
);
|
||||
$: if (disabled && show) show = false;
|
||||
$: if (disabled && (show || (inMenu && tab === 'directory'))) closeMenu();
|
||||
$: if (disabled && showPicker) showPicker = false;
|
||||
|
||||
async function refreshRecentFolders() {
|
||||
@@ -83,14 +89,12 @@
|
||||
const selectedContext =
|
||||
terminalContext?.terminalId === target.selector ? terminalContext : null;
|
||||
if (selectedContext) cwd = selectedContext.currentDirectory;
|
||||
initialization = getCwd(target).then(
|
||||
(result) => {
|
||||
if (disposed) return;
|
||||
home = result?.home ?? '';
|
||||
// A new chat ID remounts this menu before its session cwd may be ready.
|
||||
if (chatId && !selectedContext) cwd = result?.cwd ?? '';
|
||||
}
|
||||
);
|
||||
initialization = getCwd(target).then((result) => {
|
||||
if (disposed) return;
|
||||
home = result?.home ?? '';
|
||||
// A new chat ID remounts this menu before its session cwd may be ready.
|
||||
if (chatId && !selectedContext) cwd = result?.cwd ?? '';
|
||||
});
|
||||
void refreshRecentFolders();
|
||||
});
|
||||
onDestroy(() => (disposed = true));
|
||||
@@ -99,9 +103,7 @@
|
||||
if (disabled || saving) return;
|
||||
saving = true;
|
||||
// A draft has no terminal session yet; submission applies this choice after creating the chat.
|
||||
const result = chatId
|
||||
? await setCwd(target, path)
|
||||
: { cwd: path || home };
|
||||
const result = chatId ? await setCwd(target, path) : { cwd: path || home };
|
||||
if (disposed) return;
|
||||
if (!result?.cwd) {
|
||||
saving = false;
|
||||
@@ -139,149 +141,190 @@
|
||||
}
|
||||
}
|
||||
saving = false;
|
||||
show = false;
|
||||
closeMenu();
|
||||
showPicker = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class={inMenu ? 'w-full' : 'flex items-center translate-x-0.5'}>
|
||||
<Dropdown
|
||||
bind:show
|
||||
align="start"
|
||||
onOpenChange={(open) => {
|
||||
search = '';
|
||||
if (open) void refreshRecentFolders();
|
||||
{#snippet menuItems()}
|
||||
<SearchInput bind:value={search} placeholder={$i18n.t('Search folders')} />
|
||||
<hr class="mx-1 my-0.5 border-gray-50/30 dark:border-gray-800/30" />
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={!directory}
|
||||
disabled={saving || disabled}
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-[0.8125rem] font-normal cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 {!directory
|
||||
? 'bg-gray-50/40 dark:bg-gray-800/40'
|
||||
: 'hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}"
|
||||
on:click={() => selectDirectory('')}
|
||||
>
|
||||
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
<span class="flex-1 text-start">{$i18n.t('No folder')}</span>
|
||||
{#if !directory}
|
||||
<Check className="size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400" strokeWidth="2" />
|
||||
{/if}
|
||||
</button>
|
||||
{#if options.length > 0}
|
||||
<div
|
||||
class="px-2 py-1 text-[0.625rem] font-normal text-gray-400 dark:text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
{$i18n.t('Recently Used')}
|
||||
</div>
|
||||
{#if historyError}
|
||||
<div role="status" class="px-2 py-1 text-[0.6875rem] text-gray-500 dark:text-gray-400">
|
||||
{historyError}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="max-h-60 overflow-y-auto overflow-x-hidden scrollbar-thin">
|
||||
{#each options as path}
|
||||
{@const selected = !!directory && normalize(directory) === path}
|
||||
<div
|
||||
class="group/directory relative rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={selected}
|
||||
disabled={saving || disabled}
|
||||
title={path}
|
||||
class="flex h-[1.6875rem] w-full items-center justify-between gap-2 rounded-xl pl-2 {selected
|
||||
? 'pr-14'
|
||||
: 'pr-8'} text-[0.8125rem] font-normal cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 {selected
|
||||
? 'bg-gray-50/40 dark:bg-gray-800/40'
|
||||
: 'hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}"
|
||||
on:click={() => selectDirectory(path)}
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 items-center gap-2">
|
||||
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
<span class="truncate">{folderName(path)}</span>
|
||||
</div>
|
||||
{#if selected}
|
||||
<Check
|
||||
className="absolute right-2 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{/if}
|
||||
</button>
|
||||
<div
|
||||
class="absolute inset-y-0 {selected
|
||||
? 'right-6'
|
||||
: 'right-1'} flex items-center opacity-0 pointer-events-none transition-opacity group-hover/directory:opacity-100 group-hover/directory:pointer-events-auto group-focus-within/directory:opacity-100 group-focus-within/directory:pointer-events-auto"
|
||||
>
|
||||
<Tooltip content={$i18n.t('Open folder')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Open folder')}
|
||||
disabled={saving || disabled}
|
||||
class="flex size-6 shrink-0 items-center justify-center rounded-lg text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 focus-visible:outline focus-visible:outline-2 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
on:click|stopPropagation={() => {
|
||||
closeMenu();
|
||||
showFileNav.set({
|
||||
terminalId: target.selector,
|
||||
directory: path,
|
||||
chatId
|
||||
});
|
||||
}}><FolderOpen className="size-3.5" /></button
|
||||
>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<hr class="mx-1 my-0.5 border-gray-50/30 dark:border-gray-800/30" />
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving || disabled}
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-start text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 disabled:cursor-not-allowed disabled:opacity-40 dark:hover:bg-gray-800/40"
|
||||
on:click={() => {
|
||||
closeMenu();
|
||||
showPicker = true;
|
||||
}}
|
||||
>
|
||||
<Tooltip content={directory || $i18n.t('Working Directory')} placement="top">
|
||||
<FolderOpen className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
<span>{$i18n.t('Open folder')}</span>
|
||||
</button>
|
||||
{/snippet}
|
||||
|
||||
{#if inMenu}
|
||||
{#if tab === ''}
|
||||
<div in:fly={{ x: -20, duration: 150 }}>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
disabled={disabled || saving}
|
||||
aria-label={$i18n.t('Choose working directory')}
|
||||
class="flex min-w-0 items-center text-[0.8125rem] transition {inMenu
|
||||
? 'w-full gap-2 h-[1.6875rem] px-2 rounded-xl text-left hover:bg-gray-50/40 dark:hover:bg-gray-800/40'
|
||||
: 'gap-1.5 translate-y-[1px] rounded-lg p-1'} {disabled || saving
|
||||
? 'cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600'
|
||||
: directory
|
||||
? 'cursor-pointer text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200'
|
||||
: 'cursor-pointer text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400'}"
|
||||
class="flex w-full min-w-0 gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal cursor-pointer rounded-xl text-left hover:bg-gray-50/40 dark:hover:bg-gray-800/40 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
on:click={() => {
|
||||
tab = 'directory';
|
||||
search = '';
|
||||
void refreshRecentFolders();
|
||||
}}
|
||||
>
|
||||
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
{#if inMenu || directory}
|
||||
<span class="truncate {inMenu ? 'flex-1' : 'max-w-[9.375rem]'}"
|
||||
>{directory ? folderName(directory) : $i18n.t('Working Directory')}</span
|
||||
>
|
||||
{/if}
|
||||
{#if inMenu}<ChevronRight />{/if}
|
||||
<span class="flex-1 truncate"
|
||||
>{directory ? folderName(directory) : $i18n.t('Working Directory')}</span
|
||||
>
|
||||
<div class="text-gray-500"><ChevronRight /></div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
<div slot="content">
|
||||
<DropdownMenu className="{inMenu ? 'w-70' : 'w-60'} max-w-[calc(100vw-2rem)]">
|
||||
<SearchInput bind:value={search} placeholder={$i18n.t('Search folders')} />
|
||||
<hr class="mx-1 my-0.5 border-gray-50/30 dark:border-gray-800/30" />
|
||||
</div>
|
||||
{:else if tab === 'directory'}
|
||||
<div class="flex min-h-0 flex-col overflow-hidden" in:fly={{ x: 20, duration: 150 }}>
|
||||
<button
|
||||
role="menuitem"
|
||||
class="flex w-full shrink-0 justify-between gap-2 items-center h-[1.6875rem] px-2 text-[0.8125rem] font-normal select-none cursor-pointer rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
|
||||
on:click={() => {
|
||||
tab = '';
|
||||
}}
|
||||
>
|
||||
<ChevronLeft />
|
||||
<div class="flex items-center w-full justify-between">
|
||||
<div>{$i18n.t('Working Directory')}</div>
|
||||
</div>
|
||||
</button>
|
||||
<div class="min-h-0 overflow-y-auto overflow-x-hidden scrollbar-thin">
|
||||
{@render menuItems()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div data-working-directory-control class="flex items-center translate-x-0.5">
|
||||
<Dropdown
|
||||
bind:show
|
||||
align="start"
|
||||
onOpenChange={(open) => {
|
||||
search = '';
|
||||
if (open) void refreshRecentFolders();
|
||||
}}
|
||||
>
|
||||
<Tooltip content={directory || $i18n.t('Working Directory')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={!directory}
|
||||
disabled={saving || disabled}
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-[0.8125rem] font-normal cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 {!directory
|
||||
? 'bg-gray-50/40 dark:bg-gray-800/40'
|
||||
: 'hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}"
|
||||
on:click={() => selectDirectory('')}
|
||||
disabled={disabled || saving}
|
||||
aria-label={$i18n.t('Choose working directory')}
|
||||
class="flex min-w-0 items-center text-[0.8125rem] transition gap-1.5 translate-y-[1px] rounded-lg p-1 {disabled ||
|
||||
saving
|
||||
? 'cursor-not-allowed opacity-40 text-gray-400 dark:text-gray-600'
|
||||
: directory
|
||||
? 'cursor-pointer text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200'
|
||||
: 'cursor-pointer text-gray-300 hover:text-gray-500 dark:text-gray-600 dark:hover:text-gray-400'}"
|
||||
>
|
||||
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
<span class="flex-1 text-start">{$i18n.t('No folder')}</span>
|
||||
{#if !directory}
|
||||
<Check
|
||||
className="size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{#if directory}
|
||||
<span data-input-label class="truncate max-w-[9.375rem]"
|
||||
>{directory ? folderName(directory) : $i18n.t('Working Directory')}</span
|
||||
>
|
||||
{/if}
|
||||
</button>
|
||||
{#if options.length > 0}
|
||||
<div
|
||||
class="px-2 py-1 text-[0.625rem] font-normal text-gray-400 dark:text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
{$i18n.t('Recently Used')}
|
||||
</div>
|
||||
{#if historyError}
|
||||
<div role="status" class="px-2 py-1 text-[0.6875rem] text-gray-500 dark:text-gray-400">
|
||||
{historyError}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="max-h-60 overflow-y-auto overflow-x-hidden scrollbar-thin">
|
||||
{#each options as path}
|
||||
{@const selected = !!directory && normalize(directory) === path}
|
||||
<div
|
||||
class="group/directory relative rounded-xl hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={selected}
|
||||
disabled={saving || disabled}
|
||||
title={path}
|
||||
class="flex h-[1.6875rem] w-full items-center justify-between gap-2 rounded-xl pl-2 {selected
|
||||
? 'pr-14'
|
||||
: 'pr-8'} text-[0.8125rem] font-normal cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 {selected
|
||||
? 'bg-gray-50/40 dark:bg-gray-800/40'
|
||||
: 'hover:bg-gray-50/40 dark:hover:bg-gray-800/40'}"
|
||||
on:click={() => selectDirectory(path)}
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 items-center gap-2">
|
||||
<Folder className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
<span class="truncate">{folderName(path)}</span>
|
||||
</div>
|
||||
{#if selected}
|
||||
<Check
|
||||
className="absolute right-2 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{/if}
|
||||
</button>
|
||||
<div
|
||||
class="absolute inset-y-0 {selected
|
||||
? 'right-6'
|
||||
: 'right-1'} flex items-center opacity-0 pointer-events-none transition-opacity group-hover/directory:opacity-100 group-hover/directory:pointer-events-auto group-focus-within/directory:opacity-100 group-focus-within/directory:pointer-events-auto"
|
||||
>
|
||||
<Tooltip content={$i18n.t('Open folder')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Open folder')}
|
||||
disabled={saving || disabled}
|
||||
class="flex size-6 shrink-0 items-center justify-center rounded-lg text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 focus-visible:outline focus-visible:outline-2 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
on:click|stopPropagation={() => {
|
||||
show = false;
|
||||
showFileNav.set({
|
||||
terminalId: target.selector,
|
||||
directory: path,
|
||||
chatId
|
||||
});
|
||||
}}><FolderOpen className="size-3.5" /></button
|
||||
>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<hr class="mx-1 my-0.5 border-gray-50/30 dark:border-gray-800/30" />
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving || disabled}
|
||||
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-start text-[0.8125rem] font-normal cursor-pointer hover:bg-gray-50/40 disabled:cursor-not-allowed disabled:opacity-40 dark:hover:bg-gray-800/40"
|
||||
on:click={() => {
|
||||
show = false;
|
||||
showPicker = true;
|
||||
}}
|
||||
>
|
||||
<FolderOpen className="size-3.5 shrink-0" strokeWidth="2" />
|
||||
<span>{$i18n.t('Open folder')}</span>
|
||||
</button>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<div slot="content">
|
||||
<DropdownMenu className="w-60 max-w-[calc(100vw-2rem)]">
|
||||
{@render menuItems()}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if showPicker}
|
||||
<Modal bind:show={showPicker} ariaLabel={$i18n.t('Choose working directory')} size="md">
|
||||
|
||||
Reference in new issue
Block a user