dragselect 2.4.4 → 2.5.1
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 +10 -0
- package/README.md +84 -21
- package/dist/DragSelect.d.ts +26 -4
- package/dist/DragSelect.es6m.js +830 -782
- package/dist/DragSelect.js +830 -782
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/methods/addModificationObservers.d.ts +9 -1
- package/dist/methods/getAllParentNodes.d.ts +0 -43
- package/dist/methods/index.d.ts +1 -0
- package/dist/methods/isCollision.d.ts +1 -1
- package/dist/methods/subscriberAliases.d.ts +3 -1
- package/dist/modules/Area.d.ts +2 -12
- package/dist/modules/DropZone.d.ts +0 -43
- package/dist/modules/DropZones.d.ts +0 -46
- package/dist/modules/SelectableSet.d.ts +11 -0
- package/dist/modules/Selection.d.ts +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/types.d.ts +72 -2
- package/jest-puppeteer.config.js +1 -0
- package/package.json +5 -4
- package/src/DragSelect.js +29 -5
- package/src/methods/addModificationObservers.js +26 -5
- package/src/methods/canScroll.js +1 -1
- package/src/methods/getAllParentNodes.js +18 -0
- package/src/methods/handleElementPositionAttribute.js +1 -1
- package/src/methods/hydrateSettings.js +16 -0
- package/src/methods/index.js +1 -0
- package/src/methods/isCollision.js +24 -5
- package/src/methods/scrollElement.js +1 -1
- package/src/methods/subscriberAliases.js +16 -5
- package/src/methods/toArray.js +3 -2
- package/src/modules/Area.js +12 -44
- package/src/modules/DropZone.js +252 -0
- package/src/modules/DropZones.js +159 -0
- package/src/modules/SelectableSet.js +22 -0
- package/src/modules/Selection.js +9 -11
- package/src/modules/index.js +1 -0
- package/src/stores/SettingsStore.js +0 -1
- package/src/types.js +30 -2
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
declare function _default({ subscribe, publish, Interaction, SelectedSet }: {
|
|
1
|
+
declare function _default({ subscribe, publish, Interaction, SelectedSet, DropZones }: {
|
|
2
2
|
subscribe: DSSubscribe;
|
|
3
3
|
publish: DSPublish;
|
|
4
4
|
Interaction: Interaction;
|
|
5
5
|
SelectedSet: SelectedSet;
|
|
6
|
+
DropZones: DropZones;
|
|
6
7
|
}): void;
|
|
7
8
|
export default _default;
|
|
8
9
|
export type DSSubscribe = Function;
|
|
9
10
|
export type DSPublish = Function;
|
|
10
11
|
import { Interaction } from "../modules";
|
|
11
12
|
import { SelectedSet } from "../modules";
|
|
13
|
+
import { DropZones } from "../modules";
|
|
12
14
|
import "../types"
|
package/dist/modules/Area.d.ts
CHANGED
|
@@ -13,20 +13,10 @@ export default class Area {
|
|
|
13
13
|
*/
|
|
14
14
|
private DS;
|
|
15
15
|
/**
|
|
16
|
-
* @type {
|
|
16
|
+
* @type {{cleanup:() => void}}
|
|
17
17
|
* @private
|
|
18
18
|
*/
|
|
19
|
-
private
|
|
20
|
-
/**
|
|
21
|
-
* @type {MutationObserver}
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
|
-
private _modificationObserver;
|
|
25
|
-
/**
|
|
26
|
-
* @type {number}
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
private _zoom;
|
|
19
|
+
private _observers;
|
|
30
20
|
/**
|
|
31
21
|
* @type {DSArea}
|
|
32
22
|
* @private
|
|
@@ -86,46 +86,3 @@ export default class DropZone {
|
|
|
86
86
|
}
|
|
87
87
|
import DragSelect from "../DragSelect";
|
|
88
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"
|
|
@@ -47,9 +47,6 @@ export default class DropZones {
|
|
|
47
47
|
* @returns {DropZone|undefined}
|
|
48
48
|
*/
|
|
49
49
|
_getZoneByElementsFromPoint: (elements: DSElements, { x, y }: Vect2) => DropZone | undefined;
|
|
50
|
-
start: ({ isDragging }: {
|
|
51
|
-
isDragging: any;
|
|
52
|
-
}) => void;
|
|
53
50
|
stop: ({ isDragging }: {
|
|
54
51
|
isDragging: any;
|
|
55
52
|
}) => void;
|
|
@@ -74,46 +71,3 @@ export default class DropZones {
|
|
|
74
71
|
import DragSelect from "../DragSelect";
|
|
75
72
|
import DropZone from "./DropZone";
|
|
76
73
|
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"
|
|
@@ -7,6 +7,16 @@ export default class SelectableSet extends Set<any> {
|
|
|
7
7
|
constructor({ DS }: {
|
|
8
8
|
DS: DragSelect;
|
|
9
9
|
});
|
|
10
|
+
/**
|
|
11
|
+
* @type {Map<DSElement,DSBoundingRect>}
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
private _rects;
|
|
15
|
+
/**
|
|
16
|
+
* @type {NodeJS.Timeout}
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
private _timeout;
|
|
10
20
|
DS: DragSelect;
|
|
11
21
|
Settings: Settings;
|
|
12
22
|
init: () => void;
|
|
@@ -22,6 +32,7 @@ export default class SelectableSet extends Set<any> {
|
|
|
22
32
|
deleteAll: (elements: DSElements) => void;
|
|
23
33
|
/** @return {DSElements} */
|
|
24
34
|
get elements(): DSElements;
|
|
35
|
+
get rects(): Map<DSElement, DSBoundingRect>;
|
|
25
36
|
}
|
|
26
37
|
import DragSelect from "../DragSelect";
|
|
27
38
|
import "../types"
|
package/dist/modules/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as Area } from "./Area";
|
|
2
2
|
export { default as Drag } from "./Drag";
|
|
3
|
+
export { default as DropZones } from "./DropZones";
|
|
3
4
|
export { default as Interaction } from "./Interaction";
|
|
4
5
|
export { default as PubSub } from "./PubSub";
|
|
5
6
|
export { default as SelectableSet } from "./SelectableSet";
|
package/dist/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ type Settings = {
|
|
|
5
5
|
/**
|
|
6
6
|
* area in which you can drag. If not provided it will be the whole document
|
|
7
7
|
*/
|
|
8
|
-
area?: HTMLElement | SVGElement |
|
|
8
|
+
area?: HTMLElement | SVGElement | Document;
|
|
9
9
|
/**
|
|
10
10
|
* the elements that can be selected
|
|
11
11
|
*/
|
|
@@ -42,6 +42,10 @@ type Settings = {
|
|
|
42
42
|
* the square that will draw the selection
|
|
43
43
|
*/
|
|
44
44
|
selector?: HTMLElement;
|
|
45
|
+
/**
|
|
46
|
+
* how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection)
|
|
47
|
+
*/
|
|
48
|
+
selectionThreshold?: number;
|
|
45
49
|
/**
|
|
46
50
|
* When a user is dragging on an already selected element, the selection is dragged.
|
|
47
51
|
*/
|
|
@@ -66,6 +70,22 @@ type Settings = {
|
|
|
66
70
|
* Whether to use hardware accelerated css transforms when dragging or top/left instead
|
|
67
71
|
*/
|
|
68
72
|
useTransform?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Refresh rate on memoization, higher numbers mean better performance but more lag if elements are moving, lower numbers mean less lag but worse performance. If none of your DOMNodes are moving, you can set it to a very high number to increase performance. Value in milliseconds.
|
|
75
|
+
*/
|
|
76
|
+
refreshMemoryRate?: number;
|
|
77
|
+
/**
|
|
78
|
+
* one or more drop-elements: where the selectables can be dropped into
|
|
79
|
+
*/
|
|
80
|
+
dropZones?: DSInputDropZone[];
|
|
81
|
+
/**
|
|
82
|
+
* how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside)
|
|
83
|
+
*/
|
|
84
|
+
dropInsideThreshold?: number;
|
|
85
|
+
/**
|
|
86
|
+
* how much % of the zone does the pointer has to be in to be considered a target (0 = anywhere in the zone, max: 0.5 = has to point at the center of the zone)
|
|
87
|
+
*/
|
|
88
|
+
dropTargetThreshold?: number;
|
|
69
89
|
/**
|
|
70
90
|
* Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
|
|
71
91
|
*/
|
|
@@ -90,6 +110,34 @@ type Settings = {
|
|
|
90
110
|
* the class assigned to the square in which the selector resides. By default it's invisible
|
|
91
111
|
*/
|
|
92
112
|
selectorAreaClass?: string;
|
|
113
|
+
/**
|
|
114
|
+
* on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id}
|
|
115
|
+
*/
|
|
116
|
+
droppedTargetClass?: string;
|
|
117
|
+
/**
|
|
118
|
+
* on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id}
|
|
119
|
+
*/
|
|
120
|
+
droppedInsideClass?: string;
|
|
121
|
+
/**
|
|
122
|
+
* on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id}
|
|
123
|
+
*/
|
|
124
|
+
droppableClass?: string;
|
|
125
|
+
/**
|
|
126
|
+
* on each dropZone
|
|
127
|
+
*/
|
|
128
|
+
dropZoneClass?: string;
|
|
129
|
+
/**
|
|
130
|
+
* on corresponding dropZone when element is dragged
|
|
131
|
+
*/
|
|
132
|
+
dropZoneReadyClass?: string;
|
|
133
|
+
/**
|
|
134
|
+
* on dropZone that has elements from any successful target drop
|
|
135
|
+
*/
|
|
136
|
+
dropZoneTargetClass?: string;
|
|
137
|
+
/**
|
|
138
|
+
* on dropZone that has elements inside after any drop
|
|
139
|
+
*/
|
|
140
|
+
dropZoneInsideClass?: string;
|
|
93
141
|
};
|
|
94
142
|
/**
|
|
95
143
|
* The Object that is passed back to any callback method
|
|
@@ -125,8 +173,30 @@ type CallbackObject = {
|
|
|
125
173
|
settings?: Settings;
|
|
126
174
|
scroll_directions?: Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
|
|
127
175
|
scroll_multiplier?: number;
|
|
176
|
+
/**
|
|
177
|
+
* The dropZone element that the element was dropped into (or the mouse is currently hovering over)
|
|
178
|
+
*/
|
|
179
|
+
dropTarget?: DSDropZone;
|
|
128
180
|
};
|
|
129
181
|
type DSCallback = Function;
|
|
182
|
+
type DSInputDropZone = {
|
|
183
|
+
id: string;
|
|
184
|
+
element: DSElement;
|
|
185
|
+
droppables: DSInputElements;
|
|
186
|
+
};
|
|
187
|
+
type DSDropZone = {
|
|
188
|
+
id: string;
|
|
189
|
+
element: DSElement;
|
|
190
|
+
droppables: DSElements;
|
|
191
|
+
/**
|
|
192
|
+
* the items related to the target zone
|
|
193
|
+
*/
|
|
194
|
+
itemsDropped?: DSElements;
|
|
195
|
+
/**
|
|
196
|
+
* the items that are within the targets bounds
|
|
197
|
+
*/
|
|
198
|
+
itemsInside?: DSElements;
|
|
199
|
+
};
|
|
130
200
|
type Vect2 = {
|
|
131
201
|
x: number;
|
|
132
202
|
y: number;
|
|
@@ -143,7 +213,7 @@ type DSEdges = Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
|
|
|
143
213
|
/**
|
|
144
214
|
* area within which you can drag
|
|
145
215
|
*/
|
|
146
|
-
type DSArea = HTMLElement | SVGElement |
|
|
216
|
+
type DSArea = HTMLElement | SVGElement | Document;
|
|
147
217
|
/**
|
|
148
218
|
* area in which you can drag
|
|
149
219
|
*/
|
package/jest-puppeteer.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dragselect",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "easy javascript drag select functionality for your projects",
|
|
3
|
+
"version": "2.5.1",
|
|
4
|
+
"description": "easy javascript drag select & drop functionality for your projects",
|
|
5
5
|
"main": "./dist/DragSelect.js",
|
|
6
6
|
"types": "./dist/DragSelect.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@rollup/plugin-babel": "^5.2.2",
|
|
42
42
|
"@rollup/plugin-node-resolve": "^11.0.1",
|
|
43
43
|
"@typescript-eslint/eslint-plugin-tslint": "^4.12.0",
|
|
44
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
44
45
|
"babel-jest": "^26.6.3",
|
|
45
46
|
"babel-loader": "^8.2.2",
|
|
46
47
|
"babel-polyfill": "^6.26.0",
|
|
@@ -60,11 +61,11 @@
|
|
|
60
61
|
"eslint-plugin-standard": "^5.0.0",
|
|
61
62
|
"glob": "^7.1.7",
|
|
62
63
|
"jest": "^26.6.3",
|
|
63
|
-
"jest-puppeteer": "^
|
|
64
|
+
"jest-puppeteer": "^6.1.1",
|
|
64
65
|
"jsdoc": "^3.6.11",
|
|
65
66
|
"minami": "^1.2.3",
|
|
66
67
|
"prettier": "^2.2.1",
|
|
67
|
-
"puppeteer": "
|
|
68
|
+
"puppeteer": "18.1.0",
|
|
68
69
|
"rollup": "^2.36.1",
|
|
69
70
|
"rollup-plugin-terser": "^7.0.2",
|
|
70
71
|
"typescript": "^4.8.0"
|
package/src/DragSelect.js
CHANGED
|
@@ -46,6 +46,7 @@ import './types'
|
|
|
46
46
|
import {
|
|
47
47
|
Area,
|
|
48
48
|
Drag,
|
|
49
|
+
DropZones,
|
|
49
50
|
Interaction,
|
|
50
51
|
PubSub,
|
|
51
52
|
SelectableSet,
|
|
@@ -55,7 +56,7 @@ import {
|
|
|
55
56
|
SelectorArea,
|
|
56
57
|
} from './modules'
|
|
57
58
|
import { PointerStore, ScrollStore, KeyStore, SettingsStore } from './stores'
|
|
58
|
-
import { toArray,
|
|
59
|
+
import { toArray, subscriberAliases } from './methods'
|
|
59
60
|
|
|
60
61
|
// Setup
|
|
61
62
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -93,6 +94,8 @@ class DragSelect {
|
|
|
93
94
|
|
|
94
95
|
this.Drag = new Drag({ DS: this })
|
|
95
96
|
|
|
97
|
+
this.DropZones = new DropZones({ DS: this })
|
|
98
|
+
|
|
96
99
|
this.Interaction = new Interaction({ DS: this })
|
|
97
100
|
|
|
98
101
|
// Subscriber Aliases
|
|
@@ -101,6 +104,7 @@ class DragSelect {
|
|
|
101
104
|
publish: this.publish,
|
|
102
105
|
SelectedSet: this.SelectedSet,
|
|
103
106
|
Interaction: this.Interaction,
|
|
107
|
+
DropZones: this.DropZones,
|
|
104
108
|
})
|
|
105
109
|
|
|
106
110
|
this.subscribe('Interaction:end', () => (this.continue = false))
|
|
@@ -148,6 +152,12 @@ class DragSelect {
|
|
|
148
152
|
* Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
|
|
149
153
|
*/
|
|
150
154
|
break = () => (this.continue = true)
|
|
155
|
+
/**
|
|
156
|
+
* Update any setting dynamically
|
|
157
|
+
* @param {Settings} settings
|
|
158
|
+
* @return {void}
|
|
159
|
+
*/
|
|
160
|
+
setSettings = (settings) => this.stores.SettingsStore.update({ settings })
|
|
151
161
|
/**
|
|
152
162
|
* Returns the current selected nodes
|
|
153
163
|
* @return {DSElements}
|
|
@@ -314,11 +324,25 @@ class DragSelect {
|
|
|
314
324
|
*/
|
|
315
325
|
isDragging = () => this.Interaction.isDragging
|
|
316
326
|
/**
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
* @
|
|
327
|
+
* Returns first DropsZone under coordinates,
|
|
328
|
+
* if no coordinated provided current pointer coordinates are used
|
|
329
|
+
* @param {Vect2} [coordinates]
|
|
330
|
+
* @returns {DSDropZone | undefined}
|
|
320
331
|
*/
|
|
321
|
-
|
|
332
|
+
getZoneByCoordinates = (coordinates) => this.DropZones.getTarget(coordinates)?.toObject()
|
|
333
|
+
/**
|
|
334
|
+
* Returns itemsDropped into zone by zone id
|
|
335
|
+
* @param {string} zoneId
|
|
336
|
+
* @returns {DSElements|void}
|
|
337
|
+
*/
|
|
338
|
+
getItemsDroppedByZoneId = (zoneId) => this.DropZones.getItemsDroppedById(zoneId)
|
|
339
|
+
/**
|
|
340
|
+
* Returns itemsInside by zone id
|
|
341
|
+
* @param {string} zoneId
|
|
342
|
+
* @param {boolean} addClasses whether or not to add/remove the "inside" classes to the items
|
|
343
|
+
* @returns {DSElements|void}
|
|
344
|
+
*/
|
|
345
|
+
getItemsInsideByZoneId = (zoneId, addClasses) => this.DropZones.getItemsInsideById(zoneId, addClasses)
|
|
322
346
|
}
|
|
323
347
|
|
|
324
348
|
export default DragSelect
|
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import '../types'
|
|
3
3
|
|
|
4
|
+
import { removeModificationObservers } from './'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Removes event-listeners from the DOMNode
|
|
8
|
+
* @typedef {()=>void} DSCleanup
|
|
9
|
+
*/
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
|
-
* Adds event-listeners to
|
|
12
|
+
* Adds event-listeners to a DOMNode
|
|
6
13
|
* @param {DSArea[]} nodes
|
|
7
|
-
* @param {DSModificationCallback}
|
|
8
|
-
* @
|
|
14
|
+
* @param {DSModificationCallback} cb
|
|
15
|
+
* @return {{observer:MutationObserver,callback:DSModificationCallback,cleanup:DSCleanup}}
|
|
9
16
|
*/
|
|
10
|
-
export default (nodes,
|
|
17
|
+
export default (nodes, cb) => {
|
|
18
|
+
const callback = cb
|
|
19
|
+
|
|
11
20
|
window.addEventListener('resize', callback)
|
|
12
21
|
window.addEventListener('scroll', callback)
|
|
13
22
|
|
|
23
|
+
const observer = new MutationObserver(callback)
|
|
24
|
+
|
|
14
25
|
nodes.forEach((el, i) => {
|
|
15
|
-
|
|
26
|
+
observer.observe(el, {
|
|
16
27
|
childList: i !== 0,
|
|
17
28
|
attributes: true,
|
|
18
29
|
})
|
|
19
30
|
})
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Removes all observers
|
|
34
|
+
*/
|
|
35
|
+
const cleanup = () => removeModificationObservers(
|
|
36
|
+
observer,
|
|
37
|
+
callback,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return { observer, callback, cleanup }
|
|
20
41
|
}
|
package/src/methods/canScroll.js
CHANGED
|
@@ -11,7 +11,7 @@ export default (area) => {
|
|
|
11
11
|
let scroll = getCurrentScroll(area)
|
|
12
12
|
if (scroll.x || scroll.y) return true
|
|
13
13
|
|
|
14
|
-
if (area instanceof
|
|
14
|
+
if (area instanceof Document) {
|
|
15
15
|
if (area.body) return !!(area.body.scrollTop = 1)
|
|
16
16
|
else return !!(area.documentElement.scrollTop = 1)
|
|
17
17
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {DSElement|DSArea} node
|
|
3
|
+
* @returns {DSElements}
|
|
4
|
+
*/
|
|
5
|
+
export default (node) => {
|
|
6
|
+
const traverse = (toWatch, index = 0) => {
|
|
7
|
+
const parent = toWatch[index]?.parentNode
|
|
8
|
+
if (parent) {
|
|
9
|
+
toWatch.push(parent)
|
|
10
|
+
index++
|
|
11
|
+
return traverse(toWatch, index)
|
|
12
|
+
} else {
|
|
13
|
+
return toWatch
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return traverse([node])
|
|
18
|
+
}
|
|
@@ -11,6 +11,6 @@ export default ({ computedStyle, node }) => {
|
|
|
11
11
|
const position = computedStyle.position
|
|
12
12
|
const isPositioned =
|
|
13
13
|
position === 'absolute' || position === 'relative' || position === 'fixed'
|
|
14
|
-
if (!(node instanceof
|
|
14
|
+
if (!(node instanceof Document) && !isPositioned)
|
|
15
15
|
node.style.position = 'relative'
|
|
16
16
|
}
|
|
@@ -71,6 +71,10 @@ const hydrateHelper = (key, value, withFallback, fallback) => {
|
|
|
71
71
|
if (key === 'dragKeys' && isAvailable) return { [key]: Object.assign(fallback, value) }
|
|
72
72
|
else if(key === 'dragKeys' && !isAvailable) return isFallback ? { [key]: fallback } : {}
|
|
73
73
|
|
|
74
|
+
// Special rule for [dropZones]
|
|
75
|
+
if (key === 'dropZones' && isAvailable && new Set(value.map(v => v.id)).size !== value.length)
|
|
76
|
+
console.warn(`[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.`)
|
|
77
|
+
|
|
74
78
|
return isAvailable ? { [key]: value } : isFallback ? { [key]: fallback } : {}
|
|
75
79
|
}
|
|
76
80
|
|
|
@@ -95,16 +99,28 @@ export default (settings, withFallback) => ({
|
|
|
95
99
|
...hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true),
|
|
96
100
|
...hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta']),
|
|
97
101
|
...hydrateHelper('selector', settings.selector, withFallback, null),
|
|
102
|
+
...hydrateHelper('selectionThreshold', settings.selectionThreshold, withFallback, 0),
|
|
98
103
|
...hydrateHelper('draggability', settings.draggability, withFallback, true),
|
|
99
104
|
...hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true),
|
|
100
105
|
...hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true),
|
|
101
106
|
...hydrateHelper('dragKeys', settings.dragKeys, withFallback, { up: ['ArrowUp'], down: ['ArrowDown'], left: ['ArrowLeft'], right: ['ArrowRight'] }),
|
|
102
107
|
...hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10),
|
|
103
108
|
...hydrateHelper('useTransform', settings.useTransform, withFallback, true),
|
|
109
|
+
...hydrateHelper('refreshMemoryRate', settings.refreshMemoryRate, withFallback, 80),
|
|
110
|
+
...hydrateHelper('dropZones', settings.dropZones, withFallback, []),
|
|
111
|
+
...hydrateHelper('dropInsideThreshold', settings.dropInsideThreshold, withFallback, 1),
|
|
112
|
+
...hydrateHelper('dropTargetThreshold', settings.dropTargetThreshold, withFallback, 0),
|
|
104
113
|
...hydrateHelper('usePointerEvents', settings.usePointerEvents, withFallback, false),
|
|
105
114
|
...hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover'),
|
|
106
115
|
...hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable'),
|
|
107
116
|
...hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected'),
|
|
108
117
|
...hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector'),
|
|
109
118
|
...hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'),
|
|
119
|
+
...hydrateHelper('droppedTargetClass', settings.droppedTargetClass, withFallback, 'ds-dropped-target'),
|
|
120
|
+
...hydrateHelper('droppedInsideClass', settings.droppedInsideClass, withFallback, 'ds-dropped-inside'),
|
|
121
|
+
...hydrateHelper('droppableClass', settings.droppableClass, withFallback, 'ds-droppable'),
|
|
122
|
+
...hydrateHelper('dropZoneClass', settings.dropZoneClass, withFallback, 'ds-dropzone'),
|
|
123
|
+
...hydrateHelper('dropZoneReadyClass', settings.dropZoneReadyClass, withFallback, 'ds-dropzone-ready'),
|
|
124
|
+
...hydrateHelper('dropZoneTargetClass', settings.dropZoneTargetClass, withFallback, 'ds-dropzone-target'),
|
|
125
|
+
...hydrateHelper('dropZoneInsideClass', settings.dropZoneInsideClass, withFallback, 'ds-dropzone-inside'),
|
|
110
126
|
})
|
package/src/methods/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { default as createSelectorAreaElement } from './createSelectorAreaElemen
|
|
|
5
5
|
export { default as createSelectorElement } from './createSelectorElement'
|
|
6
6
|
export { default as debounce } from './debounce'
|
|
7
7
|
export { default as documentScroll } from './documentScroll'
|
|
8
|
+
export { default as getAllParentNodes } from './getAllParentNodes'
|
|
8
9
|
export { default as getAreaRect } from './getAreaRect'
|
|
9
10
|
export { default as getCurrentScroll } from './getCurrentScroll'
|
|
10
11
|
export { default as getOverflowEdges } from './getOverflowEdges'
|
|
@@ -21,14 +21,33 @@ import '../types'
|
|
|
21
21
|
* {@link https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection MDN}
|
|
22
22
|
* @param {{left:number,right:number,top:number,bottom:number}} el1
|
|
23
23
|
* @param {{left:number,right:number,top:number,bottom:number}} el2
|
|
24
|
+
* @param {number} [percent=0]
|
|
25
|
+
* 1 = the element has to be completely inside the other element
|
|
26
|
+
* 0.8 = the element has to be 80% inside the other element
|
|
27
|
+
* 0.5 = the element has to be 50% inside the other element
|
|
28
|
+
* 0.2 = the element has to be 20% inside the other element
|
|
29
|
+
* 0 = the element only has to touch the other element
|
|
24
30
|
* @returns {boolean}
|
|
25
31
|
*/
|
|
26
|
-
export default (el1, el2) => {
|
|
32
|
+
export default (el1, el2, percent = 0) => {
|
|
33
|
+
let element1 = el1
|
|
34
|
+
|
|
35
|
+
if (percent > 0) {
|
|
36
|
+
const widthPoint = (el1.right - el1.left) * percent
|
|
37
|
+
const heightPoint = (el1.bottom - el1.top) * percent
|
|
38
|
+
element1 = {
|
|
39
|
+
left: el1.left + widthPoint,
|
|
40
|
+
right: el1.right - widthPoint,
|
|
41
|
+
top: el1.top + heightPoint,
|
|
42
|
+
bottom: el1.bottom - heightPoint,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
element1.left < el2.right && // 1.
|
|
48
|
+
element1.right > el2.left && // 2.
|
|
49
|
+
element1.top < el2.bottom && // 3.
|
|
50
|
+
element1.bottom > el2.top // 4.
|
|
32
51
|
)
|
|
33
52
|
return true
|
|
34
53
|
// collision detected!
|
|
@@ -16,7 +16,7 @@ export default (element, directions, multiplier) => {
|
|
|
16
16
|
document.documentElement.scrollTop &&
|
|
17
17
|
document.documentElement
|
|
18
18
|
const _element =
|
|
19
|
-
element instanceof
|
|
19
|
+
element instanceof Document ? docEl || document.body : element
|
|
20
20
|
|
|
21
21
|
const scrollTop = directions.includes('top') && _element.scrollTop > 0
|
|
22
22
|
const scrollBot =
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import '../types'
|
|
3
|
-
import { Interaction, SelectedSet } from '../modules'
|
|
3
|
+
import { DropZones, Interaction, SelectedSet } from '../modules'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {function} DSSubscribe
|
|
@@ -22,17 +22,27 @@ import { Interaction, SelectedSet } from '../modules'
|
|
|
22
22
|
* @param {DSPublish} p.publish
|
|
23
23
|
* @param {Interaction} p.Interaction
|
|
24
24
|
* @param {SelectedSet} p.SelectedSet
|
|
25
|
+
* @param {DropZones} p.DropZones
|
|
25
26
|
*/
|
|
26
|
-
export default ({ subscribe, publish, Interaction, SelectedSet }) => {
|
|
27
|
+
export default ({ subscribe, publish, Interaction, SelectedSet, DropZones }) => {
|
|
27
28
|
const mapping = {
|
|
28
29
|
'Selected:added': [{ name: 'elementselect' }],
|
|
29
30
|
'Selected:removed': [{ name: 'elementunselect' }],
|
|
30
31
|
'Area:scroll': [{ name: 'autoscroll' }], // scroll_directions, scroll_multiplier
|
|
31
32
|
'Interaction:start': [{ name: 'dragstart' }], // event, isDraggingKeyboard
|
|
32
|
-
'Interaction:update': [
|
|
33
|
+
'Interaction:update': [ // event, isDraggingKeyboard
|
|
33
34
|
{ name: 'dragmove', condition: (data) => data.event },
|
|
34
|
-
],
|
|
35
|
-
'Interaction:end': [
|
|
35
|
+
],
|
|
36
|
+
'Interaction:end': [ // event, isDraggingKeyboard
|
|
37
|
+
{
|
|
38
|
+
name: 'callback', extraData: () => {
|
|
39
|
+
const target = DropZones.getTarget()
|
|
40
|
+
return {
|
|
41
|
+
...(target ? { dropTarget: target.toObject() } : {}),
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
],
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
for (const [sub_name, pubs] of Object.entries(mapping))
|
|
@@ -45,6 +55,7 @@ export default ({ subscribe, publish, Interaction, SelectedSet }) => {
|
|
|
45
55
|
items: SelectedSet.elements,
|
|
46
56
|
isDragging: Interaction.isDragging,
|
|
47
57
|
...data,
|
|
58
|
+
...(pub.extraData ? pub.extraData(data) : {}),
|
|
48
59
|
})
|
|
49
60
|
)
|
|
50
61
|
)
|
package/src/methods/toArray.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import '../types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Transforms any list or single
|
|
5
|
+
* Transforms any list or single dom node to an array so user doesn’t have to care. Also removes duplicates.
|
|
6
6
|
* @param {DSInputElements} items a single item, a Node-list or any element group
|
|
7
7
|
* @return {DSElements}
|
|
8
8
|
*/
|
|
@@ -13,5 +13,6 @@ export default (items) => {
|
|
|
13
13
|
(items instanceof HTMLElement || items instanceof SVGElement)
|
|
14
14
|
)
|
|
15
15
|
return [items]
|
|
16
|
-
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
return [...new Set([...items])]
|
|
17
18
|
}
|