dragselect 2.7.3 → 3.0.0

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 (144) hide show
  1. package/CHANGELOG.md +100 -22
  2. package/LICENSE +690 -0
  3. package/README.md +2 -1
  4. package/jest-puppeteer.config.js +13 -3
  5. package/jest.config.js +5 -0
  6. package/package.json +40 -46
  7. package/rollup.config.mjs +82 -0
  8. package/src/DragSelect.ts +425 -0
  9. package/src/methods/addModificationObservers.ts +51 -0
  10. package/src/methods/canScroll.ts +19 -0
  11. package/src/methods/{createSelectorAreaElement.js → createSelectorAreaElement.ts} +1 -8
  12. package/src/methods/{createSelectorElement.js → createSelectorElement.ts} +1 -9
  13. package/src/methods/{debounce.js → debounce.ts} +5 -11
  14. package/src/methods/ensureArray.ts +13 -0
  15. package/src/methods/getAllParentNodes.ts +15 -0
  16. package/src/methods/{getAreaRect.js → getAreaRect.ts} +2 -6
  17. package/src/methods/getCurrentScroll.ts +14 -0
  18. package/src/methods/{documentScroll.js → getDocumentScroll.ts} +2 -2
  19. package/src/methods/{getOverflowEdges.js → getOverflowEdges.ts} +11 -11
  20. package/src/methods/getPointerPos.ts +9 -0
  21. package/src/methods/getSelectionRect.ts +29 -0
  22. package/src/methods/{getSelectorPosition.js → getSelectorPosition.ts} +11 -9
  23. package/src/methods/{getStylePosition.spec.js → getStylePosition.spec.ts} +9 -9
  24. package/src/methods/{getStylePosition.js → getStylePosition.ts} +5 -21
  25. package/src/methods/handleElementPositionAttribute.ts +15 -0
  26. package/src/methods/handleKeyboardDragPosDifference.ts +35 -0
  27. package/src/methods/handleSelection.ts +26 -0
  28. package/src/methods/{handleUnSelection.js → handleUnSelection.ts} +14 -14
  29. package/src/methods/{hydrateSettings.js → hydrateSettings.ts} +15 -26
  30. package/src/methods/isCollision.ts +66 -0
  31. package/src/methods/limitDirection.ts +36 -0
  32. package/src/methods/moveElement.ts +18 -0
  33. package/src/methods/{scrollElement.js → scrollElement.ts} +4 -10
  34. package/src/methods/{setStylePosition.js → setStylePosition.ts} +3 -11
  35. package/src/methods/subscriberAliases.ts +240 -0
  36. package/src/methods/updateElementStylePos.ts +7 -0
  37. package/src/methods/vect2.ts +34 -0
  38. package/src/modules/Area.ts +169 -0
  39. package/src/modules/Drag.ts +236 -0
  40. package/src/modules/{DropZone.js → DropZone.ts} +80 -119
  41. package/src/modules/DropZones.ts +151 -0
  42. package/src/modules/Interaction.ts +251 -0
  43. package/src/modules/PubSub.ts +111 -0
  44. package/src/modules/SelectableSet.ts +146 -0
  45. package/src/modules/SelectedSet.ts +92 -0
  46. package/src/modules/{Selection.js → Selection.ts} +59 -44
  47. package/src/modules/Selector.ts +81 -0
  48. package/src/modules/{SelectorArea.js → SelectorArea.ts} +58 -71
  49. package/src/stores/KeyStore.ts +92 -0
  50. package/src/stores/PointerStore.ts +194 -0
  51. package/src/stores/ScrollStore.ts +87 -0
  52. package/src/stores/SettingsStore.ts +88 -0
  53. package/src/types.ts +158 -0
  54. package/tsconfig.json +105 -0
  55. package/bower.json +0 -24
  56. package/dist/DragSelect.d.ts +0 -200
  57. package/dist/DragSelect.es6m.js +0 -3877
  58. package/dist/DragSelect.js +0 -3885
  59. package/dist/ds.es6m.min.js +0 -1
  60. package/dist/ds.min.js +0 -1
  61. package/dist/methods/addModificationObservers.d.ts +0 -11
  62. package/dist/methods/canScroll.d.ts +0 -3
  63. package/dist/methods/createSelectorAreaElement.d.ts +0 -3
  64. package/dist/methods/createSelectorElement.d.ts +0 -3
  65. package/dist/methods/debounce.d.ts +0 -3
  66. package/dist/methods/documentScroll.d.ts +0 -6
  67. package/dist/methods/getAllParentNodes.d.ts +0 -3
  68. package/dist/methods/getAreaRect.d.ts +0 -3
  69. package/dist/methods/getBoundingClientRect.d.ts +0 -4
  70. package/dist/methods/getCurrentScroll.d.ts +0 -3
  71. package/dist/methods/getOverflowEdges.d.ts +0 -7
  72. package/dist/methods/getPointerPos.d.ts +0 -5
  73. package/dist/methods/getSelectorPosition.d.ts +0 -12
  74. package/dist/methods/getStylePosition.d.ts +0 -3
  75. package/dist/methods/handleElementOverflow.d.ts +0 -10
  76. package/dist/methods/handleElementPositionAttribute.d.ts +0 -6
  77. package/dist/methods/handleKeyboardDragPosDifference.d.ts +0 -13
  78. package/dist/methods/handleSelection.d.ts +0 -9
  79. package/dist/methods/handleUnSelection.d.ts +0 -9
  80. package/dist/methods/hydrateSettings.d.ts +0 -3
  81. package/dist/methods/index.d.ts +0 -30
  82. package/dist/methods/isCollision.d.ts +0 -13
  83. package/dist/methods/moveElement.d.ts +0 -8
  84. package/dist/methods/removeModificationObservers.d.ts +0 -3
  85. package/dist/methods/scrollElement.d.ts +0 -3
  86. package/dist/methods/setStylePosition.d.ts +0 -3
  87. package/dist/methods/subscriberAliases.d.ts +0 -14
  88. package/dist/methods/toArray.d.ts +0 -3
  89. package/dist/methods/updateElementStylePos.d.ts +0 -8
  90. package/dist/methods/vect2.d.ts +0 -8
  91. package/dist/modules/Area.d.ts +0 -80
  92. package/dist/modules/Drag.d.ts +0 -71
  93. package/dist/modules/DropZone.d.ts +0 -90
  94. package/dist/modules/DropZones.d.ts +0 -73
  95. package/dist/modules/Interaction.d.ts +0 -51
  96. package/dist/modules/PubSub.d.ts +0 -37
  97. package/dist/modules/SelectableSet.d.ts +0 -40
  98. package/dist/modules/SelectedSet.d.ts +0 -29
  99. package/dist/modules/Selection.d.ts +0 -54
  100. package/dist/modules/Selector.d.ts +0 -29
  101. package/dist/modules/SelectorArea.d.ts +0 -58
  102. package/dist/modules/index.d.ts +0 -11
  103. package/dist/stores/KeyStore.d.ts +0 -34
  104. package/dist/stores/PointerStore.d.ts +0 -83
  105. package/dist/stores/ScrollStore.d.ts +0 -38
  106. package/dist/stores/SettingsStore.d.ts +0 -39
  107. package/dist/stores/index.d.ts +0 -5
  108. package/dist/types.d.ts +0 -276
  109. package/jsconfig.json +0 -13
  110. package/rollup.config.js +0 -101
  111. package/src/DragSelect.js +0 -384
  112. package/src/methods/addModificationObservers.js +0 -38
  113. package/src/methods/canScroll.js +0 -20
  114. package/src/methods/getAllParentNodes.js +0 -17
  115. package/src/methods/getBoundingClientRect.js +0 -33
  116. package/src/methods/getCurrentScroll.js +0 -15
  117. package/src/methods/getPointerPos.js +0 -13
  118. package/src/methods/handleElementOverflow.js +0 -65
  119. package/src/methods/handleElementPositionAttribute.js +0 -16
  120. package/src/methods/handleKeyboardDragPosDifference.js +0 -57
  121. package/src/methods/handleSelection.js +0 -26
  122. package/src/methods/index.js +0 -29
  123. package/src/methods/isCollision.js +0 -58
  124. package/src/methods/moveElement.js +0 -39
  125. package/src/methods/removeModificationObservers.js +0 -13
  126. package/src/methods/subscriberAliases.js +0 -72
  127. package/src/methods/toArray.js +0 -18
  128. package/src/methods/updateElementStylePos.js +0 -15
  129. package/src/methods/vect2.js +0 -54
  130. package/src/modules/Area.js +0 -183
  131. package/src/modules/Drag.js +0 -257
  132. package/src/modules/DropZones.js +0 -161
  133. package/src/modules/Interaction.js +0 -208
  134. package/src/modules/PubSub.js +0 -78
  135. package/src/modules/SelectableSet.js +0 -144
  136. package/src/modules/SelectedSet.js +0 -69
  137. package/src/modules/Selector.js +0 -90
  138. package/src/modules/index.js +0 -10
  139. package/src/stores/KeyStore.js +0 -83
  140. package/src/stores/PointerStore.js +0 -218
  141. package/src/stores/ScrollStore.js +0 -92
  142. package/src/stores/SettingsStore.js +0 -66
  143. package/src/stores/index.js +0 -4
  144. package/src/types.js +0 -100
@@ -1,81 +1,60 @@
1
- // @ts-check
2
- import '../types'
3
1
  import DragSelect from '../DragSelect'
2
+ import PubSub from './PubSub'
3
+ import { DSInputElement } from '../types'
4
+ import { DSSettings } from '../stores/SettingsStore'
5
+ import { addModificationObservers } from '../methods/addModificationObservers'
6
+ import { debounce } from '../methods/debounce'
7
+ import { getAllParentNodes } from '../methods/getAllParentNodes'
8
+ import { isCollision } from '../methods/isCollision'
9
+ import { ensureArray } from '../methods/ensureArray'
10
+
11
+ export type DSDropZone<E extends DSInputElement> = {
12
+ id: string
13
+ element: E
14
+ droppables: E[]
15
+ /** items related to the target zone */
16
+ itemsDropped?: E[]
17
+ /** items that are within the targets bounds */
18
+ itemsInside?: E[]
19
+ }
4
20
 
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 }) {
21
+ export default class DropZone<E extends DSInputElement> {
22
+ public id: string
23
+ public element: E
24
+ private _droppables?: E[]
25
+ private _rect?: DOMRect
26
+ private _observers?: { cleanup: () => void }
27
+ private _timeout?: NodeJS.Timeout
28
+ private _itemsDropped: E[] = []
29
+ private _itemsInside?: E[]
30
+ private DS: DragSelect<E>
31
+ private PS: PubSub<E>
32
+ private Settings: DSSettings<E>
33
+ private isDestroyed: boolean = false
34
+ private _parentNodes?: Node[]
35
+
36
+ constructor({
37
+ DS,
38
+ PS,
39
+ id,
40
+ element,
41
+ droppables,
42
+ }: {
43
+ DS: DragSelect<E>
44
+ PS: PubSub<E>
45
+ id: string
46
+ element: E
47
+ droppables?: E[]
48
+ }) {
69
49
  this.DS = DS
70
- this.Settings = DS.stores.SettingsStore.s
71
-
50
+ this.PS = PS
51
+ this.Settings = this.DS.stores.SettingsStore.s
72
52
  this.id = id
73
53
  this.element = element
74
- if (droppables) this.droppables = toArray(droppables)
54
+ if (droppables) this.droppables = ensureArray(droppables)
75
55
  this.element.classList.add(`${this.Settings.dropZoneClass}`)
76
56
 
77
- // @ts-ignore: @todo: update to typescript
78
- this.DS.subscribe('Settings:updated:dropZoneClass', ({ settings }) => {
57
+ this.PS.subscribe('Settings:updated:dropZoneClass', ({ settings }) => {
79
58
  if (!this.element) return
80
59
  this.element.classList.remove(settings['dropZoneClass:pre'])
81
60
  this.element.classList.add(settings.dropZoneClass)
@@ -83,17 +62,14 @@ export default class DropZone {
83
62
 
84
63
  this._observers = addModificationObservers(
85
64
  this.parentNodes,
86
- debounce(() => (this._rect = null), this.Settings.refreshMemoryRate)
65
+ debounce(() => (this._rect = undefined), this.Settings.refreshMemoryRate)
87
66
  )
88
67
 
89
- this.DS.subscribe('Interaction:start', this.start)
90
- this.DS.subscribe('Interaction:end', this.stop)
68
+ this.PS.subscribe('Interaction:start', this.start)
69
+ this.PS.subscribe('Interaction:end', this.stop)
91
70
  }
92
71
 
93
- /**
94
- * @param {'add'|'remove'} action
95
- */
96
- setReadyClasses = (action) => {
72
+ private setReadyClasses = (action: 'add' | 'remove') => {
97
73
  if (this.isDestroyed) return
98
74
  const selectedEls = this.droppables.filter((el) =>
99
75
  this.DS.SelectedSet.has(el)
@@ -106,10 +82,8 @@ export default class DropZone {
106
82
  this.element.classList[action](`${this.Settings.dropZoneReadyClass}`)
107
83
  }
108
84
 
109
- /**
110
- * This zone is NOT the target of a drop
111
- */
112
- handleNoDrop = () => {
85
+ /** This zone is NOT the target of a drop */
86
+ public handleNoDrop = () => {
113
87
  if (this.isDestroyed) return
114
88
  // for each selected element that is not part of the target zone, remove the classes
115
89
  this.DS.SelectedSet.forEach((item) => {
@@ -125,13 +99,10 @@ export default class DropZone {
125
99
  this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
126
100
  }
127
101
 
128
- /**
129
- * This zone IS the target of a drop
130
- */
131
- handleDrop = () => {
102
+ /** This zone IS the target of a drop */
103
+ public handleDrop = () => {
132
104
  if (this.isDestroyed) return
133
105
  this._itemsDropped = [
134
- // @ts-ignore
135
106
  ...new Set([
136
107
  ...this._itemsDropped,
137
108
  ...this.droppables?.filter((item) => this.DS.SelectedSet.has(item)),
@@ -147,10 +118,10 @@ export default class DropZone {
147
118
  this.element.classList.add(`${this.Settings.dropZoneTargetClass}`)
148
119
  }
149
120
 
150
- handleItemsInsideClasses = () => {
121
+ public handleItemsInsideClasses = () => {
151
122
  let isAnyInside = false
152
123
  this.droppables.forEach((item) => {
153
- if (this.itemsInside.includes(item)) {
124
+ if (this.itemsInside?.includes(item)) {
154
125
  item.classList.add(`${this.Settings.droppedInsideClass}`)
155
126
  item.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`)
156
127
  isAnyInside = true
@@ -166,19 +137,19 @@ export default class DropZone {
166
137
  else this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)
167
138
  }
168
139
 
169
- start = ({ isDragging }) => {
140
+ private start = ({ isDragging }: { isDragging: boolean }) => {
170
141
  if (!isDragging || this.isDestroyed) return
171
142
  this.setReadyClasses('add')
172
143
  }
173
144
 
174
- stop = ({ isDragging }) => {
145
+ private stop = ({ isDragging }: { isDragging: boolean }) => {
175
146
  if (!isDragging || this.isDestroyed) return
176
147
  this.setReadyClasses('remove')
177
148
  this.handleItemsInsideClasses()
178
149
  }
179
150
 
180
- destroy() {
181
- this._observers.cleanup()
151
+ public destroy() {
152
+ this._observers?.cleanup()
182
153
  this.element.classList.remove(`${this.Settings.dropZoneClass}`)
183
154
  this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
184
155
  this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`)
@@ -188,20 +159,12 @@ export default class DropZone {
188
159
  item.classList.remove(`${this.Settings.droppableClass}`)
189
160
  item.classList.remove(`${this.Settings.droppableClass}-${this.id}`)
190
161
  })
191
- this.DS.unsubscribe('Interaction:start', this.start)
192
- this.DS.unsubscribe('Interaction:end', this.stop)
193
- this.element = null
194
- this.droppables = null
195
- this.id = null
196
- this._itemsDropped = null
197
- this._itemsInside = null
162
+ this.PS.unsubscribe('Interaction:start', this.start)
163
+ this.PS.unsubscribe('Interaction:end', this.stop)
198
164
  this.isDestroyed = true
199
165
  }
200
166
 
201
- /**
202
- * @returns {DSDropZone}
203
- */
204
- toObject = () => ({
167
+ public toObject = (): DSDropZone<E> => ({
205
168
  id: this.id,
206
169
  element: this.element,
207
170
  droppables: this.droppables,
@@ -209,28 +172,26 @@ export default class DropZone {
209
172
  itemsInside: this.itemsInside,
210
173
  })
211
174
 
212
- get rect() {
213
- if (this.isDestroyed) return null
175
+ public get rect() {
176
+ if (this.isDestroyed) return undefined
214
177
  if (this._rect) return this._rect
215
178
  return (this._rect = this.element.getBoundingClientRect())
216
179
  }
217
180
 
218
- get itemsDropped() {
219
- if (this.isDestroyed) return null
181
+ public get itemsDropped() {
182
+ if (this.isDestroyed) return undefined
220
183
  return this._itemsDropped
221
184
  }
222
185
 
223
- get itemsInside() {
224
- if (this.isDestroyed) return null
186
+ public get itemsInside() {
187
+ if (this.isDestroyed) return undefined
225
188
  if (this._itemsInside) return this._itemsInside
226
189
 
227
190
  this._itemsInside = this.droppables.flatMap((item) => {
191
+ const itemRect = this.DS.SelectableSet.rects.get(item)
228
192
  if (
229
- isCollision(
230
- this.DS.SelectableSet.rects.get(item),
231
- this.rect,
232
- this.Settings.dropInsideThreshold
233
- )
193
+ this.rect &&
194
+ isCollision(itemRect, this.rect, this.Settings.dropInsideThreshold)
234
195
  )
235
196
  return [item]
236
197
  return []
@@ -239,24 +200,24 @@ export default class DropZone {
239
200
  // since elements can be moved while this getter is called, we need to update the values every X seconds
240
201
  if (this._timeout) clearTimeout(this._timeout)
241
202
  this._timeout = setTimeout(
242
- () => (this._itemsInside = null),
203
+ () => (this._itemsInside = undefined),
243
204
  this.Settings.refreshMemoryRate
244
205
  )
245
206
 
246
207
  return this._itemsInside
247
208
  }
248
209
 
249
- get parentNodes() {
210
+ private get parentNodes() {
250
211
  if (this._parentNodes) return this._parentNodes
251
212
  return (this._parentNodes = getAllParentNodes(this.element))
252
213
  }
253
214
 
254
- get droppables() {
215
+ public get droppables() {
255
216
  if (this._droppables) return this._droppables
256
217
  return this.DS.SelectableSet.elements
257
218
  }
258
219
 
259
- set droppables(value) {
220
+ private set droppables(value) {
260
221
  this._droppables = value
261
222
  }
262
223
  }
@@ -0,0 +1,151 @@
1
+ import DragSelect from '../DragSelect'
2
+ import DropZone from './DropZone'
3
+ import PubSub, { DSCallback } from './PubSub'
4
+ import { DSInputDropZone, DSInputElement, Vect2 } from '../types'
5
+ import { DSSettings } from '../stores/SettingsStore'
6
+ import { isCollision } from '../methods/isCollision'
7
+ import { DSInteractionPublishEventData, InteractionEvent } from './Interaction'
8
+
9
+ export default class DropZones<E extends DSInputElement> {
10
+ /** Get the drop zone by the zone element */
11
+ private _zoneByElement: Map<Element, DropZone<E>> = new Map()
12
+ /** Get the drop zone by the zone id */
13
+ private _zoneById: Map<string, DropZone<E>> = new Map()
14
+ /** Get the drop zones by one zone item */
15
+ private _zonesByDroppable: Map<E, DropZone<E>[]> = new Map()
16
+ /** Get the drop zones by one zone item */
17
+ private _zones?: DropZone<E>[]
18
+ private DS: DragSelect<E>
19
+ private PS: PubSub<E>
20
+ private Settings: DSSettings<E>
21
+
22
+ constructor({ DS, PS }: { DS: DragSelect<E>; PS: PubSub<E> }) {
23
+ this.DS = DS
24
+ this.PS = PS
25
+ this.Settings = this.DS.stores.SettingsStore.s
26
+
27
+ this.PS.subscribe('Settings:updated:dropZones', ({ settings }) =>
28
+ this.setDropZones(settings)
29
+ )
30
+ this.setDropZones({ dropZones: this.Settings.dropZones })
31
+ this.PS.subscribe('Interaction:end', this.stop)
32
+ }
33
+
34
+ private setDropZones = ({
35
+ dropZones,
36
+ }: {
37
+ dropZones: DSInputDropZone<E>[]
38
+ }) => {
39
+ if (!dropZones) return
40
+ if (this._zones) this._zones.forEach((zone) => zone.destroy())
41
+
42
+ this._zones = dropZones.map(
43
+ (zone) => new DropZone({ DS: this.DS, PS: this.PS, ...zone })
44
+ )
45
+ this._zones.forEach((zone) => {
46
+ this._zoneByElement.set(zone.element, zone)
47
+ this._zoneById.set(zone.id, zone)
48
+ zone.droppables.forEach((droppable) => {
49
+ const zones = this._zonesByDroppable.get(droppable)
50
+ if (!zones?.length) return this._zonesByDroppable.set(droppable, [zone])
51
+ this._zonesByDroppable.set(droppable, [...new Set([...zones, zone])])
52
+ })
53
+ })
54
+ }
55
+
56
+ private _handleDrops = (target?: DropZone<E>) => {
57
+ this._zones?.forEach((zone) => {
58
+ if (zone !== target) zone.handleNoDrop()
59
+ })
60
+ if (!target) return
61
+ target.handleDrop()
62
+ }
63
+
64
+ private _getZoneByElementsFromPoint = (
65
+ elements: Element[],
66
+ { x, y }: Vect2
67
+ ) => {
68
+ for (let i = 0, il = elements.length; i < il; i++) {
69
+ const zone = this._zoneByElement.get(elements[i])
70
+ if (
71
+ isCollision(
72
+ zone?.rect,
73
+ { left: x, right: x, top: y, bottom: y },
74
+ Math.min(this.Settings.dropTargetThreshold, 0.5)
75
+ )
76
+ )
77
+ return zone
78
+ }
79
+ }
80
+
81
+ private stop: DSCallback<DSInteractionPublishEventData> = ({
82
+ isDragging,
83
+ isDraggingKeyboard,
84
+ event,
85
+ }) => {
86
+ if (!isDragging) return
87
+ const target = this.getTarget({ isDraggingKeyboard, event })
88
+ this._handleDrops(target)
89
+ }
90
+
91
+ /// ///////////////////////////////////////////////////////////////////////////////////
92
+ // Getters
93
+
94
+ public getItemsDroppedById = (zoneId: string) => {
95
+ const zone = this._zoneById.get(zoneId)
96
+ if (!zone) return console.warn(`[DragSelect] No zone found (id: ${zoneId})`)
97
+ return zone.itemsDropped
98
+ }
99
+
100
+ public getItemsInsideById = (zoneId: string, addClasses?: boolean) => {
101
+ const zone = this._zoneById.get(zoneId)
102
+ if (!zone) return console.warn(`[DragSelect] No zone found (id: ${zoneId})`)
103
+ if (addClasses) zone.handleItemsInsideClasses()
104
+ return zone.itemsInside
105
+ }
106
+
107
+ private getKeyboardItemCenter = (
108
+ isDraggingKeyboard?: boolean,
109
+ event?: InteractionEvent | KeyboardEvent
110
+ ) => {
111
+ if (!isDraggingKeyboard || !event) return
112
+ const rect = (event.target as DSInputElement)?.getBoundingClientRect()
113
+ // center of rect
114
+ const x = rect.left + rect.width / 2
115
+ const y = rect.top + rect.height / 2
116
+ return { x, y }
117
+ }
118
+
119
+ /** Returns first DropsZone under current pointer or coordinates if passed */
120
+ public getTarget = ({
121
+ coordinates,
122
+ isDraggingKeyboard,
123
+ event,
124
+ }: {
125
+ coordinates?: Vect2
126
+ isDraggingKeyboard?: boolean
127
+ event?: InteractionEvent | KeyboardEvent
128
+ }) => {
129
+ if (!this._zones?.length) return
130
+
131
+ let keyboardCoordinates: Vect2 | undefined
132
+ if (!coordinates && isDraggingKeyboard && event) {
133
+ keyboardCoordinates = this.getKeyboardItemCenter(
134
+ isDraggingKeyboard,
135
+ event
136
+ )
137
+ }
138
+
139
+ const x =
140
+ coordinates?.x ||
141
+ keyboardCoordinates?.x ||
142
+ this.DS.stores.PointerStore.currentVal.x
143
+ const y =
144
+ coordinates?.y ||
145
+ keyboardCoordinates?.y ||
146
+ this.DS.stores.PointerStore.currentVal.y
147
+
148
+ const elements = document.elementsFromPoint(x, y)
149
+ return this._getZoneByElementsFromPoint(elements, { x, y })
150
+ }
151
+ }