Skip to content

Commit 5ea742e

Browse files
committed
Add reordering panels
1 parent 2865539 commit 5ea742e

File tree

6 files changed

+97
-23
lines changed

6 files changed

+97
-23
lines changed

src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as bzw from "./bzw/mod.ts";
22
import * as dom from "./dom/mod.ts";
3+
import "./editor/mod.ts";
34

45
import {saveFile, colorThemeChanged, capitalize} from "./utils.ts";
56
import {Renderer} from "./renderer/mod.ts";

src/dom/mod.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ export const canvas = document.querySelector("canvas") as HTMLCanvasElement;
22
export const bzwFile = document.querySelector("#bzw-file") as HTMLInputElement;
33

44
export const panels = {
5-
objects: document.querySelector(".objects > .panel__content") as HTMLDivElement,
6-
properties: document.querySelector(".properties > .panel__content") as HTMLDivElement,
5+
objects: document.querySelector("#objects > .panel__content") as HTMLDivElement,
6+
properties: document.querySelector("#properties > .panel__content") as HTMLDivElement,
77
};
88

99
export const statusBar = {
10-
objects: document.querySelector("#objects") as HTMLElement,
11-
vertices: document.querySelector("#vertices") as HTMLElement,
10+
objects: document.querySelector("#status--objects") as HTMLElement,
11+
vertices: document.querySelector("#status--vertices") as HTMLElement,
1212
};
1313

1414
export const settings = {

src/editor/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./panels.ts";

src/editor/panels.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const panels = JSON.parse(localStorage.getItem("panels") ?? "{}");
2+
3+
for(const panel of document.querySelectorAll<HTMLElement>(".panel")){
4+
const header = panel.querySelector<HTMLElement>(".panel__header");
5+
if(!header){
6+
continue;
7+
}
8+
9+
header.draggable = true;
10+
11+
header.addEventListener("dragstart", (e: DragEvent) => {
12+
e.dataTransfer?.setData("text/plain", panel.id);
13+
}, false);
14+
15+
panel.addEventListener("dragenter", (e: DragEvent) => {
16+
e.preventDefault();
17+
panel.style.borderColor = "#FFF";
18+
}, false);
19+
20+
panel.addEventListener("dragover", (e: DragEvent) => {
21+
e.preventDefault();
22+
panel.style.borderColor = "#FFF";
23+
}, false);
24+
25+
panel.addEventListener("dragleave", (e: DragEvent) => {
26+
e.preventDefault();
27+
panel.style.borderColor = "";
28+
}, false);
29+
30+
panel.addEventListener("drop", (e: DragEvent) => {
31+
e.stopPropagation();
32+
panel.style.borderColor = "";
33+
34+
const id = e.dataTransfer?.getData("text/plain");
35+
36+
// ignore self
37+
if(!id || id === panel.id){
38+
return;
39+
}
40+
41+
const otherPanel = document.querySelector<HTMLElement>(`#${id}`);
42+
if(!otherPanel){
43+
return;
44+
}
45+
46+
const panelGridArea = window.getComputedStyle(panel).gridArea;
47+
const otherPanelGridArea = window.getComputedStyle(otherPanel).gridArea;
48+
49+
panel.style.gridArea = otherPanelGridArea;
50+
otherPanel.style.gridArea = panelGridArea;
51+
52+
// resize canvas if needed
53+
if(panel.id === "preview" || otherPanel.id === "preview"){
54+
const canvas = document.querySelector("canvas");
55+
56+
if(canvas){
57+
canvas.width = 0;
58+
canvas.height = 0;
59+
}
60+
}
61+
62+
panels[panel.id] = panel.style.gridArea;
63+
panels[otherPanel.id] = otherPanel.style.gridArea;
64+
localStorage.setItem("panels", JSON.stringify(panels));
65+
}, false);
66+
67+
if(panels[panel.id]){
68+
panel.style.gridArea = panels[panel.id];
69+
}
70+
}

src/index.ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@
6060
<input type="file" id="bzw-file" accept=".bzw">
6161
</header>
6262
<main>
63-
<div class="panel objects">
63+
<div class="panel" id="objects">
6464
<div class="panel__header">
6565
Objects
6666
<svg onclick="alert('not implemented yet')" width="10" height="8" viewBox="0 0 10 8" xmlns="http://www.w3.org/2000/svg"><line y1="1" x2="10" y2="1"/><line y1="4" x2="10" y2="4"/><line y1="7" x2="10" y2="7"/></svg>
6767
</div>
6868
<div class="panel__content"></div>
6969
</div>
70-
<div class="panel properties">
70+
<div class="panel" id="properties">
7171
<div class="panel__header">
7272
Properties
7373
<svg onclick="alert('not implemented yet')" width="10" height="8" viewBox="0 0 10 8" xmlns="http://www.w3.org/2000/svg"><line y1="1" x2="10" y2="1"/><line y1="4" x2="10" y2="4"/><line y1="7" x2="10" y2="7"/></svg>
7474
</div>
7575
<div class="panel__content"></div>
7676
</div>
77-
<div class="panel preview">
77+
<div class="panel" id="preview">
7878
<div class="panel__header">
7979
Preview
8080
<svg onclick="alert('not implemented yet')" width="10" height="8" viewBox="0 0 10 8" xmlns="http://www.w3.org/2000/svg"><line y1="1" x2="10" y2="1"/><line y1="4" x2="10" y2="4"/><line y1="7" x2="10" y2="7"/></svg>
@@ -85,8 +85,8 @@
8585
</div>
8686
</main>
8787
<footer>
88-
<span id="objects"></span>
89-
<span id="vertices"></span>
88+
<span id="status--objects"></span>
89+
<span id="status--vertices"></span>
9090
<span style="flex:1"></span>
9191
<span><a href="https://github.com/BZFlagCommunity/webbzw" target="_blank" rel="noopener noreferrer">GitHub</a></span>
9292
<span>Copyright &copy; 2021 <a href="https://thenoah.dev" target="_blank" rel="noopener noreferrer">The Noah</a></span>

src/style.css

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ textarea.show{
300300
font-weight: 500;
301301
display: flex;
302302
align-items: center;
303+
cursor: grab;
303304
}
304305

305306
.panel__header > svg{
306307
margin-left: .75rem;
307308
stroke: var(--text-color);
308-
cursor: grab;
309309
}
310310

311311
.panel__content{
@@ -330,52 +330,53 @@ textarea.show{
330330
background-color: var(--border-color);
331331
}
332332

333-
.objects{
333+
#objects{
334334
grid-column: 1;
335335
grid-row: 1;
336336
}
337337

338-
.objects > .panel__content{
338+
#objects > .panel__content{
339339
font-size: .8rem;
340340
font-family: "Source Code Pro", monospace;
341341
line-height: 1em;
342342
user-select: none;
343343
}
344344

345-
.objects > .panel__content > div{
345+
#objects > .panel__content > div{
346346
padding: .1rem;
347347
color: var(--text-light-color);
348348
cursor: pointer;
349349
}
350350

351-
.objects > .panel__content > div.selected, .objects > .panel__content > div:hover{
351+
#objects > .panel__content > div.selected,
352+
#objects > .panel__content > div:hover{
352353
color: var(--text-color);
353354
}
354355

355-
.properties{
356+
#properties{
356357
grid-column: 1;
357358
grid-row: 2;
358359
}
359360

360-
.properties > .panel__content > div{
361+
#properties > .panel__content > div{
361362
display: flex;
362363
flex-direction: row;
363364
align-items: center;
364365
}
365366

366-
.properties > .panel__content > div:not(:last-child){
367+
#properties > .panel__content > div:not(:last-child){
367368
margin-bottom: .5rem;
368369
}
369370

370-
.properties > .panel__content > div > *:not(input[type=checkbox]){
371+
#properties > .panel__content > div > *:not(input[type=checkbox]){
371372
flex: 1;
372373
}
373374

374-
.properties > .panel__content > div > *:not(:last-child){
375+
#properties > .panel__content > div > *:not(:last-child){
375376
margin-right: .2rem;
376377
}
377378

378-
.properties > .panel__content input{
379+
#properties > .panel__content input{
379380
padding: .2rem .5rem;
380381
background: none;
381382
font-family: "Source Code Pro", monospace;
@@ -385,15 +386,16 @@ textarea.show{
385386
outline: none;
386387
}
387388

388-
.properties > .panel__content input:not([type=checkbox]){
389+
#properties > .panel__content input:not([type=checkbox]){
389390
width: 100%;
390391
}
391392

392-
.preview{
393+
#preview{
393394
grid-column: 2;
394395
grid-row: 1 / 3;
395396
}
396397

397-
.preview canvas{
398+
#preview canvas{
399+
min-height: 100px;
398400
flex: 1;
399401
}

0 commit comments

Comments
 (0)