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