Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: ability to resize editor panels horizontally (#1500)
Kyle Mendell1dd10202a462
diff --git a/frontend/src/lib/components/resizable-split.svelte b/frontend/src/lib/components/resizable-split.sveltenew file mode 100644index 000000000..e8ac3f5ec--- /dev/null+++ b/frontend/src/lib/components/resizable-split.svelte@@ -0,0 +1,242 @@+<script lang="ts">+ import type { Snippet } from 'svelte';+ import { onDestroy, onMount } from 'svelte';+ import { PersistedState } from 'runed';+ import { DoubleArrowLeftIcon, DoubleArrowRightIcon } from '$lib/icons';++ interface Props {+ first: Snippet;+ second: Snippet;+ size?: number | null;+ minSize?: number;+ minSecondSize?: number;+ defaultRatio?: number;+ allowCollapse?: boolean;+ collapseThreshold?: number;+ handleSize?: number;+ class?: string;+ firstClass?: string;+ secondClass?: string;+ handleClass?: string;+ ariaLabel?: string;+ persistKey?: string;+ persistStorage?: 'local' | 'session';+ onResizeEnd?: () => void;+ }++ let {+ first,+ second,+ size = $bindable<number | null>(null),+ minSize = 240,+ minSecondSize = 240,+ defaultRatio = 0.5,+ allowCollapse = true,+ collapseThreshold = 28,+ handleSize = 8,+ class: className = '',+ firstClass = '',+ secondClass = '',+ handleClass = '',+ ariaLabel = 'Resize panels',+ persistKey,+ persistStorage = 'session',+ onResizeEnd = () => {}+ }: Props = $props();++ let containerRef = $state<HTMLDivElement | null>(null);+ let isResizing = $state(false);+ let collapsedSide = $state<'first' | 'second' | null>(null);+ let lastSize = minSize;+ let persistedState = $state<PersistedState<number | null> | null>(null);+ let persistedKey = $state<string | null>(null);++ let resizeStartX = 0;+ let resizeStartWidth = 0;++ const clampSize = (value: number, minValue: number, maxValue: number) => Math.min(Math.max(value, minValue), maxValue);++ const getAvailableWidth = () => {+ if (!containerRef) return 0;+ return Math.max(0, containerRef.getBoundingClientRect().width - handleSize);+ };++ const getMaxNormalSize = () => Math.max(0, getAvailableWidth() - minSecondSize);++ const ensureInitialSize = () => {+ if (!containerRef || size !== null) return;+ const available = getAvailableWidth();+ if (available <= 0) return;+ const maxNormal = getMaxNormalSize();+ const safeMin = Math.min(minSize, maxNormal);+ const initialSize = clampSize(Math.round(available * defaultRatio), safeMin, maxNormal);+ size = initialSize;+ lastSize = initialSize;+ };++ const commitSize = () => {+ if (!persistedState || size === null) return;+ persistedState.current = size;+ };++ const applySize = (nextSize: number, persist = false) => {+ const available = getAvailableWidth();+ if (available <= 0) return;+ const maxNormal = getMaxNormalSize();+ const safeMin = Math.min(minSize, maxNormal);++ if (allowCollapse && nextSize <= collapseThreshold) {+ collapsedSide = 'first';+ size = 0;+ if (persist) commitSize();+ return;+ }+ if (allowCollapse && nextSize >= available - collapseThreshold) {+ collapsedSide = 'second';+ size = available;+ if (persist) commitSize();+ return;+ }++ collapsedSide = null;+ const clamped = clampSize(nextSize, safeMin, maxNormal);+ size = clamped;+ lastSize = clamped;+ if (persist) commitSize();+ };++ const handleMove = (event: PointerEvent) => {+ if (!isResizing) return;+ applySize(resizeStartWidth + (event.clientX - resizeStartX));+ };++ const stopResize = () => {+ if (!isResizing) return;+ isResizing = false;+ window.removeEventListener('pointermove', handleMove);+ window.removeEventListener('pointerup', stopResize);+ document.body.style.cursor = '';+ document.body.style.userSelect = '';+ commitSize();+ onResizeEnd();+ };++ const handleWindowResize = () => {+ if (isResizing) return;+ if (size === null) {+ ensureInitialSize();+ if (size === null) return;+ }+ applySize(size);+ };++ function startResize(event: PointerEvent) {+ if (!containerRef) return;+ ensureInitialSize();+ resizeStartX = event.clientX;+ resizeStartWidth = size ?? 0;+ isResizing = true;+ window.addEventListener('pointermove', handleMove);+ window.addEventListener('pointerup', stopResize);+ document.body.style.cursor = 'col-resize';+ document.body.style.userSelect = 'none';+ event.preventDefault();+ }++ function restoreCollapsed() {+ const maxNormal = getMaxNormalSize();+ const safeMin = Math.min(minSize, maxNormal);+ const restored = clampSize(lastSize || safeMin, safeMin, maxNormal);+ collapsedSide = null;+ size = restored;+ lastSize = restored;+ commitSize();+ onResizeEnd();+ }++ $effect(() => {+ if (!persistKey) {+ persistedState = null;+ persistedKey = null;+ return;+ }+ if (persistedKey === persistKey && persistedState) return;+ persistedState = new PersistedState<number | null>(persistKey, size ?? null, {+ storage: persistStorage,+ syncTabs: false+ });+ persistedKey = persistKey;+ const stored = persistedState.current;+ if (stored !== null && stored !== undefined) {+ size = stored;+ }+ });++ $effect(() => {+ if (!containerRef || size === null || isResizing) return;+ applySize(size, false);+ });++ onMount(() => {+ ensureInitialSize();+ window.addEventListener('resize', handleWindowResize);+ return () => window.removeEventListener('resize', handleWindowResize);+ });++ onDestroy(() => {+ window.removeEventListener('pointermove', handleMove);+ window.removeEventListener('pointerup', stopResize);+ });+</script>++<div bind:this={containerRef} class={`flex min-h-0 min-w-0 ${className}`}>+ <div+ class={`min-h-0 min-w-0 flex-none overflow-hidden ${firstClass}`}+ style={`width: ${size ?? 0}px;`}+ aria-hidden={collapsedSide === 'first'}+ >+ {#if collapsedSide !== 'first'}+ {@render first()}+ {/if}+ </div>++ <div+ role="separator"+ aria-orientation="vertical"+ aria-label={ariaLabel}+ class={`group relative z-20 flex shrink-0 cursor-col-resize items-stretch justify-center overflow-visible ${handleClass}`}+ style={`width: ${handleSize}px;`}+ onpointerdown={startResize}+ >+ <div class="bg-border group-hover:bg-primary/50 my-2 w-0.5 rounded-full transition-colors"></div>+ {#if collapsedSide}+ <button+ class="bg-background border-border text-muted-foreground hover:text-foreground focus-visible:ring-ring absolute inset-0 z-10 m-auto flex size-6 items-center justify-center rounded-full border shadow-sm focus-visible:ring-2 focus-visible:outline-none"+ onclick={(event) => {+ event.stopPropagation();+ restoreCollapsed();+ }}+ onpointerdown={(event) => event.stopPropagation()}+ aria-label={collapsedSide === 'first' ? 'Show left panel' : 'Show right panel'}+ title={collapsedSide === 'first' ? 'Show left panel' : 'Show right panel'}+ type="button"+ >+ {#if collapsedSide === 'first'}+ <DoubleArrowRightIcon class="size-4" />+ {:else}+ <DoubleArrowLeftIcon class="size-4" />+ {/if}+ </button>+ {/if}+ </div>++ <div+ class={`min-h-0 min-w-0 flex-1 overflow-hidden ${secondClass}`}+ style={collapsedSide === 'second' ? 'flex: 0 0 0px; width: 0px;' : ''}+ aria-hidden={collapsedSide === 'second'}+ >+ {#if collapsedSide !== 'second'}+ {@render second()}+ {/if}+ </div>+</div>diff --git a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte b/frontend/src/routes/(app)/projects/[projectId]/+page.svelteindex a6f62ac55..2c93651ff 100644--- a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte+++ b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte@@ -24,6 +24,7 @@import ServicesGrid from '../components/ServicesGrid.svelte';import CodePanel from '../components/CodePanel.svelte';import ProjectsLogsPanel from '../components/ProjectLogsPanel.svelte';+ import ResizableSplit from '$lib/components/resizable-split.svelte';import SwitchWithLabel from '$lib/components/form/labeled-switch.svelte';import { untrack } from 'svelte';import { projectService } from '$lib/services/project-service';@@ -96,6 +97,12 @@let selectedFile = $state<'compose' | 'env' | string>('compose');let layoutMode = $state<'classic' | 'tree'>('classic');let selectedIncludeTab = $state<string | null>(null);+ let treePaneWidth = $state(320);+ let composeSplitWidth = $state<number | null>(null);+ const minTreePaneWidth = 200;+ const minEditorPaneWidth = 360;+ const minComposePaneWidth = 360;+ const minEnvPaneWidth = 280;const tabItems = $derived<TabItem[]>([{@@ -438,15 +445,15 @@<div class="min-h-0 flex-1">{#if layoutMode === 'tree'}- <div class="flex h-full min-h-0 flex-col gap-4 lg:flex-row">- <Card.Root class="flex min-h-0 w-full flex-1 flex-col overflow-hidden lg:w-fit lg:max-w-xs lg:min-w-48">+ <div class="flex h-full min-h-0 flex-col gap-4 lg:hidden">+ <Card.Root class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden"><Card.Header icon={FileTextIcon} class="flex-shrink-0 items-center"><Card.Title><h2>{m.project_files()}</h2></Card.Title></Card.Header>- <Card.Content class="min-h-0 flex-1 overflow-y-auto p-2">- <TreeView.Root class="p-2">+ <Card.Content class="min-h-0 flex-1 overflow-auto p-2">+ <TreeView.Root class="min-w-max p-2 whitespace-nowrap"><TreeView.Filename="compose.yaml"onclick={() => (selectedFile = 'compose')}@@ -486,7 +493,7 @@</Card.Content></Card.Root>- <div class="flex h-full min-h-0 flex-1 flex-col">+ <div class="flex min-h-0 flex-1 flex-col">{#if selectedFile === 'compose'}<CodePanelbind:open={composeOpen}@@ -517,6 +524,101 @@{/if}</div></div>++ <ResizableSplit+ class="hidden h-full min-h-0 lg:flex lg:gap-2"+ firstClass="flex min-h-0 flex-col"+ secondClass="flex min-h-0 flex-col"+ bind:size={treePaneWidth}+ minSize={minTreePaneWidth}+ minSecondSize={minEditorPaneWidth}+ defaultRatio={0.3}+ ariaLabel="Resize project files panel"+ persistKey={`arcane.compose.split:${project.id}:tree`}+ onResizeEnd={persistPrefs}+ >+ {#snippet first()}+ <Card.Root class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">+ <Card.Header icon={FileTextIcon} class="flex-shrink-0 items-center">+ <Card.Title>+ <h2>{m.project_files()}</h2>+ </Card.Title>+ </Card.Header>+ <Card.Content class="min-h-0 flex-1 overflow-auto p-2">+ <TreeView.Root class="min-w-max p-2 whitespace-nowrap">+ <TreeView.File+ name="compose.yaml"+ onclick={() => (selectedFile = 'compose')}+ class={selectedFile === 'compose' ? 'bg-accent' : ''}+ >+ {#snippet icon()}+ <FileTextIcon class="size-4 text-blue-500" />+ {/snippet}+ </TreeView.File>++ <TreeView.File+ name=".env"+ onclick={() => (selectedFile = 'env')}+ class={selectedFile === 'env' ? 'bg-accent' : ''}+ >+ {#snippet icon()}+ <FileTextIcon class="size-4 text-green-500" />+ {/snippet}+ </TreeView.File>++ {#if project?.includeFiles && project.includeFiles.length > 0}+ <TreeView.Folder name={m.project_includes()}>+ {#each project.includeFiles as includeFile (includeFile.relativePath)}+ <TreeView.File+ name={includeFile.relativePath}+ onclick={() => (selectedFile = includeFile.relativePath)}+ class={selectedFile === includeFile.relativePath ? 'bg-accent' : ''}+ >+ {#snippet icon()}+ <FileTextIcon class="size-4 text-amber-500" />+ {/snippet}+ </TreeView.File>+ {/each}+ </TreeView.Folder>+ {/if}+ </TreeView.Root>+ </Card.Content>+ </Card.Root>+ {/snippet}++ {#snippet second()}+ <div class="flex h-full min-h-0 flex-1 flex-col">+ {#if selectedFile === 'compose'}+ <CodePanel+ bind:open={composeOpen}+ title="compose.yaml"+ language="yaml"+ bind:value={$inputs.composeContent.value}+ error={$inputs.composeContent.error ?? undefined}+ readOnly={!canEditCompose}+ />+ {:else if selectedFile === 'env'}+ <CodePanel+ bind:open={envOpen}+ title=".env"+ language="env"+ bind:value={$inputs.envContent.value}+ error={$inputs.envContent.error ?? undefined}+ />+ {:else}+ {@const includeFile = project?.includeFiles?.find((f) => f.relativePath === selectedFile)}+ {#if includeFile}+ <CodePanel+ bind:open={includeFilesPanelStates[includeFile.relativePath]}+ title={includeFile.relativePath}+ language="yaml"+ bind:value={includeFilesState[includeFile.relativePath]}+ />+ {/if}+ {/if}+ </div>+ {/snippet}+ </ResizableSplit>{:else}<div class="flex h-full min-h-0 flex-col gap-4">{#if project?.includeFiles && project.includeFiles.length > 0}@@ -551,28 +653,61 @@/>{/if}{:else}- <div class="flex min-h-0 flex-1 flex-col gap-4 lg:grid lg:grid-cols-5 lg:grid-rows-1">- <div class="flex min-h-0 flex-1 flex-col lg:col-span-3">- <CodePanel- bind:open={composeOpen}- title="compose.yaml"- language="yaml"- bind:value={$inputs.composeContent.value}- error={$inputs.composeContent.error ?? undefined}- readOnly={!canEditCompose}- />- </div>-- <div class="flex min-h-0 flex-1 flex-col lg:col-span-2">- <CodePanel- bind:open={envOpen}- title=".env"- language="env"- bind:value={$inputs.envContent.value}- error={$inputs.envContent.error ?? undefined}- />- </div>+ <div class="flex min-h-0 flex-1 flex-col gap-4 lg:hidden">+ <CodePanel+ bind:open={composeOpen}+ title="compose.yaml"+ language="yaml"+ bind:value={$inputs.composeContent.value}+ error={$inputs.composeContent.error ?? undefined}+ readOnly={!canEditCompose}+ />+ <CodePanel+ bind:open={envOpen}+ title=".env"+ language="env"+ bind:value={$inputs.envContent.value}+ error={$inputs.envContent.error ?? undefined}+ /></div>++ <ResizableSplit+ class="hidden min-h-0 flex-1 lg:flex lg:gap-2"+ firstClass="flex min-h-0 flex-col"+ secondClass="flex min-h-0 flex-col"+ bind:size={composeSplitWidth}+ minSize={minComposePaneWidth}+ minSecondSize={minEnvPaneWidth}+ defaultRatio={0.6}+ ariaLabel="Resize compose and env editors"+ persistKey={`arcane.compose.split:${project.id}:classic`}+ onResizeEnd={persistPrefs}+ >+ {#snippet first()}+ <div class="flex min-h-0 flex-1 flex-col">+ <CodePanel+ bind:open={composeOpen}+ title="compose.yaml"+ language="yaml"+ bind:value={$inputs.composeContent.value}+ error={$inputs.composeContent.error ?? undefined}+ readOnly={!canEditCompose}+ />+ </div>+ {/snippet}++ {#snippet second()}+ <div class="flex min-h-0 flex-1 flex-col">+ <CodePanel+ bind:open={envOpen}+ title=".env"+ language="env"+ bind:value={$inputs.envContent.value}+ error={$inputs.envContent.error ?? undefined}+ />+ </div>+ {/snippet}+ </ResizableSplit>{/if}</div>{/if}