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,27 +0,0 @@
|
|
|
1
|
-
import { DSBoundingRect, DSEdges, Vect2 } from '../types'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
elementRect: DSBoundingRect
|
|
5
|
-
containerRect: DSBoundingRect
|
|
6
|
-
tolerance?: Vect2
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Returns the edges that an element is overflowing
|
|
11
|
-
*/
|
|
12
|
-
export const getOverflowEdges = ({
|
|
13
|
-
elementRect,
|
|
14
|
-
containerRect,
|
|
15
|
-
tolerance = {
|
|
16
|
-
x: 0,
|
|
17
|
-
y: 0,
|
|
18
|
-
},
|
|
19
|
-
}: Props): DSEdges => {
|
|
20
|
-
const edges: DSEdges = []
|
|
21
|
-
if (elementRect.top - tolerance.y < containerRect.top) edges.push('top')
|
|
22
|
-
if (elementRect.left - tolerance.x < containerRect.left) edges.push('left')
|
|
23
|
-
if (elementRect.bottom + tolerance.y > containerRect.bottom)
|
|
24
|
-
edges.push('bottom')
|
|
25
|
-
if (elementRect.right + tolerance.y > containerRect.right) edges.push('right')
|
|
26
|
-
return edges
|
|
27
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import SelectableSet from '../modules/SelectableSet'
|
|
2
|
-
import SelectedSet from '../modules/SelectedSet'
|
|
3
|
-
import { DSBoundingRect, DSInputElement } from '../types'
|
|
4
|
-
|
|
5
|
-
// @TODO: calculate the difference in all directions based on the mouse position! (since the selection square ratio won’t change we don’t have to re-calculate and re-fetch the position of every element in the square during drag)
|
|
6
|
-
|
|
7
|
-
/** Returns the compound bounding rect of multiple elements */
|
|
8
|
-
export const getSelectionRect = <E extends DSInputElement>(SelectedSet: SelectedSet<E>): DSBoundingRect => {
|
|
9
|
-
const rect = {
|
|
10
|
-
top: Number.POSITIVE_INFINITY,
|
|
11
|
-
left: Number.POSITIVE_INFINITY,
|
|
12
|
-
bottom: Number.NEGATIVE_INFINITY,
|
|
13
|
-
right: Number.NEGATIVE_INFINITY,
|
|
14
|
-
width: Number.NEGATIVE_INFINITY,
|
|
15
|
-
height: Number.NEGATIVE_INFINITY,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
SelectedSet.rects.forEach(elementRect => {
|
|
19
|
-
rect.top = Math.min(rect.top, elementRect.top || rect.top)
|
|
20
|
-
rect.left = Math.min(rect.left, elementRect.left || rect.left)
|
|
21
|
-
rect.bottom = Math.max(rect.bottom, elementRect.bottom || rect.bottom)
|
|
22
|
-
rect.right = Math.max(rect.right, elementRect.right || rect.right)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
rect.height = rect.bottom - rect.top
|
|
26
|
-
rect.width = rect.right - rect.left
|
|
27
|
-
|
|
28
|
-
return rect
|
|
29
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { DSBoundingRect, Vect2 } from "../types"
|
|
2
|
-
|
|
3
|
-
type Params = {
|
|
4
|
-
scrollAmount: Vect2
|
|
5
|
-
initialPointerPos: Vect2
|
|
6
|
-
pointerPos: Vect2
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Reliably returns the exact x,y,w,h positions of the selector element */
|
|
10
|
-
export const getSelectorPosition = ({ scrollAmount, initialPointerPos, pointerPos }: Params) => {
|
|
11
|
-
/** check for direction
|
|
12
|
-
*
|
|
13
|
-
* This is quite complicated, so also quite complicated to explain. Lemme’ try:
|
|
14
|
-
*
|
|
15
|
-
* Problem #1:
|
|
16
|
-
* Sadly in HTML we can not have negative sizes.
|
|
17
|
-
* so if we want to scale our element 10px to the right then it is easy,
|
|
18
|
-
* we just have to add +10px to the width. But if we want to scale the element
|
|
19
|
-
* -10px to the left then things become more complicated, we have to move
|
|
20
|
-
* the element -10px to the left on the x axis and also scale the element
|
|
21
|
-
* by +10px width to fake a negative sizing.
|
|
22
|
-
*
|
|
23
|
-
* One solution to this problem is using css-transforms scale() with
|
|
24
|
-
* transform-origin of top left. BUT we can’t use this since it will size
|
|
25
|
-
* everything, then when your element has a border for example, the border will
|
|
26
|
-
* get inanely huge. Also transforms are not widely supported in IE.
|
|
27
|
-
*
|
|
28
|
-
* Example #1:
|
|
29
|
-
* Unfortunately, things get even more complicated when we are inside a scroll-able
|
|
30
|
-
* DIV. Then, let’s say we scroll to the right by 10px and move the cursor right by 5px in our
|
|
31
|
-
* checks we have to subtract 10px from the initialcursor position in our check
|
|
32
|
-
* (since the initial position is moved to the left by 10px) so in our example:
|
|
33
|
-
* 1. pointerPos.x (5) > initialPointerPos.x (0) - scrollAmount.x (10) === 5 > -10 === true
|
|
34
|
-
* then set the x position to the cursors start position
|
|
35
|
-
* selectorPos.x = initialPointerPos.x (0) - scrollAmount.x (10) === 10 // 2.
|
|
36
|
-
* then we can calculate the elements width, which is
|
|
37
|
-
* the new cursor position minus the initial one plus the scroll amount, so in our example:
|
|
38
|
-
* 3. selectorPos.w = pointerPos.x (5) - initialPointerPos.x (0) + scrollAmount.x (10) === 15;
|
|
39
|
-
*
|
|
40
|
-
* let’s say after that movement we now scroll 20px to the left and move our cursor by 30px to the left:
|
|
41
|
-
* 1b. pointerPos.x (-30) > initialPointerPos.x (0) - scrollAmount.x (-20) === -30 < --20 === -30 < +20 === false;
|
|
42
|
-
* 2b. selectorPos.x = pointerPos.x (-30) === -30; move left position to cursor (for more info see Problem #1)
|
|
43
|
-
* 3b. selectorPos.w = initialPointerPos.x (0) - pointerPos.x (-30) - scrollAmount.x (-20) === 0--30--20 === 0+30+20 === 50; // scale width to original left position (for more info see Problem #1)
|
|
44
|
-
*
|
|
45
|
-
* same thing has to be done for top/bottom
|
|
46
|
-
*
|
|
47
|
-
* I hope that makes sense. Try stuff out and play around with variables to get a hang of it.
|
|
48
|
-
*/
|
|
49
|
-
const selectorPos: Partial<DSBoundingRect> = {}
|
|
50
|
-
|
|
51
|
-
// right
|
|
52
|
-
if (pointerPos.x > initialPointerPos.x - scrollAmount.x) {
|
|
53
|
-
// 1.
|
|
54
|
-
selectorPos.left = initialPointerPos.x - scrollAmount.x // 2.
|
|
55
|
-
selectorPos.width = pointerPos.x - initialPointerPos.x + scrollAmount.x // 3.
|
|
56
|
-
// left
|
|
57
|
-
} else {
|
|
58
|
-
// 1b.
|
|
59
|
-
selectorPos.left = pointerPos.x // 2b.
|
|
60
|
-
selectorPos.width = initialPointerPos.x - pointerPos.x - scrollAmount.x // 3b.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// bottom
|
|
64
|
-
if (pointerPos.y > initialPointerPos.y - scrollAmount.y) {
|
|
65
|
-
selectorPos.top = initialPointerPos.y - scrollAmount.y
|
|
66
|
-
selectorPos.height = pointerPos.y - initialPointerPos.y + scrollAmount.y
|
|
67
|
-
// top
|
|
68
|
-
} else {
|
|
69
|
-
selectorPos.top = pointerPos.y
|
|
70
|
-
selectorPos.height = initialPointerPos.y - pointerPos.y - scrollAmount.y
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return selectorPos
|
|
74
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getStylePosition } from './getStylePosition'
|
|
6
|
-
|
|
7
|
-
describe('getStylePosition', () => {
|
|
8
|
-
describe('top/left', () => {
|
|
9
|
-
it('returns the simple styles', async () => {
|
|
10
|
-
document.body.innerHTML = /*html*/ `
|
|
11
|
-
<div id="test" style="top:1px; left:2px"></div>
|
|
12
|
-
`
|
|
13
|
-
const element = document.getElementById('test') as HTMLElement
|
|
14
|
-
const position = getStylePosition(element)
|
|
15
|
-
|
|
16
|
-
expect(position).toMatchObject({
|
|
17
|
-
x: 2,
|
|
18
|
-
y: 1,
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('falls back to computed styles when set but not defined', async () => {
|
|
23
|
-
document.body.innerHTML = /*html*/ `
|
|
24
|
-
<style>#test { top: 3px; left: 4px }</style>
|
|
25
|
-
<div id="test"></div>
|
|
26
|
-
`
|
|
27
|
-
const element = document.getElementById('test') as HTMLElement
|
|
28
|
-
const position = getStylePosition(element)
|
|
29
|
-
|
|
30
|
-
expect(position).toMatchObject({
|
|
31
|
-
x: 4,
|
|
32
|
-
y: 3,
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('falls back to computed styles when not set', async () => {
|
|
37
|
-
document.body.innerHTML = /*html*/ `<div id="test"></div>`
|
|
38
|
-
const element = document.getElementById('test') as HTMLElement
|
|
39
|
-
const position = getStylePosition(element)
|
|
40
|
-
expect(position).toMatchObject({
|
|
41
|
-
x: 0,
|
|
42
|
-
y: 0,
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
describe('translate/3d', () => {
|
|
48
|
-
it('gets the simple styles', async () => {
|
|
49
|
-
document.body.innerHTML = /*html*/ `
|
|
50
|
-
<div id="test" style="transform: translate(5px, 6px) rotate(45deg)"></div>
|
|
51
|
-
`
|
|
52
|
-
const element = document.getElementById('test') as HTMLElement
|
|
53
|
-
const position = getStylePosition(element, true)
|
|
54
|
-
|
|
55
|
-
expect(position).toMatchObject({
|
|
56
|
-
x: 5,
|
|
57
|
-
y: 6,
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('gets the simple 3d styles', async () => {
|
|
62
|
-
document.body.innerHTML = /*html*/ `
|
|
63
|
-
<div id="test" style="transform: translate3d(7px, 8px, 0) scale(1.5)"></div>
|
|
64
|
-
`
|
|
65
|
-
const element = document.getElementById('test') as HTMLElement
|
|
66
|
-
const position = getStylePosition(element, true)
|
|
67
|
-
|
|
68
|
-
expect(position).toMatchObject({
|
|
69
|
-
x: 7,
|
|
70
|
-
y: 8,
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('falls back to computed styles', async () => {
|
|
75
|
-
// computed transforms are translated to a matrix. Jest Dom does not do that conversion, so we do it manually here
|
|
76
|
-
document.body.innerHTML = /*html*/ `
|
|
77
|
-
<style>#test { transform: matrix(1, 0.267949, 0.267949, 1, 9, 10) }</style>
|
|
78
|
-
<div id="test"></div>
|
|
79
|
-
`
|
|
80
|
-
const element = document.getElementById('test') as HTMLElement
|
|
81
|
-
const position = getStylePosition(element, true)
|
|
82
|
-
|
|
83
|
-
expect(position).toMatchObject({
|
|
84
|
-
x: 9,
|
|
85
|
-
y: 10,
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('falls back to computed 3d styles', async () => {
|
|
90
|
-
// computed transforms are translated to a matrix. Jest Dom does not do that conversion, so we do it manually here
|
|
91
|
-
document.body.innerHTML = /*html*/ `
|
|
92
|
-
<style>#test { transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 11, 12, 1, 1) }</style>
|
|
93
|
-
<div id="test"></div>
|
|
94
|
-
`
|
|
95
|
-
const element = document.getElementById('test') as HTMLElement
|
|
96
|
-
const position = getStylePosition(element, true)
|
|
97
|
-
|
|
98
|
-
expect(position).toMatchObject({
|
|
99
|
-
x: 11,
|
|
100
|
-
y: 12,
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('falls back to computed styles when not set', async () => {
|
|
105
|
-
document.body.innerHTML = /*html*/ `<div id="test"></div>`
|
|
106
|
-
const element = document.getElementById('test') as HTMLElement
|
|
107
|
-
const position = getStylePosition(element, true)
|
|
108
|
-
expect(position).toMatchObject({
|
|
109
|
-
x: 0,
|
|
110
|
-
y: 0,
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
})
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { DSInputElement, Vect2 } from "../types"
|
|
2
|
-
|
|
3
|
-
const getComputedTranslatePositions = <E extends DSInputElement>(element: E) => {
|
|
4
|
-
const position = {
|
|
5
|
-
x: 0,
|
|
6
|
-
y: 0,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const computed = window.getComputedStyle(element)
|
|
10
|
-
if (!computed.transform || computed.transform === 'none') return position
|
|
11
|
-
|
|
12
|
-
if (computed.transform.indexOf('3d') >= 0) {
|
|
13
|
-
const match = computed.transform.trim().match(/matrix3d\((.*?)\)/)
|
|
14
|
-
if (match && match.length) {
|
|
15
|
-
const values = match[1]?.split(',')
|
|
16
|
-
position.x = parseInt(values[12]) || 0
|
|
17
|
-
position.y = parseInt(values[13]) || 0
|
|
18
|
-
}
|
|
19
|
-
return position
|
|
20
|
-
}
|
|
21
|
-
const match = computed.transform.trim().match(/matrix\((.*?)\)/)
|
|
22
|
-
if (match && match.length) {
|
|
23
|
-
const values = match[1]?.split(',')
|
|
24
|
-
position.x = parseInt(values[4]) || 0
|
|
25
|
-
position.y = parseInt(values[5]) || 0
|
|
26
|
-
}
|
|
27
|
-
return position
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const getTranslatedPositions = <E extends DSInputElement>(element: E) => {
|
|
31
|
-
const { transform } = element.style
|
|
32
|
-
|
|
33
|
-
if (!transform || transform.indexOf('translate') < 0)
|
|
34
|
-
return getComputedTranslatePositions(element)
|
|
35
|
-
|
|
36
|
-
const position = {
|
|
37
|
-
x: 0,
|
|
38
|
-
y: 0,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const match = transform.trim().match(/translate[3dD]*?\(.*?\)/)
|
|
42
|
-
if (match) {
|
|
43
|
-
const split = match[0]?.split('(')
|
|
44
|
-
if (split) {
|
|
45
|
-
const values = split[1]?.split(',')
|
|
46
|
-
position.x = parseInt(values[0]) || 0
|
|
47
|
-
position.y = parseInt(values[1]) || 0
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!position.x && !position.x) return getComputedTranslatePositions(element)
|
|
52
|
-
|
|
53
|
-
return position
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const getTopLeftPosition = <E extends DSInputElement>(element: E) => {
|
|
57
|
-
const { style } = element
|
|
58
|
-
|
|
59
|
-
const position = {
|
|
60
|
-
x: parseInt(style.left) || 0,
|
|
61
|
-
y: parseInt(style.top) || 0,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// initial positions
|
|
65
|
-
if (!position.x && !position.x) {
|
|
66
|
-
const computed = window.getComputedStyle(element)
|
|
67
|
-
return {
|
|
68
|
-
x: parseInt(computed.left) || 0,
|
|
69
|
-
y: parseInt(computed.top) || 0,
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return position
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Returns the X and Y coordinates based on styles
|
|
78
|
-
* Can handle translate and top/left
|
|
79
|
-
*/
|
|
80
|
-
export const getStylePosition = <E extends DSInputElement>(element: E, useTranslate?: boolean): Vect2 => {
|
|
81
|
-
if (useTranslate) return getTranslatedPositions(element)
|
|
82
|
-
return getTopLeftPosition(element)
|
|
83
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { DSArea } from "../types"
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
computedStyle: CSSStyleDeclaration
|
|
5
|
-
node: DSArea
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** Fix: some elements have to have a special position attribute for calculations */
|
|
9
|
-
export const handleElementPositionAttribute = ({ computedStyle, node }: Props) => {
|
|
10
|
-
const { position } = computedStyle
|
|
11
|
-
const isPositioned =
|
|
12
|
-
position === 'absolute' || position === 'relative' || position === 'fixed'
|
|
13
|
-
if (!(node instanceof Document) && !isPositioned)
|
|
14
|
-
node.style.position = 'relative'
|
|
15
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { DSDragKeys, DSEdges, Vect2 } from "../types"
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
/** The keyboard key that was pressed */
|
|
5
|
-
key: string
|
|
6
|
-
shiftKey: boolean
|
|
7
|
-
keyboardDragSpeed: number
|
|
8
|
-
zoom: number
|
|
9
|
-
scrollDiff: Vect2
|
|
10
|
-
dragKeys?: DSDragKeys
|
|
11
|
-
}
|
|
12
|
-
export const handleKeyboardDragPosDifference = ({
|
|
13
|
-
shiftKey,
|
|
14
|
-
keyboardDragSpeed,
|
|
15
|
-
zoom,
|
|
16
|
-
key,
|
|
17
|
-
dragKeys,
|
|
18
|
-
scrollDiff,
|
|
19
|
-
}: Props): Vect2 => {
|
|
20
|
-
const posDirection = { x: 0, y: 0 }
|
|
21
|
-
const increase = shiftKey
|
|
22
|
-
? keyboardDragSpeed * 4 * zoom
|
|
23
|
-
: keyboardDragSpeed * zoom
|
|
24
|
-
|
|
25
|
-
if (dragKeys?.left.includes(key))
|
|
26
|
-
posDirection.x = scrollDiff.x || -increase
|
|
27
|
-
if (dragKeys?.right.includes(key))
|
|
28
|
-
posDirection.x = scrollDiff.x || increase
|
|
29
|
-
if (dragKeys?.up.includes(key))
|
|
30
|
-
posDirection.y = scrollDiff.y || -increase
|
|
31
|
-
if (dragKeys?.down.includes(key))
|
|
32
|
-
posDirection.y = scrollDiff.y || increase
|
|
33
|
-
|
|
34
|
-
return posDirection
|
|
35
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import SelectedSet from "../modules/SelectedSet"
|
|
2
|
-
import { DSInputElement } from "../types"
|
|
3
|
-
|
|
4
|
-
type Props<E extends DSInputElement> = {
|
|
5
|
-
element: E
|
|
6
|
-
force?: boolean
|
|
7
|
-
multiSelectionToggle: boolean
|
|
8
|
-
SelectedSet: SelectedSet<E>
|
|
9
|
-
hoverClassName: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Logic when an element is selected */
|
|
13
|
-
export const handleSelection = <E extends DSInputElement>({
|
|
14
|
-
element,
|
|
15
|
-
force,
|
|
16
|
-
multiSelectionToggle,
|
|
17
|
-
SelectedSet,
|
|
18
|
-
hoverClassName,
|
|
19
|
-
}: Props<E>) => {
|
|
20
|
-
if (element.classList.contains(hoverClassName) && !force) return
|
|
21
|
-
|
|
22
|
-
if (!SelectedSet.has(element)) SelectedSet.add(element)
|
|
23
|
-
else if (multiSelectionToggle) SelectedSet.delete(element)
|
|
24
|
-
|
|
25
|
-
element.classList.add(hoverClassName)
|
|
26
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import SelectedSet from "../modules/SelectedSet"
|
|
2
|
-
import { DSInputElement } from "../types"
|
|
3
|
-
|
|
4
|
-
type Props<E extends DSInputElement> = {
|
|
5
|
-
element: E
|
|
6
|
-
force?: boolean
|
|
7
|
-
SelectedSet: SelectedSet<E>
|
|
8
|
-
PrevSelectedSet: Set<E>
|
|
9
|
-
hoverClassName: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Logic when an element is de-selected */
|
|
13
|
-
export const handleUnSelection = <E extends DSInputElement>({
|
|
14
|
-
element,
|
|
15
|
-
force,
|
|
16
|
-
SelectedSet,
|
|
17
|
-
PrevSelectedSet,
|
|
18
|
-
hoverClassName,
|
|
19
|
-
}: Props<E>) => {
|
|
20
|
-
if (!element.classList.contains(hoverClassName) && !force) return
|
|
21
|
-
|
|
22
|
-
const inSelection = SelectedSet.has(element)
|
|
23
|
-
const inPrevSelection = PrevSelectedSet.has(element)
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Special for issue #9.
|
|
27
|
-
* if a multi-select-key is pressed, ds 'remembers' the last selection and reverts
|
|
28
|
-
* to that state if the selection is not kept, to mimic the natural OS behaviour
|
|
29
|
-
* = if item was selected and is not in selection anymore, reselect it
|
|
30
|
-
* = if item was not selected and is not in selection anymore, unselect it
|
|
31
|
-
*/
|
|
32
|
-
if (inSelection && !inPrevSelection) SelectedSet.delete(element)
|
|
33
|
-
else if (!inSelection && inPrevSelection) SelectedSet.add(element)
|
|
34
|
-
|
|
35
|
-
element.classList.remove(hoverClassName)
|
|
36
|
-
}
|