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