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.
- package/CHANGELOG.md +100 -22
- package/LICENSE +690 -0
- package/README.md +2 -1
- package/jest-puppeteer.config.js +13 -3
- package/jest.config.js +5 -0
- package/package.json +40 -46
- package/rollup.config.mjs +82 -0
- package/src/DragSelect.ts +425 -0
- package/src/methods/addModificationObservers.ts +51 -0
- package/src/methods/canScroll.ts +19 -0
- package/src/methods/{createSelectorAreaElement.js → createSelectorAreaElement.ts} +1 -8
- package/src/methods/{createSelectorElement.js → createSelectorElement.ts} +1 -9
- package/src/methods/{debounce.js → debounce.ts} +5 -11
- package/src/methods/ensureArray.ts +13 -0
- package/src/methods/getAllParentNodes.ts +15 -0
- package/src/methods/{getAreaRect.js → getAreaRect.ts} +2 -6
- package/src/methods/getCurrentScroll.ts +14 -0
- package/src/methods/{documentScroll.js → getDocumentScroll.ts} +2 -2
- package/src/methods/{getOverflowEdges.js → getOverflowEdges.ts} +11 -11
- package/src/methods/getPointerPos.ts +9 -0
- package/src/methods/getSelectionRect.ts +29 -0
- package/src/methods/{getSelectorPosition.js → getSelectorPosition.ts} +11 -9
- package/src/methods/{getStylePosition.spec.js → getStylePosition.spec.ts} +9 -9
- package/src/methods/{getStylePosition.js → getStylePosition.ts} +5 -21
- package/src/methods/handleElementPositionAttribute.ts +15 -0
- package/src/methods/handleKeyboardDragPosDifference.ts +35 -0
- package/src/methods/handleSelection.ts +26 -0
- package/src/methods/{handleUnSelection.js → handleUnSelection.ts} +14 -14
- package/src/methods/{hydrateSettings.js → hydrateSettings.ts} +15 -26
- package/src/methods/isCollision.ts +66 -0
- package/src/methods/limitDirection.ts +36 -0
- package/src/methods/moveElement.ts +18 -0
- package/src/methods/{scrollElement.js → scrollElement.ts} +4 -10
- package/src/methods/{setStylePosition.js → setStylePosition.ts} +3 -11
- package/src/methods/subscriberAliases.ts +240 -0
- package/src/methods/updateElementStylePos.ts +7 -0
- package/src/methods/vect2.ts +34 -0
- package/src/modules/Area.ts +169 -0
- package/src/modules/Drag.ts +236 -0
- package/src/modules/{DropZone.js → DropZone.ts} +80 -119
- package/src/modules/DropZones.ts +151 -0
- package/src/modules/Interaction.ts +251 -0
- package/src/modules/PubSub.ts +111 -0
- package/src/modules/SelectableSet.ts +146 -0
- package/src/modules/SelectedSet.ts +92 -0
- package/src/modules/{Selection.js → Selection.ts} +59 -44
- package/src/modules/Selector.ts +81 -0
- package/src/modules/{SelectorArea.js → SelectorArea.ts} +58 -71
- package/src/stores/KeyStore.ts +92 -0
- package/src/stores/PointerStore.ts +194 -0
- package/src/stores/ScrollStore.ts +87 -0
- package/src/stores/SettingsStore.ts +88 -0
- package/src/types.ts +158 -0
- package/tsconfig.json +105 -0
- package/bower.json +0 -24
- package/dist/DragSelect.d.ts +0 -200
- package/dist/DragSelect.es6m.js +0 -3877
- package/dist/DragSelect.js +0 -3885
- package/dist/ds.es6m.min.js +0 -1
- package/dist/ds.min.js +0 -1
- package/dist/methods/addModificationObservers.d.ts +0 -11
- package/dist/methods/canScroll.d.ts +0 -3
- package/dist/methods/createSelectorAreaElement.d.ts +0 -3
- package/dist/methods/createSelectorElement.d.ts +0 -3
- package/dist/methods/debounce.d.ts +0 -3
- package/dist/methods/documentScroll.d.ts +0 -6
- package/dist/methods/getAllParentNodes.d.ts +0 -3
- package/dist/methods/getAreaRect.d.ts +0 -3
- package/dist/methods/getBoundingClientRect.d.ts +0 -4
- package/dist/methods/getCurrentScroll.d.ts +0 -3
- package/dist/methods/getOverflowEdges.d.ts +0 -7
- package/dist/methods/getPointerPos.d.ts +0 -5
- package/dist/methods/getSelectorPosition.d.ts +0 -12
- package/dist/methods/getStylePosition.d.ts +0 -3
- package/dist/methods/handleElementOverflow.d.ts +0 -10
- package/dist/methods/handleElementPositionAttribute.d.ts +0 -6
- package/dist/methods/handleKeyboardDragPosDifference.d.ts +0 -13
- package/dist/methods/handleSelection.d.ts +0 -9
- package/dist/methods/handleUnSelection.d.ts +0 -9
- package/dist/methods/hydrateSettings.d.ts +0 -3
- package/dist/methods/index.d.ts +0 -30
- package/dist/methods/isCollision.d.ts +0 -13
- package/dist/methods/moveElement.d.ts +0 -8
- package/dist/methods/removeModificationObservers.d.ts +0 -3
- package/dist/methods/scrollElement.d.ts +0 -3
- package/dist/methods/setStylePosition.d.ts +0 -3
- package/dist/methods/subscriberAliases.d.ts +0 -14
- package/dist/methods/toArray.d.ts +0 -3
- package/dist/methods/updateElementStylePos.d.ts +0 -8
- package/dist/methods/vect2.d.ts +0 -8
- package/dist/modules/Area.d.ts +0 -80
- package/dist/modules/Drag.d.ts +0 -71
- package/dist/modules/DropZone.d.ts +0 -90
- package/dist/modules/DropZones.d.ts +0 -73
- package/dist/modules/Interaction.d.ts +0 -51
- package/dist/modules/PubSub.d.ts +0 -37
- package/dist/modules/SelectableSet.d.ts +0 -40
- package/dist/modules/SelectedSet.d.ts +0 -29
- package/dist/modules/Selection.d.ts +0 -54
- package/dist/modules/Selector.d.ts +0 -29
- package/dist/modules/SelectorArea.d.ts +0 -58
- package/dist/modules/index.d.ts +0 -11
- package/dist/stores/KeyStore.d.ts +0 -34
- package/dist/stores/PointerStore.d.ts +0 -83
- package/dist/stores/ScrollStore.d.ts +0 -38
- package/dist/stores/SettingsStore.d.ts +0 -39
- package/dist/stores/index.d.ts +0 -5
- package/dist/types.d.ts +0 -276
- package/jsconfig.json +0 -13
- package/rollup.config.js +0 -101
- package/src/DragSelect.js +0 -384
- package/src/methods/addModificationObservers.js +0 -38
- package/src/methods/canScroll.js +0 -20
- package/src/methods/getAllParentNodes.js +0 -17
- package/src/methods/getBoundingClientRect.js +0 -33
- package/src/methods/getCurrentScroll.js +0 -15
- package/src/methods/getPointerPos.js +0 -13
- package/src/methods/handleElementOverflow.js +0 -65
- package/src/methods/handleElementPositionAttribute.js +0 -16
- package/src/methods/handleKeyboardDragPosDifference.js +0 -57
- package/src/methods/handleSelection.js +0 -26
- package/src/methods/index.js +0 -29
- package/src/methods/isCollision.js +0 -58
- package/src/methods/moveElement.js +0 -39
- package/src/methods/removeModificationObservers.js +0 -13
- package/src/methods/subscriberAliases.js +0 -72
- package/src/methods/toArray.js +0 -18
- package/src/methods/updateElementStylePos.js +0 -15
- package/src/methods/vect2.js +0 -54
- package/src/modules/Area.js +0 -183
- package/src/modules/Drag.js +0 -257
- package/src/modules/DropZones.js +0 -161
- package/src/modules/Interaction.js +0 -208
- package/src/modules/PubSub.js +0 -78
- package/src/modules/SelectableSet.js +0 -144
- package/src/modules/SelectedSet.js +0 -69
- package/src/modules/Selector.js +0 -90
- package/src/modules/index.js +0 -10
- package/src/stores/KeyStore.js +0 -83
- package/src/stores/PointerStore.js +0 -218
- package/src/stores/ScrollStore.js +0 -92
- package/src/stores/SettingsStore.js +0 -66
- package/src/stores/index.js +0 -4
- package/src/types.js +0 -100
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import DragSelect from '../DragSelect'
|
|
4
|
-
|
|
5
|
-
import { toArray, handleElementPositionAttribute } from '../methods'
|
|
6
|
-
|
|
7
|
-
export default class SelectableSet extends Set {
|
|
8
|
-
/**
|
|
9
|
-
* @type {Map<DSElement,DSBoundingRect>}
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
_rects
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @type {NodeJS.Timeout}
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
_timeout
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @constructor SelectableSet
|
|
22
|
-
* @param {{DS:DragSelect}} obj
|
|
23
|
-
* @ignore
|
|
24
|
-
*/
|
|
25
|
-
constructor({ DS }) {
|
|
26
|
-
super()
|
|
27
|
-
this.DS = DS
|
|
28
|
-
this.Settings = DS.stores.SettingsStore.s
|
|
29
|
-
this.DS.subscribe('Interaction:init', this.init)
|
|
30
|
-
// @ts-ignore: @todo: update to typescript
|
|
31
|
-
this.DS.PubSub.subscribe('Settings:updated:selectables', () => {
|
|
32
|
-
this.clear()
|
|
33
|
-
this.init()
|
|
34
|
-
})
|
|
35
|
-
// @ts-ignore: @todo: update to typescript
|
|
36
|
-
this.DS.subscribe('Settings:updated:selectableClass', ({ settings }) => {
|
|
37
|
-
this.forEach((el) => {
|
|
38
|
-
el.classList.remove(settings['selectableClass:pre'])
|
|
39
|
-
el.classList.add(settings.selectableClass)
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
init = () => toArray(this.Settings.selectables).forEach((el) => this.add(el))
|
|
45
|
-
|
|
46
|
-
/** @param {DSElement} element */
|
|
47
|
-
add(element) {
|
|
48
|
-
if (super.has(element)) return
|
|
49
|
-
const publishData = {
|
|
50
|
-
items: this.elements,
|
|
51
|
-
item: element,
|
|
52
|
-
}
|
|
53
|
-
this.DS.publish('Selectable:added:pre', publishData)
|
|
54
|
-
element.classList.add(this.Settings.selectableClass)
|
|
55
|
-
element.addEventListener('click', this._onClick)
|
|
56
|
-
|
|
57
|
-
if (this.Settings.usePointerEvents)
|
|
58
|
-
element.addEventListener('pointerdown', this._onPointer, {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
passive: false,
|
|
61
|
-
})
|
|
62
|
-
else element.addEventListener('mousedown', this._onPointer)
|
|
63
|
-
|
|
64
|
-
element.addEventListener('touchstart', this._onPointer, {
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
passive: false,
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if (this.Settings.draggability && !this.Settings.useTransform)
|
|
70
|
-
handleElementPositionAttribute({
|
|
71
|
-
computedStyle: window.getComputedStyle(element),
|
|
72
|
-
node: element,
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
this.DS.publish('Selectable:added', publishData)
|
|
76
|
-
return super.add(element)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** @param {DSElement} element */
|
|
80
|
-
delete(element) {
|
|
81
|
-
if (!super.has(element)) return
|
|
82
|
-
const publishData = {
|
|
83
|
-
items: this.elements,
|
|
84
|
-
item: element,
|
|
85
|
-
}
|
|
86
|
-
this.DS.publish('Selectable:removed:pre', publishData)
|
|
87
|
-
element.classList.remove(this.Settings.selectableClass)
|
|
88
|
-
element.classList.remove(this.Settings.hoverClass)
|
|
89
|
-
element.removeEventListener('click', this._onClick)
|
|
90
|
-
|
|
91
|
-
if (this.Settings.usePointerEvents)
|
|
92
|
-
element.removeEventListener('pointerdown', this._onPointer, {
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
passive: false,
|
|
95
|
-
})
|
|
96
|
-
else element.removeEventListener('mousedown', this._onPointer)
|
|
97
|
-
|
|
98
|
-
element.removeEventListener('touchstart', this._onPointer, {
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
passive: false,
|
|
101
|
-
})
|
|
102
|
-
this.DS.publish('Selectable:removed', publishData)
|
|
103
|
-
return super.delete(element)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
clear = () => this.forEach((el) => this.delete(el))
|
|
107
|
-
|
|
108
|
-
_onClick = (event) =>
|
|
109
|
-
this.DS.publish(['Selectable:click:pre', 'Selectable:click'], { event })
|
|
110
|
-
|
|
111
|
-
_onPointer = (event) =>
|
|
112
|
-
this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], { event })
|
|
113
|
-
|
|
114
|
-
/** @param {DSElements} elements */
|
|
115
|
-
addAll = (elements) => elements.forEach((el) => this.add(el))
|
|
116
|
-
|
|
117
|
-
/** @param {DSElements} elements */
|
|
118
|
-
deleteAll = (elements) => elements.forEach((el) => this.delete(el))
|
|
119
|
-
|
|
120
|
-
/** @param {DSElement} element */
|
|
121
|
-
getRect = (element) => this._rects ? this.rects.get(element) : element.getBoundingClientRect()
|
|
122
|
-
|
|
123
|
-
/** @return {DSElements} */
|
|
124
|
-
get elements() {
|
|
125
|
-
return Array.from(this.values())
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
get rects() {
|
|
129
|
-
if (this._rects) return this._rects
|
|
130
|
-
this._rects = new Map()
|
|
131
|
-
this.forEach((element) =>
|
|
132
|
-
this._rects.set(element, element.getBoundingClientRect())
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
// since elements can be moved, we need to update the rects every X ms
|
|
136
|
-
if (this._timeout) clearTimeout(this._timeout)
|
|
137
|
-
this._timeout = setTimeout(
|
|
138
|
-
() => (this._rects = null),
|
|
139
|
-
this.Settings.refreshMemoryRate
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
return this._rects
|
|
143
|
-
}
|
|
144
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import DragSelect from '../DragSelect'
|
|
4
|
-
|
|
5
|
-
export default class SelectedSet extends Set {
|
|
6
|
-
/**
|
|
7
|
-
* @constructor SelectableSet
|
|
8
|
-
* @param {{DS:DragSelect}} obj
|
|
9
|
-
* @ignore
|
|
10
|
-
*/
|
|
11
|
-
constructor({ DS }) {
|
|
12
|
-
super()
|
|
13
|
-
this.DS = DS
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** @param {DSElement} element */
|
|
17
|
-
add(element) {
|
|
18
|
-
if (super.has(element)) return
|
|
19
|
-
const publishData = {
|
|
20
|
-
items: this.elements,
|
|
21
|
-
item: element,
|
|
22
|
-
}
|
|
23
|
-
this.DS.publish('Selected:added:pre', publishData)
|
|
24
|
-
super.add(element)
|
|
25
|
-
element.classList.add(this.DS.stores.SettingsStore.s.selectedClass)
|
|
26
|
-
element.style.zIndex = `${(parseInt(element.style.zIndex) || 0) + 1}`
|
|
27
|
-
this.DS.publish('Selected:added', publishData)
|
|
28
|
-
return this
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** @param {DSElement} element */
|
|
32
|
-
delete(element) {
|
|
33
|
-
if (!super.has(element)) return
|
|
34
|
-
const publishData = {
|
|
35
|
-
items: this.elements,
|
|
36
|
-
item: element,
|
|
37
|
-
}
|
|
38
|
-
this.DS.publish('Selected:removed:pre', publishData)
|
|
39
|
-
const deleted = super.delete(element)
|
|
40
|
-
element.classList.remove(this.DS.stores.SettingsStore.s.selectedClass)
|
|
41
|
-
element.style.zIndex = `${(parseInt(element.style.zIndex) || 0) - 1}`
|
|
42
|
-
this.DS.publish('Selected:removed', publishData)
|
|
43
|
-
return deleted
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
clear = () => this.forEach((el) => this.delete(el))
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Adds/Removes an element. If it is already selected = remove, if not = add.
|
|
50
|
-
* @param {DSElement} element
|
|
51
|
-
* @return {DSElement}
|
|
52
|
-
*/
|
|
53
|
-
toggle(element) {
|
|
54
|
-
if (this.has(element)) this.delete(element)
|
|
55
|
-
else this.add(element)
|
|
56
|
-
return element
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** @param {DSElements} elements */
|
|
60
|
-
addAll = (elements) => elements.forEach((el) => this.add(el))
|
|
61
|
-
|
|
62
|
-
/** @param {DSElements} elements */
|
|
63
|
-
deleteAll = (elements) => elements.forEach((el) => this.delete(el))
|
|
64
|
-
|
|
65
|
-
/** @return {DSElements} */
|
|
66
|
-
get elements() {
|
|
67
|
-
return Array.from(this.values())
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/modules/Selector.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import DragSelect from '../DragSelect'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
createSelectorElement,
|
|
7
|
-
getSelectorPosition,
|
|
8
|
-
updateElementStylePos,
|
|
9
|
-
vect2,
|
|
10
|
-
} from '../methods'
|
|
11
|
-
|
|
12
|
-
export default class Selector {
|
|
13
|
-
/**
|
|
14
|
-
* @type {DSBoundingRect}
|
|
15
|
-
* @private
|
|
16
|
-
*/
|
|
17
|
-
_rect
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @constructor Selector
|
|
21
|
-
* @param {{ DS:DragSelect }} p
|
|
22
|
-
* @ignore
|
|
23
|
-
*/
|
|
24
|
-
constructor({ DS }) {
|
|
25
|
-
this.DS = DS
|
|
26
|
-
|
|
27
|
-
// @ts-ignore: @todo: update to typescript
|
|
28
|
-
this.DS.subscribe('Settings:updated:selectorClass', ({ settings }) => {
|
|
29
|
-
this.HTMLNode.classList.remove(settings['selectorClass:pre'])
|
|
30
|
-
this.HTMLNode.classList.add(settings.selectorClass)
|
|
31
|
-
})
|
|
32
|
-
// @ts-ignore: @todo: update to typescript
|
|
33
|
-
this.DS.subscribe('Settings:updated:selector', this.attachSelector)
|
|
34
|
-
// @ts-ignore: @todo: update to typescript
|
|
35
|
-
this.DS.subscribe('Settings:updated:customStyles', this.attachSelector)
|
|
36
|
-
this.attachSelector()
|
|
37
|
-
|
|
38
|
-
this.DS.subscribe('Interaction:start', this.start)
|
|
39
|
-
this.DS.subscribe('Interaction:update', this.update)
|
|
40
|
-
this.DS.subscribe('Interaction:end', this.stop)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
attachSelector = () => {
|
|
44
|
-
if (this.HTMLNode && this.DS.SelectorArea?.HTMLNode)
|
|
45
|
-
this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode)
|
|
46
|
-
this.HTMLNode =
|
|
47
|
-
this.DS.stores.SettingsStore.s.selector ||
|
|
48
|
-
createSelectorElement(this.DS.stores.SettingsStore.s.customStyles)
|
|
49
|
-
this.HTMLNode.classList.add(this.DS.stores.SettingsStore.s.selectorClass)
|
|
50
|
-
if (this.HTMLNode && this.DS.SelectorArea?.HTMLNode)
|
|
51
|
-
this.DS.SelectorArea.HTMLNode.appendChild(this.HTMLNode)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
start = ({ isDragging }) => {
|
|
55
|
-
if (isDragging) return
|
|
56
|
-
const {
|
|
57
|
-
stores: { PointerStore },
|
|
58
|
-
} = this.DS
|
|
59
|
-
const pPos = PointerStore.initialValArea
|
|
60
|
-
updateElementStylePos(this.HTMLNode, vect2.vect2rect(pPos, 1))
|
|
61
|
-
this.HTMLNode.style.display = 'block'
|
|
62
|
-
this._rect = null
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
stop = () => {
|
|
66
|
-
this.HTMLNode.style.width = '0'
|
|
67
|
-
this.HTMLNode.style.height = '0'
|
|
68
|
-
this.HTMLNode.style.display = 'none'
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Moves the selection to the correct place */
|
|
72
|
-
update = ({ isDragging }) => {
|
|
73
|
-
if (isDragging || this.DS.continue) return
|
|
74
|
-
const {
|
|
75
|
-
stores: { ScrollStore, PointerStore },
|
|
76
|
-
} = this.DS
|
|
77
|
-
const pos = getSelectorPosition({
|
|
78
|
-
scrollAmount: ScrollStore.scrollAmount,
|
|
79
|
-
initialPointerPos: PointerStore.initialValArea,
|
|
80
|
-
pointerPos: PointerStore.currentValArea,
|
|
81
|
-
})
|
|
82
|
-
updateElementStylePos(this.HTMLNode, pos)
|
|
83
|
-
this._rect = null
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
get rect() {
|
|
87
|
-
if (this._rect) return this._rect
|
|
88
|
-
return (this._rect = this.HTMLNode.getBoundingClientRect())
|
|
89
|
-
}
|
|
90
|
-
}
|
package/src/modules/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as Area } from './Area'
|
|
2
|
-
export { default as Drag } from './Drag'
|
|
3
|
-
export { default as DropZones } from './DropZones'
|
|
4
|
-
export { default as Interaction } from './Interaction'
|
|
5
|
-
export { default as PubSub } from './PubSub'
|
|
6
|
-
export { default as SelectableSet } from './SelectableSet'
|
|
7
|
-
export { default as SelectedSet } from './SelectedSet'
|
|
8
|
-
export { default as Selection } from './Selection'
|
|
9
|
-
export { default as Selector } from './Selector'
|
|
10
|
-
export { default as SelectorArea } from './SelectorArea'
|
package/src/stores/KeyStore.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import DragSelect from '../DragSelect'
|
|
4
|
-
|
|
5
|
-
export default class KeyStore {
|
|
6
|
-
/**
|
|
7
|
-
* @type {Set<string>}
|
|
8
|
-
* @private
|
|
9
|
-
* */
|
|
10
|
-
_currentValues = new Set()
|
|
11
|
-
/**
|
|
12
|
-
* @type {{control:string,shift:string,meta:string}}
|
|
13
|
-
* @private
|
|
14
|
-
* */
|
|
15
|
-
_keyMapping = {
|
|
16
|
-
control: 'ctrlKey',
|
|
17
|
-
shift: 'shiftKey',
|
|
18
|
-
meta: 'metaKey',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @class KeyStore
|
|
23
|
-
* @constructor KeyStore
|
|
24
|
-
* @param {{DS:DragSelect}} p
|
|
25
|
-
* @ignore
|
|
26
|
-
*/
|
|
27
|
-
constructor({ DS }) {
|
|
28
|
-
this.DS = DS
|
|
29
|
-
this.DS.subscribe('Interaction:init', this.init)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
init = () => {
|
|
33
|
-
document.addEventListener('keydown', this.keydown)
|
|
34
|
-
document.addEventListener('keyup', this.keyup)
|
|
35
|
-
window.addEventListener('blur', this.reset)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** @param {KeyboardEvent} event */
|
|
39
|
-
keydown = (event) => {
|
|
40
|
-
const key = event.key.toLowerCase()
|
|
41
|
-
this.DS.publish('KeyStore:down:pre', { event, key })
|
|
42
|
-
this._currentValues.add(key)
|
|
43
|
-
this.DS.publish('KeyStore:down', { event, key })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** @param {KeyboardEvent} event */
|
|
47
|
-
keyup = (event) => {
|
|
48
|
-
const key = event.key.toLowerCase()
|
|
49
|
-
this.DS.publish('KeyStore:up:pre', { event, key })
|
|
50
|
-
this._currentValues.delete(key)
|
|
51
|
-
this.DS.publish('KeyStore:up', { event, key })
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
stop = () => {
|
|
55
|
-
document.removeEventListener('keydown', this.keydown)
|
|
56
|
-
document.removeEventListener('keyup', this.reset)
|
|
57
|
-
window.removeEventListener('blur', this.reset)
|
|
58
|
-
this.reset()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
reset = () => this._currentValues.clear()
|
|
62
|
-
|
|
63
|
-
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
|
|
64
|
-
isMultiSelectKeyPressed(event) {
|
|
65
|
-
if(this.DS.stores.SettingsStore.s.multiSelectMode) return true
|
|
66
|
-
const multiSelectKeys = this.DS.stores.SettingsStore.s.multiSelectKeys.map(
|
|
67
|
-
(key) => key.toLocaleLowerCase()
|
|
68
|
-
)
|
|
69
|
-
if (
|
|
70
|
-
this.currentValues.some((key) =>
|
|
71
|
-
multiSelectKeys.includes(key.toLocaleLowerCase())
|
|
72
|
-
)
|
|
73
|
-
)
|
|
74
|
-
return true
|
|
75
|
-
if (event && multiSelectKeys.some((key) => event[this._keyMapping[key]]))
|
|
76
|
-
return true
|
|
77
|
-
return false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
get currentValues() {
|
|
81
|
-
return Array.from(this._currentValues.values())
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import DragSelect from '../DragSelect'
|
|
2
|
-
import { getPointerPos, vect2 } from '../methods'
|
|
3
|
-
|
|
4
|
-
export default class PointerStore {
|
|
5
|
-
/** @type {boolean} */
|
|
6
|
-
_isMouseInteraction = false
|
|
7
|
-
|
|
8
|
-
// Pointer Positions within Area
|
|
9
|
-
/**
|
|
10
|
-
* @type {Vect2}
|
|
11
|
-
* @private
|
|
12
|
-
* */
|
|
13
|
-
_initialValArea
|
|
14
|
-
/**
|
|
15
|
-
* @type {Vect2}
|
|
16
|
-
* @private
|
|
17
|
-
* */
|
|
18
|
-
_currentValArea
|
|
19
|
-
/**
|
|
20
|
-
* @type {Vect2}
|
|
21
|
-
* @private
|
|
22
|
-
* */
|
|
23
|
-
_lastValArea
|
|
24
|
-
|
|
25
|
-
// General Pointer Position
|
|
26
|
-
/**
|
|
27
|
-
* @type {Vect2}
|
|
28
|
-
* @private
|
|
29
|
-
* */
|
|
30
|
-
_initialVal
|
|
31
|
-
/**
|
|
32
|
-
* @type {Vect2}
|
|
33
|
-
* @private
|
|
34
|
-
* */
|
|
35
|
-
_currentVal
|
|
36
|
-
/**
|
|
37
|
-
* @type {Vect2}
|
|
38
|
-
* @private
|
|
39
|
-
* */
|
|
40
|
-
_lastVal
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @type {TouchEvent}
|
|
44
|
-
* @private
|
|
45
|
-
* */
|
|
46
|
-
_lastTouch
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @class PointerStore
|
|
50
|
-
* @constructor PointerStore
|
|
51
|
-
* @param {{DS:DragSelect}} p
|
|
52
|
-
* @ignore
|
|
53
|
-
*/
|
|
54
|
-
constructor({ DS }) {
|
|
55
|
-
this.DS = DS
|
|
56
|
-
this.Settings = DS.stores.SettingsStore.s
|
|
57
|
-
this.DS.subscribe('Interaction:init', this.init)
|
|
58
|
-
this.DS.subscribe('Interaction:start', ({ event }) => this.start(event))
|
|
59
|
-
this.DS.subscribe('Interaction:end', ({ event }) => this.reset(event))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
init = () => {
|
|
63
|
-
if (this.Settings.usePointerEvents)
|
|
64
|
-
document.addEventListener('pointermove', this.update, {
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
passive: false,
|
|
67
|
-
})
|
|
68
|
-
else document.addEventListener('mousemove', this.update)
|
|
69
|
-
|
|
70
|
-
document.addEventListener('touchmove', this.update, {
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
passive: false,
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @param {DSEvent} [event] */
|
|
77
|
-
start(event) {
|
|
78
|
-
if (!event) return
|
|
79
|
-
this._isMouseInteraction = true
|
|
80
|
-
this.currentVal = this.initialVal = this.getPointerPosition(event)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** @param {DSEvent} event */
|
|
84
|
-
getPointerPosition = (event) =>
|
|
85
|
-
getPointerPos({
|
|
86
|
-
event: this._normalizedEvent(event),
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
/** @param {DSEvent} [event] */
|
|
90
|
-
update = (event) => {
|
|
91
|
-
if (!event) return
|
|
92
|
-
this.DS.publish('PointerStore:updated:pre', { event })
|
|
93
|
-
this.currentVal = this.getPointerPosition(event)
|
|
94
|
-
if (!this._isMouseInteraction) return
|
|
95
|
-
this.DS.publish('PointerStore:updated', { event })
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
stop = () => {
|
|
99
|
-
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
100
|
-
if (this.Settings.usePointerEvents)
|
|
101
|
-
document.removeEventListener('pointermove', this.update, {
|
|
102
|
-
// @ts-ignore
|
|
103
|
-
passive: false,
|
|
104
|
-
})
|
|
105
|
-
else document.removeEventListener('mousemove', this.update)
|
|
106
|
-
|
|
107
|
-
document.removeEventListener('touchmove', this.update, {
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
passive: false,
|
|
110
|
-
})
|
|
111
|
-
// debounce in order "onClick" to work
|
|
112
|
-
setTimeout(() => (this._isMouseInteraction = false), 100)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** @param {DSEvent} [event] */
|
|
116
|
-
reset = (event) => {
|
|
117
|
-
if (!event) return
|
|
118
|
-
|
|
119
|
-
this.currentVal = this.lastVal = this.getPointerPosition(event)
|
|
120
|
-
|
|
121
|
-
this.stop()
|
|
122
|
-
this.init()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @param {DSEvent} event
|
|
127
|
-
* @return {MouseEvent|PointerEvent|Touch}
|
|
128
|
-
* @private
|
|
129
|
-
*/
|
|
130
|
-
_normalizedEvent(event) {
|
|
131
|
-
// touchend has not touches. so we take the last touch if a touchevent, we need to store the positions
|
|
132
|
-
if ('touches' in event && event.type !== 'touchend') this._lastTouch = event
|
|
133
|
-
// if a touchevent, return the last touch rather than the regular event
|
|
134
|
-
// we need .touches[0] from that event instead
|
|
135
|
-
return 'touches' in event ? this._lastTouch.touches[0] : event
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** First recorded pointer position within the area */
|
|
139
|
-
get initialValArea() {
|
|
140
|
-
if (!this._initialValArea) return { x: 0, y: 0 }
|
|
141
|
-
return this._initialValArea
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Current pointer position within the area */
|
|
145
|
-
get currentValArea() {
|
|
146
|
-
if (!this._currentValArea) return { x: 0, y: 0 }
|
|
147
|
-
return this._currentValArea
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Last recorded pointer position within the area */
|
|
151
|
-
get lastValArea() {
|
|
152
|
-
if (!this._lastValArea) return { x: 0, y: 0 }
|
|
153
|
-
return this._lastValArea
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** First recorded pointer position */
|
|
157
|
-
get initialVal() {
|
|
158
|
-
if (!this._initialVal) return { x: 0, y: 0 }
|
|
159
|
-
return this._initialVal
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Current pointer position */
|
|
163
|
-
get currentVal() {
|
|
164
|
-
if (!this._currentVal) return { x: 0, y: 0 }
|
|
165
|
-
return this._currentVal
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Last recorded pointer position */
|
|
169
|
-
get lastVal() {
|
|
170
|
-
if (!this._lastVal) return { x: 0, y: 0 }
|
|
171
|
-
return this._lastVal
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
set initialVal(value) {
|
|
175
|
-
this._initialVal = value
|
|
176
|
-
this._initialValArea =
|
|
177
|
-
value &&
|
|
178
|
-
vect2.calc(
|
|
179
|
-
value,
|
|
180
|
-
'-',
|
|
181
|
-
vect2.calc(
|
|
182
|
-
vect2.rect2vect(this.DS.Area.rect),
|
|
183
|
-
'+',
|
|
184
|
-
vect2.rect2vect(this.DS.Area.computedBorder)
|
|
185
|
-
)
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
set currentVal(value) {
|
|
190
|
-
this._currentVal = value
|
|
191
|
-
this._currentValArea =
|
|
192
|
-
value &&
|
|
193
|
-
vect2.calc(
|
|
194
|
-
value,
|
|
195
|
-
'-',
|
|
196
|
-
vect2.calc(
|
|
197
|
-
vect2.rect2vect(this.DS.Area.rect),
|
|
198
|
-
'+',
|
|
199
|
-
vect2.rect2vect(this.DS.Area.computedBorder)
|
|
200
|
-
)
|
|
201
|
-
)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
set lastVal(value) {
|
|
205
|
-
this._lastVal = value
|
|
206
|
-
this._lastValArea =
|
|
207
|
-
value &&
|
|
208
|
-
vect2.calc(
|
|
209
|
-
value,
|
|
210
|
-
'-',
|
|
211
|
-
vect2.calc(
|
|
212
|
-
vect2.rect2vect(this.DS.Area.rect),
|
|
213
|
-
'+',
|
|
214
|
-
vect2.rect2vect(this.DS.Area.computedBorder)
|
|
215
|
-
)
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import DragSelect from '../DragSelect'
|
|
4
|
-
import { getCurrentScroll, vect2, canScroll } from '../methods'
|
|
5
|
-
|
|
6
|
-
export default class ScrollStore {
|
|
7
|
-
/**
|
|
8
|
-
* @type {Vect2}
|
|
9
|
-
* @private */
|
|
10
|
-
_initialVal
|
|
11
|
-
/**
|
|
12
|
-
* @type {Vect2}
|
|
13
|
-
* @private */
|
|
14
|
-
_currentVal
|
|
15
|
-
/**
|
|
16
|
-
* @type {boolean}
|
|
17
|
-
* @private */
|
|
18
|
-
_canScroll
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @class ScrollStore
|
|
22
|
-
* @constructor ScrollStore
|
|
23
|
-
* @param {{ DS:DragSelect }} p
|
|
24
|
-
* @ignore
|
|
25
|
-
*/
|
|
26
|
-
constructor({ DS }) {
|
|
27
|
-
this.DS = DS
|
|
28
|
-
this.DS.subscribe('Interaction:init', this.init)
|
|
29
|
-
this.DS.subscribe('Interaction:start', () => this.start())
|
|
30
|
-
this.DS.subscribe('Interaction:end', () => this.reset())
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
init = () =>
|
|
34
|
-
this.DS.stores.SettingsStore.s.area.addEventListener('scroll', this.update)
|
|
35
|
-
|
|
36
|
-
start = () => {
|
|
37
|
-
this._currentVal = this._initialVal = getCurrentScroll(
|
|
38
|
-
this.DS.stores.SettingsStore.s.area
|
|
39
|
-
)
|
|
40
|
-
this.DS.stores.SettingsStore.s.area.addEventListener('scroll', this.update)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
update = () =>
|
|
44
|
-
(this._currentVal = getCurrentScroll(this.DS.stores.SettingsStore.s.area))
|
|
45
|
-
|
|
46
|
-
stop = () => {
|
|
47
|
-
this.DS.stores.SettingsStore.s.area.removeEventListener(
|
|
48
|
-
'scroll',
|
|
49
|
-
this.update
|
|
50
|
-
)
|
|
51
|
-
this._initialVal = { x: 0, y: 0 }
|
|
52
|
-
this._canScroll = null
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
reset = () => {
|
|
56
|
-
this.stop()
|
|
57
|
-
this.start()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get canScroll() {
|
|
61
|
-
if (typeof this._canScroll === 'boolean') return this._canScroll
|
|
62
|
-
return (this._canScroll = canScroll(this.DS.stores.SettingsStore.s.area))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get scrollAmount() {
|
|
66
|
-
const scrollDiff = vect2.calc(this.currentVal, '-', this.initialVal)
|
|
67
|
-
|
|
68
|
-
// if area is zoomed, the scroll values are skewed, we need to fix that manually :(
|
|
69
|
-
const zoom = vect2.num2vect(this.DS.stores.SettingsStore.s.zoom)
|
|
70
|
-
const zoomScroll = vect2.calc(
|
|
71
|
-
vect2.calc(scrollDiff, '*', zoom),
|
|
72
|
-
'-',
|
|
73
|
-
scrollDiff
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
x: scrollDiff.x + zoomScroll.x,
|
|
78
|
-
y: scrollDiff.y + zoomScroll.y,
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
get initialVal() {
|
|
83
|
-
if (!this._initialVal) return { x: 0, y: 0 }
|
|
84
|
-
return this._initialVal
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
get currentVal() {
|
|
88
|
-
if (!this._currentVal)
|
|
89
|
-
this._currentVal = getCurrentScroll(this.DS.stores.SettingsStore.s.area)
|
|
90
|
-
return this._currentVal
|
|
91
|
-
}
|
|
92
|
-
}
|