dragselect 2.4.3 → 2.4.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.
- package/CHANGELOG.md +4 -0
- package/README.md +24 -11
- package/deploying.md +1 -1
- package/dist/DragSelect.es6m.js +64 -28
- package/dist/DragSelect.js +64 -28
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/methods/getAllParentNodes.d.ts +46 -0
- package/dist/methods/getPointerPos.d.ts +1 -1
- package/dist/modules/DropZone.d.ts +131 -0
- package/dist/modules/DropZones.d.ts +119 -0
- package/dist/modules/Interaction.d.ts +1 -0
- package/dist/modules/SelectableSet.d.ts +1 -0
- package/dist/modules/Selector.d.ts +1 -1
- package/dist/modules/SelectorArea.d.ts +1 -1
- package/dist/stores/KeyStore.d.ts +2 -2
- package/dist/stores/PointerStore.d.ts +2 -1
- package/dist/types.d.ts +6 -2
- package/package.json +6 -6
- package/rollup.config.js +1 -1
- package/src/methods/getPointerPos.js +1 -1
- package/src/methods/hydrateSettings.js +1 -0
- package/src/modules/Interaction.js +32 -7
- package/src/modules/SelectableSet.js +23 -8
- package/src/stores/KeyStore.js +1 -1
- package/src/stores/PointerStore.js +17 -3
- package/src/types.js +3 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export default class DropZone {
|
|
2
|
+
/**
|
|
3
|
+
* @constructor Drag
|
|
4
|
+
* @param {Object} obj
|
|
5
|
+
* @param {DragSelect} obj.DS
|
|
6
|
+
* @param {string} obj.id
|
|
7
|
+
* @param {DSElement} obj.element
|
|
8
|
+
* @param {DSInputElements} obj.droppables
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
constructor({ DS, id, element, droppables }: {
|
|
12
|
+
DS: DragSelect;
|
|
13
|
+
id: string;
|
|
14
|
+
element: DSElement;
|
|
15
|
+
droppables: DSInputElements;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* @type {string}
|
|
19
|
+
*/
|
|
20
|
+
id: string;
|
|
21
|
+
/**
|
|
22
|
+
* @type {DSElement}
|
|
23
|
+
*/
|
|
24
|
+
element: DSElement;
|
|
25
|
+
/**
|
|
26
|
+
* @type {DSElements}
|
|
27
|
+
*/
|
|
28
|
+
droppables: DSElements;
|
|
29
|
+
/**
|
|
30
|
+
* @type {DOMRect}
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private _rect;
|
|
34
|
+
/**
|
|
35
|
+
* @type {{cleanup:()=>void}}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
private _observers;
|
|
39
|
+
/**
|
|
40
|
+
* @type {NodeJS.Timeout}
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private _timeout;
|
|
44
|
+
/**
|
|
45
|
+
* @type {DSElements}
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private _itemsDropped;
|
|
49
|
+
/**
|
|
50
|
+
* @type {DSElements}
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private _itemsInside;
|
|
54
|
+
DS: DragSelect;
|
|
55
|
+
Settings: Settings;
|
|
56
|
+
/**
|
|
57
|
+
* @param {'add'|'remove'} action
|
|
58
|
+
*/
|
|
59
|
+
setReadyClasses: (action: 'add' | 'remove') => void;
|
|
60
|
+
/**
|
|
61
|
+
* This zone is NOT the target of a drop
|
|
62
|
+
*/
|
|
63
|
+
handleNoDrop: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* This zone IS the target of a drop
|
|
66
|
+
*/
|
|
67
|
+
handleDrop: () => void;
|
|
68
|
+
handleItemsInsideClasses: () => void;
|
|
69
|
+
start: ({ isDragging }: {
|
|
70
|
+
isDragging: any;
|
|
71
|
+
}) => void;
|
|
72
|
+
stop: ({ isDragging }: {
|
|
73
|
+
isDragging: any;
|
|
74
|
+
}) => void;
|
|
75
|
+
destroy(): void;
|
|
76
|
+
isDestroyed: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* @returns {DSDropZone}
|
|
79
|
+
*/
|
|
80
|
+
toObject: () => DSDropZone;
|
|
81
|
+
get rect(): DOMRect;
|
|
82
|
+
get itemsDropped(): DSElements;
|
|
83
|
+
get itemsInside(): DSElements;
|
|
84
|
+
get parentNodes(): DSElements;
|
|
85
|
+
_parentNodes: DSElements;
|
|
86
|
+
}
|
|
87
|
+
import DragSelect from "../DragSelect";
|
|
88
|
+
import "../types"
|
|
89
|
+
import "../types"
|
|
90
|
+
import "../types"
|
|
91
|
+
import "../types"
|
|
92
|
+
import "../types"
|
|
93
|
+
import "../types"
|
|
94
|
+
import "../types"
|
|
95
|
+
import "../types"
|
|
96
|
+
import "../types"
|
|
97
|
+
import "../types"
|
|
98
|
+
import "../types"
|
|
99
|
+
import "../types"
|
|
100
|
+
import "../types"
|
|
101
|
+
import "../types"
|
|
102
|
+
import "../types"
|
|
103
|
+
import "../types"
|
|
104
|
+
import "../types"
|
|
105
|
+
import "../types"
|
|
106
|
+
import "../types"
|
|
107
|
+
import "../types"
|
|
108
|
+
import "../types"
|
|
109
|
+
import "../types"
|
|
110
|
+
import "../types"
|
|
111
|
+
import "../types"
|
|
112
|
+
import "../types"
|
|
113
|
+
import "../types"
|
|
114
|
+
import "../types"
|
|
115
|
+
import "../types"
|
|
116
|
+
import "../types"
|
|
117
|
+
import "../types"
|
|
118
|
+
import "../types"
|
|
119
|
+
import "../types"
|
|
120
|
+
import "../types"
|
|
121
|
+
import "../types"
|
|
122
|
+
import "../types"
|
|
123
|
+
import "../types"
|
|
124
|
+
import "../types"
|
|
125
|
+
import "../types"
|
|
126
|
+
import "../types"
|
|
127
|
+
import "../types"
|
|
128
|
+
import "../types"
|
|
129
|
+
import "../types"
|
|
130
|
+
import "../types"
|
|
131
|
+
import "../types"
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export default class DropZones {
|
|
2
|
+
/**
|
|
3
|
+
* @constructor Drag
|
|
4
|
+
* @param {{DS:DragSelect}} obj
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
constructor({ DS }: {
|
|
8
|
+
DS: DragSelect;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Get the drop zone by the zone element
|
|
12
|
+
* @type {Map<DSElement, DropZone>}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
private _zoneByElement;
|
|
16
|
+
/**
|
|
17
|
+
* Get the drop zone by the zone id
|
|
18
|
+
* @type {Map<string, DropZone>}
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
private _zoneById;
|
|
22
|
+
/**
|
|
23
|
+
* Get the drop zones by one zone item
|
|
24
|
+
* @type {Map<DSElement,DropZone[]>}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private _zonesByDroppable;
|
|
28
|
+
/**
|
|
29
|
+
* Get the drop zones by one zone item
|
|
30
|
+
* @type {DropZone[]}
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private _zones;
|
|
34
|
+
DS: DragSelect;
|
|
35
|
+
Settings: Settings;
|
|
36
|
+
/**
|
|
37
|
+
* @param {Object} obj
|
|
38
|
+
* @param {DSDropZone[]} [obj.dropZones]
|
|
39
|
+
*/
|
|
40
|
+
setDropZones: ({ dropZones }: {
|
|
41
|
+
dropZones?: DSDropZone[];
|
|
42
|
+
}) => void;
|
|
43
|
+
_handleDrop: (target: any) => void;
|
|
44
|
+
/**
|
|
45
|
+
* @param {DSElements} elements
|
|
46
|
+
* @param {Vect2} point
|
|
47
|
+
* @returns {DropZone|undefined}
|
|
48
|
+
*/
|
|
49
|
+
_getZoneByElementsFromPoint: (elements: DSElements, { x, y }: Vect2) => DropZone | undefined;
|
|
50
|
+
start: ({ isDragging }: {
|
|
51
|
+
isDragging: any;
|
|
52
|
+
}) => void;
|
|
53
|
+
stop: ({ isDragging }: {
|
|
54
|
+
isDragging: any;
|
|
55
|
+
}) => void;
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} zoneId
|
|
58
|
+
* @returns {DSElements|void}
|
|
59
|
+
*/
|
|
60
|
+
getItemsDroppedById: (zoneId: string) => DSElements | void;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} zoneId
|
|
63
|
+
* @param {boolean} addClasses
|
|
64
|
+
* @returns {DSElements|void}
|
|
65
|
+
*/
|
|
66
|
+
getItemsInsideById: (zoneId: string, addClasses: boolean) => DSElements | void;
|
|
67
|
+
/**
|
|
68
|
+
* Returns first DropsZone under current pointer
|
|
69
|
+
* @param {Vect2} [coordinates]
|
|
70
|
+
* @returns {DropZone | undefined}
|
|
71
|
+
*/
|
|
72
|
+
getTarget: (coordinates?: Vect2) => DropZone | undefined;
|
|
73
|
+
}
|
|
74
|
+
import DragSelect from "../DragSelect";
|
|
75
|
+
import DropZone from "./DropZone";
|
|
76
|
+
import "../types"
|
|
77
|
+
import "../types"
|
|
78
|
+
import "../types"
|
|
79
|
+
import "../types"
|
|
80
|
+
import "../types"
|
|
81
|
+
import "../types"
|
|
82
|
+
import "../types"
|
|
83
|
+
import "../types"
|
|
84
|
+
import "../types"
|
|
85
|
+
import "../types"
|
|
86
|
+
import "../types"
|
|
87
|
+
import "../types"
|
|
88
|
+
import "../types"
|
|
89
|
+
import "../types"
|
|
90
|
+
import "../types"
|
|
91
|
+
import "../types"
|
|
92
|
+
import "../types"
|
|
93
|
+
import "../types"
|
|
94
|
+
import "../types"
|
|
95
|
+
import "../types"
|
|
96
|
+
import "../types"
|
|
97
|
+
import "../types"
|
|
98
|
+
import "../types"
|
|
99
|
+
import "../types"
|
|
100
|
+
import "../types"
|
|
101
|
+
import "../types"
|
|
102
|
+
import "../types"
|
|
103
|
+
import "../types"
|
|
104
|
+
import "../types"
|
|
105
|
+
import "../types"
|
|
106
|
+
import "../types"
|
|
107
|
+
import "../types"
|
|
108
|
+
import "../types"
|
|
109
|
+
import "../types"
|
|
110
|
+
import "../types"
|
|
111
|
+
import "../types"
|
|
112
|
+
import "../types"
|
|
113
|
+
import "../types"
|
|
114
|
+
import "../types"
|
|
115
|
+
import "../types"
|
|
116
|
+
import "../types"
|
|
117
|
+
import "../types"
|
|
118
|
+
import "../types"
|
|
119
|
+
import "../types"
|
|
@@ -26,8 +26,8 @@ export default class KeyStore {
|
|
|
26
26
|
keyup: (event: KeyboardEvent) => void;
|
|
27
27
|
stop: () => void;
|
|
28
28
|
reset: () => void;
|
|
29
|
-
/** @param {KeyboardEvent|MouseEvent|TouchEvent} [event] */
|
|
30
|
-
isMultiSelectKeyPressed(event?: KeyboardEvent | MouseEvent | TouchEvent): boolean;
|
|
29
|
+
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
|
|
30
|
+
isMultiSelectKeyPressed(event?: KeyboardEvent | MouseEvent | PointerEvent | TouchEvent): boolean;
|
|
31
31
|
get currentValues(): string[];
|
|
32
32
|
}
|
|
33
33
|
import DragSelect from "../DragSelect";
|
|
@@ -46,6 +46,7 @@ export default class PointerStore {
|
|
|
46
46
|
* */
|
|
47
47
|
private _lastTouch;
|
|
48
48
|
DS: DragSelect;
|
|
49
|
+
Settings: Settings;
|
|
49
50
|
init: () => void;
|
|
50
51
|
/** @param {DSEvent} [event] */
|
|
51
52
|
start(event?: DSEvent): void;
|
|
@@ -67,7 +68,7 @@ export default class PointerStore {
|
|
|
67
68
|
get lastVal(): Vect2;
|
|
68
69
|
/**
|
|
69
70
|
* @param {DSEvent} event
|
|
70
|
-
* @return {MouseEvent|Touch}
|
|
71
|
+
* @return {MouseEvent|PointerEvent|Touch}
|
|
71
72
|
* @private
|
|
72
73
|
*/
|
|
73
74
|
private _normalizedEvent;
|
package/dist/types.d.ts
CHANGED
|
@@ -66,6 +66,10 @@ type Settings = {
|
|
|
66
66
|
* Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
67
67
|
*/
|
|
68
68
|
useTransform?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
|
|
71
|
+
*/
|
|
72
|
+
usePointerEvents?: boolean;
|
|
69
73
|
/**
|
|
70
74
|
* the class assigned to the mouse hovered items
|
|
71
75
|
*/
|
|
@@ -98,7 +102,7 @@ type CallbackObject = {
|
|
|
98
102
|
/**
|
|
99
103
|
* The respective event object
|
|
100
104
|
*/
|
|
101
|
-
event?: MouseEvent | TouchEvent | KeyboardEvent | Event;
|
|
105
|
+
event?: MouseEvent | TouchEvent | PointerEvent | KeyboardEvent | Event;
|
|
102
106
|
/**
|
|
103
107
|
* The single item currently interacted with
|
|
104
108
|
*/
|
|
@@ -159,7 +163,7 @@ type DSElement = HTMLElement | SVGElement;
|
|
|
159
163
|
/**
|
|
160
164
|
* en event from a touch or mouse interaction
|
|
161
165
|
*/
|
|
162
|
-
type DSEvent = MouseEvent | TouchEvent;
|
|
166
|
+
type DSEvent = MouseEvent | TouchEvent | PointerEvent;
|
|
163
167
|
/**
|
|
164
168
|
* An array of keys that allows switching to the multi-select mode
|
|
165
169
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dragselect",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.4",
|
|
4
4
|
"description": "easy javascript drag select functionality for your projects",
|
|
5
5
|
"main": "./dist/DragSelect.js",
|
|
6
6
|
"types": "./dist/DragSelect.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"start": "npm run open & npm run watch",
|
|
11
11
|
"watch": "concurrently --kill-others \"npm run checkjs:watch\" \"npm run rollup:watch\" \"npm run test:watch\"",
|
|
12
12
|
"\n# TESTING:": "",
|
|
13
|
-
"checkjs": "tsc --lib es2019,dom -t es5 --allowJs --checkJs --noEmit src/*.js",
|
|
13
|
+
"checkjs": "tsc --lib es2019,dom -t es5 --allowJs --skipLibCheck --checkJs --noEmit src/*.js",
|
|
14
14
|
"checkjs:watch": "npm run checkjs -- -w",
|
|
15
15
|
"postcheckjs": "npm run docs && rm -rf docs",
|
|
16
16
|
"pretest": "npm run build",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"media": "cp -R .media docs/media",
|
|
24
24
|
"prerollup": "npm run types",
|
|
25
25
|
"rollup": "rollup -c",
|
|
26
|
-
"rollup:
|
|
26
|
+
"rollup:ci": "npm run rollup -- --ci",
|
|
27
27
|
"rollup:watch": "npm run rollup -- -w",
|
|
28
|
-
"types": "tsc src/DragSelect.js --lib es2019,dom -t es5 --declaration --allowJs --emitDeclarationOnly --outDir dist",
|
|
28
|
+
"types": "tsc src/DragSelect.js --lib es2019,dom -t es5 --declaration --allowJs --emitDeclarationOnly --skipLibCheck --outDir dist",
|
|
29
29
|
"\n## PROD:": "",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"ci:build": "npm run rollup:ci && npm run media && npm run docs",
|
|
31
|
+
"ci:test": "npm run test"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/cli": "^7.12.10",
|
package/rollup.config.js
CHANGED
|
@@ -74,7 +74,7 @@ export default {
|
|
|
74
74
|
{
|
|
75
75
|
name: 'copy',
|
|
76
76
|
writeBundle(options) {
|
|
77
|
-
if (!process.argv.includes('--
|
|
77
|
+
if (!process.argv.includes('--ci')) return
|
|
78
78
|
if (!fs.existsSync('docs/')) fs.mkdirSync('docs')
|
|
79
79
|
fs.copyFileSync(
|
|
80
80
|
`.v1/${path.basename(options.file)}`,
|
|
@@ -4,7 +4,7 @@ import '../types'
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns cursor x, y position based on event object
|
|
6
6
|
* @param {Object} p
|
|
7
|
-
* @param {MouseEvent|Touch} p.event
|
|
7
|
+
* @param {MouseEvent|Touch|PointerEvent} p.event
|
|
8
8
|
* @return {Vect2} cursor X/Y position
|
|
9
9
|
*/
|
|
10
10
|
export default ({ event }) => ({
|
|
@@ -101,6 +101,7 @@ export default (settings, withFallback) => ({
|
|
|
101
101
|
...hydrateHelper('dragKeys', settings.dragKeys, withFallback, { up: ['ArrowUp'], down: ['ArrowDown'], left: ['ArrowLeft'], right: ['ArrowRight'] }),
|
|
102
102
|
...hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10),
|
|
103
103
|
...hydrateHelper('useTransform', settings.useTransform, withFallback, true),
|
|
104
|
+
...hydrateHelper('usePointerEvents', settings.usePointerEvents, withFallback, false),
|
|
104
105
|
...hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover'),
|
|
105
106
|
...hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable'),
|
|
106
107
|
...hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected'),
|
|
@@ -15,6 +15,7 @@ export default class Interaction {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor({ DS }) {
|
|
17
17
|
this.DS = DS
|
|
18
|
+
this.Settings = DS.stores.SettingsStore.s
|
|
18
19
|
// @ts-ignore: @todo: update to typescript
|
|
19
20
|
this.DS.subscribe('Settings:updated:area', this.init)
|
|
20
21
|
this.DS.subscribe('PointerStore:updated', this.update)
|
|
@@ -31,7 +32,14 @@ export default class Interaction {
|
|
|
31
32
|
init = () => this.DS.publish('Interaction:init:pre', {})
|
|
32
33
|
_init = () => {
|
|
33
34
|
this.stop()
|
|
34
|
-
|
|
35
|
+
|
|
36
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
37
|
+
if (this.Settings.usePointerEvents)
|
|
38
|
+
this.DS.Area.HTMLNode.addEventListener('pointerdown', this.start, {
|
|
39
|
+
passive: false,
|
|
40
|
+
})
|
|
41
|
+
else this.DS.Area.HTMLNode.addEventListener('mousedown', this.start)
|
|
42
|
+
|
|
35
43
|
this.DS.Area.HTMLNode.addEventListener('touchstart', this.start, {
|
|
36
44
|
passive: false,
|
|
37
45
|
})
|
|
@@ -79,7 +87,12 @@ export default class Interaction {
|
|
|
79
87
|
|
|
80
88
|
this.DS.publish('Interaction:start', { event, isDragging: this.isDragging })
|
|
81
89
|
|
|
82
|
-
|
|
90
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
91
|
+
if (this.Settings.usePointerEvents) {
|
|
92
|
+
document.addEventListener('pointerup', this.reset)
|
|
93
|
+
document.addEventListener('pointercancel', this.reset)
|
|
94
|
+
} else document.addEventListener('mouseup', this.reset)
|
|
95
|
+
|
|
83
96
|
document.addEventListener('touchend', this.reset)
|
|
84
97
|
}
|
|
85
98
|
|
|
@@ -90,17 +103,17 @@ export default class Interaction {
|
|
|
90
103
|
*/
|
|
91
104
|
isDragEvent = (event) => {
|
|
92
105
|
const clickedElement = /** @type {Element} */ (event.target).closest(
|
|
93
|
-
`.${this.
|
|
106
|
+
`.${this.Settings.selectableClass}`
|
|
94
107
|
)
|
|
95
108
|
|
|
96
109
|
if (
|
|
97
|
-
!this.
|
|
110
|
+
!this.Settings.draggability ||
|
|
98
111
|
this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) ||
|
|
99
112
|
!clickedElement
|
|
100
113
|
)
|
|
101
114
|
return false
|
|
102
115
|
|
|
103
|
-
if (this.
|
|
116
|
+
if (this.Settings.immediateDrag) {
|
|
104
117
|
if (!this.DS.SelectedSet.size)
|
|
105
118
|
this.DS.SelectedSet.add(/** @type {DSElement} */ (clickedElement))
|
|
106
119
|
else if (!this.DS.SelectedSet.has(clickedElement)) {
|
|
@@ -144,12 +157,24 @@ export default class Interaction {
|
|
|
144
157
|
stop = () => {
|
|
145
158
|
this.isInteracting = false
|
|
146
159
|
this.isDragging = false
|
|
147
|
-
|
|
160
|
+
|
|
161
|
+
// @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
|
|
162
|
+
if (this.Settings.usePointerEvents) {
|
|
163
|
+
this.DS.Area.HTMLNode.removeEventListener('pointerdown', this.start, {
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
passive: false,
|
|
166
|
+
})
|
|
167
|
+
document.removeEventListener('pointerup', this.reset)
|
|
168
|
+
document.removeEventListener('pointercancel', this.reset)
|
|
169
|
+
} else {
|
|
170
|
+
this.DS.Area.HTMLNode.removeEventListener('mousedown', this.start)
|
|
171
|
+
document.removeEventListener('mouseup', this.reset)
|
|
172
|
+
}
|
|
173
|
+
|
|
148
174
|
this.DS.Area.HTMLNode.removeEventListener('touchstart', this.start, {
|
|
149
175
|
// @ts-ignore
|
|
150
176
|
passive: false,
|
|
151
177
|
})
|
|
152
|
-
document.removeEventListener('mouseup', this.reset)
|
|
153
178
|
document.removeEventListener('touchend', this.reset)
|
|
154
179
|
}
|
|
155
180
|
|
|
@@ -13,6 +13,7 @@ export default class SelectableSet extends Set {
|
|
|
13
13
|
constructor({ DS }) {
|
|
14
14
|
super()
|
|
15
15
|
this.DS = DS
|
|
16
|
+
this.Settings = DS.stores.SettingsStore.s
|
|
16
17
|
this.DS.subscribe('Interaction:init', this.init)
|
|
17
18
|
// @ts-ignore: @todo: update to typescript
|
|
18
19
|
this.DS.PubSub.subscribe('Settings:updated:selectables', () => {
|
|
@@ -29,7 +30,7 @@ export default class SelectableSet extends Set {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
init = () =>
|
|
32
|
-
toArray(this.
|
|
33
|
+
toArray(this.Settings.selectables).forEach((el) =>
|
|
33
34
|
this.add(el)
|
|
34
35
|
)
|
|
35
36
|
|
|
@@ -41,17 +42,24 @@ export default class SelectableSet extends Set {
|
|
|
41
42
|
item: element,
|
|
42
43
|
}
|
|
43
44
|
this.DS.publish('Selectable:added:pre', publishData)
|
|
44
|
-
element.classList.add(this.
|
|
45
|
+
element.classList.add(this.Settings.selectableClass)
|
|
45
46
|
element.addEventListener('click', this._onClick)
|
|
46
|
-
|
|
47
|
+
|
|
48
|
+
if (this.Settings.usePointerEvents)
|
|
49
|
+
element.addEventListener('pointerdown', this._onPointer, {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
passive: false,
|
|
52
|
+
})
|
|
53
|
+
else element.addEventListener('mousedown', this._onPointer)
|
|
54
|
+
|
|
47
55
|
element.addEventListener('touchstart', this._onPointer, {
|
|
48
56
|
// @ts-ignore
|
|
49
57
|
passive: false,
|
|
50
58
|
})
|
|
51
59
|
|
|
52
60
|
if (
|
|
53
|
-
this.
|
|
54
|
-
!this.
|
|
61
|
+
this.Settings.draggability &&
|
|
62
|
+
!this.Settings.useTransform
|
|
55
63
|
)
|
|
56
64
|
handleElementPositionAttribute({
|
|
57
65
|
computedStyle: window.getComputedStyle(element),
|
|
@@ -70,10 +78,17 @@ export default class SelectableSet extends Set {
|
|
|
70
78
|
item: element,
|
|
71
79
|
}
|
|
72
80
|
this.DS.publish('Selectable:removed:pre', publishData)
|
|
73
|
-
element.classList.remove(this.
|
|
74
|
-
element.classList.remove(this.
|
|
81
|
+
element.classList.remove(this.Settings.selectableClass)
|
|
82
|
+
element.classList.remove(this.Settings.hoverClass)
|
|
75
83
|
element.removeEventListener('click', this._onClick)
|
|
76
|
-
|
|
84
|
+
|
|
85
|
+
if (this.Settings.usePointerEvents)
|
|
86
|
+
element.removeEventListener('pointerdown', this._onPointer, {
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
passive: false,
|
|
89
|
+
})
|
|
90
|
+
else element.removeEventListener('mousedown', this._onPointer)
|
|
91
|
+
|
|
77
92
|
element.removeEventListener('touchstart', this._onPointer, {
|
|
78
93
|
// @ts-ignore
|
|
79
94
|
passive: false,
|
package/src/stores/KeyStore.js
CHANGED
|
@@ -60,7 +60,7 @@ export default class KeyStore {
|
|
|
60
60
|
|
|
61
61
|
reset = () => this._currentValues.clear()
|
|
62
62
|
|
|
63
|
-
/** @param {KeyboardEvent|MouseEvent|TouchEvent} [event] */
|
|
63
|
+
/** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */
|
|
64
64
|
isMultiSelectKeyPressed(event) {
|
|
65
65
|
if(this.DS.stores.SettingsStore.s.multiSelectMode) return true
|
|
66
66
|
const multiSelectKeys = this.DS.stores.SettingsStore.s.multiSelectKeys.map(
|
|
@@ -53,13 +53,20 @@ export default class PointerStore {
|
|
|
53
53
|
*/
|
|
54
54
|
constructor({ DS }) {
|
|
55
55
|
this.DS = DS
|
|
56
|
+
this.Settings = DS.stores.SettingsStore.s
|
|
56
57
|
this.DS.subscribe('Interaction:init', this.init)
|
|
57
58
|
this.DS.subscribe('Interaction:start', ({ event }) => this.start(event))
|
|
58
59
|
this.DS.subscribe('Interaction:end', ({ event }) => this.reset(event))
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
init = () => {
|
|
62
|
-
|
|
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
|
+
|
|
63
70
|
document.addEventListener('touchmove', this.update, {
|
|
64
71
|
// @ts-ignore
|
|
65
72
|
passive: false,
|
|
@@ -89,7 +96,14 @@ export default class PointerStore {
|
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
stop = () => {
|
|
92
|
-
|
|
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
|
+
|
|
93
107
|
document.removeEventListener('touchmove', this.update, {
|
|
94
108
|
// @ts-ignore
|
|
95
109
|
passive: false,
|
|
@@ -110,7 +124,7 @@ export default class PointerStore {
|
|
|
110
124
|
|
|
111
125
|
/**
|
|
112
126
|
* @param {DSEvent} event
|
|
113
|
-
* @return {MouseEvent|Touch}
|
|
127
|
+
* @return {MouseEvent|PointerEvent|Touch}
|
|
114
128
|
* @private
|
|
115
129
|
*/
|
|
116
130
|
_normalizedEvent(event) {
|
package/src/types.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
|
|
18
18
|
* @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
|
|
19
19
|
* @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
20
|
+
* @property {boolean} [usePointerEvents=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
|
|
20
21
|
* @property {string} [hoverClass=ds-hover] the class assigned to the mouse hovered items
|
|
21
22
|
* @property {string} [selectableClass=ds-selectable] the class assigned to the elements that can be selected
|
|
22
23
|
* @property {string} [selectedClass=ds-selected] the class assigned to the selected items
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
* The Object that is passed back to any callback method
|
|
29
30
|
* @typedef {Object} CallbackObject
|
|
30
31
|
* @property {Array<HTMLElement|SVGElement|any>} [items] The items currently selected
|
|
31
|
-
* @property {MouseEvent|TouchEvent|KeyboardEvent|Event} [event] The respective event object
|
|
32
|
+
* @property {MouseEvent|TouchEvent|PointerEvent|KeyboardEvent|Event} [event] The respective event object
|
|
32
33
|
* @property {HTMLElement|SVGElement|any} [item] The single item currently interacted with
|
|
33
34
|
* @property {boolean} [isDragging] Whether the interaction is a drag or a select
|
|
34
35
|
* @property {boolean} [isDraggingKeyboard] Whether or not the drag interaction is via keyboard
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
/** @typedef {Array.<HTMLElement|SVGElement> | HTMLElement | SVGElement} DSInputElements the elements that can be selected */
|
|
52
53
|
/** @typedef {Array.<HTMLElement|SVGElement>} DSElements the elements that can be selected */
|
|
53
54
|
/** @typedef {HTMLElement|SVGElement} DSElement a single element that can be selected */
|
|
54
|
-
/** @typedef {MouseEvent|TouchEvent} DSEvent en event from a touch or mouse interaction */
|
|
55
|
+
/** @typedef {MouseEvent|TouchEvent|PointerEvent} DSEvent en event from a touch or mouse interaction */
|
|
55
56
|
/** @typedef {Array.<'Shift'|'Control'|'Meta'|string>} DSMultiSelectKeys An array of keys that allows switching to the multi-select mode */
|
|
56
57
|
|
|
57
58
|
/** @typedef {'dragmove'|'autoscroll'|'dragstart'|'elementselect'|'elementunselect'|'callback'} DSEventNames */
|