|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { Language } from '@/components/editor/types' |
3 | | -import * as Resizable from '@/components/ui/shadcn/resizable' |
4 | 3 | import { |
5 | 4 | useApp, |
6 | 5 | useEditor, |
| 6 | + useResizeHandle, |
7 | 7 | useSnippets, |
8 | 8 | useSnippetUpdate, |
9 | 9 | useTheme, |
@@ -48,6 +48,17 @@ const { |
48 | 48 | let editor: CodeMirror.Editor | null = null |
49 | 49 | let currentSearchOverlay: any = null |
50 | 50 |
|
| 51 | +const previewHandleRef = ref<HTMLElement>() |
| 52 | +const previewHeight = ref(300) |
| 53 | +
|
| 54 | +useResizeHandle(previewHandleRef, { |
| 55 | + direction: 'vertical', |
| 56 | + onMove(dy) { |
| 57 | + previewHeight.value = Math.max(100, previewHeight.value - dy) |
| 58 | + editor?.refresh() |
| 59 | + }, |
| 60 | +}) |
| 61 | +
|
51 | 62 | const isProgrammaticChange = ref(false) |
52 | 63 |
|
53 | 64 | useCssVar('--editor-font-size', document.body, { |
@@ -362,10 +373,6 @@ async function format() { |
362 | 373 |
|
363 | 374 | ipc.on('main-menu:format', format) |
364 | 375 |
|
365 | | -function onSplitterLayout() { |
366 | | - editor?.refresh() |
367 | | -} |
368 | | -
|
369 | 376 | function createSearchOverlay(query: string) { |
370 | 377 | if (!query) |
371 | 378 | return null |
@@ -435,25 +442,28 @@ onMounted(() => { |
435 | 442 | class="grid h-full grid-rows-[auto_1fr_auto] overflow-hidden pt-[var(--content-top-offset)]" |
436 | 443 | > |
437 | 444 | <EditorHeader v-if="isShowHeader" /> |
438 | | - <Resizable.ResizablePanelGroup |
| 445 | + <div |
439 | 446 | v-show="isShowEditor" |
440 | | - direction="vertical" |
441 | | - class="overflow-auto" |
442 | | - @layout="onSplitterLayout" |
| 447 | + class="flex min-h-0 flex-1 flex-col overflow-auto" |
443 | 448 | > |
444 | | - <Resizable.ResizablePanel as-child> |
| 449 | + <div |
| 450 | + id="editor" |
| 451 | + data-editor-mount |
| 452 | + class="min-h-0 flex-1" |
| 453 | + /> |
| 454 | + <template v-if="isShowCodePreview"> |
445 | 455 | <div |
446 | | - id="editor" |
447 | | - data-editor-mount |
| 456 | + ref="previewHandleRef" |
| 457 | + class="before:bg-border hover:before:bg-primary data-[resizing]:before:bg-primary relative z-10 flex h-px shrink-0 cursor-row-resize items-center justify-center bg-transparent before:absolute before:inset-x-0 before:top-1/2 before:h-px before:-translate-y-1/2 before:transition-[background-color,height] before:duration-150 before:content-[''] after:absolute after:inset-x-0 after:top-1/2 after:h-3 after:-translate-y-1/2 after:content-[''] hover:before:h-0.5 hover:before:delay-200 data-[resizing]:before:h-0.5" |
448 | 458 | /> |
449 | | - </Resizable.ResizablePanel> |
450 | | - <template v-if="isShowCodePreview"> |
451 | | - <Resizable.ResizableHandle /> |
452 | | - <Resizable.ResizablePanel> |
| 459 | + <div |
| 460 | + :style="{ height: `${previewHeight}px` }" |
| 461 | + class="shrink-0 overflow-hidden" |
| 462 | + > |
453 | 463 | <EditorPreview /> |
454 | | - </Resizable.ResizablePanel> |
| 464 | + </div> |
455 | 465 | </template> |
456 | | - </Resizable.ResizablePanelGroup> |
| 466 | + </div> |
457 | 467 | <EditorFooter v-if="isShowEditor" /> |
458 | 468 | <EditorCodeImage v-if="isShowCodeImage" /> |
459 | 469 | <EditorJsonVisualizer v-if="isShowJsonVisualizer" /> |
|
0 commit comments