dragselect 2.4.3 → 2.4.4
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 +4 -0
- package/README.md +24 -11
- package/deploying.md +1 -1
- package/dist/DragSelect.es6m.js +64 -28
- package/dist/DragSelect.js +64 -28
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/methods/getAllParentNodes.d.ts +46 -0
- package/dist/methods/getPointerPos.d.ts +1 -1
- package/dist/modules/DropZone.d.ts +131 -0
- package/dist/modules/DropZones.d.ts +119 -0
- package/dist/modules/Interaction.d.ts +1 -0
- package/dist/modules/SelectableSet.d.ts +1 -0
- package/dist/modules/Selector.d.ts +1 -1
- package/dist/modules/SelectorArea.d.ts +1 -1
- package/dist/stores/KeyStore.d.ts +2 -2
- package/dist/stores/PointerStore.d.ts +2 -1
- package/dist/types.d.ts +6 -2
- package/package.json +6 -6
- package/rollup.config.js +1 -1
- package/src/methods/getPointerPos.js +1 -1
- package/src/methods/hydrateSettings.js +1 -0
- package/src/modules/Interaction.js +32 -7
- package/src/modules/SelectableSet.js +23 -8
- package/src/stores/KeyStore.js +1 -1
- package/src/stores/PointerStore.js +17 -3
- package/src/types.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# 2.4.4
|
|
2
|
+
|
|
3
|
+
- Add support for `pointerEvents` (from @HollowMan6) [#143](https://github.com/ThibaultJanBeyer/DragSelect/pull/143) & [#128](https://github.com/ThibaultJanBeyer/DragSelect/pull/128)
|
|
4
|
+
|
|
1
5
|
# 2.4.3
|
|
2
6
|
|
|
3
7
|
- add `triggerCallback` option to `removeSelectables` and `addSelectables`
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[GitHub](https://github.com/ThibaultJanBeyer/DragSelect/) | [NPM](https://www.npmjs.com/package/dragselect) | [Project-Page](https://dragselect.com/)
|
|
11
11
|
|
|
12
|
-
[](https://github.com/ThibaultJanBeyer/DragSelect/actions)   [](https://github.com/ThibaultJanBeyer/DragSelect/blob/master/package.json) [](https://github.com/ThibaultJanBeyer/DragSelect/blob/master/CONTRIBUTING.md) [](https://github.com/sponsors/ThibaultJanBeyer)
|
|
13
13
|
|
|
14
14
|
# DragSelect 
|
|
15
15
|
easily add a selection algorithm to your application/website.
|
|
@@ -20,20 +20,32 @@ easily add a selection algorithm to your application/website.
|
|
|
20
20
|
- [Key-Features](#key-features)
|
|
21
21
|
- [Why?](#why)
|
|
22
22
|
- [Supporters](#supporters)
|
|
23
|
+
- [Thanks to:](#thanks-to)
|
|
23
24
|
- [Installation](#installation)
|
|
25
|
+
- [NPM](#npm)
|
|
26
|
+
- [Yarn](#yarn)
|
|
27
|
+
- [Global](#global)
|
|
28
|
+
- [Bower (deprecated)](#bower-deprecated)
|
|
29
|
+
- [That's it, you're ready to rock!](#thats-it-youre-ready-to-rock)
|
|
24
30
|
- [Usage](#usage)
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
- [
|
|
32
|
-
-
|
|
31
|
+
- [Simple](#simple)
|
|
32
|
+
- [Within a scroll-able Area](#within-a-scroll-able-area)
|
|
33
|
+
- [Extended](#extended)
|
|
34
|
+
- [Mobile/Touch usage](#mobiletouch-usage)
|
|
35
|
+
- [Accessibility (a11y)](#accessibility-a11y)
|
|
36
|
+
- [Use your own Drag And Drop](#use-your-own-drag-and-drop)
|
|
37
|
+
- [Using another plugin/tool (3rd party)](#using-another-plugintool-3rd-party)
|
|
38
|
+
- [Example](#example)
|
|
39
|
+
- [Writing a fully custom solution](#writing-a-fully-custom-solution)
|
|
40
|
+
- [Example](#example-1)
|
|
41
|
+
- [Constructor Properties (Settings):](#constructor-properties-settings)
|
|
42
|
+
- [Post-Initialization Setting-Updates](#post-initialization-setting-updates)
|
|
33
43
|
- [Event Callbacks](#event-callbacks)
|
|
34
|
-
-
|
|
35
|
-
- [
|
|
44
|
+
- [Events](#events)
|
|
45
|
+
- [Callback Object Keys](#callback-object-keys)
|
|
46
|
+
- [Methods:](#methods)
|
|
36
47
|
- [Classes](#classes)
|
|
48
|
+
- [Have Fun!](#have-fun)
|
|
37
49
|
|
|
38
50
|
# Project Page: Demo & Info
|
|
39
51
|
|
|
@@ -289,6 +301,7 @@ Here is the full list:
|
|
|
289
301
|
|hoverClass |string |The class name assigned to the mouse hovered items. |[see classes](#classes)
|
|
290
302
|
|selectorClass |string |The class name assigned to the square selector helper. |[see classes](#classes)
|
|
291
303
|
|selectableClass |string |The class name assigned to the elements that can be selected. |[see classes](#classes)
|
|
304
|
+
|usePointerEvents |boolean |Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly. |`false`
|
|
292
305
|
|
|
293
306
|
## Post-Initialization Setting-Updates
|
|
294
307
|
|
package/deploying.md
CHANGED
|
@@ -14,7 +14,7 @@ if you are a regular contributor, see [contibuting](CONTRIBUTING.md) and make a
|
|
|
14
14
|
Typically you don’t have to do this, since you most likely are not the project owner.
|
|
15
15
|
But if you are the project owner:
|
|
16
16
|
|
|
17
|
-
-
|
|
17
|
+
- Github Actions will take care of deployment to gh-pages when you push/merge to github main branch (gh-pages will be build by Github Actions)
|
|
18
18
|
|
|
19
19
|
If this was successful, the next step is to publish the new version on `npm`:
|
|
20
20
|
|
package/dist/DragSelect.es6m.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/***
|
|
2
2
|
|
|
3
|
-
~~~ Version 2.4.
|
|
3
|
+
~~~ Version 2.4.4 ~~~
|
|
4
4
|
|
|
5
5
|
******************************************
|
|
6
6
|
|
|
@@ -355,6 +355,7 @@ function _nonIterableRest() {
|
|
|
355
355
|
* @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
|
|
356
356
|
* @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
|
|
357
357
|
* @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
358
|
+
* @property {boolean} [usePointerEvents=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
|
|
358
359
|
* @property {string} [hoverClass=ds-hover] the class assigned to the mouse hovered items
|
|
359
360
|
* @property {string} [selectableClass=ds-selectable] the class assigned to the elements that can be selected
|
|
360
361
|
* @property {string} [selectedClass=ds-selected] the class assigned to the selected items
|
|
@@ -366,7 +367,7 @@ function _nonIterableRest() {
|
|
|
366
367
|
* The Object that is passed back to any callback method
|
|
367
368
|
* @typedef {Object} CallbackObject
|
|
368
369
|
* @property {Array<HTMLElement|SVGElement|any>} [items] The items currently selected
|
|
369
|
-
* @property {MouseEvent|TouchEvent|KeyboardEvent|Event} [event] The respective event object
|
|
370
|
+
* @property {MouseEvent|TouchEvent|PointerEvent|KeyboardEvent|Event} [event] The respective event object
|
|
370
371
|
* @property {HTMLElement|SVGElement|any} [item] The single item currently interacted with
|
|
371
372
|
* @property {boolean} [isDragging] Whether the interaction is a drag or a select
|
|
372
373
|
* @property {boolean} [isDraggingKeyboard] Whether or not the drag interaction is via keyboard
|
|
@@ -397,7 +398,7 @@ function _nonIterableRest() {
|
|
|
397
398
|
|
|
398
399
|
/** @typedef {HTMLElement|SVGElement} DSElement a single element that can be selected */
|
|
399
400
|
|
|
400
|
-
/** @typedef {MouseEvent|TouchEvent} DSEvent en event from a touch or mouse interaction */
|
|
401
|
+
/** @typedef {MouseEvent|TouchEvent|PointerEvent} DSEvent en event from a touch or mouse interaction */
|
|
401
402
|
|
|
402
403
|
/** @typedef {Array.<'Shift'|'Control'|'Meta'|string>} DSMultiSelectKeys An array of keys that allows switching to the multi-select mode */
|
|
403
404
|
|
|
@@ -693,7 +694,7 @@ var getOverflowEdges = (function (_ref) {
|
|
|
693
694
|
/**
|
|
694
695
|
* Returns cursor x, y position based on event object
|
|
695
696
|
* @param {Object} p
|
|
696
|
-
* @param {MouseEvent|Touch} p.event
|
|
697
|
+
* @param {MouseEvent|Touch|PointerEvent} p.event
|
|
697
698
|
* @return {Vect2} cursor X/Y position
|
|
698
699
|
*/
|
|
699
700
|
|
|
@@ -1159,7 +1160,7 @@ var hydrateHelper = function hydrateHelper(key, value, withFallback, fallback) {
|
|
|
1159
1160
|
|
|
1160
1161
|
|
|
1161
1162
|
var hydrateSettings = (function (settings, withFallback) {
|
|
1162
|
-
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
|
|
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, {
|
|
1163
1164
|
x: 25,
|
|
1164
1165
|
y: 25
|
|
1165
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, {
|
|
@@ -1167,7 +1168,7 @@ var hydrateSettings = (function (settings, withFallback) {
|
|
|
1167
1168
|
down: ['ArrowDown'],
|
|
1168
1169
|
left: ['ArrowLeft'],
|
|
1169
1170
|
right: ['ArrowRight']
|
|
1170
|
-
})), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'));
|
|
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'));
|
|
1171
1172
|
});
|
|
1172
1173
|
|
|
1173
1174
|
// @ts-check
|
|
@@ -1865,9 +1866,12 @@ var Interaction = /*#__PURE__*/function () {
|
|
|
1865
1866
|
});
|
|
1866
1867
|
|
|
1867
1868
|
_defineProperty(this, "_init", function () {
|
|
1868
|
-
_this.stop();
|
|
1869
|
+
_this.stop(); // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1870
|
+
|
|
1869
1871
|
|
|
1870
|
-
_this.DS.Area.HTMLNode.addEventListener('
|
|
1872
|
+
if (_this.Settings.usePointerEvents) _this.DS.Area.HTMLNode.addEventListener('pointerdown', _this.start, {
|
|
1873
|
+
passive: false
|
|
1874
|
+
});else _this.DS.Area.HTMLNode.addEventListener('mousedown', _this.start);
|
|
1871
1875
|
|
|
1872
1876
|
_this.DS.Area.HTMLNode.addEventListener('touchstart', _this.start, {
|
|
1873
1877
|
passive: false
|
|
@@ -1893,19 +1897,24 @@ var Interaction = /*#__PURE__*/function () {
|
|
|
1893
1897
|
_this.DS.publish('Interaction:start', {
|
|
1894
1898
|
event: event,
|
|
1895
1899
|
isDragging: _this.isDragging
|
|
1896
|
-
});
|
|
1900
|
+
}); // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1901
|
+
|
|
1902
|
+
|
|
1903
|
+
if (_this.Settings.usePointerEvents) {
|
|
1904
|
+
document.addEventListener('pointerup', _this.reset);
|
|
1905
|
+
document.addEventListener('pointercancel', _this.reset);
|
|
1906
|
+
} else document.addEventListener('mouseup', _this.reset);
|
|
1897
1907
|
|
|
1898
|
-
document.addEventListener('mouseup', _this.reset);
|
|
1899
1908
|
document.addEventListener('touchend', _this.reset);
|
|
1900
1909
|
});
|
|
1901
1910
|
|
|
1902
1911
|
_defineProperty(this, "isDragEvent", function (event) {
|
|
1903
1912
|
var clickedElement =
|
|
1904
1913
|
/** @type {Element} */
|
|
1905
|
-
event.target.closest(".".concat(_this.
|
|
1906
|
-
if (!_this.
|
|
1914
|
+
event.target.closest(".".concat(_this.Settings.selectableClass));
|
|
1915
|
+
if (!_this.Settings.draggability || _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) || !clickedElement) return false;
|
|
1907
1916
|
|
|
1908
|
-
if (_this.
|
|
1917
|
+
if (_this.Settings.immediateDrag) {
|
|
1909
1918
|
if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add(
|
|
1910
1919
|
/** @type {DSElement} */
|
|
1911
1920
|
clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
|
|
@@ -1946,16 +1955,27 @@ var Interaction = /*#__PURE__*/function () {
|
|
|
1946
1955
|
|
|
1947
1956
|
_defineProperty(this, "stop", function () {
|
|
1948
1957
|
_this.isInteracting = false;
|
|
1949
|
-
_this.isDragging = false;
|
|
1958
|
+
_this.isDragging = false; // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1959
|
+
|
|
1960
|
+
if (_this.Settings.usePointerEvents) {
|
|
1961
|
+
_this.DS.Area.HTMLNode.removeEventListener('pointerdown', _this.start, {
|
|
1962
|
+
// @ts-ignore
|
|
1963
|
+
passive: false
|
|
1964
|
+
});
|
|
1950
1965
|
|
|
1951
|
-
|
|
1966
|
+
document.removeEventListener('pointerup', _this.reset);
|
|
1967
|
+
document.removeEventListener('pointercancel', _this.reset);
|
|
1968
|
+
} else {
|
|
1969
|
+
_this.DS.Area.HTMLNode.removeEventListener('mousedown', _this.start);
|
|
1970
|
+
|
|
1971
|
+
document.removeEventListener('mouseup', _this.reset);
|
|
1972
|
+
}
|
|
1952
1973
|
|
|
1953
1974
|
_this.DS.Area.HTMLNode.removeEventListener('touchstart', _this.start, {
|
|
1954
1975
|
// @ts-ignore
|
|
1955
1976
|
passive: false
|
|
1956
1977
|
});
|
|
1957
1978
|
|
|
1958
|
-
document.removeEventListener('mouseup', _this.reset);
|
|
1959
1979
|
document.removeEventListener('touchend', _this.reset);
|
|
1960
1980
|
});
|
|
1961
1981
|
|
|
@@ -1991,7 +2011,8 @@ var Interaction = /*#__PURE__*/function () {
|
|
|
1991
2011
|
});
|
|
1992
2012
|
});
|
|
1993
2013
|
|
|
1994
|
-
this.DS = DS;
|
|
2014
|
+
this.DS = DS;
|
|
2015
|
+
this.Settings = DS.stores.SettingsStore.s; // @ts-ignore: @todo: update to typescript
|
|
1995
2016
|
|
|
1996
2017
|
this.DS.subscribe('Settings:updated:area', this.init);
|
|
1997
2018
|
this.DS.subscribe('PointerStore:updated', this.update);
|
|
@@ -2129,7 +2150,7 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
|
2129
2150
|
_this = _super.call(this);
|
|
2130
2151
|
|
|
2131
2152
|
_defineProperty(_assertThisInitialized(_this), "init", function () {
|
|
2132
|
-
return toArray(_this.
|
|
2153
|
+
return toArray(_this.Settings.selectables).forEach(function (el) {
|
|
2133
2154
|
return _this.add(el);
|
|
2134
2155
|
});
|
|
2135
2156
|
});
|
|
@@ -2165,6 +2186,7 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
|
2165
2186
|
});
|
|
2166
2187
|
|
|
2167
2188
|
_this.DS = DS;
|
|
2189
|
+
_this.Settings = DS.stores.SettingsStore.s;
|
|
2168
2190
|
|
|
2169
2191
|
_this.DS.subscribe('Interaction:init', _this.init); // @ts-ignore: @todo: update to typescript
|
|
2170
2192
|
|
|
@@ -2199,14 +2221,17 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
|
2199
2221
|
item: element
|
|
2200
2222
|
};
|
|
2201
2223
|
this.DS.publish('Selectable:added:pre', publishData);
|
|
2202
|
-
element.classList.add(this.
|
|
2224
|
+
element.classList.add(this.Settings.selectableClass);
|
|
2203
2225
|
element.addEventListener('click', this._onClick);
|
|
2204
|
-
element.addEventListener('
|
|
2226
|
+
if (this.Settings.usePointerEvents) element.addEventListener('pointerdown', this._onPointer, {
|
|
2227
|
+
// @ts-ignore
|
|
2228
|
+
passive: false
|
|
2229
|
+
});else element.addEventListener('mousedown', this._onPointer);
|
|
2205
2230
|
element.addEventListener('touchstart', this._onPointer, {
|
|
2206
2231
|
// @ts-ignore
|
|
2207
2232
|
passive: false
|
|
2208
2233
|
});
|
|
2209
|
-
if (this.
|
|
2234
|
+
if (this.Settings.draggability && !this.Settings.useTransform) handleElementPositionAttribute({
|
|
2210
2235
|
computedStyle: window.getComputedStyle(element),
|
|
2211
2236
|
node: element
|
|
2212
2237
|
});
|
|
@@ -2224,10 +2249,13 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
|
|
|
2224
2249
|
item: element
|
|
2225
2250
|
};
|
|
2226
2251
|
this.DS.publish('Selectable:removed:pre', publishData);
|
|
2227
|
-
element.classList.remove(this.
|
|
2228
|
-
element.classList.remove(this.
|
|
2252
|
+
element.classList.remove(this.Settings.selectableClass);
|
|
2253
|
+
element.classList.remove(this.Settings.hoverClass);
|
|
2229
2254
|
element.removeEventListener('click', this._onClick);
|
|
2230
|
-
element.removeEventListener('
|
|
2255
|
+
if (this.Settings.usePointerEvents) element.removeEventListener('pointerdown', this._onPointer, {
|
|
2256
|
+
// @ts-ignore
|
|
2257
|
+
passive: false
|
|
2258
|
+
});else element.removeEventListener('mousedown', this._onPointer);
|
|
2231
2259
|
element.removeEventListener('touchstart', this._onPointer, {
|
|
2232
2260
|
// @ts-ignore
|
|
2233
2261
|
passive: false
|
|
@@ -2786,7 +2814,7 @@ var KeyStore = /*#__PURE__*/function () {
|
|
|
2786
2814
|
_createClass(KeyStore, [{
|
|
2787
2815
|
key: "isMultiSelectKeyPressed",
|
|
2788
2816
|
|
|
2789
|
-
/** @param {KeyboardEvent|MouseEvent|TouchEvent} [event] */
|
|
2817
|
+
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
|
|
2790
2818
|
value: function isMultiSelectKeyPressed(event) {
|
|
2791
2819
|
var _this2 = this;
|
|
2792
2820
|
|
|
@@ -2882,7 +2910,10 @@ var PointerStore = /*#__PURE__*/function () {
|
|
|
2882
2910
|
_defineProperty(this, "_lastTouch", void 0);
|
|
2883
2911
|
|
|
2884
2912
|
_defineProperty(this, "init", function () {
|
|
2885
|
-
document.addEventListener('
|
|
2913
|
+
if (_this.Settings.usePointerEvents) document.addEventListener('pointermove', _this.update, {
|
|
2914
|
+
// @ts-ignore
|
|
2915
|
+
passive: false
|
|
2916
|
+
});else document.addEventListener('mousemove', _this.update);
|
|
2886
2917
|
document.addEventListener('touchmove', _this.update, {
|
|
2887
2918
|
// @ts-ignore
|
|
2888
2919
|
passive: false
|
|
@@ -2911,7 +2942,11 @@ var PointerStore = /*#__PURE__*/function () {
|
|
|
2911
2942
|
});
|
|
2912
2943
|
|
|
2913
2944
|
_defineProperty(this, "stop", function () {
|
|
2914
|
-
|
|
2945
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
2946
|
+
if (_this.Settings.usePointerEvents) document.removeEventListener('pointermove', _this.update, {
|
|
2947
|
+
// @ts-ignore
|
|
2948
|
+
passive: false
|
|
2949
|
+
});else document.removeEventListener('mousemove', _this.update);
|
|
2915
2950
|
document.removeEventListener('touchmove', _this.update, {
|
|
2916
2951
|
// @ts-ignore
|
|
2917
2952
|
passive: false
|
|
@@ -2932,6 +2967,7 @@ var PointerStore = /*#__PURE__*/function () {
|
|
|
2932
2967
|
});
|
|
2933
2968
|
|
|
2934
2969
|
this.DS = DS;
|
|
2970
|
+
this.Settings = DS.stores.SettingsStore.s;
|
|
2935
2971
|
this.DS.subscribe('Interaction:init', this.init);
|
|
2936
2972
|
this.DS.subscribe('Interaction:start', function (_ref2) {
|
|
2937
2973
|
var event = _ref2.event;
|
|
@@ -2959,7 +2995,7 @@ var PointerStore = /*#__PURE__*/function () {
|
|
|
2959
2995
|
|
|
2960
2996
|
/**
|
|
2961
2997
|
* @param {DSEvent} event
|
|
2962
|
-
* @return {MouseEvent|Touch}
|
|
2998
|
+
* @return {MouseEvent|PointerEvent|Touch}
|
|
2963
2999
|
* @private
|
|
2964
3000
|
*/
|
|
2965
3001
|
value: function _normalizedEvent(event) {
|
package/dist/DragSelect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/***
|
|
2
2
|
|
|
3
|
-
~~~ Version 2.4.
|
|
3
|
+
~~~ Version 2.4.4 ~~~
|
|
4
4
|
|
|
5
5
|
******************************************
|
|
6
6
|
|
|
@@ -361,6 +361,7 @@
|
|
|
361
361
|
* @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
|
|
362
362
|
* @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
|
|
363
363
|
* @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
364
|
+
* @property {boolean} [usePointerEvents=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
|
|
364
365
|
* @property {string} [hoverClass=ds-hover] the class assigned to the mouse hovered items
|
|
365
366
|
* @property {string} [selectableClass=ds-selectable] the class assigned to the elements that can be selected
|
|
366
367
|
* @property {string} [selectedClass=ds-selected] the class assigned to the selected items
|
|
@@ -372,7 +373,7 @@
|
|
|
372
373
|
* The Object that is passed back to any callback method
|
|
373
374
|
* @typedef {Object} CallbackObject
|
|
374
375
|
* @property {Array<HTMLElement|SVGElement|any>} [items] The items currently selected
|
|
375
|
-
* @property {MouseEvent|TouchEvent|KeyboardEvent|Event} [event] The respective event object
|
|
376
|
+
* @property {MouseEvent|TouchEvent|PointerEvent|KeyboardEvent|Event} [event] The respective event object
|
|
376
377
|
* @property {HTMLElement|SVGElement|any} [item] The single item currently interacted with
|
|
377
378
|
* @property {boolean} [isDragging] Whether the interaction is a drag or a select
|
|
378
379
|
* @property {boolean} [isDraggingKeyboard] Whether or not the drag interaction is via keyboard
|
|
@@ -403,7 +404,7 @@
|
|
|
403
404
|
|
|
404
405
|
/** @typedef {HTMLElement|SVGElement} DSElement a single element that can be selected */
|
|
405
406
|
|
|
406
|
-
/** @typedef {MouseEvent|TouchEvent} DSEvent en event from a touch or mouse interaction */
|
|
407
|
+
/** @typedef {MouseEvent|TouchEvent|PointerEvent} DSEvent en event from a touch or mouse interaction */
|
|
407
408
|
|
|
408
409
|
/** @typedef {Array.<'Shift'|'Control'|'Meta'|string>} DSMultiSelectKeys An array of keys that allows switching to the multi-select mode */
|
|
409
410
|
|
|
@@ -699,7 +700,7 @@
|
|
|
699
700
|
/**
|
|
700
701
|
* Returns cursor x, y position based on event object
|
|
701
702
|
* @param {Object} p
|
|
702
|
-
* @param {MouseEvent|Touch} p.event
|
|
703
|
+
* @param {MouseEvent|Touch|PointerEvent} p.event
|
|
703
704
|
* @return {Vect2} cursor X/Y position
|
|
704
705
|
*/
|
|
705
706
|
|
|
@@ -1165,7 +1166,7 @@
|
|
|
1165
1166
|
|
|
1166
1167
|
|
|
1167
1168
|
var hydrateSettings = (function (settings, withFallback) {
|
|
1168
|
-
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
|
|
1169
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
|
|
1169
1170
|
x: 25,
|
|
1170
1171
|
y: 25
|
|
1171
1172
|
})), hydrateHelper('zoom', settings.zoom, withFallback, 1)), hydrateHelper('customStyles', settings.customStyles, withFallback, false)), hydrateHelper('multiSelectMode', settings.multiSelectMode, withFallback, false)), hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true)), hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta'])), hydrateHelper('selector', settings.selector, withFallback, null)), hydrateHelper('draggability', settings.draggability, withFallback, true)), hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true)), hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true)), hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
|
|
@@ -1173,7 +1174,7 @@
|
|
|
1173
1174
|
down: ['ArrowDown'],
|
|
1174
1175
|
left: ['ArrowLeft'],
|
|
1175
1176
|
right: ['ArrowRight']
|
|
1176
|
-
})), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'));
|
|
1177
|
+
})), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('usePointerEvents', settings.usePointerEvents, withFallback, false)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'));
|
|
1177
1178
|
});
|
|
1178
1179
|
|
|
1179
1180
|
// @ts-check
|
|
@@ -1871,9 +1872,12 @@
|
|
|
1871
1872
|
});
|
|
1872
1873
|
|
|
1873
1874
|
_defineProperty(this, "_init", function () {
|
|
1874
|
-
_this.stop();
|
|
1875
|
+
_this.stop(); // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1876
|
+
|
|
1875
1877
|
|
|
1876
|
-
_this.DS.Area.HTMLNode.addEventListener('
|
|
1878
|
+
if (_this.Settings.usePointerEvents) _this.DS.Area.HTMLNode.addEventListener('pointerdown', _this.start, {
|
|
1879
|
+
passive: false
|
|
1880
|
+
});else _this.DS.Area.HTMLNode.addEventListener('mousedown', _this.start);
|
|
1877
1881
|
|
|
1878
1882
|
_this.DS.Area.HTMLNode.addEventListener('touchstart', _this.start, {
|
|
1879
1883
|
passive: false
|
|
@@ -1899,19 +1903,24 @@
|
|
|
1899
1903
|
_this.DS.publish('Interaction:start', {
|
|
1900
1904
|
event: event,
|
|
1901
1905
|
isDragging: _this.isDragging
|
|
1902
|
-
});
|
|
1906
|
+
}); // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1907
|
+
|
|
1908
|
+
|
|
1909
|
+
if (_this.Settings.usePointerEvents) {
|
|
1910
|
+
document.addEventListener('pointerup', _this.reset);
|
|
1911
|
+
document.addEventListener('pointercancel', _this.reset);
|
|
1912
|
+
} else document.addEventListener('mouseup', _this.reset);
|
|
1903
1913
|
|
|
1904
|
-
document.addEventListener('mouseup', _this.reset);
|
|
1905
1914
|
document.addEventListener('touchend', _this.reset);
|
|
1906
1915
|
});
|
|
1907
1916
|
|
|
1908
1917
|
_defineProperty(this, "isDragEvent", function (event) {
|
|
1909
1918
|
var clickedElement =
|
|
1910
1919
|
/** @type {Element} */
|
|
1911
|
-
event.target.closest(".".concat(_this.
|
|
1912
|
-
if (!_this.
|
|
1920
|
+
event.target.closest(".".concat(_this.Settings.selectableClass));
|
|
1921
|
+
if (!_this.Settings.draggability || _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) || !clickedElement) return false;
|
|
1913
1922
|
|
|
1914
|
-
if (_this.
|
|
1923
|
+
if (_this.Settings.immediateDrag) {
|
|
1915
1924
|
if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add(
|
|
1916
1925
|
/** @type {DSElement} */
|
|
1917
1926
|
clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
|
|
@@ -1952,16 +1961,27 @@
|
|
|
1952
1961
|
|
|
1953
1962
|
_defineProperty(this, "stop", function () {
|
|
1954
1963
|
_this.isInteracting = false;
|
|
1955
|
-
_this.isDragging = false;
|
|
1964
|
+
_this.isDragging = false; // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
1965
|
+
|
|
1966
|
+
if (_this.Settings.usePointerEvents) {
|
|
1967
|
+
_this.DS.Area.HTMLNode.removeEventListener('pointerdown', _this.start, {
|
|
1968
|
+
// @ts-ignore
|
|
1969
|
+
passive: false
|
|
1970
|
+
});
|
|
1956
1971
|
|
|
1957
|
-
|
|
1972
|
+
document.removeEventListener('pointerup', _this.reset);
|
|
1973
|
+
document.removeEventListener('pointercancel', _this.reset);
|
|
1974
|
+
} else {
|
|
1975
|
+
_this.DS.Area.HTMLNode.removeEventListener('mousedown', _this.start);
|
|
1976
|
+
|
|
1977
|
+
document.removeEventListener('mouseup', _this.reset);
|
|
1978
|
+
}
|
|
1958
1979
|
|
|
1959
1980
|
_this.DS.Area.HTMLNode.removeEventListener('touchstart', _this.start, {
|
|
1960
1981
|
// @ts-ignore
|
|
1961
1982
|
passive: false
|
|
1962
1983
|
});
|
|
1963
1984
|
|
|
1964
|
-
document.removeEventListener('mouseup', _this.reset);
|
|
1965
1985
|
document.removeEventListener('touchend', _this.reset);
|
|
1966
1986
|
});
|
|
1967
1987
|
|
|
@@ -1997,7 +2017,8 @@
|
|
|
1997
2017
|
});
|
|
1998
2018
|
});
|
|
1999
2019
|
|
|
2000
|
-
this.DS = DS;
|
|
2020
|
+
this.DS = DS;
|
|
2021
|
+
this.Settings = DS.stores.SettingsStore.s; // @ts-ignore: @todo: update to typescript
|
|
2001
2022
|
|
|
2002
2023
|
this.DS.subscribe('Settings:updated:area', this.init);
|
|
2003
2024
|
this.DS.subscribe('PointerStore:updated', this.update);
|
|
@@ -2135,7 +2156,7 @@
|
|
|
2135
2156
|
_this = _super.call(this);
|
|
2136
2157
|
|
|
2137
2158
|
_defineProperty(_assertThisInitialized(_this), "init", function () {
|
|
2138
|
-
return toArray(_this.
|
|
2159
|
+
return toArray(_this.Settings.selectables).forEach(function (el) {
|
|
2139
2160
|
return _this.add(el);
|
|
2140
2161
|
});
|
|
2141
2162
|
});
|
|
@@ -2171,6 +2192,7 @@
|
|
|
2171
2192
|
});
|
|
2172
2193
|
|
|
2173
2194
|
_this.DS = DS;
|
|
2195
|
+
_this.Settings = DS.stores.SettingsStore.s;
|
|
2174
2196
|
|
|
2175
2197
|
_this.DS.subscribe('Interaction:init', _this.init); // @ts-ignore: @todo: update to typescript
|
|
2176
2198
|
|
|
@@ -2205,14 +2227,17 @@
|
|
|
2205
2227
|
item: element
|
|
2206
2228
|
};
|
|
2207
2229
|
this.DS.publish('Selectable:added:pre', publishData);
|
|
2208
|
-
element.classList.add(this.
|
|
2230
|
+
element.classList.add(this.Settings.selectableClass);
|
|
2209
2231
|
element.addEventListener('click', this._onClick);
|
|
2210
|
-
element.addEventListener('
|
|
2232
|
+
if (this.Settings.usePointerEvents) element.addEventListener('pointerdown', this._onPointer, {
|
|
2233
|
+
// @ts-ignore
|
|
2234
|
+
passive: false
|
|
2235
|
+
});else element.addEventListener('mousedown', this._onPointer);
|
|
2211
2236
|
element.addEventListener('touchstart', this._onPointer, {
|
|
2212
2237
|
// @ts-ignore
|
|
2213
2238
|
passive: false
|
|
2214
2239
|
});
|
|
2215
|
-
if (this.
|
|
2240
|
+
if (this.Settings.draggability && !this.Settings.useTransform) handleElementPositionAttribute({
|
|
2216
2241
|
computedStyle: window.getComputedStyle(element),
|
|
2217
2242
|
node: element
|
|
2218
2243
|
});
|
|
@@ -2230,10 +2255,13 @@
|
|
|
2230
2255
|
item: element
|
|
2231
2256
|
};
|
|
2232
2257
|
this.DS.publish('Selectable:removed:pre', publishData);
|
|
2233
|
-
element.classList.remove(this.
|
|
2234
|
-
element.classList.remove(this.
|
|
2258
|
+
element.classList.remove(this.Settings.selectableClass);
|
|
2259
|
+
element.classList.remove(this.Settings.hoverClass);
|
|
2235
2260
|
element.removeEventListener('click', this._onClick);
|
|
2236
|
-
element.removeEventListener('
|
|
2261
|
+
if (this.Settings.usePointerEvents) element.removeEventListener('pointerdown', this._onPointer, {
|
|
2262
|
+
// @ts-ignore
|
|
2263
|
+
passive: false
|
|
2264
|
+
});else element.removeEventListener('mousedown', this._onPointer);
|
|
2237
2265
|
element.removeEventListener('touchstart', this._onPointer, {
|
|
2238
2266
|
// @ts-ignore
|
|
2239
2267
|
passive: false
|
|
@@ -2792,7 +2820,7 @@
|
|
|
2792
2820
|
_createClass(KeyStore, [{
|
|
2793
2821
|
key: "isMultiSelectKeyPressed",
|
|
2794
2822
|
|
|
2795
|
-
/** @param {KeyboardEvent|MouseEvent|TouchEvent} [event] */
|
|
2823
|
+
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
|
|
2796
2824
|
value: function isMultiSelectKeyPressed(event) {
|
|
2797
2825
|
var _this2 = this;
|
|
2798
2826
|
|
|
@@ -2888,7 +2916,10 @@
|
|
|
2888
2916
|
_defineProperty(this, "_lastTouch", void 0);
|
|
2889
2917
|
|
|
2890
2918
|
_defineProperty(this, "init", function () {
|
|
2891
|
-
document.addEventListener('
|
|
2919
|
+
if (_this.Settings.usePointerEvents) document.addEventListener('pointermove', _this.update, {
|
|
2920
|
+
// @ts-ignore
|
|
2921
|
+
passive: false
|
|
2922
|
+
});else document.addEventListener('mousemove', _this.update);
|
|
2892
2923
|
document.addEventListener('touchmove', _this.update, {
|
|
2893
2924
|
// @ts-ignore
|
|
2894
2925
|
passive: false
|
|
@@ -2917,7 +2948,11 @@
|
|
|
2917
2948
|
});
|
|
2918
2949
|
|
|
2919
2950
|
_defineProperty(this, "stop", function () {
|
|
2920
|
-
|
|
2951
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
2952
|
+
if (_this.Settings.usePointerEvents) document.removeEventListener('pointermove', _this.update, {
|
|
2953
|
+
// @ts-ignore
|
|
2954
|
+
passive: false
|
|
2955
|
+
});else document.removeEventListener('mousemove', _this.update);
|
|
2921
2956
|
document.removeEventListener('touchmove', _this.update, {
|
|
2922
2957
|
// @ts-ignore
|
|
2923
2958
|
passive: false
|
|
@@ -2938,6 +2973,7 @@
|
|
|
2938
2973
|
});
|
|
2939
2974
|
|
|
2940
2975
|
this.DS = DS;
|
|
2976
|
+
this.Settings = DS.stores.SettingsStore.s;
|
|
2941
2977
|
this.DS.subscribe('Interaction:init', this.init);
|
|
2942
2978
|
this.DS.subscribe('Interaction:start', function (_ref2) {
|
|
2943
2979
|
var event = _ref2.event;
|
|
@@ -2965,7 +3001,7 @@
|
|
|
2965
3001
|
|
|
2966
3002
|
/**
|
|
2967
3003
|
* @param {DSEvent} event
|
|
2968
|
-
* @return {MouseEvent|Touch}
|
|
3004
|
+
* @return {MouseEvent|PointerEvent|Touch}
|
|
2969
3005
|
* @private
|
|
2970
3006
|
*/
|
|
2971
3007
|
value: function _normalizedEvent(event) {
|