dragselect 2.4.4 → 2.5.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +84 -21
  3. package/dist/DragSelect.d.ts +26 -4
  4. package/dist/DragSelect.es6m.js +830 -782
  5. package/dist/DragSelect.js +830 -782
  6. package/dist/ds.es6m.min.js +1 -1
  7. package/dist/ds.min.js +1 -1
  8. package/dist/methods/addModificationObservers.d.ts +9 -1
  9. package/dist/methods/getAllParentNodes.d.ts +0 -43
  10. package/dist/methods/index.d.ts +1 -0
  11. package/dist/methods/isCollision.d.ts +1 -1
  12. package/dist/methods/subscriberAliases.d.ts +3 -1
  13. package/dist/modules/Area.d.ts +2 -12
  14. package/dist/modules/DropZone.d.ts +0 -43
  15. package/dist/modules/DropZones.d.ts +0 -46
  16. package/dist/modules/SelectableSet.d.ts +11 -0
  17. package/dist/modules/Selection.d.ts +1 -0
  18. package/dist/modules/index.d.ts +1 -0
  19. package/dist/types.d.ts +72 -2
  20. package/jest-puppeteer.config.js +1 -0
  21. package/package.json +5 -4
  22. package/src/DragSelect.js +29 -5
  23. package/src/methods/addModificationObservers.js +26 -5
  24. package/src/methods/canScroll.js +1 -1
  25. package/src/methods/getAllParentNodes.js +18 -0
  26. package/src/methods/handleElementPositionAttribute.js +1 -1
  27. package/src/methods/hydrateSettings.js +16 -0
  28. package/src/methods/index.js +1 -0
  29. package/src/methods/isCollision.js +24 -5
  30. package/src/methods/scrollElement.js +1 -1
  31. package/src/methods/subscriberAliases.js +16 -5
  32. package/src/methods/toArray.js +3 -2
  33. package/src/modules/Area.js +12 -44
  34. package/src/modules/DropZone.js +252 -0
  35. package/src/modules/DropZones.js +159 -0
  36. package/src/modules/SelectableSet.js +22 -0
  37. package/src/modules/Selection.js +9 -11
  38. package/src/modules/index.js +1 -0
  39. package/src/stores/SettingsStore.js +0 -1
  40. package/src/types.js +30 -2
@@ -6,9 +6,9 @@ import {
6
6
  addModificationObservers,
7
7
  debounce,
8
8
  getAreaRect,
9
- removeModificationObservers,
10
9
  scrollElement,
11
10
  handleElementPositionAttribute,
11
+ getAllParentNodes,
12
12
  } from '../methods'
13
13
 
14
14
  export default class Area {
@@ -18,20 +18,10 @@ export default class Area {
18
18
  */
19
19
  DS
20
20
  /**
21
- * @type {DSModificationCallback}
21
+ * @type {{cleanup:() => void}}
22
22
  * @private
23
23
  */
24
- _modificationCallback
25
- /**
26
- * @type {MutationObserver}
27
- * @private
28
- */
29
- _modificationObserver
30
- /**
31
- * @type {number}
32
- * @private
33
- */
34
- _zoom
24
+ _observers
35
25
  /**
36
26
  * @type {DSArea}
37
27
  * @private
@@ -72,15 +62,6 @@ export default class Area {
72
62
  this.setArea(settings.area)
73
63
  )
74
64
 
75
- this._modificationCallback = debounce((event) => {
76
- this.DS.PubSub.publish('Area:modified:pre', { event, item: this })
77
- this.reset()
78
- this.DS.PubSub.publish('Area:modified', { event, item: this })
79
- }, 60)
80
- this._modificationObserver = new MutationObserver(
81
- this._modificationCallback
82
- )
83
-
84
65
  this.DS.PubSub.subscribe('Interaction:init', this.start)
85
66
  this.DS.PubSub.subscribe('Interaction:end', this.reset)
86
67
  }
@@ -102,10 +83,13 @@ export default class Area {
102
83
  }
103
84
 
104
85
  start = () => {
105
- addModificationObservers(
86
+ this._observers = addModificationObservers(
106
87
  this.parentNodes,
107
- this._modificationCallback,
108
- this._modificationObserver
88
+ debounce((event) => {
89
+ this.DS.PubSub.publish('Area:modified:pre', { event, item: this })
90
+ this.reset()
91
+ this.DS.PubSub.publish('Area:modified', { event, item: this })
92
+ }, 60)
109
93
  )
110
94
  }
111
95
 
@@ -117,10 +101,7 @@ export default class Area {
117
101
  }
118
102
 
119
103
  stop = () => {
120
- removeModificationObservers(
121
- this._modificationObserver,
122
- this._modificationCallback
123
- )
104
+ this._observers.cleanup()
124
105
  this.reset()
125
106
  }
126
107
 
@@ -169,7 +150,7 @@ export default class Area {
169
150
  */
170
151
  get computedStyle() {
171
152
  if (this._computedStyle) return this._computedStyle
172
- if (this.HTMLNode instanceof HTMLDocument)
153
+ if (this.HTMLNode instanceof Document)
173
154
  return (this._computedStyle = window.getComputedStyle(
174
155
  this.HTMLNode.body || this.HTMLNode.documentElement
175
156
  ))
@@ -187,19 +168,6 @@ export default class Area {
187
168
 
188
169
  get parentNodes() {
189
170
  if (this._parentNodes) return this._parentNodes
190
-
191
- const traverse = (toWatch, index = 0) => {
192
- const parent = toWatch[index]?.parentNode
193
- if (parent) {
194
- toWatch.push(parent)
195
- index++
196
- return traverse(toWatch, index)
197
- } else {
198
- return toWatch
199
- }
200
- }
201
-
202
- this._parentNodes = traverse([this.HTMLNode])
203
- return this._parentNodes
171
+ return (this._parentNodes = getAllParentNodes(this.HTMLNode))
204
172
  }
205
173
  }
@@ -0,0 +1,252 @@
1
+ // @ts-check
2
+ import '../types'
3
+ import DragSelect from '../DragSelect'
4
+
5
+ import {
6
+ isCollision,
7
+ toArray,
8
+ debounce,
9
+ addModificationObservers,
10
+ getAllParentNodes,
11
+ } from '../methods'
12
+
13
+ export default class DropZone {
14
+ /**
15
+ * @type {string}
16
+ */
17
+ id
18
+
19
+ /**
20
+ * @type {DSElement}
21
+ */
22
+ element
23
+
24
+ /**
25
+ * @type {DSElements}
26
+ */
27
+ droppables
28
+
29
+ /**
30
+ * @type {DOMRect}
31
+ * @private
32
+ */
33
+ _rect
34
+
35
+ /**
36
+ * @type {{cleanup:()=>void}}
37
+ * @private
38
+ */
39
+ _observers
40
+
41
+ /**
42
+ * @type {NodeJS.Timeout}
43
+ * @private
44
+ */
45
+ _timeout
46
+
47
+ /**
48
+ * @type {DSElements}
49
+ * @private
50
+ */
51
+ _itemsDropped = []
52
+
53
+ /**
54
+ * @type {DSElements}
55
+ * @private
56
+ */
57
+ _itemsInside
58
+
59
+ /**
60
+ * @constructor Drag
61
+ * @param {Object} obj
62
+ * @param {DragSelect} obj.DS
63
+ * @param {string} obj.id
64
+ * @param {DSElement} obj.element
65
+ * @param {DSInputElements} obj.droppables
66
+ * @ignore
67
+ */
68
+ constructor({ DS, id, element, droppables }) {
69
+ this.DS = DS
70
+ this.Settings = DS.stores.SettingsStore.s
71
+
72
+ this.id = id
73
+ this.element = element
74
+ this.droppables = toArray(droppables)
75
+ this.element.classList.add(`${this.Settings.dropZoneClass}`)
76
+
77
+ // @ts-ignore: @todo: update to typescript
78
+ this.DS.subscribe('Settings:updated:dropZoneClass', ({ settings }) => {
79
+ this.element.classList.remove(settings['dropZoneClass:pre'])
80
+ this.element.classList.add(settings.dropZoneClass)
81
+ })
82
+
83
+ this._observers = addModificationObservers(
84
+ this.parentNodes,
85
+ debounce(() => (this._rect = null), this.Settings.refreshMemoryRate)
86
+ )
87
+
88
+ this.DS.subscribe('Interaction:start', this.start)
89
+ this.DS.subscribe('Interaction:end', this.stop)
90
+ }
91
+
92
+ /**
93
+ * @param {'add'|'remove'} action
94
+ */
95
+ setReadyClasses = (action) => {
96
+ if (this.isDestroyed) return
97
+ const selectedEls = this.droppables.filter((el) =>
98
+ this.DS.SelectedSet.has(el)
99
+ )
100
+ if (!selectedEls.length) return
101
+ selectedEls.forEach((item) => {
102
+ item.classList[action](`${this.Settings.droppableClass}`)
103
+ item.classList[action](`${this.Settings.droppableClass}-${this.id}`)
104
+ })
105
+ this.element.classList[action](`${this.Settings.dropZoneReadyClass}`)
106
+ }
107
+
108
+ /**
109
+ * This zone is NOT the target of a drop
110
+ */
111
+ handleNoDrop = () => {
112
+ if (this.isDestroyed) return
113
+ // for each selected element that is not part of the target zone, remove the classes
114
+ this.DS.SelectedSet.forEach((item) => {
115
+ item.classList.remove(this.Settings.droppedTargetClass)
116
+ item.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)
117
+ })
118
+ // and remove them from the zones dropped items
119
+ this._itemsDropped = this._itemsDropped.filter(
120
+ (item) => !this.DS.SelectedSet.has(item)
121
+ )
122
+ // if the zone has no dropped left, also remove the zones class
123
+ if (!this._itemsDropped?.length)
124
+ this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
125
+ }
126
+
127
+ /**
128
+ * This zone IS the target of a drop
129
+ */
130
+ handleDrop = () => {
131
+ if (this.isDestroyed) return
132
+ this._itemsDropped = [
133
+ // @ts-ignore
134
+ ...new Set([
135
+ ...this._itemsDropped,
136
+ ...this.droppables?.filter((item) => this.DS.SelectedSet.has(item)),
137
+ ]),
138
+ ]
139
+ // add the target class to the zones dropped items
140
+ this._itemsDropped?.forEach((item) => {
141
+ item.classList.add(`${this.Settings.droppedTargetClass}`)
142
+ item.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)
143
+ })
144
+ // if the zone has dropped, add the zones class
145
+ if (this._itemsDropped?.length)
146
+ this.element.classList.add(`${this.Settings.dropZoneTargetClass}`)
147
+ }
148
+
149
+ handleItemsInsideClasses = () => {
150
+ let isAnyInside = false
151
+ this.droppables.forEach((item) => {
152
+ if (this.itemsInside.includes(item)) {
153
+ item.classList.add(`${this.Settings.droppedInsideClass}`)
154
+ item.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`)
155
+ isAnyInside = true
156
+ } else {
157
+ item.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`)
158
+ if (!item.className.includes(`${this.Settings.droppedInsideClass}-`))
159
+ item.classList.remove(`${this.Settings.droppedInsideClass}`)
160
+ }
161
+ })
162
+
163
+ if (isAnyInside)
164
+ this.element.classList.add(`${this.Settings.dropZoneInsideClass}`)
165
+ else this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)
166
+ }
167
+
168
+ start = ({ isDragging }) => {
169
+ if (!isDragging || this.isDestroyed) return
170
+ this.setReadyClasses('add')
171
+ }
172
+
173
+ stop = ({ isDragging }) => {
174
+ if (!isDragging || this.isDestroyed) return
175
+ this.setReadyClasses('remove')
176
+ this.handleItemsInsideClasses()
177
+ }
178
+
179
+ destroy() {
180
+ this._observers.cleanup()
181
+ this.element.classList.remove(`${this.Settings.dropZoneClass}`)
182
+ this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
183
+ this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`)
184
+ this.droppables.forEach((item) => {
185
+ item.classList.remove(`${this.Settings.droppedTargetClass}`)
186
+ item.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)
187
+ item.classList.remove(`${this.Settings.droppableClass}`)
188
+ item.classList.remove(`${this.Settings.droppableClass}-${this.id}`)
189
+ })
190
+ this.DS.unsubscribe('Interaction:start', this.start)
191
+ this.DS.unsubscribe('Interaction:end', this.stop)
192
+ this.element = null
193
+ this.droppables = null
194
+ this.id = null
195
+ this._itemsDropped = null
196
+ this._itemsInside = null
197
+ this.isDestroyed = true
198
+ }
199
+
200
+ /**
201
+ * @returns {DSDropZone}
202
+ */
203
+ toObject = () => ({
204
+ id: this.id,
205
+ element: this.element,
206
+ droppables: this.droppables,
207
+ itemsDropped: this.itemsDropped,
208
+ itemsInside: this.itemsInside,
209
+ })
210
+
211
+ get rect() {
212
+ if (this.isDestroyed) return null
213
+ if (this._rect) return this._rect
214
+ return (this._rect = this.element.getBoundingClientRect())
215
+ }
216
+
217
+ get itemsDropped() {
218
+ if (this.isDestroyed) return null
219
+ return this._itemsDropped
220
+ }
221
+
222
+ get itemsInside() {
223
+ if (this.isDestroyed) return null
224
+ if (this._itemsInside) return this._itemsInside
225
+
226
+ this._itemsInside = this.droppables.flatMap((item) => {
227
+ if (
228
+ isCollision(
229
+ this.DS.SelectableSet.rects.get(item),
230
+ this.rect,
231
+ this.Settings.dropInsideThreshold
232
+ )
233
+ )
234
+ return [item]
235
+ return []
236
+ })
237
+
238
+ // since elements can be moved while this getter is called, we need to update the values every X seconds
239
+ if (this._timeout) clearTimeout(this._timeout)
240
+ this._timeout = setTimeout(
241
+ () => (this._itemsInside = null),
242
+ this.Settings.refreshMemoryRate
243
+ )
244
+
245
+ return this._itemsInside
246
+ }
247
+
248
+ get parentNodes() {
249
+ if (this._parentNodes) return this._parentNodes
250
+ return (this._parentNodes = getAllParentNodes(this.element))
251
+ }
252
+ }
@@ -0,0 +1,159 @@
1
+ // @ts-check
2
+
3
+ import '../types'
4
+ import DragSelect from '../DragSelect'
5
+ import DropZone from './DropZone'
6
+
7
+ import { isCollision, toArray } from '../methods'
8
+
9
+ export default class DropZones {
10
+ /**
11
+ * Get the drop zone by the zone element
12
+ * @type {Map<DSElement, DropZone>}
13
+ * @private
14
+ */
15
+ _zoneByElement = new Map()
16
+
17
+ /**
18
+ * Get the drop zone by the zone id
19
+ * @type {Map<string, DropZone>}
20
+ * @private
21
+ */
22
+ _zoneById = new Map()
23
+
24
+ /**
25
+ * Get the drop zones by one zone item
26
+ * @type {Map<DSElement,DropZone[]>}
27
+ * @private
28
+ */
29
+ _zonesByDroppable = new Map()
30
+
31
+ /**
32
+ * Get the drop zones by one zone item
33
+ * @type {DropZone[]}
34
+ * @private
35
+ */
36
+ _zones
37
+
38
+ /**
39
+ * @constructor Drag
40
+ * @param {{DS:DragSelect}} obj
41
+ * @ignore
42
+ */
43
+ constructor({ DS }) {
44
+ this.DS = DS
45
+ this.Settings = DS.stores.SettingsStore.s
46
+
47
+ // @ts-ignore: @todo: update to typescript
48
+ this.DS.subscribe('Settings:updated:dropZones', this.setDropZones)
49
+ this.setDropZones({
50
+ dropZones: /** @type {DSDropZone[]} */ (this.DS.stores.SettingsStore.s
51
+ .dropZones),
52
+ })
53
+
54
+ this.DS.subscribe('Interaction:end', this.stop)
55
+ }
56
+
57
+ /**
58
+ * @param {Object} obj
59
+ * @param {DSDropZone[]} [obj.dropZones]
60
+ */
61
+ setDropZones = ({ dropZones }) => {
62
+ if (!dropZones) return
63
+ if (this._zones) this._zones.forEach((zone) => zone.destroy())
64
+
65
+ this._zones = dropZones.map(
66
+ (zone) => new DropZone({ DS: this.DS, ...zone })
67
+ )
68
+ this._zones.forEach((zone) => {
69
+ this._zoneByElement.set(zone.element, zone)
70
+ this._zoneById.set(zone.id, zone)
71
+ zone.droppables.forEach((droppable) => {
72
+ const zones = this._zonesByDroppable.get(droppable)
73
+ if (!zones?.length) return this._zonesByDroppable.set(droppable, [zone])
74
+ // @ts-ignore
75
+ this._zonesByDroppable.set(droppable, [...new Set([...zones, zone])])
76
+ })
77
+ })
78
+ }
79
+
80
+ _handleDrop = (target) => {
81
+ this._zones.forEach((zone) => {
82
+ if (zone === target) return
83
+ zone.handleNoDrop()
84
+ })
85
+ if (!target) return
86
+ target.handleDrop()
87
+ }
88
+
89
+ /**
90
+ * @param {DSElements} elements
91
+ * @param {Vect2} point
92
+ * @returns {DropZone|undefined}
93
+ */
94
+ _getZoneByElementsFromPoint = (elements, { x, y }) => {
95
+ for (let i = 0, il = elements.length; i < il; i++) {
96
+ const zone = this._zoneByElement.get(elements[i])
97
+ if (
98
+ zone &&
99
+ isCollision(
100
+ zone.rect,
101
+ { left: x, right: x, top: y, bottom: y },
102
+ Math.min(this.Settings.dropTargetThreshold, 0.5)
103
+ )
104
+ ) {
105
+ return zone
106
+ }
107
+ }
108
+ }
109
+
110
+ stop = ({ isDragging }) => {
111
+ if (!isDragging) return
112
+ const target = this.getTarget()
113
+ this._handleDrop(target)
114
+ }
115
+
116
+ /// ///////////////////////////////////////////////////////////////////////////////////
117
+ // Getters
118
+
119
+ /**
120
+ * @param {string} zoneId
121
+ * @returns {DSElements|void}
122
+ */
123
+ getItemsDroppedById = (zoneId) => {
124
+ const zone = this._zoneById.get(zoneId)
125
+ if (!zone) return console.warn(`[DragSelect] No zone found (id: ${zoneId})`)
126
+ return zone.itemsDropped
127
+ }
128
+
129
+ /**
130
+ * @param {string} zoneId
131
+ * @param {boolean} addClasses
132
+ * @returns {DSElements|void}
133
+ */
134
+ getItemsInsideById = (zoneId, addClasses) => {
135
+ const zone = this._zoneById.get(zoneId)
136
+ if (!zone) return console.warn(`[DragSelect] No zone found (id: ${zoneId})`)
137
+ const { itemsInside } = zone
138
+ if (addClasses) zone.handleItemsInsideClasses()
139
+ return itemsInside
140
+ }
141
+
142
+ /**
143
+ * Returns first DropsZone under current pointer
144
+ * @param {Vect2} [coordinates]
145
+ * @returns {DropZone | undefined}
146
+ */
147
+ getTarget = (coordinates) => {
148
+ if (!this._zones?.length) return
149
+
150
+ const x = coordinates?.x || this.DS.stores.PointerStore.currentVal.x
151
+ const y = coordinates?.y || this.DS.stores.PointerStore.currentVal.y
152
+
153
+ const elements = document.elementsFromPoint(x, y)
154
+ return this._getZoneByElementsFromPoint(
155
+ /** @type {DSElements} */ (elements),
156
+ { x, y }
157
+ )
158
+ }
159
+ }
@@ -5,6 +5,16 @@ import DragSelect from '../DragSelect'
5
5
  import { toArray, handleElementPositionAttribute } from '../methods'
6
6
 
7
7
  export default class SelectableSet extends Set {
8
+ /**
9
+ * @type {Map<DSElement,DSBoundingRect>}
10
+ * @private
11
+ */
12
+ _rects
13
+ /**
14
+ * @type {NodeJS.Timeout}
15
+ * @private
16
+ */
17
+ _timeout
8
18
  /**
9
19
  * @constructor SelectableSet
10
20
  * @param {{DS:DragSelect}} obj
@@ -112,4 +122,16 @@ export default class SelectableSet extends Set {
112
122
  get elements() {
113
123
  return Array.from(this.values())
114
124
  }
125
+
126
+ get rects() {
127
+ if (this._rects) return this._rects
128
+ this._rects = new Map()
129
+ this.forEach((element) => this._rects.set(element, element.getBoundingClientRect()))
130
+
131
+ // since elements can be moved, we need to update the rects every X ms
132
+ if (this._timeout) clearTimeout(this._timeout)
133
+ this._timeout = setTimeout(() => this._rects = null, this.Settings.refreshMemoryRate)
134
+
135
+ return this._rects
136
+ }
115
137
  }
@@ -18,6 +18,7 @@ export default class Selection {
18
18
  */
19
19
  constructor({ DS }) {
20
20
  this.DS = DS
21
+ this.Settings = this.DS.stores.SettingsStore.s
21
22
  this.DS.subscribe('Interaction:start', this.start)
22
23
  this.DS.subscribe('Interaction:update', this.update)
23
24
  }
@@ -60,23 +61,20 @@ export default class Selection {
60
61
  const { SelectableSet, SelectorArea, Selector } = this.DS
61
62
 
62
63
  /** @type {any} */
63
- const elPosCombo = SelectableSet.elements.map((element) => {
64
- return [element, element.getBoundingClientRect()]
65
- })
64
+ const elRects = SelectableSet.rects
66
65
 
67
66
  const select = []
68
67
  const unselect = []
69
68
 
70
- for (let i = 0, il = elPosCombo.length; i < il; i++) {
71
- if (!SelectorArea.isInside(elPosCombo[i][0], elPosCombo[i][1])) continue
72
- if (isCollision(elPosCombo[i][1], Selector.rect))
73
- select.push(elPosCombo[i][0])
74
- else unselect.push(elPosCombo[i][0])
69
+ for(const [element, rect] of elRects) {
70
+ if (!SelectorArea.isInside(element, rect)) continue
71
+ if (isCollision(rect, Selector.rect, this.Settings.selectionThreshold)) select.push(element)
72
+ else unselect.push(element)
75
73
  }
76
74
 
77
75
  const multiSelectionToggle =
78
76
  (this.DS.stores.KeyStore.isMultiSelectKeyPressed(event)) &&
79
- this.DS.stores.SettingsStore.s.multiSelectToggling
77
+ this.Settings.multiSelectToggling
80
78
 
81
79
  if (this.DS.continue) return
82
80
  select.forEach((element) =>
@@ -85,7 +83,7 @@ export default class Selection {
85
83
  force,
86
84
  multiSelectionToggle,
87
85
  SelectedSet: this.DS.SelectedSet,
88
- hoverClassName: this.DS.stores.SettingsStore.s.hoverClass,
86
+ hoverClassName: this.Settings.hoverClass,
89
87
  })
90
88
  )
91
89
  unselect.forEach((element) =>
@@ -93,7 +91,7 @@ export default class Selection {
93
91
  element,
94
92
  force,
95
93
  SelectedSet: this.DS.SelectedSet,
96
- hoverClassName: this.DS.stores.SettingsStore.s.hoverClass,
94
+ hoverClassName: this.Settings.hoverClass,
97
95
  PrevSelectedSet: this._prevSelectedSet,
98
96
  })
99
97
  )
@@ -1,5 +1,6 @@
1
1
  export { default as Area } from './Area'
2
2
  export { default as Drag } from './Drag'
3
+ export { default as DropZones } from './DropZones'
3
4
  export { default as Interaction } from './Interaction'
4
5
  export { default as PubSub } from './PubSub'
5
6
  export { default as SelectableSet } from './SelectableSet'
@@ -10,7 +10,6 @@ export default class SettingsStore {
10
10
  * @private
11
11
  * */
12
12
  _settings = {}
13
-
14
13
  /**
15
14
  * Holds the settings and their previous value `:pre`
16
15
  * @example {
package/src/types.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The Settings to be passed to the Class
3
3
  * @typedef {Object} Settings
4
- * @property {HTMLElement|SVGElement|HTMLDocument} [area=document] area in which you can drag. If not provided it will be the whole document
4
+ * @property {HTMLElement|SVGElement|Document} [area=document] area in which you can drag. If not provided it will be the whole document
5
5
  * @property {DSInputElements} [selectables=[]] the elements that can be selected
6
6
  * @property {number} [autoScrollSpeed=5] Speed in which the area scrolls while selecting (if available). Unit is pixel per movement.
7
7
  * @property {Vect2} [overflowTolerance={x:25,y:25}] Tolerance for autoScroll (how close one has to be near an edges for autoScroll to start)
@@ -11,18 +11,30 @@
11
11
  * @property {boolean} [multiSelectToggling=true] Whether or not to toggle already active elements while multi-selecting
12
12
  * @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.
13
13
  * @property {HTMLElement} [selector=HTMLElement] the square that will draw the selection
14
+ * @property {number} [selectionThreshold=0] how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection)
14
15
  * @property {boolean} [draggability=true] When a user is dragging on an already selected element, the selection is dragged.
15
16
  * @property {boolean} [immediateDrag=true] Whether an element is draggable from the start or needs to be selected first
16
17
  * @property {boolean} [keyboardDrag=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it)
17
18
  * @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
18
19
  * @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
19
20
  * @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
21
+ * @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.
22
+ * @property {DSInputDropZone[]} [dropZones=[]] one or more drop-elements: where the selectables can be dropped into
23
+ * @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)
24
+ * @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)
20
25
  * @property {boolean} [usePointerEvents=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
21
26
  * @property {string} [hoverClass=ds-hover] the class assigned to the mouse hovered items
22
27
  * @property {string} [selectableClass=ds-selectable] the class assigned to the elements that can be selected
23
28
  * @property {string} [selectedClass=ds-selected] the class assigned to the selected items
24
29
  * @property {string} [selectorClass=ds-selector] the class assigned to the square selector helper
25
30
  * @property {string} [selectorAreaClass=ds-selector-area] the class assigned to the square in which the selector resides. By default it's invisible
31
+ * @property {string} [droppedTargetClass=ds-dropped-target] on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id}
32
+ * @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}
33
+ * @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}
34
+ * @property {string} [dropZoneClass=ds-dropzone] on each dropZone
35
+ * @property {string} [dropZoneReadyClass=ds-dropzone-ready] on corresponding dropZone when element is dragged
36
+ * @property {string} [dropZoneTargetClass=ds-dropzone-target] on dropZone that has elements from any successful target drop
37
+ * @property {string} [dropZoneInsideClass=ds-dropzone-inside] on dropZone that has elements inside after any drop
26
38
  */
27
39
 
28
40
  /**
@@ -37,17 +49,33 @@
37
49
  * @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' } }
38
50
  * @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} [scroll_directions]
39
51
  * @property {number} [scroll_multiplier]
52
+ * @property {DSDropZone} [dropTarget] The dropZone element that the element was dropped into (or the mouse is currently hovering over)
40
53
  */
41
54
  /**
42
55
  * @typedef {function} DSCallback
43
56
  * @param {CallbackObject} data
44
57
  */
45
58
 
59
+ /**
60
+ * @typedef {Object} DSInputDropZone
61
+ * @property {string} id
62
+ * @property {DSElement} element
63
+ * @property {DSInputElements} droppables
64
+ */
65
+ /**
66
+ * @typedef {Object} DSDropZone
67
+ * @property {string} id
68
+ * @property {DSElement} element
69
+ * @property {DSElements} droppables
70
+ * @property {DSElements} [itemsDropped] the items related to the target zone
71
+ * @property {DSElements} [itemsInside] the items that are within the targets bounds
72
+ */
73
+
46
74
  /** @typedef {{x: number, y: number}} Vect2 */
47
75
  /** @typedef {{x:number,y:number,w:number,h:number,r:number,b:number}} DSElementPos */
48
76
  /** @typedef {Array.<'top'|'bottom'|'left'|'right'|undefined>} DSEdges */
49
77
 
50
- /** @typedef {HTMLElement|SVGElement|HTMLDocument} DSArea area within which you can drag */
78
+ /** @typedef {HTMLElement|SVGElement|Document} DSArea area within which you can drag */
51
79
  /** @typedef {HTMLElement} DSSelectorArea area in which you can drag */
52
80
  /** @typedef {Array.<HTMLElement|SVGElement> | HTMLElement | SVGElement} DSInputElements the elements that can be selected */
53
81
  /** @typedef {Array.<HTMLElement|SVGElement>} DSElements the elements that can be selected */