dragselect 2.7.4 → 3.0.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 +97 -23
- package/LICENSE +690 -0
- package/README.md +2 -1
- package/jest-puppeteer.config.js +13 -3
- package/jest.config.js +5 -0
- package/package.json +40 -46
- package/rollup.config.mjs +82 -0
- package/src/DragSelect.ts +425 -0
- package/src/methods/addModificationObservers.ts +51 -0
- package/src/methods/canScroll.ts +19 -0
- package/src/methods/{createSelectorAreaElement.js → createSelectorAreaElement.ts} +1 -8
- package/src/methods/{createSelectorElement.js → createSelectorElement.ts} +1 -9
- package/src/methods/{debounce.js → debounce.ts} +5 -11
- package/src/methods/ensureArray.ts +13 -0
- package/src/methods/getAllParentNodes.ts +15 -0
- package/src/methods/{getAreaRect.js → getAreaRect.ts} +2 -6
- package/src/methods/getCurrentScroll.ts +14 -0
- package/src/methods/{documentScroll.js → getDocumentScroll.ts} +2 -2
- package/src/methods/{getOverflowEdges.js → getOverflowEdges.ts} +11 -11
- package/src/methods/getPointerPos.ts +9 -0
- package/src/methods/getSelectionRect.ts +29 -0
- package/src/methods/{getSelectorPosition.js → getSelectorPosition.ts} +11 -9
- package/src/methods/{getStylePosition.spec.js → getStylePosition.spec.ts} +9 -9
- package/src/methods/{getStylePosition.js → getStylePosition.ts} +5 -21
- package/src/methods/handleElementPositionAttribute.ts +15 -0
- package/src/methods/handleKeyboardDragPosDifference.ts +35 -0
- package/src/methods/handleSelection.ts +26 -0
- package/src/methods/{handleUnSelection.js → handleUnSelection.ts} +14 -14
- package/src/methods/{hydrateSettings.js → hydrateSettings.ts} +15 -26
- package/src/methods/isCollision.ts +66 -0
- package/src/methods/limitDirection.ts +36 -0
- package/src/methods/moveElement.ts +18 -0
- package/src/methods/{scrollElement.js → scrollElement.ts} +4 -10
- package/src/methods/{setStylePosition.js → setStylePosition.ts} +3 -11
- package/src/methods/subscriberAliases.ts +240 -0
- package/src/methods/updateElementStylePos.ts +7 -0
- package/src/methods/vect2.ts +34 -0
- package/src/modules/Area.ts +169 -0
- package/src/modules/Drag.ts +236 -0
- package/src/modules/{DropZone.js → DropZone.ts} +80 -119
- package/src/modules/DropZones.ts +151 -0
- package/src/modules/Interaction.ts +251 -0
- package/src/modules/PubSub.ts +111 -0
- package/src/modules/SelectableSet.ts +146 -0
- package/src/modules/SelectedSet.ts +92 -0
- package/src/modules/{Selection.js → Selection.ts} +59 -44
- package/src/modules/Selector.ts +81 -0
- package/src/modules/{SelectorArea.js → SelectorArea.ts} +58 -71
- package/src/stores/KeyStore.ts +92 -0
- package/src/stores/PointerStore.ts +194 -0
- package/src/stores/ScrollStore.ts +87 -0
- package/src/stores/SettingsStore.ts +88 -0
- package/src/types.ts +158 -0
- package/tsconfig.json +105 -0
- package/bower.json +0 -24
- package/dist/DragSelect.d.ts +0 -200
- package/dist/DragSelect.es6m.js +0 -3886
- package/dist/DragSelect.js +0 -3894
- package/dist/ds.es6m.min.js +0 -1
- package/dist/ds.min.js +0 -1
- package/dist/methods/addModificationObservers.d.ts +0 -11
- package/dist/methods/canScroll.d.ts +0 -3
- package/dist/methods/createSelectorAreaElement.d.ts +0 -3
- package/dist/methods/createSelectorElement.d.ts +0 -3
- package/dist/methods/debounce.d.ts +0 -3
- package/dist/methods/documentScroll.d.ts +0 -6
- package/dist/methods/getAllParentNodes.d.ts +0 -3
- package/dist/methods/getAreaRect.d.ts +0 -3
- package/dist/methods/getBoundingClientRect.d.ts +0 -4
- package/dist/methods/getCurrentScroll.d.ts +0 -3
- package/dist/methods/getOverflowEdges.d.ts +0 -7
- package/dist/methods/getPointerPos.d.ts +0 -5
- package/dist/methods/getSelectorPosition.d.ts +0 -12
- package/dist/methods/getStylePosition.d.ts +0 -3
- package/dist/methods/handleElementOverflow.d.ts +0 -10
- package/dist/methods/handleElementPositionAttribute.d.ts +0 -6
- package/dist/methods/handleKeyboardDragPosDifference.d.ts +0 -13
- package/dist/methods/handleSelection.d.ts +0 -9
- package/dist/methods/handleUnSelection.d.ts +0 -9
- package/dist/methods/hydrateSettings.d.ts +0 -3
- package/dist/methods/index.d.ts +0 -30
- package/dist/methods/isCollision.d.ts +0 -13
- package/dist/methods/moveElement.d.ts +0 -8
- package/dist/methods/removeModificationObservers.d.ts +0 -3
- package/dist/methods/scrollElement.d.ts +0 -3
- package/dist/methods/setStylePosition.d.ts +0 -3
- package/dist/methods/subscriberAliases.d.ts +0 -14
- package/dist/methods/toArray.d.ts +0 -3
- package/dist/methods/updateElementStylePos.d.ts +0 -8
- package/dist/methods/vect2.d.ts +0 -8
- package/dist/modules/Area.d.ts +0 -80
- package/dist/modules/Drag.d.ts +0 -71
- package/dist/modules/DropZone.d.ts +0 -90
- package/dist/modules/DropZones.d.ts +0 -73
- package/dist/modules/Interaction.d.ts +0 -51
- package/dist/modules/PubSub.d.ts +0 -37
- package/dist/modules/SelectableSet.d.ts +0 -43
- package/dist/modules/SelectedSet.d.ts +0 -32
- package/dist/modules/Selection.d.ts +0 -54
- package/dist/modules/Selector.d.ts +0 -29
- package/dist/modules/SelectorArea.d.ts +0 -58
- package/dist/modules/index.d.ts +0 -11
- package/dist/stores/KeyStore.d.ts +0 -34
- package/dist/stores/PointerStore.d.ts +0 -83
- package/dist/stores/ScrollStore.d.ts +0 -38
- package/dist/stores/SettingsStore.d.ts +0 -39
- package/dist/stores/index.d.ts +0 -5
- package/dist/types.d.ts +0 -276
- package/jsconfig.json +0 -13
- package/rollup.config.js +0 -101
- package/src/DragSelect.js +0 -384
- package/src/methods/addModificationObservers.js +0 -38
- package/src/methods/canScroll.js +0 -20
- package/src/methods/getAllParentNodes.js +0 -17
- package/src/methods/getBoundingClientRect.js +0 -33
- package/src/methods/getCurrentScroll.js +0 -15
- package/src/methods/getPointerPos.js +0 -13
- package/src/methods/handleElementOverflow.js +0 -65
- package/src/methods/handleElementPositionAttribute.js +0 -16
- package/src/methods/handleKeyboardDragPosDifference.js +0 -57
- package/src/methods/handleSelection.js +0 -26
- package/src/methods/index.js +0 -29
- package/src/methods/isCollision.js +0 -58
- package/src/methods/moveElement.js +0 -39
- package/src/methods/removeModificationObservers.js +0 -13
- package/src/methods/subscriberAliases.js +0 -72
- package/src/methods/toArray.js +0 -18
- package/src/methods/updateElementStylePos.js +0 -15
- package/src/methods/vect2.js +0 -54
- package/src/modules/Area.js +0 -183
- package/src/modules/Drag.js +0 -257
- package/src/modules/DropZones.js +0 -161
- package/src/modules/Interaction.js +0 -208
- package/src/modules/PubSub.js +0 -78
- package/src/modules/SelectableSet.js +0 -149
- package/src/modules/SelectedSet.js +0 -72
- package/src/modules/Selector.js +0 -90
- package/src/modules/index.js +0 -10
- package/src/stores/KeyStore.js +0 -83
- package/src/stores/PointerStore.js +0 -218
- package/src/stores/ScrollStore.js +0 -92
- package/src/stores/SettingsStore.js +0 -66
- package/src/stores/index.js +0 -4
- package/src/types.js +0 -100
package/src/DragSelect.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/*
|
|
3
|
-
____ _____ __ __
|
|
4
|
-
/ __ \_________ _____ _/ ___/___ / /__ _____/ /_
|
|
5
|
-
/ / / / ___/ __ `/ __ `/\__ \/ _ \/ / _ \/ ___/ __/
|
|
6
|
-
/ /_/ / / / /_/ / /_/ /___/ / __/ / __/ /__/ /_
|
|
7
|
-
/_____/_/ \__,_/\__, //____/\___/_/\___/\___/\__/
|
|
8
|
-
/____/
|
|
9
|
-
|
|
10
|
-
{*} {*} STAR THIS PLUGIN ON GITHUB {*} {*}
|
|
11
|
-
|
|
12
|
-
https://github.com/ThibaultJanBeyer/DragSelect
|
|
13
|
-
Please give it a like, this is what makes me happy :-)
|
|
14
|
-
Thank You
|
|
15
|
-
|
|
16
|
-
{*} {*} STAR THIS PLUGIN ON GITHUB {*} {*}
|
|
17
|
-
|
|
18
|
-
******************************************
|
|
19
|
-
********* The MIT License (MIT) **********
|
|
20
|
-
******************************************
|
|
21
|
-
Copyright (c) 2017 ThibaultJanBeyer
|
|
22
|
-
web: http://www.dragselect.com/
|
|
23
|
-
github: https://github.com/ThibaultJanBeyer/DragSelect
|
|
24
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
26
|
-
in the Software without restriction, including without limitation the rights
|
|
27
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
28
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
29
|
-
furnished to do so, subject to the following conditions:
|
|
30
|
-
The above copyright notice and this permission notice shall be included in all
|
|
31
|
-
copies or substantial portions of the Software.
|
|
32
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
33
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
34
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
35
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
36
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
37
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
38
|
-
SOFTWARE.
|
|
39
|
-
--- Notes ---
|
|
40
|
-
Checking types using JS-Docs inspired by this post:
|
|
41
|
-
https://medium.com/@trukrs/type-safe-javascript-with-jsdoc-7a2a63209b76
|
|
42
|
-
---
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
import './types'
|
|
46
|
-
import {
|
|
47
|
-
Area,
|
|
48
|
-
Drag,
|
|
49
|
-
DropZones,
|
|
50
|
-
Interaction,
|
|
51
|
-
PubSub,
|
|
52
|
-
SelectableSet,
|
|
53
|
-
SelectedSet,
|
|
54
|
-
Selection,
|
|
55
|
-
Selector,
|
|
56
|
-
SelectorArea,
|
|
57
|
-
} from './modules'
|
|
58
|
-
import { PointerStore, ScrollStore, KeyStore, SettingsStore } from './stores'
|
|
59
|
-
import { toArray, subscriberAliases, isCollision } from './methods'
|
|
60
|
-
|
|
61
|
-
// Setup
|
|
62
|
-
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
63
|
-
|
|
64
|
-
class DragSelect {
|
|
65
|
-
/**
|
|
66
|
-
* used to skip all current Selection and dragNdrop functionality
|
|
67
|
-
* @type {boolean}
|
|
68
|
-
*/
|
|
69
|
-
continue = false
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @class DragSelect
|
|
73
|
-
* @constructor DragSelect
|
|
74
|
-
* @param {Settings} settings
|
|
75
|
-
*/
|
|
76
|
-
constructor(settings) {
|
|
77
|
-
this.PubSub = new PubSub({ DS: this })
|
|
78
|
-
this.subscribe = this.PubSub.subscribe
|
|
79
|
-
this.unsubscribe = this.PubSub.unsubscribe
|
|
80
|
-
this.publish = this.PubSub.publish
|
|
81
|
-
|
|
82
|
-
this.stores = /** @type {{ SettingsStore:SettingsStore, PointerStore:PointerStore, ScrollStore:ScrollStore, KeyStore:KeyStore }} */ ({})
|
|
83
|
-
this.stores.SettingsStore = new SettingsStore({ DS: this, settings })
|
|
84
|
-
this.stores.PointerStore = new PointerStore({ DS: this })
|
|
85
|
-
this.stores.ScrollStore = new ScrollStore({ DS: this })
|
|
86
|
-
this.stores.KeyStore = new KeyStore({ DS: this })
|
|
87
|
-
|
|
88
|
-
this.Area = new Area({ DS: this })
|
|
89
|
-
this.Selector = new Selector({ DS: this })
|
|
90
|
-
this.SelectorArea = new SelectorArea({ DS: this })
|
|
91
|
-
|
|
92
|
-
this.SelectableSet = new SelectableSet({ DS: this })
|
|
93
|
-
this.SelectedSet = new SelectedSet({ DS: this })
|
|
94
|
-
this.Selection = new Selection({ DS: this })
|
|
95
|
-
|
|
96
|
-
this.Drag = new Drag({ DS: this })
|
|
97
|
-
|
|
98
|
-
this.DropZones = new DropZones({ DS: this })
|
|
99
|
-
|
|
100
|
-
this.Interaction = new Interaction({ DS: this })
|
|
101
|
-
|
|
102
|
-
// Subscriber Aliases
|
|
103
|
-
subscriberAliases({
|
|
104
|
-
subscribe: this.subscribe,
|
|
105
|
-
publish: this.publish,
|
|
106
|
-
SelectedSet: this.SelectedSet,
|
|
107
|
-
Interaction: this.Interaction,
|
|
108
|
-
DropZones: this.DropZones,
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
this.subscribe('Interaction:end', () => (this.continue = false))
|
|
112
|
-
|
|
113
|
-
this.start()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Useful methods for the user
|
|
117
|
-
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
118
|
-
/**
|
|
119
|
-
* Initializes the functionality. Automatically triggered when created.
|
|
120
|
-
* Also, reset the functionality after a teardown
|
|
121
|
-
*/
|
|
122
|
-
start = () => {
|
|
123
|
-
this.stopped = false
|
|
124
|
-
this.Interaction.init()
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Complete function teardown
|
|
129
|
-
* Will teardown/stop the whole functionality
|
|
130
|
-
* @param {boolean} [remove] - if elements should be removed.
|
|
131
|
-
* @param {boolean} [fromSelection] - if elements should also be added/removed to the selection.
|
|
132
|
-
* @param {boolean} [withCallback] - if elements should also be added/removed to the selection.
|
|
133
|
-
*/
|
|
134
|
-
stop(remove = true, fromSelection = true, withCallback = false) {
|
|
135
|
-
if (withCallback) this.publish('callback', { items: this.getSelection() })
|
|
136
|
-
|
|
137
|
-
this.Interaction.stop()
|
|
138
|
-
this.Area.stop()
|
|
139
|
-
this.Drag.stop()
|
|
140
|
-
this.Selector.stop()
|
|
141
|
-
this.SelectorArea.stop(remove)
|
|
142
|
-
this.stores.KeyStore.stop()
|
|
143
|
-
this.stores.PointerStore.stop()
|
|
144
|
-
this.stores.ScrollStore.stop()
|
|
145
|
-
|
|
146
|
-
if (remove) this.SelectableSet.clear()
|
|
147
|
-
if (fromSelection) this.SelectedSet.clear()
|
|
148
|
-
|
|
149
|
-
this.stopped = true
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Utility to override DragSelect internal functionality:
|
|
154
|
-
* Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
|
|
155
|
-
* Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
|
|
156
|
-
*/
|
|
157
|
-
break = () => (this.continue = true)
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Update any setting dynamically
|
|
161
|
-
* @param {Settings} settings
|
|
162
|
-
* @return {void}
|
|
163
|
-
*/
|
|
164
|
-
setSettings = (settings) => this.stores.SettingsStore.update({ settings })
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Returns the current selected nodes
|
|
168
|
-
* @return {DSElements}
|
|
169
|
-
*/
|
|
170
|
-
getSelection = () => this.SelectedSet.elements
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Adds several elements to the selection list also adds the specific classes and take into account all calculations.
|
|
174
|
-
* Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
|
|
175
|
-
* @param {DSInputElements} elements one or multiple elements
|
|
176
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
177
|
-
* @param {boolean} [dontAddToSelectables] - if element should not be added to the list of selectable elements
|
|
178
|
-
* @return {DSElements} all selected elements
|
|
179
|
-
*/
|
|
180
|
-
addSelection(
|
|
181
|
-
elements,
|
|
182
|
-
triggerCallback = false,
|
|
183
|
-
dontAddToSelectables = false
|
|
184
|
-
) {
|
|
185
|
-
this.SelectedSet.addAll(toArray(elements))
|
|
186
|
-
if (!dontAddToSelectables) this.addSelectables(elements)
|
|
187
|
-
if (triggerCallback)
|
|
188
|
-
this.PubSub.publish('callback', { items: this.getSelection() })
|
|
189
|
-
return this.getSelection()
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Removes specific elements from the selection
|
|
194
|
-
* Multiple elements can be given at once, in contrary to unselect
|
|
195
|
-
* @param {DSInputElements} elements one or multiple elements
|
|
196
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
197
|
-
* @param {boolean} [removeFromSelectables] - if element should be removed from the list of selectable elements
|
|
198
|
-
* @return {DSElements} all selected elements
|
|
199
|
-
*/
|
|
200
|
-
removeSelection(
|
|
201
|
-
elements,
|
|
202
|
-
triggerCallback = false,
|
|
203
|
-
removeFromSelectables = false
|
|
204
|
-
) {
|
|
205
|
-
this.SelectedSet.deleteAll(toArray(elements))
|
|
206
|
-
if (removeFromSelectables) this.removeSelectables(elements)
|
|
207
|
-
if (triggerCallback)
|
|
208
|
-
this.PubSub.publish('callback', { items: this.getSelection() })
|
|
209
|
-
return this.getSelection()
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Toggles specific elements from the selection:
|
|
214
|
-
* If element is not in selection it will be added, if it is already selected, it will be removed.
|
|
215
|
-
* Multiple elements can be given at once.
|
|
216
|
-
* @param {DSInputElements} elements one or multiple elements
|
|
217
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
218
|
-
* @param {boolean} [removeFromSelectables] - if element should not be added/removed to the list of selectable elements accordingly
|
|
219
|
-
* @return {DSElements} all selected elements
|
|
220
|
-
*/
|
|
221
|
-
toggleSelection(
|
|
222
|
-
elements,
|
|
223
|
-
triggerCallback = false,
|
|
224
|
-
removeFromSelectables = false
|
|
225
|
-
) {
|
|
226
|
-
toArray(elements).forEach((el) =>
|
|
227
|
-
this.SelectedSet.has(el)
|
|
228
|
-
? this.removeSelection(elements, triggerCallback, removeFromSelectables)
|
|
229
|
-
: this.addSelection(elements, triggerCallback, removeFromSelectables)
|
|
230
|
-
)
|
|
231
|
-
if (triggerCallback)
|
|
232
|
-
this.PubSub.publish('callback', { items: this.getSelection() })
|
|
233
|
-
return this.getSelection()
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Sets the current selected elements and optionally run the callback
|
|
238
|
-
* By default, adds new elements also to the list of selectables
|
|
239
|
-
* @param {DSInputElements} elements – dom elements
|
|
240
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
241
|
-
* @param {boolean} [dontAddToSelectables] - if element should not be added to the list of selectable elements
|
|
242
|
-
* @return {DSElements}
|
|
243
|
-
*/
|
|
244
|
-
setSelection(
|
|
245
|
-
elements,
|
|
246
|
-
triggerCallback = false,
|
|
247
|
-
dontAddToSelectables = false
|
|
248
|
-
) {
|
|
249
|
-
this.clearSelection()
|
|
250
|
-
this.addSelection(elements, triggerCallback, dontAddToSelectables)
|
|
251
|
-
return this.getSelection()
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Unselect / Deselect all current selected Nodes
|
|
256
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
257
|
-
* @return {DSElements} this.selected, should be empty
|
|
258
|
-
*/
|
|
259
|
-
clearSelection(triggerCallback = false) {
|
|
260
|
-
this.SelectedSet.clear()
|
|
261
|
-
if (triggerCallback)
|
|
262
|
-
this.PubSub.publish('callback', { items: this.getSelection() })
|
|
263
|
-
return this.getSelection()
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Add elements that can be selected. No node is added twice
|
|
268
|
-
* @param {DSInputElements} elements dom element(s)
|
|
269
|
-
* @param {boolean} [addToSelection] if elements should also be added to current selection
|
|
270
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
271
|
-
* @return {DSInputElements} the added element(s)
|
|
272
|
-
*/
|
|
273
|
-
addSelectables(elements, addToSelection, triggerCallback) {
|
|
274
|
-
const els = toArray(elements)
|
|
275
|
-
this.SelectableSet.addAll(els)
|
|
276
|
-
if (addToSelection) this.SelectedSet.addAll(els)
|
|
277
|
-
if (triggerCallback)
|
|
278
|
-
this.PubSub.publish('callback', { items: this.getSelection() })
|
|
279
|
-
return elements
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Gets all nodes that can potentially be selected
|
|
284
|
-
* @return {DSElements} this.selectables
|
|
285
|
-
*/
|
|
286
|
-
getSelectables = () => this.SelectableSet.elements
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Sets all elements that can be selected.
|
|
290
|
-
* Removes all current selectables (& their respective classes).
|
|
291
|
-
* Adds the new set to the selectables set, thus replacing the original set.
|
|
292
|
-
* @param {DSInputElements} elements – dom element(s)
|
|
293
|
-
* @param {boolean} [removeFromSelection] if elements should also be removed from current selection
|
|
294
|
-
* @param {boolean} [addToSelection] if elements should also be added to current selection
|
|
295
|
-
* @return {DSInputElements} elements – the added element(s)
|
|
296
|
-
*/
|
|
297
|
-
setSelectables(
|
|
298
|
-
elements,
|
|
299
|
-
removeFromSelection = false,
|
|
300
|
-
addToSelection = false
|
|
301
|
-
) {
|
|
302
|
-
console.warn(
|
|
303
|
-
'[DragSelect] DEPRECATION ".setSelectables" is deprecated and will be removed soon. Please use "ds.setSettings({ selectables: << new dom elements >> })" instead (see docs)'
|
|
304
|
-
)
|
|
305
|
-
this.removeSelectables(elements, removeFromSelection)
|
|
306
|
-
return this.addSelectables(elements, addToSelection)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Remove elements from the elements that can be selected.
|
|
311
|
-
* @param {DSInputElements} elements – dom element(s)
|
|
312
|
-
* @param {boolean} [removeFromSelection] if elements should also be removed from current selection
|
|
313
|
-
* @param {boolean} [triggerCallback] - if callback should be called
|
|
314
|
-
* @return {DSInputElements} the removed element(s)
|
|
315
|
-
*/
|
|
316
|
-
removeSelectables(elements, removeFromSelection, triggerCallback) {
|
|
317
|
-
this.SelectableSet.deleteAll(toArray(elements))
|
|
318
|
-
if (removeFromSelection) this.removeSelection(elements)
|
|
319
|
-
if (triggerCallback)
|
|
320
|
-
this.PubSub.publish('callback', { items: this.getSelection() })
|
|
321
|
-
return elements
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/** The starting/initial position of the cursor/selector @return {Vect2} */
|
|
325
|
-
getInitialCursorPosition = () => this.stores.PointerStore.initialVal
|
|
326
|
-
|
|
327
|
-
/** The last seen position of the cursor/selector @return {Vect2} */
|
|
328
|
-
getCurrentCursorPosition = () => this.stores.PointerStore.currentVal
|
|
329
|
-
|
|
330
|
-
/** The previous position of the cursor/selector @return {Vect2} */
|
|
331
|
-
getPreviousCursorPosition = () => this.stores.PointerStore.lastVal
|
|
332
|
-
|
|
333
|
-
/** The starting/initial position of the cursor/selector @return {Vect2} */
|
|
334
|
-
getInitialCursorPositionArea = () => this.stores.PointerStore.initialValArea
|
|
335
|
-
|
|
336
|
-
/** The last seen position of the cursor/selector @return {Vect2} */
|
|
337
|
-
getCurrentCursorPositionArea = () => this.stores.PointerStore.currentValArea
|
|
338
|
-
|
|
339
|
-
/** The previous position of the cursor/selector @return {Vect2} */
|
|
340
|
-
getPreviousCursorPositionArea = () => this.stores.PointerStore.lastValArea
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Whether the multi-selection key was pressed
|
|
344
|
-
* @param {DSEvent|KeyboardEvent} [event]
|
|
345
|
-
* @return {boolean}
|
|
346
|
-
*/
|
|
347
|
-
isMultiSelect = (event) => this.stores.KeyStore.isMultiSelectKeyPressed(event)
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Whether the user is currently drag n dropping elements (instead of selection)
|
|
351
|
-
* @return {boolean}
|
|
352
|
-
*/
|
|
353
|
-
isDragging = () => this.Interaction.isDragging
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Returns first DropsZone under coordinates,
|
|
357
|
-
* if no coordinated provided current pointer coordinates are used
|
|
358
|
-
* @param {Vect2} [coordinates]
|
|
359
|
-
* @returns {DSDropZone | undefined}
|
|
360
|
-
*/
|
|
361
|
-
getZoneByCoordinates = (coordinates) =>
|
|
362
|
-
this.DropZones.getTarget(coordinates)?.toObject()
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Returns itemsDropped into zone by zone id
|
|
366
|
-
* @param {string} zoneId
|
|
367
|
-
* @returns {DSElements|void}
|
|
368
|
-
*/
|
|
369
|
-
getItemsDroppedByZoneId = (zoneId) =>
|
|
370
|
-
this.DropZones.getItemsDroppedById(zoneId)
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Returns itemsInside by zone id
|
|
374
|
-
* @param {string} zoneId
|
|
375
|
-
* @param {boolean} addClasses whether or not to add/remove the "inside" classes to the items
|
|
376
|
-
* @returns {DSElements|void}
|
|
377
|
-
*/
|
|
378
|
-
getItemsInsideByZoneId = (zoneId, addClasses) =>
|
|
379
|
-
this.DropZones.getItemsInsideById(zoneId, addClasses)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
DragSelect.isCollision = isCollision
|
|
383
|
-
|
|
384
|
-
export default DragSelect
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
import { removeModificationObservers } from '.'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Removes event-listeners from the DOMNode
|
|
8
|
-
* @typedef {()=>void} DSCleanup
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Adds event-listeners to a DOMNode
|
|
13
|
-
* @param {DSArea[]} nodes
|
|
14
|
-
* @param {DSModificationCallback} cb
|
|
15
|
-
* @return {{observer:MutationObserver,callback:DSModificationCallback,cleanup:DSCleanup}}
|
|
16
|
-
*/
|
|
17
|
-
export default (nodes, cb) => {
|
|
18
|
-
const callback = cb
|
|
19
|
-
|
|
20
|
-
window.addEventListener('resize', callback)
|
|
21
|
-
window.addEventListener('scroll', callback)
|
|
22
|
-
|
|
23
|
-
const observer = new MutationObserver(callback)
|
|
24
|
-
|
|
25
|
-
nodes.forEach((el, i) => {
|
|
26
|
-
observer.observe(el, {
|
|
27
|
-
childList: i !== 0,
|
|
28
|
-
attributes: true,
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Removes all observers
|
|
34
|
-
*/
|
|
35
|
-
const cleanup = () => removeModificationObservers(observer, callback)
|
|
36
|
-
|
|
37
|
-
return { observer, callback, cleanup }
|
|
38
|
-
}
|
package/src/methods/canScroll.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import { getCurrentScroll } from '.'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks whether the area can scroll or not
|
|
7
|
-
* @param {DSArea} area
|
|
8
|
-
* @return {boolean} scroll X/Y
|
|
9
|
-
*/
|
|
10
|
-
export default (area) => {
|
|
11
|
-
const scroll = getCurrentScroll(area)
|
|
12
|
-
if (scroll.x || scroll.y) return true
|
|
13
|
-
|
|
14
|
-
if (area instanceof Document) {
|
|
15
|
-
if (area.body) return !!(area.body.scrollTop = 1)
|
|
16
|
-
return !!(area.documentElement.scrollTop = 1)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return !!(area.scrollTop = 1)
|
|
20
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
|
13
|
-
return toWatch
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return traverse([node])
|
|
17
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import { SelectableSet } from '../modules'
|
|
4
|
-
import {toArray} from './'
|
|
5
|
-
/**
|
|
6
|
-
* Returns the compound bounding rect of multiple elements.
|
|
7
|
-
* @param {DSElements} elements
|
|
8
|
-
* @param {SelectableSet} SelectableSet
|
|
9
|
-
* @returns {DSBoundingRect}
|
|
10
|
-
*/
|
|
11
|
-
export default (elements, SelectableSet) => {
|
|
12
|
-
const rect = {
|
|
13
|
-
top: Number.POSITIVE_INFINITY,
|
|
14
|
-
left: Number.POSITIVE_INFINITY,
|
|
15
|
-
bottom: Number.NEGATIVE_INFINITY,
|
|
16
|
-
right: Number.NEGATIVE_INFINITY,
|
|
17
|
-
width: Number.NEGATIVE_INFINITY,
|
|
18
|
-
height: Number.NEGATIVE_INFINITY,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
toArray(elements).forEach((element) => {
|
|
22
|
-
const elementRect = SelectableSet.getRect(element)
|
|
23
|
-
rect.top = Math.min(rect.top, elementRect.top)
|
|
24
|
-
rect.left = Math.min(rect.left, elementRect.left)
|
|
25
|
-
rect.bottom = Math.max(rect.bottom, elementRect.bottom)
|
|
26
|
-
rect.right = Math.max(rect.right, elementRect.right)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
rect.height = rect.bottom - rect.top
|
|
30
|
-
rect.width = rect.right - rect.left
|
|
31
|
-
|
|
32
|
-
return rect
|
|
33
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import { documentScroll } from './'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {DSArea} [area]
|
|
7
|
-
* @return {Vect2} scroll X/Y
|
|
8
|
-
*/
|
|
9
|
-
export default (area) => {
|
|
10
|
-
if (!area || area instanceof Document) return documentScroll()
|
|
11
|
-
return {
|
|
12
|
-
x: area.scrollLeft >= 0 ? area.scrollLeft : documentScroll().x,
|
|
13
|
-
y: area.scrollTop >= 0 ? area.scrollTop : documentScroll().y,
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns cursor x, y position based on event object
|
|
6
|
-
* @param {Object} p
|
|
7
|
-
* @param {MouseEvent|Touch|PointerEvent} p.event
|
|
8
|
-
* @return {Vect2} cursor X/Y position
|
|
9
|
-
*/
|
|
10
|
-
export default ({ event }) => ({
|
|
11
|
-
x: event.clientX,
|
|
12
|
-
y: event.clientY,
|
|
13
|
-
})
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
import { setStylePosition } from './'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* pushes element back the overflow amount
|
|
8
|
-
* (top - top gives overflow, then new position pushed back by overflow)
|
|
9
|
-
* @param {Object} p
|
|
10
|
-
* @param {DSElement} p.element
|
|
11
|
-
* @param {DSEdges} p.edges
|
|
12
|
-
* @param {DSBoundingRect} p.elementRect
|
|
13
|
-
* @param {DSBoundingRect} p.containerRect
|
|
14
|
-
* @param {Vect2} p.elementPos
|
|
15
|
-
* @param {boolean} p.useTransform
|
|
16
|
-
*/
|
|
17
|
-
export default ({
|
|
18
|
-
element,
|
|
19
|
-
edges,
|
|
20
|
-
elementRect,
|
|
21
|
-
containerRect,
|
|
22
|
-
elementPos,
|
|
23
|
-
useTransform,
|
|
24
|
-
}) => {
|
|
25
|
-
if (edges.includes('top')) {
|
|
26
|
-
setStylePosition(
|
|
27
|
-
element,
|
|
28
|
-
{
|
|
29
|
-
y: elementPos.y + containerRect.top - elementRect.top,
|
|
30
|
-
x: elementPos.x,
|
|
31
|
-
},
|
|
32
|
-
useTransform
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
if (edges.includes('left')) {
|
|
36
|
-
setStylePosition(
|
|
37
|
-
element,
|
|
38
|
-
{
|
|
39
|
-
y: elementPos.y,
|
|
40
|
-
x: elementPos.x + containerRect.left - elementRect.left,
|
|
41
|
-
},
|
|
42
|
-
useTransform
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
if (edges.includes('bottom')) {
|
|
46
|
-
setStylePosition(
|
|
47
|
-
element,
|
|
48
|
-
{
|
|
49
|
-
y: elementPos.y + containerRect.bottom - elementRect.bottom,
|
|
50
|
-
x: elementPos.x,
|
|
51
|
-
},
|
|
52
|
-
useTransform
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
if (edges.includes('right')) {
|
|
56
|
-
setStylePosition(
|
|
57
|
-
element,
|
|
58
|
-
{
|
|
59
|
-
y: elementPos.y,
|
|
60
|
-
x: elementPos.x + containerRect.right - elementRect.right,
|
|
61
|
-
},
|
|
62
|
-
useTransform
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Fix: some elements have to have a special position attribute for calculations
|
|
6
|
-
* @param {Object} p
|
|
7
|
-
* @param {CSSStyleDeclaration} p.computedStyle
|
|
8
|
-
* @param {DSArea} p.node
|
|
9
|
-
*/
|
|
10
|
-
export default ({ computedStyle, node }) => {
|
|
11
|
-
const { position } = computedStyle
|
|
12
|
-
const isPositioned =
|
|
13
|
-
position === 'absolute' || position === 'relative' || position === 'fixed'
|
|
14
|
-
if (!(node instanceof Document) && !isPositioned)
|
|
15
|
-
node.style.position = 'relative'
|
|
16
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {function} ScrollCallback
|
|
6
|
-
* @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} directions
|
|
7
|
-
* @property {number} multiplier
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* @param {Object} p
|
|
11
|
-
* @param {string} p.key the keyboard key that was pressed
|
|
12
|
-
* @param {boolean} p.shiftKey
|
|
13
|
-
* @param {boolean} p.canScroll
|
|
14
|
-
* @param {number} p.keyboardDragSpeed
|
|
15
|
-
* @param {number} p.zoom
|
|
16
|
-
* @param {ScrollCallback} p.scrollCallback
|
|
17
|
-
* @param {Vect2} p.scrollDiff
|
|
18
|
-
* @param {DSDragKeys} p.dragKeys
|
|
19
|
-
* @returns {Vect2}
|
|
20
|
-
*/
|
|
21
|
-
export default ({
|
|
22
|
-
shiftKey,
|
|
23
|
-
keyboardDragSpeed,
|
|
24
|
-
zoom,
|
|
25
|
-
key,
|
|
26
|
-
dragKeys,
|
|
27
|
-
scrollDiff,
|
|
28
|
-
canScroll,
|
|
29
|
-
scrollCallback,
|
|
30
|
-
}) => {
|
|
31
|
-
const posDirection = { x: 0, y: 0 }
|
|
32
|
-
const increase = shiftKey
|
|
33
|
-
? keyboardDragSpeed * 4 * zoom
|
|
34
|
-
: keyboardDragSpeed * zoom
|
|
35
|
-
|
|
36
|
-
if (dragKeys.left.includes(key)) {
|
|
37
|
-
posDirection.x = scrollDiff.x || -increase
|
|
38
|
-
if (!shiftKey && !scrollDiff.x && canScroll)
|
|
39
|
-
scrollCallback(['left'], keyboardDragSpeed)
|
|
40
|
-
}
|
|
41
|
-
if (dragKeys.right.includes(key)) {
|
|
42
|
-
posDirection.x = scrollDiff.x || increase
|
|
43
|
-
if (!shiftKey && !scrollDiff.x && canScroll)
|
|
44
|
-
scrollCallback(['right'], keyboardDragSpeed)
|
|
45
|
-
}
|
|
46
|
-
if (dragKeys.up.includes(key)) {
|
|
47
|
-
posDirection.y = scrollDiff.y || -increase
|
|
48
|
-
if (!shiftKey && !scrollDiff.y && canScroll)
|
|
49
|
-
scrollCallback(['top'], keyboardDragSpeed)
|
|
50
|
-
}
|
|
51
|
-
if (dragKeys.down.includes(key)) {
|
|
52
|
-
posDirection.y = scrollDiff.y || increase
|
|
53
|
-
if (!shiftKey && !scrollDiff.y && canScroll)
|
|
54
|
-
scrollCallback(['bottom'], keyboardDragSpeed)
|
|
55
|
-
}
|
|
56
|
-
return posDirection
|
|
57
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Logic when an element is selected
|
|
6
|
-
* @param {Object} p
|
|
7
|
-
* @param {DSElement} p.element
|
|
8
|
-
* @param {boolean} p.force
|
|
9
|
-
* @param {boolean} p.multiSelectionToggle
|
|
10
|
-
* @param {Set} p.SelectedSet
|
|
11
|
-
* @param {string} p.hoverClassName
|
|
12
|
-
*/
|
|
13
|
-
export default ({
|
|
14
|
-
element,
|
|
15
|
-
force,
|
|
16
|
-
multiSelectionToggle,
|
|
17
|
-
SelectedSet,
|
|
18
|
-
hoverClassName,
|
|
19
|
-
}) => {
|
|
20
|
-
if (element.classList.contains(hoverClassName) && !force) return
|
|
21
|
-
|
|
22
|
-
if (!SelectedSet.has(element)) SelectedSet.add(element)
|
|
23
|
-
else if (multiSelectionToggle) SelectedSet.delete(element)
|
|
24
|
-
|
|
25
|
-
element.classList.add(hoverClassName)
|
|
26
|
-
}
|