mirror of
https://github.com/open-webui/computer.git
synced 2026-11-23 14:10:45 -05:00
refac
This commit is contained in:
1 parent
03ee3d5d2d
commit
87b4b25559
5 files changed
+89
-77
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import type { DiffHunk } from '$lib/utils/diff';
|
||||
import DiffHunkRows from './DiffHunkRows.svelte';
|
||||
|
||||
interface Props {
|
||||
hunks: DiffHunk[];
|
||||
path: string;
|
||||
showNumbers?: boolean;
|
||||
}
|
||||
|
||||
let { hunks, path, showNumbers = false }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#each hunks as hunk}
|
||||
{#if showNumbers}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<code class="whitespace-pre px-2 py-0.5">{hunk.header}</code>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="w-full border-b border-gray-100 bg-gray-50 px-2 py-0.5 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
{hunk.header}
|
||||
</div>
|
||||
{/if}
|
||||
<DiffHunkRows {hunk} {path} {showNumbers} />
|
||||
{/each}
|
||||
@@ -24,70 +24,62 @@
|
||||
{preferAbove}
|
||||
{forceAbove}
|
||||
align="end"
|
||||
className="w-56"
|
||||
className="w-48"
|
||||
headerDivider={false}
|
||||
footerDivider={false}
|
||||
>
|
||||
<div class="px-1 pb-1 text-xs">
|
||||
<div
|
||||
class="px-2 pb-0.5 pt-1 text-[0.625rem] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
Whitespace
|
||||
</div>
|
||||
|
||||
<div class="py-0.5 text-xs font-normal">
|
||||
<button
|
||||
type="button"
|
||||
class="app-interactive app-muted flex h-7 w-full items-center gap-2 rounded-xl px-2 text-left text-xs transition-colors duration-75"
|
||||
class="app-interactive app-muted flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs font-normal transition-colors duration-75"
|
||||
onclick={toggleWhitespace}
|
||||
aria-pressed={$hideWhitespaceChanges}
|
||||
>
|
||||
<Icon name="code" size={14} class="app-icon-muted shrink-0" />
|
||||
<Icon name="code" size={13} class="app-icon-muted shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate">Hide whitespace</span>
|
||||
<span
|
||||
class="relative h-4 w-7 shrink-0 rounded-full transition-colors duration-150 {$hideWhitespaceChanges
|
||||
class="relative h-3.5 w-6 shrink-0 rounded-full transition-colors duration-150 {$hideWhitespaceChanges
|
||||
? 'bg-gray-900 dark:bg-white'
|
||||
: 'bg-gray-300 dark:bg-gray-700'}"
|
||||
>
|
||||
<span
|
||||
class="absolute top-[0.125rem] h-3 w-3 rounded-full transition-all duration-150 {$hideWhitespaceChanges
|
||||
? 'left-[0.875rem] bg-white dark:bg-black'
|
||||
class="absolute top-[0.125rem] h-2.5 w-2.5 rounded-full transition-all duration-150 {$hideWhitespaceChanges
|
||||
? 'left-[0.75rem] bg-white dark:bg-black'
|
||||
: 'left-[0.125rem] bg-white dark:bg-gray-500'}"
|
||||
></span>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div
|
||||
class="px-2 pb-0.5 pt-1.5 text-[0.625rem] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-600"
|
||||
>
|
||||
<div class="app-muted px-2 pb-0.5 pt-1 text-[0.625rem] leading-none uppercase">
|
||||
Diff Display
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-7 w-full items-center gap-2 rounded-xl px-2 text-left text-xs transition-colors duration-75 {$diffDisplayMode ===
|
||||
class="flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs font-normal transition-colors duration-75 {$diffDisplayMode ===
|
||||
'unified'
|
||||
? 'app-interactive-active'
|
||||
: 'app-interactive app-muted'}"
|
||||
onclick={() => diffDisplayMode.set('unified')}
|
||||
>
|
||||
<Icon name="list" size={14} class="app-icon-muted shrink-0" />
|
||||
<Icon name="list" size={13} class="app-icon-muted shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate text-left">Unified</span>
|
||||
{#if $diffDisplayMode === 'unified'}
|
||||
<Icon name="check" size={12} class="app-icon-muted shrink-0" />
|
||||
<Icon name="check" size={11} class="app-icon-muted shrink-0" />
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-7 w-full items-center gap-2 rounded-xl px-2 text-left text-xs transition-colors duration-75 {$diffDisplayMode ===
|
||||
class="flex h-6 w-full items-center gap-2 rounded-xl px-2 text-left text-xs font-normal transition-colors duration-75 {$diffDisplayMode ===
|
||||
'split'
|
||||
? 'app-interactive-active'
|
||||
: 'app-interactive app-muted'}"
|
||||
onclick={() => diffDisplayMode.set('split')}
|
||||
>
|
||||
<Icon name="split-view" size={14} class="app-icon-muted shrink-0" />
|
||||
<Icon name="split-view" size={13} class="app-icon-muted shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate">Split</span>
|
||||
{#if $diffDisplayMode === 'split'}
|
||||
<Icon name="check" size={12} class="app-icon-muted shrink-0" />
|
||||
<Icon name="check" size={11} class="app-icon-muted shrink-0" />
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { clearTabEdit, markTabUnsaved, updateTabFilePath, activeWorkspace } from '$lib/stores';
|
||||
import { get } from 'svelte/store';
|
||||
import { t } from '$lib/i18n';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { readFile, writeFile } from '$lib/apis/files';
|
||||
import { getGitDiff } from '$lib/apis/git';
|
||||
import { hideWhitespaceChanges } from '$lib/stores/gitDiffSettings';
|
||||
import { diffDisplayMode, hideWhitespaceChanges } from '$lib/stores/gitDiffSettings';
|
||||
import { gitStatusStore, type GitFile } from '$lib/stores/gitStatus.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import SaveDialog from './SaveDialog.svelte';
|
||||
@@ -21,7 +21,7 @@
|
||||
import SvgPreview from './preview/SvgPreview.svelte';
|
||||
import OfficePreview from './preview/OfficePreview.svelte';
|
||||
import Spinner from './common/Spinner.svelte';
|
||||
import DiffHunkRows from './DiffHunkRows.svelte';
|
||||
import DiffHunkList from './DiffHunkList.svelte';
|
||||
import {
|
||||
EditorState,
|
||||
StateEffect,
|
||||
@@ -164,6 +164,7 @@
|
||||
let diffMode = $state(false);
|
||||
let diffFiles = $state<DiffFileEntry[]>([]);
|
||||
let diffLoading = $state(false);
|
||||
let diffScrollEl: HTMLDivElement | undefined;
|
||||
let hasGitChanges = $state(false);
|
||||
let gitLineChanges: GitLineChange[] = [];
|
||||
let gitBaseContent: string | null = null;
|
||||
@@ -799,6 +800,8 @@
|
||||
diffFiles = [];
|
||||
} finally {
|
||||
diffLoading = false;
|
||||
await tick();
|
||||
if (diffScrollEl) diffScrollEl.scrollLeft = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1144,20 +1147,12 @@
|
||||
<p class="state-sub">{$t('editor.noUncommittedModifications')}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="diff-scroll">
|
||||
{#each diffFiles as df}
|
||||
{#each df.hunks as hunk}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600 font-mono text-[0.6875rem]"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<code class="whitespace-pre px-2 py-0.5">{hunk.header}</code>
|
||||
</div>
|
||||
<DiffHunkRows {hunk} path={df.path} />
|
||||
<div class="diff-scroll" bind:this={diffScrollEl}>
|
||||
<div class="diff-content" class:diff-content-split={$diffDisplayMode === 'split'}>
|
||||
{#each diffFiles as df}
|
||||
<DiffHunkList hunks={df.hunks} path={df.path} />
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1471,7 +1466,16 @@
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
|
||||
font-size: 0.75rem;
|
||||
font-size: 0.6875rem;
|
||||
line-height: 1.125rem;
|
||||
}
|
||||
|
||||
.diff-content {
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.diff-content-split {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -35,7 +35,7 @@
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import DiffSettingsMenu from './DiffSettingsMenu.svelte';
|
||||
import { countDiffStats, type DiffFile } from '$lib/utils/diff';
|
||||
import DiffHunkRows from './DiffHunkRows.svelte';
|
||||
import DiffHunkList from './DiffHunkList.svelte';
|
||||
|
||||
type GitFile = {
|
||||
path: string;
|
||||
@@ -799,10 +799,9 @@
|
||||
{#if totalChanges > 0}<span
|
||||
class="mx-1.5 block min-w-0 max-w-20 shrink truncate whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
|
||||
>{$t('git.changedCount', { count: totalChanges })}</span
|
||||
><span class="text-[0.625rem] font-mono text-green-600 dark:text-green-400 ml-2"
|
||||
>+{totalAdditions}</span
|
||||
><span class="text-[0.625rem] font-mono text-red-500 dark:text-red-400 ml-1"
|
||||
>-{totalDeletions}</span
|
||||
><span class="mx-1.5 flex shrink-0 items-center gap-1 text-[0.625rem] font-mono"
|
||||
><span class="text-green-600 dark:text-green-400">+{totalAdditions}</span>
|
||||
<span class="text-red-500 dark:text-red-400">-{totalDeletions}</span></span
|
||||
>{/if}
|
||||
{#if actionMsg}<span
|
||||
class="ml-auto min-w-0 max-w-32 truncate whitespace-nowrap text-[0.625rem] font-mono text-gray-400 dark:text-gray-600"
|
||||
@@ -1258,22 +1257,24 @@
|
||||
<Icon name="check" size={7} class="text-white dark:text-black" />
|
||||
{/if}
|
||||
</span>
|
||||
{#if fp.dir}
|
||||
<span class="flex min-w-0 flex-1 items-baseline gap-1.5">
|
||||
{#if fp.dir}
|
||||
<span
|
||||
class="min-w-0 truncate text-[0.625rem] text-gray-400 dark:text-gray-600"
|
||||
>{fp.dir}</span
|
||||
>
|
||||
{/if}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<span
|
||||
class="min-w-0 flex-1 truncate text-[0.625rem] text-gray-400 dark:text-gray-600"
|
||||
>{fp.dir}</span
|
||||
class="min-w-0 max-w-[55%] shrink-0 truncate text-[0.6875rem] text-gray-800 dark:text-gray-200 hover:underline cursor-pointer"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
openFileTab(workspacePath.replace(/\/$/, '') + '/' + file.path);
|
||||
}}>{fp.name}</span
|
||||
>
|
||||
{/if}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
</span>
|
||||
<span
|
||||
class="min-w-0 max-w-1/2 shrink-0 truncate text-[0.6875rem] text-gray-800 dark:text-gray-200 hover:underline cursor-pointer"
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
openFileTab(workspacePath.replace(/\/$/, '') + '/' + file.path);
|
||||
}}>{fp.name}</span
|
||||
>
|
||||
<span
|
||||
class="ml-auto flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
|
||||
class="flex shrink-0 items-center gap-1 text-[0.625rem] font-mono font-medium"
|
||||
>
|
||||
<span class="text-green-600 dark:text-green-400">+{file.additions ?? 0}</span>
|
||||
<span class="text-red-500 dark:text-red-400">-{file.deletions ?? 0}</span>
|
||||
@@ -1428,14 +1429,7 @@
|
||||
{df.path}
|
||||
</div>
|
||||
{/if}
|
||||
{#each df.hunks as hunk}
|
||||
<div
|
||||
class="px-2 py-0.5 text-gray-400 dark:text-gray-600 bg-gray-50 dark:bg-white/3 border-b border-gray-100 dark:border-white/4 w-full"
|
||||
>
|
||||
{hunk.header}
|
||||
</div>
|
||||
<DiffHunkRows {hunk} path={df.path} showNumbers={false} />
|
||||
{/each}
|
||||
<DiffHunkList hunks={df.hunks} path={df.path} />
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import Icon from './Icon.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import DiffSettingsMenu from './DiffSettingsMenu.svelte';
|
||||
import DiffHunkRows from './DiffHunkRows.svelte';
|
||||
import DiffHunkList from './DiffHunkList.svelte';
|
||||
|
||||
type ReviewFile = {
|
||||
key: string;
|
||||
@@ -342,17 +342,7 @@
|
||||
{diffFile.path}
|
||||
</div>
|
||||
{/if}
|
||||
{#each diffFile.hunks as hunk}
|
||||
<div
|
||||
class="grid w-full grid-cols-[2.75rem_2.75rem_1.25rem_auto] border-b border-gray-100 bg-gray-50 text-gray-400 dark:border-white/4 dark:bg-white/3 dark:text-gray-600"
|
||||
>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
<code class="whitespace-pre px-2 py-0.5">{hunk.header}</code>
|
||||
</div>
|
||||
<DiffHunkRows {hunk} path={diffFile.path} />
|
||||
{/each}
|
||||
<DiffHunkList hunks={diffFile.hunks} path={diffFile.path} showNumbers />
|
||||
{/each}
|
||||
{:else}
|
||||
<div
|
||||
|
||||
Reference in new issue
Block a user