dragselect 2.2.1 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/README.md +17 -9
- package/dist/DragSelect.d.ts +2 -1
- package/dist/DragSelect.es6m.js +221 -99
- package/dist/DragSelect.js +221 -99
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/modules/Area.d.ts +15 -9
- package/dist/modules/Interaction.d.ts +18 -5
- package/dist/modules/PubSub.d.ts +9 -2
- package/dist/modules/SelectorArea.d.ts +2 -1
- package/dist/stores/PointerStore.d.ts +2 -0
- package/dist/types.d.ts +2 -2
- package/package.json +2 -1
- package/src/DragSelect.js +8 -2
- package/src/methods/subscriberAliases.js +0 -1
- package/src/modules/Area.js +29 -17
- package/src/modules/Drag.js +7 -9
- package/src/modules/Interaction.js +61 -18
- package/src/modules/PubSub.js +34 -4
- package/src/modules/SelectableSet.js +2 -2
- package/src/modules/SelectedSet.js +12 -8
- package/src/modules/Selection.js +1 -0
- package/src/modules/SelectorArea.js +10 -5
- package/src/stores/KeyStore.js +2 -0
- package/src/stores/PointerStore.js +9 -8
- package/src/types.js +2 -2
package/dist/DragSelect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/***
|
|
2
2
|
|
|
3
|
-
~~~ Version 2.
|
|
3
|
+
~~~ Version 2.3.1 ~~~
|
|
4
4
|
|
|
5
5
|
******************************************
|
|
6
6
|
|
|
@@ -416,9 +416,9 @@
|
|
|
416
416
|
|
|
417
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 */
|
|
418
418
|
|
|
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'
|
|
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
420
|
|
|
421
|
-
/** @typedef {DSEventNames|DSInternalEventNames} DSCallbackNames the name of the callback */
|
|
421
|
+
/** @typedef {DSEventNames|DSInternalEventNames|DSInternalEventNamesPre} DSCallbackNames the name of the callback */
|
|
422
422
|
|
|
423
423
|
/** @typedef {{top:number,left:number,bottom:number,right:number,width:number,height:number}} DSBoundingRect */
|
|
424
424
|
|
|
@@ -1261,12 +1261,6 @@
|
|
|
1261
1261
|
// event, isDraggingKeyboard
|
|
1262
1262
|
'Interaction:end': [{
|
|
1263
1263
|
name: 'callback'
|
|
1264
|
-
}],
|
|
1265
|
-
// event, isDraggingKeyboard
|
|
1266
|
-
'Drag:keyboardDrag': [{
|
|
1267
|
-
name: 'dragstart'
|
|
1268
|
-
}, {
|
|
1269
|
-
name: 'dragmove'
|
|
1270
1264
|
}] // event, isDraggingKeyboard
|
|
1271
1265
|
|
|
1272
1266
|
};
|
|
@@ -1320,6 +1314,13 @@
|
|
|
1320
1314
|
element.style.height = "".concat(pos.height, "px");
|
|
1321
1315
|
});
|
|
1322
1316
|
|
|
1317
|
+
/**
|
|
1318
|
+
* @typedef {Object} AreaProps
|
|
1319
|
+
* @property {DSArea} area
|
|
1320
|
+
* @property {PubSub} PS
|
|
1321
|
+
* @property {number} zoom
|
|
1322
|
+
*/
|
|
1323
|
+
|
|
1323
1324
|
var Area = /*#__PURE__*/function () {
|
|
1324
1325
|
/**
|
|
1325
1326
|
* @type {DSModificationCallback}
|
|
@@ -1363,16 +1364,13 @@
|
|
|
1363
1364
|
|
|
1364
1365
|
/**
|
|
1365
1366
|
* @constructor Area
|
|
1366
|
-
* @param {
|
|
1367
|
-
* @param {DSArea} obj.area
|
|
1368
|
-
* @param {PubSub} obj.PS
|
|
1369
|
-
* @param {number} obj.zoom
|
|
1367
|
+
* @param {AreaProps} settings
|
|
1370
1368
|
* @ignore
|
|
1371
1369
|
*/
|
|
1372
1370
|
function Area(_ref) {
|
|
1373
1371
|
var _this = this;
|
|
1374
1372
|
|
|
1375
|
-
var
|
|
1373
|
+
var _area = _ref.area,
|
|
1376
1374
|
PS = _ref.PS,
|
|
1377
1375
|
zoom = _ref.zoom;
|
|
1378
1376
|
|
|
@@ -1394,6 +1392,26 @@
|
|
|
1394
1392
|
|
|
1395
1393
|
_defineProperty(this, "_rect", void 0);
|
|
1396
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
|
+
|
|
1397
1415
|
_defineProperty(this, "start", function () {
|
|
1398
1416
|
addModificationObservers(_this.parentNodes, _this._modificationCallback, _this._modificationObserver);
|
|
1399
1417
|
});
|
|
@@ -1412,42 +1430,40 @@
|
|
|
1412
1430
|
});
|
|
1413
1431
|
|
|
1414
1432
|
_defineProperty(this, "scroll", function (directions, multiplier) {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
_this.PubSub.publish('Area:scroll', {
|
|
1433
|
+
var data = {
|
|
1418
1434
|
scroll_directions: directions,
|
|
1419
1435
|
scroll_multiplier: multiplier
|
|
1420
|
-
}
|
|
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);
|
|
1421
1443
|
});
|
|
1422
1444
|
|
|
1423
|
-
this._node = area;
|
|
1424
1445
|
this._zoom = zoom;
|
|
1425
1446
|
this.PubSub = PS;
|
|
1426
|
-
|
|
1427
|
-
computedStyle: this.computedStyle,
|
|
1428
|
-
node: this._node
|
|
1429
|
-
});
|
|
1447
|
+
this.setArea(_area);
|
|
1430
1448
|
this._modificationCallback = debounce(function (event) {
|
|
1431
|
-
_this.
|
|
1432
|
-
|
|
1433
|
-
_this.PubSub.publish('Area:modified', {
|
|
1449
|
+
_this.PubSub.publish('Area:modified:pre', {
|
|
1434
1450
|
event: event,
|
|
1435
1451
|
item: _this
|
|
1436
1452
|
});
|
|
1437
|
-
}, 60);
|
|
1438
|
-
this._modificationObserver = new MutationObserver(this._modificationCallback); // first immediate debounce to update values after dom-update
|
|
1439
1453
|
|
|
1440
|
-
setTimeout(function () {
|
|
1441
1454
|
_this.reset();
|
|
1442
1455
|
|
|
1443
1456
|
_this.PubSub.publish('Area:modified', {
|
|
1444
1457
|
event: event,
|
|
1445
1458
|
item: _this
|
|
1446
1459
|
});
|
|
1447
|
-
});
|
|
1460
|
+
}, 60);
|
|
1461
|
+
this._modificationObserver = new MutationObserver(this._modificationCallback);
|
|
1448
1462
|
this.PubSub.subscribe('Interaction:init', this.start);
|
|
1449
1463
|
this.PubSub.subscribe('Interaction:end', this.reset);
|
|
1450
1464
|
}
|
|
1465
|
+
/** @param {DSArea} area */
|
|
1466
|
+
|
|
1451
1467
|
|
|
1452
1468
|
_createClass(Area, [{
|
|
1453
1469
|
key: "HTMLNode",
|
|
@@ -1624,12 +1640,13 @@
|
|
|
1624
1640
|
var event = _ref2.event,
|
|
1625
1641
|
key = _ref2.key;
|
|
1626
1642
|
if (!_this._keyboardDrag || !_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability || _this.DS["continue"]) return;
|
|
1627
|
-
|
|
1628
|
-
_this.DS.publish('Interaction:start', {
|
|
1643
|
+
var publishData = {
|
|
1629
1644
|
event: event,
|
|
1630
1645
|
isDragging: true,
|
|
1631
1646
|
isDraggingKeyboard: true
|
|
1632
|
-
}
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
_this.DS.publish(['Interaction:start:pre', 'Interaction:start'], publishData);
|
|
1633
1650
|
|
|
1634
1651
|
_this._elements = _this.DS.getSelection();
|
|
1635
1652
|
|
|
@@ -1655,23 +1672,20 @@
|
|
|
1655
1672
|
});
|
|
1656
1673
|
});
|
|
1657
1674
|
|
|
1658
|
-
_this.DS.publish('Interaction:update',
|
|
1659
|
-
event: event,
|
|
1660
|
-
isDragging: true,
|
|
1661
|
-
isDraggingKeyboard: true
|
|
1662
|
-
});
|
|
1675
|
+
_this.DS.publish(['Interaction:update:pre', 'Interaction:update'], publishData);
|
|
1663
1676
|
});
|
|
1664
1677
|
|
|
1665
1678
|
_defineProperty(this, "keyboardEnd", function (_ref3) {
|
|
1666
1679
|
var event = _ref3.event,
|
|
1667
1680
|
key = _ref3.key;
|
|
1668
1681
|
if (!_this._keyboardDrag || !_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability) return;
|
|
1669
|
-
|
|
1670
|
-
_this.DS.publish('Interaction:end', {
|
|
1682
|
+
var publishData = {
|
|
1671
1683
|
event: event,
|
|
1672
1684
|
isDragging: _this._draggability,
|
|
1673
1685
|
isDraggingKeyboard: true
|
|
1674
|
-
}
|
|
1686
|
+
};
|
|
1687
|
+
|
|
1688
|
+
_this.DS.publish(['Interaction:end:pre', 'Interaction:end'], publishData);
|
|
1675
1689
|
});
|
|
1676
1690
|
|
|
1677
1691
|
_defineProperty(this, "start", function (_ref4) {
|
|
@@ -1788,6 +1802,11 @@
|
|
|
1788
1802
|
* @private
|
|
1789
1803
|
* */
|
|
1790
1804
|
|
|
1805
|
+
/**
|
|
1806
|
+
* @type {string}
|
|
1807
|
+
* @private
|
|
1808
|
+
* */
|
|
1809
|
+
|
|
1791
1810
|
/** @type {boolean} */
|
|
1792
1811
|
|
|
1793
1812
|
/** @type {boolean} */
|
|
@@ -1795,19 +1814,21 @@
|
|
|
1795
1814
|
/**
|
|
1796
1815
|
* @constructor Interaction
|
|
1797
1816
|
* @param {Object} obj
|
|
1817
|
+
* @param {DragSelect} obj.DS
|
|
1798
1818
|
* @param {DSArea} obj.areaElement
|
|
1799
1819
|
* @param {boolean} obj.draggability
|
|
1800
1820
|
* @param {boolean} obj.immediateDrag
|
|
1801
|
-
* @param {
|
|
1821
|
+
* @param {string} obj.selectableClass
|
|
1802
1822
|
* @ignore
|
|
1803
1823
|
*/
|
|
1804
1824
|
function Interaction(_ref) {
|
|
1805
1825
|
var _this = this;
|
|
1806
1826
|
|
|
1807
|
-
var
|
|
1808
|
-
|
|
1827
|
+
var DS = _ref.DS,
|
|
1828
|
+
areaElement = _ref.areaElement,
|
|
1809
1829
|
draggability = _ref.draggability,
|
|
1810
|
-
immediateDrag = _ref.immediateDrag
|
|
1830
|
+
immediateDrag = _ref.immediateDrag,
|
|
1831
|
+
selectableClass = _ref.selectableClass;
|
|
1811
1832
|
|
|
1812
1833
|
_classCallCheck(this, Interaction);
|
|
1813
1834
|
|
|
@@ -1817,11 +1838,17 @@
|
|
|
1817
1838
|
|
|
1818
1839
|
_defineProperty(this, "_immediateDrag", void 0);
|
|
1819
1840
|
|
|
1841
|
+
_defineProperty(this, "_selectableClass", void 0);
|
|
1842
|
+
|
|
1820
1843
|
_defineProperty(this, "isInteracting", void 0);
|
|
1821
1844
|
|
|
1822
1845
|
_defineProperty(this, "isDragging", void 0);
|
|
1823
1846
|
|
|
1824
1847
|
_defineProperty(this, "init", function () {
|
|
1848
|
+
return _this.DS.publish('Interaction:init:pre', {});
|
|
1849
|
+
});
|
|
1850
|
+
|
|
1851
|
+
_defineProperty(this, "_init", function () {
|
|
1825
1852
|
_this.stop();
|
|
1826
1853
|
|
|
1827
1854
|
_this._areaElement.addEventListener('mousedown', _this.start);
|
|
@@ -1834,6 +1861,13 @@
|
|
|
1834
1861
|
});
|
|
1835
1862
|
|
|
1836
1863
|
_defineProperty(this, "start", function (event) {
|
|
1864
|
+
return _this.DS.publish('Interaction:start:pre', {
|
|
1865
|
+
event: event,
|
|
1866
|
+
isDragging: _this.isDragging
|
|
1867
|
+
});
|
|
1868
|
+
});
|
|
1869
|
+
|
|
1870
|
+
_defineProperty(this, "_start", function (event) {
|
|
1837
1871
|
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
|
|
1838
1872
|
|
|
1839
1873
|
if (!_this._canInteract(event)) return;
|
|
@@ -1850,21 +1884,24 @@
|
|
|
1850
1884
|
});
|
|
1851
1885
|
|
|
1852
1886
|
_defineProperty(this, "isDragEvent", function (event) {
|
|
1853
|
-
|
|
1887
|
+
var clickedElement =
|
|
1888
|
+
/** @type {Element} */
|
|
1889
|
+
event.target.closest(".".concat(_this._selectableClass));
|
|
1890
|
+
if (!_this._draggability || _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) || !clickedElement) return false;
|
|
1854
1891
|
|
|
1855
1892
|
if (_this._immediateDrag) {
|
|
1856
1893
|
if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add(
|
|
1857
1894
|
/** @type {DSElement} */
|
|
1858
|
-
|
|
1895
|
+
clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
|
|
1859
1896
|
_this.DS.SelectedSet.clear();
|
|
1860
1897
|
|
|
1861
1898
|
_this.DS.SelectedSet.add(
|
|
1862
1899
|
/** @type {DSElement} */
|
|
1863
|
-
|
|
1900
|
+
clickedElement);
|
|
1864
1901
|
}
|
|
1865
1902
|
}
|
|
1866
1903
|
|
|
1867
|
-
if (_this.DS.SelectedSet.has(
|
|
1904
|
+
if (_this.DS.SelectedSet.has(clickedElement)) return true;
|
|
1868
1905
|
return false;
|
|
1869
1906
|
});
|
|
1870
1907
|
|
|
@@ -1878,8 +1915,7 @@
|
|
|
1878
1915
|
PointerStore = _this$DS$stores.PointerStore,
|
|
1879
1916
|
KeyStore = _this$DS$stores.KeyStore,
|
|
1880
1917
|
SelectableSet = _this$DS.SelectableSet,
|
|
1881
|
-
SelectedSet = _this$DS.SelectedSet
|
|
1882
|
-
publish = _this$DS.publish;
|
|
1918
|
+
SelectedSet = _this$DS.SelectedSet;
|
|
1883
1919
|
PointerStore.start(event);
|
|
1884
1920
|
var node =
|
|
1885
1921
|
/** @type {any} */
|
|
@@ -1887,10 +1923,9 @@
|
|
|
1887
1923
|
if (!SelectableSet.has(node)) return;
|
|
1888
1924
|
if (!KeyStore.isMultiSelectKeyPressed(event)) SelectedSet.clear();
|
|
1889
1925
|
SelectedSet.toggle(node);
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
}); // simulate mouse-up (that does not exist on keyboard)
|
|
1926
|
+
|
|
1927
|
+
_this.reset(); // simulate mouse-up (that does not exist on keyboard)
|
|
1928
|
+
|
|
1894
1929
|
});
|
|
1895
1930
|
|
|
1896
1931
|
_defineProperty(this, "stop", function () {
|
|
@@ -1912,7 +1947,7 @@
|
|
|
1912
1947
|
var event = _ref3.event,
|
|
1913
1948
|
scroll_directions = _ref3.scroll_directions,
|
|
1914
1949
|
scroll_multiplier = _ref3.scroll_multiplier;
|
|
1915
|
-
if (_this.isInteracting) _this.DS.publish('Interaction:update', {
|
|
1950
|
+
if (_this.isInteracting) _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], {
|
|
1916
1951
|
event: event,
|
|
1917
1952
|
scroll_directions: scroll_directions,
|
|
1918
1953
|
scroll_multiplier: scroll_multiplier,
|
|
@@ -1921,6 +1956,13 @@
|
|
|
1921
1956
|
});
|
|
1922
1957
|
|
|
1923
1958
|
_defineProperty(this, "reset", function (event) {
|
|
1959
|
+
return _this.DS.publish('Interaction:end:pre', {
|
|
1960
|
+
event: event,
|
|
1961
|
+
isDragging: _this.isDragging
|
|
1962
|
+
});
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
_defineProperty(this, "_reset", function (event) {
|
|
1924
1966
|
var isDragging = _this.isDragging;
|
|
1925
1967
|
|
|
1926
1968
|
_this.stop();
|
|
@@ -1936,6 +1978,7 @@
|
|
|
1936
1978
|
this._areaElement = areaElement;
|
|
1937
1979
|
this._draggability = draggability;
|
|
1938
1980
|
this._immediateDrag = immediateDrag;
|
|
1981
|
+
this._selectableClass = selectableClass;
|
|
1939
1982
|
this.DS = DS;
|
|
1940
1983
|
this.DS.subscribe('PointerStore:updated', this.update);
|
|
1941
1984
|
this.DS.subscribe('Selectable:click', this.onClick);
|
|
@@ -1943,19 +1986,41 @@
|
|
|
1943
1986
|
var event = _ref4.event;
|
|
1944
1987
|
return _this.start(event);
|
|
1945
1988
|
});
|
|
1989
|
+
this.DS.subscribe('Interaction:start:pre', function (_ref5) {
|
|
1990
|
+
var event = _ref5.event;
|
|
1991
|
+
return _this._start(event);
|
|
1992
|
+
});
|
|
1993
|
+
this.DS.subscribe('Interaction:init:pre', this._init);
|
|
1994
|
+
this.DS.subscribe('Interaction:end:pre', function (_ref6) {
|
|
1995
|
+
var event = _ref6.event;
|
|
1996
|
+
return _this._reset(event);
|
|
1997
|
+
});
|
|
1946
1998
|
this.DS.subscribe('Area:scroll', this.update);
|
|
1947
1999
|
}
|
|
1948
2000
|
|
|
1949
2001
|
_createClass(Interaction, [{
|
|
1950
2002
|
key: "_canInteract",
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* @param {DSEvent} event
|
|
2006
|
+
*/
|
|
1951
2007
|
value: function _canInteract(event) {
|
|
2008
|
+
var isKeyboardClick =
|
|
2009
|
+
/** @type {MouseEvent} */
|
|
2010
|
+
event.clientX === 0 &&
|
|
2011
|
+
/** @type {MouseEvent} */
|
|
2012
|
+
event.clientY === 0 &&
|
|
2013
|
+
/** @type {MouseEvent} */
|
|
2014
|
+
event.detail === 0 && event.target;
|
|
1952
2015
|
if (
|
|
1953
|
-
|
|
1954
|
-
event.button === 2 ||
|
|
1955
|
-
|
|
1956
|
-
this.
|
|
1957
|
-
|
|
1958
|
-
event.target
|
|
2016
|
+
/** @type {MouseEvent} */
|
|
2017
|
+
event.button === 2 || // right-clicks
|
|
2018
|
+
this.isInteracting || // fix double-click issues
|
|
2019
|
+
event.target && !this.DS.SelectorArea.isInside(
|
|
2020
|
+
/** @type {DSElement} */
|
|
2021
|
+
event.target) || //fix outside elements issue
|
|
2022
|
+
!isKeyboardClick && !this.DS.SelectorArea.isClicked(event) // make sure the mouse click is inside the area
|
|
2023
|
+
) return false;
|
|
1959
2024
|
return true;
|
|
1960
2025
|
}
|
|
1961
2026
|
/**
|
|
@@ -1967,9 +2032,11 @@
|
|
|
1967
2032
|
return Interaction;
|
|
1968
2033
|
}();
|
|
1969
2034
|
|
|
1970
|
-
var PubSub = function PubSub() {
|
|
2035
|
+
var PubSub = function PubSub(_ref) {
|
|
1971
2036
|
var _this = this;
|
|
1972
2037
|
|
|
2038
|
+
var DS = _ref.DS;
|
|
2039
|
+
|
|
1973
2040
|
_classCallCheck(this, PubSub);
|
|
1974
2041
|
|
|
1975
2042
|
_defineProperty(this, "subscribers", {});
|
|
@@ -1989,17 +2056,44 @@
|
|
|
1989
2056
|
});
|
|
1990
2057
|
|
|
1991
2058
|
_defineProperty(this, "publish", function (eventName, data) {
|
|
1992
|
-
|
|
2059
|
+
if (Array.isArray(eventName)) eventName.forEach(function (name) {
|
|
2060
|
+
return _this._publish(name, data);
|
|
2061
|
+
});else _this._publish(eventName, data);
|
|
2062
|
+
});
|
|
1993
2063
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
(_this$subscribers$eve = _this.subscribers[eventName]) === null || _this$subscribers$eve === void 0 ? void 0 : _this$subscribers$eve.forEach(function (callback) {
|
|
1999
|
-
return callback(data);
|
|
2000
|
-
});
|
|
2064
|
+
_defineProperty(this, "_publish", function (eventName, data) {
|
|
2065
|
+
var subscribers = _this.subscribers[eventName];
|
|
2066
|
+
if (!Array.isArray(subscribers)) return;
|
|
2067
|
+
if (eventName.includes(":pre")) _this._handlePrePublish(subscribers, data);else _this._handlePublish(subscribers, data);
|
|
2001
2068
|
});
|
|
2002
|
-
|
|
2069
|
+
|
|
2070
|
+
_defineProperty(this, "_handlePublish", function (subscribers, data) {
|
|
2071
|
+
for (var i = 0, il = subscribers.length; i < il; i++) {
|
|
2072
|
+
if (_this.DS.stopped) return;
|
|
2073
|
+
subscribers[i](data);
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
|
|
2077
|
+
_defineProperty(this, "_handlePrePublish", function (subscribers, data) {
|
|
2078
|
+
var i = subscribers.length;
|
|
2079
|
+
|
|
2080
|
+
while (i--) {
|
|
2081
|
+
if (_this.DS.stopped) return;
|
|
2082
|
+
subscribers[i](data);
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
|
|
2086
|
+
this.DS = DS;
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* Subscribe to an event
|
|
2090
|
+
* @memberof DragSelect#
|
|
2091
|
+
* @function subscribe
|
|
2092
|
+
* @param {DSCallbackNames} eventName
|
|
2093
|
+
* @param {DSCallback} callback
|
|
2094
|
+
* @returns {number} event id, can be used to unsubscribe more efficiently
|
|
2095
|
+
*/
|
|
2096
|
+
;
|
|
2003
2097
|
|
|
2004
2098
|
var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
2005
2099
|
_inherits(SelectableSet, _Set);
|
|
@@ -2079,13 +2173,13 @@
|
|
|
2079
2173
|
});
|
|
2080
2174
|
|
|
2081
2175
|
_defineProperty(_assertThisInitialized(_this), "_onClick", function (event) {
|
|
2082
|
-
return _this.DS.publish('Selectable:click', {
|
|
2176
|
+
return _this.DS.publish(['Selectable:click:pre', 'Selectable:click'], {
|
|
2083
2177
|
event: event
|
|
2084
2178
|
});
|
|
2085
2179
|
});
|
|
2086
2180
|
|
|
2087
2181
|
_defineProperty(_assertThisInitialized(_this), "_onPointer", function (event) {
|
|
2088
|
-
return _this.DS.publish('Selectable:pointer', {
|
|
2182
|
+
return _this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], {
|
|
2089
2183
|
event: event
|
|
2090
2184
|
});
|
|
2091
2185
|
});
|
|
@@ -2217,15 +2311,17 @@
|
|
|
2217
2311
|
key: "add",
|
|
2218
2312
|
value: function add(element) {
|
|
2219
2313
|
if (_get(_getPrototypeOf(SelectedSet.prototype), "has", this).call(this, element)) return;
|
|
2314
|
+
var publishData = {
|
|
2315
|
+
items: this.elements,
|
|
2316
|
+
item: element
|
|
2317
|
+
};
|
|
2318
|
+
this.DS.publish('Selected:added:pre', publishData);
|
|
2220
2319
|
|
|
2221
2320
|
_get(_getPrototypeOf(SelectedSet.prototype), "add", this).call(this, element);
|
|
2222
2321
|
|
|
2223
2322
|
element.classList.add(this._className);
|
|
2224
|
-
this.DS.publish('Selected:added', {
|
|
2225
|
-
items: this.elements,
|
|
2226
|
-
item: element
|
|
2227
|
-
});
|
|
2228
2323
|
element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + 1);
|
|
2324
|
+
this.DS.publish('Selected:added', publishData);
|
|
2229
2325
|
return this;
|
|
2230
2326
|
}
|
|
2231
2327
|
/** @param {DSElement} element */
|
|
@@ -2234,15 +2330,17 @@
|
|
|
2234
2330
|
key: "delete",
|
|
2235
2331
|
value: function _delete(element) {
|
|
2236
2332
|
if (!_get(_getPrototypeOf(SelectedSet.prototype), "has", this).call(this, element)) return;
|
|
2333
|
+
var publishData = {
|
|
2334
|
+
items: this.elements,
|
|
2335
|
+
item: element
|
|
2336
|
+
};
|
|
2337
|
+
this.DS.publish('Selected:removed:pre', publishData);
|
|
2237
2338
|
|
|
2238
2339
|
var deleted = _get(_getPrototypeOf(SelectedSet.prototype), "delete", this).call(this, element);
|
|
2239
2340
|
|
|
2240
2341
|
element.classList.remove(this._className);
|
|
2241
|
-
this.DS.publish('Selected:removed', {
|
|
2242
|
-
items: this.elements,
|
|
2243
|
-
item: element
|
|
2244
|
-
});
|
|
2245
2342
|
element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) - 1);
|
|
2343
|
+
this.DS.publish('Selected:removed', publishData);
|
|
2246
2344
|
return deleted;
|
|
2247
2345
|
}
|
|
2248
2346
|
}, {
|
|
@@ -2344,6 +2442,7 @@
|
|
|
2344
2442
|
|
|
2345
2443
|
var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this._multiSelectToggling;
|
|
2346
2444
|
|
|
2445
|
+
if (_this.DS["continue"]) return;
|
|
2347
2446
|
select.forEach(function (element) {
|
|
2348
2447
|
return handleSelection({
|
|
2349
2448
|
element: element,
|
|
@@ -2605,15 +2704,17 @@
|
|
|
2605
2704
|
|
|
2606
2705
|
/**
|
|
2607
2706
|
* checks if the click was triggered on the area.
|
|
2707
|
+
* @param {DSEvent} [event]
|
|
2608
2708
|
* @returns {boolean}
|
|
2609
2709
|
*/
|
|
2610
|
-
value: function isClicked() {
|
|
2710
|
+
value: function isClicked(event) {
|
|
2611
2711
|
var PointerStore = this.DS.stores.PointerStore;
|
|
2712
|
+
var initialVal = event ? PointerStore.getPointerPosition(event) : PointerStore.initialVal;
|
|
2612
2713
|
return isCollision({
|
|
2613
|
-
left:
|
|
2614
|
-
top:
|
|
2615
|
-
right:
|
|
2616
|
-
bottom:
|
|
2714
|
+
left: initialVal.x,
|
|
2715
|
+
top: initialVal.y,
|
|
2716
|
+
right: initialVal.x,
|
|
2717
|
+
bottom: initialVal.y
|
|
2617
2718
|
}, this.rect);
|
|
2618
2719
|
}
|
|
2619
2720
|
}, {
|
|
@@ -2684,6 +2785,11 @@
|
|
|
2684
2785
|
_defineProperty(this, "keydown", function (event) {
|
|
2685
2786
|
var key = event.key.toLowerCase();
|
|
2686
2787
|
|
|
2788
|
+
_this.DS.publish('KeyStore:down:pre', {
|
|
2789
|
+
event: event,
|
|
2790
|
+
key: key
|
|
2791
|
+
});
|
|
2792
|
+
|
|
2687
2793
|
_this._currentValues.add(key);
|
|
2688
2794
|
|
|
2689
2795
|
_this.DS.publish('KeyStore:down', {
|
|
@@ -2695,6 +2801,11 @@
|
|
|
2695
2801
|
_defineProperty(this, "keyup", function (event) {
|
|
2696
2802
|
var key = event.key.toLowerCase();
|
|
2697
2803
|
|
|
2804
|
+
_this.DS.publish('KeyStore:up:pre', {
|
|
2805
|
+
event: event,
|
|
2806
|
+
key: key
|
|
2807
|
+
});
|
|
2808
|
+
|
|
2698
2809
|
_this._currentValues["delete"](key);
|
|
2699
2810
|
|
|
2700
2811
|
_this.DS.publish('KeyStore:up', {
|
|
@@ -2841,11 +2952,20 @@
|
|
|
2841
2952
|
});
|
|
2842
2953
|
});
|
|
2843
2954
|
|
|
2955
|
+
_defineProperty(this, "getPointerPosition", function (event) {
|
|
2956
|
+
return getPointerPos({
|
|
2957
|
+
event: _this._normalizedEvent(event)
|
|
2958
|
+
});
|
|
2959
|
+
});
|
|
2960
|
+
|
|
2844
2961
|
_defineProperty(this, "update", function (event) {
|
|
2845
2962
|
if (!event) return;
|
|
2846
|
-
|
|
2847
|
-
|
|
2963
|
+
|
|
2964
|
+
_this.DS.publish('PointerStore:updated:pre', {
|
|
2965
|
+
event: event
|
|
2848
2966
|
});
|
|
2967
|
+
|
|
2968
|
+
_this.currentVal = _this.getPointerPosition(event);
|
|
2849
2969
|
if (!_this._isMouseInteraction) return;
|
|
2850
2970
|
|
|
2851
2971
|
_this.DS.publish('PointerStore:updated', {
|
|
@@ -2867,9 +2987,7 @@
|
|
|
2867
2987
|
|
|
2868
2988
|
_defineProperty(this, "reset", function (event) {
|
|
2869
2989
|
if (!event) return;
|
|
2870
|
-
_this.currentVal = _this.lastVal =
|
|
2871
|
-
event: _this._normalizedEvent(event)
|
|
2872
|
-
});
|
|
2990
|
+
_this.currentVal = _this.lastVal = _this.getPointerPosition(event);
|
|
2873
2991
|
|
|
2874
2992
|
_this.stop();
|
|
2875
2993
|
|
|
@@ -2895,11 +3013,9 @@
|
|
|
2895
3013
|
value: function start(event) {
|
|
2896
3014
|
if (!event) return;
|
|
2897
3015
|
this._isMouseInteraction = true;
|
|
2898
|
-
this.currentVal = this.initialVal =
|
|
2899
|
-
event: this._normalizedEvent(event)
|
|
2900
|
-
});
|
|
3016
|
+
this.currentVal = this.initialVal = this.getPointerPosition(event);
|
|
2901
3017
|
}
|
|
2902
|
-
/** @param {DSEvent}
|
|
3018
|
+
/** @param {DSEvent} event */
|
|
2903
3019
|
|
|
2904
3020
|
}, {
|
|
2905
3021
|
key: "_normalizedEvent",
|
|
@@ -3191,7 +3307,9 @@
|
|
|
3191
3307
|
_defineProperty(this, "continue", false);
|
|
3192
3308
|
|
|
3193
3309
|
_defineProperty(this, "start", function () {
|
|
3194
|
-
|
|
3310
|
+
_this.stopped = false;
|
|
3311
|
+
|
|
3312
|
+
_this.Interaction.init();
|
|
3195
3313
|
});
|
|
3196
3314
|
|
|
3197
3315
|
_defineProperty(this, "break", function () {
|
|
@@ -3238,7 +3356,9 @@
|
|
|
3238
3356
|
return _this.Interaction.isDragging;
|
|
3239
3357
|
});
|
|
3240
3358
|
|
|
3241
|
-
this.PubSub = new PubSub(
|
|
3359
|
+
this.PubSub = new PubSub({
|
|
3360
|
+
DS: this
|
|
3361
|
+
});
|
|
3242
3362
|
this.subscribe = this.PubSub.subscribe;
|
|
3243
3363
|
this.unsubscribe = this.PubSub.unsubscribe;
|
|
3244
3364
|
this.publish = this.PubSub.publish;
|
|
@@ -3319,7 +3439,8 @@
|
|
|
3319
3439
|
areaElement: area,
|
|
3320
3440
|
DS: this,
|
|
3321
3441
|
draggability: draggability,
|
|
3322
|
-
immediateDrag: immediateDrag
|
|
3442
|
+
immediateDrag: immediateDrag,
|
|
3443
|
+
selectableClass: selectableClass
|
|
3323
3444
|
}); // Subscriber Aliases
|
|
3324
3445
|
|
|
3325
3446
|
subscriberAliases({
|
|
@@ -3443,6 +3564,7 @@
|
|
|
3443
3564
|
this.stores.ScrollStore.stop();
|
|
3444
3565
|
if (remove) this.SelectableSet.clear();
|
|
3445
3566
|
if (fromSelection) this.SelectedSet.clear();
|
|
3567
|
+
this.stopped = true;
|
|
3446
3568
|
}
|
|
3447
3569
|
/**
|
|
3448
3570
|
* Utility to override DragSelect internal functionality:
|