dragselect 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/dist/{DragSelect.es6m.js → DragSelect.esm.js} +1 -1
- package/dist/DragSelect.js +1 -1
- package/package.json +2 -2
- package/src/DragSelect.ts +0 -425
- package/src/methods/addModificationObservers.ts +0 -51
- package/src/methods/canScroll.ts +0 -19
- package/src/methods/createSelectorAreaElement.ts +0 -8
- package/src/methods/createSelectorElement.ts +0 -13
- package/src/methods/debounce.ts +0 -31
- package/src/methods/ensureArray.ts +0 -13
- package/src/methods/getAllParentNodes.ts +0 -15
- package/src/methods/getAreaRect.ts +0 -27
- package/src/methods/getCurrentScroll.ts +0 -14
- package/src/methods/getDocumentScroll.ts +0 -5
- package/src/methods/getOverflowEdges.ts +0 -27
- package/src/methods/getPointerPos.ts +0 -9
- package/src/methods/getSelectionRect.ts +0 -29
- package/src/methods/getSelectorPosition.ts +0 -74
- package/src/methods/getStylePosition.spec.ts +0 -114
- package/src/methods/getStylePosition.ts +0 -83
- package/src/methods/handleElementPositionAttribute.ts +0 -15
- package/src/methods/handleKeyboardDragPosDifference.ts +0 -35
- package/src/methods/handleSelection.ts +0 -26
- package/src/methods/handleUnSelection.ts +0 -36
- package/src/methods/hydrateSettings.ts +0 -245
- package/src/methods/isCollision.ts +0 -66
- package/src/methods/limitDirection.ts +0 -36
- package/src/methods/moveElement.ts +0 -18
- package/src/methods/scrollElement.ts +0 -26
- package/src/methods/setStylePosition.ts +0 -16
- package/src/methods/subscriberAliases.ts +0 -240
- package/src/methods/updateElementStylePos.ts +0 -7
- package/src/methods/vect2.ts +0 -34
- package/src/modules/Area.ts +0 -169
- package/src/modules/Drag.ts +0 -236
- package/src/modules/DropZone.ts +0 -223
- package/src/modules/DropZones.ts +0 -151
- package/src/modules/Interaction.ts +0 -251
- package/src/modules/PubSub.ts +0 -111
- package/src/modules/SelectableSet.ts +0 -146
- package/src/modules/SelectedSet.ts +0 -92
- package/src/modules/Selection.ts +0 -133
- package/src/modules/Selector.ts +0 -81
- package/src/modules/SelectorArea.ts +0 -161
- package/src/stores/KeyStore.ts +0 -92
- package/src/stores/PointerStore.ts +0 -194
- package/src/stores/ScrollStore.ts +0 -87
- package/src/stores/SettingsStore.ts +0 -88
- package/src/types.ts +0 -158
- /package/dist/{ds.es6m.min.js → ds.esm.min.js} +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import DragSelect from "../DragSelect"
|
|
2
|
-
import PubSub from "./PubSub"
|
|
3
|
-
import { DSSettings } from "../stores/SettingsStore"
|
|
4
|
-
import { DSBoundingRect, DSInputElement } from "../types";
|
|
5
|
-
|
|
6
|
-
export type DSSelectedPublishEventNames = "Selected:added:pre"|"Selected:added"|"Selected:removed"|"Selected:removed:pre"
|
|
7
|
-
|
|
8
|
-
export type DSSelectedPublishEventData<E extends DSInputElement> = {
|
|
9
|
-
items: E[],
|
|
10
|
-
item: E,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type DSSelectedPublish<E extends DSInputElement> = {
|
|
14
|
-
[K in DSSelectedPublishEventNames]: DSSelectedPublishEventData<E>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default class SelectedSet<E extends DSInputElement> extends Set<E> {
|
|
18
|
-
private _rects?: Map<E, DSBoundingRect>
|
|
19
|
-
private _timeout?: NodeJS.Timeout
|
|
20
|
-
private DS: DragSelect<E>
|
|
21
|
-
private PS: PubSub<E>
|
|
22
|
-
private Settings: DSSettings<E>
|
|
23
|
-
|
|
24
|
-
constructor({ DS, PS }: { DS: DragSelect<E>, PS: PubSub<E> }) {
|
|
25
|
-
super()
|
|
26
|
-
this.DS = DS
|
|
27
|
-
this.PS = PS
|
|
28
|
-
this.Settings = this.DS.stores.SettingsStore.s
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public add(element?: E) {
|
|
32
|
-
if (!element || super.has(element)) return this
|
|
33
|
-
const publishData = {
|
|
34
|
-
items: this.elements,
|
|
35
|
-
item: element,
|
|
36
|
-
}
|
|
37
|
-
this.PS.publish('Selected:added:pre', publishData)
|
|
38
|
-
super.add(element)
|
|
39
|
-
element.classList.add(this.Settings.selectedClass)
|
|
40
|
-
element.style.zIndex = `${(parseInt(element.style.zIndex) || 0) + 1}`
|
|
41
|
-
this.PS.publish('Selected:added', publishData)
|
|
42
|
-
return this
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public delete(element: E) {
|
|
46
|
-
if (!element || !super.has(element)) return true
|
|
47
|
-
const publishData = {
|
|
48
|
-
items: this.elements,
|
|
49
|
-
item: element,
|
|
50
|
-
}
|
|
51
|
-
this.PS.publish('Selected:removed:pre', publishData)
|
|
52
|
-
const deleted = super.delete(element)
|
|
53
|
-
element.classList.remove(this.Settings.selectedClass)
|
|
54
|
-
element.style.zIndex = `${(parseInt(element.style.zIndex) || 0) - 1}`
|
|
55
|
-
this.PS.publish('Selected:removed', publishData)
|
|
56
|
-
return deleted
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public clear = () => this.forEach((el) => this.delete(el))
|
|
60
|
-
|
|
61
|
-
/** Adds/Removes an element. If it is already selected = remove, if not = add. */
|
|
62
|
-
public toggle(element: E) {
|
|
63
|
-
if (this.has(element)) this.delete(element)
|
|
64
|
-
else this.add(element)
|
|
65
|
-
return element
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public addAll = (elements: E[]) => elements.forEach((el) => this.add(el))
|
|
69
|
-
|
|
70
|
-
public deleteAll = (elements: E[]) => elements.forEach((el) => this.delete(el))
|
|
71
|
-
|
|
72
|
-
get elements() {
|
|
73
|
-
return Array.from(this.values())
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get rects() {
|
|
77
|
-
if (this._rects) return this._rects
|
|
78
|
-
this._rects = new Map()
|
|
79
|
-
this.forEach((element) =>
|
|
80
|
-
this._rects?.set(element, element.getBoundingClientRect())
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
// since elements can be moved, we need to update the rects every X ms
|
|
84
|
-
if (this._timeout) clearTimeout(this._timeout)
|
|
85
|
-
this._timeout = setTimeout(
|
|
86
|
-
() => (this._rects = undefined),
|
|
87
|
-
this.Settings.refreshMemoryRate
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
return this._rects
|
|
91
|
-
}
|
|
92
|
-
}
|
package/src/modules/Selection.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import DragSelect from '../DragSelect'
|
|
2
|
-
import PubSub from './PubSub'
|
|
3
|
-
import { DSBoundingRect, DSEvent, DSInputElement } from '../types'
|
|
4
|
-
import { DSSettings } from '../stores/SettingsStore'
|
|
5
|
-
import { handleSelection } from '../methods/handleSelection'
|
|
6
|
-
import { handleUnSelection } from '../methods/handleUnSelection'
|
|
7
|
-
import { isCollision } from '../methods/isCollision'
|
|
8
|
-
import { getSelectionRect } from '../methods/getSelectionRect'
|
|
9
|
-
|
|
10
|
-
export default class Selection<E extends DSInputElement> {
|
|
11
|
-
private _prevSelectedSet: Set<E> = new Set()
|
|
12
|
-
private _boundingRect?: DSBoundingRect
|
|
13
|
-
private _timeout?: NodeJS.Timeout
|
|
14
|
-
private DS: DragSelect<E>
|
|
15
|
-
private PS: PubSub<E>
|
|
16
|
-
private Settings: DSSettings<E>
|
|
17
|
-
|
|
18
|
-
constructor({ DS, PS }: { DS: DragSelect<E>; PS: PubSub<E> }) {
|
|
19
|
-
this.DS = DS
|
|
20
|
-
this.PS = PS
|
|
21
|
-
this.Settings = this.DS.stores.SettingsStore.s
|
|
22
|
-
this.PS.subscribe('Interaction:start', this.start)
|
|
23
|
-
this.PS.subscribe('Interaction:update', this.update)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Stores the previous selection (solves #9) */
|
|
27
|
-
private _storePrevious(event: DSEvent) {
|
|
28
|
-
const {
|
|
29
|
-
stores: { KeyStore },
|
|
30
|
-
SelectedSet,
|
|
31
|
-
} = this.DS
|
|
32
|
-
|
|
33
|
-
if (KeyStore.isMultiSelectKeyPressed(event))
|
|
34
|
-
this._prevSelectedSet = new Set(SelectedSet)
|
|
35
|
-
else this._prevSelectedSet = new Set()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private start = ({
|
|
39
|
-
event,
|
|
40
|
-
isDragging,
|
|
41
|
-
}: {
|
|
42
|
-
event: DSEvent
|
|
43
|
-
isDragging: boolean
|
|
44
|
-
}) => {
|
|
45
|
-
if (isDragging) return
|
|
46
|
-
this._storePrevious(event)
|
|
47
|
-
this._handleInsideSelection(true, event)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private update = ({ isDragging }: { isDragging?: boolean }) => {
|
|
51
|
-
if (isDragging || this.DS.continue) return
|
|
52
|
-
this._handleInsideSelection()
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Checks if any selectable element is inside selection. */
|
|
56
|
-
private _handleInsideSelection = (force?: boolean, event?: DSEvent) => {
|
|
57
|
-
const { SelectableSet, SelectorArea, Selector } = this.DS
|
|
58
|
-
|
|
59
|
-
const multiSelectionToggle =
|
|
60
|
-
this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) &&
|
|
61
|
-
this.Settings.multiSelectToggling
|
|
62
|
-
const selectionThreshold = this.Settings.selectionThreshold
|
|
63
|
-
|
|
64
|
-
const elRects = SelectableSet.rects
|
|
65
|
-
const selectorRect = Selector.rect
|
|
66
|
-
|
|
67
|
-
const select: Map<E, DSBoundingRect> = new Map()
|
|
68
|
-
const unselect: Map<E, DSBoundingRect> = new Map()
|
|
69
|
-
|
|
70
|
-
for (const [element, elementRect] of elRects) {
|
|
71
|
-
if (!SelectorArea.isInside(element, elementRect)) continue
|
|
72
|
-
if (isCollision(elementRect, selectorRect, selectionThreshold))
|
|
73
|
-
select.set(element, elementRect)
|
|
74
|
-
else unselect.set(element, elementRect)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (this.DS.continue) return
|
|
78
|
-
|
|
79
|
-
// [PUBLICLY EXPOSED METHOD]
|
|
80
|
-
const { select: filteredSelect, unselect: filteredUnselect } =
|
|
81
|
-
this.filterSelected({ select, unselect, selectorRect })
|
|
82
|
-
|
|
83
|
-
filteredSelect.forEach((_, element) =>
|
|
84
|
-
handleSelection({
|
|
85
|
-
element,
|
|
86
|
-
force,
|
|
87
|
-
multiSelectionToggle,
|
|
88
|
-
SelectedSet: this.DS.SelectedSet,
|
|
89
|
-
hoverClassName: this.Settings.hoverClass,
|
|
90
|
-
})
|
|
91
|
-
)
|
|
92
|
-
filteredUnselect.forEach((_, element) =>
|
|
93
|
-
handleUnSelection({
|
|
94
|
-
element,
|
|
95
|
-
force,
|
|
96
|
-
SelectedSet: this.DS.SelectedSet,
|
|
97
|
-
hoverClassName: this.Settings.hoverClass,
|
|
98
|
-
PrevSelectedSet: this._prevSelectedSet,
|
|
99
|
-
})
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get boundingRect() {
|
|
104
|
-
if (this._boundingRect) return this._boundingRect
|
|
105
|
-
this._boundingRect = getSelectionRect(this.DS.SelectedSet)
|
|
106
|
-
|
|
107
|
-
// since elements can be moved, we need to update the rects every X ms
|
|
108
|
-
if (this._timeout) clearTimeout(this._timeout)
|
|
109
|
-
this._timeout = setTimeout(
|
|
110
|
-
() => (this._boundingRect = undefined),
|
|
111
|
-
this.Settings.refreshMemoryRate
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
return this._boundingRect
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
////
|
|
118
|
-
// [PUBLICLY EXPOSED METHODS]
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Can be overridden to apply further filtering logic after the items to select are identified but before they actually get selected
|
|
122
|
-
* Is expected to return the select / unselect maps in the same shape as passed in
|
|
123
|
-
*/
|
|
124
|
-
public filterSelected = ({
|
|
125
|
-
select,
|
|
126
|
-
unselect,
|
|
127
|
-
selectorRect,
|
|
128
|
-
}: {
|
|
129
|
-
select: Map<E, DSBoundingRect>
|
|
130
|
-
unselect: Map<E, DSBoundingRect>
|
|
131
|
-
selectorRect: DSBoundingRect
|
|
132
|
-
}) => ({ select, unselect })
|
|
133
|
-
}
|
package/src/modules/Selector.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import DragSelect from "../DragSelect"
|
|
2
|
-
import { createSelectorElement } from "../methods/createSelectorElement";
|
|
3
|
-
import { getSelectorPosition } from "../methods/getSelectorPosition";
|
|
4
|
-
import updateElementStylePos from "../methods/updateElementStylePos";
|
|
5
|
-
import { vect2rect } from "../methods/vect2";
|
|
6
|
-
import { DSSettings } from "../stores/SettingsStore";
|
|
7
|
-
import { DSBoundingRect, DSInputElement } from "../types"
|
|
8
|
-
import PubSub from "./PubSub";
|
|
9
|
-
|
|
10
|
-
export default class Selector<E extends DSInputElement> {
|
|
11
|
-
private _rect?: DSBoundingRect
|
|
12
|
-
private DS: DragSelect<E>;
|
|
13
|
-
private PS: PubSub<E>;
|
|
14
|
-
private Settings: DSSettings<E>;
|
|
15
|
-
public HTMLNode: HTMLElement;
|
|
16
|
-
|
|
17
|
-
constructor({ DS, PS }: { DS: DragSelect<E>; PS: PubSub<E> }) {
|
|
18
|
-
this.DS = DS
|
|
19
|
-
this.PS = PS
|
|
20
|
-
this.Settings = this.DS.stores.SettingsStore.s
|
|
21
|
-
this.HTMLNode = this.Settings.selector // to make TS happy, will be replaced in `attachSelector`
|
|
22
|
-
|
|
23
|
-
this.PS.subscribe('Settings:updated:selectorClass', ({ settings }) => {
|
|
24
|
-
this.HTMLNode.classList.remove(settings['selectorClass:pre'])
|
|
25
|
-
this.HTMLNode.classList.add(settings.selectorClass)
|
|
26
|
-
})
|
|
27
|
-
this.PS.subscribe('Settings:updated:selector', this.attachSelector)
|
|
28
|
-
this.PS.subscribe('Settings:updated:customStyles', this.attachSelector)
|
|
29
|
-
this.attachSelector()
|
|
30
|
-
|
|
31
|
-
this.PS.subscribe('Interaction:start', this.start)
|
|
32
|
-
this.PS.subscribe('Interaction:update', this.update)
|
|
33
|
-
this.PS.subscribe('Interaction:end', this.stop)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private attachSelector = () => {
|
|
37
|
-
if (this.HTMLNode && this.DS.SelectorArea?.HTMLNode)
|
|
38
|
-
this.DS.SelectorArea.HTMLNode.removeChild(this.HTMLNode)
|
|
39
|
-
this.HTMLNode = this.Settings.selector || createSelectorElement(this.Settings.customStyles)
|
|
40
|
-
this.HTMLNode.classList.add(this.Settings.selectorClass)
|
|
41
|
-
if (this.HTMLNode && this.DS.SelectorArea?.HTMLNode)
|
|
42
|
-
this.DS.SelectorArea.HTMLNode.appendChild(this.HTMLNode)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private start = ({ isDragging }: { isDragging?: boolean }) => {
|
|
46
|
-
if (isDragging) return
|
|
47
|
-
const {
|
|
48
|
-
stores: { PointerStore },
|
|
49
|
-
} = this.DS
|
|
50
|
-
const pPos = PointerStore.initialValArea
|
|
51
|
-
updateElementStylePos(this.HTMLNode, vect2rect(pPos, 1))
|
|
52
|
-
this.HTMLNode.style.display = 'block'
|
|
53
|
-
this._rect = undefined
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public stop = () => {
|
|
57
|
-
this.HTMLNode.style.width = '0'
|
|
58
|
-
this.HTMLNode.style.height = '0'
|
|
59
|
-
this.HTMLNode.style.display = 'none'
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Moves the selection to the correct place */
|
|
63
|
-
private update = ({ isDragging }: { isDragging?: boolean }) => {
|
|
64
|
-
if (isDragging || this.DS.continue) return
|
|
65
|
-
const {
|
|
66
|
-
stores: { ScrollStore, PointerStore },
|
|
67
|
-
} = this.DS
|
|
68
|
-
const pos = getSelectorPosition({
|
|
69
|
-
scrollAmount: ScrollStore.scrollAmount,
|
|
70
|
-
initialPointerPos: PointerStore.initialValArea,
|
|
71
|
-
pointerPos: PointerStore.currentValArea,
|
|
72
|
-
})
|
|
73
|
-
updateElementStylePos(this.HTMLNode, pos)
|
|
74
|
-
this._rect = undefined
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public get rect() {
|
|
78
|
-
if (this._rect) return this._rect
|
|
79
|
-
return (this._rect = this.HTMLNode.getBoundingClientRect())
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import DragSelect from '../DragSelect'
|
|
2
|
-
import { createSelectorAreaElement } from '../methods/createSelectorAreaElement'
|
|
3
|
-
import { getOverflowEdges } from '../methods/getOverflowEdges'
|
|
4
|
-
import { isCollision } from '../methods/isCollision'
|
|
5
|
-
import { vect2rect } from '../methods/vect2'
|
|
6
|
-
import { DSSettings } from '../stores/SettingsStore'
|
|
7
|
-
import { DSBoundingRect, DSEdges, DSEvent, DSInputElement } from '../types'
|
|
8
|
-
import PubSub from './PubSub'
|
|
9
|
-
|
|
10
|
-
type AppendRemove = 'append' | 'remove'
|
|
11
|
-
|
|
12
|
-
export default class SelectorArea<E extends DSInputElement> {
|
|
13
|
-
private _scrollInterval?: NodeJS.Timeout
|
|
14
|
-
private _rect?: DSBoundingRect
|
|
15
|
-
private currentEdges: DSEdges = []
|
|
16
|
-
private DS: DragSelect<E>
|
|
17
|
-
private PS: PubSub<E>
|
|
18
|
-
private Settings: DSSettings<E>
|
|
19
|
-
public HTMLNode: HTMLElement
|
|
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
|
-
this.HTMLNode = createSelectorAreaElement()
|
|
26
|
-
|
|
27
|
-
this.PS.subscribe('Settings:updated:selectorAreaClass', ({ settings }) => {
|
|
28
|
-
this.HTMLNode.classList.remove(settings['selectorAreaClass:pre'])
|
|
29
|
-
this.HTMLNode.classList.add(settings['selectorAreaClass'])
|
|
30
|
-
})
|
|
31
|
-
this.HTMLNode.classList.add(this.Settings.selectorAreaClass)
|
|
32
|
-
|
|
33
|
-
this.PS.subscribe('Area:modified', this.updatePos)
|
|
34
|
-
this.PS.subscribe('Area:modified', this.updatePos)
|
|
35
|
-
this.PS.subscribe('Interaction:init', this.init)
|
|
36
|
-
this.PS.subscribe('Interaction:start', ({ isDraggingKeyboard }) =>
|
|
37
|
-
this.startAutoScroll({ isDraggingKeyboard })
|
|
38
|
-
)
|
|
39
|
-
this.PS.subscribe('Interaction:end', () => {
|
|
40
|
-
this.updatePos()
|
|
41
|
-
this.stopAutoScroll()
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private init = () => {
|
|
46
|
-
this.applyElements('append')
|
|
47
|
-
this.updatePos()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Adding / Removing elements to document */
|
|
51
|
-
private applyElements = <K extends keyof AppendRemove>(
|
|
52
|
-
method: AppendRemove[K]
|
|
53
|
-
) => {
|
|
54
|
-
const docEl = document.body ? 'body' : 'documentElement'
|
|
55
|
-
const methodName = `${method}Child` as `${AppendRemove}Child`
|
|
56
|
-
this.HTMLNode[methodName](this.DS.Selector.HTMLNode)
|
|
57
|
-
document[docEl][methodName](this.HTMLNode)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Updates the selectorAreas positions to match the areas */
|
|
61
|
-
private updatePos = () => {
|
|
62
|
-
this._rect = undefined
|
|
63
|
-
const rect = this.DS.Area.rect
|
|
64
|
-
const border = this.DS.Area.computedBorder
|
|
65
|
-
const { style } = this.HTMLNode
|
|
66
|
-
const top = `${rect.top + border.top}px`
|
|
67
|
-
const left = `${rect.left + border.left}px`
|
|
68
|
-
const width = `${rect.width}px`
|
|
69
|
-
const height = `${rect.height}px`
|
|
70
|
-
if (style.top !== top) style.top = top
|
|
71
|
-
if (style.left !== left) style.left = left
|
|
72
|
-
if (style.width !== width) style.width = width
|
|
73
|
-
if (style.height !== height) style.height = height
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public stop = (remove: boolean) => {
|
|
77
|
-
this.stopAutoScroll()
|
|
78
|
-
if (remove) this.applyElements('remove')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//////////////////////////////////////////////////////////////////////////////////////
|
|
82
|
-
// AutoScroll
|
|
83
|
-
|
|
84
|
-
private startAutoScroll = ({
|
|
85
|
-
isDraggingKeyboard,
|
|
86
|
-
}: {
|
|
87
|
-
isDraggingKeyboard?: boolean
|
|
88
|
-
}) => {
|
|
89
|
-
if (isDraggingKeyboard) return
|
|
90
|
-
this.currentEdges = []
|
|
91
|
-
this._scrollInterval = setInterval(() => this.handleAutoScroll(), 16)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Creates an interval that auto-scrolls while the cursor is near the edge */
|
|
95
|
-
private handleAutoScroll = () => {
|
|
96
|
-
if (this.DS.continue) return
|
|
97
|
-
const {
|
|
98
|
-
stores: { PointerStore },
|
|
99
|
-
Area,
|
|
100
|
-
} = this.DS
|
|
101
|
-
|
|
102
|
-
this.currentEdges = getOverflowEdges({
|
|
103
|
-
elementRect: vect2rect(PointerStore.currentVal),
|
|
104
|
-
containerRect: this.rect,
|
|
105
|
-
tolerance: this.Settings.overflowTolerance,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
if (this.currentEdges.length)
|
|
109
|
-
Area.scroll(this.currentEdges, this.Settings.autoScrollSpeed)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private stopAutoScroll = () => {
|
|
113
|
-
this.currentEdges = []
|
|
114
|
-
clearInterval(this._scrollInterval)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//////////////////////////////////////////////////////////////////////////////////////
|
|
118
|
-
// Booleans
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Checks if the element is either inside the Selector Area (as a reachable child or touching the area)
|
|
122
|
-
* @param elementRect - slight performance improvements when passed
|
|
123
|
-
*/
|
|
124
|
-
public isInside = (element: E, elementRect?: DSBoundingRect) => {
|
|
125
|
-
if (
|
|
126
|
-
this.DS.Area.HTMLNode.contains(element) &&
|
|
127
|
-
this.DS.stores.ScrollStore.canScroll
|
|
128
|
-
)
|
|
129
|
-
return true
|
|
130
|
-
return isCollision(
|
|
131
|
-
this.rect,
|
|
132
|
-
elementRect || element.getBoundingClientRect()
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** checks if the click was triggered on the area. */
|
|
137
|
-
public isClicked(event?: DSEvent) {
|
|
138
|
-
const {
|
|
139
|
-
stores: { PointerStore },
|
|
140
|
-
} = this.DS
|
|
141
|
-
|
|
142
|
-
const initialVal = event
|
|
143
|
-
? PointerStore.getPointerPosition(event)
|
|
144
|
-
: PointerStore.initialVal
|
|
145
|
-
|
|
146
|
-
return isCollision(
|
|
147
|
-
{
|
|
148
|
-
left: initialVal.x,
|
|
149
|
-
top: initialVal.y,
|
|
150
|
-
right: initialVal.x,
|
|
151
|
-
bottom: initialVal.y,
|
|
152
|
-
},
|
|
153
|
-
this.rect
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public get rect() {
|
|
158
|
-
if (this._rect) return this._rect
|
|
159
|
-
return (this._rect = this.HTMLNode.getBoundingClientRect())
|
|
160
|
-
}
|
|
161
|
-
}
|
package/src/stores/KeyStore.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import DragSelect from '../DragSelect'
|
|
2
|
-
import PubSub from '../modules/PubSub'
|
|
3
|
-
import { DSInputElement, Settings } from '../types'
|
|
4
|
-
|
|
5
|
-
export type DSKeyStorePublishEventNames = "KeyStore:down:pre"|"KeyStore:down"|"KeyStore:up:pre"|"KeyStore:up"
|
|
6
|
-
|
|
7
|
-
export type DSKeyStorePublishEventData = {
|
|
8
|
-
event: KeyboardEvent;
|
|
9
|
-
/** Pressed key (lowercase) */
|
|
10
|
-
key: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type DSKeyStorePublish = {
|
|
14
|
-
[K in DSKeyStorePublishEventNames]: DSKeyStorePublishEventData
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type KeyMapping = { [key in 'control'|'shift'|'meta']: 'ctrlKey'|'shiftKey'|'metaKey' }
|
|
18
|
-
|
|
19
|
-
export default class KeyStore<E extends DSInputElement> {
|
|
20
|
-
private _currentValues = new Set<string>()
|
|
21
|
-
private _keyMapping: KeyMapping = {
|
|
22
|
-
control: 'ctrlKey',
|
|
23
|
-
shift: 'shiftKey',
|
|
24
|
-
meta: 'metaKey',
|
|
25
|
-
}
|
|
26
|
-
private DS: DragSelect<E>
|
|
27
|
-
private PS: PubSub<E>
|
|
28
|
-
private settings: Required<Settings<E>>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @class KeyStore
|
|
32
|
-
* @constructor KeyStore
|
|
33
|
-
* @ignore
|
|
34
|
-
*/
|
|
35
|
-
constructor({ DS, PS }: { DS: DragSelect<E>, PS: PubSub<E> }) {
|
|
36
|
-
this.DS = DS
|
|
37
|
-
this.PS = PS
|
|
38
|
-
this.settings = this.DS.stores.SettingsStore.s
|
|
39
|
-
this.PS.subscribe('Interaction:init', this.init)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private init = () => {
|
|
43
|
-
document.addEventListener('keydown', this.keydown)
|
|
44
|
-
document.addEventListener('keyup', this.keyup)
|
|
45
|
-
window.addEventListener('blur', this.reset)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private keydown = (event: KeyboardEvent) => {
|
|
49
|
-
if(!event.key?.toLocaleLowerCase) return
|
|
50
|
-
const key = event.key.toLowerCase()
|
|
51
|
-
this.PS.publish('KeyStore:down:pre', { event, key })
|
|
52
|
-
this._currentValues.add(key)
|
|
53
|
-
this.PS.publish('KeyStore:down', { event, key })
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private keyup = (event: KeyboardEvent) => {
|
|
57
|
-
if(!event.key?.toLocaleLowerCase) return
|
|
58
|
-
const key = event.key.toLowerCase()
|
|
59
|
-
this.PS.publish('KeyStore:up:pre', { event, key })
|
|
60
|
-
this._currentValues.delete(key)
|
|
61
|
-
this.PS.publish('KeyStore:up', { event, key })
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public stop = () => {
|
|
65
|
-
document.removeEventListener('keydown', this.keydown)
|
|
66
|
-
document.removeEventListener('keyup', this.reset)
|
|
67
|
-
window.removeEventListener('blur', this.reset)
|
|
68
|
-
this.reset()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private reset = () => this._currentValues.clear()
|
|
72
|
-
|
|
73
|
-
public isMultiSelectKeyPressed(event?: KeyboardEvent|MouseEvent|PointerEvent|TouchEvent) {
|
|
74
|
-
if(this.settings.multiSelectMode) return true
|
|
75
|
-
|
|
76
|
-
const multiSelectKeys = this.settings.multiSelectKeys?.map(
|
|
77
|
-
(key) => key.toLocaleLowerCase() as keyof KeyMapping
|
|
78
|
-
) ?? []
|
|
79
|
-
|
|
80
|
-
if (this.currentValues.some((key) => multiSelectKeys.includes(key as keyof KeyMapping)))
|
|
81
|
-
return true
|
|
82
|
-
|
|
83
|
-
if (event && multiSelectKeys.some((key) => event[this._keyMapping[key]]))
|
|
84
|
-
return true
|
|
85
|
-
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public get currentValues() {
|
|
90
|
-
return Array.from(this._currentValues.values())
|
|
91
|
-
}
|
|
92
|
-
}
|