dragselect 3.0.2 → 3.0.4

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 (53) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +1 -1
  3. package/dist/{DragSelect.es6m.js → DragSelect.esm.js} +11 -4
  4. package/dist/DragSelect.js +11 -4
  5. package/dist/{ds.es6m.min.js → ds.esm.min.js} +1 -1
  6. package/dist/ds.min.js +1 -1
  7. package/package.json +3 -3
  8. package/src/DragSelect.ts +0 -425
  9. package/src/methods/addModificationObservers.ts +0 -51
  10. package/src/methods/canScroll.ts +0 -19
  11. package/src/methods/createSelectorAreaElement.ts +0 -8
  12. package/src/methods/createSelectorElement.ts +0 -13
  13. package/src/methods/debounce.ts +0 -31
  14. package/src/methods/ensureArray.ts +0 -13
  15. package/src/methods/getAllParentNodes.ts +0 -15
  16. package/src/methods/getAreaRect.ts +0 -27
  17. package/src/methods/getCurrentScroll.ts +0 -14
  18. package/src/methods/getDocumentScroll.ts +0 -5
  19. package/src/methods/getOverflowEdges.ts +0 -27
  20. package/src/methods/getPointerPos.ts +0 -9
  21. package/src/methods/getSelectionRect.ts +0 -29
  22. package/src/methods/getSelectorPosition.ts +0 -74
  23. package/src/methods/getStylePosition.spec.ts +0 -114
  24. package/src/methods/getStylePosition.ts +0 -83
  25. package/src/methods/handleElementPositionAttribute.ts +0 -15
  26. package/src/methods/handleKeyboardDragPosDifference.ts +0 -35
  27. package/src/methods/handleSelection.ts +0 -26
  28. package/src/methods/handleUnSelection.ts +0 -36
  29. package/src/methods/hydrateSettings.ts +0 -245
  30. package/src/methods/isCollision.ts +0 -66
  31. package/src/methods/limitDirection.ts +0 -36
  32. package/src/methods/moveElement.ts +0 -18
  33. package/src/methods/scrollElement.ts +0 -26
  34. package/src/methods/setStylePosition.ts +0 -16
  35. package/src/methods/subscriberAliases.ts +0 -240
  36. package/src/methods/updateElementStylePos.ts +0 -7
  37. package/src/methods/vect2.ts +0 -34
  38. package/src/modules/Area.ts +0 -169
  39. package/src/modules/Drag.ts +0 -236
  40. package/src/modules/DropZone.ts +0 -223
  41. package/src/modules/DropZones.ts +0 -151
  42. package/src/modules/Interaction.ts +0 -251
  43. package/src/modules/PubSub.ts +0 -111
  44. package/src/modules/SelectableSet.ts +0 -146
  45. package/src/modules/SelectedSet.ts +0 -92
  46. package/src/modules/Selection.ts +0 -133
  47. package/src/modules/Selector.ts +0 -81
  48. package/src/modules/SelectorArea.ts +0 -161
  49. package/src/stores/KeyStore.ts +0 -92
  50. package/src/stores/PointerStore.ts +0 -194
  51. package/src/stores/ScrollStore.ts +0 -87
  52. package/src/stores/SettingsStore.ts +0 -88
  53. package/src/types.ts +0 -158
@@ -1,236 +0,0 @@
1
- import DragSelect from '../DragSelect'
2
- import PubSub from './PubSub'
3
- import { DSBoundingRect, DSDragKeys, DSInputElement, Vect2 } from '../types'
4
- import { DSSettings } from '../stores/SettingsStore'
5
- import { calcVect, num2vect, vect2rect } from '../methods/vect2'
6
- import { handleKeyboardDragPosDifference } from '../methods/handleKeyboardDragPosDifference'
7
- import { moveElement } from '../methods/moveElement'
8
- import { limitDirection } from '../methods/limitDirection'
9
-
10
- export default class Drag<E extends DSInputElement> {
11
- private _prevCursorPos?: Vect2
12
- private _prevScrollPos?: Vect2
13
- private _elements: E[] = []
14
- private _dragKeys?: DSDragKeys
15
- private _dragKeysFlat: string[] = []
16
- private _selectionRect: DSBoundingRect = vect2rect(num2vect(0))
17
- DS: DragSelect<E>
18
- PS: PubSub<E>
19
- Settings: DSSettings<E>
20
-
21
- constructor({ DS, PS }: { DS: DragSelect<E>; PS: PubSub<E> }) {
22
- this.DS = DS
23
- this.PS = PS
24
- this.Settings = this.DS.stores.SettingsStore.s
25
-
26
- this.PS.subscribe('Settings:updated:dragKeys', this.assignDragKeys)
27
- this.assignDragKeys()
28
-
29
- this.PS.subscribe('Interaction:start', this.start)
30
- this.PS.subscribe('Interaction:end', this.stop)
31
- this.PS.subscribe('Interaction:update', this.update)
32
- this.PS.subscribe('KeyStore:down', this.keyboardDrag)
33
- this.PS.subscribe('KeyStore:up', this.keyboardEnd)
34
- }
35
-
36
- private assignDragKeys = () => {
37
- this._dragKeys = {
38
- up: this.Settings.dragKeys.up.map((k) => k.toLowerCase()),
39
- down: this.Settings.dragKeys.down.map((k) => k.toLowerCase()),
40
- left: this.Settings.dragKeys.left.map((k) => k.toLowerCase()),
41
- right: this.Settings.dragKeys.right.map((k) => k.toLowerCase()),
42
- }
43
- this._dragKeysFlat = [
44
- ...this._dragKeys.up,
45
- ...this._dragKeys.down,
46
- ...this._dragKeys.left,
47
- ...this._dragKeys.right,
48
- ]
49
- }
50
-
51
- private keyboardDrag = ({
52
- event,
53
- key,
54
- }: {
55
- event: KeyboardEvent
56
- key: string
57
- }) => {
58
- const _key = key.toLowerCase()
59
- if (
60
- !this.Settings.keyboardDrag ||
61
- !this._dragKeysFlat.includes(_key) ||
62
- !this.DS.SelectedSet.size ||
63
- !this.Settings.draggability ||
64
- this.DS.continue
65
- )
66
- return
67
-
68
- const publishData = {
69
- event,
70
- isDragging: true,
71
- isDraggingKeyboard: true,
72
- key,
73
- }
74
- this.PS.publish(['Interaction:start:pre', 'Interaction:start'], publishData)
75
-
76
- this._elements = this.DS.getSelection()
77
- this._selectionRect = this.DS.Selection.boundingRect
78
- this.handleZIndex(true)
79
-
80
- let posDirection = handleKeyboardDragPosDifference({
81
- shiftKey: this.DS.stores.KeyStore.currentValues.includes('shift'),
82
- keyboardDragSpeed: this.Settings.keyboardDragSpeed,
83
- zoom: this.Settings.zoom,
84
- key: _key,
85
- scrollDiff: this._scrollDiff,
86
- dragKeys: this._dragKeys,
87
- })
88
-
89
- posDirection = limitDirection({
90
- direction: posDirection,
91
- containerRect: this.DS.SelectorArea.rect,
92
- scrollAmount: this.DS.stores.ScrollStore.scrollAmount,
93
- selectionRect: this._selectionRect,
94
- })
95
-
96
- this.moveElements(posDirection)
97
-
98
- this.PS.publish(
99
- ['Interaction:update:pre', 'Interaction:update'],
100
- publishData
101
- )
102
- }
103
-
104
- private keyboardEnd = ({
105
- event,
106
- key,
107
- }: {
108
- event: KeyboardEvent
109
- key: string
110
- }) => {
111
- const _key = key.toLowerCase()
112
- if (
113
- !this.Settings.keyboardDrag ||
114
- !this._dragKeysFlat.includes(_key) ||
115
- !this.DS.SelectedSet.size ||
116
- !this.Settings.draggability
117
- )
118
- return
119
- const publishData = {
120
- event,
121
- isDragging: this.Settings.draggability,
122
- isDraggingKeyboard: true,
123
- key,
124
- }
125
- this.PS.publish(['Interaction:end:pre', 'Interaction:end'], publishData)
126
- }
127
-
128
- private start = ({
129
- isDragging,
130
- isDraggingKeyboard,
131
- }: {
132
- isDragging?: boolean
133
- isDraggingKeyboard?: boolean
134
- }) => {
135
- if (!isDragging || isDraggingKeyboard) return
136
- this._prevCursorPos = undefined
137
- this._prevScrollPos = undefined
138
- this._elements = this.DS.getSelection()
139
- this._selectionRect = this.DS.Selection.boundingRect
140
- this.handleZIndex(true)
141
- }
142
-
143
- public stop = () => {
144
- this._prevCursorPos = undefined
145
- this._prevScrollPos = undefined
146
- this.handleZIndex(false)
147
- this._elements = []
148
- }
149
-
150
- private update = ({
151
- isDragging,
152
- isDraggingKeyboard,
153
- }: {
154
- isDragging?: boolean
155
- isDraggingKeyboard?: boolean
156
- }) => {
157
- if (
158
- !isDragging ||
159
- !this._elements.length ||
160
- isDraggingKeyboard ||
161
- this.DS.continue
162
- )
163
- return
164
-
165
- let posDirection = calcVect(this._cursorDiff, '+', this._scrollDiff)
166
- posDirection = limitDirection({
167
- direction: posDirection,
168
- containerRect: this.DS.SelectorArea.rect,
169
- scrollAmount: this.DS.stores.ScrollStore.scrollAmount,
170
- selectionRect: this._selectionRect,
171
- })
172
-
173
- this.moveElements(posDirection)
174
- }
175
-
176
- private handleZIndex = (add: boolean) => {
177
- this._elements.forEach(
178
- (element) =>
179
- (element.style.zIndex = `${
180
- (parseInt(element.style.zIndex) || 0) + (add ? 9999 : -9998)
181
- }`)
182
- )
183
- }
184
-
185
- private moveElements = (posDirection: Vect2) => {
186
- // [PUBLICLY EXPOSED METHOD]
187
- const { elements, direction } = this.filterDragElements({
188
- elements: this._elements,
189
- direction: posDirection,
190
- })
191
- elements.forEach((element) => {
192
- moveElement({
193
- element,
194
- posDirection: direction,
195
- containerRect: this.DS.SelectorArea.rect,
196
- useTransform: this.Settings.useTransform,
197
- })
198
- })
199
- }
200
-
201
- private get _cursorDiff() {
202
- const currentPointerVal = this.DS.stores.PointerStore.currentVal
203
- const cursorDiff = this._prevCursorPos
204
- ? calcVect(currentPointerVal, '-', this._prevCursorPos)
205
- : { x: 0, y: 0 }
206
- this._prevCursorPos = currentPointerVal
207
- return cursorDiff
208
- }
209
-
210
- private get _scrollDiff() {
211
- const currentScrollVal = this.DS.stores.ScrollStore.currentVal
212
- const scrollDiff = this._prevScrollPos
213
- ? calcVect(currentScrollVal, '-', this._prevScrollPos)
214
- : { x: 0, y: 0 }
215
- this._prevScrollPos = currentScrollVal
216
- return scrollDiff
217
- }
218
-
219
- ////
220
- // [PUBLICLY EXPOSED METHODS]
221
-
222
- /**
223
- * Can be overridden to apply further filtering logic after the items to move are identified but before they actually get moved
224
- * Is expected to return the elements in the same shape as passed in
225
- */
226
- public filterDragElements = ({
227
- elements,
228
- direction,
229
- }: {
230
- elements: E[]
231
- direction: Vect2
232
- }) => ({
233
- elements,
234
- direction,
235
- })
236
- }
@@ -1,223 +0,0 @@
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
- }
20
-
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
- }) {
49
- this.DS = DS
50
- this.PS = PS
51
- this.Settings = this.DS.stores.SettingsStore.s
52
- this.id = id
53
- this.element = element
54
- if (droppables) this.droppables = ensureArray(droppables)
55
- this.element.classList.add(`${this.Settings.dropZoneClass}`)
56
-
57
- this.PS.subscribe('Settings:updated:dropZoneClass', ({ settings }) => {
58
- if (!this.element) return
59
- this.element.classList.remove(settings['dropZoneClass:pre'])
60
- this.element.classList.add(settings.dropZoneClass)
61
- })
62
-
63
- this._observers = addModificationObservers(
64
- this.parentNodes,
65
- debounce(() => (this._rect = undefined), this.Settings.refreshMemoryRate)
66
- )
67
-
68
- this.PS.subscribe('Interaction:start', this.start)
69
- this.PS.subscribe('Interaction:end', this.stop)
70
- }
71
-
72
- private setReadyClasses = (action: 'add' | 'remove') => {
73
- if (this.isDestroyed) return
74
- const selectedEls = this.droppables.filter((el) =>
75
- this.DS.SelectedSet.has(el)
76
- )
77
- if (!selectedEls.length) return
78
- selectedEls.forEach((item) => {
79
- item.classList[action](`${this.Settings.droppableClass}`)
80
- item.classList[action](`${this.Settings.droppableClass}-${this.id}`)
81
- })
82
- this.element.classList[action](`${this.Settings.dropZoneReadyClass}`)
83
- }
84
-
85
- /** This zone is NOT the target of a drop */
86
- public handleNoDrop = () => {
87
- if (this.isDestroyed) return
88
- // for each selected element that is not part of the target zone, remove the classes
89
- this.DS.SelectedSet.forEach((item) => {
90
- item.classList.remove(this.Settings.droppedTargetClass)
91
- item.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)
92
- })
93
- // and remove them from the zones dropped items
94
- this._itemsDropped = this._itemsDropped.filter(
95
- (item) => !this.DS.SelectedSet.has(item)
96
- )
97
- // if the zone has no dropped left, also remove the zones class
98
- if (!this._itemsDropped?.length)
99
- this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
100
- }
101
-
102
- /** This zone IS the target of a drop */
103
- public handleDrop = () => {
104
- if (this.isDestroyed) return
105
- this._itemsDropped = [
106
- ...new Set([
107
- ...this._itemsDropped,
108
- ...this.droppables?.filter((item) => this.DS.SelectedSet.has(item)),
109
- ]),
110
- ]
111
- // add the target class to the zones dropped items
112
- this._itemsDropped?.forEach((item) => {
113
- item.classList.add(`${this.Settings.droppedTargetClass}`)
114
- item.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)
115
- })
116
- // if the zone has dropped, add the zones class
117
- if (this._itemsDropped?.length)
118
- this.element.classList.add(`${this.Settings.dropZoneTargetClass}`)
119
- }
120
-
121
- public handleItemsInsideClasses = () => {
122
- let isAnyInside = false
123
- this.droppables.forEach((item) => {
124
- if (this.itemsInside?.includes(item)) {
125
- item.classList.add(`${this.Settings.droppedInsideClass}`)
126
- item.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`)
127
- isAnyInside = true
128
- } else {
129
- item.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`)
130
- if (!item.className.includes(`${this.Settings.droppedInsideClass}-`))
131
- item.classList.remove(`${this.Settings.droppedInsideClass}`)
132
- }
133
- })
134
-
135
- if (isAnyInside)
136
- this.element.classList.add(`${this.Settings.dropZoneInsideClass}`)
137
- else this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)
138
- }
139
-
140
- private start = ({ isDragging }: { isDragging: boolean }) => {
141
- if (!isDragging || this.isDestroyed) return
142
- this.setReadyClasses('add')
143
- }
144
-
145
- private stop = ({ isDragging }: { isDragging: boolean }) => {
146
- if (!isDragging || this.isDestroyed) return
147
- this.setReadyClasses('remove')
148
- this.handleItemsInsideClasses()
149
- }
150
-
151
- public destroy() {
152
- this._observers?.cleanup()
153
- this.element.classList.remove(`${this.Settings.dropZoneClass}`)
154
- this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
155
- this.element.classList.remove(`${this.Settings.dropZoneReadyClass}`)
156
- this.droppables.forEach((item) => {
157
- item.classList.remove(`${this.Settings.droppedTargetClass}`)
158
- item.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)
159
- item.classList.remove(`${this.Settings.droppableClass}`)
160
- item.classList.remove(`${this.Settings.droppableClass}-${this.id}`)
161
- })
162
- this.PS.unsubscribe('Interaction:start', this.start)
163
- this.PS.unsubscribe('Interaction:end', this.stop)
164
- this.isDestroyed = true
165
- }
166
-
167
- public toObject = (): DSDropZone<E> => ({
168
- id: this.id,
169
- element: this.element,
170
- droppables: this.droppables,
171
- itemsDropped: this.itemsDropped,
172
- itemsInside: this.itemsInside,
173
- })
174
-
175
- public get rect() {
176
- if (this.isDestroyed) return undefined
177
- if (this._rect) return this._rect
178
- return (this._rect = this.element.getBoundingClientRect())
179
- }
180
-
181
- public get itemsDropped() {
182
- if (this.isDestroyed) return undefined
183
- return this._itemsDropped
184
- }
185
-
186
- public get itemsInside() {
187
- if (this.isDestroyed) return undefined
188
- if (this._itemsInside) return this._itemsInside
189
-
190
- this._itemsInside = this.droppables.flatMap((item) => {
191
- const itemRect = this.DS.SelectableSet.rects.get(item)
192
- if (
193
- this.rect &&
194
- isCollision(itemRect, this.rect, this.Settings.dropInsideThreshold)
195
- )
196
- return [item]
197
- return []
198
- })
199
-
200
- // since elements can be moved while this getter is called, we need to update the values every X seconds
201
- if (this._timeout) clearTimeout(this._timeout)
202
- this._timeout = setTimeout(
203
- () => (this._itemsInside = undefined),
204
- this.Settings.refreshMemoryRate
205
- )
206
-
207
- return this._itemsInside
208
- }
209
-
210
- private get parentNodes() {
211
- if (this._parentNodes) return this._parentNodes
212
- return (this._parentNodes = getAllParentNodes(this.element))
213
- }
214
-
215
- public get droppables() {
216
- if (this._droppables) return this._droppables
217
- return this.DS.SelectableSet.elements
218
- }
219
-
220
- private set droppables(value) {
221
- this._droppables = value
222
- }
223
- }
@@ -1,151 +0,0 @@
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
- }