-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./panels.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const panels = JSON.parse(localStorage.getItem("panels") ?? "{}"); | ||
|
||
for(const panel of document.querySelectorAll<HTMLElement>(".panel")){ | ||
const header = panel.querySelector<HTMLElement>(".panel__header"); | ||
if(!header){ | ||
continue; | ||
} | ||
|
||
header.draggable = true; | ||
|
||
header.addEventListener("dragstart", (e: DragEvent) => { | ||
e.dataTransfer?.setData("text/plain", panel.id); | ||
}, false); | ||
|
||
panel.addEventListener("dragenter", (e: DragEvent) => { | ||
e.preventDefault(); | ||
panel.style.borderColor = "#FFF"; | ||
}, false); | ||
|
||
panel.addEventListener("dragover", (e: DragEvent) => { | ||
e.preventDefault(); | ||
panel.style.borderColor = "#FFF"; | ||
}, false); | ||
|
||
panel.addEventListener("dragleave", (e: DragEvent) => { | ||
e.preventDefault(); | ||
panel.style.borderColor = ""; | ||
}, false); | ||
|
||
panel.addEventListener("drop", (e: DragEvent) => { | ||
e.stopPropagation(); | ||
panel.style.borderColor = ""; | ||
|
||
const id = e.dataTransfer?.getData("text/plain"); | ||
|
||
// ignore self | ||
if(!id || id === panel.id){ | ||
return; | ||
} | ||
|
||
const otherPanel = document.querySelector<HTMLElement>(`#${id}`); | ||
if(!otherPanel){ | ||
return; | ||
} | ||
|
||
const panelGridArea = window.getComputedStyle(panel).gridArea; | ||
const otherPanelGridArea = window.getComputedStyle(otherPanel).gridArea; | ||
|
||
panel.style.gridArea = otherPanelGridArea; | ||
otherPanel.style.gridArea = panelGridArea; | ||
|
||
// resize canvas if needed | ||
if(panel.id === "preview" || otherPanel.id === "preview"){ | ||
const canvas = document.querySelector("canvas"); | ||
|
||
if(canvas){ | ||
canvas.width = 0; | ||
canvas.height = 0; | ||
} | ||
} | ||
|
||
panels[panel.id] = panel.style.gridArea; | ||
panels[otherPanel.id] = otherPanel.style.gridArea; | ||
localStorage.setItem("panels", JSON.stringify(panels)); | ||
}, false); | ||
|
||
if(panels[panel.id]){ | ||
panel.style.gridArea = panels[panel.id]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters