-
-
Notifications
You must be signed in to change notification settings - Fork 322
Expand file tree
/
Copy pathelements_window_handle.js
More file actions
69 lines (60 loc) · 1.66 KB
/
elements_window_handle.js
File metadata and controls
69 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class ElementsWindowHandle extends HTMLElement {
#dragging = false
#elementsWindow = null
#previewWindow = null
connectedCallback() {
this.addEventListener("mousedown", this)
window.addEventListener("mousemove", this)
window.addEventListener("mouseup", this)
}
disconnectedCallback() {
this.removeEventListener("mousedown", this)
window.removeEventListener("mousemove", this)
window.removeEventListener("mouseup", this)
}
handleEvent(event) {
switch (event.type) {
case "mousedown":
event.stopPropagation()
this.onMouseDown()
break
case "mouseup":
this.onMouseUp()
break
case "mousemove":
if (this.#dragging) {
this.onDrag(event.pageX)
}
break
}
}
onMouseDown() {
this.#dragging = true
this.elementsWindow.isDragged = true
this.previewWindow.isDragged = true
this.classList.add("is-dragged")
}
onMouseUp() {
this.#dragging = false
this.elementsWindow.isDragged = false
this.previewWindow.isDragged = false
this.classList.remove("is-dragged")
}
onDrag(pageX) {
const elementWindowWidth = window.innerWidth - pageX
this.elementsWindow.resize(elementWindowWidth)
}
get elementsWindow() {
if (!this.#elementsWindow) {
this.#elementsWindow = document.querySelector("alchemy-elements-window")
}
return this.#elementsWindow
}
get previewWindow() {
if (!this.#previewWindow) {
this.#previewWindow = document.getElementById("alchemy_preview_window")
}
return this.#previewWindow
}
}
customElements.define("alchemy-elements-window-handle", ElementsWindowHandle)