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