dragselect 2.5.1 → 2.5.3
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 +63 -47
- package/dist/DragSelect.js +63 -47
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/methods/subscriberAliases.d.ts +1 -1
- package/dist/modules/DropZone.d.ts +5 -3
- package/dist/types.d.ts +10 -1
- package/package.json +1 -1
- package/src/methods/addModificationObservers.js +2 -5
- package/src/methods/canScroll.js +3 -3
- package/src/methods/getAllParentNodes.js +1 -2
- package/src/methods/getStylePosition.js +10 -11
- package/src/methods/handleElementPositionAttribute.js +1 -1
- package/src/methods/hydrateSettings.js +176 -47
- package/src/methods/isCollision.js +1 -1
- package/src/methods/subscriberAliases.js +16 -7
- package/src/modules/Area.js +14 -5
- package/src/modules/Drag.js +16 -4
- package/src/modules/DropZone.js +12 -3
- package/src/modules/DropZones.js +4 -2
- package/src/modules/Interaction.js +8 -5
- package/src/modules/PubSub.js +5 -7
- package/src/modules/SelectableSet.js +17 -13
- package/src/modules/SelectedSet.js +2 -0
- package/src/modules/Selection.js +4 -3
- package/src/modules/Selector.js +3 -3
- package/src/types.js +3 -3
package/src/modules/DropZone.js
CHANGED
|
@@ -24,7 +24,7 @@ export default class DropZone {
|
|
|
24
24
|
/**
|
|
25
25
|
* @type {DSElements}
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
_droppables
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @type {DOMRect}
|
|
@@ -62,7 +62,7 @@ export default class DropZone {
|
|
|
62
62
|
* @param {DragSelect} obj.DS
|
|
63
63
|
* @param {string} obj.id
|
|
64
64
|
* @param {DSElement} obj.element
|
|
65
|
-
* @param {DSInputElements} obj.droppables
|
|
65
|
+
* @param {DSInputElements} [obj.droppables]
|
|
66
66
|
* @ignore
|
|
67
67
|
*/
|
|
68
68
|
constructor({ DS, id, element, droppables }) {
|
|
@@ -71,7 +71,7 @@ export default class DropZone {
|
|
|
71
71
|
|
|
72
72
|
this.id = id
|
|
73
73
|
this.element = element
|
|
74
|
-
this.droppables = toArray(droppables)
|
|
74
|
+
if (droppables) this.droppables = toArray(droppables)
|
|
75
75
|
this.element.classList.add(`${this.Settings.dropZoneClass}`)
|
|
76
76
|
|
|
77
77
|
// @ts-ignore: @todo: update to typescript
|
|
@@ -249,4 +249,13 @@ export default class DropZone {
|
|
|
249
249
|
if (this._parentNodes) return this._parentNodes
|
|
250
250
|
return (this._parentNodes = getAllParentNodes(this.element))
|
|
251
251
|
}
|
|
252
|
+
|
|
253
|
+
get droppables() {
|
|
254
|
+
if (this._droppables) return this._droppables
|
|
255
|
+
return this.DS.SelectableSet.elements
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
set droppables(value) {
|
|
259
|
+
this._droppables = value
|
|
260
|
+
}
|
|
252
261
|
}
|
package/src/modules/DropZones.js
CHANGED
|
@@ -4,7 +4,7 @@ import '../types'
|
|
|
4
4
|
import DragSelect from '../DragSelect'
|
|
5
5
|
import DropZone from './DropZone'
|
|
6
6
|
|
|
7
|
-
import { isCollision
|
|
7
|
+
import { isCollision } from '../methods'
|
|
8
8
|
|
|
9
9
|
export default class DropZones {
|
|
10
10
|
/**
|
|
@@ -45,7 +45,9 @@ export default class DropZones {
|
|
|
45
45
|
this.Settings = DS.stores.SettingsStore.s
|
|
46
46
|
|
|
47
47
|
// @ts-ignore: @todo: update to typescript
|
|
48
|
-
this.DS.subscribe('Settings:updated:dropZones',
|
|
48
|
+
this.DS.subscribe('Settings:updated:dropZones', ({ settings }) =>
|
|
49
|
+
this.setDropZones(settings)
|
|
50
|
+
)
|
|
49
51
|
this.setDropZones({
|
|
50
52
|
dropZones: /** @type {DSDropZone[]} */ (this.DS.stores.SettingsStore.s
|
|
51
53
|
.dropZones),
|
|
@@ -5,6 +5,7 @@ import '../types'
|
|
|
5
5
|
export default class Interaction {
|
|
6
6
|
/** @type {boolean} */
|
|
7
7
|
isInteracting
|
|
8
|
+
|
|
8
9
|
/** @type {boolean} */
|
|
9
10
|
isDragging
|
|
10
11
|
|
|
@@ -30,9 +31,10 @@ export default class Interaction {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
init = () => this.DS.publish('Interaction:init:pre', {})
|
|
34
|
+
|
|
33
35
|
_init = () => {
|
|
34
36
|
this.stop()
|
|
35
|
-
|
|
37
|
+
|
|
36
38
|
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
37
39
|
if (this.Settings.usePointerEvents)
|
|
38
40
|
this.DS.Area.HTMLNode.addEventListener('pointerdown', this.start, {
|
|
@@ -62,7 +64,7 @@ export default class Interaction {
|
|
|
62
64
|
(event.target &&
|
|
63
65
|
!this.DS.SelectorArea.isInside(
|
|
64
66
|
/** @type {DSElement} */ (event.target)
|
|
65
|
-
)) || //fix outside elements issue
|
|
67
|
+
)) || // fix outside elements issue
|
|
66
68
|
(!isKeyboardClick && !this.DS.SelectorArea.isClicked(event)) // make sure the mouse click is inside the area
|
|
67
69
|
)
|
|
68
70
|
return false
|
|
@@ -78,6 +80,7 @@ export default class Interaction {
|
|
|
78
80
|
event,
|
|
79
81
|
isDragging: this.isDragging,
|
|
80
82
|
})
|
|
83
|
+
|
|
81
84
|
_start = (event) => {
|
|
82
85
|
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
|
|
83
86
|
if (!this._canInteract(event)) return
|
|
@@ -147,8 +150,7 @@ export default class Interaction {
|
|
|
147
150
|
const node = /** @type {any} */ (event.target)
|
|
148
151
|
if (!SelectableSet.has(node)) return
|
|
149
152
|
|
|
150
|
-
if (!KeyStore.isMultiSelectKeyPressed(event))
|
|
151
|
-
SelectedSet.clear()
|
|
153
|
+
if (!KeyStore.isMultiSelectKeyPressed(event)) SelectedSet.clear()
|
|
152
154
|
SelectedSet.toggle(node)
|
|
153
155
|
|
|
154
156
|
this.reset() // simulate mouse-up (that does not exist on keyboard)
|
|
@@ -193,8 +195,9 @@ export default class Interaction {
|
|
|
193
195
|
event,
|
|
194
196
|
isDragging: this.isDragging,
|
|
195
197
|
})
|
|
198
|
+
|
|
196
199
|
_reset = (event) => {
|
|
197
|
-
const isDragging = this
|
|
200
|
+
const { isDragging } = this
|
|
198
201
|
this.stop()
|
|
199
202
|
this.init()
|
|
200
203
|
this.DS.publish('Interaction:end', { event, isDragging })
|
package/src/modules/PubSub.js
CHANGED
|
@@ -48,17 +48,15 @@ export default class PubSub {
|
|
|
48
48
|
*/
|
|
49
49
|
publish = (eventName, data) => {
|
|
50
50
|
if (Array.isArray(eventName))
|
|
51
|
-
eventName.forEach(name => this._publish(name, data))
|
|
52
|
-
else
|
|
53
|
-
this._publish(eventName, data)
|
|
51
|
+
eventName.forEach((name) => this._publish(name, data))
|
|
52
|
+
else this._publish(eventName, data)
|
|
54
53
|
}
|
|
54
|
+
|
|
55
55
|
_publish = (eventName, data) => {
|
|
56
56
|
const subscribers = this.subscribers[eventName]
|
|
57
57
|
if (!Array.isArray(subscribers)) return
|
|
58
|
-
if (eventName.includes(`:pre`))
|
|
59
|
-
|
|
60
|
-
else
|
|
61
|
-
this._handlePublish(subscribers, data)
|
|
58
|
+
if (eventName.includes(`:pre`)) this._handlePrePublish(subscribers, data)
|
|
59
|
+
else this._handlePublish(subscribers, data)
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
// non-pre events are executed first in first out
|
|
@@ -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
|
}
|
|
@@ -58,8 +58,10 @@ export default class SelectedSet extends Set {
|
|
|
58
58
|
|
|
59
59
|
/** @param {DSElements} elements */
|
|
60
60
|
addAll = (elements) => elements.forEach((el) => this.add(el))
|
|
61
|
+
|
|
61
62
|
/** @param {DSElements} elements */
|
|
62
63
|
deleteAll = (elements) => elements.forEach((el) => this.delete(el))
|
|
64
|
+
|
|
63
65
|
/** @return {DSElements} */
|
|
64
66
|
get elements() {
|
|
65
67
|
return Array.from(this.values())
|
package/src/modules/Selection.js
CHANGED
|
@@ -66,14 +66,15 @@ export default class Selection {
|
|
|
66
66
|
const select = []
|
|
67
67
|
const unselect = []
|
|
68
68
|
|
|
69
|
-
for(const [element, rect] of elRects) {
|
|
69
|
+
for (const [element, rect] of elRects) {
|
|
70
70
|
if (!SelectorArea.isInside(element, rect)) continue
|
|
71
|
-
if (isCollision(rect, Selector.rect, this.Settings.selectionThreshold))
|
|
71
|
+
if (isCollision(rect, Selector.rect, this.Settings.selectionThreshold))
|
|
72
|
+
select.push(element)
|
|
72
73
|
else unselect.push(element)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
const multiSelectionToggle =
|
|
76
|
-
|
|
77
|
+
this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) &&
|
|
77
78
|
this.Settings.multiSelectToggling
|
|
78
79
|
|
|
79
80
|
if (this.DS.continue) return
|
package/src/modules/Selector.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
import '../types
|
|
2
|
+
import '../types'
|
|
3
3
|
import DragSelect from '../DragSelect'
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -27,7 +27,7 @@ export default class Selector {
|
|
|
27
27
|
// @ts-ignore: @todo: update to typescript
|
|
28
28
|
this.DS.subscribe('Settings:updated:selectorClass', ({ settings }) => {
|
|
29
29
|
this.HTMLNode.classList.remove(settings['selectorClass:pre'])
|
|
30
|
-
this.HTMLNode.classList.add(settings
|
|
30
|
+
this.HTMLNode.classList.add(settings.selectorClass)
|
|
31
31
|
})
|
|
32
32
|
// @ts-ignore: @todo: update to typescript
|
|
33
33
|
this.DS.subscribe('Settings:updated:selector', this.attachSelector)
|
|
@@ -37,7 +37,7 @@ export default class Selector {
|
|
|
37
37
|
this.DS.subscribe('Interaction:update', this.update)
|
|
38
38
|
this.DS.subscribe('Interaction:end', this.stop)
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
attachSelector = () => {
|
|
42
42
|
if (this.HTMLNode && this.DS.SelectorArea?.HTMLNode)
|
|
43
43
|
this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode)
|
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
|