dragselect 2.1.2 → 2.3.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 +29 -1
- package/CODE_OF_CONDUCT.md +128 -0
- package/README.md +88 -15
- package/dist/DragSelect.d.ts +17 -4
- package/dist/DragSelect.es6m.js +466 -194
- package/dist/DragSelect.js +466 -194
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/methods/index.d.ts +1 -0
- package/dist/methods/subscriberAliases.d.ts +12 -0
- package/dist/modules/Area.d.ts +15 -9
- package/dist/modules/Drag.d.ts +13 -5
- package/dist/modules/Interaction.d.ts +11 -4
- package/dist/modules/PubSub.d.ts +10 -3
- package/dist/modules/SelectorArea.d.ts +9 -1
- package/dist/stores/PointerStore.d.ts +2 -0
- package/dist/types.d.ts +15 -2
- package/package.json +12 -9
- package/src/DragSelect.js +43 -53
- package/src/methods/index.js +1 -0
- package/src/methods/subscriberAliases.js +52 -0
- package/src/modules/Area.js +29 -17
- package/src/modules/Drag.js +37 -15
- package/src/modules/Interaction.js +33 -13
- package/src/modules/PubSub.js +35 -4
- package/src/modules/SelectableSet.js +2 -2
- package/src/modules/SelectedSet.js +12 -8
- package/src/modules/Selection.js +2 -1
- package/src/modules/Selector.js +1 -1
- package/src/modules/SelectorArea.js +30 -8
- package/src/stores/KeyStore.js +2 -0
- package/src/stores/PointerStore.js +9 -8
- package/src/types.js +6 -2
package/dist/DragSelect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/***
|
|
2
2
|
|
|
3
|
-
~~~ Version 2.
|
|
3
|
+
~~~ Version 2.3.0 ~~~
|
|
4
4
|
|
|
5
5
|
******************************************
|
|
6
6
|
|
|
@@ -72,6 +72,40 @@
|
|
|
72
72
|
return obj;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
function ownKeys(object, enumerableOnly) {
|
|
76
|
+
var keys = Object.keys(object);
|
|
77
|
+
|
|
78
|
+
if (Object.getOwnPropertySymbols) {
|
|
79
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
80
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
81
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
82
|
+
});
|
|
83
|
+
keys.push.apply(keys, symbols);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return keys;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function _objectSpread2(target) {
|
|
90
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
91
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
92
|
+
|
|
93
|
+
if (i % 2) {
|
|
94
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
95
|
+
_defineProperty(target, key, source[key]);
|
|
96
|
+
});
|
|
97
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
98
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
99
|
+
} else {
|
|
100
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
101
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return target;
|
|
107
|
+
}
|
|
108
|
+
|
|
75
109
|
function _inherits(subClass, superClass) {
|
|
76
110
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
77
111
|
throw new TypeError("Super expression must either be null or a function");
|
|
@@ -236,6 +270,10 @@
|
|
|
236
270
|
return _get(target, property, receiver || target);
|
|
237
271
|
}
|
|
238
272
|
|
|
273
|
+
function _slicedToArray(arr, i) {
|
|
274
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
275
|
+
}
|
|
276
|
+
|
|
239
277
|
function _toConsumableArray(arr) {
|
|
240
278
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
241
279
|
}
|
|
@@ -244,10 +282,41 @@
|
|
|
244
282
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
245
283
|
}
|
|
246
284
|
|
|
285
|
+
function _arrayWithHoles(arr) {
|
|
286
|
+
if (Array.isArray(arr)) return arr;
|
|
287
|
+
}
|
|
288
|
+
|
|
247
289
|
function _iterableToArray(iter) {
|
|
248
290
|
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
|
249
291
|
}
|
|
250
292
|
|
|
293
|
+
function _iterableToArrayLimit(arr, i) {
|
|
294
|
+
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
|
295
|
+
var _arr = [];
|
|
296
|
+
var _n = true;
|
|
297
|
+
var _d = false;
|
|
298
|
+
var _e = undefined;
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
302
|
+
_arr.push(_s.value);
|
|
303
|
+
|
|
304
|
+
if (i && _arr.length === i) break;
|
|
305
|
+
}
|
|
306
|
+
} catch (err) {
|
|
307
|
+
_d = true;
|
|
308
|
+
_e = err;
|
|
309
|
+
} finally {
|
|
310
|
+
try {
|
|
311
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
312
|
+
} finally {
|
|
313
|
+
if (_d) throw _e;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return _arr;
|
|
318
|
+
}
|
|
319
|
+
|
|
251
320
|
function _unsupportedIterableToArray(o, minLen) {
|
|
252
321
|
if (!o) return;
|
|
253
322
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -269,6 +338,10 @@
|
|
|
269
338
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
270
339
|
}
|
|
271
340
|
|
|
341
|
+
function _nonIterableRest() {
|
|
342
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
343
|
+
}
|
|
344
|
+
|
|
272
345
|
/**
|
|
273
346
|
* The Settings to be passed to the Class
|
|
274
347
|
* @typedef {Object} Settings
|
|
@@ -284,6 +357,7 @@
|
|
|
284
357
|
* @property {HTMLElement} [selector=HTMLElement] the square that will draw the selection
|
|
285
358
|
* @property {boolean} [draggability=true] When a user is dragging on an already selected element, the selection is dragged.
|
|
286
359
|
* @property {boolean} [immediateDrag=true] Whether an element is draggable from the start or needs to be selected first
|
|
360
|
+
* @property {boolean} [keyboardDrag=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it)
|
|
287
361
|
* @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
|
|
288
362
|
* @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
|
|
289
363
|
* @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
@@ -304,9 +378,11 @@
|
|
|
304
378
|
* The Object that is passed back to any callback method
|
|
305
379
|
* @typedef {Object} CallbackObject
|
|
306
380
|
* @property {Array<HTMLElement|SVGElement|any>} [items] The items currently selected
|
|
307
|
-
* @property {MouseEvent|TouchEvent|Event} [event] The respective event object
|
|
381
|
+
* @property {MouseEvent|TouchEvent|KeyboardEvent|Event} [event] The respective event object
|
|
308
382
|
* @property {HTMLElement|SVGElement|any} [item] The single item currently interacted with
|
|
309
383
|
* @property {boolean} [isDragging] Whether the interaction is a drag or a select
|
|
384
|
+
* @property {boolean} [isDraggingKeyboard] Whether or not the drag interaction is via keyboard
|
|
385
|
+
* @property {string} [key] Pressed key (lowercase)
|
|
310
386
|
* @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} [scroll_directions]
|
|
311
387
|
* @property {number} [scroll_multiplier]
|
|
312
388
|
*/
|
|
@@ -340,7 +416,9 @@
|
|
|
340
416
|
|
|
341
417
|
/** @typedef {'Interaction:init'|'Interaction:start'|'Interaction:end'|'Interaction:update'|'Area:modified'|'Area:scroll'|'PointerStore:updated'|'Selected:added'|'Selected:removed'|'Selectable:click'|'Selectable:pointer'|'KeyStore:down'|'KeyStore:up'} DSInternalEventNames */
|
|
342
418
|
|
|
343
|
-
/** @typedef {
|
|
419
|
+
/** @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:pointer:pre'|'KeyStore:down:pre'|'KeyStore:up:pre'} DSInternalEventNamesPre */
|
|
420
|
+
|
|
421
|
+
/** @typedef {DSEventNames|DSInternalEventNames|DSInternalEventNamesPre} DSCallbackNames the name of the callback */
|
|
344
422
|
|
|
345
423
|
/** @typedef {{top:number,left:number,bottom:number,right:number,width:number,height:number}} DSBoundingRect */
|
|
346
424
|
|
|
@@ -1131,6 +1209,84 @@
|
|
|
1131
1209
|
return element;
|
|
1132
1210
|
});
|
|
1133
1211
|
|
|
1212
|
+
/**
|
|
1213
|
+
* @typedef {function} DSSubscribe
|
|
1214
|
+
* @param {DSCallbackNames} eventName
|
|
1215
|
+
* @param {DSCallback} callback
|
|
1216
|
+
* @returns {number} event id, can be used to unsubscribe more efficiently
|
|
1217
|
+
*/
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* @typedef {function} DSPublish
|
|
1221
|
+
* @param {DSCallbackNames} eventName
|
|
1222
|
+
* @param {CallbackObject} data passed to the subscription method
|
|
1223
|
+
*/
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Maps internal events to external ones
|
|
1227
|
+
*
|
|
1228
|
+
* @param {Object} p
|
|
1229
|
+
* @param {DSSubscribe} p.subscribe
|
|
1230
|
+
* @param {DSPublish} p.publish
|
|
1231
|
+
* @param {Interaction} p.Interaction
|
|
1232
|
+
* @param {SelectedSet} p.SelectedSet
|
|
1233
|
+
*/
|
|
1234
|
+
|
|
1235
|
+
var subscriberAliases = (function (_ref) {
|
|
1236
|
+
var subscribe = _ref.subscribe,
|
|
1237
|
+
publish = _ref.publish,
|
|
1238
|
+
Interaction = _ref.Interaction,
|
|
1239
|
+
SelectedSet = _ref.SelectedSet;
|
|
1240
|
+
var mapping = {
|
|
1241
|
+
'Selected:added': [{
|
|
1242
|
+
name: 'elementselect'
|
|
1243
|
+
}],
|
|
1244
|
+
'Selected:removed': [{
|
|
1245
|
+
name: 'elementunselect'
|
|
1246
|
+
}],
|
|
1247
|
+
'Area:scroll': [{
|
|
1248
|
+
name: 'autoscroll'
|
|
1249
|
+
}],
|
|
1250
|
+
// scroll_directions, scroll_multiplier
|
|
1251
|
+
'Interaction:start': [{
|
|
1252
|
+
name: 'dragstart'
|
|
1253
|
+
}],
|
|
1254
|
+
// event, isDraggingKeyboard
|
|
1255
|
+
'Interaction:update': [{
|
|
1256
|
+
name: 'dragmove',
|
|
1257
|
+
condition: function condition(data) {
|
|
1258
|
+
return data.event;
|
|
1259
|
+
}
|
|
1260
|
+
}],
|
|
1261
|
+
// event, isDraggingKeyboard
|
|
1262
|
+
'Interaction:end': [{
|
|
1263
|
+
name: 'callback'
|
|
1264
|
+
}] // event, isDraggingKeyboard
|
|
1265
|
+
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
var _loop = function _loop() {
|
|
1269
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1270
|
+
sub_name = _Object$entries$_i[0],
|
|
1271
|
+
pubs = _Object$entries$_i[1];
|
|
1272
|
+
|
|
1273
|
+
['pre', false].forEach(function (filler) {
|
|
1274
|
+
return subscribe(filler ? "".concat(sub_name, ":").concat(filler) : sub_name, function (data) {
|
|
1275
|
+
return pubs.forEach(function (pub) {
|
|
1276
|
+
return (!pub.condition || pub.condition(data)) && publish(filler ? "".concat(filler).concat(pub.name) : pub.name, _objectSpread2({
|
|
1277
|
+
items: SelectedSet.elements,
|
|
1278
|
+
isDragging: Interaction.isDragging
|
|
1279
|
+
}, data));
|
|
1280
|
+
});
|
|
1281
|
+
});
|
|
1282
|
+
});
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
for (var _i = 0, _Object$entries = Object.entries(mapping); _i < _Object$entries.length; _i++) {
|
|
1286
|
+
_loop();
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
|
|
1134
1290
|
/**
|
|
1135
1291
|
* Transforms any list or single item to an array so user doesn’t have to care.
|
|
1136
1292
|
* @param {DSInputElements} items a single item, a Node-list or any element group
|
|
@@ -1158,6 +1314,13 @@
|
|
|
1158
1314
|
element.style.height = "".concat(pos.height, "px");
|
|
1159
1315
|
});
|
|
1160
1316
|
|
|
1317
|
+
/**
|
|
1318
|
+
* @typedef {Object} AreaProps
|
|
1319
|
+
* @property {DSArea} area
|
|
1320
|
+
* @property {PubSub} PS
|
|
1321
|
+
* @property {number} zoom
|
|
1322
|
+
*/
|
|
1323
|
+
|
|
1161
1324
|
var Area = /*#__PURE__*/function () {
|
|
1162
1325
|
/**
|
|
1163
1326
|
* @type {DSModificationCallback}
|
|
@@ -1201,16 +1364,13 @@
|
|
|
1201
1364
|
|
|
1202
1365
|
/**
|
|
1203
1366
|
* @constructor Area
|
|
1204
|
-
* @param {
|
|
1205
|
-
* @param {DSArea} obj.area
|
|
1206
|
-
* @param {PubSub} obj.PS
|
|
1207
|
-
* @param {number} obj.zoom
|
|
1367
|
+
* @param {AreaProps} settings
|
|
1208
1368
|
* @ignore
|
|
1209
1369
|
*/
|
|
1210
1370
|
function Area(_ref) {
|
|
1211
1371
|
var _this = this;
|
|
1212
1372
|
|
|
1213
|
-
var
|
|
1373
|
+
var _area = _ref.area,
|
|
1214
1374
|
PS = _ref.PS,
|
|
1215
1375
|
zoom = _ref.zoom;
|
|
1216
1376
|
|
|
@@ -1232,6 +1392,26 @@
|
|
|
1232
1392
|
|
|
1233
1393
|
_defineProperty(this, "_rect", void 0);
|
|
1234
1394
|
|
|
1395
|
+
_defineProperty(this, "setArea", function (area) {
|
|
1396
|
+
_this._node = area;
|
|
1397
|
+
handleElementPositionAttribute({
|
|
1398
|
+
computedStyle: _this.computedStyle,
|
|
1399
|
+
node: _this._node
|
|
1400
|
+
}); // first immediate debounce to update values after dom-update
|
|
1401
|
+
|
|
1402
|
+
setTimeout(function () {
|
|
1403
|
+
_this.PubSub.publish('Area:modified:pre', {
|
|
1404
|
+
item: _this
|
|
1405
|
+
});
|
|
1406
|
+
|
|
1407
|
+
_this.reset();
|
|
1408
|
+
|
|
1409
|
+
_this.PubSub.publish('Area:modified', {
|
|
1410
|
+
item: _this
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1235
1415
|
_defineProperty(this, "start", function () {
|
|
1236
1416
|
addModificationObservers(_this.parentNodes, _this._modificationCallback, _this._modificationObserver);
|
|
1237
1417
|
});
|
|
@@ -1250,42 +1430,40 @@
|
|
|
1250
1430
|
});
|
|
1251
1431
|
|
|
1252
1432
|
_defineProperty(this, "scroll", function (directions, multiplier) {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
_this.PubSub.publish('Area:scroll', {
|
|
1433
|
+
var data = {
|
|
1256
1434
|
scroll_directions: directions,
|
|
1257
1435
|
scroll_multiplier: multiplier
|
|
1258
|
-
}
|
|
1436
|
+
};
|
|
1437
|
+
|
|
1438
|
+
_this.PubSub.publish('Area:scroll:pre', data);
|
|
1439
|
+
|
|
1440
|
+
scrollElement(_this._node, directions, multiplier);
|
|
1441
|
+
|
|
1442
|
+
_this.PubSub.publish('Area:scroll', data);
|
|
1259
1443
|
});
|
|
1260
1444
|
|
|
1261
|
-
this._node = area;
|
|
1262
1445
|
this._zoom = zoom;
|
|
1263
1446
|
this.PubSub = PS;
|
|
1264
|
-
|
|
1265
|
-
computedStyle: this.computedStyle,
|
|
1266
|
-
node: this._node
|
|
1267
|
-
});
|
|
1447
|
+
this.setArea(_area);
|
|
1268
1448
|
this._modificationCallback = debounce(function (event) {
|
|
1269
|
-
_this.
|
|
1270
|
-
|
|
1271
|
-
_this.PubSub.publish('Area:modified', {
|
|
1449
|
+
_this.PubSub.publish('Area:modified:pre', {
|
|
1272
1450
|
event: event,
|
|
1273
1451
|
item: _this
|
|
1274
1452
|
});
|
|
1275
|
-
}, 60);
|
|
1276
|
-
this._modificationObserver = new MutationObserver(this._modificationCallback); // first immediate debounce to update values after dom-update
|
|
1277
1453
|
|
|
1278
|
-
setTimeout(function () {
|
|
1279
1454
|
_this.reset();
|
|
1280
1455
|
|
|
1281
1456
|
_this.PubSub.publish('Area:modified', {
|
|
1282
1457
|
event: event,
|
|
1283
1458
|
item: _this
|
|
1284
1459
|
});
|
|
1285
|
-
});
|
|
1460
|
+
}, 60);
|
|
1461
|
+
this._modificationObserver = new MutationObserver(this._modificationCallback);
|
|
1286
1462
|
this.PubSub.subscribe('Interaction:init', this.start);
|
|
1287
1463
|
this.PubSub.subscribe('Interaction:end', this.reset);
|
|
1288
1464
|
}
|
|
1465
|
+
/** @param {DSArea} area */
|
|
1466
|
+
|
|
1289
1467
|
|
|
1290
1468
|
_createClass(Area, [{
|
|
1291
1469
|
key: "HTMLNode",
|
|
@@ -1399,6 +1577,11 @@
|
|
|
1399
1577
|
* @private
|
|
1400
1578
|
*/
|
|
1401
1579
|
|
|
1580
|
+
/**
|
|
1581
|
+
* @type {boolean}
|
|
1582
|
+
* @private
|
|
1583
|
+
*/
|
|
1584
|
+
|
|
1402
1585
|
/**
|
|
1403
1586
|
* @type {number}
|
|
1404
1587
|
* @private
|
|
@@ -1415,6 +1598,7 @@
|
|
|
1415
1598
|
* @param {boolean} p.draggability
|
|
1416
1599
|
* @param {boolean} p.useTransform
|
|
1417
1600
|
* @param {DSDragKeys} p.dragKeys
|
|
1601
|
+
* @param {boolean} p.keyboardDrag
|
|
1418
1602
|
* @param {number} p.keyboardDragSpeed
|
|
1419
1603
|
* @param {number} p.zoom
|
|
1420
1604
|
* @ignore
|
|
@@ -1425,6 +1609,7 @@
|
|
|
1425
1609
|
var DS = _ref.DS,
|
|
1426
1610
|
dragKeys = _ref.dragKeys,
|
|
1427
1611
|
draggability = _ref.draggability,
|
|
1612
|
+
keyboardDrag = _ref.keyboardDrag,
|
|
1428
1613
|
keyboardDragSpeed = _ref.keyboardDragSpeed,
|
|
1429
1614
|
useTransform = _ref.useTransform,
|
|
1430
1615
|
zoom = _ref.zoom;
|
|
@@ -1445,6 +1630,8 @@
|
|
|
1445
1630
|
|
|
1446
1631
|
_defineProperty(this, "_dragKeysFlat", void 0);
|
|
1447
1632
|
|
|
1633
|
+
_defineProperty(this, "_keyboardDrag", void 0);
|
|
1634
|
+
|
|
1448
1635
|
_defineProperty(this, "_keyboardDragSpeed", void 0);
|
|
1449
1636
|
|
|
1450
1637
|
_defineProperty(this, "_zoom", void 0);
|
|
@@ -1452,14 +1639,14 @@
|
|
|
1452
1639
|
_defineProperty(this, "keyboardDrag", function (_ref2) {
|
|
1453
1640
|
var event = _ref2.event,
|
|
1454
1641
|
key = _ref2.key;
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
_this._isKeyboard = true;
|
|
1458
|
-
|
|
1459
|
-
_this.DS.publish('Interaction:start', {
|
|
1642
|
+
if (!_this._keyboardDrag || !_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability || _this.DS["continue"]) return;
|
|
1643
|
+
var publishData = {
|
|
1460
1644
|
event: event,
|
|
1461
|
-
isDragging: true
|
|
1462
|
-
|
|
1645
|
+
isDragging: true,
|
|
1646
|
+
isDraggingKeyboard: true
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
_this.DS.publish(['Interaction:start:pre', 'Interaction:start'], publishData);
|
|
1463
1650
|
|
|
1464
1651
|
_this._elements = _this.DS.getSelection();
|
|
1465
1652
|
|
|
@@ -1485,31 +1672,26 @@
|
|
|
1485
1672
|
});
|
|
1486
1673
|
});
|
|
1487
1674
|
|
|
1488
|
-
_this.DS.publish('Interaction:update',
|
|
1489
|
-
event: event,
|
|
1490
|
-
isDragging: true
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
_this._isKeyboard = false;
|
|
1675
|
+
_this.DS.publish(['Interaction:update:pre', 'Interaction:update'], publishData);
|
|
1494
1676
|
});
|
|
1495
1677
|
|
|
1496
1678
|
_defineProperty(this, "keyboardEnd", function (_ref3) {
|
|
1497
1679
|
var event = _ref3.event,
|
|
1498
1680
|
key = _ref3.key;
|
|
1499
|
-
if (!_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability) return;
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
_this.DS.publish('Interaction:end', {
|
|
1681
|
+
if (!_this._keyboardDrag || !_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability) return;
|
|
1682
|
+
var publishData = {
|
|
1503
1683
|
event: event,
|
|
1504
|
-
isDragging:
|
|
1505
|
-
|
|
1684
|
+
isDragging: _this._draggability,
|
|
1685
|
+
isDraggingKeyboard: true
|
|
1686
|
+
};
|
|
1506
1687
|
|
|
1507
|
-
_this.
|
|
1688
|
+
_this.DS.publish(['Interaction:end:pre', 'Interaction:end'], publishData);
|
|
1508
1689
|
});
|
|
1509
1690
|
|
|
1510
1691
|
_defineProperty(this, "start", function (_ref4) {
|
|
1511
|
-
var isDragging = _ref4.isDragging
|
|
1512
|
-
|
|
1692
|
+
var isDragging = _ref4.isDragging,
|
|
1693
|
+
isDraggingKeyboard = _ref4.isDraggingKeyboard;
|
|
1694
|
+
if (!isDragging || isDraggingKeyboard) return;
|
|
1513
1695
|
_this._prevCursorPos = null;
|
|
1514
1696
|
_this._prevScrollPos = null;
|
|
1515
1697
|
_this._elements = _this.DS.getSelection();
|
|
@@ -1517,8 +1699,8 @@
|
|
|
1517
1699
|
_this.handleZIndex(true);
|
|
1518
1700
|
});
|
|
1519
1701
|
|
|
1520
|
-
_defineProperty(this, "stop", function () {
|
|
1521
|
-
if (
|
|
1702
|
+
_defineProperty(this, "stop", function (evt) {
|
|
1703
|
+
if (evt !== null && evt !== void 0 && evt.isKeyboard) return;
|
|
1522
1704
|
_this._prevCursorPos = null;
|
|
1523
1705
|
_this._prevScrollPos = null;
|
|
1524
1706
|
|
|
@@ -1528,8 +1710,9 @@
|
|
|
1528
1710
|
});
|
|
1529
1711
|
|
|
1530
1712
|
_defineProperty(this, "update", function (_ref5) {
|
|
1531
|
-
var isDragging = _ref5.isDragging
|
|
1532
|
-
|
|
1713
|
+
var isDragging = _ref5.isDragging,
|
|
1714
|
+
isDraggingKeyboard = _ref5.isDraggingKeyboard;
|
|
1715
|
+
if (!isDragging || !_this._elements.length || isDraggingKeyboard || _this.DS["continue"]) return;
|
|
1533
1716
|
var posDirection = calc(_this._cursorDiff, '+', _this._scrollDiff);
|
|
1534
1717
|
|
|
1535
1718
|
_this._elements.forEach(function (element) {
|
|
@@ -1551,6 +1734,7 @@
|
|
|
1551
1734
|
this.DS = DS;
|
|
1552
1735
|
this._useTransform = useTransform;
|
|
1553
1736
|
this._keyboardDragSpeed = keyboardDragSpeed;
|
|
1737
|
+
this._keyboardDrag = keyboardDrag;
|
|
1554
1738
|
this._zoom = zoom;
|
|
1555
1739
|
this._draggability = draggability;
|
|
1556
1740
|
this._dragKeys = {
|
|
@@ -1652,6 +1836,10 @@
|
|
|
1652
1836
|
_defineProperty(this, "isDragging", void 0);
|
|
1653
1837
|
|
|
1654
1838
|
_defineProperty(this, "init", function () {
|
|
1839
|
+
return _this.DS.publish('Interaction:init:pre', {});
|
|
1840
|
+
});
|
|
1841
|
+
|
|
1842
|
+
_defineProperty(this, "_init", function () {
|
|
1655
1843
|
_this.stop();
|
|
1656
1844
|
|
|
1657
1845
|
_this._areaElement.addEventListener('mousedown', _this.start);
|
|
@@ -1664,6 +1852,13 @@
|
|
|
1664
1852
|
});
|
|
1665
1853
|
|
|
1666
1854
|
_defineProperty(this, "start", function (event) {
|
|
1855
|
+
return _this.DS.publish('Interaction:start:pre', {
|
|
1856
|
+
event: event,
|
|
1857
|
+
isDragging: _this.isDragging
|
|
1858
|
+
});
|
|
1859
|
+
});
|
|
1860
|
+
|
|
1861
|
+
_defineProperty(this, "_start", function (event) {
|
|
1667
1862
|
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
|
|
1668
1863
|
|
|
1669
1864
|
if (!_this._canInteract(event)) return;
|
|
@@ -1708,8 +1903,7 @@
|
|
|
1708
1903
|
PointerStore = _this$DS$stores.PointerStore,
|
|
1709
1904
|
KeyStore = _this$DS$stores.KeyStore,
|
|
1710
1905
|
SelectableSet = _this$DS.SelectableSet,
|
|
1711
|
-
SelectedSet = _this$DS.SelectedSet
|
|
1712
|
-
publish = _this$DS.publish;
|
|
1906
|
+
SelectedSet = _this$DS.SelectedSet;
|
|
1713
1907
|
PointerStore.start(event);
|
|
1714
1908
|
var node =
|
|
1715
1909
|
/** @type {any} */
|
|
@@ -1717,10 +1911,9 @@
|
|
|
1717
1911
|
if (!SelectableSet.has(node)) return;
|
|
1718
1912
|
if (!KeyStore.isMultiSelectKeyPressed(event)) SelectedSet.clear();
|
|
1719
1913
|
SelectedSet.toggle(node);
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
}); // simulate mouse-up (that does not exist on keyboard)
|
|
1914
|
+
|
|
1915
|
+
_this.reset(); // simulate mouse-up (that does not exist on keyboard)
|
|
1916
|
+
|
|
1724
1917
|
});
|
|
1725
1918
|
|
|
1726
1919
|
_defineProperty(this, "stop", function () {
|
|
@@ -1740,15 +1933,24 @@
|
|
|
1740
1933
|
|
|
1741
1934
|
_defineProperty(this, "update", function (_ref3) {
|
|
1742
1935
|
var event = _ref3.event,
|
|
1743
|
-
|
|
1744
|
-
|
|
1936
|
+
scroll_directions = _ref3.scroll_directions,
|
|
1937
|
+
scroll_multiplier = _ref3.scroll_multiplier;
|
|
1938
|
+
if (_this.isInteracting) _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], {
|
|
1745
1939
|
event: event,
|
|
1746
|
-
|
|
1940
|
+
scroll_directions: scroll_directions,
|
|
1941
|
+
scroll_multiplier: scroll_multiplier,
|
|
1747
1942
|
isDragging: _this.isDragging
|
|
1748
1943
|
});
|
|
1749
1944
|
});
|
|
1750
1945
|
|
|
1751
1946
|
_defineProperty(this, "reset", function (event) {
|
|
1947
|
+
return _this.DS.publish('Interaction:end:pre', {
|
|
1948
|
+
event: event,
|
|
1949
|
+
isDragging: _this.isDragging
|
|
1950
|
+
});
|
|
1951
|
+
});
|
|
1952
|
+
|
|
1953
|
+
_defineProperty(this, "_reset", function (event) {
|
|
1752
1954
|
var isDragging = _this.isDragging;
|
|
1753
1955
|
|
|
1754
1956
|
_this.stop();
|
|
@@ -1771,19 +1973,41 @@
|
|
|
1771
1973
|
var event = _ref4.event;
|
|
1772
1974
|
return _this.start(event);
|
|
1773
1975
|
});
|
|
1976
|
+
this.DS.subscribe('Interaction:start:pre', function (_ref5) {
|
|
1977
|
+
var event = _ref5.event;
|
|
1978
|
+
return _this._start(event);
|
|
1979
|
+
});
|
|
1980
|
+
this.DS.subscribe('Interaction:init:pre', this._init);
|
|
1981
|
+
this.DS.subscribe('Interaction:end:pre', function (_ref6) {
|
|
1982
|
+
var event = _ref6.event;
|
|
1983
|
+
return _this._reset(event);
|
|
1984
|
+
});
|
|
1774
1985
|
this.DS.subscribe('Area:scroll', this.update);
|
|
1775
1986
|
}
|
|
1776
1987
|
|
|
1777
1988
|
_createClass(Interaction, [{
|
|
1778
1989
|
key: "_canInteract",
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* @param {DSEvent} event
|
|
1993
|
+
*/
|
|
1779
1994
|
value: function _canInteract(event) {
|
|
1995
|
+
var isKeyboardClick =
|
|
1996
|
+
/** @type {MouseEvent} */
|
|
1997
|
+
event.clientX === 0 &&
|
|
1998
|
+
/** @type {MouseEvent} */
|
|
1999
|
+
event.clientY === 0 &&
|
|
2000
|
+
/** @type {MouseEvent} */
|
|
2001
|
+
event.detail === 0 && event.target;
|
|
1780
2002
|
if (
|
|
1781
|
-
|
|
1782
|
-
event.button === 2 ||
|
|
1783
|
-
|
|
1784
|
-
this.
|
|
1785
|
-
|
|
1786
|
-
event.target
|
|
2003
|
+
/** @type {MouseEvent} */
|
|
2004
|
+
event.button === 2 || // right-clicks
|
|
2005
|
+
this.isInteracting || // fix double-click issues
|
|
2006
|
+
event.target && !this.DS.SelectorArea.isInside(
|
|
2007
|
+
/** @type {DSElement} */
|
|
2008
|
+
event.target) || //fix outside elements issue
|
|
2009
|
+
!isKeyboardClick && !this.DS.SelectorArea.isClicked(event) // make sure the mouse click is inside the area
|
|
2010
|
+
) return false;
|
|
1787
2011
|
return true;
|
|
1788
2012
|
}
|
|
1789
2013
|
/**
|
|
@@ -1795,9 +2019,11 @@
|
|
|
1795
2019
|
return Interaction;
|
|
1796
2020
|
}();
|
|
1797
2021
|
|
|
1798
|
-
var PubSub = function PubSub() {
|
|
2022
|
+
var PubSub = function PubSub(_ref) {
|
|
1799
2023
|
var _this = this;
|
|
1800
2024
|
|
|
2025
|
+
var DS = _ref.DS;
|
|
2026
|
+
|
|
1801
2027
|
_classCallCheck(this, PubSub);
|
|
1802
2028
|
|
|
1803
2029
|
_defineProperty(this, "subscribers", {});
|
|
@@ -1817,13 +2043,44 @@
|
|
|
1817
2043
|
});
|
|
1818
2044
|
|
|
1819
2045
|
_defineProperty(this, "publish", function (eventName, data) {
|
|
1820
|
-
if (
|
|
2046
|
+
if (Array.isArray(eventName)) eventName.forEach(function (name) {
|
|
2047
|
+
return _this._publish(name, data);
|
|
2048
|
+
});else _this._publish(eventName, data);
|
|
2049
|
+
});
|
|
1821
2050
|
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
2051
|
+
_defineProperty(this, "_publish", function (eventName, data) {
|
|
2052
|
+
var subscribers = _this.subscribers[eventName];
|
|
2053
|
+
if (!Array.isArray(subscribers)) return;
|
|
2054
|
+
if (eventName.includes(":pre")) _this._handlePrePublish(subscribers, data);else _this._handlePublish(subscribers, data);
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
_defineProperty(this, "_handlePublish", function (subscribers, data) {
|
|
2058
|
+
for (var i = 0, il = subscribers.length; i < il; i++) {
|
|
2059
|
+
if (_this.DS.stopped) return;
|
|
2060
|
+
subscribers[i](data);
|
|
2061
|
+
}
|
|
2062
|
+
});
|
|
2063
|
+
|
|
2064
|
+
_defineProperty(this, "_handlePrePublish", function (subscribers, data) {
|
|
2065
|
+
var i = subscribers.length;
|
|
2066
|
+
|
|
2067
|
+
while (i--) {
|
|
2068
|
+
if (_this.DS.stopped) return;
|
|
2069
|
+
subscribers[i](data);
|
|
2070
|
+
}
|
|
1825
2071
|
});
|
|
1826
|
-
|
|
2072
|
+
|
|
2073
|
+
this.DS = DS;
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Subscribe to an event
|
|
2077
|
+
* @memberof DragSelect#
|
|
2078
|
+
* @function subscribe
|
|
2079
|
+
* @param {DSCallbackNames} eventName
|
|
2080
|
+
* @param {DSCallback} callback
|
|
2081
|
+
* @returns {number} event id, can be used to unsubscribe more efficiently
|
|
2082
|
+
*/
|
|
2083
|
+
;
|
|
1827
2084
|
|
|
1828
2085
|
var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
1829
2086
|
_inherits(SelectableSet, _Set);
|
|
@@ -1903,13 +2160,13 @@
|
|
|
1903
2160
|
});
|
|
1904
2161
|
|
|
1905
2162
|
_defineProperty(_assertThisInitialized(_this), "_onClick", function (event) {
|
|
1906
|
-
return _this.DS.publish('Selectable:click', {
|
|
2163
|
+
return _this.DS.publish(['Selectable:click:pre', 'Selectable:click'], {
|
|
1907
2164
|
event: event
|
|
1908
2165
|
});
|
|
1909
2166
|
});
|
|
1910
2167
|
|
|
1911
2168
|
_defineProperty(_assertThisInitialized(_this), "_onPointer", function (event) {
|
|
1912
|
-
return _this.DS.publish('Selectable:pointer', {
|
|
2169
|
+
return _this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], {
|
|
1913
2170
|
event: event
|
|
1914
2171
|
});
|
|
1915
2172
|
});
|
|
@@ -2041,15 +2298,17 @@
|
|
|
2041
2298
|
key: "add",
|
|
2042
2299
|
value: function add(element) {
|
|
2043
2300
|
if (_get(_getPrototypeOf(SelectedSet.prototype), "has", this).call(this, element)) return;
|
|
2301
|
+
var publishData = {
|
|
2302
|
+
items: this.elements,
|
|
2303
|
+
item: element
|
|
2304
|
+
};
|
|
2305
|
+
this.DS.publish('Selected:added:pre', publishData);
|
|
2044
2306
|
|
|
2045
2307
|
_get(_getPrototypeOf(SelectedSet.prototype), "add", this).call(this, element);
|
|
2046
2308
|
|
|
2047
2309
|
element.classList.add(this._className);
|
|
2048
|
-
this.DS.publish('Selected:added', {
|
|
2049
|
-
items: this.elements,
|
|
2050
|
-
item: element
|
|
2051
|
-
});
|
|
2052
2310
|
element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + 1);
|
|
2311
|
+
this.DS.publish('Selected:added', publishData);
|
|
2053
2312
|
return this;
|
|
2054
2313
|
}
|
|
2055
2314
|
/** @param {DSElement} element */
|
|
@@ -2058,15 +2317,17 @@
|
|
|
2058
2317
|
key: "delete",
|
|
2059
2318
|
value: function _delete(element) {
|
|
2060
2319
|
if (!_get(_getPrototypeOf(SelectedSet.prototype), "has", this).call(this, element)) return;
|
|
2320
|
+
var publishData = {
|
|
2321
|
+
items: this.elements,
|
|
2322
|
+
item: element
|
|
2323
|
+
};
|
|
2324
|
+
this.DS.publish('Selected:removed:pre', publishData);
|
|
2061
2325
|
|
|
2062
2326
|
var deleted = _get(_getPrototypeOf(SelectedSet.prototype), "delete", this).call(this, element);
|
|
2063
2327
|
|
|
2064
2328
|
element.classList.remove(this._className);
|
|
2065
|
-
this.DS.publish('Selected:removed', {
|
|
2066
|
-
items: this.elements,
|
|
2067
|
-
item: element
|
|
2068
|
-
});
|
|
2069
2329
|
element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) - 1);
|
|
2330
|
+
this.DS.publish('Selected:removed', publishData);
|
|
2070
2331
|
return deleted;
|
|
2071
2332
|
}
|
|
2072
2333
|
}, {
|
|
@@ -2143,7 +2404,7 @@
|
|
|
2143
2404
|
|
|
2144
2405
|
_defineProperty(this, "update", function (_ref3) {
|
|
2145
2406
|
var isDragging = _ref3.isDragging;
|
|
2146
|
-
if (isDragging) return;
|
|
2407
|
+
if (isDragging || _this.DS["continue"]) return;
|
|
2147
2408
|
|
|
2148
2409
|
_this._handleInsideSelection();
|
|
2149
2410
|
});
|
|
@@ -2168,6 +2429,7 @@
|
|
|
2168
2429
|
|
|
2169
2430
|
var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this._multiSelectToggling;
|
|
2170
2431
|
|
|
2432
|
+
if (_this.DS["continue"]) return;
|
|
2171
2433
|
select.forEach(function (element) {
|
|
2172
2434
|
return handleSelection({
|
|
2173
2435
|
element: element,
|
|
@@ -2261,7 +2523,7 @@
|
|
|
2261
2523
|
|
|
2262
2524
|
_defineProperty(this, "update", function (_ref3) {
|
|
2263
2525
|
var isDragging = _ref3.isDragging;
|
|
2264
|
-
if (isDragging) return;
|
|
2526
|
+
if (isDragging || _this.DS["continue"]) return;
|
|
2265
2527
|
var _this$DS$stores = _this.DS.stores,
|
|
2266
2528
|
ScrollStore = _this$DS$stores.ScrollStore,
|
|
2267
2529
|
PointerStore = _this$DS$stores.PointerStore;
|
|
@@ -2345,6 +2607,20 @@
|
|
|
2345
2607
|
|
|
2346
2608
|
_defineProperty(this, "_overflowTolerance", void 0);
|
|
2347
2609
|
|
|
2610
|
+
_defineProperty(this, "start", function () {
|
|
2611
|
+
return _this.applyElements('append');
|
|
2612
|
+
});
|
|
2613
|
+
|
|
2614
|
+
_defineProperty(this, "applyElements", function () {
|
|
2615
|
+
var method = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'append';
|
|
2616
|
+
var docEl = document.body ? 'body' : 'documentElement';
|
|
2617
|
+
var methodName = "".concat(method, "Child");
|
|
2618
|
+
|
|
2619
|
+
_this.HTMLNode[methodName](_this.DS.Selector.HTMLNode);
|
|
2620
|
+
|
|
2621
|
+
document[docEl][methodName](_this.HTMLNode);
|
|
2622
|
+
});
|
|
2623
|
+
|
|
2348
2624
|
_defineProperty(this, "updatePos", function () {
|
|
2349
2625
|
_this._rect = null;
|
|
2350
2626
|
var rect = _this.DS.Area.rect;
|
|
@@ -2360,6 +2636,12 @@
|
|
|
2360
2636
|
if (style.height !== height) style.height = height;
|
|
2361
2637
|
});
|
|
2362
2638
|
|
|
2639
|
+
_defineProperty(this, "stop", function (remove) {
|
|
2640
|
+
_this.stopAutoScroll();
|
|
2641
|
+
|
|
2642
|
+
if (remove) _this.applyElements('remove');
|
|
2643
|
+
});
|
|
2644
|
+
|
|
2363
2645
|
_defineProperty(this, "startAutoScroll", function () {
|
|
2364
2646
|
_this.currentEdges = [];
|
|
2365
2647
|
_this._scrollInterval = setInterval(function () {
|
|
@@ -2368,6 +2650,7 @@
|
|
|
2368
2650
|
});
|
|
2369
2651
|
|
|
2370
2652
|
_defineProperty(this, "handleAutoScroll", function () {
|
|
2653
|
+
if (_this.DS["continue"]) return;
|
|
2371
2654
|
var _this$DS = _this.DS,
|
|
2372
2655
|
PointerStore = _this$DS.stores.PointerStore,
|
|
2373
2656
|
Area = _this$DS.Area;
|
|
@@ -2393,10 +2676,8 @@
|
|
|
2393
2676
|
this._overflowTolerance = overflowTolerance;
|
|
2394
2677
|
this.DS = DS;
|
|
2395
2678
|
this.HTMLNode = createSelectorAreaElement(selectorAreaClass);
|
|
2396
|
-
this.HTMLNode.appendChild(this.DS.Selector.HTMLNode);
|
|
2397
|
-
var docEl = document.body ? 'body' : 'documentElement';
|
|
2398
|
-
document[docEl].appendChild(this.HTMLNode);
|
|
2399
2679
|
this.DS.subscribe('Area:modified', this.updatePos);
|
|
2680
|
+
this.DS.subscribe('Interaction:init', this.start);
|
|
2400
2681
|
this.DS.subscribe('Interaction:start', this.startAutoScroll);
|
|
2401
2682
|
this.DS.subscribe('Interaction:end', function () {
|
|
2402
2683
|
_this.updatePos();
|
|
@@ -2404,23 +2685,23 @@
|
|
|
2404
2685
|
_this.stopAutoScroll();
|
|
2405
2686
|
});
|
|
2406
2687
|
}
|
|
2407
|
-
/** Updates the selectorAreas positions to match the areas */
|
|
2408
|
-
|
|
2409
2688
|
|
|
2410
2689
|
_createClass(SelectorArea, [{
|
|
2411
2690
|
key: "isClicked",
|
|
2412
2691
|
|
|
2413
2692
|
/**
|
|
2414
2693
|
* checks if the click was triggered on the area.
|
|
2694
|
+
* @param {DSEvent} [event]
|
|
2415
2695
|
* @returns {boolean}
|
|
2416
2696
|
*/
|
|
2417
|
-
value: function isClicked() {
|
|
2697
|
+
value: function isClicked(event) {
|
|
2418
2698
|
var PointerStore = this.DS.stores.PointerStore;
|
|
2699
|
+
var initialVal = event ? PointerStore.getPointerPosition(event) : PointerStore.initialVal;
|
|
2419
2700
|
return isCollision({
|
|
2420
|
-
left:
|
|
2421
|
-
top:
|
|
2422
|
-
right:
|
|
2423
|
-
bottom:
|
|
2701
|
+
left: initialVal.x,
|
|
2702
|
+
top: initialVal.y,
|
|
2703
|
+
right: initialVal.x,
|
|
2704
|
+
bottom: initialVal.y
|
|
2424
2705
|
}, this.rect);
|
|
2425
2706
|
}
|
|
2426
2707
|
}, {
|
|
@@ -2491,6 +2772,11 @@
|
|
|
2491
2772
|
_defineProperty(this, "keydown", function (event) {
|
|
2492
2773
|
var key = event.key.toLowerCase();
|
|
2493
2774
|
|
|
2775
|
+
_this.DS.publish('KeyStore:down:pre', {
|
|
2776
|
+
event: event,
|
|
2777
|
+
key: key
|
|
2778
|
+
});
|
|
2779
|
+
|
|
2494
2780
|
_this._currentValues.add(key);
|
|
2495
2781
|
|
|
2496
2782
|
_this.DS.publish('KeyStore:down', {
|
|
@@ -2502,6 +2788,11 @@
|
|
|
2502
2788
|
_defineProperty(this, "keyup", function (event) {
|
|
2503
2789
|
var key = event.key.toLowerCase();
|
|
2504
2790
|
|
|
2791
|
+
_this.DS.publish('KeyStore:up:pre', {
|
|
2792
|
+
event: event,
|
|
2793
|
+
key: key
|
|
2794
|
+
});
|
|
2795
|
+
|
|
2505
2796
|
_this._currentValues["delete"](key);
|
|
2506
2797
|
|
|
2507
2798
|
_this.DS.publish('KeyStore:up', {
|
|
@@ -2648,11 +2939,20 @@
|
|
|
2648
2939
|
});
|
|
2649
2940
|
});
|
|
2650
2941
|
|
|
2942
|
+
_defineProperty(this, "getPointerPosition", function (event) {
|
|
2943
|
+
return getPointerPos({
|
|
2944
|
+
event: _this._normalizedEvent(event)
|
|
2945
|
+
});
|
|
2946
|
+
});
|
|
2947
|
+
|
|
2651
2948
|
_defineProperty(this, "update", function (event) {
|
|
2652
2949
|
if (!event) return;
|
|
2653
|
-
|
|
2654
|
-
|
|
2950
|
+
|
|
2951
|
+
_this.DS.publish('PointerStore:updated:pre', {
|
|
2952
|
+
event: event
|
|
2655
2953
|
});
|
|
2954
|
+
|
|
2955
|
+
_this.currentVal = _this.getPointerPosition(event);
|
|
2656
2956
|
if (!_this._isMouseInteraction) return;
|
|
2657
2957
|
|
|
2658
2958
|
_this.DS.publish('PointerStore:updated', {
|
|
@@ -2674,9 +2974,7 @@
|
|
|
2674
2974
|
|
|
2675
2975
|
_defineProperty(this, "reset", function (event) {
|
|
2676
2976
|
if (!event) return;
|
|
2677
|
-
_this.currentVal = _this.lastVal =
|
|
2678
|
-
event: _this._normalizedEvent(event)
|
|
2679
|
-
});
|
|
2977
|
+
_this.currentVal = _this.lastVal = _this.getPointerPosition(event);
|
|
2680
2978
|
|
|
2681
2979
|
_this.stop();
|
|
2682
2980
|
|
|
@@ -2702,11 +3000,9 @@
|
|
|
2702
3000
|
value: function start(event) {
|
|
2703
3001
|
if (!event) return;
|
|
2704
3002
|
this._isMouseInteraction = true;
|
|
2705
|
-
this.currentVal = this.initialVal =
|
|
2706
|
-
event: this._normalizedEvent(event)
|
|
2707
|
-
});
|
|
3003
|
+
this.currentVal = this.initialVal = this.getPointerPosition(event);
|
|
2708
3004
|
}
|
|
2709
|
-
/** @param {DSEvent}
|
|
3005
|
+
/** @param {DSEvent} event */
|
|
2710
3006
|
|
|
2711
3007
|
}, {
|
|
2712
3008
|
key: "_normalizedEvent",
|
|
@@ -2929,6 +3225,11 @@
|
|
|
2929
3225
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
2930
3226
|
|
|
2931
3227
|
var DragSelect = /*#__PURE__*/function () {
|
|
3228
|
+
/**
|
|
3229
|
+
* used to skip all current Selection and dragNdrop functionality
|
|
3230
|
+
* @type {boolean}
|
|
3231
|
+
*/
|
|
3232
|
+
|
|
2932
3233
|
/**
|
|
2933
3234
|
* @class DragSelect
|
|
2934
3235
|
* @constructor DragSelect
|
|
@@ -2964,6 +3265,8 @@
|
|
|
2964
3265
|
draggability = _ref$draggability === void 0 ? true : _ref$draggability,
|
|
2965
3266
|
_ref$immediateDrag = _ref.immediateDrag,
|
|
2966
3267
|
immediateDrag = _ref$immediateDrag === void 0 ? true : _ref$immediateDrag,
|
|
3268
|
+
_ref$keyboardDrag = _ref.keyboardDrag,
|
|
3269
|
+
keyboardDrag = _ref$keyboardDrag === void 0 ? true : _ref$keyboardDrag,
|
|
2967
3270
|
dragKeys = _ref.dragKeys,
|
|
2968
3271
|
_ref$keyboardDragSpee = _ref.keyboardDragSpeed,
|
|
2969
3272
|
keyboardDragSpeed = _ref$keyboardDragSpee === void 0 ? 10 : _ref$keyboardDragSpee,
|
|
@@ -2988,8 +3291,16 @@
|
|
|
2988
3291
|
|
|
2989
3292
|
_classCallCheck(this, DragSelect);
|
|
2990
3293
|
|
|
3294
|
+
_defineProperty(this, "continue", false);
|
|
3295
|
+
|
|
2991
3296
|
_defineProperty(this, "start", function () {
|
|
2992
|
-
|
|
3297
|
+
_this.stopped = false;
|
|
3298
|
+
|
|
3299
|
+
_this.Interaction.init();
|
|
3300
|
+
});
|
|
3301
|
+
|
|
3302
|
+
_defineProperty(this, "break", function () {
|
|
3303
|
+
return _this["continue"] = true;
|
|
2993
3304
|
});
|
|
2994
3305
|
|
|
2995
3306
|
_defineProperty(this, "getSelection", function () {
|
|
@@ -3032,7 +3343,9 @@
|
|
|
3032
3343
|
return _this.Interaction.isDragging;
|
|
3033
3344
|
});
|
|
3034
3345
|
|
|
3035
|
-
this.PubSub = new PubSub(
|
|
3346
|
+
this.PubSub = new PubSub({
|
|
3347
|
+
DS: this
|
|
3348
|
+
});
|
|
3036
3349
|
this.subscribe = this.PubSub.subscribe;
|
|
3037
3350
|
this.unsubscribe = this.PubSub.unsubscribe;
|
|
3038
3351
|
this.publish = this.PubSub.publish;
|
|
@@ -3099,6 +3412,7 @@
|
|
|
3099
3412
|
DS: this,
|
|
3100
3413
|
draggability: draggability,
|
|
3101
3414
|
useTransform: useTransform,
|
|
3415
|
+
keyboardDrag: keyboardDrag,
|
|
3102
3416
|
dragKeys: Object.assign({
|
|
3103
3417
|
up: ['ArrowUp'],
|
|
3104
3418
|
down: ['ArrowDown'],
|
|
@@ -3115,61 +3429,14 @@
|
|
|
3115
3429
|
immediateDrag: immediateDrag
|
|
3116
3430
|
}); // Subscriber Aliases
|
|
3117
3431
|
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
item: item,
|
|
3124
|
-
isDragging: _this.Interaction.isDragging
|
|
3125
|
-
});
|
|
3432
|
+
subscriberAliases({
|
|
3433
|
+
subscribe: this.subscribe,
|
|
3434
|
+
publish: this.publish,
|
|
3435
|
+
SelectedSet: this.SelectedSet,
|
|
3436
|
+
Interaction: this.Interaction
|
|
3126
3437
|
});
|
|
3127
|
-
this.subscribe('
|
|
3128
|
-
|
|
3129
|
-
item = _ref3.item;
|
|
3130
|
-
return _this.publish('elementunselect', {
|
|
3131
|
-
items: items,
|
|
3132
|
-
item: item,
|
|
3133
|
-
isDragging: _this.Interaction.isDragging
|
|
3134
|
-
});
|
|
3135
|
-
});
|
|
3136
|
-
this.subscribe('Interaction:update', function (_ref4) {
|
|
3137
|
-
var event = _ref4.event,
|
|
3138
|
-
isDragging = _ref4.isDragging;
|
|
3139
|
-
if (event) _this.publish('dragmove', {
|
|
3140
|
-
items: _this.getSelection(),
|
|
3141
|
-
event: event,
|
|
3142
|
-
isDragging: isDragging
|
|
3143
|
-
});
|
|
3144
|
-
});
|
|
3145
|
-
this.subscribe('Area:scroll', function (_ref5) {
|
|
3146
|
-
var scroll_directions = _ref5.scroll_directions,
|
|
3147
|
-
scroll_multiplier = _ref5.scroll_multiplier;
|
|
3148
|
-
|
|
3149
|
-
_this.publish('autoscroll', {
|
|
3150
|
-
items: _this.getSelection(),
|
|
3151
|
-
scroll_directions: scroll_directions,
|
|
3152
|
-
scroll_multiplier: scroll_multiplier,
|
|
3153
|
-
isDragging: _this.Interaction.isDragging
|
|
3154
|
-
});
|
|
3155
|
-
});
|
|
3156
|
-
this.subscribe('Interaction:start', function (_ref6) {
|
|
3157
|
-
var event = _ref6.event,
|
|
3158
|
-
isDragging = _ref6.isDragging;
|
|
3159
|
-
return _this.publish('dragstart', {
|
|
3160
|
-
items: _this.getSelection(),
|
|
3161
|
-
event: event,
|
|
3162
|
-
isDragging: isDragging
|
|
3163
|
-
});
|
|
3164
|
-
});
|
|
3165
|
-
this.subscribe('Interaction:end', function (_ref7) {
|
|
3166
|
-
var event = _ref7.event,
|
|
3167
|
-
isDragging = _ref7.isDragging;
|
|
3168
|
-
return _this.publish('callback', {
|
|
3169
|
-
items: _this.getSelection(),
|
|
3170
|
-
event: event,
|
|
3171
|
-
isDragging: isDragging
|
|
3172
|
-
});
|
|
3438
|
+
this.subscribe('Interaction:end', function () {
|
|
3439
|
+
return _this["continue"] = false;
|
|
3173
3440
|
});
|
|
3174
3441
|
this.start();
|
|
3175
3442
|
} // @TODO: remove after deprecation
|
|
@@ -3177,13 +3444,13 @@
|
|
|
3177
3444
|
|
|
3178
3445
|
_createClass(DragSelect, [{
|
|
3179
3446
|
key: "_callbacksTemp",
|
|
3180
|
-
value: function _callbacksTemp(
|
|
3181
|
-
var callback =
|
|
3182
|
-
onDragMove =
|
|
3183
|
-
onDragStart =
|
|
3184
|
-
onDragStartBegin =
|
|
3185
|
-
onElementSelect =
|
|
3186
|
-
onElementUnselect =
|
|
3447
|
+
value: function _callbacksTemp(_ref2) {
|
|
3448
|
+
var callback = _ref2.callback,
|
|
3449
|
+
onDragMove = _ref2.onDragMove,
|
|
3450
|
+
onDragStart = _ref2.onDragStart,
|
|
3451
|
+
onDragStartBegin = _ref2.onDragStartBegin,
|
|
3452
|
+
onElementSelect = _ref2.onElementSelect,
|
|
3453
|
+
onElementUnselect = _ref2.onElementUnselect;
|
|
3187
3454
|
|
|
3188
3455
|
var warnMessage = function warnMessage(name, newName) {
|
|
3189
3456
|
return console.warn("[DragSelect] ".concat(name, " is deprecated. Use DragSelect.subscribe(\"").concat(newName, "\", (callbackObject) => {}) instead. Act Now! See docs for more info"));
|
|
@@ -3191,60 +3458,60 @@
|
|
|
3191
3458
|
|
|
3192
3459
|
if (callback) {
|
|
3193
3460
|
warnMessage('callback', 'callback');
|
|
3194
|
-
this.subscribe('callback', function (
|
|
3195
|
-
var items =
|
|
3196
|
-
item =
|
|
3197
|
-
event =
|
|
3461
|
+
this.subscribe('callback', function (_ref3) {
|
|
3462
|
+
var items = _ref3.items,
|
|
3463
|
+
item = _ref3.item,
|
|
3464
|
+
event = _ref3.event;
|
|
3198
3465
|
return callback(items, event);
|
|
3199
3466
|
});
|
|
3200
3467
|
}
|
|
3201
3468
|
|
|
3202
3469
|
if (onDragMove) {
|
|
3203
3470
|
warnMessage('onDragMove', 'dragmove');
|
|
3204
|
-
this.subscribe('dragmove', function (
|
|
3205
|
-
var items =
|
|
3206
|
-
item =
|
|
3207
|
-
event =
|
|
3471
|
+
this.subscribe('dragmove', function (_ref4) {
|
|
3472
|
+
var items = _ref4.items,
|
|
3473
|
+
item = _ref4.item,
|
|
3474
|
+
event = _ref4.event;
|
|
3208
3475
|
return onDragMove(event);
|
|
3209
3476
|
});
|
|
3210
3477
|
}
|
|
3211
3478
|
|
|
3212
3479
|
if (onDragStart) {
|
|
3213
3480
|
warnMessage('onDragStart', 'dragstart');
|
|
3214
|
-
this.subscribe('dragstart', function (
|
|
3215
|
-
var items =
|
|
3216
|
-
item =
|
|
3217
|
-
event =
|
|
3481
|
+
this.subscribe('dragstart', function (_ref5) {
|
|
3482
|
+
var items = _ref5.items,
|
|
3483
|
+
item = _ref5.item,
|
|
3484
|
+
event = _ref5.event;
|
|
3218
3485
|
return onDragStart(event);
|
|
3219
3486
|
});
|
|
3220
3487
|
}
|
|
3221
3488
|
|
|
3222
3489
|
if (onDragStartBegin) {
|
|
3223
3490
|
warnMessage('onDragStartBegin', 'dragstart');
|
|
3224
|
-
this.subscribe('dragstart', function (
|
|
3225
|
-
var items =
|
|
3226
|
-
item =
|
|
3227
|
-
event =
|
|
3491
|
+
this.subscribe('dragstart', function (_ref6) {
|
|
3492
|
+
var items = _ref6.items,
|
|
3493
|
+
item = _ref6.item,
|
|
3494
|
+
event = _ref6.event;
|
|
3228
3495
|
return onDragStartBegin(event);
|
|
3229
3496
|
});
|
|
3230
3497
|
}
|
|
3231
3498
|
|
|
3232
3499
|
if (onElementSelect) {
|
|
3233
3500
|
warnMessage('onElementSelect', 'elementselect');
|
|
3234
|
-
this.subscribe('elementselect', function (
|
|
3235
|
-
var items =
|
|
3236
|
-
item =
|
|
3237
|
-
event =
|
|
3501
|
+
this.subscribe('elementselect', function (_ref7) {
|
|
3502
|
+
var items = _ref7.items,
|
|
3503
|
+
item = _ref7.item,
|
|
3504
|
+
event = _ref7.event;
|
|
3238
3505
|
return onElementSelect(item, event);
|
|
3239
3506
|
});
|
|
3240
3507
|
}
|
|
3241
3508
|
|
|
3242
3509
|
if (onElementUnselect) {
|
|
3243
3510
|
warnMessage('onElementUnselect', 'elementunselect');
|
|
3244
|
-
this.subscribe('elementunselect', function (
|
|
3245
|
-
var items =
|
|
3246
|
-
item =
|
|
3247
|
-
event =
|
|
3511
|
+
this.subscribe('elementunselect', function (_ref8) {
|
|
3512
|
+
var items = _ref8.items,
|
|
3513
|
+
item = _ref8.item,
|
|
3514
|
+
event = _ref8.event;
|
|
3248
3515
|
return onElementUnselect(item, event);
|
|
3249
3516
|
});
|
|
3250
3517
|
}
|
|
@@ -3277,15 +3544,18 @@
|
|
|
3277
3544
|
this.Area.stop();
|
|
3278
3545
|
this.Drag.stop();
|
|
3279
3546
|
this.Selector.stop();
|
|
3547
|
+
this.SelectorArea.stop(remove);
|
|
3280
3548
|
this.stores.KeyStore.stop();
|
|
3281
3549
|
this.stores.PointerStore.stop();
|
|
3282
3550
|
this.stores.ScrollStore.stop();
|
|
3283
3551
|
if (remove) this.SelectableSet.clear();
|
|
3284
3552
|
if (fromSelection) this.SelectedSet.clear();
|
|
3553
|
+
this.stopped = true;
|
|
3285
3554
|
}
|
|
3286
3555
|
/**
|
|
3287
|
-
*
|
|
3288
|
-
*
|
|
3556
|
+
* Utility to override DragSelect internal functionality:
|
|
3557
|
+
* Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
|
|
3558
|
+
* Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
|
|
3289
3559
|
*/
|
|
3290
3560
|
|
|
3291
3561
|
}, {
|
|
@@ -3449,16 +3719,18 @@
|
|
|
3449
3719
|
key: "getCursorPositionDifference",
|
|
3450
3720
|
|
|
3451
3721
|
/**
|
|
3452
|
-
*
|
|
3722
|
+
* Utility method that returns the cursor position difference between start and now
|
|
3453
3723
|
* @param {boolean} [usePreviousCursorDifference] if true, it will output the cursor position difference between the previous selection and now
|
|
3724
|
+
* @param {boolean} [useAreaPositions] if true, it will use cursor positions relative to the area
|
|
3454
3725
|
* @return {Vect2}
|
|
3455
3726
|
* @deprecated
|
|
3456
3727
|
*/
|
|
3457
3728
|
value: function getCursorPositionDifference() {
|
|
3458
3729
|
var usePreviousCursorDifference = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
3730
|
+
var useAreaPositions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3459
3731
|
console.warn('[DragSelect] Using .getCursorPositionDifference is deprecated. Calculate yourself instead. i.e. `.getCurrentCursorPosition().x - .getInitialCursorPosition().x`');
|
|
3460
|
-
var posA = this.getCurrentCursorPosition();
|
|
3461
|
-
var posB = usePreviousCursorDifference ? this.getPreviousCursorPosition() : this.getInitialCursorPosition();
|
|
3732
|
+
var posA = useAreaPositions ? this.getCurrentCursorPositionArea() : this.getCurrentCursorPosition();
|
|
3733
|
+
var posB = usePreviousCursorDifference ? useAreaPositions ? this.getPreviousCursorPositionArea() : this.getPreviousCursorPosition() : useAreaPositions ? this.getInitialCursorPositionArea() : this.getInitialCursorPosition();
|
|
3462
3734
|
return calc(posA, '-', posB);
|
|
3463
3735
|
}
|
|
3464
3736
|
/**
|