dragselect 2.5.0 → 2.5.2
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 +8 -0
- package/README.md +3 -3
- package/dist/DragSelect.es6m.js +39 -33
- package/dist/DragSelect.js +39 -33
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/modules/DropZone.d.ts +5 -3
- package/dist/modules/DropZones.d.ts +0 -3
- package/dist/types.d.ts +10 -1
- package/package.json +1 -1
- package/src/methods/hydrateSettings.js +176 -47
- package/src/modules/DropZone.js +62 -25
- package/src/modules/DropZones.js +22 -16
- package/src/modules/SelectableSet.js +17 -13
- package/src/types.js +3 -3
|
@@ -10,11 +10,13 @@ export default class SelectableSet extends Set {
|
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
12
|
_rects
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* @type {NodeJS.Timeout}
|
|
15
16
|
* @private
|
|
16
17
|
*/
|
|
17
18
|
_timeout
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* @constructor SelectableSet
|
|
20
22
|
* @param {{DS:DragSelect}} obj
|
|
@@ -34,15 +36,12 @@ export default class SelectableSet extends Set {
|
|
|
34
36
|
this.DS.subscribe('Settings:updated:selectableClass', ({ settings }) => {
|
|
35
37
|
this.forEach((el) => {
|
|
36
38
|
el.classList.remove(settings['selectableClass:pre'])
|
|
37
|
-
el.classList.add(settings
|
|
39
|
+
el.classList.add(settings.selectableClass)
|
|
38
40
|
})
|
|
39
41
|
})
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
init = () =>
|
|
43
|
-
toArray(this.Settings.selectables).forEach((el) =>
|
|
44
|
-
this.add(el)
|
|
45
|
-
)
|
|
44
|
+
init = () => toArray(this.Settings.selectables).forEach((el) => this.add(el))
|
|
46
45
|
|
|
47
46
|
/** @param {DSElement} element */
|
|
48
47
|
add(element) {
|
|
@@ -54,23 +53,20 @@ export default class SelectableSet extends Set {
|
|
|
54
53
|
this.DS.publish('Selectable:added:pre', publishData)
|
|
55
54
|
element.classList.add(this.Settings.selectableClass)
|
|
56
55
|
element.addEventListener('click', this._onClick)
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
if (this.Settings.usePointerEvents)
|
|
59
58
|
element.addEventListener('pointerdown', this._onPointer, {
|
|
60
59
|
// @ts-ignore
|
|
61
60
|
passive: false,
|
|
62
61
|
})
|
|
63
62
|
else element.addEventListener('mousedown', this._onPointer)
|
|
64
|
-
|
|
63
|
+
|
|
65
64
|
element.addEventListener('touchstart', this._onPointer, {
|
|
66
65
|
// @ts-ignore
|
|
67
66
|
passive: false,
|
|
68
67
|
})
|
|
69
68
|
|
|
70
|
-
if (
|
|
71
|
-
this.Settings.draggability &&
|
|
72
|
-
!this.Settings.useTransform
|
|
73
|
-
)
|
|
69
|
+
if (this.Settings.draggability && !this.Settings.useTransform)
|
|
74
70
|
handleElementPositionAttribute({
|
|
75
71
|
computedStyle: window.getComputedStyle(element),
|
|
76
72
|
node: element,
|
|
@@ -111,13 +107,16 @@ export default class SelectableSet extends Set {
|
|
|
111
107
|
|
|
112
108
|
_onClick = (event) =>
|
|
113
109
|
this.DS.publish(['Selectable:click:pre', 'Selectable:click'], { event })
|
|
110
|
+
|
|
114
111
|
_onPointer = (event) =>
|
|
115
112
|
this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], { event })
|
|
116
113
|
|
|
117
114
|
/** @param {DSElements} elements */
|
|
118
115
|
addAll = (elements) => elements.forEach((el) => this.add(el))
|
|
116
|
+
|
|
119
117
|
/** @param {DSElements} elements */
|
|
120
118
|
deleteAll = (elements) => elements.forEach((el) => this.delete(el))
|
|
119
|
+
|
|
121
120
|
/** @return {DSElements} */
|
|
122
121
|
get elements() {
|
|
123
122
|
return Array.from(this.values())
|
|
@@ -126,11 +125,16 @@ export default class SelectableSet extends Set {
|
|
|
126
125
|
get rects() {
|
|
127
126
|
if (this._rects) return this._rects
|
|
128
127
|
this._rects = new Map()
|
|
129
|
-
this.forEach((element) =>
|
|
128
|
+
this.forEach((element) =>
|
|
129
|
+
this._rects.set(element, element.getBoundingClientRect())
|
|
130
|
+
)
|
|
130
131
|
|
|
131
132
|
// since elements can be moved, we need to update the rects every X ms
|
|
132
133
|
if (this._timeout) clearTimeout(this._timeout)
|
|
133
|
-
this._timeout = setTimeout(
|
|
134
|
+
this._timeout = setTimeout(
|
|
135
|
+
() => (this._rects = null),
|
|
136
|
+
this.Settings.refreshMemoryRate
|
|
137
|
+
)
|
|
134
138
|
|
|
135
139
|
return this._rects
|
|
136
140
|
}
|
package/src/types.js
CHANGED
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @typedef {Object} DSInputDropZone
|
|
61
|
-
* @property {string} id
|
|
62
|
-
* @property {DSElement} element
|
|
63
|
-
* @property {DSInputElements} droppables
|
|
61
|
+
* @property {string} id can be any unique identifier of type string
|
|
62
|
+
* @property {DSElement} element is the dropzone itself
|
|
63
|
+
* @property {DSInputElements} [droppables] the elements that can be dropped into that zone. This is optional, by default it will be all selectables
|
|
64
64
|
*/
|
|
65
65
|
/**
|
|
66
66
|
* @typedef {Object} DSDropZone
|