forked from daybrush/selecto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoveable.html
248 lines (215 loc) · 6.2 KB
/
moveable.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html>
<body>
<style>
html,
body,
#root {
position: relative;
margin: 0;
padding: 0;
height: 100%;
color: #333;
background: #fdfdfd;
}
.app {
position: relative;
min-height: 100%;
padding: 10px 20px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.container {
max-width: 800px;
;
}
body {
background: #fff;
}
.logo {
position: relative;
width: 150px;
height: 150px;
margin: 0px auto;
font-size: 0;
text-align: left;
}
.logo.logos {
width: 320px;
text-align: center;
}
.logos .selecto {
padding: 16px;
}
.logo img {
position: relative;
height: 100%;
box-sizing: border-box;
}
.cube {
display: inline-block;
border-radius: 5px;
width: 40px;
height: 40px;
margin: 4px;
background: #eee;
--color: #4af;
}
h1,
.description {
text-align: center;
}
.button {
border: 1px solid #333;
color: #333;
background: transparent;
appearance: none;
-webkit-appearance: none;
box-sizing: border-box;
cursor: pointer;
width: 120px;
height: 42px;
font-size: 14px;
letter-spacing: 1px;
transition: all ease 0.2s;
margin: 0px 5px;
}
.button:hover {
background: #333;
color: white;
}
.elements {
margin-top: 40px;
border: 2px solid #eee;
}
.selecto-area {
padding: 20px;
}
#selecto1 .cube {
transition: all ease 0.2s;
}
.moveable #selecto1 .cube {
transition: none;
}
.selecto-area .selected {
color: #fff;
background: var(--color);
}
.scroll {
overflow: auto;
padding-top: 10px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.infinite-viewer,
.scroll {
width: 100%;
height: 300px;
box-sizing: border-box;
}
.infinite-viewer .viewport {
padding-top: 10px;
}
.empty.elements {
border: none;
}
</style>
<div class="moveable app">
<div class="container">
<div class="logo logos" id="logo">
<a href="https://github.com/daybrush/selecto" target="_blank"><img
src="https://daybrush.com/selecto/images/256x256.png" class="selecto" /></a>
<a href="https://github.com/daybrush/moveable" target="_blank"><img
src="https://daybrush.com/moveable/images/256x256.png" /></a>
</div>
<h1>Select Moveable targets in real time.</h1>
<p class="description">You can drag and move targets and select them.</p>
<div class="elements selecto-area"></div>
</div>
</div>
</body>
<script src="../../dist/selecto.js"></script>
<script src="https://daybrush.com/moveable/release/latest/dist/moveable.js"></script>
<script>
const container = document.querySelector(".container");
const frameMap = new Map();
const cubes = [];
let targets = [];
for (let i = 0; i < 30; ++i) {
cubes.push(i);
}
container.querySelector(".selecto-area").innerHTML
= cubes.map(i => `<div class="cube"></div>`).join("");
const selecto = new Selecto({
container,
dragContainer: ".elements",
selectableTargets: [".selecto-area .cube"],
hitRate: 0,
selectByClick: true,
selectFromInside: false,
toggleContinueSelect: ["shift"],
ratio: 0,
});
const moveable = new Moveable(container, {
draggable: true,
}).on("clickGroup", e => {
selecto.clickTarget(e.inputEvent, e.inputTarget);
}).on("dragStart", e => {
const target = e.target;
if (!frameMap.has(target)) {
frameMap.set(target, {
translate: [0, 0],
});
}
const frame = frameMap.get(target);
e.set(frame.translate);
}).on("drag", e => {
const target = e.target;
const frame = frameMap.get(target);
frame.translate = e.beforeTranslate;
target.style.transform = `translate(${frame.translate[0]}px, ${frame.translate[1]}px)`;
}).on("dragGroupStart", e => {
e.events.forEach(ev => {
const target = ev.target;
if (!frameMap.has(target)) {
frameMap.set(target, {
translate: [0, 0],
});
}
const frame = frameMap.get(target);
ev.set(frame.translate);
});
}).on("dragGroup", e => {
e.events.forEach(ev => {
const target = ev.target;
const frame = frameMap.get(target);
frame.translate = ev.beforeTranslate;
target.style.transform = `translate(${frame.translate[0]}px, ${frame.translate[1]}px)`;
});
});
selecto.on("dragStart", e => {
const target = e.inputEvent.target;
if (
moveable.isMoveableElement(target)
|| targets.some(t => t === target || t.contains(target))
) {
e.stop();
}
}).on("select", e => {
targets = e.selected;
moveable.target = targets;
}).on("selectEnd", e => {
if (e.isDragStart) {
e.inputEvent.preventDefault();
setTimeout(() => {
moveable.dragStart(e.inputEvent);
});
}
});
</script>
</html>