From a8193566626197f50612975abf0c832df04bee5c Mon Sep 17 00:00:00 2001 From: Krasilnikov Roman Date: Thu, 6 Jun 2024 22:31:38 +0300 Subject: [PATCH] Extract editor panel tabs --- src/components/editor/editor-surface.svelte | 3 +- src/components/editor/editor.svelte | 6 +- src/components/editor/panel/header.svelte | 97 ++++++++ src/components/editor/panel/model.ts | 11 + src/components/editor/panel/panel.svelte | 114 ++++++++++ src/components/editor/panel/settings.svelte | 14 ++ src/components/editor/panel/terminal.svelte | 20 ++ src/components/editor/{ => panel}/terminal.ts | 0 src/components/editor/panel/tests.svelte | 34 +++ src/components/editor/testing-panel.svelte | 215 ------------------ 10 files changed, 295 insertions(+), 219 deletions(-) create mode 100644 src/components/editor/panel/header.svelte create mode 100644 src/components/editor/panel/model.ts create mode 100644 src/components/editor/panel/panel.svelte create mode 100644 src/components/editor/panel/settings.svelte create mode 100644 src/components/editor/panel/terminal.svelte rename src/components/editor/{ => panel}/terminal.ts (100%) create mode 100644 src/components/editor/panel/tests.svelte delete mode 100644 src/components/editor/testing-panel.svelte diff --git a/src/components/editor/editor-surface.svelte b/src/components/editor/editor-surface.svelte index 8a8d895..8fe4dde 100644 --- a/src/components/editor/editor-surface.svelte +++ b/src/components/editor/editor-surface.svelte @@ -20,7 +20,8 @@ } const PANEL_BORDER_HEIGHT = 1 - const MIN_PANEL_HEIGHT = 32 + PANEL_BORDER_HEIGHT + const PANEL_HEADER_VPADDING = 4 * 2 + const MIN_PANEL_HEIGHT = 32 + PANEL_HEADER_VPADDING + PANEL_BORDER_HEIGHT function normalizeHeight(height: number) { return Math.min(Math.max(height, 0), window.innerHeight - MIN_PANEL_HEIGHT); diff --git a/src/components/editor/editor.svelte b/src/components/editor/editor.svelte index cf1bf50..6470929 100644 --- a/src/components/editor/editor.svelte +++ b/src/components/editor/editor.svelte @@ -11,7 +11,7 @@ import EditorSurface from "./editor-surface.svelte"; import LangSelect from "./lang-select.svelte"; - import TestingPanel from "./testing-panel.svelte"; + import Panel from "./panel/panel.svelte" import VimMode from './vim-mode.svelte'; interface Props { @@ -68,7 +68,7 @@ {#snippet panel({ resizer, api })} - {/snippet} - + {/snippet} diff --git a/src/components/editor/panel/header.svelte b/src/components/editor/panel/header.svelte new file mode 100644 index 0000000..642436d --- /dev/null +++ b/src/components/editor/panel/header.svelte @@ -0,0 +1,97 @@ + + +
+ +
+ {#snippet tabButton({ tab, append }: TabButtonProps)} + { + selectedTab = tab + api.showPanel(window.innerHeight/3) + }} + > + {TAB_TITLES[tab]} + {#if append} + {@render append()} + {/if} + + {/snippet} + {#snippet testBadge()} +
= 0} + > + {lastTestId}/{testsCount} +
+ {/snippet} + {@render tabButton({ tab: Tab.Tests, append: testBadge })} + {@render tabButton({ tab: Tab.Output })} + {@render tabButton({ tab: Tab.Settings })} +
+
+ {@render append()} + +
+ + diff --git a/src/components/editor/panel/model.ts b/src/components/editor/panel/model.ts new file mode 100644 index 0000000..ad0dac9 --- /dev/null +++ b/src/components/editor/panel/model.ts @@ -0,0 +1,11 @@ +export enum Tab { + Tests = "tests", + Output = "output", + Settings = "settings", +} + +export const TAB_TITLES: Record = { + [Tab.Tests]: "Tests", + [Tab.Output]: "Output", + [Tab.Settings]: "Settings", +}; diff --git a/src/components/editor/panel/panel.svelte b/src/components/editor/panel/panel.svelte new file mode 100644 index 0000000..715031a --- /dev/null +++ b/src/components/editor/panel/panel.svelte @@ -0,0 +1,114 @@ + + +
+ + {#if selectedTab === Tab.Tests} + + {:else if selectedTab === Tab.Settings} + + {/if} + + + {@render children()} +
diff --git a/src/components/editor/panel/settings.svelte b/src/components/editor/panel/settings.svelte new file mode 100644 index 0000000..32377ee --- /dev/null +++ b/src/components/editor/panel/settings.svelte @@ -0,0 +1,14 @@ + + +
+
+
+ +
+
+
diff --git a/src/components/editor/panel/terminal.svelte b/src/components/editor/panel/terminal.svelte new file mode 100644 index 0000000..f6870f4 --- /dev/null +++ b/src/components/editor/panel/terminal.svelte @@ -0,0 +1,20 @@ + + +
diff --git a/src/components/editor/terminal.ts b/src/components/editor/panel/terminal.ts similarity index 100% rename from src/components/editor/terminal.ts rename to src/components/editor/panel/terminal.ts diff --git a/src/components/editor/panel/tests.svelte b/src/components/editor/panel/tests.svelte new file mode 100644 index 0000000..0bd390a --- /dev/null +++ b/src/components/editor/panel/tests.svelte @@ -0,0 +1,34 @@ + + +
+
+ {#each testsData as testData, i} +
+
+ {#if lastTestId === i} + + {:else if i < lastTestId} + + {:else} + + {/if} + Case {i + 1} +
+
{JSON.stringify(testData.input, null, 2)}
+
+ {/each} +
+
diff --git a/src/components/editor/testing-panel.svelte b/src/components/editor/testing-panel.svelte deleted file mode 100644 index 71f951a..0000000 --- a/src/components/editor/testing-panel.svelte +++ /dev/null @@ -1,215 +0,0 @@ - - -
-
- -
- {#snippet tabButton({ tab, append }: TabButtonProps)} - { - selectedTab = tab - api.showPanel(window.innerHeight/3) - }} - > - {TAB_TITLES[tab]} - {#if append} - {@render append()} - {/if} - - {/snippet} - {#snippet testBadge()} -
= 0} - > - {lastTestId}/{testsData.length} -
- {/snippet} - {@render tabButton({ tab: Tab.Tests, append: testBadge })} - {@render tabButton({ tab: Tab.Output })} - {@render tabButton({ tab: Tab.Settings })} -
-
- {@render header()} - -
-
-
- {#each testsData as testData, i} -
-
- {#if lastTestId === i} - - {:else if i < lastTestId} - - {:else} - - {/if} - Case {i + 1} -
-
{JSON.stringify(testData.input, null, 2)}
-
- {/each} -
-
-
-
-
-
- -
-
-
- {@render children()} -
- -