dragselect 2.5.1 → 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 +4 -0
- package/README.md +3 -3
- package/dist/DragSelect.es6m.js +36 -24
- package/dist/DragSelect.js +36 -24
- 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/types.d.ts +10 -1
- package/package.json +1 -1
- package/src/methods/hydrateSettings.js +176 -47
- package/src/modules/DropZone.js +12 -3
- package/src/modules/SelectableSet.js +17 -13
- package/src/types.js +3 -3
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
|
@@ -24,7 +24,7 @@ export default class DropZone {
|
|
|
24
24
|
/**
|
|
25
25
|
* @type {DSElements}
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
_droppables
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @type {DOMRect}
|
|
@@ -62,7 +62,7 @@ export default class DropZone {
|
|
|
62
62
|
* @param {DragSelect} obj.DS
|
|
63
63
|
* @param {string} obj.id
|
|
64
64
|
* @param {DSElement} obj.element
|
|
65
|
-
* @param {DSInputElements} obj.droppables
|
|
65
|
+
* @param {DSInputElements} [obj.droppables]
|
|
66
66
|
* @ignore
|
|
67
67
|
*/
|
|
68
68
|
constructor({ DS, id, element, droppables }) {
|
|
@@ -71,7 +71,7 @@ export default class DropZone {
|
|
|
71
71
|
|
|
72
72
|
this.id = id
|
|
73
73
|
this.element = element
|
|
74
|
-
this.droppables = toArray(droppables)
|
|
74
|
+
if (droppables) this.droppables = toArray(droppables)
|
|
75
75
|
this.element.classList.add(`${this.Settings.dropZoneClass}`)
|
|
76
76
|
|
|
77
77
|
// @ts-ignore: @todo: update to typescript
|
|
@@ -249,4 +249,13 @@ export default class DropZone {
|
|
|
249
249
|
if (this._parentNodes) return this._parentNodes
|
|
250
250
|
return (this._parentNodes = getAllParentNodes(this.element))
|
|
251
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
|
+
}
|
|
252
261
|
}
|
|
@@ -10,11 +10,13 @@ export default class SelectableSet extends Set {
|
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
12
|
_rects
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* @type {NodeJS.Timeout}
|
|
15
16
|
* @private
|
|
16
17
|
*/
|
|
17
18
|
_timeout
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* @constructor SelectableSet
|
|
20
22
|
* @param {{DS:DragSelect}} obj
|
|
@@ -34,15 +36,12 @@ export default class SelectableSet extends Set {
|
|
|
34
36
|
this.DS.subscribe('Settings:updated:selectableClass', ({ settings }) => {
|
|
35
37
|
this.forEach((el) => {
|
|
36
38
|
el.classList.remove(settings['selectableClass:pre'])
|
|
37
|
-
el.classList.add(settings
|
|
39
|
+
el.classList.add(settings.selectableClass)
|
|
38
40
|
})
|
|
39
41
|
})
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
init = () =>
|
|
43
|
-
toArray(this.Settings.selectables).forEach((el) =>
|
|
44
|
-
this.add(el)
|
|
45
|
-
)
|
|
44
|
+
init = () => toArray(this.Settings.selectables).forEach((el) => this.add(el))
|
|
46
45
|
|
|
47
46
|
/** @param {DSElement} element */
|
|
48
47
|
add(element) {
|
|
@@ -54,23 +53,20 @@ export default class SelectableSet extends Set {
|
|
|
54
53
|
this.DS.publish('Selectable:added:pre', publishData)
|
|
55
54
|
element.classList.add(this.Settings.selectableClass)
|
|
56
55
|
element.addEventListener('click', this._onClick)
|
|
57
|
-
|
|
56
|
+
|
|
58
57
|
if (this.Settings.usePointerEvents)
|
|
59
58
|
element.addEventListener('pointerdown', this._onPointer, {
|
|
60
59
|
// @ts-ignore
|
|
61
60
|
passive: false,
|
|
62
61
|
})
|
|
63
62
|
else element.addEventListener('mousedown', this._onPointer)
|
|
64
|
-
|
|
63
|
+
|
|
65
64
|
element.addEventListener('touchstart', this._onPointer, {
|
|
66
65
|
// @ts-ignore
|
|
67
66
|
passive: false,
|
|
68
67
|
})
|
|
69
68
|
|
|
70
|
-
if (
|
|
71
|
-
this.Settings.draggability &&
|
|
72
|
-
!this.Settings.useTransform
|
|
73
|
-
)
|
|
69
|
+
if (this.Settings.draggability && !this.Settings.useTransform)
|
|
74
70
|
handleElementPositionAttribute({
|
|
75
71
|
computedStyle: window.getComputedStyle(element),
|
|
76
72
|
node: element,
|
|
@@ -111,13 +107,16 @@ export default class SelectableSet extends Set {
|
|
|
111
107
|
|
|
112
108
|
_onClick = (event) =>
|
|
113
109
|
this.DS.publish(['Selectable:click:pre', 'Selectable:click'], { event })
|
|
110
|
+
|
|
114
111
|
_onPointer = (event) =>
|
|
115
112
|
this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], { event })
|
|
116
113
|
|
|
117
114
|
/** @param {DSElements} elements */
|
|
118
115
|
addAll = (elements) => elements.forEach((el) => this.add(el))
|
|
116
|
+
|
|
119
117
|
/** @param {DSElements} elements */
|
|
120
118
|
deleteAll = (elements) => elements.forEach((el) => this.delete(el))
|
|
119
|
+
|
|
121
120
|
/** @return {DSElements} */
|
|
122
121
|
get elements() {
|
|
123
122
|
return Array.from(this.values())
|
|
@@ -126,11 +125,16 @@ export default class SelectableSet extends Set {
|
|
|
126
125
|
get rects() {
|
|
127
126
|
if (this._rects) return this._rects
|
|
128
127
|
this._rects = new Map()
|
|
129
|
-
this.forEach((element) =>
|
|
128
|
+
this.forEach((element) =>
|
|
129
|
+
this._rects.set(element, element.getBoundingClientRect())
|
|
130
|
+
)
|
|
130
131
|
|
|
131
132
|
// since elements can be moved, we need to update the rects every X ms
|
|
132
133
|
if (this._timeout) clearTimeout(this._timeout)
|
|
133
|
-
this._timeout = setTimeout(
|
|
134
|
+
this._timeout = setTimeout(
|
|
135
|
+
() => (this._rects = null),
|
|
136
|
+
this.Settings.refreshMemoryRate
|
|
137
|
+
)
|
|
134
138
|
|
|
135
139
|
return this._rects
|
|
136
140
|
}
|
package/src/types.js
CHANGED
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @typedef {Object} DSInputDropZone
|
|
61
|
-
* @property {string} id
|
|
62
|
-
* @property {DSElement} element
|
|
63
|
-
* @property {DSInputElements} droppables
|
|
61
|
+
* @property {string} id can be any unique identifier of type string
|
|
62
|
+
* @property {DSElement} element is the dropzone itself
|
|
63
|
+
* @property {DSInputElements} [droppables] the elements that can be dropped into that zone. This is optional, by default it will be all selectables
|
|
64
64
|
*/
|
|
65
65
|
/**
|
|
66
66
|
* @typedef {Object} DSDropZone
|