Skip to content

Commit

Permalink
Merge pull request #3097 from AlchemyCMS/resizable-element-window
Browse files Browse the repository at this point in the history
Resizable elements window
  • Loading branch information
tvdeyen authored Dec 2, 2024
2 parents e6523b8 + 44d3a39 commit b4b2471
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/admin.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/custom-properties.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/custom-properties.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/welcome.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/builds/alchemy/welcome.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions app/javascript/alchemy_admin/components/elements_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SortableElements from "alchemy_admin/sortable_elements"

class ElementsWindow extends HTMLElement {
#visible = true
#turboFrame = null

constructor() {
super()
Expand All @@ -19,6 +20,7 @@ class ElementsWindow extends HTMLElement {
?.trigger("FocusElementEditor.Alchemy")
}
SortableElements()
this.resize()
}

collapseAllElements() {
Expand All @@ -38,17 +40,30 @@ class ElementsWindow extends HTMLElement {
this.toggleButton
.querySelector("alchemy-icon")
.setAttribute("name", "menu-unfold")
this.resize()
}

hide() {
document.body.classList.remove("elements-window-visible")
document.body.style.removeProperty("--elements-window-width")
this.#visible = false
this.toggleButton.closest("sl-tooltip").content = Alchemy.t("Show elements")
this.toggleButton
.querySelector("alchemy-icon")
.setAttribute("name", "menu-fold")
}

resize(width) {
if (width === undefined) {
width = this.widthFromCookie
}

if (width) {
document.body.style.setProperty("--elements-window-width", `${width}px`)
document.cookie = `alchemy-elements-window-width=${width}; SameSite=Lax; Path=/;`
}
}

get collapseButton() {
return this.querySelector("#collapse-all-elements-button")
}
Expand All @@ -61,6 +76,25 @@ class ElementsWindow extends HTMLElement {
return document.getElementById("alchemy_preview_window")
}

get turboFrame() {
if (!this.#turboFrame) {
this.#turboFrame = this.closest("turbo-frame")
}
return this.#turboFrame
}

get widthFromCookie() {
return document.cookie
.split("; ")
.find((row) => row.startsWith("alchemy-elements-window-width="))
?.split("=")[1]
}

set isDragged(dragged) {
this.turboFrame.style.transitionProperty = dragged ? "none" : null
this.turboFrame.style.pointerEvents = dragged ? "none" : null
}

#attachEvents() {
this.collapseButton?.addEventListener("click", () => {
this.collapseAllElements()
Expand Down
Loading

0 comments on commit b4b2471

Please sign in to comment.