From 27e80dfaa154bf511890619fc83da09c60e47e91 Mon Sep 17 00:00:00 2001 From: ernstmul Date: Thu, 15 May 2025 15:38:51 +0200 Subject: [PATCH] Editor terminal resizing --- src/lib/components/editor/editor.svelte | 4 +- src/lib/components/editor/filesystem.svelte | 1 + .../studio/artifact-[artifact]/+layout.svelte | 373 +++++++++++------- 3 files changed, 229 insertions(+), 149 deletions(-) diff --git a/src/lib/components/editor/editor.svelte b/src/lib/components/editor/editor.svelte index aeab43c5a..450c76535 100644 --- a/src/lib/components/editor/editor.svelte +++ b/src/lib/components/editor/editor.svelte @@ -73,8 +73,8 @@ const resizer = throttle(() => { if (!editorElement) return; editor.layout({ - height: editorElement.offsetHeight, - width: editorElement.offsetWidth + height: editorElement.parentElement.offsetHeight, + width: editorElement.parentElement.offsetWidth }); }, 50); const observer = new ResizeObserver(resizer); diff --git a/src/lib/components/editor/filesystem.svelte b/src/lib/components/editor/filesystem.svelte index c13ff0f9a..0e5618d84 100644 --- a/src/lib/components/editor/filesystem.svelte +++ b/src/lib/components/editor/filesystem.svelte @@ -40,5 +40,6 @@ display: flex; flex-direction: column; gap: 0; + overflow-y: scroll; } diff --git a/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+layout.svelte b/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+layout.svelte index 22d964047..5dc4b7e85 100644 --- a/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+layout.svelte +++ b/src/routes/(console)/project-[project]/studio/artifact-[artifact]/+layout.svelte @@ -15,6 +15,7 @@ import { disableBodySelect, enabledBodySelect, + getChatWidthFromPrefs, getTerminalHeightFromPrefs, getTerminalOpenFromPrefs, saveTerminalHeightToPrefs, @@ -69,12 +70,27 @@ let terminalOpen = $state(getTerminalOpenFromPrefs()); let asideRef: HTMLElement; let isResizing = false; - let terminalHeight = $state(getTerminalHeightFromPrefs()); + + const minHeight = 350; + let resizerTopPosition = $state(minHeight); + const terminalTabsHeight = 50; + let layoutElement = $state(null); + + let editorHeight = $derived(resizerTopPosition + 1); + let terminalHeight = $derived( + layoutElement.offsetHeight - resizerTopPosition - terminalTabsHeight + ); $effect(() => { if (terminalOpen !== undefined) { saveTerminalOpenToPrefs(terminalOpen); } + if (terminalOpen === false) { + editorHeight = layoutElement.offsetHeight - 46; + } else if (terminalOpen) { + editorHeight = resizerTopPosition + 1; + terminalHeight = layoutElement.offsetHeight - resizerTopPosition - terminalTabsHeight; + } }); function startResize() { @@ -91,17 +107,25 @@ function resize(event: MouseEvent | TouchEvent) { if (!isResizing) return; - const clientY = 'touches' in event ? event.touches[0].clientY : event.clientY; + const relativeY = clientY - 50; // y distance from top of card + const maxHeight = window.innerHeight - 400; + if (relativeY < minHeight) { + resizerTopPosition = minHeight; + } else if (relativeY > maxHeight) { + resizerTopPosition = maxHeight; + } else { + resizerTopPosition = relativeY; + } - let height = - asideRef.getBoundingClientRect().y - - clientY + - asideRef.getBoundingClientRect().height - - 32; - - terminalHeight = height < maxHeight ? height : maxHeight; + // let height = + // asideRef.getBoundingClientRect().y - + // clientY + + // asideRef.getBoundingClientRect().height - + // 32; + // + // terminalHeight = height < maxHeight ? height : maxHeight; } function stopResize() { @@ -151,6 +175,12 @@ }); return mappedArtifacts; }); + + $effect(() => { + if (view === 'editor' && terminals.size === 0) { + createTerminal(); + } + }); {#snippet artifactSelector()} @@ -159,140 +189,159 @@ {/if} {/snippet} - - - {#if $isSmallViewport} - -
- {@render artifactSelector()} +
+ + + {#if $isSmallViewport} + +
+ {@render artifactSelector()} +
+
+
+
-
-
- -
- {/if} - - - {#if !$showChat} - { - showChat.set(true); - }}> - {/if} - - { - view = 'preview'; - }}>Preview - { - view = 'editor'; - }}>Code - - - {#if !$isSmallViewport} - {@render artifactSelector()} {/if} - - - Release - - -
- -
-
-
- {@render children()} -
-
- -
- - + + Release + + +
+ +
+ +
+ {@render children()} +
+
+
+ +
+
+ {#if view === 'editor'} + {#if terminalOpen} +