dragselect 2.5.0 → 2.5.2
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 +8 -0
- package/README.md +3 -3
- package/dist/DragSelect.es6m.js +39 -33
- package/dist/DragSelect.js +39 -33
- package/dist/ds.es6m.min.js +1 -1
- package/dist/ds.min.js +1 -1
- package/dist/modules/DropZone.d.ts +5 -3
- package/dist/modules/DropZones.d.ts +0 -3
- package/dist/types.d.ts +10 -1
- package/package.json +1 -1
- package/src/methods/hydrateSettings.js +176 -47
- package/src/modules/DropZone.js +62 -25
- package/src/modules/DropZones.js +22 -16
- package/src/modules/SelectableSet.js +17 -13
- package/src/types.js +3 -3
|
@@ -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;
|
package/dist/types.d.ts
CHANGED
|
@@ -180,9 +180,18 @@ type CallbackObject = {
|
|
|
180
180
|
};
|
|
181
181
|
type DSCallback = Function;
|
|
182
182
|
type DSInputDropZone = {
|
|
183
|
+
/**
|
|
184
|
+
* can be any unique identifier of type string
|
|
185
|
+
*/
|
|
183
186
|
id: string;
|
|
187
|
+
/**
|
|
188
|
+
* is the dropzone itself
|
|
189
|
+
*/
|
|
184
190
|
element: DSElement;
|
|
185
|
-
|
|
191
|
+
/**
|
|
192
|
+
* the elements that can be dropped into that zone. This is optional, by default it will be all selectables
|
|
193
|
+
*/
|
|
194
|
+
droppables?: DSInputElements;
|
|
186
195
|
};
|
|
187
196
|
type DSDropZone = {
|
|
188
197
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {string} key
|
|
3
|
-
* @param {string} type
|
|
2
|
+
* @param {string} key
|
|
3
|
+
* @param {string} type
|
|
4
4
|
* @param {*} fallback
|
|
5
5
|
* @returns {void}
|
|
6
6
|
*/
|
|
7
|
-
const wrongTypeWarn = (key, type, fallback) =>
|
|
8
|
-
console.warn(
|
|
7
|
+
const wrongTypeWarn = (key, type, fallback) =>
|
|
8
|
+
console.warn(
|
|
9
|
+
`[DragSelect] TypeIssue: setting "${key}" is not of type "${type}".`
|
|
10
|
+
)
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
|
-
* @param {string} key
|
|
13
|
+
* @param {string} key
|
|
12
14
|
* @param {*} value
|
|
13
|
-
* @param {boolean} withFallback
|
|
14
|
-
* @param {*} fallback
|
|
15
|
+
* @param {boolean} withFallback
|
|
16
|
+
* @param {*} fallback
|
|
15
17
|
* @returns {object}
|
|
16
18
|
*/
|
|
17
19
|
const hydrateHelper = (key, value, withFallback, fallback) => {
|
|
18
20
|
// no value available
|
|
19
|
-
if (value === undefined)
|
|
20
|
-
return withFallback ? { [key]: fallback } : {}
|
|
21
|
+
if (value === undefined) return withFallback ? { [key]: fallback } : {}
|
|
21
22
|
// force unsetting of a value
|
|
22
23
|
if (value === null) return { [key]: null }
|
|
23
24
|
|
|
@@ -27,31 +28,35 @@ const hydrateHelper = (key, value, withFallback, fallback) => {
|
|
|
27
28
|
|
|
28
29
|
// TypeCheck [String]
|
|
29
30
|
const expectedString = typeof fallback === 'string'
|
|
30
|
-
if (expectedString)
|
|
31
|
+
if (expectedString)
|
|
32
|
+
isAvailable = typeof value === 'string' || value instanceof String
|
|
31
33
|
if (expectedString && !isAvailable) {
|
|
32
34
|
forceFallback = true
|
|
33
35
|
wrongTypeWarn(key, 'string', fallback)
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
// TypeCheck [Number]
|
|
37
|
-
const expectedNumber = !isNaN(fallback) && typeof fallback === 'number'
|
|
38
|
-
if (expectedNumber)
|
|
39
|
+
const expectedNumber = !Number.isNaN(fallback) && typeof fallback === 'number'
|
|
40
|
+
if (expectedNumber)
|
|
41
|
+
isAvailable = !Number.isNaN(value) && typeof value === 'number'
|
|
39
42
|
if (expectedNumber && !isAvailable) {
|
|
40
43
|
forceFallback = true
|
|
41
44
|
wrongTypeWarn(key, 'number', fallback)
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
// TypeCheck [Object]
|
|
45
|
-
const expectedObject =
|
|
46
|
-
|
|
48
|
+
const expectedObject =
|
|
49
|
+
Object.prototype.toString.call(fallback) === '[object Object]'
|
|
50
|
+
if (expectedObject)
|
|
51
|
+
isAvailable = Object.prototype.toString.call(value) === '[object Object]'
|
|
47
52
|
if (expectedObject && !isAvailable) {
|
|
48
53
|
forceFallback = true
|
|
49
54
|
wrongTypeWarn(key, 'object', fallback)
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
// TypeCheck [Boolean]
|
|
53
|
-
const expectedBoolean = typeof fallback ===
|
|
54
|
-
if (expectedBoolean) isAvailable = typeof value ===
|
|
58
|
+
const expectedBoolean = typeof fallback === 'boolean'
|
|
59
|
+
if (expectedBoolean) isAvailable = typeof value === 'boolean'
|
|
55
60
|
if (expectedBoolean && !isAvailable) {
|
|
56
61
|
forceFallback = true
|
|
57
62
|
wrongTypeWarn(key, 'boolean', fallback)
|
|
@@ -68,59 +73,183 @@ const hydrateHelper = (key, value, withFallback, fallback) => {
|
|
|
68
73
|
const isFallback = forceFallback || withFallback
|
|
69
74
|
|
|
70
75
|
// Special rule for [dragKeys]
|
|
71
|
-
if (key === 'dragKeys' && isAvailable)
|
|
72
|
-
|
|
76
|
+
if (key === 'dragKeys' && isAvailable)
|
|
77
|
+
return { [key]: Object.assign(fallback, value) }
|
|
78
|
+
if (key === 'dragKeys' && !isAvailable)
|
|
79
|
+
return isFallback ? { [key]: fallback } : {}
|
|
73
80
|
|
|
74
81
|
// Special rule for [dropZones]
|
|
75
|
-
if (
|
|
76
|
-
|
|
82
|
+
if (
|
|
83
|
+
key === 'dropZones' &&
|
|
84
|
+
isAvailable &&
|
|
85
|
+
new Set(value.map((v) => v.id)).size !== value.length
|
|
86
|
+
)
|
|
87
|
+
console.warn(
|
|
88
|
+
`[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.`
|
|
89
|
+
)
|
|
77
90
|
|
|
78
|
-
|
|
91
|
+
if (isAvailable) return { [key]: value }
|
|
92
|
+
if (isFallback) return { [key]: fallback }
|
|
93
|
+
return {}
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
/**
|
|
82
97
|
* This helper method creates the setting object,
|
|
83
98
|
* - if the settings provided are of wrong type, the fallback value will be used
|
|
84
99
|
* - - except for if settings are undefined or explicitly marked as "null"
|
|
85
|
-
* - if "withfallback" is true, it will return the object with all settings:
|
|
100
|
+
* - if "withfallback" is true, it will return the object with all settings:
|
|
86
101
|
* - - if not provided from the settings object (or wrong type), the fallback will be used
|
|
87
102
|
* (the fallback value for each setting is the last prop of the hydrateHelper)
|
|
88
|
-
* @param {Settings} settings
|
|
89
|
-
* @param {boolean} withFallback
|
|
103
|
+
* @param {Settings} settings
|
|
104
|
+
* @param {boolean} withFallback
|
|
90
105
|
*/
|
|
91
106
|
export default (settings, withFallback) => ({
|
|
92
107
|
...hydrateHelper('area', settings.area, withFallback, document),
|
|
93
108
|
...hydrateHelper('selectables', settings.selectables, withFallback, null),
|
|
94
|
-
...hydrateHelper(
|
|
95
|
-
|
|
109
|
+
...hydrateHelper(
|
|
110
|
+
'autoScrollSpeed',
|
|
111
|
+
settings.autoScrollSpeed,
|
|
112
|
+
withFallback,
|
|
113
|
+
5
|
|
114
|
+
),
|
|
115
|
+
...hydrateHelper(
|
|
116
|
+
'overflowTolerance',
|
|
117
|
+
settings.overflowTolerance,
|
|
118
|
+
withFallback,
|
|
119
|
+
{ x: 25, y: 25 }
|
|
120
|
+
),
|
|
96
121
|
...hydrateHelper('zoom', settings.zoom, withFallback, 1),
|
|
97
122
|
...hydrateHelper('customStyles', settings.customStyles, withFallback, false),
|
|
98
|
-
...hydrateHelper(
|
|
99
|
-
|
|
100
|
-
|
|
123
|
+
...hydrateHelper(
|
|
124
|
+
'multiSelectMode',
|
|
125
|
+
settings.multiSelectMode,
|
|
126
|
+
withFallback,
|
|
127
|
+
false
|
|
128
|
+
),
|
|
129
|
+
...hydrateHelper(
|
|
130
|
+
'multiSelectToggling',
|
|
131
|
+
settings.multiSelectToggling,
|
|
132
|
+
withFallback,
|
|
133
|
+
true
|
|
134
|
+
),
|
|
135
|
+
...hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, [
|
|
136
|
+
'Control',
|
|
137
|
+
'Shift',
|
|
138
|
+
'Meta',
|
|
139
|
+
]),
|
|
101
140
|
...hydrateHelper('selector', settings.selector, withFallback, null),
|
|
102
|
-
...hydrateHelper(
|
|
141
|
+
...hydrateHelper(
|
|
142
|
+
'selectionThreshold',
|
|
143
|
+
settings.selectionThreshold,
|
|
144
|
+
withFallback,
|
|
145
|
+
0
|
|
146
|
+
),
|
|
103
147
|
...hydrateHelper('draggability', settings.draggability, withFallback, true),
|
|
104
148
|
...hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true),
|
|
105
149
|
...hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true),
|
|
106
|
-
...hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
|
|
107
|
-
|
|
150
|
+
...hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
|
|
151
|
+
up: ['ArrowUp'],
|
|
152
|
+
down: ['ArrowDown'],
|
|
153
|
+
left: ['ArrowLeft'],
|
|
154
|
+
right: ['ArrowRight'],
|
|
155
|
+
}),
|
|
156
|
+
...hydrateHelper(
|
|
157
|
+
'keyboardDragSpeed',
|
|
158
|
+
settings.keyboardDragSpeed,
|
|
159
|
+
withFallback,
|
|
160
|
+
10
|
|
161
|
+
),
|
|
108
162
|
...hydrateHelper('useTransform', settings.useTransform, withFallback, true),
|
|
109
|
-
...hydrateHelper(
|
|
163
|
+
...hydrateHelper(
|
|
164
|
+
'refreshMemoryRate',
|
|
165
|
+
settings.refreshMemoryRate,
|
|
166
|
+
withFallback,
|
|
167
|
+
80
|
|
168
|
+
),
|
|
110
169
|
...hydrateHelper('dropZones', settings.dropZones, withFallback, []),
|
|
111
|
-
...hydrateHelper(
|
|
112
|
-
|
|
113
|
-
|
|
170
|
+
...hydrateHelper(
|
|
171
|
+
'dropInsideThreshold',
|
|
172
|
+
settings.dropInsideThreshold,
|
|
173
|
+
withFallback,
|
|
174
|
+
1
|
|
175
|
+
),
|
|
176
|
+
...hydrateHelper(
|
|
177
|
+
'dropTargetThreshold',
|
|
178
|
+
settings.dropTargetThreshold,
|
|
179
|
+
withFallback,
|
|
180
|
+
0
|
|
181
|
+
),
|
|
182
|
+
...hydrateHelper(
|
|
183
|
+
'usePointerEvents',
|
|
184
|
+
settings.usePointerEvents,
|
|
185
|
+
withFallback,
|
|
186
|
+
false
|
|
187
|
+
),
|
|
114
188
|
...hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover'),
|
|
115
|
-
...hydrateHelper(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
...hydrateHelper(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
189
|
+
...hydrateHelper(
|
|
190
|
+
'selectableClass',
|
|
191
|
+
settings.selectableClass,
|
|
192
|
+
withFallback,
|
|
193
|
+
'ds-selectable'
|
|
194
|
+
),
|
|
195
|
+
...hydrateHelper(
|
|
196
|
+
'selectedClass',
|
|
197
|
+
settings.selectedClass,
|
|
198
|
+
withFallback,
|
|
199
|
+
'ds-selected'
|
|
200
|
+
),
|
|
201
|
+
...hydrateHelper(
|
|
202
|
+
'selectorClass',
|
|
203
|
+
settings.selectorClass,
|
|
204
|
+
withFallback,
|
|
205
|
+
'ds-selector'
|
|
206
|
+
),
|
|
207
|
+
...hydrateHelper(
|
|
208
|
+
'selectorAreaClass',
|
|
209
|
+
settings.selectorAreaClass,
|
|
210
|
+
withFallback,
|
|
211
|
+
'ds-selector-area'
|
|
212
|
+
),
|
|
213
|
+
...hydrateHelper(
|
|
214
|
+
'droppedTargetClass',
|
|
215
|
+
settings.droppedTargetClass,
|
|
216
|
+
withFallback,
|
|
217
|
+
'ds-dropped-target'
|
|
218
|
+
),
|
|
219
|
+
...hydrateHelper(
|
|
220
|
+
'droppedInsideClass',
|
|
221
|
+
settings.droppedInsideClass,
|
|
222
|
+
withFallback,
|
|
223
|
+
'ds-dropped-inside'
|
|
224
|
+
),
|
|
225
|
+
...hydrateHelper(
|
|
226
|
+
'droppableClass',
|
|
227
|
+
settings.droppableClass,
|
|
228
|
+
withFallback,
|
|
229
|
+
'ds-droppable'
|
|
230
|
+
),
|
|
231
|
+
...hydrateHelper(
|
|
232
|
+
'dropZoneClass',
|
|
233
|
+
settings.dropZoneClass,
|
|
234
|
+
withFallback,
|
|
235
|
+
'ds-dropzone'
|
|
236
|
+
),
|
|
237
|
+
...hydrateHelper(
|
|
238
|
+
'dropZoneReadyClass',
|
|
239
|
+
settings.dropZoneReadyClass,
|
|
240
|
+
withFallback,
|
|
241
|
+
'ds-dropzone-ready'
|
|
242
|
+
),
|
|
243
|
+
...hydrateHelper(
|
|
244
|
+
'dropZoneTargetClass',
|
|
245
|
+
settings.dropZoneTargetClass,
|
|
246
|
+
withFallback,
|
|
247
|
+
'ds-dropzone-target'
|
|
248
|
+
),
|
|
249
|
+
...hydrateHelper(
|
|
250
|
+
'dropZoneInsideClass',
|
|
251
|
+
settings.dropZoneInsideClass,
|
|
252
|
+
withFallback,
|
|
253
|
+
'ds-dropzone-inside'
|
|
254
|
+
),
|
|
126
255
|
})
|
package/src/modules/DropZone.js
CHANGED
|
@@ -2,53 +2,67 @@
|
|
|
2
2
|
import '../types'
|
|
3
3
|
import DragSelect from '../DragSelect'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
isCollision,
|
|
7
|
+
toArray,
|
|
8
|
+
debounce,
|
|
9
|
+
addModificationObservers,
|
|
10
|
+
getAllParentNodes,
|
|
11
|
+
} from '../methods'
|
|
6
12
|
|
|
7
13
|
export default class DropZone {
|
|
8
14
|
/**
|
|
9
15
|
* @type {string}
|
|
10
16
|
*/
|
|
11
17
|
id
|
|
18
|
+
|
|
12
19
|
/**
|
|
13
20
|
* @type {DSElement}
|
|
14
21
|
*/
|
|
15
22
|
element
|
|
23
|
+
|
|
16
24
|
/**
|
|
17
25
|
* @type {DSElements}
|
|
18
26
|
*/
|
|
19
|
-
|
|
27
|
+
_droppables
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
* @type {DOMRect}
|
|
22
31
|
* @private
|
|
23
32
|
*/
|
|
24
33
|
_rect
|
|
34
|
+
|
|
25
35
|
/**
|
|
26
36
|
* @type {{cleanup:()=>void}}
|
|
27
37
|
* @private
|
|
28
38
|
*/
|
|
29
39
|
_observers
|
|
40
|
+
|
|
30
41
|
/**
|
|
31
42
|
* @type {NodeJS.Timeout}
|
|
32
43
|
* @private
|
|
33
44
|
*/
|
|
34
45
|
_timeout
|
|
46
|
+
|
|
35
47
|
/**
|
|
36
48
|
* @type {DSElements}
|
|
37
49
|
* @private
|
|
38
50
|
*/
|
|
39
51
|
_itemsDropped = []
|
|
52
|
+
|
|
40
53
|
/**
|
|
41
54
|
* @type {DSElements}
|
|
42
55
|
* @private
|
|
43
56
|
*/
|
|
44
57
|
_itemsInside
|
|
58
|
+
|
|
45
59
|
/**
|
|
46
60
|
* @constructor Drag
|
|
47
61
|
* @param {Object} obj
|
|
48
62
|
* @param {DragSelect} obj.DS
|
|
49
63
|
* @param {string} obj.id
|
|
50
64
|
* @param {DSElement} obj.element
|
|
51
|
-
* @param {DSInputElements} obj.droppables
|
|
65
|
+
* @param {DSInputElements} [obj.droppables]
|
|
52
66
|
* @ignore
|
|
53
67
|
*/
|
|
54
68
|
constructor({ DS, id, element, droppables }) {
|
|
@@ -57,18 +71,18 @@ export default class DropZone {
|
|
|
57
71
|
|
|
58
72
|
this.id = id
|
|
59
73
|
this.element = element
|
|
60
|
-
this.droppables = toArray(droppables)
|
|
74
|
+
if (droppables) this.droppables = toArray(droppables)
|
|
61
75
|
this.element.classList.add(`${this.Settings.dropZoneClass}`)
|
|
62
76
|
|
|
63
77
|
// @ts-ignore: @todo: update to typescript
|
|
64
78
|
this.DS.subscribe('Settings:updated:dropZoneClass', ({ settings }) => {
|
|
65
79
|
this.element.classList.remove(settings['dropZoneClass:pre'])
|
|
66
|
-
this.element.classList.add(settings
|
|
80
|
+
this.element.classList.add(settings.dropZoneClass)
|
|
67
81
|
})
|
|
68
82
|
|
|
69
83
|
this._observers = addModificationObservers(
|
|
70
84
|
this.parentNodes,
|
|
71
|
-
debounce(() => this._rect = null, this.Settings.refreshMemoryRate)
|
|
85
|
+
debounce(() => (this._rect = null), this.Settings.refreshMemoryRate)
|
|
72
86
|
)
|
|
73
87
|
|
|
74
88
|
this.DS.subscribe('Interaction:start', this.start)
|
|
@@ -79,8 +93,10 @@ export default class DropZone {
|
|
|
79
93
|
* @param {'add'|'remove'} action
|
|
80
94
|
*/
|
|
81
95
|
setReadyClasses = (action) => {
|
|
82
|
-
if(this.isDestroyed) return
|
|
83
|
-
const selectedEls = this.droppables.filter((el) =>
|
|
96
|
+
if (this.isDestroyed) return
|
|
97
|
+
const selectedEls = this.droppables.filter((el) =>
|
|
98
|
+
this.DS.SelectedSet.has(el)
|
|
99
|
+
)
|
|
84
100
|
if (!selectedEls.length) return
|
|
85
101
|
selectedEls.forEach((item) => {
|
|
86
102
|
item.classList[action](`${this.Settings.droppableClass}`)
|
|
@@ -93,16 +109,18 @@ export default class DropZone {
|
|
|
93
109
|
* This zone is NOT the target of a drop
|
|
94
110
|
*/
|
|
95
111
|
handleNoDrop = () => {
|
|
96
|
-
if(this.isDestroyed) return
|
|
112
|
+
if (this.isDestroyed) return
|
|
97
113
|
// for each selected element that is not part of the target zone, remove the classes
|
|
98
114
|
this.DS.SelectedSet.forEach((item) => {
|
|
99
115
|
item.classList.remove(this.Settings.droppedTargetClass)
|
|
100
116
|
item.classList.remove(`${this.Settings.droppedTargetClass}-${this.id}`)
|
|
101
117
|
})
|
|
102
118
|
// and remove them from the zones dropped items
|
|
103
|
-
this._itemsDropped = this._itemsDropped.filter(
|
|
119
|
+
this._itemsDropped = this._itemsDropped.filter(
|
|
120
|
+
(item) => !this.DS.SelectedSet.has(item)
|
|
121
|
+
)
|
|
104
122
|
// if the zone has no dropped left, also remove the zones class
|
|
105
|
-
if(!this._itemsDropped?.length)
|
|
123
|
+
if (!this._itemsDropped?.length)
|
|
106
124
|
this.element.classList.remove(`${this.Settings.dropZoneTargetClass}`)
|
|
107
125
|
}
|
|
108
126
|
|
|
@@ -110,16 +128,21 @@ export default class DropZone {
|
|
|
110
128
|
* This zone IS the target of a drop
|
|
111
129
|
*/
|
|
112
130
|
handleDrop = () => {
|
|
113
|
-
if(this.isDestroyed) return
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
if (this.isDestroyed) return
|
|
132
|
+
this._itemsDropped = [
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
...new Set([
|
|
135
|
+
...this._itemsDropped,
|
|
136
|
+
...this.droppables?.filter((item) => this.DS.SelectedSet.has(item)),
|
|
137
|
+
]),
|
|
138
|
+
]
|
|
116
139
|
// add the target class to the zones dropped items
|
|
117
140
|
this._itemsDropped?.forEach((item) => {
|
|
118
141
|
item.classList.add(`${this.Settings.droppedTargetClass}`)
|
|
119
142
|
item.classList.add(`${this.Settings.droppedTargetClass}-${this.id}`)
|
|
120
143
|
})
|
|
121
144
|
// if the zone has dropped, add the zones class
|
|
122
|
-
if(this._itemsDropped?.length)
|
|
145
|
+
if (this._itemsDropped?.length)
|
|
123
146
|
this.element.classList.add(`${this.Settings.dropZoneTargetClass}`)
|
|
124
147
|
}
|
|
125
148
|
|
|
@@ -131,15 +154,15 @@ export default class DropZone {
|
|
|
131
154
|
item.classList.add(`${this.Settings.droppedInsideClass}-${this.id}`)
|
|
132
155
|
isAnyInside = true
|
|
133
156
|
} else {
|
|
134
|
-
item.classList.remove(`${this.Settings.droppedInsideClass}`)
|
|
135
157
|
item.classList.remove(`${this.Settings.droppedInsideClass}-${this.id}`)
|
|
158
|
+
if (!item.className.includes(`${this.Settings.droppedInsideClass}-`))
|
|
159
|
+
item.classList.remove(`${this.Settings.droppedInsideClass}`)
|
|
136
160
|
}
|
|
137
161
|
})
|
|
138
162
|
|
|
139
163
|
if (isAnyInside)
|
|
140
164
|
this.element.classList.add(`${this.Settings.dropZoneInsideClass}`)
|
|
141
|
-
else
|
|
142
|
-
this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)
|
|
165
|
+
else this.element.classList.remove(`${this.Settings.dropZoneInsideClass}`)
|
|
143
166
|
}
|
|
144
167
|
|
|
145
168
|
start = ({ isDragging }) => {
|
|
@@ -192,7 +215,7 @@ export default class DropZone {
|
|
|
192
215
|
}
|
|
193
216
|
|
|
194
217
|
get itemsDropped() {
|
|
195
|
-
if(this.isDestroyed) return null
|
|
218
|
+
if (this.isDestroyed) return null
|
|
196
219
|
return this._itemsDropped
|
|
197
220
|
}
|
|
198
221
|
|
|
@@ -201,18 +224,23 @@ export default class DropZone {
|
|
|
201
224
|
if (this._itemsInside) return this._itemsInside
|
|
202
225
|
|
|
203
226
|
this._itemsInside = this.droppables.flatMap((item) => {
|
|
204
|
-
if(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
227
|
+
if (
|
|
228
|
+
isCollision(
|
|
229
|
+
this.DS.SelectableSet.rects.get(item),
|
|
230
|
+
this.rect,
|
|
231
|
+
this.Settings.dropInsideThreshold
|
|
232
|
+
)
|
|
233
|
+
)
|
|
209
234
|
return [item]
|
|
210
235
|
return []
|
|
211
236
|
})
|
|
212
237
|
|
|
213
238
|
// since elements can be moved while this getter is called, we need to update the values every X seconds
|
|
214
239
|
if (this._timeout) clearTimeout(this._timeout)
|
|
215
|
-
this._timeout = setTimeout(
|
|
240
|
+
this._timeout = setTimeout(
|
|
241
|
+
() => (this._itemsInside = null),
|
|
242
|
+
this.Settings.refreshMemoryRate
|
|
243
|
+
)
|
|
216
244
|
|
|
217
245
|
return this._itemsInside
|
|
218
246
|
}
|
|
@@ -221,4 +249,13 @@ export default class DropZone {
|
|
|
221
249
|
if (this._parentNodes) return this._parentNodes
|
|
222
250
|
return (this._parentNodes = getAllParentNodes(this.element))
|
|
223
251
|
}
|
|
252
|
+
|
|
253
|
+
get droppables() {
|
|
254
|
+
if (this._droppables) return this._droppables
|
|
255
|
+
return this.DS.SelectableSet.elements
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
set droppables(value) {
|
|
259
|
+
this._droppables = value
|
|
260
|
+
}
|
|
224
261
|
}
|
package/src/modules/DropZones.js
CHANGED
|
@@ -13,18 +13,21 @@ export default class DropZones {
|
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
15
|
_zoneByElement = new Map()
|
|
16
|
+
|
|
16
17
|
/**
|
|
17
18
|
* Get the drop zone by the zone id
|
|
18
19
|
* @type {Map<string, DropZone>}
|
|
19
20
|
* @private
|
|
20
21
|
*/
|
|
21
22
|
_zoneById = new Map()
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* Get the drop zones by one zone item
|
|
24
26
|
* @type {Map<DSElement,DropZone[]>}
|
|
25
27
|
* @private
|
|
26
28
|
*/
|
|
27
29
|
_zonesByDroppable = new Map()
|
|
30
|
+
|
|
28
31
|
/**
|
|
29
32
|
* Get the drop zones by one zone item
|
|
30
33
|
* @type {DropZone[]}
|
|
@@ -43,9 +46,11 @@ export default class DropZones {
|
|
|
43
46
|
|
|
44
47
|
// @ts-ignore: @todo: update to typescript
|
|
45
48
|
this.DS.subscribe('Settings:updated:dropZones', this.setDropZones)
|
|
46
|
-
this.setDropZones({
|
|
49
|
+
this.setDropZones({
|
|
50
|
+
dropZones: /** @type {DSDropZone[]} */ (this.DS.stores.SettingsStore.s
|
|
51
|
+
.dropZones),
|
|
52
|
+
})
|
|
47
53
|
|
|
48
|
-
this.DS.subscribe('Interaction:start', this.start)
|
|
49
54
|
this.DS.subscribe('Interaction:end', this.stop)
|
|
50
55
|
}
|
|
51
56
|
|
|
@@ -57,7 +62,9 @@ export default class DropZones {
|
|
|
57
62
|
if (!dropZones) return
|
|
58
63
|
if (this._zones) this._zones.forEach((zone) => zone.destroy())
|
|
59
64
|
|
|
60
|
-
this._zones = dropZones.map(
|
|
65
|
+
this._zones = dropZones.map(
|
|
66
|
+
(zone) => new DropZone({ DS: this.DS, ...zone })
|
|
67
|
+
)
|
|
61
68
|
this._zones.forEach((zone) => {
|
|
62
69
|
this._zoneByElement.set(zone.element, zone)
|
|
63
70
|
this._zoneById.set(zone.id, zone)
|
|
@@ -85,7 +92,7 @@ export default class DropZones {
|
|
|
85
92
|
* @returns {DropZone|undefined}
|
|
86
93
|
*/
|
|
87
94
|
_getZoneByElementsFromPoint = (elements, { x, y }) => {
|
|
88
|
-
for(let i = 0, il = elements.length; i < il; i++) {
|
|
95
|
+
for (let i = 0, il = elements.length; i < il; i++) {
|
|
89
96
|
const zone = this._zoneByElement.get(elements[i])
|
|
90
97
|
if (
|
|
91
98
|
zone &&
|
|
@@ -100,21 +107,17 @@ export default class DropZones {
|
|
|
100
107
|
}
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
start = ({ isDragging }) => {
|
|
104
|
-
if (!isDragging) return
|
|
105
|
-
}
|
|
106
|
-
|
|
107
110
|
stop = ({ isDragging }) => {
|
|
108
111
|
if (!isDragging) return
|
|
109
112
|
const target = this.getTarget()
|
|
110
113
|
this._handleDrop(target)
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
114
117
|
// Getters
|
|
115
118
|
|
|
116
119
|
/**
|
|
117
|
-
* @param {string} zoneId
|
|
120
|
+
* @param {string} zoneId
|
|
118
121
|
* @returns {DSElements|void}
|
|
119
122
|
*/
|
|
120
123
|
getItemsDroppedById = (zoneId) => {
|
|
@@ -124,15 +127,15 @@ export default class DropZones {
|
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
/**
|
|
127
|
-
* @param {string} zoneId
|
|
130
|
+
* @param {string} zoneId
|
|
128
131
|
* @param {boolean} addClasses
|
|
129
132
|
* @returns {DSElements|void}
|
|
130
133
|
*/
|
|
131
134
|
getItemsInsideById = (zoneId, addClasses) => {
|
|
132
135
|
const zone = this._zoneById.get(zoneId)
|
|
133
136
|
if (!zone) return console.warn(`[DragSelect] No zone found (id: ${zoneId})`)
|
|
134
|
-
const itemsInside = zone
|
|
135
|
-
if(addClasses) zone.handleItemsInsideClasses()
|
|
137
|
+
const { itemsInside } = zone
|
|
138
|
+
if (addClasses) zone.handleItemsInsideClasses()
|
|
136
139
|
return itemsInside
|
|
137
140
|
}
|
|
138
141
|
|
|
@@ -143,11 +146,14 @@ export default class DropZones {
|
|
|
143
146
|
*/
|
|
144
147
|
getTarget = (coordinates) => {
|
|
145
148
|
if (!this._zones?.length) return
|
|
146
|
-
|
|
149
|
+
|
|
147
150
|
const x = coordinates?.x || this.DS.stores.PointerStore.currentVal.x
|
|
148
151
|
const y = coordinates?.y || this.DS.stores.PointerStore.currentVal.y
|
|
149
|
-
|
|
152
|
+
|
|
150
153
|
const elements = document.elementsFromPoint(x, y)
|
|
151
|
-
return this._getZoneByElementsFromPoint(
|
|
154
|
+
return this._getZoneByElementsFromPoint(
|
|
155
|
+
/** @type {DSElements} */ (elements),
|
|
156
|
+
{ x, y }
|
|
157
|
+
)
|
|
152
158
|
}
|
|
153
159
|
}
|