mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 02:57:57 -05:00
refac
This commit is contained in:
1 parent
b7a7ddff18
commit
301ae2cf7d
7 files changed
+157
-30
No files matched your search
@@ -51,6 +51,7 @@
|
||||
};
|
||||
export let disabled = false;
|
||||
export let chatId: string | null = null;
|
||||
export let onSelect = (id: string | null) => selectMachine(selectedMachineId, id, chatId);
|
||||
export let machineContext: MachineContext | null = null;
|
||||
/** Also offers the working directory of the selected machine. */
|
||||
export let showDirectory = true;
|
||||
@@ -127,7 +128,7 @@
|
||||
|
||||
const toggleMachine = (id: string) => {
|
||||
closeMenu();
|
||||
selectMachine(selectedMachineId, $selectedMachineId === id ? null : id, chatId);
|
||||
onSelect($selectedMachineId === id ? null : id);
|
||||
};
|
||||
|
||||
$: selectedSystemMachine = systemMachines.find(
|
||||
@@ -428,7 +429,7 @@
|
||||
bind:show={showMachines}
|
||||
machineId={managedMachineId}
|
||||
connections={writable}
|
||||
onCreate={async (id) => selectMachine(selectedMachineId, id, chatId)}
|
||||
onCreate={async (id) => onSelect(id)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
const updatedFolder = { ...targetFolder, ..._folder };
|
||||
if ($selectedFolder?.id === targetFolder.id) selectedFolder.set(updatedFolder);
|
||||
onUpdate(updatedFolder);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -158,6 +159,7 @@
|
||||
if (res) {
|
||||
toast.success($i18n.t('Folder created successfully'));
|
||||
onUpdate();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -77,8 +77,15 @@
|
||||
const mouse = position(event);
|
||||
if (!mouse) return;
|
||||
flush();
|
||||
const canvas = surface.querySelector('canvas')!;
|
||||
const box = canvas.getBoundingClientRect();
|
||||
// Some browsers report mouse wheels in lines or pages.
|
||||
const unit = [1, 16, box.height][event.deltaMode] * (canvas.width / box.width);
|
||||
send({
|
||||
...mouse,
|
||||
scrollX: event.deltaX * unit,
|
||||
scrollY: event.deltaY * unit,
|
||||
// Older servers scroll by notches instead.
|
||||
deltaX: Math.sign(event.deltaX) * Math.ceil(Math.abs(event.deltaX) / 100),
|
||||
deltaY: Math.sign(event.deltaY) * Math.ceil(Math.abs(event.deltaY) / 100)
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { toast } from 'svelte-sonner';
|
||||
import equal from 'fast-deep-equal';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import Sortable from 'sortablejs';
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -25,6 +24,7 @@
|
||||
socket,
|
||||
onSocketRestored,
|
||||
config,
|
||||
machines,
|
||||
visiblePinnedModels,
|
||||
visibleControls,
|
||||
selectedFolder,
|
||||
@@ -100,6 +100,8 @@
|
||||
import Spinner from '../common/Spinner.svelte';
|
||||
import Loader from '../common/Loader.svelte';
|
||||
import Folder from '../common/Folder.svelte';
|
||||
import NewFolderAlt from '../icons/NewFolderAlt.svelte';
|
||||
import FolderOpen from '../icons/FolderOpen.svelte';
|
||||
import SidebarSection from './Sidebar/Section.svelte';
|
||||
import Tooltip from '../common/Tooltip.svelte';
|
||||
import Folders from './Sidebar/Folders.svelte';
|
||||
@@ -109,6 +111,7 @@
|
||||
import ChannelItem from './Sidebar/ChannelItem.svelte';
|
||||
import SearchModal from './SearchModal.svelte';
|
||||
import FolderModal from './Sidebar/Folders/FolderModal.svelte';
|
||||
import OpenDirectoryModal from './Sidebar/Folders/OpenDirectoryModal.svelte';
|
||||
import PinnedModelList from './Sidebar/PinnedModelList.svelte';
|
||||
import PinnedNoteList from './Sidebar/PinnedNoteList.svelte';
|
||||
import CalendarIcon from './Sidebar/icons/Calendar.svelte';
|
||||
@@ -130,6 +133,7 @@
|
||||
import XMarkIcon from '../icons/XMark.svelte';
|
||||
import ConfirmDialog from '../common/ConfirmDialog.svelte';
|
||||
import MoreHorizontalIcon from './Sidebar/icons/MoreHorizontal.svelte';
|
||||
import PlusIcon from './Sidebar/icons/Plus.svelte';
|
||||
import MobileSwipePanel from '../common/MobileSwipePanel.svelte';
|
||||
|
||||
const DEFAULT_PINNED_ITEMS = ['notes', 'workspace'];
|
||||
@@ -261,6 +265,14 @@
|
||||
|
||||
let showCreateFolderModal = false;
|
||||
|
||||
let showOpenDirectory = false;
|
||||
// A machine per chat or model has no one directory to open.
|
||||
$: directoryMachines = $config?.features?.enable_tool_servers
|
||||
? ($machines ?? []).filter(
|
||||
(machine) => machine.id && machine.scope !== 'chat' && machine.scope !== 'model'
|
||||
)
|
||||
: [];
|
||||
|
||||
let showPinnedModels = true;
|
||||
let showPinnedNotes = false;
|
||||
let showChannels = false;
|
||||
@@ -478,7 +490,7 @@
|
||||
folders = folderMap;
|
||||
};
|
||||
|
||||
const createFolder = async ({ name, data, meta, parent_id }) => {
|
||||
const createFolder = async ({ name, data, meta, parent_id }: any) => {
|
||||
name = name?.trim();
|
||||
if (!name) {
|
||||
toast.error($i18n.t('Folder name cannot be empty.'));
|
||||
@@ -499,19 +511,6 @@
|
||||
name = `${name} ${i}`;
|
||||
}
|
||||
|
||||
// Add a dummy folder to the list to show the user that the folder is being created
|
||||
const tempId = uuidv4();
|
||||
folders = {
|
||||
...folders,
|
||||
[tempId]: {
|
||||
id: tempId,
|
||||
name: name,
|
||||
parent_id: parent_id,
|
||||
created_at: Date.now(),
|
||||
updated_at: Date.now()
|
||||
}
|
||||
};
|
||||
|
||||
const res = await createNewFolder(localStorage.token, {
|
||||
name,
|
||||
data,
|
||||
@@ -527,6 +526,20 @@
|
||||
await initFolders();
|
||||
showFolders = true;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
// A folder on a machine's directory, named after it.
|
||||
const openDirectory = async (machineId: string, directory: string) => {
|
||||
const folder = await createFolder({
|
||||
name: directory.split('/').filter(Boolean).at(-1) ?? directory,
|
||||
data: { machine_id: machineId, working_directory: directory },
|
||||
parent_id: null
|
||||
});
|
||||
if (!folder) return false;
|
||||
await goto(`/folders/${folder.id}`);
|
||||
closeMobileSidebar();
|
||||
return true;
|
||||
};
|
||||
|
||||
// Only fetch channels if the feature is enabled and user has permission
|
||||
@@ -1129,13 +1142,15 @@
|
||||
/>
|
||||
|
||||
{#if $config?.features?.enable_folders && ($user?.role === 'admin' || ($user?.permissions?.features?.folders ?? true))}
|
||||
<FolderModal
|
||||
bind:show={showCreateFolderModal}
|
||||
onSubmit={async (folder) => {
|
||||
await createFolder(folder);
|
||||
showCreateFolderModal = false;
|
||||
}}
|
||||
/>
|
||||
<FolderModal bind:show={showCreateFolderModal} onSubmit={createFolder} />
|
||||
|
||||
{#if showOpenDirectory}
|
||||
<OpenDirectoryModal
|
||||
bind:show={showOpenDirectory}
|
||||
machines={directoryMachines}
|
||||
onSelect={openDirectory}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<svelte:document on:click|capture={sidebarLinkClickHandler} />
|
||||
@@ -1645,9 +1660,11 @@
|
||||
id="sidebar-folders"
|
||||
bind:open={showFolders}
|
||||
name={$i18n.t('Folders')}
|
||||
onAdd={() => {
|
||||
showCreateFolderModal = true;
|
||||
}}
|
||||
onAdd={directoryMachines.length
|
||||
? null
|
||||
: () => {
|
||||
showCreateFolderModal = true;
|
||||
}}
|
||||
onAddLabel={$i18n.t('New Folder')}
|
||||
on:drop={async (e) => {
|
||||
const { type, id, item } = e.detail;
|
||||
@@ -1671,6 +1688,34 @@
|
||||
}
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="action">
|
||||
{#if directoryMachines.length}
|
||||
<Dropdown align="start" closeOnSelect>
|
||||
<Tooltip content={$i18n.t('New Folder')}>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center justify-center w-7 h-7 rounded-lg text-base-300 hover:text-base-500 dark:text-base-600 dark:hover:text-base-400 transition-colors duration-100"
|
||||
aria-label={$i18n.t('New Folder')}
|
||||
>
|
||||
<PlusIcon className="size-3.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
<div slot="content">
|
||||
<DropdownMenu className="min-w-[10.625rem]">
|
||||
<button type="button" on:click={() => (showCreateFolderModal = true)}>
|
||||
<NewFolderAlt />
|
||||
{$i18n.t('New Folder')}
|
||||
</button>
|
||||
<button type="button" on:click={() => (showOpenDirectory = true)}>
|
||||
<FolderOpen />
|
||||
{$i18n.t('Open directory')}
|
||||
</button>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</Dropdown>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<Folders
|
||||
bind:folderRegistry
|
||||
{folders}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
const i18n = getContext<Writable<I18n>>('i18n');
|
||||
|
||||
export let show = false;
|
||||
/** Returns true once saved; otherwise the form stays open. */
|
||||
export let onSubmit: Function = (e) => {};
|
||||
|
||||
export let folderId = null;
|
||||
@@ -126,7 +127,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
await onSubmit({
|
||||
const saved = await onSubmit({
|
||||
name,
|
||||
meta,
|
||||
// Sharing saves separately; do not overwrite its mode with the editor's snapshot.
|
||||
@@ -140,7 +141,7 @@
|
||||
},
|
||||
parent_id: edit ? undefined : parentId
|
||||
});
|
||||
show = false;
|
||||
if (saved) show = false;
|
||||
loading = false;
|
||||
};
|
||||
|
||||
@@ -373,7 +374,11 @@
|
||||
)}
|
||||
/>
|
||||
<div class="flex min-w-0">
|
||||
<MachineMenu selectedMachineId={folderMachineSelection} showDirectory={false}>
|
||||
<MachineMenu
|
||||
selectedMachineId={folderMachineSelection}
|
||||
onSelect={folderMachineSelection.set}
|
||||
showDirectory={false}
|
||||
>
|
||||
{#snippet trigger(selected: string | null, label: string)}
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from 'svelte';
|
||||
|
||||
import Modal from '$lib/components/common/Modal.svelte';
|
||||
import SettingsSelect from '$lib/components/common/SettingsSelect.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
|
||||
const i18n = getContext<any>('i18n');
|
||||
|
||||
export let show = false;
|
||||
export let machines: { id: string; name?: string }[] = [];
|
||||
/** Returns true once opened; otherwise the picker stays open. */
|
||||
export let onSelect: (machineId: string, directory: string) => Promise<boolean>;
|
||||
|
||||
// Start on the machine new chats use.
|
||||
let machineId = (
|
||||
machines.find((machine) => machine.id === localStorage.selectedMachineId) ?? machines[0]
|
||||
).id;
|
||||
let opening = false;
|
||||
|
||||
const selectDirectory = async (directory: string) => {
|
||||
if (opening) return;
|
||||
opening = true;
|
||||
if (await onSelect(machineId, directory)) show = false;
|
||||
opening = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<Modal bind:show ariaLabel={$i18n.t('Open directory')} size="md">
|
||||
<div class="px-2 py-4">
|
||||
<div class="mb-3 flex items-center justify-between gap-2 px-2 text-sm">
|
||||
<span class="flex-1">{$i18n.t('Open directory')}</span>
|
||||
{#if machines.length > 1}
|
||||
<SettingsSelect
|
||||
bind:value={machineId}
|
||||
ariaLabel={$i18n.t('Machine')}
|
||||
className="min-w-0 max-w-[50%]"
|
||||
disabled={opening}
|
||||
>
|
||||
{#each machines as machine (machine.id)}
|
||||
<option value={machine.id}>{machine.name || $i18n.t('Machine')}</option>
|
||||
{/each}
|
||||
</SettingsSelect>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Close')}
|
||||
class="text-base-500 hover:text-base-900 dark:hover:text-base-100"
|
||||
on:click={() => (show = false)}><XMark className="size-4" /></button
|
||||
>
|
||||
</div>
|
||||
<div class="h-[60dvh] min-h-0" aria-busy={opening}>
|
||||
{#await import('$lib/components/chat/FileNav.svelte') then { default: FileNav }}
|
||||
{#key machineId}
|
||||
<FileNav
|
||||
{machineId}
|
||||
manageFileRequests={false}
|
||||
showTerminalDock={false}
|
||||
onSelectDirectory={selectDirectory}
|
||||
/>
|
||||
{/key}
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -549,6 +549,7 @@
|
||||
}
|
||||
}
|
||||
dispatch('update');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -709,6 +710,7 @@
|
||||
if (res) {
|
||||
toast.success($i18n.t('Folder created successfully'));
|
||||
dispatch('update');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user