-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvd-tool.html
130 lines (105 loc) · 3.63 KB
/
vd-tool.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<html doctype>
<head>
<title>Visual Design Tool</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
width:100%;
display:flex;
/* justify-content: center; */
margin-top: 55px;
align-items: center;
height: 100%;
}
.componentsPanel {
width: 30%;
height: 100%;
border: 1px solid lightseagreen;
background: black;
color: white;
padding: 5px 10px;
}
.hellbox {
border: 1px solid palevioletred;
width: 100%;
height: 100%;
}
.propsPanel {
width: 30%;
height: 100%;
border: 1px solid limegreen;
}
.hellbox button {
padding: 5px;
color: white;
background: palevioletred;
border: unset;
}
.draggable {
background: gray;
padding: 5px 10px;
margin: 2px 0;
}
.hellboxSelected {
border: 1px solid lime !important;
}
</style>
</head>
<body>
<div class="componentsPanel">
<div id="draggable" element="div" elementText="Div" class="draggable" draggable="true" ondragstart = "return dragStart(event)">Div</div>
<div id="draggable" element="button" elementText="Button" class="draggable" draggable="true" ondragstart = "return dragStart(event)">Button</div>
</div>
<div id="hellbox" onclick="return hellboxClick(event)" class="hellbox" ondragenter="return dragEnter(event)" ondrop="return dragDrop(event)" ondragover="return dragOver(event)">
Hell
</div>
<div class="propsPanel" id="propsPanel">
</div>
</body>
<script>
function dragStart(ev) {
ev.dataTransfer.effectAllowed = 'copy';
/* ev.target.getAttribute('id') */
ev.dataTransfer.setData("element", ev.target.getAttribute('element'));
ev.dataTransfer.setData("elementText", ev.target.getAttribute('elementText'));
ev.dataTransfer.setDragImage(ev.target, 0, 0);
return true;
}
function dragEnter(ev){
event.preventDefault();
return true;
}
function dragOver(ev) {
return false;
}
function dragDrop(ev){
var src = ev.dataTransfer.getData("element");
var elText = ev.dataTransfer.getData("elementText");
const el = document.createElement(src)
el.append(document.createTextNode(elText))
ev.target.appendChild(el);
ev.stopPropagation();
return false;
}
function hellboxClick(ev) {
const nodes = document.querySelectorAll(".hellboxSelected")
nodes.forEach(node => {
node.classList.remove("hellboxSelected")
})
ev.target.classList.add("hellboxSelected")
displayProps(ev.target)
}
function displayProps(el) {
const { innerHTML, innerText, style } = el;
console.log(el, style)
const { width, height, color, background } = style;
propsPanel.innerHTML = ""
propsPanel.innerHTML += `
<div>
<div>Width: ${width}</div>
<div>Height: ${height}</div>
</div>
`
}
</script>
</html>