gridstack 7.3.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/dd-base-impl.d.ts +20 -20
- package/dist/dd-base-impl.js +31 -35
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +28 -28
- package/dist/dd-draggable.js +336 -344
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +26 -26
- package/dist/dd-droppable.js +146 -148
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +27 -27
- package/dist/dd-element.js +90 -94
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +34 -34
- package/dist/dd-gridstack.js +127 -124
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +22 -22
- package/dist/dd-manager.js +9 -13
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +14 -14
- package/dist/dd-resizable-handle.js +102 -105
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +28 -28
- package/dist/dd-resizable.js +290 -296
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +33 -33
- package/dist/dd-touch.js +173 -182
- package/dist/dd-touch.js.map +1 -1
- package/dist/es5/dd-base-impl.d.ts +20 -20
- package/dist/es5/dd-base-impl.js +40 -40
- package/dist/es5/dd-base-impl.js.map +1 -1
- package/dist/es5/dd-draggable.d.ts +28 -28
- package/dist/es5/dd-draggable.js +366 -367
- package/dist/es5/dd-draggable.js.map +1 -1
- package/dist/es5/dd-droppable.d.ts +26 -26
- package/dist/es5/dd-droppable.js +181 -179
- package/dist/es5/dd-droppable.js.map +1 -1
- package/dist/es5/dd-element.d.ts +27 -27
- package/dist/es5/dd-element.js +95 -95
- package/dist/es5/dd-element.js.map +1 -1
- package/dist/es5/dd-gridstack.d.ts +34 -34
- package/dist/es5/dd-gridstack.js +144 -144
- package/dist/es5/dd-gridstack.js.map +1 -1
- package/dist/es5/dd-manager.d.ts +22 -22
- package/dist/es5/dd-manager.js +16 -16
- package/dist/es5/dd-manager.js.map +1 -1
- package/dist/es5/dd-resizable-handle.d.ts +14 -14
- package/dist/es5/dd-resizable-handle.js +105 -106
- package/dist/es5/dd-resizable-handle.js.map +1 -1
- package/dist/es5/dd-resizable.d.ts +28 -28
- package/dist/es5/dd-resizable.js +317 -318
- package/dist/es5/dd-resizable.js.map +1 -1
- package/dist/es5/dd-touch.d.ts +33 -33
- package/dist/es5/dd-touch.js +185 -185
- package/dist/es5/dd-touch.js.map +1 -1
- package/dist/es5/gridstack-all.js +1 -1
- package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/es5/gridstack-all.js.map +1 -1
- package/dist/es5/gridstack-engine.d.ts +102 -102
- package/dist/es5/gridstack-engine.js +1000 -995
- package/dist/es5/gridstack-engine.js.map +1 -1
- package/dist/es5/gridstack-poly.js +1 -1
- package/dist/es5/gridstack.d.ts +392 -376
- package/dist/es5/gridstack.js +2254 -2233
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +279 -284
- package/dist/es5/types.js +47 -35
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +95 -93
- package/dist/es5/utils.js +600 -569
- package/dist/es5/utils.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +102 -102
- package/dist/gridstack-engine.js +950 -954
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack-extra.css +0 -390
- package/dist/gridstack-extra.min.css +1 -1
- package/dist/gridstack.css +19 -97
- package/dist/gridstack.d.ts +392 -376
- package/dist/gridstack.js +2155 -2157
- package/dist/gridstack.js.map +1 -1
- package/dist/gridstack.min.css +1 -1
- package/dist/ng/README.md +154 -0
- package/dist/ng/gridstack-item.component.d.ts +29 -0
- package/dist/ng/gridstack-item.component.js +65 -0
- package/dist/ng/gridstack-item.component.js.map +1 -0
- package/dist/ng/gridstack.component.d.ts +118 -0
- package/dist/ng/gridstack.component.js +245 -0
- package/dist/ng/gridstack.component.js.map +1 -0
- package/dist/src/gridstack-extra.scss +0 -2
- package/dist/src/gridstack.scss +14 -9
- package/dist/types.d.ts +279 -284
- package/dist/types.js +44 -35
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +95 -93
- package/dist/utils.js +546 -527
- package/dist/utils.js.map +1 -1
- package/{dist → dist_save}/angular/gridstack-item.component.ts +5 -3
- package/{dist → dist_save}/angular/gridstack.component.ts +32 -18
- package/dist_save/dd-base-impl.d.ts +20 -0
- package/dist_save/dd-base-impl.js +36 -0
- package/dist_save/dd-base-impl.js.map +1 -0
- package/dist_save/dd-draggable.d.ts +28 -0
- package/dist_save/dd-draggable.js +343 -0
- package/dist_save/dd-draggable.js.map +1 -0
- package/dist_save/dd-droppable.d.ts +26 -0
- package/dist_save/dd-droppable.js +149 -0
- package/dist_save/dd-droppable.js.map +1 -0
- package/dist_save/dd-element.d.ts +27 -0
- package/dist_save/dd-element.js +95 -0
- package/dist_save/dd-element.js.map +1 -0
- package/dist_save/dd-gridstack.d.ts +34 -0
- package/dist_save/dd-gridstack.js +125 -0
- package/dist_save/dd-gridstack.js.map +1 -0
- package/dist_save/dd-manager.d.ts +22 -0
- package/dist_save/dd-manager.js +14 -0
- package/dist_save/dd-manager.js.map +1 -0
- package/dist_save/dd-resizable-handle.d.ts +14 -0
- package/dist_save/dd-resizable-handle.js +106 -0
- package/dist_save/dd-resizable-handle.js.map +1 -0
- package/dist_save/dd-resizable.d.ts +28 -0
- package/dist_save/dd-resizable.js +294 -0
- package/dist_save/dd-resizable.js.map +1 -0
- package/dist_save/dd-touch.d.ts +33 -0
- package/dist_save/dd-touch.js +183 -0
- package/dist_save/dd-touch.js.map +1 -0
- package/dist_save/es5/dd-base-impl.d.ts +20 -0
- package/dist_save/es5/dd-base-impl.js +41 -0
- package/dist_save/es5/dd-base-impl.js.map +1 -0
- package/dist_save/es5/dd-draggable.d.ts +28 -0
- package/dist_save/es5/dd-draggable.js +366 -0
- package/dist_save/es5/dd-draggable.js.map +1 -0
- package/dist_save/es5/dd-droppable.d.ts +26 -0
- package/dist_save/es5/dd-droppable.js +180 -0
- package/dist_save/es5/dd-droppable.js.map +1 -0
- package/dist_save/es5/dd-element.d.ts +27 -0
- package/dist_save/es5/dd-element.js +96 -0
- package/dist_save/es5/dd-element.js.map +1 -0
- package/dist_save/es5/dd-gridstack.d.ts +34 -0
- package/dist_save/es5/dd-gridstack.js +145 -0
- package/dist_save/es5/dd-gridstack.js.map +1 -0
- package/dist_save/es5/dd-manager.d.ts +22 -0
- package/dist_save/es5/dd-manager.js +17 -0
- package/dist_save/es5/dd-manager.js.map +1 -0
- package/dist_save/es5/dd-resizable-handle.d.ts +14 -0
- package/dist_save/es5/dd-resizable-handle.js +107 -0
- package/dist_save/es5/dd-resizable-handle.js.map +1 -0
- package/dist_save/es5/dd-resizable.d.ts +28 -0
- package/dist_save/es5/dd-resizable.js +316 -0
- package/dist_save/es5/dd-resizable.js.map +1 -0
- package/dist_save/es5/dd-touch.d.ts +33 -0
- package/dist_save/es5/dd-touch.js +186 -0
- package/dist_save/es5/dd-touch.js.map +1 -0
- package/dist_save/es5/gridstack-all.js +3 -0
- package/dist_save/es5/gridstack-all.js.LICENSE.txt +7 -0
- package/dist_save/es5/gridstack-all.js.map +1 -0
- package/dist_save/es5/gridstack-engine.d.ts +102 -0
- package/dist_save/es5/gridstack-engine.js +997 -0
- package/dist_save/es5/gridstack-engine.js.map +1 -0
- package/dist_save/es5/gridstack-poly.js +356 -0
- package/dist_save/es5/gridstack.d.ts +376 -0
- package/dist_save/es5/gridstack.js +2238 -0
- package/dist_save/es5/gridstack.js.map +1 -0
- package/dist_save/es5/types.d.ts +284 -0
- package/dist_save/es5/types.js +36 -0
- package/dist_save/es5/types.js.map +1 -0
- package/dist_save/es5/utils.d.ts +95 -0
- package/dist_save/es5/utils.js +590 -0
- package/dist_save/es5/utils.js.map +1 -0
- package/dist_save/gridstack-all.js +3 -0
- package/dist_save/gridstack-all.js.LICENSE.txt +7 -0
- package/dist_save/gridstack-all.js.map +1 -0
- package/dist_save/gridstack-engine.d.ts +102 -0
- package/dist_save/gridstack-engine.js +956 -0
- package/dist_save/gridstack-engine.js.map +1 -0
- package/dist_save/gridstack-extra.css +433 -0
- package/dist_save/gridstack-extra.min.css +1 -0
- package/dist_save/gridstack.css +226 -0
- package/dist_save/gridstack.d.ts +376 -0
- package/dist_save/gridstack.js +2162 -0
- package/dist_save/gridstack.js.map +1 -0
- package/dist_save/gridstack.min.css +1 -0
- package/dist_save/src/gridstack-extra.scss +27 -0
- package/dist_save/src/gridstack.scss +131 -0
- package/dist_save/types.d.ts +284 -0
- package/dist_save/types.js +36 -0
- package/dist_save/types.js.map +1 -0
- package/dist_save/utils.d.ts +95 -0
- package/dist_save/utils.js +548 -0
- package/dist_save/utils.js.map +1 -0
- package/doc/CHANGES.md +20 -0
- package/doc/README.md +21 -14
- package/package.json +25 -24
- /package/{dist → dist_save}/angular/README.md +0 -0
package/dist/dd-draggable.js
CHANGED
|
@@ -1,345 +1,337 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
super.
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
delete this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
return true;
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
this.
|
|
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
|
-
this.
|
|
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
|
-
this.
|
|
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
|
-
if (this.
|
|
188
|
-
this.
|
|
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
|
-
this.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
|
|
338
|
-
*/
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
exports.DDDraggable = DDDraggable;
|
|
343
|
-
/** @internal properties we change during dragging, and restore back */
|
|
344
|
-
DDDraggable.originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top', 'minWidth', 'willChange'];
|
|
1
|
+
/**
|
|
2
|
+
* dd-draggable.ts 8.0.1
|
|
3
|
+
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
|
|
4
|
+
*/
|
|
5
|
+
import { DDManager } from './dd-manager';
|
|
6
|
+
import { Utils } from './utils';
|
|
7
|
+
import { DDBaseImplement } from './dd-base-impl';
|
|
8
|
+
import { isTouch, touchend, touchmove, touchstart, pointerdown } from './dd-touch';
|
|
9
|
+
// let count = 0; // TEST
|
|
10
|
+
class DDDraggable extends DDBaseImplement {
|
|
11
|
+
constructor(el, option = {}) {
|
|
12
|
+
super();
|
|
13
|
+
this.el = el;
|
|
14
|
+
this.option = option;
|
|
15
|
+
// get the element that is actually supposed to be dragged by
|
|
16
|
+
let handleName = option.handle.substring(1);
|
|
17
|
+
this.dragEl = el.classList.contains(handleName) ? el : el.querySelector(option.handle) || el;
|
|
18
|
+
// create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
|
|
19
|
+
this._mouseDown = this._mouseDown.bind(this);
|
|
20
|
+
this._mouseMove = this._mouseMove.bind(this);
|
|
21
|
+
this._mouseUp = this._mouseUp.bind(this);
|
|
22
|
+
this.enable();
|
|
23
|
+
}
|
|
24
|
+
on(event, callback) {
|
|
25
|
+
super.on(event, callback);
|
|
26
|
+
}
|
|
27
|
+
off(event) {
|
|
28
|
+
super.off(event);
|
|
29
|
+
}
|
|
30
|
+
enable() {
|
|
31
|
+
if (this.disabled === false)
|
|
32
|
+
return;
|
|
33
|
+
super.enable();
|
|
34
|
+
this.dragEl.addEventListener('mousedown', this._mouseDown);
|
|
35
|
+
if (isTouch) {
|
|
36
|
+
this.dragEl.addEventListener('touchstart', touchstart);
|
|
37
|
+
this.dragEl.addEventListener('pointerdown', pointerdown);
|
|
38
|
+
// this.dragEl.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
|
|
39
|
+
}
|
|
40
|
+
this.el.classList.remove('ui-draggable-disabled');
|
|
41
|
+
}
|
|
42
|
+
disable(forDestroy = false) {
|
|
43
|
+
if (this.disabled === true)
|
|
44
|
+
return;
|
|
45
|
+
super.disable();
|
|
46
|
+
this.dragEl.removeEventListener('mousedown', this._mouseDown);
|
|
47
|
+
if (isTouch) {
|
|
48
|
+
this.dragEl.removeEventListener('touchstart', touchstart);
|
|
49
|
+
this.dragEl.removeEventListener('pointerdown', pointerdown);
|
|
50
|
+
}
|
|
51
|
+
if (!forDestroy)
|
|
52
|
+
this.el.classList.add('ui-draggable-disabled');
|
|
53
|
+
}
|
|
54
|
+
destroy() {
|
|
55
|
+
if (this.dragTimeout)
|
|
56
|
+
window.clearTimeout(this.dragTimeout);
|
|
57
|
+
delete this.dragTimeout;
|
|
58
|
+
if (this.dragging)
|
|
59
|
+
this._mouseUp(this.mouseDownEvent);
|
|
60
|
+
this.disable(true);
|
|
61
|
+
delete this.el;
|
|
62
|
+
delete this.helper;
|
|
63
|
+
delete this.option;
|
|
64
|
+
super.destroy();
|
|
65
|
+
}
|
|
66
|
+
updateOption(opts) {
|
|
67
|
+
Object.keys(opts).forEach(key => this.option[key] = opts[key]);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/** @internal call when mouse goes down before a dragstart happens */
|
|
71
|
+
_mouseDown(e) {
|
|
72
|
+
// don't let more than one widget handle mouseStart
|
|
73
|
+
if (DDManager.mouseHandled)
|
|
74
|
+
return;
|
|
75
|
+
if (e.button !== 0)
|
|
76
|
+
return true; // only left click
|
|
77
|
+
// make sure we are not clicking on known object that handles mouseDown (TODO: make this extensible ?) #2054
|
|
78
|
+
const skipMouseDown = ['input', 'textarea', 'button', 'select', 'option'];
|
|
79
|
+
const name = e.target.nodeName.toLowerCase();
|
|
80
|
+
if (skipMouseDown.find(skip => skip === name))
|
|
81
|
+
return true;
|
|
82
|
+
// also check for content editable
|
|
83
|
+
if (e.target.closest('[contenteditable="true"]'))
|
|
84
|
+
return true;
|
|
85
|
+
// REMOVE: why would we get the event if it wasn't for us or child ?
|
|
86
|
+
// make sure we are clicking on a drag handle or child of it...
|
|
87
|
+
// Note: we don't need to check that's handle is an immediate child, as mouseHandled will prevent parents from also handling it (lowest wins)
|
|
88
|
+
// let className = this.option.handle.substring(1);
|
|
89
|
+
// let el = e.target as HTMLElement;
|
|
90
|
+
// while (el && !el.classList.contains(className)) { el = el.parentElement; }
|
|
91
|
+
// if (!el) return;
|
|
92
|
+
this.mouseDownEvent = e;
|
|
93
|
+
delete this.dragging;
|
|
94
|
+
delete DDManager.dragElement;
|
|
95
|
+
delete DDManager.dropElement;
|
|
96
|
+
// document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
|
|
97
|
+
document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
|
|
98
|
+
document.addEventListener('mouseup', this._mouseUp, true);
|
|
99
|
+
if (isTouch) {
|
|
100
|
+
this.dragEl.addEventListener('touchmove', touchmove);
|
|
101
|
+
this.dragEl.addEventListener('touchend', touchend);
|
|
102
|
+
}
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
// preventDefault() prevents blur event which occurs just after mousedown event.
|
|
105
|
+
// if an editable content has focus, then blur must be call
|
|
106
|
+
if (document.activeElement)
|
|
107
|
+
document.activeElement.blur();
|
|
108
|
+
DDManager.mouseHandled = true;
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
/** @internal method to call actual drag event */
|
|
112
|
+
_callDrag(e) {
|
|
113
|
+
if (!this.dragging)
|
|
114
|
+
return;
|
|
115
|
+
const ev = Utils.initEvent(e, { target: this.el, type: 'drag' });
|
|
116
|
+
if (this.option.drag) {
|
|
117
|
+
this.option.drag(ev, this.ui());
|
|
118
|
+
}
|
|
119
|
+
this.triggerEvent('drag', ev);
|
|
120
|
+
}
|
|
121
|
+
/** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */
|
|
122
|
+
_mouseMove(e) {
|
|
123
|
+
// console.log(`${count++} move ${e.x},${e.y}`)
|
|
124
|
+
let s = this.mouseDownEvent;
|
|
125
|
+
if (this.dragging) {
|
|
126
|
+
this._dragFollow(e);
|
|
127
|
+
// delay actual grid handling drag until we pause for a while if set
|
|
128
|
+
if (DDManager.pauseDrag) {
|
|
129
|
+
const pause = Number.isInteger(DDManager.pauseDrag) ? DDManager.pauseDrag : 100;
|
|
130
|
+
if (this.dragTimeout)
|
|
131
|
+
window.clearTimeout(this.dragTimeout);
|
|
132
|
+
this.dragTimeout = window.setTimeout(() => this._callDrag(e), pause);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this._callDrag(e);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (Math.abs(e.x - s.x) + Math.abs(e.y - s.y) > 3) {
|
|
139
|
+
/**
|
|
140
|
+
* don't start unless we've moved at least 3 pixels
|
|
141
|
+
*/
|
|
142
|
+
this.dragging = true;
|
|
143
|
+
DDManager.dragElement = this;
|
|
144
|
+
// if we're dragging an actual grid item, set the current drop as the grid (to detect enter/leave)
|
|
145
|
+
let grid = this.el.gridstackNode?.grid;
|
|
146
|
+
if (grid) {
|
|
147
|
+
DDManager.dropElement = grid.el.ddElement.ddDroppable;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
delete DDManager.dropElement;
|
|
151
|
+
}
|
|
152
|
+
this.helper = this._createHelper(e);
|
|
153
|
+
this._setupHelperContainmentStyle();
|
|
154
|
+
this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment);
|
|
155
|
+
const ev = Utils.initEvent(e, { target: this.el, type: 'dragstart' });
|
|
156
|
+
this._setupHelperStyle(e);
|
|
157
|
+
if (this.option.start) {
|
|
158
|
+
this.option.start(ev, this.ui());
|
|
159
|
+
}
|
|
160
|
+
this.triggerEvent('dragstart', ev);
|
|
161
|
+
}
|
|
162
|
+
e.preventDefault(); // needed otherwise we get text sweep text selection as we drag around
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
/** @internal call when the mouse gets released to drop the item at current location */
|
|
166
|
+
_mouseUp(e) {
|
|
167
|
+
document.removeEventListener('mousemove', this._mouseMove, true);
|
|
168
|
+
document.removeEventListener('mouseup', this._mouseUp, true);
|
|
169
|
+
if (isTouch) {
|
|
170
|
+
this.dragEl.removeEventListener('touchmove', touchmove, true);
|
|
171
|
+
this.dragEl.removeEventListener('touchend', touchend, true);
|
|
172
|
+
}
|
|
173
|
+
if (this.dragging) {
|
|
174
|
+
delete this.dragging;
|
|
175
|
+
// reset the drop target if dragging over ourself (already parented, just moving during stop callback below)
|
|
176
|
+
if (DDManager.dropElement?.el === this.el.parentElement) {
|
|
177
|
+
delete DDManager.dropElement;
|
|
178
|
+
}
|
|
179
|
+
this.helperContainment.style.position = this.parentOriginStylePosition || null;
|
|
180
|
+
if (this.helper === this.el) {
|
|
181
|
+
this._removeHelperStyle();
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
this.helper.remove();
|
|
185
|
+
}
|
|
186
|
+
const ev = Utils.initEvent(e, { target: this.el, type: 'dragstop' });
|
|
187
|
+
if (this.option.stop) {
|
|
188
|
+
this.option.stop(ev); // NOTE: destroy() will be called when removing item, so expect NULL ptr after!
|
|
189
|
+
}
|
|
190
|
+
this.triggerEvent('dragstop', ev);
|
|
191
|
+
// call the droppable method to receive the item
|
|
192
|
+
if (DDManager.dropElement) {
|
|
193
|
+
DDManager.dropElement.drop(e);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
delete this.helper;
|
|
197
|
+
delete this.mouseDownEvent;
|
|
198
|
+
delete DDManager.dragElement;
|
|
199
|
+
delete DDManager.dropElement;
|
|
200
|
+
delete DDManager.mouseHandled;
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
}
|
|
203
|
+
/** @internal create a clone copy (or user defined method) of the original drag item if set */
|
|
204
|
+
_createHelper(event) {
|
|
205
|
+
let helper = this.el;
|
|
206
|
+
if (typeof this.option.helper === 'function') {
|
|
207
|
+
helper = this.option.helper(event);
|
|
208
|
+
}
|
|
209
|
+
else if (this.option.helper === 'clone') {
|
|
210
|
+
helper = Utils.cloneNode(this.el);
|
|
211
|
+
}
|
|
212
|
+
if (!document.body.contains(helper)) {
|
|
213
|
+
Utils.appendTo(helper, this.option.appendTo === 'parent' ? this.el.parentElement : this.option.appendTo);
|
|
214
|
+
}
|
|
215
|
+
if (helper === this.el) {
|
|
216
|
+
this.dragElementOriginStyle = DDDraggable.originStyleProp.map(prop => this.el.style[prop]);
|
|
217
|
+
}
|
|
218
|
+
return helper;
|
|
219
|
+
}
|
|
220
|
+
/** @internal set the fix position of the dragged item */
|
|
221
|
+
_setupHelperStyle(e) {
|
|
222
|
+
this.helper.classList.add('ui-draggable-dragging');
|
|
223
|
+
// TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593
|
|
224
|
+
const style = this.helper.style;
|
|
225
|
+
style.pointerEvents = 'none'; // needed for over items to get enter/leave
|
|
226
|
+
// style.cursor = 'move'; // TODO: can't set with pointerEvents=none ! (done in CSS as well)
|
|
227
|
+
style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)
|
|
228
|
+
style.width = this.dragOffset.width + 'px';
|
|
229
|
+
style.height = this.dragOffset.height + 'px';
|
|
230
|
+
style.willChange = 'left, top';
|
|
231
|
+
style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'
|
|
232
|
+
this._dragFollow(e); // now position it
|
|
233
|
+
style.transition = 'none'; // show up instantly
|
|
234
|
+
setTimeout(() => {
|
|
235
|
+
if (this.helper) {
|
|
236
|
+
style.transition = null; // recover animation
|
|
237
|
+
}
|
|
238
|
+
}, 0);
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
/** @internal restore back the original style before dragging */
|
|
242
|
+
_removeHelperStyle() {
|
|
243
|
+
this.helper.classList.remove('ui-draggable-dragging');
|
|
244
|
+
let node = this.helper?.gridstackNode;
|
|
245
|
+
// don't bother restoring styles if we're gonna remove anyway...
|
|
246
|
+
if (!node?._isAboutToRemove && this.dragElementOriginStyle) {
|
|
247
|
+
let helper = this.helper;
|
|
248
|
+
// don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'.
|
|
249
|
+
// TODO: this also removes resizing animation which doesn't have this issue, but others.
|
|
250
|
+
// Ideally both would animate ('move' would immediately restore 'absolute' and adjust coordinate to match,
|
|
251
|
+
// then trigger a delay (repaint) to restore to final dest with animate) but then we need to make sure 'resizestop'
|
|
252
|
+
// is called AFTER 'transitionend' event is received (see https://github.com/gridstack/gridstack.js/issues/2033)
|
|
253
|
+
let transition = this.dragElementOriginStyle['transition'] || null;
|
|
254
|
+
helper.style.transition = this.dragElementOriginStyle['transition'] = 'none'; // can't be NULL #1973
|
|
255
|
+
DDDraggable.originStyleProp.forEach(prop => helper.style[prop] = this.dragElementOriginStyle[prop] || null);
|
|
256
|
+
setTimeout(() => helper.style.transition = transition, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)
|
|
257
|
+
}
|
|
258
|
+
delete this.dragElementOriginStyle;
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
/** @internal updates the top/left position to follow the mouse */
|
|
262
|
+
_dragFollow(e) {
|
|
263
|
+
let containmentRect = { left: 0, top: 0 };
|
|
264
|
+
// if (this.helper.style.position === 'absolute') { // we use 'fixed'
|
|
265
|
+
// const { left, top } = this.helperContainment.getBoundingClientRect();
|
|
266
|
+
// containmentRect = { left, top };
|
|
267
|
+
// }
|
|
268
|
+
const style = this.helper.style;
|
|
269
|
+
const offset = this.dragOffset;
|
|
270
|
+
style.left = e.clientX + offset.offsetLeft - containmentRect.left + 'px';
|
|
271
|
+
style.top = e.clientY + offset.offsetTop - containmentRect.top + 'px';
|
|
272
|
+
}
|
|
273
|
+
/** @internal */
|
|
274
|
+
_setupHelperContainmentStyle() {
|
|
275
|
+
this.helperContainment = this.helper.parentElement;
|
|
276
|
+
if (this.helper.style.position !== 'fixed') {
|
|
277
|
+
this.parentOriginStylePosition = this.helperContainment.style.position;
|
|
278
|
+
if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {
|
|
279
|
+
this.helperContainment.style.position = 'relative';
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
/** @internal */
|
|
285
|
+
_getDragOffset(event, el, parent) {
|
|
286
|
+
// in case ancestor has transform/perspective css properties that change the viewpoint
|
|
287
|
+
let xformOffsetX = 0;
|
|
288
|
+
let xformOffsetY = 0;
|
|
289
|
+
if (parent) {
|
|
290
|
+
const testEl = document.createElement('div');
|
|
291
|
+
Utils.addElStyles(testEl, {
|
|
292
|
+
opacity: '0',
|
|
293
|
+
position: 'fixed',
|
|
294
|
+
top: 0 + 'px',
|
|
295
|
+
left: 0 + 'px',
|
|
296
|
+
width: '1px',
|
|
297
|
+
height: '1px',
|
|
298
|
+
zIndex: '-999999',
|
|
299
|
+
});
|
|
300
|
+
parent.appendChild(testEl);
|
|
301
|
+
const testElPosition = testEl.getBoundingClientRect();
|
|
302
|
+
parent.removeChild(testEl);
|
|
303
|
+
xformOffsetX = testElPosition.left;
|
|
304
|
+
xformOffsetY = testElPosition.top;
|
|
305
|
+
// TODO: scale ?
|
|
306
|
+
}
|
|
307
|
+
const targetOffset = el.getBoundingClientRect();
|
|
308
|
+
return {
|
|
309
|
+
left: targetOffset.left,
|
|
310
|
+
top: targetOffset.top,
|
|
311
|
+
offsetLeft: -event.clientX + targetOffset.left - xformOffsetX,
|
|
312
|
+
offsetTop: -event.clientY + targetOffset.top - xformOffsetY,
|
|
313
|
+
width: targetOffset.width,
|
|
314
|
+
height: targetOffset.height
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/** @internal TODO: set to public as called by DDDroppable! */
|
|
318
|
+
ui() {
|
|
319
|
+
const containmentEl = this.el.parentElement;
|
|
320
|
+
const containmentRect = containmentEl.getBoundingClientRect();
|
|
321
|
+
const offset = this.helper.getBoundingClientRect();
|
|
322
|
+
return {
|
|
323
|
+
position: {
|
|
324
|
+
top: offset.top - containmentRect.top,
|
|
325
|
+
left: offset.left - containmentRect.left
|
|
326
|
+
}
|
|
327
|
+
/* not used by GridStack for now...
|
|
328
|
+
helper: [this.helper], //The object arr representing the helper that's being dragged.
|
|
329
|
+
offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
|
|
330
|
+
*/
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/** @internal properties we change during dragging, and restore back */
|
|
335
|
+
DDDraggable.originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top', 'minWidth', 'willChange'];
|
|
336
|
+
export { DDDraggable };
|
|
345
337
|
//# sourceMappingURL=dd-draggable.js.map
|