dragselect 2.4.4 → 2.5.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/CHANGELOG.md +10 -0
- package/README.md +84 -21
- package/dist/DragSelect.d.ts +26 -4
- package/dist/DragSelect.es6m.js +830 -782
- package/dist/DragSelect.js +830 -782
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/methods/addModificationObservers.d.ts +9 -1
- package/dist/methods/getAllParentNodes.d.ts +0 -43
- package/dist/methods/index.d.ts +1 -0
- package/dist/methods/isCollision.d.ts +1 -1
- package/dist/methods/subscriberAliases.d.ts +3 -1
- package/dist/modules/Area.d.ts +2 -12
- package/dist/modules/DropZone.d.ts +0 -43
- package/dist/modules/DropZones.d.ts +0 -46
- package/dist/modules/SelectableSet.d.ts +11 -0
- package/dist/modules/Selection.d.ts +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/types.d.ts +72 -2
- package/jest-puppeteer.config.js +1 -0
- package/package.json +5 -4
- package/src/DragSelect.js +29 -5
- package/src/methods/addModificationObservers.js +26 -5
- package/src/methods/canScroll.js +1 -1
- package/src/methods/getAllParentNodes.js +18 -0
- package/src/methods/handleElementPositionAttribute.js +1 -1
- package/src/methods/hydrateSettings.js +16 -0
- package/src/methods/index.js +1 -0
- package/src/methods/isCollision.js +24 -5
- package/src/methods/scrollElement.js +1 -1
- package/src/methods/subscriberAliases.js +16 -5
- package/src/methods/toArray.js +3 -2
- package/src/modules/Area.js +12 -44
- package/src/modules/DropZone.js +252 -0
- package/src/modules/DropZones.js +159 -0
- package/src/modules/SelectableSet.js +22 -0
- package/src/modules/Selection.js +9 -11
- package/src/modules/index.js +1 -0
- package/src/stores/SettingsStore.js +0 -1
- package/src/types.js +30 -2
package/dist/DragSelect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/***
|
|
2
2
|
|
|
3
|
-
~~~ Version 2.
|
|
3
|
+
~~~ Version 2.5.1 ~~~
|
|
4
4
|
|
|
5
5
|
******************************************
|
|
6
6
|
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
throw new TypeError("Cannot call a class as a function");
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
44
43
|
function _defineProperties(target, props) {
|
|
45
44
|
for (var i = 0; i < props.length; i++) {
|
|
46
45
|
var descriptor = props[i];
|
|
@@ -50,13 +49,11 @@
|
|
|
50
49
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
|
|
54
52
|
function _createClass(Constructor, protoProps, staticProps) {
|
|
55
53
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
56
54
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
57
55
|
return Constructor;
|
|
58
56
|
}
|
|
59
|
-
|
|
60
57
|
function _defineProperty(obj, key, value) {
|
|
61
58
|
if (key in obj) {
|
|
62
59
|
Object.defineProperty(obj, key, {
|
|
@@ -68,13 +65,10 @@
|
|
|
68
65
|
} else {
|
|
69
66
|
obj[key] = value;
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
return obj;
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
function ownKeys(object, enumerableOnly) {
|
|
76
71
|
var keys = Object.keys(object);
|
|
77
|
-
|
|
78
72
|
if (Object.getOwnPropertySymbols) {
|
|
79
73
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
80
74
|
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
@@ -82,14 +76,11 @@
|
|
|
82
76
|
});
|
|
83
77
|
keys.push.apply(keys, symbols);
|
|
84
78
|
}
|
|
85
|
-
|
|
86
79
|
return keys;
|
|
87
80
|
}
|
|
88
|
-
|
|
89
81
|
function _objectSpread2(target) {
|
|
90
82
|
for (var i = 1; i < arguments.length; i++) {
|
|
91
83
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
92
|
-
|
|
93
84
|
if (i % 2) {
|
|
94
85
|
ownKeys(Object(source), true).forEach(function (key) {
|
|
95
86
|
_defineProperty(target, key, source[key]);
|
|
@@ -102,15 +93,12 @@
|
|
|
102
93
|
});
|
|
103
94
|
}
|
|
104
95
|
}
|
|
105
|
-
|
|
106
96
|
return target;
|
|
107
97
|
}
|
|
108
|
-
|
|
109
98
|
function _inherits(subClass, superClass) {
|
|
110
99
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
111
100
|
throw new TypeError("Super expression must either be null or a function");
|
|
112
101
|
}
|
|
113
|
-
|
|
114
102
|
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
115
103
|
constructor: {
|
|
116
104
|
value: subClass,
|
|
@@ -120,28 +108,23 @@
|
|
|
120
108
|
});
|
|
121
109
|
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
122
110
|
}
|
|
123
|
-
|
|
124
111
|
function _getPrototypeOf(o) {
|
|
125
112
|
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
126
113
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
127
114
|
};
|
|
128
115
|
return _getPrototypeOf(o);
|
|
129
116
|
}
|
|
130
|
-
|
|
131
117
|
function _setPrototypeOf(o, p) {
|
|
132
118
|
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
133
119
|
o.__proto__ = p;
|
|
134
120
|
return o;
|
|
135
121
|
};
|
|
136
|
-
|
|
137
122
|
return _setPrototypeOf(o, p);
|
|
138
123
|
}
|
|
139
|
-
|
|
140
124
|
function _isNativeReflectConstruct() {
|
|
141
125
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
142
126
|
if (Reflect.construct.sham) return false;
|
|
143
127
|
if (typeof Proxy === "function") return true;
|
|
144
|
-
|
|
145
128
|
try {
|
|
146
129
|
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
|
147
130
|
return true;
|
|
@@ -149,7 +132,6 @@
|
|
|
149
132
|
return false;
|
|
150
133
|
}
|
|
151
134
|
}
|
|
152
|
-
|
|
153
135
|
function _construct(Parent, args, Class) {
|
|
154
136
|
if (_isNativeReflectConstruct()) {
|
|
155
137
|
_construct = Reflect.construct;
|
|
@@ -163,34 +145,25 @@
|
|
|
163
145
|
return instance;
|
|
164
146
|
};
|
|
165
147
|
}
|
|
166
|
-
|
|
167
148
|
return _construct.apply(null, arguments);
|
|
168
149
|
}
|
|
169
|
-
|
|
170
150
|
function _isNativeFunction(fn) {
|
|
171
151
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
172
152
|
}
|
|
173
|
-
|
|
174
153
|
function _wrapNativeSuper(Class) {
|
|
175
154
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
176
|
-
|
|
177
155
|
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
178
156
|
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
179
|
-
|
|
180
157
|
if (typeof Class !== "function") {
|
|
181
158
|
throw new TypeError("Super expression must either be null or a function");
|
|
182
159
|
}
|
|
183
|
-
|
|
184
160
|
if (typeof _cache !== "undefined") {
|
|
185
161
|
if (_cache.has(Class)) return _cache.get(Class);
|
|
186
|
-
|
|
187
162
|
_cache.set(Class, Wrapper);
|
|
188
163
|
}
|
|
189
|
-
|
|
190
164
|
function Wrapper() {
|
|
191
165
|
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
192
166
|
}
|
|
193
|
-
|
|
194
167
|
Wrapper.prototype = Object.create(Class.prototype, {
|
|
195
168
|
constructor: {
|
|
196
169
|
value: Wrapper,
|
|
@@ -201,106 +174,81 @@
|
|
|
201
174
|
});
|
|
202
175
|
return _setPrototypeOf(Wrapper, Class);
|
|
203
176
|
};
|
|
204
|
-
|
|
205
177
|
return _wrapNativeSuper(Class);
|
|
206
178
|
}
|
|
207
|
-
|
|
208
179
|
function _assertThisInitialized(self) {
|
|
209
180
|
if (self === void 0) {
|
|
210
181
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
211
182
|
}
|
|
212
|
-
|
|
213
183
|
return self;
|
|
214
184
|
}
|
|
215
|
-
|
|
216
185
|
function _possibleConstructorReturn(self, call) {
|
|
217
186
|
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
218
187
|
return call;
|
|
219
188
|
}
|
|
220
|
-
|
|
221
189
|
return _assertThisInitialized(self);
|
|
222
190
|
}
|
|
223
|
-
|
|
224
191
|
function _createSuper(Derived) {
|
|
225
192
|
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
226
|
-
|
|
227
193
|
return function _createSuperInternal() {
|
|
228
194
|
var Super = _getPrototypeOf(Derived),
|
|
229
|
-
|
|
230
|
-
|
|
195
|
+
result;
|
|
231
196
|
if (hasNativeReflectConstruct) {
|
|
232
197
|
var NewTarget = _getPrototypeOf(this).constructor;
|
|
233
|
-
|
|
234
198
|
result = Reflect.construct(Super, arguments, NewTarget);
|
|
235
199
|
} else {
|
|
236
200
|
result = Super.apply(this, arguments);
|
|
237
201
|
}
|
|
238
|
-
|
|
239
202
|
return _possibleConstructorReturn(this, result);
|
|
240
203
|
};
|
|
241
204
|
}
|
|
242
|
-
|
|
243
205
|
function _superPropBase(object, property) {
|
|
244
206
|
while (!Object.prototype.hasOwnProperty.call(object, property)) {
|
|
245
207
|
object = _getPrototypeOf(object);
|
|
246
208
|
if (object === null) break;
|
|
247
209
|
}
|
|
248
|
-
|
|
249
210
|
return object;
|
|
250
211
|
}
|
|
251
|
-
|
|
252
212
|
function _get(target, property, receiver) {
|
|
253
213
|
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
254
214
|
_get = Reflect.get;
|
|
255
215
|
} else {
|
|
256
216
|
_get = function _get(target, property, receiver) {
|
|
257
217
|
var base = _superPropBase(target, property);
|
|
258
|
-
|
|
259
218
|
if (!base) return;
|
|
260
219
|
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
261
|
-
|
|
262
220
|
if (desc.get) {
|
|
263
221
|
return desc.get.call(receiver);
|
|
264
222
|
}
|
|
265
|
-
|
|
266
223
|
return desc.value;
|
|
267
224
|
};
|
|
268
225
|
}
|
|
269
|
-
|
|
270
226
|
return _get(target, property, receiver || target);
|
|
271
227
|
}
|
|
272
|
-
|
|
273
228
|
function _slicedToArray(arr, i) {
|
|
274
229
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
275
230
|
}
|
|
276
|
-
|
|
277
231
|
function _toConsumableArray(arr) {
|
|
278
232
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
279
233
|
}
|
|
280
|
-
|
|
281
234
|
function _arrayWithoutHoles(arr) {
|
|
282
235
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
283
236
|
}
|
|
284
|
-
|
|
285
237
|
function _arrayWithHoles(arr) {
|
|
286
238
|
if (Array.isArray(arr)) return arr;
|
|
287
239
|
}
|
|
288
|
-
|
|
289
240
|
function _iterableToArray(iter) {
|
|
290
241
|
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
|
291
242
|
}
|
|
292
|
-
|
|
293
243
|
function _iterableToArrayLimit(arr, i) {
|
|
294
244
|
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
|
295
245
|
var _arr = [];
|
|
296
246
|
var _n = true;
|
|
297
247
|
var _d = false;
|
|
298
248
|
var _e = undefined;
|
|
299
|
-
|
|
300
249
|
try {
|
|
301
250
|
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
302
251
|
_arr.push(_s.value);
|
|
303
|
-
|
|
304
252
|
if (i && _arr.length === i) break;
|
|
305
253
|
}
|
|
306
254
|
} catch (err) {
|
|
@@ -313,10 +261,8 @@
|
|
|
313
261
|
if (_d) throw _e;
|
|
314
262
|
}
|
|
315
263
|
}
|
|
316
|
-
|
|
317
264
|
return _arr;
|
|
318
265
|
}
|
|
319
|
-
|
|
320
266
|
function _unsupportedIterableToArray(o, minLen) {
|
|
321
267
|
if (!o) return;
|
|
322
268
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -325,27 +271,73 @@
|
|
|
325
271
|
if (n === "Map" || n === "Set") return Array.from(o);
|
|
326
272
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
327
273
|
}
|
|
328
|
-
|
|
329
274
|
function _arrayLikeToArray(arr, len) {
|
|
330
275
|
if (len == null || len > arr.length) len = arr.length;
|
|
331
|
-
|
|
332
276
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
333
|
-
|
|
334
277
|
return arr2;
|
|
335
278
|
}
|
|
336
|
-
|
|
337
279
|
function _nonIterableSpread() {
|
|
338
280
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
339
281
|
}
|
|
340
|
-
|
|
341
282
|
function _nonIterableRest() {
|
|
342
283
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
343
284
|
}
|
|
285
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
286
|
+
var it;
|
|
287
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
288
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
289
|
+
if (it) o = it;
|
|
290
|
+
var i = 0;
|
|
291
|
+
var F = function () {};
|
|
292
|
+
return {
|
|
293
|
+
s: F,
|
|
294
|
+
n: function () {
|
|
295
|
+
if (i >= o.length) return {
|
|
296
|
+
done: true
|
|
297
|
+
};
|
|
298
|
+
return {
|
|
299
|
+
done: false,
|
|
300
|
+
value: o[i++]
|
|
301
|
+
};
|
|
302
|
+
},
|
|
303
|
+
e: function (e) {
|
|
304
|
+
throw e;
|
|
305
|
+
},
|
|
306
|
+
f: F
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
310
|
+
}
|
|
311
|
+
var normalCompletion = true,
|
|
312
|
+
didErr = false,
|
|
313
|
+
err;
|
|
314
|
+
return {
|
|
315
|
+
s: function () {
|
|
316
|
+
it = o[Symbol.iterator]();
|
|
317
|
+
},
|
|
318
|
+
n: function () {
|
|
319
|
+
var step = it.next();
|
|
320
|
+
normalCompletion = step.done;
|
|
321
|
+
return step;
|
|
322
|
+
},
|
|
323
|
+
e: function (e) {
|
|
324
|
+
didErr = true;
|
|
325
|
+
err = e;
|
|
326
|
+
},
|
|
327
|
+
f: function () {
|
|
328
|
+
try {
|
|
329
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
330
|
+
} finally {
|
|
331
|
+
if (didErr) throw err;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
344
336
|
|
|
345
337
|
/**
|
|
346
338
|
* The Settings to be passed to the Class
|
|
347
339
|
* @typedef {Object} Settings
|
|
348
|
-
* @property {HTMLElement|SVGElement|
|
|
340
|
+
* @property {HTMLElement|SVGElement|Document} [area=document] area in which you can drag. If not provided it will be the whole document
|
|
349
341
|
* @property {DSInputElements} [selectables=[]] the elements that can be selected
|
|
350
342
|
* @property {number} [autoScrollSpeed=5] Speed in which the area scrolls while selecting (if available). Unit is pixel per movement.
|
|
351
343
|
* @property {Vect2} [overflowTolerance={x:25,y:25}] Tolerance for autoScroll (how close one has to be near an edges for autoScroll to start)
|
|
@@ -355,18 +347,30 @@
|
|
|
355
347
|
* @property {boolean} [multiSelectToggling=true] Whether or not to toggle already active elements while multi-selecting
|
|
356
348
|
* @property {DSMultiSelectKeys} [multiSelectKeys=['Control', 'Shift', 'Meta']] Keys that allows switching to the multi-select mode (see the multiSelectMode option). Any key value is possible ([see MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)). Note that the best support is given for <kbd>Control</kbd>, <kbd>Shift</kbd> and <kbd>Meta</kbd>. Provide an empty array `[]` if you want to turn off the functionality.
|
|
357
349
|
* @property {HTMLElement} [selector=HTMLElement] the square that will draw the selection
|
|
350
|
+
* @property {number} [selectionThreshold=0] how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection)
|
|
358
351
|
* @property {boolean} [draggability=true] When a user is dragging on an already selected element, the selection is dragged.
|
|
359
352
|
* @property {boolean} [immediateDrag=true] Whether an element is draggable from the start or needs to be selected first
|
|
360
353
|
* @property {boolean} [keyboardDrag=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it)
|
|
361
354
|
* @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
|
|
362
355
|
* @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
|
|
363
356
|
* @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
357
|
+
* @property {number} [refreshMemoryRate=80] Refresh rate on memoization, higher numbers mean better performance but more lag if elements are moving, lower numbers mean less lag but worse performance. If none of your DOMNodes are moving, you can set it to a very high number to increase performance. Value in milliseconds.
|
|
358
|
+
* @property {DSInputDropZone[]} [dropZones=[]] one or more drop-elements: where the selectables can be dropped into
|
|
359
|
+
* @property {number} [dropInsideThreshold=1] how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside)
|
|
360
|
+
* @property {number} [dropTargetThreshold=0] how much % of the zone does the pointer has to be in to be considered a target (0 = anywhere in the zone, max: 0.5 = has to point at the center of the zone)
|
|
364
361
|
* @property {boolean} [usePointerEvents=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
|
|
365
362
|
* @property {string} [hoverClass=ds-hover] the class assigned to the mouse hovered items
|
|
366
363
|
* @property {string} [selectableClass=ds-selectable] the class assigned to the elements that can be selected
|
|
367
364
|
* @property {string} [selectedClass=ds-selected] the class assigned to the selected items
|
|
368
365
|
* @property {string} [selectorClass=ds-selector] the class assigned to the square selector helper
|
|
369
366
|
* @property {string} [selectorAreaClass=ds-selector-area] the class assigned to the square in which the selector resides. By default it's invisible
|
|
367
|
+
* @property {string} [droppedTargetClass=ds-dropped-target] on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id}
|
|
368
|
+
* @property {string} [droppedInsideClass=ds-dropped-inside] on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id}
|
|
369
|
+
* @property {string} [droppableClass=ds-droppable] on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id}
|
|
370
|
+
* @property {string} [dropZoneClass=ds-dropzone] on each dropZone
|
|
371
|
+
* @property {string} [dropZoneReadyClass=ds-dropzone-ready] on corresponding dropZone when element is dragged
|
|
372
|
+
* @property {string} [dropZoneTargetClass=ds-dropzone-target] on dropZone that has elements from any successful target drop
|
|
373
|
+
* @property {string} [dropZoneInsideClass=ds-dropzone-inside] on dropZone that has elements inside after any drop
|
|
370
374
|
*/
|
|
371
375
|
|
|
372
376
|
/**
|
|
@@ -381,46 +385,48 @@
|
|
|
381
385
|
* @property {Settings} [settings] the settings being updates/manipulated/passed, also holds the previous value. i.e. updating selectorClass will publish { settings: { selectorClass: 'newVal', 'selectorClass:pre': 'oldVal' } }
|
|
382
386
|
* @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} [scroll_directions]
|
|
383
387
|
* @property {number} [scroll_multiplier]
|
|
388
|
+
* @property {DSDropZone} [dropTarget] The dropZone element that the element was dropped into (or the mouse is currently hovering over)
|
|
384
389
|
*/
|
|
385
|
-
|
|
386
390
|
/**
|
|
387
391
|
* @typedef {function} DSCallback
|
|
388
392
|
* @param {CallbackObject} data
|
|
389
393
|
*/
|
|
390
394
|
|
|
391
|
-
/**
|
|
395
|
+
/**
|
|
396
|
+
* @typedef {Object} DSInputDropZone
|
|
397
|
+
* @property {string} id
|
|
398
|
+
* @property {DSElement} element
|
|
399
|
+
* @property {DSInputElements} droppables
|
|
400
|
+
*/
|
|
401
|
+
/**
|
|
402
|
+
* @typedef {Object} DSDropZone
|
|
403
|
+
* @property {string} id
|
|
404
|
+
* @property {DSElement} element
|
|
405
|
+
* @property {DSElements} droppables
|
|
406
|
+
* @property {DSElements} [itemsDropped] the items related to the target zone
|
|
407
|
+
* @property {DSElements} [itemsInside] the items that are within the targets bounds
|
|
408
|
+
*/
|
|
392
409
|
|
|
410
|
+
/** @typedef {{x: number, y: number}} Vect2 */
|
|
393
411
|
/** @typedef {{x:number,y:number,w:number,h:number,r:number,b:number}} DSElementPos */
|
|
394
|
-
|
|
395
412
|
/** @typedef {Array.<'top'|'bottom'|'left'|'right'|undefined>} DSEdges */
|
|
396
413
|
|
|
397
|
-
/** @typedef {HTMLElement|SVGElement|
|
|
398
|
-
|
|
414
|
+
/** @typedef {HTMLElement|SVGElement|Document} DSArea area within which you can drag */
|
|
399
415
|
/** @typedef {HTMLElement} DSSelectorArea area in which you can drag */
|
|
400
|
-
|
|
401
416
|
/** @typedef {Array.<HTMLElement|SVGElement> | HTMLElement | SVGElement} DSInputElements the elements that can be selected */
|
|
402
|
-
|
|
403
417
|
/** @typedef {Array.<HTMLElement|SVGElement>} DSElements the elements that can be selected */
|
|
404
|
-
|
|
405
418
|
/** @typedef {HTMLElement|SVGElement} DSElement a single element that can be selected */
|
|
406
|
-
|
|
407
419
|
/** @typedef {MouseEvent|TouchEvent|PointerEvent} DSEvent en event from a touch or mouse interaction */
|
|
408
|
-
|
|
409
420
|
/** @typedef {Array.<'Shift'|'Control'|'Meta'|string>} DSMultiSelectKeys An array of keys that allows switching to the multi-select mode */
|
|
410
421
|
|
|
411
422
|
/** @typedef {'dragmove'|'autoscroll'|'dragstart'|'elementselect'|'elementunselect'|'callback'} DSEventNames */
|
|
412
|
-
|
|
413
423
|
/** @typedef {'Interaction:init'|'Interaction:start'|'Interaction:end'|'Interaction:update'|'Area:modified'|'Area:scroll'|'PointerStore:updated'|'Selected:added'|'Selected:removed'|'Selectable:click'|'Selectable:added'|'Selectable:removed'|'Selectable:pointer'|'KeyStore:down'|'KeyStore:up'} DSInternalEventNames */
|
|
414
|
-
|
|
415
424
|
/** @typedef {'Interaction:init:pre'|'Interaction:start:pre'|'Interaction:end:pre'|'Interaction:update:pre'|'Area:modified:pre'|'Area:scroll:pre'|'PointerStore:updated:pre'|'Selected:added:pre'|'Selected:removed:pre'|'Selectable:click:pre'|'Selectable:added:pre'|'Selectable:removed:pre'|'Selectable:pointer:pre'|'KeyStore:down:pre'|'KeyStore:up:pre'} DSInternalEventNamesPre */
|
|
416
425
|
// @todo: update to typescript for complex defs like `Settings:updated:${string}` | `Settings:updated:${string}:pre`
|
|
417
|
-
|
|
418
426
|
/** @typedef {'Settings:updated'|'Settings:updated:pre'|'Settings:updated:*'|'Settings:updated:*:pre'} DSInternalSettingEvents */
|
|
419
|
-
|
|
420
427
|
/** @typedef {DSEventNames|DSInternalEventNames|DSInternalEventNamesPre|DSInternalSettingEvents} DSCallbackNames the name of the callback */
|
|
421
428
|
|
|
422
429
|
/** @typedef {{top:number,left:number,bottom:number,right:number,width:number,height:number}} DSBoundingRect */
|
|
423
|
-
|
|
424
430
|
/** @typedef {{up:string[],down:string[],left:string[],right:string[]}} DSDragKeys */
|
|
425
431
|
|
|
426
432
|
/**
|
|
@@ -429,18 +435,18 @@
|
|
|
429
435
|
*/
|
|
430
436
|
|
|
431
437
|
// @ts-check
|
|
438
|
+
|
|
432
439
|
/**
|
|
433
440
|
* @param {Vect2} v1
|
|
434
441
|
* @param {'+'|'-'|'*'|'/'} operator
|
|
435
442
|
* @param {Vect2} v2
|
|
436
443
|
* @return {Vect2}
|
|
437
444
|
*/
|
|
438
|
-
|
|
439
445
|
var calc = function calc(_ref, operator, _ref2) {
|
|
440
446
|
var x1 = _ref.x,
|
|
441
|
-
|
|
447
|
+
y1 = _ref.y;
|
|
442
448
|
var x2 = _ref2.x,
|
|
443
|
-
|
|
449
|
+
y2 = _ref2.y;
|
|
444
450
|
var calculations = {
|
|
445
451
|
'+': {
|
|
446
452
|
x: x1 + x2,
|
|
@@ -461,11 +467,11 @@
|
|
|
461
467
|
};
|
|
462
468
|
return calculations[operator];
|
|
463
469
|
};
|
|
470
|
+
|
|
464
471
|
/**
|
|
465
472
|
* @param {{left:number,top:number}} rect
|
|
466
473
|
* @returns {Vect2}
|
|
467
474
|
*/
|
|
468
|
-
|
|
469
475
|
var rect2vect = function rect2vect(rect) {
|
|
470
476
|
return {
|
|
471
477
|
x: rect.left,
|
|
@@ -477,7 +483,6 @@
|
|
|
477
483
|
* @param {number} dimension
|
|
478
484
|
* @returns {DSBoundingRect}
|
|
479
485
|
*/
|
|
480
|
-
|
|
481
486
|
var vect2rect = function vect2rect(vect) {
|
|
482
487
|
var dimension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
483
488
|
return {
|
|
@@ -493,7 +498,6 @@
|
|
|
493
498
|
* @param {number} n
|
|
494
499
|
* @returns {Vect2}
|
|
495
500
|
*/
|
|
496
|
-
|
|
497
501
|
var num2vect = function num2vect(n) {
|
|
498
502
|
return {
|
|
499
503
|
x: n,
|
|
@@ -502,48 +506,65 @@
|
|
|
502
506
|
};
|
|
503
507
|
|
|
504
508
|
// @ts-check
|
|
509
|
+
|
|
505
510
|
/**
|
|
506
|
-
*
|
|
507
|
-
* @
|
|
508
|
-
* @param {DSModificationCallback} callback
|
|
509
|
-
* @param {MutationObserver} modificationObserver
|
|
511
|
+
* Removes event-listeners from the DOMNode
|
|
512
|
+
* @typedef {()=>void} DSCleanup
|
|
510
513
|
*/
|
|
511
514
|
|
|
512
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Adds event-listeners to a DOMNode
|
|
517
|
+
* @param {DSArea[]} nodes
|
|
518
|
+
* @param {DSModificationCallback} cb
|
|
519
|
+
* @return {{observer:MutationObserver,callback:DSModificationCallback,cleanup:DSCleanup}}
|
|
520
|
+
*/
|
|
521
|
+
var addModificationObservers = (function (nodes, cb) {
|
|
522
|
+
var callback = cb;
|
|
513
523
|
window.addEventListener('resize', callback);
|
|
514
524
|
window.addEventListener('scroll', callback);
|
|
525
|
+
var observer = new MutationObserver(callback);
|
|
515
526
|
nodes.forEach(function (el, i) {
|
|
516
|
-
|
|
527
|
+
observer.observe(el, {
|
|
517
528
|
childList: i !== 0,
|
|
518
529
|
attributes: true
|
|
519
530
|
});
|
|
520
531
|
});
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Removes all observers
|
|
535
|
+
*/
|
|
536
|
+
var cleanup = function cleanup() {
|
|
537
|
+
return removeModificationObservers(observer, callback);
|
|
538
|
+
};
|
|
539
|
+
return {
|
|
540
|
+
observer: observer,
|
|
541
|
+
callback: callback,
|
|
542
|
+
cleanup: cleanup
|
|
543
|
+
};
|
|
521
544
|
});
|
|
522
545
|
|
|
523
546
|
// @ts-check
|
|
547
|
+
|
|
524
548
|
/**
|
|
525
549
|
* Checks whether the area can scroll or not
|
|
526
550
|
* @param {DSArea} area
|
|
527
551
|
* @return {boolean} scroll X/Y
|
|
528
552
|
*/
|
|
529
|
-
|
|
530
553
|
var canScroll = (function (area) {
|
|
531
554
|
var scroll = getCurrentScroll(area);
|
|
532
555
|
if (scroll.x || scroll.y) return true;
|
|
533
|
-
|
|
534
|
-
if (area instanceof HTMLDocument) {
|
|
556
|
+
if (area instanceof Document) {
|
|
535
557
|
if (area.body) return !!(area.body.scrollTop = 1);else return !!(area.documentElement.scrollTop = 1);
|
|
536
558
|
}
|
|
537
|
-
|
|
538
559
|
return !!(area.scrollTop = 1);
|
|
539
560
|
});
|
|
540
561
|
|
|
541
562
|
// @ts-check
|
|
563
|
+
|
|
542
564
|
/**
|
|
543
565
|
* Creates the SelectorArea
|
|
544
566
|
* @return {HTMLDivElement}
|
|
545
567
|
*/
|
|
546
|
-
|
|
547
568
|
var createSelectorAreaElement = (function () {
|
|
548
569
|
var node = document.createElement('div');
|
|
549
570
|
node.style.position = 'fixed';
|
|
@@ -554,16 +575,15 @@
|
|
|
554
575
|
});
|
|
555
576
|
|
|
556
577
|
// @ts-check
|
|
578
|
+
|
|
557
579
|
/**
|
|
558
580
|
* Create the selector node
|
|
559
581
|
* @param {boolean} customStyles
|
|
560
582
|
* @return {HTMLElement}
|
|
561
583
|
*/
|
|
562
|
-
|
|
563
584
|
var createSelectorElement = (function (customStyles) {
|
|
564
585
|
var selector = document.createElement('div');
|
|
565
586
|
selector.style.position = 'absolute';
|
|
566
|
-
|
|
567
587
|
if (!customStyles) {
|
|
568
588
|
selector.style.background = 'rgba(0, 0, 255, 0.1)';
|
|
569
589
|
selector.style.border = '1px solid rgba(0, 0, 255, 0.45)';
|
|
@@ -575,6 +595,7 @@
|
|
|
575
595
|
});
|
|
576
596
|
|
|
577
597
|
// @ts-check
|
|
598
|
+
|
|
578
599
|
/**
|
|
579
600
|
* Returns a function, that, as long as it continues to be invoked, will not
|
|
580
601
|
* be triggered. The function will be called after it stops being called for
|
|
@@ -583,32 +604,32 @@
|
|
|
583
604
|
* @param {number} wait
|
|
584
605
|
* @returns {DSModificationCallback}
|
|
585
606
|
*/
|
|
586
|
-
|
|
587
607
|
var debounce = (function (func, wait) {
|
|
588
|
-
var timeout;
|
|
589
|
-
// We spread (...args) to capture any number of parameters we want to pass
|
|
608
|
+
var timeout;
|
|
590
609
|
|
|
610
|
+
// This is the function that is returned and will be executed many times
|
|
611
|
+
// We spread (...args) to capture any number of parameters we want to pass
|
|
591
612
|
return function () {
|
|
592
613
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
593
614
|
args[_key] = arguments[_key];
|
|
594
615
|
}
|
|
595
|
-
|
|
596
616
|
// The callback function to be executed after
|
|
597
617
|
// the debounce time has elapsed
|
|
598
618
|
var later = function later() {
|
|
599
619
|
// null timeout to indicate the debounce ended
|
|
600
|
-
timeout = null;
|
|
620
|
+
timeout = null;
|
|
601
621
|
|
|
622
|
+
// Execute the callback
|
|
602
623
|
func.apply(void 0, args);
|
|
603
|
-
};
|
|
624
|
+
};
|
|
625
|
+
// This will reset the waiting every function execution.
|
|
604
626
|
// This is the step that prevents the function from
|
|
605
627
|
// being executed because it will never reach the
|
|
606
628
|
// inside of the previous setTimeout
|
|
629
|
+
clearTimeout(timeout);
|
|
607
630
|
|
|
608
|
-
|
|
609
|
-
clearTimeout(timeout); // Restart the debounce waiting period.
|
|
631
|
+
// Restart the debounce waiting period.
|
|
610
632
|
// setTimeout returns a truthy value (it differs in web vs Node)
|
|
611
|
-
|
|
612
633
|
timeout = setTimeout(later, wait);
|
|
613
634
|
};
|
|
614
635
|
});
|
|
@@ -616,13 +637,32 @@
|
|
|
616
637
|
// @ts-check
|
|
617
638
|
var documentScroll = (function () {
|
|
618
639
|
var _document$body, _document$documentEle, _document$body2, _document$documentEle2;
|
|
619
|
-
|
|
620
640
|
return {
|
|
621
641
|
y: ((_document$body = document.body) === null || _document$body === void 0 ? void 0 : _document$body.scrollTop) || ((_document$documentEle = document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.scrollTop) || 0,
|
|
622
642
|
x: ((_document$body2 = document.body) === null || _document$body2 === void 0 ? void 0 : _document$body2.scrollLeft) || ((_document$documentEle2 = document.documentElement) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.scrollLeft) || 0
|
|
623
643
|
};
|
|
624
644
|
});
|
|
625
645
|
|
|
646
|
+
/**
|
|
647
|
+
* @param {DSElement|DSArea} node
|
|
648
|
+
* @returns {DSElements}
|
|
649
|
+
*/
|
|
650
|
+
var getAllParentNodes = (function (node) {
|
|
651
|
+
var traverse = function traverse(toWatch) {
|
|
652
|
+
var _toWatch$index;
|
|
653
|
+
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
654
|
+
var parent = (_toWatch$index = toWatch[index]) === null || _toWatch$index === void 0 ? void 0 : _toWatch$index.parentNode;
|
|
655
|
+
if (parent) {
|
|
656
|
+
toWatch.push(parent);
|
|
657
|
+
index++;
|
|
658
|
+
return traverse(toWatch, index);
|
|
659
|
+
} else {
|
|
660
|
+
return toWatch;
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
return traverse([node]);
|
|
664
|
+
});
|
|
665
|
+
|
|
626
666
|
// @ts-check
|
|
627
667
|
/**
|
|
628
668
|
* Returns the top/left/bottom/right/width/height
|
|
@@ -632,7 +672,6 @@
|
|
|
632
672
|
* @param {number} zoom
|
|
633
673
|
* @returns {DSBoundingRect}
|
|
634
674
|
*/
|
|
635
|
-
|
|
636
675
|
var getAreaRect = (function (area, zoom) {
|
|
637
676
|
if (area instanceof Document) return {
|
|
638
677
|
top: 0,
|
|
@@ -654,11 +693,11 @@
|
|
|
654
693
|
});
|
|
655
694
|
|
|
656
695
|
// @ts-check
|
|
696
|
+
|
|
657
697
|
/**
|
|
658
698
|
* @param {DSArea} [area]
|
|
659
699
|
* @return {Vect2} scroll X/Y
|
|
660
700
|
*/
|
|
661
|
-
|
|
662
701
|
var getCurrentScroll = (function (area) {
|
|
663
702
|
if (!area || area instanceof Document) return documentScroll();
|
|
664
703
|
return {
|
|
@@ -668,6 +707,7 @@
|
|
|
668
707
|
});
|
|
669
708
|
|
|
670
709
|
// @ts-check
|
|
710
|
+
|
|
671
711
|
/**
|
|
672
712
|
* Returns the edges that an element is overflowing
|
|
673
713
|
* @param {Object} p
|
|
@@ -676,34 +716,31 @@
|
|
|
676
716
|
* @param {Vect2} [p.tolerance]
|
|
677
717
|
* @returns {DSEdges}
|
|
678
718
|
*/
|
|
679
|
-
|
|
680
719
|
var getOverflowEdges = (function (_ref) {
|
|
681
720
|
var elementRect = _ref.elementRect,
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
721
|
+
containerRect = _ref.containerRect,
|
|
722
|
+
_ref$tolerance = _ref.tolerance,
|
|
723
|
+
tolerance = _ref$tolerance === void 0 ? {
|
|
724
|
+
x: 0,
|
|
725
|
+
y: 0
|
|
726
|
+
} : _ref$tolerance;
|
|
688
727
|
var edges = [];
|
|
689
728
|
if (elementRect.top - tolerance.y < containerRect.top) edges.push('top');
|
|
690
729
|
if (elementRect.left - tolerance.x < containerRect.left) edges.push('left');
|
|
691
730
|
if (elementRect.bottom + tolerance.y > containerRect.bottom) edges.push('bottom');
|
|
692
731
|
if (elementRect.right + tolerance.y > containerRect.right) edges.push('right');
|
|
693
|
-
return (
|
|
694
|
-
/** @type {DSEdges} */
|
|
695
|
-
edges
|
|
732
|
+
return (/** @type {DSEdges} */edges
|
|
696
733
|
);
|
|
697
734
|
});
|
|
698
735
|
|
|
699
736
|
// @ts-check
|
|
737
|
+
|
|
700
738
|
/**
|
|
701
739
|
* Returns cursor x, y position based on event object
|
|
702
740
|
* @param {Object} p
|
|
703
741
|
* @param {MouseEvent|Touch|PointerEvent} p.event
|
|
704
742
|
* @return {Vect2} cursor X/Y position
|
|
705
743
|
*/
|
|
706
|
-
|
|
707
744
|
var getPointerPos = (function (_ref) {
|
|
708
745
|
var event = _ref.event;
|
|
709
746
|
return {
|
|
@@ -718,12 +755,10 @@
|
|
|
718
755
|
* @param {{ scrollAmount:Vect2, initialPointerPos:Vect2, pointerPos:Vect2 }} p
|
|
719
756
|
* @returns {{left:number,top:number,width:number,height:number}}
|
|
720
757
|
*/
|
|
721
|
-
|
|
722
758
|
var getSelectorPosition = (function (_ref) {
|
|
723
759
|
var scrollAmount = _ref.scrollAmount,
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
760
|
+
initialPointerPos = _ref.initialPointerPos,
|
|
761
|
+
pointerPos = _ref.pointerPos;
|
|
727
762
|
/** check for direction
|
|
728
763
|
*
|
|
729
764
|
* This is quite complicated, so also quite complicated to explain. Lemme’ try:
|
|
@@ -762,39 +797,38 @@
|
|
|
762
797
|
*
|
|
763
798
|
* I hope that makes sense. Try stuff out and play around with variables to get a hang of it.
|
|
764
799
|
*/
|
|
765
|
-
var selectorPos = {};
|
|
800
|
+
var selectorPos = {};
|
|
766
801
|
|
|
802
|
+
// right
|
|
767
803
|
if (pointerPos.x > initialPointerPos.x - scrollAmount.x) {
|
|
768
804
|
// 1.
|
|
769
805
|
selectorPos.left = initialPointerPos.x - scrollAmount.x; // 2.
|
|
770
|
-
|
|
771
806
|
selectorPos.width = pointerPos.x - initialPointerPos.x + scrollAmount.x; // 3.
|
|
772
807
|
// left
|
|
773
808
|
} else {
|
|
774
809
|
// 1b.
|
|
775
810
|
selectorPos.left = pointerPos.x; // 2b.
|
|
776
|
-
|
|
777
811
|
selectorPos.width = initialPointerPos.x - pointerPos.x - scrollAmount.x; // 3b.
|
|
778
|
-
}
|
|
779
|
-
|
|
812
|
+
}
|
|
780
813
|
|
|
814
|
+
// bottom
|
|
781
815
|
if (pointerPos.y > initialPointerPos.y - scrollAmount.y) {
|
|
782
816
|
selectorPos.top = initialPointerPos.y - scrollAmount.y;
|
|
783
|
-
selectorPos.height = pointerPos.y - initialPointerPos.y + scrollAmount.y;
|
|
817
|
+
selectorPos.height = pointerPos.y - initialPointerPos.y + scrollAmount.y;
|
|
818
|
+
// top
|
|
784
819
|
} else {
|
|
785
820
|
selectorPos.top = pointerPos.y;
|
|
786
821
|
selectorPos.height = initialPointerPos.y - pointerPos.y - scrollAmount.y;
|
|
787
822
|
}
|
|
788
|
-
|
|
789
823
|
return selectorPos;
|
|
790
824
|
});
|
|
791
825
|
|
|
792
826
|
// @ts-check
|
|
827
|
+
|
|
793
828
|
/**
|
|
794
829
|
* @param {DSElement} element
|
|
795
830
|
* @return {Vect2}
|
|
796
831
|
*/
|
|
797
|
-
|
|
798
832
|
var getComputedTranslatePositions = function getComputedTranslatePositions(element) {
|
|
799
833
|
var position = {
|
|
800
834
|
x: 0,
|
|
@@ -802,40 +836,31 @@
|
|
|
802
836
|
};
|
|
803
837
|
var computed = window.getComputedStyle(element);
|
|
804
838
|
if (!computed.transform || computed.transform === 'none') return position;
|
|
805
|
-
|
|
806
839
|
if (computed.transform.indexOf('3d') >= 0) {
|
|
807
840
|
var match = computed.transform.trim().match(/matrix3d\((.*?)\)/);
|
|
808
|
-
|
|
809
841
|
if (match && match.length) {
|
|
810
842
|
var _match$;
|
|
811
|
-
|
|
812
843
|
var values = (_match$ = match[1]) === null || _match$ === void 0 ? void 0 : _match$.split(',');
|
|
813
844
|
position.x = parseInt(values[12]) || 0;
|
|
814
845
|
position.y = parseInt(values[13]) || 0;
|
|
815
846
|
}
|
|
816
|
-
|
|
817
847
|
return position;
|
|
818
848
|
} else {
|
|
819
849
|
var _match = computed.transform.trim().match(/matrix\((.*?)\)/);
|
|
820
|
-
|
|
821
850
|
if (_match && _match.length) {
|
|
822
851
|
var _match$2;
|
|
823
|
-
|
|
824
852
|
var _values = (_match$2 = _match[1]) === null || _match$2 === void 0 ? void 0 : _match$2.split(',');
|
|
825
|
-
|
|
826
853
|
position.x = parseInt(_values[4]) || 0;
|
|
827
854
|
position.y = parseInt(_values[5]) || 0;
|
|
828
855
|
}
|
|
829
|
-
|
|
830
856
|
return position;
|
|
831
857
|
}
|
|
832
858
|
};
|
|
859
|
+
|
|
833
860
|
/**
|
|
834
861
|
* @param {DSElement} element
|
|
835
862
|
* @return {Vect2}
|
|
836
863
|
*/
|
|
837
|
-
|
|
838
|
-
|
|
839
864
|
var getTranslatedPositions = function getTranslatedPositions(element) {
|
|
840
865
|
var transform = element.style.transform;
|
|
841
866
|
if (!transform || transform.indexOf('translate') < 0) return getComputedTranslatePositions(element);
|
|
@@ -844,37 +869,32 @@
|
|
|
844
869
|
y: 0
|
|
845
870
|
};
|
|
846
871
|
var match = transform.trim().match(/translate[3dD]*?\(.*?\)/);
|
|
847
|
-
|
|
848
872
|
if (match) {
|
|
849
873
|
var _match$3;
|
|
850
|
-
|
|
851
874
|
var split = (_match$3 = match[0]) === null || _match$3 === void 0 ? void 0 : _match$3.split('(');
|
|
852
|
-
|
|
853
875
|
if (split) {
|
|
854
876
|
var _split$;
|
|
855
|
-
|
|
856
877
|
var values = (_split$ = split[1]) === null || _split$ === void 0 ? void 0 : _split$.split(',');
|
|
857
878
|
position.x = parseInt(values[0]) || 0;
|
|
858
879
|
position.y = parseInt(values[1]) || 0;
|
|
859
880
|
}
|
|
860
881
|
}
|
|
861
|
-
|
|
862
882
|
if (!position.x && !position.x) return getComputedTranslatePositions(element);
|
|
863
883
|
return position;
|
|
864
884
|
};
|
|
885
|
+
|
|
865
886
|
/**
|
|
866
887
|
* @param {DSElement} element
|
|
867
888
|
* @return {Vect2}
|
|
868
889
|
*/
|
|
869
|
-
|
|
870
|
-
|
|
871
890
|
var getTopLeftPosition = function getTopLeftPosition(element) {
|
|
872
891
|
var style = element.style;
|
|
873
892
|
var position = {
|
|
874
893
|
x: parseInt(style.left) || 0,
|
|
875
894
|
y: parseInt(style.top) || 0
|
|
876
|
-
};
|
|
895
|
+
};
|
|
877
896
|
|
|
897
|
+
// initial positions
|
|
878
898
|
if (!position.x && !position.x) {
|
|
879
899
|
var computed = window.getComputedStyle(element);
|
|
880
900
|
return {
|
|
@@ -882,9 +902,9 @@
|
|
|
882
902
|
y: parseInt(computed.top) || 0
|
|
883
903
|
};
|
|
884
904
|
}
|
|
885
|
-
|
|
886
905
|
return position;
|
|
887
906
|
};
|
|
907
|
+
|
|
888
908
|
/**
|
|
889
909
|
* Returns the X and Y coordinates based on styles
|
|
890
910
|
* Can handle translate and top/left
|
|
@@ -892,13 +912,12 @@
|
|
|
892
912
|
* @param {boolean} [useTranslate]
|
|
893
913
|
* @return {Vect2}
|
|
894
914
|
*/
|
|
895
|
-
|
|
896
|
-
|
|
897
915
|
var getStylePosition = (function (element, useTranslate) {
|
|
898
916
|
if (useTranslate) return getTranslatedPositions(element);else return getTopLeftPosition(element);
|
|
899
917
|
});
|
|
900
918
|
|
|
901
919
|
// @ts-check
|
|
920
|
+
|
|
902
921
|
/**
|
|
903
922
|
* pushes element back the overflow amount
|
|
904
923
|
* (top - top gives overflow, then new position pushed back by overflow)
|
|
@@ -910,36 +929,31 @@
|
|
|
910
929
|
* @param {Vect2} p.elementPos
|
|
911
930
|
* @param {boolean} p.useTransform
|
|
912
931
|
*/
|
|
913
|
-
|
|
914
932
|
var handleElementOverflow = (function (_ref) {
|
|
915
933
|
var element = _ref.element,
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
934
|
+
edges = _ref.edges,
|
|
935
|
+
elementRect = _ref.elementRect,
|
|
936
|
+
containerRect = _ref.containerRect,
|
|
937
|
+
elementPos = _ref.elementPos,
|
|
938
|
+
useTransform = _ref.useTransform;
|
|
922
939
|
if (edges.includes('top')) {
|
|
923
940
|
setStylePosition(element, {
|
|
924
941
|
y: elementPos.y + containerRect.top - elementRect.top,
|
|
925
942
|
x: elementPos.x
|
|
926
943
|
}, useTransform);
|
|
927
944
|
}
|
|
928
|
-
|
|
929
945
|
if (edges.includes('left')) {
|
|
930
946
|
setStylePosition(element, {
|
|
931
947
|
y: elementPos.y,
|
|
932
948
|
x: elementPos.x + containerRect.left - elementRect.left
|
|
933
949
|
}, useTransform);
|
|
934
950
|
}
|
|
935
|
-
|
|
936
951
|
if (edges.includes('bottom')) {
|
|
937
952
|
setStylePosition(element, {
|
|
938
953
|
y: elementPos.y + containerRect.bottom - elementRect.bottom,
|
|
939
954
|
x: elementPos.x
|
|
940
955
|
}, useTransform);
|
|
941
956
|
}
|
|
942
|
-
|
|
943
957
|
if (edges.includes('right')) {
|
|
944
958
|
setStylePosition(element, {
|
|
945
959
|
y: elementPos.y,
|
|
@@ -949,28 +963,28 @@
|
|
|
949
963
|
});
|
|
950
964
|
|
|
951
965
|
// @ts-check
|
|
966
|
+
|
|
952
967
|
/**
|
|
953
968
|
* Fix: some elements have to have a special position attribute for calculations
|
|
954
969
|
* @param {Object} p
|
|
955
970
|
* @param {CSSStyleDeclaration} p.computedStyle
|
|
956
971
|
* @param {DSArea} p.node
|
|
957
972
|
*/
|
|
958
|
-
|
|
959
973
|
var handleElementPositionAttribute = (function (_ref) {
|
|
960
974
|
var computedStyle = _ref.computedStyle,
|
|
961
|
-
|
|
975
|
+
node = _ref.node;
|
|
962
976
|
var position = computedStyle.position;
|
|
963
977
|
var isPositioned = position === 'absolute' || position === 'relative' || position === 'fixed';
|
|
964
|
-
if (!(node instanceof
|
|
978
|
+
if (!(node instanceof Document) && !isPositioned) node.style.position = 'relative';
|
|
965
979
|
});
|
|
966
980
|
|
|
967
981
|
// @ts-check
|
|
982
|
+
|
|
968
983
|
/**
|
|
969
984
|
* @typedef {function} ScrollCallback
|
|
970
985
|
* @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} directions
|
|
971
986
|
* @property {number} multiplier
|
|
972
987
|
*/
|
|
973
|
-
|
|
974
988
|
/**
|
|
975
989
|
* @param {Object} p
|
|
976
990
|
* @param {string} p.key the keyboard key that was pressed
|
|
@@ -983,46 +997,41 @@
|
|
|
983
997
|
* @param {DSDragKeys} p.dragKeys
|
|
984
998
|
* @returns {Vect2}
|
|
985
999
|
*/
|
|
986
|
-
|
|
987
1000
|
var handleKeyboardDragPosDifference = (function (_ref) {
|
|
988
1001
|
var shiftKey = _ref.shiftKey,
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1002
|
+
keyboardDragSpeed = _ref.keyboardDragSpeed,
|
|
1003
|
+
zoom = _ref.zoom,
|
|
1004
|
+
key = _ref.key,
|
|
1005
|
+
dragKeys = _ref.dragKeys,
|
|
1006
|
+
scrollDiff = _ref.scrollDiff,
|
|
1007
|
+
canScroll = _ref.canScroll,
|
|
1008
|
+
scrollCallback = _ref.scrollCallback;
|
|
996
1009
|
var posDirection = {
|
|
997
1010
|
x: 0,
|
|
998
1011
|
y: 0
|
|
999
1012
|
};
|
|
1000
1013
|
var increase = shiftKey ? keyboardDragSpeed * 4 * zoom : keyboardDragSpeed * zoom;
|
|
1001
|
-
|
|
1002
1014
|
if (dragKeys.left.includes(key)) {
|
|
1003
1015
|
posDirection.x = scrollDiff.x || -increase;
|
|
1004
1016
|
if (!shiftKey && !scrollDiff.x && canScroll) scrollCallback(['left'], keyboardDragSpeed);
|
|
1005
1017
|
}
|
|
1006
|
-
|
|
1007
1018
|
if (dragKeys.right.includes(key)) {
|
|
1008
1019
|
posDirection.x = scrollDiff.x || increase;
|
|
1009
1020
|
if (!shiftKey && !scrollDiff.x && canScroll) scrollCallback(['right'], keyboardDragSpeed);
|
|
1010
1021
|
}
|
|
1011
|
-
|
|
1012
1022
|
if (dragKeys.up.includes(key)) {
|
|
1013
1023
|
posDirection.y = scrollDiff.y || -increase;
|
|
1014
1024
|
if (!shiftKey && !scrollDiff.y && canScroll) scrollCallback(['top'], keyboardDragSpeed);
|
|
1015
1025
|
}
|
|
1016
|
-
|
|
1017
1026
|
if (dragKeys.down.includes(key)) {
|
|
1018
1027
|
posDirection.y = scrollDiff.y || increase;
|
|
1019
1028
|
if (!shiftKey && !scrollDiff.y && canScroll) scrollCallback(['bottom'], keyboardDragSpeed);
|
|
1020
1029
|
}
|
|
1021
|
-
|
|
1022
1030
|
return posDirection;
|
|
1023
1031
|
});
|
|
1024
1032
|
|
|
1025
1033
|
// @ts-check
|
|
1034
|
+
|
|
1026
1035
|
/**
|
|
1027
1036
|
* Logic when an element is selected
|
|
1028
1037
|
* @param {Object} p
|
|
@@ -1032,19 +1041,19 @@
|
|
|
1032
1041
|
* @param {Set} p.SelectedSet
|
|
1033
1042
|
* @param {string} p.hoverClassName
|
|
1034
1043
|
*/
|
|
1035
|
-
|
|
1036
1044
|
var handleSelection = (function (_ref) {
|
|
1037
1045
|
var element = _ref.element,
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1046
|
+
force = _ref.force,
|
|
1047
|
+
multiSelectionToggle = _ref.multiSelectionToggle,
|
|
1048
|
+
SelectedSet = _ref.SelectedSet,
|
|
1049
|
+
hoverClassName = _ref.hoverClassName;
|
|
1042
1050
|
if (element.classList.contains(hoverClassName) && !force) return;
|
|
1043
1051
|
if (!SelectedSet.has(element)) SelectedSet.add(element);else if (multiSelectionToggle) SelectedSet["delete"](element);
|
|
1044
1052
|
element.classList.add(hoverClassName);
|
|
1045
1053
|
});
|
|
1046
1054
|
|
|
1047
1055
|
// @ts-check
|
|
1056
|
+
|
|
1048
1057
|
/**
|
|
1049
1058
|
* Logic when an element is de-selected
|
|
1050
1059
|
* @param {Object} p
|
|
@@ -1054,16 +1063,16 @@
|
|
|
1054
1063
|
* @param {Set} p.PrevSelectedSet
|
|
1055
1064
|
* @param {string} p.hoverClassName
|
|
1056
1065
|
*/
|
|
1057
|
-
|
|
1058
1066
|
var handleUnSelection = (function (_ref) {
|
|
1059
1067
|
var element = _ref.element,
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1068
|
+
force = _ref.force,
|
|
1069
|
+
SelectedSet = _ref.SelectedSet,
|
|
1070
|
+
PrevSelectedSet = _ref.PrevSelectedSet,
|
|
1071
|
+
hoverClassName = _ref.hoverClassName;
|
|
1064
1072
|
if (!element.classList.contains(hoverClassName) && !force) return false;
|
|
1065
1073
|
var inSelection = SelectedSet.has(element);
|
|
1066
1074
|
var inPrevSelection = PrevSelectedSet.has(element);
|
|
1075
|
+
|
|
1067
1076
|
/**
|
|
1068
1077
|
* Special for issue #9.
|
|
1069
1078
|
* if a multi-select-key is pressed, ds 'remembers' the last selection and reverts
|
|
@@ -1071,7 +1080,6 @@
|
|
|
1071
1080
|
* = if item was selected and is not in selection anymore, reselect it
|
|
1072
1081
|
* = if item was not selected and is not in selection anymore, unselect it
|
|
1073
1082
|
*/
|
|
1074
|
-
|
|
1075
1083
|
if (inSelection && !inPrevSelection) SelectedSet["delete"](element);else if (!inSelection && inPrevSelection) SelectedSet.add(element);
|
|
1076
1084
|
element.classList.remove(hoverClassName);
|
|
1077
1085
|
});
|
|
@@ -1085,6 +1093,7 @@
|
|
|
1085
1093
|
var wrongTypeWarn = function wrongTypeWarn(key, type, fallback) {
|
|
1086
1094
|
return console.warn("[DragSelect] TypeIssue: setting \"".concat(key, "\" is not of type \"").concat(type, "\"."));
|
|
1087
1095
|
};
|
|
1096
|
+
|
|
1088
1097
|
/**
|
|
1089
1098
|
* @param {string} key
|
|
1090
1099
|
* @param {*} value
|
|
@@ -1092,67 +1101,67 @@
|
|
|
1092
1101
|
* @param {*} fallback
|
|
1093
1102
|
* @returns {object}
|
|
1094
1103
|
*/
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
1104
|
var hydrateHelper = function hydrateHelper(key, value, withFallback, fallback) {
|
|
1098
1105
|
// no value available
|
|
1099
|
-
if (value === undefined) return withFallback ? _defineProperty({}, key, fallback) : {};
|
|
1100
|
-
|
|
1101
|
-
if (value === null) return _defineProperty({}, key, null);
|
|
1106
|
+
if (value === undefined) return withFallback ? _defineProperty({}, key, fallback) : {};
|
|
1107
|
+
// force unsetting of a value
|
|
1108
|
+
if (value === null) return _defineProperty({}, key, null);
|
|
1102
1109
|
|
|
1110
|
+
// TypeCheck [GENERIC]
|
|
1103
1111
|
var isAvailable = true; // if it’s not undefined, it was set voluntarily
|
|
1112
|
+
var forceFallback = false;
|
|
1104
1113
|
|
|
1105
|
-
|
|
1106
|
-
|
|
1114
|
+
// TypeCheck [String]
|
|
1107
1115
|
var expectedString = typeof fallback === 'string';
|
|
1108
1116
|
if (expectedString) isAvailable = typeof value === 'string' || value instanceof String;
|
|
1109
|
-
|
|
1110
1117
|
if (expectedString && !isAvailable) {
|
|
1111
1118
|
forceFallback = true;
|
|
1112
1119
|
wrongTypeWarn(key, 'string');
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1120
|
+
}
|
|
1115
1121
|
|
|
1122
|
+
// TypeCheck [Number]
|
|
1116
1123
|
var expectedNumber = !isNaN(fallback) && typeof fallback === 'number';
|
|
1117
1124
|
if (expectedNumber) isAvailable = !isNaN(value) && typeof value === 'number';
|
|
1118
|
-
|
|
1119
1125
|
if (expectedNumber && !isAvailable) {
|
|
1120
1126
|
forceFallback = true;
|
|
1121
1127
|
wrongTypeWarn(key, 'number');
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1128
|
+
}
|
|
1124
1129
|
|
|
1130
|
+
// TypeCheck [Object]
|
|
1125
1131
|
var expectedObject = Object.prototype.toString.call(fallback) === "[object Object]";
|
|
1126
1132
|
if (expectedObject) isAvailable = Object.prototype.toString.call(value) === "[object Object]";
|
|
1127
|
-
|
|
1128
1133
|
if (expectedObject && !isAvailable) {
|
|
1129
1134
|
forceFallback = true;
|
|
1130
1135
|
wrongTypeWarn(key, 'object');
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1136
|
+
}
|
|
1133
1137
|
|
|
1138
|
+
// TypeCheck [Boolean]
|
|
1134
1139
|
var expectedBoolean = typeof fallback === "boolean";
|
|
1135
1140
|
if (expectedBoolean) isAvailable = typeof value === "boolean";
|
|
1136
|
-
|
|
1137
1141
|
if (expectedBoolean && !isAvailable) {
|
|
1138
1142
|
forceFallback = true;
|
|
1139
1143
|
wrongTypeWarn(key, 'boolean');
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1144
|
+
}
|
|
1142
1145
|
|
|
1146
|
+
// TypeCheck [Array]
|
|
1143
1147
|
var expectedArray = Array.isArray(fallback);
|
|
1144
1148
|
if (expectedArray) isAvailable = Array.isArray(value);
|
|
1145
|
-
|
|
1146
1149
|
if (expectedArray && !isAvailable) {
|
|
1147
1150
|
forceFallback = true;
|
|
1148
1151
|
wrongTypeWarn(key, 'array');
|
|
1149
1152
|
}
|
|
1153
|
+
var isFallback = forceFallback || withFallback;
|
|
1150
1154
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1155
|
+
// Special rule for [dragKeys]
|
|
1153
1156
|
if (key === 'dragKeys' && isAvailable) return _defineProperty({}, key, Object.assign(fallback, value));else if (key === 'dragKeys' && !isAvailable) return isFallback ? _defineProperty({}, key, fallback) : {};
|
|
1157
|
+
|
|
1158
|
+
// Special rule for [dropZones]
|
|
1159
|
+
if (key === 'dropZones' && isAvailable && new Set(value.map(function (v) {
|
|
1160
|
+
return v.id;
|
|
1161
|
+
})).size !== value.length) console.warn("[DragSelect] UniqueConstraintsIssue: setting \"dropZones\" contains duplicate ids.");
|
|
1154
1162
|
return isAvailable ? _defineProperty({}, key, value) : isFallback ? _defineProperty({}, key, fallback) : {};
|
|
1155
1163
|
};
|
|
1164
|
+
|
|
1156
1165
|
/**
|
|
1157
1166
|
* This helper method creates the setting object,
|
|
1158
1167
|
* - if the settings provided are of wrong type, the fallback value will be used
|
|
@@ -1163,18 +1172,16 @@
|
|
|
1163
1172
|
* @param {Settings} settings
|
|
1164
1173
|
* @param {boolean} withFallback
|
|
1165
1174
|
*/
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
1175
|
var hydrateSettings = (function (settings, withFallback) {
|
|
1169
|
-
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
|
|
1176
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
|
|
1170
1177
|
x: 25,
|
|
1171
1178
|
y: 25
|
|
1172
|
-
})), hydrateHelper('zoom', settings.zoom, withFallback, 1)), hydrateHelper('customStyles', settings.customStyles, withFallback, false)), hydrateHelper('multiSelectMode', settings.multiSelectMode, withFallback, false)), hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true)), hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta'])), hydrateHelper('selector', settings.selector, withFallback, null)), hydrateHelper('draggability', settings.draggability, withFallback, true)), hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true)), hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true)), hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
|
|
1179
|
+
})), hydrateHelper('zoom', settings.zoom, withFallback, 1)), hydrateHelper('customStyles', settings.customStyles, withFallback, false)), hydrateHelper('multiSelectMode', settings.multiSelectMode, withFallback, false)), hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true)), hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta'])), hydrateHelper('selector', settings.selector, withFallback, null)), hydrateHelper('selectionThreshold', settings.selectionThreshold, withFallback, 0)), hydrateHelper('draggability', settings.draggability, withFallback, true)), hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true)), hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true)), hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
|
|
1173
1180
|
up: ['ArrowUp'],
|
|
1174
1181
|
down: ['ArrowDown'],
|
|
1175
1182
|
left: ['ArrowLeft'],
|
|
1176
1183
|
right: ['ArrowRight']
|
|
1177
|
-
})), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('usePointerEvents', settings.usePointerEvents, withFallback, false)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'));
|
|
1184
|
+
})), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('refreshMemoryRate', settings.refreshMemoryRate, withFallback, 80)), hydrateHelper('dropZones', settings.dropZones, withFallback, [])), hydrateHelper('dropInsideThreshold', settings.dropInsideThreshold, withFallback, 1)), hydrateHelper('dropTargetThreshold', settings.dropTargetThreshold, withFallback, 0)), hydrateHelper('usePointerEvents', settings.usePointerEvents, withFallback, false)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area')), hydrateHelper('droppedTargetClass', settings.droppedTargetClass, withFallback, 'ds-dropped-target')), hydrateHelper('droppedInsideClass', settings.droppedInsideClass, withFallback, 'ds-dropped-inside')), hydrateHelper('droppableClass', settings.droppableClass, withFallback, 'ds-droppable')), hydrateHelper('dropZoneClass', settings.dropZoneClass, withFallback, 'ds-dropzone')), hydrateHelper('dropZoneReadyClass', settings.dropZoneReadyClass, withFallback, 'ds-dropzone-ready')), hydrateHelper('dropZoneTargetClass', settings.dropZoneTargetClass, withFallback, 'ds-dropzone-target')), hydrateHelper('dropZoneInsideClass', settings.dropZoneInsideClass, withFallback, 'ds-dropzone-inside'));
|
|
1178
1185
|
});
|
|
1179
1186
|
|
|
1180
1187
|
// @ts-check
|
|
@@ -1199,19 +1206,41 @@
|
|
|
1199
1206
|
* {@link https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection MDN}
|
|
1200
1207
|
* @param {{left:number,right:number,top:number,bottom:number}} el1
|
|
1201
1208
|
* @param {{left:number,right:number,top:number,bottom:number}} el2
|
|
1209
|
+
* @param {number} [percent=0]
|
|
1210
|
+
* 1 = the element has to be completely inside the other element
|
|
1211
|
+
* 0.8 = the element has to be 80% inside the other element
|
|
1212
|
+
* 0.5 = the element has to be 50% inside the other element
|
|
1213
|
+
* 0.2 = the element has to be 20% inside the other element
|
|
1214
|
+
* 0 = the element only has to touch the other element
|
|
1202
1215
|
* @returns {boolean}
|
|
1203
1216
|
*/
|
|
1204
|
-
|
|
1205
1217
|
var isCollision = (function (el1, el2) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1218
|
+
var percent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
1219
|
+
var element1 = el1;
|
|
1220
|
+
if (percent > 0) {
|
|
1221
|
+
var widthPoint = (el1.right - el1.left) * percent;
|
|
1222
|
+
var heightPoint = (el1.bottom - el1.top) * percent;
|
|
1223
|
+
element1 = {
|
|
1224
|
+
left: el1.left + widthPoint,
|
|
1225
|
+
right: el1.right - widthPoint,
|
|
1226
|
+
top: el1.top + heightPoint,
|
|
1227
|
+
bottom: el1.bottom - heightPoint
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
if (element1.left < el2.right &&
|
|
1231
|
+
// 1.
|
|
1232
|
+
element1.right > el2.left &&
|
|
1233
|
+
// 2.
|
|
1234
|
+
element1.top < el2.bottom &&
|
|
1235
|
+
// 3.
|
|
1236
|
+
element1.bottom > el2.top // 4.
|
|
1237
|
+
) return true;
|
|
1238
|
+
// collision detected!
|
|
1211
1239
|
else return false;
|
|
1212
1240
|
});
|
|
1213
1241
|
|
|
1214
1242
|
// @ts-check
|
|
1243
|
+
|
|
1215
1244
|
/**
|
|
1216
1245
|
* Moves the element in a posDirection
|
|
1217
1246
|
* @param {Object} p
|
|
@@ -1220,12 +1249,11 @@
|
|
|
1220
1249
|
* @param {DSBoundingRect} p.containerRect
|
|
1221
1250
|
* @param {boolean} p.useTransform
|
|
1222
1251
|
*/
|
|
1223
|
-
|
|
1224
1252
|
var moveElement = (function (_ref) {
|
|
1225
1253
|
var element = _ref.element,
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1254
|
+
posDirection = _ref.posDirection,
|
|
1255
|
+
containerRect = _ref.containerRect,
|
|
1256
|
+
useTransform = _ref.useTransform;
|
|
1229
1257
|
var elementPos = getStylePosition(element, useTransform);
|
|
1230
1258
|
var newPos = calc(elementPos, '+', posDirection);
|
|
1231
1259
|
setStylePosition(element, newPos, useTransform);
|
|
@@ -1245,12 +1273,12 @@
|
|
|
1245
1273
|
});
|
|
1246
1274
|
|
|
1247
1275
|
// @ts-check
|
|
1276
|
+
|
|
1248
1277
|
/**
|
|
1249
1278
|
* Removes event-listeners to the selectorArea
|
|
1250
1279
|
* @param {MutationObserver} modificationObserver
|
|
1251
1280
|
* @param {DSModificationCallback} callback
|
|
1252
1281
|
*/
|
|
1253
|
-
|
|
1254
1282
|
var removeModificationObservers = (function (modificationObserver, callback) {
|
|
1255
1283
|
window.removeEventListener('resize', callback);
|
|
1256
1284
|
window.removeEventListener('scroll', callback);
|
|
@@ -1258,27 +1286,21 @@
|
|
|
1258
1286
|
});
|
|
1259
1287
|
|
|
1260
1288
|
// @ts-check
|
|
1289
|
+
|
|
1261
1290
|
/**
|
|
1262
1291
|
* Scroll the element in the specified direction
|
|
1263
1292
|
* @param {DSArea} element
|
|
1264
1293
|
* @param {Array.<'top'|'bottom'|'left'|'right'|undefined>} directions
|
|
1265
1294
|
* @param {number} multiplier
|
|
1266
1295
|
*/
|
|
1267
|
-
|
|
1268
1296
|
var scrollElement = (function (element, directions, multiplier) {
|
|
1269
1297
|
if (!directions.length) return;
|
|
1270
1298
|
var docEl = document && document.documentElement && document.documentElement.scrollTop && document.documentElement;
|
|
1271
|
-
|
|
1272
|
-
var _element = element instanceof HTMLDocument ? docEl || document.body : element;
|
|
1273
|
-
|
|
1299
|
+
var _element = element instanceof Document ? docEl || document.body : element;
|
|
1274
1300
|
var scrollTop = directions.includes('top') && _element.scrollTop > 0;
|
|
1275
|
-
|
|
1276
1301
|
var scrollBot = directions.includes('bottom') && _element.scrollTop < _element.scrollHeight;
|
|
1277
|
-
|
|
1278
1302
|
var scrollLeft = directions.includes('left') && _element.scrollLeft > 0;
|
|
1279
|
-
|
|
1280
1303
|
var scrollRight = directions.includes('right') && _element.scrollLeft < _element.scrollWidth;
|
|
1281
|
-
|
|
1282
1304
|
if (scrollTop) _element.scrollTop -= 1 * multiplier;
|
|
1283
1305
|
if (scrollBot) _element.scrollTop += 1 * multiplier;
|
|
1284
1306
|
if (scrollLeft) _element.scrollLeft -= 1 * multiplier;
|
|
@@ -1286,6 +1308,7 @@
|
|
|
1286
1308
|
});
|
|
1287
1309
|
|
|
1288
1310
|
// @ts-check
|
|
1311
|
+
|
|
1289
1312
|
/**
|
|
1290
1313
|
* Sets the style position to the X and Y coordinates
|
|
1291
1314
|
* Can handle translate and top/left
|
|
@@ -1294,7 +1317,6 @@
|
|
|
1294
1317
|
* @param {boolean} [useTranslate]
|
|
1295
1318
|
* @return {DSElement}
|
|
1296
1319
|
*/
|
|
1297
|
-
|
|
1298
1320
|
var setStylePosition = (function (element, values, useTranslate) {
|
|
1299
1321
|
if (useTranslate) {
|
|
1300
1322
|
var prevTransform = element.style.transform;
|
|
@@ -1303,7 +1325,6 @@
|
|
|
1303
1325
|
element.style.left = "".concat(values.x, "px");
|
|
1304
1326
|
element.style.top = "".concat(values.y, "px");
|
|
1305
1327
|
}
|
|
1306
|
-
|
|
1307
1328
|
return element;
|
|
1308
1329
|
});
|
|
1309
1330
|
|
|
@@ -1313,7 +1334,6 @@
|
|
|
1313
1334
|
* @param {DSCallback} callback
|
|
1314
1335
|
* @returns {number} event id, can be used to unsubscribe more efficiently
|
|
1315
1336
|
*/
|
|
1316
|
-
|
|
1317
1337
|
/**
|
|
1318
1338
|
* @typedef {function} DSPublish
|
|
1319
1339
|
* @param {DSCallbackNames} eventName
|
|
@@ -1328,13 +1348,14 @@
|
|
|
1328
1348
|
* @param {DSPublish} p.publish
|
|
1329
1349
|
* @param {Interaction} p.Interaction
|
|
1330
1350
|
* @param {SelectedSet} p.SelectedSet
|
|
1351
|
+
* @param {DropZones} p.DropZones
|
|
1331
1352
|
*/
|
|
1332
|
-
|
|
1333
1353
|
var subscriberAliases = (function (_ref) {
|
|
1334
1354
|
var subscribe = _ref.subscribe,
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1355
|
+
publish = _ref.publish,
|
|
1356
|
+
Interaction = _ref.Interaction,
|
|
1357
|
+
SelectedSet = _ref.SelectedSet,
|
|
1358
|
+
DropZones = _ref.DropZones;
|
|
1338
1359
|
var mapping = {
|
|
1339
1360
|
'Selected:added': [{
|
|
1340
1361
|
name: 'elementselect'
|
|
@@ -1350,61 +1371,66 @@
|
|
|
1350
1371
|
name: 'dragstart'
|
|
1351
1372
|
}],
|
|
1352
1373
|
// event, isDraggingKeyboard
|
|
1353
|
-
'Interaction:update': [
|
|
1374
|
+
'Interaction:update': [
|
|
1375
|
+
// event, isDraggingKeyboard
|
|
1376
|
+
{
|
|
1354
1377
|
name: 'dragmove',
|
|
1355
1378
|
condition: function condition(data) {
|
|
1356
1379
|
return data.event;
|
|
1357
1380
|
}
|
|
1358
1381
|
}],
|
|
1382
|
+
'Interaction:end': [
|
|
1359
1383
|
// event, isDraggingKeyboard
|
|
1360
|
-
|
|
1361
|
-
name: 'callback'
|
|
1362
|
-
|
|
1363
|
-
|
|
1384
|
+
{
|
|
1385
|
+
name: 'callback',
|
|
1386
|
+
extraData: function extraData() {
|
|
1387
|
+
var target = DropZones.getTarget();
|
|
1388
|
+
return _objectSpread2({}, target ? {
|
|
1389
|
+
dropTarget: target.toObject()
|
|
1390
|
+
} : {});
|
|
1391
|
+
}
|
|
1392
|
+
}]
|
|
1364
1393
|
};
|
|
1365
|
-
|
|
1366
1394
|
var _loop = function _loop() {
|
|
1367
1395
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1396
|
+
sub_name = _Object$entries$_i[0],
|
|
1397
|
+
pubs = _Object$entries$_i[1];
|
|
1371
1398
|
['pre', false].forEach(function (filler) {
|
|
1372
1399
|
return subscribe(filler ? "".concat(sub_name, ":").concat(filler) : sub_name, function (data) {
|
|
1373
1400
|
return pubs.forEach(function (pub) {
|
|
1374
|
-
return (!pub.condition || pub.condition(data)) && publish(filler ? "".concat(filler).concat(pub.name) : pub.name, _objectSpread2({
|
|
1401
|
+
return (!pub.condition || pub.condition(data)) && publish(filler ? "".concat(filler).concat(pub.name) : pub.name, _objectSpread2(_objectSpread2({
|
|
1375
1402
|
items: SelectedSet.elements,
|
|
1376
1403
|
isDragging: Interaction.isDragging
|
|
1377
|
-
}, data));
|
|
1404
|
+
}, data), pub.extraData ? pub.extraData(data) : {}));
|
|
1378
1405
|
});
|
|
1379
1406
|
});
|
|
1380
1407
|
});
|
|
1381
1408
|
};
|
|
1382
|
-
|
|
1383
1409
|
for (var _i = 0, _Object$entries = Object.entries(mapping); _i < _Object$entries.length; _i++) {
|
|
1384
1410
|
_loop();
|
|
1385
1411
|
}
|
|
1386
1412
|
});
|
|
1387
1413
|
|
|
1388
1414
|
/**
|
|
1389
|
-
* Transforms any list or single
|
|
1415
|
+
* Transforms any list or single dom node to an array so user doesn’t have to care. Also removes duplicates.
|
|
1390
1416
|
* @param {DSInputElements} items a single item, a Node-list or any element group
|
|
1391
1417
|
* @return {DSElements}
|
|
1392
1418
|
*/
|
|
1393
|
-
|
|
1394
1419
|
var toArray = (function (items) {
|
|
1395
1420
|
if (!items) return [];
|
|
1396
1421
|
if (!Array.isArray(items) && (items instanceof HTMLElement || items instanceof SVGElement)) return [items];
|
|
1397
|
-
|
|
1422
|
+
// @ts-ignore
|
|
1423
|
+
return _toConsumableArray(new Set(_toConsumableArray(items)));
|
|
1398
1424
|
});
|
|
1399
1425
|
|
|
1400
1426
|
// @ts-check
|
|
1427
|
+
|
|
1401
1428
|
/**
|
|
1402
1429
|
* Updates element style left, top, width, height values
|
|
1403
1430
|
* according to pos input object.
|
|
1404
1431
|
* @param {HTMLElement} element
|
|
1405
1432
|
* @param {{left:number,top:number,width:number,height:number}} pos
|
|
1406
1433
|
*/
|
|
1407
|
-
|
|
1408
1434
|
var updateElementStylePos = (function (element, pos) {
|
|
1409
1435
|
element.style.left = "".concat(pos.left, "px");
|
|
1410
1436
|
element.style.top = "".concat(pos.top, "px");
|
|
@@ -1419,34 +1445,24 @@
|
|
|
1419
1445
|
*/
|
|
1420
1446
|
|
|
1421
1447
|
/**
|
|
1422
|
-
* @type {
|
|
1448
|
+
* @type {{cleanup:() => void}}
|
|
1423
1449
|
* @private
|
|
1424
1450
|
*/
|
|
1425
1451
|
|
|
1426
1452
|
/**
|
|
1427
|
-
* @type {
|
|
1453
|
+
* @type {DSArea}
|
|
1428
1454
|
* @private
|
|
1429
1455
|
*/
|
|
1430
1456
|
|
|
1431
1457
|
/**
|
|
1432
|
-
* @type {
|
|
1458
|
+
* @type {DSArea[]}
|
|
1433
1459
|
* @private
|
|
1434
1460
|
*/
|
|
1435
1461
|
|
|
1436
1462
|
/**
|
|
1437
|
-
* @type {
|
|
1463
|
+
* @type {CSSStyleDeclaration}
|
|
1438
1464
|
* @private
|
|
1439
|
-
*/
|
|
1440
|
-
|
|
1441
|
-
/**
|
|
1442
|
-
* @type {DSArea[]}
|
|
1443
|
-
* @private
|
|
1444
|
-
*/
|
|
1445
|
-
|
|
1446
|
-
/**
|
|
1447
|
-
* @type {CSSStyleDeclaration}
|
|
1448
|
-
* @private
|
|
1449
|
-
* */
|
|
1465
|
+
* */
|
|
1450
1466
|
|
|
1451
1467
|
/**
|
|
1452
1468
|
* @type {{top:number,bottom:number,left:number,right:number}}
|
|
@@ -1465,121 +1481,89 @@
|
|
|
1465
1481
|
*/
|
|
1466
1482
|
function Area(_ref) {
|
|
1467
1483
|
var _this = this;
|
|
1468
|
-
|
|
1469
1484
|
var DS = _ref.DS;
|
|
1470
|
-
|
|
1471
1485
|
_classCallCheck(this, Area);
|
|
1472
|
-
|
|
1473
1486
|
_defineProperty(this, "DS", void 0);
|
|
1474
|
-
|
|
1475
|
-
_defineProperty(this, "_modificationCallback", void 0);
|
|
1476
|
-
|
|
1477
|
-
_defineProperty(this, "_modificationObserver", void 0);
|
|
1478
|
-
|
|
1479
|
-
_defineProperty(this, "_zoom", void 0);
|
|
1480
|
-
|
|
1487
|
+
_defineProperty(this, "_observers", void 0);
|
|
1481
1488
|
_defineProperty(this, "_node", void 0);
|
|
1482
|
-
|
|
1483
1489
|
_defineProperty(this, "_parentNodes", void 0);
|
|
1484
|
-
|
|
1485
1490
|
_defineProperty(this, "_computedStyle", void 0);
|
|
1486
|
-
|
|
1487
1491
|
_defineProperty(this, "_computedBorder", void 0);
|
|
1488
|
-
|
|
1489
1492
|
_defineProperty(this, "_rect", void 0);
|
|
1490
|
-
|
|
1491
1493
|
_defineProperty(this, "setArea", function (area) {
|
|
1492
1494
|
_this._node = area;
|
|
1493
1495
|
handleElementPositionAttribute({
|
|
1494
1496
|
computedStyle: _this.computedStyle,
|
|
1495
1497
|
node: _this._node
|
|
1496
|
-
});
|
|
1498
|
+
});
|
|
1497
1499
|
|
|
1500
|
+
// first immediate debounce to update values after dom-update
|
|
1498
1501
|
setTimeout(function () {
|
|
1499
1502
|
_this.DS.PubSub.publish('Area:modified:pre', {
|
|
1500
1503
|
item: _this
|
|
1501
1504
|
});
|
|
1502
|
-
|
|
1503
1505
|
_this.reset();
|
|
1504
|
-
|
|
1505
1506
|
_this.DS.PubSub.publish('Area:modified', {
|
|
1506
1507
|
item: _this
|
|
1507
1508
|
});
|
|
1508
1509
|
});
|
|
1509
1510
|
});
|
|
1510
|
-
|
|
1511
1511
|
_defineProperty(this, "start", function () {
|
|
1512
|
-
addModificationObservers(_this.parentNodes,
|
|
1512
|
+
_this._observers = addModificationObservers(_this.parentNodes, debounce(function (event) {
|
|
1513
|
+
_this.DS.PubSub.publish('Area:modified:pre', {
|
|
1514
|
+
event: event,
|
|
1515
|
+
item: _this
|
|
1516
|
+
});
|
|
1517
|
+
_this.reset();
|
|
1518
|
+
_this.DS.PubSub.publish('Area:modified', {
|
|
1519
|
+
event: event,
|
|
1520
|
+
item: _this
|
|
1521
|
+
});
|
|
1522
|
+
}, 60));
|
|
1513
1523
|
});
|
|
1514
|
-
|
|
1515
1524
|
_defineProperty(this, "reset", function () {
|
|
1516
1525
|
_this._computedStyle = undefined;
|
|
1517
1526
|
_this._rect = undefined;
|
|
1518
1527
|
_this._computedBorder = undefined;
|
|
1519
1528
|
_this._parentNodes = undefined;
|
|
1520
1529
|
});
|
|
1521
|
-
|
|
1522
1530
|
_defineProperty(this, "stop", function () {
|
|
1523
|
-
|
|
1524
|
-
|
|
1531
|
+
_this._observers.cleanup();
|
|
1525
1532
|
_this.reset();
|
|
1526
1533
|
});
|
|
1527
|
-
|
|
1528
1534
|
_defineProperty(this, "scroll", function (directions, multiplier) {
|
|
1529
1535
|
var data = {
|
|
1530
1536
|
scroll_directions: directions,
|
|
1531
1537
|
scroll_multiplier: multiplier
|
|
1532
1538
|
};
|
|
1533
|
-
|
|
1534
1539
|
_this.DS.PubSub.publish('Area:scroll:pre', data);
|
|
1535
|
-
|
|
1536
1540
|
scrollElement(_this._node, directions, multiplier);
|
|
1537
|
-
|
|
1538
1541
|
_this.DS.PubSub.publish('Area:scroll', data);
|
|
1539
1542
|
});
|
|
1540
|
-
|
|
1541
1543
|
this.DS = DS;
|
|
1542
|
-
this.setArea(this.DS.stores.SettingsStore.s.area);
|
|
1543
|
-
|
|
1544
|
+
this.setArea(this.DS.stores.SettingsStore.s.area);
|
|
1545
|
+
// @ts-ignore: @todo: update to typescript
|
|
1544
1546
|
this.DS.PubSub.subscribe('Settings:updated:area', function (_ref2) {
|
|
1545
1547
|
var settings = _ref2.settings;
|
|
1546
1548
|
return _this.setArea(settings.area);
|
|
1547
1549
|
});
|
|
1548
|
-
this._modificationCallback = debounce(function (event) {
|
|
1549
|
-
_this.DS.PubSub.publish('Area:modified:pre', {
|
|
1550
|
-
event: event,
|
|
1551
|
-
item: _this
|
|
1552
|
-
});
|
|
1553
|
-
|
|
1554
|
-
_this.reset();
|
|
1555
|
-
|
|
1556
|
-
_this.DS.PubSub.publish('Area:modified', {
|
|
1557
|
-
event: event,
|
|
1558
|
-
item: _this
|
|
1559
|
-
});
|
|
1560
|
-
}, 60);
|
|
1561
|
-
this._modificationObserver = new MutationObserver(this._modificationCallback);
|
|
1562
1550
|
this.DS.PubSub.subscribe('Interaction:init', this.start);
|
|
1563
1551
|
this.DS.PubSub.subscribe('Interaction:end', this.reset);
|
|
1564
1552
|
}
|
|
1565
|
-
/** @param {DSArea} area */
|
|
1566
|
-
|
|
1567
1553
|
|
|
1554
|
+
/** @param {DSArea} area */
|
|
1568
1555
|
_createClass(Area, [{
|
|
1569
1556
|
key: "HTMLNode",
|
|
1570
1557
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
1571
1558
|
// Node Getters
|
|
1572
1559
|
get: function get() {
|
|
1573
|
-
return (
|
|
1574
|
-
/** @type {DSArea} */
|
|
1575
|
-
this._node
|
|
1560
|
+
return (/** @type {DSArea} */this._node
|
|
1576
1561
|
);
|
|
1577
1562
|
}
|
|
1578
1563
|
/**
|
|
1579
1564
|
* The computed border from the element (caches result)
|
|
1580
1565
|
* @type {{top:number,bottom:number,left:number,right:number}}
|
|
1581
1566
|
*/
|
|
1582
|
-
|
|
1583
1567
|
}, {
|
|
1584
1568
|
key: "computedBorder",
|
|
1585
1569
|
get: function get() {
|
|
@@ -1595,18 +1579,16 @@
|
|
|
1595
1579
|
* The computed styles from the element (caches result)
|
|
1596
1580
|
* @type {CSSStyleDeclaration}
|
|
1597
1581
|
*/
|
|
1598
|
-
|
|
1599
1582
|
}, {
|
|
1600
1583
|
key: "computedStyle",
|
|
1601
1584
|
get: function get() {
|
|
1602
1585
|
if (this._computedStyle) return this._computedStyle;
|
|
1603
|
-
if (this.HTMLNode instanceof
|
|
1586
|
+
if (this.HTMLNode instanceof Document) return this._computedStyle = window.getComputedStyle(this.HTMLNode.body || this.HTMLNode.documentElement);else return this._computedStyle = window.getComputedStyle(this.HTMLNode);
|
|
1604
1587
|
}
|
|
1605
1588
|
/**
|
|
1606
1589
|
* The element rect (caches result) (without scrollbar or borders)
|
|
1607
1590
|
* @type {DSBoundingRect}
|
|
1608
1591
|
*/
|
|
1609
|
-
|
|
1610
1592
|
}, {
|
|
1611
1593
|
key: "rect",
|
|
1612
1594
|
get: function get() {
|
|
@@ -1617,27 +1599,9 @@
|
|
|
1617
1599
|
key: "parentNodes",
|
|
1618
1600
|
get: function get() {
|
|
1619
1601
|
if (this._parentNodes) return this._parentNodes;
|
|
1620
|
-
|
|
1621
|
-
var traverse = function traverse(toWatch) {
|
|
1622
|
-
var _toWatch$index;
|
|
1623
|
-
|
|
1624
|
-
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1625
|
-
var parent = (_toWatch$index = toWatch[index]) === null || _toWatch$index === void 0 ? void 0 : _toWatch$index.parentNode;
|
|
1626
|
-
|
|
1627
|
-
if (parent) {
|
|
1628
|
-
toWatch.push(parent);
|
|
1629
|
-
index++;
|
|
1630
|
-
return traverse(toWatch, index);
|
|
1631
|
-
} else {
|
|
1632
|
-
return toWatch;
|
|
1633
|
-
}
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
|
-
this._parentNodes = traverse([this.HTMLNode]);
|
|
1637
|
-
return this._parentNodes;
|
|
1602
|
+
return this._parentNodes = getAllParentNodes(this.HTMLNode);
|
|
1638
1603
|
}
|
|
1639
1604
|
}]);
|
|
1640
|
-
|
|
1641
1605
|
return Area;
|
|
1642
1606
|
}();
|
|
1643
1607
|
|
|
@@ -1674,21 +1638,13 @@
|
|
|
1674
1638
|
*/
|
|
1675
1639
|
function Drag(_ref) {
|
|
1676
1640
|
var _this = this;
|
|
1677
|
-
|
|
1678
1641
|
var DS = _ref.DS;
|
|
1679
|
-
|
|
1680
1642
|
_classCallCheck(this, Drag);
|
|
1681
|
-
|
|
1682
1643
|
_defineProperty(this, "_prevCursorPos", void 0);
|
|
1683
|
-
|
|
1684
1644
|
_defineProperty(this, "_prevScrollPos", void 0);
|
|
1685
|
-
|
|
1686
1645
|
_defineProperty(this, "_elements", []);
|
|
1687
|
-
|
|
1688
1646
|
_defineProperty(this, "_dragKeys", void 0);
|
|
1689
|
-
|
|
1690
1647
|
_defineProperty(this, "_dragKeysFlat", []);
|
|
1691
|
-
|
|
1692
1648
|
_defineProperty(this, "assignDragkeys", function () {
|
|
1693
1649
|
_this._dragKeys = {
|
|
1694
1650
|
up: _this.DS.stores.SettingsStore.s.dragKeys.up.map(function (k) {
|
|
@@ -1706,26 +1662,19 @@
|
|
|
1706
1662
|
};
|
|
1707
1663
|
_this._dragKeysFlat = [].concat(_toConsumableArray(_this._dragKeys.up), _toConsumableArray(_this._dragKeys.down), _toConsumableArray(_this._dragKeys.left), _toConsumableArray(_this._dragKeys.right));
|
|
1708
1664
|
});
|
|
1709
|
-
|
|
1710
1665
|
_defineProperty(this, "keyboardDrag", function (_ref2) {
|
|
1711
1666
|
var event = _ref2.event,
|
|
1712
|
-
|
|
1713
|
-
|
|
1667
|
+
key = _ref2.key;
|
|
1714
1668
|
var _key = key.toLowerCase();
|
|
1715
|
-
|
|
1716
1669
|
if (!_this.DS.stores.SettingsStore.s.keyboardDrag || !_this._dragKeysFlat.includes(_key) || !_this.DS.SelectedSet.size || !_this.DS.stores.SettingsStore.s.draggability || _this.DS["continue"]) return;
|
|
1717
1670
|
var publishData = {
|
|
1718
1671
|
event: event,
|
|
1719
1672
|
isDragging: true,
|
|
1720
1673
|
isDraggingKeyboard: true
|
|
1721
1674
|
};
|
|
1722
|
-
|
|
1723
1675
|
_this.DS.publish(['Interaction:start:pre', 'Interaction:start'], publishData);
|
|
1724
|
-
|
|
1725
1676
|
_this._elements = _this.DS.getSelection();
|
|
1726
|
-
|
|
1727
1677
|
_this.handleZIndex(true);
|
|
1728
|
-
|
|
1729
1678
|
var posDirection = handleKeyboardDragPosDifference({
|
|
1730
1679
|
shiftKey: _this.DS.stores.KeyStore.currentValues.includes('shift'),
|
|
1731
1680
|
keyboardDragSpeed: _this.DS.stores.SettingsStore.s.keyboardDragSpeed,
|
|
@@ -1736,7 +1685,6 @@
|
|
|
1736
1685
|
canScroll: _this.DS.stores.ScrollStore.canScroll,
|
|
1737
1686
|
dragKeys: _this._dragKeys
|
|
1738
1687
|
});
|
|
1739
|
-
|
|
1740
1688
|
_this._elements.forEach(function (element) {
|
|
1741
1689
|
return moveElement({
|
|
1742
1690
|
element: element,
|
|
@@ -1745,53 +1693,41 @@
|
|
|
1745
1693
|
useTransform: _this.DS.stores.SettingsStore.s.useTransform
|
|
1746
1694
|
});
|
|
1747
1695
|
});
|
|
1748
|
-
|
|
1749
1696
|
_this.DS.publish(['Interaction:update:pre', 'Interaction:update'], publishData);
|
|
1750
1697
|
});
|
|
1751
|
-
|
|
1752
1698
|
_defineProperty(this, "keyboardEnd", function (_ref3) {
|
|
1753
1699
|
var event = _ref3.event,
|
|
1754
|
-
|
|
1755
|
-
|
|
1700
|
+
key = _ref3.key;
|
|
1756
1701
|
var _key = key.toLowerCase();
|
|
1757
|
-
|
|
1758
1702
|
if (!_this.DS.stores.SettingsStore.s.keyboardDrag || !_this._dragKeysFlat.includes(_key) || !_this.DS.SelectedSet.size || !_this.DS.stores.SettingsStore.s.draggability) return;
|
|
1759
1703
|
var publishData = {
|
|
1760
1704
|
event: event,
|
|
1761
1705
|
isDragging: _this.DS.stores.SettingsStore.s.draggability,
|
|
1762
1706
|
isDraggingKeyboard: true
|
|
1763
1707
|
};
|
|
1764
|
-
|
|
1765
1708
|
_this.DS.publish(['Interaction:end:pre', 'Interaction:end'], publishData);
|
|
1766
1709
|
});
|
|
1767
|
-
|
|
1768
1710
|
_defineProperty(this, "start", function (_ref4) {
|
|
1769
1711
|
var isDragging = _ref4.isDragging,
|
|
1770
|
-
|
|
1712
|
+
isDraggingKeyboard = _ref4.isDraggingKeyboard;
|
|
1771
1713
|
if (!isDragging || isDraggingKeyboard) return;
|
|
1772
1714
|
_this._prevCursorPos = null;
|
|
1773
1715
|
_this._prevScrollPos = null;
|
|
1774
1716
|
_this._elements = _this.DS.getSelection();
|
|
1775
|
-
|
|
1776
1717
|
_this.handleZIndex(true);
|
|
1777
1718
|
});
|
|
1778
|
-
|
|
1779
1719
|
_defineProperty(this, "stop", function (evt) {
|
|
1780
1720
|
if (evt !== null && evt !== void 0 && evt.isKeyboard) return;
|
|
1781
1721
|
_this._prevCursorPos = null;
|
|
1782
1722
|
_this._prevScrollPos = null;
|
|
1783
|
-
|
|
1784
1723
|
_this.handleZIndex(false);
|
|
1785
|
-
|
|
1786
1724
|
_this._elements = [];
|
|
1787
1725
|
});
|
|
1788
|
-
|
|
1789
1726
|
_defineProperty(this, "update", function (_ref5) {
|
|
1790
1727
|
var isDragging = _ref5.isDragging,
|
|
1791
|
-
|
|
1728
|
+
isDraggingKeyboard = _ref5.isDraggingKeyboard;
|
|
1792
1729
|
if (!isDragging || !_this._elements.length || isDraggingKeyboard || _this.DS["continue"]) return;
|
|
1793
1730
|
var posDirection = calc(_this._cursorDiff, '+', _this._scrollDiff);
|
|
1794
|
-
|
|
1795
1731
|
_this._elements.forEach(function (element) {
|
|
1796
1732
|
return moveElement({
|
|
1797
1733
|
element: element,
|
|
@@ -1801,15 +1737,14 @@
|
|
|
1801
1737
|
});
|
|
1802
1738
|
});
|
|
1803
1739
|
});
|
|
1804
|
-
|
|
1805
1740
|
_defineProperty(this, "handleZIndex", function (add) {
|
|
1806
1741
|
_this._elements.forEach(function (element) {
|
|
1807
1742
|
return element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + add ? 9999 : -9998);
|
|
1808
1743
|
});
|
|
1809
1744
|
});
|
|
1745
|
+
this.DS = DS;
|
|
1810
1746
|
|
|
1811
|
-
|
|
1812
|
-
|
|
1747
|
+
// @ts-ignore: @todo: update to typescript
|
|
1813
1748
|
this.DS.subscribe('Settings:updated:dragKeys', this.assignDragkeys);
|
|
1814
1749
|
this.assignDragkeys();
|
|
1815
1750
|
this.DS.subscribe('Interaction:start', this.start);
|
|
@@ -1818,7 +1753,6 @@
|
|
|
1818
1753
|
this.DS.subscribe('KeyStore:down', this.keyboardDrag);
|
|
1819
1754
|
this.DS.subscribe('KeyStore:up', this.keyboardEnd);
|
|
1820
1755
|
}
|
|
1821
|
-
|
|
1822
1756
|
_createClass(Drag, [{
|
|
1823
1757
|
key: "_cursorDiff",
|
|
1824
1758
|
get: function get() {
|
|
@@ -1842,10 +1776,364 @@
|
|
|
1842
1776
|
return scrollDiff;
|
|
1843
1777
|
}
|
|
1844
1778
|
}]);
|
|
1845
|
-
|
|
1846
1779
|
return Drag;
|
|
1847
1780
|
}();
|
|
1848
1781
|
|
|
1782
|
+
var DropZone = /*#__PURE__*/function () {
|
|
1783
|
+
/**
|
|
1784
|
+
* @type {string}
|
|
1785
|
+
*/
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* @type {DSElement}
|
|
1789
|
+
*/
|
|
1790
|
+
|
|
1791
|
+
/**
|
|
1792
|
+
* @type {DSElements}
|
|
1793
|
+
*/
|
|
1794
|
+
|
|
1795
|
+
/**
|
|
1796
|
+
* @type {DOMRect}
|
|
1797
|
+
* @private
|
|
1798
|
+
*/
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* @type {{cleanup:()=>void}}
|
|
1802
|
+
* @private
|
|
1803
|
+
*/
|
|
1804
|
+
|
|
1805
|
+
/**
|
|
1806
|
+
* @type {NodeJS.Timeout}
|
|
1807
|
+
* @private
|
|
1808
|
+
*/
|
|
1809
|
+
|
|
1810
|
+
/**
|
|
1811
|
+
* @type {DSElements}
|
|
1812
|
+
* @private
|
|
1813
|
+
*/
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* @type {DSElements}
|
|
1817
|
+
* @private
|
|
1818
|
+
*/
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* @constructor Drag
|
|
1822
|
+
* @param {Object} obj
|
|
1823
|
+
* @param {DragSelect} obj.DS
|
|
1824
|
+
* @param {string} obj.id
|
|
1825
|
+
* @param {DSElement} obj.element
|
|
1826
|
+
* @param {DSInputElements} obj.droppables
|
|
1827
|
+
* @ignore
|
|
1828
|
+
*/
|
|
1829
|
+
function DropZone(_ref) {
|
|
1830
|
+
var _this = this;
|
|
1831
|
+
var DS = _ref.DS,
|
|
1832
|
+
id = _ref.id,
|
|
1833
|
+
element = _ref.element,
|
|
1834
|
+
droppables = _ref.droppables;
|
|
1835
|
+
_classCallCheck(this, DropZone);
|
|
1836
|
+
_defineProperty(this, "id", void 0);
|
|
1837
|
+
_defineProperty(this, "element", void 0);
|
|
1838
|
+
_defineProperty(this, "droppables", void 0);
|
|
1839
|
+
_defineProperty(this, "_rect", void 0);
|
|
1840
|
+
_defineProperty(this, "_observers", void 0);
|
|
1841
|
+
_defineProperty(this, "_timeout", void 0);
|
|
1842
|
+
_defineProperty(this, "_itemsDropped", []);
|
|
1843
|
+
_defineProperty(this, "_itemsInside", void 0);
|
|
1844
|
+
_defineProperty(this, "setReadyClasses", function (action) {
|
|
1845
|
+
if (_this.isDestroyed) return;
|
|
1846
|
+
var selectedEls = _this.droppables.filter(function (el) {
|
|
1847
|
+
return _this.DS.SelectedSet.has(el);
|
|
1848
|
+
});
|
|
1849
|
+
if (!selectedEls.length) return;
|
|
1850
|
+
selectedEls.forEach(function (item) {
|
|
1851
|
+
item.classList[action]("".concat(_this.Settings.droppableClass));
|
|
1852
|
+
item.classList[action]("".concat(_this.Settings.droppableClass, "-").concat(_this.id));
|
|
1853
|
+
});
|
|
1854
|
+
_this.element.classList[action]("".concat(_this.Settings.dropZoneReadyClass));
|
|
1855
|
+
});
|
|
1856
|
+
_defineProperty(this, "handleNoDrop", function () {
|
|
1857
|
+
var _this$_itemsDropped;
|
|
1858
|
+
if (_this.isDestroyed) return;
|
|
1859
|
+
// for each selected element that is not part of the target zone, remove the classes
|
|
1860
|
+
_this.DS.SelectedSet.forEach(function (item) {
|
|
1861
|
+
item.classList.remove(_this.Settings.droppedTargetClass);
|
|
1862
|
+
item.classList.remove("".concat(_this.Settings.droppedTargetClass, "-").concat(_this.id));
|
|
1863
|
+
});
|
|
1864
|
+
// and remove them from the zones dropped items
|
|
1865
|
+
_this._itemsDropped = _this._itemsDropped.filter(function (item) {
|
|
1866
|
+
return !_this.DS.SelectedSet.has(item);
|
|
1867
|
+
});
|
|
1868
|
+
// if the zone has no dropped left, also remove the zones class
|
|
1869
|
+
if (!((_this$_itemsDropped = _this._itemsDropped) !== null && _this$_itemsDropped !== void 0 && _this$_itemsDropped.length)) _this.element.classList.remove("".concat(_this.Settings.dropZoneTargetClass));
|
|
1870
|
+
});
|
|
1871
|
+
_defineProperty(this, "handleDrop", function () {
|
|
1872
|
+
var _this$droppables, _this$_itemsDropped2, _this$_itemsDropped3;
|
|
1873
|
+
if (_this.isDestroyed) return;
|
|
1874
|
+
_this._itemsDropped = _toConsumableArray(new Set([].concat(_toConsumableArray(_this._itemsDropped), _toConsumableArray((_this$droppables = _this.droppables) === null || _this$droppables === void 0 ? void 0 : _this$droppables.filter(function (item) {
|
|
1875
|
+
return _this.DS.SelectedSet.has(item);
|
|
1876
|
+
})))));
|
|
1877
|
+
// add the target class to the zones dropped items
|
|
1878
|
+
(_this$_itemsDropped2 = _this._itemsDropped) === null || _this$_itemsDropped2 === void 0 ? void 0 : _this$_itemsDropped2.forEach(function (item) {
|
|
1879
|
+
item.classList.add("".concat(_this.Settings.droppedTargetClass));
|
|
1880
|
+
item.classList.add("".concat(_this.Settings.droppedTargetClass, "-").concat(_this.id));
|
|
1881
|
+
});
|
|
1882
|
+
// if the zone has dropped, add the zones class
|
|
1883
|
+
if ((_this$_itemsDropped3 = _this._itemsDropped) !== null && _this$_itemsDropped3 !== void 0 && _this$_itemsDropped3.length) _this.element.classList.add("".concat(_this.Settings.dropZoneTargetClass));
|
|
1884
|
+
});
|
|
1885
|
+
_defineProperty(this, "handleItemsInsideClasses", function () {
|
|
1886
|
+
var isAnyInside = false;
|
|
1887
|
+
_this.droppables.forEach(function (item) {
|
|
1888
|
+
if (_this.itemsInside.includes(item)) {
|
|
1889
|
+
item.classList.add("".concat(_this.Settings.droppedInsideClass));
|
|
1890
|
+
item.classList.add("".concat(_this.Settings.droppedInsideClass, "-").concat(_this.id));
|
|
1891
|
+
isAnyInside = true;
|
|
1892
|
+
} else {
|
|
1893
|
+
item.classList.remove("".concat(_this.Settings.droppedInsideClass, "-").concat(_this.id));
|
|
1894
|
+
if (!item.className.includes("".concat(_this.Settings.droppedInsideClass, "-"))) item.classList.remove("".concat(_this.Settings.droppedInsideClass));
|
|
1895
|
+
}
|
|
1896
|
+
});
|
|
1897
|
+
if (isAnyInside) _this.element.classList.add("".concat(_this.Settings.dropZoneInsideClass));else _this.element.classList.remove("".concat(_this.Settings.dropZoneInsideClass));
|
|
1898
|
+
});
|
|
1899
|
+
_defineProperty(this, "start", function (_ref2) {
|
|
1900
|
+
var isDragging = _ref2.isDragging;
|
|
1901
|
+
if (!isDragging || _this.isDestroyed) return;
|
|
1902
|
+
_this.setReadyClasses('add');
|
|
1903
|
+
});
|
|
1904
|
+
_defineProperty(this, "stop", function (_ref3) {
|
|
1905
|
+
var isDragging = _ref3.isDragging;
|
|
1906
|
+
if (!isDragging || _this.isDestroyed) return;
|
|
1907
|
+
_this.setReadyClasses('remove');
|
|
1908
|
+
_this.handleItemsInsideClasses();
|
|
1909
|
+
});
|
|
1910
|
+
_defineProperty(this, "toObject", function () {
|
|
1911
|
+
return {
|
|
1912
|
+
id: _this.id,
|
|
1913
|
+
element: _this.element,
|
|
1914
|
+
droppables: _this.droppables,
|
|
1915
|
+
itemsDropped: _this.itemsDropped,
|
|
1916
|
+
itemsInside: _this.itemsInside
|
|
1917
|
+
};
|
|
1918
|
+
});
|
|
1919
|
+
this.DS = DS;
|
|
1920
|
+
this.Settings = DS.stores.SettingsStore.s;
|
|
1921
|
+
this.id = id;
|
|
1922
|
+
this.element = element;
|
|
1923
|
+
this.droppables = toArray(droppables);
|
|
1924
|
+
this.element.classList.add("".concat(this.Settings.dropZoneClass));
|
|
1925
|
+
|
|
1926
|
+
// @ts-ignore: @todo: update to typescript
|
|
1927
|
+
this.DS.subscribe('Settings:updated:dropZoneClass', function (_ref4) {
|
|
1928
|
+
var settings = _ref4.settings;
|
|
1929
|
+
_this.element.classList.remove(settings['dropZoneClass:pre']);
|
|
1930
|
+
_this.element.classList.add(settings.dropZoneClass);
|
|
1931
|
+
});
|
|
1932
|
+
this._observers = addModificationObservers(this.parentNodes, debounce(function () {
|
|
1933
|
+
return _this._rect = null;
|
|
1934
|
+
}, this.Settings.refreshMemoryRate));
|
|
1935
|
+
this.DS.subscribe('Interaction:start', this.start);
|
|
1936
|
+
this.DS.subscribe('Interaction:end', this.stop);
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
/**
|
|
1940
|
+
* @param {'add'|'remove'} action
|
|
1941
|
+
*/
|
|
1942
|
+
_createClass(DropZone, [{
|
|
1943
|
+
key: "destroy",
|
|
1944
|
+
value: function destroy() {
|
|
1945
|
+
var _this2 = this;
|
|
1946
|
+
this._observers.cleanup();
|
|
1947
|
+
this.element.classList.remove("".concat(this.Settings.dropZoneClass));
|
|
1948
|
+
this.element.classList.remove("".concat(this.Settings.dropZoneTargetClass));
|
|
1949
|
+
this.element.classList.remove("".concat(this.Settings.dropZoneReadyClass));
|
|
1950
|
+
this.droppables.forEach(function (item) {
|
|
1951
|
+
item.classList.remove("".concat(_this2.Settings.droppedTargetClass));
|
|
1952
|
+
item.classList.remove("".concat(_this2.Settings.droppedTargetClass, "-").concat(_this2.id));
|
|
1953
|
+
item.classList.remove("".concat(_this2.Settings.droppableClass));
|
|
1954
|
+
item.classList.remove("".concat(_this2.Settings.droppableClass, "-").concat(_this2.id));
|
|
1955
|
+
});
|
|
1956
|
+
this.DS.unsubscribe('Interaction:start', this.start);
|
|
1957
|
+
this.DS.unsubscribe('Interaction:end', this.stop);
|
|
1958
|
+
this.element = null;
|
|
1959
|
+
this.droppables = null;
|
|
1960
|
+
this.id = null;
|
|
1961
|
+
this._itemsDropped = null;
|
|
1962
|
+
this._itemsInside = null;
|
|
1963
|
+
this.isDestroyed = true;
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* @returns {DSDropZone}
|
|
1967
|
+
*/
|
|
1968
|
+
}, {
|
|
1969
|
+
key: "rect",
|
|
1970
|
+
get: function get() {
|
|
1971
|
+
if (this.isDestroyed) return null;
|
|
1972
|
+
if (this._rect) return this._rect;
|
|
1973
|
+
return this._rect = this.element.getBoundingClientRect();
|
|
1974
|
+
}
|
|
1975
|
+
}, {
|
|
1976
|
+
key: "itemsDropped",
|
|
1977
|
+
get: function get() {
|
|
1978
|
+
if (this.isDestroyed) return null;
|
|
1979
|
+
return this._itemsDropped;
|
|
1980
|
+
}
|
|
1981
|
+
}, {
|
|
1982
|
+
key: "itemsInside",
|
|
1983
|
+
get: function get() {
|
|
1984
|
+
var _this3 = this;
|
|
1985
|
+
if (this.isDestroyed) return null;
|
|
1986
|
+
if (this._itemsInside) return this._itemsInside;
|
|
1987
|
+
this._itemsInside = this.droppables.flatMap(function (item) {
|
|
1988
|
+
if (isCollision(_this3.DS.SelectableSet.rects.get(item), _this3.rect, _this3.Settings.dropInsideThreshold)) return [item];
|
|
1989
|
+
return [];
|
|
1990
|
+
});
|
|
1991
|
+
|
|
1992
|
+
// since elements can be moved while this getter is called, we need to update the values every X seconds
|
|
1993
|
+
if (this._timeout) clearTimeout(this._timeout);
|
|
1994
|
+
this._timeout = setTimeout(function () {
|
|
1995
|
+
return _this3._itemsInside = null;
|
|
1996
|
+
}, this.Settings.refreshMemoryRate);
|
|
1997
|
+
return this._itemsInside;
|
|
1998
|
+
}
|
|
1999
|
+
}, {
|
|
2000
|
+
key: "parentNodes",
|
|
2001
|
+
get: function get() {
|
|
2002
|
+
if (this._parentNodes) return this._parentNodes;
|
|
2003
|
+
return this._parentNodes = getAllParentNodes(this.element);
|
|
2004
|
+
}
|
|
2005
|
+
}]);
|
|
2006
|
+
return DropZone;
|
|
2007
|
+
}();
|
|
2008
|
+
|
|
2009
|
+
var DropZones =
|
|
2010
|
+
/**
|
|
2011
|
+
* Get the drop zone by the zone element
|
|
2012
|
+
* @type {Map<DSElement, DropZone>}
|
|
2013
|
+
* @private
|
|
2014
|
+
*/
|
|
2015
|
+
|
|
2016
|
+
/**
|
|
2017
|
+
* Get the drop zone by the zone id
|
|
2018
|
+
* @type {Map<string, DropZone>}
|
|
2019
|
+
* @private
|
|
2020
|
+
*/
|
|
2021
|
+
|
|
2022
|
+
/**
|
|
2023
|
+
* Get the drop zones by one zone item
|
|
2024
|
+
* @type {Map<DSElement,DropZone[]>}
|
|
2025
|
+
* @private
|
|
2026
|
+
*/
|
|
2027
|
+
|
|
2028
|
+
/**
|
|
2029
|
+
* Get the drop zones by one zone item
|
|
2030
|
+
* @type {DropZone[]}
|
|
2031
|
+
* @private
|
|
2032
|
+
*/
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* @constructor Drag
|
|
2036
|
+
* @param {{DS:DragSelect}} obj
|
|
2037
|
+
* @ignore
|
|
2038
|
+
*/
|
|
2039
|
+
function DropZones(_ref) {
|
|
2040
|
+
var _this = this;
|
|
2041
|
+
var DS = _ref.DS;
|
|
2042
|
+
_classCallCheck(this, DropZones);
|
|
2043
|
+
_defineProperty(this, "_zoneByElement", new Map());
|
|
2044
|
+
_defineProperty(this, "_zoneById", new Map());
|
|
2045
|
+
_defineProperty(this, "_zonesByDroppable", new Map());
|
|
2046
|
+
_defineProperty(this, "_zones", void 0);
|
|
2047
|
+
_defineProperty(this, "setDropZones", function (_ref2) {
|
|
2048
|
+
var dropZones = _ref2.dropZones;
|
|
2049
|
+
if (!dropZones) return;
|
|
2050
|
+
if (_this._zones) _this._zones.forEach(function (zone) {
|
|
2051
|
+
return zone.destroy();
|
|
2052
|
+
});
|
|
2053
|
+
_this._zones = dropZones.map(function (zone) {
|
|
2054
|
+
return new DropZone(_objectSpread2({
|
|
2055
|
+
DS: _this.DS
|
|
2056
|
+
}, zone));
|
|
2057
|
+
});
|
|
2058
|
+
_this._zones.forEach(function (zone) {
|
|
2059
|
+
_this._zoneByElement.set(zone.element, zone);
|
|
2060
|
+
_this._zoneById.set(zone.id, zone);
|
|
2061
|
+
zone.droppables.forEach(function (droppable) {
|
|
2062
|
+
var zones = _this._zonesByDroppable.get(droppable);
|
|
2063
|
+
if (!(zones !== null && zones !== void 0 && zones.length)) return _this._zonesByDroppable.set(droppable, [zone]);
|
|
2064
|
+
// @ts-ignore
|
|
2065
|
+
_this._zonesByDroppable.set(droppable, _toConsumableArray(new Set([].concat(_toConsumableArray(zones), [zone]))));
|
|
2066
|
+
});
|
|
2067
|
+
});
|
|
2068
|
+
});
|
|
2069
|
+
_defineProperty(this, "_handleDrop", function (target) {
|
|
2070
|
+
_this._zones.forEach(function (zone) {
|
|
2071
|
+
if (zone === target) return;
|
|
2072
|
+
zone.handleNoDrop();
|
|
2073
|
+
});
|
|
2074
|
+
if (!target) return;
|
|
2075
|
+
target.handleDrop();
|
|
2076
|
+
});
|
|
2077
|
+
_defineProperty(this, "_getZoneByElementsFromPoint", function (elements, _ref3) {
|
|
2078
|
+
var x = _ref3.x,
|
|
2079
|
+
y = _ref3.y;
|
|
2080
|
+
for (var i = 0, il = elements.length; i < il; i++) {
|
|
2081
|
+
var zone = _this._zoneByElement.get(elements[i]);
|
|
2082
|
+
if (zone && isCollision(zone.rect, {
|
|
2083
|
+
left: x,
|
|
2084
|
+
right: x,
|
|
2085
|
+
top: y,
|
|
2086
|
+
bottom: y
|
|
2087
|
+
}, Math.min(_this.Settings.dropTargetThreshold, 0.5))) {
|
|
2088
|
+
return zone;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
});
|
|
2092
|
+
_defineProperty(this, "stop", function (_ref4) {
|
|
2093
|
+
var isDragging = _ref4.isDragging;
|
|
2094
|
+
if (!isDragging) return;
|
|
2095
|
+
var target = _this.getTarget();
|
|
2096
|
+
_this._handleDrop(target);
|
|
2097
|
+
});
|
|
2098
|
+
_defineProperty(this, "getItemsDroppedById", function (zoneId) {
|
|
2099
|
+
var zone = _this._zoneById.get(zoneId);
|
|
2100
|
+
if (!zone) return console.warn("[DragSelect] No zone found (id: ".concat(zoneId, ")"));
|
|
2101
|
+
return zone.itemsDropped;
|
|
2102
|
+
});
|
|
2103
|
+
_defineProperty(this, "getItemsInsideById", function (zoneId, addClasses) {
|
|
2104
|
+
var zone = _this._zoneById.get(zoneId);
|
|
2105
|
+
if (!zone) return console.warn("[DragSelect] No zone found (id: ".concat(zoneId, ")"));
|
|
2106
|
+
var itemsInside = zone.itemsInside;
|
|
2107
|
+
if (addClasses) zone.handleItemsInsideClasses();
|
|
2108
|
+
return itemsInside;
|
|
2109
|
+
});
|
|
2110
|
+
_defineProperty(this, "getTarget", function (coordinates) {
|
|
2111
|
+
var _this$_zones;
|
|
2112
|
+
if (!((_this$_zones = _this._zones) !== null && _this$_zones !== void 0 && _this$_zones.length)) return;
|
|
2113
|
+
var x = (coordinates === null || coordinates === void 0 ? void 0 : coordinates.x) || _this.DS.stores.PointerStore.currentVal.x;
|
|
2114
|
+
var y = (coordinates === null || coordinates === void 0 ? void 0 : coordinates.y) || _this.DS.stores.PointerStore.currentVal.y;
|
|
2115
|
+
var elements = document.elementsFromPoint(x, y);
|
|
2116
|
+
return _this._getZoneByElementsFromPoint( /** @type {DSElements} */elements, {
|
|
2117
|
+
x: x,
|
|
2118
|
+
y: y
|
|
2119
|
+
});
|
|
2120
|
+
});
|
|
2121
|
+
this.DS = DS;
|
|
2122
|
+
this.Settings = DS.stores.SettingsStore.s;
|
|
2123
|
+
|
|
2124
|
+
// @ts-ignore: @todo: update to typescript
|
|
2125
|
+
this.DS.subscribe('Settings:updated:dropZones', this.setDropZones);
|
|
2126
|
+
this.setDropZones({
|
|
2127
|
+
dropZones: /** @type {DSDropZone[]} */this.DS.stores.SettingsStore.s.dropZones
|
|
2128
|
+
});
|
|
2129
|
+
this.DS.subscribe('Interaction:end', this.stop);
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* @param {Object} obj
|
|
2134
|
+
* @param {DSDropZone[]} [obj.dropZones]
|
|
2135
|
+
*/;
|
|
2136
|
+
|
|
1849
2137
|
var Interaction = /*#__PURE__*/function () {
|
|
1850
2138
|
/** @type {boolean} */
|
|
1851
2139
|
|
|
@@ -1858,137 +2146,103 @@
|
|
|
1858
2146
|
*/
|
|
1859
2147
|
function Interaction(_ref) {
|
|
1860
2148
|
var _this = this;
|
|
1861
|
-
|
|
1862
2149
|
var DS = _ref.DS;
|
|
1863
|
-
|
|
1864
2150
|
_classCallCheck(this, Interaction);
|
|
1865
|
-
|
|
1866
2151
|
_defineProperty(this, "isInteracting", void 0);
|
|
1867
|
-
|
|
1868
2152
|
_defineProperty(this, "isDragging", void 0);
|
|
1869
|
-
|
|
1870
2153
|
_defineProperty(this, "init", function () {
|
|
1871
2154
|
return _this.DS.publish('Interaction:init:pre', {});
|
|
1872
2155
|
});
|
|
1873
|
-
|
|
1874
2156
|
_defineProperty(this, "_init", function () {
|
|
1875
|
-
_this.stop();
|
|
1876
|
-
|
|
2157
|
+
_this.stop();
|
|
1877
2158
|
|
|
2159
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1878
2160
|
if (_this.Settings.usePointerEvents) _this.DS.Area.HTMLNode.addEventListener('pointerdown', _this.start, {
|
|
1879
2161
|
passive: false
|
|
1880
2162
|
});else _this.DS.Area.HTMLNode.addEventListener('mousedown', _this.start);
|
|
1881
|
-
|
|
1882
2163
|
_this.DS.Area.HTMLNode.addEventListener('touchstart', _this.start, {
|
|
1883
2164
|
passive: false
|
|
1884
2165
|
});
|
|
1885
|
-
|
|
1886
2166
|
_this.DS.publish('Interaction:init', {});
|
|
1887
2167
|
});
|
|
1888
|
-
|
|
1889
2168
|
_defineProperty(this, "start", function (event) {
|
|
1890
2169
|
return _this.DS.publish('Interaction:start:pre', {
|
|
1891
2170
|
event: event,
|
|
1892
2171
|
isDragging: _this.isDragging
|
|
1893
2172
|
});
|
|
1894
2173
|
});
|
|
1895
|
-
|
|
1896
2174
|
_defineProperty(this, "_start", function (event) {
|
|
1897
2175
|
if (event.type === 'touchstart') event.preventDefault(); // Call preventDefault() to prevent double click issue, see https://github.com/ThibaultJanBeyer/DragSelect/pull/29 & https://developer.mozilla.org/vi/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
|
1898
|
-
|
|
1899
2176
|
if (!_this._canInteract(event)) return;
|
|
1900
2177
|
_this.isInteracting = true;
|
|
1901
2178
|
_this.isDragging = _this.isDragEvent(event);
|
|
1902
|
-
|
|
1903
2179
|
_this.DS.publish('Interaction:start', {
|
|
1904
2180
|
event: event,
|
|
1905
2181
|
isDragging: _this.isDragging
|
|
1906
|
-
});
|
|
1907
|
-
|
|
2182
|
+
});
|
|
1908
2183
|
|
|
2184
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1909
2185
|
if (_this.Settings.usePointerEvents) {
|
|
1910
2186
|
document.addEventListener('pointerup', _this.reset);
|
|
1911
2187
|
document.addEventListener('pointercancel', _this.reset);
|
|
1912
2188
|
} else document.addEventListener('mouseup', _this.reset);
|
|
1913
|
-
|
|
1914
2189
|
document.addEventListener('touchend', _this.reset);
|
|
1915
2190
|
});
|
|
1916
|
-
|
|
1917
2191
|
_defineProperty(this, "isDragEvent", function (event) {
|
|
1918
|
-
var clickedElement =
|
|
1919
|
-
/** @type {Element} */
|
|
1920
|
-
event.target.closest(".".concat(_this.Settings.selectableClass));
|
|
2192
|
+
var clickedElement = /** @type {Element} */event.target.closest(".".concat(_this.Settings.selectableClass));
|
|
1921
2193
|
if (!_this.Settings.draggability || _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) || !clickedElement) return false;
|
|
1922
|
-
|
|
1923
2194
|
if (_this.Settings.immediateDrag) {
|
|
1924
|
-
if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add(
|
|
1925
|
-
/** @type {DSElement} */
|
|
1926
|
-
clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
|
|
2195
|
+
if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add( /** @type {DSElement} */clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
|
|
1927
2196
|
_this.DS.SelectedSet.clear();
|
|
1928
|
-
|
|
1929
|
-
_this.DS.SelectedSet.add(
|
|
1930
|
-
/** @type {DSElement} */
|
|
1931
|
-
clickedElement);
|
|
2197
|
+
_this.DS.SelectedSet.add( /** @type {DSElement} */clickedElement);
|
|
1932
2198
|
}
|
|
1933
2199
|
}
|
|
1934
|
-
|
|
1935
2200
|
if (_this.DS.SelectedSet.has(clickedElement)) return true;
|
|
1936
2201
|
return false;
|
|
1937
2202
|
});
|
|
1938
|
-
|
|
1939
2203
|
_defineProperty(this, "onClick", function (_ref2) {
|
|
1940
2204
|
var event = _ref2.event;
|
|
1941
2205
|
if (!_this._canInteract(event)) return;
|
|
1942
2206
|
if (event.detail > 0) return; // mouse interaction
|
|
1943
|
-
|
|
1944
2207
|
var _this$DS = _this.DS,
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
2208
|
+
_this$DS$stores = _this$DS.stores,
|
|
2209
|
+
PointerStore = _this$DS$stores.PointerStore,
|
|
2210
|
+
KeyStore = _this$DS$stores.KeyStore,
|
|
2211
|
+
SelectableSet = _this$DS.SelectableSet,
|
|
2212
|
+
SelectedSet = _this$DS.SelectedSet;
|
|
1950
2213
|
PointerStore.start(event);
|
|
1951
|
-
var node =
|
|
1952
|
-
/** @type {any} */
|
|
1953
|
-
event.target;
|
|
2214
|
+
var node = /** @type {any} */event.target;
|
|
1954
2215
|
if (!SelectableSet.has(node)) return;
|
|
1955
2216
|
if (!KeyStore.isMultiSelectKeyPressed(event)) SelectedSet.clear();
|
|
1956
2217
|
SelectedSet.toggle(node);
|
|
1957
|
-
|
|
1958
2218
|
_this.reset(); // simulate mouse-up (that does not exist on keyboard)
|
|
1959
|
-
|
|
1960
2219
|
});
|
|
1961
|
-
|
|
1962
2220
|
_defineProperty(this, "stop", function () {
|
|
1963
2221
|
_this.isInteracting = false;
|
|
1964
|
-
_this.isDragging = false;
|
|
2222
|
+
_this.isDragging = false;
|
|
1965
2223
|
|
|
2224
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1966
2225
|
if (_this.Settings.usePointerEvents) {
|
|
1967
2226
|
_this.DS.Area.HTMLNode.removeEventListener('pointerdown', _this.start, {
|
|
1968
2227
|
// @ts-ignore
|
|
1969
2228
|
passive: false
|
|
1970
2229
|
});
|
|
1971
|
-
|
|
1972
2230
|
document.removeEventListener('pointerup', _this.reset);
|
|
1973
2231
|
document.removeEventListener('pointercancel', _this.reset);
|
|
1974
2232
|
} else {
|
|
1975
2233
|
_this.DS.Area.HTMLNode.removeEventListener('mousedown', _this.start);
|
|
1976
|
-
|
|
1977
2234
|
document.removeEventListener('mouseup', _this.reset);
|
|
1978
2235
|
}
|
|
1979
|
-
|
|
1980
2236
|
_this.DS.Area.HTMLNode.removeEventListener('touchstart', _this.start, {
|
|
1981
2237
|
// @ts-ignore
|
|
1982
2238
|
passive: false
|
|
1983
2239
|
});
|
|
1984
|
-
|
|
1985
2240
|
document.removeEventListener('touchend', _this.reset);
|
|
1986
2241
|
});
|
|
1987
|
-
|
|
1988
2242
|
_defineProperty(this, "update", function (_ref3) {
|
|
1989
2243
|
var event = _ref3.event,
|
|
1990
|
-
|
|
1991
|
-
|
|
2244
|
+
scroll_directions = _ref3.scroll_directions,
|
|
2245
|
+
scroll_multiplier = _ref3.scroll_multiplier;
|
|
1992
2246
|
if (_this.isInteracting) _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], {
|
|
1993
2247
|
event: event,
|
|
1994
2248
|
scroll_directions: scroll_directions,
|
|
@@ -1996,30 +2250,24 @@
|
|
|
1996
2250
|
isDragging: _this.isDragging
|
|
1997
2251
|
});
|
|
1998
2252
|
});
|
|
1999
|
-
|
|
2000
2253
|
_defineProperty(this, "reset", function (event) {
|
|
2001
2254
|
return _this.DS.publish('Interaction:end:pre', {
|
|
2002
2255
|
event: event,
|
|
2003
2256
|
isDragging: _this.isDragging
|
|
2004
2257
|
});
|
|
2005
2258
|
});
|
|
2006
|
-
|
|
2007
2259
|
_defineProperty(this, "_reset", function (event) {
|
|
2008
2260
|
var isDragging = _this.isDragging;
|
|
2009
|
-
|
|
2010
2261
|
_this.stop();
|
|
2011
|
-
|
|
2012
2262
|
_this.init();
|
|
2013
|
-
|
|
2014
2263
|
_this.DS.publish('Interaction:end', {
|
|
2015
2264
|
event: event,
|
|
2016
2265
|
isDragging: isDragging
|
|
2017
2266
|
});
|
|
2018
2267
|
});
|
|
2019
|
-
|
|
2020
2268
|
this.DS = DS;
|
|
2021
|
-
this.Settings = DS.stores.SettingsStore.s;
|
|
2022
|
-
|
|
2269
|
+
this.Settings = DS.stores.SettingsStore.s;
|
|
2270
|
+
// @ts-ignore: @todo: update to typescript
|
|
2023
2271
|
this.DS.subscribe('Settings:updated:area', this.init);
|
|
2024
2272
|
this.DS.subscribe('PointerStore:updated', this.update);
|
|
2025
2273
|
this.DS.subscribe('Selectable:click', this.onClick);
|
|
@@ -2038,28 +2286,19 @@
|
|
|
2038
2286
|
});
|
|
2039
2287
|
this.DS.subscribe('Area:scroll', this.update);
|
|
2040
2288
|
}
|
|
2041
|
-
|
|
2042
2289
|
_createClass(Interaction, [{
|
|
2043
2290
|
key: "_canInteract",
|
|
2044
|
-
|
|
2045
2291
|
/**
|
|
2046
2292
|
* @param {DSEvent} event
|
|
2047
2293
|
*/
|
|
2048
2294
|
value: function _canInteract(event) {
|
|
2049
|
-
var isKeyboardClick =
|
|
2050
|
-
/** @type {MouseEvent} */
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
/** @type {
|
|
2055
|
-
|
|
2056
|
-
if (
|
|
2057
|
-
/** @type {MouseEvent} */
|
|
2058
|
-
event.button === 2 || // right-clicks
|
|
2059
|
-
this.isInteracting || // fix double-click issues
|
|
2060
|
-
event.target && !this.DS.SelectorArea.isInside(
|
|
2061
|
-
/** @type {DSElement} */
|
|
2062
|
-
event.target) || //fix outside elements issue
|
|
2295
|
+
var isKeyboardClick = /** @type {MouseEvent} */event.clientX === 0 && /** @type {MouseEvent} */event.clientY === 0 && /** @type {MouseEvent} */event.detail === 0 && event.target;
|
|
2296
|
+
if ( /** @type {MouseEvent} */event.button === 2 ||
|
|
2297
|
+
// right-clicks
|
|
2298
|
+
this.isInteracting ||
|
|
2299
|
+
// fix double-click issues
|
|
2300
|
+
event.target && !this.DS.SelectorArea.isInside( /** @type {DSElement} */event.target) ||
|
|
2301
|
+
//fix outside elements issue
|
|
2063
2302
|
!isKeyboardClick && !this.DS.SelectorArea.isClicked(event) // make sure the mouse click is inside the area
|
|
2064
2303
|
) return false;
|
|
2065
2304
|
return true;
|
|
@@ -2067,65 +2306,51 @@
|
|
|
2067
2306
|
/**
|
|
2068
2307
|
* @param {DSEvent} event
|
|
2069
2308
|
*/
|
|
2070
|
-
|
|
2071
2309
|
}]);
|
|
2072
|
-
|
|
2073
2310
|
return Interaction;
|
|
2074
2311
|
}();
|
|
2075
2312
|
|
|
2076
2313
|
var PubSub = function PubSub(_ref) {
|
|
2077
2314
|
var _this = this;
|
|
2078
|
-
|
|
2079
2315
|
var DS = _ref.DS;
|
|
2080
|
-
|
|
2081
2316
|
_classCallCheck(this, PubSub);
|
|
2082
|
-
|
|
2083
2317
|
_defineProperty(this, "subscribers", {});
|
|
2084
|
-
|
|
2085
2318
|
_defineProperty(this, "subscribe", function (eventName, callback) {
|
|
2086
2319
|
if (!Array.isArray(_this.subscribers[eventName])) _this.subscribers[eventName] = [];
|
|
2087
|
-
|
|
2088
2320
|
_this.subscribers[eventName].push(callback);
|
|
2089
|
-
|
|
2090
2321
|
return _this.subscribers[eventName].length - 1;
|
|
2091
2322
|
});
|
|
2092
|
-
|
|
2093
2323
|
_defineProperty(this, "unsubscribe", function (eventName, callback, id) {
|
|
2094
2324
|
if (id >= 0) _this.subscribers[eventName].splice(id, 1);else if (callback) _this.subscribers[eventName] = _this.subscribers[eventName].filter(function (cb) {
|
|
2095
2325
|
return cb !== callback;
|
|
2096
2326
|
});
|
|
2097
2327
|
});
|
|
2098
|
-
|
|
2099
2328
|
_defineProperty(this, "publish", function (eventName, data) {
|
|
2100
2329
|
if (Array.isArray(eventName)) eventName.forEach(function (name) {
|
|
2101
2330
|
return _this._publish(name, data);
|
|
2102
2331
|
});else _this._publish(eventName, data);
|
|
2103
2332
|
});
|
|
2104
|
-
|
|
2105
2333
|
_defineProperty(this, "_publish", function (eventName, data) {
|
|
2106
2334
|
var subscribers = _this.subscribers[eventName];
|
|
2107
2335
|
if (!Array.isArray(subscribers)) return;
|
|
2108
2336
|
if (eventName.includes(":pre")) _this._handlePrePublish(subscribers, data);else _this._handlePublish(subscribers, data);
|
|
2109
2337
|
});
|
|
2110
|
-
|
|
2111
2338
|
_defineProperty(this, "_handlePublish", function (subscribers, data) {
|
|
2112
2339
|
for (var i = 0, il = subscribers.length; i < il; i++) {
|
|
2113
2340
|
if (_this.DS.stopped) return;
|
|
2114
2341
|
subscribers[i](data);
|
|
2115
2342
|
}
|
|
2116
2343
|
});
|
|
2117
|
-
|
|
2118
2344
|
_defineProperty(this, "_handlePrePublish", function (subscribers, data) {
|
|
2119
2345
|
var i = subscribers.length;
|
|
2120
|
-
|
|
2121
2346
|
while (i--) {
|
|
2122
2347
|
if (_this.DS.stopped) return;
|
|
2123
2348
|
subscribers[i](data);
|
|
2124
2349
|
}
|
|
2125
2350
|
});
|
|
2126
|
-
|
|
2127
2351
|
this.DS = DS;
|
|
2128
2352
|
}
|
|
2353
|
+
|
|
2129
2354
|
/**
|
|
2130
2355
|
* Subscribe to an event
|
|
2131
2356
|
* @memberof DragSelect#
|
|
@@ -2133,13 +2358,20 @@
|
|
|
2133
2358
|
* @param {DSCallbackNames} eventName
|
|
2134
2359
|
* @param {DSCallback} callback
|
|
2135
2360
|
* @returns {number} event id, can be used to unsubscribe more efficiently
|
|
2136
|
-
|
|
2137
|
-
;
|
|
2361
|
+
*/;
|
|
2138
2362
|
|
|
2139
2363
|
var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
2140
2364
|
_inherits(SelectableSet, _Set);
|
|
2141
|
-
|
|
2142
2365
|
var _super = _createSuper(SelectableSet);
|
|
2366
|
+
/**
|
|
2367
|
+
* @type {Map<DSElement,DSBoundingRect>}
|
|
2368
|
+
* @private
|
|
2369
|
+
*/
|
|
2370
|
+
|
|
2371
|
+
/**
|
|
2372
|
+
* @type {NodeJS.Timeout}
|
|
2373
|
+
* @private
|
|
2374
|
+
*/
|
|
2143
2375
|
|
|
2144
2376
|
/**
|
|
2145
2377
|
* @constructor SelectableSet
|
|
@@ -2148,79 +2380,62 @@
|
|
|
2148
2380
|
*/
|
|
2149
2381
|
function SelectableSet(_ref) {
|
|
2150
2382
|
var _this;
|
|
2151
|
-
|
|
2152
2383
|
var DS = _ref.DS;
|
|
2153
|
-
|
|
2154
2384
|
_classCallCheck(this, SelectableSet);
|
|
2155
|
-
|
|
2156
2385
|
_this = _super.call(this);
|
|
2157
|
-
|
|
2386
|
+
_defineProperty(_assertThisInitialized(_this), "_rects", void 0);
|
|
2387
|
+
_defineProperty(_assertThisInitialized(_this), "_timeout", void 0);
|
|
2158
2388
|
_defineProperty(_assertThisInitialized(_this), "init", function () {
|
|
2159
2389
|
return toArray(_this.Settings.selectables).forEach(function (el) {
|
|
2160
2390
|
return _this.add(el);
|
|
2161
2391
|
});
|
|
2162
2392
|
});
|
|
2163
|
-
|
|
2164
2393
|
_defineProperty(_assertThisInitialized(_this), "clear", function () {
|
|
2165
2394
|
return _this.forEach(function (el) {
|
|
2166
2395
|
return _this["delete"](el);
|
|
2167
2396
|
});
|
|
2168
2397
|
});
|
|
2169
|
-
|
|
2170
2398
|
_defineProperty(_assertThisInitialized(_this), "_onClick", function (event) {
|
|
2171
2399
|
return _this.DS.publish(['Selectable:click:pre', 'Selectable:click'], {
|
|
2172
2400
|
event: event
|
|
2173
2401
|
});
|
|
2174
2402
|
});
|
|
2175
|
-
|
|
2176
2403
|
_defineProperty(_assertThisInitialized(_this), "_onPointer", function (event) {
|
|
2177
2404
|
return _this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], {
|
|
2178
2405
|
event: event
|
|
2179
2406
|
});
|
|
2180
2407
|
});
|
|
2181
|
-
|
|
2182
2408
|
_defineProperty(_assertThisInitialized(_this), "addAll", function (elements) {
|
|
2183
2409
|
return elements.forEach(function (el) {
|
|
2184
2410
|
return _this.add(el);
|
|
2185
2411
|
});
|
|
2186
2412
|
});
|
|
2187
|
-
|
|
2188
2413
|
_defineProperty(_assertThisInitialized(_this), "deleteAll", function (elements) {
|
|
2189
2414
|
return elements.forEach(function (el) {
|
|
2190
2415
|
return _this["delete"](el);
|
|
2191
2416
|
});
|
|
2192
2417
|
});
|
|
2193
|
-
|
|
2194
2418
|
_this.DS = DS;
|
|
2195
2419
|
_this.Settings = DS.stores.SettingsStore.s;
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2420
|
+
_this.DS.subscribe('Interaction:init', _this.init);
|
|
2421
|
+
// @ts-ignore: @todo: update to typescript
|
|
2200
2422
|
_this.DS.PubSub.subscribe('Settings:updated:selectables', function () {
|
|
2201
2423
|
_this.clear();
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2424
|
+
_this.init();
|
|
2425
|
+
});
|
|
2426
|
+
// @ts-ignore: @todo: update to typescript
|
|
2207
2427
|
_this.DS.subscribe('Settings:updated:selectableClass', function (_ref2) {
|
|
2208
2428
|
var settings = _ref2.settings;
|
|
2209
|
-
|
|
2210
2429
|
_this.forEach(function (el) {
|
|
2211
2430
|
el.classList.remove(settings['selectableClass:pre']);
|
|
2212
2431
|
el.classList.add(settings['selectableClass']);
|
|
2213
2432
|
});
|
|
2214
2433
|
});
|
|
2215
|
-
|
|
2216
2434
|
return _this;
|
|
2217
2435
|
}
|
|
2218
|
-
|
|
2219
2436
|
_createClass(SelectableSet, [{
|
|
2220
2437
|
key: "add",
|
|
2221
|
-
|
|
2222
|
-
/** @param {DSElement} element */
|
|
2223
|
-
value: function add(element) {
|
|
2438
|
+
/** @param {DSElement} element */value: function add(element) {
|
|
2224
2439
|
if (_get(_getPrototypeOf(SelectableSet.prototype), "has", this).call(this, element)) return;
|
|
2225
2440
|
var publishData = {
|
|
2226
2441
|
items: this.elements,
|
|
@@ -2243,9 +2458,7 @@
|
|
|
2243
2458
|
});
|
|
2244
2459
|
this.DS.publish('Selectable:added', publishData);
|
|
2245
2460
|
return _get(_getPrototypeOf(SelectableSet.prototype), "add", this).call(this, element);
|
|
2246
|
-
}
|
|
2247
|
-
/** @param {DSElement} element */
|
|
2248
|
-
|
|
2461
|
+
} /** @param {DSElement} element */
|
|
2249
2462
|
}, {
|
|
2250
2463
|
key: "delete",
|
|
2251
2464
|
value: function _delete(element) {
|
|
@@ -2271,21 +2484,33 @@
|
|
|
2271
2484
|
}
|
|
2272
2485
|
}, {
|
|
2273
2486
|
key: "elements",
|
|
2274
|
-
|
|
2275
|
-
/** @return {DSElements} */
|
|
2276
|
-
get: function get() {
|
|
2487
|
+
/** @return {DSElements} */get: function get() {
|
|
2277
2488
|
return Array.from(this.values());
|
|
2278
2489
|
}
|
|
2279
|
-
}
|
|
2490
|
+
}, {
|
|
2491
|
+
key: "rects",
|
|
2492
|
+
get: function get() {
|
|
2493
|
+
var _this2 = this;
|
|
2494
|
+
if (this._rects) return this._rects;
|
|
2495
|
+
this._rects = new Map();
|
|
2496
|
+
this.forEach(function (element) {
|
|
2497
|
+
return _this2._rects.set(element, element.getBoundingClientRect());
|
|
2498
|
+
});
|
|
2280
2499
|
|
|
2500
|
+
// since elements can be moved, we need to update the rects every X ms
|
|
2501
|
+
if (this._timeout) clearTimeout(this._timeout);
|
|
2502
|
+
this._timeout = setTimeout(function () {
|
|
2503
|
+
return _this2._rects = null;
|
|
2504
|
+
}, this.Settings.refreshMemoryRate);
|
|
2505
|
+
return this._rects;
|
|
2506
|
+
}
|
|
2507
|
+
}]);
|
|
2281
2508
|
return SelectableSet;
|
|
2282
2509
|
}( /*#__PURE__*/_wrapNativeSuper(Set));
|
|
2283
2510
|
|
|
2284
2511
|
var SelectedSet = /*#__PURE__*/function (_Set) {
|
|
2285
2512
|
_inherits(SelectedSet, _Set);
|
|
2286
|
-
|
|
2287
2513
|
var _super = _createSuper(SelectedSet);
|
|
2288
|
-
|
|
2289
2514
|
/**
|
|
2290
2515
|
* @constructor SelectableSet
|
|
2291
2516
|
* @param {{DS:DragSelect}} obj
|
|
@@ -2293,37 +2518,29 @@
|
|
|
2293
2518
|
*/
|
|
2294
2519
|
function SelectedSet(_ref) {
|
|
2295
2520
|
var _this;
|
|
2296
|
-
|
|
2297
2521
|
var DS = _ref.DS;
|
|
2298
|
-
|
|
2299
2522
|
_classCallCheck(this, SelectedSet);
|
|
2300
|
-
|
|
2301
2523
|
_this = _super.call(this);
|
|
2302
|
-
|
|
2303
2524
|
_defineProperty(_assertThisInitialized(_this), "clear", function () {
|
|
2304
2525
|
return _this.forEach(function (el) {
|
|
2305
2526
|
return _this["delete"](el);
|
|
2306
2527
|
});
|
|
2307
2528
|
});
|
|
2308
|
-
|
|
2309
2529
|
_defineProperty(_assertThisInitialized(_this), "addAll", function (elements) {
|
|
2310
2530
|
return elements.forEach(function (el) {
|
|
2311
2531
|
return _this.add(el);
|
|
2312
2532
|
});
|
|
2313
2533
|
});
|
|
2314
|
-
|
|
2315
2534
|
_defineProperty(_assertThisInitialized(_this), "deleteAll", function (elements) {
|
|
2316
2535
|
return elements.forEach(function (el) {
|
|
2317
2536
|
return _this["delete"](el);
|
|
2318
2537
|
});
|
|
2319
2538
|
});
|
|
2320
|
-
|
|
2321
2539
|
_this.DS = DS;
|
|
2322
2540
|
return _this;
|
|
2323
2541
|
}
|
|
2324
|
-
/** @param {DSElement} element */
|
|
2325
|
-
|
|
2326
2542
|
|
|
2543
|
+
/** @param {DSElement} element */
|
|
2327
2544
|
_createClass(SelectedSet, [{
|
|
2328
2545
|
key: "add",
|
|
2329
2546
|
value: function add(element) {
|
|
@@ -2333,16 +2550,12 @@
|
|
|
2333
2550
|
item: element
|
|
2334
2551
|
};
|
|
2335
2552
|
this.DS.publish('Selected:added:pre', publishData);
|
|
2336
|
-
|
|
2337
2553
|
_get(_getPrototypeOf(SelectedSet.prototype), "add", this).call(this, element);
|
|
2338
|
-
|
|
2339
2554
|
element.classList.add(this.DS.stores.SettingsStore.s.selectedClass);
|
|
2340
2555
|
element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + 1);
|
|
2341
2556
|
this.DS.publish('Selected:added', publishData);
|
|
2342
2557
|
return this;
|
|
2343
|
-
}
|
|
2344
|
-
/** @param {DSElement} element */
|
|
2345
|
-
|
|
2558
|
+
} /** @param {DSElement} element */
|
|
2346
2559
|
}, {
|
|
2347
2560
|
key: "delete",
|
|
2348
2561
|
value: function _delete(element) {
|
|
@@ -2352,9 +2565,7 @@
|
|
|
2352
2565
|
item: element
|
|
2353
2566
|
};
|
|
2354
2567
|
this.DS.publish('Selected:removed:pre', publishData);
|
|
2355
|
-
|
|
2356
2568
|
var deleted = _get(_getPrototypeOf(SelectedSet.prototype), "delete", this).call(this, element);
|
|
2357
|
-
|
|
2358
2569
|
element.classList.remove(this.DS.stores.SettingsStore.s.selectedClass);
|
|
2359
2570
|
element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) - 1);
|
|
2360
2571
|
this.DS.publish('Selected:removed', publishData);
|
|
@@ -2362,7 +2573,6 @@
|
|
|
2362
2573
|
}
|
|
2363
2574
|
}, {
|
|
2364
2575
|
key: "toggle",
|
|
2365
|
-
|
|
2366
2576
|
/**
|
|
2367
2577
|
* Adds/Removes an element. If it is already selected = remove, if not = add.
|
|
2368
2578
|
* @param {DSElement} element
|
|
@@ -2371,18 +2581,13 @@
|
|
|
2371
2581
|
value: function toggle(element) {
|
|
2372
2582
|
if (this.has(element)) this["delete"](element);else this.add(element);
|
|
2373
2583
|
return element;
|
|
2374
|
-
}
|
|
2375
|
-
/** @param {DSElements} elements */
|
|
2376
|
-
|
|
2584
|
+
} /** @param {DSElements} elements */
|
|
2377
2585
|
}, {
|
|
2378
2586
|
key: "elements",
|
|
2379
|
-
|
|
2380
|
-
/** @return {DSElements} */
|
|
2381
|
-
get: function get() {
|
|
2587
|
+
/** @return {DSElements} */get: function get() {
|
|
2382
2588
|
return Array.from(this.values());
|
|
2383
2589
|
}
|
|
2384
2590
|
}]);
|
|
2385
|
-
|
|
2386
2591
|
return SelectedSet;
|
|
2387
2592
|
}( /*#__PURE__*/_wrapNativeSuper(Set));
|
|
2388
2593
|
|
|
@@ -2399,50 +2604,46 @@
|
|
|
2399
2604
|
*/
|
|
2400
2605
|
function Selection(_ref) {
|
|
2401
2606
|
var _this = this;
|
|
2402
|
-
|
|
2403
2607
|
var DS = _ref.DS;
|
|
2404
|
-
|
|
2405
2608
|
_classCallCheck(this, Selection);
|
|
2406
|
-
|
|
2407
2609
|
_defineProperty(this, "_prevSelectedSet", void 0);
|
|
2408
|
-
|
|
2409
2610
|
_defineProperty(this, "start", function (_ref2) {
|
|
2410
2611
|
var event = _ref2.event,
|
|
2411
|
-
|
|
2612
|
+
isDragging = _ref2.isDragging;
|
|
2412
2613
|
if (isDragging) return;
|
|
2413
|
-
|
|
2414
2614
|
_this._storePrevious(event);
|
|
2415
|
-
|
|
2416
2615
|
_this._handleInsideSelection(true, event);
|
|
2417
2616
|
});
|
|
2418
|
-
|
|
2419
2617
|
_defineProperty(this, "update", function (_ref3) {
|
|
2420
2618
|
var isDragging = _ref3.isDragging;
|
|
2421
2619
|
if (isDragging || _this.DS["continue"]) return;
|
|
2422
|
-
|
|
2423
2620
|
_this._handleInsideSelection();
|
|
2424
2621
|
});
|
|
2425
|
-
|
|
2426
2622
|
_defineProperty(this, "_handleInsideSelection", function (force, event) {
|
|
2427
2623
|
var _this$DS = _this.DS,
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2624
|
+
SelectableSet = _this$DS.SelectableSet,
|
|
2625
|
+
SelectorArea = _this$DS.SelectorArea,
|
|
2626
|
+
Selector = _this$DS.Selector;
|
|
2431
2627
|
/** @type {any} */
|
|
2432
|
-
|
|
2433
|
-
var elPosCombo = SelectableSet.elements.map(function (element) {
|
|
2434
|
-
return [element, element.getBoundingClientRect()];
|
|
2435
|
-
});
|
|
2628
|
+
var elRects = SelectableSet.rects;
|
|
2436
2629
|
var select = [];
|
|
2437
2630
|
var unselect = [];
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2631
|
+
var _iterator = _createForOfIteratorHelper(elRects),
|
|
2632
|
+
_step;
|
|
2633
|
+
try {
|
|
2634
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2635
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
2636
|
+
element = _step$value[0],
|
|
2637
|
+
rect = _step$value[1];
|
|
2638
|
+
if (!SelectorArea.isInside(element, rect)) continue;
|
|
2639
|
+
if (isCollision(rect, Selector.rect, _this.Settings.selectionThreshold)) select.push(element);else unselect.push(element);
|
|
2640
|
+
}
|
|
2641
|
+
} catch (err) {
|
|
2642
|
+
_iterator.e(err);
|
|
2643
|
+
} finally {
|
|
2644
|
+
_iterator.f();
|
|
2442
2645
|
}
|
|
2443
|
-
|
|
2444
|
-
var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this.DS.stores.SettingsStore.s.multiSelectToggling;
|
|
2445
|
-
|
|
2646
|
+
var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this.Settings.multiSelectToggling;
|
|
2446
2647
|
if (_this.DS["continue"]) return;
|
|
2447
2648
|
select.forEach(function (element) {
|
|
2448
2649
|
return handleSelection({
|
|
@@ -2450,7 +2651,7 @@
|
|
|
2450
2651
|
force: force,
|
|
2451
2652
|
multiSelectionToggle: multiSelectionToggle,
|
|
2452
2653
|
SelectedSet: _this.DS.SelectedSet,
|
|
2453
|
-
hoverClassName: _this.
|
|
2654
|
+
hoverClassName: _this.Settings.hoverClass
|
|
2454
2655
|
});
|
|
2455
2656
|
});
|
|
2456
2657
|
unselect.forEach(function (element) {
|
|
@@ -2458,35 +2659,31 @@
|
|
|
2458
2659
|
element: element,
|
|
2459
2660
|
force: force,
|
|
2460
2661
|
SelectedSet: _this.DS.SelectedSet,
|
|
2461
|
-
hoverClassName: _this.
|
|
2662
|
+
hoverClassName: _this.Settings.hoverClass,
|
|
2462
2663
|
PrevSelectedSet: _this._prevSelectedSet
|
|
2463
2664
|
});
|
|
2464
2665
|
});
|
|
2465
2666
|
});
|
|
2466
|
-
|
|
2467
2667
|
this.DS = DS;
|
|
2668
|
+
this.Settings = this.DS.stores.SettingsStore.s;
|
|
2468
2669
|
this.DS.subscribe('Interaction:start', this.start);
|
|
2469
2670
|
this.DS.subscribe('Interaction:update', this.update);
|
|
2470
2671
|
}
|
|
2672
|
+
|
|
2471
2673
|
/**
|
|
2472
2674
|
* Stores the previous selection (solves #9)
|
|
2473
2675
|
* @param {DSEvent} event
|
|
2474
2676
|
* @private
|
|
2475
2677
|
* */
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
2678
|
_createClass(Selection, [{
|
|
2479
2679
|
key: "_storePrevious",
|
|
2480
2680
|
value: function _storePrevious(event) {
|
|
2481
2681
|
var _this$DS2 = this.DS,
|
|
2482
|
-
|
|
2483
|
-
|
|
2682
|
+
KeyStore = _this$DS2.stores.KeyStore,
|
|
2683
|
+
SelectedSet = _this$DS2.SelectedSet;
|
|
2484
2684
|
if (KeyStore.isMultiSelectKeyPressed(event)) this._prevSelectedSet = new Set(SelectedSet);else this._prevSelectedSet = new Set();
|
|
2485
|
-
}
|
|
2486
|
-
/** @param {{event:DSEvent,isDragging:boolean}} event */
|
|
2487
|
-
|
|
2685
|
+
} /** @param {{event:DSEvent,isDragging:boolean}} event */
|
|
2488
2686
|
}]);
|
|
2489
|
-
|
|
2490
2687
|
return Selection;
|
|
2491
2688
|
}();
|
|
2492
2689
|
|
|
@@ -2503,24 +2700,16 @@
|
|
|
2503
2700
|
*/
|
|
2504
2701
|
function Selector(_ref) {
|
|
2505
2702
|
var _this = this;
|
|
2506
|
-
|
|
2507
2703
|
var DS = _ref.DS;
|
|
2508
|
-
|
|
2509
2704
|
_classCallCheck(this, Selector);
|
|
2510
|
-
|
|
2511
2705
|
_defineProperty(this, "_rect", void 0);
|
|
2512
|
-
|
|
2513
2706
|
_defineProperty(this, "attachSelector", function () {
|
|
2514
2707
|
var _this$DS$SelectorArea, _this$DS$SelectorArea2;
|
|
2515
|
-
|
|
2516
2708
|
if (_this.HTMLNode && (_this$DS$SelectorArea = _this.DS.SelectorArea) !== null && _this$DS$SelectorArea !== void 0 && _this$DS$SelectorArea.HTMLNode) _this.DS.SelectorArea.HTMLNode.removeChild(_this.HTMLNode);
|
|
2517
2709
|
_this.HTMLNode = _this.DS.stores.SettingsStore.s.selector || createSelectorElement(_this.DS.stores.SettingsStore.s.customStyles);
|
|
2518
|
-
|
|
2519
2710
|
_this.HTMLNode.classList.add(_this.DS.stores.SettingsStore.s.selectorClass);
|
|
2520
|
-
|
|
2521
2711
|
if (_this.HTMLNode && (_this$DS$SelectorArea2 = _this.DS.SelectorArea) !== null && _this$DS$SelectorArea2 !== void 0 && _this$DS$SelectorArea2.HTMLNode) _this.DS.SelectorArea.HTMLNode.appendChild(_this.HTMLNode);
|
|
2522
2712
|
});
|
|
2523
|
-
|
|
2524
2713
|
_defineProperty(this, "start", function (_ref2) {
|
|
2525
2714
|
var isDragging = _ref2.isDragging;
|
|
2526
2715
|
if (isDragging) return;
|
|
@@ -2530,19 +2719,17 @@
|
|
|
2530
2719
|
_this.HTMLNode.style.display = 'block';
|
|
2531
2720
|
_this._rect = null;
|
|
2532
2721
|
});
|
|
2533
|
-
|
|
2534
2722
|
_defineProperty(this, "stop", function () {
|
|
2535
2723
|
_this.HTMLNode.style.width = '0';
|
|
2536
2724
|
_this.HTMLNode.style.height = '0';
|
|
2537
2725
|
_this.HTMLNode.style.display = 'none';
|
|
2538
2726
|
});
|
|
2539
|
-
|
|
2540
2727
|
_defineProperty(this, "update", function (_ref3) {
|
|
2541
2728
|
var isDragging = _ref3.isDragging;
|
|
2542
2729
|
if (isDragging || _this.DS["continue"]) return;
|
|
2543
2730
|
var _this$DS$stores = _this.DS.stores,
|
|
2544
|
-
|
|
2545
|
-
|
|
2731
|
+
ScrollStore = _this$DS$stores.ScrollStore,
|
|
2732
|
+
PointerStore = _this$DS$stores.PointerStore;
|
|
2546
2733
|
var pos = getSelectorPosition({
|
|
2547
2734
|
scrollAmount: ScrollStore.scrollAmount,
|
|
2548
2735
|
initialPointerPos: PointerStore.initialValArea,
|
|
@@ -2551,24 +2738,21 @@
|
|
|
2551
2738
|
updateElementStylePos(_this.HTMLNode, pos);
|
|
2552
2739
|
_this._rect = null;
|
|
2553
2740
|
});
|
|
2741
|
+
this.DS = DS;
|
|
2554
2742
|
|
|
2555
|
-
|
|
2556
|
-
|
|
2743
|
+
// @ts-ignore: @todo: update to typescript
|
|
2557
2744
|
this.DS.subscribe('Settings:updated:selectorClass', function (_ref4) {
|
|
2558
2745
|
var settings = _ref4.settings;
|
|
2559
|
-
|
|
2560
2746
|
_this.HTMLNode.classList.remove(settings['selectorClass:pre']);
|
|
2561
|
-
|
|
2562
2747
|
_this.HTMLNode.classList.add(settings['selectorClass']);
|
|
2563
|
-
});
|
|
2564
|
-
|
|
2748
|
+
});
|
|
2749
|
+
// @ts-ignore: @todo: update to typescript
|
|
2565
2750
|
this.DS.subscribe('Settings:updated:selector', this.attachSelector);
|
|
2566
2751
|
this.attachSelector();
|
|
2567
2752
|
this.DS.subscribe('Interaction:start', this.start);
|
|
2568
2753
|
this.DS.subscribe('Interaction:update', this.update);
|
|
2569
2754
|
this.DS.subscribe('Interaction:end', this.stop);
|
|
2570
2755
|
}
|
|
2571
|
-
|
|
2572
2756
|
_createClass(Selector, [{
|
|
2573
2757
|
key: "rect",
|
|
2574
2758
|
get: function get() {
|
|
@@ -2576,7 +2760,6 @@
|
|
|
2576
2760
|
return this._rect = this.HTMLNode.getBoundingClientRect();
|
|
2577
2761
|
}
|
|
2578
2762
|
}]);
|
|
2579
|
-
|
|
2580
2763
|
return Selector;
|
|
2581
2764
|
}();
|
|
2582
2765
|
|
|
@@ -2604,31 +2787,21 @@
|
|
|
2604
2787
|
*/
|
|
2605
2788
|
function SelectorArea(_ref) {
|
|
2606
2789
|
var _this = this;
|
|
2607
|
-
|
|
2608
2790
|
var DS = _ref.DS;
|
|
2609
|
-
|
|
2610
2791
|
_classCallCheck(this, SelectorArea);
|
|
2611
|
-
|
|
2612
2792
|
_defineProperty(this, "_scrollInterval", void 0);
|
|
2613
|
-
|
|
2614
2793
|
_defineProperty(this, "_rect", void 0);
|
|
2615
|
-
|
|
2616
2794
|
_defineProperty(this, "currentEdges", []);
|
|
2617
|
-
|
|
2618
2795
|
_defineProperty(this, "start", function () {
|
|
2619
2796
|
return _this.applyElements('append');
|
|
2620
2797
|
});
|
|
2621
|
-
|
|
2622
2798
|
_defineProperty(this, "applyElements", function () {
|
|
2623
2799
|
var method = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'append';
|
|
2624
2800
|
var docEl = document.body ? 'body' : 'documentElement';
|
|
2625
2801
|
var methodName = "".concat(method, "Child");
|
|
2626
|
-
|
|
2627
2802
|
_this.HTMLNode[methodName](_this.DS.Selector.HTMLNode);
|
|
2628
|
-
|
|
2629
2803
|
document[docEl][methodName](_this.HTMLNode);
|
|
2630
2804
|
});
|
|
2631
|
-
|
|
2632
2805
|
_defineProperty(this, "updatePos", function () {
|
|
2633
2806
|
_this._rect = null;
|
|
2634
2807
|
var rect = _this.DS.Area.rect;
|
|
@@ -2643,25 +2816,21 @@
|
|
|
2643
2816
|
if (style.width !== width) style.width = width;
|
|
2644
2817
|
if (style.height !== height) style.height = height;
|
|
2645
2818
|
});
|
|
2646
|
-
|
|
2647
2819
|
_defineProperty(this, "stop", function (remove) {
|
|
2648
2820
|
_this.stopAutoScroll();
|
|
2649
|
-
|
|
2650
2821
|
if (remove) _this.applyElements('remove');
|
|
2651
2822
|
});
|
|
2652
|
-
|
|
2653
2823
|
_defineProperty(this, "startAutoScroll", function () {
|
|
2654
2824
|
_this.currentEdges = [];
|
|
2655
2825
|
_this._scrollInterval = setInterval(function () {
|
|
2656
2826
|
return _this.handleAutoScroll();
|
|
2657
2827
|
}, 16);
|
|
2658
2828
|
});
|
|
2659
|
-
|
|
2660
2829
|
_defineProperty(this, "handleAutoScroll", function () {
|
|
2661
2830
|
if (_this.DS["continue"]) return;
|
|
2662
2831
|
var _this$DS = _this.DS,
|
|
2663
|
-
|
|
2664
|
-
|
|
2832
|
+
PointerStore = _this$DS.stores.PointerStore,
|
|
2833
|
+
Area = _this$DS.Area;
|
|
2665
2834
|
_this.currentEdges = getOverflowEdges({
|
|
2666
2835
|
elementRect: vect2rect(PointerStore.currentVal),
|
|
2667
2836
|
containerRect: _this.rect,
|
|
@@ -2669,25 +2838,20 @@
|
|
|
2669
2838
|
});
|
|
2670
2839
|
if (_this.currentEdges.length) Area.scroll(_this.currentEdges, _this.DS.stores.SettingsStore.s.autoScrollSpeed);
|
|
2671
2840
|
});
|
|
2672
|
-
|
|
2673
2841
|
_defineProperty(this, "stopAutoScroll", function () {
|
|
2674
2842
|
_this.currentEdges = [];
|
|
2675
2843
|
clearInterval(_this._scrollInterval);
|
|
2676
2844
|
});
|
|
2677
|
-
|
|
2678
2845
|
_defineProperty(this, "isInside", function (element, elementRect) {
|
|
2679
2846
|
if (_this.DS.Area.HTMLNode.contains(element) && _this.DS.stores.ScrollStore.canScroll) return true;
|
|
2680
2847
|
return isCollision(_this.rect, elementRect || element.getBoundingClientRect());
|
|
2681
2848
|
});
|
|
2682
|
-
|
|
2683
2849
|
this.DS = DS;
|
|
2684
|
-
this.HTMLNode = createSelectorAreaElement();
|
|
2685
|
-
|
|
2850
|
+
this.HTMLNode = createSelectorAreaElement();
|
|
2851
|
+
// @ts-ignore: @todo: update to typescript
|
|
2686
2852
|
this.DS.subscribe('Settings:updated:selectorAreaClass', function (_ref2) {
|
|
2687
2853
|
var settings = _ref2.settings;
|
|
2688
|
-
|
|
2689
2854
|
_this.HTMLNode.classList.remove(settings['selectorAreaClass:pre']);
|
|
2690
|
-
|
|
2691
2855
|
_this.HTMLNode.classList.add(settings['selectorAreaClass']);
|
|
2692
2856
|
});
|
|
2693
2857
|
this.HTMLNode.classList.add(this.DS.stores.SettingsStore.s.selectorAreaClass);
|
|
@@ -2697,14 +2861,11 @@
|
|
|
2697
2861
|
this.DS.subscribe('Interaction:start', this.startAutoScroll);
|
|
2698
2862
|
this.DS.subscribe('Interaction:end', function () {
|
|
2699
2863
|
_this.updatePos();
|
|
2700
|
-
|
|
2701
2864
|
_this.stopAutoScroll();
|
|
2702
2865
|
});
|
|
2703
2866
|
}
|
|
2704
|
-
|
|
2705
2867
|
_createClass(SelectorArea, [{
|
|
2706
2868
|
key: "isClicked",
|
|
2707
|
-
|
|
2708
2869
|
/**
|
|
2709
2870
|
* checks if the click was triggered on the area.
|
|
2710
2871
|
* @param {DSEvent} [event]
|
|
@@ -2727,7 +2888,6 @@
|
|
|
2727
2888
|
return this._rect = this.HTMLNode.getBoundingClientRect();
|
|
2728
2889
|
}
|
|
2729
2890
|
}]);
|
|
2730
|
-
|
|
2731
2891
|
return SelectorArea;
|
|
2732
2892
|
}();
|
|
2733
2893
|
|
|
@@ -2750,80 +2910,59 @@
|
|
|
2750
2910
|
*/
|
|
2751
2911
|
function KeyStore(_ref) {
|
|
2752
2912
|
var _this = this;
|
|
2753
|
-
|
|
2754
2913
|
var DS = _ref.DS;
|
|
2755
|
-
|
|
2756
2914
|
_classCallCheck(this, KeyStore);
|
|
2757
|
-
|
|
2758
2915
|
_defineProperty(this, "_currentValues", new Set());
|
|
2759
|
-
|
|
2760
2916
|
_defineProperty(this, "_keyMapping", {
|
|
2761
2917
|
control: 'ctrlKey',
|
|
2762
2918
|
shift: 'shiftKey',
|
|
2763
2919
|
meta: 'metaKey'
|
|
2764
2920
|
});
|
|
2765
|
-
|
|
2766
2921
|
_defineProperty(this, "init", function () {
|
|
2767
2922
|
document.addEventListener('keydown', _this.keydown);
|
|
2768
2923
|
document.addEventListener('keyup', _this.keyup);
|
|
2769
2924
|
window.addEventListener('blur', _this.reset);
|
|
2770
2925
|
});
|
|
2771
|
-
|
|
2772
2926
|
_defineProperty(this, "keydown", function (event) {
|
|
2773
2927
|
var key = event.key.toLowerCase();
|
|
2774
|
-
|
|
2775
2928
|
_this.DS.publish('KeyStore:down:pre', {
|
|
2776
2929
|
event: event,
|
|
2777
2930
|
key: key
|
|
2778
2931
|
});
|
|
2779
|
-
|
|
2780
2932
|
_this._currentValues.add(key);
|
|
2781
|
-
|
|
2782
2933
|
_this.DS.publish('KeyStore:down', {
|
|
2783
2934
|
event: event,
|
|
2784
2935
|
key: key
|
|
2785
2936
|
});
|
|
2786
2937
|
});
|
|
2787
|
-
|
|
2788
2938
|
_defineProperty(this, "keyup", function (event) {
|
|
2789
2939
|
var key = event.key.toLowerCase();
|
|
2790
|
-
|
|
2791
2940
|
_this.DS.publish('KeyStore:up:pre', {
|
|
2792
2941
|
event: event,
|
|
2793
2942
|
key: key
|
|
2794
2943
|
});
|
|
2795
|
-
|
|
2796
2944
|
_this._currentValues["delete"](key);
|
|
2797
|
-
|
|
2798
2945
|
_this.DS.publish('KeyStore:up', {
|
|
2799
2946
|
event: event,
|
|
2800
2947
|
key: key
|
|
2801
2948
|
});
|
|
2802
2949
|
});
|
|
2803
|
-
|
|
2804
2950
|
_defineProperty(this, "stop", function () {
|
|
2805
2951
|
document.removeEventListener('keydown', _this.keydown);
|
|
2806
2952
|
document.removeEventListener('keyup', _this.reset);
|
|
2807
2953
|
window.removeEventListener('blur', _this.reset);
|
|
2808
|
-
|
|
2809
2954
|
_this.reset();
|
|
2810
2955
|
});
|
|
2811
|
-
|
|
2812
2956
|
_defineProperty(this, "reset", function () {
|
|
2813
2957
|
return _this._currentValues.clear();
|
|
2814
2958
|
});
|
|
2815
|
-
|
|
2816
2959
|
this.DS = DS;
|
|
2817
2960
|
this.DS.subscribe('Interaction:init', this.init);
|
|
2818
2961
|
}
|
|
2819
|
-
|
|
2820
2962
|
_createClass(KeyStore, [{
|
|
2821
2963
|
key: "isMultiSelectKeyPressed",
|
|
2822
|
-
|
|
2823
|
-
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
|
|
2824
|
-
value: function isMultiSelectKeyPressed(event) {
|
|
2964
|
+
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */value: function isMultiSelectKeyPressed(event) {
|
|
2825
2965
|
var _this2 = this;
|
|
2826
|
-
|
|
2827
2966
|
if (this.DS.stores.SettingsStore.s.multiSelectMode) return true;
|
|
2828
2967
|
var multiSelectKeys = this.DS.stores.SettingsStore.s.multiSelectKeys.map(function (key) {
|
|
2829
2968
|
return key.toLocaleLowerCase();
|
|
@@ -2842,14 +2981,13 @@
|
|
|
2842
2981
|
return Array.from(this._currentValues.values());
|
|
2843
2982
|
}
|
|
2844
2983
|
}]);
|
|
2845
|
-
|
|
2846
2984
|
return KeyStore;
|
|
2847
2985
|
}();
|
|
2848
2986
|
|
|
2849
2987
|
var PointerStore = /*#__PURE__*/function () {
|
|
2850
2988
|
/** @type {boolean} */
|
|
2851
|
-
// Pointer Positions within Area
|
|
2852
2989
|
|
|
2990
|
+
// Pointer Positions within Area
|
|
2853
2991
|
/**
|
|
2854
2992
|
* @type {Vect2}
|
|
2855
2993
|
* @private
|
|
@@ -2864,8 +3002,8 @@
|
|
|
2864
3002
|
* @type {Vect2}
|
|
2865
3003
|
* @private
|
|
2866
3004
|
* */
|
|
2867
|
-
// General Pointer Position
|
|
2868
3005
|
|
|
3006
|
+
// General Pointer Position
|
|
2869
3007
|
/**
|
|
2870
3008
|
* @type {Vect2}
|
|
2871
3009
|
* @private
|
|
@@ -2894,27 +3032,16 @@
|
|
|
2894
3032
|
*/
|
|
2895
3033
|
function PointerStore(_ref) {
|
|
2896
3034
|
var _this = this;
|
|
2897
|
-
|
|
2898
3035
|
var DS = _ref.DS;
|
|
2899
|
-
|
|
2900
3036
|
_classCallCheck(this, PointerStore);
|
|
2901
|
-
|
|
2902
3037
|
_defineProperty(this, "_isMouseInteraction", false);
|
|
2903
|
-
|
|
2904
3038
|
_defineProperty(this, "_initialValArea", void 0);
|
|
2905
|
-
|
|
2906
3039
|
_defineProperty(this, "_currentValArea", void 0);
|
|
2907
|
-
|
|
2908
3040
|
_defineProperty(this, "_lastValArea", void 0);
|
|
2909
|
-
|
|
2910
3041
|
_defineProperty(this, "_initialVal", void 0);
|
|
2911
|
-
|
|
2912
3042
|
_defineProperty(this, "_currentVal", void 0);
|
|
2913
|
-
|
|
2914
3043
|
_defineProperty(this, "_lastVal", void 0);
|
|
2915
|
-
|
|
2916
3044
|
_defineProperty(this, "_lastTouch", void 0);
|
|
2917
|
-
|
|
2918
3045
|
_defineProperty(this, "init", function () {
|
|
2919
3046
|
if (_this.Settings.usePointerEvents) document.addEventListener('pointermove', _this.update, {
|
|
2920
3047
|
// @ts-ignore
|
|
@@ -2925,28 +3052,22 @@
|
|
|
2925
3052
|
passive: false
|
|
2926
3053
|
});
|
|
2927
3054
|
});
|
|
2928
|
-
|
|
2929
3055
|
_defineProperty(this, "getPointerPosition", function (event) {
|
|
2930
3056
|
return getPointerPos({
|
|
2931
3057
|
event: _this._normalizedEvent(event)
|
|
2932
3058
|
});
|
|
2933
3059
|
});
|
|
2934
|
-
|
|
2935
3060
|
_defineProperty(this, "update", function (event) {
|
|
2936
3061
|
if (!event) return;
|
|
2937
|
-
|
|
2938
3062
|
_this.DS.publish('PointerStore:updated:pre', {
|
|
2939
3063
|
event: event
|
|
2940
3064
|
});
|
|
2941
|
-
|
|
2942
3065
|
_this.currentVal = _this.getPointerPosition(event);
|
|
2943
3066
|
if (!_this._isMouseInteraction) return;
|
|
2944
|
-
|
|
2945
3067
|
_this.DS.publish('PointerStore:updated', {
|
|
2946
3068
|
event: event
|
|
2947
3069
|
});
|
|
2948
3070
|
});
|
|
2949
|
-
|
|
2950
3071
|
_defineProperty(this, "stop", function () {
|
|
2951
3072
|
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
2952
3073
|
if (_this.Settings.usePointerEvents) document.removeEventListener('pointermove', _this.update, {
|
|
@@ -2956,22 +3077,18 @@
|
|
|
2956
3077
|
document.removeEventListener('touchmove', _this.update, {
|
|
2957
3078
|
// @ts-ignore
|
|
2958
3079
|
passive: false
|
|
2959
|
-
});
|
|
2960
|
-
|
|
3080
|
+
});
|
|
3081
|
+
// debounce in order "onClick" to work
|
|
2961
3082
|
setTimeout(function () {
|
|
2962
3083
|
return _this._isMouseInteraction = false;
|
|
2963
3084
|
}, 100);
|
|
2964
3085
|
});
|
|
2965
|
-
|
|
2966
3086
|
_defineProperty(this, "reset", function (event) {
|
|
2967
3087
|
if (!event) return;
|
|
2968
3088
|
_this.currentVal = _this.lastVal = _this.getPointerPosition(event);
|
|
2969
|
-
|
|
2970
3089
|
_this.stop();
|
|
2971
|
-
|
|
2972
3090
|
_this.init();
|
|
2973
3091
|
});
|
|
2974
|
-
|
|
2975
3092
|
this.DS = DS;
|
|
2976
3093
|
this.Settings = DS.stores.SettingsStore.s;
|
|
2977
3094
|
this.DS.subscribe('Interaction:init', this.init);
|
|
@@ -2984,21 +3101,15 @@
|
|
|
2984
3101
|
return _this.reset(event);
|
|
2985
3102
|
});
|
|
2986
3103
|
}
|
|
2987
|
-
|
|
2988
3104
|
_createClass(PointerStore, [{
|
|
2989
3105
|
key: "start",
|
|
2990
|
-
|
|
2991
|
-
/** @param {DSEvent} [event] */
|
|
2992
|
-
value: function start(event) {
|
|
3106
|
+
/** @param {DSEvent} [event] */value: function start(event) {
|
|
2993
3107
|
if (!event) return;
|
|
2994
3108
|
this._isMouseInteraction = true;
|
|
2995
3109
|
this.currentVal = this.initialVal = this.getPointerPosition(event);
|
|
2996
|
-
}
|
|
2997
|
-
/** @param {DSEvent} event */
|
|
2998
|
-
|
|
3110
|
+
} /** @param {DSEvent} event */
|
|
2999
3111
|
}, {
|
|
3000
3112
|
key: "_normalizedEvent",
|
|
3001
|
-
|
|
3002
3113
|
/**
|
|
3003
3114
|
* @param {DSEvent} event
|
|
3004
3115
|
* @return {MouseEvent|PointerEvent|Touch}
|
|
@@ -3006,13 +3117,11 @@
|
|
|
3006
3117
|
*/
|
|
3007
3118
|
value: function _normalizedEvent(event) {
|
|
3008
3119
|
// touchend has not touches. so we take the last touch if a touchevent, we need to store the positions
|
|
3009
|
-
if ('touches' in event && event.type !== 'touchend') this._lastTouch = event;
|
|
3120
|
+
if ('touches' in event && event.type !== 'touchend') this._lastTouch = event;
|
|
3121
|
+
// if a touchevent, return the last touch rather than the regular event
|
|
3010
3122
|
// we need .touches[0] from that event instead
|
|
3011
|
-
|
|
3012
3123
|
return 'touches' in event ? this._lastTouch.touches[0] : event;
|
|
3013
|
-
}
|
|
3014
|
-
/** First recorded pointer position within the area */
|
|
3015
|
-
|
|
3124
|
+
} /** First recorded pointer position within the area */
|
|
3016
3125
|
}, {
|
|
3017
3126
|
key: "initialValArea",
|
|
3018
3127
|
get: function get() {
|
|
@@ -3021,9 +3130,7 @@
|
|
|
3021
3130
|
y: 0
|
|
3022
3131
|
};
|
|
3023
3132
|
return this._initialValArea;
|
|
3024
|
-
}
|
|
3025
|
-
/** Current pointer position within the area */
|
|
3026
|
-
|
|
3133
|
+
} /** Current pointer position within the area */
|
|
3027
3134
|
}, {
|
|
3028
3135
|
key: "currentValArea",
|
|
3029
3136
|
get: function get() {
|
|
@@ -3032,9 +3139,7 @@
|
|
|
3032
3139
|
y: 0
|
|
3033
3140
|
};
|
|
3034
3141
|
return this._currentValArea;
|
|
3035
|
-
}
|
|
3036
|
-
/** Last recorded pointer position within the area */
|
|
3037
|
-
|
|
3142
|
+
} /** Last recorded pointer position within the area */
|
|
3038
3143
|
}, {
|
|
3039
3144
|
key: "lastValArea",
|
|
3040
3145
|
get: function get() {
|
|
@@ -3043,9 +3148,7 @@
|
|
|
3043
3148
|
y: 0
|
|
3044
3149
|
};
|
|
3045
3150
|
return this._lastValArea;
|
|
3046
|
-
}
|
|
3047
|
-
/** First recorded pointer position */
|
|
3048
|
-
|
|
3151
|
+
} /** First recorded pointer position */
|
|
3049
3152
|
}, {
|
|
3050
3153
|
key: "initialVal",
|
|
3051
3154
|
get: function get() {
|
|
@@ -3054,9 +3157,7 @@
|
|
|
3054
3157
|
y: 0
|
|
3055
3158
|
};
|
|
3056
3159
|
return this._initialVal;
|
|
3057
|
-
}
|
|
3058
|
-
/** Current pointer position */
|
|
3059
|
-
,
|
|
3160
|
+
} /** Current pointer position */,
|
|
3060
3161
|
set: function set(value) {
|
|
3061
3162
|
this._initialVal = value;
|
|
3062
3163
|
this._initialValArea = value && calc(value, '-', calc(rect2vect(this.DS.Area.rect), '+', rect2vect(this.DS.Area.computedBorder)));
|
|
@@ -3069,9 +3170,7 @@
|
|
|
3069
3170
|
y: 0
|
|
3070
3171
|
};
|
|
3071
3172
|
return this._currentVal;
|
|
3072
|
-
}
|
|
3073
|
-
/** Last recorded pointer position */
|
|
3074
|
-
,
|
|
3173
|
+
} /** Last recorded pointer position */,
|
|
3075
3174
|
set: function set(value) {
|
|
3076
3175
|
this._currentVal = value;
|
|
3077
3176
|
this._currentValArea = value && calc(value, '-', calc(rect2vect(this.DS.Area.rect), '+', rect2vect(this.DS.Area.computedBorder)));
|
|
@@ -3090,7 +3189,6 @@
|
|
|
3090
3189
|
this._lastValArea = value && calc(value, '-', calc(rect2vect(this.DS.Area.rect), '+', rect2vect(this.DS.Area.computedBorder)));
|
|
3091
3190
|
}
|
|
3092
3191
|
}]);
|
|
3093
|
-
|
|
3094
3192
|
return PointerStore;
|
|
3095
3193
|
}();
|
|
3096
3194
|
|
|
@@ -3115,47 +3213,33 @@
|
|
|
3115
3213
|
*/
|
|
3116
3214
|
function ScrollStore(_ref) {
|
|
3117
3215
|
var _this = this;
|
|
3118
|
-
|
|
3119
3216
|
var DS = _ref.DS;
|
|
3120
|
-
|
|
3121
3217
|
_classCallCheck(this, ScrollStore);
|
|
3122
|
-
|
|
3123
3218
|
_defineProperty(this, "_initialVal", void 0);
|
|
3124
|
-
|
|
3125
3219
|
_defineProperty(this, "_currentVal", void 0);
|
|
3126
|
-
|
|
3127
3220
|
_defineProperty(this, "_canScroll", void 0);
|
|
3128
|
-
|
|
3129
3221
|
_defineProperty(this, "init", function () {
|
|
3130
3222
|
return _this.DS.stores.SettingsStore.s.area.addEventListener('scroll', _this.update);
|
|
3131
3223
|
});
|
|
3132
|
-
|
|
3133
3224
|
_defineProperty(this, "start", function () {
|
|
3134
3225
|
_this._currentVal = _this._initialVal = getCurrentScroll(_this.DS.stores.SettingsStore.s.area);
|
|
3135
|
-
|
|
3136
3226
|
_this.DS.stores.SettingsStore.s.area.addEventListener('scroll', _this.update);
|
|
3137
3227
|
});
|
|
3138
|
-
|
|
3139
3228
|
_defineProperty(this, "update", function () {
|
|
3140
3229
|
return _this._currentVal = getCurrentScroll(_this.DS.stores.SettingsStore.s.area);
|
|
3141
3230
|
});
|
|
3142
|
-
|
|
3143
3231
|
_defineProperty(this, "stop", function () {
|
|
3144
3232
|
_this.DS.stores.SettingsStore.s.area.removeEventListener('scroll', _this.update);
|
|
3145
|
-
|
|
3146
3233
|
_this._initialVal = {
|
|
3147
3234
|
x: 0,
|
|
3148
3235
|
y: 0
|
|
3149
3236
|
};
|
|
3150
3237
|
_this._canScroll = null;
|
|
3151
3238
|
});
|
|
3152
|
-
|
|
3153
3239
|
_defineProperty(this, "reset", function () {
|
|
3154
3240
|
_this.stop();
|
|
3155
|
-
|
|
3156
3241
|
_this.start();
|
|
3157
3242
|
});
|
|
3158
|
-
|
|
3159
3243
|
this.DS = DS;
|
|
3160
3244
|
this.DS.subscribe('Interaction:init', this.init);
|
|
3161
3245
|
this.DS.subscribe('Interaction:start', function () {
|
|
@@ -3165,7 +3249,6 @@
|
|
|
3165
3249
|
return _this.reset();
|
|
3166
3250
|
});
|
|
3167
3251
|
}
|
|
3168
|
-
|
|
3169
3252
|
_createClass(ScrollStore, [{
|
|
3170
3253
|
key: "canScroll",
|
|
3171
3254
|
get: function get() {
|
|
@@ -3175,8 +3258,9 @@
|
|
|
3175
3258
|
}, {
|
|
3176
3259
|
key: "scrollAmount",
|
|
3177
3260
|
get: function get() {
|
|
3178
|
-
var scrollDiff = calc(this.currentVal, '-', this.initialVal);
|
|
3261
|
+
var scrollDiff = calc(this.currentVal, '-', this.initialVal);
|
|
3179
3262
|
|
|
3263
|
+
// if area is zoomed, the scroll values are skewed, we need to fix that manually :(
|
|
3180
3264
|
var zoom = num2vect(this.DS.stores.SettingsStore.s.zoom);
|
|
3181
3265
|
var zoomScroll = calc(calc(scrollDiff, '*', zoom), '-', scrollDiff);
|
|
3182
3266
|
return {
|
|
@@ -3200,7 +3284,6 @@
|
|
|
3200
3284
|
return this._currentVal;
|
|
3201
3285
|
}
|
|
3202
3286
|
}]);
|
|
3203
|
-
|
|
3204
3287
|
return ScrollStore;
|
|
3205
3288
|
}();
|
|
3206
3289
|
|
|
@@ -3227,39 +3310,29 @@
|
|
|
3227
3310
|
*/
|
|
3228
3311
|
function SettingsStore(_ref) {
|
|
3229
3312
|
var _this = this;
|
|
3230
|
-
|
|
3231
3313
|
var DS = _ref.DS,
|
|
3232
|
-
|
|
3233
|
-
|
|
3314
|
+
_settings2 = _ref.settings;
|
|
3234
3315
|
_classCallCheck(this, SettingsStore);
|
|
3235
|
-
|
|
3236
3316
|
_defineProperty(this, "_settings", {});
|
|
3237
|
-
|
|
3238
3317
|
_defineProperty(this, "s", {});
|
|
3239
|
-
|
|
3240
3318
|
_defineProperty(this, "update", function (_ref2) {
|
|
3241
3319
|
var settings = _ref2.settings,
|
|
3242
|
-
|
|
3320
|
+
init = _ref2.init;
|
|
3243
3321
|
return _this.DS.publish('Settings:updated:pre', _objectSpread2({
|
|
3244
3322
|
settings: settings
|
|
3245
3323
|
}, init ? {
|
|
3246
3324
|
init: init
|
|
3247
3325
|
} : {}));
|
|
3248
3326
|
});
|
|
3249
|
-
|
|
3250
3327
|
_defineProperty(this, "_update", function (_ref3) {
|
|
3251
3328
|
var settings = _ref3.settings,
|
|
3252
|
-
|
|
3253
|
-
|
|
3329
|
+
init = _ref3.init;
|
|
3254
3330
|
var _settings = hydrateSettings(settings, init);
|
|
3255
|
-
|
|
3256
3331
|
var _loop = function _loop() {
|
|
3257
3332
|
var _settings4;
|
|
3258
|
-
|
|
3259
3333
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3334
|
+
key = _Object$entries$_i[0],
|
|
3335
|
+
value = _Object$entries$_i[1];
|
|
3263
3336
|
if (!(key in _this._settings)) {
|
|
3264
3337
|
Object.defineProperty(_this.s, key, {
|
|
3265
3338
|
get: function get() {
|
|
@@ -3272,24 +3345,19 @@
|
|
|
3272
3345
|
}
|
|
3273
3346
|
});
|
|
3274
3347
|
}
|
|
3275
|
-
|
|
3276
3348
|
_this._settings["".concat(key, ":pre")] = _this._settings[key];
|
|
3277
3349
|
_this._settings[key] = value;
|
|
3278
3350
|
var update = {
|
|
3279
3351
|
settings: (_settings4 = {}, _defineProperty(_settings4, key, _this._settings[key]), _defineProperty(_settings4, "".concat(key, ":pre"), _this._settings["".concat(key, ":pre")]), _settings4)
|
|
3280
3352
|
};
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3353
|
+
_this.DS.publish('Settings:updated', update);
|
|
3354
|
+
// @ts-ignore: @todo: update to typescript
|
|
3285
3355
|
_this.DS.publish("Settings:updated:".concat(key), update);
|
|
3286
3356
|
};
|
|
3287
|
-
|
|
3288
3357
|
for (var _i = 0, _Object$entries = Object.entries(_settings); _i < _Object$entries.length; _i++) {
|
|
3289
3358
|
_loop();
|
|
3290
3359
|
}
|
|
3291
3360
|
});
|
|
3292
|
-
|
|
3293
3361
|
this.DS = DS;
|
|
3294
3362
|
this.DS.subscribe('Settings:updated:pre', this._update);
|
|
3295
3363
|
this.update({
|
|
@@ -3297,11 +3365,11 @@
|
|
|
3297
3365
|
init: true
|
|
3298
3366
|
});
|
|
3299
3367
|
}
|
|
3300
|
-
/** @param {{settings: Settings, init?: boolean}} props */
|
|
3301
|
-
;
|
|
3302
3368
|
|
|
3303
|
-
|
|
3369
|
+
/** @param {{settings: Settings, init?: boolean}} props */;
|
|
3304
3370
|
|
|
3371
|
+
// Setup
|
|
3372
|
+
//////////////////////////////////////////////////////////////////////////////////////
|
|
3305
3373
|
var DragSelect = /*#__PURE__*/function () {
|
|
3306
3374
|
/**
|
|
3307
3375
|
* used to skip all current Selection and dragNdrop functionality
|
|
@@ -3315,76 +3383,67 @@
|
|
|
3315
3383
|
*/
|
|
3316
3384
|
function DragSelect(_settings) {
|
|
3317
3385
|
var _this = this;
|
|
3318
|
-
|
|
3319
3386
|
_classCallCheck(this, DragSelect);
|
|
3320
|
-
|
|
3321
3387
|
_defineProperty(this, "continue", false);
|
|
3322
|
-
|
|
3323
3388
|
_defineProperty(this, "start", function () {
|
|
3324
3389
|
_this.stopped = false;
|
|
3325
|
-
|
|
3326
3390
|
_this.Interaction.init();
|
|
3327
3391
|
});
|
|
3328
|
-
|
|
3329
3392
|
_defineProperty(this, "break", function () {
|
|
3330
3393
|
return _this["continue"] = true;
|
|
3331
3394
|
});
|
|
3332
|
-
|
|
3395
|
+
_defineProperty(this, "setSettings", function (settings) {
|
|
3396
|
+
return _this.stores.SettingsStore.update({
|
|
3397
|
+
settings: settings
|
|
3398
|
+
});
|
|
3399
|
+
});
|
|
3333
3400
|
_defineProperty(this, "getSelection", function () {
|
|
3334
3401
|
return _this.SelectedSet.elements;
|
|
3335
3402
|
});
|
|
3336
|
-
|
|
3337
3403
|
_defineProperty(this, "getSelectables", function () {
|
|
3338
3404
|
return _this.SelectableSet.elements;
|
|
3339
3405
|
});
|
|
3340
|
-
|
|
3341
3406
|
_defineProperty(this, "getInitialCursorPosition", function () {
|
|
3342
3407
|
return _this.stores.PointerStore.initialVal;
|
|
3343
3408
|
});
|
|
3344
|
-
|
|
3345
3409
|
_defineProperty(this, "getCurrentCursorPosition", function () {
|
|
3346
3410
|
return _this.stores.PointerStore.currentVal;
|
|
3347
3411
|
});
|
|
3348
|
-
|
|
3349
3412
|
_defineProperty(this, "getPreviousCursorPosition", function () {
|
|
3350
3413
|
return _this.stores.PointerStore.lastVal;
|
|
3351
3414
|
});
|
|
3352
|
-
|
|
3353
3415
|
_defineProperty(this, "getInitialCursorPositionArea", function () {
|
|
3354
3416
|
return _this.stores.PointerStore.initialValArea;
|
|
3355
3417
|
});
|
|
3356
|
-
|
|
3357
3418
|
_defineProperty(this, "getCurrentCursorPositionArea", function () {
|
|
3358
3419
|
return _this.stores.PointerStore.currentValArea;
|
|
3359
3420
|
});
|
|
3360
|
-
|
|
3361
3421
|
_defineProperty(this, "getPreviousCursorPositionArea", function () {
|
|
3362
3422
|
return _this.stores.PointerStore.lastValArea;
|
|
3363
3423
|
});
|
|
3364
|
-
|
|
3365
3424
|
_defineProperty(this, "isMultiSelect", function (event) {
|
|
3366
3425
|
return _this.stores.KeyStore.isMultiSelectKeyPressed(event);
|
|
3367
3426
|
});
|
|
3368
|
-
|
|
3369
3427
|
_defineProperty(this, "isDragging", function () {
|
|
3370
3428
|
return _this.Interaction.isDragging;
|
|
3371
3429
|
});
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
return _this.
|
|
3375
|
-
|
|
3376
|
-
|
|
3430
|
+
_defineProperty(this, "getZoneByCoordinates", function (coordinates) {
|
|
3431
|
+
var _this$DropZones$getTa;
|
|
3432
|
+
return (_this$DropZones$getTa = _this.DropZones.getTarget(coordinates)) === null || _this$DropZones$getTa === void 0 ? void 0 : _this$DropZones$getTa.toObject();
|
|
3433
|
+
});
|
|
3434
|
+
_defineProperty(this, "getItemsDroppedByZoneId", function (zoneId) {
|
|
3435
|
+
return _this.DropZones.getItemsDroppedById(zoneId);
|
|
3436
|
+
});
|
|
3437
|
+
_defineProperty(this, "getItemsInsideByZoneId", function (zoneId, addClasses) {
|
|
3438
|
+
return _this.DropZones.getItemsInsideById(zoneId, addClasses);
|
|
3377
3439
|
});
|
|
3378
|
-
|
|
3379
3440
|
this.PubSub = new PubSub({
|
|
3380
3441
|
DS: this
|
|
3381
3442
|
});
|
|
3382
3443
|
this.subscribe = this.PubSub.subscribe;
|
|
3383
3444
|
this.unsubscribe = this.PubSub.unsubscribe;
|
|
3384
3445
|
this.publish = this.PubSub.publish;
|
|
3385
|
-
this.stores =
|
|
3386
|
-
/** @type {{ SettingsStore:SettingsStore, PointerStore:PointerStore, ScrollStore:ScrollStore, KeyStore:KeyStore }} */
|
|
3387
|
-
{};
|
|
3446
|
+
this.stores = /** @type {{ SettingsStore:SettingsStore, PointerStore:PointerStore, ScrollStore:ScrollStore, KeyStore:KeyStore }} */{};
|
|
3388
3447
|
this.stores.SettingsStore = new SettingsStore({
|
|
3389
3448
|
DS: this,
|
|
3390
3449
|
settings: _settings
|
|
@@ -3419,32 +3478,35 @@
|
|
|
3419
3478
|
this.Drag = new Drag({
|
|
3420
3479
|
DS: this
|
|
3421
3480
|
});
|
|
3481
|
+
this.DropZones = new DropZones({
|
|
3482
|
+
DS: this
|
|
3483
|
+
});
|
|
3422
3484
|
this.Interaction = new Interaction({
|
|
3423
3485
|
DS: this
|
|
3424
|
-
});
|
|
3486
|
+
});
|
|
3425
3487
|
|
|
3488
|
+
// Subscriber Aliases
|
|
3426
3489
|
subscriberAliases({
|
|
3427
3490
|
subscribe: this.subscribe,
|
|
3428
3491
|
publish: this.publish,
|
|
3429
3492
|
SelectedSet: this.SelectedSet,
|
|
3430
|
-
Interaction: this.Interaction
|
|
3493
|
+
Interaction: this.Interaction,
|
|
3494
|
+
DropZones: this.DropZones
|
|
3431
3495
|
});
|
|
3432
3496
|
this.subscribe('Interaction:end', function () {
|
|
3433
3497
|
return _this["continue"] = false;
|
|
3434
3498
|
});
|
|
3435
3499
|
this.start();
|
|
3436
|
-
}
|
|
3437
|
-
//////////////////////////////////////////////////////////////////////////////////////
|
|
3500
|
+
}
|
|
3438
3501
|
|
|
3502
|
+
// Useful methods for the user
|
|
3503
|
+
//////////////////////////////////////////////////////////////////////////////////////
|
|
3439
3504
|
/**
|
|
3440
3505
|
* Initializes the functionality. Automatically triggered when created.
|
|
3441
3506
|
* Also, reset the functionality after a teardown
|
|
3442
3507
|
*/
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
3508
|
_createClass(DragSelect, [{
|
|
3446
3509
|
key: "stop",
|
|
3447
|
-
|
|
3448
3510
|
/**
|
|
3449
3511
|
* Complete function teardown
|
|
3450
3512
|
* Will teardown/stop the whole functionality
|
|
@@ -3476,10 +3538,8 @@
|
|
|
3476
3538
|
* Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
|
|
3477
3539
|
* Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
|
|
3478
3540
|
*/
|
|
3479
|
-
|
|
3480
3541
|
}, {
|
|
3481
3542
|
key: "addSelection",
|
|
3482
|
-
|
|
3483
3543
|
/**
|
|
3484
3544
|
* Adds several elements to the selection list also adds the specific classes and take into account all calculations.
|
|
3485
3545
|
* Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
|
|
@@ -3506,7 +3566,6 @@
|
|
|
3506
3566
|
* @param {boolean} [removeFromSelectables] - if element should be removed from the list of selectable elements
|
|
3507
3567
|
* @return {DSElements} all selected elements
|
|
3508
3568
|
*/
|
|
3509
|
-
|
|
3510
3569
|
}, {
|
|
3511
3570
|
key: "removeSelection",
|
|
3512
3571
|
value: function removeSelection(elements) {
|
|
@@ -3528,12 +3587,10 @@
|
|
|
3528
3587
|
* @param {boolean} [alsoSelectables] - if element should not be added/removed to the list of selectable elements accordingly
|
|
3529
3588
|
* @return {DSElements} all selected elements
|
|
3530
3589
|
*/
|
|
3531
|
-
|
|
3532
3590
|
}, {
|
|
3533
3591
|
key: "toggleSelection",
|
|
3534
3592
|
value: function toggleSelection(elements) {
|
|
3535
3593
|
var _this2 = this;
|
|
3536
|
-
|
|
3537
3594
|
var triggerCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3538
3595
|
var alsoSelectables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
3539
3596
|
toArray(elements).forEach(function (el) {
|
|
@@ -3552,7 +3609,6 @@
|
|
|
3552
3609
|
* @param {boolean} [dontAddToSelectables] - if element should not be added to the list of selectable elements
|
|
3553
3610
|
* @return {DSElements}
|
|
3554
3611
|
*/
|
|
3555
|
-
|
|
3556
3612
|
}, {
|
|
3557
3613
|
key: "setSelection",
|
|
3558
3614
|
value: function setSelection(elements) {
|
|
@@ -3567,7 +3623,6 @@
|
|
|
3567
3623
|
* @param {boolean} [triggerCallback] - if callback should be called
|
|
3568
3624
|
* @return {DSElements} this.selected, should be empty
|
|
3569
3625
|
*/
|
|
3570
|
-
|
|
3571
3626
|
}, {
|
|
3572
3627
|
key: "clearSelection",
|
|
3573
3628
|
value: function clearSelection() {
|
|
@@ -3585,7 +3640,6 @@
|
|
|
3585
3640
|
* @param {boolean} [triggerCallback] - if callback should be called
|
|
3586
3641
|
* @return {DSInputElements} the added element(s)
|
|
3587
3642
|
*/
|
|
3588
|
-
|
|
3589
3643
|
}, {
|
|
3590
3644
|
key: "addSelectables",
|
|
3591
3645
|
value: function addSelectables(elements, addToSelection, triggerCallback) {
|
|
@@ -3601,10 +3655,8 @@
|
|
|
3601
3655
|
* Gets all nodes that can potentially be selected
|
|
3602
3656
|
* @return {DSElements} this.selectables
|
|
3603
3657
|
*/
|
|
3604
|
-
|
|
3605
3658
|
}, {
|
|
3606
3659
|
key: "setSelectables",
|
|
3607
|
-
|
|
3608
3660
|
/**
|
|
3609
3661
|
* Sets all elements that can be selected.
|
|
3610
3662
|
* Removes all current selectables (& their respective classes).
|
|
@@ -3628,7 +3680,6 @@
|
|
|
3628
3680
|
* @param {boolean} [triggerCallback] - if callback should be called
|
|
3629
3681
|
* @return {DSInputElements} the removed element(s)
|
|
3630
3682
|
*/
|
|
3631
|
-
|
|
3632
3683
|
}, {
|
|
3633
3684
|
key: "removeSelectables",
|
|
3634
3685
|
value: function removeSelectables(elements, removeFromSelection, triggerCallback) {
|
|
@@ -3638,11 +3689,8 @@
|
|
|
3638
3689
|
items: this.getSelection()
|
|
3639
3690
|
});
|
|
3640
3691
|
return elements;
|
|
3641
|
-
}
|
|
3642
|
-
/** The starting/initial position of the cursor/selector @return {Vect2} */
|
|
3643
|
-
|
|
3692
|
+
} /** The starting/initial position of the cursor/selector @return {Vect2} */
|
|
3644
3693
|
}]);
|
|
3645
|
-
|
|
3646
3694
|
return DragSelect;
|
|
3647
3695
|
}();
|
|
3648
3696
|
|