Skip to content

Commit 83eef5c

Browse files
authored
Merge pull request #844 from quoid/editor-sidebar-resize
feat: editor sidebar can resize and hidden now
2 parents c729099 + 47401a7 commit 83eef5c

File tree

6 files changed

+123
-17
lines changed

6 files changed

+123
-17
lines changed

src/ext/extension-page/App.svelte

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@
5858
window.location.reload();
5959
}
6060
});
61+
62+
let splitterActive = false;
63+
let sidebarHidden = false;
64+
let sidebarWidth = "23svw";
65+
const sidebarMinWidth = "20rem";
66+
const editorMinWidth = "20rem";
67+
68+
function sidebarSwitch() {
69+
sidebarHidden = !sidebarHidden;
70+
}
71+
72+
function handleSplitterDrag(event) {
73+
if (event.type === "mouseup") {
74+
splitterActive = false;
75+
} else if (event.type === "mousedown") {
76+
splitterActive = true;
77+
} else if (event.type === "mousemove") {
78+
const vw = window.innerWidth;
79+
const sw = (event.x / vw) * 100;
80+
sidebarWidth = `max(min(${sw}svw, 100svw - ${editorMinWidth}), ${sidebarMinWidth})`;
81+
}
82+
event.preventDefault();
83+
}
6184
</script>
6285

6386
<svelte:window on:keydown={preventKeyCommands} />
@@ -72,10 +95,30 @@
7295
{/if}
7396
</div>
7497
{/if}
75-
<main>
76-
<Sidebar />
77-
<Editor />
98+
<main
99+
style:--sidebar-width={sidebarWidth}
100+
style:--sidebar-min-width={sidebarMinWidth}
101+
>
102+
{#if !sidebarHidden}
103+
<Sidebar {sidebarSwitch} />
104+
{/if}
105+
<div
106+
role="none"
107+
class="splitter"
108+
class:dragging={splitterActive}
109+
on:mousedown={handleSplitterDrag}
110+
on:mouseup={handleSplitterDrag}
111+
></div>
112+
<Editor {sidebarHidden} {sidebarSwitch} />
78113
</main>
114+
{#if splitterActive}
115+
<div
116+
role="none"
117+
class="resize-mask"
118+
on:mouseup={handleSplitterDrag}
119+
on:mousemove={handleSplitterDrag}
120+
></div>
121+
{/if}
79122
<ul>
80123
{#each $notifications as item (item.id)}
81124
<Notification on:click={() => notifications.remove(item.id)} {item} />
@@ -120,6 +163,34 @@
120163
overflow: hidden;
121164
}
122165
166+
.resize-mask {
167+
background-color: transparent;
168+
cursor: col-resize;
169+
position: fixed;
170+
inset: 0;
171+
z-index: 200;
172+
}
173+
174+
.splitter {
175+
--splitter-width: 6px;
176+
--splitter-offset: calc(var(--splitter-width) / 2);
177+
--sidebar-fixed-width: max(var(--sidebar-min-width), var(--sidebar-width));
178+
179+
background-color: transparent;
180+
cursor: col-resize;
181+
position: fixed;
182+
left: calc(var(--sidebar-fixed-width) - var(--splitter-offset));
183+
width: var(--splitter-width);
184+
height: 100svh;
185+
z-index: 201;
186+
transition: background-color 0.2s ease-in-out;
187+
188+
&:hover,
189+
&.dragging {
190+
background-color: var(--color-blue);
191+
}
192+
}
193+
123194
ul {
124195
bottom: 1rem;
125196
left: 50%;

src/ext/extension-page/Components/Editor/Editor.svelte

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import iconDownload from "@shared/img/icon-download.svg?raw";
1414
import iconTrash from "@shared/img/icon-trash.svg?raw";
1515
import iconSync from "@shared/img/icon-sync.svg?raw";
16+
import iconSidebar from "@shared/img/icon-sidebar.svg?raw";
17+
18+
export let sidebarHidden;
19+
export let sidebarSwitch;
1620
1721
// the data the populates editor elements
1822
let canUpdate;
@@ -167,13 +171,22 @@
167171
<div class="editor__empty">No Item Selected</div>
168172
{/if}
169173
<div class="editor__header">
174+
{#if sidebarHidden}
175+
<div class="sidebar-switch">
176+
<IconButton
177+
icon={iconSidebar}
178+
on:click={sidebarSwitch}
179+
title="Show sidebar"
180+
/>
181+
</div>
182+
{/if}
170183
<div class="editor__header__content">
171184
<div>
172185
<Tag {type} />
173186
<div class="editor__title truncate">{name}</div>
174187
</div>
175188
<div class="editor__status">
176-
<div>
189+
<div class="truncate">
177190
{#if $v4state.includes("saving")}
178191
Saving...
179192
{:else if $v4state.includes("trashing")}
@@ -233,6 +246,7 @@
233246
flex-grow: 1;
234247
overflow: hidden;
235248
position: relative;
249+
width: calc(100svw - var(--sidebar-width));
236250
}
237251
238252
.info {
@@ -260,7 +274,12 @@
260274
align-items: center;
261275
display: flex;
262276
flex-shrink: 0;
263-
padding: 1rem 0.5rem 1rem 1.5rem;
277+
padding: 1rem;
278+
gap: 1rem;
279+
}
280+
281+
.sidebar-switch {
282+
scale: 1.5;
264283
}
265284
266285
.editor__header__content {

src/ext/extension-page/Components/Sidebar/Sidebar.svelte

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
import Loader from "@shared/Components/Loader.svelte";
1212
import iconPlus from "@shared/img/icon-plus.svg?raw";
1313
import iconSettings from "@shared/img/icon-settings.svg?raw";
14+
import iconSidebar from "@shared/img/icon-sidebar.svg?raw";
1415
import {
1516
cmChanged,
1617
cmGetInstance,
1718
cmSetSavedCode,
1819
cmSetSessionCode,
1920
} from "../Editor/CodeMirror.svelte";
2021
22+
export let sidebarSwitch;
23+
2124
// disable buttons accordingly
2225
$: disabled = !$v4state.includes("ready");
2326
@@ -30,6 +33,8 @@
3033
$: if (list.find((a) => a.active)) {
3134
const active = list.find((a) => a.active);
3235
scrollToEl(active.filename);
36+
} else {
37+
activate(list[0]);
3338
}
3439
3540
/**
@@ -204,11 +209,17 @@
204209
</script>
205210

206211
<div
207-
class="sidebar {!$settings['editor_list_descriptions']
208-
? 'sidebar--compact'
209-
: ''}"
212+
class="sidebar"
213+
class:sidebar--compact={!$settings["editor_list_descriptions"]}
210214
>
211215
<div class="sidebar__header">
216+
<div class="sidebar-switch">
217+
<IconButton
218+
icon={iconSidebar}
219+
on:click={sidebarSwitch}
220+
title="Hide sidebar"
221+
/>
222+
</div>
212223
<div class="sidebar__filter"><SidebarFilter /></div>
213224
<IconButton
214225
warnDot={!$settings["global_active"]}
@@ -217,7 +228,7 @@
217228
title="Open settings"
218229
{disabled}
219230
/>
220-
<Dropdown icon={iconPlus} title="New item" {disabled}>
231+
<Dropdown icon={iconPlus} title="New item" {disabled} right>
221232
<button on:click={() => newItem("js")}>New JS</button>
222233
<button on:click={() => newItem("css")}>New CSS</button>
223234
<button on:click={newRemote}>New Remote</button>
@@ -250,27 +261,27 @@
250261
border-right: 1px solid var(--border-color);
251262
display: flex;
252263
flex-direction: column;
253-
flex: 0 0 23rem;
254-
max-width: 23rem;
264+
width: var(--sidebar-width);
265+
min-width: var(--sidebar-min-width);
255266
position: relative;
256267
}
257268
269+
.sidebar-switch {
270+
scale: 1.5;
271+
}
272+
258273
.sidebar__header {
259274
align-items: center;
260275
display: flex;
261276
flex-shrink: 0;
262-
flex-wrap: wrap;
263277
padding: 1rem;
278+
gap: 0.5rem;
264279
}
265280
266281
.sidebar__filter {
267282
flex-grow: 1;
268283
}
269284
270-
:global(.sidebar__filter + button) {
271-
margin: 0 0.5rem;
272-
}
273-
274285
.sidebar__count {
275286
backdrop-filter: blur(3px);
276287
-webkit-backdrop-filter: blur(3px);

src/ext/extension-page/Components/Sidebar/SidebarItem.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
<Toggle checked={!data.disabled} on:click={toggleClick} />
4343
</div>
4444
{#if description}
45-
<div class="item__description" title={showTitle ? data.description : null}>
45+
<div
46+
class="item__description truncate"
47+
title={showTitle ? data.description : null}
48+
>
4649
{description}
4750
</div>
4851
{/if}

src/shared/Components/IconButton.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
color: inherit;
2929
cursor: pointer;
3030
display: flex;
31+
flex-shrink: 0;
3132
height: 1.5rem;
3233
justify-content: center;
3334
overflow: visible;

src/shared/img/icon-sidebar.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)